mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-03 11:51:11 +00:00
nodedev: expose internal helper for naming devices
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@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
e3107a1862
commit
8fed1d9636
@ -980,3 +980,29 @@ nodedevRegister(void)
|
|||||||
return udevNodeRegister();
|
return udevNodeRegister();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
nodeDeviceGenerateName(virNodeDeviceDef *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);
|
||||||
|
|
||||||
|
g_free(def->name);
|
||||||
|
def->name = virBufferContentAndReset(&buf);
|
||||||
|
|
||||||
|
for (i = 0; i < strlen(def->name); i++) {
|
||||||
|
if (!(g_ascii_isalnum(*(def->name + i))))
|
||||||
|
*(def->name + i) = '_';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -120,3 +120,9 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def,
|
|||||||
virCommandPtr
|
virCommandPtr
|
||||||
nodeDeviceGetMdevctlStopCommand(const char *uuid,
|
nodeDeviceGetMdevctlStopCommand(const char *uuid,
|
||||||
char **errmsg);
|
char **errmsg);
|
||||||
|
|
||||||
|
void
|
||||||
|
nodeDeviceGenerateName(virNodeDeviceDef *def,
|
||||||
|
const char *subsystem,
|
||||||
|
const char *sysname,
|
||||||
|
const char *s);
|
||||||
|
@ -311,22 +311,9 @@ udevGenerateDeviceName(struct udev_device *device,
|
|||||||
virNodeDeviceDefPtr def,
|
virNodeDeviceDefPtr def,
|
||||||
const char *s)
|
const char *s)
|
||||||
{
|
{
|
||||||
size_t i;
|
nodeDeviceGenerateName(def,
|
||||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
|
||||||
|
|
||||||
virBufferAsprintf(&buf, "%s_%s",
|
|
||||||
udev_device_get_subsystem(device),
|
udev_device_get_subsystem(device),
|
||||||
udev_device_get_sysname(device));
|
udev_device_get_sysname(device), s);
|
||||||
|
|
||||||
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) = '_';
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user