]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: update snaptable when renaming snapshot
authorYan, Zheng <zyan@redhat.com>
Wed, 8 Apr 2015 02:55:58 +0000 (10:55 +0800)
committerYan, Zheng <zyan@redhat.com>
Fri, 10 Apr 2015 01:48:46 +0000 (09:48 +0800)
Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/mds/Server.cc
src/mds/SnapClient.h
src/mds/SnapServer.cc
src/mds/SnapServer.h

index 14a80f5805984e3353e1e5e94a2f019eeffb4041..6a92790342d86d818c7f0aa7ef90ac902fd1a23e 100644 (file)
@@ -7997,6 +7997,20 @@ void Server::handle_client_renamesnap(MDRequestRef& mdr)
   if (!mds->locker->acquire_locks(mdr, rdlocks, wrlocks, xlocks))
     return;
 
+    // prepare
+  if (!mdr->more()->stid) {
+    mds->snapclient->prepare_update(diri->ino(), snapid, dstname, utime_t(),
+                                   &mdr->more()->stid, &mdr->more()->snapidbl,
+                                   new C_MDS_RetryRequest(mds->mdcache, mdr));
+    return;
+  }
+
+  version_t stid = mdr->more()->stid;
+  bufferlist::iterator p = mdr->more()->snapidbl.begin();
+  snapid_t seq;
+  ::decode(seq, p);
+  dout(10) << " stid is " << stid << ", seq is " << seq << dendl;
+
   // journal
   inode_t *pi = diri->project_inode();
   pi->ctime = mdr->get_op_stamp();
@@ -8013,6 +8027,7 @@ void Server::handle_client_renamesnap(MDRequestRef& mdr)
   mdlog->start_entry(le);
 
   le->metablob.add_client_req(req->get_reqid(), req->get_oldest_client_tid());
+  le->metablob.add_table_transaction(TABLE_SNAP, stid);
   mdcache->predirty_journal_parents(mdr, &le->metablob, diri, 0, PREDIRTY_PRIMARY, false);
   mdcache->journal_dirty_inode(mdr.get(), &le->metablob, diri);
 
@@ -8029,6 +8044,8 @@ void Server::_renamesnap_finish(MDRequestRef& mdr, CInode *diri, snapid_t snapid
   diri->pop_and_dirty_projected_inode(mdr->ls);
   mdr->apply();
 
+  mds->snapclient->commit(mdr->more()->stid, mdr->ls);
+
   dout(10) << "snaprealm now " << *diri->snaprealm << dendl;
 
   mdcache->do_realm_invalidate_and_update_notify(diri, CEPH_SNAP_OP_CREATE, true);
index 3e8d6a282786dc935658610dc40b2659aac584bf..ea1b3acdcd5cc9c3c61f0fce668f4cebe06488cc 100644 (file)
@@ -56,6 +56,18 @@ public:
     ::encode(snapid, bl);
     _prepare(bl, pstid, pbl, onfinish);
   }
+
+  void prepare_update(inodeno_t ino, snapid_t snapid, const string& name, utime_t stamp,
+                     version_t *pstid, bufferlist *pbl, MDSInternalContextBase *onfinish) {
+    bufferlist bl;
+    __u32 op = TABLE_OP_UPDATE;
+    ::encode(op, bl);
+    ::encode(ino, bl);
+    ::encode(snapid, bl);
+    ::encode(name, bl);
+    ::encode(stamp, bl);
+    _prepare(bl, pstid, pbl, onfinish);
+  }
 };
 
 #endif
index 29812e4c49c40adaea4855f8e2605ae757abe16d..5599b19437fd622bd5aa376ed13f8e47e5baac32 100644 (file)
@@ -76,7 +76,8 @@ void SnapServer::_prepare(bufferlist &bl, uint64_t reqid, mds_rank_t bymds)
        ::decode(info.name, p);
        ::decode(info.stamp, p);
        info.snapid = ++last_snap;
-       pending_create[version] = info;
+       info.long_name = "create";
+       pending_update[version] = info;
        dout(10) << "prepare v" << version << " create " << info << dendl;
       } else {
        pending_noop.insert(version);
@@ -106,6 +107,26 @@ void SnapServer::_prepare(bufferlist &bl, uint64_t reqid, mds_rank_t bymds)
     }
     break;
 
+  case TABLE_OP_UPDATE:
+    {
+      SnapInfo info;
+      ::decode(info.ino, p);
+      ::decode(info.snapid, p);
+      ::decode(info.name, p);
+      ::decode(info.stamp, p);
+      info.long_name = "update";
+
+      version++;
+      // bump last_snap... we use it as a version value on the snaprealm.
+      ++last_snap;
+      pending_update[version] = info;
+      dout(10) << "prepare v" << version << " update " << info << dendl;
+
+      bl.clear();
+      ::encode(last_snap, bl);
+    }
+    break;
+
   default:
     assert(0);
   }
