*
* 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, 2017, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#include <limits.h>
#include "obdctl.h"
+#include "lustreapi_internal.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_cfg.h>
-#include <lustre_ioctl.h>
-#include <lustre_ver.h>
+#include <linux/lnet/nidstr.h>
+#include <linux/lnet/lnetctl.h>
+#include <linux/lustre/lustre_barrier_user.h>
+#include <linux/lustre/lustre_cfg.h>
+#include <linux/lustre/lustre_ioctl.h>
+#include <linux/lustre/lustre_ostid.h>
+#include <linux/lustre/lustre_param.h>
+#include <linux/lustre/lustre_ver.h>
-#include <lnet/lnetctl.h>
#include <lustre/lustreapi.h>
-#include <lustre_param.h>
#define MAX_STRING_SIZE 128
lcfg->lcfg_buflens);
data.ioc_pbuf1 = (void *)lcfg;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(func));
lcfg->lcfg_buflens);
data.ioc_pbuf1 = (void *)lcfg;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(func));
data.ioc_inlbuf1 = name;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc < 0) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(func));
rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_NAME2DEV, buf);
if (rc < 0)
return errno;
- rc = obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
+ rc = llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid reply\n",
jt_cmdname(func));
*/
int parse_devname(char *func, char *name)
{
- int rc;
- int ret = -1;
+ int rc;
+ int ret = -1;
+ int try_digit;
+
+ if (!name)
+ return ret;
- if (!name)
- return ret;
- if (isdigit(name[0])) {
+ try_digit = isdigit(name[0]);
+
+ if (name[0] == '$' || name[0] == '%')
+ name++;
+
+ rc = do_name2dev(func, name);
+ if (rc >= N2D_OFF)
+ return rc - N2D_OFF;
+
+ if (try_digit)
ret = strtoul(name, NULL, 0);
- } else {
- if (name[0] == '$' || name[0] == '%')
- name++;
- rc = do_name2dev(func, name);
- if (rc >= N2D_OFF) {
- ret = rc - N2D_OFF;
- // printf("Name %s is device %d\n", name, ret);
- } else {
- fprintf(stderr, "No device found for name %s: %s\n",
+ else
+ fprintf(stderr, "No device found for name %s: %s\n",
name, strerror(rc));
- }
- }
return ret;
}
return CMD_HELP;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
return CMD_HELP;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
return CMD_HELP;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
memset(buf, 0, sizeof(rawbuf));
data->ioc_version = OBD_IOCTL_VERSION;
data->ioc_inllen1 =
- sizeof(rawbuf) - cfs_size_round(sizeof(*data));
- data->ioc_inlbuf1 = buf + cfs_size_round(sizeof(*data));
+ sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(*data), 8);
+ data->ioc_inlbuf1 = buf + __ALIGN_KERNEL(sizeof(*data), 8);
data->ioc_len = obd_ioctl_packlen(data);
data->ioc_count = index;
data.ioc_plen2 = sizeof(max_count);
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: invalid ioctl rc = %d\n", rc);
return rc;
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) {
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;
count += data.ioc_count;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl %d\n",
jt_cmdname(argv[0]), rc);
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));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
return rc;
}
rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_CREATE, buf);
- obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
+ llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
shmem_bump(1);
if (rc < 0) {
fprintf(stderr, "error: %s: #%d - %s\n",
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));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
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));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
if (argc < 2 || argc > 4)
return CMD_HELP;
+ errno = 0;
id = strtoull(argv[1], &end, 0);
if (*end || id == 0 || errno != 0) {
fprintf(stderr, "error: %s: invalid objid '%s'\n",
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;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
return rc;
}
rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_DESTROY, buf);
- obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
+ llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
shmem_bump(1);
if (rc < 0) {
fprintf(stderr, "error: %s: objid %#jx: %s\n",
{
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;
(uintmax_t)ostid_id(&data.ioc_obdo1.o_oi));
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
return rc;
}
rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_GETATTR, buf);
- obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
+ llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
strerror(rc = errno));
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));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
#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;
for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
data.ioc_obdo1.o_valid &= ~(OBD_MD_FLBLOCKS|OBD_MD_FLGRANT);
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
memset(&desc, 0, sizeof(desc));
obd_str2uuid(&desc.ld_uuid, argv[1]);
- desc.ld_tgt_count = ((OBD_MAX_IOCTL_BUFFER-sizeof(data)-sizeof(desc)) /
+ desc.ld_tgt_count = ((MAX_IOC_BUFLEN-sizeof(data)-sizeof(desc)) /
(sizeof(*uuidarray) + sizeof(*obdgens)));
repeat:
data.ioc_inllen3 = desc.ld_tgt_count * sizeof(*obdgens);
data.ioc_inlbuf3 = (char *)obdgens;
- if (obd_ioctl_pack(&data, &buf, sizeof(rawbuf))) {
+ if (llapi_ioctl_pack(&data, &buf, sizeof(rawbuf))) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
rc = -EINVAL;
__u32 *genp;
int i;
- if (obd_ioctl_unpack(&data, buf, sizeof(rawbuf))) {
+ if (llapi_ioctl_unpack(&data, buf, sizeof(rawbuf))) {
fprintf(stderr, "error: %s: invalid reply\n",
jt_cmdname(argv[0]));
rc = -EINVAL;
data.ioc_offset = flag;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
* are skipped and recorded with new nids and uuid.
*
* \see mgs_replace_nids
- * \see mgs_replace_nids_log
- * \see mgs_replace_handler
+ * \see mgs_replace_log
+ * \see mgs_replace_nids_handler
*/
int jt_replace_nids(int argc, char **argv)
{
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));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
return rc;
}
+/**
+ * Clear config logs for given device or filesystem.
+ * lctl clear_conf <devicename|fsname>
+ * Command has to be run on MGS node having MGS device mounted with -o
+ * nosvc.
+ *
+ * Configuration logs for filesystem or one particular log is
+ * processed. New log is created, original log is read, its records
+ * marked SKIP do not get copied to new log. Others are copied as-is.
+ * Original file is renamed to log.${time}.bak.
+ *
+ * \see mgs_clear_configs
+ * \see mgs_replace_log
+ * \see mgs_clear_config_handler
+ **/
+int jt_lcfg_clear(int argc, char **argv)
+{
+ int rc;
+ char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
+ struct obd_ioctl_data data;
+
+ memset(&data, 0, sizeof(data));
+ data.ioc_dev = get_mgs_device();
+ if (argc != 2)
+ return CMD_HELP;
+
+ data.ioc_inllen1 = strlen(argv[1]) + 1;
+ data.ioc_inlbuf1 = argv[1];
+
+ memset(buf, 0, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ if (rc) {
+ fprintf(stderr, "error: %s: invalid ioctl\n",
+ jt_cmdname(argv[0]));
+ return rc;
+ }
+
+ rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_CLEAR_CONFIGS, buf);
+ if (rc < 0) {
+ fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
+ strerror(rc = errno));
+ }
+
+ return rc;
+}
+
int jt_obd_deactivate(int argc, char **argv)
{
return do_activate(argc, argv, 0);
}
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
data.ioc_inlbuf1 = child;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
close(fd);
if (verbose) {
- rc = obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
+ rc = llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid reply\n",
jt_cmdname(argv[0]));
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 = llapi_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 = llapi_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;
memset(&data, 0, sizeof(data));
data.ioc_dev = cur_device;
- data.ioc_inllen1 = sizeof(rawbuf) - cfs_size_round(sizeof(data));
+ data.ioc_inllen1 = sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(data), 8);
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
data.ioc_dev = cur_device;
data.ioc_inllen1 = strlen(argv[1]) + 1;
data.ioc_inlbuf1 = argv[1];
- data.ioc_inllen2 = sizeof(rawbuf) - cfs_size_round(sizeof(data)) -
- cfs_size_round(data.ioc_inllen1);
+ data.ioc_inllen2 = sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(data), 8) -
+ __ALIGN_KERNEL(data.ioc_inllen1, 8);
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
data.ioc_inllen3 = strlen(to) + 1;
data.ioc_inlbuf3 = to;
}
- 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);
+ data.ioc_inllen4 = sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(data), 8) -
+ __ALIGN_KERNEL(data.ioc_inllen1, 8) -
+ __ALIGN_KERNEL(data.ioc_inllen2, 8) -
+ __ALIGN_KERNEL(data.ioc_inllen3, 8);
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
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) {
}
/*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;
}
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
data.ioc_inllen3 = strlen(to) + 1;
data.ioc_inlbuf3 = to;
}
- 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);
+ data.ioc_inllen4 = sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(data), 8) -
+ __ALIGN_KERNEL(data.ioc_inllen1, 8) -
+ __ALIGN_KERNEL(data.ioc_inllen2, 8) -
+ __ALIGN_KERNEL(data.ioc_inllen3, 8);
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
data.ioc_inlbuf2 = argv[2];
}
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
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) {
if (shmem_setup() != 0)
return -1;
- register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH,
- OBD_DEV_MAJOR, OBD_DEV_MINOR);
+ register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH);
return 0;
}
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 (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();
data.ioc_pbuf1 = (void *)lcfg;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
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);
- return rc;
+ switch (rc) {
+ case -ENAMETOOLONG:
+ fprintf(stderr, "error: %s: either the pool or file "
+ "system name is too long (max pool name len "
+ "is %d and file system name is %d)\n",
+ jt_cmdname(cmdname), LOV_MAXPOOLNAME,
+ LUSTRE_MAXFSNAME);
+ break;
+ case -EINVAL:
+ fprintf(stderr, "error: %s can contain only "
+ "alphanumeric characters, underscores, and "
+ "dashes besides the required '.'\n",
+ jt_cmdname(cmdname));
+ default:
+ break;
+ }
+ free(lcfg);
+ return rc;
}
/**
}
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();
data.ioc_pbuf1 = (void *)lcfg;
memset(buf, 0, sizeof(rawbuf));
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc != 0) {
fprintf(stderr, "error: invalid ioctl: %08x errno: %d with "
"rc=%d\n", cmd, errno, rc);
}
if (ret_data != NULL) {
- rc = obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
+ rc = llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
if (rc != 0)
goto out;
memcpy(ret_data, data.ioc_pbuf1, ret_size);
}
out:
- lustre_cfg_free(lcfg);
+ free(lcfg);
return rc;
}
int rc = 0;
int c;
- static struct option long_options[] = {
- {
- .name = "nid",
- .has_arg = required_argument,
- .flag = 0,
- .val = 'n',
- },
- {
- .name = "idtype",
- .has_arg = required_argument,
- .flag = 0,
- .val = 't',
- },
- {
- .name = "id",
- .has_arg = required_argument,
- .flag = 0,
- .val = 'i',
- },
- {
- NULL
- }
- };
+ static struct option long_opts[] = {
+ { .val = 'i', .name = "id", .has_arg = required_argument },
+ { .val = 'n', .name = "nid", .has_arg = required_argument },
+ { .val = 't', .name = "idtype",
+ .has_arg = required_argument },
+ { .name = NULL } };
while ((c = getopt_long(argc, argv, "n:t:i:",
- long_options, NULL)) != -1) {
+ long_opts, NULL)) != -1) {
switch (c) {
case 'n':
nidstr = optarg;
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;
return -1;
}
- if (!cfs_nidrange_is_contiguous(&nidlist)) {
- fprintf(stderr, "error: %s: nodemap ranges must be "
- "contiguous\n", jt_cmdname(argv[0]));
- return -1;
+ rc = cfs_nidrange_find_min_max(&nidlist, &min_nid[0], &max_nid[0],
+ LNET_NIDSTR_SIZE);
+ if (rc < 0) {
+ errno = -rc;
+ if (rc == -EINVAL)
+ fprintf(stderr, "error: %s: nid range uses "
+ "currently unsupported features\n",
+ jt_cmdname(argv[0]));
+ else if (rc == -ERANGE)
+ fprintf(stderr, "error: %s: nodemap ranges must be "
+ "contiguous\n", jt_cmdname(argv[0]));
+
+ return rc;
}
- cfs_nidrange_find_min_max(&nidlist, &min_nid[0], &max_nid[0],
- LNET_NIDSTR_SIZE);
snprintf(nid_range, sizeof(nid_range), "%s:%s", min_nid, max_nid);
rc = nodemap_cmd(LCFG_NODEMAP_ADD_RANGE, NULL, 0, argv[0],
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;
return -1;
}
- if (!cfs_nidrange_is_contiguous(&nidlist)) {
- fprintf(stderr, "error: %s: nodemap ranges must be "
- "contiguous\n", jt_cmdname(argv[0]));
- return -1;
+ rc = cfs_nidrange_find_min_max(&nidlist, &min_nid[0], &max_nid[0],
+ LNET_NIDSTR_SIZE);
+ if (rc < 0) {
+ errno = -rc;
+ if (rc == -EINVAL)
+ fprintf(stderr, "error: %s: nid range uses "
+ "currently unsupported features\n",
+ jt_cmdname(argv[0]));
+ else if (rc == -ERANGE)
+ fprintf(stderr, "error: %s: nodemap ranges must be "
+ "contiguous\n", jt_cmdname(argv[0]));
+
+ return rc;
}
- cfs_nidrange_find_min_max(&nidlist, &min_nid[0], &max_nid[0],
- LNET_NIDSTR_SIZE);
snprintf(nid_range, sizeof(nid_range), "%s:%s", min_nid, max_nid);
rc = nodemap_cmd(LCFG_NODEMAP_DEL_RANGE, NULL, 0, argv[0],
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;
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;
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 deny_unknown\n");
+ fprintf(stderr, "valid properties: admin trusted map_mode "
+ "squash_uid squash_gid deny_unknown audit_mode\n");
return -1;
}
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 if (strcmp("audit_mode", param) == 0) {
+ cmd = LCFG_NODEMAP_AUDIT_MODE;
} else {
fprintf(stderr, "error: %s: nodemap_modify invalid "
"subcommand: %s\n",
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;
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;
char *ptr;
int rc;
- strlcpy(fsname, arg, PATH_MAX + 1);
+ snprintf(fsname, PATH_MAX + 1, "%s", arg);
ptr = strchr(fsname, '.');
if (ptr == NULL) {
fprintf(stderr, ". is missing in %s\n", 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);
poolname[LOV_MAXPOOLNAME] = '\0';
+
+ if (strncmp(poolname, "none", LOV_MAXPOOLNAME) == 0) {
+ fprintf(stderr, "poolname cannot be 'none'\n");
+ return -EINVAL;
+ }
return 0;
err:
return rc;
}
+#ifdef HAVE_SERVER_SUPPORT
+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 = llapi_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 = llapi_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(const char *fsname, 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, fsname, sizeof(bc->bc_name));
+ data.ioc_inlbuf1 = (char *)bc;
+ data.ioc_inllen1 = sizeof(*bc);
+ memset(buf, 0, sizeof(rawbuf));
+ rc = llapi_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",
+ fsname, strerror(errno));
+ else
+ llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
+
+ return rc;
+}
+
+int jt_barrier_stat(int argc, char **argv)
+{
+ struct barrier_ctl bc;
+ static struct option long_opt_barrier_stat[] = {
+ {
+ .val = 's',
+ .name = "state",
+ .has_arg = no_argument,
+ },
+ { .val = 't',
+ .name = "timeout",
+ .has_arg = no_argument,
+ },
+ {
+ NULL
+ }
+ };
+ const char *name;
+ int index;
+ int opt;
+ int rc;
+ bool state = false;
+ bool timeout = false;
+
+ while ((opt = getopt_long(argc, argv, "st", long_opt_barrier_stat,
+ &index)) != EOF) {
+ switch (opt) {
+ case 's':
+ state = true;
+ break;
+ case 't':
+ timeout = true;
+ break;
+ default:
+ return CMD_HELP;
+ }
+ }
+
+ if (optind >= argc)
+ return CMD_HELP;
+
+ name = argv[optind];
+ if (strlen(name) > 8) {
+ fprintf(stderr, "fsname name %s is too long. "
+ "It should not exceed 8.\n", name);
+ return -EINVAL;
+ }
+
+ rc = __jt_barrier_stat(name, &bc);
+ if (!rc) {
+ if (state && !timeout)
+ printf("%s\n", barrier_status2name(bc.bc_status));
+ else if (timeout && !state)
+ printf("%d\n",
+ (bc.bc_status == BS_FREEZING_P1 ||
+ bc.bc_status == BS_FREEZING_P2 ||
+ bc.bc_status == BS_FROZEN) ?
+ bc.bc_timeout : 0);
+ else
+ printf("state: %s\ntimeout: %d seconds\n",
+ barrier_status2name(bc.bc_status),
+ (bc.bc_status == BS_FREEZING_P1 ||
+ bc.bc_status == BS_FREEZING_P2 ||
+ bc.bc_status == BS_FROZEN) ?
+ bc.bc_timeout : 0);
+ }
+
+ 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 = llapi_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 {
+ llapi_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;
+}
+#endif /* HAVE_SERVER_SUPPORT */
+
int jt_get_obj_version(int argc, char **argv)
{
struct lu_fid fid;
data.ioc_inllen2 = sizeof version;
memset(buf, 0, sizeof *buf);
- rc = obd_ioctl_pack(&data, &buf, sizeof rawbuf);
+ rc = llapi_ioctl_pack(&data, &buf, sizeof rawbuf);
if (rc) {
fprintf(stderr, "error: %s: packing ioctl arguments: %s\n",
jt_cmdname(argv[0]), strerror(-rc));
return -errno;
}
- obd_ioctl_unpack(&data, buf, sizeof rawbuf);
+ llapi_ioctl_unpack(&data, buf, sizeof rawbuf);
printf("%#jx\n", (uintmax_t)version);
return 0;
}
data.ioc_dev = cur_device;
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc < 0) {
fprintf(stderr, "error: %s: cannot pack ioctl: %s\n",
jt_cmdname(argv[0]), strerror(-rc));
return rc;
}
- obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
+ llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
if (data.ioc_u32_1 == 0) {
fprintf(stderr, "received invalid userid!\n");
data.ioc_dev = cur_device;
data.ioc_u32_1 = id;
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc < 0) {
fprintf(stderr, "error: %s: invalid ioctl\n",
jt_cmdname(argv[0]));
return rc;
}
- obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
+ llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
printf("%s: Deregistered changelog user '%s%u'\n",
device, CHANGELOG_USER_PREFIX, data.ioc_u32_1);