2008-02-20 15:34:52 +00:00
|
|
|
/*
|
|
|
|
* storage_driver.c: core driver for storage APIs
|
|
|
|
*
|
2014-01-03 15:08:52 +00:00
|
|
|
* Copyright (C) 2006-2014 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-02-20 15:34:52 +00:00
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
2010-02-23 03:13:18 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2008-04-18 08:33:23 +00:00
|
|
|
#if HAVE_PWD_H
|
2010-03-09 18:22:22 +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>
|
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
#include "datatypes.h"
|
2008-02-20 15:34:52 +00:00
|
|
|
#include "driver.h"
|
|
|
|
#include "storage_driver.h"
|
|
|
|
#include "storage_conf.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2008-02-20 15:34:52 +00:00
|
|
|
#include "storage_backend.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2009-07-14 15:24:42 +00:00
|
|
|
#include "fdstream.h"
|
2010-11-16 14:54:17 +00:00
|
|
|
#include "configmake.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2013-04-23 10:56:22 +00:00
|
|
|
#include "viraccessapicheck.h"
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("storage.storage_driver");
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
static virStorageDriverStatePtr driverState;
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int storageStateCleanup(void);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
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
|
2014-03-18 08:15:36 +00:00
|
|
|
storageDriverAutostart(virStorageDriverStatePtr driver)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-07-15 20:26:10 +00:00
|
|
|
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 */
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < driver->pools.count; i++) {
|
2008-10-10 15:13:28 +00:00
|
|
|
virStoragePoolObjPtr pool = driver->pools.objs[i];
|
2010-11-11 20:09:20 +00:00
|
|
|
virStorageBackendPtr backend;
|
|
|
|
bool started = false;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjLock(pool);
|
2010-11-11 20:09:20 +00:00
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL) {
|
|
|
|
VIR_ERROR(_("Missing backend %d"), pool->def->type);
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
continue;
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-11-11 20:09:20 +00:00
|
|
|
if (backend->checkPool &&
|
2013-07-15 20:26:10 +00:00
|
|
|
backend->checkPool(conn, pool, &started) < 0) {
|
2010-11-11 20:09:20 +00:00
|
|
|
virErrorPtr err = virGetLastError();
|
|
|
|
VIR_ERROR(_("Failed to initialize storage pool '%s': %s"),
|
|
|
|
pool->def->name, err ? err->message :
|
|
|
|
_("no error message found"));
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!started &&
|
|
|
|
pool->autostart &&
|
|
|
|
!virStoragePoolObjIsActive(pool)) {
|
2008-02-20 15:34:52 +00:00
|
|
|
if (backend->startPool &&
|
2013-07-15 20:26:10 +00:00
|
|
|
backend->startPool(conn, pool) < 0) {
|
2008-02-20 15:34:52 +00:00
|
|
|
virErrorPtr err = virGetLastError();
|
2010-05-20 06:15:46 +00:00
|
|
|
VIR_ERROR(_("Failed to autostart storage pool '%s': %s"),
|
2010-01-31 17:12:05 +00:00
|
|
|
pool->def->name, err ? err->message :
|
2010-11-11 20:09:20 +00:00
|
|
|
_("no error message found"));
|
2008-12-04 21:40:42 +00:00
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-02-20 15:34:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-11-11 20:09:20 +00:00
|
|
|
started = true;
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-11-11 20:09:20 +00:00
|
|
|
if (started) {
|
2013-07-15 20:26:10 +00:00
|
|
|
if (backend->refreshPool(conn, pool) < 0) {
|
2008-02-20 15:34:52 +00:00
|
|
|
virErrorPtr err = virGetLastError();
|
|
|
|
if (backend->stopPool)
|
2013-07-15 20:26:10 +00:00
|
|
|
backend->stopPool(conn, pool);
|
2010-05-20 06:15:46 +00:00
|
|
|
VIR_ERROR(_("Failed to autostart storage pool '%s': %s"),
|
2010-01-31 17:12:05 +00:00
|
|
|
pool->def->name, err ? err->message :
|
2010-11-11 20:09:20 +00:00
|
|
|
_("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
|
|
|
}
|
2013-07-15 20:26:10 +00:00
|
|
|
|
2014-01-03 15:08:52 +00:00
|
|
|
virObjectUnref(conn);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageStartup:
|
|
|
|
*
|
|
|
|
* Initialization function for the QEmu daemon
|
|
|
|
*/
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageStateInitialize(bool privileged,
|
|
|
|
virStateInhibitCallback callback ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2011-01-15 16:38:57 +00:00
|
|
|
{
|
2008-02-20 15:34:52 +00:00
|
|
|
char *base = NULL;
|
|
|
|
|
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) {
|
2013-05-03 12:49:08 +00:00
|
|
|
if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0)
|
|
|
|
goto error;
|
2008-02-20 15:34:52 +00:00
|
|
|
} else {
|
2012-05-24 12:29:42 +00:00
|
|
|
base = virGetUserConfigDirectory();
|
2012-05-03 16:36:27 +00:00
|
|
|
if (!base)
|
2009-01-22 19:41:48 +00:00
|
|
|
goto error;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2013-07-15 20:26:10 +00:00
|
|
|
driverState->privileged = privileged;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2012-05-03 16:36:27 +00:00
|
|
|
/* Configuration paths are either $USER_CONFIG_HOME/libvirt/storage/... (session) or
|
2008-02-20 15:34:52 +00:00
|
|
|
* /etc/libvirt/storage/... (system).
|
|
|
|
*/
|
2008-12-23 13:03:29 +00:00
|
|
|
if (virAsprintf(&driverState->configDir,
|
|
|
|
"%s/storage", base) == -1)
|
2013-07-04 10:16:29 +00:00
|
|
|
goto error;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-23 13:03:29 +00:00
|
|
|
if (virAsprintf(&driverState->autostartDir,
|
|
|
|
"%s/storage/autostart", base) == -1)
|
2013-07-04 10:16:29 +00:00
|
|
|
goto error;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
VIR_FREE(base);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStoragePoolLoadAllConfigs(&driverState->pools,
|
2008-10-10 15:13:28 +00:00
|
|
|
driverState->configDir,
|
2008-12-04 21:40:42 +00:00
|
|
|
driverState->autostartDir) < 0)
|
|
|
|
goto error;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverUnlock(driverState);
|
2008-02-20 15:34:52 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
error:
|
2008-12-04 21:40:42 +00:00
|
|
|
VIR_FREE(base);
|
|
|
|
storageDriverUnlock(driverState);
|
2013-04-23 12:50:18 +00:00
|
|
|
storageStateCleanup();
|
2008-02-20 15:34:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-25 12:03:38 +00:00
|
|
|
/**
|
|
|
|
* storageStateAutoStart:
|
|
|
|
*
|
|
|
|
* Function to auto start the storage driver
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
storageStateAutoStart(void)
|
|
|
|
{
|
|
|
|
if (!driverState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
storageDriverLock(driverState);
|
|
|
|
storageDriverAutostart(driverState);
|
|
|
|
storageDriverUnlock(driverState);
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
/**
|
2013-04-23 12:50:18 +00:00
|
|
|
* storageStateReload:
|
2008-02-20 15:34:52 +00:00
|
|
|
*
|
|
|
|
* Function to restart the storage driver, it will recheck the configuration
|
|
|
|
* files and update its state
|
|
|
|
*/
|
|
|
|
static int
|
2014-03-18 08:15:36 +00:00
|
|
|
storageStateReload(void)
|
|
|
|
{
|
2008-10-10 15:13:28 +00:00
|
|
|
if (!driverState)
|
|
|
|
return -1;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driverState);
|
2010-02-10 11:42:56 +00:00
|
|
|
virStoragePoolLoadAllConfigs(&driverState->pools,
|
2008-10-10 15:13:28 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-04-23 12:50:18 +00:00
|
|
|
* storageStateCleanup
|
2008-02-20 15:34:52 +00:00
|
|
|
*
|
|
|
|
* Shutdown the storage driver, it will stop all active storage pools
|
|
|
|
*/
|
|
|
|
static int
|
2014-03-18 08:15:36 +00:00
|
|
|
storageStateCleanup(void)
|
|
|
|
{
|
2008-02-20 15:34:52 +00:00
|
|
|
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,
|
2014-03-18 08:15:36 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolLookupByUUIDEnsureACL(conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid,
|
|
|
|
NULL, NULL);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2014-03-25 06:52:40 +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,
|
2014-03-18 08:15:36 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching name '%s'"), name);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolLookupByNameEnsureACL(conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid,
|
|
|
|
NULL, NULL);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2014-03-25 06:52:40 +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
|
2014-03-18 08:15:36 +00:00
|
|
|
storagePoolLookupByVolume(virStorageVolPtr vol)
|
|
|
|
{
|
2013-04-23 10:56:22 +00:00
|
|
|
virStorageDriverStatePtr driver = vol->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
virStoragePoolPtr ret = NULL;
|
|
|
|
|
|
|
|
storageDriverLock(driver);
|
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, vol->pool);
|
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!pool) {
|
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
|
|
_("no storage pool with matching name '%s'"), vol->pool);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStoragePoolLookupByVolumeEnsureACL(vol->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = virGetStoragePool(vol->conn, pool->def->name, pool->def->uuid,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2013-04-23 10:56:22 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static virDrvOpenStatus
|
|
|
|
storageOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
2011-07-06 22:51:23 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!driverState)
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
conn->storagePrivateData = driverState;
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-18 08:15:36 +00:00
|
|
|
storageClose(virConnectPtr conn)
|
|
|
|
{
|
2008-02-20 15:34:52 +00:00
|
|
|
conn->storagePrivateData = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-18 08:15:36 +00:00
|
|
|
storageConnectNumOfStoragePools(virConnectPtr conn)
|
|
|
|
{
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
|
|
|
int nactive = 0;
|
2008-10-10 15:13:28 +00:00
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectNumOfStoragePoolsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < driver->pools.count; i++) {
|
2013-06-26 17:47:48 +00:00
|
|
|
virStoragePoolObjPtr obj = driver->pools.objs[i];
|
|
|
|
virStoragePoolObjLock(obj);
|
|
|
|
if (virConnectNumOfStoragePoolsCheckACL(conn, obj->def) &&
|
2014-02-14 15:03:22 +00:00
|
|
|
virStoragePoolObjIsActive(obj))
|
2008-10-10 15:13:28 +00:00
|
|
|
nactive++;
|
2013-06-26 17:47:48 +00:00
|
|
|
virStoragePoolObjUnlock(obj);
|
2008-12-04 21:40:42 +00:00
|
|
|
}
|
|
|
|
storageDriverUnlock(driver);
|
2008-10-10 15:13:28 +00:00
|
|
|
|
|
|
|
return nactive;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageConnectListStoragePools(virConnectPtr conn,
|
|
|
|
char **const names,
|
2014-03-18 08:15:36 +00:00
|
|
|
int nnames)
|
|
|
|
{
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int got = 0;
|
|
|
|
size_t i;
|
2008-10-10 15:13:28 +00:00
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectListStoragePoolsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < driver->pools.count && got < nnames; i++) {
|
2013-06-26 17:47:48 +00:00
|
|
|
virStoragePoolObjPtr obj = driver->pools.objs[i];
|
|
|
|
virStoragePoolObjLock(obj);
|
|
|
|
if (virConnectListStoragePoolsCheckACL(conn, obj->def) &&
|
2014-02-14 15:03:22 +00:00
|
|
|
virStoragePoolObjIsActive(obj)) {
|
2013-06-26 17:47:48 +00:00
|
|
|
if (VIR_STRDUP(names[got], obj->def->name) < 0) {
|
|
|
|
virStoragePoolObjUnlock(obj);
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
got++;
|
|
|
|
}
|
2013-06-26 17:47:48 +00:00
|
|
|
virStoragePoolObjUnlock(obj);
|
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);
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < got; i++)
|
2008-12-04 21:40:42 +00:00
|
|
|
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
|
2014-03-18 08:15:36 +00:00
|
|
|
storageConnectNumOfDefinedStoragePools(virConnectPtr conn)
|
|
|
|
{
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
|
|
|
int nactive = 0;
|
2008-10-10 15:13:28 +00:00
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectNumOfDefinedStoragePoolsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < driver->pools.count; i++) {
|
2013-06-26 17:47:48 +00:00
|
|
|
virStoragePoolObjPtr obj = driver->pools.objs[i];
|
|
|
|
virStoragePoolObjLock(obj);
|
|
|
|
if (virConnectNumOfDefinedStoragePoolsCheckACL(conn, obj->def) &&
|
2014-02-14 15:03:22 +00:00
|
|
|
!virStoragePoolObjIsActive(obj))
|
2008-10-10 15:13:28 +00:00
|
|
|
nactive++;
|
2013-06-26 17:47:48 +00:00
|
|
|
virStoragePoolObjUnlock(obj);
|
2008-12-04 21:40:42 +00:00
|
|
|
}
|
|
|
|
storageDriverUnlock(driver);
|
2008-10-10 15:13:28 +00:00
|
|
|
|
|
|
|
return nactive;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageConnectListDefinedStoragePools(virConnectPtr conn,
|
|
|
|
char **const names,
|
2014-03-18 08:15:36 +00:00
|
|
|
int nnames)
|
|
|
|
{
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int got = 0;
|
|
|
|
size_t i;
|
2008-10-10 15:13:28 +00:00
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectListDefinedStoragePoolsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < driver->pools.count && got < nnames; i++) {
|
2013-06-26 17:47:48 +00:00
|
|
|
virStoragePoolObjPtr obj = driver->pools.objs[i];
|
|
|
|
virStoragePoolObjLock(obj);
|
|
|
|
if (virConnectListDefinedStoragePoolsCheckACL(conn, obj->def) &&
|
2014-02-14 15:03:22 +00:00
|
|
|
!virStoragePoolObjIsActive(obj)) {
|
2013-06-26 17:47:48 +00:00
|
|
|
if (VIR_STRDUP(names[got], obj->def->name) < 0) {
|
|
|
|
virStoragePoolObjUnlock(obj);
|
2008-02-20 15:34:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
got++;
|
|
|
|
}
|
2013-06-26 17:47:48 +00:00
|
|
|
virStoragePoolObjUnlock(obj);
|
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);
|
2013-05-21 07:21:21 +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 *
|
2013-04-23 12:50:18 +00:00
|
|
|
storageConnectFindStoragePoolSources(virConnectPtr conn,
|
|
|
|
const char *type,
|
|
|
|
const char *srcSpec,
|
|
|
|
unsigned int flags)
|
2008-08-27 20:05:58 +00:00
|
|
|
{
|
|
|
|
int backend_type;
|
|
|
|
virStorageBackendPtr backend;
|
2008-12-04 21:39:45 +00:00
|
|
|
char *ret = NULL;
|
2008-08-27 20:05:58 +00:00
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectFindStoragePoolSourcesEnsureACL(conn) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
backend_type = virStoragePoolTypeFromString(type);
|
2009-10-08 14:24:37 +00:00
|
|
|
if (backend_type < 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_SUPPORT,
|
|
|
|
_("pool type '%s' does not support source "
|
|
|
|
"discovery"), type);
|
2009-10-08 14:24:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = backend->findPoolSources(conn, srcSpec, flags);
|
2008-08-27 20:05:58 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2008-12-04 21:39:45 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(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;
|
|
|
|
}
|
2013-04-23 10:56:22 +00:00
|
|
|
|
|
|
|
if (virStoragePoolIsActiveEnsureACL(pool->conn, obj->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
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
|
|
|
ret = virStoragePoolObjIsActive(obj);
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
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
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(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;
|
|
|
|
}
|
2013-04-23 10:56:22 +00:00
|
|
|
|
|
|
|
if (virStoragePoolIsPersistentEnsureACL(pool->conn, obj->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
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
|
|
|
ret = obj->configFile ? 1 : 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
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
|
|
|
if (obj)
|
|
|
|
virStoragePoolObjUnlock(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
static virStoragePoolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
storagePoolCreateXML(virConnectPtr conn,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags)
|
2011-07-06 22:51:23 +00:00
|
|
|
{
|
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;
|
|
|
|
|
2011-07-06 22:51:23 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(def = virStoragePoolDefParseString(xml)))
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolCreateXMLEnsureACL(conn, def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2010-05-27 11:41:30 +00:00
|
|
|
if (virStoragePoolObjIsDuplicate(&driver->pools, def, 1) < 0)
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2011-09-05 07:52:03 +00:00
|
|
|
if (virStoragePoolSourceFindDuplicate(&driver->pools, def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-12-04 21:39:45 +00:00
|
|
|
if ((backend = virStorageBackendForType(def->type)) == NULL)
|
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(pool = virStoragePoolObjAssignDef(&driver->pools, def)))
|
2008-12-04 21:39:45 +00:00
|
|
|
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
|
|
|
}
|
maint: omit translation for all VIR_INFO
We were 31/73 on whether to translate; since less than 50% translated
and since VIR_INFO is less than VIR_WARN which also doesn't translate,
this makes sense.
* cfg.mk (sc_prohibit_gettext_markup): Add VIR_INFO, since it
falls between WARN and DEBUG.
* daemon/libvirtd.c (qemudDispatchSignalEvent, remoteCheckAccess)
(qemudDispatchServer): Adjust offenders.
* daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
* src/network/bridge_driver.c (networkReloadIptablesRules)
(networkStartNetworkDaemon, networkShutdownNetworkDaemon)
(networkCreate, networkDefine, networkUndefine): Likewise.
* src/qemu/qemu_driver.c (qemudDomainDefine)
(qemudDomainUndefine): Likewise.
* src/storage/storage_driver.c (storagePoolCreate)
(storagePoolDefine, storagePoolUndefine, storagePoolStart)
(storagePoolDestroy, storagePoolDelete, storageVolumeCreateXML)
(storageVolumeCreateXMLFrom, storageVolumeDelete): Likewise.
* src/util/bridge.c (brProbeVnetHdr): Likewise.
* po/POTFILES.in: Drop src/util/bridge.c.
2011-05-11 15:08:44 +00:00
|
|
|
VIR_INFO("Creating storage pool '%s'", pool->def->name);
|
2008-02-20 15:34:52 +00:00
|
|
|
pool->active = 1;
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid,
|
|
|
|
NULL, NULL);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2008-12-04 21:39:45 +00:00
|
|
|
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
|
2013-04-23 12:50:18 +00:00
|
|
|
storagePoolDefineXML(virConnectPtr conn,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags)
|
2011-07-06 22:51:23 +00:00
|
|
|
{
|
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
|
|
|
|
2011-07-06 22:51:23 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(def = virStoragePoolDefParseString(xml)))
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolDefineXMLEnsureACL(conn, def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2010-05-27 11:41:30 +00:00
|
|
|
if (virStoragePoolObjIsDuplicate(&driver->pools, def, 0) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-09-05 07:52:03 +00:00
|
|
|
if (virStoragePoolSourceFindDuplicate(&driver->pools, def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
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
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(pool = virStoragePoolObjAssignDef(&driver->pools, def)))
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStoragePoolObjSaveDef(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
|
|
|
|
maint: omit translation for all VIR_INFO
We were 31/73 on whether to translate; since less than 50% translated
and since VIR_INFO is less than VIR_WARN which also doesn't translate,
this makes sense.
* cfg.mk (sc_prohibit_gettext_markup): Add VIR_INFO, since it
falls between WARN and DEBUG.
* daemon/libvirtd.c (qemudDispatchSignalEvent, remoteCheckAccess)
(qemudDispatchServer): Adjust offenders.
* daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
* src/network/bridge_driver.c (networkReloadIptablesRules)
(networkStartNetworkDaemon, networkShutdownNetworkDaemon)
(networkCreate, networkDefine, networkUndefine): Likewise.
* src/qemu/qemu_driver.c (qemudDomainDefine)
(qemudDomainUndefine): Likewise.
* src/storage/storage_driver.c (storagePoolCreate)
(storagePoolDefine, storagePoolUndefine, storagePoolStart)
(storagePoolDestroy, storagePoolDelete, storageVolumeCreateXML)
(storageVolumeCreateXMLFrom, storageVolumeDelete): Likewise.
* src/util/bridge.c (brProbeVnetHdr): Likewise.
* po/POTFILES.in: Drop src/util/bridge.c.
2011-05-11 15:08:44 +00:00
|
|
|
VIR_INFO("Defining storage pool '%s'", pool->def->name);
|
2012-11-10 07:18:07 +00:00
|
|
|
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid,
|
|
|
|
NULL, NULL);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2008-12-04 21:39:45 +00:00
|
|
|
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
|
2014-03-18 08:15:36 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolUndefineEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (virStoragePoolObjIsActive(pool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is still active"),
|
|
|
|
pool->def->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 (pool->asyncjobs > 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("pool '%s' has asynchronous jobs running."),
|
|
|
|
pool->def->name);
|
2009-04-17 19:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStoragePoolObjDeleteDef(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];
|
2010-05-20 06:15:46 +00:00
|
|
|
VIR_ERROR(_("Failed to delete autostart link '%s': %s"),
|
2012-03-29 09:52:04 +00:00
|
|
|
pool->autostartLink, virStrerror(errno, ebuf, sizeof(ebuf)));
|
2009-02-05 16:28:30 +00:00
|
|
|
}
|
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
|
|
|
|
maint: omit translation for all VIR_INFO
We were 31/73 on whether to translate; since less than 50% translated
and since VIR_INFO is less than VIR_WARN which also doesn't translate,
this makes sense.
* cfg.mk (sc_prohibit_gettext_markup): Add VIR_INFO, since it
falls between WARN and DEBUG.
* daemon/libvirtd.c (qemudDispatchSignalEvent, remoteCheckAccess)
(qemudDispatchServer): Adjust offenders.
* daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
* src/network/bridge_driver.c (networkReloadIptablesRules)
(networkStartNetworkDaemon, networkShutdownNetworkDaemon)
(networkCreate, networkDefine, networkUndefine): Likewise.
* src/qemu/qemu_driver.c (qemudDomainDefine)
(qemudDomainUndefine): Likewise.
* src/storage/storage_driver.c (storagePoolCreate)
(storagePoolDefine, storagePoolUndefine, storagePoolStart)
(storagePoolDestroy, storagePoolDelete, storageVolumeCreateXML)
(storageVolumeCreateXMLFrom, storageVolumeDelete): Likewise.
* src/util/bridge.c (brProbeVnetHdr): Likewise.
* po/POTFILES.in: Drop src/util/bridge.c.
2011-05-11 15:08:44 +00:00
|
|
|
VIR_INFO("Undefining storage pool '%s'", pool->def->name);
|
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
|
|
|
|
2014-03-25 06:52:40 +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
|
2013-04-23 12:50:18 +00:00
|
|
|
storagePoolCreate(virStoragePoolPtr obj,
|
|
|
|
unsigned int flags)
|
2011-07-06 22:51:23 +00:00
|
|
|
{
|
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
|
|
|
|
2011-07-06 22:51:23 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolCreateEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
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)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is already active"),
|
|
|
|
pool->def->name);
|
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
|
|
|
}
|
|
|
|
|
maint: omit translation for all VIR_INFO
We were 31/73 on whether to translate; since less than 50% translated
and since VIR_INFO is less than VIR_WARN which also doesn't translate,
this makes sense.
* cfg.mk (sc_prohibit_gettext_markup): Add VIR_INFO, since it
falls between WARN and DEBUG.
* daemon/libvirtd.c (qemudDispatchSignalEvent, remoteCheckAccess)
(qemudDispatchServer): Adjust offenders.
* daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
* src/network/bridge_driver.c (networkReloadIptablesRules)
(networkStartNetworkDaemon, networkShutdownNetworkDaemon)
(networkCreate, networkDefine, networkUndefine): Likewise.
* src/qemu/qemu_driver.c (qemudDomainDefine)
(qemudDomainUndefine): Likewise.
* src/storage/storage_driver.c (storagePoolCreate)
(storagePoolDefine, storagePoolUndefine, storagePoolStart)
(storagePoolDestroy, storagePoolDelete, storageVolumeCreateXML)
(storageVolumeCreateXMLFrom, storageVolumeDelete): Likewise.
* src/util/bridge.c (brProbeVnetHdr): Likewise.
* po/POTFILES.in: Drop src/util/bridge.c.
2011-05-11 15:08:44 +00:00
|
|
|
VIR_INFO("Starting up storage pool '%s'", pool->def->name);
|
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
|
|
|
|
2014-03-25 06:52:40 +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,
|
2014-03-18 08:15:36 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolBuildEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
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)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is already active"),
|
|
|
|
pool->def->name);
|
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
|
|
|
|
2014-03-25 06:52:40 +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
|
2014-03-18 08:15:36 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolDestroyEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
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)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->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 (pool->asyncjobs > 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("pool '%s' has asynchronous jobs running."),
|
|
|
|
pool->def->name);
|
2009-04-17 19:12:37 +00:00
|
|
|
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;
|
maint: omit translation for all VIR_INFO
We were 31/73 on whether to translate; since less than 50% translated
and since VIR_INFO is less than VIR_WARN which also doesn't translate,
this makes sense.
* cfg.mk (sc_prohibit_gettext_markup): Add VIR_INFO, since it
falls between WARN and DEBUG.
* daemon/libvirtd.c (qemudDispatchSignalEvent, remoteCheckAccess)
(qemudDispatchServer): Adjust offenders.
* daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
* src/network/bridge_driver.c (networkReloadIptablesRules)
(networkStartNetworkDaemon, networkShutdownNetworkDaemon)
(networkCreate, networkDefine, networkUndefine): Likewise.
* src/qemu/qemu_driver.c (qemudDomainDefine)
(qemudDomainUndefine): Likewise.
* src/storage/storage_driver.c (storagePoolCreate)
(storagePoolDefine, storagePoolUndefine, storagePoolStart)
(storagePoolDestroy, storagePoolDelete, storageVolumeCreateXML)
(storageVolumeCreateXMLFrom, storageVolumeDelete): Likewise.
* src/util/bridge.c (brProbeVnetHdr): Likewise.
* po/POTFILES.in: Drop src/util/bridge.c.
2011-05-11 15:08:44 +00:00
|
|
|
VIR_INFO("Shutting down storage pool '%s'", pool->def->name);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
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;
|
2012-06-25 09:38:17 +00:00
|
|
|
} else if (pool->newDef) {
|
|
|
|
virStoragePoolDefFree(pool->def);
|
|
|
|
pool->def = pool->newDef;
|
|
|
|
pool->newDef = NULL;
|
2008-12-04 21:40:42 +00:00
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2014-03-25 06:52:40 +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,
|
2014-03-18 08:15:36 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolDeleteEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
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)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is still active"),
|
|
|
|
pool->def->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 (pool->asyncjobs > 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("pool '%s' has asynchronous jobs running."),
|
2009-04-17 19:12:37 +00:00
|
|
|
pool->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!backend->deletePool) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_SUPPORT,
|
|
|
|
"%s", _("pool does not support pool deletion"));
|
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;
|
maint: omit translation for all VIR_INFO
We were 31/73 on whether to translate; since less than 50% translated
and since VIR_INFO is less than VIR_WARN which also doesn't translate,
this makes sense.
* cfg.mk (sc_prohibit_gettext_markup): Add VIR_INFO, since it
falls between WARN and DEBUG.
* daemon/libvirtd.c (qemudDispatchSignalEvent, remoteCheckAccess)
(qemudDispatchServer): Adjust offenders.
* daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
* src/network/bridge_driver.c (networkReloadIptablesRules)
(networkStartNetworkDaemon, networkShutdownNetworkDaemon)
(networkCreate, networkDefine, networkUndefine): Likewise.
* src/qemu/qemu_driver.c (qemudDomainDefine)
(qemudDomainUndefine): Likewise.
* src/storage/storage_driver.c (storagePoolCreate)
(storagePoolDefine, storagePoolUndefine, storagePoolStart)
(storagePoolDestroy, storagePoolDelete, storageVolumeCreateXML)
(storageVolumeCreateXMLFrom, storageVolumeDelete): Likewise.
* src/util/bridge.c (brProbeVnetHdr): Likewise.
* po/POTFILES.in: Drop src/util/bridge.c.
2011-05-11 15:08:44 +00:00
|
|
|
VIR_INFO("Deleting storage pool '%s'", pool->def->name);
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2014-03-25 06:52:40 +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,
|
2011-07-06 22:51:23 +00:00
|
|
|
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
|
|
|
|
2011-07-06 22:51:23 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolRefreshEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
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)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->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 (pool->asyncjobs > 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("pool '%s' has asynchronous jobs running."),
|
|
|
|
pool->def->name);
|
2009-04-17 19:12:37 +00:00
|
|
|
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
|
|
|
|
2014-03-25 06:52:40 +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,
|
2014-03-18 08:15:36 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolGetInfoEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
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
|
|
|
|
2014-03-25 06:52:40 +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 *
|
2011-05-06 19:53:10 +00:00
|
|
|
storagePoolGetXMLDesc(virStoragePoolPtr obj,
|
2011-07-06 22:51:23 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
2012-06-25 10:24:45 +00:00
|
|
|
virStoragePoolDefPtr def;
|
2008-12-04 21:39:45 +00:00
|
|
|
char *ret = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2012-06-25 10:24:45 +00:00
|
|
|
virCheckFlags(VIR_STORAGE_XML_INACTIVE, NULL);
|
2011-07-06 22:51:23 +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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolGetXMLDescEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-06-25 10:24:45 +00:00
|
|
|
if ((flags & VIR_STORAGE_XML_INACTIVE) && pool->newDef)
|
|
|
|
def = pool->newDef;
|
|
|
|
else
|
|
|
|
def = pool->def;
|
|
|
|
|
|
|
|
ret = virStoragePoolDefFormat(def);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2014-03-25 06:52:40 +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
|
|
|
|
storagePoolGetAutostart(virStoragePoolPtr obj,
|
2014-03-18 08:15:36 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolGetAutostartEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
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
|
|
|
|
2014-03-25 06:52:40 +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,
|
2014-03-18 08:15:36 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolSetAutostartEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!pool->configFile) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%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) {
|
2011-07-05 21:02:53 +00:00
|
|
|
if (virFileMakePath(driver->autostartDir) < 0) {
|
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("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) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("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) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("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
|
|
|
|
2014-03-25 06:52:40 +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
|
2014-03-18 08:15:36 +00:00
|
|
|
storagePoolNumOfVolumes(virStoragePoolPtr obj)
|
|
|
|
{
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolNumOfVolumesEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2013-06-26 17:47:48 +00:00
|
|
|
ret = 0;
|
|
|
|
for (i = 0; i < pool->volumes.count; i++) {
|
|
|
|
if (virStoragePoolNumOfVolumesCheckACL(obj->conn, pool->def,
|
|
|
|
pool->volumes.objs[i]))
|
|
|
|
ret++;
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2014-03-25 06:52:40 +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,
|
2014-03-18 08:15:36 +00:00
|
|
|
int maxnames)
|
|
|
|
{
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
|
|
|
int 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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolListVolumesEnsureACL(obj->conn, pool->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < pool->volumes.count && n < maxnames; i++) {
|
2013-06-26 17:47:48 +00:00
|
|
|
if (!virStoragePoolListVolumesCheckACL(obj->conn, pool->def,
|
|
|
|
pool->volumes.objs[i]))
|
|
|
|
continue;
|
2013-05-03 12:49:08 +00:00
|
|
|
if (VIR_STRDUP(names[n++], pool->volumes.objs[i]->name) < 0)
|
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);
|
2013-05-21 07:21:21 +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;
|
|
|
|
}
|
|
|
|
|
2012-09-04 15:32:55 +00:00
|
|
|
static int
|
|
|
|
storagePoolListAllVolumes(virStoragePoolPtr pool,
|
|
|
|
virStorageVolPtr **vols,
|
2014-03-18 08:15:36 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2012-09-04 15:32:55 +00:00
|
|
|
virStorageDriverStatePtr driver = pool->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr obj;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2012-09-04 15:32:55 +00:00
|
|
|
virStorageVolPtr *tmp_vols = NULL;
|
|
|
|
virStorageVolPtr vol = NULL;
|
|
|
|
int nvols = 0;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
storageDriverLock(driver);
|
|
|
|
obj = virStoragePoolObjFindByUUID(&driver->pools, pool->uuid);
|
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!obj) {
|
2012-10-08 22:37:22 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
|
|
_("no storage pool with matching uuid %s"),
|
|
|
|
pool->uuid);
|
2012-09-04 15:32:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStoragePoolListAllVolumesEnsureACL(pool->conn, obj->def) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-09-04 15:32:55 +00:00
|
|
|
if (!virStoragePoolObjIsActive(obj)) {
|
2012-10-08 22:37:22 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), obj->def->name);
|
2012-09-04 15:32:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Just returns the volumes count */
|
|
|
|
if (!vols) {
|
|
|
|
ret = obj->volumes.count;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:16:29 +00:00
|
|
|
if (VIR_ALLOC_N(tmp_vols, obj->volumes.count + 1) < 0)
|
2013-06-26 17:47:48 +00:00
|
|
|
goto cleanup;
|
2012-09-04 15:32:55 +00:00
|
|
|
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < obj->volumes.count; i++) {
|
2013-06-26 17:47:48 +00:00
|
|
|
if (!virStoragePoolListAllVolumesCheckACL(pool->conn, obj->def,
|
|
|
|
obj->volumes.objs[i]))
|
|
|
|
continue;
|
2012-09-04 15:32:55 +00:00
|
|
|
if (!(vol = virGetStorageVol(pool->conn, obj->def->name,
|
|
|
|
obj->volumes.objs[i]->name,
|
2012-11-10 07:18:07 +00:00
|
|
|
obj->volumes.objs[i]->key,
|
|
|
|
NULL, NULL)))
|
2012-09-04 15:32:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
tmp_vols[nvols++] = vol;
|
|
|
|
}
|
|
|
|
|
|
|
|
*vols = tmp_vols;
|
|
|
|
tmp_vols = NULL;
|
|
|
|
ret = nvols;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (tmp_vols) {
|
|
|
|
for (i = 0; i < nvols; i++) {
|
|
|
|
if (tmp_vols[i])
|
|
|
|
virStorageVolFree(tmp_vols[i]);
|
|
|
|
}
|
2013-01-09 14:54:15 +00:00
|
|
|
VIR_FREE(tmp_vols);
|
2012-09-04 15:32:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (obj)
|
|
|
|
virStoragePoolObjUnlock(obj);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolLookupByName(virStoragePoolPtr obj,
|
2014-03-18 08:15:36 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vol = virStorageVolDefFindByName(pool, name);
|
|
|
|
|
|
|
|
if (!vol) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStorageVolLookupByNameEnsureACL(obj->conn, pool->def, vol) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
ret = virGetStorageVol(obj->conn, pool->def->name, vol->name, vol->key,
|
|
|
|
NULL, NULL);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2014-03-25 06:52:40 +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 virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolLookupByKey(virConnectPtr conn,
|
2014-03-18 08:15:36 +00:00
|
|
|
const char *key)
|
|
|
|
{
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t 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);
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < driver->pools.count && !ret; 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])) {
|
|
|
|
virStorageVolDefPtr vol =
|
|
|
|
virStorageVolDefFindByKey(driver->pools.objs[i], key);
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (vol) {
|
2013-07-04 12:41:46 +00:00
|
|
|
if (virStorageVolLookupByKeyEnsureACL(conn, driver->pools.objs[i]->def, vol) < 0) {
|
|
|
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
2013-04-23 10:56:22 +00:00
|
|
|
goto cleanup;
|
2013-07-04 12:41:46 +00:00
|
|
|
}
|
2013-04-23 10:56:22 +00:00
|
|
|
|
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,
|
2012-11-10 07:18:07 +00:00
|
|
|
vol->key,
|
|
|
|
NULL, NULL);
|
2013-04-23 10:56:22 +00:00
|
|
|
}
|
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)
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage vol with matching key %s"), key);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2013-04-23 10:56:22 +00:00
|
|
|
storageDriverUnlock(driver);
|
2008-12-04 21:39:45 +00:00
|
|
|
return ret;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolLookupByPath(virConnectPtr conn,
|
2014-03-18 08:15:36 +00:00
|
|
|
const char *path)
|
|
|
|
{
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2008-12-04 21:39:45 +00:00
|
|
|
virStorageVolPtr ret = NULL;
|
2010-05-20 15:41:31 +00:00
|
|
|
char *cleanpath;
|
|
|
|
|
|
|
|
cleanpath = virFileSanitizePath(path);
|
|
|
|
if (!cleanpath)
|
|
|
|
return NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2008-12-04 21:40:42 +00:00
|
|
|
storageDriverLock(driver);
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < driver->pools.count && !ret; i++) {
|
2014-02-25 14:51:15 +00:00
|
|
|
virStoragePoolObjPtr pool = driver->pools.objs[i];
|
|
|
|
virStorageVolDefPtr vol;
|
|
|
|
char *stable_path = NULL;
|
|
|
|
|
|
|
|
virStoragePoolObjLock(pool);
|
2008-11-17 11:19:33 +00:00
|
|
|
|
2014-02-25 14:51:15 +00:00
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
continue;
|
|
|
|
}
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2014-02-25 14:51:15 +00:00
|
|
|
switch ((enum virStoragePoolType) pool->def->type) {
|
|
|
|
case VIR_STORAGE_POOL_DIR:
|
|
|
|
case VIR_STORAGE_POOL_FS:
|
|
|
|
case VIR_STORAGE_POOL_NETFS:
|
|
|
|
case VIR_STORAGE_POOL_LOGICAL:
|
|
|
|
case VIR_STORAGE_POOL_DISK:
|
|
|
|
case VIR_STORAGE_POOL_ISCSI:
|
|
|
|
case VIR_STORAGE_POOL_SCSI:
|
|
|
|
case VIR_STORAGE_POOL_MPATH:
|
|
|
|
stable_path = virStorageBackendStablePath(pool,
|
|
|
|
cleanpath,
|
|
|
|
false);
|
|
|
|
if (stable_path == NULL) {
|
|
|
|
/* Don't break the whole lookup process if it fails on
|
|
|
|
* getting the stable path for some of the pools.
|
|
|
|
*/
|
|
|
|
VIR_WARN("Failed to get stable path for pool '%s'",
|
|
|
|
pool->def->name);
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_STORAGE_POOL_GLUSTER:
|
|
|
|
case VIR_STORAGE_POOL_RBD:
|
|
|
|
case VIR_STORAGE_POOL_SHEEPDOG:
|
|
|
|
case VIR_STORAGE_POOL_LAST:
|
|
|
|
if (VIR_STRDUP(stable_path, path) < 0) {
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2013-04-23 10:56:22 +00:00
|
|
|
goto cleanup;
|
2013-07-04 12:41:46 +00:00
|
|
|
}
|
2014-02-25 14:51:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-04-23 10:56:22 +00:00
|
|
|
|
2014-02-25 14:51:15 +00:00
|
|
|
vol = virStorageVolDefFindByPath(pool, stable_path);
|
|
|
|
VIR_FREE(stable_path);
|
|
|
|
|
|
|
|
if (vol) {
|
|
|
|
if (virStorageVolLookupByPathEnsureACL(conn, pool->def, vol) < 0) {
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
goto cleanup;
|
2013-04-23 10:56:22 +00:00
|
|
|
}
|
2014-02-25 14:51:15 +00:00
|
|
|
|
|
|
|
ret = virGetStorageVol(conn, pool->def->name,
|
|
|
|
vol->name, vol->key,
|
|
|
|
NULL, NULL);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
2014-02-25 14:51:15 +00:00
|
|
|
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
2014-02-24 15:07:40 +00:00
|
|
|
if (!ret) {
|
|
|
|
if (STREQ(path, cleanpath)) {
|
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching path '%s'"), path);
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching path '%s' (%s)"),
|
|
|
|
path, cleanpath);
|
|
|
|
}
|
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2010-05-20 15:41:31 +00:00
|
|
|
VIR_FREE(cleanpath);
|
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
|
|
|
}
|
|
|
|
|
2013-12-10 14:28:58 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
storageVolDelete(virStorageVolPtr obj,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
virStorageBackendPtr backend;
|
|
|
|
virStorageVolDefPtr vol = NULL;
|
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
storageDriverLock(driver);
|
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!pool) {
|
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
|
|
_("no storage pool with matching name '%s'"),
|
|
|
|
obj->pool);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
vol = virStorageVolDefFindByName(pool, obj->name);
|
|
|
|
|
|
|
|
if (!vol) {
|
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
obj->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStorageVolDeleteEnsureACL(obj->conn, pool->def, vol) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (vol->building) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("volume '%s' is still being allocated."),
|
|
|
|
vol->name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!backend->deleteVol) {
|
|
|
|
virReportError(VIR_ERR_NO_SUPPORT,
|
|
|
|
"%s", _("storage pool does not support vol deletion"));
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backend->deleteVol(obj->conn, pool, vol, flags) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Update pool metadata */
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
pool->def->allocation -= vol->target.allocation;
|
|
|
|
pool->def->available += vol->target.allocation;
|
2013-12-10 14:28:58 +00:00
|
|
|
|
|
|
|
for (i = 0; i < pool->volumes.count; i++) {
|
|
|
|
if (pool->volumes.objs[i] == vol) {
|
|
|
|
VIR_INFO("Deleting volume '%s' from storage pool '%s'",
|
|
|
|
vol->name, pool->def->name);
|
|
|
|
virStorageVolDefFree(vol);
|
|
|
|
|
2014-01-09 15:28:30 +00:00
|
|
|
VIR_DELETE_ELEMENT(pool->volumes.objs, i, pool->volumes.count);
|
2013-12-10 14:28:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2013-12-10 14:28:58 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolCreateXML(virStoragePoolPtr obj,
|
|
|
|
const char *xmldesc,
|
|
|
|
unsigned int flags)
|
2011-07-06 22:51:23 +00:00
|
|
|
{
|
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;
|
2013-08-16 12:08:07 +00:00
|
|
|
virStorageVolDefPtr buildvoldef = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2012-12-05 10:48:07 +00:00
|
|
|
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
|
2011-07-06 22:51:23 +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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->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
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
voldef = virStorageVolDefParseString(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
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStorageVolCreateXMLEnsureACL(obj->conn, pool->def, voldef) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2009-04-17 19:12:37 +00:00
|
|
|
if (virStorageVolDefFindByName(pool, voldef->name)) {
|
2013-10-07 17:21:47 +00:00
|
|
|
virReportError(VIR_ERR_STORAGE_VOL_EXIST,
|
2013-10-07 14:04:26 +00:00
|
|
|
_("'%s'"), voldef->name);
|
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,
|
2013-07-04 10:16:29 +00:00
|
|
|
pool->volumes.count+1) < 0)
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_SUPPORT,
|
|
|
|
"%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
|
|
|
}
|
|
|
|
|
storage: use valid XML for awkward volume names
$ touch /var/lib/libvirt/images/'a<b>c'
$ virsh pool-refresh default
$ virsh vol-dumpxml 'a<b>c' default | head -n2
<volume>
<name>a<b>c</name>
Oops. That's not valid XML. And when we fix the XML
generation, it fails RelaxNG validation.
I'm also tired of seeing <key>(null)</key> in the example
output for volume xml; while we used NULLSTR() to avoid
a NULL deref rather than relying on glibc's printf
extension behavior, it's even better if we avoid the issue
in the first place. But this requires being careful that
we don't invalidate any storage backends that were relying
on key being unassigned during virStoragVolCreateXML[From].
I would have split this into two patches (one for escaping,
one for avoiding <key>(null)</key>), but since they both
end up touching a lot of the same test files, I ended up
merging it into one.
Note that this patch allows pretty much any volume name
that can appear in a directory (excluding . and .. because
those are special), but does nothing to change the current
(unenforced) RelaxNG claim that pool names will consist
only of letters, numbers, _, -, and +. Tightening the C
code to match RelaxNG patterns and/or relaxing the grammar
to match the C code for pool names is a task for another
day (but remember, we DID recently tighten C code for
domain names to exclude a leading '.').
* src/conf/storage_conf.c (virStoragePoolSourceFormat)
(virStoragePoolDefFormat, virStorageVolTargetDefFormat)
(virStorageVolDefFormat): Escape user-controlled strings.
(virStorageVolDefParseXML): Parse key, for use in unit tests.
* src/storage/storage_driver.c (storageVolCreateXML)
(storageVolCreateXMLFrom): Ensure parsed key doesn't confuse
volume creation.
* docs/schemas/basictypes.rng (volName): Relax definition.
* tests/storagepoolxml2xmltest.c (mymain): Test it.
* tests/storagevolxml2xmltest.c (mymain): Likewise.
* tests/storagepoolxml2xmlin/pool-dir-naming.xml: New file.
* tests/storagepoolxml2xmlout/pool-dir-naming.xml: Likewise.
* tests/storagevolxml2xmlin/vol-file-naming.xml: Likewise.
* tests/storagevolxml2xmlout/vol-file-naming.xml: Likewise.
* tests/storagevolxml2xmlout/vol-*.xml: Fix fallout.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-11-21 00:04:05 +00:00
|
|
|
/* Wipe any key the user may have suggested, as volume creation
|
|
|
|
* will generate the canonical key. */
|
|
|
|
VIR_FREE(voldef->key);
|
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,
|
2012-11-10 07:18:07 +00:00
|
|
|
voldef->key, NULL, NULL);
|
2011-05-03 17:44:04 +00:00
|
|
|
if (!volobj) {
|
|
|
|
pool->volumes.count--;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2013-08-16 12:08:07 +00:00
|
|
|
if (VIR_ALLOC(buildvoldef) < 0) {
|
|
|
|
voldef = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-04-17 19:12:37 +00:00
|
|
|
|
2013-08-16 12:08:07 +00:00
|
|
|
/* 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));
|
2009-04-17 19:12:37 +00:00
|
|
|
|
2013-08-16 12:08:07 +00:00
|
|
|
if (backend->buildVol) {
|
|
|
|
int buildret;
|
2009-04-17 19:12:37 +00:00
|
|
|
|
|
|
|
/* Drop the pool lock during volume allocation */
|
|
|
|
pool->asyncjobs++;
|
|
|
|
voldef->building = 1;
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
|
2012-12-05 10:48:07 +00:00
|
|
|
buildret = backend->buildVol(obj->conn, pool, buildvoldef, flags);
|
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;
|
|
|
|
|
|
|
|
if (buildret < 0) {
|
|
|
|
virStoragePoolObjUnlock(pool);
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolDelete(volobj, 0);
|
2009-04-17 19:12:37 +00:00
|
|
|
pool = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-16 12:08:07 +00:00
|
|
|
/* Update pool metadata */
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
pool->def->allocation += buildvoldef->target.allocation;
|
|
|
|
pool->def->available -= buildvoldef->target.allocation;
|
2013-08-16 12:08:07 +00:00
|
|
|
|
maint: omit translation for all VIR_INFO
We were 31/73 on whether to translate; since less than 50% translated
and since VIR_INFO is less than VIR_WARN which also doesn't translate,
this makes sense.
* cfg.mk (sc_prohibit_gettext_markup): Add VIR_INFO, since it
falls between WARN and DEBUG.
* daemon/libvirtd.c (qemudDispatchSignalEvent, remoteCheckAccess)
(qemudDispatchServer): Adjust offenders.
* daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
* src/network/bridge_driver.c (networkReloadIptablesRules)
(networkStartNetworkDaemon, networkShutdownNetworkDaemon)
(networkCreate, networkDefine, networkUndefine): Likewise.
* src/qemu/qemu_driver.c (qemudDomainDefine)
(qemudDomainUndefine): Likewise.
* src/storage/storage_driver.c (storagePoolCreate)
(storagePoolDefine, storagePoolUndefine, storagePoolStart)
(storagePoolDestroy, storagePoolDelete, storageVolumeCreateXML)
(storageVolumeCreateXMLFrom, storageVolumeDelete): Likewise.
* src/util/bridge.c (brProbeVnetHdr): Likewise.
* po/POTFILES.in: Drop src/util/bridge.c.
2011-05-11 15:08:44 +00:00
|
|
|
VIR_INFO("Creating volume '%s' in storage pool '%s'",
|
2011-03-30 01:19:47 +00:00
|
|
|
volobj->name, pool->def->name);
|
2009-04-17 19:12:37 +00:00
|
|
|
ret = volobj;
|
|
|
|
volobj = NULL;
|
|
|
|
voldef = NULL;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
Convert public datatypes to inherit from virObject
This converts the following public API datatypes to use the
virObject infrastructure:
virConnectPtr
virDomainPtr
virDomainSnapshotPtr
virInterfacePtr
virNetworkPtr
virNodeDevicePtr
virNWFilterPtr
virSecretPtr
virStreamPtr
virStorageVolPtr
virStoragePoolPtr
The code is significantly simplified, since the mutex in the
virConnectPtr object now only needs to be held when accessing
the per-connection virError object instance. All other operations
are completely lock free.
* src/datatypes.c, src/datatypes.h, src/libvirt.c: Convert
public datatypes to use virObject
* src/conf/domain_event.c, src/phyp/phyp_driver.c,
src/qemu/qemu_command.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c, src/storage/storage_driver.c,
src/vbox/vbox_tmpl.c, src/xen/xend_internal.c,
tests/qemuxml2argvtest.c, tests/qemuxmlnstest.c,
tests/sexpr2xmltest.c, tests/xmconfigtest.c: Convert
to use virObjectUnref/virObjectRef
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-07-31 16:55:36 +00:00
|
|
|
virObjectUnref(volobj);
|
2009-04-17 19:12:37 +00:00
|
|
|
virStorageVolDefFree(voldef);
|
2013-08-20 09:08:49 +00:00
|
|
|
VIR_FREE(buildvoldef);
|
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
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolCreateXMLFrom(virStoragePoolPtr obj,
|
|
|
|
const char *xmldesc,
|
|
|
|
virStorageVolPtr vobj,
|
|
|
|
unsigned int flags)
|
2011-07-06 22:51:23 +00:00
|
|
|
{
|
2009-05-19 13:37:51 +00:00
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool, origpool = NULL;
|
|
|
|
virStorageBackendPtr backend;
|
|
|
|
virStorageVolDefPtr origvol = NULL, newvol = NULL;
|
|
|
|
virStorageVolPtr ret = NULL, volobj = NULL;
|
2013-08-20 15:28:28 +00:00
|
|
|
unsigned long long allocation;
|
2009-09-02 13:02:06 +00:00
|
|
|
int buildret;
|
2009-05-19 13:37:51 +00:00
|
|
|
|
2012-12-05 10:48:07 +00:00
|
|
|
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
|
2011-07-06 22:51:23 +00:00
|
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching uuid %s"), obj->uuid);
|
2009-05-19 13:37:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-09-02 13:02:06 +00:00
|
|
|
if (STRNEQ(obj->name, vobj->pool) && !origpool) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(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)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
2009-05-19 13:37:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-09-02 13:02:06 +00:00
|
|
|
if (origpool && !virStoragePoolObjIsActive(origpool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"),
|
|
|
|
origpool->def->name);
|
2009-05-19 13:37:51 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
vobj->name);
|
2009-05-19 13:37:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
newvol = virStorageVolDefParseString(pool->def, xmldesc);
|
2009-05-19 13:37:51 +00:00
|
|
|
if (newvol == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStorageVolCreateXMLFromEnsureACL(obj->conn, pool->def, newvol) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2009-05-19 13:37:51 +00:00
|
|
|
if (virStorageVolDefFindByName(pool, newvol->name)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("storage volume name '%s' already in use."),
|
|
|
|
newvol->name);
|
2009-05-19 13:37:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is there ever a valid case for this? */
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
if (newvol->target.capacity < origvol->target.capacity)
|
|
|
|
newvol->target.capacity = origvol->target.capacity;
|
2009-05-19 13:37:51 +00:00
|
|
|
|
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 */
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
if (newvol->target.allocation < origvol->target.capacity)
|
|
|
|
newvol->target.allocation = origvol->target.capacity;
|
2009-06-22 16:33:24 +00:00
|
|
|
|
2009-05-19 13:37:51 +00:00
|
|
|
if (!backend->buildVolFrom) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_SUPPORT,
|
|
|
|
"%s", _("storage pool does not support volume creation from an existing volume"));
|
2009-05-19 13:37:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (origvol->building) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("volume '%s' is still being allocated."),
|
|
|
|
origvol->name);
|
2009-05-19 13:37:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backend->refreshVol &&
|
|
|
|
backend->refreshVol(obj->conn, pool, origvol) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(pool->volumes.objs,
|
2013-07-04 10:16:29 +00:00
|
|
|
pool->volumes.count+1) < 0)
|
2009-05-19 13:37:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
storage: use valid XML for awkward volume names
$ touch /var/lib/libvirt/images/'a<b>c'
$ virsh pool-refresh default
$ virsh vol-dumpxml 'a<b>c' default | head -n2
<volume>
<name>a<b>c</name>
Oops. That's not valid XML. And when we fix the XML
generation, it fails RelaxNG validation.
I'm also tired of seeing <key>(null)</key> in the example
output for volume xml; while we used NULLSTR() to avoid
a NULL deref rather than relying on glibc's printf
extension behavior, it's even better if we avoid the issue
in the first place. But this requires being careful that
we don't invalidate any storage backends that were relying
on key being unassigned during virStoragVolCreateXML[From].
I would have split this into two patches (one for escaping,
one for avoiding <key>(null)</key>), but since they both
end up touching a lot of the same test files, I ended up
merging it into one.
Note that this patch allows pretty much any volume name
that can appear in a directory (excluding . and .. because
those are special), but does nothing to change the current
(unenforced) RelaxNG claim that pool names will consist
only of letters, numbers, _, -, and +. Tightening the C
code to match RelaxNG patterns and/or relaxing the grammar
to match the C code for pool names is a task for another
day (but remember, we DID recently tighten C code for
domain names to exclude a leading '.').
* src/conf/storage_conf.c (virStoragePoolSourceFormat)
(virStoragePoolDefFormat, virStorageVolTargetDefFormat)
(virStorageVolDefFormat): Escape user-controlled strings.
(virStorageVolDefParseXML): Parse key, for use in unit tests.
* src/storage/storage_driver.c (storageVolCreateXML)
(storageVolCreateXMLFrom): Ensure parsed key doesn't confuse
volume creation.
* docs/schemas/basictypes.rng (volName): Relax definition.
* tests/storagepoolxml2xmltest.c (mymain): Test it.
* tests/storagevolxml2xmltest.c (mymain): Likewise.
* tests/storagepoolxml2xmlin/pool-dir-naming.xml: New file.
* tests/storagepoolxml2xmlout/pool-dir-naming.xml: Likewise.
* tests/storagevolxml2xmlin/vol-file-naming.xml: Likewise.
* tests/storagevolxml2xmlout/vol-file-naming.xml: Likewise.
* tests/storagevolxml2xmlout/vol-*.xml: Fix fallout.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-11-21 00:04:05 +00:00
|
|
|
/* 'Define' the new volume so we get async progress reporting.
|
|
|
|
* Wipe any key the user may have suggested, as volume creation
|
|
|
|
* will generate the canonical key. */
|
|
|
|
VIR_FREE(newvol->key);
|
2009-05-19 13:37:51 +00:00
|
|
|
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,
|
2012-11-10 07:18:07 +00:00
|
|
|
newvol->key, NULL, NULL);
|
2014-02-12 11:05:51 +00:00
|
|
|
if (!volobj) {
|
|
|
|
pool->volumes.count--;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-05-19 13:37:51 +00:00
|
|
|
|
|
|
|
/* 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;
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
allocation = newvol->target.allocation;
|
2009-05-19 13:37:51 +00:00
|
|
|
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);
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolDelete(volobj, 0);
|
2009-05-19 13:37:51 +00:00
|
|
|
pool = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-08-16 12:08:07 +00:00
|
|
|
/* Updating pool metadata */
|
2013-08-20 15:28:28 +00:00
|
|
|
pool->def->allocation += allocation;
|
|
|
|
pool->def->available -= allocation;
|
2013-08-16 12:08:07 +00:00
|
|
|
|
maint: omit translation for all VIR_INFO
We were 31/73 on whether to translate; since less than 50% translated
and since VIR_INFO is less than VIR_WARN which also doesn't translate,
this makes sense.
* cfg.mk (sc_prohibit_gettext_markup): Add VIR_INFO, since it
falls between WARN and DEBUG.
* daemon/libvirtd.c (qemudDispatchSignalEvent, remoteCheckAccess)
(qemudDispatchServer): Adjust offenders.
* daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
* src/network/bridge_driver.c (networkReloadIptablesRules)
(networkStartNetworkDaemon, networkShutdownNetworkDaemon)
(networkCreate, networkDefine, networkUndefine): Likewise.
* src/qemu/qemu_driver.c (qemudDomainDefine)
(qemudDomainUndefine): Likewise.
* src/storage/storage_driver.c (storagePoolCreate)
(storagePoolDefine, storagePoolUndefine, storagePoolStart)
(storagePoolDestroy, storagePoolDelete, storageVolumeCreateXML)
(storageVolumeCreateXMLFrom, storageVolumeDelete): Likewise.
* src/util/bridge.c (brProbeVnetHdr): Likewise.
* po/POTFILES.in: Drop src/util/bridge.c.
2011-05-11 15:08:44 +00:00
|
|
|
VIR_INFO("Creating volume '%s' in storage pool '%s'",
|
2011-03-30 01:19:47 +00:00
|
|
|
volobj->name, pool->def->name);
|
2009-05-19 13:37:51 +00:00
|
|
|
ret = volobj;
|
|
|
|
volobj = NULL;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
Convert public datatypes to inherit from virObject
This converts the following public API datatypes to use the
virObject infrastructure:
virConnectPtr
virDomainPtr
virDomainSnapshotPtr
virInterfacePtr
virNetworkPtr
virNodeDevicePtr
virNWFilterPtr
virSecretPtr
virStreamPtr
virStorageVolPtr
virStoragePoolPtr
The code is significantly simplified, since the mutex in the
virConnectPtr object now only needs to be held when accessing
the per-connection virError object instance. All other operations
are completely lock free.
* src/datatypes.c, src/datatypes.h, src/libvirt.c: Convert
public datatypes to use virObject
* src/conf/domain_event.c, src/phyp/phyp_driver.c,
src/qemu/qemu_command.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c, src/storage/storage_driver.c,
src/vbox/vbox_tmpl.c, src/xen/xend_internal.c,
tests/qemuxml2argvtest.c, tests/qemuxmlnstest.c,
tests/sexpr2xmltest.c, tests/xmconfigtest.c: Convert
to use virObjectUnref/virObjectRef
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-07-31 16:55:36 +00:00
|
|
|
virObjectUnref(volobj);
|
2009-05-19 13:37:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-02-23 03:13:18 +00:00
|
|
|
|
2009-07-14 15:24:42 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolDownload(virStorageVolPtr obj,
|
|
|
|
virStreamPtr stream,
|
|
|
|
unsigned long long offset,
|
|
|
|
unsigned long long length,
|
|
|
|
unsigned int flags)
|
2009-07-14 15:24:42 +00:00
|
|
|
{
|
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool = NULL;
|
|
|
|
virStorageVolDefPtr vol = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
storageDriverLock(driver);
|
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!pool) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching name '%s'"),
|
|
|
|
obj->pool);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2009-07-14 15:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2009-07-14 15:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vol = virStorageVolDefFindByName(pool, obj->name);
|
|
|
|
|
|
|
|
if (vol == NULL) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
obj->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2009-07-14 15:24:42 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStorageVolDownloadEnsureACL(obj->conn, pool->def, vol) < 0)
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2013-04-23 10:56:22 +00:00
|
|
|
|
2009-07-14 15:24:42 +00:00
|
|
|
if (vol->building) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("volume '%s' is still being allocated."),
|
|
|
|
vol->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2009-07-14 15:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virFDStreamOpenFile(stream,
|
|
|
|
vol->target.path,
|
|
|
|
offset, length,
|
2011-08-02 17:19:53 +00:00
|
|
|
O_RDONLY) < 0)
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2009-07-14 15:24:42 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2009-07-14 15:24:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolUpload(virStorageVolPtr obj,
|
|
|
|
virStreamPtr stream,
|
|
|
|
unsigned long long offset,
|
|
|
|
unsigned long long length,
|
|
|
|
unsigned int flags)
|
2009-07-14 15:24:42 +00:00
|
|
|
{
|
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool = NULL;
|
|
|
|
virStorageVolDefPtr vol = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
storageDriverLock(driver);
|
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!pool) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching name '%s'"),
|
|
|
|
obj->pool);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2009-07-14 15:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2009-07-14 15:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vol = virStorageVolDefFindByName(pool, obj->name);
|
|
|
|
|
|
|
|
if (vol == NULL) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
obj->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2009-07-14 15:24:42 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStorageVolUploadEnsureACL(obj->conn, pool->def, vol) < 0)
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2013-04-23 10:56:22 +00:00
|
|
|
|
2009-07-14 15:24:42 +00:00
|
|
|
if (vol->building) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("volume '%s' is still being allocated."),
|
|
|
|
vol->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2009-07-14 15:24:42 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 15:11:28 +00:00
|
|
|
switch ((enum virStoragePoolType) pool->def->type) {
|
|
|
|
case VIR_STORAGE_POOL_DIR:
|
|
|
|
case VIR_STORAGE_POOL_FS:
|
|
|
|
case VIR_STORAGE_POOL_NETFS:
|
|
|
|
case VIR_STORAGE_POOL_LOGICAL:
|
|
|
|
case VIR_STORAGE_POOL_DISK:
|
|
|
|
case VIR_STORAGE_POOL_ISCSI:
|
|
|
|
case VIR_STORAGE_POOL_SCSI:
|
|
|
|
case VIR_STORAGE_POOL_MPATH:
|
|
|
|
/* Not using O_CREAT because the file is required to already exist at
|
|
|
|
* this point */
|
|
|
|
if (virFDStreamOpenFile(stream, vol->target.path,
|
|
|
|
offset, length, O_WRONLY) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_STORAGE_POOL_SHEEPDOG:
|
|
|
|
case VIR_STORAGE_POOL_RBD:
|
|
|
|
case VIR_STORAGE_POOL_GLUSTER:
|
|
|
|
case VIR_STORAGE_POOL_LAST:
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
|
|
|
|
_("volume upload is not supported with pools of type %s"),
|
|
|
|
virStoragePoolTypeToString(pool->def->type));
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2014-03-03 15:11:28 +00:00
|
|
|
}
|
2009-07-14 15:24:42 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2009-07-14 15:24:42 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-01-30 07:40:00 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolResize(virStorageVolPtr obj,
|
|
|
|
unsigned long long capacity,
|
|
|
|
unsigned int flags)
|
2012-01-30 07:40:00 +00:00
|
|
|
{
|
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStorageBackendPtr backend;
|
|
|
|
virStoragePoolObjPtr pool = NULL;
|
|
|
|
virStorageVolDefPtr vol = NULL;
|
|
|
|
unsigned long long abs_capacity;
|
|
|
|
int ret = -1;
|
|
|
|
|
2013-05-31 05:16:14 +00:00
|
|
|
virCheckFlags(VIR_STORAGE_VOL_RESIZE_ALLOCATE |
|
2013-05-31 05:16:15 +00:00
|
|
|
VIR_STORAGE_VOL_RESIZE_DELTA |
|
|
|
|
VIR_STORAGE_VOL_RESIZE_SHRINK, -1);
|
2012-01-30 07:40:00 +00:00
|
|
|
|
|
|
|
storageDriverLock(driver);
|
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!pool) {
|
2012-10-08 22:37:22 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
|
|
_("no storage pool with matching name '%s'"),
|
|
|
|
obj->pool);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2012-01-30 07:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
2012-10-08 22:37:22 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2012-01-30 07:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2012-01-30 07:40:00 +00:00
|
|
|
|
|
|
|
vol = virStorageVolDefFindByName(pool, obj->name);
|
|
|
|
|
|
|
|
if (vol == NULL) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
obj->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2012-01-30 07:40:00 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStorageVolResizeEnsureACL(obj->conn, pool->def, vol) < 0)
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2013-04-23 10:56:22 +00:00
|
|
|
|
2012-01-30 07:40:00 +00:00
|
|
|
if (vol->building) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("volume '%s' is still being allocated."),
|
|
|
|
vol->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2012-01-30 07:40:00 +00:00
|
|
|
}
|
2009-07-14 15:24:42 +00:00
|
|
|
|
2012-01-30 07:40:00 +00:00
|
|
|
if (flags & VIR_STORAGE_VOL_RESIZE_DELTA) {
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
abs_capacity = vol->target.capacity + capacity;
|
2012-01-30 07:40:00 +00:00
|
|
|
flags &= ~VIR_STORAGE_VOL_RESIZE_DELTA;
|
|
|
|
} else {
|
|
|
|
abs_capacity = capacity;
|
|
|
|
}
|
|
|
|
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
if (abs_capacity < vol->target.allocation) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
2012-07-18 11:38:29 +00:00
|
|
|
_("can't shrink capacity below "
|
|
|
|
"existing allocation"));
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2012-01-30 07:40:00 +00:00
|
|
|
}
|
|
|
|
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
if (abs_capacity < vol->target.capacity &&
|
2013-05-31 05:16:15 +00:00
|
|
|
!(flags & VIR_STORAGE_VOL_RESIZE_SHRINK)) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Can't shrink capacity below current "
|
|
|
|
"capacity with shrink flag explicitly specified"));
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2013-05-31 05:16:15 +00:00
|
|
|
}
|
|
|
|
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
if (abs_capacity > vol->target.capacity + pool->def->available) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
2012-07-18 11:38:29 +00:00
|
|
|
_("Not enough space left on storage pool"));
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2012-01-30 07:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!backend->resizeVol) {
|
maint: don't permit format strings without %
Any time we have a string with no % passed through gettext, a
translator can inject a % to cause a stack overread. When there
is nothing to format, it's easier to ask for a string that cannot
be used as a formatter, by using a trivial "%s" format instead.
In the past, we have used --disable-nls to catch some of the
offenders, but that doesn't get run very often, and many more
uses have crept in. Syntax check to the rescue!
The syntax check can catch uses such as
virReportError(code,
_("split "
"string"));
by using a sed script to fold context lines into one pattern
space before checking for a string without %.
This patch is just mechanical insertion of %s; there are probably
several messages touched by this patch where we would be better
off giving the user more information than a fixed string.
* cfg.mk (sc_prohibit_diagnostic_without_format): New rule.
* src/datatypes.c (virUnrefConnect, virGetDomain)
(virUnrefDomain, virGetNetwork, virUnrefNetwork, virGetInterface)
(virUnrefInterface, virGetStoragePool, virUnrefStoragePool)
(virGetStorageVol, virUnrefStorageVol, virGetNodeDevice)
(virGetSecret, virUnrefSecret, virGetNWFilter, virUnrefNWFilter)
(virGetDomainSnapshot, virUnrefDomainSnapshot): Add %s wrapper.
* src/lxc/lxc_driver.c (lxcDomainSetBlkioParameters)
(lxcDomainGetBlkioParameters): Likewise.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML)
(virDomainDiskDefParseXML, virDomainGraphicsDefParseXML):
Likewise.
* src/conf/network_conf.c (virNetworkDNSHostsDefParseXML)
(virNetworkDefParseXML): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterIsValidChainName):
Likewise.
* src/conf/nwfilter_params.c (virNWFilterVarValueCreateSimple)
(virNWFilterVarAccessParse): Likewise.
* src/libvirt.c (virDomainSave, virDomainSaveFlags)
(virDomainRestore, virDomainRestoreFlags)
(virDomainSaveImageGetXMLDesc, virDomainSaveImageDefineXML)
(virDomainCoreDump, virDomainGetXMLDesc)
(virDomainMigrateVersion1, virDomainMigrateVersion2)
(virDomainMigrateVersion3, virDomainMigrate, virDomainMigrate2)
(virStreamSendAll, virStreamRecvAll)
(virDomainSnapshotGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopReqLeaseDel)
(virNWFilterDHCPSnoopReq): Likewise.
* src/openvz/openvz_driver.c (openvzUpdateDevice): Likewise.
* src/openvz/openvz_util.c (openvzKBPerPages): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Likewise.
* src/qemu/qemu_command.c (qemuBuildHubDevStr, qemuBuildChrChardevStr)
(qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/rpc/virnetsaslcontext.c (virNetSASLSessionGetIdentity):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectUNIX)
(virNetSocketSendFD, virNetSocketRecvFD): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemProbe)
(virStorageBackendFileSystemBuild): Likewise.
* src/storage/storage_backend_rbd.c
(virStorageBackendRBDOpenRADOSConn): Likewise.
* src/storage/storage_driver.c (storageVolumeResize): Likewise.
* src/test/test_driver.c (testInterfaceChangeBegin)
(testInterfaceChangeCommit, testInterfaceChangeRollback):
Likewise.
* src/vbox/vbox_tmpl.c (vboxListAllDomains): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk, xenFormatSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetUUID, xenFormatXMDisk)
(xenFormatXM): Likewise.
2012-07-23 20:33:08 +00:00
|
|
|
virReportError(VIR_ERR_NO_SUPPORT, "%s",
|
2012-07-18 11:38:29 +00:00
|
|
|
_("storage pool does not support changing of "
|
|
|
|
"volume capacity"));
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2012-01-30 07:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (backend->resizeVol(obj->conn, pool, vol, abs_capacity, flags) < 0)
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2012-01-30 07:40:00 +00:00
|
|
|
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
vol->target.capacity = abs_capacity;
|
2013-12-16 05:00:00 +00:00
|
|
|
if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE)
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
vol->target.allocation = abs_capacity;
|
2013-08-16 12:08:07 +00:00
|
|
|
|
|
|
|
/* Update pool metadata */
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
pool->def->allocation += (abs_capacity - vol->target.capacity);
|
|
|
|
pool->def->available -= (abs_capacity - vol->target.capacity);
|
2013-08-16 12:08:07 +00:00
|
|
|
|
2013-04-13 07:22:01 +00:00
|
|
|
ret = 0;
|
2012-01-30 07:40:00 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2012-01-30 07:40:00 +00:00
|
|
|
if (pool)
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-07-14 15:24:42 +00:00
|
|
|
|
2010-02-23 03:13:18 +00:00
|
|
|
/* If the volume we're wiping is already a sparse file, we simply
|
|
|
|
* truncate and extend it to its original size, filling it with
|
|
|
|
* zeroes. This behavior is guaranteed by POSIX:
|
|
|
|
*
|
|
|
|
* http://www.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html
|
|
|
|
*
|
|
|
|
* If fildes refers to a regular file, the ftruncate() function shall
|
|
|
|
* cause the size of the file to be truncated to length. If the size
|
|
|
|
* of the file previously exceeded length, the extra data shall no
|
|
|
|
* longer be available to reads on the file. If the file previously
|
|
|
|
* was smaller than this size, ftruncate() shall increase the size of
|
|
|
|
* the file. If the file size is increased, the extended area shall
|
|
|
|
* appear as if it were zero-filled.
|
|
|
|
*/
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolZeroSparseFile(virStorageVolDefPtr vol,
|
|
|
|
off_t size,
|
|
|
|
int fd)
|
2010-02-23 03:13:18 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
ret = ftruncate(fd, 0);
|
|
|
|
if (ret == -1) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to truncate volume with "
|
|
|
|
"path '%s' to 0 bytes"),
|
|
|
|
vol->target.path);
|
2014-03-03 14:47:32 +00:00
|
|
|
return ret;
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = ftruncate(fd, size);
|
|
|
|
if (ret == -1) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to truncate volume with "
|
2010-04-02 19:44:04 +00:00
|
|
|
"path '%s' to %ju bytes"),
|
2010-12-08 00:31:14 +00:00
|
|
|
vol->target.path, (uintmax_t)size);
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
storageWipeExtent(virStorageVolDefPtr vol,
|
|
|
|
int fd,
|
|
|
|
off_t extent_start,
|
|
|
|
off_t extent_length,
|
|
|
|
char *writebuf,
|
|
|
|
size_t writebuf_length,
|
|
|
|
size_t *bytes_wiped)
|
|
|
|
{
|
|
|
|
int ret = -1, written = 0;
|
|
|
|
off_t remaining = 0;
|
|
|
|
size_t write_size = 0;
|
|
|
|
|
|
|
|
VIR_DEBUG("extent logical start: %ju len: %ju",
|
2010-12-08 00:31:14 +00:00
|
|
|
(uintmax_t)extent_start, (uintmax_t)extent_length);
|
2010-02-23 03:13:18 +00:00
|
|
|
|
|
|
|
if ((ret = lseek(fd, extent_start, SEEK_SET)) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to seek to position %ju in volume "
|
|
|
|
"with path '%s'"),
|
2010-12-08 00:31:14 +00:00
|
|
|
(uintmax_t)extent_start, vol->target.path);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
remaining = extent_length;
|
|
|
|
while (remaining > 0) {
|
|
|
|
|
|
|
|
write_size = (writebuf_length < remaining) ? writebuf_length : remaining;
|
|
|
|
written = safewrite(fd, writebuf, write_size);
|
|
|
|
if (written < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to write %zu bytes to "
|
|
|
|
"storage volume with path '%s'"),
|
|
|
|
write_size, vol->target.path);
|
|
|
|
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*bytes_wiped += written;
|
|
|
|
remaining -= written;
|
|
|
|
}
|
|
|
|
|
2011-08-18 12:40:03 +00:00
|
|
|
if (fdatasync(fd) < 0) {
|
|
|
|
ret = -errno;
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("cannot sync data to volume with path '%s'"),
|
|
|
|
vol->target.path);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2011-08-18 12:40:03 +00:00
|
|
|
}
|
|
|
|
|
2010-02-23 03:13:18 +00:00
|
|
|
VIR_DEBUG("Wrote %zu bytes to volume with path '%s'",
|
|
|
|
*bytes_wiped, vol->target.path);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2010-02-23 03:13:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolWipeInternal(virStorageVolDefPtr def,
|
|
|
|
unsigned int algorithm)
|
2010-02-23 03:13:18 +00:00
|
|
|
{
|
|
|
|
int ret = -1, fd = -1;
|
|
|
|
struct stat st;
|
|
|
|
char *writebuf = NULL;
|
|
|
|
size_t bytes_wiped = 0;
|
2012-01-09 16:05:03 +00:00
|
|
|
virCommandPtr cmd = NULL;
|
2010-02-23 03:13:18 +00:00
|
|
|
|
2012-01-09 16:05:03 +00:00
|
|
|
VIR_DEBUG("Wiping volume with path '%s' and algorithm %u",
|
|
|
|
def->target.path, algorithm);
|
2010-02-23 03:13:18 +00:00
|
|
|
|
|
|
|
fd = open(def->target.path, O_RDWR);
|
|
|
|
if (fd == -1) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to open storage volume with path '%s'"),
|
|
|
|
def->target.path);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fstat(fd, &st) == -1) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to stat storage volume with path '%s'"),
|
|
|
|
def->target.path);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 16:05:03 +00:00
|
|
|
if (algorithm != VIR_STORAGE_VOL_WIPE_ALG_ZERO) {
|
|
|
|
const char *alg_char ATTRIBUTE_UNUSED = NULL;
|
|
|
|
switch (algorithm) {
|
|
|
|
case VIR_STORAGE_VOL_WIPE_ALG_NNSA:
|
|
|
|
alg_char = "nnsa";
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_VOL_WIPE_ALG_DOD:
|
|
|
|
alg_char = "dod";
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_VOL_WIPE_ALG_BSI:
|
|
|
|
alg_char = "bsi";
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_VOL_WIPE_ALG_GUTMANN:
|
|
|
|
alg_char = "gutmann";
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_VOL_WIPE_ALG_SCHNEIER:
|
2012-02-29 06:20:32 +00:00
|
|
|
alg_char = "schneier";
|
2012-01-09 16:05:03 +00:00
|
|
|
break;
|
|
|
|
case VIR_STORAGE_VOL_WIPE_ALG_PFITZNER7:
|
|
|
|
alg_char = "pfitzner7";
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_VOL_WIPE_ALG_PFITZNER33:
|
2012-02-29 10:42:00 +00:00
|
|
|
alg_char = "pfitzner33";
|
2012-01-09 16:05:03 +00:00
|
|
|
break;
|
|
|
|
case VIR_STORAGE_VOL_WIPE_ALG_RANDOM:
|
|
|
|
alg_char = "random";
|
|
|
|
break;
|
|
|
|
default:
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unsupported algorithm %d"),
|
|
|
|
algorithm);
|
2012-01-09 16:05:03 +00:00
|
|
|
}
|
|
|
|
cmd = virCommandNew(SCRUB);
|
|
|
|
virCommandAddArgList(cmd, "-f", "-p", alg_char,
|
|
|
|
def->target.path, NULL);
|
2010-02-23 03:13:18 +00:00
|
|
|
|
2012-01-09 16:05:03 +00:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2010-02-23 03:13:18 +00:00
|
|
|
|
2012-01-09 16:05:03 +00:00
|
|
|
ret = 0;
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2012-01-09 16:05:03 +00:00
|
|
|
} else {
|
|
|
|
if (S_ISREG(st.st_mode) && st.st_blocks < (st.st_size / DEV_BSIZE)) {
|
2013-04-23 12:50:18 +00:00
|
|
|
ret = storageVolZeroSparseFile(def, st.st_size, fd);
|
2012-01-09 16:05:03 +00:00
|
|
|
} else {
|
|
|
|
|
2013-07-04 10:16:29 +00:00
|
|
|
if (VIR_ALLOC_N(writebuf, st.st_blksize) < 0)
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2012-01-09 16:05:03 +00:00
|
|
|
|
|
|
|
ret = storageWipeExtent(def,
|
|
|
|
fd,
|
|
|
|
0,
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
def->target.allocation,
|
2012-01-09 16:05:03 +00:00
|
|
|
writebuf,
|
|
|
|
st.st_blksize,
|
|
|
|
&bytes_wiped);
|
|
|
|
}
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2012-01-09 16:05:03 +00:00
|
|
|
virCommandFree(cmd);
|
2010-02-23 03:13:18 +00:00
|
|
|
VIR_FREE(writebuf);
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(fd);
|
2010-02-23 03:13:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolWipePattern(virStorageVolPtr obj,
|
|
|
|
unsigned int algorithm,
|
|
|
|
unsigned int flags)
|
2010-02-23 03:13:18 +00:00
|
|
|
{
|
|
|
|
virStorageDriverStatePtr driver = obj->conn->storagePrivateData;
|
|
|
|
virStoragePoolObjPtr pool = NULL;
|
|
|
|
virStorageVolDefPtr vol = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(0, -1);
|
2010-02-23 03:13:18 +00:00
|
|
|
|
2012-01-09 16:05:03 +00:00
|
|
|
if (algorithm >= VIR_STORAGE_VOL_WIPE_ALG_LAST) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("wiping algorithm %d not supported"),
|
|
|
|
algorithm);
|
2012-01-09 16:05:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-02-23 03:13:18 +00:00
|
|
|
storageDriverLock(driver);
|
|
|
|
pool = virStoragePoolObjFindByName(&driver->pools, obj->pool);
|
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!pool) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching name '%s'"),
|
|
|
|
obj->pool);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vol = virStorageVolDefFindByName(pool, obj->name);
|
|
|
|
|
|
|
|
if (vol == NULL) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("no storage vol with matching name '%s'"),
|
|
|
|
obj->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStorageVolWipePatternEnsureACL(obj->conn, pool->def, vol) < 0)
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2013-04-23 10:56:22 +00:00
|
|
|
|
2010-02-23 03:13:18 +00:00
|
|
|
if (vol->building) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("volume '%s' is still being allocated."),
|
|
|
|
vol->name);
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
if (storageVolWipeInternal(vol, algorithm) == -1) {
|
2014-03-03 14:47:32 +00:00
|
|
|
goto cleanup;
|
2010-02-23 03:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2010-02-23 03:13:18 +00:00
|
|
|
if (pool) {
|
|
|
|
virStoragePoolObjUnlock(pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-01-09 16:05:03 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolWipe(virStorageVolPtr obj,
|
|
|
|
unsigned int flags)
|
2012-01-09 16:05:03 +00:00
|
|
|
{
|
2013-04-23 12:50:18 +00:00
|
|
|
return storageVolWipePattern(obj, VIR_STORAGE_VOL_WIPE_ALG_ZERO, flags);
|
2012-01-09 16:05:03 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolGetInfo(virStorageVolPtr obj,
|
2014-03-18 08:15:36 +00:00
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching name '%s'"),
|
|
|
|
obj->pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStorageVolGetInfoEnsureACL(obj->conn, pool->def, vol) < 0)
|
|
|
|
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;
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
info->capacity = vol->target.capacity;
|
|
|
|
info->allocation = vol->target.allocation;
|
2008-12-04 21:39:45 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:34:52 +00:00
|
|
|
|
2014-03-25 06:52:40 +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 *
|
2013-04-23 12:50:18 +00:00
|
|
|
storageVolGetXMLDesc(virStorageVolPtr obj,
|
|
|
|
unsigned int flags)
|
2011-07-06 22:51:23 +00:00
|
|
|
{
|
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
|
|
|
|
2011-07-06 22:51:23 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching name '%s'"),
|
|
|
|
obj->pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStorageVolGetXMLDescEnsureACL(obj->conn, pool->def, vol) < 0)
|
|
|
|
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
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
ret = virStorageVolDefFormat(pool->def, vol);
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2014-03-25 06:52:40 +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 *
|
2014-03-18 08:15:36 +00:00
|
|
|
storageVolGetPath(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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("no storage pool with matching name '%s'"),
|
|
|
|
obj->pool);
|
2008-12-04 21:39:45 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!virStoragePoolObjIsActive(pool)) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
2012-10-08 22:37:22 +00:00
|
|
|
_("storage pool '%s' is not active"), pool->def->name);
|
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) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virStorageVolGetPathEnsureACL(obj->conn, pool->def, vol) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-03 12:49:08 +00:00
|
|
|
ignore_value(VIR_STRDUP(ret, vol->target.path));
|
2008-12-04 21:39:45 +00:00
|
|
|
|
2014-03-25 06:52:40 +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;
|
|
|
|
}
|
|
|
|
|
2012-09-04 15:16:27 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
storageConnectListAllStoragePools(virConnectPtr conn,
|
|
|
|
virStoragePoolPtr **pools,
|
|
|
|
unsigned int flags)
|
2012-09-04 15:16:27 +00:00
|
|
|
{
|
|
|
|
virStorageDriverStatePtr driver = conn->storagePrivateData;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ALL, -1);
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectListAllStoragePoolsEnsureACL(conn) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-09-04 15:16:27 +00:00
|
|
|
storageDriverLock(driver);
|
2013-06-26 17:47:48 +00:00
|
|
|
ret = virStoragePoolObjListExport(conn, driver->pools, pools,
|
|
|
|
virConnectListAllStoragePoolsCheckACL, flags);
|
2012-09-04 15:16:27 +00:00
|
|
|
storageDriverUnlock(driver);
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2012-09-04 15:16:27 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-03 15:12:57 +00:00
|
|
|
|
2008-02-20 15:34:52 +00:00
|
|
|
static virStorageDriver storageDriver = {
|
2008-09-22 19:53:42 +00:00
|
|
|
.name = "storage",
|
2013-04-23 12:49:21 +00:00
|
|
|
.storageOpen = storageOpen, /* 0.4.0 */
|
|
|
|
.storageClose = storageClose, /* 0.4.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectNumOfStoragePools = storageConnectNumOfStoragePools, /* 0.4.0 */
|
|
|
|
.connectListStoragePools = storageConnectListStoragePools, /* 0.4.0 */
|
|
|
|
.connectNumOfDefinedStoragePools = storageConnectNumOfDefinedStoragePools, /* 0.4.0 */
|
|
|
|
.connectListDefinedStoragePools = storageConnectListDefinedStoragePools, /* 0.4.0 */
|
|
|
|
.connectListAllStoragePools = storageConnectListAllStoragePools, /* 0.10.2 */
|
|
|
|
.connectFindStoragePoolSources = storageConnectFindStoragePoolSources, /* 0.4.0 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.storagePoolLookupByName = storagePoolLookupByName, /* 0.4.0 */
|
|
|
|
.storagePoolLookupByUUID = storagePoolLookupByUUID, /* 0.4.0 */
|
|
|
|
.storagePoolLookupByVolume = storagePoolLookupByVolume, /* 0.4.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.storagePoolCreateXML = storagePoolCreateXML, /* 0.4.0 */
|
|
|
|
.storagePoolDefineXML = storagePoolDefineXML, /* 0.4.0 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.storagePoolBuild = storagePoolBuild, /* 0.4.0 */
|
|
|
|
.storagePoolUndefine = storagePoolUndefine, /* 0.4.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.storagePoolCreate = storagePoolCreate, /* 0.4.0 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.storagePoolDestroy = storagePoolDestroy, /* 0.4.0 */
|
|
|
|
.storagePoolDelete = storagePoolDelete, /* 0.4.0 */
|
|
|
|
.storagePoolRefresh = storagePoolRefresh, /* 0.4.0 */
|
|
|
|
.storagePoolGetInfo = storagePoolGetInfo, /* 0.4.0 */
|
|
|
|
.storagePoolGetXMLDesc = storagePoolGetXMLDesc, /* 0.4.0 */
|
|
|
|
.storagePoolGetAutostart = storagePoolGetAutostart, /* 0.4.0 */
|
|
|
|
.storagePoolSetAutostart = storagePoolSetAutostart, /* 0.4.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.storagePoolNumOfVolumes = storagePoolNumOfVolumes, /* 0.4.0 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.storagePoolListVolumes = storagePoolListVolumes, /* 0.4.0 */
|
|
|
|
.storagePoolListAllVolumes = storagePoolListAllVolumes, /* 0.10.2 */
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
.storageVolLookupByName = storageVolLookupByName, /* 0.4.0 */
|
|
|
|
.storageVolLookupByKey = storageVolLookupByKey, /* 0.4.0 */
|
|
|
|
.storageVolLookupByPath = storageVolLookupByPath, /* 0.4.0 */
|
|
|
|
.storageVolCreateXML = storageVolCreateXML, /* 0.4.0 */
|
|
|
|
.storageVolCreateXMLFrom = storageVolCreateXMLFrom, /* 0.6.4 */
|
|
|
|
.storageVolDownload = storageVolDownload, /* 0.9.0 */
|
|
|
|
.storageVolUpload = storageVolUpload, /* 0.9.0 */
|
|
|
|
.storageVolDelete = storageVolDelete, /* 0.4.0 */
|
|
|
|
.storageVolWipe = storageVolWipe, /* 0.8.0 */
|
|
|
|
.storageVolWipePattern = storageVolWipePattern, /* 0.9.10 */
|
|
|
|
.storageVolGetInfo = storageVolGetInfo, /* 0.4.0 */
|
|
|
|
.storageVolGetXMLDesc = storageVolGetXMLDesc, /* 0.4.0 */
|
|
|
|
.storageVolGetPath = storageVolGetPath, /* 0.4.0 */
|
|
|
|
.storageVolResize = storageVolResize, /* 0.9.10 */
|
2013-04-22 17:26:01 +00:00
|
|
|
|
|
|
|
.storagePoolIsActive = storagePoolIsActive, /* 0.7.3 */
|
|
|
|
.storagePoolIsPersistent = storagePoolIsPersistent, /* 0.7.3 */
|
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",
|
2013-04-23 12:50:18 +00:00
|
|
|
.stateInitialize = storageStateInitialize,
|
2013-07-25 12:03:38 +00:00
|
|
|
.stateAutoStart = storageStateAutoStart,
|
2013-04-23 12:50:18 +00:00
|
|
|
.stateCleanup = storageStateCleanup,
|
|
|
|
.stateReload = storageStateReload,
|
2008-02-20 15:34:52 +00:00
|
|
|
};
|
|
|
|
|
2013-12-02 20:31:42 +00:00
|
|
|
int storageRegister(void)
|
|
|
|
{
|
|
|
|
if (virRegisterStorageDriver(&storageDriver) < 0)
|
|
|
|
return -1;
|
2014-03-17 13:35:42 +00:00
|
|
|
if (virRegisterStateDriver(&stateDriver) < 0)
|
|
|
|
return -1;
|
2008-02-20 15:34:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-02-03 15:12:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* ----------- file handlers cooperating with storage driver --------------- */
|
|
|
|
void
|
|
|
|
virStorageFileFree(virStorageFilePtr file)
|
|
|
|
{
|
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (file->backend &&
|
|
|
|
file->backend->backendDeinit)
|
|
|
|
file->backend->backendDeinit(file);
|
|
|
|
|
|
|
|
VIR_FREE(file->path);
|
conf: split network host structs to util/
Continuing the refactoring of host-side storage descriptions out
of conf/domain_conf and into util/virstoragefile, this patch
focuses on details about a host name/port/transport as used by
a network storage volume.
* src/conf/domain_conf.h (virDomainDiskProtocolTransport)
(virDomainDiskHostDef, virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): Move...
* src/util/virstoragefile.h (virStorageNetHostTransport)
(virStorageNetHostDef, virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): ...here,
with better names.
* src/util/virstoragefile.c (virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): Moved from...
* src/conf/domain_conf.c (virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): ...here.
(virDomainDiskSourceDefClear, virDomainDiskSourceDefParse)
(virDomainDiskSourceDefFormatInternal): Adjust callers.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear):
Likewise.
* src/qemu/qemu_command.c (qemuAddRBDHost)
(qemuParseDriveURIString, qemuParseNBDString)
(qemuBuildNetworkDriveURI, qemuParseCommandLineDisk)
(qemuParseCommandLine, qemuGetDriveSourceString): Likewise.
* src/qemu/qemu_command.h: Likewise.
* src/qemu/qemu_conf.c (qemuAddISCSIPoolSourceHost)
(qemuTranslateDiskSourcePool): Likewise.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotUndoSingleDiskActive): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGlusterInit): Likewise.
* src/storage/storage_driver.c (virStorageFileFree)
(virStorageFileInitInternal): Likewise.
* src/storage/storage_driver.h (_virStorageFile): Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-26 22:33:08 +00:00
|
|
|
virStorageNetHostDefFree(file->nhosts, file->hosts);
|
2014-02-03 15:12:57 +00:00
|
|
|
VIR_FREE(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virStorageFilePtr
|
|
|
|
virStorageFileInitInternal(int type,
|
|
|
|
const char *path,
|
|
|
|
int protocol,
|
|
|
|
size_t nhosts,
|
conf: split network host structs to util/
Continuing the refactoring of host-side storage descriptions out
of conf/domain_conf and into util/virstoragefile, this patch
focuses on details about a host name/port/transport as used by
a network storage volume.
* src/conf/domain_conf.h (virDomainDiskProtocolTransport)
(virDomainDiskHostDef, virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): Move...
* src/util/virstoragefile.h (virStorageNetHostTransport)
(virStorageNetHostDef, virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): ...here,
with better names.
* src/util/virstoragefile.c (virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): Moved from...
* src/conf/domain_conf.c (virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): ...here.
(virDomainDiskSourceDefClear, virDomainDiskSourceDefParse)
(virDomainDiskSourceDefFormatInternal): Adjust callers.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear):
Likewise.
* src/qemu/qemu_command.c (qemuAddRBDHost)
(qemuParseDriveURIString, qemuParseNBDString)
(qemuBuildNetworkDriveURI, qemuParseCommandLineDisk)
(qemuParseCommandLine, qemuGetDriveSourceString): Likewise.
* src/qemu/qemu_command.h: Likewise.
* src/qemu/qemu_conf.c (qemuAddISCSIPoolSourceHost)
(qemuTranslateDiskSourcePool): Likewise.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotUndoSingleDiskActive): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGlusterInit): Likewise.
* src/storage/storage_driver.c (virStorageFileFree)
(virStorageFileInitInternal): Likewise.
* src/storage/storage_driver.h (_virStorageFile): Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-26 22:33:08 +00:00
|
|
|
virStorageNetHostDefPtr hosts)
|
2014-02-03 15:12:57 +00:00
|
|
|
{
|
|
|
|
virStorageFilePtr file = NULL;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(file) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
file->type = type;
|
|
|
|
file->protocol = protocol;
|
|
|
|
file->nhosts = nhosts;
|
|
|
|
|
|
|
|
if (VIR_STRDUP(file->path, path) < 0)
|
|
|
|
goto error;
|
|
|
|
|
conf: split network host structs to util/
Continuing the refactoring of host-side storage descriptions out
of conf/domain_conf and into util/virstoragefile, this patch
focuses on details about a host name/port/transport as used by
a network storage volume.
* src/conf/domain_conf.h (virDomainDiskProtocolTransport)
(virDomainDiskHostDef, virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): Move...
* src/util/virstoragefile.h (virStorageNetHostTransport)
(virStorageNetHostDef, virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): ...here,
with better names.
* src/util/virstoragefile.c (virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): Moved from...
* src/conf/domain_conf.c (virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): ...here.
(virDomainDiskSourceDefClear, virDomainDiskSourceDefParse)
(virDomainDiskSourceDefFormatInternal): Adjust callers.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear):
Likewise.
* src/qemu/qemu_command.c (qemuAddRBDHost)
(qemuParseDriveURIString, qemuParseNBDString)
(qemuBuildNetworkDriveURI, qemuParseCommandLineDisk)
(qemuParseCommandLine, qemuGetDriveSourceString): Likewise.
* src/qemu/qemu_command.h: Likewise.
* src/qemu/qemu_conf.c (qemuAddISCSIPoolSourceHost)
(qemuTranslateDiskSourcePool): Likewise.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotUndoSingleDiskActive): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGlusterInit): Likewise.
* src/storage/storage_driver.c (virStorageFileFree)
(virStorageFileInitInternal): Likewise.
* src/storage/storage_driver.h (_virStorageFile): Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-26 22:33:08 +00:00
|
|
|
if (!(file->hosts = virStorageNetHostDefCopy(nhosts, hosts)))
|
2014-02-03 15:12:57 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(file->backend = virStorageFileBackendForType(file->type,
|
|
|
|
file->protocol)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (file->backend->backendInit &&
|
|
|
|
file->backend->backendInit(file) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return file;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
error:
|
2014-02-03 15:12:57 +00:00
|
|
|
VIR_FREE(file->path);
|
conf: split network host structs to util/
Continuing the refactoring of host-side storage descriptions out
of conf/domain_conf and into util/virstoragefile, this patch
focuses on details about a host name/port/transport as used by
a network storage volume.
* src/conf/domain_conf.h (virDomainDiskProtocolTransport)
(virDomainDiskHostDef, virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): Move...
* src/util/virstoragefile.h (virStorageNetHostTransport)
(virStorageNetHostDef, virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): ...here,
with better names.
* src/util/virstoragefile.c (virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): Moved from...
* src/conf/domain_conf.c (virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): ...here.
(virDomainDiskSourceDefClear, virDomainDiskSourceDefParse)
(virDomainDiskSourceDefFormatInternal): Adjust callers.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear):
Likewise.
* src/qemu/qemu_command.c (qemuAddRBDHost)
(qemuParseDriveURIString, qemuParseNBDString)
(qemuBuildNetworkDriveURI, qemuParseCommandLineDisk)
(qemuParseCommandLine, qemuGetDriveSourceString): Likewise.
* src/qemu/qemu_command.h: Likewise.
* src/qemu/qemu_conf.c (qemuAddISCSIPoolSourceHost)
(qemuTranslateDiskSourcePool): Likewise.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotUndoSingleDiskActive): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGlusterInit): Likewise.
* src/storage/storage_driver.c (virStorageFileFree)
(virStorageFileInitInternal): Likewise.
* src/storage/storage_driver.h (_virStorageFile): Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-26 22:33:08 +00:00
|
|
|
virStorageNetHostDefFree(file->nhosts, file->hosts);
|
2014-02-03 15:12:57 +00:00
|
|
|
VIR_FREE(file);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virStorageFilePtr
|
|
|
|
virStorageFileInitFromDiskDef(virDomainDiskDefPtr disk)
|
|
|
|
{
|
|
|
|
return virStorageFileInitInternal(virDomainDiskGetActualType(disk),
|
conf: prepare to track multiple host source files per <disk>
It's finally time to start tracking disk backing chains in
<domain> XML. The first step is to start refactoring code
so that we have an object more convenient for representing
each host source resource in the context of a single guest
<disk>. Ultimately, I plan to move the new type into src/util
where it can be reused by virStorageFile, but to make the
transition easier to review, this patch just creates the
new type then fixes everything until it compiles again.
* src/conf/domain_conf.h (_virDomainDiskDef): Split...
(_virDomainDiskSourceDef): ...to new struct.
(virDomainDiskAuthClear): Use new type.
* src/conf/domain_conf.c (virDomainDiskDefFree): Split...
(virDomainDiskSourceDefClear): ...to new function.
(virDomainDiskGetType, virDomainDiskSetType)
(virDomainDiskGetSource, virDomainDiskSetSource)
(virDomainDiskGetDriver, virDomainDiskSetDriver)
(virDomainDiskGetFormat, virDomainDiskSetFormat)
(virDomainDiskAuthClear, virDomainDiskGetActualType)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormat)
(virDomainDiskDefFormat, virDomainDiskDefForeachPath)
(virDomainDiskDefGetSecurityLabelDef)
(virDomainDiskSourceIsBlockType): Adjust all users.
* src/lxc/lxc_controller.c (virLXCControllerSetupDisk):
Likewise.
* src/lxc/lxc_driver.c (lxcDomainAttachDeviceMknodHelper):
Likewise.
* src/qemu/qemu_command.c (qemuAddRBDHost, qemuParseRBDString)
(qemuParseDriveURIString, qemuParseGlusterString)
(qemuParseISCSIString, qemuParseNBDString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuAddISCSIPoolSourceHost, qemuTranslateDiskSourcePool):
Likewise.
* src/qemu/qemu_driver.c (qemuDomainUpdateDeviceConfig)
(qemuDomainPrepareDiskChainElement)
(qemuDomainSnapshotCreateInactiveExternal)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotUndoSingleDiskActive)
(qemuDomainBlockPivot, qemuDomainBlockJobImpl)
(qemuDomainBlockCopy, qemuDomainBlockCommit): Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase)
(qemuProcessInitPasswords): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxSetSecurityFileLabel): Likewise.
* src/storage/storage_driver.c (virStorageFileInitFromDiskDef):
Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-19 17:11:16 +00:00
|
|
|
disk->src.path,
|
|
|
|
disk->src.protocol,
|
|
|
|
disk->src.nhosts,
|
|
|
|
disk->src.hosts);
|
2014-02-03 15:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virStorageFilePtr
|
|
|
|
virStorageFileInitFromSnapshotDef(virDomainSnapshotDiskDefPtr disk)
|
|
|
|
{
|
|
|
|
return virStorageFileInitInternal(virDomainSnapshotDiskGetActualType(disk),
|
2014-03-29 22:01:05 +00:00
|
|
|
disk->src.path,
|
|
|
|
disk->src.protocol,
|
|
|
|
disk->src.nhosts,
|
|
|
|
disk->src.hosts);
|
2014-02-03 15:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageFileCreate: Creates an empty storage file via storage driver
|
|
|
|
*
|
|
|
|
* @file: file structure pointing to the file
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -2 if the function isn't supported by the backend,
|
|
|
|
* -1 on other failure. Errno is set in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStorageFileCreate(virStorageFilePtr file)
|
|
|
|
{
|
|
|
|
if (!file->backend->storageFileCreate) {
|
|
|
|
errno = ENOSYS;
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return file->backend->storageFileCreate(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageFileUnlink: Unlink storage file via storage driver
|
|
|
|
*
|
|
|
|
* @file: file structure pointing to the file
|
|
|
|
*
|
|
|
|
* Unlinks the file described by the @file structure.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -2 if the function isn't supported by the backend,
|
|
|
|
* -1 on other failure. Errno is set in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStorageFileUnlink(virStorageFilePtr file)
|
|
|
|
{
|
|
|
|
if (!file->backend->storageFileUnlink) {
|
|
|
|
errno = ENOSYS;
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return file->backend->storageFileUnlink(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageFileStat: returns stat struct of a file via storage driver
|
|
|
|
*
|
|
|
|
* @file: file structure pointing to the file
|
|
|
|
* @stat: stat structure to return data
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -2 if the function isn't supported by the backend,
|
|
|
|
* -1 on other failure. Errno is set in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStorageFileStat(virStorageFilePtr file,
|
|
|
|
struct stat *st)
|
|
|
|
{
|
|
|
|
if (!(file->backend->storageFileStat)) {
|
|
|
|
errno = ENOSYS;
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return file->backend->storageFileStat(file, st);
|
|
|
|
}
|