From b24d69492b818457d9da0d6dce3adc0f91f18ec6 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Fri, 22 Feb 2019 10:41:34 -0500 Subject: [PATCH] LU-8066 utils: have llapi_target_iterate use sysfs tree Update llapi_target_iterate() to not use 'devices' but collect the data from the lustre sysfs tree itself. Change-Id: If100b4918bdcc8b24e72f37127048a32a808310f Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/33799 Tested-by: Jenkins Reviewed-by: Yang Sheng Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/utils/liblustreapi.c | 78 ++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index bb1bf98..75ae65c 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -4868,52 +4868,66 @@ failed: int llapi_target_iterate(int type_num, char **obd_type, void *args, llapi_cb_t cb) { - char buf[MAX_STRING_SIZE]; int i, rc = 0; glob_t param; FILE *fp; - rc = cfs_get_param_paths(¶m, "devices"); - if (rc != 0) - return -ENOENT; + for (i = 0; i < type_num; i++) { + int j; - fp = fopen(param.gl_pathv[0], "r"); - if (fp == NULL) { - rc = -errno; - llapi_error(LLAPI_MSG_ERROR, rc, "error: opening '%s'", - param.gl_pathv[0]); - goto free_path; - } + rc = cfs_get_param_paths(¶m, "%s/*/uuid", obd_type[i]); + if (rc != 0) + continue; + + for (j = 0; j < param.gl_pathc; j++) { + char obd_uuid[UUID_MAX + 1]; + char *obd_name; + char *ptr; - while (fgets(buf, sizeof(buf), fp) != NULL) { - char *obd_type_name = NULL; - char *obd_name = NULL; - char *obd_uuid = NULL; - char *bufp = buf; - struct obd_statfs osfs_buffer; + fp = fopen(param.gl_pathv[j], "r"); + if (fp == NULL) { + rc = -errno; + llapi_error(LLAPI_MSG_ERROR, rc, + "error: opening '%s'", + param.gl_pathv[j]); + goto free_path; + } - while(bufp[0] == ' ') - ++bufp; + if (fgets(obd_uuid, sizeof(obd_uuid), fp) == NULL) { + rc = -errno; + llapi_error(LLAPI_MSG_ERROR, rc, + "error: reading '%s'", + param.gl_pathv[j]); + goto free_path; + } - for(i = 0; i < 3; i++) { - obd_type_name = strsep(&bufp, " "); - } - obd_name = strsep(&bufp, " "); - obd_uuid = strsep(&bufp, " "); + /* Extract the obd_name from the sysfs path. + * 'topsysfs'/fs/lustre/'obd_type'/'obd_name'. + */ + obd_name = strstr(param.gl_pathv[j], "/fs/lustre/"); + if (!obd_name) { + rc = -EINVAL; + goto free_path; + } - memset(&osfs_buffer, 0, sizeof (osfs_buffer)); + /* skip /fs/lustre/'obd_type'/ */ + obd_name += strlen(obd_type[i]) + 12; + /* chop off after obd_name */ + ptr = strrchr(obd_name, '/'); + if (ptr) + *ptr = '\0'; - for (i = 0; i < type_num; i++) { - if (strcmp(obd_type_name, obd_type[i]) != 0) - continue; + cb(obd_type[i], obd_name, obd_uuid, args); - cb(obd_type_name, obd_name, obd_uuid, args); - } + fclose(fp); + fp = NULL; + } } - fclose(fp); free_path: + if (fp) + fclose(fp); cfs_free_param_data(¶m); - return 0; + return rc; } static void do_target_check(char *obd_type_name, char *obd_name, -- 1.8.3.1