diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index fd9b2e76276e1c12a61623a7ccd2634bf5d1c56b..62ff1fd93e232c7d2f2a187c245324e623e0f0dd 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 43bf6dece5f19b48be6a128f0c9d563202424303..4f0c63182c88f7d0d2d2784a8fd06d4454862589 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).