X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Fobd.c;h=05c64984800ad34dd881dc7efa1690dc8819a437;hb=9999d2d959e74f79be00e1708d0e53c5e600c47a;hp=37a9b8e7d1cc628e3259a4976b41ea218f992207;hpb=0c5fbd80f1ba60a1c6e523864d67a4d9dcf468e6;p=fs%2Flustre-release.git diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index 37a9b8e..05c6498 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -15,11 +15,7 @@ * * You should have received a copy of the GNU General Public License * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * http://www.gnu.org/licenses/gpl-2.0.html * * GPL HEADER END */ @@ -27,7 +23,7 @@ * Copyright (c) 2002, 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/ @@ -64,20 +60,23 @@ #include #include "obdctl.h" +#include "lustreapi_internal.h" +#include #include #include #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include -#include +#include +#include #define MAX_STRING_SIZE 128 @@ -1151,18 +1150,21 @@ int jt_obd_md_common(int argc, char **argv, int cmd) char *name = NULL; struct jt_fid_space fid_space = {0}; int version = 0; - struct option long_opts[] = { - {"child_base_id", required_argument, 0, 'b'}, - {"stripe_count", required_argument, 0, 'c'}, - {"parent_basedir", required_argument, 0, 'd'}, - {"parent_dircount", required_argument, 0, 'D'}, - {"stripe_index", required_argument, 0, 'i'}, - {"mode", required_argument, 0, 'm'}, - {"count", required_argument, 0, 'n'}, - {"time", required_argument, 0, 't'}, - {"version", no_argument, 0, 'v'}, - {0, 0, 0, 0} - }; + struct option long_opts[] = { + { .val = 'b', .name = "child_base_id", + .has_arg = required_argument }, + { .val = 'c', .name = "stripe_count", + .has_arg = required_argument }, + { .val = 'd', .name = "parent_basedir", + .has_arg = required_argument }, + { .val = 'D', .name = "parent_dircount", + .has_arg = required_argument }, + { .val = 'i', .name = "stripe_index", .has_arg = required_argument }, + { .val = 'm', .name = "mode", .has_arg = required_argument }, + { .val = 'n', .name = "count", .has_arg = required_argument }, + { .val = 't', .name = "time", .has_arg = required_argument }, + { .val = 'v', .name = "version", .has_arg = no_argument }, + { .name = NULL } }; while ((c = getopt_long(argc, argv, "b:c:d:D:m:n:t:v", long_opts, NULL)) >= 0) { @@ -1367,7 +1369,7 @@ int jt_obd_md_common(int argc, char **argv, int cmd) fprintf(stderr, "Allocate fids error %d.\n",rc); return rc; } - fid_to_ostid(&fid, &data.ioc_obdo1.o_oi); + data.ioc_obdo1.o_oi.oi_fid = fid; } child_base_id += data.ioc_count; @@ -1495,13 +1497,19 @@ int jt_obd_create(int argc, char **argv) ostid_set_seq_echo(&data.ioc_obdo1.o_oi); for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) { + /* + * base_id is 1 so we don't need to worry about it being + * greater than OBIF_MAX_OID + */ + data.ioc_obdo1.o_oi.oi_fid.f_oid = base_id; data.ioc_obdo1.o_mode = mode; - ostid_set_id(&data.ioc_obdo1.o_oi, base_id); data.ioc_obdo1.o_uid = 0; data.ioc_obdo1.o_gid = 0; + data.ioc_obdo1.o_projid = 0; data.ioc_obdo1.o_valid = OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLID | OBD_MD_FLUID | - OBD_MD_FLGID | OBD_MD_FLGROUP; + OBD_MD_FLGID | OBD_MD_FLGROUP | + OBD_MD_FLPROJID; memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); @@ -1536,30 +1544,42 @@ int jt_obd_create(int argc, char **argv) int jt_obd_setattr(int argc, char **argv) { - struct obd_ioctl_data data; - char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; - char *end; - int rc; + struct obd_ioctl_data data; + char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; + __u64 objid; + char *end; + int mode; + int rc; memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc != 2) return CMD_HELP; - ostid_set_seq_echo(&data.ioc_obdo1.o_oi); - ostid_set_id(&data.ioc_obdo1.o_oi, strtoull(argv[1], &end, 0)); - if (*end) { + objid = strtoull(argv[1], &end, 0); + if (*end) { + fprintf(stderr, "error: %s: objid '%s' is not a number\n", + jt_cmdname(argv[0]), argv[1]); + return CMD_HELP; + } + + if (objid >= OBIF_MAX_OID) { fprintf(stderr, "error: %s: invalid objid '%s'\n", jt_cmdname(argv[0]), argv[1]); return CMD_HELP; } - data.ioc_obdo1.o_mode = S_IFREG | strtoul(argv[2], &end, 0); + + mode = strtoul(argv[2], &end, 0); if (*end) { fprintf(stderr, "error: %s: invalid mode '%s'\n", jt_cmdname(argv[0]), argv[2]); return CMD_HELP; } - data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE; + + ostid_set_seq_echo(&data.ioc_obdo1.o_oi); + data.ioc_obdo1.o_mode = S_IFREG | mode; + data.ioc_obdo1.o_oi.oi_fid.f_oid = objid; + data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE; memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); @@ -1629,7 +1649,13 @@ int jt_obd_test_setattr(int argc, char **argv) ostid_set_seq_echo(&data.ioc_obdo1.o_oi); for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) { - ostid_set_id(&data.ioc_obdo1.o_oi, objid); + if (objid >= OBIF_MAX_OID) { + fprintf(stderr, "errr: %s: invalid objid '%llu'\n", + jt_cmdname(argv[0]), objid); + return -E2BIG; + } + + data.ioc_obdo1.o_oi.oi_fid.f_oid = objid; data.ioc_obdo1.o_mode = S_IFREG; data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE; memset(buf, 0, sizeof(rawbuf)); @@ -1715,7 +1741,13 @@ int jt_obd_destroy(int argc, char **argv) ostid_set_seq_echo(&data.ioc_obdo1.o_oi); for (i = 1, next_count = verbose; i <= count && shmem_running(); i++, id++) { - ostid_set_id(&data.ioc_obdo1.o_oi, id); + if (id >= OBIF_MAX_OID) { + fprintf(stderr, "errr: %s: invalid objid '%llu'\n", + jt_cmdname(argv[0]), id); + return -E2BIG; + } + + data.ioc_obdo1.o_oi.oi_fid.f_oid = id; data.ioc_obdo1.o_mode = S_IFREG | 0644; data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLMODE; @@ -1748,21 +1780,30 @@ int jt_obd_getattr(int argc, char **argv) { struct obd_ioctl_data data; char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; + __u64 objid; char *end; int rc; if (argc != 2) return CMD_HELP; - memset(&data, 0, sizeof(data)); - data.ioc_dev = cur_device; - ostid_set_seq_echo(&data.ioc_obdo1.o_oi); - ostid_set_id(&data.ioc_obdo1.o_oi, strtoull(argv[1], &end, 0)); + objid = strtoull(argv[1], &end, 0); if (*end) { + fprintf(stderr, "error: %s: objid '%s' is not a number\n", + jt_cmdname(argv[0]), argv[1]); + return CMD_HELP; + } + + if (objid >= OBIF_MAX_OID) { fprintf(stderr, "error: %s: invalid objid '%s'\n", jt_cmdname(argv[0]), argv[1]); return CMD_HELP; } + + memset(&data, 0, sizeof(data)); + data.ioc_dev = cur_device; + ostid_set_seq_echo(&data.ioc_obdo1.o_oi); + data.ioc_obdo1.o_oi.oi_fid.f_oid = objid; /* to help obd filter */ data.ioc_obdo1.o_mode = 0100644; data.ioc_obdo1.o_valid = 0xffffffff; @@ -1842,7 +1883,13 @@ int jt_obd_test_getattr(int argc, char **argv) ostid_set_seq_echo(&data.ioc_obdo1.o_oi); for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) { - ostid_set_id(&data.ioc_obdo1.o_oi, objid); + if (objid >= OBIF_MAX_OID) { + fprintf(stderr, "errr: %s: invalid objid '%llu'\n", + jt_cmdname(argv[0]), objid); + return -E2BIG; + } + + data.ioc_obdo1.o_oi.oi_fid.f_oid = objid; data.ioc_obdo1.o_mode = S_IFREG; data.ioc_obdo1.o_valid = 0xffffffff; memset(buf, 0, sizeof(rawbuf)); @@ -2049,7 +2096,13 @@ int jt_obd_test_brw(int argc, char **argv) #endif ostid_set_seq_echo(&data.ioc_obdo1.o_oi); - ostid_set_id(&data.ioc_obdo1.o_oi, objid); + if (objid >= OBIF_MAX_OID) { + fprintf(stderr, "errr: %s: invalid objid '%llu'\n", + jt_cmdname(argv[0]), objid); + return -E2BIG; + } + + data.ioc_obdo1.o_oi.oi_fid.f_oid = objid; data.ioc_obdo1.o_mode = S_IFREG; data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLFLAGS | OBD_MD_FLGROUP; @@ -2423,6 +2476,73 @@ int jt_obd_mdc_lookup(int argc, char **argv) return rc; } +int jt_lcfg_fork(int argc, char **argv) +{ + struct obd_ioctl_data data; + char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; + int rc; + + if (argc != 3) + return CMD_HELP; + + memset(&data, 0, sizeof(data)); + data.ioc_dev = get_mgs_device(); + data.ioc_inllen1 = strlen(argv[1]) + 1; + data.ioc_inlbuf1 = argv[1]; + data.ioc_inllen2 = strlen(argv[2]) + 1; + data.ioc_inlbuf2 = argv[2]; + + memset(buf, 0, sizeof(rawbuf)); + rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); + if (rc) { + fprintf(stderr, "error: %s: invalid ioctl\n", + jt_cmdname(argv[0])); + return rc; + } + + rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LCFG_FORK, buf); + if (rc < 0) + fprintf(stderr, "error: %s: OBD_IOC_LCFG_FORK failed: %s\n", + jt_cmdname(argv[0]), strerror(errno)); + + return rc; +} + +int jt_lcfg_erase(int argc, char **argv) +{ + struct obd_ioctl_data data; + char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; + int rc; + + if (argc == 3) { + if (strncmp(argv[2], "-q", strlen("-q")) != 0 && + strncmp(argv[2], "--quiet", strlen("--quiet")) != 0) + return CMD_HELP; + } else if (argc != 2) { + return CMD_HELP; + } + + memset(&data, 0, sizeof(data)); + data.ioc_dev = get_mgs_device(); + data.ioc_inllen1 = strlen(argv[1]) + 1; + data.ioc_inlbuf1 = argv[1]; + + memset(buf, 0, sizeof(rawbuf)); + rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); + if (rc) { + fprintf(stderr, "error: %s: invalid ioctl\n", + jt_cmdname(argv[0])); + return rc; + } + + rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LCFG_ERASE, buf); + if (rc < 0) + fprintf(stderr, "error: %s: OBD_IOC_LCFG_ERASE failed: %s\n", + jt_cmdname(argv[0]), strerror(errno)); + + return rc; +} + int jt_llog_catlist(int argc, char **argv) { struct obd_ioctl_data data; @@ -2536,14 +2656,13 @@ static int llog_cancel_parse_optional(int argc, char **argv, struct obd_ioctl_data *data) { int cOpt; - const char *const short_options = "c:l:i:h"; - const struct option long_options[] = { - {"catalog", required_argument, NULL, 'c'}, - {"log_id", required_argument, NULL, 'l'}, - {"log_idx", required_argument, NULL, 'i'}, - {"help", no_argument, NULL, 'h'}, - {NULL, 0, NULL, 0} - }; + const char *const short_opts = "c:l:i:h"; + const struct option long_opts[] = { + { .val = 'c', .name = "catalog", .has_arg = required_argument }, + { .val = 'h', .name = "help", .has_arg = no_argument }, + { .val = 'i', .name = "log_idx", .has_arg = required_argument }, + { .val = 'l', .name = "log_id", .has_arg = required_argument }, + { .name = NULL } }; /* sanity check */ if (!data || argc <= 1) { @@ -2551,8 +2670,8 @@ static int llog_cancel_parse_optional(int argc, char **argv, } /*now process command line arguments*/ - while ((cOpt = getopt_long(argc, argv, short_options, - long_options, NULL)) != -1) { + while ((cOpt = getopt_long(argc, argv, short_opts, + long_opts, NULL)) != -1) { switch (cOpt) { case 'c': data->ioc_inllen1 = strlen(optarg) + 1; @@ -2729,208 +2848,6 @@ int jt_llog_remove(int argc, char **argv) return rc; } -/* attach a regular file to virtual block device. - * return vaule: - * -1: fatal error - * 1: error, it always means the command run failed - * 0: success - */ -static int jt_blockdev_run_process(const char *file, char *argv[]) -{ - pid_t pid; - int rc; - - pid = vfork(); - if (pid == 0) { /* child process */ - /* don't print error messages */ - close(1), close(2); - (void)execvp(file, argv); - exit(-1); - } else if (pid > 0) { - int status; - - rc = waitpid(pid, &status, 0); - if (rc < 0 || !WIFEXITED(status)) - return -1; - - return WEXITSTATUS(status); - } - - return -1; -} - -static int jt_blockdev_find_module(const char *module) -{ - FILE *fp; - int found = 0; - char buf[1024]; - char *ptr; - - fp = fopen("/proc/modules", "r"); - if (fp == NULL) - return -1; - - while (fgets(buf, 1024, fp) != NULL) { - ptr = strchr(buf, ' '); - if (ptr != NULL) - *ptr = 0; - if (strcmp(module, buf) == 0) { - found = 1; - break; - } - } - fclose(fp); - - return found; -} - -static int jt_blockdev_probe_module(const char *module) -{ - char buf[1024]; - char *argv[10]; - int c, rc; - - if (jt_blockdev_find_module(module) == 1) - return 0; - - /* run modprobe first */ - c = 0; - argv[c++] = "/sbin/modprobe"; - argv[c++] = "-q"; - argv[c++] = (char *)module; - argv[c++] = NULL; - rc = jt_blockdev_run_process("modprobe", argv); - if (rc != 1) - return rc; - - /* cannot find the module in default directory ... */ - sprintf(buf, "../llite/%s.ko", module); - c = 0; - argv[c++] = "/sbin/insmod"; - argv[c++] = buf; - argv[c++] = NULL; - rc = jt_blockdev_run_process("insmod", argv); - return rc ? -1 : 0; -} - -int jt_blockdev_attach(int argc, char **argv) -{ - int rc, fd; - struct stat st; - char *filename, *devname; - unsigned long dev; - - if (argc != 3) - return CMD_HELP; - - if (jt_blockdev_probe_module("llite_lloop") < 0) { - fprintf(stderr, "error: cannot find module llite_lloop.(k)o\n"); - return ENOENT; - } - - filename = argv[1]; - devname = argv[2]; - - fd = open(filename, O_RDWR); - if (fd < 0) { - fprintf(stderr, "file %s can't be opened(%s)\n\n", - filename, strerror(errno)); - return CMD_HELP; - } - - rc = ioctl(fd, LL_IOC_LLOOP_ATTACH, &dev); - if (rc < 0) { - rc = errno; - fprintf(stderr, "attach error(%s)\n", strerror(rc)); - goto out; - } - - rc = stat(devname, &st); - if (rc == 0 && (!S_ISBLK(st.st_mode) || st.st_rdev != dev)) { - rc = EEXIST; - } else if (rc < 0) { - if (errno == ENOENT && - !mknod(devname, S_IFBLK|S_IRUSR|S_IWUSR, dev)) - rc = 0; - else - rc = errno; - } - - if (rc) { - fprintf(stderr, "error: the file %s could be attached to block " - "device %X but creating %s failed: %s\n" - "now detaching the block device..", - filename, (int)dev, devname, strerror(rc)); - - (void)ioctl(fd, LL_IOC_LLOOP_DETACH_BYDEV, dev); - fprintf(stderr, "%s\n", strerror(errno)); - } -out: - close(fd); - return -rc; -} - -int jt_blockdev_detach(int argc, char **argv) -{ - char *filename; - int rc, fd; - - if (argc != 2) - return CMD_HELP; - - filename = argv[1]; - fd = open(filename, O_RDONLY); - if (fd < 0) { - fprintf(stderr, "cannot open file %s error %s\n", - filename, strerror(errno)); - return CMD_HELP; - } - - rc = ioctl(fd, LL_IOC_LLOOP_DETACH, 0); - if (rc < 0) { - rc = errno; - fprintf(stderr, "detach error(%s)\n", strerror(rc)); - } else { - (void)unlink(filename); - } - - close(fd); - return -rc; -} - -int jt_blockdev_info(int argc, char **argv) -{ - char *filename; - int rc, fd; - struct lu_fid fid; - - if (argc != 2) - return CMD_HELP; - - filename = argv[1]; - fd = open(filename, O_RDONLY); - if (fd < 0) { - fprintf(stderr, "cannot open file %s error: %s\n", - filename, strerror(errno)); - return CMD_HELP; - } - - rc = ioctl(fd, LL_IOC_LLOOP_INFO, &fid); - if (rc < 0) { - rc = errno; - fprintf(stderr, "error: %s\n", strerror(errno)); - goto out; - } - fprintf(stdout, "lloop device info: "); - if (fid_is_zero(&fid)) - fprintf(stdout, "Not attached\n"); - else - fprintf(stdout, "attached to inode "DFID"\n", PFID(&fid)); -out: - close(fd); - return -rc; -} - static void signal_server(int sig) { if (sig == SIGINT) { @@ -2981,7 +2898,9 @@ static int check_pool_cmd(enum lcfg_command_type cmd, switch (cmd) { case LCFG_POOL_NEW: { - LASSERT(ostname == NULL); + if (ostname != NULL) + return -EINVAL; + if (rc >= 0) { fprintf(stderr, "Pool %s.%s already exists\n", fsname, poolname); @@ -2990,7 +2909,9 @@ static int check_pool_cmd(enum lcfg_command_type cmd, return 0; } case LCFG_POOL_DEL: { - LASSERT(ostname == NULL); + if (ostname != NULL) + return -EINVAL; + if (rc == 1) { fprintf(stderr, "Pool %s.%s not empty, " "please remove all members\n", @@ -3198,9 +3119,11 @@ static int pool_cmd(enum lcfg_command_type cmd, if (ostname != NULL) lustre_cfg_bufs_set_string(&bufs, 2, ostname); - lcfg = lustre_cfg_new(cmd, &bufs); + + lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen)); if (lcfg == NULL) return -ENOMEM; + lustre_cfg_init(lcfg, cmd, &bufs); memset(&data, 0, sizeof(data)); rc = data.ioc_dev = get_mgs_device(); @@ -3217,14 +3140,14 @@ static int pool_cmd(enum lcfg_command_type cmd, if (rc) { fprintf(stderr, "error: %s: invalid ioctl\n", jt_cmdname(cmdname)); - lustre_cfg_free(lcfg); + free(lcfg); return rc; } rc = l_ioctl(OBD_DEV_ID, OBD_IOC_POOL, buf); out: if (rc) rc = -errno; - lustre_cfg_free(lcfg); + free(lcfg); return rc; } @@ -3264,9 +3187,10 @@ static int nodemap_cmd(enum lcfg_command_type cmd, void *ret_data, } va_end(ap); - lcfg = lustre_cfg_new(cmd, &bufs); + lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen)); if (lcfg == NULL) return -ENOMEM; + lustre_cfg_init(lcfg, cmd, &bufs); memset(&data, 0, sizeof(data)); rc = data.ioc_dev = get_mgs_device(); @@ -3304,7 +3228,7 @@ static int nodemap_cmd(enum lcfg_command_type cmd, void *ret_data, memcpy(ret_data, data.ioc_pbuf1, ret_size); } out: - lustre_cfg_free(lcfg); + free(lcfg); return rc; } @@ -3514,28 +3438,15 @@ int jt_nodemap_add_range(int argc, char **argv) int rc = 0; int c; - static struct option long_options[] = { - { - .name = "name", - .has_arg = required_argument, - .flag = 0, - .val = 'n', - }, - { - .name = "range", - .has_arg = required_argument, - .flag = 0, - .val = 'r', - }, - { - NULL - } - }; + static struct option long_opts[] = { + { .val = 'n', .name = "name", .has_arg = required_argument }, + { .val = 'r', .name = "range", .has_arg = required_argument }, + { .name = NULL } }; INIT_LIST_HEAD(&nidlist); while ((c = getopt_long(argc, argv, "n:r:", - long_options, NULL)) != -1) { + long_opts, NULL)) != -1) { switch (c) { case 'n': nodemap_name = optarg; @@ -3688,26 +3599,13 @@ int jt_nodemap_set_fileset(int argc, char **argv) int rc = 0; int c; - static struct option long_options[] = { - { - .name = "name", - .has_arg = required_argument, - .flag = 0, - .val = 'n', - }, - { - .name = "fileset", - .has_arg = required_argument, - .flag = 0, - .val = 'f', - }, - { - NULL - } - }; + static struct option long_opts[] = { + { .val = 'f', .name = "fileset", .has_arg = required_argument }, + { .val = 'n', .name = "name", .has_arg = required_argument }, + { .name = NULL } }; while ((c = getopt_long(argc, argv, "n:f:", - long_options, NULL)) != -1) { + long_opts, NULL)) != -1) { switch (c) { case 'n': nodemap_name = optarg; @@ -3758,32 +3656,14 @@ int jt_nodemap_modify(int argc, char **argv) char *param = NULL; char *value = NULL; - static struct option long_options[] = { - { - .name = "name", - .has_arg = required_argument, - .flag = 0, - .val = 'n', - }, - { - .name = "property", - .has_arg = required_argument, - .flag = 0, - .val = 'p', - }, - { - .name = "value", - .has_arg = required_argument, - .flag = 0, - .val = 'v', - }, - { - NULL - } - }; + static struct option long_opts[] = { + { .val = 'n', .name = "name", .has_arg = required_argument }, + { .val = 'p', .name = "property", .has_arg = required_argument }, + { .val = 'v', .name = "value", .has_arg = required_argument }, + { .name = NULL } }; while ((c = getopt_long(argc, argv, "n:p:v:", - long_options, NULL)) != -1) { + long_opts, NULL)) != -1) { switch (c) { case 'n': nodemap_name = optarg; @@ -3800,8 +3680,8 @@ int jt_nodemap_modify(int argc, char **argv) if (nodemap_name == NULL || param == NULL || value == NULL) { fprintf(stderr, "usage: nodemap_modify --name " "--property --value \n"); - fprintf(stderr, "valid properties: admin trusted " - "squash_uid squash_gid\n"); + fprintf(stderr, "valid properties: admin trusted map_mode " + "squash_uid squash_gid deny_unknown\n"); return -1; } @@ -3809,10 +3689,14 @@ int jt_nodemap_modify(int argc, char **argv) cmd = LCFG_NODEMAP_ADMIN; } else if (strcmp("trusted", param) == 0) { cmd = LCFG_NODEMAP_TRUSTED; + } else if (strcmp("deny_unknown", param) == 0) { + cmd = LCFG_NODEMAP_DENY_UNKNOWN; } else if (strcmp("squash_uid", param) == 0) { cmd = LCFG_NODEMAP_SQUASH_UID; } else if (strcmp("squash_gid", param) == 0) { cmd = LCFG_NODEMAP_SQUASH_GID; + } else if (strcmp("map_mode", param) == 0) { + cmd = LCFG_NODEMAP_MAP_MODE; } else { fprintf(stderr, "error: %s: nodemap_modify invalid " "subcommand: %s\n", @@ -3841,32 +3725,14 @@ int jt_nodemap_add_idmap(int argc, char **argv) char *idtype = NULL; int rc = 0; - static struct option long_options[] = { - { - .name = "name", - .has_arg = required_argument, - .flag = 0, - .val = 'n', - }, - { - .name = "idmap", - .has_arg = required_argument, - .flag = 0, - .val = 'm', - }, - { - .name = "idtype", - .has_arg = required_argument, - .flag = 0, - .val = 'i', - }, - { - NULL - } - }; + static struct option long_opts[] = { + { .val = 'i', .name = "idtype", .has_arg = required_argument }, + { .val = 'm', .name = "idmap", .has_arg = required_argument }, + { .val = 'n', .name = "name", .has_arg = required_argument }, + { .name = NULL } }; while ((c = getopt_long(argc, argv, "n:m:i:", - long_options, NULL)) != -1) { + long_opts, NULL)) != -1) { switch (c) { case 'n': nodemap_name = optarg; @@ -3915,32 +3781,14 @@ int jt_nodemap_del_idmap(int argc, char **argv) char *idtype = NULL; int rc = 0; - static struct option long_options[] = { - { - .name = "name", - .has_arg = required_argument, - .flag = 0, - .val = 'n', - }, - { - .name = "idmap", - .has_arg = required_argument, - .flag = 0, - .val = 'm', - }, - { - .name = "idtype", - .has_arg = required_argument, - .flag = 0, - .val = 'i', - }, - { - NULL - } - }; + static struct option long_opts[] = { + { .val = 'i', .name = "idtype", .has_arg = required_argument }, + { .val = 'm', .name = "idmap", .has_arg = required_argument }, + { .val = 'n', .name = "name", .has_arg = required_argument }, + { .name = NULL } }; while ((c = getopt_long(argc, argv, "n:m:i:", - long_options, NULL)) != -1) { + long_opts, NULL)) != -1) { switch (c) { case 'n': nodemap_name = optarg; @@ -4088,35 +3936,10 @@ static int extract_fsname_poolname(const char *arg, char *fsname, *ptr = '\0'; ++ptr; - rc = lustre_is_fsname_valid(fsname, 1, LUSTRE_MAXFSNAME); - if (rc < 0) { - fprintf(stderr, "filesystem name %s must be 1-%d chars\n", - fsname, LUSTRE_MAXFSNAME); - rc = -EINVAL; - goto err; - } else if (rc > 0) { - fprintf(stderr, "char '%c' not allowed in filesystem name\n", - rc); - rc = -EINVAL; - goto err; - } - - rc = lustre_is_poolname_valid(ptr, 1, LOV_MAXPOOLNAME); - if (rc == -1) { + if (strlen(ptr) == 0) { fprintf(stderr, "poolname is empty\n"); rc = -EINVAL; goto err; - } else if (rc == -2) { - fprintf(stderr, - "poolname %s is too long (max is %d)\n", - ptr, LOV_MAXPOOLNAME); - rc = -ENAMETOOLONG; - goto err; - } else if (rc > 0) { - fprintf(stderr, "char '%c' not allowed in pool name '%s'\n", - rc, ptr); - rc = -EINVAL; - goto err; } strncpy(poolname, ptr, LOV_MAXPOOLNAME); @@ -4263,6 +4086,236 @@ out: return rc; } +static const char *barrier_status2name(enum barrier_status status) +{ + switch (status) { + case BS_INIT: + return "init"; + case BS_FREEZING_P1: + return "freezing_p1"; + case BS_FREEZING_P2: + return "freezing_p2"; + case BS_FROZEN: + return "frozen"; + case BS_THAWING: + return "thawing"; + case BS_THAWED: + return "thawed"; + case BS_FAILED: + return "failed"; + case BS_EXPIRED: + return "expired"; + case BS_RESCAN: + return "rescan"; + default: + return "unknown"; + } +} + +int jt_barrier_freeze(int argc, char **argv) +{ + struct obd_ioctl_data data; + char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; + struct barrier_ctl bc; + int rc; + + if (argc < 2 || argc > 3) + return CMD_HELP; + + memset(&data, 0, sizeof(data)); + rc = data.ioc_dev = get_mgs_device(); + if (rc < 0) + return rc; + + memset(&bc, 0, sizeof(bc)); + bc.bc_version = BARRIER_VERSION_V1; + bc.bc_cmd = BC_FREEZE; + if (argc == 3) + bc.bc_timeout = atoi(argv[2]); + if (bc.bc_timeout == 0) + bc.bc_timeout = BARRIER_TIMEOUT_DEFAULT; + + if (strlen(argv[1]) > 8) { + fprintf(stderr, "%s: fsname name %s is too long. " + "It should not exceed 8.\n", argv[0], argv[1]); + return -EINVAL; + } + + strncpy(bc.bc_name, argv[1], sizeof(bc.bc_name)); + data.ioc_inlbuf1 = (char *)&bc; + data.ioc_inllen1 = sizeof(bc); + memset(buf, 0, sizeof(rawbuf)); + rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); + if (rc) { + fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc); + return rc; + } + + rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf); + if (rc < 0) + fprintf(stderr, "Fail to freeze barrier for %s: %s\n", + argv[1], strerror(errno)); + + return rc; +} + +int jt_barrier_thaw(int argc, char **argv) +{ + struct obd_ioctl_data data; + char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; + struct barrier_ctl bc; + int rc; + + if (argc != 2) + return CMD_HELP; + + memset(&data, 0, sizeof(data)); + rc = data.ioc_dev = get_mgs_device(); + if (rc < 0) + return rc; + + memset(&bc, 0, sizeof(bc)); + bc.bc_version = BARRIER_VERSION_V1; + bc.bc_cmd = BC_THAW; + + if (strlen(argv[1]) > 8) { + fprintf(stderr, "fsname name %s is too long. " + "It should not exceed 8.\n", argv[1]); + return -EINVAL; + } + + strncpy(bc.bc_name, argv[1], sizeof(bc.bc_name)); + data.ioc_inlbuf1 = (char *)&bc; + data.ioc_inllen1 = sizeof(bc); + memset(buf, 0, sizeof(rawbuf)); + rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); + if (rc) { + fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc); + return rc; + } + + rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf); + if (rc < 0) + fprintf(stderr, "Fail to thaw barrier for %s: %s\n", + argv[1], strerror(errno)); + + return rc; +} + +int __jt_barrier_stat(int argc, char **argv, struct barrier_ctl *bc) +{ + struct obd_ioctl_data data; + char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; + int rc; + + memset(&data, 0, sizeof(data)); + rc = data.ioc_dev = get_mgs_device(); + if (rc < 0) + return rc; + + memset(bc, 0, sizeof(*bc)); + bc->bc_version = BARRIER_VERSION_V1; + bc->bc_cmd = BC_STAT; + strncpy(bc->bc_name, argv[1], sizeof(bc->bc_name)); + data.ioc_inlbuf1 = (char *)bc; + data.ioc_inllen1 = sizeof(*bc); + memset(buf, 0, sizeof(rawbuf)); + rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); + if (rc) { + fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc); + return rc; + } + + rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf); + if (rc < 0) + fprintf(stderr, "Fail to query barrier for %s: %s\n", + argv[1], strerror(errno)); + else + obd_ioctl_unpack(&data, buf, sizeof(rawbuf)); + + return rc; +} + +int jt_barrier_stat(int argc, char **argv) +{ + struct barrier_ctl bc; + int rc; + + if (argc != 2) + return CMD_HELP; + + if (strlen(argv[1]) > 8) { + fprintf(stderr, "fsname name %s is too long. " + "It should not exceed 8.\n", argv[1]); + return -EINVAL; + } + + rc = __jt_barrier_stat(argc, argv, &bc); + if (!rc) { + printf("The barrier for %s is in '%s'\n", + argv[1], barrier_status2name(bc.bc_status)); + if (bc.bc_status == BS_FREEZING_P1 || + bc.bc_status == BS_FREEZING_P2 || + bc.bc_status == BS_FROZEN) + printf("The barrier will be expired after %d " + "seconds\n", bc.bc_timeout); + } + + return rc; +} + +int jt_barrier_rescan(int argc, char **argv) +{ + struct obd_ioctl_data data; + char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; + struct barrier_ctl bc; + int rc; + + if (argc < 2 || argc > 3) + return CMD_HELP; + + memset(&data, 0, sizeof(data)); + rc = data.ioc_dev = get_mgs_device(); + if (rc < 0) + return rc; + + memset(&bc, 0, sizeof(bc)); + bc.bc_version = BARRIER_VERSION_V1; + bc.bc_cmd = BC_RESCAN; + if (argc == 3) + bc.bc_timeout = atoi(argv[2]); + if (bc.bc_timeout == 0) + bc.bc_timeout = BARRIER_TIMEOUT_DEFAULT; + + if (strlen(argv[1]) > 8) { + fprintf(stderr, "fsname name %s is too long. " + "It should not exceed 8.\n", argv[1]); + return -EINVAL; + } + + strncpy(bc.bc_name, argv[1], sizeof(bc.bc_name)); + data.ioc_inlbuf1 = (char *)&bc; + data.ioc_inllen1 = sizeof(bc); + memset(buf, 0, sizeof(rawbuf)); + rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); + if (rc) { + fprintf(stderr, "Fail to pack ioctl data: rc = %d.\n", rc); + return rc; + } + + rc = l_ioctl(OBD_DEV_ID, OBD_IOC_BARRIER, buf); + if (rc < 0) { + fprintf(stderr, "Fail to rescan barrier bitmap for %s: %s\n", + argv[1], strerror(errno)); + } else { + obd_ioctl_unpack(&data, buf, sizeof(rawbuf)); + printf("%u of %u MDT(s) in the filesystem %s are inactive\n", + bc.bc_absence, bc.bc_total, argv[1]); + } + + return rc; +} + int jt_get_obj_version(int argc, char **argv) { struct lu_fid fid;