Re: [PATCH] qemu: domain: Replace qemuDomainFilePathIsHostCDROM with virFileIsCDROM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/07/2018 11:21 AM, Peter Krempa wrote:
> Use the new helper when checking that the VM needs to be tainted as a
> host-cdrom passthrough.
>
> Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
> ---
>  src/qemu/qemu_domain.c | 31 +------------------------------
>  1 file changed, 1 insertion(+), 30 deletions(-)
>
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index b13e6d8ca4..ec865e68c8 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -6483,35 +6483,6 @@ qemuDomainDefFormatLive(virQEMUDriverPtr driver,
>  }
>
>
> -/* qemuDomainFilePathIsHostCDROM
> - * @path: Supplied path.
> - *
> - * Determine if the path is a host CD-ROM path. Typically this is
> - * either /dev/cdrom[n] or /dev/srN, so those are easy checks, but
> - * it's also possible that @path resolves to /dev/srN, so check for
> - * those conditions on @path in order to emit the tainted message.
> - *
> - * Returns true if the path is a CDROM, false otherwise or on error.
> - */
> -static bool
> -qemuDomainFilePathIsHostCDROM(const char *path)
> -{
> -    bool ret = false;
> -    char *linkpath = NULL;
> -
> -    if (virFileResolveLink(path, &linkpath) < 0)
> -        goto cleanup;
> -
> -    if (STRPREFIX(path, "/dev/cdrom") || STRPREFIX(path, "/dev/sr") ||
> -        STRPREFIX(linkpath, "/dev/sr"))
> -        ret = true;
> -
> - cleanup:
> -    VIR_FREE(linkpath);
> -    return ret;
> -}
> -
> -
>  void qemuDomainObjTaint(virQEMUDriverPtr driver,
>                          virDomainObjPtr obj,
>                          virDomainTaintFlags taint,
> @@ -6630,7 +6601,7 @@ void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
>
>      if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
>          virStorageSourceGetActualType(disk->src) == VIR_STORAGE_TYPE_BLOCK &&
> -        disk->src->path && qemuDomainFilePathIsHostCDROM(disk->src->path))
> +        disk->src->path && virFileIsCDROM(disk->src->path))
>          qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH,
>                             logCtxt);
>

Not a 1 for 1 replacement of code, so possible behavior may change in
some odd circumstance, but if it does, that's probably a *good* thing
since the new function is more accurate.

However, virFileIsCDROM() returns different values than
qemuDomainFilePathIsHostCDROM(). In particular, it can fail and return
-1. The other use of virFileCDRom compares with 1 (meaning that
"failure" is the same as "not a CDROM"), but here you're just checking
for T/F, so "failure" == "*is* a CDROM.


I won't attempt to say which is the better behavior, but I'd venture it
should be consistent. Once you've fixed that (or with a short
explanation in the commit message of why you treated the two uses
differently):


Reviewed-by: Laine Stump <laine@xxxxxxxxx>


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux