[PATCH 1/2] Add wrappers for virDomainDiskIndexBy*

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

 



Sometimes the only thing we need is the pointer to virDomainDiskDef and
having to call virDomainDiskIndexBy* APIs, storing the disk index, and
looking it up in the disks array is ugly. After this patch, we can just
call virDomainDiskBy* and get the pointer in one step.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/conf/domain_conf.c   | 20 ++++++++++++++++++++
 src/conf/domain_conf.h   |  8 ++++++++
 src/libvirt_private.syms |  2 ++
 3 files changed, 30 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 394890e..892d7d7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12349,6 +12349,17 @@ virDomainDiskIndexByAddress(virDomainDefPtr def,
     return -1;
 }
 
+virDomainDiskDefPtr
+virDomainDiskByAddress(virDomainDefPtr def,
+                       virDevicePCIAddressPtr pci_address,
+                       unsigned int bus,
+                       unsigned int target,
+                       unsigned int unit)
+{
+    int idx = virDomainDiskIndexByAddress(def, pci_address, bus, target, unit);
+    return idx < 0 ? NULL : def->disks[idx];
+}
+
 int
 virDomainDiskIndexByName(virDomainDefPtr def, const char *name,
                          bool allow_ambiguous)
@@ -12388,6 +12399,15 @@ virDomainDiskPathByName(virDomainDefPtr def, const char *name)
     return idx < 0 ? NULL : virDomainDiskGetSource(def->disks[idx]);
 }
 
+virDomainDiskDefPtr
+virDomainDiskByName(virDomainDefPtr def,
+                    const char *name,
+                    bool allow_ambiguous)
+{
+    int idx = virDomainDiskIndexByName(def, name, allow_ambiguous);
+    return idx < 0 ? NULL : def->disks[idx];
+}
+
 int virDomainDiskInsert(virDomainDefPtr def,
                         virDomainDiskDefPtr disk)
 {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f93d73e..f27f2e4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2685,8 +2685,16 @@ int virDomainDiskIndexByAddress(virDomainDefPtr def,
                                 virDevicePCIAddressPtr pci_controller,
                                 unsigned int bus, unsigned int target,
                                 unsigned int unit);
+virDomainDiskDefPtr virDomainDiskByAddress(virDomainDefPtr def,
+                                           virDevicePCIAddressPtr pci_controller,
+                                           unsigned int bus,
+                                           unsigned int target,
+                                           unsigned int unit);
 int virDomainDiskIndexByName(virDomainDefPtr def, const char *name,
                              bool allow_ambiguous);
+virDomainDiskDefPtr virDomainDiskByName(virDomainDefPtr def,
+                                        const char *name,
+                                        bool allow_ambiguous);
 const char *virDomainDiskPathByName(virDomainDefPtr, const char *name);
 int virDomainDiskInsert(virDomainDefPtr def,
                         virDomainDiskDefPtr disk)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 15e71d5..6a95fb9 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -238,6 +238,8 @@ virDomainDeviceInfoCopy;
 virDomainDeviceInfoIterate;
 virDomainDeviceTypeToString;
 virDomainDiskBusTypeToString;
+virDomainDiskByAddress;
+virDomainDiskByName;
 virDomainDiskCacheTypeFromString;
 virDomainDiskCacheTypeToString;
 virDomainDiskDefAssignAddress;
-- 
2.4.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]