summaryrefslogtreecommitdiffstats
path: root/src/cls/rbd/cls_rbd_client.cc
diff options
context:
space:
mode:
authorJulien Collet <julien.collet@cern.ch>2018-02-20 10:14:00 +0100
committerJason Dillaman <dillaman@redhat.com>2018-08-21 22:17:17 +0200
commit809c5430c2929ea1b33d3d1ab7c0023fbb2ce7a5 (patch)
tree7d11af46ef75621e0674697c479e31f4b7f15888 /src/cls/rbd/cls_rbd_client.cc
parentMerge pull request #23649 from trociny/wip-26939 (diff)
downloadceph-809c5430c2929ea1b33d3d1ab7c0023fbb2ce7a5.tar.xz
ceph-809c5430c2929ea1b33d3d1ab7c0023fbb2ce7a5.zip
librbd: add image access/last modified timestamps
Add access and modify timestamps and associated tests to RBD images. Access (resp. modify) timestamps are updated on read (resp. write) operations. A configurable throttling mechanism is implemented (default to 60s). Signed-off-by: Julien Collet <julien.collet@cern.ch>
Diffstat (limited to 'src/cls/rbd/cls_rbd_client.cc')
-rw-r--r--src/cls/rbd/cls_rbd_client.cc92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/cls/rbd/cls_rbd_client.cc b/src/cls/rbd/cls_rbd_client.cc
index 087ed597b23..88317f893bc 100644
--- a/src/cls/rbd/cls_rbd_client.cc
+++ b/src/cls/rbd/cls_rbd_client.cc
@@ -1065,6 +1065,32 @@ namespace librbd {
return ioctx->operate(oid, &op);
}
+ void set_modify_timestamp(librados::ObjectWriteOperation *op)
+ {
+ bufferlist empty_bl;
+ op->exec("rbd","set_modify_timestamp",empty_bl);
+ }
+
+ int set_modify_timestamp(librados::IoCtx *ioctx, const std::string &oid)
+ {
+ librados::ObjectWriteOperation op;
+ set_modify_timestamp(&op);
+ return ioctx->operate(oid, &op);
+ }
+
+ void set_access_timestamp(librados::ObjectWriteOperation *op)
+ {
+ bufferlist empty_bl;
+ op->exec("rbd","set_access_timestamp",empty_bl);
+ }
+
+ int set_access_timestamp(librados::IoCtx *ioctx, const std::string &oid)
+ {
+ librados::ObjectWriteOperation op;
+ set_access_timestamp(&op);
+ return ioctx->operate(oid, &op);
+ }
+
void get_create_timestamp_start(librados::ObjectReadOperation *op) {
bufferlist empty_bl;
op->exec("rbd", "get_create_timestamp", empty_bl);
@@ -1098,6 +1124,72 @@ namespace librbd {
return get_create_timestamp_finish(&it, timestamp);
}
+ void get_access_timestamp_start(librados::ObjectReadOperation *op) {
+ bufferlist empty_bl;
+ op->exec("rbd", "get_access_timestamp", empty_bl);
+ }
+
+ int get_access_timestamp_finish(bufferlist::const_iterator *it,
+ utime_t *timestamp) {
+ assert(timestamp);
+
+ try {
+ decode(*timestamp, *it);
+ } catch (const buffer::error &err) {
+ return -EBADMSG;
+ }
+ return 0;
+ }
+
+ int get_access_timestamp(librados::IoCtx *ioctx, const std::string &oid,
+ utime_t *timestamp)
+ {
+ librados::ObjectReadOperation op;
+ get_access_timestamp_start(&op);
+
+ bufferlist out_bl;
+ int r = ioctx->operate(oid, &op, &out_bl);
+ if (r < 0) {
+ return r;
+ }
+
+ auto it = out_bl.cbegin();
+ return get_access_timestamp_finish(&it, timestamp);
+ }
+
+ void get_modify_timestamp_start(librados::ObjectReadOperation *op) {
+ bufferlist empty_bl;
+ op->exec("rbd", "get_modify_timestamp", empty_bl);
+ }
+
+ int get_modify_timestamp_finish(bufferlist::const_iterator *it,
+ utime_t *timestamp) {
+ assert(timestamp);
+
+ try {
+ decode(*timestamp, *it);
+ } catch (const buffer::error &err) {
+ return -EBADMSG;
+ }
+ return 0;
+ }
+
+ int get_modify_timestamp(librados::IoCtx *ioctx, const std::string &oid,
+ utime_t *timestamp)
+ {
+ librados::ObjectReadOperation op;
+ get_modify_timestamp_start(&op);
+
+ bufferlist out_bl;
+ int r = ioctx->operate(oid, &op, &out_bl);
+ if (r < 0) {
+ return r;
+ }
+
+ auto it = out_bl.cbegin();
+ return get_modify_timestamp_finish(&it, timestamp);
+ }
+
/************************ rbd_id object methods ************************/
void get_id_start(librados::ObjectReadOperation *op) {