From efab27afbf02743a3a2582e9a111eb1b7d985b26 Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Tue, 30 Apr 2013 13:48:46 +0200 Subject: [PATCH] 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/' safely and populate it to target.path. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=952973 --- docs/schemas/storagepool.rng | 13 ++++++++++- src/conf/storage_conf.c | 17 +++++++++----- src/storage/storage_backend_logical.c | 22 +++---------------- src/storage/storage_driver.c | 2 +- .../pool-logical-create.xml | 2 +- .../pool-logical-nopath.xml | 19 ++++++++++++++++ .../pool-logical-nopath.xml | 22 +++++++++++++++++++ tests/storagepoolxml2xmltest.c | 1 + 8 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 tests/storagepoolxml2xmlin/pool-logical-nopath.xml create mode 100644 tests/storagepoolxml2xmlout/pool-logical-nopath.xml diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng index 6da3c11ac1..a4ef5aff0c 100644 --- a/docs/schemas/storagepool.rng +++ b/docs/schemas/storagepool.rng @@ -62,7 +62,7 @@ - + @@ -207,6 +207,17 @@ + + + + + + + + + + + diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index d6df1ed71f..002663f1e4 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1,7 +1,7 @@ /* * 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 * * This library is free software; you can redistribute it and/or @@ -956,10 +956,17 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) /* When we are working with a virtual disk we can skip the target * path and permissions */ if (!(options->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)) { - if (!(target_path = virXPathString("string(./target/path)", ctxt))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing storage pool target path")); - goto error; + 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", + _("missing storage pool target path")); + goto error; + } } ret->target.path = virFileSanitizePath(target_path); if (!ret->target.path) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 416a0424fe..8998a11b92 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -454,17 +454,7 @@ virStorageBackendLogicalCheckPool(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool, bool *isActive) { - char *path; - - *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); - + *isActive = (access(pool->def->target.path, F_OK) == 0); return 0; } @@ -794,21 +784,16 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned int flags) { int ret = -1; - char *volpath = NULL; virCommandPtr lvchange_cmd = NULL; virCommandPtr lvremove_cmd = NULL; virCheckFlags(0, -1); - if (virAsprintf(&volpath, "%s/%s", - pool->def->source.name, vol->name) < 0) - goto cleanup; - virFileWaitForDevices(); - lvchange_cmd = virCommandNewArgList(LVCHANGE, "-aln", volpath, NULL); - lvremove_cmd = virCommandNewArgList(LVREMOVE, "-f", volpath, NULL); + lvchange_cmd = virCommandNewArgList(LVCHANGE, "-aln", vol->target.path, NULL); + lvremove_cmd = virCommandNewArgList(LVREMOVE, "-f", vol->target.path, NULL); if (virCommandRun(lvremove_cmd, NULL) < 0) { if (virCommandRun(lvchange_cmd, NULL) < 0) { @@ -821,7 +806,6 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED, ret = 0; cleanup: - VIR_FREE(volpath); virCommandFree(lvchange_cmd); virCommandFree(lvremove_cmd); return ret; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index a8eb731aec..43bf6dece5 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1,7 +1,7 @@ /* * 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 * * This library is free software; you can redistribute it and/or diff --git a/tests/storagepoolxml2xmlin/pool-logical-create.xml b/tests/storagepoolxml2xmlin/pool-logical-create.xml index 4c670899da..fd551e016b 100644 --- a/tests/storagepoolxml2xmlin/pool-logical-create.xml +++ b/tests/storagepoolxml2xmlin/pool-logical-create.xml @@ -10,7 +10,7 @@ - /dev/HostVG + /invalid/nonexistent/path 0700 0 diff --git a/tests/storagepoolxml2xmlin/pool-logical-nopath.xml b/tests/storagepoolxml2xmlin/pool-logical-nopath.xml new file mode 100644 index 0000000000..e1bb4db48c --- /dev/null +++ b/tests/storagepoolxml2xmlin/pool-logical-nopath.xml @@ -0,0 +1,19 @@ + + HostVG + 1c13165a-d0f4-3aee-b447-30fb38789091 + 99891544064 + 99220455424 + 671088640 + + + + + + + + 0700 + 0 + 0 + + + diff --git a/tests/storagepoolxml2xmlout/pool-logical-nopath.xml b/tests/storagepoolxml2xmlout/pool-logical-nopath.xml new file mode 100644 index 0000000000..7413f1cfe4 --- /dev/null +++ b/tests/storagepoolxml2xmlout/pool-logical-nopath.xml @@ -0,0 +1,22 @@ + + HostVG + 1c13165a-d0f4-3aee-b447-30fb38789091 + 0 + 0 + 0 + + + + + HostVG + + + + /dev/HostVG + + 0700 + 0 + 0 + + + diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index 53a7f83ca1..d59cff9746 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -87,6 +87,7 @@ mymain(void) DO_TEST("pool-dir"); DO_TEST("pool-fs"); DO_TEST("pool-logical"); + DO_TEST("pool-logical-nopath"); DO_TEST("pool-logical-create"); DO_TEST("pool-disk"); DO_TEST("pool-iscsi"); -- 2.39.5