I want to change the driver->open function so that as well as declining a name (returning -1 as now), it may also indicate that it accepts the name, but there is an error opening the name (-2). virConnectOpen fails in this second case, rather than going on and trying the next driver in sequence.
Rich. -- Emerging Technologies, Red Hat http://et.redhat.com/~rjones/ 64 Baker Street, London, W1U 7DF Mobile: +44 7866 314 421 "[Negative numbers] darken the very whole doctrines of the equations and make dark of the things which are in their nature excessively obvious and simple" (Francis Maseres FRS, mathematician, 1759)
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.58
diff -u -r1.58 libvirt.c
--- src/libvirt.c 23 Feb 2007 08:51:30 -0000 1.58
+++ src/libvirt.c 28 Feb 2007 16:10:26 -0000
@@ -303,16 +305,22 @@
for (i = 0;i < MAX_DRIVERS;i++) {
if ((virDriverTab[i] != NULL) && (virDriverTab[i]->open != NULL)) {
res = virDriverTab[i]->open(ret, name, VIR_DRV_OPEN_QUIET);
- /*
- * For a default connect to Xen make sure we manage to contact
- * all related drivers.
- */
- if ((res < 0) && (for_xen) &&
- (!strncasecmp(virDriverTab[i]->name, "xen", 3)) &&
- (virDriverTab[i]->no != VIR_DRV_XEN_PROXY))
- goto failed;
- if (res == 0)
+ switch (res)
+ {
+ case VIR_DRV_OPEN_ERROR: goto failed;
+ case VIR_DRV_OPEN_DECLINED:
+ /*
+ * For a default connect to Xen make sure we manage to contact
+ * all related drivers.
+ */
+ if (for_xen &&
+ strncasecmp(virDriverTab[i]->name, "xen", 3) == 0 &&
+ virDriverTab[i]->no != VIR_DRV_XEN_PROXY)
+ goto failed;
+ break;
+ case VIR_DRV_OPEN_SUCCESS:
ret->drivers[ret->nb_drivers++] = virDriverTab[i];
+ }
}
}
@@ -379,9 +387,13 @@
if ((virDriverTab[i] != NULL) && (virDriverTab[i]->open != NULL)) {
res = virDriverTab[i]->open(ret, name,
VIR_DRV_OPEN_QUIET | VIR_DRV_OPEN_RO);
- if (res == 0)
- ret->drivers[ret->nb_drivers++] = virDriverTab[i];
-
+ switch (res)
+ {
+ case VIR_DRV_OPEN_ERROR: goto failed;
+ case VIR_DRV_OPEN_DECLINED: break;
+ case VIR_DRV_OPEN_SUCCESS:
+ ret->drivers[ret->nb_drivers++] = virDriverTab[i];
+ }
}
if ((virNetworkDriverTab[i] != NULL) && (virNetworkDriverTab[i]->open != NULL) &&
(res = virNetworkDriverTab[i]->open(ret, name, VIR_DRV_OPEN_QUIET)) == 0) {
Index: src/driver.h
===================================================================
RCS file: /data/cvs/libvirt/src/driver.h,v
retrieving revision 1.21
diff -u -r1.21 driver.h
--- src/driver.h 23 Feb 2007 08:51:30 -0000 1.21
+++ src/driver.h 28 Feb 2007 16:10:26 -0000
@@ -32,10 +33,24 @@
VIR_DRV_OPEN_RO = 2
} virDrvOpenFlag;
-typedef int
- (*virDrvOpen) (virConnectPtr conn,
- const char *name,
- int flags);
+/* Status codes returned from driver open call. */
+typedef enum {
+ /* Opened successfully. */
+ VIR_DRV_OPEN_SUCCESS = 0,
+
+ /* 'name' is not for us. */
+ VIR_DRV_OPEN_DECLINED = -1,
+
+ /* 'name' is for us, but there was some error. virConnectOpen will
+ * return an error rather than continue probing the other drivers.
+ */
+ VIR_DRV_OPEN_ERROR = -2,
+} virDrvOpenStatus;
+
+typedef virDrvOpenStatus
+ (*virDrvOpen) (virConnectPtr conn,
+ const char *name,
+ int flags);
typedef int
(*virDrvClose) (virConnectPtr conn);
typedef const char *
smime.p7s
Description: S/MIME Cryptographic Signature
-- Libvir-list mailing list [email protected] https://www.redhat.com/mailman/listinfo/libvir-list
