summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2022-11-07 16:13:56 -0600
committerDavid Teigland <teigland@redhat.com>2022-11-07 16:13:56 -0600
commite149a81be491f440ba0cce2a1a076a35aa5219be (patch)
tree337e4fea45bb78402cc2719923d663795cbf9588
parentc98617c593a84e32ff8ee32ecf2382d4e1369c16 (diff)
downloadlvm2-dev-dct-deviceid-dasd.tar.gz
device_id: add type for dasddev-dct-deviceid-dasd
-rw-r--r--lib/device/device.h1
-rw-r--r--lib/device/device_id.c54
2 files changed, 55 insertions, 0 deletions
diff --git a/lib/device/device.h b/lib/device/device.h
index 446104218..8378850cf 100644
--- a/lib/device/device.h
+++ b/lib/device/device.h
@@ -70,6 +70,7 @@ struct dev_ext {
#define DEV_ID_TYPE_WWID_NAA 9
#define DEV_ID_TYPE_WWID_EUI 10
#define DEV_ID_TYPE_WWID_T10 11
+#define DEV_ID_TYPE_DASD 12
/* Max length of WWID_NAA, WWID_EUI, WWID_T10 */
#define DEV_WWID_SIZE 128
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index aae875776..29e4758b6 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -185,6 +185,42 @@ void free_dids(struct dm_list *ids)
}
}
+static int _read_sys_dasd(struct cmd_context *cmd, struct device *dev,
+ char *sysbuf, int sysbufsize)
+{
+ char path[PATH_MAX];
+ char basebuf[16] = { 0 };
+ char *base;
+ int i, j = 0, ret;
+
+ if (dm_list_empty(&dev->aliases))
+ return 0;
+
+ base = basename(dev_name(dev));
+ for (i = 0; i < strlen(base); i++) {
+ if (isdigit(base[i]))
+ break;
+ basebuf[j++] = base[i];
+ }
+
+ if (dm_snprintf(path, sizeof(path), "%sdev/block/%s/device/uid",
+ dm_sysfs_dir(), basebuf) < 0) {
+ log_error("Failed to create sysfs path for %s", dev_name(dev));
+ return 0;
+ }
+
+ ret = get_sysfs_value(path, sysbuf, sysbufsize, 0);
+ if (ret && !sysbuf[0])
+ ret = 0;
+
+ if (ret) {
+ sysbuf[sysbufsize - 1] = '\0';
+ return 1;
+ }
+
+ return 0;
+}
+
static int _read_sys_block(struct cmd_context *cmd, struct device *dev,
const char *suffix, char *sysbuf, int sysbufsize,
int binary, int *retlen)
@@ -572,6 +608,9 @@ const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, u
return idname;
}
+ else if (idtype == DEV_ID_TYPE_DASD)
+ _read_sys_dasd(cmd, dev, sysbuf, sizeof(sysbuf));
+
else if (idtype == DEV_ID_TYPE_WWID_NAA ||
idtype == DEV_ID_TYPE_WWID_EUI ||
idtype == DEV_ID_TYPE_WWID_T10) {
@@ -667,6 +706,10 @@ static int _dev_has_stable_id(struct cmd_context *cmd, struct device *dev)
if (!dm_list_empty(&dev->wwids))
return 1;
+ if ((MAJOR(dev->dev) == cmd->dev_types->dasd_major) &&
+ _read_sys_dasd(cmd, dev, sysbuf, sizeof(sysbuf)))
+ return 1;
+
out:
/* DEV_ID_TYPE_DEVNAME would be used for this dev. */
return 0;
@@ -696,6 +739,8 @@ const char *idtype_to_str(uint16_t idtype)
return "wwid_eui";
if (idtype == DEV_ID_TYPE_WWID_T10)
return "wwid_t10";
+ if (idtype == DEV_ID_TYPE_DASD)
+ return "dasd";
return "unknown";
}
@@ -723,6 +768,8 @@ uint16_t idtype_from_str(const char *str)
return DEV_ID_TYPE_WWID_EUI;
if (!strcmp(str, "wwid_t10"))
return DEV_ID_TYPE_WWID_T10;
+ if (!strcmp(str, "dasd"))
+ return DEV_ID_TYPE_DASD;
return 0;
}
@@ -1672,6 +1719,9 @@ static int _idtype_compatible_with_major_number(struct cmd_context *cmd, int idt
if (idtype == DEV_ID_TYPE_LOOP_FILE)
return (major == cmd->dev_types->loop_major);
+ if (idtype == DEV_ID_TYPE_DASD)
+ return (major == cmd->dev_types->dasd_major);
+
if (major == cmd->dev_types->device_mapper_major)
return (idtype == DEV_ID_TYPE_MPATH_UUID ||
idtype == DEV_ID_TYPE_CRYPT_UUID ||
@@ -1686,6 +1736,10 @@ static int _idtype_compatible_with_major_number(struct cmd_context *cmd, int idt
return (idtype == DEV_ID_TYPE_LOOP_FILE ||
idtype == DEV_ID_TYPE_DEVNAME);
+ if (major == cmd->dev_types->dasd_major)
+ return (idtype == DEV_ID_TYPE_DASD ||
+ idtype == DEV_ID_TYPE_DEVNAME);
+
return 1;
}