Expose a helper function that can be used by udev and mdevctl to
generate device names for node devices.
Signed-off-by: Jonathon Jongsma <jjongsma(a)redhat.com>
---
src/node_device/node_device_driver.c | 25 +++++++++++++++++++++++++
src/node_device/node_device_driver.h | 6 ++++++
src/node_device/node_device_udev.c | 19 +++----------------
3 files changed, 34 insertions(+), 16 deletions(-)
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index c992251121..6143459618 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -968,3 +968,28 @@ nodedevRegister(void)
return udevNodeRegister();
#endif
}
+
+
+void
+nodeDeviceGenerateName(virNodeDeviceDefPtr def,
+ const char *subsystem,
+ const char *sysname,
+ const char *s)
+{
+ size_t i;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+
+ virBufferAsprintf(&buf, "%s_%s",
+ subsystem,
+ sysname);
+
+ if (s != NULL)
+ virBufferAsprintf(&buf, "_%s", s);
+
+ def->name = virBufferContentAndReset(&buf);
+
+ for (i = 0; i < strlen(def->name); i++) {
+ if (!(g_ascii_isalnum(*(def->name + i))))
+ *(def->name + i) = '_';
+ }
+}
diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h
index 2113d2b0a5..02baf56dab 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -118,3 +118,9 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def,
char **uuid_out);
virCommandPtr
nodeDeviceGetMdevctlStopCommand(const char *uuid);
+
+void
+nodeDeviceGenerateName(virNodeDeviceDefPtr def,
+ const char *subsystem,
+ const char *sysname,
+ const char *s);
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 208f256895..be59e6c6bc 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -308,22 +308,9 @@ udevGenerateDeviceName(struct udev_device *device,
virNodeDeviceDefPtr def,
const char *s)
{
- size_t i;
- g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-
- virBufferAsprintf(&buf, "%s_%s",
- udev_device_get_subsystem(device),
- udev_device_get_sysname(device));
-
- if (s != NULL)
- virBufferAsprintf(&buf, "_%s", s);
-
- def->name = virBufferContentAndReset(&buf);
-
- for (i = 0; i < strlen(def->name); i++) {
- if (!(g_ascii_isalnum(*(def->name + i))))
- *(def->name + i) = '_';
- }
+ nodeDeviceGenerateName(def,
+ udev_device_get_subsystem(device),
+ udev_device_get_sysname(device), s);
return 0;
}
--
2.26.2