From: Yehuda Sadeh Date: Thu, 17 Oct 2019 23:24:29 +0000 (-0700) Subject: rgw_admin: code cleanup X-Git-Tag: v15.1.0~22^2~96 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6fff88da910101c2cca4d62f6d34ab30fc5fcebf;p=ceph.git rgw_admin: code cleanup Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 741e9203c2cc..1c819c737a55 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -2602,48 +2602,29 @@ static bool directional_flow_opt(const string& opt) } template -static bool require_opt(std::optional opt, const string& err_msg) -{ - if (!opt) { - cerr << err_msg << std::endl; - return false; - } - return true; -} - -template -static bool require_opt(std::optional opt, bool extra_check, const string& err_msg) +static bool require_opt(std::optional opt, bool extra_check = true) { if (!opt || !extra_check) { - cerr << err_msg << std::endl; - return false; - } - return true; -} - -template -static bool require_non_empty_opt(std::optional opt, const string& err_msg) -{ - if (!opt || opt->empty()) { - cerr << err_msg << std::endl; return false; } return true; } template -static bool require_non_empty_opt(std::optional opt, bool extra_check, const string& err_msg) +static bool require_non_empty_opt(std::optional opt, bool extra_check = true) { if (!opt || opt->empty() || !extra_check) { - cerr << err_msg << std::endl; return false; } return true; } -#define CHECK_TRUE(x, err) \ +#define CHECK_TRUE(x, msg, err) \ do { \ - if (!x) return err; \ + if (!x) { \ + cerr << msg << std::endl; \ + return err; \ + } \ } while (0) template @@ -7675,8 +7656,8 @@ next: if (opt_cmd == OPT::SYNC_GROUP_CREATE || opt_cmd == OPT::SYNC_GROUP_MODIFY) { - CHECK_TRUE(require_opt(opt_group_id, "ERROR: --group-id not specified"), EINVAL); - CHECK_TRUE(require_opt(opt_status, "ERROR: --status is not specified (options: forbidden, enabled, activated)"), EINVAL); + CHECK_TRUE(require_opt(opt_group_id), "ERROR: --group-id not specified", EINVAL); + CHECK_TRUE(require_opt(opt_status), "ERROR: --status is not specified (options: forbidden, enabled, activated)", EINVAL); RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); ret = zonegroup.init(g_ceph_context, store->svc()->sysobj); @@ -7741,7 +7722,7 @@ next: } if (opt_cmd == OPT::SYNC_GROUP_REMOVE) { - CHECK_TRUE(require_opt(opt_group_id, "ERROR: --group-id not specified"), EINVAL); + CHECK_TRUE(require_opt(opt_group_id), "ERROR: --group-id not specified", EINVAL); RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); ret = zonegroup.init(g_ceph_context, store->svc()->sysobj); @@ -7767,12 +7748,12 @@ next: } if (opt_cmd == OPT::SYNC_GROUP_FLOW_CREATE) { - CHECK_TRUE(require_opt(opt_group_id, "ERROR: --group-id not specified"), EINVAL); - CHECK_TRUE(require_opt(opt_flow_id, "ERROR: --flow-id not specified"), EINVAL); + CHECK_TRUE(require_opt(opt_group_id), "ERROR: --group-id not specified", EINVAL); + CHECK_TRUE(require_opt(opt_flow_id), "ERROR: --flow-id not specified", EINVAL); CHECK_TRUE(require_opt(opt_flow_type, (symmetrical_flow_opt(*opt_flow_type) || - directional_flow_opt(*opt_flow_type)), - "ERROR: --flow-type not specified or invalid (options: symmetrical, directional)"), EINVAL); + directional_flow_opt(*opt_flow_type))), + "ERROR: --flow-type not specified or invalid (options: symmetrical, directional)", EINVAL); RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); ret = zonegroup.init(g_ceph_context, store->svc()->sysobj); @@ -7790,7 +7771,7 @@ next: auto& group = iter->second; if (symmetrical_flow_opt(*opt_flow_type)) { - CHECK_TRUE(require_non_empty_opt(opt_zones, "ERROR: --zones not provided for symmetrical flow, or is empty"), EINVAL); + CHECK_TRUE(require_non_empty_opt(opt_zones), "ERROR: --zones not provided for symmetrical flow, or is empty", EINVAL); rgw_sync_symmetric_group *flow_group; @@ -7800,8 +7781,8 @@ next: flow_group->zones.insert(z); } } else { /* directional */ - CHECK_TRUE(require_non_empty_opt(opt_source_zone, "ERROR: --source-zone not provided for directional flow rule, or is empty"), EINVAL); - CHECK_TRUE(require_non_empty_opt(opt_dest_zone, "ERROR: --dest-zone not provided for directional flow rule, or is empty"), EINVAL); + CHECK_TRUE(require_non_empty_opt(opt_source_zone), "ERROR: --source-zone not provided for directional flow rule, or is empty", EINVAL); + CHECK_TRUE(require_non_empty_opt(opt_dest_zone), "ERROR: --dest-zone not provided for directional flow rule, or is empty", EINVAL); rgw_sync_directional_rule *flow_rule; @@ -7818,12 +7799,12 @@ next: } if (opt_cmd == OPT::SYNC_GROUP_FLOW_REMOVE) { - CHECK_TRUE(require_opt(opt_group_id, "ERROR: --group-id not specified"), EINVAL); - CHECK_TRUE(require_opt(opt_flow_id, "ERROR: --flow-id not specified"), EINVAL); + CHECK_TRUE(require_opt(opt_group_id), "ERROR: --group-id not specified", EINVAL); + CHECK_TRUE(require_opt(opt_flow_id), "ERROR: --flow-id not specified", EINVAL); CHECK_TRUE(require_opt(opt_flow_type, (symmetrical_flow_opt(*opt_flow_type) || - directional_flow_opt(*opt_flow_type)), - "ERROR: --flow-type not specified or invalid (options: symmetrical, directional)"), EINVAL); + directional_flow_opt(*opt_flow_type))), + "ERROR: --flow-type not specified or invalid (options: symmetrical, directional)", EINVAL); RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); ret = zonegroup.init(g_ceph_context, store->svc()->sysobj); @@ -7843,8 +7824,8 @@ next: if (symmetrical_flow_opt(*opt_flow_type)) { group.data_flow.remove_symmetrical(*opt_flow_id, opt_zones); } else { /* directional */ - CHECK_TRUE(require_non_empty_opt(opt_source_zone, "ERROR: --source-zone not provided for directional flow rule, or is empty"), EINVAL); - CHECK_TRUE(require_non_empty_opt(opt_dest_zone, "ERROR: --dest-zone not provided for directional flow rule, or is empty"), EINVAL); + CHECK_TRUE(require_non_empty_opt(opt_source_zone), "ERROR: --source-zone not provided for directional flow rule, or is empty", EINVAL); + CHECK_TRUE(require_non_empty_opt(opt_dest_zone), "ERROR: --dest-zone not provided for directional flow rule, or is empty", EINVAL); group.data_flow.remove_directional(*opt_source_zone, *opt_dest_zone); } @@ -7859,10 +7840,10 @@ next: } if (opt_cmd == OPT::SYNC_GROUP_PIPE_CREATE) { - CHECK_TRUE(require_opt(opt_group_id, "ERROR: --group-id not specified"), EINVAL); - CHECK_TRUE(require_opt(opt_pipe_id, "ERROR: --pipe-id not specified"), EINVAL); - CHECK_TRUE(require_non_empty_opt(opt_source_zones, "ERROR: --source-zones not provided or is empty; should be list of zones or '*'"), EINVAL); - CHECK_TRUE(require_non_empty_opt(opt_dest_zones, "ERROR: --dest-zones not provided or is empty; should be list of zones or '*'"), EINVAL); + CHECK_TRUE(require_opt(opt_group_id), "ERROR: --group-id not specified", EINVAL); + CHECK_TRUE(require_opt(opt_pipe_id), "ERROR: --pipe-id not specified", EINVAL); + CHECK_TRUE(require_non_empty_opt(opt_source_zones), "ERROR: --source-zones not provided or is empty; should be list of zones or '*'", EINVAL); + CHECK_TRUE(require_non_empty_opt(opt_dest_zones), "ERROR: --dest-zones not provided or is empty; should be list of zones or '*'", EINVAL); RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); @@ -7903,8 +7884,8 @@ next: } if (opt_cmd == OPT::SYNC_GROUP_PIPE_REMOVE) { - CHECK_TRUE(require_opt(opt_group_id, "ERROR: --group-id not specified"), EINVAL); - CHECK_TRUE(require_opt(opt_pipe_id, "ERROR: --pipe-id not specified"), EINVAL); + CHECK_TRUE(require_opt(opt_group_id), "ERROR: --group-id not specified", EINVAL); + CHECK_TRUE(require_opt(opt_pipe_id), "ERROR: --pipe-id not specified", EINVAL); RGWZoneGroup zonegroup(zonegroup_id, zonegroup_name); ret = zonegroup.init(g_ceph_context, store->svc()->sysobj);