2008-02-20 15:52:17 +00:00
|
|
|
/*
|
|
|
|
* storage_backend_disk.c: storage backend for disk handling
|
|
|
|
*
|
2010-05-14 20:50:27 +00:00
|
|
|
* Copyright (C) 2007-2008, 2010 Red Hat, Inc.
|
2008-02-20 15:52:17 +00:00
|
|
|
* Copyright (C) 2007-2008 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2008-09-16 16:46:08 +00:00
|
|
|
#include <string.h>
|
2008-09-17 14:29:47 +00:00
|
|
|
#include <unistd.h>
|
2008-11-17 11:19:33 +00:00
|
|
|
#include <stdio.h>
|
2008-02-20 15:52:17 +00:00
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
#include "virterror_internal.h"
|
2008-11-06 16:36:07 +00:00
|
|
|
#include "logging.h"
|
2008-02-20 15:52:17 +00:00
|
|
|
#include "storage_backend_disk.h"
|
|
|
|
#include "util.h"
|
2008-06-06 11:09:57 +00:00
|
|
|
#include "memory.h"
|
2011-02-17 07:29:07 +00:00
|
|
|
#include "command.h"
|
2010-11-16 14:54:17 +00:00
|
|
|
#include "configmake.h"
|
2008-02-20 15:52:17 +00:00
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
|
|
|
|
2010-11-16 14:54:17 +00:00
|
|
|
#define PARTHELPER LIBEXECDIR "/libvirt_parthelper"
|
2008-02-20 15:52:17 +00:00
|
|
|
|
2009-06-26 16:18:59 +00:00
|
|
|
#define SECTOR_SIZE 512
|
|
|
|
|
2008-02-20 15:52:17 +00:00
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
|
2008-02-20 15:52:17 +00:00
|
|
|
char **const groups,
|
|
|
|
virStorageVolDefPtr vol)
|
|
|
|
{
|
|
|
|
char *tmp, *devpath;
|
|
|
|
|
|
|
|
if (vol == NULL) {
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(vol) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:52:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
if (VIR_REALLOC_N(pool->volumes.objs,
|
|
|
|
pool->volumes.count+1) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-10-10 15:13:28 +00:00
|
|
|
virStorageVolDefFree(vol);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
pool->volumes.objs[pool->volumes.count++] = vol;
|
2008-02-20 15:52:17 +00:00
|
|
|
|
|
|
|
/* Prepended path will be same for all partitions, so we can
|
|
|
|
* strip the path to form a reasonable pool-unique name
|
|
|
|
*/
|
|
|
|
tmp = strrchr(groups[0], '/');
|
|
|
|
if ((vol->name = strdup(tmp ? tmp + 1 : groups[0])) == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:52:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vol->target.path == NULL) {
|
|
|
|
if ((devpath = strdup(groups[0])) == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:52:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now figure out the stable path
|
|
|
|
*
|
|
|
|
* XXX this method is O(N) because it scans the pool target
|
|
|
|
* dir every time its run. Should figure out a more efficient
|
|
|
|
* way of doing this...
|
|
|
|
*/
|
2010-02-04 20:02:58 +00:00
|
|
|
vol->target.path = virStorageBackendStablePath(pool, devpath);
|
2008-11-03 11:37:11 +00:00
|
|
|
VIR_FREE(devpath);
|
2009-11-10 11:56:11 +00:00
|
|
|
if (vol->target.path == NULL)
|
|
|
|
return -1;
|
2008-02-20 15:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vol->key == NULL) {
|
|
|
|
/* XXX base off a unique key of the underlying disk */
|
|
|
|
if ((vol->key = strdup(vol->target.path)) == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:52:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vol->source.extents == NULL) {
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(vol->source.extents) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:52:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
vol->source.nextent = 1;
|
|
|
|
|
|
|
|
if (virStrToLong_ull(groups[3], NULL, 10,
|
|
|
|
&vol->source.extents[0].start) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("cannot parse device start location"));
|
2008-02-20 15:52:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStrToLong_ull(groups[4], NULL, 10,
|
|
|
|
&vol->source.extents[0].end) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("cannot parse device end location"));
|
2008-02-20 15:52:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vol->source.extents[0].path =
|
|
|
|
strdup(pool->def->source.devices[0].path)) == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:52:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Refresh allocation/capacity/perms */
|
2010-02-04 20:02:58 +00:00
|
|
|
if (virStorageBackendUpdateVolInfo(vol, 1) < 0)
|
2008-02-20 15:52:17 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-06-26 16:18:59 +00:00
|
|
|
/* set partition type */
|
2010-08-18 20:54:48 +00:00
|
|
|
if (STREQ(groups[1], "normal"))
|
2009-06-26 16:18:59 +00:00
|
|
|
vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_PRIMARY;
|
2010-08-18 20:54:48 +00:00
|
|
|
else if (STREQ(groups[1], "logical"))
|
2009-06-26 16:18:59 +00:00
|
|
|
vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_LOGICAL;
|
2010-08-18 20:54:48 +00:00
|
|
|
else if (STREQ(groups[1], "extended"))
|
2009-06-26 16:18:59 +00:00
|
|
|
vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_EXTENDED;
|
|
|
|
else
|
|
|
|
vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_NONE;
|
|
|
|
|
2008-11-17 11:19:33 +00:00
|
|
|
vol->type = VIR_STORAGE_VOL_BLOCK;
|
|
|
|
|
2008-02-20 15:52:17 +00:00
|
|
|
/* The above gets allocation wrong for
|
|
|
|
* extended partitions, so overwrite it */
|
|
|
|
vol->allocation = vol->capacity =
|
|
|
|
(vol->source.extents[0].end - vol->source.extents[0].start);
|
|
|
|
|
|
|
|
if (STRNEQ(groups[2], "metadata"))
|
|
|
|
pool->def->allocation += vol->allocation;
|
|
|
|
if (vol->source.extents[0].end > pool->def->capacity)
|
|
|
|
pool->def->capacity = vol->source.extents[0].end;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendDiskMakeFreeExtent(virStoragePoolObjPtr pool,
|
2008-02-20 15:52:17 +00:00
|
|
|
char **const groups)
|
|
|
|
{
|
|
|
|
virStoragePoolSourceDevicePtr dev = &pool->def->source.devices[0];
|
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_REALLOC_N(dev->freeExtents,
|
|
|
|
dev->nfreeExtent + 1) < 0)
|
2008-02-20 15:52:17 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(dev->freeExtents +
|
2008-06-06 11:09:57 +00:00
|
|
|
dev->nfreeExtent, 0,
|
|
|
|
sizeof(dev->freeExtents[0]));
|
2008-02-20 15:52:17 +00:00
|
|
|
|
2009-06-26 16:18:59 +00:00
|
|
|
/* set type of free area */
|
2010-08-18 20:54:48 +00:00
|
|
|
if (STREQ(groups[1], "logical")) {
|
2009-06-26 16:18:59 +00:00
|
|
|
dev->freeExtents[dev->nfreeExtent].type = VIR_STORAGE_FREE_LOGICAL;
|
|
|
|
} else {
|
|
|
|
dev->freeExtents[dev->nfreeExtent].type = VIR_STORAGE_FREE_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 15:52:17 +00:00
|
|
|
if (virStrToLong_ull(groups[3], NULL, 10,
|
|
|
|
&dev->freeExtents[dev->nfreeExtent].start) < 0)
|
|
|
|
return -1; /* Don't bother to re-alloc freeExtents - it'll be free'd shortly */
|
|
|
|
|
|
|
|
if (virStrToLong_ull(groups[4], NULL, 10,
|
|
|
|
&dev->freeExtents[dev->nfreeExtent].end) < 0)
|
|
|
|
return -1; /* Don't bother to re-alloc freeExtents - it'll be free'd shortly */
|
|
|
|
|
2009-06-26 16:18:59 +00:00
|
|
|
/* first block reported as free, even if it is not */
|
|
|
|
if (dev->freeExtents[dev->nfreeExtent].start == 0) {
|
|
|
|
dev->freeExtents[dev->nfreeExtent].start = SECTOR_SIZE;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:52:17 +00:00
|
|
|
pool->def->available +=
|
|
|
|
(dev->freeExtents[dev->nfreeExtent].end -
|
|
|
|
dev->freeExtents[dev->nfreeExtent].start);
|
|
|
|
if (dev->freeExtents[dev->nfreeExtent].end > pool->def->capacity)
|
|
|
|
pool->def->capacity = dev->freeExtents[dev->nfreeExtent].end;
|
|
|
|
|
|
|
|
dev->nfreeExtent++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendDiskMakeVol(virStoragePoolObjPtr pool,
|
2008-02-20 15:52:17 +00:00
|
|
|
size_t ntok ATTRIBUTE_UNUSED,
|
|
|
|
char **const groups,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Ignore normal+metadata, and logical+metadata partitions
|
|
|
|
* since they're basically internal book-keeping regions
|
|
|
|
* we have no control over. Do keep extended+metadata though
|
|
|
|
* because that's the MS-DOS extended partition region we
|
|
|
|
* need to be able to view/create/delete
|
|
|
|
*/
|
|
|
|
if ((STREQ(groups[1], "normal") ||
|
|
|
|
STREQ(groups[1], "logical")) &&
|
|
|
|
STREQ(groups[2], "metadata"))
|
|
|
|
return 0;
|
|
|
|
|
2008-02-27 10:37:19 +00:00
|
|
|
/* Remaining data / metadata parts get turn into volumes... */
|
2008-02-20 15:52:17 +00:00
|
|
|
if (STREQ(groups[2], "metadata") ||
|
|
|
|
STREQ(groups[2], "data")) {
|
|
|
|
virStorageVolDefPtr vol = data;
|
2009-07-10 01:51:36 +00:00
|
|
|
|
|
|
|
if (vol) {
|
|
|
|
/* We're searching for a specific vol only */
|
|
|
|
if (vol->key) {
|
|
|
|
if (STRNEQ(vol->key, groups[0]))
|
|
|
|
return 0;
|
|
|
|
} else if (virStorageVolDefFindByKey(pool, groups[0]) != NULL) {
|
|
|
|
/* If no key, the volume must be newly created. If groups[0]
|
|
|
|
* isn't already a volume, assume it's the path we want */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 15:52:17 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
return virStorageBackendDiskMakeDataVol(pool, groups, vol);
|
2008-02-20 15:52:17 +00:00
|
|
|
} else if (STREQ(groups[2], "free")) {
|
|
|
|
/* ....or free space extents */
|
2010-02-10 11:42:56 +00:00
|
|
|
return virStorageBackendDiskMakeFreeExtent(pool, groups);
|
2008-02-20 15:52:17 +00:00
|
|
|
} else {
|
2008-02-27 10:37:19 +00:00
|
|
|
/* This code path should never happen unless someone changed
|
2008-02-20 15:52:17 +00:00
|
|
|
* libvirt_parthelper forgot to change this code */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* To get a list of partitions we run an external helper
|
|
|
|
* tool which then uses parted APIs. This is because
|
|
|
|
* parted's API is not compatible with libvirt's license
|
|
|
|
* but we really really want to use parted because the
|
|
|
|
* other options all suck :-)
|
|
|
|
*
|
|
|
|
* All the other storage backends run an external tool for
|
|
|
|
* listing volumes so this really isn't too much of a pain,
|
|
|
|
* and we can even ensure the output is friendly.
|
|
|
|
*/
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool,
|
2008-02-20 15:52:17 +00:00
|
|
|
virStorageVolDefPtr vol)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* # libvirt_parthelper DEVICE
|
|
|
|
* /dev/sda1 normal data 32256 106928128 106896384
|
|
|
|
* /dev/sda2 normal data 106928640 100027629568 99920701440
|
|
|
|
* - normal metadata 100027630080 100030242304 2612736
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
const char *prog[] = {
|
|
|
|
PARTHELPER, pool->def->source.devices[0].path, NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
pool->def->allocation = pool->def->capacity = pool->def->available = 0;
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
return virStorageBackendRunProgNul(pool,
|
2008-02-20 15:52:17 +00:00
|
|
|
prog,
|
|
|
|
6,
|
|
|
|
virStorageBackendDiskMakeVol,
|
|
|
|
vol);
|
|
|
|
}
|
|
|
|
|
2009-06-26 16:18:59 +00:00
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendDiskMakePoolGeometry(virStoragePoolObjPtr pool,
|
|
|
|
size_t ntok ATTRIBUTE_UNUSED,
|
|
|
|
char **const groups,
|
|
|
|
void *data ATTRIBUTE_UNUSED)
|
2009-06-26 16:18:59 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
pool->def->source.devices[0].geometry.cyliders = atoi(groups[0]);
|
|
|
|
pool->def->source.devices[0].geometry.heads = atoi(groups[1]);
|
|
|
|
pool->def->source.devices[0].geometry.sectors = atoi(groups[2]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool)
|
2009-06-26 16:18:59 +00:00
|
|
|
{
|
|
|
|
const char *prog[] = {
|
|
|
|
PARTHELPER, pool->def->source.devices[0].path, "-g", NULL,
|
|
|
|
};
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
return virStorageBackendRunProgNul(pool,
|
2009-06-26 16:18:59 +00:00
|
|
|
prog,
|
|
|
|
3,
|
|
|
|
virStorageBackendDiskMakePoolGeometry,
|
|
|
|
NULL);
|
|
|
|
}
|
2008-02-20 15:52:17 +00:00
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendDiskRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-02-20 15:52:17 +00:00
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(pool->def->source.devices[0].freeExtents);
|
2008-02-20 15:52:17 +00:00
|
|
|
pool->def->source.devices[0].nfreeExtent = 0;
|
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
virFileWaitForDevices();
|
2008-11-28 07:50:20 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageBackendDiskReadGeometry(pool) != 0) {
|
2009-06-26 16:18:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
return virStorageBackendDiskReadPartitions(pool, NULL);
|
2008-02-20 15:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a new partition table header
|
|
|
|
*/
|
|
|
|
static int
|
2010-02-04 22:41:52 +00:00
|
|
|
virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-02-20 15:52:17 +00:00
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/* eg parted /dev/sda mklabel msdos */
|
|
|
|
const char *prog[] = {
|
|
|
|
PARTED,
|
|
|
|
pool->def->source.devices[0].path,
|
|
|
|
"mklabel",
|
2008-08-12 11:29:49 +00:00
|
|
|
"--script",
|
2008-08-13 09:45:10 +00:00
|
|
|
((pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) ? "msdos" :
|
2008-11-17 11:19:33 +00:00
|
|
|
virStoragePoolFormatDiskTypeToString(pool->def->source.format)),
|
2008-02-20 15:52:17 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(prog, NULL) < 0)
|
2008-02-20 15:52:17 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-26 16:18:59 +00:00
|
|
|
/**
|
|
|
|
* Decides what kind of partition type that should be created.
|
|
|
|
* Important when the partition table is of msdos type
|
|
|
|
*/
|
2008-02-20 15:52:17 +00:00
|
|
|
static int
|
2009-06-26 16:18:59 +00:00
|
|
|
virStorageBackendDiskPartTypeToCreate(virStoragePoolObjPtr pool)
|
|
|
|
{
|
|
|
|
if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) {
|
|
|
|
/* count primary and extended paritions,
|
|
|
|
can't be more than 3 to create a new primary partition */
|
|
|
|
int i;
|
|
|
|
int count = 0;
|
|
|
|
for (i = 0; i < pool->volumes.count; i++) {
|
|
|
|
if (pool->volumes.objs[i]->target.type == VIR_STORAGE_VOL_DISK_TYPE_PRIMARY ||
|
|
|
|
pool->volumes.objs[i]->target.type == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count >= 4) {
|
|
|
|
return VIR_STORAGE_VOL_DISK_TYPE_LOGICAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for all other cases, all partitions are primary */
|
|
|
|
return VIR_STORAGE_VOL_DISK_TYPE_PRIMARY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
|
2009-06-26 16:18:59 +00:00
|
|
|
virStorageVolDefPtr vol,
|
2010-08-18 21:54:11 +00:00
|
|
|
char** partFormat)
|
2009-06-26 16:18:59 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) {
|
2010-08-18 20:54:48 +00:00
|
|
|
const char *partedFormat;
|
|
|
|
partedFormat = virStoragePartedFsTypeTypeToString(vol->target.format);
|
|
|
|
if (partedFormat == NULL) {
|
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Invalid partition type"));
|
|
|
|
return -1;
|
2009-06-26 16:18:59 +00:00
|
|
|
}
|
|
|
|
if (vol->target.format == VIR_STORAGE_VOL_DISK_EXTENDED) {
|
|
|
|
/* make sure we don't have a extended partition already */
|
|
|
|
for (i = 0; i < pool->volumes.count; i++) {
|
2010-08-18 20:54:48 +00:00
|
|
|
if (pool->volumes.objs[i]->target.format ==
|
|
|
|
VIR_STORAGE_VOL_DISK_EXTENDED) {
|
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("extended partition already exists"));
|
|
|
|
return -1;
|
|
|
|
}
|
2009-06-26 16:18:59 +00:00
|
|
|
}
|
2010-08-18 21:54:11 +00:00
|
|
|
if ((*partFormat = strdup(partedFormat)) == NULL) {
|
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
2009-06-26 16:18:59 +00:00
|
|
|
} else {
|
|
|
|
/* create primary partition as long as it is possible
|
|
|
|
and after that check if an extended partition exists
|
|
|
|
to create logical partitions. */
|
|
|
|
/* XXX Only support one extended partition */
|
|
|
|
switch (virStorageBackendDiskPartTypeToCreate(pool)) {
|
2010-08-18 20:54:48 +00:00
|
|
|
case VIR_STORAGE_VOL_DISK_TYPE_PRIMARY:
|
2010-08-18 21:54:11 +00:00
|
|
|
if (virAsprintf(partFormat, "primary %s", partedFormat) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
2010-08-18 20:54:48 +00:00
|
|
|
break;
|
|
|
|
case VIR_STORAGE_VOL_DISK_TYPE_LOGICAL:
|
|
|
|
/* make sure we have a extended partition */
|
|
|
|
for (i = 0; i < pool->volumes.count; i++) {
|
|
|
|
if (pool->volumes.objs[i]->target.format ==
|
|
|
|
VIR_STORAGE_VOL_DISK_EXTENDED) {
|
2010-08-18 21:54:11 +00:00
|
|
|
if (virAsprintf(partFormat, "logical %s",
|
|
|
|
partedFormat) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
2010-08-18 20:54:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == pool->volumes.count) {
|
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("no extended partition found and no primary partition available"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2010-08-18 21:54:11 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("unknown partition type"));
|
|
|
|
return -1;
|
2009-06-26 16:18:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-08-18 21:54:11 +00:00
|
|
|
if ((*partFormat = strdup("primary")) == NULL) {
|
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
2009-06-26 16:18:59 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Aligns a new partition to nearest cylinder boundry
|
2010-08-18 20:54:48 +00:00
|
|
|
* when having a msdos partition table type
|
2009-06-26 16:18:59 +00:00
|
|
|
* to avoid any problem with all ready existing
|
|
|
|
* partitions
|
|
|
|
*/
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendDiskPartBoundries(virStoragePoolObjPtr pool,
|
2009-06-26 16:18:59 +00:00
|
|
|
unsigned long long *start,
|
|
|
|
unsigned long long *end,
|
|
|
|
unsigned long long allocation)
|
2008-02-20 15:52:17 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int smallestExtent = -1;
|
2009-06-26 16:18:59 +00:00
|
|
|
unsigned long long smallestSize = 0;
|
|
|
|
unsigned long long extraBytes = 0;
|
|
|
|
unsigned long long alignedAllocation = allocation;
|
2008-02-20 15:52:17 +00:00
|
|
|
virStoragePoolSourceDevicePtr dev = &pool->def->source.devices[0];
|
2009-06-26 16:18:59 +00:00
|
|
|
unsigned long long cylinderSize = dev->geometry.heads *
|
|
|
|
dev->geometry.sectors * SECTOR_SIZE;
|
|
|
|
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("find free area: allocation %llu, cyl size %llu", allocation,
|
2010-08-18 20:54:48 +00:00
|
|
|
cylinderSize);
|
2009-06-26 16:18:59 +00:00
|
|
|
int partType = virStorageBackendDiskPartTypeToCreate(pool);
|
|
|
|
|
|
|
|
/* how many extra bytes we have since we allocate
|
|
|
|
aligned to the cylinder boundry */
|
|
|
|
extraBytes = cylinderSize - (allocation % cylinderSize);
|
|
|
|
|
|
|
|
for (i = 0 ; i < dev->nfreeExtent ; i++) {
|
|
|
|
unsigned long long size =
|
|
|
|
dev->freeExtents[i].end -
|
|
|
|
dev->freeExtents[i].start;
|
|
|
|
unsigned long long neededSize = allocation;
|
|
|
|
|
|
|
|
if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) {
|
|
|
|
/* align to cylinder boundry */
|
|
|
|
neededSize += extraBytes;
|
|
|
|
if ((*start % cylinderSize) > extraBytes) {
|
|
|
|
/* add an extra cylinder if the offset can't fit within
|
|
|
|
the extra bytes we have */
|
|
|
|
neededSize += cylinderSize;
|
|
|
|
}
|
|
|
|
/* if we are creating a logical patition, we need one extra
|
|
|
|
block between partitions (or actually move start one block) */
|
|
|
|
if (partType == VIR_STORAGE_VOL_DISK_TYPE_LOGICAL) {
|
|
|
|
size -= SECTOR_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (size > neededSize &&
|
|
|
|
(smallestSize == 0 ||
|
|
|
|
size < smallestSize)) {
|
|
|
|
/* for logical partition, the free extent
|
|
|
|
must be within a logical free area */
|
|
|
|
if (partType == VIR_STORAGE_VOL_DISK_TYPE_LOGICAL &&
|
|
|
|
dev->freeExtents[i].type != VIR_STORAGE_FREE_LOGICAL) {
|
|
|
|
continue;
|
|
|
|
/* for primary partition, the free extent
|
|
|
|
must not be within a logical free area */
|
2010-08-18 20:54:48 +00:00
|
|
|
} else if (partType == VIR_STORAGE_VOL_DISK_TYPE_PRIMARY &&
|
|
|
|
dev->freeExtents[i].type != VIR_STORAGE_FREE_NORMAL) {
|
|
|
|
continue;
|
2009-06-26 16:18:59 +00:00
|
|
|
}
|
|
|
|
smallestSize = size;
|
|
|
|
smallestExtent = i;
|
|
|
|
alignedAllocation = neededSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (smallestExtent == -1) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2009-06-26 16:18:59 +00:00
|
|
|
"%s", _("no large enough free extent"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("aligned alloc %llu", alignedAllocation);
|
2009-06-26 16:18:59 +00:00
|
|
|
*start = dev->freeExtents[smallestExtent].start;
|
|
|
|
|
|
|
|
if (partType == VIR_STORAGE_VOL_DISK_TYPE_LOGICAL) {
|
|
|
|
/* for logical partition, skip one block */
|
|
|
|
*start += SECTOR_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*end = *start + alignedAllocation;
|
|
|
|
if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) {
|
|
|
|
/* adjust our allocation if start is not at a cylinder boundry */
|
|
|
|
*end -= (*start % cylinderSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* counting in byte, we want the last byte of the current sector */
|
|
|
|
*end -= 1;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("final aligned start %llu, end %llu", *start, *end);
|
2009-06-26 16:18:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2009-06-26 16:18:59 +00:00
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
virStorageVolDefPtr vol)
|
|
|
|
{
|
2010-08-18 21:54:11 +00:00
|
|
|
int res = -1;
|
|
|
|
char *start = NULL;
|
|
|
|
char *end = NULL;
|
|
|
|
char *partFormat;
|
2009-06-26 16:18:59 +00:00
|
|
|
unsigned long long startOffset = 0, endOffset = 0;
|
2008-02-20 15:52:17 +00:00
|
|
|
const char *cmdargv[] = {
|
|
|
|
PARTED,
|
|
|
|
pool->def->source.devices[0].path,
|
|
|
|
"mkpart",
|
|
|
|
"--script",
|
2010-08-18 21:54:11 +00:00
|
|
|
NULL /*partFormat*/,
|
|
|
|
NULL /*start*/,
|
|
|
|
NULL /*end*/,
|
2008-02-20 15:52:17 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-07-21 02:40:50 +00:00
|
|
|
if (vol->target.encryption != NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_NO_SUPPORT,
|
2009-07-21 02:40:50 +00:00
|
|
|
"%s", _("storage pool does not support encrypted "
|
|
|
|
"volumes"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-08-18 21:54:11 +00:00
|
|
|
if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) != 0) {
|
2009-06-26 16:18:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-08-18 21:54:11 +00:00
|
|
|
cmdargv[4] = partFormat;
|
2009-06-26 16:18:59 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageBackendDiskPartBoundries(pool, &startOffset,
|
2009-07-10 01:51:36 +00:00
|
|
|
&endOffset,
|
2009-07-10 13:05:20 +00:00
|
|
|
vol->capacity) != 0) {
|
2010-08-18 21:54:11 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:52:17 +00:00
|
|
|
}
|
|
|
|
|
2010-08-18 21:54:11 +00:00
|
|
|
if (virAsprintf(&start, "%lluB", startOffset) < 0 ||
|
|
|
|
virAsprintf(&end, "%lluB", endOffset) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
cmdargv[5] = start;
|
|
|
|
cmdargv[6] = end;
|
2008-02-20 15:52:17 +00:00
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(cmdargv, NULL) < 0)
|
2010-08-18 21:54:11 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:52:17 +00:00
|
|
|
|
2009-06-26 16:18:59 +00:00
|
|
|
/* wait for device node to show up */
|
2010-02-04 22:41:52 +00:00
|
|
|
virFileWaitForDevices();
|
2009-06-26 16:18:59 +00:00
|
|
|
|
2008-02-20 15:52:17 +00:00
|
|
|
/* Blow away free extent info, as we're about to re-populate it */
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(pool->def->source.devices[0].freeExtents);
|
2008-02-20 15:52:17 +00:00
|
|
|
pool->def->source.devices[0].nfreeExtent = 0;
|
|
|
|
|
2009-07-10 01:51:36 +00:00
|
|
|
/* Specifying a target path is meaningless */
|
|
|
|
VIR_FREE(vol->target.path);
|
|
|
|
|
|
|
|
/* Fetch actual extent info, generate key */
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageBackendDiskReadPartitions(pool, vol) < 0)
|
2010-08-18 21:54:11 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:52:17 +00:00
|
|
|
|
2010-08-18 21:54:11 +00:00
|
|
|
res = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(partFormat);
|
|
|
|
VIR_FREE(start);
|
|
|
|
VIR_FREE(end);
|
|
|
|
return res;
|
2008-02-20 15:52:17 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 23:17:31 +00:00
|
|
|
static int
|
|
|
|
virStorageBackendDiskBuildVolFrom(virConnectPtr conn,
|
2010-01-20 23:41:52 +00:00
|
|
|
virStoragePoolObjPtr pool,
|
2009-07-09 23:17:31 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
virStorageVolDefPtr inputvol,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virStorageBackendBuildVolFrom build_func;
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
build_func = virStorageBackendGetBuildVolFromFunction(vol, inputvol);
|
2009-07-09 23:17:31 +00:00
|
|
|
if (!build_func)
|
|
|
|
return -1;
|
|
|
|
|
2010-01-20 23:41:52 +00:00
|
|
|
return build_func(conn, pool, vol, inputvol, flags);
|
2009-07-09 23:17:31 +00:00
|
|
|
}
|
2008-02-20 15:52:17 +00:00
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendDiskDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-09-16 16:46:08 +00:00
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
virStorageVolDefPtr vol,
|
2008-02-20 15:52:17 +00:00
|
|
|
unsigned int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2008-09-16 16:46:08 +00:00
|
|
|
char *part_num = NULL;
|
2009-04-01 10:26:22 +00:00
|
|
|
char *devpath = NULL;
|
2008-09-16 16:46:08 +00:00
|
|
|
char *devname, *srcname;
|
2011-02-17 07:29:07 +00:00
|
|
|
virCommandPtr cmd = NULL;
|
|
|
|
bool isDevMapperDevice;
|
2009-04-01 10:26:22 +00:00
|
|
|
int rc = -1;
|
2008-09-16 16:46:08 +00:00
|
|
|
|
2010-05-14 20:50:27 +00:00
|
|
|
if (virFileResolveLink(vol->target.path, &devpath) < 0) {
|
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("Couldn't read volume target path '%s'"),
|
|
|
|
vol->target.path);
|
2009-04-01 10:26:22 +00:00
|
|
|
goto cleanup;
|
2008-09-16 16:46:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
devname = basename(devpath);
|
|
|
|
srcname = basename(pool->def->source.devices[0].path);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("devname=%s, srcname=%s", devname, srcname);
|
2008-09-16 16:46:08 +00:00
|
|
|
|
2011-02-17 07:29:07 +00:00
|
|
|
isDevMapperDevice = virIsDevMapperDevice(devpath);
|
|
|
|
|
|
|
|
if (!isDevMapperDevice && !STRPREFIX(devname, srcname)) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-09-16 16:46:08 +00:00
|
|
|
_("Volume path '%s' did not start with parent "
|
|
|
|
"pool source device name."), devname);
|
2009-04-01 10:26:22 +00:00
|
|
|
goto cleanup;
|
2008-09-16 16:46:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-17 07:29:07 +00:00
|
|
|
if (!isDevMapperDevice) {
|
|
|
|
part_num = devname + strlen(srcname);
|
2008-09-16 16:46:08 +00:00
|
|
|
|
2011-02-17 07:29:07 +00:00
|
|
|
if (*part_num == 0) {
|
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot parse partition number from target "
|
|
|
|
"'%s'"), devname);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-09-16 16:46:08 +00:00
|
|
|
|
2011-02-17 07:29:07 +00:00
|
|
|
/* eg parted /dev/sda rm 2 */
|
|
|
|
cmd = virCommandNewArgList(PARTED,
|
|
|
|
pool->def->source.devices[0].path,
|
|
|
|
"rm",
|
|
|
|
"--script",
|
|
|
|
part_num,
|
|
|
|
NULL);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
cmd = virCommandNewArgList(DMSETUP, "remove", "--force", devpath, NULL);
|
2008-09-16 16:46:08 +00:00
|
|
|
|
2011-02-17 07:29:07 +00:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-09-16 16:46:08 +00:00
|
|
|
|
2009-04-01 10:26:22 +00:00
|
|
|
rc = 0;
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(devpath);
|
2011-02-17 07:29:07 +00:00
|
|
|
virCommandFree(cmd);
|
2009-04-01 10:26:22 +00:00
|
|
|
return rc;
|
2008-02-20 15:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virStorageBackend virStorageBackendDisk = {
|
|
|
|
.type = VIR_STORAGE_POOL_DISK,
|
|
|
|
|
|
|
|
.buildPool = virStorageBackendDiskBuildPool,
|
|
|
|
.refreshPool = virStorageBackendDiskRefreshPool,
|
|
|
|
|
|
|
|
.createVol = virStorageBackendDiskCreateVol,
|
|
|
|
.deleteVol = virStorageBackendDiskDeleteVol,
|
2009-07-09 23:17:31 +00:00
|
|
|
.buildVolFrom = virStorageBackendDiskBuildVolFrom,
|
2008-02-20 15:52:17 +00:00
|
|
|
};
|