]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: Add timestamp metadata when creating rbd snapshot
authorPan Liu <pan.liu@istuary.com>
Fri, 27 Jan 2017 11:14:29 +0000 (19:14 +0800)
committerPan Liu <pan.liu@istuary.com>
Mon, 30 Jan 2017 19:18:14 +0000 (03:18 +0800)
Signed-off-by: Pan Liu <pan.liu@istuary.com>
src/cls/rbd/cls_rbd.cc
src/cls/rbd/cls_rbd.h
src/librbd/ImageCtx.cc
src/librbd/ImageCtx.h
src/librbd/operation/SnapshotCreateRequest.cc
src/test/librbd/image/test_mock_RefreshRequest.cc
src/test/librbd/mock/MockImageCtx.h
src/test/librbd/object_map/test_mock_SnapshotCreateRequest.cc
src/test/librbd/operation/test_mock_SnapshotCreateRequest.cc
src/test/rbd_mirror/image_replayer/test_mock_EventPreprocessor.cc

index 22fd7577b364af6926d963c1b69ed1fb66e563bc..8f86ca13f9713e530e0426fb3f55683c3e6a15b2 100644 (file)
@@ -1567,6 +1567,8 @@ int snapshot_add(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
     return r;
   }
 
+  snap_meta.timestamp = ceph_clock_now();
+
   int max_read = RBD_MAX_KEYS_READ;
   uint64_t total_read = 0;
   string last_read = RBD_SNAP_KEY_PREFIX;
index 8c0a05336300cf7c5c9f039400903e45916afe74..88f0bbccd93e1a6f2b88f7f3a4b1cca06f409a39 100644 (file)
@@ -65,6 +65,7 @@ struct cls_rbd_snap {
   uint8_t protection_status;
   cls_rbd_parent parent;
   uint64_t flags;
+  utime_t timestamp;
   cls::rbd::SnapshotNamespaceOnDisk snapshot_namespace;
 
   /// true if we have a parent
@@ -74,10 +75,10 @@ struct cls_rbd_snap {
 
   cls_rbd_snap() : id(CEPH_NOSNAP), image_size(0), features(0),
                   protection_status(RBD_PROTECTION_STATUS_UNPROTECTED),
-                   flags(0)
+                   flags(0), timestamp(utime_t())
     {}
   void encode(bufferlist& bl) const {
-    ENCODE_START(5, 1, bl);
+    ENCODE_START(6, 1, bl);
     ::encode(id, bl);
     ::encode(name, bl);
     ::encode(image_size, bl);
@@ -86,10 +87,11 @@ struct cls_rbd_snap {
     ::encode(protection_status, bl);
     ::encode(flags, bl);
     ::encode(snapshot_namespace, bl);
+    ::encode(timestamp, bl);
     ENCODE_FINISH(bl);
   }
   void decode(bufferlist::iterator& p) {
-    DECODE_START(5, p);
+    DECODE_START(6, p);
     ::decode(id, p);
     ::decode(name, p);
     ::decode(image_size, p);
@@ -108,6 +110,9 @@ struct cls_rbd_snap {
     } else {
       snapshot_namespace = cls::rbd::SnapshotNamespaceOnDisk(cls::rbd::UserSnapshotNamespace());
     }
+    if (struct_v >= 6) {
+      ::decode(timestamp, p);
+    }
     DECODE_FINISH(p);
   }
   void dump(Formatter *f) const {
@@ -154,6 +159,7 @@ struct cls_rbd_snap {
     t->parent.overlap = 12345;
     t->protection_status = RBD_PROTECTION_STATUS_PROTECTED;
     t->flags = 14;
+    t->timestamp = utime_t();
     o.push_back(t);
   }
 };
index 258ccab56f6bfca7edbd0eadd705fb91ea9e452a..bc3132a912fe0169df0eaf9e8cbbde93b1a19216 100644 (file)
@@ -545,12 +545,12 @@ struct C_InvalidateCache : public Context {
                          cls::rbd::SnapshotNamespace in_snap_namespace,
                          snap_t id, uint64_t in_size,
                          parent_info parent, uint8_t protection_status,
-                          uint64_t flags)
+                          uint64_t flags, utime_t timestamp)
   {
     assert(snap_lock.is_wlocked());
     snaps.push_back(id);
     SnapInfo info(in_snap_name, in_snap_namespace,
-                 in_size, parent, protection_status, flags);
+                 in_size, parent, protection_status, flags, timestamp);
     snap_info.insert(pair<snap_t, SnapInfo>(id, info));
     snap_ids.insert(pair<string, snap_t>(in_snap_name, id));
   }
index dfa134c18f273b2c551f94df9a19b323da728d77..f8c5b0c4288a7a73e46e9b615182e359d24f28dd 100644 (file)
@@ -251,7 +251,7 @@ namespace librbd {
                  cls::rbd::SnapshotNamespace in_snap_namespace,
                  librados::snap_t id,
                  uint64_t in_size, parent_info parent,
-                  uint8_t protection_status, uint64_t flags);
+                 uint8_t protection_status, uint64_t flags, utime_t timestamp);
     void rm_snap(std::string in_snap_name, librados::snap_t id);
     uint64_t get_image_size(librados::snap_t in_snap_id) const;
     uint64_t get_object_count(librados::snap_t in_snap_id) const;
index 36888d748170f74137bf97f4d3a74ff2fb52475e..ce816bb71cf4eb6ce6962f330cacbbcf10f94c18 100644 (file)
@@ -294,8 +294,9 @@ void SnapshotCreateRequest<I>::update_snap_context() {
          image_ctx.exclusive_lock->is_lock_owner());
 
   // immediately add a reference to the new snapshot
