Skip to content

Commit 8476a02

Browse files
committed
cls/rgw: define lc ops in terms of ObjectOperation instead of IoCtx
clean up the lc functions that were supposed to be hidden by CLS_CLIENT_HIDE_IOCTX this allows rgw to use them asynchonously with rgw_rados_operate() and optional_yield, and warn about blocking calls that should be async Signed-off-by: Casey Bodley <[email protected]>
1 parent 3f11eb9 commit 8476a02

File tree

3 files changed

+128
-82
lines changed

3 files changed

+128
-82
lines changed

src/cls/rgw/cls_rgw_client.cc

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -940,92 +940,90 @@ void cls_rgw_gc_remove(librados::ObjectWriteOperation& op, const vector<string>&
940940
op.exec(RGW_CLASS, RGW_GC_REMOVE, in);
941941
}
942942

943-
int cls_rgw_lc_get_head(IoCtx& io_ctx, const string& oid, cls_rgw_lc_obj_head& head)
943+
void cls_rgw_lc_get_head(ObjectReadOperation& op, bufferlist& out)
944944
{
945-
bufferlist in, out;
946-
int r = io_ctx.exec(oid, RGW_CLASS, RGW_LC_GET_HEAD, in, out);
947-
if (r < 0)
948-
return r;
945+
bufferlist in;
946+
op.exec(RGW_CLASS, RGW_LC_GET_HEAD, in, &out, nullptr);
947+
}
949948

949+
int cls_rgw_lc_get_head_decode(const bufferlist& out, cls_rgw_lc_obj_head& head)
950+
{
950951
cls_rgw_lc_get_head_ret ret;
951952
try {
952953
auto iter = out.cbegin();
953954
decode(ret, iter);
954955
} catch (ceph::buffer::error& err) {
955956
return -EIO;
956957
}
957-
head = ret.head;
958+
head = std::move(ret.head);
958959

959-
return r;
960+
return 0;
960961
}
961962

962-
int cls_rgw_lc_put_head(IoCtx& io_ctx, const string& oid, cls_rgw_lc_obj_head& head)
963+
void cls_rgw_lc_put_head(ObjectWriteOperation& op, const cls_rgw_lc_obj_head& head)
963964
{
964-
bufferlist in, out;
965+
bufferlist in;
965966
cls_rgw_lc_put_head_op call;
966967
call.head = head;
967968
encode(call, in);
968-
int r = io_ctx.exec(oid, RGW_CLASS, RGW_LC_PUT_HEAD, in, out);
969-
return r;
969+
op.exec(RGW_CLASS, RGW_LC_PUT_HEAD, in);
970970
}
971971

972-
int cls_rgw_lc_get_next_entry(IoCtx& io_ctx, const string& oid, const string& marker,
973-
cls_rgw_lc_entry& entry)
972+
void cls_rgw_lc_get_next_entry(ObjectReadOperation& op, const string& marker,
973+
bufferlist& out)
974974
{
975-
bufferlist in, out;
975+
bufferlist in;
976976
cls_rgw_lc_get_next_entry_op call;
977977
call.marker = marker;
978978
encode(call, in);
979-
int r = io_ctx.exec(oid, RGW_CLASS, RGW_LC_GET_NEXT_ENTRY, in, out);
980-
if (r < 0)
981-
return r;
979+
op.exec(RGW_CLASS, RGW_LC_GET_NEXT_ENTRY, in, &out, nullptr);
980+
}
982981

982+
int cls_rgw_lc_get_next_entry_decode(const bufferlist& out, cls_rgw_lc_entry& entry)
983+
{
983984
cls_rgw_lc_get_next_entry_ret ret;
984985
try {
985986
auto iter = out.cbegin();
986987
decode(ret, iter);
987988
} catch (ceph::buffer::error& err) {
988989
return -EIO;
989990
}
990-
entry = ret.entry;
991+
entry = std::move(ret.entry);
991992

992-
return r;
993+
return 0;
993994
}
994995

