From 9ce5802a5e4b8fe8b307d3aca0772332df7b590a Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Tue, 16 Jun 2009 14:22:32 -0700 Subject: [PATCH] mon:Added server-side handling of MPoolSnap. Currently assumes it's a snap-create message. --- src/messages/MPoolSnapReply.h | 6 +++-- src/mon/Monitor.cc | 4 ++++ src/mon/OSDMonitor.cc | 45 +++++++++++++++++++++++++++++++++++ src/mon/OSDMonitor.h | 15 ++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/messages/MPoolSnapReply.h b/src/messages/MPoolSnapReply.h index a73031f908b6e..63885173f86c8 100644 --- a/src/messages/MPoolSnapReply.h +++ b/src/messages/MPoolSnapReply.h @@ -21,10 +21,12 @@ public: ceph_fsid_t fsid; tid_t tid; int replyCode; + int epoch; + MPoolSnapReply() : Message(MSG_POOLSNAPREPLY) {} - MPoolSnapReply( ceph_fsid_t& f, tid_t t, int rc) : - Message(MSG_POOLSNAPREPLY), fsid(f), tid(t), replyCode(rc) {} + MPoolSnapReply( ceph_fsid_t& f, tid_t t, int rc, int e) : + Message(MSG_POOLSNAPREPLY), fsid(f), tid(t), replyCode(rc), epoch(e) {} const char *get_type_name() { return "poolsnapreply"; } diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index a7e061fcb68e0..e6eb6cdb971ea 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -419,6 +419,10 @@ bool Monitor::dispatch_impl(Message *m) paxos_service[PAXOS_PGMAP]->dispatch(m); break; + case MSG_POOLSNAP: + paxos_service[PAXOS_OSDMAP]->dispatch(m); + break; + // log case MSG_LOG: paxos_service[PAXOS_LOG]->dispatch(m); diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index fc8a5283a4bb7..911b5b19983b5 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -271,6 +271,9 @@ bool OSDMonitor::preprocess_query(Message *m) return preprocess_out((MOSDOut*)m); */ + case MSG_POOLSNAP: + return preprocess_pool_snap((MPoolSnap*)m); + case MSG_REMOVE_SNAPS: return preprocess_remove_snaps((MRemoveSnaps*)m); @@ -301,6 +304,8 @@ bool OSDMonitor::prepare_update(Message *m) case MSG_OSD_OUT: return prepare_out((MOSDOut*)m); */ + case MSG_POOLSNAP: + return prepare_pool_snap((MPoolSnap*)m); case MSG_REMOVE_SNAPS: return prepare_remove_snaps((MRemoveSnaps*)m); @@ -1264,4 +1269,44 @@ out: return false; } +bool OSDMonitor::preprocess_pool_snap ( MPoolSnap *m) { + if (m->pool < 0 ) { + ss << "unrecognized pool '" << m->pool << "'"; + err = -ENOENT; + //create reply, set replyCode to badness + _pool_snap(m->fsid, m->tid, -1, pending_inc.epoch); + return true; + } + +} + +bool OSDMonitor::prepare_pool_snap ( MPoolSnap *m) { + const pg_pool_t *p = &osdmap.get_pg_pool(m->pool); + pg_pool_t *pp = 0; + if (pending_inc.new_pools.count(pool)) pp = &pending_inc.new_pools[pool]; + //if the snapname is already in use, we have a problem + if (p->snap_exists(m->name) || + pp && pp->snap_exists(m->name)) { + ss << "pool " << m->pool << " snap " << m->name << " already exists"; + err = -EEXIST; + _pool_snap(m->fsid, m->tid, -2, pending_inc.epoch); + return false; + } else { + if(!pp) { + pp = &pending_inc.new_pools[pool]; + *pp = *p; + } + pp->add_snap(m->name, g_clock.now()); + pp->set_snap_epoch(pending_inc.epoch); + ss << "created pool " << m->pool << " snap " << m->name; + getline(ss, rs); + paxos->wait_for_commit(new Monitor::C_Snap(mon, m, 0, pending_inc.epoch)); + return true; + } +} + void _pool_snap(ceph_fsid_t fsid, tid_t tid, int replyCode, int epoch) { + MPoolSnapReply *m = new MPoolSnapReply(fsid, tid, replyCode, epoch); + mon->messenger->send_message(m, m->get_orig_source_inst()); + delete m; + } diff --git a/src/mon/OSDMonitor.h b/src/mon/OSDMonitor.h index 2a93bda44b5ea..502b25315b2e5 100644 --- a/src/mon/OSDMonitor.h +++ b/src/mon/OSDMonitor.h @@ -83,6 +83,10 @@ private: bool prepare_alive(class MOSDAlive *m); void _alive(MOSDAlive *m); + bool preprocess_pool_snap ( class MPoolSnap *m); + bool prepare_pool_snap (MPoolSnap *m); + void _pool_snap(ceph_fsid_t fsid, tid_t tid, int replyCode, int epoch); + struct C_Booted : public Context { OSDMonitor *cmon; MOSDBoot *m; @@ -115,6 +119,17 @@ private: cmon->dispatch((Message*)m); } }; + struct C_Snap : public Context { + OSDMonitor *osdmon; + MPoolSnap *m; + int replyCode; + int epoch; + C_Snap(OSDMonitor * osd, MPoolSnap *m_, int rc, int e) : + osdmon(osd), m(m_), replyCode(rc), epoch(e) {} + void finish(int r) { + osdmon->_pool_snap(m->fsid, m->tid, replyCode, epoch); + } + }; bool preprocess_out(class MOSDOut *m); bool prepare_out(class MOSDOut *m); -- 2.39.5