#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+#include <yaml.h>
#include <libcfs/util/param.h>
+#include <linux/lustre/lustre_kernelcomm.h>
#include <linux/lustre/lustre_user.h>
+#include <lnetconfig/liblnetconfig.h>
#include <lustre/lustreapi.h>
#include "lustreapi_internal.h"
return rc;
}
+static void print_obd_line(char *s)
+{
+ const char *param = "osc/%s/ost_conn_uuid";
+ char obd_name[MAX_OBD_NAME];
+ char buf[MAX_OBD_NAME];
+ FILE *fp = NULL;
+ glob_t path;
+ char *ptr;
+retry:
+ /* obd device type is the first 3 characters of param name */
+ snprintf(buf, sizeof(buf), " %%*d %%*s %.3s %%%zus %%*s %%*d ",
+ param, sizeof(obd_name) - 1);
+ if (sscanf(s, buf, obd_name) == 0)
+ goto try_mdc;
+ if (cfs_get_param_paths(&path, param, obd_name) != 0)
+ goto try_mdc;
+ fp = fopen(path.gl_pathv[0], "r");
+ if (!fp) {
+ /* need to free path data before retry */
+ cfs_free_param_data(&path);
+try_mdc:
+ if (param[0] == 'o') { /* failed with osc, try mdc */
+ param = "mdc/%s/mds_conn_uuid";
+ goto retry;
+ }
+ buf[0] = '\0';
+ goto fail_print;
+ }
+
+ /* should not ignore fgets(3)'s return value */
+ if (!fgets(buf, sizeof(buf), fp)) {
+ fprintf(stderr, "reading from %s: %s", buf, strerror(errno));
+ goto fail_close;
+ }
+
+fail_close:
+ fclose(fp);
+ cfs_free_param_data(&path);
+
+ /* trim trailing newlines */
+ ptr = strrchr(buf, '\n');
+ if (ptr)
+ *ptr = '\0';
+fail_print:
+ ptr = strrchr(s, '\n');
+ if (ptr)
+ *ptr = '\0';
+ printf("%s%s%s\n", s, buf[0] ? " " : "", buf);
+}
+
+static int print_out_devices(yaml_parser_t *reply, enum lctl_param_flags flags)
+{
+ char buf[PATH_MAX / 2], *tmp = NULL;
+ size_t buf_len = sizeof(buf);
+ yaml_event_t event;
+ bool done = false;
+ int rc;
+
+ if (flags & PARAM_FLAGS_SHOW_SOURCE) {
+ snprintf(buf, buf_len, "devices=");
+ printf("%s\n", buf);
+ }
+ bzero(buf, sizeof(buf));
+
+ while (!done) {
+ rc = yaml_parser_parse(reply, &event);
+ if (rc == 0)
+ break;
+
+ if (event.type == YAML_MAPPING_START_EVENT) {
+ size_t len = strlen(buf);
+
+ if (len > 0 && strcmp(buf, "devices=\n") != 0) {
+ /* eat last white space */
+ buf[len - 1] = '\0';
+ if (flags & PARAM_FLAGS_EXTRA_DETAILS)
+ print_obd_line(buf);
+ else
+ printf("%s\n", buf);
+ }
+ bzero(buf, sizeof(buf));
+ tmp = buf;
+ }
+
+ if (event.type == YAML_SCALAR_EVENT) {
+ char *value = (char *)event.data.scalar.value;
+
+ if (strcmp(value, "index") == 0) {
+ yaml_event_delete(&event);
+ rc = yaml_parser_parse(reply, &event);
+ if (rc == 0)
+ break;
+
+ value = (char *)event.data.scalar.value;
+ snprintf(tmp, buf_len, "%3s ", value);
+ buf_len -= 4;
+ tmp += 4;
+ }
+
+ if (strcmp(value, "status") == 0 ||
+ strcmp(value, "type") == 0 ||
+ strcmp(value, "name") == 0 ||
+ strcmp(value, "uuid") == 0 ||
+ strcmp(value, "refcount") == 0) {
+ yaml_event_delete(&event);
+ rc = yaml_parser_parse(reply, &event);
+ if (rc == 0)
+ break;
+
+ value = (char *)event.data.scalar.value;
+ snprintf(tmp, buf_len, "%s ", value);
+ buf_len -= strlen(value) + 1;
+ tmp += strlen(value) + 1;
+ }
+ }
+
+ done = (event.type == YAML_DOCUMENT_END_EVENT);
+ if (done) {
+ size_t len = strlen(buf);
+
+ if (len > 0) {
+ /* eat last white space */
+ buf[len - 1] = '\0';
+ if (flags & PARAM_FLAGS_EXTRA_DETAILS)
+ print_obd_line(buf);
+ else
+ printf("%s\n", buf);
+ }
+ bzero(buf, sizeof(buf));
+ tmp = buf;
+ }
+ yaml_event_delete(&event);
+ }
+
+ return rc;
+}
+
+int lcfg_param_get_yaml(yaml_parser_t *reply, struct nl_sock *sk,
+ int version, char *pattern)
+{
+ char source[PATH_MAX / 2], group[GENL_NAMSIZ + 1];
+ char *family = "lustre", *tmp;
+ yaml_emitter_t request;
+ yaml_event_t event;
+ int cmd = 0;
+ int rc;
+
+ bzero(source, sizeof(source));
+ /* replace '/' with '.' to match conf_param and sysctl */
+ for (tmp = strchr(pattern, '/'); tmp != NULL;
+ tmp = strchr(tmp, '/'))
+ *tmp = '.';
+
+ tmp = strrchr(pattern, '.');
+ if (tmp) {
+ size_t len = tmp - pattern;
+
+ strncpy(group, tmp + 1, GENL_NAMSIZ);
+ strncpy(source, pattern, len);
+ } else {
+ strncpy(group, pattern, GENL_NAMSIZ);
+ }
+
+ if (strcmp(group, "devices") == 0)
+ cmd = LUSTRE_CMD_DEVICES;
+
+ if (!cmd)
+ return -EOPNOTSUPP;
+
+ /* Setup parser to recieve Netlink packets */
+ rc = yaml_parser_initialize(reply);
+ if (rc == 0)
+ return -EOPNOTSUPP;
+
+ rc = yaml_parser_set_input_netlink(reply, sk, false);
+ if (rc == 0)
+ return -EOPNOTSUPP;
+
+ /* Create Netlink emitter to send request to kernel */
+ yaml_emitter_initialize(&request);
+ rc = yaml_emitter_set_output_netlink(&request, sk,
+ family, version,
+ cmd, NLM_F_DUMP);
+ if (rc == 0)
+ goto error;
+
+ yaml_emitter_open(&request);
+
+ yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+
+ yaml_mapping_start_event_initialize(&event, NULL,
+ (yaml_char_t *)YAML_MAP_TAG,
+ 1, YAML_ANY_MAPPING_STYLE);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+
+ yaml_scalar_event_initialize(&event, NULL,
+ (yaml_char_t *)YAML_STR_TAG,
+ (yaml_char_t *)group,
+ strlen(group), 1, 0,
+ YAML_PLAIN_SCALAR_STYLE);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+
+ if (source[0]) {
+ const char *key = cmd == LUSTRE_CMD_DEVICES ? "name" : "source";
+
+ /* Now fill in 'path' filter */
+ yaml_sequence_start_event_initialize(&event, NULL,
+ (yaml_char_t *)YAML_SEQ_TAG,
+ 1, YAML_ANY_SEQUENCE_STYLE);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+
+ yaml_mapping_start_event_initialize(&event, NULL,
+ (yaml_char_t *)YAML_MAP_TAG,
+ 1, YAML_ANY_MAPPING_STYLE);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+
+ yaml_scalar_event_initialize(&event, NULL,
+ (yaml_char_t *)YAML_STR_TAG,
+ (yaml_char_t *)key, strlen(key),
+ 1, 0, YAML_PLAIN_SCALAR_STYLE);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+
+ yaml_scalar_event_initialize(&event, NULL,
+ (yaml_char_t *)YAML_STR_TAG,
+ (yaml_char_t *)source,
+ strlen(source), 1, 0,
+ YAML_PLAIN_SCALAR_STYLE);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+
+ yaml_mapping_end_event_initialize(&event);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+
+ yaml_sequence_end_event_initialize(&event);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+ } else {
+ yaml_scalar_event_initialize(&event, NULL,
+ (yaml_char_t *)YAML_STR_TAG,
+ (yaml_char_t *)"",
+ strlen(""), 1, 0,
+ YAML_PLAIN_SCALAR_STYLE);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+ }
+ yaml_mapping_end_event_initialize(&event);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+
+ yaml_document_end_event_initialize(&event, 0);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+
+ yaml_emitter_close(&request);
+error:
+ if (rc == 0) {
+ yaml_emitter_log_error(&request, stderr);
+ rc = -EINVAL;
+ }
+ yaml_emitter_delete(&request);
+
+ return rc == 1 ? 0 : -EINVAL;
+}
+
+int llapi_param_display_value(char *path, int version,
+ enum lctl_param_flags flags, FILE *fp)
+{
+ yaml_parser_t reply;
+ struct nl_sock *sk;
+ int rc;
+
+ /* version zero means just list sources. "devices is special case */
+ if (!version && strcmp(path, "devices") == 0) {
+ fprintf(fp, "devices\n");
+ return 0;
+ }
+
+ sk = nl_socket_alloc();
+ if (!sk)
+ return -ENOMEM;
+
+ rc = lcfg_param_get_yaml(&reply, sk, version, path);
+ if (rc < 0)
+ return rc;
+
+ if (flags & PARAM_FLAGS_YAML_FORMAT) {
+ yaml_document_t results;
+ yaml_emitter_t output;
+
+ /* load the reply results */
+ rc = yaml_parser_load(&reply, &results);
+ if (rc == 0) {
+ yaml_parser_log_error(&reply, stderr, "get_param: ");
+ yaml_document_delete(&results);
+ rc = -EINVAL;
+ goto free_reply;
+ }
+
+ /* create emitter to output results */
+ rc = yaml_emitter_initialize(&output);
+ if (rc == 1) {
+ yaml_emitter_set_output_file(&output, fp);
+
+ rc = yaml_emitter_dump(&output, &results);
+ }
+
+ yaml_document_delete(&results);
+ if (rc == 0) {
+ yaml_emitter_log_error(&output, stderr);
+ rc = -EINVAL;
+ }
+ yaml_emitter_delete(&output);
+ } else {
+ yaml_event_t event;
+ bool done = false;
+
+ while (!done) {
+ rc = yaml_parser_parse(&reply, &event);
+ if (rc == 0)
+ break;
+
+ if (event.type == YAML_SCALAR_EVENT) {
+ char *value = (char *)event.data.scalar.value;
+
+ if (strcmp(value, "devices") == 0)
+ rc = print_out_devices(&reply, flags);
+ if (rc == 0)
+ break;
+ }
+
+ done = (event.type == YAML_STREAM_END_EVENT);
+ yaml_event_delete(&event);
+ }
+
+ if (rc == 0) {
+ yaml_parser_log_error(&reply, stderr, "get_param: ");
+ rc = -EINVAL;
+ }
+ }
+free_reply:
+ yaml_parser_delete(&reply);
+ nl_socket_free(sk);
+ return rc == 1 ? 0 : rc;
+}
+
/**
* Read the value of the file with location \a path
* into a buffer.
printf("%s%s%s\n", s, buf[0] ? " " : "", buf);
}
-static int print_out_devices(yaml_parser_t *reply, struct param_opts *popt)
+int yaml_get_device_index(char *source)
{
- char buf[MAX_OBD_NAME], *tmp = NULL;
- size_t buf_len = sizeof(buf);
- yaml_event_t event;
- bool done = false;
- int rc;
-
- bzero(buf, sizeof(buf));
-
- while (!done) {
- rc = yaml_parser_parse(reply, &event);
- if (rc == 0)
- break;
-
- if (event.type == YAML_MAPPING_START_EVENT) {
- size_t len = strlen(buf);
-
- if (len > 0) {
- /* eat last white space */
- buf[len - 1] = '\0';
- if (popt->po_detail)
- print_obd_line(buf);
- else
- printf("%s\n", buf);
- }
- bzero(buf, sizeof(buf));
- tmp = buf;
- }
-
- if (event.type == YAML_SCALAR_EVENT) {
- char *value = (char *)event.data.scalar.value;
-
- if (strcmp(value, "index") == 0) {
- yaml_event_delete(&event);
- rc = yaml_parser_parse(reply, &event);
- if (rc == 0)
- break;
-
- value = (char *)event.data.scalar.value;
-
- snprintf(tmp, buf_len, "%3s ", value);
- buf_len -= 4;
- tmp += 4;
- }
-
- if (strcmp(value, "status") == 0 ||
- strcmp(value, "type") == 0 ||
- strcmp(value, "name") == 0 ||
- strcmp(value, "uuid") == 0 ||
- strcmp(value, "refcount") == 0) {
- yaml_event_delete(&event);
- rc = yaml_parser_parse(reply, &event);
- if (rc == 0)
- break;
-
- value = (char *)event.data.scalar.value;
-
- snprintf(tmp, buf_len, "%s ", value);
- buf_len -= strlen(value) + 1;
- tmp += strlen(value) + 1;
- }
- }
-
- done = (event.type == YAML_DOCUMENT_END_EVENT);
- if (done) {
- size_t len = strlen(buf);
-
- if (len > 0) {
- /* eat last white space */
- buf[len - 1] = '\0';
- if (popt->po_detail)
- print_obd_line(buf);
- else
- printf("%s\n", buf);
- }
- bzero(buf, sizeof(buf));
- tmp = buf;
- }
- yaml_event_delete(&event);
- }
-
- return rc;
-}
-
-int lcfg_param_get_yaml(yaml_parser_t *reply, struct nl_sock *sk, char *pattern)
-{
- char source[MAX_OBD_NAME], group[GENL_NAMSIZ + 1];
- int version = LUSTRE_GENL_VERSION;
- char *family = "lustre", *tmp;
yaml_emitter_t request;
+ yaml_parser_t reply;
yaml_event_t event;
- int cmd = 0;
+ struct nl_sock *sk;
+ bool done = false;
int rc;
- bzero(source, sizeof(source));
- tmp = strrchr(pattern, '/');
- if (tmp) {
- size_t len = tmp - pattern;
-
- strncpy(group, tmp + 1, GENL_NAMSIZ);
- strncpy(source, pattern, len);
-
- /* replace '/' with '.' to match conf_param and sysctl */
- for (tmp = strchr(pattern, '/'); tmp != NULL;
- tmp = strchr(tmp, '/'))
- *tmp = '.';
- } else {
- strncpy(group, pattern, GENL_NAMSIZ);
- }
-
- if (strcmp(group, "devices") == 0)
- cmd = LUSTRE_CMD_DEVICES;
-
- if (!cmd)
+ sk = nl_socket_alloc();
+ if (!sk)
return -EOPNOTSUPP;
/* Setup parser to recieve Netlink packets */
- rc = yaml_parser_initialize(reply);
+ rc = yaml_parser_initialize(&reply);
if (rc == 0)
return -EOPNOTSUPP;
- rc = yaml_parser_set_input_netlink(reply, sk, false);
+ rc = yaml_parser_set_input_netlink(&reply, sk, false);
if (rc == 0)
return -EOPNOTSUPP;
/* Create Netlink emitter to send request to kernel */
yaml_emitter_initialize(&request);
- rc = yaml_emitter_set_output_netlink(&request, sk,
- family, version,
- cmd, NLM_F_DUMP);
+ rc = yaml_emitter_set_output_netlink(&request, sk, "lustre",
+ LUSTRE_GENL_VERSION,
+ LUSTRE_CMD_DEVICES, NLM_F_DUMP);
if (rc == 0)
goto error;
yaml_scalar_event_initialize(&event, NULL,
(yaml_char_t *)YAML_STR_TAG,
- (yaml_char_t *)group,
- strlen(group), 1, 0,
+ (yaml_char_t *)"devices",
+ strlen("devices"), 1, 0,
YAML_PLAIN_SCALAR_STYLE);
rc = yaml_emitter_emit(&request, &event);
if (rc == 0)
goto error;
- if (source[0]) {
- const char *key = "name";
+ yaml_sequence_start_event_initialize(&event, NULL,
+ (yaml_char_t *)YAML_SEQ_TAG,
+ 1, YAML_ANY_SEQUENCE_STYLE);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
- /* Now fill in 'path' filter */
- yaml_sequence_start_event_initialize(&event, NULL,
- (yaml_char_t *)YAML_SEQ_TAG,
- 1, YAML_ANY_SEQUENCE_STYLE);
- rc = yaml_emitter_emit(&request, &event);
- if (rc == 0)
- goto error;
+ yaml_mapping_start_event_initialize(&event, NULL,
+ (yaml_char_t *)YAML_MAP_TAG,
+ 1, YAML_ANY_MAPPING_STYLE);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
- yaml_mapping_start_event_initialize(&event, NULL,
- (yaml_char_t *)YAML_MAP_TAG,
- 1, YAML_ANY_MAPPING_STYLE);
- rc = yaml_emitter_emit(&request, &event);
- if (rc == 0)
- goto error;
+ yaml_scalar_event_initialize(&event, NULL,
+ (yaml_char_t *)YAML_STR_TAG,
+ (yaml_char_t *)"name",
+ strlen("name"),
+ 1, 0, YAML_PLAIN_SCALAR_STYLE);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
- yaml_scalar_event_initialize(&event, NULL,
- (yaml_char_t *)YAML_STR_TAG,
- (yaml_char_t *)key, strlen(key),
- 1, 0, YAML_PLAIN_SCALAR_STYLE);
- rc = yaml_emitter_emit(&request, &event);
- if (rc == 0)
- goto error;
-
- yaml_scalar_event_initialize(&event, NULL,
- (yaml_char_t *)YAML_STR_TAG,
- (yaml_char_t *)source,
- strlen(source), 1, 0,
- YAML_PLAIN_SCALAR_STYLE);
- rc = yaml_emitter_emit(&request, &event);
- if (rc == 0)
- goto error;
+ yaml_scalar_event_initialize(&event, NULL,
+ (yaml_char_t *)YAML_STR_TAG,
+ (yaml_char_t *)source,
+ strlen(source), 1, 0,
+ YAML_PLAIN_SCALAR_STYLE);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
- yaml_mapping_end_event_initialize(&event);
- rc = yaml_emitter_emit(&request, &event);
- if (rc == 0)
- goto error;
+ yaml_mapping_end_event_initialize(&event);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
+
+ yaml_sequence_end_event_initialize(&event);
+ rc = yaml_emitter_emit(&request, &event);
+ if (rc == 0)
+ goto error;
- yaml_sequence_end_event_initialize(&event);
- rc = yaml_emitter_emit(&request, &event);
- if (rc == 0)
- goto error;
- } else {
- yaml_scalar_event_initialize(&event, NULL,
- (yaml_char_t *)YAML_STR_TAG,
- (yaml_char_t *)"",
- strlen(""), 1, 0,
- YAML_PLAIN_SCALAR_STYLE);
- rc = yaml_emitter_emit(&request, &event);
- if (rc == 0)
- goto error;
- }
yaml_mapping_end_event_initialize(&event);
rc = yaml_emitter_emit(&request, &event);
if (rc == 0)
}
yaml_emitter_delete(&request);
- return rc == 1 ? 0 : -EINVAL;
-}
-
-int lcfg_getparam_yaml(char *path, struct param_opts *popt)
-{
- yaml_parser_t reply;
- struct nl_sock *sk;
- int rc;
-
- sk = nl_socket_alloc();
- if (!sk)
- return -ENOMEM;
-
- rc = lcfg_param_get_yaml(&reply, sk, path);
- if (rc < 0)
- return rc;
-
- if (popt->po_yaml) {
- yaml_document_t results;
- yaml_emitter_t output;
-
- /* load the reply results */
- rc = yaml_parser_load(&reply, &results);
+ while (!done) {
+ rc = yaml_parser_parse(&reply, &event);
if (rc == 0) {
- yaml_parser_log_error(&reply, stderr, "get_param: ");
- yaml_document_delete(&results);
+ yaml_parser_log_error(&reply, stdout, "lctl: ");
rc = -EINVAL;
- goto free_reply;
- }
-
- /* create emitter to output results */
- rc = yaml_emitter_initialize(&output);
- if (rc == 1) {
- yaml_emitter_set_output_file(&output, stdout);
-
- rc = yaml_emitter_dump(&output, &results);
+ break;
}
- yaml_document_delete(&results);
- if (rc == 0) {
- yaml_emitter_log_error(&output, stderr);
- rc = -EINVAL;
- }
- yaml_emitter_delete(&output);
- } else {
- yaml_event_t event;
- bool done = false;
-
- while (!done) {
- rc = yaml_parser_parse(&reply, &event);
- if (rc == 0)
- break;
-
- if (event.type == YAML_SCALAR_EVENT) {
- char *value = (char *)event.data.scalar.value;
+ if (event.type == YAML_SCALAR_EVENT) {
+ char *value = (char *)event.data.scalar.value;
- if (strcmp(value, "devices") == 0)
- rc = print_out_devices(&reply, popt);
- if (rc == 0)
- break;
+ if (strcmp(value, "index") == 0) {
+ yaml_event_delete(&event);
+ rc = yaml_parser_parse(&reply, &event);
+ if (rc == 1) {
+ value = (char *)event.data.scalar.value;
+ errno = 0;
+ rc = strtoul(value, NULL, 10);
+ if (errno) {
+ yaml_event_delete(&event);
+ rc = -errno;
+ }
+ return rc;
+ }
}
-
- done = (event.type == YAML_STREAM_END_EVENT);
- yaml_event_delete(&event);
- }
-
- if (rc == 0) {
- yaml_parser_log_error(&reply, stderr, "get_param: ");
- rc = -EINVAL;
}
+ done = (event.type == YAML_STREAM_END_EVENT);
+ yaml_event_delete(&event);
}
-free_reply:
- yaml_parser_delete(&reply);
+
nl_socket_free(sk);
- return rc == 1 ? 0 : rc;
+
+ return rc;
}
/**
rc2 = param_display(&popt, path, NULL, LIST_PARAM);
if (rc2 < 0) {
- fprintf(stderr, "error: %s: listing '%s': %s\n",
- jt_cmdname(argv[0]), path, strerror(-rc2));
+ if (rc2 == -ENOENT && getuid() != 0)
+ rc2 = llapi_param_display_value(path, 0, 0,
+ stdout);
if (rc == 0)
rc = rc2;
+
+ if (rc < 0) {
+ fprintf(stderr, "error: %s: listing '%s': %s\n",
+ jt_cmdname(argv[0]), path,
+ strerror(-rc2));
+ }
continue;
}
}
popt->po_show_path = 1;
- while ((ch = getopt(argc, argv, "FnNR")) != -1) {
+ while ((ch = getopt(argc, argv, "FnNRy")) != -1) {
switch (ch) {
case 'F':
popt->po_show_type = 1;
case 'R':
popt->po_recursive = 1;
break;
+ case 'y':
+ popt->po_yaml = 1;
+ break;
default:
return -1;
}
int jt_lcfg_getparam(int argc, char **argv)
{
+ int version = LUSTRE_GENL_VERSION;
enum parameter_operation mode;
int rc = 0, index, i;
struct param_opts popt;
+ int flags = 0;
char *path;
memset(&popt, 0, sizeof(popt));
return CMD_HELP;
mode = popt.po_only_path ? LIST_PARAM : GET_PARAM;
+ if (mode == LIST_PARAM)
+ version = 0;
+
+ if (popt.po_yaml)
+ flags |= PARAM_FLAGS_YAML_FORMAT;
+ if (popt.po_show_path)
+ flags |= PARAM_FLAGS_SHOW_SOURCE;
+
for (i = index; i < argc; i++) {
int rc2;
rc2 = param_display(&popt, path, NULL, mode);
if (rc2 < 0) {
- if (mode == GET_PARAM && rc2 == -ENOENT &&
- getuid() != 0)
- rc2 = lcfg_getparam_yaml(path, &popt);
-
+ if (rc2 == -ENOENT && getuid() != 0)
+ rc2 = llapi_param_display_value(path, version,
+ flags, stdout);
if (rc == 0)
rc = rc2;
continue;
}
/* get device list by netlink or debugfs */
-int jt_obd_list(int argc, char **argv)
+int jt_device_list(int argc, char **argv)
{
static const struct option long_opts[] = {
{ .name = "target", .has_arg = no_argument, .val = 't' },
};
struct param_opts opts;
char buf[MAX_OBD_NAME];
- struct nl_sock *sk;
+ int flags = 0;
glob_t path;
int rc, c;
FILE *fp;
- if (optind < argc)
+ if (optind + 1 < argc)
return CMD_HELP;
memset(&opts, 0, sizeof(opts));
while ((c = getopt_long(argc, argv, "ty", long_opts, NULL)) != -1) {
switch (c) {
case 't':
+ flags |= PARAM_FLAGS_EXTRA_DETAILS;
opts.po_detail = true;
break;
case 'y':
+ flags |= PARAM_FLAGS_YAML_FORMAT;
opts.po_yaml = true;
break;
default:
}
optind = 1;
- sk = nl_socket_alloc();
- if (!sk)
- goto non_netlink;
-
/* Use YAML to list all devices */
- rc = lcfg_getparam_yaml("devices", &opts);
+ rc = llapi_param_display_value("devices", LUSTRE_GENL_VERSION, flags,
+ stdout);
if (rc == 0)
return 0;
-non_netlink:
- if (sk) {
- nl_close(sk);
- nl_socket_free(sk);
- }
-
rc = llapi_param_get_paths("devices", &path);
if (rc < 0)
return rc;
{
struct obd_ioctl_data data;
char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
- yaml_parser_t output;
- yaml_event_t event;
- struct nl_sock *sk;
- bool done = false;
- int rc = 0;
-
- memset(buf, 0, sizeof(rawbuf));
- scnprintf(buf, sizeof(rawbuf), "%s/devices",
- name);
-
- sk = nl_socket_alloc();
- if (!sk)
- goto ioctl;
-
- /* Use YAML to list all devices */
- rc = lcfg_param_get_yaml(&output, sk, buf);
- if (rc < 0) {
- if (rc == -EOPNOTSUPP)
- goto ioctl;
- return rc;
- }
-
- while (!done) {
- rc = yaml_parser_parse(&output, &event);
- if (rc == 0) {
- yaml_parser_log_error(&output, stdout, "lctl: ");
- rc = -EINVAL;
- break;
- }
-
- if (event.type == YAML_SCALAR_EVENT) {
- char *value = (char *)event.data.scalar.value;
-
- if (strcmp(value, "index") == 0) {
- yaml_event_delete(&event);
- rc = yaml_parser_parse(&output, &event);
- if (rc == 1) {
- value = (char *)event.data.scalar.value;
- errno = 0;
- rc = strtoul(value, NULL, 10);
- if (errno) {
- yaml_event_delete(&event);
- rc = -errno;
- goto ioctl;
- }
- return rc;
- }
- }
- }
- done = (event.type == YAML_STREAM_END_EVENT);
- yaml_event_delete(&event);
- }
-ioctl:
- if (sk)
- nl_socket_free(sk);
+ int rc;
- if (rc > 0 || rc != -EOPNOTSUPP)
+ /* Use YAML to find device index */
+ rc = yaml_get_device_index(name);
+ if (rc >= 0 || rc != -EOPNOTSUPP)
return rc;
memset(&data, 0, sizeof(data));