[PATCH] libxl: Fix node device detach when driver unspecified

Jim Fehlig posted 1 patch 3 years, 1 month ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20210301224956.13620-1-jfehlig@suse.com
src/libxl/libxl_driver.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] libxl: Fix node device detach when driver unspecified
Posted by Jim Fehlig 3 years, 1 month ago
Commit 887dd0d331 caused a small regression in NodeDeviceDetach in the libxl
driver when the 'driver' parameter is not specified. E.g.

error: Failed to detach device pci_0000_0a_10_0
error: An error occurred, but the cause is unknown

If the driver name is not specified, NULL is passed to
virDomainDriverNodeDeviceDetachFlags, in which case virPCIDeviceSetStubDriver
is never called to set the stub to pciback. Fix it by setting the driver to
"xen" if it is not specified when invoking NodeDeviceDetach.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 src/libxl/libxl_driver.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 75a8d46af0..348434ca72 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5777,6 +5777,9 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev,
 
     virCheckFlags(0, -1);
 
+    if (!driverName)
+        driverName = "xen";
+
     if (driverName && STRNEQ(driverName, "xen")) {
         virReportError(VIR_ERR_INVALID_ARG,
                        _("unsupported driver name '%s'"), driverName);
-- 
2.29.2


Re: [PATCH] libxl: Fix node device detach when driver unspecified
Posted by Pavel Hrdina 3 years, 1 month ago
On Mon, Mar 01, 2021 at 03:49:56PM -0700, Jim Fehlig wrote:
> Commit 887dd0d331 caused a small regression in NodeDeviceDetach in the libxl
> driver when the 'driver' parameter is not specified. E.g.
> 
> error: Failed to detach device pci_0000_0a_10_0
> error: An error occurred, but the cause is unknown
> 
> If the driver name is not specified, NULL is passed to
> virDomainDriverNodeDeviceDetachFlags, in which case virPCIDeviceSetStubDriver
> is never called to set the stub to pciback. Fix it by setting the driver to
> "xen" if it is not specified when invoking NodeDeviceDetach.
> 
> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
> ---
>  src/libxl/libxl_driver.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
> index 75a8d46af0..348434ca72 100644
> --- a/src/libxl/libxl_driver.c
> +++ b/src/libxl/libxl_driver.c
> @@ -5777,6 +5777,9 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev,
>  
>      virCheckFlags(0, -1);
>  
> +    if (!driverName)
> +        driverName = "xen";
> +
>      if (driverName && STRNEQ(driverName, "xen")) {

I would update this condition as well because the check for driverName
is now redundant.

With that fixed

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

>          virReportError(VIR_ERR_INVALID_ARG,
>                         _("unsupported driver name '%s'"), driverName);
> -- 
> 2.29.2