From: Kefu Chai Date: Tue, 8 Jun 2021 04:44:21 +0000 (+0800) Subject: rgw/rgw_lua*: return unknown field error using luaL_error() X-Git-Tag: v17.1.0~1715^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F41743%2Fhead;p=ceph.git rgw/rgw_lua*: return unknown field error using luaL_error() it's found on aarch64, the exception is not caught even if we do catch exactly the same type of thrown exception, and the uncaught exception ends up with a std::terminate() call. it could be the ABI mismatch in aarch64, so the C++ runtime failed to find the catch block. in this change, luaL_error() is used to populate the error to the caller instead to workaround this issue. Signed-off-by: Kefu Chai --- diff --git a/src/rgw/rgw_lua_request.cc b/src/rgw/rgw_lua_request.cc index 5a367250278..ce7e9235219 100644 --- a/src/rgw/rgw_lua_request.cc +++ b/src/rgw/rgw_lua_request.cc @@ -58,7 +58,7 @@ struct ResponseMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "Message") == 0) { pushstring(L, err->message); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -77,7 +77,7 @@ struct ResponseMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "Message") == 0) { err->message.assign(luaL_checkstring(L, 3)); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return NO_RETURNVAL; } @@ -101,7 +101,7 @@ struct QuotaMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "Rounded") == 0) { lua_pushboolean(L, !info->check_on_raw); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -121,7 +121,7 @@ struct PlacementRuleMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "StorageClass") == 0) { pushstring(L, rule->storage_class); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -141,7 +141,7 @@ struct UserMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "Id") == 0) { pushstring(L, user->id); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -161,7 +161,7 @@ struct OwnerMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "User") == 0) { create_metatable(L, false, &(owner->get_id())); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -203,7 +203,7 @@ struct BucketMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "User") == 0) { create_metatable(L, false, &(bucket->get_info().owner)); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -231,7 +231,7 @@ struct ObjectMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "MTime") == 0) { pushtime(L, obj->get_mtime()); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -346,7 +346,7 @@ struct GrantMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "Referer") == 0) { pushstring(L, grant->get_referer()); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -446,7 +446,7 @@ struct ACLMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "Grants") == 0) { create_metatable(L, false, &(acl->get_acl().get_grant_map())); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -543,7 +543,7 @@ struct PolicyMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "Statements") == 0) { create_metatable(L, &(policy->statements)); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -641,7 +641,7 @@ struct HTTPMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "Domain") == 0) { pushstring(L, info->domain); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -663,7 +663,7 @@ struct CopyFromMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "Object") == 0) { create_metatable(L, false, s->src_object); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -683,7 +683,7 @@ struct ZoneGroupMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "Endpoint") == 0) { pushstring(L, s->zonegroup_endpoint); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } @@ -762,7 +762,7 @@ struct RequestMetaTable : public EmptyMetaTable { } else if (strcasecmp(index, "Tags") == 0) { create_metatable>(L, false, &(s->tagset.get_tags())); } else { - throw_unknown_field(index, TableName()); + return error_unknown_field(L, index, TableName()); } return ONE_RETURNVAL; } diff --git a/src/rgw/rgw_lua_utils.h b/src/rgw/rgw_lua_utils.h index 53b6cfc28f2..ac4ec4799e4 100644 --- a/src/rgw/rgw_lua_utils.h +++ b/src/rgw/rgw_lua_utils.h @@ -164,8 +164,9 @@ struct EmptyMetaTable { return luaL_error(L, "trying to get length of non-iterable field"); } - static void throw_unknown_field(const std::string& index, const std::string& table) { - throw std::runtime_error("unknown field name: " + index + " provided to: " + table); + static int error_unknown_field(lua_State* L, const std::string& index, const std::string& table) { + return luaL_error(L, "unknown field name: %s provided to: %s", + index.c_str(), table.c_str()); } };