+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], '-');
+ LASSERT(ptr != NULL);
+
+ for (i = 1; i < param.gl_pathc; i++) {
+ char *ptr2 = strrchr(param.gl_pathv[i], '-');
+
+ LASSERT(ptr2 != NULL);
+
+ 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;
+}
+