From: Dai Zhiwei Date: Fri, 6 May 2022 12:04:15 +0000 (+0800) Subject: rgw: support full object encryption stack on compression X-Git-Tag: v18.1.0~963^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F46188%2Fhead;p=ceph.git rgw: support full object encryption stack on compression add implementation for full object encryption stack on compression. Compressing first and then encrypting. Fixed: https://tracker.ceph.com/issues/19988 Signed-off-by: Dai Zhiwei Signed-off-by: luo rixin --- diff --git a/qa/suites/rgw/crypt/3-rgw/rgw.yaml b/qa/suites/rgw/crypt/3-rgw/rgw.yaml index ee8d62af05c..764d216aade 100644 --- a/qa/suites/rgw/crypt/3-rgw/rgw.yaml +++ b/qa/suites/rgw/crypt/3-rgw/rgw.yaml @@ -6,6 +6,8 @@ overrides: setgroup: ceph rgw crypt require ssl: false debug rgw: 20 + rgw: + compression type: random tasks: - rgw: diff --git a/src/rgw/rgw_compression.cc b/src/rgw/rgw_compression.cc index 8835a8fc554..8306e766a76 100644 --- a/src/rgw/rgw_compression.cc +++ b/src/rgw/rgw_compression.cc @@ -44,6 +44,8 @@ int rgw_compression_info_from_attrset(const map& attrs, int RGWPutObj_Compress::process(bufferlist&& in, uint64_t logical_offset) { bufferlist out; + compressed_ofs = logical_offset; + if (in.length() > 0) { // compression stuff if ((logical_offset > 0 && compressed) || // if previous part was compressed @@ -69,14 +71,20 @@ int RGWPutObj_Compress::process(bufferlist&& in, uint64_t logical_offset) newbl.new_ofs = bs > 0 ? blocks[bs-1].len + blocks[bs-1].new_ofs : 0; newbl.len = out.length(); blocks.push_back(newbl); + + compressed_ofs = newbl.new_ofs; } } else { compressed = false; out = std::move(in); } // end of compression stuff + } else { + size_t bs = blocks.size(); + compressed_ofs = bs > 0 ? blocks[bs-1].len + blocks[bs-1].new_ofs : logical_offset; } - return Pipe::process(std::move(out), logical_offset); + + return Pipe::process(std::move(out), compressed_ofs); } //----------------RGWGetObj_Decompress--------------------- @@ -99,7 +107,7 @@ RGWGetObj_Decompress::RGWGetObj_Decompress(CephContext* cct_, int RGWGetObj_Decompress::handle_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) { ldout(cct, 10) << "Compression for rgw is enabled, decompress part " - << "bl_ofs="<< bl_ofs << ", bl_len=" << bl_len << dendl; + << "bl_ofs=" << bl_ofs << ", bl_len=" << bl_len << dendl; if (!compressor.get()) { // if compressor isn't available - error, because cannot return decompressed data? diff --git a/src/rgw/rgw_compression.h b/src/rgw/rgw_compression.h index bc6511c8673..e558f3bbd8e 100644 --- a/src/rgw/rgw_compression.h +++ b/src/rgw/rgw_compression.h @@ -47,6 +47,7 @@ class RGWPutObj_Compress : public rgw::putobj::Pipe CompressorRef compressor; std::optional compressor_message; std::vector blocks; + uint64_t compressed_ofs{0}; public: RGWPutObj_Compress(CephContext* cct_, CompressorRef compressor, rgw::sal::DataProcessor *next) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index e983be0e5ba..734ea9bfe3f 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2265,6 +2265,10 @@ void RGWGetObj::execute(optional_yield y) goto done_err; total_len = (ofs <= end ? end + 1 - ofs : 0); + ofs_x = ofs; + end_x = end; + filter->fixup_range(ofs_x, end_x); + /* Check whether the object has expired. Swift API documentation * stands that we should return 404 Not Found in such case. */ if (need_object_expiration() && s->object->is_expired()) { @@ -2282,6 +2286,7 @@ void RGWGetObj::execute(optional_yield y) attr_iter != attrs.end() ? &(attr_iter->second) : nullptr); if (decrypt != nullptr) { filter = decrypt.get(); + filter->fixup_range(ofs_x, end_x); } if (op_ret < 0) { goto done_err; @@ -2294,9 +2299,6 @@ void RGWGetObj::execute(optional_yield y) perfcounter->inc(l_rgw_get_b, end - ofs); - ofs_x = ofs; - end_x = end; - filter->fixup_range(ofs_x, end_x); op_ret = read_op->iterate(this, ofs_x, end_x, filter, s->yield); if (op_ret >= 0) @@ -4050,7 +4052,8 @@ void RGWPutObj::execute(optional_yield y) } if (encrypt != nullptr) { filter = &*encrypt; - } else if (compression_type != "none") { + } + if (compression_type != "none") { plugin = get_compressor_plugin(s, compression_type); if (!plugin) { ldpp_dout(this, 1) << "Cannot load plugin for compression type "