X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Futils%2Fobd.c;h=6e2a9b01cc83fb6e3ea1697190f4805a47607333;hp=a5ba5a9ab6cb303ae27b49a2d933a21f5d387b1f;hb=5c5d70dc828ac4e3b348939a108f20395cb900ba;hpb=6e7769fce4ce49c008759aeef1a0110142f64847 diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index a5ba5a9..6e2a9b0 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -909,8 +909,8 @@ int jt_get_version(int argc, char **argv) memset(buf, 0, sizeof(rawbuf)); data->ioc_version = OBD_IOCTL_VERSION; - data->ioc_inllen1 = sizeof(rawbuf) - size_round(sizeof(*data)); - data->ioc_inlbuf1 = buf + size_round(sizeof(*data)); + data->ioc_inllen1 = sizeof(rawbuf) - cfs_size_round(sizeof(*data)); + data->ioc_inlbuf1 = buf + cfs_size_round(sizeof(*data)); data->ioc_len = obd_ioctl_packlen(data); rc = l2_ioctl(OBD_DEV_ID, OBD_GET_VERSION, buf); @@ -953,7 +953,12 @@ try_mdc: goto fail; got_one: - fgets(buf, sizeof(buf), fp); + /* should not ignore fgets(3)'s return value */ + if (!fgets(buf, sizeof(buf), fp)) { + fprintf(stderr, "reading from %s: %s", buf, strerror(errno)); + fclose(fp); + return; + } fclose(fp); /* trim trailing newlines */ @@ -986,8 +991,9 @@ int jt_obd_list_ioctl(int argc, char **argv) for (index = 0;; index++) { memset(buf, 0, sizeof(rawbuf)); data->ioc_version = OBD_IOCTL_VERSION; - data->ioc_inllen1 = sizeof(rawbuf) - size_round(sizeof(*data)); - data->ioc_inlbuf1 = buf + size_round(sizeof(*data)); + data->ioc_inllen1 = + sizeof(rawbuf) - cfs_size_round(sizeof(*data)); + data->ioc_inlbuf1 = buf + cfs_size_round(sizeof(*data)); data->ioc_len = obd_ioctl_packlen(data); data->ioc_count = index; @@ -1643,7 +1649,7 @@ int jt_obd_test_brw(int argc, char **argv) l_cond_broadcast(&shared_data->cond); else l_cond_wait(&shared_data->cond, - &shared_data->mutex); + &shared_data->mutex); shmem_unlock (); } @@ -2070,7 +2076,7 @@ int jt_llog_catlist(int argc, char **argv) memset(&data, 0x00, sizeof(data)); data.ioc_dev = cur_device; - data.ioc_inllen1 = sizeof(rawbuf) - size_round(sizeof(data)); + data.ioc_inllen1 = sizeof(rawbuf) - cfs_size_round(sizeof(data)); memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { @@ -2101,8 +2107,8 @@ int jt_llog_info(int argc, char **argv) data.ioc_dev = cur_device; data.ioc_inllen1 = strlen(argv[1]) + 1; data.ioc_inlbuf1 = argv[1]; - data.ioc_inllen2 = sizeof(rawbuf) - size_round(sizeof(data)) - - size_round(data.ioc_inllen1); + data.ioc_inllen2 = sizeof(rawbuf) - cfs_size_round(sizeof(data)) - + cfs_size_round(data.ioc_inllen1); memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { @@ -2146,10 +2152,10 @@ int jt_llog_print(int argc, char **argv) data.ioc_inllen3 = strlen(to) + 1; data.ioc_inlbuf3 = to; } - data.ioc_inllen4 = sizeof(rawbuf) - size_round(sizeof(data)) - - size_round(data.ioc_inllen1) - - size_round(data.ioc_inllen2) - - size_round(data.ioc_inllen3); + data.ioc_inllen4 = sizeof(rawbuf) - cfs_size_round(sizeof(data)) - + cfs_size_round(data.ioc_inllen1) - + cfs_size_round(data.ioc_inllen2) - + cfs_size_round(data.ioc_inllen3); memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { @@ -2228,10 +2234,10 @@ int jt_llog_check(int argc, char **argv) data.ioc_inllen3 = strlen(to) + 1; data.ioc_inlbuf3 = to; } - data.ioc_inllen4 = sizeof(rawbuf) - size_round(sizeof(data)) - - size_round(data.ioc_inllen1) - - size_round(data.ioc_inllen2) - - size_round(data.ioc_inllen3); + data.ioc_inllen4 = sizeof(rawbuf) - cfs_size_round(sizeof(data)) - + cfs_size_round(data.ioc_inllen1) - + cfs_size_round(data.ioc_inllen2) - + cfs_size_round(data.ioc_inllen3); memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { @@ -2522,106 +2528,13 @@ void obd_finalize(int argc, char **argv) do_disconnect(argv[0], 1); } -static int find_target_obdpath(char *fsname, char *path) -{ - glob_t glob_info; - char pattern[PATH_MAX + 1]; - int rc; - - snprintf(pattern, PATH_MAX, - "/proc/fs/lustre/lov/%s-*/target_obd", - fsname); - rc = glob(pattern, GLOB_BRACE, NULL, &glob_info); - if (rc == GLOB_NOMATCH) - return -ENODEV; - else if (rc) - return -EINVAL; - - strcpy(path, glob_info.gl_pathv[0]); - globfree(&glob_info); - return 0; -} - -static int find_poolpath(char *fsname, char *poolname, char *poolpath) -{ - glob_t glob_info; - char pattern[PATH_MAX + 1]; - int rc; - - snprintf(pattern, PATH_MAX, - "/proc/fs/lustre/lov/%s-*/pools/%s", - fsname, poolname); - rc = glob(pattern, GLOB_BRACE, NULL, &glob_info); - /* If no pools, make sure the lov is available */ - if ((rc == GLOB_NOMATCH) && - (find_target_obdpath(fsname, poolpath) == -ENODEV)) - return -ENODEV; - if (rc) - return -EINVAL; - - strcpy(poolpath, glob_info.gl_pathv[0]); - globfree(&glob_info); - return 0; -} - -/* - * if pool is NULL, search ostname in target_obd - * if pool is no NULL - * if pool not found returns errno < 0 - * if ostname is NULL, returns 1 if pool is not empty and 0 if pool empty - * if ostname is not NULL, returns 1 if OST is in pool and 0 if not - */ -static int search_ost(char *fsname, char *poolname, char *ostname) -{ - FILE *fd; - char buffer[PATH_MAX + 1]; - int len = 0, rc; - - if (ostname != NULL) - len = strlen(ostname); - - if (poolname == NULL) - rc = find_target_obdpath(fsname, buffer); - else - rc = find_poolpath(fsname, poolname, buffer); - if (rc) - return rc; - - if ((fd = fopen(buffer, "r")) == NULL) - return -EINVAL; - - while (fgets(buffer, sizeof(buffer), fd) != NULL) { - if (poolname == NULL) { - char *ptr; - /* Search for an ostname in the list of OSTs - Line format is IDX: fsname-OSTxxxx_UUID STATUS */ - ptr = strchr(buffer, ' '); - if ((ptr != NULL) && - (strncmp(ptr + 1, ostname, len) == 0)) { - fclose(fd); - return 1; - } - } else { - /* Search for an ostname in a pool, - (or an existing non-empty pool if no ostname) */ - if ((ostname == NULL) || - (strncmp(buffer, ostname, len) == 0)) { - fclose(fd); - return 1; - } - } - } - fclose(fd); - return 0; -} - static int check_pool_cmd(enum lcfg_command_type cmd, char *fsname, char *poolname, char *ostname) { int rc; - rc = search_ost(fsname, poolname, ostname); + rc = llapi_search_ost(fsname, poolname, ostname); if (rc < 0 && (cmd != LCFG_POOL_NEW)) { fprintf(stderr, "Pool %s.%s not found\n", fsname, poolname); @@ -2654,7 +2567,7 @@ static int check_pool_cmd(enum lcfg_command_type cmd, ostname, fsname, poolname); return -EEXIST; } - rc = search_ost(fsname, NULL, ostname); + rc = llapi_search_ost(fsname, NULL, ostname); if (rc == 0) { fprintf(stderr, "OST %s is not part of the '%s' fs.\n", ostname, fsname); @@ -2691,7 +2604,7 @@ static int check_pool_cmd_result(enum lcfg_command_type cmd, switch (cmd) { case LCFG_POOL_NEW: { do { - rc = search_ost(fsname, poolname, NULL); + rc = llapi_search_ost(fsname, poolname, NULL); if (rc == -ENODEV) return rc; if (rc < 0) @@ -2710,7 +2623,7 @@ static int check_pool_cmd_result(enum lcfg_command_type cmd, } case LCFG_POOL_DEL: { do { - rc = search_ost(fsname, poolname, NULL); + rc = llapi_search_ost(fsname, poolname, NULL); if (rc == -ENODEV) return rc; if (rc >= 0) @@ -2729,7 +2642,7 @@ static int check_pool_cmd_result(enum lcfg_command_type cmd, } case LCFG_POOL_ADD: { do { - rc = search_ost(fsname, poolname, ostname); + rc = llapi_search_ost(fsname, poolname, ostname); if (rc == -ENODEV) return rc; if (rc != 1) @@ -2748,7 +2661,7 @@ static int check_pool_cmd_result(enum lcfg_command_type cmd, } case LCFG_POOL_REM: { do { - rc = search_ost(fsname, poolname, ostname); + rc = llapi_search_ost(fsname, poolname, ostname); if (rc == -ENODEV) return rc; if (rc == 1) @@ -3178,7 +3091,7 @@ int jt_get_obj_version(int argc, char **argv) } obd_ioctl_unpack(&data, buf, sizeof rawbuf); - printf("0x%llx\n", version); + printf(LPX64"\n", version); return 0; }