[PATCH 05/10] conf: Move some virDomainDeviceInfo functions

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

 



The virDomainDeviceInfo struct is defined in device_conf,
so generic functions that operate on it should also be
defined there rather than in domain_conf.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 src/conf/device_conf.c   | 109 ++++++++++++++++++++++++++++++++++++++++++++
 src/conf/device_conf.h   |   8 ++++
 src/conf/domain_conf.c   | 114 -----------------------------------------------
 src/conf/domain_conf.h   |   7 ---
 src/libvirt_private.syms |   4 +-
 5 files changed, 119 insertions(+), 123 deletions(-)

diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index f58b9d0..4644580 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -32,6 +32,115 @@
 
 #define VIR_FROM_THIS VIR_FROM_DEVICE
 
+void
+virDomainDeviceInfoClear(virDomainDeviceInfoPtr info)
+{
+    VIR_FREE(info->alias);
+    memset(&info->addr, 0, sizeof(info->addr));
+    info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE;
+    VIR_FREE(info->romfile);
+    VIR_FREE(info->loadparm);
+}
+
+int
+virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst,
+                        virDomainDeviceInfoPtr src)
+{
+    /* Assume that dst is already cleared */
+
+    /* first a shallow copy of *everything* */
+    *dst = *src;
+
+    /* then redo the two fields that are pointers */
+    dst->alias = NULL;
+    dst->romfile = NULL;
+
+    if (VIR_STRDUP(dst->alias, src->alias) < 0 ||
+        VIR_STRDUP(dst->romfile, src->romfile) < 0)
+        return -1;
+    return 0;
+}
+
+void
+virDomainDeviceInfoFree(virDomainDeviceInfoPtr info)
+{
+    if (info) {
+        virDomainDeviceInfoClear(info);
+        VIR_FREE(info);
+    }
+}
+
+bool
+virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a,
+                                  const virDomainDeviceInfo *b)
+{
+    if (a->type != b->type)
+        return false;
+
+    switch ((virDomainDeviceAddressType) a->type) {
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
+    /* address types below don't have any specific data */
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
+        break;
+
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
+        /* the 'multi' field shouldn't be checked */
+        if (a->addr.pci.domain != b->addr.pci.domain ||
+            a->addr.pci.bus != b->addr.pci.bus ||
+            a->addr.pci.slot != b->addr.pci.slot ||
+            a->addr.pci.function != b->addr.pci.function)
+            return false;
+        break;
+
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
+        if (memcmp(&a->addr.drive, &b->addr.drive, sizeof(a->addr.drive)))
+            return false;
+        break;
+
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL:
+        if (memcmp(&a->addr.vioserial, &b->addr.vioserial, sizeof(a->addr.vioserial)))
+            return false;
+        break;
+
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID:
+        if (memcmp(&a->addr.ccid, &b->addr.ccid, sizeof(a->addr.ccid)))
+            return false;
+        break;
+
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
+        if (memcmp(&a->addr.usb, &b->addr.usb, sizeof(a->addr.usb)))
+            return false;
+        break;
+
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
+        if (memcmp(&a->addr.spaprvio, &b->addr.spaprvio, sizeof(a->addr.spaprvio)))
+            return false;
+        break;
+
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
+        /* the 'assigned' field denotes that the address was generated */
+        if (a->addr.ccw.cssid != b->addr.ccw.cssid ||
+            a->addr.ccw.ssid != b->addr.ccw.ssid ||
+            a->addr.ccw.devno != b->addr.ccw.devno)
+            return false;
+        break;
+
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
+        if (memcmp(&a->addr.isa, &b->addr.isa, sizeof(a->addr.isa)))
+            return false;
+        break;
+
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM:
+        if (memcmp(&a->addr.dimm, &b->addr.dimm, sizeof(a->addr.dimm)))
+            return false;
+        break;
+    }
+
+    return true;
+}
+
 int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
                                bool report)
 {
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index 48782be..53abe1b 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -170,6 +170,14 @@ struct _virDomainDeviceInfo {
     char *loadparm;
 };
 
+void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info);
+int virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst,
+                            virDomainDeviceInfoPtr src);
+void virDomainDeviceInfoFree(virDomainDeviceInfoPtr info);
+
+bool virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a,
+                                       const virDomainDeviceInfo *b)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 
 int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
                                bool report);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fdb919d..6a89fab 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1324,27 +1324,6 @@ bool virDomainObjTaint(virDomainObjPtr obj,
 
 
 static void
-virDomainDeviceInfoClear(virDomainDeviceInfoPtr info)
-{
-    VIR_FREE(info->alias);
-    memset(&info->addr, 0, sizeof(info->addr));
-    info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE;
-    VIR_FREE(info->romfile);
-    VIR_FREE(info->loadparm);
-}
-
-
-static void
-virDomainDeviceInfoFree(virDomainDeviceInfoPtr info)
-{
-    if (info) {
-        virDomainDeviceInfoClear(info);
-        VIR_FREE(info);
-    }
-}
-
-
-static void
 virDomainGraphicsAuthDefClear(virDomainGraphicsAuthDefPtr def)
 {
     if (!def)
@@ -3495,77 +3474,6 @@ virDomainDeviceInfoNeedsFormat(virDomainDeviceInfoPtr info, unsigned int flags)
     return false;
 }
 
-bool
-virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a,
-                                  const virDomainDeviceInfo *b)
-{
-    if (a->type != b->type)
-        return false;
-
-    switch ((virDomainDeviceAddressType) a->type) {
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
-    /* address types below don't have any specific data */
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
-        break;
-
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
-        /* the 'multi' field shouldn't be checked */
-        if (a->addr.pci.domain != b->addr.pci.domain ||
-            a->addr.pci.bus != b->addr.pci.bus ||
-            a->addr.pci.slot != b->addr.pci.slot ||
-            a->addr.pci.function != b->addr.pci.function)
-            return false;
-        break;
-
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
-        if (memcmp(&a->addr.drive, &b->addr.drive, sizeof(a->addr.drive)))
-            return false;
-        break;
-
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL:
-        if (memcmp(&a->addr.vioserial, &b->addr.vioserial, sizeof(a->addr.vioserial)))
-            return false;
-        break;
-
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID:
-        if (memcmp(&a->addr.ccid, &b->addr.ccid, sizeof(a->addr.ccid)))
-            return false;
-        break;
-
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
-        if (memcmp(&a->addr.usb, &b->addr.usb, sizeof(a->addr.usb)))
-            return false;
-        break;
-
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
-        if (memcmp(&a->addr.spaprvio, &b->addr.spaprvio, sizeof(a->addr.spaprvio)))
-            return false;
-        break;
-
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
-        /* the 'assigned' field denotes that the address was generated */
-        if (a->addr.ccw.cssid != b->addr.ccw.cssid ||
-            a->addr.ccw.ssid != b->addr.ccw.ssid ||
-            a->addr.ccw.devno != b->addr.ccw.devno)
-            return false;
-        break;
-
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
-        if (memcmp(&a->addr.isa, &b->addr.isa, sizeof(a->addr.isa)))
-            return false;
-        break;
-
-    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM:
-        if (memcmp(&a->addr.dimm, &b->addr.dimm, sizeof(a->addr.dimm)))
-            return false;
-        break;
-    }
-
-    return true;
-}
-
 
 static int
 virDomainDefHasDeviceAddressIterator(virDomainDefPtr def ATTRIBUTE_UNUSED,
@@ -3583,28 +3491,6 @@ virDomainDefHasDeviceAddressIterator(virDomainDefPtr def ATTRIBUTE_UNUSED,
 }
 
 
-int
-virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst,
-                        virDomainDeviceInfoPtr src)
-{
-    /* Assume that dst is already cleared */
-
-    /* first a shallow copy of *everything* */
-    *dst = *src;
-
-    /* then copy whatever's left */
-    dst->alias = NULL;
-    dst->romfile = NULL;
-    dst->loadparm = NULL;
-
-    if (VIR_STRDUP(dst->alias, src->alias) < 0 ||
-        VIR_STRDUP(dst->romfile, src->romfile) < 0 ||
-        VIR_STRDUP(dst->loadparm, src->loadparm) < 0)
-        return -1;
-    return 0;
-}
-
-
 static bool
 virDomainSkipBackcompatConsole(virDomainDefPtr def,
                                size_t idx,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index cbcffa4..00d0d65 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2699,8 +2699,6 @@ virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
 int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info,
                                   int type);
 virDomainDeviceInfoPtr virDomainDeviceGetInfo(virDomainDeviceDefPtr device);
