From afe1eaa3c17c4e61dee2b6411724d369ef193f47 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 31 Jan 2012 13:47:13 -0800 Subject: rados tool: add expire/unexpire commands expire sets in how many seconds (in the future) object may be expired. Unexpire removes the expiration that was set on the object. Signed-off-by: Yehuda Sadeh --- src/rados.cc | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/rados.cc') diff --git a/src/rados.cc b/src/rados.cc index 6b8b411a63e..d33c6b1f484 100644 --- a/src/rados.cc +++ b/src/rados.cc @@ -63,6 +63,8 @@ void usage(ostream& out) " put [infile] write object\n" " create [category] create object\n" " rm remove object\n" +" expire set expiration time (from now) on an object\n" +" unexpire unset object expiration\n" " listxattr \n" " getxattr attr\n" " setxattr attr val\n" @@ -1043,7 +1045,38 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, return 1; } } - else if (strcmp(nargs[0], "create") == 0) { + else if (strcmp(nargs[0], "expire") == 0) { + if (!pool_name || nargs.size() < 3) + usage_exit(); + string oid(nargs[1]); + long long seconds = strtoll(nargs[2], NULL, 10); + int err = errno; + if (err) { + cerr << "bad expiration time, errno=" << err << std::endl; + return 1; + } + utime_t t = ceph_clock_now(g_ceph_context); + t += seconds; + + ret = io_ctx.set_expiration(oid, t); + if (ret < 0) { + cerr << "error expiring " << pool_name << "/" << oid << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl; + return 1; + } + } + else if (strcmp(nargs[0], "unexpire") == 0) { + if (!pool_name || nargs.size() < 2) + usage_exit(); + string oid(nargs[1]); + utime_t t(0, 0); + + ret = io_ctx.set_expiration(oid, t); + if (ret < 0) { + cerr << "error removing expiration from " << pool_name << "/" << oid << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl; + return 1; + } + } + else if (strcmp(nargs[0], "create") == 0) { if (!pool_name || nargs.size() < 2) usage_exit(); string oid(nargs[1]); -- cgit v1.2.1