995-
int cls_rgw_lc_rm_entry(IoCtx& io_ctx, const string& oid,
996-
const cls_rgw_lc_entry& entry)
996+
void cls_rgw_lc_rm_entry(ObjectWriteOperation& op,
997+
const cls_rgw_lc_entry& entry)
997998
{
998-
bufferlist in, out;
999+
bufferlist in;
9991000
cls_rgw_lc_rm_entry_op call;
10001001
call.entry = entry;
10011002
encode(call, in);
1002-
int r = io_ctx.exec(oid, RGW_CLASS, RGW_LC_RM_ENTRY, in, out);
1003-
return r;
1003+
op.exec(RGW_CLASS, RGW_LC_RM_ENTRY, in);
10041004
}
10051005

1006-
int cls_rgw_lc_set_entry(IoCtx& io_ctx, const string& oid,
1007-
const cls_rgw_lc_entry& entry)
1006+
void cls_rgw_lc_set_entry(ObjectWriteOperation& op,
1007+
const cls_rgw_lc_entry& entry)
10081008
{
10091009
bufferlist in, out;
10101010
cls_rgw_lc_set_entry_op call;
10111011
call.entry = entry;
10121012
encode(call, in);
1013-
int r = io_ctx.exec(oid, RGW_CLASS, RGW_LC_SET_ENTRY, in, out);
1014-
return r;
1013+
op.exec(RGW_CLASS, RGW_LC_SET_ENTRY, in);
10151014
}
10161015

1017-
int cls_rgw_lc_get_entry(IoCtx& io_ctx, const string& oid,
1018-
const std::string& marker, cls_rgw_lc_entry& entry)
1016+
void cls_rgw_lc_get_entry(ObjectReadOperation& op, const std::string& marker,
1017+
bufferlist& out)
10191018
{
1020-
bufferlist in, out;
1021-
cls_rgw_lc_get_entry_op call{marker};;
1019+
bufferlist in;
1020+
cls_rgw_lc_get_entry_op call{marker};
10221021
encode(call, in);
1023-
int r = io_ctx.exec(oid, RGW_CLASS, RGW_LC_GET_ENTRY, in, out);
1024-
1025-
if (r < 0) {
1026-
return r;
1027-
}
1022+
op.exec(RGW_CLASS, RGW_LC_GET_ENTRY, in, &out, nullptr);
1023+
}
10281024

