From a873b496daad822ed01094f177c67c8f7fcccfd8 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Mon, 15 Jul 2013 16:26:10 -0400 Subject: [PATCH] storage: Add connection for autostart storage pool Add a privileged field to storageDriverState Use the privileged value in order to generate a connection which could be passed to the various storage backend drivers. In particular, the iSCSI driver will need a connect in order to perform pool authentication using the 'chap' secrets and the RBD driver utilizes the connection during pool refresh for pools using 'ceph' secrets. For now that connection will be to be to qemu driver until a mechanism is devised to get a connection to just the secret driver without qemu. --- src/conf/storage_conf.h | 1 + src/storage/storage_driver.c | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index fd9b2e7627..62ff1fd93e 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -354,6 +354,7 @@ struct _virStorageDriverState { char *configDir; char *autostartDir; + bool privileged; }; typedef struct _virStoragePoolSourceList virStoragePoolSourceList; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 43bf6dece5..4f0c63182c 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -68,6 +68,14 @@ static void storageDriverUnlock(virStorageDriverStatePtr driver) static void storageDriverAutostart(virStorageDriverStatePtr driver) { size_t i; + virConnectPtr conn = NULL; + + /* XXX Remove hardcoding of QEMU URI */ + if (driverState->privileged) + conn = virConnectOpen("qemu:///system"); + else + conn = virConnectOpen("qemu:///session"); + /* Ignoring NULL conn - let backends decide */ for (i = 0; i < driver->pools.count; i++) { virStoragePoolObjPtr pool = driver->pools.objs[i]; @@ -82,7 +90,7 @@ storageDriverAutostart(virStorageDriverStatePtr driver) { } if (backend->checkPool && - backend->checkPool(NULL, pool, &started) < 0) { + backend->checkPool(conn, pool, &started) < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to initialize storage pool '%s': %s"), pool->def->name, err ? err->message : @@ -95,7 +103,7 @@ storageDriverAutostart(virStorageDriverStatePtr driver) { pool->autostart && !virStoragePoolObjIsActive(pool)) { if (backend->startPool && - backend->startPool(NULL, pool) < 0) { + backend->startPool(conn, pool) < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to autostart storage pool '%s': %s"), pool->def->name, err ? err->message : @@ -107,10 +115,10 @@ storageDriverAutostart(virStorageDriverStatePtr driver) { } if (started) { - if (backend->refreshPool(NULL, pool) < 0) { + if (backend->refreshPool(conn, pool) < 0) { virErrorPtr err = virGetLastError(); if (backend->stopPool) - backend->stopPool(NULL, pool); + backend->stopPool(conn, pool); VIR_ERROR(_("Failed to autostart storage pool '%s': %s"), pool->def->name, err ? err->message : _("no error message found")); @@ -121,6 +129,9 @@ storageDriverAutostart(virStorageDriverStatePtr driver) { } virStoragePoolObjUnlock(pool); } + + if (conn) + virConnectClose(conn); } /** @@ -152,6 +163,7 @@ storageStateInitialize(bool privileged, if (!base) goto error; } + driverState->privileged = privileged; /* Configuration paths are either $USER_CONFIG_HOME/libvirt/storage/... (session) or * /etc/libvirt/storage/... (system). -- GitLab