lvm2/0003-device_id-handle-wwid-with-spaces-or-control-charact.patch
2022-01-04 22:26:44 +01:00

56 lines
1.7 KiB
Diff

From c265ff79d34e1c1c76db360a7c056c95c32ce216 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Thu, 2 Dec 2021 13:30:36 -0600
Subject: [PATCH 3/3] device_id: handle wwid with spaces or control characters
non-standard wwid can be reported from sysfs with spaces/etc.
replace with "_"
(cherry picked from commit ae54e75176d787de2d447ec40142f85f4dcc47c4)
---
lib/device/device_id.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index 167bf661b..8b822e4c0 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -302,6 +302,7 @@ const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, u
{
char sysbuf[PATH_MAX] = { 0 };
const char *idname = NULL;
+ int i;
if (idtype == DEV_ID_TYPE_SYS_WWID) {
read_sys_block(cmd, dev, "device/wwid", sysbuf, sizeof(sysbuf));
@@ -309,13 +310,10 @@ const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, u
if (!sysbuf[0])
read_sys_block(cmd, dev, "wwid", sysbuf, sizeof(sysbuf));
- /* scsi_debug wwid begins "t10.Linux scsi_debug ..." */
- if (strstr(sysbuf, "scsi_debug"))
- sysbuf[0] = '\0';
-
/* qemu wwid begins "t10.ATA QEMU HARDDISK ..." */
if (strstr(sysbuf, "QEMU HARDDISK"))
sysbuf[0] = '\0';
+
}
else if (idtype == DEV_ID_TYPE_SYS_SERIAL)
@@ -353,6 +351,11 @@ const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, u
return idname;
}
+ for (i = 0; i < strlen(sysbuf); i++) {
+ if (isblank(sysbuf[i]) || isspace(sysbuf[i]) || iscntrl(sysbuf[i]))
+ sysbuf[i] = '_';
+ }
+
if (!sysbuf[0])
goto_bad;
--
2.31.1