]> xenbits.xensource.com Git - libvirt.git/commitdiff
driver: add some helpers for opening secondary driver connections
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 31 Jan 2018 18:21:52 +0000 (18:21 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 31 Jan 2018 18:34:47 +0000 (18:34 +0000)
Various parts of libvirt will want to open connections to secondary
drivers. The right URI to use will depend on the context, so rather than
duplicating that logic in various places, use some helper APIs. This
will also make it easier for us to later pre-open/cache connections to
avoid repeated opening & closing the same connectiong during autostart.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/driver.c
src/driver.h
src/libvirt_private.syms

index 04dd0a44318bfe0eb264d29501ba6a1084409f2d..a6a7ff925a86dd1a93d63e0d0a41dc8c9a85d64d 100644 (file)
@@ -167,3 +167,33 @@ virDriverLoadModule(const char *name,
 
 
 /* XXX unload modules, but we can't until we can unregister libvirt drivers */
+
+virConnectPtr virGetConnectInterface(void)
+{
+    return virConnectOpen(geteuid() == 0 ? "interface:///system" : "interface:///session");
+}
+
+virConnectPtr virGetConnectNetwork(void)
+{
+    return virConnectOpen(geteuid() == 0 ? "network:///system" : "network:///session");
+}
+
+virConnectPtr virGetConnectNWFilter(void)
+{
+    return virConnectOpen(geteuid() == 0 ? "nwfilter:///system" : "nwfilter:///session");
+}
+
+virConnectPtr virGetConnectNodeDev(void)
+{
+    return virConnectOpen(geteuid() == 0 ? "nodedev:///system" : "nodedev:///session");
+}
+
+virConnectPtr virGetConnectSecret(void)
+{
+    return virConnectOpen(geteuid() == 0 ? "secret:///system" : "secret:///session");
+}
+
+virConnectPtr virGetConnectStorage(void)
+{
+    return virConnectOpen(geteuid() == 0 ? "storage:///system" : "storage:///session");
+}
index 936c9816035398fbf139398d46af6b7f2021d79c..fe0cec09230093c1c858e2f223b79785ea20bc77 100644 (file)
@@ -105,4 +105,11 @@ int virDriverLoadModuleFull(const char *name,
                             const char *regfunc,
                             void **handle);
 
+virConnectPtr virGetConnectInterface(void);
+virConnectPtr virGetConnectNetwork(void);
+virConnectPtr virGetConnectNWFilter(void);
+virConnectPtr virGetConnectNodeDev(void);
+virConnectPtr virGetConnectSecret(void);
+virConnectPtr virGetConnectStorage(void);
+
 #endif /* __VIR_DRIVER_H__ */
index 43deca9a520155cff825872741f49cf28b922dd3..0a42bfd401e550a055f57378fc24080fc664583f 100644 (file)
@@ -1183,6 +1183,15 @@ virStorageVolClass;
 virStreamClass;
 
 
+# driver.h
+virGetConnectInterface;
+virGetConnectNetwork;
+virGetConnectNodeDev;
+virGetConnectNWFilter;
+virGetConnectSecret;
+virGetConnectStorage;
+
+
 # libvirt_internal.h
 virConnectSupportsFeature;
 virDomainMigrateBegin3;