@@ -115,17 +136,25 @@ void SnapServer::_prepare(bufferlist &bl, uint64_t reqid, mds_rank_t bymds)
 bool SnapServer::_is_prepared(version_t tid)
 {
   return 
-    pending_create.count(tid) ||
+    pending_update.count(tid) ||
     pending_destroy.count(tid);
 }
 
 bool SnapServer::_commit(version_t tid, MMDSTableRequest *req)
 {
-  if (pending_create.count(tid)) {
-    dout(7) << "commit " << tid << " create " << pending_create[tid] << dendl;
-    snaps[pending_create[tid].snapid] = pending_create[tid];
-    pending_create.erase(tid);
-  } 
+  if (pending_update.count(tid)) {
+    SnapInfo &info = pending_update[tid];
+    string opname;
+    if (info.long_name.empty())
+      opname = "create";
+    else
+      opname.swap(info.long_name);
+    if (info.stamp == utime_t() && snaps.count(info.snapid))
+      info.stamp = snaps[info.snapid].stamp;
+    dout(7) << "commit " << tid << " " << opname << " " << info << dendl;
+    snaps[info.snapid] = info;
+    pending_update.erase(tid);
+  }
 
   else if (pending_destroy.count(tid)) {
     snapid_t sn = pending_destroy[tid].first;
@@ -157,9 +186,15 @@ bool SnapServer::_commit(version_t tid, MMDSTableRequest *req)
 
 void SnapServer::_rollback(version_t tid) 
 {
-  if (pending_create.count(tid)) {
-    dout(7) << "rollback " << tid << " create " << pending_create[tid] << dendl;
-    pending_create.erase(tid);
+  if (pending_update.count(tid)) {
+    SnapInfo &info = pending_update[tid];
+    string opname;
+    if (info.long_name.empty())
+      opname = "create";
+    else
+      opname.swap(info.long_name);
+    dout(7) << "rollback " << tid << " " << opname << " " << info << dendl;
+    pending_update.erase(tid);
   } 
 
   else if (pending_destroy.count(tid)) {
@@ -287,8 +322,8 @@ void SnapServer::dump(Formatter *f) const
   }
   f->close_section();
 
-  f->open_array_section("pending_create");
-  for(map<version_t, SnapInfo>::const_iterator i = pending_create.begin(); i != pending_create.end(); ++i) {
+  f->open_array_section("pending_update");
+  for(map<version_t, SnapInfo>::const_iterator i = pending_update.begin(); i != pending_update.end(); ++i) {
     f->open_object_section("snap");
     f->dump_unsigned("version", i->first);
     f->open_object_section("snapinfo");
@@ -326,7 +361,7 @@ void SnapServer::generate_test_instances(list<SnapServer*>& ls)
   populated->last_snap = 123;
   populated->snaps[456] = populated_snapinfo;
   populated->need_to_purge[2].insert(012);
-  populated->pending_create[234] = populated_snapinfo;
+  populated->pending_update[234] = populated_snapinfo;
   populated->pending_destroy[345].first = 567;
   populated->pending_destroy[345].second = 768;
   populated->pending_noop.insert(890);
index 13669fccd3a21c6853f4c1c37d76fd3e0221fb0f..80ced2b457aded7d29968f69819e84f2b2224d41 100644 (file)
@@ -28,7 +28,7 @@ protected:
   map<snapid_t, SnapInfo> snaps;
   map<int, set<snapid_t> > need_to_purge;
   
-  map<version_t, SnapInfo> pending_create;
+  map<version_t, SnapInfo> pending_update;
   map<version_t, pair<snapid_t,snapid_t> > pending_destroy; // (removed_snap, seq)
   set<version_t>           pending_noop;
 
@@ -44,7 +44,7 @@ public:
     ::encode(last_snap, bl);
     ::encode(snaps, bl);
     ::encode(need_to_purge, bl);
-    ::encode(pending_create, bl);
+    ::encode(pending_update, bl);
     ::encode(pending_destroy, bl);
     ::encode(pending_noop, bl);
     ENCODE_FINISH(bl);
@@ -54,7 +54,7 @@ public:
     ::decode(last_snap, bl);
     ::decode(snaps, bl);
     ::decode(need_to_purge, bl);
-    ::decode(pending_create, bl);
+    ::decode(pending_update, bl);
     if (struct_v >= 2)
       ::decode(pending_destroy, bl);
     else {