ueventd: support by-name symlinks for virtual block devices

This patch makes ueventd create by-name symlinks for virtual block
devices when Android is running as a Xen guest OS.

The symlinks will be created under /dev/block/vbd/. For example:
/dev/block/vbd/768/by-name/

Change-Id: Id45da560d13f641d7c8419511c154de9ae8a4ec9
Test: manual
Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
This commit is contained in:
Jeremy Compostella 2017-03-03 16:27:29 +01:00
parent 6684ec8d97
commit 937309d3e3

View file

@ -390,6 +390,34 @@ static int find_pci_device_prefix(const char *path, char *buf, ssize_t buf_sz)
return 0;
}
/* Given a path that may start with a virtual block device, populate
* the supplied buffer with the virtual block device ID and return 0.
* If it doesn't start with a virtual block device, or there is some
* error, return -1 */
static int find_vbd_device_prefix(const char *path, char *buf, ssize_t buf_sz)
{
const char *start, *end;
/* Beginning of the prefix is the initial "vbd-" after "/devices/" */
if (strncmp(path, "/devices/vbd-", 13))
return -1;
/* End of the prefix is one path '/' later, capturing the
virtual block device ID. Example: 768 */
start = path + 13;
end = strchr(start, '/');
if (!end)
return -1;
/* Make sure we have enough room for the string plus null terminator */
if (end - start + 1 > buf_sz)
return -1;
strncpy(buf, start, end - start);
buf[end - start] = '\0';
return 0;
}
static void parse_event(const char *msg, struct uevent *uevent)
{
uevent->action = "";
@ -516,6 +544,9 @@ static char **get_block_device_symlinks(struct uevent *uevent)
} else if (!find_pci_device_prefix(uevent->path, buf, sizeof(buf))) {
device = buf;
type = "pci";
} else if (!find_vbd_device_prefix(uevent->path, buf, sizeof(buf))) {
device = buf;
type = "vbd";
} else {
return NULL;
}