2008-02-20 15:45:33 +00:00
|
|
|
/*
|
|
|
|
* storage_backend_logvol.c: storage backend for logical volume handling
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2008 Red Hat, Inc.
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
Standardize use of header files, making internal.h primary.
* qemud/internal.h, qemud/qemud.h: Rename this file so it
doesn't conflict with src/internal.h.
* HACKING: Document how header files should be used.
* qemud/Makefile.am: Add src/ directory to includes.
* qemud/event.c, qemud/mdns.c, qemud/qemud.c, qemud/remote.c,
qemud/remote_protocol.c, qemud/remote_protocol.h,
qemud/remote_protocol.x, src/buf.c, src/libvirt.c,
src/nodeinfo.c, src/qemu_conf.c, src/qemu_driver.c,
src/stats_linux.c, src/storage_backend.c, src/storage_backend_fs.c,
src/storage_backend_iscsi.c, src/storage_backend_logical.c,
src/storage_conf.c, src/storage_driver.c, src/util.c,
src/util.h, src/virsh.c, src/virterror.c, src/xend_internal.c,
src/xml.c, tests/reconnect.c, tests/xmlrpctest.c,
tests/qparamtest.c: Standardize use of header files.
* docs/*, po/*: Rebuild docs.
2008-05-23 08:24:41 +00:00
|
|
|
#include "internal.h"
|
2008-02-20 15:45:33 +00:00
|
|
|
#include "storage_backend_logical.h"
|
|
|
|
#include "storage_conf.h"
|
|
|
|
#include "util.h"
|
2008-06-06 11:09:57 +00:00
|
|
|
#include "memory.h"
|
2008-02-20 15:45:33 +00:00
|
|
|
|
|
|
|
#define PV_BLANK_SECTOR_SIZE 512
|
|
|
|
|
|
|
|
enum {
|
|
|
|
VIR_STORAGE_POOL_LOGICAL_LVM2 = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalPoolFormatFromString(virConnectPtr conn,
|
|
|
|
const char *format) {
|
|
|
|
if (format == NULL)
|
|
|
|
return VIR_STORAGE_POOL_LOGICAL_LVM2;
|
|
|
|
|
|
|
|
if (STREQ(format, "lvm2"))
|
|
|
|
return VIR_STORAGE_POOL_LOGICAL_LVM2;
|
|
|
|
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unsupported pool format %s"), format);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
virStorageBackendLogicalPoolFormatToString(virConnectPtr conn,
|
|
|
|
int format) {
|
|
|
|
switch (format) {
|
|
|
|
case VIR_STORAGE_POOL_LOGICAL_LVM2:
|
|
|
|
return "lvm2";
|
|
|
|
}
|
|
|
|
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unsupported pool format %d"), format);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalSetActive(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
int on)
|
|
|
|
{
|
|
|
|
const char *cmdargv[4];
|
|
|
|
|
|
|
|
cmdargv[0] = VGCHANGE;
|
|
|
|
cmdargv[1] = on ? "-ay" : "-an";
|
2008-09-02 14:15:42 +00:00
|
|
|
cmdargv[2] = pool->def->source.name;
|
2008-02-20 15:45:33 +00:00
|
|
|
cmdargv[3] = NULL;
|
|
|
|
|
2008-08-08 15:43:38 +00:00
|
|
|
if (virRun(conn, cmdargv, NULL) < 0)
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalMakeVol(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
char **const groups,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
virStorageVolDefPtr vol = NULL;
|
|
|
|
unsigned long long offset, size, length;
|
|
|
|
|
|
|
|
/* See if we're only looking for a specific volume */
|
|
|
|
if (data != NULL) {
|
|
|
|
vol = data;
|
|
|
|
if (STRNEQ(vol->name, groups[0]))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Or filling in more data on an existing volume */
|
|
|
|
if (vol == NULL)
|
|
|
|
vol = virStorageVolDefFindByName(pool, groups[0]);
|
|
|
|
|
|
|
|
/* Or a completely new volume */
|
|
|
|
if (vol == NULL) {
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(vol) < 0) {
|
2008-02-22 16:26:13 +00:00
|
|
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vol->name = strdup(groups[0])) == NULL) {
|
2008-02-22 16:26:13 +00:00
|
|
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
2008-10-10 15:13:28 +00:00
|
|
|
virStorageVolDefFree(vol);
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-10-10 15:13:28 +00:00
|
|
|
if (VIR_REALLOC_N(pool->volumes.objs,
|
|
|
|
pool->volumes.count + 1)) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, NULL);
|
|
|
|
virStorageVolDefFree(vol);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
pool->volumes.objs[pool->volumes.count++] = vol;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vol->target.path == NULL) {
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
|
|
|
|
1 + strlen(vol->name) + 1) < 0) {
|
2008-02-22 16:26:13 +00:00
|
|
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
strcpy(vol->target.path, pool->def->target.path);
|
|
|
|
strcat(vol->target.path, "/");
|
|
|
|
strcat(vol->target.path, vol->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vol->key == NULL &&
|
|
|
|
(vol->key = strdup(groups[1])) == NULL) {
|
2008-02-22 16:26:13 +00:00
|
|
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStorageBackendUpdateVolInfo(conn, vol, 1) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Finally fill in extents information */
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_REALLOC_N(vol->source.extents,
|
|
|
|
vol->source.nextent + 1) < 0) {
|
2008-02-22 16:26:13 +00:00
|
|
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("extents"));
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vol->source.extents[vol->source.nextent].path =
|
|
|
|
strdup(groups[2])) == NULL) {
|
2008-02-22 16:26:13 +00:00
|
|
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("extents"));
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStrToLong_ull(groups[3], NULL, 10, &offset) < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("malformed volume extent offset value"));
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (virStrToLong_ull(groups[4], NULL, 10, &length) < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("malformed volume extent length value"));
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (virStrToLong_ull(groups[5], NULL, 10, &size) < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("malformed volume extent size value"));
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vol->source.extents[vol->source.nextent].start = offset * size;
|
|
|
|
vol->source.extents[vol->source.nextent].end = (offset * size) + length;
|
|
|
|
vol->source.nextent++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalFindLVs(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
virStorageVolDefPtr vol)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* # lvs --separator : --noheadings --units b --unbuffered --nosuffix --options "lv_name,uuid,devices,seg_size,vg_extent_size" VGNAME
|
|
|
|
* RootLV:06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky:/dev/hda2(0):5234491392:33554432
|
|
|
|
* SwapLV:oHviCK-8Ik0-paqS-V20c-nkhY-Bm1e-zgzU0M:/dev/hda2(156):1040187392:33554432
|
|
|
|
* Test2:3pg3he-mQsA-5Sui-h0i6-HNmc-Cz7W-QSndcR:/dev/hda2(219):1073741824:33554432
|
|
|
|
* Test3:UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht:/dev/hda2(251):2181038080:33554432
|
|
|
|
* Test3:UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht:/dev/hda2(187):1040187392:33554432
|
|
|
|
*
|
|
|
|
* Pull out name & uuid, device, device extent start #, segment size, extent size.
|
|
|
|
*
|
|
|
|
* NB can be multiple rows per volume if they have many extents
|
2008-07-30 08:52:44 +00:00
|
|
|
*
|
|
|
|
* NB lvs from some distros (e.g. SLES10 SP2) outputs trailing ":" on each line
|
2008-02-20 15:45:33 +00:00
|
|
|
*/
|
|
|
|
const char *regexes[] = {
|
2008-07-30 08:52:44 +00:00
|
|
|
"^\\s*(\\S+):(\\S+):(\\S+)\\((\\S+)\\):(\\S+):([0-9]+):?\\s*$"
|
2008-02-20 15:45:33 +00:00
|
|
|
};
|
|
|
|
int vars[] = {
|
|
|
|
6
|
|
|
|
};
|
|
|
|
const char *prog[] = {
|
|
|
|
LVS, "--separator", ":", "--noheadings", "--units", "b",
|
|
|
|
"--unbuffered", "--nosuffix", "--options",
|
|
|
|
"lv_name,uuid,devices,seg_size,vg_extent_size",
|
2008-09-02 14:15:42 +00:00
|
|
|
pool->def->source.name, NULL
|
2008-02-20 15:45:33 +00:00
|
|
|
};
|
|
|
|
|
2008-06-17 12:45:24 +00:00
|
|
|
int exitstatus;
|
|
|
|
|
|
|
|
if (virStorageBackendRunProgRegex(conn,
|
|
|
|
pool,
|
|
|
|
prog,
|
|
|
|
1,
|
|
|
|
regexes,
|
|
|
|
vars,
|
|
|
|
virStorageBackendLogicalMakeVol,
|
|
|
|
vol,
|
|
|
|
&exitstatus) < 0) {
|
|
|
|
virStorageReportError(conn, 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", _("lvs command failed"));
|
2008-06-17 12:45:24 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exitstatus != 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("lvs command failed with exitstatus %d"),
|
|
|
|
exitstatus);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalRefreshPoolFunc(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
|
|
|
char **const groups,
|
|
|
|
void *data ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
if (virStrToLong_ull(groups[0], NULL, 10, &pool->def->capacity) < 0)
|
|
|
|
return -1;
|
|
|
|
if (virStrToLong_ull(groups[1], NULL, 10, &pool->def->available) < 0)
|
|
|
|
return -1;
|
|
|
|
pool->def->allocation = pool->def->capacity - pool->def->available;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-27 20:05:58 +00:00
|
|
|
static int
|
|
|
|
virStorageBackendLogicalFindPoolSourcesFunc(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
|
|
|
char **const groups,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
virStringList **rest = data;
|
|
|
|
virStringList *newItem;
|
|
|
|
const char *name = groups[0];
|
|
|
|
|
|
|
|
/* Append new XML desc to list */
|
|
|
|
|
|
|
|
if (VIR_ALLOC(newItem) != 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("new xml desc"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asprintf(&newItem->val, "<source><name>%s</name></source>", name) <= 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", _("asprintf failed"));
|
|
|
|
VIR_FREE(newItem);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
newItem->len = strlen(newItem->val);
|
|
|
|
newItem->next = *rest;
|
|
|
|
*rest = newItem;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
virStorageBackendLogicalFindPoolSources(virConnectPtr conn,
|
|
|
|
const char *srcSpec ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/*
|
2008-09-22 20:22:35 +00:00
|
|
|
* # vgs --noheadings -o vg_name
|
2008-08-27 20:05:58 +00:00
|
|
|
* VolGroup00
|
|
|
|
* VolGroup01
|
|
|
|
*/
|
|
|
|
const char *regexes[] = {
|
|
|
|
"^\\s*(\\S+)\\s*$"
|
|
|
|
};
|
|
|
|
int vars[] = {
|
|
|
|
1
|
|
|
|
};
|
|
|
|
virStringList *descs = NULL;
|
|
|
|
const char *prog[] = { VGS, "--noheadings", "-o", "vg_name", NULL };
|
|
|
|
int exitstatus;
|
|
|
|
char *retval = NULL;
|
|
|
|
|
|
|
|
if (virStorageBackendRunProgRegex(conn, NULL, prog, 1, regexes, vars,
|
|
|
|
virStorageBackendLogicalFindPoolSourcesFunc,
|
|
|
|
&descs, &exitstatus) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
retval = virStringListJoin(descs, SOURCES_START_TAG, SOURCES_END_TAG, "\n");
|
|
|
|
if (retval == NULL) {
|
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
|
|
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("retval"));
|
2008-08-27 20:05:58 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virStringListFree(descs);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 15:45:33 +00:00
|
|
|
static int
|
|
|
|
virStorageBackendLogicalStartPool(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
|
|
|
if (virStorageBackendLogicalSetActive(conn, pool, 1) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalBuildPool(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
const char **vgargv;
|
|
|
|
const char *pvargv[3];
|
|
|
|
int n = 0, i, fd;
|
|
|
|
char zeros[PV_BLANK_SECTOR_SIZE];
|
|
|
|
|
|
|
|
memset(zeros, 0, sizeof(zeros));
|
|
|
|
|
2008-09-04 13:13:32 +00:00
|
|
|
if (VIR_ALLOC_N(vgargv, 3 + pool->def->source.ndevice) < 0) {
|
2008-02-22 16:26:13 +00:00
|
|
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("command line"));
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vgargv[n++] = VGCREATE;
|
2008-09-02 14:15:42 +00:00
|
|
|
vgargv[n++] = pool->def->source.name;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
|
|
|
pvargv[0] = PVCREATE;
|
|
|
|
pvargv[2] = NULL;
|
|
|
|
for (i = 0 ; i < pool->def->source.ndevice ; i++) {
|
|
|
|
/*
|
|
|
|
* LVM requires that the first sector is blanked if using
|
|
|
|
* a whole disk as a PV. So we just blank them out regardless
|
|
|
|
* rather than trying to figure out if we're a disk or partition
|
|
|
|
*/
|
|
|
|
if ((fd = open(pool->def->source.devices[i].path, O_WRONLY)) < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot open device %s"),
|
|
|
|
strerror(errno));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-02-25 10:00:16 +00:00
|
|
|
if (safewrite(fd, zeros, sizeof(zeros)) < 0) {
|
2008-02-20 15:45:33 +00:00
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot clear device header %s"),
|
|
|
|
strerror(errno));
|
|
|
|
close(fd);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (close(fd) < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot close device %s"),
|
|
|
|
strerror(errno));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the physical volume because vgcreate is not
|
|
|
|
* clever enough todo this for us :-(
|
|
|
|
*/
|
|
|
|
vgargv[n++] = pool->def->source.devices[i].path;
|
|
|
|
pvargv[1] = pool->def->source.devices[i].path;
|
2008-08-08 15:43:38 +00:00
|
|
|
if (virRun(conn, pvargv, NULL) < 0)
|
2008-02-20 15:45:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vgargv[n++] = NULL;
|
|
|
|
|
|
|
|
/* Now create the volume group itself */
|
2008-08-08 15:43:38 +00:00
|
|
|
if (virRun(conn, vgargv, NULL) < 0)
|
2008-02-20 15:45:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(vgargv);
|
2008-02-20 15:45:33 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(vgargv);
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalRefreshPool(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* # vgs --separator : --noheadings --units b --unbuffered --nosuffix --options "vg_size,vg_free" VGNAME
|
|
|
|
* 10603200512:4328521728
|
|
|
|
*
|
|
|
|
* Pull out size & free
|
2008-07-30 08:52:44 +00:00
|
|
|
*
|
|
|
|
* NB vgs from some distros (e.g. SLES10 SP2) outputs trailing ":" on each line
|
2008-02-20 15:45:33 +00:00
|
|
|
*/
|
|
|
|
const char *regexes[] = {
|
2008-07-30 08:52:44 +00:00
|
|
|
"^\\s*(\\S+):([0-9]+):?\\s*$"
|
2008-02-20 15:45:33 +00:00
|
|
|
};
|
|
|
|
int vars[] = {
|
|
|
|
2
|
|
|
|
};
|
|
|
|
const char *prog[] = {
|
|
|
|
VGS, "--separator", ":", "--noheadings", "--units", "b", "--unbuffered",
|
|
|
|
"--nosuffix", "--options", "vg_size,vg_free",
|
2008-09-02 14:15:42 +00:00
|
|
|
pool->def->source.name, NULL
|
2008-02-20 15:45:33 +00:00
|
|
|
};
|
2008-06-17 12:45:24 +00:00
|
|
|
int exitstatus;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
|
|
|
/* Get list of all logical volumes */
|
|
|
|
if (virStorageBackendLogicalFindLVs(conn, pool, NULL) < 0) {
|
|
|
|
virStoragePoolObjClearVols(pool);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now get basic volgrp metadata */
|
|
|
|
if (virStorageBackendRunProgRegex(conn,
|
|
|
|
pool,
|
|
|
|
prog,
|
|
|
|
1,
|
|
|
|
regexes,
|
|
|
|
vars,
|
|
|
|
virStorageBackendLogicalRefreshPoolFunc,
|
2008-06-17 12:45:24 +00:00
|
|
|
NULL,
|
|
|
|
&exitstatus) < 0) {
|
|
|
|
virStoragePoolObjClearVols(pool);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exitstatus != 0) {
|
2008-02-20 15:45:33 +00:00
|
|
|
virStoragePoolObjClearVols(pool);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-22 20:22:35 +00:00
|
|
|
/*
|
|
|
|
* This is actually relatively safe; if you happen to try to "stop" the
|
|
|
|
* pool that your / is on, for instance, you will get failure like:
|
|
|
|
* "Can't deactivate volume group "VolGroup00" with 3 open logical volume(s)"
|
2008-02-20 15:45:33 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalStopPool(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
|
|
|
if (virStorageBackendLogicalSetActive(conn, pool, 0) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalDeletePool(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
const char *cmdargv[] = {
|
2008-09-23 20:48:49 +00:00
|
|
|
VGREMOVE, "-f", pool->def->source.name, NULL
|
2008-02-20 15:45:33 +00:00
|
|
|
};
|
2008-09-22 20:22:35 +00:00
|
|
|
const char *pvargv[3];
|
|
|
|
int i, error;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2008-09-22 20:22:35 +00:00
|
|
|
/* first remove the volume group */
|
2008-08-08 15:43:38 +00:00
|
|
|
if (virRun(conn, cmdargv, NULL) < 0)
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
|
2008-09-22 20:22:35 +00:00
|
|
|
/* now remove the pv devices and clear them out */
|
|
|
|
error = 0;
|
|
|
|
pvargv[0] = PVREMOVE;
|
|
|
|
pvargv[2] = NULL;
|
|
|
|
for (i = 0 ; i < pool->def->source.ndevice ; i++) {
|
|
|
|
pvargv[1] = pool->def->source.devices[i].path;
|
|
|
|
if (virRun(conn, pvargv, NULL) < 0) {
|
|
|
|
error = -1;
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot remove PV device %s: %s"),
|
|
|
|
pool->def->source.devices[i].path,
|
|
|
|
strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2008-09-22 20:22:35 +00:00
|
|
|
return error;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalDeleteVol(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
unsigned int flags);
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalCreateVol(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
virStorageVolDefPtr vol)
|
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
char size[100];
|
|
|
|
const char *cmdargv[] = {
|
|
|
|
LVCREATE, "--name", vol->name, "-L", size,
|
|
|
|
pool->def->target.path, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
snprintf(size, sizeof(size)-1, "%lluK", vol->capacity/1024);
|
|
|
|
size[sizeof(size)-1] = '\0';
|
|
|
|
|
2008-08-20 13:33:01 +00:00
|
|
|
if (vol->target.path != NULL) {
|
|
|
|
/* A target path passed to CreateVol has no meaning */
|
|
|
|
VIR_FREE(vol->target.path);
|
|
|
|
}
|
|
|
|
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
|
|
|
|
1 + strlen(vol->name) + 1) < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
strcpy(vol->target.path, pool->def->target.path);
|
|
|
|
strcat(vol->target.path, "/");
|
|
|
|
strcat(vol->target.path, vol->name);
|
|
|
|
|
2008-08-08 15:43:38 +00:00
|
|
|
if (virRun(conn, cmdargv, NULL) < 0)
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot read path '%s': %s"),
|
|
|
|
vol->target.path, strerror(errno));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can only chown/grp if root */
|
|
|
|
if (getuid() == 0) {
|
|
|
|
if (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot set file owner '%s': %s"),
|
|
|
|
vol->target.path, strerror(errno));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fchmod(fd, vol->target.perms.mode) < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot set file mode '%s': %s"),
|
|
|
|
vol->target.path, strerror(errno));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (close(fd) < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot close file '%s': %s"),
|
|
|
|
vol->target.path, strerror(errno));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
fd = -1;
|
|
|
|
|
|
|
|
/* Fill in data about this new vol */
|
|
|
|
if (virStorageBackendLogicalFindLVs(conn, pool, vol) < 0) {
|
|
|
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot find newly created volume '%s': %s"),
|
|
|
|
vol->target.path, strerror(errno));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (fd != -1)
|
|
|
|
close(fd);
|
|
|
|
virStorageBackendLogicalDeleteVol(conn, pool, vol, 0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendLogicalDeleteVol(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
const char *cmdargv[] = {
|
|
|
|
LVREMOVE, "-f", vol->target.path, NULL
|
|
|
|
};
|
|
|
|
|
2008-08-08 15:43:38 +00:00
|
|
|
if (virRun(conn, cmdargv, NULL) < 0)
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virStorageBackend virStorageBackendLogical = {
|
|
|
|
.type = VIR_STORAGE_POOL_LOGICAL,
|
|
|
|
|
2008-08-27 20:05:58 +00:00
|
|
|
.findPoolSources = virStorageBackendLogicalFindPoolSources,
|
2008-02-20 15:45:33 +00:00
|
|
|
.startPool = virStorageBackendLogicalStartPool,
|
|
|
|
.buildPool = virStorageBackendLogicalBuildPool,
|
|
|
|
.refreshPool = virStorageBackendLogicalRefreshPool,
|
|
|
|
.stopPool = virStorageBackendLogicalStopPool,
|
|
|
|
.deletePool = virStorageBackendLogicalDeletePool,
|
|
|
|
.createVol = virStorageBackendLogicalCreateVol,
|
|
|
|
.deleteVol = virStorageBackendLogicalDeleteVol,
|
|
|
|
|
|
|
|
.poolOptions = {
|
2008-09-08 08:03:54 +00:00
|
|
|
.flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_NAME |
|
|
|
|
VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE),
|
2008-02-20 15:45:33 +00:00
|
|
|
.formatFromString = virStorageBackendLogicalPoolFormatFromString,
|
|
|
|
.formatToString = virStorageBackendLogicalPoolFormatToString,
|
|
|
|
},
|
|
|
|
|
|
|
|
.volType = VIR_STORAGE_VOL_BLOCK,
|
|
|
|
};
|