mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-02 04:15:46 +00:00
Make logical pools independent on target path
When using logical pools, we had to trust the target->path provided. This parameter, however, can be completely ommited and we can use '/dev/<source.name>' safely and populate it to target.path. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=952973
This commit is contained in:
parent
9e45b3dfe3
commit
efab27afbf
@ -62,7 +62,7 @@
|
|||||||
<ref name='commonmetadata'/>
|
<ref name='commonmetadata'/>
|
||||||
<ref name='sizing'/>
|
<ref name='sizing'/>
|
||||||
<ref name='sourcelogical'/>
|
<ref name='sourcelogical'/>
|
||||||
<ref name='target'/>
|
<ref name='targetlogical'/>
|
||||||
</define>
|
</define>
|
||||||
|
|
||||||
<define name='pooldisk'>
|
<define name='pooldisk'>
|
||||||
@ -207,6 +207,17 @@
|
|||||||
</element>
|
</element>
|
||||||
</define>
|
</define>
|
||||||
|
|
||||||
|
<define name='targetlogical'>
|
||||||
|
<element name='target'>
|
||||||
|
<optional>
|
||||||
|
<element name='path'>
|
||||||
|
<ref name='absFilePath'/>
|
||||||
|
</element>
|
||||||
|
</optional>
|
||||||
|
<ref name='permissions'/>
|
||||||
|
</element>
|
||||||
|
</define>
|
||||||
|
|
||||||
<define name='sourceinfohost'>
|
<define name='sourceinfohost'>
|
||||||
<oneOrMore>
|
<oneOrMore>
|
||||||
<element name='host'>
|
<element name='host'>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* storage_conf.c: config handling for storage driver
|
* storage_conf.c: config handling for storage driver
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2012 Red Hat, Inc.
|
* Copyright (C) 2006-2013 Red Hat, Inc.
|
||||||
* Copyright (C) 2006-2008 Daniel P. Berrange
|
* Copyright (C) 2006-2008 Daniel P. Berrange
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
@ -956,11 +956,18 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
/* When we are working with a virtual disk we can skip the target
|
/* When we are working with a virtual disk we can skip the target
|
||||||
* path and permissions */
|
* path and permissions */
|
||||||
if (!(options->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)) {
|
if (!(options->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)) {
|
||||||
if (!(target_path = virXPathString("string(./target/path)", ctxt))) {
|
if (ret->type == VIR_STORAGE_POOL_LOGICAL) {
|
||||||
|
if (virAsprintf(&target_path, "/dev/%s", ret->source.name) < 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
target_path = virXPathString("string(./target/path)", ctxt);
|
||||||
|
if (!target_path) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing storage pool target path"));
|
_("missing storage pool target path"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ret->target.path = virFileSanitizePath(target_path);
|
ret->target.path = virFileSanitizePath(target_path);
|
||||||
if (!ret->target.path)
|
if (!ret->target.path)
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -454,17 +454,7 @@ virStorageBackendLogicalCheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
bool *isActive)
|
bool *isActive)
|
||||||
{
|
{
|
||||||
char *path;
|
*isActive = (access(pool->def->target.path, F_OK) == 0);
|
||||||
|
|
||||||
*isActive = false;
|
|
||||||
if (virAsprintf(&path, "/dev/%s", pool->def->source.name) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (access(path, F_OK) == 0)
|
|
||||||
*isActive = true;
|
|
||||||
|
|
||||||
VIR_FREE(path);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -794,21 +784,16 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *volpath = NULL;
|
|
||||||
|
|
||||||
virCommandPtr lvchange_cmd = NULL;
|
virCommandPtr lvchange_cmd = NULL;
|
||||||
virCommandPtr lvremove_cmd = NULL;
|
virCommandPtr lvremove_cmd = NULL;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
if (virAsprintf(&volpath, "%s/%s",
|
|
||||||
pool->def->source.name, vol->name) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
virFileWaitForDevices();
|
virFileWaitForDevices();
|
||||||
|
|
||||||
lvchange_cmd = virCommandNewArgList(LVCHANGE, "-aln", volpath, NULL);
|
lvchange_cmd = virCommandNewArgList(LVCHANGE, "-aln", vol->target.path, NULL);
|
||||||
lvremove_cmd = virCommandNewArgList(LVREMOVE, "-f", volpath, NULL);
|
lvremove_cmd = virCommandNewArgList(LVREMOVE, "-f", vol->target.path, NULL);
|
||||||
|
|
||||||
if (virCommandRun(lvremove_cmd, NULL) < 0) {
|
if (virCommandRun(lvremove_cmd, NULL) < 0) {
|
||||||
if (virCommandRun(lvchange_cmd, NULL) < 0) {
|
if (virCommandRun(lvchange_cmd, NULL) < 0) {
|
||||||
@ -821,7 +806,6 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(volpath);
|
|
||||||
virCommandFree(lvchange_cmd);
|
virCommandFree(lvchange_cmd);
|
||||||
virCommandFree(lvremove_cmd);
|
virCommandFree(lvremove_cmd);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* storage_driver.c: core driver for storage APIs
|
* storage_driver.c: core driver for storage APIs
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2012 Red Hat, Inc.
|
* Copyright (C) 2006-2013 Red Hat, Inc.
|
||||||
* Copyright (C) 2006-2008 Daniel P. Berrange
|
* Copyright (C) 2006-2008 Daniel P. Berrange
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<device path="/dev/sdb3"/>
|
<device path="/dev/sdb3"/>
|
||||||
</source>
|
</source>
|
||||||
<target>
|
<target>
|
||||||
<path>/dev/HostVG</path>
|
<path>/invalid/nonexistent/path</path>
|
||||||
<permissions>
|
<permissions>
|
||||||
<mode>0700</mode>
|
<mode>0700</mode>
|
||||||
<owner>0</owner>
|
<owner>0</owner>
|
||||||
|
19
tests/storagepoolxml2xmlin/pool-logical-nopath.xml
Normal file
19
tests/storagepoolxml2xmlin/pool-logical-nopath.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<pool type='logical'>
|
||||||
|
<name>HostVG</name>
|
||||||
|
<uuid>1c13165a-d0f4-3aee-b447-30fb38789091</uuid>
|
||||||
|
<capacity>99891544064</capacity>
|
||||||
|
<allocation>99220455424</allocation>
|
||||||
|
<available>671088640</available>
|
||||||
|
<source>
|
||||||
|
<device path="/dev/sdb1"/>
|
||||||
|
<device path="/dev/sdb2"/>
|
||||||
|
<device path="/dev/sdb3"/>
|
||||||
|
</source>
|
||||||
|
<target>
|
||||||
|
<permissions>
|
||||||
|
<mode>0700</mode>
|
||||||
|
<owner>0</owner>
|
||||||
|
<group>0</group>
|
||||||
|
</permissions>
|
||||||
|
</target>
|
||||||
|
</pool>
|
22
tests/storagepoolxml2xmlout/pool-logical-nopath.xml
Normal file
22
tests/storagepoolxml2xmlout/pool-logical-nopath.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<pool type='logical'>
|
||||||
|
<name>HostVG</name>
|
||||||
|
<uuid>1c13165a-d0f4-3aee-b447-30fb38789091</uuid>
|
||||||
|
<capacity unit='bytes'>0</capacity>
|
||||||
|
<allocation unit='bytes'>0</allocation>
|
||||||
|
<available unit='bytes'>0</available>
|
||||||
|
<source>
|
||||||
|
<device path='/dev/sdb1'/>
|
||||||
|
<device path='/dev/sdb2'/>
|
||||||
|
<device path='/dev/sdb3'/>
|
||||||
|
<name>HostVG</name>
|
||||||
|
<format type='lvm2'/>
|
||||||
|
</source>
|
||||||
|
<target>
|
||||||
|
<path>/dev/HostVG</path>
|
||||||
|
<permissions>
|
||||||
|
<mode>0700</mode>
|
||||||
|
<owner>0</owner>
|
||||||
|
<group>0</group>
|
||||||
|
</permissions>
|
||||||
|
</target>
|
||||||
|
</pool>
|
@ -87,6 +87,7 @@ mymain(void)
|
|||||||
DO_TEST("pool-dir");
|
DO_TEST("pool-dir");
|
||||||
DO_TEST("pool-fs");
|
DO_TEST("pool-fs");
|
||||||
DO_TEST("pool-logical");
|
DO_TEST("pool-logical");
|
||||||
|
DO_TEST("pool-logical-nopath");
|
||||||
DO_TEST("pool-logical-create");
|
DO_TEST("pool-logical-create");
|
||||||
DO_TEST("pool-disk");
|
DO_TEST("pool-disk");
|
||||||
DO_TEST("pool-iscsi");
|
DO_TEST("pool-iscsi");
|
||||||
|
Loading…
Reference in New Issue
Block a user