[libvirt] [PATCH 0/n] round 2 of storage chain refactoring

In round 1, I split out a new struct in domain_conf.h. This starts round 2: moving the struct into util/virstoragefile.h, so it can be shared by domain, snapshot, and existing virstoragefile backing chain operations. It's turned out to be a bigger process than I first thought, so I've tried splitting it into smaller patches to ease review. I also want to get review started on the parts I have compiling, while still working on the rest of the series, since I know that at least Peter will be heavily impacted by some of the changes in this series. Eric Blake (2): conf: split security label structs to util/ conf: split network host structs to util/ src/Makefile.am | 1 + src/conf/domain_conf.c | 139 +++------------------------------- src/conf/domain_conf.h | 71 +---------------- src/conf/snapshot_conf.c | 5 +- src/conf/snapshot_conf.h | 4 +- src/libvirt_private.syms | 21 ++--- src/qemu/qemu_command.c | 38 +++++----- src/qemu/qemu_command.h | 6 +- src/qemu/qemu_conf.c | 4 +- src/qemu/qemu_driver.c | 24 +++--- src/qemu/qemu_process.c | 2 +- src/security/security_manager.c | 2 +- src/security/security_selinux.c | 2 +- src/storage/storage_backend_gluster.c | 8 +- src/storage/storage_driver.c | 8 +- src/storage/storage_driver.h | 2 +- src/util/virseclabel.c | 82 ++++++++++++++++++++ src/util/virseclabel.h | 67 ++++++++++++++++ src/util/virstoragefile.c | 71 ++++++++++++++++- src/util/virstoragefile.h | 30 +++++++- 20 files changed, 328 insertions(+), 259 deletions(-) create mode 100644 src/util/virseclabel.c create mode 100644 src/util/virseclabel.h -- 1.8.5.3

