2008-02-20 15:34:52 +00:00
|
|
|
/*
|
|
|
|
* storage_driver.c: core driver for storage APIs
|
|
|
|
*
|
2009-02-05 16:28:30 +00:00
|
|
|
* Copyright (C) 2006-2009 Red Hat, Inc.
|
2008-02-20 15:34:52 +00:00
|
|
|
* Copyright (C) 2006-2008 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
2008-04-18 08:33:23 +00:00
|
|
|
#if HAVE_PWD_H
|
2008-02-20 15:34:52 +00:00
|
|
|
#include <pwd.h>
|
2008-04-18 08:33:23 +00:00
|
|
|
#endif
|
2008-02-20 15:34:52 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
#include "virterror_internal.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
#include "datatypes.h"
|
2008-02-20 15:34:52 +00:00
|
|
|
#include "driver.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "storage_driver.h"
|
|
|
|
#include "storage_conf.h"
|
2008-06-06 11:09:57 +00:00
|
|
|
#include "memory.h"
|
2008-02-20 15:34:52 +00:00
|
|
|
#include "storage_backend.h"
|
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
#define storageLog(msg...) fprintf(stderr, msg)
|
|
|
|
|
|
|
|
static virStorageDriverStatePtr driverState;
|
|
|
|
|
|
|
|
static int storageDriverShutdown(void);
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
static void storageDriverLock(virStorageDriverStatePtr driver)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&driver->lock);
|
2008-12-04 21:40:42 +00:00
|
|
|
}
|
|
|
|
static void storageDriverUnlock(virStorageDriverStatePtr driver)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&driver->lock);
|
2008-12-04 21:40:42 +00:00
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
storageDriverAutostart(virStorageDriverStatePtr driver) {
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
for (i = 0 ; i < driver->pools.count ; i++) {
|
|
|
|
virStoragePoolObjPtr pool = driver->pools.objs[i];
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjLock(pool);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (pool->autostart &&
|
|
|
|
!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageBackendPtr backend;
|
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
|
|
|
|
storageLog("Missing backend %d",
|
|
|
|
pool->def->type);
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-02-20 15:34:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backend->startPool &&
|
|
|
|
backend->startPool(NULL, pool) < 0) {
|
|
|
|
virErrorPtr err = virGetLastError();
|
|
|
|
storageLog("Failed to autostart storage pool '%s': %s",
|
2009-11-10 11:56:11 +00:00
|
|
|
pool->def->name, err ? err->message :
|
|
|
|
"no error message found");
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-02-20 15:34:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backend->refreshPool(NULL, pool) < 0) {
|
|
|
|
virErrorPtr err = virGetLastError();
|
|
|
|
if (backend->stopPool)
|
|
|
|
backend->stopPool(NULL, pool);
|
|
|
|
storageLog("Failed to autostart storage pool '%s': %s",
|
2009-11-10 11:56:11 +00:00
|
|
|
pool->def->name, err ? err->message :
|
|
|
|
"no error message found");
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-02-20 15:34:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pool->active = 1;
|
|
|
|
}
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageStartup:
|
|
|
|
*
|
|
|
|
* Initialization function for the QEmu daemon
|
|
|
|
*/
|
|
|
|
static int
|
2009-06-12 13:20:13 +00:00
|
|
|
storageDriverStartup(int privileged) {
|
2008-02-20 15:34:52 +00:00
|
|
|
char *base = NULL;
|
|
|
|
char driverConf[PATH_MAX];
|
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(driverState) < 0)
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
if (virMutexInit(&driverState->lock) < 0) {
|
|
|
|
VIR_FREE(driverState);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driverState);
|
|
|
|
|
2009-06-12 13:20:13 +00:00
|
|
|
if (privileged) {
|
2008-02-20 15:34:52 +00:00
|
|
|
if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
|
|
|
|
goto out_of_memory;
|
|
|
|
} else {
|
2009-06-12 13:20:13 +00:00
|
|
|
uid_t uid = geteuid();
|
2009-01-22 19:41:48 +00:00
|
|
|
char *userdir = virGetUserDirectory(NULL, uid);
|
|
|
|
|
|
|
|
if (!userdir)
|
|
|
|
goto error;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-01-22 19:41:48 +00:00
|
|
|
if (virAsprintf(&base, "%s/.libvirt", userdir) == -1) {
|
2008-12-23 13:03:29 +00:00
|
|
|
storageLog("out of memory in virAsprintf");
|
2009-01-22 19:41:48 +00:00
|
|
|
VIR_FREE(userdir);
|
2008-02-20 15:34:52 +00:00
|
|
|
goto out_of_memory;
|
|
|
|
}
|
2009-01-22 19:41:48 +00:00
|
|
|
VIR_FREE(userdir);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Configuration paths are either ~/.libvirt/storage/... (session) or
|
|
|
|
* /etc/libvirt/storage/... (system).
|
|
|
|
*/
|
|
|
|
if (snprintf (driverConf, sizeof(driverConf),
|
|
|
|
"%s/storage.conf", base) == -1)
|
|
|
|
goto out_of_memory;
|
|
|
|
driverConf[sizeof(driverConf)-1] = '\0';
|
|
|
|
|
2008-12-23 13:03:29 +00:00
|
|
|
if (virAsprintf(&driverState->configDir,
|
|
|
|
"%s/storage", base) == -1)
|
2008-02-20 15:34:52 +00:00
|
|
|
goto out_of_memory;
|
|
|
|
|
2008-12-23 13:03:29 +00:00
|
|
|
if (virAsprintf(&driverState->autostartDir,
|
|
|
|
"%s/storage/autostart", base) == -1)
|
2008-02-20 15:34:52 +00:00
|
|
|
goto out_of_memory;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
VIR_FREE(base);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
if (virStorageLoadDriverConfig(driver, driverConf) < 0) {
|
|
|
|
virStorageDriverShutdown();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
if (virStoragePoolLoadAllConfigs(NULL,
|
|
|
|
&driverState->pools,
|
|
|
|
driverState->configDir,
|
2008-12-04 21:40:42 +00:00
|
|
|
driverState->autostartDir) < 0)
|
|
|
|
goto error;
|
2008-02-20 15:34:52 +00:00
|
|
|
storageDriverAutostart(driverState);
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driverState);
|
2008-02-20 15:34:52 +00:00
|
|
|
return 0;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
out_of_memory:
|
2008-02-20 15:34:52 +00:00
|
|
|
storageLog("virStorageStartup: out of memory");
|
2008-12-04 21:40:42 +00:00
|
|
|
error:
|
|
|
|
VIR_FREE(base);
|
|
|
|
storageDriverUnlock(driverState);
|
|
|
|
storageDriverShutdown();
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageReload:
|
|
|
|
*
|
|
|
|
* Function to restart the storage driver, it will recheck the configuration
|
|
|
|
* files and update its state
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
storageDriverReload(void) {
|
2008-10-10 15:13:28 +00:00
|
|
|
if (!driverState)
|
|
|
|
return -1;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driverState);
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolLoadAllConfigs(NULL,
|
|
|
|
&driverState->pools,
|
|
|
|
driverState->configDir,
|
|
|
|
driverState->autostartDir);
|
2008-02-20 15:34:52 +00:00
|
|
|
storageDriverAutostart(driverState);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driverState);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageActive:
|
|
|
|
*
|
|
|
|
* Checks if the storage driver is active, i.e. has an active pool
|
|
|
|
*
|
|
|
|
* Returns 1 if active, 0 otherwise
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
storageDriverActive(void) {
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
2008-12-04 21:40:42 +00:00
|
|
|
int active = 0;
|
2008-10-10 15:13:28 +00:00
|
|
|
|
|
|
|
if (!driverState)
|
|
|
|
return 0;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driverState);
|
|
|
|
|
|
|
|
for (i = 0 ; i < driverState->pools.count ; i++) {
|
|
|
|
virStoragePoolObjLock(driverState->pools.objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
if (virStoragePoolObjIsActive(driverState->pools.objs[i]))
|
2008-12-04 21:40:42 +00:00
|
|
|
active = 1;
|
|
|
|
virStoragePoolObjUnlock(driverState->pools.objs[i]);
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driverState);
|
|
|
|
return active;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageShutdown:
|
|
|
|
*
|
|
|
|
* Shutdown the storage driver, it will stop all active storage pools
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
storageDriverShutdown(void) {
|
|
|
|
if (!driverState)
|
|
|
|
return -1;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driverState);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
/* free inactive pools */
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolObjListFree(&driverState->pools);
|
|
|
|
|
|
|
|
VIR_FREE(driverState->configDir);
|
|
|
|
VIR_FREE(driverState->autostartDir);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driverState);
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexDestroy(&driverState->lock);
|
2008-10-10 15:13:28 +00:00
|
|
|
VIR_FREE(driverState);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virStoragePoolPtr
|
|
|
|
storagePoolLookupByUUID(virConnectPtr conn,
|
|
|
|
const unsigned char *uuid) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
virStoragePoolPtr ret = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_NO_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-02-20 15:34:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virStoragePoolPtr
|
|
|
|
storagePoolLookupByName(virConnectPtr conn,
|
|
|
|
const char *name) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
virStoragePoolPtr ret = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, name);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_NO_STORAGE_POOL,
|
2009-07-08 10:01:35 +00:00
|
|
|
_("no pool with matching name '%s'"), name);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-02-20 15:34:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virStoragePoolPtr
|
|
|
|
storagePoolLookupByVolume(virStorageVolPtr vol) {
|
|
|
|
return storagePoolLookupByName(vol->conn, vol->pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDrvOpenStatus
|
|
|
|
storageOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
|
|
|
int flags ATTRIBUTE_UNUSED) {
|
|
|
|
if (!driverState)
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
conn->storagePrivateData = driverState;
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storageClose(virConnectPtr conn) {
|
|
|
|
conn->storagePrivateData = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storageNumPools(virConnectPtr conn) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i, nactive = 0;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
|
|
|
for (i = 0 ; i < driver->pools.count ; i++) {
|
|
|
|
virStoragePoolObjLock(driver->pools.objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
if (virStoragePoolObjIsActive(driver->pools.objs[i]))
|
|
|
|
nactive++;
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
|
|
|
}
|
|
|
|
storageDriverUnlock(driver);
|
2008-10-10 15:13:28 +00:00
|
|
|
|
|
|
|
return nactive;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storageListPools(virConnectPtr conn,
|
|
|
|
char **const names,
|
|
|
|
int nnames) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
2008-02-20 15:34:52 +00:00
|
|
|
int got = 0, i;
|
2008-10-10 15:13:28 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-10-10 15:13:28 +00:00
|
|
|
for (i = 0 ; i < driver->pools.count && got < nnames ; i++) {
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjLock(driver->pools.objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
|
|
|
|
if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) {
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportOOMError(conn);
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
got++;
|
|
|
|
}
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
2008-02-20 15:34:52 +00:00
|
|
|
return got;
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
for (i = 0 ; i < got ; i++)
|
|
|
|
VIR_FREE(names[i]);
|
2008-12-02 15:59:14 +00:00
|
|
|
memset(names, 0, nnames * sizeof(*names));
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storageNumDefinedPools(virConnectPtr conn) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i, nactive = 0;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
|
|
|
for (i = 0 ; i < driver->pools.count ; i++) {
|
|
|
|
virStoragePoolObjLock(driver->pools.objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
if (!virStoragePoolObjIsActive(driver->pools.objs[i]))
|
|
|
|
nactive++;
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
|
|
|
}
|
|
|
|
storageDriverUnlock(driver);
|
2008-10-10 15:13:28 +00:00
|
|
|
|
|
|
|
return nactive;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storageListDefinedPools(virConnectPtr conn,
|
|
|
|
char **const names,
|
|
|
|
int nnames) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
2008-02-20 15:34:52 +00:00
|
|
|
int got = 0, i;
|
2008-10-10 15:13:28 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-10-10 15:13:28 +00:00
|
|
|
for (i = 0 ; i < driver->pools.count && got < nnames ; i++) {
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjLock(driver->pools.objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
if (!virStoragePoolObjIsActive(driver->pools.objs[i])) {
|
|
|
|
if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) {
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportOOMError(conn);
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
got++;
|
|
|
|
}
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
2008-02-20 15:34:52 +00:00
|
|
|
return got;
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
2008-02-20 15:34:52 +00:00
|
|
|
for (i = 0 ; i < got ; i++) {
|
2009-12-09 23:00:50 +00:00
|
|
|
VIR_FREE(names[i]);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-12-02 15:59:14 +00:00
|
|
|
memset(names, 0, nnames * sizeof(*names));
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
/* This method is required to be re-entrant / thread safe, so
|
|
|
|
uses no driver lock */
|
2008-08-27 20:05:58 +00:00
|
|
|
static char *
|
|
|
|
storageFindPoolSources(virConnectPtr conn,
|
|
|
|
const char *type,
|
|
|
|
const char *srcSpec,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int backend_type;
|
|
|
|
virStorageBackendPtr backend;
|
2008-12-04 21:39:45 +00:00
|
|
|
char *ret = NULL;
|
2008-08-27 20:05:58 +00:00
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
backend_type = virStoragePoolTypeFromString(type);
|
2009-10-08 14:24:37 +00:00
|
|
|
if (backend_type < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unknown storage pool type %s"), type);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2009-10-08 14:24:37 +00:00
|
|
|
}
|
2008-08-27 20:05:58 +00:00
|
|
|
|
|
|
|
backend = virStorageBackendForType(backend_type);
|
|
|
|
if (backend == NULL)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-08-27 20:05:58 +00:00
|
|
|
|
2009-10-08 14:24:37 +00:00
|
|
|
if (!backend->findPoolSources) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_NO_SUPPORT,
|
|
|
|
_("pool type '%s' does not support source "
|
|
|
|
"discovery"), type);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = backend->findPoolSources(conn, srcSpec, flags);
|
2008-08-27 20:05:58 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
|
|
|
return ret;
|
2008-08-27 20:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-09 09:38:11 +00:00
|
|
|
static int storagePoolIsActive(virStoragePoolPtr pool)
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
{
|
2009-12-09 09:38:11 +00:00
|
|
|
virStorageDriverStatePtr driver = pool->conn->storagePrivateData;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
storageDriverLock(driver);
|
2009-12-09 09:38:11 +00:00
|
|
|
obj = virStoragePoolObjFindByUUID(&driver->pools, pool->uuid);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
if (!obj) {
|
2009-12-09 09:38:11 +00:00
|
|
|
virStorageReportError(pool->conn, VIR_ERR_NO_STORAGE_POOL, NULL);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = virStoragePoolObjIsActive(obj);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (obj)
|
|
|
|
virStoragePoolObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-09 09:38:11 +00:00
|
|
|
static int storagePoolIsPersistent(virStoragePoolPtr pool)
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
{
|
2009-12-09 09:38:11 +00:00
|
|
|
virStorageDriverStatePtr driver = pool->conn->storagePrivateData;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
virStoragePoolObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
storageDriverLock(driver);
|
2009-12-09 09:38:11 +00:00
|
|
|
obj = virStoragePoolObjFindByUUID(&driver->pools, pool->uuid);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
if (!obj) {
|
2009-12-09 09:38:11 +00:00
|
|
|
virStorageReportError(pool->conn, VIR_ERR_NO_STORAGE_POOL, NULL);
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = obj->configFile ? 1 : 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (obj)
|
|
|
|
virStoragePoolObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
static virStoragePoolPtr
|
|
|
|
storagePoolCreate(virConnectPtr conn,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjPtr pool = NULL;
|
2008-12-04 21:39:45 +00:00
|
|
|
virStoragePoolPtr ret = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendPtr backend;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2009-06-22 16:41:34 +00:00
|
|
|
if (!(def = virStoragePoolDefParseString(conn, xml)))
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, def->uuid);
|
|
|
|
if (!pool)
|
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, def->name);
|
|
|
|
|
|
|
|
if (pool) {
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool already exists"));
|
2009-07-01 08:33:22 +00:00
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
pool = NULL;
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if ((backend = virStorageBackendForType(def->type)) == NULL)
|
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if (!(pool = virStoragePoolObjAssignDef(conn, &driver->pools, def)))
|
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-03-17 15:10:48 +00:00
|
|
|
if (backend->startPool &&
|
2009-09-02 13:02:06 +00:00
|
|
|
backend->startPool(conn, pool) < 0) {
|
|
|
|
virStoragePoolObjRemove(&driver->pools, pool);
|
|
|
|
pool = NULL;
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2009-09-02 13:02:06 +00:00
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2008-03-17 15:10:48 +00:00
|
|
|
if (backend->refreshPool(conn, pool) < 0) {
|
|
|
|
if (backend->stopPool)
|
|
|
|
backend->stopPool(conn, pool);
|
2009-09-02 13:02:06 +00:00
|
|
|
virStoragePoolObjRemove(&driver->pools, pool);
|
|
|
|
pool = NULL;
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
pool->active = 1;
|
|
|
|
|
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid);
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
|
|
|
virStoragePoolDefFree(def);
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
2009-09-02 13:02:06 +00:00
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
2008-02-20 15:34:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virStoragePoolPtr
|
|
|
|
storagePoolDefine(virConnectPtr conn,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjPtr pool = NULL;
|
2008-12-04 21:39:45 +00:00
|
|
|
virStoragePoolPtr ret = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2009-06-22 16:41:34 +00:00
|
|
|
if (!(def = virStoragePoolDefParseString(conn, xml)))
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-09-04 15:18:29 +00:00
|
|
|
if (virStorageBackendForType(def->type) == NULL)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if (!(pool = virStoragePoolObjAssignDef(conn, &driver->pools, def)))
|
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
if (virStoragePoolObjSaveDef(conn, driver, pool, def) < 0) {
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolObjRemove(&driver->pools, pool);
|
2008-12-22 16:30:57 +00:00
|
|
|
def = NULL;
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-12-22 16:30:57 +00:00
|
|
|
def = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virStoragePoolDefFree(def);
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
storageDriverUnlock(driver);
|
2008-02-20 15:34:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storagePoolUndefine(virStoragePoolPtr obj) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("pool is still active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
if (pool->asyncjobs > 0) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("pool '%s' has asynchronous jobs running."),
|
|
|
|
pool->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (virStoragePoolObjDeleteDef(obj->conn, pool) < 0)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-02-05 16:28:30 +00:00
|
|
|
if (unlink(pool->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
|
|
|
|
char ebuf[1024];
|
2008-02-20 15:34:52 +00:00
|
|
|
storageLog("Failed to delete autostart link '%s': %s",
|
2009-02-05 16:28:30 +00:00
|
|
|
pool->autostartLink, virStrerror(errno, ebuf, sizeof ebuf));
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
VIR_FREE(pool->configFile);
|
|
|
|
VIR_FREE(pool->autostartLink);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolObjRemove(&driver->pools, pool);
|
2008-12-04 21:40:42 +00:00
|
|
|
pool = NULL;
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
storageDriverUnlock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storagePoolStart(virStoragePoolPtr obj,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendPtr backend;
|
2008-12-04 21:39:45 +00:00
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
if (virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("pool already active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
if (backend->startPool &&
|
|
|
|
backend->startPool(obj->conn, pool) < 0)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (backend->refreshPool(obj->conn, pool) < 0) {
|
|
|
|
if (backend->stopPool)
|
|
|
|
backend->stopPool(obj->conn, pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pool->active = 1;
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storagePoolBuild(virStoragePoolPtr obj,
|
|
|
|
unsigned int flags) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendPtr backend;
|
2008-12-04 21:39:45 +00:00
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
if (virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is already active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (backend->buildPool &&
|
|
|
|
backend->buildPool(obj->conn, pool, flags) < 0)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
storagePoolDestroy(virStoragePoolPtr obj) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendPtr backend;
|
2008-12-04 21:39:45 +00:00
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is not active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
if (pool->asyncjobs > 0) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("pool '%s' has asynchronous jobs running."),
|
|
|
|
pool->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (backend->stopPool &&
|
|
|
|
backend->stopPool(obj->conn, pool) < 0)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
virStoragePoolObjClearVols(pool);
|
|
|
|
|
|
|
|
pool->active = 0;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool->configFile == NULL) {
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolObjRemove(&driver->pools, pool);
|
2008-12-04 21:40:42 +00:00
|
|
|
pool = NULL;
|
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
storageDriverUnlock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
storagePoolDelete(virStoragePoolPtr obj,
|
|
|
|
unsigned int flags) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendPtr backend;
|
2008-12-04 21:39:45 +00:00
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
if (virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is still active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
if (pool->asyncjobs > 0) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("pool '%s' has asynchronous jobs running."),
|
|
|
|
pool->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!backend->deletePool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_NO_SUPPORT,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("pool does not support volume delete"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
if (backend->deletePool(obj->conn, pool, flags) < 0)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
storagePoolRefresh(virStoragePoolPtr obj,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendPtr backend;
|
2008-12-04 21:39:45 +00:00
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is not active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
if (pool->asyncjobs > 0) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("pool '%s' has asynchronous jobs running."),
|
|
|
|
pool->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
virStoragePoolObjClearVols(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
if (backend->refreshPool(obj->conn, pool) < 0) {
|
2008-02-20 15:34:52 +00:00
|
|
|
if (backend->stopPool)
|
|
|
|
backend->stopPool(obj->conn, pool);
|
|
|
|
|
|
|
|
pool->active = 0;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool->configFile == NULL) {
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolObjRemove(&driver->pools, pool);
|
2008-12-04 21:40:42 +00:00
|
|
|
pool = NULL;
|
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2009-05-19 11:06:25 +00:00
|
|
|
storageDriverUnlock(driver);
|
2008-02-20 15:34:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
storagePoolGetInfo(virStoragePoolPtr obj,
|
|
|
|
virStoragePoolInfoPtr info) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 15:18:29 +00:00
|
|
|
if (virStorageBackendForType(pool->def->type) == NULL)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
memset(info, 0, sizeof(virStoragePoolInfo));
|
|
|
|
if (pool->active)
|
|
|
|
info->state = VIR_STORAGE_POOL_RUNNING;
|
|
|
|
else
|
|
|
|
info->state = VIR_STORAGE_POOL_INACTIVE;
|
|
|
|
info->capacity = pool->def->capacity;
|
|
|
|
info->allocation = pool->def->allocation;
|
|
|
|
info->available = pool->def->available;
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
storagePoolDumpXML(virStoragePoolPtr obj,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
char *ret = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = virStoragePoolDefFormat(obj->conn, pool->def);
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storagePoolGetAutostart(virStoragePoolPtr obj,
|
|
|
|
int *autostart) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!pool->configFile) {
|
|
|
|
*autostart = 0;
|
|
|
|
} else {
|
|
|
|
*autostart = pool->autostart;
|
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-11 15:00:12 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storagePoolSetAutostart(virStoragePoolPtr obj,
|
|
|
|
int autostart) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!pool->configFile) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_ARG,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("pool has no config file"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
autostart = (autostart != 0);
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if (pool->autostart != autostart) {
|
|
|
|
if (autostart) {
|
|
|
|
int err;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if ((err = virFileMakePath(driver->autostartDir))) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(obj->conn, err,
|
|
|
|
_("cannot create autostart directory %s"),
|
|
|
|
driver->autostartDir);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if (symlink(pool->configFile, pool->autostartLink) < 0) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(obj->conn, errno,
|
|
|
|
_("Failed to create symlink '%s' to '%s'"),
|
|
|
|
pool->autostartLink, pool->configFile);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (unlink(pool->autostartLink) < 0 &&
|
|
|
|
errno != ENOENT && errno != ENOTDIR) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(obj->conn, errno,
|
|
|
|
_("Failed to delete symlink '%s'"),
|
|
|
|
pool->autostartLink);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
pool->autostart = autostart;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2009-05-19 11:06:25 +00:00
|
|
|
storageDriverUnlock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
storagePoolNumVolumes(virStoragePoolPtr obj) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is not active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = pool->volumes.count;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storagePoolListVolumes(virStoragePoolPtr obj,
|
|
|
|
char **const names,
|
|
|
|
int maxnames) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2008-10-10 15:13:28 +00:00
|
|
|
int i, n = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
memset(names, 0, maxnames * sizeof(*names));
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is not active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
for (i = 0 ; i < pool->volumes.count && n < maxnames ; i++) {
|
|
|
|
if ((names[n++] = strdup(pool->volumes.objs[i]->name)) == NULL) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportOOMError(obj->conn);
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-10-10 15:13:28 +00:00
|
|
|
return n;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-10-10 15:13:28 +00:00
|
|
|
for (n = 0 ; n < maxnames ; n++)
|
2008-12-04 21:39:45 +00:00
|
|
|
VIR_FREE(names[n]);
|
2008-10-10 15:13:28 +00:00
|
|
|
|
2008-12-02 15:59:14 +00:00
|
|
|
memset(names, 0, maxnames * sizeof(*names));
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virStorageVolPtr
|
|
|
|
storageVolumeLookupByName(virStoragePoolPtr obj,
|
|
|
|
const char *name) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageVolDefPtr vol;
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageVolPtr ret = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is not active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vol = virStorageVolDefFindByName(pool, name);
|
|
|
|
|
|
|
|
if (!vol) {
|
2009-07-08 10:01:35 +00:00
|
|
|
virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
name);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = virGetStorageVol(obj->conn, pool->def->name, vol->name, vol->key);
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virStorageVolPtr
|
|
|
|
storageVolumeLookupByKey(virConnectPtr conn,
|
|
|
|
const char *key) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageVolPtr ret = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
|
|
|
for (i = 0 ; i < driver->pools.count && !ret ; i++) {
|
|
|
|
virStoragePoolObjLock(driver->pools.objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
|
|
|
|
virStorageVolDefPtr vol =
|
|
|
|
virStorageVolDefFindByKey(driver->pools.objs[i], key);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
if (vol)
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = virGetStorageVol(conn,
|
2008-12-04 21:40:42 +00:00
|
|
|
driver->pools.objs[i]->def->name,
|
|
|
|
vol->name,
|
|
|
|
vol->key);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if (!ret)
|
|
|
|
virStorageReportError(conn, VIR_ERR_INVALID_STORAGE_VOL,
|
|
|
|
"%s", _("no storage vol with matching key"));
|
|
|
|
|
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static virStorageVolPtr
|
|
|
|
storageVolumeLookupByPath(virConnectPtr conn,
|
|
|
|
const char *path) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageVolPtr ret = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
|
|
|
for (i = 0 ; i < driver->pools.count && !ret ; i++) {
|
|
|
|
virStoragePoolObjLock(driver->pools.objs[i]);
|
2008-10-10 15:13:28 +00:00
|
|
|
if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
|
2008-11-03 11:37:11 +00:00
|
|
|
virStorageVolDefPtr vol;
|
2008-11-17 11:19:33 +00:00
|
|
|
const char *stable_path;
|
|
|
|
|
|
|
|
stable_path = virStorageBackendStablePath(conn,
|
|
|
|
driver->pools.objs[i],
|
|
|
|
path);
|
|
|
|
/*
|
|
|
|
* virStorageBackendStablePath already does
|
|
|
|
* virStorageReportError if it fails; we just need to keep
|
|
|
|
* propagating the return code
|
|
|
|
*/
|
2008-12-04 21:40:42 +00:00
|
|
|
if (stable_path == NULL) {
|
|
|
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-12-04 21:40:42 +00:00
|
|
|
}
|
2008-11-17 11:19:33 +00:00
|
|
|
|
|
|
|
vol = virStorageVolDefFindByPath(driver->pools.objs[i],
|
|
|
|
stable_path);
|
|
|
|
VIR_FREE(stable_path);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
if (vol)
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = virGetStorageVol(conn,
|
|
|
|
driver->pools.objs[i]->def->name,
|
|
|
|
vol->name,
|
|
|
|
vol->key);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if (!ret)
|
|
|
|
virStorageReportError(conn, VIR_ERR_INVALID_STORAGE_VOL,
|
|
|
|
"%s", _("no storage vol with matching path"));
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
static int storageVolumeDelete(virStorageVolPtr obj, unsigned int flags);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
static virStorageVolPtr
|
|
|
|
storageVolumeCreateXML(virStoragePoolPtr obj,
|
|
|
|
const char *xmldesc,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendPtr backend;
|
2009-04-17 19:12:37 +00:00
|
|
|
virStorageVolDefPtr voldef = NULL;
|
|
|
|
virStorageVolPtr ret = NULL, volobj = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is not active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-06-22 16:41:34 +00:00
|
|
|
voldef = virStorageVolDefParseString(obj->conn, pool->def, xmldesc);
|
2009-04-17 19:12:37 +00:00
|
|
|
if (voldef == NULL)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
if (virStorageVolDefFindByName(pool, voldef->name)) {
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage vol already exists"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
if (VIR_REALLOC_N(pool->volumes.objs,
|
|
|
|
pool->volumes.count+1) < 0) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportOOMError(obj->conn);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-10-10 15:13:28 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!backend->createVol) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_NO_SUPPORT,
|
2009-04-17 19:12:37 +00:00
|
|
|
"%s", _("storage pool does not support volume "
|
|
|
|
"creation"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
if (backend->createVol(obj->conn, pool, voldef) < 0) {
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
pool->volumes.objs[pool->volumes.count++] = voldef;
|
|
|
|
volobj = virGetStorageVol(obj->conn, pool->def->name, voldef->name,
|
|
|
|
voldef->key);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
if (volobj && backend->buildVol) {
|
|
|
|
int buildret;
|
|
|
|
virStorageVolDefPtr buildvoldef = NULL;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(buildvoldef) < 0) {
|
|
|
|
virReportOOMError(obj->conn);
|
|
|
|
voldef = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make a shallow copy of the 'defined' volume definition, since the
|
|
|
|
* original allocation value will change as the user polls 'info',
|
|
|
|
* but we only need the initial requested values
|
|
|
|
*/
|
|
|
|
memcpy(buildvoldef, voldef, sizeof(*voldef));
|
|
|
|
|
|
|
|
/* Drop the pool lock during volume allocation */
|
|
|
|
pool->asyncjobs++;
|
|
|
|
voldef->building = 1;
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
|
2010-01-20 23:41:52 +00:00
|
|
|
buildret = backend->buildVol(obj->conn, pool, buildvoldef);
|
2009-04-17 19:12:37 +00:00
|
|
|
|
2009-05-19 11:06:25 +00:00
|
|
|
storageDriverLock(driver);
|
2009-04-17 19:12:37 +00:00
|
|
|
virStoragePoolObjLock(pool);
|
2009-05-19 11:06:25 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
voldef->building = 0;
|
|
|
|
pool->asyncjobs--;
|
|
|
|
|
|
|
|
voldef = NULL;
|
|
|
|
VIR_FREE(buildvoldef);
|
|
|
|
|
|
|
|
if (buildret < 0) {
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
storageVolumeDelete(volobj, 0);
|
|
|
|
pool = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = volobj;
|
|
|
|
volobj = NULL;
|
|
|
|
voldef = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2009-04-17 19:12:37 +00:00
|
|
|
if (volobj)
|
|
|
|
virUnrefStorageVol(volobj);
|
|
|
|
virStorageVolDefFree(voldef);
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2009-05-19 13:37:51 +00:00
|
|
|
static virStorageVolPtr
|
|
|
|
storageVolumeCreateXMLFrom(virStoragePoolPtr obj,
|
|
|
|
const char *xmldesc,
|
|
|
|
virStorageVolPtr vobj,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool, origpool = NULL;
|
|
|
|
virStorageBackendPtr backend;
|
|
|
|
virStorageVolDefPtr origvol = NULL, newvol = NULL;
|
|
|
|
virStorageVolPtr ret = NULL, volobj = NULL;
|
2009-09-02 13:02:06 +00:00
|
|
|
int buildret;
|
2009-05-19 13:37:51 +00:00
|
|
|
|
|
|
|
storageDriverLock(driver);
|
|
|
|
pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
|
2009-09-02 13:02:06 +00:00
|
|
|
if (pool && STRNEQ(obj->name, vobj->pool)) {
|
2009-07-10 16:56:12 +00:00
|
|
|
virStoragePoolObjUnlock(pool);
|
2009-05-19 13:37:51 +00:00
|
|
|
origpool = virStoragePoolObjFindByName(&driver->pools, vobj->pool);
|
2009-07-10 16:56:12 +00:00
|
|
|
virStoragePoolObjLock(pool);
|
2009-09-02 13:02:06 +00:00
|
|
|
}
|
2009-05-19 13:37:51 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
|
|
|
"%s", _("no storage pool with matching uuid"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-09-02 13:02:06 +00:00
|
|
|
if (STRNEQ(obj->name, vobj->pool) && !origpool) {
|
2009-07-08 10:01:35 +00:00
|
|
|
virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_POOL,
|
|
|
|
_("no storage pool with matching name '%s'"),
|
|
|
|
vobj->pool);
|
2009-05-19 13:37:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("storage pool is not active"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-09-02 13:02:06 +00:00
|
|
|
if (origpool && !virStoragePoolObjIsActive(origpool)) {
|
2009-05-19 13:37:51 +00:00
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("storage pool is not active"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2009-09-02 13:02:06 +00:00
|
|
|
origvol = virStorageVolDefFindByName(origpool ? origpool : pool, vobj->name);
|
2009-05-19 13:37:51 +00:00
|
|
|
if (!origvol) {
|
2009-07-08 10:01:35 +00:00
|
|
|
virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
vobj->name);
|
2009-05-19 13:37:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-06-22 16:41:34 +00:00
|
|
|
newvol = virStorageVolDefParseString(obj->conn, pool->def, xmldesc);
|
2009-05-19 13:37:51 +00:00
|
|
|
if (newvol == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virStorageVolDefFindByName(pool, newvol->name)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
|
|
|
_("storage volume name '%s' already in use."),
|
|
|
|
newvol->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is there ever a valid case for this? */
|
|
|
|
if (newvol->capacity < origvol->capacity)
|
|
|
|
newvol->capacity = origvol->capacity;
|
|
|
|
|
2009-06-22 16:33:24 +00:00
|
|
|
/* Make sure allocation is at least as large as the destination cap,
|
|
|
|
* to make absolutely sure we copy all possible contents */
|
|
|
|
if (newvol->allocation < origvol->capacity)
|
|
|
|
newvol->allocation = origvol->capacity;
|
|
|
|
|
2009-05-19 13:37:51 +00:00
|
|
|
if (!backend->buildVolFrom) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_NO_SUPPORT,
|
|
|
|
"%s", _("storage pool does not support volume creation from an existing volume"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (origvol->building) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("volume '%s' is still being allocated."),
|
|
|
|
origvol->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backend->refreshVol &&
|
|
|
|
backend->refreshVol(obj->conn, pool, origvol) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(pool->volumes.objs,
|
|
|
|
pool->volumes.count+1) < 0) {
|
|
|
|
virReportOOMError(obj->conn);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 'Define' the new volume so we get async progress reporting */
|
|
|
|
if (backend->createVol(obj->conn, pool, newvol) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
pool->volumes.objs[pool->volumes.count++] = newvol;
|
|
|
|
volobj = virGetStorageVol(obj->conn, pool->def->name, newvol->name,
|
|
|
|
newvol->key);
|
|
|
|
|
|
|
|
/* Drop the pool lock during volume allocation */
|
|
|
|
pool->asyncjobs++;
|
|
|
|
origvol->building = 1;
|
|
|
|
newvol->building = 1;
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
|
2009-09-02 13:02:06 +00:00
|
|
|
if (origpool) {
|
2009-05-19 13:37:51 +00:00
|
|
|
origpool->asyncjobs++;
|
|
|
|
virStoragePoolObjUnlock(origpool);
|
|
|
|
}
|
|
|
|
|
2010-01-20 23:41:52 +00:00
|
|
|
buildret = backend->buildVolFrom(obj->conn, pool, newvol, origvol, flags);
|
2009-05-19 13:37:51 +00:00
|
|
|
|
|
|
|
storageDriverLock(driver);
|
|
|
|
virStoragePoolObjLock(pool);
|
2009-09-02 13:02:06 +00:00
|
|
|
if (origpool)
|
2009-05-19 13:37:51 +00:00
|
|
|
virStoragePoolObjLock(origpool);
|
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
|
|
|
origvol->building = 0;
|
|
|
|
newvol->building = 0;
|
|
|
|
newvol = NULL;
|
|
|
|
pool->asyncjobs--;
|
|
|
|
|
2009-09-02 13:02:06 +00:00
|
|
|
if (origpool) {
|
2009-05-19 13:37:51 +00:00
|
|
|
origpool->asyncjobs--;
|
|
|
|
virStoragePoolObjUnlock(origpool);
|
|
|
|
origpool = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buildret < 0) {
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
storageVolumeDelete(volobj, 0);
|
|
|
|
pool = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = volobj;
|
|
|
|
volobj = NULL;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (volobj)
|
|
|
|
virUnrefStorageVol(volobj);
|
|
|
|
virStorageVolDefFree(newvol);
|
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2009-09-02 13:02:06 +00:00
|
|
|
if (origpool)
|
2009-05-19 13:37:51 +00:00
|
|
|
virStoragePoolObjUnlock(origpool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
static int
|
|
|
|
storageVolumeDelete(virStorageVolPtr obj,
|
|
|
|
unsigned int flags) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendPtr backend;
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageVolDefPtr vol = NULL;
|
2008-10-10 15:13:28 +00:00
|
|
|
unsigned int i;
|
2008-12-04 21:39:45 +00:00
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is not active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
vol = virStorageVolDefFindByName(pool, obj->name);
|
|
|
|
|
|
|
|
if (!vol) {
|
2009-07-08 10:01:35 +00:00
|
|
|
virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
obj->name);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
if (vol->building) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("volume '%s' is still being allocated."),
|
|
|
|
vol->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!backend->deleteVol) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_NO_SUPPORT,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool does not support vol deletion"));
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if (backend->deleteVol(obj->conn, pool, vol, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
for (i = 0 ; i < pool->volumes.count ; i++) {
|
|
|
|
if (pool->volumes.objs[i] == vol) {
|
|
|
|
virStorageVolDefFree(vol);
|
2008-12-04 21:39:45 +00:00
|
|
|
vol = NULL;
|
2008-10-10 15:13:28 +00:00
|
|
|
|
|
|
|
if (i < (pool->volumes.count - 1))
|
|
|
|
memmove(pool->volumes.objs + i, pool->volumes.objs + i + 1,
|
|
|
|
sizeof(*(pool->volumes.objs)) * (pool->volumes.count - (i + 1)));
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count - 1) < 0) {
|
|
|
|
; /* Failure to reduce memory allocation isn't fatal */
|
|
|
|
}
|
|
|
|
pool->volumes.count--;
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
storageVolumeGetInfo(virStorageVolPtr obj,
|
|
|
|
virStorageVolInfoPtr info) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendPtr backend;
|
|
|
|
virStorageVolDefPtr vol;
|
2008-12-04 21:39:45 +00:00
|
|
|
int ret = -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is not active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vol = virStorageVolDefFindByName(pool, obj->name);
|
|
|
|
|
|
|
|
if (!vol) {
|
2009-07-08 10:01:35 +00:00
|
|
|
virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
obj->name);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
if (backend->refreshVol &&
|
|
|
|
backend->refreshVol(obj->conn, pool, vol) < 0)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
memset(info, 0, sizeof(*info));
|
2008-11-17 11:19:33 +00:00
|
|
|
info->type = vol->type;
|
2008-02-20 15:34:52 +00:00
|
|
|
info->capacity = vol->capacity;
|
|
|
|
info->allocation = vol->allocation;
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
storageVolumeGetXMLDesc(virStorageVolPtr obj,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageBackendPtr backend;
|
|
|
|
virStorageVolDefPtr vol;
|
2008-12-04 21:39:45 +00:00
|
|
|
char *ret = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is not active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vol = virStorageVolDefFindByName(pool, obj->name);
|
|
|
|
|
|
|
|
if (!vol) {
|
2009-07-08 10:01:35 +00:00
|
|
|
virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
obj->name);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2009-04-03 14:15:30 +00:00
|
|
|
|
|
|
|
if (backend->refreshVol &&
|
|
|
|
backend->refreshVol(obj->conn, pool, vol) < 0)
|
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = virStorageVolDefFormat(obj->conn, pool->def, vol);
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
storageVolumeGetPath(virStorageVolPtr obj) {
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjPtr pool;
|
2008-02-20 15:34:52 +00:00
|
|
|
virStorageVolDefPtr vol;
|
2008-12-04 21:39:45 +00:00
|
|
|
char *ret = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
|
|
|
storageDriverUnlock(driver);
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("no storage pool with matching uuid"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("storage pool is not active"));
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vol = virStorageVolDefFindByName(pool, obj->name);
|
|
|
|
|
|
|
|
if (!vol) {
|
2009-07-08 10:01:35 +00:00
|
|
|
virStorageReportError(obj->conn, VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
obj->name);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = strdup(vol->target.path);
|
2008-12-04 21:39:45 +00:00
|
|
|
if (ret == NULL)
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportOOMError(obj->conn);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:40:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-02-20 15:34:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virStorageDriver storageDriver = {
|
2008-09-22 19:53:42 +00:00
|
|
|
.name = "storage",
|
|
|
|
.open = storageOpen,
|
|
|
|
.close = storageClose,
|
|
|
|
.numOfPools = storageNumPools,
|
|
|
|
.listPools = storageListPools,
|
|
|
|
.numOfDefinedPools = storageNumDefinedPools,
|
|
|
|
.listDefinedPools = storageListDefinedPools,
|
|
|
|
.findPoolSources = storageFindPoolSources,
|
|
|
|
.poolLookupByName = storagePoolLookupByName,
|
|
|
|
.poolLookupByUUID = storagePoolLookupByUUID,
|
|
|
|
.poolLookupByVolume = storagePoolLookupByVolume,
|
|
|
|
.poolCreateXML = storagePoolCreate,
|
|
|
|
.poolDefineXML = storagePoolDefine,
|
|
|
|
.poolBuild = storagePoolBuild,
|
|
|
|
.poolUndefine = storagePoolUndefine,
|
|
|
|
.poolCreate = storagePoolStart,
|
|
|
|
.poolDestroy = storagePoolDestroy,
|
|
|
|
.poolDelete = storagePoolDelete,
|
|
|
|
.poolRefresh = storagePoolRefresh,
|
|
|
|
.poolGetInfo = storagePoolGetInfo,
|
|
|
|
.poolGetXMLDesc = storagePoolDumpXML,
|
|
|
|
.poolGetAutostart = storagePoolGetAutostart,
|
|
|
|
.poolSetAutostart = storagePoolSetAutostart,
|
|
|
|
.poolNumOfVolumes = storagePoolNumVolumes,
|
|
|
|
.poolListVolumes = storagePoolListVolumes,
|
|
|
|
|
|
|
|
.volLookupByName = storageVolumeLookupByName,
|
|
|
|
.volLookupByKey = storageVolumeLookupByKey,
|
|
|
|
.volLookupByPath = storageVolumeLookupByPath,
|
|
|
|
.volCreateXML = storageVolumeCreateXML,
|
2009-05-19 13:37:51 +00:00
|
|
|
.volCreateXMLFrom = storageVolumeCreateXMLFrom,
|
2008-09-22 19:53:42 +00:00
|
|
|
.volDelete = storageVolumeDelete,
|
|
|
|
.volGetInfo = storageVolumeGetInfo,
|
|
|
|
.volGetXMLDesc = storageVolumeGetXMLDesc,
|
|
|
|
.volGetPath = storageVolumeGetPath,
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
|
|
|
|
.poolIsActive = storagePoolIsActive,
|
|
|
|
.poolIsPersistent = storagePoolIsPersistent,
|
2008-02-20 15:34:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static virStateDriver stateDriver = {
|
Fix return value in virStateInitialize impl for LXC
The LXC driver was mistakenly returning -1 for lxcStartup()
in scenarios that are not an error. This caused the libvirtd
to quit for unprivileged users. This fixes the return code
of LXC driver, and also adds a "name" field to the virStateDriver
struct and logging to make it easier to find these problems
in the future
* src/driver.h: Add a 'name' field to state driver to allow
easy identification during failures
* src/libvirt.c: Log name of failed driver for virStateInit
failures
* src/lxc/lxc_driver.c: Don't return a failure code for
lxcStartup() if LXC is not available on this host, simply
disable the driver.
* src/network/bridge_driver.c, src/node_device/node_device_devkit.c,
src/node_device/node_device_hal.c, src/opennebula/one_driver.c,
src/qemu/qemu_driver.c, src/remote/remote_driver.c,
src/secret/secret_driver.c, src/storage/storage_driver.c,
src/uml/uml_driver.c, src/xen/xen_driver.c: Fill in name
field in virStateDriver struct
2009-11-02 23:18:19 +00:00
|
|
|
.name = "Storage",
|
2008-10-06 15:40:37 +00:00
|
|
|
.initialize = storageDriverStartup,
|
|
|
|
.cleanup = storageDriverShutdown,
|
|
|
|
.reload = storageDriverReload,
|
|
|
|
.active = storageDriverActive,
|
2008-02-20 15:34:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int storageRegister(void) {
|
|
|
|
virRegisterStorageDriver(&storageDriver);
|
|
|
|
virRegisterStateDriver(&stateDriver);
|
|
|
|
return 0;
|
|
|
|
}
|