[PATCH 02/10] storage: allow opening with storage:///system and storage:///session URIs

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

 



Allow the possibility of opening a connection to only the storage
driver, by defining storage:///system and storage:///session URIs
and registering a fake hypervisor driver that supports them.

The hypervisor drivers can now directly open a storage driver
connection at time of need, instead of having to pass around a
virConnectPtr through many functions. This will facilitate the later
change to support separate daemons for each driver.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/storage/storage_driver.c | 90 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index f68acc75be..5d21007edb 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -388,6 +388,79 @@ storageStateCleanup(void)
     return 0;
 }
 
+static virDrvOpenStatus storageConnectOpen(virConnectPtr conn,
+                                           virConnectAuthPtr auth ATTRIBUTE_UNUSED,
+                                           virConfPtr conf ATTRIBUTE_UNUSED,
+                                           unsigned int flags)
+{
+    virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
+    /* Verify uri was specified */
+    if (conn->uri == NULL) {
+        /* Only hypervisor drivers are permitted to auto-open on NULL uri */
+        return VIR_DRV_OPEN_DECLINED;
+    } else {
+        if (STRNEQ_NULLABLE(conn->uri->scheme, "storage"))
+            return VIR_DRV_OPEN_DECLINED;
+
+        /* Leave for remote driver */
+        if (conn->uri->server != NULL)
+            return VIR_DRV_OPEN_DECLINED;
+
+        if (driver == NULL) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("storage state driver is not active"));
+            return VIR_DRV_OPEN_ERROR;
+        }
+
+        if (driver->privileged) {
+            if (STRNEQ(conn->uri->path, "/system")) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("unexpected storage URI path '%s', try storage:///system"),
+                               conn->uri->path);
+                return VIR_DRV_OPEN_ERROR;
+            }
+        } else {
+            if (STRNEQ(conn->uri->path, "/session")) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("unexpected storage URI path '%s', try storage:///session"),
+                               conn->uri->path);
+                return VIR_DRV_OPEN_ERROR;
+            }
+        }
+    }
+
+    if (virConnectOpenEnsureACL(conn) < 0)
+        return VIR_DRV_OPEN_ERROR;
+
+    return VIR_DRV_OPEN_SUCCESS;
+}
+
+static int storageConnectClose(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    return 0;
+}
+
+
+static int storageConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    /* Trivially secure, since always inside the daemon */
+    return 1;
+}
+
+
+static int storageConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    /* Not encrypted, but remote driver takes care of that */
+    return 0;
+}
+
+
+static int storageConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    return 1;
+}
+
 
 static virStoragePoolObjPtr
 storagePoolObjFindByUUID(const unsigned char *uuid,
@@ -3031,6 +3104,21 @@ static virStorageDriver storageDriver = {
 };
 
 
+static virHypervisorDriver storageHypervisorDriver = {
+    .name = "storage",
+    .connectOpen = storageConnectOpen, /* 4.1.0 */
+    .connectClose = storageConnectClose, /* 4.1.0 */
+    .connectIsEncrypted = storageConnectIsEncrypted, /* 4.1.0 */
+    .connectIsSecure = storageConnectIsSecure, /* 4.1.0 */
+    .connectIsAlive = storageConnectIsAlive, /* 4.1.0 */
+};
+
+static virConnectDriver storageConnectDriver = {
+    .hypervisorDriver = &storageHypervisorDriver,
+    .storageDriver = &storageDriver,
+};
+
+
 static virStateDriver stateDriver = {
     .name = "storage",
     .stateInitialize = storageStateInitialize,
@@ -3043,6 +3131,8 @@ static virStateDriver stateDriver = {
 static int
 storageRegisterFull(bool allbackends)
 {
+    if (virRegisterConnectDriver(&storageConnectDriver, false) < 0)
+        return -1;
     if (virStorageBackendDriversRegister(allbackends) < 0)
         return -1;
     if (virSetSharedStorageDriver(&storageDriver) < 0)
-- 
2.14.3

--
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]
  Powered by Linux