+  utime_t snap_time = ceph_clock_now();
   image_ctx.add_snap(m_snap_name, m_snap_namespace, m_snap_id, m_size, m_parent_info,
-                     RBD_PROTECTION_STATUS_UNPROTECTED, 0);
+                     RBD_PROTECTION_STATUS_UNPROTECTED, 0, snap_time);
 
   // immediately start using the new snap context if we
   // own the exclusive lock
index 6978fa950ea8da9509732bc94aa2e47f17f52479..5f96ddb90e9ccf7a1a56c449f862c38753138fcf 100644 (file)
@@ -210,7 +210,7 @@ public:
 
   void expect_add_snap(MockRefreshImageCtx &mock_image_ctx,
                        const std::string &snap_name, uint64_t snap_id) {
-    EXPECT_CALL(mock_image_ctx, add_snap(snap_name, _, snap_id, _, _, _, _));
+    EXPECT_CALL(mock_image_ctx, add_snap(snap_name, _, snap_id, _, _, _, _, _));
   }
 
   void expect_init_exclusive_lock(MockRefreshImageCtx &mock_image_ctx,
index 2a4e6c8b03285c4a8f37890a027ede5e9367ae84..b7983facb08a9d1f10a6391d295d3161f01d49ee 100644 (file)
@@ -151,11 +151,11 @@ struct MockImageCtx {
   MOCK_CONST_METHOD2(is_snap_unprotected, int(librados::snap_t in_snap_id,
                                               bool *is_unprotected));
 
-  MOCK_METHOD7(add_snap, void(std::string in_snap_name,
+  MOCK_METHOD8(add_snap, void(std::string in_snap_name,
                              cls::rbd::SnapshotNamespace in_snap_namespace,
                              librados::snap_t id,
-                              uint64_t in_size, parent_info parent,
-                              uint8_t protection_status, uint64_t flags));
+                             uint64_t in_size, parent_info parent,
+                             uint8_t protection_status, uint64_t flags, utime_t timestamp));
   MOCK_METHOD2(rm_snap, void(std::string in_snap_name, librados::snap_t id));
 
   MOCK_METHOD0(user_flushed, void());
index 00f5b8bfe37ddceb88bc6f3ade563a02082eef88..7280aef4da87e05928bbdd876bc813693f8f3815 100644 (file)
@@ -28,7 +28,7 @@ public:
     ictx->add_snap("snap name",
          cls::rbd::UserSnapshotNamespace(), snap_id,
                   ictx->size, ictx->parent_md,
-                   RBD_PROTECTION_STATUS_UNPROTECTED, 0);
+                   RBD_PROTECTION_STATUS_UNPROTECTED, 0, utime_t());
   }
 
   void expect_read_map(librbd::ImageCtx *ictx, int r) {
index ceb21835c61bcc4518f983f3de6808fe45c73f16..dada4a552b712fedeaf2c8334a5063edabc1ca82 100644 (file)
@@ -89,7 +89,7 @@ public:
     // state machine checks to ensure a refresh hasn't already added the snap
     EXPECT_CALL(mock_image_ctx, get_snap_info(_))
                   .WillOnce(Return(static_cast<const librbd::SnapInfo*>(NULL)));
-    EXPECT_CALL(mock_image_ctx, add_snap("snap1", _, _, _, _, _, _));
+    EXPECT_CALL(mock_image_ctx, add_snap("snap1", _, _, _, _, _, _, _));
   }
 
   void expect_unblock_writes(MockImageCtx &mock_image_ctx) {
index 7dd96f95871f7ce888780ad7343d4fc5d8285399..0ef282003b6e0635d038c1a82d4e5507f1984de8 100644 (file)
@@ -120,7 +120,7 @@ TEST_F(TestMockImageReplayerEventPreprocessor, PreprocessSnapMapPrune) {
   expect_update_client(mock_remote_journaler, 0);
 
   mock_local_image_ctx.snap_info = {
-    {6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U}}};
+    {6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U, utime_t()}}};
   m_client_meta.snap_seqs = {{1, 2}, {3, 4}, {5, 6}};
   MockEventPreprocessor event_preprocessor(mock_local_image_ctx,
                                            mock_remote_journaler,
@@ -146,7 +146,7 @@ TEST_F(TestMockImageReplayerEventPreprocessor, PreprocessSnapRename) {
 
   mock_local_image_ctx.snap_ids = {{"snap", 6}};
   mock_local_image_ctx.snap_info = {
-    {6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U}}};
+    {6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U, utime_t()}}};
   MockEventPreprocessor event_preprocessor(mock_local_image_ctx,
                                            mock_remote_journaler,
                                            "local mirror uuid",
@@ -197,7 +197,7 @@ TEST_F(TestMockImageReplayerEventPreprocessor, PreprocessSnapRenameKnown) {
   expect_image_refresh(mock_local_image_ctx, 0);
 
   mock_local_image_ctx.snap_info = {
-    {6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U}}};
+    {6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U, utime_t()}}};
   m_client_meta.snap_seqs = {{5, 6}};
   MockEventPreprocessor event_preprocessor(mock_local_image_ctx,
                                            mock_remote_journaler,
@@ -246,7 +246,7 @@ TEST_F(TestMockImageReplayerEventPreprocessor, PreprocessClientUpdateError) {
 
   mock_local_image_ctx.snap_ids = {{"snap", 6}};
   mock_local_image_ctx.snap_info = {
-    {6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U}}};
+    {6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U, utime_t()}}};
   MockEventPreprocessor event_preprocessor(mock_local_image_ctx,
                                            mock_remote_journaler,
                                            "local mirror uuid",