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

[libvirt] [PATCH alternative 2/2] Change contract of virDomainGetID to make it safer



This changes the contract of the existing virDomainGetID call so that
it is guaranteed to return the ID provided that the @domain parameter
is not NULL or corrupted.

This should be compatible with all preceeding versions of libvirt,
since all they have ever done is to check the @domain parameter and
return the dom->id field.

However it might not be forwards compatible with future versions: At
the moment there is an odd distinction between the local and remote
case.  In the local case, the dom->id field is set to -1 when the
domain goes (mostly anyhow, not always).  In the remote case it is not
set, because this is not known.

In practice, this never really matters.  All significant libvirt
callers grab a new virDomain object from the remote end each time,
thus getting an updated ID.  virDomain objects seem to be individually
very short-lived.

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
Read my OCaml programming blog: http://camltastic.blogspot.com/
Fedora now supports 64 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
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:47 -0000
@@ -1878,7 +1878,9 @@
  *
  * Get the hypervisor ID number for the domain
  *
- * Returns the domain ID number or (unsigned int) -1 in case of error
+ * Returns the domain ID number or (unsigned int) -1 if the domain is
+ * not running.  If @domain is NULL or its memory is corrupted
+ * then this can also return (unsigned int) -1.
  */
 unsigned int
 virDomainGetID(virDomainPtr domain)

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