---
src/storage/storage_backend.h | 2 +-
src/storage/storage_backend_disk.c | 3 ++-
src/storage/storage_backend_fs.c | 30 +++++++++++++++++++++++-------
src/storage/storage_backend_logical.c | 6 ++++--
src/storage/storage_backend_rbd.c | 3 ++-
src/storage/storage_backend_sheepdog.c | 3 ++-
src/storage/storage_driver.c | 4 ++--
7 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index 9e07dd8..4d0c057 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -41,7 +41,7 @@ typedef int (*virStorageBackendDeletePool)(virConnectPtr conn,
virStoragePoolObj
typedef int (*virStorageBackendBuildVol)(virConnectPtr conn,
virStoragePoolObjPtr pool, virStorageVolDefPtr
vol,
unsigned int flags);
-typedef int (*virStorageBackendCreateVol)(virConnectPtr conn, virStoragePoolObjPtr pool,
virStorageVolDefPtr vol);
+typedef int (*virStorageBackendCreateVol)(virConnectPtr conn, virStoragePoolObjPtr pool,
virStorageVolDefPtr vol, bool internal);
typedef int (*virStorageBackendRefreshVol)(virConnectPtr conn, virStoragePoolObjPtr pool,
virStorageVolDefPtr vol);
typedef int (*virStorageBackendDeleteVol)(virConnectPtr conn, virStoragePoolObjPtr pool,
virStorageVolDefPtr vol, unsigned int flags);
typedef int (*virStorageBackendBuildVolFrom)(virConnectPtr conn, virStoragePoolObjPtr
pool,
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index aa3b72f..a77c298 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -618,7 +618,8 @@ virStorageBackendDiskPartBoundries(virStoragePoolObjPtr pool,
static int
virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
- virStorageVolDefPtr vol)
+ virStorageVolDefPtr vol,
+ bool internal ATTRIBUTE_UNUSED)
{
if (vol->target.encryption != NULL) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 9188ffa..f9f7ea3 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -997,8 +997,10 @@ virStorageBackendFileSystemDelete(virConnectPtr conn
ATTRIBUTE_UNUSED,
static int
virStorageBackendFileSystemVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
- virStorageVolDefPtr vol)
+ virStorageVolDefPtr vol,
+ bool internal)
{
+ struct stat st;
vol->type = VIR_STORAGE_VOL_FILE;
@@ -1008,15 +1010,29 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn
ATTRIBUTE_UNUSED,
vol->name) == -1)
return -1;
- if (virFileExists(vol->target.path)) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- _("volume target path '%s' already exists"),
- vol->target.path);
- return -1;
+ if (internal) {
+ if (stat(vol->target.path, &st) == 0) {
+ if (S_ISDIR(st.st_mode))
+ vol->type = VIR_STORAGE_VOL_DIR;
+ else if (S_ISBLK(st.st_mode))
+ vol->type = VIR_STORAGE_VOL_BLOCK;
+ else
+ vol->type = VIR_STORAGE_VOL_FILE;
+ }
+ } else {
+ if (virFileExists(vol->target.path)) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("volume target path '%s' already
exists"),
+ vol->target.path);
+ return -1;
+ }
}
VIR_FREE(vol->key);
- return VIR_STRDUP(vol->key, vol->target.path);
+ if (VIR_STRDUP(vol->key, vol->target.path) < 0)
+ return -1;
+
+ return 0;
}
static int createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED,
diff --git a/src/storage/storage_backend_logical.c
b/src/storage/storage_backend_logical.c
index 039d962..2e2560f 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -784,7 +784,8 @@ error:
static int
virStorageBackendLogicalCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
- virStorageVolDefPtr vol)
+ virStorageVolDefPtr vol,
+ bool internal)
{
if (vol->target.encryption != NULL) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -800,7 +801,8 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn
ATTRIBUTE_UNUSED,
vol->name) == -1)
return -1;
- if (virFileExists(vol->target.path)) {
+ if (!internal &&
+ virFileExists(vol->target.path)) {
virReportError(VIR_ERR_OPERATION_INVALID,
_("volume target path '%s' already exists"),
vol->target.path);
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index c5f0bc5..75425f4 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -439,7 +439,8 @@ cleanup:
static int
virStorageBackendRBDCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
- virStorageVolDefPtr vol)
+ virStorageVolDefPtr vol,
+ bool internal ATTRIBUTE_UNUSED)
{
vol->type = VIR_STORAGE_VOL_NETWORK;
diff --git a/src/storage/storage_backend_sheepdog.c
b/src/storage/storage_backend_sheepdog.c
index a6981ce..705451b 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -152,7 +152,8 @@ virStorageBackendSheepdogDeleteVol(virConnectPtr conn
ATTRIBUTE_UNUSED,
static int
virStorageBackendSheepdogCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
- virStorageVolDefPtr vol)
+ virStorageVolDefPtr vol,
+ bool internal ATTRIBUTE_UNUSED)
{
if (vol->target.encryption != NULL) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 00f2c50..c92e6c2 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1651,7 +1651,7 @@ storageVolCreateXML(virStoragePoolPtr obj,
/* Wipe any key the user may have suggested, as volume creation
* will generate the canonical key. */
VIR_FREE(voldef->key);
- if (backend->createVol(obj->conn, pool, voldef) < 0) {
+ if (backend->createVol(obj->conn, pool, voldef, false) < 0) {
goto cleanup;
}
@@ -1830,7 +1830,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
* Wipe any key the user may have suggested, as volume creation
* will generate the canonical key. */
VIR_FREE(newvol->key);
- if (backend->createVol(obj->conn, pool, newvol) < 0) {
+ if (backend->createVol(obj->conn, pool, newvol, false) < 0) {
goto cleanup;
}
--
1.8.5.1