[PATCH v2 01/12] Introduce virDomainDetachDeviceAlias API

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

 



When detaching a device it can be uniquely identified by its
alias. Instead of misusing virDomainDetachDeviceFlags which has
the same signature introduce new function.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 include/libvirt/libvirt-domain.h |  3 +++
 src/driver-hypervisor.h          |  6 +++++
 src/libvirt-domain.c             | 53 ++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms          |  5 ++++
 4 files changed, 67 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index d7cbd18796..da773b76cb 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -2022,6 +2022,9 @@ int virDomainDetachDeviceFlags(virDomainPtr domain,
 int virDomainUpdateDeviceFlags(virDomainPtr domain,
                                const char *xml, unsigned int flags);
 
+int virDomainDetachDeviceAlias(virDomainPtr domain,
+                               const char *alias, unsigned int flags);
+
 typedef struct _virDomainStatsRecord virDomainStatsRecord;
 typedef virDomainStatsRecord *virDomainStatsRecordPtr;
 struct _virDomainStatsRecord {
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index e71a72a441..9a224998fd 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -441,6 +441,11 @@ typedef int
                                  const char *xml,
                                  unsigned int flags);
 
+typedef int
+(*virDrvDomainDetachDeviceAlias)(virDomainPtr domain,
+                                 const char *alias,
+                                 unsigned int flags);
+
 typedef int
 (*virDrvDomainGetAutostart)(virDomainPtr domain,
                             int *autostart);
@@ -1392,6 +1397,7 @@ struct _virHypervisorDriver {
     virDrvDomainDetachDevice domainDetachDevice;
     virDrvDomainDetachDeviceFlags domainDetachDeviceFlags;
     virDrvDomainUpdateDeviceFlags domainUpdateDeviceFlags;
+    virDrvDomainDetachDeviceAlias domainDetachDeviceAlias;
     virDrvDomainGetAutostart domainGetAutostart;
     virDrvDomainSetAutostart domainSetAutostart;
     virDrvDomainGetSchedulerType domainGetSchedulerType;
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 2d86e48979..e536781e38 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -8349,6 +8349,59 @@ virDomainUpdateDeviceFlags(virDomainPtr domain,
 }
 
 
+/**
+ * virDomainDetachDeviceAlias:
+ * @domain: pointer to domain object
+ * @alias: device alias
+ * @flags: bitwise-OR of virDomainDeviceModifyFlags
+ *
+ * Detach a virtual device from a domain, using the alias to
+ * specify device. The value of @flags should be either
+ * VIR_DOMAIN_AFFECT_CURRENT, or a bitwise-or of values from
+ * VIR_DOMAIN_AFFECT_LIVE and VIR_DOMAIN_AFFECT_CURRENT, although
+ * hypervisors vary in which flags are supported.
+ *
+ * In contrast to virDomainDetachDeviceFlags() this API only send
+ * request to the hypervisor and returns immediately. It's
+ * caller's responsibility to wait for
+ * VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED event to signal actual
+ * device removal.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+int
+virDomainDetachDeviceAlias(virDomainPtr domain,
+                           const char *alias,
+                           unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "alias=%s, flags=0x%x", alias, flags);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+
+    virCheckNonNullArgGoto(alias, error);
+    virCheckReadOnlyGoto(conn->flags, error);
+
+    if (conn->driver->domainDetachDeviceAlias) {
+        int ret;
+        ret = conn->driver->domainDetachDeviceAlias(domain, alias, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
+
 /**
  * virConnectDomainEventRegister:
  * @conn: pointer to the connection
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 95df3a0dbc..cd6b0c1fdc 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -785,4 +785,9 @@ LIBVIRT_4.1.0 {
         virStoragePoolLookupByTargetPath;
 } LIBVIRT_3.9.0;
 
+LIBVIRT_4.4.0 {
+    global:
+        virDomainDetachDeviceAlias;
+} LIBVIRT_4.1.0;
+
 # .... define new API here using predicted next version number ....
-- 
2.16.1

--
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