]> xenbits.xensource.com Git - libvirt.git/commitdiff
virpci: Introduce virPCIDeviceAddressCopy
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 7 Jun 2019 14:32:37 +0000 (16:32 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 17 Dec 2019 09:04:43 +0000 (10:04 +0100)
This helper is cleaner than plain memcpy() because one doesn't
have to look into virPCIDeviceAddress struct to see if it
contains any strings / pointers.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
src/libvirt_private.syms
src/util/virpci.c
src/util/virpci.h

index 2424e475c7ec394a68819ad1562dcb4671d07628..50e63b24928039f2671ed9d16f65cf4aed0759bd 100644 (file)
@@ -2706,6 +2706,7 @@ virObjectUnref;
 
 # util/virpci.h
 virPCIDeviceAddressAsString;
+virPCIDeviceAddressCopy;
 virPCIDeviceAddressEqual;
 virPCIDeviceAddressFree;
 virPCIDeviceAddressGetIOMMUGroupAddresses;
index b0a4107551886c1f007cd1a6d324a18dfa0a0dbf..99a80027436e50694b3fd43024cbcbd9a9c0947b 100644 (file)
@@ -1340,6 +1340,20 @@ virPCIDeviceAddressEqual(const virPCIDeviceAddress *addr1,
     return false;
 }
 
+/**
+ * virPCIDeviceAddressCopy:
+ * @dst: where to store address
+ * @src: source address to copy
+ *
+ * Creates a deep copy of given @src address and stores it into
+ * @dst which has to be pre-allocated by caller.
+ */
+void virPCIDeviceAddressCopy(virPCIDeviceAddressPtr dst,
+                             const virPCIDeviceAddress *src)
+{
+    memcpy(dst, src, sizeof(*src));
+}
+
 char *
 virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr)
 {
index 1c94dc307c876889a3db196f0382e65a1413f095..f6796fc4228bd17e74b35eecac674f50a1c26c30 100644 (file)
@@ -44,6 +44,7 @@ typedef virZPCIDeviceAddress *virZPCIDeviceAddressPtr;
 struct _virZPCIDeviceAddress {
     unsigned int uid; /* exempt from syntax-check */
     unsigned int fid;
+    /* Don't forget to update virPCIDeviceAddressCopy if needed. */
 };
 
 #define VIR_PCI_DEVICE_ADDRESS_FMT "%04x:%02x:%02x.%d"
@@ -56,6 +57,7 @@ struct _virPCIDeviceAddress {
     int multi; /* virTristateSwitch */
     int extFlags; /* enum virPCIDeviceAddressExtensionFlags */
     virZPCIDeviceAddress zpci;
+    /* Don't forget to update virPCIDeviceAddressCopy if needed. */
 };
 
 typedef enum {
@@ -236,6 +238,8 @@ bool virPCIDeviceAddressIsEmpty(const virPCIDeviceAddress *addr);
 
 bool virPCIDeviceAddressEqual(const virPCIDeviceAddress *addr1,
                               const virPCIDeviceAddress *addr2);
+void virPCIDeviceAddressCopy(virPCIDeviceAddressPtr dst,
+                             const virPCIDeviceAddress *src);
 
 char *virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr)
       ATTRIBUTE_NONNULL(1);