*
* 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
*/
* 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/
#include <limits.h>
#include "obdctl.h"
+#include <libcfs/util/list.h>
#include <libcfs/util/ioctl.h>
#include <libcfs/util/param.h>
#include <libcfs/util/parser.h>
#include <libcfs/util/string.h>
#include <lnet/nidstr.h>
-#include <lustre/lustre_idl.h>
+#include <lustre/lustre_ostid.h>
#include <lustre_cfg.h>
#include <lustre_ioctl.h>
#include <lustre_ver.h>
#include <lnet/lnetctl.h>
#include <lustre/lustreapi.h>
#include <lustre_param.h>
+#include <lustre/lustre_barrier_user.h>
#define MAX_STRING_SIZE 128
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));
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;
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) {
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);
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",
if (nodemap_name == NULL || param == NULL || value == NULL) {
fprintf(stderr, "usage: nodemap_modify --name <nodemap_name> "
"--property <property_name> --value <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;
}
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",
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;