From: Casey Bodley Date: Sun, 19 Feb 2023 15:44:51 +0000 (-0500) Subject: rgw/sal: add Object::get_torrent_info() X-Git-Tag: v19.0.0~1568^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2419880f0c721d08b8df2b9d9bf7785243dafbfc;p=ceph.git rgw/sal: add Object::get_torrent_info() although torrent info is moving into RGW_ATTR_TORRENT, we'll still need to support the rados backend's omap fallback.. forever. expose a new Object API specifically for torrent info so we can remove all of the omap-specific ones Signed-off-by: Casey Bodley --- diff --git a/src/rgw/driver/rados/rgw_sal_rados.cc b/src/rgw/driver/rados/rgw_sal_rados.cc index fb34ae25aa8f..57658558d8b7 100644 --- a/src/rgw/driver/rados/rgw_sal_rados.cc +++ b/src/rgw/driver/rados/rgw_sal_rados.cc @@ -1835,6 +1835,42 @@ void RadosObject::get_raw_obj(rgw_raw_obj* raw_obj) store->getRados()->obj_to_raw((bucket->get_info()).placement_rule, get_obj(), raw_obj); } +int RadosObject::get_torrent_info(const DoutPrefixProvider* dpp, + optional_yield y, bufferlist& bl) +{ + // try to read torrent info from attr + int ret = StoreObject::get_torrent_info(dpp, y, bl); + if (ret >= 0) { + return ret; + } + + // try falling back to old torrent info stored in omap + rgw_raw_obj raw_obj; + get_raw_obj(&raw_obj); + + rgw_rados_ref ref; + ret = store->getRados()->get_raw_obj_ref(dpp, raw_obj, &ref); + if (ret < 0) { + return ret; + } + + const std::set keys = {"rgw.torrent"}; + std::map result; + + librados::ObjectReadOperation op; + op.omap_get_vals_by_keys(keys, &result, nullptr); + + ret = rgw_rados_operate(dpp, ref.pool.ioctx(), ref.obj.oid, &op, nullptr, y); + if (ret < 0) { + return ret; + } + if (result.empty()) { // omap key not found + return -ENOENT; + } + bl = std::move(result.begin()->second); + return 0; +} + int RadosObject::omap_get_vals_by_keys(const DoutPrefixProvider *dpp, const std::string& oid, const std::set& keys, Attrs* vals) diff --git a/src/rgw/driver/rados/rgw_sal_rados.h b/src/rgw/driver/rados/rgw_sal_rados.h index 73be3efb6950..917addaa442e 100644 --- a/src/rgw/driver/rados/rgw_sal_rados.h +++ b/src/rgw/driver/rados/rgw_sal_rados.h @@ -460,6 +460,9 @@ class RadosObject : public StoreObject { virtual std::unique_ptr get_read_op() override; virtual std::unique_ptr get_delete_op() override; + virtual int get_torrent_info(const DoutPrefixProvider* dpp, + optional_yield y, bufferlist& bl) override; + /* OMAP */ virtual int omap_get_vals_by_keys(const DoutPrefixProvider *dpp, const std::string& oid, const std::set& keys, diff --git a/src/rgw/rgw_sal.h b/src/rgw/rgw_sal.h index 037806d6854a..0af1c24d5b31 100644 --- a/src/rgw/rgw_sal.h +++ b/src/rgw/rgw_sal.h @@ -1078,7 +1078,10 @@ class Object { /** Get a new DeleteOp for this object */ virtual std::unique_ptr get_delete_op() = 0; - // TODO: remove omap APIs. rgw_torrent.cc shouldn't use omap + /// Return stored torrent info or -ENOENT if there isn't any. + virtual int get_torrent_info(const DoutPrefixProvider* dpp, + optional_yield y, bufferlist& bl) = 0; + /** Get the OMAP values matching the given set of keys */ virtual int omap_get_vals_by_keys(const DoutPrefixProvider *dpp, const std::string& oid, const std::set& keys, diff --git a/src/rgw/rgw_sal_filter.cc b/src/rgw/rgw_sal_filter.cc index b57c664e2ea0..18c8a8bdaea8 100644 --- a/src/rgw/rgw_sal_filter.cc +++ b/src/rgw/rgw_sal_filter.cc @@ -1007,6 +1007,12 @@ std::unique_ptr FilterObject::get_delete_op() return std::make_unique(std::move(d)); } +int FilterObject::get_torrent_info(const DoutPrefixProvider* dpp, + optional_yield y, bufferlist& bl) +{ + return next->get_torrent_info(dpp, y, bl); +} + int FilterObject::omap_get_vals_by_keys(const DoutPrefixProvider *dpp, const std::string& oid, const std::set& keys, diff --git a/src/rgw/rgw_sal_filter.h b/src/rgw/rgw_sal_filter.h index 340f52ad1ef5..6260f3acae37 100644 --- a/src/rgw/rgw_sal_filter.h +++ b/src/rgw/rgw_sal_filter.h @@ -670,6 +670,9 @@ public: virtual std::unique_ptr get_read_op() override; virtual std::unique_ptr get_delete_op() override; + virtual int get_torrent_info(const DoutPrefixProvider* dpp, + optional_yield y, bufferlist& bl) override; + virtual int omap_get_vals_by_keys(const DoutPrefixProvider *dpp, const std::string& oid, const std::set& keys, diff --git a/src/rgw/rgw_sal_store.h b/src/rgw/rgw_sal_store.h index 55b43e3d90bd..e4822a6cb6e5 100644 --- a/src/rgw/rgw_sal_store.h +++ b/src/rgw/rgw_sal_store.h @@ -241,6 +241,16 @@ class StoreObject : public Object { return -1; } + virtual int get_torrent_info(const DoutPrefixProvider* dpp, + optional_yield y, bufferlist& bl) override { + const auto& attrs = get_attrs(); + if (auto i = attrs.find(RGW_ATTR_TORRENT); i != attrs.end()) { + bl = i->second; + return 0; + } + return -ENOENT; + } + virtual void print(std::ostream& out) const override { if (bucket) out << bucket << ":";