summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhang Shaowen <zhangshaowen@cmss.chinamobile.com>2019-06-14 08:40:41 +0200
committerzhang Shaowen <zhangshaowen@cmss.chinamobile.com>2019-06-14 08:40:41 +0200
commitc45a1b1ad5667a3aa756dcd3b6a15ae2212045f9 (patch)
treef3209bc10467fe42f72e80d4749316fcbcf0c369
parentrgw: modify iam_policy unit test to support object lock. (diff)
downloadceph-c45a1b1ad5667a3aa756dcd3b6a15ae2212045f9.tar.xz
ceph-c45a1b1ad5667a3aa756dcd3b6a15ae2212045f9.zip
rgw: lifecycle expiration should check object lock before removing objects indeed
Signed-off-by: zhang Shaowen <zhangshaowen@cmss.chinamobile.com>
-rw-r--r--src/rgw/rgw_lc.cc49
-rw-r--r--src/rgw/rgw_op.cc6
2 files changed, 51 insertions, 4 deletions
diff --git a/src/rgw/rgw_lc.cc b/src/rgw/rgw_lc.cc
index e634f055012..b46a3c00f3f 100644
--- a/src/rgw/rgw_lc.cc
+++ b/src/rgw/rgw_lc.cc
@@ -312,6 +312,53 @@ static bool obj_has_expired(CephContext *cct, ceph::real_time mtime, int days, c
return (timediff >= cmp);
}
+static bool pass_object_lock_check(RGWRados *store, RGWBucketInfo& bucket_info, rgw_obj& obj, RGWObjectCtx& ctx)
+{
+ if (!bucket_info.obj_lock_enabled()) {
+ return true;
+ }
+ RGWRados::Object op_target(store, bucket_info, ctx, obj);
+ RGWRados::Object::Read read_op(&op_target);
+ map<string, bufferlist> attrs;
+ read_op.params.attrs = &attrs;
+ int ret = read_op.prepare();
+ if (ret < 0) {
+ if (ret == -ENOENT) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ auto iter = attrs.find(RGW_ATTR_OBJECT_RETENTION);
+ if (iter != attrs.end()) {
+ RGWObjectRetention retention;
+ try {
+ decode(retention, iter->second);
+ } catch (buffer::error& err) {
+ ldout(store->ctx(), 0) << "ERROR: failed to decode RGWObjectRetention" << dendl;
+ return false;
+ }
+ if (ceph::real_clock::to_time_t(retention.get_retain_until_date()) > ceph_clock_now()) {
+ return false;
+ }
+ }
+ iter = attrs.find(RGW_ATTR_OBJECT_LEGAL_HOLD);
+ if (iter != attrs.end()) {
+ RGWObjectLegalHold obj_legal_hold;
+ try {
+ decode(obj_legal_hold, iter->second);
+ } catch (buffer::error& err) {
+ ldout(store->ctx(), 0) << "ERROR: failed to decode RGWObjectLegalHold" << dendl;
+ return false;
+ }
+ if (obj_legal_hold.is_enabled()) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
+
int RGWLC::handle_multipart_expiration(
RGWRados::Bucket *target, const multimap<string, lc_op>& prefix_map)
{
@@ -718,7 +765,7 @@ public:
bool is_expired = obj_has_expired(oc.cct, mtime, expiration, exp_time);
ldout(oc.cct, 20) << __func__ << "(): key=" << o.key << ": is_expired=" << is_expired << dendl;
- return is_expired;
+ return is_expired && pass_object_lock_check(oc.store, oc.bucket_info, oc.obj, oc.rctx);
}
int process(lc_op_ctx& oc) {
diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc
index 063534b98ff..957f7975cb5 100644
--- a/src/rgw/rgw_op.cc
+++ b/src/rgw/rgw_op.cc
@@ -7533,7 +7533,7 @@ void RGWPutBucketObjectLock::execute()
try {
RGWXMLDecoder::decode_xml("ObjectLockConfiguration", obj_lock, &parser, true);
} catch (RGWXMLDecoder::err& err) {
- ldout(s->cct, 5) << "unexpected xml:" << err.message << dendl;
+ ldout(s->cct, 5) << "unexpected xml:" << err << dendl;
op_ret = -ERR_MALFORMED_XML;
return;
}
@@ -7625,7 +7625,7 @@ void RGWPutObjRetention::execute()
try {
RGWXMLDecoder::decode_xml("Retention", obj_retention, &parser, true);
} catch (RGWXMLDecoder::err& err) {
- ldpp_dout(this, 5) << "unexpected xml:" << err.message << dendl;
+ ldpp_dout(this, 5) << "unexpected xml:" << err << dendl;
op_ret = -ERR_MALFORMED_XML;
return;
}
@@ -7753,7 +7753,7 @@ void RGWPutObjLegalHold::execute() {
try {
RGWXMLDecoder::decode_xml("LegalHold", obj_legal_hold, &parser, true);
} catch (RGWXMLDecoder::err &err) {
- ldout(s->cct, 5) << "unexpected xml:" << err.message << dendl;
+ ldout(s->cct, 5) << "unexpected xml:" << err << dendl;
op_ret = -ERR_MALFORMED_XML;
return;
}