In order to reuse the newly-created host-side disk struct in the virstoragefile backing chain code, I first have to move it to util/. This starts the process, by first moving the security label structures. * src/conf/domain_conf.h (virDomainDefGenSecurityLabelDef) (virDomainDiskDefGenSecurityLabelDef, virSecurityLabelDefFree) (virSecurityDeviceLabelDefFree, virSecurityLabelDef) (virSecurityDeviceLabelDef): Move... * src/util/virseclabel.h: ...to new file. (virSecurityLabelDefNew, virSecurityDeviceLabelDefNew): Rename the GenSecurity functions. * src/qemu/qemu_process.c (qemuProcessAttach): Adjust callers. * src/security/security_manager.c (virSecurityManagerGenLabel): Likewise. * src/security/security_selinux.c (virSecuritySELinuxSetSecurityFileLabel): Likewise. * src/util/virseclabel.c: New file. * src/conf/domain_conf.c: Move security code, and fix fallout. * src/Makefile.am (UTIL_SOURCES): Build new file. * src/libvirt_private.syms (domain_conf.h): Move symbols... (virseclabel.h): ...to new section. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/Makefile.am | 1 + src/conf/domain_conf.c | 51 ------------------------- src/conf/domain_conf.h | 43 +-------------------- src/libvirt_private.syms | 11 ++++-- src/qemu/qemu_process.c | 2 +- src/security/security_manager.c | 2 +- src/security/security_selinux.c | 2 +- src/util/virseclabel.c | 82 +++++++++++++++++++++++++++++++++++++++++ src/util/virseclabel.h | 67 +++++++++++++++++++++++++++++++++ 9 files changed, 161 insertions(+), 100 deletions(-) create mode 100644 src/util/virseclabel.c create mode 100644 src/util/virseclabel.h diff --git a/src/Makefile.am b/src/Makefile.am index 55427ed..54206e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -142,6 +142,7 @@ UTIL_SOURCES = \ util/virprocess.c util/virprocess.h \ util/virrandom.h util/virrandom.c \ util/virscsi.c util/virscsi.h \ + util/virseclabel.c util/virseclabel.h \ util/virsexpr.c util/virsexpr.h \ util/virsocketaddr.h util/virsocketaddr.c \ util/virstatslinux.c util/virstatslinux.h \ diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6fb216e..66eeaa9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1149,29 +1149,6 @@ virDomainGraphicsListenDefClear(virDomainGraphicsListenDefPtr def) return; } -void -virSecurityLabelDefFree(virSecurityLabelDefPtr def) -{ - if (!def) - return; - VIR_FREE(def->model); - VIR_FREE(def->label); - VIR_FREE(def->imagelabel); - VIR_FREE(def->baselabel); - VIR_FREE(def); -} - - -void -virSecurityDeviceLabelDefFree(virSecurityDeviceLabelDefPtr def) -{ - if (!def) - return; - VIR_FREE(def->model); - VIR_FREE(def->label); - VIR_FREE(def); -} - void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def) { @@ -19422,34 +19399,6 @@ virDomainChrDefGetSecurityLabelDef(virDomainChrDefPtr def, const char *model) return NULL; } -virSecurityLabelDefPtr -virDomainDefGenSecurityLabelDef(const char *model) -{ - virSecurityLabelDefPtr seclabel = NULL; - - if (VIR_ALLOC(seclabel) < 0 || - VIR_STRDUP(seclabel->model, model) < 0) { - virSecurityLabelDefFree(seclabel); - seclabel = NULL; - } - - return seclabel; -} - -virSecurityDeviceLabelDefPtr -virDomainDiskDefGenSecurityLabelDef(const char *model) -{ - virSecurityDeviceLabelDefPtr seclabel = NULL; - - if (VIR_ALLOC(seclabel) < 0 || - VIR_STRDUP(seclabel->model, model) < 0) { - virSecurityDeviceLabelDefFree(seclabel); - seclabel = NULL; - } - - return seclabel; -} - typedef struct { const char *devAlias; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f3f24c4..a249208 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -47,6 +47,7 @@ # include "virbitmap.h" # include "virstoragefile.h" # include "virnuma.h" +# include "virseclabel.h" /* forward declarations of all device types, required by * virDomainDeviceDef @@ -328,39 +329,6 @@ struct _virDomainDeviceInfo { int bootIndex; }; -enum virDomainSeclabelType { - VIR_DOMAIN_SECLABEL_DEFAULT, - VIR_DOMAIN_SECLABEL_NONE, - VIR_DOMAIN_SECLABEL_DYNAMIC, - VIR_DOMAIN_SECLABEL_STATIC, - - VIR_DOMAIN_SECLABEL_LAST -}; - -/* Security configuration for domain */ -typedef struct _virSecurityLabelDef virSecurityLabelDef; -typedef virSecurityLabelDef *virSecurityLabelDefPtr; -struct _virSecurityLabelDef { - char *model; /* name of security model */ - char *label; /* security label string */ - char *imagelabel; /* security image label string */ - char *baselabel; /* base name of label string */ - int type; /* virDomainSeclabelType */ - bool norelabel; - bool implicit; /* true if seclabel is auto-added */ -}; - - -/* Security configuration for domain */ -typedef struct _virSecurityDeviceLabelDef virSecurityDeviceLabelDef; -typedef virSecurityDeviceLabelDef *virSecurityDeviceLabelDefPtr; -struct _virSecurityDeviceLabelDef { - char *model; - char *label; /* image label string */ - bool norelabel; /* true to skip label attempts */ - bool labelskip; /* live-only; true if skipping failed label attempt */ -}; - typedef struct _virDomainHostdevOrigStates virDomainHostdevOrigStates; typedef virDomainHostdevOrigStates *virDomainHostdevOrigStatesPtr; @@ -2674,15 +2642,6 @@ virDomainDiskDefGetSecurityLabelDef(virDomainDiskDefPtr def, const char *model); virSecurityDeviceLabelDefPtr virDomainChrDefGetSecurityLabelDef(virDomainChrDefPtr def, const char *model); -virSecurityLabelDefPtr -virDomainDefGenSecurityLabelDef(const char *model); - -virSecurityDeviceLabelDefPtr -virDomainDiskDefGenSecurityLabelDef(const char *model); - -void virSecurityLabelDefFree(virSecurityLabelDefPtr def); -void virSecurityDeviceLabelDefFree(virSecurityDeviceLabelDefPtr def); - typedef const char* (*virEventActionToStringFunc)(int type); typedef int (*virEventActionFromStringFunc)(const char *type); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2357f95..74b8a7e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -161,7 +161,6 @@ virDomainDefFindDevice; virDomainDefFormat; virDomainDefFormatInternal; virDomainDefFree; -virDomainDefGenSecurityLabelDef; virDomainDefGetDefaultEmulator; virDomainDefGetSecurityLabelDef; virDomainDefMaybeAddController; @@ -191,7 +190,6 @@ virDomainDiskCopyOnReadTypeToString; virDomainDiskDefAssignAddress; virDomainDiskDefForeachPath; virDomainDiskDefFree; -virDomainDiskDefGenSecurityLabelDef; virDomainDiskDefGetSecurityLabelDef; virDomainDiskDeviceTypeToString; virDomainDiskDiscardTypeToString; @@ -425,8 +423,6 @@ virDomainWatchdogModelTypeFromString; virDomainWatchdogModelTypeToString; virDomainXMLOptionGetNamespace; virDomainXMLOptionNew; -virSecurityDeviceLabelDefFree; -virSecurityLabelDefFree; # conf/domain_event.h @@ -1777,6 +1773,13 @@ virSCSIDeviceNew; virSCSIDeviceSetUsedBy; +# util/virseclabel.h +virSecurityDeviceLabelDefFree; +virSecurityDeviceLabelDefNew; +virSecurityLabelDefFree; +virSecurityLabelDefNew; + + # util/virsexpr.h sexpr2string; sexpr_append; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 583ff76..ca9e15c 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4582,7 +4582,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, model = virSecurityManagerGetModel(sec_managers[i]); seclabeldef = virDomainDefGetSecurityLabelDef(vm->def, model); if (seclabeldef == NULL) { - if (!(seclabeldef = virDomainDefGenSecurityLabelDef(model))) + if (!(seclabeldef = virSecurityLabelDefNew(model))) goto error; seclabelgen = true; } diff --git a/src/security/security_manager.c b/src/security/security_manager.c index a308dfc..d68c7e9 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -485,7 +485,7 @@ int virSecurityManagerGenLabel(virSecurityManagerPtr mgr, generated = false; seclabel = virDomainDefGetSecurityLabelDef(vm, sec_managers[i]->drv->name); if (!seclabel) { - if (!(seclabel = virDomainDefGenSecurityLabelDef(sec_managers[i]->drv->name))) + if (!(seclabel = virSecurityLabelDefNew(sec_managers[i]->drv->name))) goto cleanup; generated = seclabel->implicit = true; } diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index f9d1122..b55ae38 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1233,7 +1233,7 @@ virSecuritySELinuxSetSecurityFileLabel(virDomainDiskDefPtr disk, if (ret == 1 && !disk_seclabel) { /* If we failed to set a label, but virt_use_nfs let us * proceed anyway, then we don't need to relabel later. */ - disk_seclabel = virDomainDiskDefGenSecurityLabelDef(SECURITY_SELINUX_NAME); + disk_seclabel = virSecurityDeviceLabelDefNew(SECURITY_SELINUX_NAME); if (!disk_seclabel) return -1; disk_seclabel->labelskip = true; diff --git a/src/util/virseclabel.c b/src/util/virseclabel.c new file mode 100644 index 0000000..5a4d78e --- /dev/null +++ b/src/util/virseclabel.c @@ -0,0 +1,82 @@ +/* + * virseclabel.c: security label utility functions + * + * Copyright (C) 2006-2014 Red Hat, Inc. + * Copyright (C) 2006-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, see + * <http://www.gnu.org/licenses/>. + */ + +#include <config.h> + +#include "internal.h" +#include "viralloc.h" +#include "virseclabel.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + + +void +virSecurityLabelDefFree(virSecurityLabelDefPtr def) +{ + if (!def) + return; + VIR_FREE(def->model); + VIR_FREE(def->label); + VIR_FREE(def->imagelabel); + VIR_FREE(def->baselabel); + VIR_FREE(def); +} + + +void +virSecurityDeviceLabelDefFree(virSecurityDeviceLabelDefPtr def) +{ + if (!def) + return; + VIR_FREE(def->model); + VIR_FREE(def->label); + VIR_FREE(def); +} + + +virSecurityLabelDefPtr +virSecurityLabelDefNew(const char *model) +{ + virSecurityLabelDefPtr seclabel = NULL; + + if (VIR_ALLOC(seclabel) < 0 || + VIR_STRDUP(seclabel->model, model) < 0) { + virSecurityLabelDefFree(seclabel); + seclabel = NULL; + } + + return seclabel; +} + +virSecurityDeviceLabelDefPtr +virSecurityDeviceLabelDefNew(const char *model) +{ + virSecurityDeviceLabelDefPtr seclabel = NULL; + + if (VIR_ALLOC(seclabel) < 0 || + VIR_STRDUP(seclabel->model, model) < 0) { + virSecurityDeviceLabelDefFree(seclabel); + seclabel = NULL; + } + + return seclabel; +} diff --git a/src/util/virseclabel.h b/src/util/virseclabel.h new file mode 100644 index 0000000..41b90bc --- /dev/null +++ b/src/util/virseclabel.h @@ -0,0 +1,67 @@ +/* + * virseclabel.h: security label utility functions + * + * Copyright (C) 2006-2014 Red Hat, Inc. + * Copyright (C) 2006-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, see + * <http://www.gnu.org/licenses/>. + */ + +#ifndef __SECLABEL_H +# define __SECLABEL_H + +enum virDomainSeclabelType { + VIR_DOMAIN_SECLABEL_DEFAULT, + VIR_DOMAIN_SECLABEL_NONE, + VIR_DOMAIN_SECLABEL_DYNAMIC, + VIR_DOMAIN_SECLABEL_STATIC, + + VIR_DOMAIN_SECLABEL_LAST +}; + +/* Security configuration for domain */ +typedef struct _virSecurityLabelDef virSecurityLabelDef; +typedef virSecurityLabelDef *virSecurityLabelDefPtr; +struct _virSecurityLabelDef { + char *model; /* name of security model */ + char *label; /* security label string */ + char *imagelabel; /* security image label string */ + char *baselabel; /* base name of label string */ + int type; /* virDomainSeclabelType */ + bool norelabel; + bool implicit; /* true if seclabel is auto-added */ +}; + + +/* Security configuration for domain */ +typedef struct _virSecurityDeviceLabelDef virSecurityDeviceLabelDef; +typedef virSecurityDeviceLabelDef *virSecurityDeviceLabelDefPtr; +struct _virSecurityDeviceLabelDef { + char *model; + char *label; /* image label string */ + bool norelabel; /* true to skip label attempts */ + bool labelskip; /* live-only; true if skipping failed label attempt */ +}; + +virSecurityLabelDefPtr +virSecurityLabelDefNew(const char *model); + +virSecurityDeviceLabelDefPtr +virSecurityDeviceLabelDefNew(const char *model); + +void virSecurityLabelDefFree(virSecurityLabelDefPtr def); +void virSecurityDeviceLabelDefFree(virSecurityDeviceLabelDefPtr def); + +#endif /* __SECLABEL_H */ -- 1.8.5.3

On 03/27/14 00:09, Eric Blake wrote:
In order to reuse the newly-created host-side disk struct in the virstoragefile backing chain code, I first have to move it to util/. This starts the process, by first moving the security label structures.
* src/conf/domain_conf.h (virDomainDefGenSecurityLabelDef) (virDomainDiskDefGenSecurityLabelDef, virSecurityLabelDefFree) (virSecurityDeviceLabelDefFree, virSecurityLabelDef) (virSecurityDeviceLabelDef): Move... * src/util/virseclabel.h: ...to new file. (virSecurityLabelDefNew, virSecurityDeviceLabelDefNew): Rename the GenSecurity functions. * src/qemu/qemu_process.c (qemuProcessAttach): Adjust callers. * src/security/security_manager.c (virSecurityManagerGenLabel): Likewise. * src/security/security_selinux.c (virSecuritySELinuxSetSecurityFileLabel): Likewise. * src/util/virseclabel.c: New file. * src/conf/domain_conf.c: Move security code, and fix fallout. * src/Makefile.am (UTIL_SOURCES): Build new file. * src/libvirt_private.syms (domain_conf.h): Move symbols... (virseclabel.h): ...to new section.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/Makefile.am | 1 + src/conf/domain_conf.c | 51 ------------------------- src/conf/domain_conf.h | 43 +-------------------- src/libvirt_private.syms | 11 ++++-- src/qemu/qemu_process.c | 2 +- src/security/security_manager.c | 2 +- src/security/security_selinux.c | 2 +- src/util/virseclabel.c | 82 +++++++++++++++++++++++++++++++++++++++++ src/util/virseclabel.h | 67 +++++++++++++++++++++++++++++++++ 9 files changed, 161 insertions(+), 100 deletions(-) create mode 100644 src/util/virseclabel.c create mode 100644 src/util/virseclabel.h
ACK. Peter

Continuing the refactoring of host-side storage descriptions out of conf/domain_conf and into util/virstoragefile, this patch focuses on details about a host name/port/transport as used by a network storage volume. * src/conf/domain_conf.h (virDomainDiskProtocolTransport) (virDomainDiskHostDef, virDomainDiskHostDefClear) (virDomainDiskHostDefFree, virDomainDiskHostDefCopy): Move... * src/util/virstoragefile.h (virStorageNetHostTransport) (virStorageNetHostDef, virStorageNetHostDefClear) (virStorageNetHostDefFree, virStorageNetHostDefCopy): ...here, with better names. * src/util/virstoragefile.c (virStorageNetHostDefClear) (virStorageNetHostDefFree, virStorageNetHostDefCopy): Moved from... * src/conf/domain_conf.c (virDomainDiskHostDefClear) (virDomainDiskHostDefFree, virDomainDiskHostDefCopy): ...here. (virDomainDiskSourceDefClear, virDomainDiskSourceDefParse) (virDomainDiskSourceDefFormatInternal): Adjust callers. * src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise. * src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear): Likewise. * src/qemu/qemu_command.c (qemuAddRBDHost) (qemuParseDriveURIString, qemuParseNBDString) (qemuBuildNetworkDriveURI, qemuParseCommandLineDisk) (qemuParseCommandLine, qemuGetDriveSourceString): Likewise. * src/qemu/qemu_command.h: Likewise. * src/qemu/qemu_conf.c (qemuAddISCSIPoolSourceHost) (qemuTranslateDiskSourcePool): Likewise. * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateSingleDiskActive) (qemuDomainSnapshotUndoSingleDiskActive): Likewise. * src/storage/storage_backend_gluster.c (virStorageFileBackendGlusterInit): Likewise. * src/storage/storage_driver.c (virStorageFileFree) (virStorageFileInitInternal): Likewise. * src/storage/storage_driver.h (_virStorageFile): Likewise. * src/libvirt_private.syms (domain_conf.h): Move symbols... (virstoragefile.h): ...as appropriate. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 88 +++++------------------------------ src/conf/domain_conf.h | 28 ++--------- src/conf/snapshot_conf.c | 5 +- src/conf/snapshot_conf.h | 4 +- src/libvirt_private.syms | 10 ++-- src/qemu/qemu_command.c | 38 +++++++-------- src/qemu/qemu_command.h | 6 +-- src/qemu/qemu_conf.c | 4 +- src/qemu/qemu_driver.c | 24 +++++----- src/storage/storage_backend_gluster.c | 8 ++-- src/storage/storage_driver.c | 8 ++-- src/storage/storage_driver.h | 2 +- src/util/virstoragefile.c | 71 +++++++++++++++++++++++++++- src/util/virstoragefile.h | 30 +++++++++++- 14 files changed, 167 insertions(+), 159 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 66eeaa9..159a9c3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -276,11 +276,6 @@ VIR_ENUM_IMPL(virDomainDiskProtocol, VIR_DOMAIN_DISK_PROTOCOL_LAST, "ftps", "tftp") -VIR_ENUM_IMPL(virDomainDiskProtocolTransport, VIR_DOMAIN_DISK_PROTO_TRANS_LAST, - "tcp", - "unix", - "rdma") - VIR_ENUM_IMPL(virDomainDiskSecretType, VIR_DOMAIN_DISK_SECRET_TYPE_LAST, "none", "uuid", @@ -1245,7 +1240,7 @@ virDomainDiskSourceDefClear(virDomainDiskSourceDefPtr def) VIR_FREE(def->seclabels); } - virDomainDiskHostDefFree(def->nhosts, def->hosts); + virStorageNetHostDefFree(def->nhosts, def->hosts); virDomainDiskAuthClear(def); } @@ -1282,67 +1277,6 @@ virDomainDiskAuthClear(virDomainDiskSourceDefPtr def) } -void virDomainDiskHostDefClear(virDomainDiskHostDefPtr def) -{ - if (!def) - return; - - VIR_FREE(def->name); - VIR_FREE(def->port); - VIR_FREE(def->socket); -} - - -void -virDomainDiskHostDefFree(size_t nhosts, - virDomainDiskHostDefPtr hosts) -{ - size_t i; - - if (!hosts) - return; - - for (i = 0; i < nhosts; i++) - virDomainDiskHostDefClear(&hosts[i]); - - VIR_FREE(hosts); -} - - -virDomainDiskHostDefPtr -virDomainDiskHostDefCopy(size_t nhosts, - virDomainDiskHostDefPtr hosts) -{ - virDomainDiskHostDefPtr ret = NULL; - size_t i; - - if (VIR_ALLOC_N(ret, nhosts) < 0) - goto error; - - for (i = 0; i < nhosts; i++) { - virDomainDiskHostDefPtr src = &hosts[i]; - virDomainDiskHostDefPtr dst = &ret[i]; - - dst->transport = src->transport; - - if (VIR_STRDUP(dst->name, src->name) < 0) - goto error; - - if (VIR_STRDUP(dst->port, src->port) < 0) - goto error; - - if (VIR_STRDUP(dst->socket, src->socket) < 0) - goto error; - } - - return ret; - - error: - virDomainDiskHostDefFree(nhosts, ret); - return NULL; -} - - int virDomainDiskGetType(virDomainDiskDefPtr def) { @@ -5102,12 +5036,12 @@ virDomainDiskSourceDefParse(xmlNodePtr node, char **source, int *proto, size_t *nhosts, - virDomainDiskHostDefPtr *hosts, + virStorageNetHostDefPtr *hosts, virDomainDiskSourcePoolDefPtr *srcpool) { char *protocol = NULL; char *transport = NULL; - virDomainDiskHostDef host; + virStorageNetHostDef host; xmlNodePtr child; int ret = -1; @@ -5148,11 +5082,11 @@ virDomainDiskSourceDefParse(xmlNodePtr node, if (child->type == XML_ELEMENT_NODE && xmlStrEqual(child->name, BAD_CAST "host")) { - host.transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; + host.transport = VIR_STORAGE_NET_HOST_TRANS_TCP; /* transport can be tcp (default), unix or rdma. */ if ((transport = virXMLPropString(child, "transport"))) { - host.transport = virDomainDiskProtocolTransportTypeFromString(transport); + host.transport = virStorageNetHostTransportTypeFromString(transport); if (host.transport < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown protocol transport type '%s'"), @@ -5163,14 +5097,14 @@ virDomainDiskSourceDefParse(xmlNodePtr node, host.socket = virXMLPropString(child, "socket"); - if (host.transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX && + if (host.transport == VIR_STORAGE_NET_HOST_TRANS_UNIX && host.socket == NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing socket for unix transport")); goto cleanup; } - if (host.transport != VIR_DOMAIN_DISK_PROTO_TRANS_UNIX && + if (host.transport != VIR_STORAGE_NET_HOST_TRANS_UNIX && host.socket != NULL) { virReportError(VIR_ERR_XML_ERROR, _("transport '%s' does not support " @@ -5181,7 +5115,7 @@ virDomainDiskSourceDefParse(xmlNodePtr node, VIR_FREE(transport); - if (host.transport != VIR_DOMAIN_DISK_PROTO_TRANS_UNIX) { + if (host.transport != VIR_STORAGE_NET_HOST_TRANS_UNIX) { if (!(host.name = virXMLPropString(child, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing name for host")); @@ -5217,7 +5151,7 @@ virDomainDiskSourceDefParse(xmlNodePtr node, ret = 0; cleanup: - virDomainDiskHostDefClear(&host); + virStorageNetHostDefClear(&host); VIR_FREE(protocol); VIR_FREE(transport); return ret; @@ -14843,7 +14777,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, int policy, int protocol, size_t nhosts, - virDomainDiskHostDefPtr hosts, + virStorageNetHostDefPtr hosts, size_t nseclabels, virSecurityDeviceLabelDefPtr *seclabels, virDomainDiskSourcePoolDefPtr srcpool, @@ -14897,7 +14831,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, if (hosts[n].transport) virBufferAsprintf(buf, " transport='%s'", - virDomainDiskProtocolTransportTypeToString(hosts[n].transport)); + virStorageNetHostTransportTypeToString(hosts[n].transport)); virBufferEscapeString(buf, " socket='%s'", hosts[n].socket); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a249208..cbf2dca 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -533,14 +533,6 @@ enum virDomainDiskProtocol { VIR_DOMAIN_DISK_PROTOCOL_LAST }; -enum virDomainDiskProtocolTransport { - VIR_DOMAIN_DISK_PROTO_TRANS_TCP, - VIR_DOMAIN_DISK_PROTO_TRANS_UNIX, - VIR_DOMAIN_DISK_PROTO_TRANS_RDMA, - - VIR_DOMAIN_DISK_PROTO_TRANS_LAST -}; - enum virDomainDiskTray { VIR_DOMAIN_DISK_TRAY_CLOSED, VIR_DOMAIN_DISK_TRAY_OPEN, @@ -557,15 +549,6 @@ enum virDomainDiskGeometryTrans { VIR_DOMAIN_DISK_TRANS_LAST }; -typedef struct _virDomainDiskHostDef virDomainDiskHostDef; -typedef virDomainDiskHostDef *virDomainDiskHostDefPtr; -struct _virDomainDiskHostDef { - char *name; - char *port; - int transport; /* enum virDomainDiskProtocolTransport */ - char *socket; /* path to unix socket */ -}; - enum virDomainDiskIo { VIR_DOMAIN_DISK_IO_DEFAULT, VIR_DOMAIN_DISK_IO_NATIVE, @@ -684,7 +667,7 @@ struct _virDomainDiskSourceDef { char *path; int protocol; /* enum virDomainDiskProtocol */ size_t nhosts; - virDomainDiskHostDefPtr hosts; + virStorageNetHostDefPtr hosts; virDomainDiskSourcePoolDefPtr srcpool; struct { char *username; @@ -2232,10 +2215,6 @@ void virDomainInputDefFree(virDomainInputDefPtr def); void virDomainDiskDefFree(virDomainDiskDefPtr def); void virDomainLeaseDefFree(virDomainLeaseDefPtr def); void virDomainDiskAuthClear(virDomainDiskSourceDefPtr def); -void virDomainDiskHostDefClear(virDomainDiskHostDefPtr def); -void virDomainDiskHostDefFree(size_t nhosts, virDomainDiskHostDefPtr hosts); -virDomainDiskHostDefPtr virDomainDiskHostDefCopy(size_t nhosts, - virDomainDiskHostDefPtr hosts); int virDomainDiskGetType(virDomainDiskDefPtr def); void virDomainDiskSetType(virDomainDiskDefPtr def, int type); int virDomainDiskGetActualType(virDomainDiskDefPtr def); @@ -2388,7 +2367,7 @@ int virDomainDiskSourceDefFormatInternal(virBufferPtr buf, int policy, int protocol, size_t nhosts, - virDomainDiskHostDefPtr hosts, + virStorageNetHostDefPtr hosts, size_t nseclabels, virSecurityDeviceLabelDefPtr *seclabels, virDomainDiskSourcePoolDefPtr srcpool, @@ -2444,7 +2423,7 @@ int virDomainDiskSourceDefParse(xmlNodePtr node, char **source, int *proto, size_t *nhosts, - virDomainDiskHostDefPtr *hosts, + virStorageNetHostDefPtr *hosts, virDomainDiskSourcePoolDefPtr *srcpool); bool virDomainHasDiskMirror(virDomainObjPtr vm); @@ -2664,7 +2643,6 @@ VIR_ENUM_DECL(virDomainDiskBus) VIR_ENUM_DECL(virDomainDiskCache) VIR_ENUM_DECL(virDomainDiskErrorPolicy) VIR_ENUM_DECL(virDomainDiskProtocol) -VIR_ENUM_DECL(virDomainDiskProtocolTransport) VIR_ENUM_DECL(virDomainDiskIo) VIR_ENUM_DECL(virDomainDiskSecretType) VIR_ENUM_DECL(virDomainDeviceSGIO) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index ccce46c..9f4ea7f 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -84,9 +84,8 @@ virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDefPtr disk) { VIR_FREE(disk->name); VIR_FREE(disk->file); - while (disk->nhosts) - virDomainDiskHostDefClear(&disk->hosts[--disk->nhosts]); - VIR_FREE(disk->hosts); + virStorageNetHostDefFree(disk->nhosts, disk->hosts); + disk->nhosts = 0; } void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def) diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index 59c6d92..fc73438 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -1,7 +1,7 @@ /* * snapshot_conf.h: domain snapshot XML processing * - * Copyright (C) 2006-2013 Red Hat, Inc. + * Copyright (C) 2006-2014 Red Hat, Inc. * Copyright (C) 2006-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -56,7 +56,7 @@ struct _virDomainSnapshotDiskDef { int format; /* enum virStorageFileFormat */ int protocol; /* network source protocol */ size_t nhosts; /* network source hosts count */ - virDomainDiskHostDefPtr hosts; /* network source hosts */ + virStorageNetHostDefPtr hosts; /* network source hosts */ }; /* Stores the complete snapshot metadata */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 74b8a7e..64c63ff 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -203,17 +203,12 @@ virDomainDiskGetDriver; virDomainDiskGetFormat; virDomainDiskGetSource; virDomainDiskGetType; -virDomainDiskHostDefClear; -virDomainDiskHostDefCopy; -virDomainDiskHostDefFree; virDomainDiskIndexByName; virDomainDiskInsert; virDomainDiskInsertPreAlloced; virDomainDiskIoTypeFromString; virDomainDiskIoTypeToString; virDomainDiskPathByName; -virDomainDiskProtocolTransportTypeFromString; -virDomainDiskProtocolTransportTypeToString; virDomainDiskProtocolTypeToString; virDomainDiskRemove; virDomainDiskRemoveByName; @@ -1841,6 +1836,11 @@ virStorageFileIsSharedFSType; virStorageFileProbeFormat; virStorageFileProbeFormatFromBuf; virStorageFileResize; +virStorageNetHostDefClear; +virStorageNetHostDefCopy; +virStorageNetHostDefFree; +virStorageNetHostTransportTypeFromString; +virStorageNetHostTransportTypeToString; # util/virstring.h diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9a314bf..c43a0f7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3285,7 +3285,7 @@ static int qemuAddRBDHost(virDomainDiskDefPtr disk, char *hostport) if (!disk->src.hosts[disk->src.nhosts-1].name) goto error; - disk->src.hosts[disk->src.nhosts-1].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; + disk->src.hosts[disk->src.nhosts-1].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; disk->src.hosts[disk->src.nhosts-1].socket = NULL; return 0; @@ -3388,9 +3388,9 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, } if (!transp) { - def->src.hosts->transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; + def->src.hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; } else { - def->src.hosts->transport = virDomainDiskProtocolTransportTypeFromString(transp); + def->src.hosts->transport = virStorageNetHostTransportTypeFromString(transp); if (def->src.hosts->transport < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid %s transport type '%s'"), scheme, transp); @@ -3399,7 +3399,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, } def->src.nhosts = 0; /* set to 1 once everything succeeds */ - if (def->src.hosts->transport != VIR_DOMAIN_DISK_PROTO_TRANS_UNIX) { + if (def->src.hosts->transport != VIR_STORAGE_NET_HOST_TRANS_UNIX) { if (VIR_STRDUP(def->src.hosts->name, uri->server) < 0) goto error; @@ -3447,7 +3447,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, return ret; error: - virDomainDiskHostDefClear(def->src.hosts); + virStorageNetHostDefClear(def->src.hosts); VIR_FREE(def->src.hosts); goto cleanup; } @@ -3492,7 +3492,7 @@ qemuParseISCSIString(virDomainDiskDefPtr def) static int qemuParseNBDString(virDomainDiskDefPtr disk) { - virDomainDiskHostDefPtr h = NULL; + virStorageNetHostDefPtr h = NULL; char *host, *port; char *src; @@ -3513,7 +3513,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk) if (src) *src++ = '\0'; - h->transport = VIR_DOMAIN_DISK_PROTO_TRANS_UNIX; + h->transport = VIR_STORAGE_NET_HOST_TRANS_UNIX; if (VIR_STRDUP(h->socket, host + strlen("unix:")) < 0) goto error; } else { @@ -3550,7 +3550,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk) return 0; error: - virDomainDiskHostDefClear(h); + virStorageNetHostDefClear(h); VIR_FREE(h); return -1; } @@ -3615,7 +3615,7 @@ char * qemuBuildNetworkDriveURI(int protocol, const char *src, size_t nhosts, - virDomainDiskHostDefPtr hosts, + virStorageNetHostDefPtr hosts, const char *username, const char *secret) { @@ -3634,23 +3634,23 @@ qemuBuildNetworkDriveURI(int protocol, } if (!((hosts->name && strchr(hosts->name, ':')) || - (hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP && + (hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP && !hosts->name) || - (hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX && + (hosts->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX && hosts->socket && hosts->socket[0] != '/'))) { virBufferAddLit(&buf, "nbd:"); switch (hosts->transport) { - case VIR_DOMAIN_DISK_PROTO_TRANS_TCP: + case VIR_STORAGE_NET_HOST_TRANS_TCP: virBufferStrcat(&buf, hosts->name, NULL); virBufferAsprintf(&buf, ":%s", hosts->port ? hosts->port : QEMU_DEFAULT_NBD_PORT); break; - case VIR_DOMAIN_DISK_PROTO_TRANS_UNIX: + case VIR_STORAGE_NET_HOST_TRANS_UNIX: if (!hosts->socket) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("socket attribute required for " @@ -3664,7 +3664,7 @@ qemuBuildNetworkDriveURI(int protocol, default: virReportError(VIR_ERR_INTERNAL_ERROR, _("nbd does not support transport '%s'"), - virDomainDiskProtocolTransportTypeToString(hosts->transport)); + virStorageNetHostTransportTypeToString(hosts->transport)); goto cleanup; } @@ -3699,14 +3699,14 @@ qemuBuildNetworkDriveURI(int protocol, if (VIR_ALLOC(uri) < 0) goto cleanup; - if (hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP) { + if (hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) { if (VIR_STRDUP(uri->scheme, virDomainDiskProtocolTypeToString(protocol)) < 0) goto cleanup; } else { if (virAsprintf(&uri->scheme, "%s+%s", virDomainDiskProtocolTypeToString(protocol), - virDomainDiskProtocolTransportTypeToString(hosts->transport)) < 0) + virStorageNetHostTransportTypeToString(hosts->transport)) < 0) goto cleanup; } @@ -3826,7 +3826,7 @@ qemuGetDriveSourceString(int type, const char *src, int protocol, size_t nhosts, - virDomainDiskHostDefPtr hosts, + virStorageNetHostDefPtr hosts, const char *username, const char *secret, char **path) @@ -10274,7 +10274,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, def->src.hosts->name = def->src.path; if (VIR_STRDUP(def->src.hosts->port, port) < 0) goto error; - def->src.hosts->transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; + def->src.hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; def->src.hosts->socket = NULL; if (VIR_STRDUP(def->src.path, vdi) < 0) goto error; @@ -12070,7 +12070,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps, VIR_FREE(hosts); goto error; } - first_rbd_disk->src.hosts[first_rbd_disk->src.nhosts].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; + first_rbd_disk->src.hosts[first_rbd_disk->src.nhosts].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; first_rbd_disk->src.hosts[first_rbd_disk->src.nhosts].socket = NULL; first_rbd_disk->src.nhosts++; diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 50dc4a0..ea3ff8b 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -1,7 +1,7 @@ /* * qemu_command.h: QEMU command generation * - * Copyright (C) 2006-2013 Red Hat, Inc. + * Copyright (C) 2006-2014 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -185,7 +185,7 @@ char * qemuBuildRedirdevDevStr(virDomainDefPtr def, char *qemuBuildNetworkDriveURI(int proto, const char *src, size_t nhosts, - virDomainDiskHostDefPtr hosts, + virStorageNetHostDefPtr hosts, const char *username, const char *secret); @@ -318,7 +318,7 @@ int qemuGetDriveSourceString(int type, const char *src, int protocol, size_t nhosts, - virDomainDiskHostDefPtr hosts, + virStorageNetHostDefPtr hosts, const char *username, const char *secret, char **path); diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index dc9b3ae..78ab02a 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1192,7 +1192,7 @@ qemuAddISCSIPoolSourceHost(virDomainDiskDefPtr def, /* Storage pool have not supported these 2 attributes yet, * use the defaults. */ - def->src.hosts[0].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP; + def->src.hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; def->src.hosts[0].socket = NULL; def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_ISCSI; @@ -1309,7 +1309,7 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, } VIR_FREE(def->src.path); - virDomainDiskHostDefFree(def->src.nhosts, def->src.hosts); + virStorageNetHostDefFree(def->src.nhosts, def->src.hosts); virDomainDiskAuthClear(&def->src); switch ((enum virStoragePoolType) pooldef->type) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b032441..60dbb7f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12748,8 +12748,8 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, char *device = NULL; char *source = NULL; char *newsource = NULL; - virDomainDiskHostDefPtr newhosts = NULL; - virDomainDiskHostDefPtr persistHosts = NULL; + virStorageNetHostDefPtr newhosts = NULL; + virStorageNetHostDefPtr persistHosts = NULL; int format = snap->format; const char *formatStr = NULL; char *persistSource = NULL; @@ -12815,11 +12815,11 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, case VIR_DOMAIN_DISK_TYPE_NETWORK: switch (snap->protocol) { case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: - if (!(newhosts = virDomainDiskHostDefCopy(snap->nhosts, snap->hosts))) + if (!(newhosts = virStorageNetHostDefCopy(snap->nhosts, snap->hosts))) goto cleanup; if (persistDisk && - !(persistHosts = virDomainDiskHostDefCopy(snap->nhosts, snap->hosts))) + !(persistHosts = virStorageNetHostDefCopy(snap->nhosts, snap->hosts))) goto cleanup; break; @@ -12870,7 +12870,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, need_unlink = false; VIR_FREE(disk->src.path); - virDomainDiskHostDefFree(disk->src.nhosts, disk->src.hosts); + virStorageNetHostDefFree(disk->src.nhosts, disk->src.hosts); disk->src.path = newsource; disk->src.format = format; @@ -12884,7 +12884,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, if (persistDisk) { VIR_FREE(persistDisk->src.path); - virDomainDiskHostDefFree(persistDisk->src.nhosts, + virStorageNetHostDefFree(persistDisk->src.nhosts, persistDisk->src.hosts); persistDisk->src.path = persistSource; @@ -12906,8 +12906,8 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, VIR_FREE(source); VIR_FREE(newsource); VIR_FREE(persistSource); - virDomainDiskHostDefFree(snap->nhosts, newhosts); - virDomainDiskHostDefFree(snap->nhosts, persistHosts); + virStorageNetHostDefFree(snap->nhosts, newhosts); + virStorageNetHostDefFree(snap->nhosts, persistHosts); return ret; } @@ -12947,9 +12947,9 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver, disk->src.format = origdisk->src.format; disk->src.type = origdisk->src.type; disk->src.protocol = origdisk->src.protocol; - virDomainDiskHostDefFree(disk->src.nhosts, disk->src.hosts); + virStorageNetHostDefFree(disk->src.nhosts, disk->src.hosts); disk->src.nhosts = origdisk->src.nhosts; - disk->src.hosts = virDomainDiskHostDefCopy(origdisk->src.nhosts, + disk->src.hosts = virStorageNetHostDefCopy(origdisk->src.nhosts, origdisk->src.hosts); if (persistDisk) { VIR_FREE(persistDisk->src.path); @@ -12958,10 +12958,10 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver, persistDisk->src.format = origdisk->src.format; persistDisk->src.type = origdisk->src.type; persistDisk->src.protocol = origdisk->src.protocol; - virDomainDiskHostDefFree(persistDisk->src.nhosts, + virStorageNetHostDefFree(persistDisk->src.nhosts, persistDisk->src.hosts); persistDisk->src.nhosts = origdisk->src.nhosts; - persistDisk->src.hosts = virDomainDiskHostDefCopy(origdisk->src.nhosts, + persistDisk->src.hosts = virStorageNetHostDefCopy(origdisk->src.nhosts, origdisk->src.hosts); } diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c index 9a6180e..84c5fe2 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -1,7 +1,7 @@ /* * storage_backend_gluster.c: storage backend for Gluster handling * - * Copyright (C) 2013 Red Hat, Inc. + * Copyright (C) 2013-2014 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 @@ -509,7 +509,7 @@ static int virStorageFileBackendGlusterInit(virStorageFilePtr file) { virStorageFileBackendGlusterPrivPtr priv = NULL; - virDomainDiskHostDefPtr host = &(file->hosts[0]); + virStorageNetHostDefPtr host = &(file->hosts[0]); const char *hostname = host->name; int port = 0; @@ -540,7 +540,7 @@ virStorageFileBackendGlusterInit(virStorageFilePtr file) goto error; } - if (host->transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX) + if (host->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX) hostname = host->socket; @@ -550,7 +550,7 @@ virStorageFileBackendGlusterInit(virStorageFilePtr file) } if (glfs_set_volfile_server(priv->vol, - virDomainDiskProtocolTransportTypeToString(host->transport), + virStorageNetHostTransportTypeToString(host->transport), hostname, port) < 0) { virReportSystemError(errno, _("failed to set gluster volfile server '%s'"), diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 70a122d..cdb8536 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2742,7 +2742,7 @@ virStorageFileFree(virStorageFilePtr file) file->backend->backendDeinit(file); VIR_FREE(file->path); - virDomainDiskHostDefFree(file->nhosts, file->hosts); + virStorageNetHostDefFree(file->nhosts, file->hosts); VIR_FREE(file); } @@ -2752,7 +2752,7 @@ virStorageFileInitInternal(int type, const char *path, int protocol, size_t nhosts, - virDomainDiskHostDefPtr hosts) + virStorageNetHostDefPtr hosts) { virStorageFilePtr file = NULL; @@ -2766,7 +2766,7 @@ virStorageFileInitInternal(int type, if (VIR_STRDUP(file->path, path) < 0) goto error; - if (!(file->hosts = virDomainDiskHostDefCopy(nhosts, hosts))) + if (!(file->hosts = virStorageNetHostDefCopy(nhosts, hosts))) goto error; if (!(file->backend = virStorageFileBackendForType(file->type, @@ -2781,7 +2781,7 @@ virStorageFileInitInternal(int type, error: VIR_FREE(file->path); - virDomainDiskHostDefFree(file->nhosts, file->hosts); + virStorageNetHostDefFree(file->nhosts, file->hosts); VIR_FREE(file); return NULL; } diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h index 993bba5..886a4d5 100644 --- a/src/storage/storage_driver.h +++ b/src/storage/storage_driver.h @@ -42,7 +42,7 @@ struct _virStorageFile { int protocol; size_t nhosts; - virDomainDiskHostDefPtr hosts; + virStorageNetHostDefPtr hosts; }; virStorageFilePtr diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index c7384d1..320473d 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1,7 +1,7 @@ /* * virstoragefile.c: file utility functions for FS storage backend * - * Copyright (C) 2007-2013 Red Hat, Inc. + * Copyright (C) 2007-2014 Red Hat, Inc. * Copyright (C) 2007-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -66,6 +66,13 @@ VIR_ENUM_IMPL(virStorageFileFeature, "lazy_refcounts", ) + +VIR_ENUM_IMPL(virStorageNetHostTransport, VIR_STORAGE_NET_HOST_TRANS_LAST, + "tcp", + "unix", + "rdma") + + enum lv_endian { LV_LITTLE_ENDIAN = 1, /* 1234 */ LV_BIG_ENDIAN /* 4321 */ @@ -1556,3 +1563,65 @@ virStorageFileChainLookup(virStorageFileMetadataPtr chain, const char *start, *meta = NULL; return NULL; } + + +void +virStorageNetHostDefClear(virStorageNetHostDefPtr def) +{ + if (!def) + return; + + VIR_FREE(def->name); + VIR_FREE(def->port); + VIR_FREE(def->socket); +} + + +void +virStorageNetHostDefFree(size_t nhosts, + virStorageNetHostDefPtr hosts) +{ + size_t i; + + if (!hosts) + return; + + for (i = 0; i < nhosts; i++) + virStorageNetHostDefClear(&hosts[i]); + + VIR_FREE(hosts); +} + + +virStorageNetHostDefPtr +virStorageNetHostDefCopy(size_t nhosts, + virStorageNetHostDefPtr hosts) +{ + virStorageNetHostDefPtr ret = NULL; + size_t i; + + if (VIR_ALLOC_N(ret, nhosts) < 0) + goto error; + + for (i = 0; i < nhosts; i++) { + virStorageNetHostDefPtr src = &hosts[i]; + virStorageNetHostDefPtr dst = &ret[i]; + + dst->transport = src->transport; + + if (VIR_STRDUP(dst->name, src->name) < 0) + goto error; + + if (VIR_STRDUP(dst->port, src->port) < 0) + goto error; + + if (VIR_STRDUP(dst->socket, src->socket) < 0) + goto error; + } + + return ret; + + error: + virStorageNetHostDefFree(nhosts, ret); + return NULL; +} diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 7bd2fe0..7b8a7f7 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -1,7 +1,7 @@ /* * virstoragefile.h: file utility functions for FS storage backend * - * Copyright (C) 2007-2009, 2012-2013 Red Hat, Inc. + * Copyright (C) 2007-2009, 2012-2014 Red Hat, Inc. * Copyright (C) 2007-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -83,6 +83,28 @@ struct _virStorageFileMetadata { char *compat; }; + +/* Information related to network storage */ +enum virStorageNetHostTransport { + VIR_STORAGE_NET_HOST_TRANS_TCP, + VIR_STORAGE_NET_HOST_TRANS_UNIX, + VIR_STORAGE_NET_HOST_TRANS_RDMA, + + VIR_STORAGE_NET_HOST_TRANS_LAST +}; + +VIR_ENUM_DECL(virStorageNetHostTransport) + +typedef struct _virStorageNetHostDef virStorageNetHostDef; +typedef virStorageNetHostDef *virStorageNetHostDefPtr; +struct _virStorageNetHostDef { + char *name; + char *port; + int transport; /* enum virStorageNetHostTransport */ + char *socket; /* path to unix socket */ +}; + + # ifndef DEV_BSIZE # define DEV_BSIZE 512 # endif @@ -138,4 +160,10 @@ int virStorageFileGetLVMKey(const char *path, int virStorageFileGetSCSIKey(const char *path, char **key); +void virStorageNetHostDefClear(virStorageNetHostDefPtr def); +void virStorageNetHostDefFree(size_t nhosts, virStorageNetHostDefPtr hosts); +virStorageNetHostDefPtr virStorageNetHostDefCopy(size_t nhosts, + virStorageNetHostDefPtr hosts); + + #endif /* __VIR_STORAGE_FILE_H__ */ -- 1.8.5.3

On 03/27/14 00:09, Eric Blake wrote:
Continuing the refactoring of host-side storage descriptions out of conf/domain_conf and into util/virstoragefile, this patch focuses on details about a host name/port/transport as used by a network storage volume.
* src/conf/domain_conf.h (virDomainDiskProtocolTransport) (virDomainDiskHostDef, virDomainDiskHostDefClear) (virDomainDiskHostDefFree, virDomainDiskHostDefCopy): Move... * src/util/virstoragefile.h (virStorageNetHostTransport) (virStorageNetHostDef, virStorageNetHostDefClear) (virStorageNetHostDefFree, virStorageNetHostDefCopy): ...here, with better names. * src/util/virstoragefile.c (virStorageNetHostDefClear) (virStorageNetHostDefFree, virStorageNetHostDefCopy): Moved from... * src/conf/domain_conf.c (virDomainDiskHostDefClear) (virDomainDiskHostDefFree, virDomainDiskHostDefCopy): ...here. (virDomainDiskSourceDefClear, virDomainDiskSourceDefParse) (virDomainDiskSourceDefFormatInternal): Adjust callers. * src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise. * src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear): Likewise. * src/qemu/qemu_command.c (qemuAddRBDHost) (qemuParseDriveURIString, qemuParseNBDString) (qemuBuildNetworkDriveURI, qemuParseCommandLineDisk) (qemuParseCommandLine, qemuGetDriveSourceString): Likewise. * src/qemu/qemu_command.h: Likewise. * src/qemu/qemu_conf.c (qemuAddISCSIPoolSourceHost) (qemuTranslateDiskSourcePool): Likewise. * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateSingleDiskActive) (qemuDomainSnapshotUndoSingleDiskActive): Likewise. * src/storage/storage_backend_gluster.c (virStorageFileBackendGlusterInit): Likewise. * src/storage/storage_driver.c (virStorageFileFree) (virStorageFileInitInternal): Likewise. * src/storage/storage_driver.h (_virStorageFile): Likewise. * src/libvirt_private.syms (domain_conf.h): Move symbols... (virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 88 +++++------------------------------ src/conf/domain_conf.h | 28 ++--------- src/conf/snapshot_conf.c | 5 +- src/conf/snapshot_conf.h | 4 +- src/libvirt_private.syms | 10 ++-- src/qemu/qemu_command.c | 38 +++++++-------- src/qemu/qemu_command.h | 6 +-- src/qemu/qemu_conf.c | 4 +- src/qemu/qemu_driver.c | 24 +++++----- src/storage/storage_backend_gluster.c | 8 ++-- src/storage/storage_driver.c | 8 ++-- src/storage/storage_driver.h | 2 +- src/util/virstoragefile.c | 71 +++++++++++++++++++++++++++- src/util/virstoragefile.h | 30 +++++++++++- 14 files changed, 167 insertions(+), 159 deletions(-)
Unpleasant amount of fallout from these changes :/.. ACK Peter

A continuation of the migration of disk details to virstoragefile. This patch moves a single enum, but converting the name has quite a bit of fallout. * src/conf/domain_conf.h (virDomainDiskType): Move... * src/util/virstoragefile.h (virStorageType): ...and rename. * src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr) (virBhyveProcessBuildLoadCmd): Update clients. * src/conf/domain_conf.c (virDomainDiskSourceDefParse) (virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal) (virDomainDiskDefFormat, virDomainDiskGetActualType) (virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType): Likewise. * src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise. * src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML) (virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat): Likewise. * src/esx/esx_driver.c (esxAutodetectSCSIControllerModel) (esxDomainDefineXML): Likewise. * src/locking/domain_lock.c (virDomainLockManagerAddDisk): Likewise. * src/lxc/lxc_controller.c (virLXCControllerSetupLoopDeviceDisk) (virLXCControllerSetupNBDDeviceDisk) (virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk): Likewise. * src/parallels/parallels_driver.c (parallelsGetHddInfo): Likewise. * src/phyp/phyp_driver.c (phypDiskType): Likewise. * src/qemu/qemu_command.c (qemuGetDriveSourceString) (qemuDomainDiskGetSourceString, qemuBuildDriveStr) (qemuBuildCommandLine, qemuParseCommandLineDisk) (qemuParseCommandLine): Likewise. * src/qemu/qemu_conf.c (qemuCheckSharedDevice) (qemuTranslateDiskSourcePool) (qemuTranslateSnapshotDiskSourcePool): Likewise. * src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse) (qemuDomainDetermineDiskChain): Likewise. * src/qemu/qemu_driver.c (qemuDomainGetBlockInfo) (qemuDomainSnapshotPrepareDiskExternalBackingInactive) (qemuDomainSnapshotPrepareDiskExternalBackingActive) (qemuDomainSnapshotPrepareDiskExternalOverlayActive) (qemuDomainSnapshotPrepareDiskExternalOverlayInactive) (qemuDomainSnapshotPrepareDiskInternal) (qemuDomainSnapshotPrepare) (qemuDomainSnapshotCreateSingleDiskActive): Likewise. * src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia): Likewise. * src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise. * src/security/security_apparmor.c (AppArmorRestoreSecurityImageLabel) (AppArmorSetSecurityImageLabel): Likewise. * src/security/security_dac.c (virSecurityDACSetSecurityImageLabel) (virSecurityDACRestoreSecurityImageLabelInt) (virSecurityDACSetSecurityAllLabel): Likewise. * src/security/security_selinux.c (virSecuritySELinuxRestoreSecurityImageLabelInt) (virSecuritySELinuxSetSecurityImageLabel) (virSecuritySELinuxSetSecurityAllLabel): Likewise. * src/storage/storage_backend.c (virStorageFileBackendForType): Likewise. * src/storage/storage_backend_fs.c (virStorageFileBackendFile) (virStorageFileBackendBlock): Likewise. * src/storage/storage_backend_gluster.c (virStorageFileBackendGluster): Likewise. * src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives) (vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise. * src/vmware/vmware_conf.c (vmwareVmxPath): Likewise. * src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk) (virVMXFormatFloppy): Likewise. * src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr) (xenFormatSxprDisk): Likewise. * src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise. * tests/securityselinuxlabeltest.c (testSELinuxLoadDef): Likewise. * src/libvirt_private.syms (domain_conf.h): Move symbols... (virstoragefile.h): ...as appropriate. Signed-off-by: Eric Blake <eblake@redhat.com> --- The fallout is once again rather longer than I would like. And given that there is more to come, I'm not going to push this until after the 1.2.3 release. Peter, let me know if I should post these in a repo somewhere to make it easier for you to rebase your pending gluster patches on top of this. src/bhyve/bhyve_command.c | 4 +- src/conf/domain_conf.c | 51 ++++++++++------------- src/conf/domain_conf.h | 18 ++------ src/conf/snapshot_conf.c | 16 +++---- src/conf/snapshot_conf.h | 2 +- src/esx/esx_driver.c | 4 +- src/libvirt_private.syms | 4 +- src/locking/domain_lock.c | 6 +-- src/lxc/lxc_controller.c | 8 ++-- src/parallels/parallels_driver.c | 4 +- src/phyp/phyp_driver.c | 4 +- src/qemu/qemu_command.c | 72 ++++++++++++++++---------------- src/qemu/qemu_conf.c | 16 +++---- src/qemu/qemu_domain.c | 12 +++--- src/qemu/qemu_driver.c | 78 +++++++++++++++++------------------ src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_migration.c | 4 +- src/security/security_apparmor.c | 6 +-- src/security/security_dac.c | 6 +-- src/security/security_selinux.c | 6 +-- src/storage/storage_backend.c | 8 ++-- src/storage/storage_backend_fs.c | 4 +- src/storage/storage_backend_gluster.c | 2 +- src/util/virstoragefile.c | 7 ++++ src/util/virstoragefile.h | 15 +++++++ src/vbox/vbox_tmpl.c | 38 ++++++++--------- src/vmware/vmware_conf.c | 2 +- src/vmx/vmx.c | 38 ++++++++--------- src/xenxs/xen_sxpr.c | 18 ++++---- src/xenxs/xen_xm.c | 12 +++--- tests/securityselinuxlabeltest.c | 4 +- 31 files changed, 238 insertions(+), 233 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 3373cfc..139c7e2 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -148,7 +148,7 @@ bhyveBuildDiskArgStr(const virDomainDef *def, virCommandPtr cmd) return -1; } - if (virDomainDiskGetType(disk) != VIR_DOMAIN_DISK_TYPE_FILE) { + if (virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_FILE) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unsupported disk type")); return -1; @@ -252,7 +252,7 @@ virBhyveProcessBuildLoadCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED, return NULL; } - if (virDomainDiskGetType(disk) != VIR_DOMAIN_DISK_TYPE_FILE) { + if (virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_FILE) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unsupported disk type")); return NULL; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 159a9c3..8c49d58 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -219,13 +219,6 @@ VIR_ENUM_IMPL(virDomainDeviceAddress, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST, "virtio-mmio", "isa") -VIR_ENUM_IMPL(virDomainDisk, VIR_DOMAIN_DISK_TYPE_LAST, - "block", - "file", - "dir", - "network", - "volume") - VIR_ENUM_IMPL(virDomainDiskDevice, VIR_DOMAIN_DISK_DEVICE_LAST, "disk", "cdrom", @@ -1294,7 +1287,7 @@ virDomainDiskSetType(virDomainDiskDefPtr def, int type) int virDomainDiskGetActualType(virDomainDiskDefPtr def) { - if (def->src.type == VIR_DOMAIN_DISK_TYPE_VOLUME && def->src.srcpool) + if (def->src.type == VIR_STORAGE_TYPE_VOLUME && def->src.srcpool) return def->src.srcpool->actualtype; return def->src.type; @@ -5048,16 +5041,16 @@ virDomainDiskSourceDefParse(xmlNodePtr node, memset(&host, 0, sizeof(host)); switch (type) { - case VIR_DOMAIN_DISK_TYPE_FILE: + case VIR_STORAGE_TYPE_FILE: *source = virXMLPropString(node, "file"); break; - case VIR_DOMAIN_DISK_TYPE_BLOCK: + case VIR_STORAGE_TYPE_BLOCK: *source = virXMLPropString(node, "dev"); break; - case VIR_DOMAIN_DISK_TYPE_DIR: + case VIR_STORAGE_TYPE_DIR: *source = virXMLPropString(node, "dir"); break; - case VIR_DOMAIN_DISK_TYPE_NETWORK: + case VIR_STORAGE_TYPE_NETWORK: if (!(protocol = virXMLPropString(node, "protocol"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing network source protocol type")); @@ -5131,14 +5124,14 @@ virDomainDiskSourceDefParse(xmlNodePtr node, child = child->next; } break; - case VIR_DOMAIN_DISK_TYPE_VOLUME: + case VIR_STORAGE_TYPE_VOLUME: if (virDomainDiskSourcePoolDefParse(node, srcpool) < 0) goto cleanup; break; default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected disk type %s"), - virDomainDiskTypeToString(type)); + virStorageTypeToString(type)); goto cleanup; } @@ -5232,13 +5225,13 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, type = virXMLPropString(node, "type"); if (type) { - if ((def->src.type = virDomainDiskTypeFromString(type)) < 0) { + if ((def->src.type = virStorageTypeFromString(type)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk type '%s'"), type); goto error; } } else { - def->src.type = VIR_DOMAIN_DISK_TYPE_FILE; + def->src.type = VIR_STORAGE_TYPE_FILE; } snapshot = virXMLPropString(node, "snapshot"); @@ -5261,7 +5254,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, &def->src.srcpool) < 0) goto error; - if (def->src.type == VIR_DOMAIN_DISK_TYPE_NETWORK) { + if (def->src.type == VIR_STORAGE_TYPE_NETWORK) { if (def->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_ISCSI) expected_secret_usage = VIR_SECRET_USAGE_TYPE_ISCSI; else if (def->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD) @@ -5857,7 +5850,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } - if (def->src.type == VIR_DOMAIN_DISK_TYPE_NETWORK) { + if (def->src.type == VIR_STORAGE_TYPE_NETWORK) { virReportError(VIR_ERR_XML_ERROR, _("Setting disk %s is not allowed for " "disk of network type"), @@ -14791,7 +14784,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, if (src || nhosts > 0 || srcpool || startupPolicy) { switch (type) { - case VIR_DOMAIN_DISK_TYPE_FILE: + case VIR_STORAGE_TYPE_FILE: virBufferAddLit(buf, "<source"); virBufferEscapeString(buf, " file='%s'", src); virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); @@ -14799,7 +14792,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, virDomainDiskSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags); break; - case VIR_DOMAIN_DISK_TYPE_BLOCK: + case VIR_STORAGE_TYPE_BLOCK: virBufferAddLit(buf, "<source"); virBufferEscapeString(buf, " dev='%s'", src); virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); @@ -14807,14 +14800,14 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, virDomainDiskSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags); break; - case VIR_DOMAIN_DISK_TYPE_DIR: + case VIR_STORAGE_TYPE_DIR: virBufferAddLit(buf, "<source"); virBufferEscapeString(buf, " dir='%s'", src); virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); virBufferAddLit(buf, "/>\n"); break; - case VIR_DOMAIN_DISK_TYPE_NETWORK: + case VIR_STORAGE_TYPE_NETWORK: virBufferAsprintf(buf, "<source protocol='%s'", virDomainDiskProtocolTypeToString(protocol)); virBufferEscapeString(buf, " name='%s'", src); @@ -14842,7 +14835,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, } break; - case VIR_DOMAIN_DISK_TYPE_VOLUME: + case VIR_STORAGE_TYPE_VOLUME: virBufferAddLit(buf, "<source"); if (srcpool) { @@ -14860,7 +14853,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected disk type %s"), - virDomainDiskTypeToString(type)); + virStorageTypeToString(type)); return -1; } } @@ -14893,7 +14886,7 @@ virDomainDiskDefFormat(virBufferPtr buf, virDomainDiskDefPtr def, unsigned int flags) { - const char *type = virDomainDiskTypeToString(def->src.type); + const char *type = virStorageTypeToString(def->src.type); const char *device = virDomainDiskDeviceTypeToString(def->device); const char *bus = virDomainDiskBusTypeToString(def->bus); const char *cachemode = virDomainDiskCacheTypeToString(def->cachemode); @@ -18546,8 +18539,8 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk, const char *path = virDomainDiskGetSource(disk); int type = virDomainDiskGetType(disk); - if (!path || type == VIR_DOMAIN_DISK_TYPE_NETWORK || - (type == VIR_DOMAIN_DISK_TYPE_VOLUME && + if (!path || type == VIR_STORAGE_TYPE_NETWORK || + (type == VIR_STORAGE_TYPE_VOLUME && disk->src.srcpool && disk->src.srcpool->mode == VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT)) return 0; @@ -19397,13 +19390,13 @@ virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def) if (!virDomainDiskGetSource(def)) return false; - if (virDomainDiskGetType(def) == VIR_DOMAIN_DISK_TYPE_BLOCK) + if (virDomainDiskGetType(def) == VIR_STORAGE_TYPE_BLOCK) return true; /* For volume types, check the srcpool. * If it's a block type source pool, then it's possible */ - if (virDomainDiskGetType(def) == VIR_DOMAIN_DISK_TYPE_VOLUME && + if (virDomainDiskGetType(def) == VIR_STORAGE_TYPE_VOLUME && def->src.srcpool && def->src.srcpool->voltype == VIR_STORAGE_VOL_BLOCK) { /* We don't think the volume accessed by remote URI is diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index cbf2dca..247b2f8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -462,18 +462,9 @@ struct _virDomainHostdevDef { virDomainDeviceInfoPtr info; /* Guest address */ }; -/* Types of disk backends (host resource) */ -enum virDomainDiskType { - VIR_DOMAIN_DISK_TYPE_BLOCK, - VIR_DOMAIN_DISK_TYPE_FILE, - VIR_DOMAIN_DISK_TYPE_DIR, - VIR_DOMAIN_DISK_TYPE_NETWORK, - VIR_DOMAIN_DISK_TYPE_VOLUME, - VIR_DOMAIN_DISK_TYPE_LAST -}; - -/* Types of disk frontend (guest view) */ +/* Types of disk frontend (guest view). For backends (host view), see + * virStorageType in util/virstoragefile.h */ enum virDomainDiskDevice { VIR_DOMAIN_DISK_DEVICE_DISK, VIR_DOMAIN_DISK_DEVICE_CDROM, @@ -651,7 +642,7 @@ struct _virDomainDiskSourcePoolDef { char *volume; /* volume name */ int voltype; /* enum virStorageVolType, internal only */ int pooltype; /* enum virStoragePoolType, internal only */ - int actualtype; /* enum virDomainDiskType, internal only */ + int actualtype; /* enum virStorageType, internal only */ int mode; /* enum virDomainDiskSourcePoolMode */ }; typedef virDomainDiskSourcePoolDef *virDomainDiskSourcePoolDefPtr; @@ -663,7 +654,7 @@ typedef virDomainDiskSourceDef *virDomainDiskSourceDefPtr; * backing chains, multiple source disks join to form a single guest * view. TODO Move this to util/ */ struct _virDomainDiskSourceDef { - int type; /* enum virDomainDiskType */ + int type; /* enum virStorageType */ char *path; int protocol; /* enum virDomainDiskProtocol */ size_t nhosts; @@ -2636,7 +2627,6 @@ VIR_ENUM_DECL(virDomainLifecycleCrash) VIR_ENUM_DECL(virDomainPMState) VIR_ENUM_DECL(virDomainDevice) VIR_ENUM_DECL(virDomainDeviceAddress) -VIR_ENUM_DECL(virDomainDisk) VIR_ENUM_DECL(virDomainDiskDevice) VIR_ENUM_DECL(virDomainDiskGeometryTrans) VIR_ENUM_DECL(virDomainDiskBus) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 9f4ea7f..ebb3bb4 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -134,15 +134,15 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, } if ((type = virXMLPropString(node, "type"))) { - if ((def->type = virDomainDiskTypeFromString(type)) < 0 || - def->type == VIR_DOMAIN_DISK_TYPE_VOLUME || - def->type == VIR_DOMAIN_DISK_TYPE_DIR) { + if ((def->type = virStorageTypeFromString(type)) < 0 || + def->type == VIR_STORAGE_TYPE_VOLUME || + def->type == VIR_STORAGE_TYPE_DIR) { virReportError(VIR_ERR_XML_ERROR, _("unknown disk snapshot type '%s'"), type); goto cleanup; } } else { - def->type = VIR_DOMAIN_DISK_TYPE_FILE; + def->type = VIR_STORAGE_TYPE_FILE; } for (cur = node->children; cur; cur = cur->next) { @@ -543,7 +543,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, goto cleanup; disk->index = i; disk->snapshot = def->dom->disks[i]->snapshot; - disk->type = VIR_DOMAIN_DISK_TYPE_FILE; + disk->type = VIR_STORAGE_TYPE_FILE; if (!disk->snapshot) disk->snapshot = default_snapshot; } @@ -561,11 +561,11 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, const char *tmp; struct stat sb; - if (disk->type != VIR_DOMAIN_DISK_TYPE_FILE) { + if (disk->type != VIR_STORAGE_TYPE_FILE) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("cannot generate external snapshot name " "for disk '%s' on a '%s' device"), - disk->name, virDomainDiskTypeToString(disk->type)); + disk->name, virStorageTypeToString(disk->type)); goto cleanup; } @@ -629,7 +629,7 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf, return; } - virBufferAsprintf(buf, " type='%s'>\n", virDomainDiskTypeToString(type)); + virBufferAsprintf(buf, " type='%s'>\n", virStorageTypeToString(type)); virBufferAdjustIndent(buf, 2); if (disk->format > 0) diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index fc73438..f6fec88 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -51,7 +51,7 @@ struct _virDomainSnapshotDiskDef { char *name; /* name matching the <target dev='...' of the domain */ int index; /* index within snapshot->dom->disks that matches name */ int snapshot; /* enum virDomainSnapshotLocation */ - int type; /* enum virDomainDiskType */ + int type; /* enum virStorageType */ char *file; /* new source file when snapshot is external */ int format; /* enum virStorageFileFormat */ int protocol; /* network source protocol */ diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index ff44881..5b12bd4 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -389,7 +389,7 @@ esxAutodetectSCSIControllerModel(virDomainDiskDefPtr def, int *model, if (def->device != VIR_DOMAIN_DISK_DEVICE_DISK || def->bus != VIR_DOMAIN_DISK_BUS_SCSI || - virDomainDiskGetType(def) != VIR_DOMAIN_DISK_TYPE_FILE || + virDomainDiskGetType(def) != VIR_STORAGE_TYPE_FILE || !src || !STRPREFIX(src, "[")) { /* * This isn't a file-based SCSI disk device with a datastore related @@ -3122,7 +3122,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) for (i = 0; i < def->ndisks; ++i) { if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK && - virDomainDiskGetType(def->disks[i]) == VIR_DOMAIN_DISK_TYPE_FILE) { + virDomainDiskGetType(def->disks[i]) == VIR_STORAGE_TYPE_FILE) { disk = def->disks[i]; break; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 96f637d..29b47b7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -217,8 +217,6 @@ virDomainDiskSetFormat; virDomainDiskSetSource; virDomainDiskSetType; virDomainDiskSourceIsBlockType; -virDomainDiskTypeFromString; -virDomainDiskTypeToString; virDomainEmulatorPinAdd; virDomainEmulatorPinDel; virDomainFeatureStateTypeFromString; @@ -1842,6 +1840,8 @@ virStorageNetHostDefCopy; virStorageNetHostDefFree; virStorageNetHostTransportTypeFromString; virStorageNetHostTransportTypeToString; +virStorageTypeFromString; +virStorageTypeToString; # util/virstring.h diff --git a/src/locking/domain_lock.c b/src/locking/domain_lock.c index 01ea441..4b3f4d4 100644 --- a/src/locking/domain_lock.c +++ b/src/locking/domain_lock.c @@ -78,9 +78,9 @@ static int virDomainLockManagerAddDisk(virLockManagerPtr lock, if (!src) return 0; - if (!(type == VIR_DOMAIN_DISK_TYPE_BLOCK || - type == VIR_DOMAIN_DISK_TYPE_FILE || - type == VIR_DOMAIN_DISK_TYPE_DIR)) + if (!(type == VIR_STORAGE_TYPE_BLOCK || + type == VIR_STORAGE_TYPE_FILE || + type == VIR_STORAGE_TYPE_DIR)) return 0; if (disk->readonly) diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 3bc15cc..1d3a74b 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -395,7 +395,7 @@ static int virLXCControllerSetupLoopDeviceDisk(virDomainDiskDefPtr disk) * We now change it into a block device type, so that * the rest of container setup 'just works' */ - virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_BLOCK); + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK); if (virDomainDiskSetSource(disk, loname) < 0) goto cleanup; @@ -465,7 +465,7 @@ static int virLXCControllerSetupNBDDeviceDisk(virDomainDiskDefPtr disk) * We now change it into a block device type, so that * the rest of container setup 'just works' */ - virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_BLOCK); + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK); if (virDomainDiskSetSource(disk, dev) < 0) { VIR_FREE(dev); return -1; @@ -536,7 +536,7 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl) const char *driver = virDomainDiskGetDriver(disk); int format = virDomainDiskGetFormat(disk); - if (virDomainDiskGetType(disk) != VIR_DOMAIN_DISK_TYPE_FILE) + if (virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_FILE) continue; /* If no driverName is set, we prefer 'loop' for @@ -1677,7 +1677,7 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl, mode_t mode; char *tmpsrc = def->src.path; - if (virDomainDiskGetType(def) != VIR_DOMAIN_DISK_TYPE_BLOCK) { + if (virDomainDiskGetType(def) != VIR_STORAGE_TYPE_BLOCK) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Can't setup disk for non-block device")); goto cleanup; diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index c72da0f..a0d5f8c 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -302,7 +302,7 @@ parallelsGetHddInfo(virDomainDefPtr def, disk->device = VIR_DOMAIN_DISK_DEVICE_DISK; if (virJSONValueObjectHasKey(value, "real") == 1) { - virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_BLOCK); + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK); if (!(tmp = virJSONValueObjectGetString(value, "real"))) { parallelsParseError(); @@ -312,7 +312,7 @@ parallelsGetHddInfo(virDomainDefPtr def, if (virDomainDiskSetSource(disk, tmp) < 0) return -1; } else { - virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE); + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); if (!(tmp = virJSONValueObjectGetString(value, "image"))) { parallelsParseError(); diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index d0b0166..fc3e7db 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -3087,9 +3087,9 @@ phypDiskType(virConnectPtr conn, char *backing_device) goto cleanup; if (STREQ(ret, "LVPOOL")) - disk_type = VIR_DOMAIN_DISK_TYPE_BLOCK; + disk_type = VIR_STORAGE_TYPE_BLOCK; else if (STREQ(ret, "FBPOOL")) - disk_type = VIR_DOMAIN_DISK_TYPE_FILE; + disk_type = VIR_STORAGE_TYPE_FILE; cleanup: VIR_FREE(ret); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c43a0f7..b3ad7b1 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3833,10 +3833,10 @@ qemuGetDriveSourceString(int type, { *path = NULL; - switch ((enum virDomainDiskType) type) { - case VIR_DOMAIN_DISK_TYPE_BLOCK: - case VIR_DOMAIN_DISK_TYPE_FILE: - case VIR_DOMAIN_DISK_TYPE_DIR: + switch ((enum virStorageType) type) { + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_FILE: + case VIR_STORAGE_TYPE_DIR: if (!src) return 1; @@ -3845,7 +3845,7 @@ qemuGetDriveSourceString(int type, break; - case VIR_DOMAIN_DISK_TYPE_NETWORK: + case VIR_STORAGE_TYPE_NETWORK: if (!(*path = qemuBuildNetworkDriveURI(protocol, src, nhosts, @@ -3855,8 +3855,8 @@ qemuGetDriveSourceString(int type, return -1; break; - case VIR_DOMAIN_DISK_TYPE_VOLUME: - case VIR_DOMAIN_DISK_TYPE_LAST: + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_LAST: break; } @@ -3874,7 +3874,7 @@ qemuDomainDiskGetSourceString(virConnectPtr conn, *source = NULL; - if (actualType == VIR_DOMAIN_DISK_TYPE_NETWORK && + if (actualType == VIR_STORAGE_TYPE_NETWORK && disk->src.auth.username && (disk->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_ISCSI || disk->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD)) { @@ -4019,7 +4019,7 @@ qemuBuildDriveStr(virConnectPtr conn, virBufferAddLit(&opt, "file="); switch (actualType) { - case VIR_DOMAIN_DISK_TYPE_DIR: + case VIR_STORAGE_TYPE_DIR: /* QEMU only supports magic FAT format for now */ if (disk->src.format > 0 && disk->src.format != VIR_STORAGE_FILE_FAT) { @@ -4042,10 +4042,10 @@ qemuBuildDriveStr(virConnectPtr conn, break; - case VIR_DOMAIN_DISK_TYPE_BLOCK: + case VIR_STORAGE_TYPE_BLOCK: if (disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - disk->src.type == VIR_DOMAIN_DISK_TYPE_VOLUME ? + disk->src.type == VIR_STORAGE_TYPE_VOLUME ? _("tray status 'open' is invalid for block type volume") : _("tray status 'open' is invalid for block type disk")); goto error; @@ -4106,7 +4106,7 @@ qemuBuildDriveStr(virConnectPtr conn, goto error; } if (disk->src.format > 0 && - disk->src.type != VIR_DOMAIN_DISK_TYPE_DIR && + disk->src.type != VIR_STORAGE_TYPE_DIR && virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_FORMAT)) virBufferAsprintf(&opt, ",format=%s", virStorageFileFormatTypeToString(disk->src.format)); @@ -4320,7 +4320,7 @@ qemuBuildDriveDevStr(virDomainDefPtr def, bus); goto error; } - if (disk->src.type == VIR_DOMAIN_DISK_TYPE_NETWORK) { + if (disk->src.type == VIR_STORAGE_TYPE_NETWORK) { if (disk->src.protocol != VIR_DOMAIN_DISK_PROTOCOL_ISCSI) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("disk device='lun' is not supported for protocol='%s'"), @@ -8633,7 +8633,7 @@ qemuBuildCommandLine(virConnectPtr conn, const char *fmt; virDomainDiskDefPtr disk = def->disks[i]; - if ((disk->src.type == VIR_DOMAIN_DISK_TYPE_BLOCK) && + if ((disk->src.type == VIR_STORAGE_TYPE_BLOCK) && (disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("tray status 'open' is invalid for " @@ -8672,7 +8672,7 @@ qemuBuildCommandLine(virConnectPtr conn, } } - if (disk->src.type == VIR_DOMAIN_DISK_TYPE_DIR) { + if (disk->src.type == VIR_STORAGE_TYPE_DIR) { /* QEMU only supports magic FAT format for now */ if (disk->src.format > 0 && disk->src.format != VIR_STORAGE_FILE_FAT) { @@ -8693,7 +8693,7 @@ qemuBuildCommandLine(virConnectPtr conn, if (virAsprintf(&file, fmt, disk->src) < 0) goto error; - } else if (disk->src.type == VIR_DOMAIN_DISK_TYPE_NETWORK) { + } else if (disk->src.type == VIR_STORAGE_TYPE_NETWORK) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("network disks are only supported with -drive")); } else { @@ -10201,7 +10201,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, else def->bus = VIR_DOMAIN_DISK_BUS_IDE; def->device = VIR_DOMAIN_DISK_DEVICE_DISK; - def->src.type = VIR_DOMAIN_DISK_TYPE_FILE; + def->src.type = VIR_STORAGE_TYPE_FILE; for (i = 0; i < nkeywords; i++) { if (STREQ(keywords[i], "file")) { @@ -10209,10 +10209,10 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, def->src.path = values[i]; values[i] = NULL; if (STRPREFIX(def->src.path, "/dev/")) - def->src.type = VIR_DOMAIN_DISK_TYPE_BLOCK; + def->src.type = VIR_STORAGE_TYPE_BLOCK; else if (STRPREFIX(def->src.path, "nbd:") || STRPREFIX(def->src.path, "nbd+")) { - def->src.type = VIR_DOMAIN_DISK_TYPE_NETWORK; + def->src.type = VIR_STORAGE_TYPE_NETWORK; def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_NBD; if (qemuParseNBDString(def) < 0) @@ -10220,7 +10220,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, } else if (STRPREFIX(def->src.path, "rbd:")) { char *p = def->src.path; - def->src.type = VIR_DOMAIN_DISK_TYPE_NETWORK; + def->src.type = VIR_STORAGE_TYPE_NETWORK; def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_RBD; if (VIR_STRDUP(def->src.path, p + strlen("rbd:")) < 0) goto error; @@ -10233,13 +10233,13 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, VIR_FREE(p); } else if (STRPREFIX(def->src.path, "gluster:") || STRPREFIX(def->src.path, "gluster+")) { - def->src.type = VIR_DOMAIN_DISK_TYPE_NETWORK; + def->src.type = VIR_STORAGE_TYPE_NETWORK; def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_GLUSTER; if (qemuParseGlusterString(def) < 0) goto error; } else if (STRPREFIX(def->src.path, "iscsi:")) { - def->src.type = VIR_DOMAIN_DISK_TYPE_NETWORK; + def->src.type = VIR_STORAGE_TYPE_NETWORK; def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_ISCSI; if (qemuParseISCSIString(def) < 0) @@ -10248,7 +10248,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, char *p = def->src.path; char *port, *vdi; - def->src.type = VIR_DOMAIN_DISK_TYPE_NETWORK; + def->src.type = VIR_STORAGE_TYPE_NETWORK; def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG; if (VIR_STRDUP(def->src.path, p + strlen("sheepdog:")) < 0) goto error; @@ -10280,9 +10280,9 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, goto error; } } else - def->src.type = VIR_DOMAIN_DISK_TYPE_FILE; + def->src.type = VIR_STORAGE_TYPE_FILE; } else { - def->src.type = VIR_DOMAIN_DISK_TYPE_FILE; + def->src.type = VIR_STORAGE_TYPE_FILE; } } else if (STREQ(keywords[i], "if")) { if (STREQ(values[i], "ide")) { @@ -10417,7 +10417,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, if (!def->src.path && def->device == VIR_DOMAIN_DISK_DEVICE_DISK && - def->src.type != VIR_DOMAIN_DISK_TYPE_NETWORK) { + def->src.type != VIR_STORAGE_TYPE_NETWORK) { virReportError(VIR_ERR_INTERNAL_ERROR, _("missing file parameter in drive '%s'"), val); goto error; @@ -11502,23 +11502,23 @@ qemuParseCommandLine(virCapsPtr qemuCaps, goto error; if (STRPREFIX(val, "/dev/")) - disk->src.type = VIR_DOMAIN_DISK_TYPE_BLOCK; + disk->src.type = VIR_STORAGE_TYPE_BLOCK; else if (STRPREFIX(val, "nbd:")) { - disk->src.type = VIR_DOMAIN_DISK_TYPE_NETWORK; + disk->src.type = VIR_STORAGE_TYPE_NETWORK; disk->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_NBD; } else if (STRPREFIX(val, "rbd:")) { - disk->src.type = VIR_DOMAIN_DISK_TYPE_NETWORK; + disk->src.type = VIR_STORAGE_TYPE_NETWORK; disk->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_RBD; val += strlen("rbd:"); } else if (STRPREFIX(val, "gluster")) { - disk->src.type = VIR_DOMAIN_DISK_TYPE_NETWORK; + disk->src.type = VIR_STORAGE_TYPE_NETWORK; disk->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_GLUSTER; } else if (STRPREFIX(val, "sheepdog:")) { - disk->src.type = VIR_DOMAIN_DISK_TYPE_NETWORK; + disk->src.type = VIR_STORAGE_TYPE_NETWORK; disk->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG; val += strlen("sheepdog:"); } else - disk->src.type = VIR_DOMAIN_DISK_TYPE_FILE; + disk->src.type = VIR_STORAGE_TYPE_FILE; if (STREQ(arg, "-cdrom")) { disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; if (((def->os.arch == VIR_ARCH_PPC64) && @@ -11547,7 +11547,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps, if (VIR_STRDUP(disk->src.path, val) < 0) goto error; - if (disk->src.type == VIR_DOMAIN_DISK_TYPE_NETWORK) { + if (disk->src.type == VIR_STORAGE_TYPE_NETWORK) { char *port; switch (disk->src.protocol) { @@ -11794,9 +11794,9 @@ qemuParseCommandLine(virCapsPtr qemuCaps, if (VIR_STRDUP(disk->src.path, val + strlen("disk:")) < 0) goto error; if (STRPREFIX(disk->src.path, "/dev/")) - disk->src.type = VIR_DOMAIN_DISK_TYPE_BLOCK; + disk->src.type = VIR_STORAGE_TYPE_BLOCK; else - disk->src.type = VIR_DOMAIN_DISK_TYPE_FILE; + disk->src.type = VIR_STORAGE_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_DISK; disk->bus = VIR_DOMAIN_DISK_BUS_USB; disk->removable = VIR_DOMAIN_FEATURE_STATE_DEFAULT; @@ -12027,7 +12027,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps, char *hosts, *port, *saveptr = NULL, *token; virDomainDiskDefPtr first_rbd_disk = NULL; for (i = 0; i < def->ndisks; i++) { - if (def->disks[i]->src.type == VIR_DOMAIN_DISK_TYPE_NETWORK && + if (def->disks[i]->src.type == VIR_STORAGE_TYPE_NETWORK && def->disks[i]->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD) { first_rbd_disk = def->disks[i]; break; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 78ab02a..dd851c6 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -793,7 +793,7 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices, disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED)) goto cleanup; - if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_VOLUME) { + if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_VOLUME) { virReportError(VIR_ERR_OPERATION_INVALID, _("sgio of shared disk 'pool=%s' 'volume=%s' conflicts " "with other active domains"), @@ -1269,7 +1269,7 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, int ret = -1; virErrorPtr savedError = NULL; - if (def->src.type != VIR_DOMAIN_DISK_TYPE_VOLUME) + if (def->src.type != VIR_STORAGE_TYPE_VOLUME) return 0; if (!def->src.srcpool) @@ -1332,15 +1332,15 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, switch (info.type) { case VIR_STORAGE_VOL_FILE: - def->src.srcpool->actualtype = VIR_DOMAIN_DISK_TYPE_FILE; + def->src.srcpool->actualtype = VIR_STORAGE_TYPE_FILE; break; case VIR_STORAGE_VOL_DIR: - def->src.srcpool->actualtype = VIR_DOMAIN_DISK_TYPE_DIR; + def->src.srcpool->actualtype = VIR_STORAGE_TYPE_DIR; break; case VIR_STORAGE_VOL_BLOCK: - def->src.srcpool->actualtype = VIR_DOMAIN_DISK_TYPE_BLOCK; + def->src.srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK; break; case VIR_STORAGE_VOL_NETWORK: @@ -1369,13 +1369,13 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, def->src.srcpool->mode = VIR_DOMAIN_DISK_SOURCE_POOL_MODE_HOST; /* fallthrough */ case VIR_DOMAIN_DISK_SOURCE_POOL_MODE_HOST: - def->src.srcpool->actualtype = VIR_DOMAIN_DISK_TYPE_BLOCK; + def->src.srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK; if (!(def->src.path = virStorageVolGetPath(vol))) goto cleanup; break; case VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT: - def->src.srcpool->actualtype = VIR_DOMAIN_DISK_TYPE_NETWORK; + def->src.srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK; def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_ISCSI; if (qemuTranslateDiskSourcePoolAuth(def, pooldef) < 0) @@ -1422,7 +1422,7 @@ int qemuTranslateSnapshotDiskSourcePool(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainSnapshotDiskDefPtr def) { - if (def->type != VIR_DOMAIN_DISK_TYPE_VOLUME) + if (def->type != VIR_STORAGE_TYPE_VOLUME) return 0; virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 36cb2c6..cdd4601 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -873,8 +873,8 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, if (cfg->allowDiskFormatProbing) { /* default disk format for drives */ if (virDomainDiskGetFormat(disk) == VIR_STORAGE_FILE_NONE && - (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_FILE || - virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_BLOCK)) + (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_FILE || + virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_BLOCK)) virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_AUTO); /* default disk format for mirrored drive */ @@ -889,8 +889,8 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, /* default disk format for drives */ if (virDomainDiskGetFormat(disk) == VIR_STORAGE_FILE_NONE && - (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_FILE || - virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_BLOCK)) + (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_FILE || + virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_BLOCK)) virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW); /* default disk format for mirrored drive */ @@ -2404,8 +2404,8 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver, int type = virDomainDiskGetType(disk); if (!src || - type == VIR_DOMAIN_DISK_TYPE_NETWORK || - type == VIR_DOMAIN_DISK_TYPE_VOLUME) + type == VIR_STORAGE_TYPE_NETWORK || + type == VIR_STORAGE_TYPE_VOLUME) goto cleanup; if (disk->backingChain) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 60dbb7f..b1c22c0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10433,7 +10433,7 @@ qemuDomainGetBlockInfo(virDomainPtr dom, /* ..but if guest is not using raw disk format and on a block device, * then query highest allocated extent from QEMU */ - if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_BLOCK && + if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_BLOCK && format != VIR_STORAGE_FILE_RAW && S_ISBLK(sb.st_mode)) { qemuDomainObjPrivatePtr priv = vm->privateData; @@ -12350,12 +12350,12 @@ qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk) { int actualType = virDomainDiskGetActualType(disk); - switch ((enum virDomainDiskType) actualType) { - case VIR_DOMAIN_DISK_TYPE_BLOCK: - case VIR_DOMAIN_DISK_TYPE_FILE: + switch ((enum virStorageType) actualType) { + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_FILE: return 0; - case VIR_DOMAIN_DISK_TYPE_NETWORK: + case VIR_STORAGE_TYPE_NETWORK: switch ((enum virDomainDiskProtocol) disk->src.protocol) { case VIR_DOMAIN_DISK_PROTOCOL_NBD: case VIR_DOMAIN_DISK_PROTOCOL_RBD: @@ -12376,12 +12376,12 @@ qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk) } break; - case VIR_DOMAIN_DISK_TYPE_DIR: - case VIR_DOMAIN_DISK_TYPE_VOLUME: - case VIR_DOMAIN_DISK_TYPE_LAST: + case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("external inactive snapshots are not supported on " - "'%s' disks"), virDomainDiskTypeToString(actualType)); + "'%s' disks"), virStorageTypeToString(actualType)); return -1; } @@ -12394,7 +12394,7 @@ qemuDomainSnapshotPrepareDiskExternalBackingActive(virDomainDiskDefPtr disk) { int actualType = virDomainDiskGetActualType(disk); - if (actualType == VIR_DOMAIN_DISK_TYPE_BLOCK && + if (actualType == VIR_STORAGE_TYPE_BLOCK && disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("external active snapshots are not supported on scsi " @@ -12411,12 +12411,12 @@ qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d { int actualType = virDomainSnapshotDiskGetActualType(disk); - switch ((enum virDomainDiskType) actualType) { - case VIR_DOMAIN_DISK_TYPE_BLOCK: - case VIR_DOMAIN_DISK_TYPE_FILE: + switch ((enum virStorageType) actualType) { + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_FILE: return 0; - case VIR_DOMAIN_DISK_TYPE_NETWORK: + case VIR_STORAGE_TYPE_NETWORK: switch ((enum virDomainDiskProtocol) disk->protocol) { case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: return 0; @@ -12440,12 +12440,12 @@ qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d } break; - case VIR_DOMAIN_DISK_TYPE_DIR: - case VIR_DOMAIN_DISK_TYPE_VOLUME: - case VIR_DOMAIN_DISK_TYPE_LAST: + case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("external active snapshots are not supported on " - "'%s' disks"), virDomainDiskTypeToString(actualType)); + "'%s' disks"), virStorageTypeToString(actualType)); return -1; } @@ -12458,18 +12458,18 @@ qemuDomainSnapshotPrepareDiskExternalOverlayInactive(virDomainSnapshotDiskDefPtr { int actualType = virDomainSnapshotDiskGetActualType(disk); - switch ((enum virDomainDiskType) actualType) { - case VIR_DOMAIN_DISK_TYPE_BLOCK: - case VIR_DOMAIN_DISK_TYPE_FILE: + switch ((enum virStorageType) actualType) { + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_FILE: return 0; - case VIR_DOMAIN_DISK_TYPE_NETWORK: - case VIR_DOMAIN_DISK_TYPE_DIR: - case VIR_DOMAIN_DISK_TYPE_VOLUME: - case VIR_DOMAIN_DISK_TYPE_LAST: + case VIR_STORAGE_TYPE_NETWORK: + case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("external inactive snapshots are not supported on " - "'%s' disks"), virDomainDiskTypeToString(actualType)); + "'%s' disks"), virStorageTypeToString(actualType)); return -1; } @@ -12555,12 +12555,12 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr conn, actualType = virDomainDiskGetActualType(disk); - switch ((enum virDomainDiskType) actualType) { - case VIR_DOMAIN_DISK_TYPE_BLOCK: - case VIR_DOMAIN_DISK_TYPE_FILE: + switch ((enum virStorageType) actualType) { + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_FILE: return 0; - case VIR_DOMAIN_DISK_TYPE_NETWORK: + case VIR_STORAGE_TYPE_NETWORK: switch ((enum virDomainDiskProtocol) disk->src.protocol) { case VIR_DOMAIN_DISK_PROTOCOL_NBD: case VIR_DOMAIN_DISK_PROTOCOL_RBD: @@ -12581,12 +12581,12 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr conn, } break; - case VIR_DOMAIN_DISK_TYPE_DIR: - case VIR_DOMAIN_DISK_TYPE_VOLUME: - case VIR_DOMAIN_DISK_TYPE_LAST: + case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("internal inactive snapshots are not supported on " - "'%s' disks"), virDomainDiskTypeToString(actualType)); + "'%s' disks"), virStorageTypeToString(actualType)); return -1; } @@ -12636,7 +12636,7 @@ qemuDomainSnapshotPrepare(virConnectPtr conn, active) < 0) goto cleanup; - if (dom_disk->src.type == VIR_DOMAIN_DISK_TYPE_NETWORK && + if (dom_disk->src.type == VIR_STORAGE_TYPE_NETWORK && (dom_disk->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG || dom_disk->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD)) { break; @@ -12789,10 +12789,10 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, goto cleanup; switch (snap->type) { - case VIR_DOMAIN_DISK_TYPE_BLOCK: + case VIR_STORAGE_TYPE_BLOCK: reuse = true; /* fallthrough */ - case VIR_DOMAIN_DISK_TYPE_FILE: + case VIR_STORAGE_TYPE_FILE: /* create the stub file and set selinux labels; manipulate disk in * place, in a way that can be reverted on failure. */ @@ -12812,7 +12812,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, } break; - case VIR_DOMAIN_DISK_TYPE_NETWORK: + case VIR_STORAGE_TYPE_NETWORK: switch (snap->protocol) { case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: if (!(newhosts = virStorageNetHostDefCopy(snap->nhosts, snap->hosts))) @@ -12836,7 +12836,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, default: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("snapshots are not supported on '%s' volumes"), - virDomainDiskTypeToString(snap->type)); + virStorageTypeToString(snap->type)); goto cleanup; } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 19d96cb..e81bc7a 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -138,7 +138,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, int type = virDomainDiskGetType(disk); int diskFormat = virDomainDiskGetFormat(disk); - if (type != VIR_DOMAIN_DISK_TYPE_DIR) { + if (type != VIR_STORAGE_TYPE_DIR) { if (diskFormat > 0) { format = virStorageFileFormatTypeToString(diskFormat); } else { diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 4732b64..7fb455d 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1533,7 +1533,7 @@ qemuMigrationIsSafe(virDomainDefPtr def) disk->cachemode != VIR_DOMAIN_DISK_CACHE_DISABLE) { int rc; - if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_FILE) { + if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_FILE) { if ((rc = virStorageFileIsSharedFS(src)) < 0) return false; else if (rc == 0) @@ -1542,7 +1542,7 @@ qemuMigrationIsSafe(virDomainDefPtr def) return false; else if (rc == 1) continue; - } else if (disk->src.type == VIR_DOMAIN_DISK_TYPE_NETWORK && + } else if (disk->src.type == VIR_STORAGE_TYPE_NETWORK && disk->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD) { continue; } diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index e969a69..ec8c101 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -1,7 +1,7 @@ /* * AppArmor security driver for libvirt * - * Copyright (C) 2011-2013 Red Hat, Inc. + * Copyright (C) 2011-2014 Red Hat, Inc. * Copyright (C) 2009-2010 Canonical Ltd. * * This library is free software; you can redistribute it and/or @@ -688,7 +688,7 @@ AppArmorRestoreSecurityImageLabel(virSecurityManagerPtr mgr, virDomainDefPtr def, virDomainDiskDefPtr disk) { - if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_NETWORK) + if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_NETWORK) return 0; return reload_profile(mgr, def, NULL, false); @@ -711,7 +711,7 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr, return 0; if (!virDomainDiskGetSource(disk) || - virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_NETWORK) + virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_NETWORK) return 0; if (secdef->imagelabel) { diff --git a/src/security/security_dac.c b/src/security/security_dac.c index b418ada..00c81d0 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -355,7 +355,7 @@ virSecurityDACSetSecurityImageLabel(virSecurityManagerPtr mgr, if (!priv->dynamicOwnership) return 0; - if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_NETWORK) + if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_NETWORK) return 0; params[0] = mgr; @@ -379,7 +379,7 @@ virSecurityDACRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr, if (!priv->dynamicOwnership) return 0; - if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_NETWORK) + if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_NETWORK) return 0; /* Don't restore labels on readoly/shared disks, because @@ -905,7 +905,7 @@ virSecurityDACSetSecurityAllLabel(virSecurityManagerPtr mgr, for (i = 0; i < def->ndisks; i++) { /* XXX fixme - we need to recursively label the entire tree :-( */ - if (virDomainDiskGetType(def->disks[i]) == VIR_DOMAIN_DISK_TYPE_DIR) + if (virDomainDiskGetType(def->disks[i]) == VIR_STORAGE_TYPE_DIR) continue; if (virSecurityDACSetSecurityImageLabel(mgr, def, diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index b55ae38..aa21a22 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1163,7 +1163,7 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr, if (disk->readonly || disk->shared) return 0; - if (!src || virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_NETWORK) + if (!src || virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_NETWORK) return 0; /* If we have a shared FS & doing migrated, we must not @@ -1263,7 +1263,7 @@ virSecuritySELinuxSetSecurityImageLabel(virSecurityManagerPtr mgr, if (cbdata.secdef->norelabel) return 0; - if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_NETWORK) + if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_NETWORK) return 0; return virDomainDiskDefForeachPath(disk, @@ -2272,7 +2272,7 @@ virSecuritySELinuxSetSecurityAllLabel(virSecurityManagerPtr mgr, for (i = 0; i < def->ndisks; i++) { /* XXX fixme - we need to recursively label the entire tree :-( */ - if (virDomainDiskGetType(def->disks[i]) == VIR_DOMAIN_DISK_TYPE_DIR) { + if (virDomainDiskGetType(def->disks[i]) == VIR_STORAGE_TYPE_DIR) { VIR_WARN("Unable to relabel directory tree %s for disk %s", virDomainDiskGetSource(def->disks[i]), def->disks[i]->dst); diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 5b3b536..e0fba3f 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -1,7 +1,7 @@ /* * storage_backend.c: internal storage driver backend contract * - * Copyright (C) 2007-2013 Red Hat, Inc. + * Copyright (C) 2007-2014 Red Hat, Inc. * Copyright (C) 2007-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -1175,7 +1175,7 @@ virStorageFileBackendForType(int type, for (i = 0; fileBackends[i]; i++) { if (fileBackends[i]->type == type) { - if (type == VIR_DOMAIN_DISK_TYPE_NETWORK && + if (type == VIR_STORAGE_TYPE_NETWORK && fileBackends[i]->protocol != protocol) continue; @@ -1183,7 +1183,7 @@ virStorageFileBackendForType(int type, } } - if (type == VIR_DOMAIN_DISK_TYPE_NETWORK) { + if (type == VIR_STORAGE_TYPE_NETWORK) { virReportError(VIR_ERR_INTERNAL_ERROR, _("missing storage backend for network files " "using %s protocol"), @@ -1191,7 +1191,7 @@ virStorageFileBackendForType(int type, } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("missing storage backend for '%s' storage"), - virDomainDiskTypeToString(type)); + virStorageTypeToString(type)); } return NULL; diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 0f8da06..084ae56 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -1363,7 +1363,7 @@ virStorageFileBackendFileStat(virStorageFilePtr file, virStorageFileBackend virStorageFileBackendFile = { - .type = VIR_DOMAIN_DISK_TYPE_FILE, + .type = VIR_STORAGE_TYPE_FILE, .storageFileUnlink = virStorageFileBackendFileUnlink, .storageFileStat = virStorageFileBackendFileStat, @@ -1371,7 +1371,7 @@ virStorageFileBackend virStorageFileBackendFile = { virStorageFileBackend virStorageFileBackendBlock = { - .type = VIR_DOMAIN_DISK_TYPE_BLOCK, + .type = VIR_STORAGE_TYPE_BLOCK, .storageFileStat = virStorageFileBackendFileStat, }; diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c index 84c5fe2..7b38fcb 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -610,7 +610,7 @@ virStorageFileBackendGlusterStat(virStorageFilePtr file, virStorageFileBackend virStorageFileBackendGluster = { - .type = VIR_DOMAIN_DISK_TYPE_NETWORK, + .type = VIR_STORAGE_TYPE_NETWORK, .protocol = VIR_DOMAIN_DISK_PROTOCOL_GLUSTER, .backendInit = virStorageFileBackendGlusterInit, diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 320473d..2e78472 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -53,6 +53,13 @@ VIR_LOG_INIT("util.storagefile"); +VIR_ENUM_IMPL(virStorage, VIR_STORAGE_TYPE_LAST, + "block", + "file", + "dir", + "network", + "volume") + VIR_ENUM_IMPL(virStorageFileFormat, VIR_STORAGE_FILE_LAST, "none", diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 7b8a7f7..3de7f2a 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -35,6 +35,21 @@ * beyond this size, in practice that doesn't matter. */ # define VIR_STORAGE_MAX_HEADER 0x8200 + +/* Types of disk backends (host resource) */ +enum virStorageType { + VIR_STORAGE_TYPE_BLOCK, + VIR_STORAGE_TYPE_FILE, + VIR_STORAGE_TYPE_DIR, + VIR_STORAGE_TYPE_NETWORK, + VIR_STORAGE_TYPE_VOLUME, + + VIR_STORAGE_TYPE_LAST +}; + +VIR_ENUM_DECL(virStorage) + + enum virStorageFileFormat { VIR_STORAGE_FILE_AUTO_SAFE = -2, VIR_STORAGE_FILE_AUTO = -1, diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 5839184..4eed78e 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2772,7 +2772,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { def->disks[i]->device = VIR_DOMAIN_DISK_DEVICE_DISK; def->disks[i]->bus = VIR_DOMAIN_DISK_BUS_IDE; virDomainDiskSetType(def->disks[i], - VIR_DOMAIN_DISK_TYPE_FILE); + VIR_STORAGE_TYPE_FILE); } } } @@ -2975,7 +2975,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { def->disks[diskCount]->readonly = true; virDomainDiskSetType(def->disks[diskCount], - VIR_DOMAIN_DISK_TYPE_FILE); + VIR_STORAGE_TYPE_FILE); VBOX_RELEASE(medium); VBOX_RELEASE(storageController); @@ -3251,7 +3251,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { def->disks[def->ndisks - 1]->device = VIR_DOMAIN_DISK_DEVICE_CDROM; def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_IDE; virDomainDiskSetType(def->disks[def->ndisks - 1], - VIR_DOMAIN_DISK_TYPE_FILE); + VIR_STORAGE_TYPE_FILE); def->disks[def->ndisks - 1]->readonly = true; ignore_value(virDomainDiskSetSource(def->disks[def->ndisks - 1], location)); ignore_value(VIR_STRDUP(def->disks[def->ndisks - 1]->dst, "hdc")); @@ -3298,7 +3298,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { def->disks[def->ndisks - 1]->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY; def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_FDC; virDomainDiskSetType(def->disks[def->ndisks - 1], - VIR_DOMAIN_DISK_TYPE_FILE); + VIR_STORAGE_TYPE_FILE); def->disks[def->ndisks - 1]->readonly = false; ignore_value(virDomainDiskSetSource(def->disks[def->ndisks - 1], location)); ignore_value(VIR_STRDUP(def->disks[def->ndisks - 1]->dst, "fda")); @@ -3911,7 +3911,7 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) ? "True" : "False")); if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM) { - if (type == VIR_DOMAIN_DISK_TYPE_FILE && src) { + if (type == VIR_STORAGE_TYPE_FILE && src) { IDVDDrive *dvdDrive = NULL; /* Currently CDROM/DVD Drive is always IDE * Secondary Master so neglecting the following @@ -3962,10 +3962,10 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) VBOX_UTF16_FREE(dvdfileUtf16); VBOX_RELEASE(dvdDrive); } - } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) { + } else if (type == VIR_STORAGE_TYPE_BLOCK) { } } else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) { - if (type == VIR_DOMAIN_DISK_TYPE_FILE && src) { + if (type == VIR_STORAGE_TYPE_FILE && src) { IHardDisk *hardDisk = NULL; PRUnichar *hddfileUtf16 = NULL; vboxIID hdduuid = VBOX_IID_INITIALIZER; @@ -4066,10 +4066,10 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) vboxIIDUnalloc(&hdduuid); VBOX_UTF16_FREE(hddEmpty); VBOX_UTF16_FREE(hddfileUtf16); - } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) { + } else if (type == VIR_STORAGE_TYPE_BLOCK) { } } else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) { - if (type == VIR_DOMAIN_DISK_TYPE_FILE && src) { + if (type == VIR_STORAGE_TYPE_FILE && src) { IFloppyDrive *floppyDrive; machine->vtbl->GetFloppyDrive(machine, &floppyDrive); if (floppyDrive) { @@ -4119,7 +4119,7 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) } VBOX_RELEASE(floppyDrive); } - } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) { + } else if (type == VIR_STORAGE_TYPE_BLOCK) { } } } @@ -4193,7 +4193,7 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) VIR_DEBUG("disk(%zu) shared: %s", i, (def->disks[i]->shared ? "True" : "False")); - if (type == VIR_DOMAIN_DISK_TYPE_FILE && src) { + if (type == VIR_STORAGE_TYPE_FILE && src) { IMedium *medium = NULL; PRUnichar *mediumUUID = NULL; PRUnichar *mediumFileUtf16 = NULL; @@ -5536,7 +5536,7 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom, int type = virDomainDiskGetType(dev->data.disk); if (dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) { - if (type == VIR_DOMAIN_DISK_TYPE_FILE && src) { + if (type == VIR_STORAGE_TYPE_FILE && src) { IDVDDrive *dvdDrive = NULL; /* Currently CDROM/DVD Drive is always IDE * Secondary Master so neglecting the following @@ -5582,10 +5582,10 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom, VBOX_UTF16_FREE(dvdfileUtf16); VBOX_RELEASE(dvdDrive); } - } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) { + } else if (type == VIR_STORAGE_TYPE_BLOCK) { } } else if (dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) { - if (type == VIR_DOMAIN_DISK_TYPE_FILE && src) { + if (type == VIR_STORAGE_TYPE_FILE && src) { IFloppyDrive *floppyDrive; machine->vtbl->GetFloppyDrive(machine, &floppyDrive); if (floppyDrive) { @@ -5632,7 +5632,7 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom, } VBOX_RELEASE(floppyDrive); } - } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) { + } else if (type == VIR_STORAGE_TYPE_BLOCK) { } } #else /* VBOX_API_VERSION >= 3001000 */ @@ -5769,7 +5769,7 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml) int type = virDomainDiskGetType(dev->data.disk); if (dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) { - if (type == VIR_DOMAIN_DISK_TYPE_FILE) { + if (type == VIR_STORAGE_TYPE_FILE) { IDVDDrive *dvdDrive = NULL; /* Currently CDROM/DVD Drive is always IDE * Secondary Master so neglecting the following @@ -5787,10 +5787,10 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml) } VBOX_RELEASE(dvdDrive); } - } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) { + } else if (type == VIR_STORAGE_TYPE_BLOCK) { } } else if (dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) { - if (type == VIR_DOMAIN_DISK_TYPE_FILE) { + if (type == VIR_STORAGE_TYPE_FILE) { IFloppyDrive *floppyDrive; machine->vtbl->GetFloppyDrive(machine, &floppyDrive); if (floppyDrive) { @@ -5815,7 +5815,7 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml) } VBOX_RELEASE(floppyDrive); } - } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) { + } else if (type == VIR_STORAGE_TYPE_BLOCK) { } } #else /* VBOX_API_VERSION >= 3001000 */ diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 118c7c3..6aba4f8 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -406,7 +406,7 @@ vmwareVmxPath(virDomainDefPtr vmdef, char **vmxPath) for (i = 0; i < vmdef->ndisks; ++i) { if (vmdef->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK && - virDomainDiskGetType(vmdef->disks[i]) == VIR_DOMAIN_DISK_TYPE_FILE) { + virDomainDiskGetType(vmdef->disks[i]) == VIR_STORAGE_TYPE_FILE) { disk = vmdef->disks[i]; break; } diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 32ddd05..a7129e8 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2187,7 +2187,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con } } - virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_FILE); + virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); if (!(tmp = ctx->parseFileName(fileName, ctx->opaque))) goto cleanup; if (virDomainDiskSetSource(*def, tmp) < 0) { @@ -2231,7 +2231,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con } } - virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_FILE); + virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); if (!(tmp = ctx->parseFileName(fileName, ctx->opaque))) goto cleanup; if (virDomainDiskSetSource(*def, tmp) < 0) { @@ -2248,7 +2248,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con */ goto ignore; } else if (STRCASEEQ(deviceType, "atapi-cdrom")) { - virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_BLOCK); + virDomainDiskSetType(*def, VIR_STORAGE_TYPE_BLOCK); if (STRCASEEQ(fileName, "auto detect")) { ignore_value(virDomainDiskSetSource(*def, NULL)); @@ -2259,7 +2259,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con } else if (STRCASEEQ(deviceType, "cdrom-raw")) { /* Raw access CD-ROMs actually are device='lun' */ (*def)->device = VIR_DOMAIN_DISK_DEVICE_LUN; - virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_BLOCK); + virDomainDiskSetType(*def, VIR_STORAGE_TYPE_BLOCK); if (STRCASEEQ(fileName, "auto detect")) { ignore_value(virDomainDiskSetSource(*def, NULL)); @@ -2277,13 +2277,13 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con } } else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) { if (fileType != NULL && STRCASEEQ(fileType, "device")) { - virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_BLOCK); + virDomainDiskSetType(*def, VIR_STORAGE_TYPE_BLOCK); if (virDomainDiskSetSource(*def, fileName) < 0) goto cleanup; } else if (fileType != NULL && STRCASEEQ(fileType, "file")) { char *tmp; - virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_FILE); + virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE); if (!(tmp = ctx->parseFileName(fileName, ctx->opaque))) goto cleanup; if (virDomainDiskSetSource(*def, tmp) < 0) { @@ -3438,14 +3438,14 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def, } /* We only support type='file' and type='block' */ - if (type != VIR_DOMAIN_DISK_TYPE_FILE && - type != VIR_DOMAIN_DISK_TYPE_BLOCK) { + if (type != VIR_STORAGE_TYPE_FILE && + type != VIR_STORAGE_TYPE_BLOCK) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("%s %s '%s' has unsupported type '%s', expecting " "'%s' or '%s'"), busType, deviceType, def->dst, diskType, - virDomainDiskTypeToString(VIR_DOMAIN_DISK_TYPE_FILE), - virDomainDiskTypeToString(VIR_DOMAIN_DISK_TYPE_BLOCK)); + virStorageTypeToString(VIR_STORAGE_TYPE_FILE), + virStorageTypeToString(VIR_STORAGE_TYPE_BLOCK)); return -1; } @@ -3467,11 +3467,11 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def, } if (def->device == VIR_DOMAIN_DISK_DEVICE_DISK && - type == VIR_DOMAIN_DISK_TYPE_FILE) { + type == VIR_STORAGE_TYPE_FILE) { vmxDeviceType = (def->bus == VIR_DOMAIN_DISK_BUS_SCSI) ? "scsi-hardDisk" : "ata-hardDisk"; } else if (def->device == VIR_DOMAIN_DISK_DEVICE_CDROM) { - if (type == VIR_DOMAIN_DISK_TYPE_FILE) + if (type == VIR_STORAGE_TYPE_FILE) vmxDeviceType = "cdrom-image"; else vmxDeviceType = "atapi-cdrom"; @@ -3489,7 +3489,7 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def, virBufferAsprintf(buffer, "%s%d:%d.deviceType = \"%s\"\n", busType, controllerOrBus, unit, vmxDeviceType); - if (type == VIR_DOMAIN_DISK_TYPE_FILE) { + if (type == VIR_STORAGE_TYPE_FILE) { const char *src = virDomainDiskGetSource(def); if (src && ! virFileHasSuffix(src, fileExt)) { @@ -3510,7 +3510,7 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def, busType, controllerOrBus, unit, fileName); VIR_FREE(fileName); - } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) { + } else if (type == VIR_STORAGE_TYPE_BLOCK) { const char *src = virDomainDiskGetSource(def); if (!src && @@ -3567,7 +3567,7 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def, virBufferAsprintf(buffer, "floppy%d.present = \"true\"\n", unit); - if (type == VIR_DOMAIN_DISK_TYPE_FILE) { + if (type == VIR_STORAGE_TYPE_FILE) { virBufferAsprintf(buffer, "floppy%d.fileType = \"file\"\n", unit); if (src) { @@ -3582,7 +3582,7 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def, VIR_FREE(fileName); } - } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) { + } else if (type == VIR_STORAGE_TYPE_BLOCK) { virBufferAsprintf(buffer, "floppy%d.fileType = \"device\"\n", unit); if (src) { @@ -3593,9 +3593,9 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Floppy '%s' has unsupported type '%s', expecting '%s' " "or '%s'"), def->dst, - virDomainDiskTypeToString(type), - virDomainDiskTypeToString(VIR_DOMAIN_DISK_TYPE_FILE), - virDomainDiskTypeToString(VIR_DOMAIN_DISK_TYPE_BLOCK)); + virStorageTypeToString(type), + virStorageTypeToString(VIR_STORAGE_TYPE_FILE), + virStorageTypeToString(VIR_STORAGE_TYPE_BLOCK)); return -1; } diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 1165b98..29316a4 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -447,17 +447,17 @@ xenParseSxprDisks(virDomainDefPtr def, so we assume common case here. If blktap becomes omnipotent, we can revisit this, perhaps stat()'ing the src file in question */ - virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE); + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); } else if (STREQ(virDomainDiskGetDriver(disk), "phy")) { - virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_BLOCK); + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK); } else if (STREQ(virDomainDiskGetDriver(disk), "file")) { - virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE); + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); } } else { /* No CDROM media so can't really tell. We'll just call if a FILE for now and update when media is inserted later */ - virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE); + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); } if (STREQLEN(dst, "ioemu:", 6)) @@ -1310,7 +1310,7 @@ xenParseSxpr(const struct sexpr *root, virDomainDiskDefFree(disk); goto error; } - virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE); + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; if (VIR_STRDUP(disk->dst, "hdc") < 0) { virDomainDiskDefFree(disk); @@ -1345,7 +1345,7 @@ xenParseSxpr(const struct sexpr *root, VIR_FREE(disk); goto error; } - virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE); + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); disk->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY; if (VIR_STRDUP(disk->dst, fds[i]) < 0) { virDomainDiskDefFree(disk); @@ -1801,9 +1801,9 @@ xenFormatSxprDisk(virDomainDiskDefPtr def, } else { int type = virDomainDiskGetType(def); - if (type == VIR_DOMAIN_DISK_TYPE_FILE) { + if (type == VIR_STORAGE_TYPE_FILE) { virBufferEscapeSexpr(buf, "(uname 'file:%s')", src); - } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) { + } else if (type == VIR_STORAGE_TYPE_BLOCK) { if (src[0] == '/') virBufferEscapeSexpr(buf, "(uname 'phy:%s')", src); else @@ -1812,7 +1812,7 @@ xenFormatSxprDisk(virDomainDiskDefPtr def, } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unsupported disk type %s"), - virDomainDiskTypeToString(type)); + virStorageTypeToString(type)); return -1; } } diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 9e4050d..c0422cf 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -592,8 +592,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, /* phy: type indicates a block device */ virDomainDiskSetType(disk, STREQ(virDomainDiskGetDriver(disk), "phy") ? - VIR_DOMAIN_DISK_TYPE_BLOCK : - VIR_DOMAIN_DISK_TYPE_FILE); + VIR_STORAGE_TYPE_BLOCK : + VIR_STORAGE_TYPE_FILE); /* Check for a :cdrom/:disk postfix */ disk->device = VIR_DOMAIN_DISK_DEVICE_DISK; @@ -635,7 +635,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (VIR_ALLOC(disk) < 0) goto cleanup; - virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE); + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; if (virDomainDiskSetDriver(disk, "file") < 0) goto cleanup; @@ -1214,16 +1214,16 @@ xenFormatXMDisk(virConfValuePtr list, virBufferAsprintf(&buf, "%s:", type); } else { switch (virDomainDiskGetType(disk)) { - case VIR_DOMAIN_DISK_TYPE_FILE: + case VIR_STORAGE_TYPE_FILE: virBufferAddLit(&buf, "file:"); break; - case VIR_DOMAIN_DISK_TYPE_BLOCK: + case VIR_STORAGE_TYPE_BLOCK: virBufferAddLit(&buf, "phy:"); break; default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported disk type %s"), - virDomainDiskTypeToString(virDomainDiskGetType(disk))); + virStorageTypeToString(virDomainDiskGetType(disk))); goto cleanup; } } diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index ce5e6a8..047356e 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -169,8 +169,8 @@ testSELinuxLoadDef(const char *testname) goto cleanup; for (i = 0; i < def->ndisks; i++) { - if (def->disks[i]->src.type != VIR_DOMAIN_DISK_TYPE_FILE && - def->disks[i]->src.type != VIR_DOMAIN_DISK_TYPE_BLOCK) + if (def->disks[i]->src.type != VIR_STORAGE_TYPE_FILE && + def->disks[i]->src.type != VIR_STORAGE_TYPE_BLOCK) continue; if (testSELinuxMungePath(&def->disks[i]->src.path) < 0) -- 1.9.0

On 03/27/14 23:08, Eric Blake wrote:
A continuation of the migration of disk details to virstoragefile. This patch moves a single enum, but converting the name has quite a bit of fallout.
* src/conf/domain_conf.h (virDomainDiskType): Move... * src/util/virstoragefile.h (virStorageType): ...and rename. * src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr) (virBhyveProcessBuildLoadCmd): Update clients. * src/conf/domain_conf.c (virDomainDiskSourceDefParse) (virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal) (virDomainDiskDefFormat, virDomainDiskGetActualType) (virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType): Likewise. * src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise. * src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML) (virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat): Likewise. * src/esx/esx_driver.c (esxAutodetectSCSIControllerModel) (esxDomainDefineXML): Likewise. * src/locking/domain_lock.c (virDomainLockManagerAddDisk): Likewise. * src/lxc/lxc_controller.c (virLXCControllerSetupLoopDeviceDisk) (virLXCControllerSetupNBDDeviceDisk) (virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk): Likewise. * src/parallels/parallels_driver.c (parallelsGetHddInfo): Likewise. * src/phyp/phyp_driver.c (phypDiskType): Likewise. * src/qemu/qemu_command.c (qemuGetDriveSourceString) (qemuDomainDiskGetSourceString, qemuBuildDriveStr) (qemuBuildCommandLine, qemuParseCommandLineDisk) (qemuParseCommandLine): Likewise. * src/qemu/qemu_conf.c (qemuCheckSharedDevice) (qemuTranslateDiskSourcePool) (qemuTranslateSnapshotDiskSourcePool): Likewise. * src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse) (qemuDomainDetermineDiskChain): Likewise. * src/qemu/qemu_driver.c (qemuDomainGetBlockInfo) (qemuDomainSnapshotPrepareDiskExternalBackingInactive) (qemuDomainSnapshotPrepareDiskExternalBackingActive) (qemuDomainSnapshotPrepareDiskExternalOverlayActive) (qemuDomainSnapshotPrepareDiskExternalOverlayInactive) (qemuDomainSnapshotPrepareDiskInternal) (qemuDomainSnapshotPrepare) (qemuDomainSnapshotCreateSingleDiskActive): Likewise. * src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia): Likewise. * src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise. * src/security/security_apparmor.c (AppArmorRestoreSecurityImageLabel) (AppArmorSetSecurityImageLabel): Likewise. * src/security/security_dac.c (virSecurityDACSetSecurityImageLabel) (virSecurityDACRestoreSecurityImageLabelInt) (virSecurityDACSetSecurityAllLabel): Likewise. * src/security/security_selinux.c (virSecuritySELinuxRestoreSecurityImageLabelInt) (virSecuritySELinuxSetSecurityImageLabel) (virSecuritySELinuxSetSecurityAllLabel): Likewise. * src/storage/storage_backend.c (virStorageFileBackendForType): Likewise. * src/storage/storage_backend_fs.c (virStorageFileBackendFile) (virStorageFileBackendBlock): Likewise. * src/storage/storage_backend_gluster.c (virStorageFileBackendGluster): Likewise. * src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives) (vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise. * src/vmware/vmware_conf.c (vmwareVmxPath): Likewise. * src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk) (virVMXFormatFloppy): Likewise. * src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr) (xenFormatSxprDisk): Likewise. * src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise. * tests/securityselinuxlabeltest.c (testSELinuxLoadDef): Likewise. * src/libvirt_private.syms (domain_conf.h): Move symbols... (virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com> ---
The fallout is once again rather longer than I would like. And given that there is more to come, I'm not going to push this until after the 1.2.3 release. Peter, let me know if I should post these in a repo somewhere to make it easier for you to rebase your pending gluster patches on top of this.
ACK, a lot of mechanical changes. Passed my compile test and quick look-over. Peter

Another enum moved to util/, this time the fallout from renaming is not quite as large. * src/conf/domain_conf.h (virDomainDiskProtocol): Move... * src/util/virstoragefile.h (virStorageNetProtocol): ...and rename. * src/conf/domain_conf.c: Update clients. * src/qemu/qemu_command.c: Likewise. * src/qemu/qemu_conf.c: Likewise. * src/qemu/qemu_driver.c: Likewise. * src/qemu/qemu_migration.c: Likewise. * src/storage/storage_backend.c: Likewise. * src/storage/storage_backend_gluster.c: Likewise. * src/libvirt_private.syms (domain_conf.h): Move symbols... (virstoragefile.h): ...as appropriate. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 26 +++------- src/conf/domain_conf.h | 17 +----- src/libvirt_private.syms | 2 +- src/qemu/qemu_command.c | 98 +++++++++++++++++------------------ src/qemu/qemu_conf.c | 4 +- src/qemu/qemu_driver.c | 86 +++++++++++++++--------------- src/qemu/qemu_migration.c | 2 +- src/storage/storage_backend.c | 2 +- src/storage/storage_backend_gluster.c | 2 +- src/util/virstoragefile.c | 11 ++++ src/util/virstoragefile.h | 18 +++++++ 11 files changed, 135 insertions(+), 133 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8c49d58..36149da 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -257,18 +257,6 @@ VIR_ENUM_IMPL(virDomainDiskErrorPolicy, VIR_DOMAIN_DISK_ERROR_POLICY_LAST, "ignore", "enospace") -VIR_ENUM_IMPL(virDomainDiskProtocol, VIR_DOMAIN_DISK_PROTOCOL_LAST, - "nbd", - "rbd", - "sheepdog", - "gluster", - "iscsi", - "http", - "https", - "ftp", - "ftps", - "tftp") - VIR_ENUM_IMPL(virDomainDiskSecretType, VIR_DOMAIN_DISK_SECRET_TYPE_LAST, "none", "uuid", @@ -5057,14 +5045,14 @@ virDomainDiskSourceDefParse(xmlNodePtr node, goto cleanup; } - if ((*proto = virDomainDiskProtocolTypeFromString(protocol)) < 0){ + if ((*proto = virStorageNetProtocolTypeFromString(protocol)) < 0){ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown protocol type '%s'"), protocol); goto cleanup; } if (!(*source = virXMLPropString(node, "name")) && - *proto != VIR_DOMAIN_DISK_PROTOCOL_NBD) { + *proto != VIR_STORAGE_NET_PROTOCOL_NBD) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing name for disk source")); goto cleanup; @@ -5255,9 +5243,9 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; if (def->src.type == VIR_STORAGE_TYPE_NETWORK) { - if (def->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_ISCSI) + if (def->src.protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI) expected_secret_usage = VIR_SECRET_USAGE_TYPE_ISCSI; - else if (def->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD) + else if (def->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD) expected_secret_usage = VIR_SECRET_USAGE_TYPE_CEPH; } @@ -14809,7 +14797,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, case VIR_STORAGE_TYPE_NETWORK: virBufferAsprintf(buf, "<source protocol='%s'", - virDomainDiskProtocolTypeToString(protocol)); + virStorageNetProtocolTypeToString(protocol)); virBufferEscapeString(buf, " name='%s'", src); if (nhosts == 0) { @@ -14984,9 +14972,9 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferEscapeString(buf, "<auth username='%s'>\n", def->src.auth.username); virBufferAdjustIndent(buf, 2); - if (def->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_ISCSI) { + if (def->src.protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI) { virBufferAddLit(buf, "<secret type='iscsi'"); - } else if (def->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD) { + } else if (def->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD) { virBufferAddLit(buf, "<secret type='ceph'"); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 247b2f8..bf92593 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -509,20 +509,6 @@ enum virDomainDiskErrorPolicy { VIR_DOMAIN_DISK_ERROR_POLICY_LAST }; -enum virDomainDiskProtocol { - VIR_DOMAIN_DISK_PROTOCOL_NBD, - VIR_DOMAIN_DISK_PROTOCOL_RBD, - VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG, - VIR_DOMAIN_DISK_PROTOCOL_GLUSTER, - VIR_DOMAIN_DISK_PROTOCOL_ISCSI, - VIR_DOMAIN_DISK_PROTOCOL_HTTP, - VIR_DOMAIN_DISK_PROTOCOL_HTTPS, - VIR_DOMAIN_DISK_PROTOCOL_FTP, - VIR_DOMAIN_DISK_PROTOCOL_FTPS, - VIR_DOMAIN_DISK_PROTOCOL_TFTP, - - VIR_DOMAIN_DISK_PROTOCOL_LAST -}; enum virDomainDiskTray { VIR_DOMAIN_DISK_TRAY_CLOSED, @@ -656,7 +642,7 @@ typedef virDomainDiskSourceDef *virDomainDiskSourceDefPtr; struct _virDomainDiskSourceDef { int type; /* enum virStorageType */ char *path; - int protocol; /* enum virDomainDiskProtocol */ + int protocol; /* enum virStorageNetProtocol */ size_t nhosts; virStorageNetHostDefPtr hosts; virDomainDiskSourcePoolDefPtr srcpool; @@ -2632,7 +2618,6 @@ VIR_ENUM_DECL(virDomainDiskGeometryTrans) VIR_ENUM_DECL(virDomainDiskBus) VIR_ENUM_DECL(virDomainDiskCache) VIR_ENUM_DECL(virDomainDiskErrorPolicy) -VIR_ENUM_DECL(virDomainDiskProtocol) VIR_ENUM_DECL(virDomainDiskIo) VIR_ENUM_DECL(virDomainDiskSecretType) VIR_ENUM_DECL(virDomainDeviceSGIO) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 29b47b7..99781a2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -209,7 +209,6 @@ virDomainDiskInsertPreAlloced; virDomainDiskIoTypeFromString; virDomainDiskIoTypeToString; virDomainDiskPathByName; -virDomainDiskProtocolTypeToString; virDomainDiskRemove; virDomainDiskRemoveByName; virDomainDiskSetDriver; @@ -1840,6 +1839,7 @@ virStorageNetHostDefCopy; virStorageNetHostDefFree; virStorageNetHostTransportTypeFromString; virStorageNetHostTransportTypeToString; +virStorageNetProtocolTypeToString; virStorageTypeFromString; virStorageTypeToString; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b3ad7b1..3cdda68 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3573,35 +3573,35 @@ qemuNetworkDriveGetPort(int protocol, return ret; } - switch ((enum virDomainDiskProtocol) protocol) { - case VIR_DOMAIN_DISK_PROTOCOL_HTTP: + switch ((enum virStorageNetProtocol) protocol) { + case VIR_STORAGE_NET_PROTOCOL_HTTP: return 80; - case VIR_DOMAIN_DISK_PROTOCOL_HTTPS: + case VIR_STORAGE_NET_PROTOCOL_HTTPS: return 443; - case VIR_DOMAIN_DISK_PROTOCOL_FTP: + case VIR_STORAGE_NET_PROTOCOL_FTP: return 21; - case VIR_DOMAIN_DISK_PROTOCOL_FTPS: + case VIR_STORAGE_NET_PROTOCOL_FTPS: return 990; - case VIR_DOMAIN_DISK_PROTOCOL_TFTP: + case VIR_STORAGE_NET_PROTOCOL_TFTP: return 69; - case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG: + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: return 7000; - case VIR_DOMAIN_DISK_PROTOCOL_NBD: + case VIR_STORAGE_NET_PROTOCOL_NBD: return 10809; - case VIR_DOMAIN_DISK_PROTOCOL_ISCSI: - case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: /* no default port specified */ return 0; - case VIR_DOMAIN_DISK_PROTOCOL_RBD: - case VIR_DOMAIN_DISK_PROTOCOL_LAST: + case VIR_STORAGE_NET_PROTOCOL_RBD: + case VIR_STORAGE_NET_PROTOCOL_LAST: /* not aplicable */ return -1; } @@ -3624,12 +3624,12 @@ qemuBuildNetworkDriveURI(int protocol, virURIPtr uri = NULL; size_t i; - switch ((enum virDomainDiskProtocol) protocol) { - case VIR_DOMAIN_DISK_PROTOCOL_NBD: + switch ((enum virStorageNetProtocol) protocol) { + case VIR_STORAGE_NET_PROTOCOL_NBD: if (nhosts != 1) { virReportError(VIR_ERR_INTERNAL_ERROR, _("protocol '%s' accepts only one host"), - virDomainDiskProtocolTypeToString(protocol)); + virStorageNetProtocolTypeToString(protocol)); goto cleanup; } @@ -3682,17 +3682,17 @@ qemuBuildNetworkDriveURI(int protocol, /* fallthrough */ /* NBD code uses same formatting scheme as others in some cases */ - case VIR_DOMAIN_DISK_PROTOCOL_HTTP: - case VIR_DOMAIN_DISK_PROTOCOL_HTTPS: - case VIR_DOMAIN_DISK_PROTOCOL_FTP: - case VIR_DOMAIN_DISK_PROTOCOL_FTPS: - case VIR_DOMAIN_DISK_PROTOCOL_TFTP: - case VIR_DOMAIN_DISK_PROTOCOL_ISCSI: - case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: + case VIR_STORAGE_NET_PROTOCOL_HTTP: + case VIR_STORAGE_NET_PROTOCOL_HTTPS: + case VIR_STORAGE_NET_PROTOCOL_FTP: + case VIR_STORAGE_NET_PROTOCOL_FTPS: + case VIR_STORAGE_NET_PROTOCOL_TFTP: + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: if (nhosts != 1) { virReportError(VIR_ERR_INTERNAL_ERROR, _("protocol '%s' accepts only one host"), - virDomainDiskProtocolTypeToString(protocol)); + virStorageNetProtocolTypeToString(protocol)); goto cleanup; } @@ -3701,11 +3701,11 @@ qemuBuildNetworkDriveURI(int protocol, if (hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) { if (VIR_STRDUP(uri->scheme, - virDomainDiskProtocolTypeToString(protocol)) < 0) + virStorageNetProtocolTypeToString(protocol)) < 0) goto cleanup; } else { if (virAsprintf(&uri->scheme, "%s+%s", - virDomainDiskProtocolTypeToString(protocol), + virStorageNetProtocolTypeToString(protocol), virStorageNetHostTransportTypeToString(hosts->transport)) < 0) goto cleanup; } @@ -3740,7 +3740,7 @@ qemuBuildNetworkDriveURI(int protocol, break; - case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG: + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: if (!src) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing disk source for 'sheepdog' protocol")); @@ -3764,7 +3764,7 @@ qemuBuildNetworkDriveURI(int protocol, break; - case VIR_DOMAIN_DISK_PROTOCOL_RBD: + case VIR_STORAGE_NET_PROTOCOL_RBD: if (strchr(src, ':')) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("':' not allowed in RBD source volume name '%s'"), @@ -3809,7 +3809,7 @@ qemuBuildNetworkDriveURI(int protocol, break; - case VIR_DOMAIN_DISK_PROTOCOL_LAST: + case VIR_STORAGE_NET_PROTOCOL_LAST: goto cleanup; } @@ -3876,19 +3876,19 @@ qemuDomainDiskGetSourceString(virConnectPtr conn, if (actualType == VIR_STORAGE_TYPE_NETWORK && disk->src.auth.username && - (disk->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_ISCSI || - disk->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD)) { + (disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI || + disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD)) { bool encode = false; int secretType = VIR_SECRET_USAGE_TYPE_ISCSI; - if (disk->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD) { + if (disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD) { /* qemu requires the secret to be encoded for RBD */ encode = true; secretType = VIR_SECRET_USAGE_TYPE_CEPH; } if (!(secret = qemuGetSecretString(conn, - virDomainDiskProtocolTypeToString(disk->src.protocol), + virStorageNetProtocolTypeToString(disk->src.protocol), encode, disk->src.auth.secretType, disk->src.auth.username, @@ -4321,10 +4321,10 @@ qemuBuildDriveDevStr(virDomainDefPtr def, goto error; } if (disk->src.type == VIR_STORAGE_TYPE_NETWORK) { - if (disk->src.protocol != VIR_DOMAIN_DISK_PROTOCOL_ISCSI) { + if (disk->src.protocol != VIR_STORAGE_NET_PROTOCOL_ISCSI) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("disk device='lun' is not supported for protocol='%s'"), - virDomainDiskProtocolTypeToString(disk->src.protocol)); + virStorageNetProtocolTypeToString(disk->src.protocol)); goto error; } } else if (!virDomainDiskSourceIsBlockType(disk)) { @@ -10213,7 +10213,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, else if (STRPREFIX(def->src.path, "nbd:") || STRPREFIX(def->src.path, "nbd+")) { def->src.type = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_NBD; + def->src.protocol = VIR_STORAGE_NET_PROTOCOL_NBD; if (qemuParseNBDString(def) < 0) goto error; @@ -10221,7 +10221,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, char *p = def->src.path; def->src.type = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_RBD; + def->src.protocol = VIR_STORAGE_NET_PROTOCOL_RBD; if (VIR_STRDUP(def->src.path, p + strlen("rbd:")) < 0) goto error; /* old-style CEPH_ARGS env variable is parsed later */ @@ -10234,13 +10234,13 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, } else if (STRPREFIX(def->src.path, "gluster:") || STRPREFIX(def->src.path, "gluster+")) { def->src.type = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_GLUSTER; + def->src.protocol = VIR_STORAGE_NET_PROTOCOL_GLUSTER; if (qemuParseGlusterString(def) < 0) goto error; } else if (STRPREFIX(def->src.path, "iscsi:")) { def->src.type = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_ISCSI; + def->src.protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; if (qemuParseISCSIString(def) < 0) goto error; @@ -10249,7 +10249,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, char *port, *vdi; def->src.type = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG; + def->src.protocol = VIR_STORAGE_NET_PROTOCOL_SHEEPDOG; if (VIR_STRDUP(def->src.path, p + strlen("sheepdog:")) < 0) goto error; VIR_FREE(p); @@ -11505,17 +11505,17 @@ qemuParseCommandLine(virCapsPtr qemuCaps, disk->src.type = VIR_STORAGE_TYPE_BLOCK; else if (STRPREFIX(val, "nbd:")) { disk->src.type = VIR_STORAGE_TYPE_NETWORK; - disk->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_NBD; + disk->src.protocol = VIR_STORAGE_NET_PROTOCOL_NBD; } else if (STRPREFIX(val, "rbd:")) { disk->src.type = VIR_STORAGE_TYPE_NETWORK; - disk->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_RBD; + disk->src.protocol = VIR_STORAGE_NET_PROTOCOL_RBD; val += strlen("rbd:"); } else if (STRPREFIX(val, "gluster")) { disk->src.type = VIR_STORAGE_TYPE_NETWORK; - disk->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_GLUSTER; + disk->src.protocol = VIR_STORAGE_NET_PROTOCOL_GLUSTER; } else if (STRPREFIX(val, "sheepdog:")) { disk->src.type = VIR_STORAGE_TYPE_NETWORK; - disk->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG; + disk->src.protocol = VIR_STORAGE_NET_PROTOCOL_SHEEPDOG; val += strlen("sheepdog:"); } else disk->src.type = VIR_STORAGE_TYPE_FILE; @@ -11551,16 +11551,16 @@ qemuParseCommandLine(virCapsPtr qemuCaps, char *port; switch (disk->src.protocol) { - case VIR_DOMAIN_DISK_PROTOCOL_NBD: + case VIR_STORAGE_NET_PROTOCOL_NBD: if (qemuParseNBDString(disk) < 0) goto error; break; - case VIR_DOMAIN_DISK_PROTOCOL_RBD: + case VIR_STORAGE_NET_PROTOCOL_RBD: /* old-style CEPH_ARGS env variable is parsed later */ if (!ceph_args && qemuParseRBDString(disk) < 0) goto error; break; - case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG: + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: /* disk->src must be [vdiname] or [host]:[port]:[vdiname] */ port = strchr(disk->src.path, ':'); if (port) { @@ -11584,12 +11584,12 @@ qemuParseCommandLine(virCapsPtr qemuCaps, goto error; } break; - case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: if (qemuParseGlusterString(disk) < 0) goto error; break; - case VIR_DOMAIN_DISK_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_ISCSI: if (qemuParseISCSIString(disk) < 0) goto error; @@ -12028,7 +12028,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps, virDomainDiskDefPtr first_rbd_disk = NULL; for (i = 0; i < def->ndisks; i++) { if (def->disks[i]->src.type == VIR_STORAGE_TYPE_NETWORK && - def->disks[i]->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD) { + def->disks[i]->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD) { first_rbd_disk = def->disks[i]; break; } diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index dd851c6..0f33553 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1195,7 +1195,7 @@ qemuAddISCSIPoolSourceHost(virDomainDiskDefPtr def, def->src.hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; def->src.hosts[0].socket = NULL; - def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_ISCSI; + def->src.protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; ret = 0; @@ -1376,7 +1376,7 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, case VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT: def->src.srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_DOMAIN_DISK_PROTOCOL_ISCSI; + def->src.protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; if (qemuTranslateDiskSourcePoolAuth(def, pooldef) < 0) goto cleanup; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b1c22c0..b57700e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12356,22 +12356,22 @@ qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk) return 0; case VIR_STORAGE_TYPE_NETWORK: - switch ((enum virDomainDiskProtocol) disk->src.protocol) { - case VIR_DOMAIN_DISK_PROTOCOL_NBD: - case VIR_DOMAIN_DISK_PROTOCOL_RBD: - case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG: - case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: - case VIR_DOMAIN_DISK_PROTOCOL_ISCSI: - case VIR_DOMAIN_DISK_PROTOCOL_HTTP: - case VIR_DOMAIN_DISK_PROTOCOL_HTTPS: - case VIR_DOMAIN_DISK_PROTOCOL_FTP: - case VIR_DOMAIN_DISK_PROTOCOL_FTPS: - case VIR_DOMAIN_DISK_PROTOCOL_TFTP: - case VIR_DOMAIN_DISK_PROTOCOL_LAST: + switch ((enum virStorageNetProtocol) disk->src.protocol) { + case VIR_STORAGE_NET_PROTOCOL_NBD: + case VIR_STORAGE_NET_PROTOCOL_RBD: + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_HTTP: + case VIR_STORAGE_NET_PROTOCOL_HTTPS: + case VIR_STORAGE_NET_PROTOCOL_FTP: + case VIR_STORAGE_NET_PROTOCOL_FTPS: + case VIR_STORAGE_NET_PROTOCOL_TFTP: + case VIR_STORAGE_NET_PROTOCOL_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("external inactive snapshots are not supported on " "'network' disks using '%s' protocol"), - virDomainDiskProtocolTypeToString(disk->src.protocol)); + virStorageNetProtocolTypeToString(disk->src.protocol)); return -1; } break; @@ -12417,24 +12417,24 @@ qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d return 0; case VIR_STORAGE_TYPE_NETWORK: - switch ((enum virDomainDiskProtocol) disk->protocol) { - case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: + switch ((enum virStorageNetProtocol) disk->protocol) { + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: return 0; - case VIR_DOMAIN_DISK_PROTOCOL_NBD: - case VIR_DOMAIN_DISK_PROTOCOL_RBD: - case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG: - case VIR_DOMAIN_DISK_PROTOCOL_ISCSI: - case VIR_DOMAIN_DISK_PROTOCOL_HTTP: - case VIR_DOMAIN_DISK_PROTOCOL_HTTPS: - case VIR_DOMAIN_DISK_PROTOCOL_FTP: - case VIR_DOMAIN_DISK_PROTOCOL_FTPS: - case VIR_DOMAIN_DISK_PROTOCOL_TFTP: - case VIR_DOMAIN_DISK_PROTOCOL_LAST: + case VIR_STORAGE_NET_PROTOCOL_NBD: + case VIR_STORAGE_NET_PROTOCOL_RBD: + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_HTTP: + case VIR_STORAGE_NET_PROTOCOL_HTTPS: + case VIR_STORAGE_NET_PROTOCOL_FTP: + case VIR_STORAGE_NET_PROTOCOL_FTPS: + case VIR_STORAGE_NET_PROTOCOL_TFTP: + case VIR_STORAGE_NET_PROTOCOL_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("external active snapshots are not supported on " "'network' disks using '%s' protocol"), - virDomainDiskProtocolTypeToString(disk->protocol)); + virStorageNetProtocolTypeToString(disk->protocol)); return -1; } @@ -12561,22 +12561,22 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr conn, return 0; case VIR_STORAGE_TYPE_NETWORK: - switch ((enum virDomainDiskProtocol) disk->src.protocol) { - case VIR_DOMAIN_DISK_PROTOCOL_NBD: - case VIR_DOMAIN_DISK_PROTOCOL_RBD: - case VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG: - case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: - case VIR_DOMAIN_DISK_PROTOCOL_ISCSI: - case VIR_DOMAIN_DISK_PROTOCOL_HTTP: - case VIR_DOMAIN_DISK_PROTOCOL_HTTPS: - case VIR_DOMAIN_DISK_PROTOCOL_FTP: - case VIR_DOMAIN_DISK_PROTOCOL_FTPS: - case VIR_DOMAIN_DISK_PROTOCOL_TFTP: - case VIR_DOMAIN_DISK_PROTOCOL_LAST: + switch ((enum virStorageNetProtocol) disk->src.protocol) { + case VIR_STORAGE_NET_PROTOCOL_NBD: + case VIR_STORAGE_NET_PROTOCOL_RBD: + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_HTTP: + case VIR_STORAGE_NET_PROTOCOL_HTTPS: + case VIR_STORAGE_NET_PROTOCOL_FTP: + case VIR_STORAGE_NET_PROTOCOL_FTPS: + case VIR_STORAGE_NET_PROTOCOL_TFTP: + case VIR_STORAGE_NET_PROTOCOL_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("internal inactive snapshots are not supported on " "'network' disks using '%s' protocol"), - virDomainDiskProtocolTypeToString(disk->src.protocol)); + virStorageNetProtocolTypeToString(disk->src.protocol)); return -1; } break; @@ -12637,8 +12637,8 @@ qemuDomainSnapshotPrepare(virConnectPtr conn, goto cleanup; if (dom_disk->src.type == VIR_STORAGE_TYPE_NETWORK && - (dom_disk->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG || - dom_disk->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD)) { + (dom_disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_SHEEPDOG || + dom_disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD)) { break; } if (vm->def->disks[i]->src.format > 0 && @@ -12814,7 +12814,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, case VIR_STORAGE_TYPE_NETWORK: switch (snap->protocol) { - case VIR_DOMAIN_DISK_PROTOCOL_GLUSTER: + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: if (!(newhosts = virStorageNetHostDefCopy(snap->nhosts, snap->hosts))) goto cleanup; @@ -12828,7 +12828,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("snapshots on volumes using '%s' protocol " "are not supported"), - virDomainDiskProtocolTypeToString(snap->protocol)); + virStorageNetProtocolTypeToString(snap->protocol)); goto cleanup; } break; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 7fb455d..b389d0a 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1543,7 +1543,7 @@ qemuMigrationIsSafe(virDomainDefPtr def) else if (rc == 1) continue; } else if (disk->src.type == VIR_STORAGE_TYPE_NETWORK && - disk->src.protocol == VIR_DOMAIN_DISK_PROTOCOL_RBD) { + disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD) { continue; } diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index e0fba3f..a4481b2 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -1187,7 +1187,7 @@ virStorageFileBackendForType(int type, virReportError(VIR_ERR_INTERNAL_ERROR, _("missing storage backend for network files " "using %s protocol"), - virDomainDiskProtocolTypeToString(protocol)); + virStorageNetProtocolTypeToString(protocol)); } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("missing storage backend for '%s' storage"), diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c index 7b38fcb..d5d042f 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -611,7 +611,7 @@ virStorageFileBackendGlusterStat(virStorageFilePtr file, virStorageFileBackend virStorageFileBackendGluster = { .type = VIR_STORAGE_TYPE_NETWORK, - .protocol = VIR_DOMAIN_DISK_PROTOCOL_GLUSTER, + .protocol = VIR_STORAGE_NET_PROTOCOL_GLUSTER, .backendInit = virStorageFileBackendGlusterInit, .backendDeinit = virStorageFileBackendGlusterDeinit, diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 2e78472..2ed5617 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -73,6 +73,17 @@ VIR_ENUM_IMPL(virStorageFileFeature, "lazy_refcounts", ) +VIR_ENUM_IMPL(virStorageNetProtocol, VIR_STORAGE_NET_PROTOCOL_LAST, + "nbd", + "rbd", + "sheepdog", + "gluster", + "iscsi", + "http", + "https", + "ftp", + "ftps", + "tftp") VIR_ENUM_IMPL(virStorageNetHostTransport, VIR_STORAGE_NET_HOST_TRANS_LAST, "tcp", diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 3de7f2a..fccf0b9 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -100,6 +100,24 @@ struct _virStorageFileMetadata { /* Information related to network storage */ +enum virStorageNetProtocol { + VIR_STORAGE_NET_PROTOCOL_NBD, + VIR_STORAGE_NET_PROTOCOL_RBD, + VIR_STORAGE_NET_PROTOCOL_SHEEPDOG, + VIR_STORAGE_NET_PROTOCOL_GLUSTER, + VIR_STORAGE_NET_PROTOCOL_ISCSI, + VIR_STORAGE_NET_PROTOCOL_HTTP, + VIR_STORAGE_NET_PROTOCOL_HTTPS, + VIR_STORAGE_NET_PROTOCOL_FTP, + VIR_STORAGE_NET_PROTOCOL_FTPS, + VIR_STORAGE_NET_PROTOCOL_TFTP, + + VIR_STORAGE_NET_PROTOCOL_LAST +}; + +VIR_ENUM_DECL(virStorageNetProtocol) + + enum virStorageNetHostTransport { VIR_STORAGE_NET_HOST_TRANS_TCP, VIR_STORAGE_NET_HOST_TRANS_UNIX, -- 1.9.0

On 03/27/14 23:48, Eric Blake wrote:
Another enum moved to util/, this time the fallout from renaming is not quite as large.
* src/conf/domain_conf.h (virDomainDiskProtocol): Move... * src/util/virstoragefile.h (virStorageNetProtocol): ...and rename. * src/conf/domain_conf.c: Update clients. * src/qemu/qemu_command.c: Likewise. * src/qemu/qemu_conf.c: Likewise. * src/qemu/qemu_driver.c: Likewise. * src/qemu/qemu_migration.c: Likewise. * src/storage/storage_backend.c: Likewise. * src/storage/storage_backend_gluster.c: Likewise. * src/libvirt_private.syms (domain_conf.h): Move symbols... (virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 26 +++------- src/conf/domain_conf.h | 17 +----- src/libvirt_private.syms | 2 +- src/qemu/qemu_command.c | 98 +++++++++++++++++------------------ src/qemu/qemu_conf.c | 4 +- src/qemu/qemu_driver.c | 86 +++++++++++++++--------------- src/qemu/qemu_migration.c | 2 +- src/storage/storage_backend.c | 2 +- src/storage/storage_backend_gluster.c | 2 +- src/util/virstoragefile.c | 11 ++++ src/util/virstoragefile.h | 18 +++++++ 11 files changed, 135 insertions(+), 133 deletions(-)
ACK Peter

Encryption keys can be associated with each source file in a backing chain; as such, this file belongs more in util/ where it can be used by virstoragefile.h. * src/conf/storage_encryption_conf.h: Rename... * src/util/virstorageencryption.h: ...to this. * src/conf/storage_encryption_conf.c: Rename... * src/util/virstorageencryption.c: ...to this. * src/Makefile.am (ENCRYPTION_CONF_SOURCES, CONF_SOURCES) (UTIL_SOURCES): Update to new file names. * src/libvirt_private.syms: Likewise. * src/conf/domain_conf.h: Update client. * src/conf/storage_conf.h: Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> --- po/POTFILES.in | 2 +- src/Makefile.am | 5 +---- src/conf/domain_conf.h | 2 +- src/conf/storage_conf.h | 4 ++-- src/libvirt_private.syms | 14 +++++++------- .../virstorageencryption.c} | 5 ++--- .../virstorageencryption.h} | 4 ++-- 7 files changed, 16 insertions(+), 20 deletions(-) rename src/{conf/storage_encryption_conf.c => util/virstorageencryption.c} (98%) rename src/{conf/storage_encryption_conf.h => util/virstorageencryption.h} (95%) diff --git a/po/POTFILES.in b/po/POTFILES.in index 5a4112a..122b853 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -28,7 +28,6 @@ src/conf/object_event.c src/conf/secret_conf.c src/conf/snapshot_conf.c src/conf/storage_conf.c -src/conf/storage_encryption_conf.c src/conf/virchrdev.c src/cpu/cpu.c src/cpu/cpu_generic.c @@ -193,6 +192,7 @@ src/util/virsexpr.c src/util/virscsi.c src/util/virsocketaddr.c src/util/virstatslinux.c +src/util/virstorageencryption.c src/util/virstoragefile.c src/util/virstring.c src/util/virsysinfo.c diff --git a/src/Makefile.am b/src/Makefile.am index 54206e4..38b2697 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -146,6 +146,7 @@ UTIL_SOURCES = \ util/virsexpr.c util/virsexpr.h \ util/virsocketaddr.h util/virsocketaddr.c \ util/virstatslinux.c util/virstatslinux.h \ + util/virstorageencryption.c util/virstorageencryption.h \ util/virstoragefile.c util/virstoragefile.h \ util/virstring.h util/virstring.c \ util/virsysinfo.c util/virsysinfo.h \ @@ -288,9 +289,6 @@ SECRET_CONF_SOURCES = \ NODE_DEVICE_CONF_SOURCES = \ conf/node_device_conf.c conf/node_device_conf.h -ENCRYPTION_CONF_SOURCES = \ - conf/storage_encryption_conf.c conf/storage_encryption_conf.h - CPU_CONF_SOURCES = \ conf/cpu_conf.c conf/cpu_conf.h @@ -312,7 +310,6 @@ CONF_SOURCES = \ $(NWFILTER_CONF_SOURCES) \ $(NODE_DEVICE_CONF_SOURCES) \ $(STORAGE_CONF_SOURCES) \ - $(ENCRYPTION_CONF_SOURCES) \ $(INTERFACE_CONF_SOURCES) \ $(SECRET_CONF_SOURCES) \ $(CPU_CONF_SOURCES) \ diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index bf92593..b2eeefd 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -30,7 +30,7 @@ # include "internal.h" # include "capabilities.h" -# include "storage_encryption_conf.h" +# include "virstorageencryption.h" # include "cpu_conf.h" # include "virthread.h" # include "virhash.h" diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index e410f41..b811046 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -1,7 +1,7 @@ /* * storage_conf.h: config handling for storage driver * - * Copyright (C) 2006-2008, 2010-2013 Red Hat, Inc. + * Copyright (C) 2006-2008, 2010-2014 Red Hat, Inc. * Copyright (C) 2006-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -25,7 +25,7 @@ # define __VIR_STORAGE_CONF_H__ # include "internal.h" -# include "storage_encryption_conf.h" +# include "virstorageencryption.h" # include "virbitmap.h" # include "virthread.h" diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 99781a2..60c2d44 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -729,13 +729,6 @@ virStorageVolTypeFromString; virStorageVolTypeToString; -# conf/storage_encryption_conf.h -virStorageEncryptionFormat; -virStorageEncryptionFree; -virStorageEncryptionParseNode; -virStorageGenerateQcowPassphrase; - - # conf/virchrdev.h virChrdevAlloc; virChrdevFree; @@ -1815,6 +1808,13 @@ virSocketAddrSetIPv4Addr; virSocketAddrSetPort; +# util/virstorageencryption.h +virStorageEncryptionFormat; +virStorageEncryptionFree; +virStorageEncryptionParseNode; +virStorageGenerateQcowPassphrase; + + # util/virstoragefile.h virStorageFileChainGetBroken; virStorageFileChainLookup; diff --git a/src/conf/storage_encryption_conf.c b/src/util/virstorageencryption.c similarity index 98% rename from src/conf/storage_encryption_conf.c rename to src/util/virstorageencryption.c index bba067b..9089278 100644 --- a/src/conf/storage_encryption_conf.c +++ b/src/util/virstorageencryption.c @@ -1,5 +1,5 @@ /* - * storage_encryption_conf.c: volume encryption information + * virstorageencryption.c: volume encryption information * * Copyright (C) 2009-2014 Red Hat, Inc. * @@ -29,8 +29,7 @@ #include "virbuffer.h" #include "viralloc.h" -#include "storage_conf.h" -#include "storage_encryption_conf.h" +#include "virstorageencryption.h" #include "virxml.h" #include "virerror.h" #include "viruuid.h" diff --git a/src/conf/storage_encryption_conf.h b/src/util/virstorageencryption.h similarity index 95% rename from src/conf/storage_encryption_conf.h rename to src/util/virstorageencryption.h index 57ab1a0..03c38a5 100644 --- a/src/conf/storage_encryption_conf.h +++ b/src/util/virstorageencryption.h @@ -1,7 +1,7 @@ /* - * storage_encryption_conf.h: volume encryption information + * virstorageencryption.h: volume encryption information * - * Copyright (C) 2009-2011 Red Hat, Inc. + * Copyright (C) 2009-2011, 2014 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 -- 1.9.0

On 03/28/14 04:38, Eric Blake wrote:
Encryption keys can be associated with each source file in a backing chain; as such, this file belongs more in util/ where it can be used by virstoragefile.h.
* src/conf/storage_encryption_conf.h: Rename... * src/util/virstorageencryption.h: ...to this. * src/conf/storage_encryption_conf.c: Rename... * src/util/virstorageencryption.c: ...to this. * src/Makefile.am (ENCRYPTION_CONF_SOURCES, CONF_SOURCES) (UTIL_SOURCES): Update to new file names. * src/libvirt_private.syms: Likewise. * src/conf/domain_conf.h: Update client. * src/conf/storage_conf.h: Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com> --- po/POTFILES.in | 2 +- src/Makefile.am | 5 +---- src/conf/domain_conf.h | 2 +- src/conf/storage_conf.h | 4 ++-- src/libvirt_private.syms | 14 +++++++------- .../virstorageencryption.c} | 5 ++--- .../virstorageencryption.h} | 4 ++-- 7 files changed, 16 insertions(+), 20 deletions(-) rename src/{conf/storage_encryption_conf.c => util/virstorageencryption.c} (98%) rename src/{conf/storage_encryption_conf.h => util/virstorageencryption.h} (95%)
ACK Peter

Another struct being moved to util. This one doesn't have as much use yet, thankfully. * src/conf/domain_conf.h (virDomainDiskSourcePoolMode) (virDomainDiskSourcePoolDef): Move... * src/util/virstoragefile.h (virStorageSourcePoolMode) (virStorageSourcePoolDef): ...and rename. * src/conf/domain_conf.c (virDomainDiskSourcePoolDefFree) (virDomainDiskSourceDefClear, virDomainDiskSourcePoolDefParse) (virDomainDiskDefParseXML, virDomainDiskSourceDefParse) (virDomainDiskSourceDefFormatInternal) (virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType): Adjust clients. * src/qemu/qemu_conf.c (qemuTranslateDiskSourcePool): Likewise. * src/libvirt_private.syms (domain_conf.h): Move symbols... (virstoragefile.h): ...as appropriate. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 23 +++++++++-------------- src/conf/domain_conf.h | 38 +++----------------------------------- src/libvirt_private.syms | 2 ++ src/qemu/qemu_conf.c | 10 +++++----- src/util/virstoragefile.c | 5 +++++ src/util/virstoragefile.h | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 54 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 36149da..643b066 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -763,11 +763,6 @@ VIR_ENUM_IMPL(virDomainDiskDiscard, VIR_DOMAIN_DISK_DISCARD_LAST, "default", "unmap", "ignore") -VIR_ENUM_IMPL(virDomainDiskSourcePoolMode, - VIR_DOMAIN_DISK_SOURCE_POOL_MODE_LAST, - "default", - "host", - "direct") #define VIR_DOMAIN_XML_WRITE_FLAGS VIR_DOMAIN_XML_SECURE #define VIR_DOMAIN_XML_READ_FLAGS VIR_DOMAIN_XML_INACTIVE @@ -1190,7 +1185,7 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def) } static void -virDomainDiskSourcePoolDefFree(virDomainDiskSourcePoolDefPtr def) +virDomainDiskSourcePoolDefFree(virStorageSourcePoolDefPtr def) { if (!def) return; @@ -4964,10 +4959,10 @@ virDomainLeaseDefParseXML(xmlNodePtr node) static int virDomainDiskSourcePoolDefParse(xmlNodePtr node, - virDomainDiskSourcePoolDefPtr *srcpool) + virStorageSourcePoolDefPtr *srcpool) { char *mode = NULL; - virDomainDiskSourcePoolDefPtr source; + virStorageSourcePoolDefPtr source; int ret = -1; *srcpool = NULL; @@ -4993,7 +4988,7 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node, } if (mode && - (source->mode = virDomainDiskSourcePoolModeTypeFromString(mode)) <= 0) { + (source->mode = virStorageSourcePoolModeTypeFromString(mode)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown source mode '%s' for volume type disk"), mode); @@ -5018,7 +5013,7 @@ virDomainDiskSourceDefParse(xmlNodePtr node, int *proto, size_t *nhosts, virStorageNetHostDefPtr *hosts, - virDomainDiskSourcePoolDefPtr *srcpool) + virStorageSourcePoolDefPtr *srcpool) { char *protocol = NULL; char *transport = NULL; @@ -14761,7 +14756,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, virStorageNetHostDefPtr hosts, size_t nseclabels, virSecurityDeviceLabelDefPtr *seclabels, - virDomainDiskSourcePoolDefPtr srcpool, + virStorageSourcePoolDefPtr srcpool, unsigned int flags) { size_t n; @@ -14831,7 +14826,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, srcpool->pool, srcpool->volume); if (srcpool->mode) virBufferAsprintf(buf, " mode='%s'", - virDomainDiskSourcePoolModeTypeToString(srcpool->mode)); + virStorageSourcePoolModeTypeToString(srcpool->mode)); } virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); @@ -18530,7 +18525,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk, if (!path || type == VIR_STORAGE_TYPE_NETWORK || (type == VIR_STORAGE_TYPE_VOLUME && disk->src.srcpool && - disk->src.srcpool->mode == VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT)) + disk->src.srcpool->mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT)) return 0; if (iter(disk, path, 0, opaque) < 0) @@ -19392,7 +19387,7 @@ virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def) * (e.g. set sgio=filtered|unfiltered for it) in libvirt. */ if (def->src.srcpool->pooltype == VIR_STORAGE_POOL_ISCSI && - def->src.srcpool->mode == VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT) + def->src.srcpool->mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT) return false; return true; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index b2eeefd..e5d945f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -602,37 +602,6 @@ struct _virDomainBlockIoTuneInfo { }; typedef virDomainBlockIoTuneInfo *virDomainBlockIoTuneInfoPtr; -/* - * Used for volume "type" disk to indicate how to represent - * the disk source if the specified "pool" is of iscsi type. - */ -enum virDomainDiskSourcePoolMode { - VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DEFAULT = 0, - - /* Use the path as it shows up on host, e.g. - * /dev/disk/by-path/ip-$ip-iscsi-$iqn:iscsi.iscsi-pool0-lun-1 - */ - VIR_DOMAIN_DISK_SOURCE_POOL_MODE_HOST, - - /* Use the URI from the storage pool source element host attribute. E.g. - * file=iscsi://demo.org:6000/iqn.1992-01.com.example/1. - */ - VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT, - - VIR_DOMAIN_DISK_SOURCE_POOL_MODE_LAST -}; - -typedef struct _virDomainDiskSourcePoolDef virDomainDiskSourcePoolDef; -struct _virDomainDiskSourcePoolDef { - char *pool; /* pool name */ - char *volume; /* volume name */ - int voltype; /* enum virStorageVolType, internal only */ - int pooltype; /* enum virStoragePoolType, internal only */ - int actualtype; /* enum virStorageType, internal only */ - int mode; /* enum virDomainDiskSourcePoolMode */ -}; -typedef virDomainDiskSourcePoolDef *virDomainDiskSourcePoolDefPtr; - typedef struct _virDomainDiskSourceDef virDomainDiskSourceDef; typedef virDomainDiskSourceDef *virDomainDiskSourceDefPtr; @@ -645,7 +614,7 @@ struct _virDomainDiskSourceDef { int protocol; /* enum virStorageNetProtocol */ size_t nhosts; virStorageNetHostDefPtr hosts; - virDomainDiskSourcePoolDefPtr srcpool; + virStorageSourcePoolDefPtr srcpool; struct { char *username; int secretType; /* enum virDomainDiskSecretType */ @@ -2347,7 +2316,7 @@ int virDomainDiskSourceDefFormatInternal(virBufferPtr buf, virStorageNetHostDefPtr hosts, size_t nseclabels, virSecurityDeviceLabelDefPtr *seclabels, - virDomainDiskSourcePoolDefPtr srcpool, + virStorageSourcePoolDefPtr srcpool, unsigned int flags); int virDomainNetDefFormat(virBufferPtr buf, @@ -2401,7 +2370,7 @@ int virDomainDiskSourceDefParse(xmlNodePtr node, int *proto, size_t *nhosts, virStorageNetHostDefPtr *hosts, - virDomainDiskSourcePoolDefPtr *srcpool); + virStorageSourcePoolDefPtr *srcpool); bool virDomainHasDiskMirror(virDomainObjPtr vm); @@ -2623,7 +2592,6 @@ VIR_ENUM_DECL(virDomainDiskSecretType) VIR_ENUM_DECL(virDomainDeviceSGIO) VIR_ENUM_DECL(virDomainDiskTray) VIR_ENUM_DECL(virDomainDiskDiscard) -VIR_ENUM_DECL(virDomainDiskSourcePoolMode) VIR_ENUM_DECL(virDomainIoEventFd) VIR_ENUM_DECL(virDomainVirtioEventIdx) VIR_ENUM_DECL(virDomainDiskCopyOnRead) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 60c2d44..da70ee3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1840,6 +1840,8 @@ virStorageNetHostDefFree; virStorageNetHostTransportTypeFromString; virStorageNetHostTransportTypeToString; virStorageNetProtocolTypeToString; +virStorageSourcePoolModeTypeFromString; +virStorageSourcePoolModeTypeToString; virStorageTypeFromString; virStorageTypeToString; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 0f33553..96a2caf 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1364,17 +1364,17 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, } switch (def->src.srcpool->mode) { - case VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DEFAULT: - case VIR_DOMAIN_DISK_SOURCE_POOL_MODE_LAST: - def->src.srcpool->mode = VIR_DOMAIN_DISK_SOURCE_POOL_MODE_HOST; + case VIR_STORAGE_SOURCE_POOL_MODE_DEFAULT: + case VIR_STORAGE_SOURCE_POOL_MODE_LAST: + def->src.srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST; /* fallthrough */ - case VIR_DOMAIN_DISK_SOURCE_POOL_MODE_HOST: + case VIR_STORAGE_SOURCE_POOL_MODE_HOST: def->src.srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK; if (!(def->src.path = virStorageVolGetPath(vol))) goto cleanup; break; - case VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT: + case VIR_STORAGE_SOURCE_POOL_MODE_DIRECT: def->src.srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK; def->src.protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 2ed5617..e1b69ec 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -90,6 +90,11 @@ VIR_ENUM_IMPL(virStorageNetHostTransport, VIR_STORAGE_NET_HOST_TRANS_LAST, "unix", "rdma") +VIR_ENUM_IMPL(virStorageSourcePoolMode, + VIR_STORAGE_SOURCE_POOL_MODE_LAST, + "default", + "host", + "direct") enum lv_endian { LV_LITTLE_ENDIAN = 1, /* 1234 */ diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index fccf0b9..81d6954 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -137,6 +137,41 @@ struct _virStorageNetHostDef { char *socket; /* path to unix socket */ }; +/* Information for a storage volume from a virStoragePool */ + +/* + * Used for volume "type" disk to indicate how to represent + * the disk source if the specified "pool" is of iscsi type. + */ +enum virStorageSourcePoolMode { + VIR_STORAGE_SOURCE_POOL_MODE_DEFAULT = 0, + + /* Use the path as it shows up on host, e.g. + * /dev/disk/by-path/ip-$ip-iscsi-$iqn:iscsi.iscsi-pool0-lun-1 + */ + VIR_STORAGE_SOURCE_POOL_MODE_HOST, + + /* Use the URI from the storage pool source element host attribute. E.g. + * file=iscsi://demo.org:6000/iqn.1992-01.com.example/1. + */ + VIR_STORAGE_SOURCE_POOL_MODE_DIRECT, + + VIR_STORAGE_SOURCE_POOL_MODE_LAST +}; + +VIR_ENUM_DECL(virStorageSourcePoolMode) + +typedef struct _virStorageSourcePoolDef virStorageSourcePoolDef; +struct _virStorageSourcePoolDef { + char *pool; /* pool name */ + char *volume; /* volume name */ + int voltype; /* enum virStorageVolType, internal only */ + int pooltype; /* enum virStoragePoolType, internal only */ + int actualtype; /* enum virStorageType, internal only */ + int mode; /* enum virStorageSourcePoolMode */ +}; +typedef virStorageSourcePoolDef *virStorageSourcePoolDefPtr; + # ifndef DEV_BSIZE # define DEV_BSIZE 512 -- 1.9.0

On 03/28/14 05:35, Eric Blake wrote:
Another struct being moved to util. This one doesn't have as much use yet, thankfully.
* src/conf/domain_conf.h (virDomainDiskSourcePoolMode) (virDomainDiskSourcePoolDef): Move... * src/util/virstoragefile.h (virStorageSourcePoolMode) (virStorageSourcePoolDef): ...and rename. * src/conf/domain_conf.c (virDomainDiskSourcePoolDefFree) (virDomainDiskSourceDefClear, virDomainDiskSourcePoolDefParse) (virDomainDiskDefParseXML, virDomainDiskSourceDefParse) (virDomainDiskSourceDefFormatInternal) (virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType): Adjust clients. * src/qemu/qemu_conf.c (qemuTranslateDiskSourcePool): Likewise. * src/libvirt_private.syms (domain_conf.h): Move symbols... (virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 23 +++++++++-------------- src/conf/domain_conf.h | 38 +++----------------------------------- src/libvirt_private.syms | 2 ++ src/qemu/qemu_conf.c | 10 +++++----- src/util/virstoragefile.c | 5 +++++ src/util/virstoragefile.h | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 54 deletions(-)
ACK Peter

This one is a relatively easy move. We don't ever convert the enum to or from strings (it is inferred from other elements in the xml, rather than directly represented). * src/conf/domain_conf.h (virDomainDiskSecretType): Move... * src/util/virstoragefile.h (virStorageSecreteType): ...and rename. * src/conf/domain_conf.c (virDomainDiskSecretType): Drop unused enum conversion. (virDomainDiskAuthClear, virDomainDiskDefParseXML) (virDomainDiskDefFormat): Adjust clients. * src/qemu/qemu_command.c (qemuGetSecretString): Likewise. * src/qemu/qemu_conf.c (qemuTranslateDiskSourcePoolAuth): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 19 +++++++------------ src/conf/domain_conf.h | 10 +--------- src/qemu/qemu_command.c | 8 ++++---- src/qemu/qemu_conf.c | 8 ++++---- src/util/virstoragefile.h | 9 +++++++++ 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 643b066..a5afacf 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -257,11 +257,6 @@ VIR_ENUM_IMPL(virDomainDiskErrorPolicy, VIR_DOMAIN_DISK_ERROR_POLICY_LAST, "ignore", "enospace") -VIR_ENUM_IMPL(virDomainDiskSecretType, VIR_DOMAIN_DISK_SECRET_TYPE_LAST, - "none", - "uuid", - "usage") - VIR_ENUM_IMPL(virDomainDiskIo, VIR_DOMAIN_DISK_IO_LAST, "default", "native", @@ -1246,10 +1241,10 @@ virDomainDiskAuthClear(virDomainDiskSourceDefPtr def) { VIR_FREE(def->auth.username); - if (def->auth.secretType == VIR_DOMAIN_DISK_SECRET_TYPE_USAGE) + if (def->auth.secretType == VIR_STORAGE_SECRET_TYPE_USAGE) VIR_FREE(def->auth.secret.usage); - def->auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_NONE; + def->auth.secretType = VIR_STORAGE_SECRET_TYPE_NONE; } @@ -5349,7 +5344,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } - def->src.auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_NONE; + def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_NONE; child = cur->children; while (child != NULL) { if (child->type == XML_ELEMENT_NODE && @@ -5386,7 +5381,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } if (authUUID != NULL) { - def->src.auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_UUID; + def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_UUID; if (virUUIDParse(authUUID, def->src.auth.secret.uuid) < 0) { virReportError(VIR_ERR_XML_ERROR, @@ -5395,7 +5390,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } } else if (authUsage != NULL) { - def->src.auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_USAGE; + def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_USAGE; def->src.auth.secret.usage = authUsage; authUsage = NULL; } @@ -14973,11 +14968,11 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferAddLit(buf, "<secret type='ceph'"); } - if (def->src.auth.secretType == VIR_DOMAIN_DISK_SECRET_TYPE_UUID) { + if (def->src.auth.secretType == VIR_STORAGE_SECRET_TYPE_UUID) { virUUIDFormat(def->src.auth.secret.uuid, uuidstr); virBufferAsprintf(buf, " uuid='%s'/>\n", uuidstr); } - if (def->src.auth.secretType == VIR_DOMAIN_DISK_SECRET_TYPE_USAGE) { + if (def->src.auth.secretType == VIR_STORAGE_SECRET_TYPE_USAGE) { virBufferEscapeString(buf, " usage='%s'/>\n", def->src.auth.secret.usage); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e5d945f..52b59a1 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -567,13 +567,6 @@ enum virDomainStartupPolicy { VIR_DOMAIN_STARTUP_POLICY_LAST }; -enum virDomainDiskSecretType { - VIR_DOMAIN_DISK_SECRET_TYPE_NONE, - VIR_DOMAIN_DISK_SECRET_TYPE_UUID, - VIR_DOMAIN_DISK_SECRET_TYPE_USAGE, - - VIR_DOMAIN_DISK_SECRET_TYPE_LAST -}; enum virDomainDeviceSGIO { VIR_DOMAIN_DEVICE_SGIO_DEFAULT = 0, @@ -617,7 +610,7 @@ struct _virDomainDiskSourceDef { virStorageSourcePoolDefPtr srcpool; struct { char *username; - int secretType; /* enum virDomainDiskSecretType */ + int secretType; /* enum virStorageSecretType */ union { unsigned char uuid[VIR_UUID_BUFLEN]; char *usage; @@ -2588,7 +2581,6 @@ VIR_ENUM_DECL(virDomainDiskBus) VIR_ENUM_DECL(virDomainDiskCache) VIR_ENUM_DECL(virDomainDiskErrorPolicy) VIR_ENUM_DECL(virDomainDiskIo) -VIR_ENUM_DECL(virDomainDiskSecretType) VIR_ENUM_DECL(virDomainDeviceSGIO) VIR_ENUM_DECL(virDomainDiskTray) VIR_ENUM_DECL(virDomainDiskDiscard) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3cdda68..099a777 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3192,17 +3192,17 @@ qemuGetSecretString(virConnectPtr conn, /* look up secret */ switch (diskSecretType) { - case VIR_DOMAIN_DISK_SECRET_TYPE_UUID: + case VIR_STORAGE_SECRET_TYPE_UUID: sec = virSecretLookupByUUID(conn, uuid); virUUIDFormat(uuid, uuidStr); break; - case VIR_DOMAIN_DISK_SECRET_TYPE_USAGE: + case VIR_STORAGE_SECRET_TYPE_USAGE: sec = virSecretLookupByUsage(conn, secretUsageType, usage); break; } if (!sec) { - if (diskSecretType == VIR_DOMAIN_DISK_SECRET_TYPE_UUID) { + if (diskSecretType == VIR_STORAGE_SECRET_TYPE_UUID) { virReportError(VIR_ERR_NO_SECRET, _("%s no secret matches uuid '%s'"), scheme, uuidStr); @@ -3217,7 +3217,7 @@ qemuGetSecretString(virConnectPtr conn, secret = (char *)conn->secretDriver->secretGetValue(sec, &secret_size, 0, VIR_SECRET_GET_VALUE_INTERNAL_CALL); if (!secret) { - if (diskSecretType == VIR_DOMAIN_DISK_SECRET_TYPE_UUID) { + if (diskSecretType == VIR_STORAGE_SECRET_TYPE_UUID) { virReportError(VIR_ERR_INTERNAL_ERROR, _("could not get value of the secret for " "username '%s' using uuid '%s'"), diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 96a2caf..3352936 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1224,7 +1224,7 @@ qemuTranslateDiskSourcePoolAuth(virDomainDiskDefPtr def, pooldef->source.auth.chap.username) < 0) goto cleanup; if (pooldef->source.auth.chap.secret.uuidUsable) { - def->src.auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_UUID; + def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_UUID; memcpy(def->src.auth.secret.uuid, pooldef->source.auth.chap.secret.uuid, VIR_UUID_BUFLEN); @@ -1232,14 +1232,14 @@ qemuTranslateDiskSourcePoolAuth(virDomainDiskDefPtr def, if (VIR_STRDUP(def->src.auth.secret.usage, pooldef->source.auth.chap.secret.usage) < 0) goto cleanup; - def->src.auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_USAGE; + def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_USAGE; } } else if (pooldef->source.authType == VIR_STORAGE_POOL_AUTH_CEPHX) { if (VIR_STRDUP(def->src.auth.username, pooldef->source.auth.cephx.username) < 0) goto cleanup; if (pooldef->source.auth.cephx.secret.uuidUsable) { - def->src.auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_UUID; + def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_UUID; memcpy(def->src.auth.secret.uuid, pooldef->source.auth.cephx.secret.uuid, VIR_UUID_BUFLEN); @@ -1247,7 +1247,7 @@ qemuTranslateDiskSourcePoolAuth(virDomainDiskDefPtr def, if (VIR_STRDUP(def->src.auth.secret.usage, pooldef->source.auth.cephx.secret.usage) < 0) goto cleanup; - def->src.auth.secretType = VIR_DOMAIN_DISK_SECRET_TYPE_USAGE; + def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_USAGE; } } ret = 0; diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 81d6954..68172c8 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -173,6 +173,15 @@ struct _virStorageSourcePoolDef { typedef virStorageSourcePoolDef *virStorageSourcePoolDefPtr; +enum virStorageSecretType { + VIR_STORAGE_SECRET_TYPE_NONE, + VIR_STORAGE_SECRET_TYPE_UUID, + VIR_STORAGE_SECRET_TYPE_USAGE, + + VIR_STORAGE_SECRET_TYPE_LAST +}; + + # ifndef DEV_BSIZE # define DEV_BSIZE 512 # endif -- 1.9.0

On 03/28/14 16:01, Eric Blake wrote:
This one is a relatively easy move. We don't ever convert the enum to or from strings (it is inferred from other elements in the xml, rather than directly represented).
* src/conf/domain_conf.h (virDomainDiskSecretType): Move... * src/util/virstoragefile.h (virStorageSecreteType): ...and rename. * src/conf/domain_conf.c (virDomainDiskSecretType): Drop unused enum conversion. (virDomainDiskAuthClear, virDomainDiskDefParseXML) (virDomainDiskDefFormat): Adjust clients. * src/qemu/qemu_command.c (qemuGetSecretString): Likewise. * src/qemu/qemu_conf.c (qemuTranslateDiskSourcePoolAuth): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 19 +++++++------------ src/conf/domain_conf.h | 10 +--------- src/qemu/qemu_command.c | 8 ++++---- src/qemu/qemu_conf.c | 8 ++++---- src/util/virstoragefile.h | 9 +++++++++ 5 files changed, 25 insertions(+), 29 deletions(-)
ACK Peter

With this patch, all information related to a host resource in a storage file backing chain now lives in util/virstoragefile.h. The next step will be to consolidate various places that have been tracking backing chain details to all use a common struct. The changes to tools/Makefile.am were made necessary by the fact that virstorageencryption includes uses of libxml, and is now pulled in by inclusion from virstoragefile.h. No additional libraries are linked into the final image, and in comparison, the build of the setuid library in src/Makefile.am already was using LIBXML_CFLAGS via AM_CFLAGS. * src/conf/domain_conf.h (virDomainDiskSourceDef): Move... * src/util/virstoragefile.h (virStorageSource): ...and rename. * src/conf/domain_conf.c (virDomainDiskSourceDefClear) (virDomainDiskAuthClear): Adjust clients. * tools/Makefile.am (virt_login_shell_CFLAGS) (virt_host_validate_CFLAGS): Add libxml headers. Signed-off-by: Eric Blake <eblake@redhat.com> --- Surprisingly small in size; a lot of the heavy lifting was done piecemeal in the earlier commits. This one took me a while to figure out, because it took me longer than expected to figure out the best way to resolve the build failure of virt-login-shell and still make sure I wasn't introducing a problem into that setuid helper. src/conf/domain_conf.c | 4 ++-- src/conf/domain_conf.h | 32 ++------------------------------ src/util/virstoragefile.h | 32 ++++++++++++++++++++++++++++++++ tools/Makefile.am | 2 ++ 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a5afacf..b38021d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1193,7 +1193,7 @@ virDomainDiskSourcePoolDefFree(virStorageSourcePoolDefPtr def) static void -virDomainDiskSourceDefClear(virDomainDiskSourceDefPtr def) +virDomainDiskSourceDefClear(virStorageSourcePtr def) { size_t i; @@ -1237,7 +1237,7 @@ virDomainDiskDefFree(virDomainDiskDefPtr def) void -virDomainDiskAuthClear(virDomainDiskSourceDefPtr def) +virDomainDiskAuthClear(virStorageSourcePtr def) { VIR_FREE(def->auth.username); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 52b59a1..b011847 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -595,38 +595,10 @@ struct _virDomainBlockIoTuneInfo { }; typedef virDomainBlockIoTuneInfo *virDomainBlockIoTuneInfoPtr; -typedef struct _virDomainDiskSourceDef virDomainDiskSourceDef; -typedef virDomainDiskSourceDef *virDomainDiskSourceDefPtr; - -/* Stores information related to a host resource. In the case of - * backing chains, multiple source disks join to form a single guest - * view. TODO Move this to util/ */ -struct _virDomainDiskSourceDef { - int type; /* enum virStorageType */ - char *path; - int protocol; /* enum virStorageNetProtocol */ - size_t nhosts; - virStorageNetHostDefPtr hosts; - virStorageSourcePoolDefPtr srcpool; - struct { - char *username; - int secretType; /* enum virStorageSecretType */ - union { - unsigned char uuid[VIR_UUID_BUFLEN]; - char *usage; - } secret; - } auth; - virStorageEncryptionPtr encryption; - char *driverName; - int format; /* enum virStorageFileFormat */ - - size_t nseclabels; - virSecurityDeviceLabelDefPtr *seclabels; -}; /* Stores the virtual disk configuration */ struct _virDomainDiskDef { - virDomainDiskSourceDef src; + virStorageSource src; int device; /* enum virDomainDiskDevice */ int bus; /* enum virDomainDiskBus */ @@ -2153,7 +2125,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def); void virDomainInputDefFree(virDomainInputDefPtr def); void virDomainDiskDefFree(virDomainDiskDefPtr def); void virDomainLeaseDefFree(virDomainLeaseDefPtr def); -void virDomainDiskAuthClear(virDomainDiskSourceDefPtr def); +void virDomainDiskAuthClear(virStorageSourcePtr def); int virDomainDiskGetType(virDomainDiskDefPtr def); void virDomainDiskSetType(virDomainDiskDefPtr def, int type); int virDomainDiskGetActualType(virDomainDiskDefPtr def); diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 68172c8..a6dcfa4 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -25,6 +25,8 @@ # define __VIR_STORAGE_FILE_H__ # include "virbitmap.h" +# include "virseclabel.h" +# include "virstorageencryption.h" # include "virutil.h" /* Minimum header size required to probe all known formats with @@ -182,6 +184,36 @@ enum virStorageSecretType { }; +typedef struct _virStorageSource virStorageSource; +typedef virStorageSource *virStorageSourcePtr; + +/* Stores information related to a host resource. In the case of + * backing chains, multiple source disks join to form a single guest + * view. */ +struct _virStorageSource { + int type; /* enum virStorageType */ + char *path; + int protocol; /* enum virStorageNetProtocol */ + size_t nhosts; + virStorageNetHostDefPtr hosts; + virStorageSourcePoolDefPtr srcpool; + struct { + char *username; + int secretType; /* enum virStorageSecretType */ + union { + unsigned char uuid[VIR_UUID_BUFLEN]; + char *usage; + } secret; + } auth; + virStorageEncryptionPtr encryption; + char *driverName; + int format; /* enum virStorageFileFormat */ + + size_t nseclabels; + virSecurityDeviceLabelDefPtr *seclabels; +}; + + # ifndef DEV_BSIZE # define DEV_BSIZE 512 # endif diff --git a/tools/Makefile.am b/tools/Makefile.am index 6847f13..93d642d 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -148,6 +148,7 @@ virt_host_validate_LDADD = \ $(NULL) virt_host_validate_CFLAGS = \ + $(LIBXML_CFLAGS) \ $(WARN_CFLAGS) \ $(PIE_CFLAGS) \ $(COVERAGE_CFLAGS) \ @@ -173,6 +174,7 @@ virt_login_shell_LDADD = \ virt_login_shell_CFLAGS = \ -DLIBVIRT_SETUID_RPC_CLIENT \ + $(LIBXML_CFLAGS) \ $(WARN_CFLAGS) \ $(PIE_CFLAGS) \ $(COVERAGE_CFLAGS) -- 1.9.0

On 03/28/14 23:10, Eric Blake wrote:
With this patch, all information related to a host resource in a storage file backing chain now lives in util/virstoragefile.h. The next step will be to consolidate various places that have been tracking backing chain details to all use a common struct.
The changes to tools/Makefile.am were made necessary by the fact that virstorageencryption includes uses of libxml, and is now pulled in by inclusion from virstoragefile.h. No additional libraries are linked into the final image, and in comparison, the build of the setuid library in src/Makefile.am already was using LIBXML_CFLAGS via AM_CFLAGS.
* src/conf/domain_conf.h (virDomainDiskSourceDef): Move... * src/util/virstoragefile.h (virStorageSource): ...and rename. * src/conf/domain_conf.c (virDomainDiskSourceDefClear) (virDomainDiskAuthClear): Adjust clients. * tools/Makefile.am (virt_login_shell_CFLAGS) (virt_host_validate_CFLAGS): Add libxml headers.
Signed-off-by: Eric Blake <eblake@redhat.com> ---
Surprisingly small in size; a lot of the heavy lifting was done piecemeal in the earlier commits.
This one took me a while to figure out, because it took me longer than expected to figure out the best way to resolve the build failure of virt-login-shell and still make sure I wasn't introducing a problem into that setuid helper.
src/conf/domain_conf.c | 4 ++-- src/conf/domain_conf.h | 32 ++------------------------------ src/util/virstoragefile.h | 32 ++++++++++++++++++++++++++++++++ tools/Makefile.am | 2 ++ 4 files changed, 38 insertions(+), 32 deletions(-)
ACK Peter

The code in virstoragefile.c is getting more complex as I consolidate backing chain handling code. But for the setuid virt-login-shell, we don't need to crawl backing chains. It's easier to audit things for setuid security if there are fewer files involved, so this patch moves the one function that virFileOpen() was actually relying on to also live in virfile.c. * src/util/virstoragefile.c (virStorageFileIsSharedFS) (virStorageFileIsSharedFSType): Move... * src/util/virfile.c (virFileIsSharedFS, virFileIsSharedFSType): ...to here, and rename. (virFileOpenAs): Update caller. * src/security/security_selinux.c (virSecuritySELinuxSetFileconHelper) (virSecuritySELinuxSetSecurityAllLabel) (virSecuritySELinuxRestoreSecurityImageLabelInt): Likewise. * src/security/security_dac.c (virSecurityDACRestoreSecurityImageLabelInt): Likewise. * src/qemu/qemu_driver.c (qemuOpenFileAs): Likewise. * src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise. * src/util/virstoragefile.h: Adjust declarations. * src/util/virfile.h: Likewise. * src/libvirt_private.syms (virfile.h, virstoragefile.h): Move symbols as appropriate. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/libvirt_private.syms | 4 +- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_migration.c | 2 +- src/security/security_dac.c | 2 +- src/security/security_selinux.c | 8 +-- src/util/virfile.c | 122 ++++++++++++++++++++++++++++++++++++++- src/util/virfile.h | 13 ++++- src/util/virstoragefile.c | 123 +--------------------------------------- src/util/virstoragefile.h | 12 ---- 9 files changed, 144 insertions(+), 144 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index da70ee3..07d4f36 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1242,6 +1242,8 @@ virFileIsDir; virFileIsExecutable; virFileIsLink; virFileIsMountPoint; +virFileIsSharedFS; +virFileIsSharedFSType; virFileLinkPointsTo; virFileLock; virFileLoopDeviceAssociate; @@ -1829,8 +1831,6 @@ virStorageFileGetMetadataFromBuf; virStorageFileGetMetadataFromFD; virStorageFileGetSCSIKey; virStorageFileIsClusterFS; -virStorageFileIsSharedFS; -virStorageFileIsSharedFSType; virStorageFileProbeFormat; virStorageFileProbeFormatFromBuf; virStorageFileResize; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b57700e..9d48a46 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2790,7 +2790,7 @@ qemuOpenFileAs(uid_t fallback_uid, gid_t fallback_gid, bool bypass_security = false; unsigned int vfoflags = 0; int fd = -1; - int path_shared = virStorageFileIsSharedFS(path); + int path_shared = virFileIsSharedFS(path); uid_t uid = geteuid(); gid_t gid = getegid(); diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index b389d0a..593d2d3 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1534,7 +1534,7 @@ qemuMigrationIsSafe(virDomainDefPtr def) int rc; if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_FILE) { - if ((rc = virStorageFileIsSharedFS(src)) < 0) + if ((rc = virFileIsSharedFS(src)) < 0) return false; else if (rc == 0) continue; diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 00c81d0..8512767 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -402,7 +402,7 @@ virSecurityDACRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr, * VM's I/O attempts :-) */ if (migrated) { - int rc = virStorageFileIsSharedFS(src); + int rc = virFileIsSharedFS(src); if (rc < 0) return -1; if (rc == 1) { diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index aa21a22..bfac11c 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -920,8 +920,7 @@ virSecuritySELinuxSetFileconHelper(const char *path, char *tcon, bool optional) return -1; } else { const char *msg; - if ((virStorageFileIsSharedFSType(path, - VIR_STORAGE_FILE_SHFS_NFS) == 1) && + if (virFileIsSharedFSType(path, VIR_FILE_SHFS_NFS) == 1 && security_get_boolean_active("virt_use_nfs") != 1) { msg = _("Setting security context '%s' on '%s' not supported. " "Consider setting virt_use_nfs"); @@ -1172,7 +1171,7 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr, * VM's I/O attempts :-) */ if (migrated) { - int rc = virStorageFileIsSharedFS(src); + int rc = virFileIsSharedFS(src); if (rc < 0) return -1; if (rc == 1) { @@ -2323,8 +2322,7 @@ virSecuritySELinuxSetSecurityAllLabel(virSecurityManagerPtr mgr, if (stdin_path) { if (virSecuritySELinuxSetFilecon(stdin_path, data->content_context) < 0 && - virStorageFileIsSharedFSType(stdin_path, - VIR_STORAGE_FILE_SHFS_NFS) != 1) + virFileIsSharedFSType(stdin_path, VIR_FILE_SHFS_NFS) != 1) return -1; } diff --git a/src/util/virfile.c b/src/util/virfile.c index 6debbb0..fcc65b1 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -43,6 +43,13 @@ # include <sys/mman.h> #endif +#ifdef __linux__ +# if HAVE_LINUX_MAGIC_H +# include <linux/magic.h> +# endif +# include <sys/statfs.h> +#endif + #if defined(__linux__) && HAVE_DECL_LO_FLAGS_AUTOCLEAR # include <linux/loop.h> # include <sys/ioctl.h> @@ -2050,7 +2057,7 @@ virFileOpenAs(const char *path, int openflags, mode_t mode, /* On Linux we can also verify the FS-type of the * directory. (this is a NOP on other platforms). */ - if (virStorageFileIsSharedFS(path) <= 0) + if (virFileIsSharedFS(path) <= 0) goto error; } @@ -2646,3 +2653,116 @@ int virFilePrintf(FILE *fp, const char *msg, ...) return ret; } + + +#ifdef __linux__ + +# ifndef NFS_SUPER_MAGIC +# define NFS_SUPER_MAGIC 0x6969 +# endif +# ifndef OCFS2_SUPER_MAGIC +# define OCFS2_SUPER_MAGIC 0x7461636f +# endif +# ifndef GFS2_MAGIC +# define GFS2_MAGIC 0x01161970 +# endif +# ifndef AFS_FS_MAGIC +# define AFS_FS_MAGIC 0x6B414653 +# endif +# ifndef SMB_SUPER_MAGIC +# define SMB_SUPER_MAGIC 0x517B +# endif +# ifndef CIFS_SUPER_MAGIC +# define CIFS_SUPER_MAGIC 0xFF534D42 +# endif + +int +virFileIsSharedFSType(const char *path, + int fstypes) +{ + char *dirpath, *p; + struct statfs sb; + int statfs_ret; + + if (VIR_STRDUP(dirpath, path) < 0) + return -1; + + do { + + /* Try less and less of the path until we get to a + * directory we can stat. Even if we don't have 'x' + * permission on any directory in the path on the NFS + * server (assuming it's NFS), we will be able to stat the + * mount point, and that will properly tell us if the + * fstype is NFS. + */ + + if ((p = strrchr(dirpath, '/')) == NULL) { + virReportSystemError(EINVAL, + _("Invalid relative path '%s'"), path); + VIR_FREE(dirpath); + return -1; + } + + if (p == dirpath) + *(p+1) = '\0'; + else + *p = '\0'; + + statfs_ret = statfs(dirpath, &sb); + + } while ((statfs_ret < 0) && (p != dirpath)); + + VIR_FREE(dirpath); + + if (statfs_ret < 0) { + virReportSystemError(errno, + _("cannot determine filesystem for '%s'"), + path); + return -1; + } + + VIR_DEBUG("Check if path %s with FS magic %lld is shared", + path, (long long int)sb.f_type); + + if ((fstypes & VIR_FILE_SHFS_NFS) && + (sb.f_type == NFS_SUPER_MAGIC)) + return 1; + + if ((fstypes & VIR_FILE_SHFS_GFS2) && + (sb.f_type == GFS2_MAGIC)) + return 1; + if ((fstypes & VIR_FILE_SHFS_OCFS) && + (sb.f_type == OCFS2_SUPER_MAGIC)) + return 1; + if ((fstypes & VIR_FILE_SHFS_AFS) && + (sb.f_type == AFS_FS_MAGIC)) + return 1; + if ((fstypes & VIR_FILE_SHFS_SMB) && + (sb.f_type == SMB_SUPER_MAGIC)) + return 1; + if ((fstypes & VIR_FILE_SHFS_CIFS) && + (sb.f_type == CIFS_SUPER_MAGIC)) + return 1; + + return 0; +} +#else +int virFileIsSharedFSType(const char *path ATTRIBUTE_UNUSED, + int fstypes ATTRIBUTE_UNUSED) +{ + /* XXX implement me :-) */ + return 0; +} +#endif + +int virFileIsSharedFS(const char *path) +{ + return virFileIsSharedFSType(path, + VIR_FILE_SHFS_NFS | + VIR_FILE_SHFS_GFS2 | + VIR_FILE_SHFS_OCFS | + VIR_FILE_SHFS_AFS | + VIR_FILE_SHFS_SMB | + VIR_FILE_SHFS_CIFS); +} diff --git a/src/util/virfile.h b/src/util/virfile.h index 302b74f..638378a 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -1,7 +1,7 @@ /* * virfile.h: safer file handling * - * Copyright (C) 2010-2011, 2013 Red Hat, Inc. + * Copyright (C) 2010-2014 Red Hat, Inc. * Copyright (C) 2010 IBM Corporation * Copyright (C) 2010 Stefan Berger * Copyright (C) 2010 Eric Blake @@ -159,6 +159,17 @@ bool virFileIsDir (const char *file) ATTRIBUTE_NONNULL(1); bool virFileExists(const char *file) ATTRIBUTE_NONNULL(1); bool virFileIsExecutable(const char *file) ATTRIBUTE_NONNULL(1); +enum { + VIR_FILE_SHFS_NFS = (1 << 0), + VIR_FILE_SHFS_GFS2 = (1 << 1), + VIR_FILE_SHFS_OCFS = (1 << 2), + VIR_FILE_SHFS_AFS = (1 << 3), + VIR_FILE_SHFS_SMB = (1 << 4), + VIR_FILE_SHFS_CIFS = (1 << 5), +}; + +int virFileIsSharedFSType(const char *path, int fstypes) ATTRIBUTE_NONNULL(1); +int virFileIsSharedFS(const char *path) ATTRIBUTE_NONNULL(1); int virFileIsMountPoint(const char *file) ATTRIBUTE_NONNULL(1); int virFileGetMountSubtree(const char *mtabpath, diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index e1b69ec..e201bc9 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -28,12 +28,6 @@ #include <unistd.h> #include <fcntl.h> #include <stdlib.h> -#ifdef __linux__ -# if HAVE_LINUX_MAGIC_H -# include <linux/magic.h> -# endif -# include <sys/statfs.h> -#endif #include "dirname.h" #include "viralloc.h" #include "virerror.h" @@ -1283,126 +1277,15 @@ virStorageFileResize(const char *path, return ret; } -#ifdef __linux__ - -# ifndef NFS_SUPER_MAGIC -# define NFS_SUPER_MAGIC 0x6969 -# endif -# ifndef OCFS2_SUPER_MAGIC -# define OCFS2_SUPER_MAGIC 0x7461636f -# endif -# ifndef GFS2_MAGIC -# define GFS2_MAGIC 0x01161970 -# endif -# ifndef AFS_FS_MAGIC -# define AFS_FS_MAGIC 0x6B414653 -# endif -# ifndef SMB_SUPER_MAGIC -# define SMB_SUPER_MAGIC 0x517B -# endif -# ifndef CIFS_SUPER_MAGIC -# define CIFS_SUPER_MAGIC 0xFF534D42 -# endif - - -int virStorageFileIsSharedFSType(const char *path, - int fstypes) -{ - char *dirpath, *p; - struct statfs sb; - int statfs_ret; - - if (VIR_STRDUP(dirpath, path) < 0) - return -1; - - do { - - /* Try less and less of the path until we get to a - * directory we can stat. Even if we don't have 'x' - * permission on any directory in the path on the NFS - * server (assuming it's NFS), we will be able to stat the - * mount point, and that will properly tell us if the - * fstype is NFS. - */ - - if ((p = strrchr(dirpath, '/')) == NULL) { - virReportSystemError(EINVAL, - _("Invalid relative path '%s'"), path); - VIR_FREE(dirpath); - return -1; - } - - if (p == dirpath) - *(p+1) = '\0'; - else - *p = '\0'; - - statfs_ret = statfs(dirpath, &sb); - - } while ((statfs_ret < 0) && (p != dirpath)); - - VIR_FREE(dirpath); - - if (statfs_ret < 0) { - virReportSystemError(errno, - _("cannot determine filesystem for '%s'"), - path); - return -1; - } - - VIR_DEBUG("Check if path %s with FS magic %lld is shared", - path, (long long int)sb.f_type); - - if ((fstypes & VIR_STORAGE_FILE_SHFS_NFS) && - (sb.f_type == NFS_SUPER_MAGIC)) - return 1; - - if ((fstypes & VIR_STORAGE_FILE_SHFS_GFS2) && - (sb.f_type == GFS2_MAGIC)) - return 1; - if ((fstypes & VIR_STORAGE_FILE_SHFS_OCFS) && - (sb.f_type == OCFS2_SUPER_MAGIC)) - return 1; - if ((fstypes & VIR_STORAGE_FILE_SHFS_AFS) && - (sb.f_type == AFS_FS_MAGIC)) - return 1; - if ((fstypes & VIR_STORAGE_FILE_SHFS_SMB) && - (sb.f_type == SMB_SUPER_MAGIC)) - return 1; - if ((fstypes & VIR_STORAGE_FILE_SHFS_CIFS) && - (sb.f_type == CIFS_SUPER_MAGIC)) - return 1; - - return 0; -} -#else -int virStorageFileIsSharedFSType(const char *path ATTRIBUTE_UNUSED, - int fstypes ATTRIBUTE_UNUSED) -{ - /* XXX implement me :-) */ - return 0; -} -#endif - -int virStorageFileIsSharedFS(const char *path) -{ - return virStorageFileIsSharedFSType(path, - VIR_STORAGE_FILE_SHFS_NFS | - VIR_STORAGE_FILE_SHFS_GFS2 | - VIR_STORAGE_FILE_SHFS_OCFS | - VIR_STORAGE_FILE_SHFS_AFS | - VIR_STORAGE_FILE_SHFS_SMB | - VIR_STORAGE_FILE_SHFS_CIFS); -} int virStorageFileIsClusterFS(const char *path) { /* These are coherent cluster filesystems known to be safe for * migration with cache != none */ - return virStorageFileIsSharedFSType(path, - VIR_STORAGE_FILE_SHFS_GFS2 | - VIR_STORAGE_FILE_SHFS_OCFS); + return virFileIsSharedFSType(path, + VIR_FILE_SHFS_GFS2 | + VIR_FILE_SHFS_OCFS); } #ifdef LVS diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index a6dcfa4..18db09e 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -250,19 +250,7 @@ int virStorageFileResize(const char *path, unsigned long long orig_capacity, bool pre_allocate); -enum { - VIR_STORAGE_FILE_SHFS_NFS = (1 << 0), - VIR_STORAGE_FILE_SHFS_GFS2 = (1 << 1), - VIR_STORAGE_FILE_SHFS_OCFS = (1 << 2), - VIR_STORAGE_FILE_SHFS_AFS = (1 << 3), - VIR_STORAGE_FILE_SHFS_SMB = (1 << 4), - VIR_STORAGE_FILE_SHFS_CIFS = (1 << 5), -}; - -int virStorageFileIsSharedFS(const char *path); int virStorageFileIsClusterFS(const char *path); -int virStorageFileIsSharedFSType(const char *path, - int fstypes); int virStorageFileGetLVMKey(const char *path, char **key); -- 1.9.0

On 03/29/14 21:46, Eric Blake wrote:
The code in virstoragefile.c is getting more complex as I consolidate backing chain handling code. But for the setuid virt-login-shell, we don't need to crawl backing chains. It's easier to audit things for setuid security if there are fewer files involved, so this patch moves the one function that virFileOpen() was actually relying on to also live in virfile.c.
* src/util/virstoragefile.c (virStorageFileIsSharedFS) (virStorageFileIsSharedFSType): Move... * src/util/virfile.c (virFileIsSharedFS, virFileIsSharedFSType): ...to here, and rename. (virFileOpenAs): Update caller. * src/security/security_selinux.c (virSecuritySELinuxSetFileconHelper) (virSecuritySELinuxSetSecurityAllLabel) (virSecuritySELinuxRestoreSecurityImageLabelInt): Likewise. * src/security/security_dac.c (virSecurityDACRestoreSecurityImageLabelInt): Likewise. * src/qemu/qemu_driver.c (qemuOpenFileAs): Likewise. * src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise. * src/util/virstoragefile.h: Adjust declarations. * src/util/virfile.h: Likewise. * src/libvirt_private.syms (virfile.h, virstoragefile.h): Move symbols as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/libvirt_private.syms | 4 +- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_migration.c | 2 +- src/security/security_dac.c | 2 +- src/security/security_selinux.c | 8 +-- src/util/virfile.c | 122 ++++++++++++++++++++++++++++++++++++++- src/util/virfile.h | 13 ++++- src/util/virstoragefile.c | 123 +--------------------------------------- src/util/virstoragefile.h | 12 ---- 9 files changed, 144 insertions(+), 144 deletions(-)
ACK, Peter

The only remaining reason that virt-login-shell was trying to link against virstoragefile was because of a call to virStorageFileFormatTypeToString when spawning a qemu-nbd process - but setuid processes shouldn't be spawning qemu-nbd. * src/util/virfile.c (virFileLoopDeviceAssociate) (virFileNBDDeviceAssociate): Cripple in setuid builds. * src/Makefile.am (libvirt_setuid_rpc_client_la_SOURCES): Drop virstoragefile from the list. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/Makefile.am | 1 - src/util/virfile.c | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 38b2697..f6690b6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2069,7 +2069,6 @@ libvirt_setuid_rpc_client_la_SOURCES = \ util/virprocess.c \ util/virrandom.c \ util/virsocketaddr.c \ - util/virstoragefile.c \ util/virstring.c \ util/virtime.c \ util/virthread.c \ diff --git a/src/util/virfile.c b/src/util/virfile.c index fcc65b1..a28cbf1 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -540,7 +540,8 @@ int virFileUpdatePerm(const char *path, } -#if defined(__linux__) && HAVE_DECL_LO_FLAGS_AUTOCLEAR +#if defined(__linux__) && HAVE_DECL_LO_FLAGS_AUTOCLEAR && \ + !defined(LIBVIRT_SETUID_RPC_CLIENT) # if HAVE_DECL_LOOP_CTL_GET_FREE -- 1.9.0

On 03/29/14 21:56, Eric Blake wrote:
The only remaining reason that virt-login-shell was trying to link against virstoragefile was because of a call to virStorageFileFormatTypeToString when spawning a qemu-nbd process - but setuid processes shouldn't be spawning qemu-nbd.
* src/util/virfile.c (virFileLoopDeviceAssociate) (virFileNBDDeviceAssociate): Cripple in setuid builds. * src/Makefile.am (libvirt_setuid_rpc_client_la_SOURCES): Drop virstoragefile from the list.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/Makefile.am | 1 - src/util/virfile.c | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-)
ACK Peter

Move some functions out of domain_conf for use in the next patch where snapshot starts to directly use structs in virstoragefile. * src/conf/domain_conf.c (virDomainDiskDefFree) (virDomainDiskSourcePoolDefParse): Adjust callers. (virDomainDiskSourceDefClear, virDomainDiskSourcePoolDefFree) (virDomainDiskAuthClear): Move... * src/util/virstoragefile.c (virStorageSourceClear) (virStorageSourcePoolDefFree, virStorageSourceAuthClear): ...and rename. * src/conf/domain_conf.h (virDomainDiskAuthClear): Drop declaration. * src/qemu/qemu_conf.c (qemuTranslateDiskSourcePool): Adjust caller. * src/util/virstoragefile.h: Declare them. * src/libvirt_private.syms (virstoragefile.h): Export them. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 52 ++--------------------------------------------- src/conf/domain_conf.h | 1 - src/libvirt_private.syms | 4 +++- src/qemu/qemu_conf.c | 2 +- src/util/virstoragefile.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ src/util/virstoragefile.h | 3 +++ 6 files changed, 58 insertions(+), 53 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b38021d..0af5be7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1179,42 +1179,6 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def) VIR_FREE(def); } -static void -virDomainDiskSourcePoolDefFree(virStorageSourcePoolDefPtr def) -{ - if (!def) - return; - - VIR_FREE(def->pool); - VIR_FREE(def->volume); - - VIR_FREE(def); -} - - -static void -virDomainDiskSourceDefClear(virStorageSourcePtr def) -{ - size_t i; - - if (!def) - return; - - VIR_FREE(def->path); - virDomainDiskSourcePoolDefFree(def->srcpool); - VIR_FREE(def->driverName); - virStorageEncryptionFree(def->encryption); - - if (def->seclabels) { - for (i = 0; i < def->nseclabels; i++) - virSecurityDeviceLabelDefFree(def->seclabels[i]); - VIR_FREE(def->seclabels); - } - - virStorageNetHostDefFree(def->nhosts, def->hosts); - virDomainDiskAuthClear(def); -} - void virDomainDiskDefFree(virDomainDiskDefPtr def) @@ -1222,7 +1186,7 @@ virDomainDiskDefFree(virDomainDiskDefPtr def) if (!def) return; - virDomainDiskSourceDefClear(&def->src); + virStorageSourceClear(&def->src); VIR_FREE(def->serial); VIR_FREE(def->dst); virStorageFileFreeMetadata(def->backingChain); @@ -1236,18 +1200,6 @@ virDomainDiskDefFree(virDomainDiskDefPtr def) } -void -virDomainDiskAuthClear(virStorageSourcePtr def) -{ - VIR_FREE(def->auth.username); - - if (def->auth.secretType == VIR_STORAGE_SECRET_TYPE_USAGE) - VIR_FREE(def->auth.secret.usage); - - def->auth.secretType = VIR_STORAGE_SECRET_TYPE_NONE; -} - - int virDomainDiskGetType(virDomainDiskDefPtr def) { @@ -4995,7 +4947,7 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node, ret = 0; cleanup: - virDomainDiskSourcePoolDefFree(source); + virStorageSourcePoolDefFree(source); VIR_FREE(mode); return ret; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index b011847..02ac5de 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2125,7 +2125,6 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def); void virDomainInputDefFree(virDomainInputDefPtr def); void virDomainDiskDefFree(virDomainDiskDefPtr def); void virDomainLeaseDefFree(virDomainLeaseDefPtr def); -void virDomainDiskAuthClear(virStorageSourcePtr def); int virDomainDiskGetType(virDomainDiskDefPtr def); void virDomainDiskSetType(virDomainDiskDefPtr def, int type); int virDomainDiskGetActualType(virDomainDiskDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 07d4f36..2d12105 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -181,7 +181,6 @@ virDomainDeviceGetInfo; virDomainDeviceInfoCopy; virDomainDeviceInfoIterate; virDomainDeviceTypeToString; -virDomainDiskAuthClear; virDomainDiskBusTypeToString; virDomainDiskCacheTypeFromString; virDomainDiskCacheTypeToString; @@ -1840,6 +1839,9 @@ virStorageNetHostDefFree; virStorageNetHostTransportTypeFromString; virStorageNetHostTransportTypeToString; virStorageNetProtocolTypeToString; +virStorageSourceAuthClear; +virStorageSourceClear; +virStorageSourcePoolDefFree; virStorageSourcePoolModeTypeFromString; virStorageSourcePoolModeTypeToString; virStorageTypeFromString; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 3352936..209558d 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1310,7 +1310,7 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, VIR_FREE(def->src.path); virStorageNetHostDefFree(def->src.nhosts, def->src.hosts); - virDomainDiskAuthClear(&def->src); + virStorageSourceAuthClear(&def->src); switch ((enum virStoragePoolType) pooldef->type) { case VIR_STORAGE_POOL_DIR: diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index e201bc9..bbaa171 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1531,3 +1531,52 @@ virStorageNetHostDefCopy(size_t nhosts, virStorageNetHostDefFree(nhosts, ret); return NULL; } + + +void +virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def) +{ + if (!def) + return; + + VIR_FREE(def->pool); + VIR_FREE(def->volume); + + VIR_FREE(def); +} + + +void +virStorageSourceAuthClear(virStorageSourcePtr def) +{ + VIR_FREE(def->auth.username); + + if (def->auth.secretType == VIR_STORAGE_SECRET_TYPE_USAGE) + VIR_FREE(def->auth.secret.usage); + + def->auth.secretType = VIR_STORAGE_SECRET_TYPE_NONE; +} + + +void +virStorageSourceClear(virStorageSourcePtr def) +{ + size_t i; + + if (!def) + return; + + VIR_FREE(def->path); + virStorageSourcePoolDefFree(def->srcpool); + VIR_FREE(def->driverName); + virStorageEncryptionFree(def->encryption); + + if (def->seclabels) { + for (i = 0; i < def->nseclabels; i++) + virSecurityDeviceLabelDefFree(def->seclabels[i]); + VIR_FREE(def->seclabels); + } + + virStorageNetHostDefFree(def->nhosts, def->hosts); + virStorageSourceAuthClear(def); +} diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 18db09e..4980960 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -262,5 +262,8 @@ void virStorageNetHostDefFree(size_t nhosts, virStorageNetHostDefPtr hosts); virStorageNetHostDefPtr virStorageNetHostDefCopy(size_t nhosts, virStorageNetHostDefPtr hosts); +void virStorageSourceAuthClear(virStorageSourcePtr def); +void virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def); +void virStorageSourceClear(virStorageSourcePtr def); #endif /* __VIR_STORAGE_FILE_H__ */ -- 1.9.0

On 03/29/14 22:05, Eric Blake wrote:
Move some functions out of domain_conf for use in the next patch where snapshot starts to directly use structs in virstoragefile.
* src/conf/domain_conf.c (virDomainDiskDefFree) (virDomainDiskSourcePoolDefParse): Adjust callers. (virDomainDiskSourceDefClear, virDomainDiskSourcePoolDefFree) (virDomainDiskAuthClear): Move... * src/util/virstoragefile.c (virStorageSourceClear) (virStorageSourcePoolDefFree, virStorageSourceAuthClear): ...and rename. * src/conf/domain_conf.h (virDomainDiskAuthClear): Drop declaration. * src/qemu/qemu_conf.c (qemuTranslateDiskSourcePool): Adjust caller. * src/util/virstoragefile.h: Declare them. * src/libvirt_private.syms (virstoragefile.h): Export them.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 52 ++--------------------------------------------- src/conf/domain_conf.h | 1 - src/libvirt_private.syms | 4 +++- src/qemu/qemu_conf.c | 2 +- src/util/virstoragefile.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ src/util/virstoragefile.h | 3 +++ 6 files changed, 58 insertions(+), 53 deletions(-)
ACK, Peter

Now that we have a common struct, it's time to start using it! Since external snapshots make a longer backing chain, it is only natural to use the same struct for the file created by the snapshot as what we use for <domain> disks. * src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Use common struct instead of open-coded duplicate fields. * src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear) (virDomainSnapshotDiskDefParseXML, virDomainSnapshotAlignDisks) (virDomainSnapshotDiskDefFormat) (virDomainSnapshotDiskGetActualType): Adjust clients. * src/qemu/qemu_conf.c (qemuTranslateSnapshotDiskSourcePool): Likewise. * src/qemu/qemu_driver.c (qemuDomainSnapshotDiskGetSourceString) (qemuDomainSnapshotCreateInactiveExternal) (qemuDomainSnapshotPrepareDiskExternalOverlayActive) (qemuDomainSnapshotPrepareDiskExternal) (qemuDomainSnapshotPrepare) (qemuDomainSnapshotCreateSingleDiskActive): Likewise. * src/storage/storage_driver.c (virStorageFileInitFromSnapshotDef): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/snapshot_conf.c | 68 +++++++++++++++++------------------ src/conf/snapshot_conf.h | 8 ++--- src/qemu/qemu_conf.c | 2 +- src/qemu/qemu_driver.c | 86 ++++++++++++++++++++++---------------------- src/storage/storage_driver.c | 8 ++--- 5 files changed, 85 insertions(+), 87 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index ebb3bb4..3bd4732 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -83,9 +83,7 @@ static void virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDefPtr disk) { VIR_FREE(disk->name); - VIR_FREE(disk->file); - virStorageNetHostDefFree(disk->nhosts, disk->hosts); - disk->nhosts = 0; + virStorageSourceClear(&disk->src); } void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def) @@ -134,39 +132,39 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, } if ((type = virXMLPropString(node, "type"))) { - if ((def->type = virStorageTypeFromString(type)) < 0 || - def->type == VIR_STORAGE_TYPE_VOLUME || - def->type == VIR_STORAGE_TYPE_DIR) { + if ((def->src.type = virStorageTypeFromString(type)) < 0 || + def->src.type == VIR_STORAGE_TYPE_VOLUME || + def->src.type == VIR_STORAGE_TYPE_DIR) { virReportError(VIR_ERR_XML_ERROR, _("unknown disk snapshot type '%s'"), type); goto cleanup; } } else { - def->type = VIR_STORAGE_TYPE_FILE; + def->src.type = VIR_STORAGE_TYPE_FILE; } for (cur = node->children; cur; cur = cur->next) { if (cur->type != XML_ELEMENT_NODE) continue; - if (!def->file && + if (!def->src.path && xmlStrEqual(cur->name, BAD_CAST "source")) { if (virDomainDiskSourceDefParse(cur, - def->type, - &def->file, - &def->protocol, - &def->nhosts, - &def->hosts, + def->src.type, + &def->src.path, + &def->src.protocol, + &def->src.nhosts, + &def->src.hosts, NULL) < 0) goto cleanup; - } else if (!def->format && + } else if (!def->src.format && xmlStrEqual(cur->name, BAD_CAST "driver")) { char *driver = virXMLPropString(cur, "type"); if (driver) { - def->format = virStorageFileFormatTypeFromString(driver); - if (def->format <= 0) { + def->src.format = virStorageFileFormatTypeFromString(driver); + if (def->src.format <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk snapshot driver '%s'"), driver); @@ -178,7 +176,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, } } - if (!def->snapshot && (def->file || def->format)) + if (!def->snapshot && (def->src.path || def->src.format)) def->snapshot = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL; ret = 0; @@ -511,12 +509,12 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, disk->name, tmp); goto cleanup; } - if (disk->file && + if (disk->src.path && disk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("file '%s' for disk '%s' requires " "use of external snapshot mode"), - disk->file, disk->name); + disk->src.path, disk->name); goto cleanup; } if (STRNEQ(disk->name, def->dom->disks[idx]->dst)) { @@ -543,7 +541,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, goto cleanup; disk->index = i; disk->snapshot = def->dom->disks[i]->snapshot; - disk->type = VIR_STORAGE_TYPE_FILE; + disk->src.type = VIR_STORAGE_TYPE_FILE; if (!disk->snapshot) disk->snapshot = default_snapshot; } @@ -556,16 +554,17 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, virDomainSnapshotDiskDefPtr disk = &def->disks[i]; if (disk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL && - !disk->file) { + !disk->src.path) { const char *original = virDomainDiskGetSource(def->dom->disks[i]); const char *tmp; struct stat sb; - if (disk->type != VIR_STORAGE_TYPE_FILE) { + if (disk->src.type != VIR_STORAGE_TYPE_FILE) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("cannot generate external snapshot name " "for disk '%s' on a '%s' device"), - disk->name, virStorageTypeToString(disk->type)); + disk->name, + virStorageTypeToString(disk->src.type)); goto cleanup; } @@ -587,7 +586,8 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, tmp = strrchr(original, '.'); if (!tmp || strchr(tmp, '/')) { - if (virAsprintf(&disk->file, "%s.%s", original, def->name) < 0) + if (virAsprintf(&disk->src.path, "%s.%s", original, + def->name) < 0) goto cleanup; } else { if ((tmp - original) > INT_MAX) { @@ -595,7 +595,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, _("integer overflow")); goto cleanup; } - if (virAsprintf(&disk->file, "%.*s.%s", + if (virAsprintf(&disk->src.path, "%.*s.%s", (int) (tmp - original), original, def->name) < 0) goto cleanup; @@ -614,7 +614,7 @@ static void virDomainSnapshotDiskDefFormat(virBufferPtr buf, virDomainSnapshotDiskDefPtr disk) { - int type = disk->type; + int type = disk->src.type; if (!disk->name) return; @@ -624,7 +624,7 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " snapshot='%s'", virDomainSnapshotLocationTypeToString(disk->snapshot)); - if (!disk->file && disk->format == 0) { + if (!disk->src.path && disk->src.format == 0) { virBufferAddLit(buf, "/>\n"); return; } @@ -632,16 +632,16 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " type='%s'>\n", virStorageTypeToString(type)); virBufferAdjustIndent(buf, 2); - if (disk->format > 0) + if (disk->src.format > 0) virBufferEscapeString(buf, "<driver type='%s'/>\n", - virStorageFileFormatTypeToString(disk->format)); + virStorageFileFormatTypeToString(disk->src.format)); virDomainDiskSourceDefFormatInternal(buf, type, - disk->file, + disk->src.path, 0, - disk->protocol, - disk->nhosts, - disk->hosts, + disk->src.protocol, + disk->src.nhosts, + disk->src.hosts, 0, NULL, NULL, 0); virBufferAdjustIndent(buf, -2); @@ -1308,5 +1308,5 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain, int virDomainSnapshotDiskGetActualType(virDomainSnapshotDiskDefPtr def) { - return def->type; + return def->src.type; } diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index f6fec88..1444d77 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -51,12 +51,8 @@ struct _virDomainSnapshotDiskDef { char *name; /* name matching the <target dev='...' of the domain */ int index; /* index within snapshot->dom->disks that matches name */ int snapshot; /* enum virDomainSnapshotLocation */ - int type; /* enum virStorageType */ - char *file; /* new source file when snapshot is external */ - int format; /* enum virStorageFileFormat */ - int protocol; /* network source protocol */ - size_t nhosts; /* network source hosts count */ - virStorageNetHostDefPtr hosts; /* network source hosts */ + + virStorageSource src; /* new wrapper file when snapshot is external */ }; /* Stores the complete snapshot metadata */ diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 209558d..198ee2f 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1422,7 +1422,7 @@ int qemuTranslateSnapshotDiskSourcePool(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainSnapshotDiskDefPtr def) { - if (def->type != VIR_STORAGE_TYPE_VOLUME) + if (def->src.type != VIR_STORAGE_TYPE_VOLUME) return 0; virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9d48a46..9a2de12 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12028,10 +12028,10 @@ qemuDomainSnapshotDiskGetSourceString(virDomainSnapshotDiskDefPtr disk, *source = NULL; return qemuGetDriveSourceString(virDomainSnapshotDiskGetActualType(disk), - disk->file, - disk->protocol, - disk->nhosts, - disk->hosts, + disk->src.path, + disk->src.protocol, + disk->src.nhosts, + disk->src.hosts, NULL, NULL, source); @@ -12178,14 +12178,14 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, if (snapdisk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) continue; - if (!snapdisk->format) - snapdisk->format = VIR_STORAGE_FILE_QCOW2; + if (!snapdisk->src.format) + snapdisk->src.format = VIR_STORAGE_FILE_QCOW2; /* creates cmd line args: qemu-img create -f qcow2 -o */ if (!(cmd = virCommandNewArgList(qemuImgPath, "create", "-f", - virStorageFileFormatTypeToString(snapdisk->format), + virStorageFileFormatTypeToString(snapdisk->src.format), "-o", NULL))) goto cleanup; @@ -12209,10 +12209,10 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, } /* adds cmd line args: /path/to/target/file */ - virCommandAddArg(cmd, snapdisk->file); + virCommandAddArg(cmd, snapdisk->src.path); /* If the target does not exist, we're going to create it possibly */ - if (!virFileExists(snapdisk->file)) + if (!virFileExists(snapdisk->src.path)) ignore_value(virBitmapSetBit(created, i)); if (virCommandRun(cmd, NULL) < 0) @@ -12229,11 +12229,11 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { VIR_FREE(defdisk->src.path); - if (VIR_STRDUP(defdisk->src.path, snapdisk->file) < 0) { + if (VIR_STRDUP(defdisk->src.path, snapdisk->src.path) < 0) { /* we cannot rollback here in a sane way */ goto cleanup; } - defdisk->src.format = snapdisk->format; + defdisk->src.format = snapdisk->src.format; } } @@ -12247,9 +12247,9 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, ssize_t bit = -1; while ((bit = virBitmapNextSetBit(created, bit)) >= 0) { snapdisk = &(snap->def->disks[bit]); - if (unlink(snapdisk->file) < 0) + if (unlink(snapdisk->src.path) < 0) VIR_WARN("Failed to remove snapshot image '%s'", - snapdisk->file); + snapdisk->src.path); } } virBitmapFree(created); @@ -12417,7 +12417,7 @@ qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d return 0; case VIR_STORAGE_TYPE_NETWORK: - switch ((enum virStorageNetProtocol) disk->protocol) { + switch ((enum virStorageNetProtocol) disk->src.protocol) { case VIR_STORAGE_NET_PROTOCOL_GLUSTER: return 0; @@ -12434,7 +12434,7 @@ qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d virReportError(VIR_ERR_INTERNAL_ERROR, _("external active snapshots are not supported on " "'network' disks using '%s' protocol"), - virStorageNetProtocolTypeToString(disk->protocol)); + virStorageNetProtocolTypeToString(disk->src.protocol)); return -1; } @@ -12515,19 +12515,19 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn, if (errno != ENOENT) { virReportSystemError(errno, _("unable to stat for disk %s: %s"), - snapdisk->name, snapdisk->file); + snapdisk->name, snapdisk->src.path); goto cleanup; } else if (reuse) { virReportSystemError(errno, _("missing existing file for disk %s: %s"), - snapdisk->name, snapdisk->file); + snapdisk->name, snapdisk->src.path); goto cleanup; } } else if (!S_ISBLK(st.st_mode) && st.st_size && !reuse) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("external snapshot file for disk %s already " "exists and is not a block device: %s"), - snapdisk->name, snapdisk->file); + snapdisk->name, snapdisk->src.path); goto cleanup; } @@ -12654,15 +12654,15 @@ qemuDomainSnapshotPrepare(virConnectPtr conn, break; case VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL: - if (!disk->format) { - disk->format = VIR_STORAGE_FILE_QCOW2; - } else if (disk->format != VIR_STORAGE_FILE_QCOW2 && - disk->format != VIR_STORAGE_FILE_QED) { + if (!disk->src.format) { + disk->src.format = VIR_STORAGE_FILE_QCOW2; + } else if (disk->src.format != VIR_STORAGE_FILE_QCOW2 && + disk->src.format != VIR_STORAGE_FILE_QED) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("external snapshot format for disk %s " "is unsupported: %s"), disk->name, - virStorageFileFormatTypeToString(disk->format)); + virStorageFileFormatTypeToString(disk->src.format)); goto cleanup; } @@ -12750,7 +12750,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, char *newsource = NULL; virStorageNetHostDefPtr newhosts = NULL; virStorageNetHostDefPtr persistHosts = NULL; - int format = snap->format; + int format = snap->src.format; const char *formatStr = NULL; char *persistSource = NULL; int ret = -1; @@ -12781,14 +12781,14 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, if (qemuDomainSnapshotDiskGetSourceString(snap, &source) < 0) goto cleanup; - if (VIR_STRDUP(newsource, snap->file) < 0) + if (VIR_STRDUP(newsource, snap->src.path) < 0) goto cleanup; if (persistDisk && - VIR_STRDUP(persistSource, snap->file) < 0) + VIR_STRDUP(persistSource, snap->src.path) < 0) goto cleanup; - switch (snap->type) { + switch (snap->src.type) { case VIR_STORAGE_TYPE_BLOCK: reuse = true; /* fallthrough */ @@ -12813,13 +12813,15 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, break; case VIR_STORAGE_TYPE_NETWORK: - switch (snap->protocol) { + switch (snap->src.protocol) { case VIR_STORAGE_NET_PROTOCOL_GLUSTER: - if (!(newhosts = virStorageNetHostDefCopy(snap->nhosts, snap->hosts))) + if (!(newhosts = virStorageNetHostDefCopy(snap->src.nhosts, + snap->src.hosts))) goto cleanup; if (persistDisk && - !(persistHosts = virStorageNetHostDefCopy(snap->nhosts, snap->hosts))) + !(persistHosts = virStorageNetHostDefCopy(snap->src.nhosts, + snap->src.hosts))) goto cleanup; break; @@ -12828,7 +12830,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("snapshots on volumes using '%s' protocol " "are not supported"), - virStorageNetProtocolTypeToString(snap->protocol)); + virStorageNetProtocolTypeToString(snap->src.protocol)); goto cleanup; } break; @@ -12836,13 +12838,13 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, default: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("snapshots are not supported on '%s' volumes"), - virStorageTypeToString(snap->type)); + virStorageTypeToString(snap->src.type)); goto cleanup; } /* create the actual snapshot */ - if (snap->format) - formatStr = virStorageFileFormatTypeToString(snap->format); + if (snap->src.format) + formatStr = virStorageFileFormatTypeToString(snap->src.format); /* The monitor is only accessed if qemu doesn't support transactions. * Otherwise the following monitor command only constructs the command. @@ -12874,9 +12876,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, disk->src.path = newsource; disk->src.format = format; - disk->src.type = snap->type; - disk->src.protocol = snap->protocol; - disk->src.nhosts = snap->nhosts; + disk->src.type = snap->src.type; + disk->src.protocol = snap->src.protocol; + disk->src.nhosts = snap->src.nhosts; disk->src.hosts = newhosts; newsource = NULL; @@ -12889,9 +12891,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, persistDisk->src.path = persistSource; persistDisk->src.format = format; - persistDisk->src.type = snap->type; - persistDisk->src.protocol = snap->protocol; - persistDisk->src.nhosts = snap->nhosts; + persistDisk->src.type = snap->src.type; + persistDisk->src.protocol = snap->src.protocol; + persistDisk->src.nhosts = snap->src.nhosts; persistDisk->src.hosts = persistHosts; persistSource = NULL; @@ -12906,8 +12908,8 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, VIR_FREE(source); VIR_FREE(newsource); VIR_FREE(persistSource); - virStorageNetHostDefFree(snap->nhosts, newhosts); - virStorageNetHostDefFree(snap->nhosts, persistHosts); + virStorageNetHostDefFree(snap->src.nhosts, newhosts); + virStorageNetHostDefFree(snap->src.nhosts, persistHosts); return ret; } diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index cdb8536..6fca3d2 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2802,10 +2802,10 @@ virStorageFilePtr virStorageFileInitFromSnapshotDef(virDomainSnapshotDiskDefPtr disk) { return virStorageFileInitInternal(virDomainSnapshotDiskGetActualType(disk), - disk->file, - disk->protocol, - disk->nhosts, - disk->hosts); + disk->src.path, + disk->src.protocol, + disk->src.nhosts, + disk->src.hosts); } -- 1.9.0

On 03/29/14 23:20, Eric Blake wrote:
Now that we have a common struct, it's time to start using it! Since external snapshots make a longer backing chain, it is only natural to use the same struct for the file created by the snapshot as what we use for <domain> disks.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Use common struct instead of open-coded duplicate fields. * src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear) (virDomainSnapshotDiskDefParseXML, virDomainSnapshotAlignDisks) (virDomainSnapshotDiskDefFormat) (virDomainSnapshotDiskGetActualType): Adjust clients. * src/qemu/qemu_conf.c (qemuTranslateSnapshotDiskSourcePool): Likewise. * src/qemu/qemu_driver.c (qemuDomainSnapshotDiskGetSourceString) (qemuDomainSnapshotCreateInactiveExternal) (qemuDomainSnapshotPrepareDiskExternalOverlayActive) (qemuDomainSnapshotPrepareDiskExternal) (qemuDomainSnapshotPrepare) (qemuDomainSnapshotCreateSingleDiskActive): Likewise. * src/storage/storage_driver.c (virStorageFileInitFromSnapshotDef): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/snapshot_conf.c | 68 +++++++++++++++++------------------ src/conf/snapshot_conf.h | 8 ++--- src/qemu/qemu_conf.c | 2 +- src/qemu/qemu_driver.c | 86 ++++++++++++++++++++++---------------------- src/storage/storage_driver.c | 8 ++--- 5 files changed, 85 insertions(+), 87 deletions(-)
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index ebb3bb4..3bd4732 100644
@@ -632,16 +632,16 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " type='%s'>\n", virStorageTypeToString(type)); virBufferAdjustIndent(buf, 2);
- if (disk->format > 0) + if (disk->src.format > 0) virBufferEscapeString(buf, "<driver type='%s'/>\n", - virStorageFileFormatTypeToString(disk->format)); + virStorageFileFormatTypeToString(disk->src.format)); virDomainDiskSourceDefFormatInternal(buf,
Hmm, now that we have a common struct, we can unify the source formatter and have it accept the common struct instead of splitting out separate fields ...
type, - disk->file, + disk->src.path, 0, - disk->protocol, - disk->nhosts, - disk->hosts, + disk->src.protocol, + disk->src.nhosts, + disk->src.hosts, 0, NULL, NULL, 0);
virBufferAdjustIndent(buf, -2);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9d48a46..9a2de12 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12028,10 +12028,10 @@ qemuDomainSnapshotDiskGetSourceString(virDomainSnapshotDiskDefPtr disk, *source = NULL;
return qemuGetDriveSourceString(virDomainSnapshotDiskGetActualType(disk),
same here. This function can now be refactored to take the struct instead of the fields separately.
- disk->file, - disk->protocol, - disk->nhosts, - disk->hosts, + disk->src.path, + disk->src.protocol, + disk->src.nhosts, + disk->src.hosts, NULL, NULL, source);
@@ -12874,9 +12876,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
disk->src.path = newsource; disk->src.format = format; - disk->src.type = snap->type; - disk->src.protocol = snap->protocol; - disk->src.nhosts = snap->nhosts; + disk->src.type = snap->src.type; + disk->src.protocol = snap->src.protocol; + disk->src.nhosts = snap->src.nhosts; disk->src.hosts = newhosts;
And here we can introduce a function to copy the source instead of doing it manually.
newsource = NULL; @@ -12889,9 +12891,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
persistDisk->src.path = persistSource; persistDisk->src.format = format; - persistDisk->src.type = snap->type; - persistDisk->src.protocol = snap->protocol; - persistDisk->src.nhosts = snap->nhosts; + persistDisk->src.type = snap->src.type; + persistDisk->src.protocol = snap->src.protocol; + persistDisk->src.nhosts = snap->src.nhosts; persistDisk->src.hosts = persistHosts;
persistSource = NULL;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index cdb8536..6fca3d2 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2802,10 +2802,10 @@ virStorageFilePtr virStorageFileInitFromSnapshotDef(virDomainSnapshotDiskDefPtr disk) { return virStorageFileInitInternal(virDomainSnapshotDiskGetActualType(disk), - disk->file, - disk->protocol, - disk->nhosts, - disk->hosts); + disk->src.path, + disk->src.protocol, + disk->src.nhosts, + disk->src.hosts); }
ACK to the patch. The proposed changes are definitely separable and better to review separately. Peter

On 03/31/2014 02:56 AM, Peter Krempa wrote:
On 03/29/14 23:20, Eric Blake wrote:
Now that we have a common struct, it's time to start using it! Since external snapshots make a longer backing chain, it is only natural to use the same struct for the file created by the snapshot as what we use for <domain> disks.
Hmm, now that we have a common struct, we can unify the source formatter and have it accept the common struct instead of splitting out separate fields ...
type, - disk->file, + disk->src.path, 0, - disk->protocol, - disk->nhosts, - disk->hosts, + disk->src.protocol, + disk->src.nhosts, + disk->src.hosts, 0, NULL, NULL, 0);
Yep, you've guessed one of my future patches.
@@ -12874,9 +12876,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
disk->src.path = newsource; disk->src.format = format; - disk->src.type = snap->type; - disk->src.protocol = snap->protocol; - disk->src.nhosts = snap->nhosts; + disk->src.type = snap->src.type; + disk->src.protocol = snap->src.protocol; + disk->src.nhosts = snap->src.nhosts; disk->src.hosts = newhosts;
And here we can introduce a function to copy the source instead of doing it manually.
Also a future patch that I was already planning on :)
ACK to the patch. The proposed changes are definitely separable and better to review separately.
Good - we're on the same page. Again, I'm waiting for this series until after 1.2.3 is out, but glad that it is ACKed so far. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 03/31/2014 09:56 AM, Eric Blake wrote:
On 03/31/2014 02:56 AM, Peter Krempa wrote:
On 03/29/14 23:20, Eric Blake wrote:
Now that we have a common struct, it's time to start using it! Since external snapshots make a longer backing chain, it is only natural to use the same struct for the file created by the snapshot as what we use for <domain> disks.
And here we can introduce a function to copy the source instead of doing it manually.
Also a future patch that I was already planning on :)
ACK to the patch. The proposed changes are definitely separable and better to review separately.
Good - we're on the same page. Again, I'm waiting for this series until after 1.2.3 is out, but glad that it is ACKed so far.
I've pushed through here; the rest of what I've posted in this thread (13-16) is something I'm still thinking about, and may rebase slightly differently. I'll start a new thread for my next work, which is trying to merge virStorageFileMetadata and virStorageSource into a single struct. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Some preparatory work before consolidating storage volume structs with the rest of virstoragefile. Making these changes allows a volume target to be much closer to the virStorageSource struct. * src/conf/storage_conf.h (_virStorageVolTarget): Change perms to pointer, enhance comments. * src/conf/storage_conf.c (virStorageVolDefFree) (virStorageVolDefParseXML, virStorageVolTargetDefFormat): Update clients. * src/storage/storage_backend_fs.c (createFileDir): Likewise. * src/storage/storage_backend.c (virStorageBackendCreateBlockFrom) (virStorageBackendCreateRaw, virStorageBackendCreateExecCommand) (virStorageBackendUpdateVolTargetInfoFD): Likewise. * src/storage/storage_backend_logical.c (virStorageBackendLogicalCreateVol): Likewise. * src/storage/storage_backend_disk.c (virStorageBackendDiskMakeDataVol) (virStorageBackendDiskPartTypeToCreate): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/storage_conf.c | 26 ++++++++++++------ src/conf/storage_conf.h | 7 ++--- src/storage/storage_backend.c | 50 ++++++++++++++++++++--------------- src/storage/storage_backend_disk.c | 14 +++++----- src/storage/storage_backend_fs.c | 6 ++--- src/storage/storage_backend_logical.c | 6 ++--- 6 files changed, 63 insertions(+), 46 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index a300476..49b790d 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -332,11 +332,17 @@ virStorageVolDefFree(virStorageVolDefPtr def) VIR_FREE(def->target.compat); virBitmapFree(def->target.features); VIR_FREE(def->target.path); - VIR_FREE(def->target.perms.label); + if (def->target.perms) { + VIR_FREE(def->target.perms->label); + VIR_FREE(def->target.perms); + } VIR_FREE(def->target.timestamps); virStorageEncryptionFree(def->target.encryption); VIR_FREE(def->backingStore.path); - VIR_FREE(def->backingStore.perms.label); + if (def->backingStore.perms) { + VIR_FREE(def->backingStore.perms->label); + VIR_FREE(def->backingStore.perms); + } VIR_FREE(def->backingStore.timestamps); virStorageEncryptionFree(def->backingStore.encryption); VIR_FREE(def); @@ -1355,7 +1361,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, VIR_FREE(format); } - if (virStorageDefParsePerms(ctxt, &ret->target.perms, + if (VIR_ALLOC(ret->target.perms) < 0) + goto error; + if (virStorageDefParsePerms(ctxt, ret->target.perms, "./target/permissions", DEFAULT_VOL_PERM_MODE) < 0) goto error; @@ -1424,7 +1432,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, VIR_FREE(nodes); } - if (virStorageDefParsePerms(ctxt, &ret->backingStore.perms, + if (VIR_ALLOC(ret->backingStore.perms) < 0) + goto error; + if (virStorageDefParsePerms(ctxt, ret->backingStore.perms, "./backingStore/permissions", DEFAULT_VOL_PERM_MODE) < 0) goto error; @@ -1541,15 +1551,15 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options, virBufferAdjustIndent(buf, 2); virBufferAsprintf(buf, "<mode>0%o</mode>\n", - def->perms.mode); + def->perms->mode); virBufferAsprintf(buf, "<owner>%u</owner>\n", - (unsigned int) def->perms.uid); + (unsigned int) def->perms->uid); virBufferAsprintf(buf, "<group>%u</group>\n", - (unsigned int) def->perms.gid); + (unsigned int) def->perms->gid); virBufferEscapeString(buf, "<label>%s</label>\n", - def->perms.label); + def->perms->label); virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</permissions>\n"); diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index b811046..76d6c9c 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -81,10 +81,11 @@ typedef struct _virStorageVolTarget virStorageVolTarget; typedef virStorageVolTarget *virStorageVolTargetPtr; struct _virStorageVolTarget { char *path; - int format; - virStoragePerms perms; + int format; /* enum virStorageFileFormat */ + virStoragePermsPtr perms; virStorageTimestampsPtr timestamps; - int type; /* only used by disk backend for partition type */ + int partType; /* enum virStorageVolTypeDisk, only used by disk + * backend for partition type */ /* The next three are currently only used in vol->target, * not in vol->backingStore. */ virStorageEncryptionPtr encryption; diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index a4481b2..00066da 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -301,8 +301,10 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED, vol->target.path); goto cleanup; } - uid = (vol->target.perms.uid != st.st_uid) ? vol->target.perms.uid : (uid_t) -1; - gid = (vol->target.perms.gid != st.st_gid) ? vol->target.perms.gid : (gid_t) -1; + uid = (vol->target.perms->uid != st.st_uid) ? vol->target.perms->uid + : (uid_t) -1; + gid = (vol->target.perms->gid != st.st_gid) ? vol->target.perms->gid + : (gid_t) -1; if (((uid != (uid_t) -1) || (gid != (gid_t) -1)) && (fchown(fd, uid, gid) < 0)) { virReportSystemError(errno, @@ -311,10 +313,10 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED, (unsigned int) gid); goto cleanup; } - if (fchmod(fd, vol->target.perms.mode) < 0) { + if (fchmod(fd, vol->target.perms->mode) < 0) { virReportSystemError(errno, _("cannot set mode of '%s' to %04o"), - vol->target.path, vol->target.perms.mode); + vol->target.path, vol->target.perms->mode); goto cleanup; } if (VIR_CLOSE(fd) < 0) { @@ -439,9 +441,9 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED, if ((fd = virFileOpenAs(vol->target.path, O_RDWR | O_CREAT | O_EXCL, - vol->target.perms.mode, - vol->target.perms.uid, - vol->target.perms.gid, + vol->target.perms->mode, + vol->target.perms->uid, + vol->target.perms->gid, operation_flags)) < 0) { virReportSystemError(-fd, _("Failed to create file '%s'"), @@ -578,13 +580,13 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool, if ((pool->def->type == VIR_STORAGE_POOL_NETFS) && (((geteuid() == 0) - && (vol->target.perms.uid != (uid_t) -1) - && (vol->target.perms.uid != 0)) - || ((vol->target.perms.gid != (gid_t) -1) - && (vol->target.perms.gid != getegid())))) { + && (vol->target.perms->uid != (uid_t) -1) + && (vol->target.perms->uid != 0)) + || ((vol->target.perms->gid != (gid_t) -1) + && (vol->target.perms->gid != getegid())))) { - virCommandSetUID(cmd, vol->target.perms.uid); - virCommandSetGID(cmd, vol->target.perms.gid); + virCommandSetUID(cmd, vol->target.perms->uid); + virCommandSetGID(cmd, vol->target.perms->gid); if (virCommandRun(cmd, NULL) == 0) { /* command was successfully run, check if the file was created */ @@ -608,8 +610,10 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool, } } - uid = (vol->target.perms.uid != st.st_uid) ? vol->target.perms.uid : (uid_t) -1; - gid = (vol->target.perms.gid != st.st_gid) ? vol->target.perms.gid : (gid_t) -1; + uid = (vol->target.perms->uid != st.st_uid) ? vol->target.perms->uid + : (uid_t) -1; + gid = (vol->target.perms->gid != st.st_gid) ? vol->target.perms->gid + : (gid_t) -1; if (((uid != (uid_t) -1) || (gid != (gid_t) -1)) && (chown(vol->target.path, uid, gid) < 0)) { virReportSystemError(errno, @@ -618,10 +622,10 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool, (unsigned int) gid); return -1; } - if (chmod(vol->target.path, vol->target.perms.mode) < 0) { + if (chmod(vol->target.path, vol->target.perms->mode) < 0) { virReportSystemError(errno, _("cannot set mode of '%s' to %04o"), - vol->target.path, vol->target.perms.mode); + vol->target.path, vol->target.perms->mode); return -1; } return 0; @@ -1425,9 +1429,11 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target, } } - target->perms.mode = sb->st_mode & S_IRWXUGO; - target->perms.uid = sb->st_uid; - target->perms.gid = sb->st_gid; + if (!target->perms && VIR_ALLOC(target->perms) < 0) + return -1; + target->perms->mode = sb->st_mode & S_IRWXUGO; + target->perms->uid = sb->st_uid; + target->perms->gid = sb->st_gid; if (!target->timestamps && VIR_ALLOC(target->timestamps) < 0) return -1; @@ -1436,7 +1442,7 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target, target->timestamps->ctime = get_stat_ctime(sb); target->timestamps->mtime = get_stat_mtime(sb); - VIR_FREE(target->perms.label); + VIR_FREE(target->perms->label); #if WITH_SELINUX /* XXX: make this a security driver call */ @@ -1449,7 +1455,7 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target, return -1; } } else { - if (VIR_STRDUP(target->perms.label, filecon) < 0) { + if (VIR_STRDUP(target->perms->label, filecon) < 0) { freecon(filecon); return -1; } diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index 8276c96..bfc2e65 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -1,7 +1,7 @@ /* * storage_backend_disk.c: storage backend for disk handling * - * Copyright (C) 2007-2008, 2010-2013 Red Hat, Inc. + * Copyright (C) 2007-2014 Red Hat, Inc. * Copyright (C) 2007-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -118,13 +118,13 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, /* set partition type */ if (STREQ(groups[1], "normal")) - vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_PRIMARY; + vol->target.partType = VIR_STORAGE_VOL_DISK_TYPE_PRIMARY; else if (STREQ(groups[1], "logical")) - vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_LOGICAL; + vol->target.partType = VIR_STORAGE_VOL_DISK_TYPE_LOGICAL; else if (STREQ(groups[1], "extended")) - vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_EXTENDED; + vol->target.partType = VIR_STORAGE_VOL_DISK_TYPE_EXTENDED; else - vol->target.type = VIR_STORAGE_VOL_DISK_TYPE_NONE; + vol->target.partType = VIR_STORAGE_VOL_DISK_TYPE_NONE; vol->type = VIR_STORAGE_VOL_BLOCK; @@ -444,8 +444,8 @@ virStorageBackendDiskPartTypeToCreate(virStoragePoolObjPtr pool) size_t i; int count = 0; for (i = 0; i < pool->volumes.count; i++) { - if (pool->volumes.objs[i]->target.type == VIR_STORAGE_VOL_DISK_TYPE_PRIMARY || - pool->volumes.objs[i]->target.type == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) { + if (pool->volumes.objs[i]->target.partType == VIR_STORAGE_VOL_DISK_TYPE_PRIMARY || + pool->volumes.objs[i]->target.partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) { count++; } } diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 084ae56..fd03ca4 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -1037,9 +1037,9 @@ static int createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED, return -1; } - if ((err = virDirCreate(vol->target.path, vol->target.perms.mode, - vol->target.perms.uid, - vol->target.perms.gid, + if ((err = virDirCreate(vol->target.path, vol->target.perms->mode, + vol->target.perms->uid, + vol->target.perms->gid, VIR_DIR_CREATE_FORCE_PERMS | (pool->def->type == VIR_STORAGE_POOL_NETFS ? VIR_DIR_CREATE_AS_UID : 0))) < 0) { diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index f90d373..874ebf6 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -1,7 +1,7 @@ /* * storage_backend_logical.c: storage backend for logical volume handling * - * Copyright (C) 2007-2009, 2011, 2013 Red Hat, Inc. + * Copyright (C) 2007-2014 Red Hat, Inc. * Copyright (C) 2007-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -764,14 +764,14 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, /* We can only chown/grp if root */ if (geteuid() == 0) { - if (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0) { + if (fchown(fd, vol->target.perms->uid, vol->target.perms->gid) < 0) { virReportSystemError(errno, _("cannot set file owner '%s'"), vol->target.path); goto error; } } - if (fchmod(fd, vol->target.perms.mode) < 0) { + if (fchmod(fd, vol->target.perms->mode) < 0) { virReportSystemError(errno, _("cannot set file mode '%s'"), vol->target.path); -- 1.9.0

On 03/30/14 05:37, Eric Blake wrote:
Some preparatory work before consolidating storage volume structs with the rest of virstoragefile. Making these changes allows a volume target to be much closer to the virStorageSource struct.
While I don't think that the refactor of the target is a good idea ...
* src/conf/storage_conf.h (_virStorageVolTarget): Change perms to pointer, enhance comments. * src/conf/storage_conf.c (virStorageVolDefFree) (virStorageVolDefParseXML, virStorageVolTargetDefFormat): Update clients. * src/storage/storage_backend_fs.c (createFileDir): Likewise. * src/storage/storage_backend.c (virStorageBackendCreateBlockFrom) (virStorageBackendCreateRaw, virStorageBackendCreateExecCommand) (virStorageBackendUpdateVolTargetInfoFD): Likewise. * src/storage/storage_backend_logical.c (virStorageBackendLogicalCreateVol): Likewise. * src/storage/storage_backend_disk.c (virStorageBackendDiskMakeDataVol) (virStorageBackendDiskPartTypeToCreate): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/storage_conf.c | 26 ++++++++++++------ src/conf/storage_conf.h | 7 ++--- src/storage/storage_backend.c | 50 ++++++++++++++++++++--------------- src/storage/storage_backend_disk.c | 14 +++++----- src/storage/storage_backend_fs.c | 6 ++--- src/storage/storage_backend_logical.c | 6 ++--- 6 files changed, 63 insertions(+), 46 deletions(-)
... ACK to this patch Peter

Another step towards unification of structures. While we might not expose everything in XML via domain disk as we do for storage volume pointer, both places want to deal with (at least part of) the backing chain; therefore, moving towards a single struct usable from both contexts will make the backing chain code more reusable. * src/conf/storage_conf.h (_virStoragePerms) (virStorageTimestamps): Move... * src/util/virstoragefile.h: ...here. (_virStorageSource): Add more fields. * src/util/virstoragefile.c (virStorageSourceClear): Clean additional fields. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/storage_conf.h | 23 +---------------------- src/util/virstoragefile.c | 6 ++++++ src/util/virstoragefile.h | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 76d6c9c..eb09443 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -26,33 +26,12 @@ # include "internal.h" # include "virstorageencryption.h" +# include "virstoragefile.h" # include "virbitmap.h" # include "virthread.h" # include <libxml/tree.h> -typedef struct _virStoragePerms virStoragePerms; -typedef virStoragePerms *virStoragePermsPtr; -struct _virStoragePerms { - mode_t mode; - uid_t uid; - gid_t gid; - char *label; -}; - -typedef struct _virStorageTimestamps virStorageTimestamps; -typedef virStorageTimestamps *virStorageTimestampsPtr; -struct _virStorageTimestamps { - struct timespec atime; - /* if btime.tv_nsec == -1 then - * birth time is unknown - */ - struct timespec btime; - struct timespec ctime; - struct timespec mtime; -}; - - /* * How the volume's data is stored on underlying * physical devices - can potentially span many diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index bbaa171..912b90d 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1569,6 +1569,7 @@ virStorageSourceClear(virStorageSourcePtr def) VIR_FREE(def->path); virStorageSourcePoolDefFree(def->srcpool); VIR_FREE(def->driverName); + VIR_FREE(def->compat); virStorageEncryptionFree(def->encryption); if (def->seclabels) { @@ -1576,6 +1577,11 @@ virStorageSourceClear(virStorageSourcePtr def) virSecurityDeviceLabelDefFree(def->seclabels[i]); VIR_FREE(def->seclabels); } + if (def->perms) { + VIR_FREE(def->perms->label); + VIR_FREE(def->perms); + } + VIR_FREE(def->timestamps); virStorageNetHostDefFree(def->nhosts, def->hosts); virStorageSourceAuthClear(def); diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 4980960..f7edce8 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -85,6 +85,26 @@ enum virStorageFileFeature { VIR_ENUM_DECL(virStorageFileFeature); +typedef struct _virStoragePerms virStoragePerms; +typedef virStoragePerms *virStoragePermsPtr; +struct _virStoragePerms { + mode_t mode; + uid_t uid; + gid_t gid; + char *label; +}; + + +typedef struct _virStorageTimestamps virStorageTimestamps; +typedef virStorageTimestamps *virStorageTimestampsPtr; +struct _virStorageTimestamps { + struct timespec atime; + struct timespec btime; /* birth time unknown if btime.tv_nsec == -1 */ + struct timespec ctime; + struct timespec mtime; +}; + + typedef struct _virStorageFileMetadata virStorageFileMetadata; typedef virStorageFileMetadata *virStorageFileMetadataPtr; struct _virStorageFileMetadata { @@ -206,9 +226,15 @@ struct _virStorageSource { } secret; } auth; virStorageEncryptionPtr encryption; + char *driverName; int format; /* enum virStorageFileFormat */ + virBitmapPtr features; + char *compat; + virStoragePermsPtr perms; + virStorageTimestampsPtr timestamps; + int partType; /* enum virStorageVolTypeDisk */ size_t nseclabels; virSecurityDeviceLabelDefPtr *seclabels; }; -- 1.9.0

On 03/30/14 05:37, Eric Blake wrote:
Another step towards unification of structures. While we might not expose everything in XML via domain disk as we do for storage volume pointer, both places want to deal with (at least part of) the backing chain; therefore, moving towards a single struct usable from both contexts will make the backing chain code more reusable.
* src/conf/storage_conf.h (_virStoragePerms) (virStorageTimestamps): Move... * src/util/virstoragefile.h: ...here. (_virStorageSource): Add more fields. * src/util/virstoragefile.c (virStorageSourceClear): Clean additional fields.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/storage_conf.h | 23 +---------------------- src/util/virstoragefile.c | 6 ++++++ src/util/virstoragefile.h | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 22 deletions(-)
I don't like the mixing in of storage volume target from the storage drivers ... see 15/n for my reasoning. Peter

A fairly smooth transition. And now that domain disks and storage volumes share a common struct, it opens the doors for a future patch to expose more details in the XML for both objects. * src/conf/storage_conf.h (_virStorageVolTarget): Delete. (_virStorageVolDef): Use common type. * src/conf/storage_conf.c (virStorageVolDefFree) (virStorageVolTargetDefFormat): Update clients. * src/storage/storage_backend.h: Likewise. * src/storage/storage_backend.c (virStorageBackendUpdateVolTargetInfo) (virStorageBackendUpdateVolTargetInfoFD) (virStorageBackendDetectBlockVolFormatFD): Likewise. * src/storage/storage_backend_fs.c (virStorageBackendProbeTarget): Likewise. * src/storage/storage_backend_scsi.c (virStorageBackendSCSIUpdateVolTargetInfo): Likewise. * src/storage/storage_backend_mpath.c (virStorageBackendMpathUpdateVolTargetInfo): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/storage_conf.c | 20 +++----------------- src/conf/storage_conf.h | 23 ++--------------------- src/storage/storage_backend.c | 6 +++--- src/storage/storage_backend.h | 6 +++--- src/storage/storage_backend_fs.c | 2 +- src/storage/storage_backend_mpath.c | 4 ++-- src/storage/storage_backend_scsi.c | 2 +- 7 files changed, 15 insertions(+), 48 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 49b790d..fe98b18 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -329,22 +329,8 @@ virStorageVolDefFree(virStorageVolDefPtr def) } VIR_FREE(def->source.extents); - VIR_FREE(def->target.compat); - virBitmapFree(def->target.features); - VIR_FREE(def->target.path); - if (def->target.perms) { - VIR_FREE(def->target.perms->label); - VIR_FREE(def->target.perms); - } - VIR_FREE(def->target.timestamps); - virStorageEncryptionFree(def->target.encryption); - VIR_FREE(def->backingStore.path); - if (def->backingStore.perms) { - VIR_FREE(def->backingStore.perms->label); - VIR_FREE(def->backingStore.perms); - } - VIR_FREE(def->backingStore.timestamps); - virStorageEncryptionFree(def->backingStore.encryption); + virStorageSourceClear(&def->target); + virStorageSourceClear(&def->backingStore); VIR_FREE(def); } @@ -1528,7 +1514,7 @@ virStorageVolTimestampFormat(virBufferPtr buf, const char *name, static int virStorageVolTargetDefFormat(virStorageVolOptionsPtr options, virBufferPtr buf, - virStorageVolTargetPtr def, + virStorageSourcePtr def, const char *type) { virBufferAsprintf(buf, "<%s>\n", type); diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index eb09443..d16d679 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -53,25 +53,6 @@ struct _virStorageVolSource { }; -/* - * How the volume appears on the host - */ -typedef struct _virStorageVolTarget virStorageVolTarget; -typedef virStorageVolTarget *virStorageVolTargetPtr; -struct _virStorageVolTarget { - char *path; - int format; /* enum virStorageFileFormat */ - virStoragePermsPtr perms; - virStorageTimestampsPtr timestamps; - int partType; /* enum virStorageVolTypeDisk, only used by disk - * backend for partition type */ - /* The next three are currently only used in vol->target, - * not in vol->backingStore. */ - virStorageEncryptionPtr encryption; - virBitmapPtr features; - char *compat; -}; - typedef struct _virStorageVolDef virStorageVolDef; typedef virStorageVolDef *virStorageVolDefPtr; struct _virStorageVolDef { @@ -85,8 +66,8 @@ struct _virStorageVolDef { unsigned long long capacity; /* bytes */ virStorageVolSource source; - virStorageVolTarget target; - virStorageVolTarget backingStore; + virStorageSource target; + virStorageSource backingStore; }; typedef struct _virStorageVolDefList virStorageVolDefList; diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 00066da..6204f18 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -1317,7 +1317,7 @@ int virStorageBackendVolOpen(const char *path) } int -virStorageBackendUpdateVolTargetInfo(virStorageVolTargetPtr target, +virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target, unsigned long long *allocation, unsigned long long *capacity, unsigned int openflags) @@ -1381,7 +1381,7 @@ int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol, * Returns 0 for success, -1 on a legitimate error condition. */ int -virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target, +virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target, int fd, struct stat *sb, unsigned long long *allocation, @@ -1502,7 +1502,7 @@ static struct diskType const disk_types[] = { int -virStorageBackendDetectBlockVolFormatFD(virStorageVolTargetPtr target, +virStorageBackendDetectBlockVolFormatFD(virStorageSourcePtr target, int fd) { size_t i; diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h index 2034a22..3ff3e5c 100644 --- a/src/storage/storage_backend.h +++ b/src/storage/storage_backend.h @@ -142,16 +142,16 @@ int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol, int virStorageBackendUpdateVolInfoFlags(virStorageVolDefPtr vol, int withCapacity, unsigned int openflags); -int virStorageBackendUpdateVolTargetInfo(virStorageVolTargetPtr target, +int virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target, unsigned long long *allocation, unsigned long long *capacity, unsigned int openflags); -int virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target, +int virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target, int fd, struct stat *sb, unsigned long long *allocation, unsigned long long *capacity); -int virStorageBackendDetectBlockVolFormatFD(virStorageVolTargetPtr target, +int virStorageBackendDetectBlockVolFormatFD(virStorageSourcePtr target, int fd); char *virStorageBackendStablePath(virStoragePoolObjPtr pool, diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index fd03ca4..3fef6bd 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -62,7 +62,7 @@ VIR_LOG_INIT("storage.storage_backend_fs"); ~VIR_STORAGE_VOL_OPEN_ERROR) static int ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) -virStorageBackendProbeTarget(virStorageVolTargetPtr target, +virStorageBackendProbeTarget(virStorageSourcePtr target, char **backingStore, int *backingStoreFormat, unsigned long long *allocation, diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c index 82e3e20..6ee278b 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -1,7 +1,7 @@ /* * storage_backend_mpath.c: storage backend for multipath handling * - * Copyright (C) 2009-2011, 2013 Red Hat, Inc. + * Copyright (C) 2009-2014 Red Hat, Inc. * Copyright (C) 2009-2008 Dave Allan * * This library is free software; you can redistribute it and/or @@ -42,7 +42,7 @@ VIR_LOG_INIT("storage.storage_backend_mpath"); static int -virStorageBackendMpathUpdateVolTargetInfo(virStorageVolTargetPtr target, +virStorageBackendMpathUpdateVolTargetInfo(virStorageSourcePtr target, unsigned long long *allocation, unsigned long long *capacity) { diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c index a318f29..f7693a0 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -103,7 +103,7 @@ getDeviceType(uint32_t host, } static int -virStorageBackendSCSIUpdateVolTargetInfo(virStorageVolTargetPtr target, +virStorageBackendSCSIUpdateVolTargetInfo(virStorageSourcePtr target, unsigned long long *allocation, unsigned long long *capacity) { -- 1.9.0

On 03/30/14 05:38, Eric Blake wrote:
A fairly smooth transition. And now that domain disks and storage volumes share a common struct, it opens the doors for a future patch to expose more details in the XML for both objects.
* src/conf/storage_conf.h (_virStorageVolTarget): Delete. (_virStorageVolDef): Use common type. * src/conf/storage_conf.c (virStorageVolDefFree) (virStorageVolTargetDefFormat): Update clients. * src/storage/storage_backend.h: Likewise. * src/storage/storage_backend.c (virStorageBackendUpdateVolTargetInfo) (virStorageBackendUpdateVolTargetInfoFD) (virStorageBackendDetectBlockVolFormatFD): Likewise. * src/storage/storage_backend_fs.c (virStorageBackendProbeTarget): Likewise. * src/storage/storage_backend_scsi.c (virStorageBackendSCSIUpdateVolTargetInfo): Likewise. * src/storage/storage_backend_mpath.c (virStorageBackendMpathUpdateVolTargetInfo): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/storage_conf.c | 20 +++----------------- src/conf/storage_conf.h | 23 ++--------------------- src/storage/storage_backend.c | 6 +++--- src/storage/storage_backend.h | 6 +++--- src/storage/storage_backend_fs.c | 2 +- src/storage/storage_backend_mpath.c | 4 ++-- src/storage/storage_backend_scsi.c | 2 +- 7 files changed, 15 insertions(+), 48 deletions(-)
...
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index eb09443..d16d679 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -53,25 +53,6 @@ struct _virStorageVolSource { };
-/* - * How the volume appears on the host - */ -typedef struct _virStorageVolTarget virStorageVolTarget; -typedef virStorageVolTarget *virStorageVolTargetPtr; -struct _virStorageVolTarget { - char *path; - int format; /* enum virStorageFileFormat */ - virStoragePermsPtr perms; - virStorageTimestampsPtr timestamps; - int partType; /* enum virStorageVolTypeDisk, only used by disk - * backend for partition type */ - /* The next three are currently only used in vol->target, - * not in vol->backingStore. */ - virStorageEncryptionPtr encryption; - virBitmapPtr features; - char *compat; -}; - typedef struct _virStorageVolDef virStorageVolDef; typedef virStorageVolDef *virStorageVolDefPtr; struct _virStorageVolDef { @@ -85,8 +66,8 @@ struct _virStorageVolDef { unsigned long long capacity; /* bytes */
virStorageVolSource source; - virStorageVolTarget target; - virStorageVolTarget backingStore; + virStorageSource target;
Hmmm, converting target to a source definition doesn't seem to be a good idea to me: * As in other parts of the code, the semantics of the target and source differ in the data needed to store about those fields. * Tracking of the target requires us to add additional data to the struct which makes it to bloat and it's probable that those metadata won't be used by other parts of the code. * Other parts that are already present in the source structure are irrelevant to the host representation, such as the network information. I'd rather see those separated. It might seem that the structs carry similar data but they are semantically different IMO.
+ virStorageSource backingStore;
In case of the backing chain I think that the backing store is a property of the source and not the target thus I'm fine with changing this.
};
typedef struct _virStorageVolDefList virStorageVolDefList;
Peter

On 03/31/2014 03:59 AM, Peter Krempa wrote:
On 03/30/14 05:38, Eric Blake wrote:
A fairly smooth transition. And now that domain disks and storage volumes share a common struct, it opens the doors for a future patch to expose more details in the XML for both objects.
Let's examine how things are prior to patch 14:
-/* - * How the volume appears on the host - */ -typedef struct _virStorageVolTarget virStorageVolTarget; -typedef virStorageVolTarget *virStorageVolTargetPtr; -struct _virStorageVolTarget { - char *path; - int format; /* enum virStorageFileFormat */
both already in virStorageSource
- virStoragePermsPtr perms; - virStorageTimestampsPtr timestamps;
Neither in virStorageSource, but present in 'vol-dumpxml' output for both the <target> (primary volume information) and <backingStore> (immediate backing chain information) elements. I personally think it would be useful to have both of these items added to output-only <domain> information - it is NICE to know the timestamps and permissions of a disk image in use by a domain.
- int partType; /* enum virStorageVolTypeDisk, only used by disk - * backend for partition type */
Not in virStorageSource - this was the field that I'm least sure of what to do. Is it possible to have a partition-based pool whose volumes are even listed with a <backingStore>?
- /* The next three are currently only used in vol->target, - * not in vol->backingStore. */ - virStorageEncryptionPtr encryption;
This one is present in virStorageSource, which means that both storage volumes and domain disks care about it.
- virBitmapPtr features; - char *compat;
These two are not yet in virStorageSource, but definitely belong there, right alongside driver and format (that is, knowing something is qcow2 is only part of the picture - we really DO want to know qcow2v2 (compat=0.10) vs. qcow2v3 (compat=1.1) when traversing backing chains, particularly since RHEL 6 still lacks qcow2v3 support).
- virStorageVolTarget target; - virStorageVolTarget backingStore; + virStorageSource target;
Hmmm, converting target to a source definition doesn't seem to be a good idea to me:
* As in other parts of the code, the semantics of the target and source differ in the data needed to store about those fields.
Only in that the code _currently_ displays more for <target> than it does for <backingStore>, but the two are otherwise highly related. Also, I envision making a storage volume <backingStore> recursive, just as I do for domain <disk> backing store information. Knowing only the first backing element is not as useful as knowing the entire backing chain.
* Tracking of the target requires us to add additional data to the struct which makes it to bloat and it's probable that those metadata won't be used by other parts of the code.
You may have a point for partType, but the other parts of the metadata ARE useful in other parts of the code, even if we aren't using them yet.
* Other parts that are already present in the source structure are irrelevant to the host representation, such as the network information.
Not irrelevant, so much as redundant. That is, when listing a storage volume from a network storage pool such as gluster, the network information can be obtained from the pool that owns the storage volume - but it shouldn't hurt to also list the network information in the storage volume itself instead of forcing callers to make multiple API calls to obtain all the pieces.
I'd rather see those separated. It might seem that the structs carry similar data but they are semantically different IMO.
+ virStorageSource backingStore;
In case of the backing chain I think that the backing store is a property of the source and not the target thus I'm fine with changing this.
The name <target> in storage volume XML is rather misleading. It really is the same as the <source> element of a domain <disk> element. The name <source> in storage volume XML gives additional details (such as extent mappings on things such as LVM volumes), but THAT is the one that is semantically unrelated to <source> in a domain <disk> element. I can indeed limit the patch to just changing the backingStore to the common type, but I'm not yet convinced why changing the <target> to use virStorageSource is wrong. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 03/31/14 18:10, Eric Blake wrote:
On 03/31/2014 03:59 AM, Peter Krempa wrote:
On 03/30/14 05:38, Eric Blake wrote:
A fairly smooth transition. And now that domain disks and storage volumes share a common struct, it opens the doors for a future patch to expose more details in the XML for both objects.
Let's examine how things are prior to patch 14:
-/* - * How the volume appears on the host - */ -typedef struct _virStorageVolTarget virStorageVolTarget; -typedef virStorageVolTarget *virStorageVolTargetPtr; -struct _virStorageVolTarget { - char *path; - int format; /* enum virStorageFileFormat */
both already in virStorageSource
- virStoragePermsPtr perms; - virStorageTimestampsPtr timestamps;
Neither in virStorageSource, but present in 'vol-dumpxml' output for both the <target> (primary volume information) and <backingStore> (immediate backing chain information) elements. I personally think it would be useful to have both of these items added to output-only <domain> information - it is NICE to know the timestamps and permissions of a disk image in use by a domain.
Okay, fair enough in this case. If we will use this it might be worth adding information about selinux too. (In the future, not right now)
- int partType; /* enum virStorageVolTypeDisk, only used by disk - * backend for partition type */
Not in virStorageSource - this was the field that I'm least sure of what to do. Is it possible to have a partition-based pool whose volumes are even listed with a <backingStore>?
Not sure if libvirt allows and reports it but it's certainly possible to store a qcow2 overlay in a partition. Thus we might need to be able to describe that.
- /* The next three are currently only used in vol->target, - * not in vol->backingStore. */ - virStorageEncryptionPtr encryption;
This one is present in virStorageSource, which means that both storage volumes and domain disks care about it.
- virBitmapPtr features; - char *compat;
These two are not yet in virStorageSource, but definitely belong there, right alongside driver and format (that is, knowing something is qcow2 is only part of the picture - we really DO want to know qcow2v2 (compat=0.10) vs. qcow2v3 (compat=1.1) when traversing backing chains, particularly since RHEL 6 still lacks qcow2v3 support).
- virStorageVolTarget target; - virStorageVolTarget backingStore; + virStorageSource target;
Hmmm, converting target to a source definition doesn't seem to be a good idea to me:
* As in other parts of the code, the semantics of the target and source differ in the data needed to store about those fields.
Only in that the code _currently_ displays more for <target> than it does for <backingStore>, but the two are otherwise highly related. Also, I envision making a storage volume <backingStore> recursive, just as I do for domain <disk> backing store information. Knowing only the first backing element is not as useful as knowing the entire backing chain.
* Tracking of the target requires us to add additional data to the struct which makes it to bloat and it's probable that those metadata won't be used by other parts of the code.
You may have a point for partType, but the other parts of the metadata ARE useful in other parts of the code, even if we aren't using them yet.
* Other parts that are already present in the source structure are irrelevant to the host representation, such as the network information.
Not irrelevant, so much as redundant. That is, when listing a storage volume from a network storage pool such as gluster, the network information can be obtained from the pool that owns the storage volume - but it shouldn't hurt to also list the network information in the storage volume itself instead of forcing callers to make multiple API calls to obtain all the pieces.
I'd rather see those separated. It might seem that the structs carry similar data but they are semantically different IMO.
+ virStorageSource backingStore;
In case of the backing chain I think that the backing store is a property of the source and not the target thus I'm fine with changing this.
The name <target> in storage volume XML is rather misleading. It really is the same as the <source> element of a domain <disk> element. The name <source> in storage volume XML gives additional details (such as extent mappings on things such as LVM volumes), but THAT is the one that is semantically unrelated to <source> in a domain <disk> element.
I can indeed limit the patch to just changing the backingStore to the common type, but I'm not yet convinced why changing the <target> to use virStorageSource is wrong.
Well you've convinced me. ACK to the original patch if you well-document what partType is used for. PEter

Now that we have a dedicated type for representing a disk source, we might as well parse and format directly into that type instead of piecemeal into pointers to members of the type. * src/conf/domain_conf.h (virDomainDiskSourceDefFormatInternal) (virDomainDiskSourceDefParse): Rename... (virDomainDiskSourceFormat, virDomainDiskSourceParse): ...and compress signatures. * src/conf/domain_conf.c (virDomainDiskSourceParse) (virDomainDiskSourceFormat): Rewrite to use common struct. (virDomainDiskSourceDefFormat): Delete. (virDomainDiskDefParseXML, virDomainDiskDefFormat): Update callers. * src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML) (virDomainSnapshotDiskDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 133 ++++++++++++++++++----------------------------- src/conf/domain_conf.h | 24 +++------ src/conf/snapshot_conf.c | 17 +----- 3 files changed, 60 insertions(+), 114 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0af5be7..fba13e2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4954,13 +4954,8 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node, int -virDomainDiskSourceDefParse(xmlNodePtr node, - int type, - char **source, - int *proto, - size_t *nhosts, - virStorageNetHostDefPtr *hosts, - virStorageSourcePoolDefPtr *srcpool) +virDomainDiskSourceParse(xmlNodePtr node, + virStorageSourcePtr src) { char *protocol = NULL; char *transport = NULL; @@ -4970,15 +4965,15 @@ virDomainDiskSourceDefParse(xmlNodePtr node, memset(&host, 0, sizeof(host)); - switch (type) { + switch (src->type) { case VIR_STORAGE_TYPE_FILE: - *source = virXMLPropString(node, "file"); + src->path = virXMLPropString(node, "file"); break; case VIR_STORAGE_TYPE_BLOCK: - *source = virXMLPropString(node, "dev"); + src->path = virXMLPropString(node, "dev"); break; case VIR_STORAGE_TYPE_DIR: - *source = virXMLPropString(node, "dir"); + src->path = virXMLPropString(node, "dir"); break; case VIR_STORAGE_TYPE_NETWORK: if (!(protocol = virXMLPropString(node, "protocol"))) { @@ -4987,14 +4982,14 @@ virDomainDiskSourceDefParse(xmlNodePtr node, goto cleanup; } - if ((*proto = virStorageNetProtocolTypeFromString(protocol)) < 0){ + if ((src->protocol = virStorageNetProtocolTypeFromString(protocol)) < 0){ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown protocol type '%s'"), protocol); goto cleanup; } - if (!(*source = virXMLPropString(node, "name")) && - *proto != VIR_STORAGE_NET_PROTOCOL_NBD) { + if (!(src->path = virXMLPropString(node, "name")) && + src->protocol != VIR_STORAGE_NET_PROTOCOL_NBD) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing name for disk source")); goto cleanup; @@ -5048,28 +5043,28 @@ virDomainDiskSourceDefParse(xmlNodePtr node, host.port = virXMLPropString(child, "port"); } - if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0) + if (VIR_APPEND_ELEMENT(src->hosts, src->nhosts, host) < 0) goto cleanup; } child = child->next; } break; case VIR_STORAGE_TYPE_VOLUME: - if (virDomainDiskSourcePoolDefParse(node, srcpool) < 0) + if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0) goto cleanup; break; default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected disk type %s"), - virStorageTypeToString(type)); + virStorageTypeToString(src->type)); goto cleanup; } /* People sometimes pass a bogus '' source path when they mean to omit the * source element completely (e.g. CDROM without media). This is just a * little compatibility check to help those broken apps */ - if (*source && STREQ(*source, "")) - VIR_FREE(*source); + if (src->path && !*src->path) + VIR_FREE(src->path); ret = 0; @@ -5176,12 +5171,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, xmlStrEqual(cur->name, BAD_CAST "source")) { sourceNode = cur; - if (virDomainDiskSourceDefParse(cur, def->src.type, - &source, - &def->src.protocol, - &def->src.nhosts, - &def->src.hosts, - &def->src.srcpool) < 0) + if (virDomainDiskSourceParse(cur, &def->src) < 0) goto error; if (def->src.type == VIR_STORAGE_TYPE_NETWORK) { @@ -14694,17 +14684,10 @@ virDomainDiskSourceDefFormatSeclabel(virBufferPtr buf, } int -virDomainDiskSourceDefFormatInternal(virBufferPtr buf, - int type, - const char *src, - int policy, - int protocol, - size_t nhosts, - virStorageNetHostDefPtr hosts, - size_t nseclabels, - virSecurityDeviceLabelDefPtr *seclabels, - virStorageSourcePoolDefPtr srcpool, - unsigned int flags) +virDomainDiskSourceFormat(virBufferPtr buf, + virStorageSourcePtr src, + int policy, + unsigned int flags) { size_t n; const char *startupPolicy = NULL; @@ -14712,51 +14695,56 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, if (policy) startupPolicy = virDomainStartupPolicyTypeToString(policy); - if (src || nhosts > 0 || srcpool || startupPolicy) { - switch (type) { + if (src->path || src->nhosts > 0 || src->srcpool || startupPolicy) { + switch ((enum virStorageType)src->type) { case VIR_STORAGE_TYPE_FILE: virBufferAddLit(buf, "<source"); - virBufferEscapeString(buf, " file='%s'", src); + virBufferEscapeString(buf, " file='%s'", src->path); virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); - virDomainDiskSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags); + virDomainDiskSourceDefFormatSeclabel(buf, src->nseclabels, + src->seclabels, flags); break; case VIR_STORAGE_TYPE_BLOCK: virBufferAddLit(buf, "<source"); - virBufferEscapeString(buf, " dev='%s'", src); + virBufferEscapeString(buf, " dev='%s'", src->path); virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); - virDomainDiskSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags); + virDomainDiskSourceDefFormatSeclabel(buf, src->nseclabels, + src->seclabels, flags); break; case VIR_STORAGE_TYPE_DIR: virBufferAddLit(buf, "<source"); - virBufferEscapeString(buf, " dir='%s'", src); + virBufferEscapeString(buf, " dir='%s'", src->path); virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); virBufferAddLit(buf, "/>\n"); break; case VIR_STORAGE_TYPE_NETWORK: virBufferAsprintf(buf, "<source protocol='%s'", - virStorageNetProtocolTypeToString(protocol)); - virBufferEscapeString(buf, " name='%s'", src); + virStorageNetProtocolTypeToString(src->protocol)); + virBufferEscapeString(buf, " name='%s'", src->path); - if (nhosts == 0) { + if (src->nhosts == 0) { virBufferAddLit(buf, "/>\n"); } else { virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); - for (n = 0; n < nhosts; n++) { + for (n = 0; n < src->nhosts; n++) { virBufferAddLit(buf, "<host"); - virBufferEscapeString(buf, " name='%s'", hosts[n].name); - virBufferEscapeString(buf, " port='%s'", hosts[n].port); + virBufferEscapeString(buf, " name='%s'", + src->hosts[n].name); + virBufferEscapeString(buf, " port='%s'", + src->hosts[n].port); - if (hosts[n].transport) + if (src->hosts[n].transport) virBufferAsprintf(buf, " transport='%s'", - virStorageNetHostTransportTypeToString(hosts[n].transport)); + virStorageNetHostTransportTypeToString(src->hosts[n].transport)); - virBufferEscapeString(buf, " socket='%s'", hosts[n].socket); + virBufferEscapeString(buf, " socket='%s'", + src->hosts[n].socket); virBufferAddLit(buf, "/>\n"); } @@ -14768,22 +14756,23 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, case VIR_STORAGE_TYPE_VOLUME: virBufferAddLit(buf, "<source"); - if (srcpool) { - virBufferAsprintf(buf, " pool='%s' volume='%s'", - srcpool->pool, srcpool->volume); - if (srcpool->mode) + if (src->srcpool) { + virBufferEscapeString(buf, " pool='%s'", src->srcpool->pool); + virBufferEscapeString(buf, " volume='%s'", + src->srcpool->volume); + if (src->srcpool->mode) virBufferAsprintf(buf, " mode='%s'", - virStorageSourcePoolModeTypeToString(srcpool->mode)); + virStorageSourcePoolModeTypeToString(src->srcpool->mode)); } virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); - virDomainDiskSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags); + virDomainDiskSourceDefFormatSeclabel(buf, src->nseclabels, + src->seclabels, flags); break; - default: + case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected disk type %s"), - virStorageTypeToString(type)); + _("unexpected disk type %d"), src->type); return -1; } } @@ -14793,25 +14782,6 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, static int -virDomainDiskSourceDefFormat(virBufferPtr buf, - virDomainDiskDefPtr def, - unsigned int flags) -{ - return virDomainDiskSourceDefFormatInternal(buf, - def->src.type, - def->src.path, - def->startupPolicy, - def->src.protocol, - def->src.nhosts, - def->src.hosts, - def->src.nseclabels, - def->src.seclabels, - def->src.srcpool, - flags); -} - - -static int virDomainDiskDefFormat(virBufferPtr buf, virDomainDiskDefPtr def, unsigned int flags) @@ -14932,7 +14902,8 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferAddLit(buf, "</auth>\n"); } - if (virDomainDiskSourceDefFormat(buf, def, flags) < 0) + if (virDomainDiskSourceFormat(buf, &def->src, def->startupPolicy, + flags) < 0) return -1; virDomainDiskGeometryDefFormat(buf, def); virDomainDiskBlockIoDefFormat(buf, def); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 02ac5de..2f874c5 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2271,17 +2271,10 @@ int virDomainDefFormatInternal(virDomainDefPtr def, unsigned int flags, virBufferPtr buf); -int virDomainDiskSourceDefFormatInternal(virBufferPtr buf, - int type, - const char *src, - int policy, - int protocol, - size_t nhosts, - virStorageNetHostDefPtr hosts, - size_t nseclabels, - virSecurityDeviceLabelDefPtr *seclabels, - virStorageSourcePoolDefPtr srcpool, - unsigned int flags); +int virDomainDiskSourceFormat(virBufferPtr buf, + virStorageSourcePtr src, + int policy, + unsigned int flags); int virDomainNetDefFormat(virBufferPtr buf, virDomainNetDefPtr def, @@ -2328,13 +2321,8 @@ virDomainDiskDefPtr virDomainDiskRemove(virDomainDefPtr def, size_t i); virDomainDiskDefPtr virDomainDiskRemoveByName(virDomainDefPtr def, const char *name); -int virDomainDiskSourceDefParse(xmlNodePtr node, - int type, - char **source, - int *proto, - size_t *nhosts, - virStorageNetHostDefPtr *hosts, - virStorageSourcePoolDefPtr *srcpool); +int virDomainDiskSourceParse(xmlNodePtr node, + virStorageSourcePtr src); bool virDomainHasDiskMirror(virDomainObjPtr vm); diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 3bd4732..374a104 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -150,13 +150,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, if (!def->src.path && xmlStrEqual(cur->name, BAD_CAST "source")) { - if (virDomainDiskSourceDefParse(cur, - def->src.type, - &def->src.path, - &def->src.protocol, - &def->src.nhosts, - &def->src.hosts, - NULL) < 0) + if (virDomainDiskSourceParse(cur, &def->src) < 0) goto cleanup; } else if (!def->src.format && @@ -635,14 +629,7 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf, if (disk->src.format > 0) virBufferEscapeString(buf, "<driver type='%s'/>\n", virStorageFileFormatTypeToString(disk->src.format)); - virDomainDiskSourceDefFormatInternal(buf, - type, - disk->src.path, - 0, - disk->src.protocol, - disk->src.nhosts, - disk->src.hosts, - 0, NULL, NULL, 0); + virDomainDiskSourceFormat(buf, &disk->src, 0, 0); virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</disk>\n"); -- 1.9.0

On 03/31/2014 12:09 PM, Eric Blake wrote:
Now that we have a dedicated type for representing a disk source, we might as well parse and format directly into that type instead of piecemeal into pointers to members of the type.
Aargh; hit send too soon. I'm still tracking down why this patch breaks 'make check'. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 03/31/2014 12:13 PM, Eric Blake wrote:
On 03/31/2014 12:09 PM, Eric Blake wrote:
Now that we have a dedicated type for representing a disk source, we might as well parse and format directly into that type instead of piecemeal into pointers to members of the type.
Aargh; hit send too soon. I'm still tracking down why this patch breaks 'make check'.
Squash this in: diff --git i/src/conf/domain_conf.c w/src/conf/domain_conf.c index fba13e2..6e71885 100644 --- i/src/conf/domain_conf.c +++ w/src/conf/domain_conf.c @@ -5102,7 +5102,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, char *sgio = NULL; char *driverName = NULL; char *driverType = NULL; - char *source = NULL; + const char *source = NULL; char *target = NULL; char *trans = NULL; char *bus = NULL; @@ -5173,6 +5173,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, if (virDomainDiskSourceParse(cur, &def->src) < 0) goto error; + source = def->src.path; if (def->src.type == VIR_STORAGE_TYPE_NETWORK) { if (def->src.protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI) @@ -5789,8 +5790,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, def->startupPolicy = val; } - def->src.path = source; - source = NULL; def->dst = target; target = NULL; def->src.auth.username = authUsername; @@ -5842,7 +5841,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, VIR_FREE(rawio); VIR_FREE(sgio); VIR_FREE(target); - VIR_FREE(source); VIR_FREE(tray); VIR_FREE(removable); VIR_FREE(trans); -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Peter Krempa