-int virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst,
-                            virDomainDeviceInfoPtr src);
 void virDomainTPMDefFree(virDomainTPMDefPtr def);
 
 typedef int (*virDomainDeviceInfoCallback)(virDomainDefPtr def,
@@ -3323,11 +3321,6 @@ virDomainGetBlkioParametersAssignFromDef(virDomainDefPtr def,
                                          int *nparams,
                                          int maxparams);
 
-bool
-virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a,
-                                  const virDomainDeviceInfo *b)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
-
 int virDomainDiskSetBlockIOTune(virDomainDiskDefPtr disk,
                                 virDomainBlockIoTuneInfo *info);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e92fe52..178aefc 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -89,6 +89,8 @@ virCPUModeTypeToString;
 
 
 # conf/device_conf.h
+virDomainDeviceInfoAddressIsEqual;
+virDomainDeviceInfoCopy;
 virInterfaceLinkFormat;
 virInterfaceLinkParseXML;
 virPCIDeviceAddressEqual;
@@ -285,8 +287,6 @@ virDomainDeviceDefFree;
 virDomainDeviceDefParse;
 virDomainDeviceFindControllerModel;
 virDomainDeviceGetInfo;
-virDomainDeviceInfoAddressIsEqual;
-virDomainDeviceInfoCopy;
 virDomainDeviceInfoIterate;
 virDomainDeviceTypeToString;
 virDomainDiskBusTypeToString;
-- 
2.7.5

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