In the 'directory' and 'netfs' storage pools, a user can see
both 'file' and 'dir' storage volume types, to know when they
can descend into a subdirectory. But in a network-based storage
pool, such as the upcoming 'gluster' pool, we use 'network'
instead of 'file', and did not have any counterpart for a
directory until this patch. Adding a new volume type
'network-dir' is better than reusing 'dir', because it makes
it clear that the only way to access 'network' volumes within
that container is through the network mounting (leaving 'dir'
for something accessible in the local file system).
* include/libvirt/libvirt.h.in (virStorageVolType): Expand enum.
* src/qemu/qemu_command.c (qemuBuildVolumeString): Fix client.
* src/qemu/qemu_conf.c (qemuTranslateDiskSourcePool): Likewise.
* tools/virsh-volume.c (vshVolumeTypeToString): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemVolDelete): Likewise.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
If you do 'virsh vol-list $pool --details', you'll see various
types of volumes listed in the output. For 'directory' and
'netfs' pools, telling 'dir' and 'file' apart is important.
For my pending 'gluster' work, seeing 'network' everywhere
hides that distinction, hence my proposal of adding a new type.
But as I prepared this patch for posting, I noticed a bigger
problem: we don't expose this information in volume XML, but
only in virStorageVolGetInfo(). So, I'm wondering if I should
pursue this further by enhancing the <volume> XML to _also_
expose this type (currently 'file', 'dir', 'block', or
'network',
and possibly my addition of 'network-dir'), so that callers
can get the information via a single call to
virStorageVolGetXMLDesc() (which already reports everything else
that you can get from virStorageVolGetInfo, and would thus make
it a full superset instead of needing both calls to get the
full picture).
include/libvirt/libvirt.h.in | 2 ++
src/qemu/qemu_command.c | 6 ++++--
src/qemu/qemu_conf.c | 4 +++-
src/storage/storage_backend_fs.c | 5 +++--
tools/virsh-volume.c | 7 +++++--
5 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 146a59b..5e8cba6 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2951,6 +2951,8 @@ typedef enum {
VIR_STORAGE_VOL_BLOCK = 1, /* Block based volumes */
VIR_STORAGE_VOL_DIR = 2, /* Directory-passthrough based volume */
VIR_STORAGE_VOL_NETWORK = 3, /* Network volumes like RBD (RADOS Block Device) */
+ VIR_STORAGE_VOL_NETWORK_DIR = 4, /* Network accessible directory that can
+ * contain other network volumes */
#ifdef VIR_ENUM_SENTINELS
VIR_STORAGE_VOL_LAST
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6668fed..bf3533b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3780,7 +3780,7 @@ qemuBuildVolumeString(virConnectPtr conn,
{
int ret = -1;
- switch (disk->srcpool->voltype) {
+ switch ((virStorageVolType) disk->srcpool->voltype) {
case VIR_STORAGE_VOL_DIR:
if (!disk->readonly) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -3823,10 +3823,12 @@ qemuBuildVolumeString(virConnectPtr conn,
}
break;
case VIR_STORAGE_VOL_NETWORK:
+ case VIR_STORAGE_VOL_NETWORK_DIR:
+ case VIR_STORAGE_VOL_LAST:
/* Keep the compiler quiet, qemuTranslateDiskSourcePool already
* reported the unsupported error.
*/
- break;
+ goto cleanup;
}
ret = 0;
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 03c9c7d..c9d03b0 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1331,7 +1331,7 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
goto cleanup;
}
- switch (info.type) {
+ switch ((virStorageVolType) info.type) {
case VIR_STORAGE_VOL_FILE:
case VIR_STORAGE_VOL_DIR:
if (!(def->src = virStorageVolGetPath(vol)))
@@ -1376,6 +1376,8 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
break;
case VIR_STORAGE_VOL_NETWORK:
+ case VIR_STORAGE_VOL_NETWORK_DIR:
+ case VIR_STORAGE_VOL_LAST:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Using network volume as disk source is not
supported"));
goto cleanup;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 510a3d6..2af6faf 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1137,7 +1137,7 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn
ATTRIBUTE_UNUSED,
{
virCheckFlags(0, -1);
- switch (vol->type) {
+ switch ((virStorageVolType) vol->type) {
case VIR_STORAGE_VOL_FILE:
if (unlink(vol->target.path) < 0) {
/* Silently ignore failures where the vol has already gone away */
@@ -1159,7 +1159,8 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn
ATTRIBUTE_UNUSED,
break;
case VIR_STORAGE_VOL_BLOCK:
case VIR_STORAGE_VOL_NETWORK:
- default:
+ case VIR_STORAGE_VOL_NETWORK_DIR:
+ case VIR_STORAGE_VOL_LAST:
virReportError(VIR_ERR_NO_SUPPORT,
_("removing block or network volumes is not supported:
%s"),
vol->target.path);
diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index 55a99d0..377a73b 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -1,7 +1,7 @@
/*
* virsh-volume.c: Commands to manage storage volume
*
- * Copyright (C) 2005, 2007-2012 Red Hat, Inc.
+ * Copyright (C) 2005, 2007-2013 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -946,7 +946,7 @@ out:
static const char *
vshVolumeTypeToString(int type)
{
- switch (type) {
+ switch ((virStorageVolType) type) {
case VIR_STORAGE_VOL_FILE:
return N_("file");
@@ -959,6 +959,9 @@ vshVolumeTypeToString(int type)
case VIR_STORAGE_VOL_NETWORK:
return N_("network");
+ case VIR_STORAGE_VOL_NETWORK_DIR:
+ return N_("net-dir");
+
case VIR_STORAGE_VOL_LAST:
break;
}
--
1.8.3.1