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<std::string> keys = {"rgw.torrent"};
+ std::map<std::string, bufferlist> 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<std::string>& keys,
Attrs* vals)
virtual std::unique_ptr<ReadOp> get_read_op() override;
virtual std::unique_ptr<DeleteOp> 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<std::string>& keys,
/** Get a new DeleteOp for this object */
virtual std::unique_ptr<DeleteOp> 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<std::string>& keys,
return std::make_unique<FilterDeleteOp>(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<std::string>& keys,
virtual std::unique_ptr<ReadOp> get_read_op() override;
virtual std::unique_ptr<DeleteOp> 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<std::string>& keys,
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 << ":";