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

Re: [libvirt] [PATCH 1/2] Add wrappers for virDomainDiskIndexBy*



On 05/21/2015 11:42 AM, Jiri Denemark wrote:
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 redhat com>
---
  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)
Shouldn't this new function be called virDomainDiskByPCIAddess(..)?

+{
+    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;



--
Mit freundlichen Grüßen/Kind regards
   Boris Fiuczynski

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martina Köderitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


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