From: zhang Shaowen Date: Fri, 14 Jun 2019 06:40:41 +0000 (+0800) Subject: rgw: lifecycle expiration should check object lock before removing objects indeed X-Git-Tag: v14.2.5~119^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e3736e6aaeb490a1b96324344707c82904f4555b;p=ceph.git rgw: lifecycle expiration should check object lock before removing objects indeed Signed-off-by: zhang Shaowen (cherry picked from commit c45a1b1ad5667a3aa756dcd3b6a15ae2212045f9) --- diff --git a/src/rgw/rgw_lc.cc b/src/rgw/rgw_lc.cc index 6fc0af0ec59c7..9f32275aa8193 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 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& prefix_map) { @@ -717,7 +764,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 5f295d848fe88..5fa74883c3730 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -7541,7 +7541,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; } @@ -7633,7 +7633,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; } @@ -7761,7 +7761,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; }