1025+
int cls_rgw_lc_get_entry_decode(const bufferlist& out, cls_rgw_lc_entry& entry)
1026+
{
10291027
cls_rgw_lc_get_entry_ret ret;
10301028
try {
10311029
auto iter = out.cbegin();
@@ -1035,28 +1033,24 @@ int cls_rgw_lc_get_entry(IoCtx& io_ctx, const string& oid,
10351033
}
10361034

10371035
entry = std::move(ret.entry);
1038-
return r;
1036+
return 0;
10391037
}
10401038

1041-
int cls_rgw_lc_list(IoCtx& io_ctx, const string& oid,
1042-
const string& marker,
1043-
uint32_t max_entries,
1044-
vector<cls_rgw_lc_entry>& entries)
1039+
void cls_rgw_lc_list(ObjectReadOperation& op, const string& marker,
1040+
uint32_t max_entries, bufferlist& out)
10451041
{
1046-
bufferlist in, out;
1047-
cls_rgw_lc_list_entries_op op;
1048-
1049-
entries.clear();
1050-
1051-
op.marker = marker;
1052-
op.max_entries = max_entries;
1042+
bufferlist in;
1043+
cls_rgw_lc_list_entries_op call;
1044+
call.marker = marker;
1045+
call.max_entries = max_entries;
10531046

1054-
encode(op, in);
1047+
encode(call, in);
10551048

1056-
int r = io_ctx.exec(oid, RGW_CLASS, RGW_LC_LIST_ENTRIES, in, out);
1057-
if (r < 0)
1058-
return r;
1049+
op.exec(RGW_CLASS, RGW_LC_LIST_ENTRIES, in, &out, nullptr);
1050+
}
10591051

1052+
int cls_rgw_lc_list_decode(const bufferlist& out, std::vector<cls_rgw_lc_entry>& entries)
1053+
{
10601054
cls_rgw_lc_list_entries_ret ret;
10611055
try {
10621056
auto iter = out.cbegin();
@@ -1069,7 +1063,7 @@ int cls_rgw_lc_list(IoCtx& io_ctx, const string& oid,
10691063
[](const cls_rgw_lc_entry& a, const cls_rgw_lc_entry& b)
10701064
{ return a.bucket < b.bucket; });
10711065
entries = std::move(ret.entries);
1072-
return r;
1066+
return 0;
10731067
}
10741068

10751069
void cls_rgw_mp_upload_part_info_update(librados::ObjectWriteOperation& op,

src/cls/rgw/cls_rgw_client.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -609,19 +609,19 @@ int cls_rgw_gc_list(librados::IoCtx& io_ctx, std::string& oid, std::string& mark
609609
#endif
610610

611611
/* lifecycle */
612-
// these overloads which call io_ctx.operate() should not be called in the rgw.
613-
// rgw_rados_operate() should be called after the overloads w/o calls to io_ctx.operate()
614-
#ifndef CLS_CLIENT_HIDE_IOCTX
615-
int cls_rgw_lc_get_head(librados::IoCtx& io_ctx, const std::string& oid, cls_rgw_lc_obj_head& head);
616-
int cls_rgw_lc_put_head(librados::IoCtx& io_ctx, const std::string& oid, cls_rgw_lc_obj_head& head);
617-
int cls_rgw_lc_get_next_entry(librados::IoCtx& io_ctx, const std::string& oid, const std::string& marker, cls_rgw_lc_entry& entry);
618-
int cls_rgw_lc_rm_entry(librados::IoCtx& io_ctx, const std::string& oid, const cls_rgw_lc_entry& entry);
619-
int cls_rgw_lc_set_entry(librados::IoCtx& io_ctx, const std::string& oid, const cls_rgw_lc_entry& entry);
620-
int cls_rgw_lc_get_entry(librados::IoCtx& io_ctx, const std::string& oid, const std::string& marker, cls_rgw_lc_entry& entry);
621-
int cls_rgw_lc_list(librados::IoCtx& io_ctx, const std::string& oid,
622-
const std::string& marker, uint32_t max_entries,
623-
std::vector<cls_rgw_lc_entry>& entries);
624-
#endif
612+
void cls_rgw_lc_get_head(librados::ObjectReadOperation& op, bufferlist& bl);
613+
int cls_rgw_lc_get_head_decode(const bufferlist& bl, cls_rgw_lc_obj_head& head);
614+
void cls_rgw_lc_put_head(librados::ObjectWriteOperation& op, const cls_rgw_lc_obj_head& head);
615+
void cls_rgw_lc_get_next_entry(librados::ObjectReadOperation& op, const std::string& marker, bufferlist& bl);
616+
int cls_rgw_lc_get_next_entry_decode(const bufferlist& bl, cls_rgw_lc_entry& entry);
617+
void cls_rgw_lc_rm_entry(librados::ObjectWriteOperation& op, const cls_rgw_lc_entry& entry);
618+
void cls_rgw_lc_set_entry(librados::ObjectWriteOperation& op, const cls_rgw_lc_entry& entry);
619+
void cls_rgw_lc_get_entry(librados::ObjectReadOperation& op, const std::string& marker, bufferlist& bl);
620+
int cls_rgw_lc_get_entry_decode(const bufferlist& bl, cls_rgw_lc_entry& entry);
621+
void cls_rgw_lc_list(librados::ObjectReadOperation& op,
622+
const std::string& marker, uint32_t max_entries,
623+
bufferlist& bl);
624+
int cls_rgw_lc_list_decode(const bufferlist& bl, std::vector<cls_rgw_lc_entry>& entries);
625625

626626
/* multipart */
627627
void cls_rgw_mp_upload_part_info_update(librados::ObjectWriteOperation& op, const std::string& part_key, const RGWUploadPartInfo& info);

src/rgw/driver/rados/rgw_sal_rados.cc

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,10 +3608,21 @@ int RadosLifecycle::get_entry(const DoutPrefixProvider* dpp, optional_yield y,
36083608
const std::string& oid, const std::string& marker,
36093609
std::unique_ptr<LCEntry>* entry)
36103610
{
3611+
librados::ObjectReadOperation op;
3612+
bufferlist bl;
3613+
cls_rgw_lc_get_entry(op, marker, bl);
3614+
3615+
auto& ioctx = *store->getRados()->get_lc_pool_ctx();
3616+
int ret = rgw_rados_operate(dpp, ioctx, oid, &op, nullptr, y);
3617+
if (ret < 0) {
3618+
return ret;
3619+
}
3620+
36113621
cls_rgw_lc_entry cls_entry;
3612-
int ret = cls_rgw_lc_get_entry(*store->getRados()->get_lc_pool_ctx(), oid, marker, cls_entry);
3613-
if (ret)
3622+
ret = cls_rgw_lc_get_entry_decode(bl, cls_entry);
3623+
if (ret < 0) {
36143624
return ret;
3625+
}
36153626

36163627
*entry = std::make_unique<StoreLCEntry>(cls_entry.bucket, cls_entry.start_time, cls_entry.status);
36173628
return 0;
@@ -3621,12 +3632,21 @@ int RadosLifecycle::get_next_entry(const DoutPrefixProvider* dpp, optional_yield
36213632
const std::string& oid, const std::string& marker,
36223633
std::unique_ptr<LCEntry>* entry)
36233634
{
3624-
cls_rgw_lc_entry cls_entry;
3625-
int ret = cls_rgw_lc_get_next_entry(*store->getRados()->get_lc_pool_ctx(), oid, marker,
3626-
cls_entry);
3635+
librados::ObjectReadOperation op;
3636+
bufferlist bl;
3637+
cls_rgw_lc_get_next_entry(op, marker, bl);
36273638

3628-
if (ret)
3639+
auto& ioctx = *store->getRados()->get_lc_pool_ctx();
3640+
int ret = rgw_rados_operate(dpp, ioctx, oid, &op, nullptr, y);
3641+
if (ret < 0) {
36293642
return ret;
3643+
}
3644+
3645+
cls_rgw_lc_entry cls_entry;
3646+
ret = cls_rgw_lc_get_next_entry_decode(bl, cls_entry);
3647+
if (ret < 0) {
3648+
return ret;
3649+
}
36303650

36313651
*entry = std::make_unique<StoreLCEntry>(cls_entry.bucket, cls_entry.start_time, cls_entry.status);
36323652
return 0;
@@ -3641,7 +3661,11 @@ int RadosLifecycle::set_entry(const DoutPrefixProvider* dpp, optional_yield y,
36413661
cls_entry.start_time = entry.get_start_time();
36423662
cls_entry.status = entry.get_status();
36433663

3644-
return cls_rgw_lc_set_entry(*store->getRados()->get_lc_pool_ctx(), oid, cls_entry);
3664+
librados::ObjectWriteOperation op;
3665+
cls_rgw_lc_set_entry(op, cls_entry);
3666+
3667+
auto& ioctx = *store->getRados()->get_lc_pool_ctx();
3668+
return rgw_rados_operate(dpp, ioctx, oid, &op, y);
36453669
}
36463670

36473671
int RadosLifecycle::list_entries(const DoutPrefixProvider* dpp, optional_yield y,
@@ -3650,11 +3674,21 @@ int RadosLifecycle::list_entries(const DoutPrefixProvider* dpp, optional_yield y
36503674
{
36513675
entries.clear();
36523676

3653-
vector<cls_rgw_lc_entry> cls_entries;
3654-
int ret = cls_rgw_lc_list(*store->getRados()->get_lc_pool_ctx(), oid, marker, max_entries, cls_entries);
3677+
librados::ObjectReadOperation op;
3678+
bufferlist bl;
3679+
cls_rgw_lc_list(op, marker, max_entries, bl);
36553680

3656-
if (ret < 0)
3681+
auto& ioctx = *store->getRados()->get_lc_pool_ctx();
3682+
int ret = rgw_rados_operate(dpp, ioctx, oid, &op, nullptr, y);
3683+
if (ret < 0) {
3684+
return ret;
3685+
}
3686+
3687+
vector<cls_rgw_lc_entry> cls_entries;
3688+
ret = cls_rgw_lc_list_decode(bl, cls_entries);
3689+
if (ret < 0) {
36573690
return ret;
3691+
}
36583692

36593693
for (auto& entry : cls_entries) {
36603694
entries.push_back(std::make_unique<StoreLCEntry>(entry.bucket, oid,
@@ -3668,21 +3702,35 @@ int RadosLifecycle::rm_entry(const DoutPrefixProvider* dpp, optional_yield y,
36683702
const std::string& oid, LCEntry& entry)
36693703
{
36703704
cls_rgw_lc_entry cls_entry;
3671-
36723705
cls_entry.bucket = entry.get_bucket();
36733706
cls_entry.start_time = entry.get_start_time();
36743707
cls_entry.status = entry.get_status();
36753708

3676-
return cls_rgw_lc_rm_entry(*store->getRados()->get_lc_pool_ctx(), oid, cls_entry);
3709+
librados::ObjectWriteOperation op;
3710+
cls_rgw_lc_rm_entry(op, cls_entry);
3711+
3712+
auto& ioctx = *store->getRados()->get_lc_pool_ctx();
3713+
return rgw_rados_operate(dpp, ioctx, oid, &op, y);
36773714
}
36783715

36793716
int RadosLifecycle::get_head(const DoutPrefixProvider* dpp, optional_yield y,
36803717
const std::string& oid, std::unique_ptr<LCHead>* head)
36813718
{
3719+
librados::ObjectReadOperation op;
3720+
bufferlist bl;
3721+
cls_rgw_lc_get_head(op, bl);
3722+
3723+
auto& ioctx = *store->getRados()->get_lc_pool_ctx();
3724+
int ret = rgw_rados_operate(dpp, ioctx, oid, &op, nullptr, y);
3725+
if (ret < 0) {
3726+
return ret;
3727+
}
3728+
36823729
cls_rgw_lc_obj_head cls_head;
3683-
int ret = cls_rgw_lc_get_head(*store->getRados()->get_lc_pool_ctx(), oid, cls_head);
3684-
if (ret)
3730+
ret = cls_rgw_lc_get_head_decode(bl, cls_head);
3731+
if (ret < 0) {
36853732
return ret;
3733+
}
36863734

36873735
*head = std::make_unique<StoreLCHead>(cls_head.start_date, cls_head.shard_rollover_date, cls_head.marker);
36883736
return 0;
@@ -3697,7 +3745,11 @@ int RadosLifecycle::put_head(const DoutPrefixProvider* dpp, optional_yield y,
36973745
cls_head.start_date = head.get_start_date();
36983746
cls_head.shard_rollover_date = head.get_shard_rollover_date();
36993747

3700-
return cls_rgw_lc_put_head(*store->getRados()->get_lc_pool_ctx(), oid, cls_head);
3748+
librados::ObjectWriteOperation op;
3749+
cls_rgw_lc_put_head(op, cls_head);
3750+
3751+
auto& ioctx = *store->getRados()->get_lc_pool_ctx();
3752+
return rgw_rados_operate(dpp, ioctx, oid, &op, y);
37013753
}
37023754

37033755
std::unique_ptr<LCSerializer> RadosLifecycle::get_serializer(const std::string& lock_name,

0 commit comments

Comments
 (0)