+ fprintf(stderr, "stop LFSCK\n"
+ "usage:\n"
+ "lfsck_stop [-M | --device {MDT,OST}_device]\n"
+ " [-A | --all] [-h | --help]\n"
+ "options:\n"
+ "-M: device to stop LFSCK/scrub on\n"
+ "-A: stop LFSCK on all nodes via the specified MDT device "
+ "(see \"-M\" option) by single LFSCK command\n"
+ "-h: this help message\n");
+}
+
+static void usage_query(void)
+{
+ fprintf(stderr, "check the LFSCK global status\n"
+ "usage:\n"
+ "lfsck_query [-M | --device MDT_device] [-h | --help]\n"
+ " [-t | --type check_type[,check_type...]]\n"
+ " [-t | --wait]\n"
+ "options:\n"
+ "-M: device to query LFSCK on\n"
+ "-t: LFSCK type(s) to be queried (default is all)\n"
+ "-h: this help message\n"
+ "-w: do not return until LFSCK not running\n");
+}
+
+static int lfsck_pack_dev(struct obd_ioctl_data *data, char *device, char *arg)
+{
+ int len = strlen(arg) + 1;
+
+ if (len > MAX_OBD_NAME) {
+ fprintf(stderr, "device name is too long. "
+ "Valid length should be less than %d\n", MAX_OBD_NAME);
+ return -EINVAL;
+ }
+
+ memcpy(device, arg, len);
+ data->ioc_inlbuf4 = device;
+ data->ioc_inllen4 = len;
+ data->ioc_dev = OBD_DEV_BY_DEVNAME;
+ return 0;
+}
+
+static int lfsck_get_dev_name(struct obd_ioctl_data *data, char *device,
+ int types, bool multipe_devices)
+{
+ glob_t param = { 0 };
+ char *ptr;
+ int rc;
+ int i;
+
+ rc = cfs_get_param_paths(¶m, "mdd/*-MDT*");
+ if (rc) {
+ if (multipe_devices || errno != ENOENT ||
+ types & LFSCK_TYPE_NAMESPACE) {
+ fprintf(stderr, "Fail to get device name: rc = %d\n."
+ "You can specify the device explicitly "
+ "via '-M' option.\n", rc);
+ return rc;
+ }
+
+ rc = cfs_get_param_paths(¶m, "obdfilter/*-OST*");
+ if (rc) {
+ fprintf(stderr, "Fail to get device name: rc = %d\n."
+ "You can specify the device explicitly "
+ "via '-M' option.\n", rc);
+ return rc;
+ }
+ }
+
+ if (param.gl_pathc == 1)
+ goto pack;
+
+ if (!multipe_devices) {
+ fprintf(stderr,
+ "Detect multiple devices on current node. "
+ "Please specify the device explicitly "
+ "via '-M' option or '-A' option for all.\n");
+ rc = -EINVAL;
+ goto out;
+ }
+
+ ptr = strrchr(param.gl_pathv[0], '-');
+ if (ptr == NULL) {
+ rc = -EINVAL;
+ goto out;
+ }
+
+ for (i = 1; i < param.gl_pathc; i++) {
+ char *ptr2 = strrchr(param.gl_pathv[i], '-');
+
+ if (ptr2 == NULL) {
+ rc = -EINVAL;
+ goto out;
+ }
+
+ if ((ptr - param.gl_pathv[0]) != (ptr2 - param.gl_pathv[i]) ||
+ strncmp(param.gl_pathv[0], param.gl_pathv[i],
+ (ptr - param.gl_pathv[0])) != 0) {
+ fprintf(stderr,
+ "Detect multiple filesystems on current node. "
+ "Please specify the device explicitly "
+ "via '-M' option.\n");
+ rc = -EINVAL;
+ goto out;
+ }
+ }
+
+pack:
+ rc = lfsck_pack_dev(data, device, basename(param.gl_pathv[0]));
+
+out:
+ cfs_free_param_data(¶m);
+
+ return rc;