goto out;
}
+ if (!(src || rte || dst)) {
+ snprintf(err_str, sizeof(err_str),
+ "\"Missing required argument(s)\"");
+ rc = LUSTRE_CFG_RC_BAD_PARAM;
+ goto out;
+ }
+
/* sanitize parameters:
* src-dst can be simultaneously present
* dst-rte can be simultaneously present
*/
- if ((!src && !rte && !dst) ||
- (src && rte && dst) ||
- (src && rte && !dst)) {
+ if (src && rte && dst) {
snprintf(err_str, sizeof(err_str),
"\"The combination of src, dst and rte is not supported\"");
rc = LUSTRE_CFG_RC_BAD_PARAM;
goto out;
}
+ if (src && rte) {
+ snprintf(err_str, sizeof(err_str),
+ "\"src and rte cannot be combined\"");
+ rc = LUSTRE_CFG_RC_BAD_PARAM;
+ goto out;
+ }
+
udsp = lnet_udsp_alloc();
if (!udsp) {
snprintf(err_str, sizeof(err_str), "\"out of memory\"");
if (rc < 0) {
snprintf(err_str,
sizeof(err_str),
- "\failed to parse src parameter\"");
+ "\"failed to parse src parameter\"");
goto out;
}
}
if (rc < 0) {
snprintf(err_str,
sizeof(err_str),
- "\failed to parse dst parameter\"");
+ "\"failed to parse dst parameter\"");
goto out;
}
}
if (rc < 0) {
snprintf(err_str,
sizeof(err_str),
- "\failed to parse rte parameter\"");
+ "\"failed to parse rte parameter\"");
goto out;
}
}
udsp_bulk.iou_idx = idx;
rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_UDSP, &udsp_bulk);
- if (rc < 0) {
- rc = -errno;
+ if (rc < 0)
snprintf(err_str, sizeof(err_str),
- "\"cannot del udsp: %s\"", strerror(rc));
- }
+ "\"cannot del udsp: %s\"", strerror(errno));
cYAML_build_error(rc, seq_no, ADD_CMD, "udsp", err_str, err_rc);
return rc;
command_t udsp_cmds[] = {
{"add", jt_add_udsp, 0, "add a udsp\n"
- "\t--src: ip2nets syntax specifying the local NID to match\n"
- "\t--dst: ip2nets syntax specifying the remote NID to match\n"
- "\t--rte: ip2nets syntax specifying the router NID to match\n"
- "\t--priority: priority value (0 - highest priority)\n"
- "\t--idx: index of where to insert the rule.\n"
- "\t By default, appends to the end of the rule list.\n"},
+ "\t--src nid|net: ip2nets syntax specifying the local NID or network to match.\n"
+ "\t--dst nid: ip2nets syntax specifying the remote NID to match.\n"
+ "\t--rte nid: ip2nets syntax specifying the router NID to match.\n"
+ "\t--priority p: Assign priority value p where p >= 0.\n"
+ "\t Note: 0 is the highest priority.\n"
+ "\t--idx n: Insert the rule in the n'th position on the list of rules.\n"
+ "\t By default, rules are appended to the end of the rule list.\n"},
{"del", jt_del_udsp, 0, "delete a udsp\n"
- "\t--idx: index of the Policy.\n"},
+ "\t--all: Delete all rules.\n"
+ "\t--idx n: Delete the rule at index n.\n"},
{"show", jt_show_udsp, 0, "show udsps\n"
- "\t --idx: index of the policy to show.\n"},
+ "\t--idx n: Show the rule at at index n.\n"
+ "\t By default, all rules are shown.\n"},
{ 0, 0, 0, NULL }
};
static int jt_show_udsp(int argc, char **argv)
{
- int idx = -1;
+ long int idx = -1;
int rc, opt;
struct cYAML *err_rc = NULL, *show_rc = NULL;
long_options, NULL)) != -1) {
switch (opt) {
case 'i':
- idx = atoi(optarg);
+ rc = parse_long(optarg, &idx);
+ if (rc != 0 || idx < -1) {
+ printf("Invalid index \"%s\"\n", optarg);
+ return -EINVAL;
+ }
break;
case '?':
print_help(net_cmds, "net", "show");
break;
case 'p':
rc = parse_long(optarg, &priority);
- if (rc != 0)
- priority = -1;
+ if (rc != 0 || priority < 0) {
+ printf("Invalid priority \"%s\"\n", optarg);
+ return -EINVAL;
+ }
action_type = "priority";
udsp_action.udsp_priority = priority;
break;
case 'i':
rc = parse_long(optarg, &idx);
- if (rc != 0)
- idx = 0;
+ if (rc != 0 || idx < 0) {
+ printf("Invalid index \"%s\"\n", optarg);
+ return -EINVAL;
+ }
break;
case '?':
print_help(udsp_cmds, "udsp", "add");
}
}
+ if (!(src || dst || rte)) {
+ print_help(udsp_cmds, "udsp", "add");
+ return 0;
+ }
+
rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
idx, -1, &err_rc);
static int jt_del_udsp(int argc, char **argv)
{
struct cYAML *err_rc = NULL;
- long int idx = 0;
+ long int idx = -2;
int opt, rc = 0;
+ bool all = false;
- const char *const short_options = "i:";
+ const char *const short_options = "ai:";
static const struct option long_options[] = {
+ { .name = "all", .has_arg = no_argument, .val = 'a' },
{ .name = "idx", .has_arg = required_argument, .val = 'i' },
{ .name = NULL } };
while ((opt = getopt_long(argc, argv, short_options,
long_options, NULL)) != -1) {
switch (opt) {
+ case 'a':
+ all = true;
+ break;
case 'i':
rc = parse_long(optarg, &idx);
- if (rc != 0)
- idx = 0;
+ if (rc != 0 || idx < -1) {
+ printf("Invalid index \"%s\"\n", optarg);
+ return -EINVAL;
+ }
break;
case '?':
print_help(udsp_cmds, "udsp", "del");
}
}
+ if (all && idx != -2) {
+ printf("Cannot combine --all with --idx\n");
+ return -EINVAL;
+ } else if (all) {
+ idx = -1;
+ } else if (idx == -2) {
+ printf("Must specify --idx or --all\n");
+ return -EINVAL;
+ }
+
rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
if (rc != LUSTRE_CFG_RC_NO_ERR)
cYAML_print_tree2file(stderr, err_rc);