From 595c31f390fda700e6e346c208849d23c74bdf5f Mon Sep 17 00:00:00 2001 From: Jing Wenjun Date: Fri, 24 Feb 2017 04:45:04 +0800 Subject: [PATCH] rgw: add the remove-x-delete feature to cancel swift object expiration In openstack swift, it also support the feature to cancel the object expiration, which could be found at last point in https://docs.openstack.org/user-guide/cli-swift-set-object-expiration.html. we can remove the object expiration by set 'X-Remove-Delete-At:'. This patch also could fix the bug that when we set the object expiration and then upload the same object to the container again. The previous object expiration also works, which is not compatible with the openstack swift. Fixes: http://tracker.ceph.com/issues/19074 Signed-off-by: Jing Wenjun (cherry picked from commit 230429ebc4ac9b5840bb93c7e0eeb5edbb949106) --- src/rgw/rgw_file.cc | 4 ++-- src/rgw/rgw_op.cc | 9 +++++---- src/rgw/rgw_op.h | 16 ++++++++-------- src/rgw/rgw_rados.cc | 2 ++ src/rgw/rgw_rest_swift.cc | 18 ++++++++++++------ 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index e2a39dff59cbf..c5d0b7acc69df 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -1069,8 +1069,8 @@ namespace rgw { emplace_attr(RGW_ATTR_SLO_UINDICATOR, std::move(slo_userindicator_bl)); } - op_ret = processor->complete(s->obj_size, etag, &mtime, real_time(), attrs, delete_at, - if_match, if_nomatch); + op_ret = processor->complete(s->obj_size, etag, &mtime, real_time(), attrs, + (delete_at ? *delete_at : real_time()), if_match, if_nomatch); if (! op_ret) { /* update stats */ rgw_fh->set_mtime(real_clock::to_timespec(mtime)); diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index fd10cfcb73979..aaf24fd80e6eb 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1318,7 +1318,7 @@ static bool object_is_expired(map& attrs) { return false; } - if (delete_at <= ceph_clock_now()) { + if (delete_at <= ceph_clock_now() && !delete_at.is_zero()) { return true; } } @@ -3170,7 +3170,7 @@ void RGWPutObj::execute() } op_ret = processor->complete(s->obj_size, etag, &mtime, real_time(), attrs, - delete_at, if_match, if_nomatch); + (delete_at ? *delete_at : real_time()), if_match, if_nomatch); /* produce torrent */ if (s->cct->_conf->rgw_torrent_flag && (ofs == torrent.get_data_len())) @@ -3341,7 +3341,8 @@ void RGWPostObj::execute() emplace_attr(RGW_ATTR_COMPRESSION, std::move(tmp)); } - op_ret = processor.complete(s->obj_size, etag, NULL, real_time(), attrs, delete_at); + op_ret = processor.complete(s->obj_size, etag, NULL, real_time(), attrs, + (delete_at ? *delete_at : real_time())); } @@ -4005,7 +4006,7 @@ void RGWCopyObj::execute() copy_if_newer, attrs, RGW_OBJ_CATEGORY_MAIN, olh_epoch, - delete_at, + (delete_at ? *delete_at : real_time()), (version_id.empty() ? NULL : &version_id), &s->req_id, /* use req_id as tag */ &etag, diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 44a693c10bb80..ebfb7a5a0bd9e 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -720,7 +720,7 @@ class RGWPutObj : public RGWOp { string version_id; bufferlist bl_aux; - ceph::real_time delete_at; + boost::optional delete_at; public: RGWPutObj() : ofs(0), @@ -798,7 +798,7 @@ class RGWPostObj : public RGWOp { string content_type; RGWAccessControlPolicy policy; map attrs; - ceph::real_time delete_at; + boost::optional delete_at; public: RGWPostObj() : min_len(0), @@ -908,7 +908,7 @@ class RGWPutMetadataObject : public RGWOp { protected: RGWAccessControlPolicy policy; string placement_rule; - ceph::real_time delete_at; + boost::optional delete_at; const char *dlo_manifest; public: @@ -998,7 +998,7 @@ class RGWCopyObj : public RGWOp { string version_id; uint64_t olh_epoch; - ceph::real_time delete_at; + boost::optional delete_at; bool copy_if_newer; int init_common(); @@ -1701,15 +1701,15 @@ static inline void rgw_get_request_metadata(CephContext *cct, } } /* rgw_get_request_metadata */ -static inline void encode_delete_at_attr(ceph::real_time delete_at, +static inline void encode_delete_at_attr(boost::optional delete_at, map& attrs) { - if (real_clock::is_zero(delete_at)) { + if (delete_at == boost::none) { return; - } + } bufferlist delatbl; - ::encode(delete_at, delatbl); + ::encode(*delete_at, delatbl); attrs[RGW_ATTR_DELETE_AT] = delatbl; } /* encode_delete_at_attr */ diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 47f3790b3313f..1d97072ce9ed8 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -8250,6 +8250,8 @@ int RGWRados::Object::Delete::delete_obj() if (params.expiration_time != delete_at) { return -ERR_PRECONDITION_FAILED; } + } else { + return -ERR_PRECONDITION_FAILED; } } diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index 2ce570306bb95..a86f849622987 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -663,7 +663,7 @@ void RGWDeleteBucket_ObjStore_SWIFT::send_response() rgw_flush_formatter_and_reset(s, s->formatter); } -static int get_delete_at_param(req_state *s, real_time *delete_at) +static int get_delete_at_param(req_state *s, boost::optional &delete_at) { /* Handle Swift object expiration. */ real_time delat_proposal; @@ -678,6 +678,10 @@ static int get_delete_at_param(req_state *s, real_time *delete_at) } if (x_delete.empty()) { + delete_at = boost::none; + if (s->info.env->exists("HTTP_X_REMOVE_DELETE_AT")) { + delete_at = boost::in_place(real_time()); + } return 0; } string err; @@ -692,7 +696,7 @@ static int get_delete_at_param(req_state *s, real_time *delete_at) return -EINVAL; } - *delete_at = delat_proposal; + delete_at = delat_proposal; return 0; } @@ -746,7 +750,7 @@ int RGWPutObj_ObjStore_SWIFT::get_params() policy.create_default(s->user->user_id, s->user->display_name); - int r = get_delete_at_param(s, &delete_at); + int r = get_delete_at_param(s, delete_at); if (r < 0) { ldout(s->cct, 5) << "ERROR: failed to get Delete-At param" << dendl; return r; @@ -919,7 +923,7 @@ int RGWPutMetadataObject_ObjStore_SWIFT::get_params() } /* Handle Swift object expiration. */ - int r = get_delete_at_param(s, &delete_at); + int r = get_delete_at_param(s, delete_at); if (r < 0) { ldout(s->cct, 5) << "ERROR: failed to get Delete-At param" << dendl; return r; @@ -1118,7 +1122,9 @@ static void dump_object_metadata(struct req_state * const s, utime_t delete_at; try { ::decode(delete_at, iter->second); - dump_header(s, "X-Delete-At", delete_at.sec()); + if (!delete_at.is_zero()) { + dump_header(s, "X-Delete-At", delete_at.sec()); + } } catch (buffer::error& err) { ldout(s->cct, 0) << "ERROR: cannot decode object's " RGW_ATTR_DELETE_AT " attr, ignoring" @@ -1155,7 +1161,7 @@ int RGWCopyObj_ObjStore_SWIFT::get_params() attrs_mod = RGWRados::ATTRSMOD_MERGE; } - int r = get_delete_at_param(s, &delete_at); + int r = get_delete_at_param(s, delete_at); if (r < 0) { ldout(s->cct, 5) << "ERROR: failed to get Delete-At param" << dendl; return r;