[libvirt] Re: [PATCH alternative 1/2] virDomainGetID2

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

 



On Wed, Sep 03, 2008 at 05:18:16PM +0100, Richard W.M. Jones wrote:
> This adds virDomainGetID2 which uses a pointer to int parameter,
> allowing the -1 (non-running) domain ID to be returned safely.

With the patch this time ...

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
Index: include/libvirt/libvirt.h.in
===================================================================
RCS file: /data/cvs/libvirt/include/libvirt/libvirt.h.in,v
retrieving revision 1.53
diff -u -r1.53 libvirt.h.in
--- include/libvirt/libvirt.h.in	27 Aug 2008 20:05:58 -0000	1.53
+++ include/libvirt/libvirt.h.in	3 Sep 2008 16:16:12 -0000
@@ -493,6 +493,8 @@
  */
 const char *            virDomainGetName        (virDomainPtr domain);
 unsigned int            virDomainGetID          (virDomainPtr domain);
+int                     virDomainGetID2         (virDomainPtr domain,
+                                                 int *idptr);
 int                     virDomainGetUUID        (virDomainPtr domain,
                                                  unsigned char *uuid);
 int                     virDomainGetUUIDString  (virDomainPtr domain,
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.155
diff -u -r1.155 libvirt.c
--- src/libvirt.c	2 Sep 2008 15:00:09 -0000	1.155
+++ src/libvirt.c	3 Sep 2008 16:16:16 -0000
@@ -1876,9 +1876,12 @@
  * virDomainGetID:
  * @domain: a domain object
  *
- * Get the hypervisor ID number for the domain
+ * Get the hypervisor ID number for the domain.
  *
  * Returns the domain ID number or (unsigned int) -1 in case of error
+ *
+ * This call can return -1 for both errors and undefined domains.
+ * Use virDomainGetID2 for a safe version.
  */
 unsigned int
 virDomainGetID(virDomainPtr domain)
@@ -1893,6 +1896,33 @@
 }
 
 /**
+ * virDomainGetID2:
+ * @domain: a domain object
+ * @idptr: pointer to int to save the domain's ID
+ *
+ * Get the ID number for the domain.  If @idptr is not NULL
+ * then the ID is saved in *idptr.  The ID may be -1 indicating
+ * that the domain is not running.
+ *
+ * Note that this call is available on all drivers.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainGetID2 (virDomainPtr domain, int *idptr)
+{
+    DEBUG("domain=%p, idptr=%p", domain, idptr);
+
+    if (!VIR_IS_DOMAIN (domain)) {
+        virLibDomainError (NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        return -1;
+    }
+
+    if (idptr) *idptr = domain->id;
+    return 0;
+}
+
+/**
  * virDomainGetOSType:
  * @domain: a domain object
  *
--
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]