diff --git a/ipl_tools/ccw.c b/ipl_tools/ccw.c index c06125e5..88eaed13 100644 --- a/ipl_tools/ccw.c +++ b/ipl_tools/ccw.c @@ -9,7 +9,6 @@ * it under the terms of the MIT license. See LICENSE for details. */ -#include #include #include #include @@ -17,6 +16,7 @@ #include #include "lib/util_path.h" +#include "lib/util_panic.h" #include "ipl_tools.h" /* @@ -26,9 +26,10 @@ */ static int device_sysfs_path(const char *device, char *path, const size_t path_size) { - assert(device); - assert(path); - assert(path_size == PATH_MAX); + util_assert(device != NULL, "Internal error: device is NULL"); + util_assert(path != NULL, "Internal error: path is NULL"); + util_assert(path_size == PATH_MAX, "Internal error: path_size is '%zu', but must be '%zu'", + path_size, PATH_MAX); char *buf = util_path_sysfs("block/%s/device", device); if (!realpath(buf, path)) { @@ -64,6 +65,26 @@ int ccw_is_device(const char *busid) return 0; } +/* + * Check if the specified device is a valid virtio subchannel device + */ +int ccw_is_virtio_device(const char *device) +{ + char path[PATH_MAX] = { '\0' }; + unsigned virtio = 0; + + if (device_sysfs_path(device, path, sizeof(path)) != 0) + return -1; + + /* + * The output has the following format: + * /sys/devices/css0/0.0.0000/0.0.0000/virtio0/block/vda + */ + if (sscanf(path, "/sys/devices/css0/%*[0-9a-f.]/%*[0-9a-f.]/virtio%u", &virtio) != 1) + return -1; + return 0; +} + /* * Return CCW Bus ID (old sysfs) */ diff --git a/ipl_tools/cmd_chreipl.c b/ipl_tools/cmd_chreipl.c index b7cca2d9..a76aa77e 100644 --- a/ipl_tools/cmd_chreipl.c +++ b/ipl_tools/cmd_chreipl.c @@ -391,7 +391,8 @@ static void dev_from_part_nvme(char *dev_name) static int set_reipl_type(const char *dev_name) { if (strncmp(dev_name, "dasd", strlen("dasd")) == 0 || - strncmp(dev_name, "vd", strlen("vd")) == 0) + strncmp(dev_name, "vd", strlen("vd")) == 0 || + ccw_is_virtio_device(dev_name) == 0) l.reipl_type = REIPL_CCW; else if (strncmp(dev_name, "sd", strlen("sd")) == 0) l.reipl_type = REIPL_FCP; diff --git a/ipl_tools/ipl_tools.h b/ipl_tools/ipl_tools.h index e9d11976..69611de3 100644 --- a/ipl_tools/ipl_tools.h +++ b/ipl_tools/ipl_tools.h @@ -87,6 +87,7 @@ int nvme_is_device(char *fid_str, char *nsid_str); * CCW */ extern int ccw_is_device(const char *devno); +extern int ccw_is_virtio_device(const char *device); extern void ccw_busid_get(const char *device, char *devno); /*