X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Futils%2Fliblustreapi.c;h=cf27a9bbf85a76bd3c59b0d258cb0621a6e39484;hp=ef34c1bffd2da0687389a66f27ec98dad93cb1ce;hb=a1c8e27ca38de157c2ce4ecf3f21392a079ac1a0;hpb=bfd4600f31691fdad676a8489f591bccc24f2100 diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index ef34c1b..cf27a9b 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -23,7 +23,7 @@ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2015, Intel Corporation. + * Copyright (c) 2011, 2016, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -72,11 +72,16 @@ #include #include #include +#include #include #include "lustreapi_internal.h" static int llapi_msg_level = LLAPI_MSG_MAX; +char *mdt_hash_name[] = { "none", + LMV_HASH_NAME_ALL_CHARS, + LMV_HASH_NAME_FNV_1A_64 }; + void llapi_msg_set_level(int level) { /* ensure level is in the good range */ @@ -1739,23 +1744,23 @@ int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count) int llapi_get_obd_count(char *mnt, int *count, int is_mdt) { - DIR *root; - int rc; + int root; + int rc; - root = opendir(mnt); - if (!root) { - rc = -errno; - llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt); - return rc; - } + root = open(mnt, O_RDONLY | O_DIRECTORY); + if (root < 0) { + rc = -errno; + llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt); + return rc; + } - *count = is_mdt; - rc = ioctl(dirfd(root), LL_IOC_GETOBDCOUNT, count); - if (rc < 0) - rc = -errno; + *count = is_mdt; + rc = ioctl(root, LL_IOC_GETOBDCOUNT, count); + if (rc < 0) + rc = -errno; - closedir(root); - return rc; + close(root); + return rc; } /* Check if user specified value matches a real uuid. Ignore _UUID, @@ -1783,7 +1788,7 @@ int llapi_uuid_match(char *real_uuid, char *search_uuid) /* Here, param->fp_obd_uuid points to a single obduuid, the index of which is * returned in param->fp_obd_index */ -static int setup_obd_uuid(DIR *dir, char *dname, struct find_param *param) +static int setup_obd_uuid(int fd, char *dname, struct find_param *param) { struct obd_uuid obd_uuid; char buf[PATH_MAX]; @@ -1797,9 +1802,9 @@ static int setup_obd_uuid(DIR *dir, char *dname, struct find_param *param) /* Get the lov/lmv name */ if (param->fp_get_lmv) - rc = llapi_file_fget_lmv_uuid(dirfd(dir), &obd_uuid); + rc = llapi_file_fget_lmv_uuid(fd, &obd_uuid); else - rc = llapi_file_fget_lov_uuid(dirfd(dir), &obd_uuid); + rc = llapi_file_fget_lov_uuid(fd, &obd_uuid); if (rc) { if (rc != -ENOTTY) { llapi_error(LLAPI_MSG_ERROR, rc, @@ -1986,17 +1991,17 @@ static int setup_target_indexes(DIR *dir, char *path, struct find_param *param) int llapi_ostlist(char *path, struct find_param *param) { - DIR *dir; - int ret; + int fd; + int ret; - dir = opendir(path); - if (dir == NULL) - return -errno; + fd = open(path, O_RDONLY | O_DIRECTORY); + if (fd < 0) + return -errno; - ret = setup_obd_uuid(dir, path, param); - closedir(dir); + ret = setup_obd_uuid(fd, path, param); + close(fd); - return ret; + return ret; } /* @@ -2332,7 +2337,8 @@ void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name, /* show all information default */ if (!verbose) { if (lum->lum_magic == LMV_USER_MAGIC) - verbose = VERBOSE_POOL | VERBOSE_COUNT | VERBOSE_OFFSET; + verbose = VERBOSE_POOL | VERBOSE_COUNT | + VERBOSE_OFFSET | VERBOSE_HASH_TYPE; else verbose = VERBOSE_OBJID; } @@ -2358,6 +2364,24 @@ void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name, llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_offset: "); llapi_printf(LLAPI_MSG_NORMAL, "%d", (int)lum->lum_stripe_offset); + if (verbose & VERBOSE_HASH_TYPE) + separator = " "; + else + separator = "\n"; + } + + if (verbose & VERBOSE_HASH_TYPE) { + unsigned int type = lum->lum_hash_type; + + llapi_printf(LLAPI_MSG_NORMAL, "%s", separator); + if (verbose & ~VERBOSE_HASH_TYPE) + llapi_printf(LLAPI_MSG_NORMAL, "lmv_hash_type: "); + if (type < LMV_HASH_TYPE_MAX) + llapi_printf(LLAPI_MSG_NORMAL, "%s", + mdt_hash_name[type]); + else + llapi_printf(LLAPI_MSG_NORMAL, "%d", + (int)type); separator = "\n"; } @@ -2692,9 +2716,10 @@ static int print_failed_tgt(struct find_param *param, char *path, int type) { struct obd_statfs stat_buf; struct obd_uuid uuid_buf; - int ret; + int ret; - LASSERT(type == LL_STATFS_LOV || type == LL_STATFS_LMV); + if (type != LL_STATFS_LOV && type != LL_STATFS_LMV) + return -EINVAL; memset(&stat_buf, 0, sizeof(struct obd_statfs)); memset(&uuid_buf, 0, sizeof(struct obd_uuid)); @@ -2722,7 +2747,8 @@ static int cb_find_init(char *path, DIR *parent, DIR **dirp, int checked_type = 0; int ret = 0; - LASSERT(parent != NULL || dir != NULL); + if (parent == NULL && dir == NULL) + return -EINVAL; param->fp_lmd->lmd_lmm.lmm_stripe_count = 0; @@ -3058,7 +3084,9 @@ static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp, char *filename; bool retry = false; - LASSERT(parent != NULL || dirp != NULL); + if (parent == NULL && dirp == NULL) + return -EINVAL; + if (dirp != NULL) closedir(*dirp); @@ -3140,7 +3168,7 @@ int llapi_migrate_mdt(char *path, struct find_param *param) int llapi_mv(char *path, struct find_param *param) { -#if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 9, 53, 0) +#if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 9, 59, 0) static bool printed; if (!printed) { @@ -3177,7 +3205,8 @@ static int cb_get_mdt_index(char *path, DIR *parent, DIR **dirp, void *data, int ret; int mdtidx; - LASSERT(parent != NULL || d != NULL); + if (parent == NULL && d == NULL) + return -EINVAL; if (d != NULL) { ret = llapi_file_fget_mdtidx(dirfd(d), &mdtidx); @@ -3239,14 +3268,15 @@ static int cb_getstripe(char *path, DIR *parent, DIR **dirp, void *data, DIR *d = dirp == NULL ? NULL : *dirp; int ret = 0; - LASSERT(parent != NULL || d != NULL); + if (parent == NULL && d == NULL) + return -EINVAL; if (param->fp_obd_uuid) { param->fp_quiet = 1; - ret = setup_obd_uuid(d ? d : parent, path, param); - if (ret) - return ret; - } + ret = setup_obd_uuid(d ? dirfd(d) : dirfd(parent), path, param); + if (ret) + return ret; + } if (d) { if (param->fp_get_lmv || param->fp_get_default_lmv) { @@ -3532,7 +3562,7 @@ int llapi_is_lustre_mnt(struct mntent *mnt) int llapi_quotactl(char *mnt, struct if_quotactl *qctl) { char fsname[PATH_MAX + 1]; - DIR *root; + int root; int rc; rc = llapi_search_fsname(mnt, fsname); @@ -3542,19 +3572,19 @@ int llapi_quotactl(char *mnt, struct if_quotactl *qctl) return rc; } - root = opendir(mnt); - if (!root) { - rc = -errno; - llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt); - return rc; - } + root = open(mnt, O_RDONLY | O_DIRECTORY); + if (root < 0) { + rc = -errno; + llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt); + return rc; + } - rc = ioctl(dirfd(root), OBD_IOC_QUOTACTL, qctl); - if (rc < 0) - rc = -errno; + rc = ioctl(root, OBD_IOC_QUOTACTL, qctl); + if (rc < 0) + rc = -errno; - closedir(root); - return rc; + close(root); + return rc; } /* Print mdtname 'name' into 'buf' using 'format'. Add -MDT0000 if needed. @@ -3996,24 +4026,24 @@ int llapi_path2parent(const char *path, unsigned int linkno, int llapi_get_connect_flags(const char *mnt, __u64 *flags) { - DIR *root; - int rc; + int root; + int rc; - root = opendir(mnt); - if (!root) { - rc = -errno; - llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt); - return rc; - } + root = open(mnt, O_RDONLY | O_DIRECTORY); + if (root < 0) { + rc = -errno; + llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt); + return rc; + } - rc = ioctl(dirfd(root), LL_IOC_GET_CONNECT_FLAGS, flags); - if (rc < 0) { - rc = -errno; - llapi_error(LLAPI_MSG_ERROR, rc, - "ioctl on %s for getting connect flags failed", mnt); - } - closedir(root); - return rc; + rc = ioctl(root, LL_IOC_GET_CONNECT_FLAGS, flags); + if (rc < 0) { + rc = -errno; + llapi_error(LLAPI_MSG_ERROR, rc, + "ioctl on %s for getting connect flags failed", mnt); + } + close(root); + return rc; } /**