Skip to content

Commit 514eb89

Browse files
authored
Merge pull request ceph#45810 from zenomri/wip-rgw-lua-bucketname
rgw: support bucket name in lua pre request execution
2 parents 2c12dbb + cd97a30 commit 514eb89

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

doc/radosgw/lua-scripting.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,27 +140,27 @@ Request Fields
140140
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
141141
| ``Request.SwiftAccountName`` | string | swift account name | no | no | yes |
142142
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
143-
| ``Request.Bucket`` | table | info on the bucket | no | no | yes |
143+
| ``Request.Bucket`` | table | info on the bucket | no | no | no |
144144
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
145-
| ``Request.Bucket.Tenant`` | string | tenant of the bucket | no | no | no |
145+
| ``Request.Bucket.Tenant`` | string | tenant of the bucket | no | no | yes |
146146
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
147147
| ``Request.Bucket.Name`` | string | bucket name | no | no | no |
148148
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
149-
| ``Request.Bucket.Marker`` | string | bucket marker (initial id) | no | no | no |
149+
| ``Request.Bucket.Marker`` | string | bucket marker (initial id) | no | no | yes |
150150
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
151-
| ``Request.Bucket.Id`` | string | bucket id | no | no | no |
151+
| ``Request.Bucket.Id`` | string | bucket id | no | no | yes |
152152
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
153-
| ``Request.Bucket.Count`` | integer | number of objects in the bucket | no | no | no |
153+
| ``Request.Bucket.Count`` | integer | number of objects in the bucket | no | no | yes |
154154
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
155-
| ``Request.Bucket.Size`` | integer | total size of objects in the bucket | no | no | no |
155+
| ``Request.Bucket.Size`` | integer | total size of objects in the bucket | no | no | yes |
156156
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
157-
| ``Request.Bucket.ZoneGroupId`` | string | zone group of the bucket | no | no | no |
157+
| ``Request.Bucket.ZoneGroupId`` | string | zone group of the bucket | no | no | yes |
158158
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
159-
| ``Request.Bucket.CreationTime`` | time | creation time of the bucket | no | no | no |
159+
| ``Request.Bucket.CreationTime`` | time | creation time of the bucket | no | no | yes |
160160
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
161-
| ``Request.Bucket.MTime`` | time | modification time of the bucket | no | no | no |
161+
| ``Request.Bucket.MTime`` | time | modification time of the bucket | no | no | yes |
162162
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
163-
| ``Request.Bucket.Quota`` | table | bucket quota | no | no | no |
163+
| ``Request.Bucket.Quota`` | table | bucket quota | no | no | yes |
164164
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
165165
| ``Request.Bucket.Quota.MaxSize`` | integer | bucket quota max size | no | no | no |
166166
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
@@ -170,13 +170,13 @@ Request Fields
170170
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
171171
| ``Request.Bucket.Quota.Rounded`` | boolean | bucket quota is rounded to 4K | no | no | no |
172172
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
173-
| ``Request.Bucket.PlacementRule`` | table | bucket placement rule | no | no | no |
173+
| ``Request.Bucket.PlacementRule`` | table | bucket placement rule | no | no | yes |
174174
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
175175
| ``Request.Bucket.PlacementRule.Name`` | string | bucket placement rule name | no | no | no |
176176
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
177177
| ``Request.Bucket.PlacementRule.StorageClass`` | string | bucket placement rule storage class | no | no | no |
178178
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
179-
| ``Request.Bucket.User`` | table | bucket owner | no | no | no |
179+
| ``Request.Bucket.User`` | table | bucket owner | no | no | yes |
180180
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
181181
| ``Request.Bucket.User.Tenant`` | string | bucket owner tenant | no | no | no |
182182
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+

src/rgw/rgw_lua_request.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,19 @@ struct BucketMetaTable : public EmptyMetaTable {
170170
static std::string TableName() {return "Bucket";}
171171
static std::string Name() {return TableName() + "Meta";}
172172

173-
using Type = rgw::sal::Bucket;
174-
175173
static int IndexClosure(lua_State* L) {
176-
const auto bucket = reinterpret_cast<Type*>(lua_touserdata(L, lua_upvalueindex(1)));
174+
const auto s = reinterpret_cast<req_state*>(lua_touserdata(L, lua_upvalueindex(1)));
175+
const auto bucket = s->bucket.get();
177176

178177
const char* index = luaL_checkstring(L, 2);
179178

180-
if (strcasecmp(index, "Tenant") == 0) {
179+
if (rgw::sal::Bucket::empty(bucket)) {
180+
if (strcasecmp(index, "Name") == 0) {
181+
pushstring(L, s->init_state.url_bucket);
182+
} else {
183+
lua_pushnil(L);
184+
}
185+
} else if (strcasecmp(index, "Tenant") == 0) {
181186
pushstring(L, bucket->get_tenant());
182187
} else if (strcasecmp(index, "Name") == 0) {
183188
pushstring(L, bucket->get_name());
@@ -731,7 +736,7 @@ struct RequestMetaTable : public EmptyMetaTable {
731736
lua_pushnil(L);
732737
}
733738
} else if (strcasecmp(index, "Bucket") == 0) {
734-
create_metatable<BucketMetaTable>(L, false, s->bucket);
739+
create_metatable<BucketMetaTable>(L, false, s);
735740
} else if (strcasecmp(index, "Object") == 0) {
736741
create_metatable<ObjectMetaTable>(L, false, s->object);
737742
} else if (strcasecmp(index, "CopyFrom") == 0) {

0 commit comments

Comments
 (0)