]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/cls/rbd/cls_rbd.cc
update sources to v12.1.0
[ceph.git] / ceph / src / cls / rbd / cls_rbd.cc
index c5dc0cf45ebad78383aa423158a3864ce612007f..3eb64a45a5c88bd0b96be5fc7e65dd95c46e57de 100644 (file)
  * parameters as the client sees them - it would be silly to mention
  * in each one that they take an input and an output bufferlist.
  */
-#include "include/int_types.h"
 #include "include/types.h"
 
 #include <algorithm>
-#include <cstring>
-#include <cstdlib>
 #include <errno.h>
-#include <iostream>
-#include <map>
 #include <sstream>
-#include <vector>
 
 #include "common/bit_vector.hpp"
 #include "common/errno.h"
@@ -229,12 +223,15 @@ int create(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
   bufferlist featuresbl;
   bufferlist object_prefixbl;
   bufferlist snap_seqbl;
+  bufferlist create_timestampbl;
   uint64_t snap_seq = 0;
+  utime_t create_timestamp = ceph_clock_now();
   ::encode(size, sizebl);
   ::encode(order, orderbl);
   ::encode(features, featuresbl);
   ::encode(object_prefix, object_prefixbl);
   ::encode(snap_seq, snap_seqbl);
+  ::encode(create_timestamp, create_timestampbl);
 
   map<string, bufferlist> omap_vals;
   omap_vals["size"] = sizebl;
@@ -242,6 +239,7 @@ int create(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
   omap_vals["features"] = featuresbl;
   omap_vals["object_prefix"] = object_prefixbl;
   omap_vals["snap_seq"] = snap_seqbl;
+  omap_vals["create_timestamp"] = create_timestampbl;
 
   if (features & RBD_FEATURE_DATA_POOL) {
     if (data_pool_id == -1) {
@@ -775,6 +773,32 @@ int set_stripe_unit_count(cls_method_context_t hctx, bufferlist *in, bufferlist
   return 0;
 }
 
+int get_create_timestamp(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
+{
+  CLS_LOG(20, "get_create_timestamp");
+
+  utime_t timestamp;
+  bufferlist bl;
+  int r = cls_cxx_map_get_val(hctx, "create_timestamp", &bl);
+  if (r < 0) {
+    if (r != -ENOENT) {
+      CLS_ERR("error reading create_timestamp: %s", cpp_strerror(r).c_str());
+      return r;
+    }
+  } else {
+    try {
+      bufferlist::iterator it = bl.begin();
+      ::decode(timestamp, it);
+    } catch (const buffer::error &err) {
+      CLS_ERR("could not decode create_timestamp");
+      return -EIO;
+    }
+  }
+
+  ::encode(timestamp, *out);
+  return 0;
+}
+
 /**
  * get the image flags
  *
@@ -5085,6 +5109,7 @@ CLS_INIT(rbd)
   cls_method_handle_t h_set_protection_status;
   cls_method_handle_t h_get_stripe_unit_count;
   cls_method_handle_t h_set_stripe_unit_count;
+  cls_method_handle_t h_get_create_timestamp;
   cls_method_handle_t h_get_flags;
   cls_method_handle_t h_set_flags;
   cls_method_handle_t h_remove_parent;
@@ -5233,6 +5258,9 @@ CLS_INIT(rbd)
   cls_register_cxx_method(h_class, "set_stripe_unit_count",
                          CLS_METHOD_RD | CLS_METHOD_WR,
                          set_stripe_unit_count, &h_set_stripe_unit_count);
+  cls_register_cxx_method(h_class, "get_create_timestamp",
+                          CLS_METHOD_RD,
+                          get_create_timestamp, &h_get_create_timestamp);
   cls_register_cxx_method(h_class, "get_flags",
                           CLS_METHOD_RD,
                           get_flags, &h_get_flags);