From: sonya <rodinasophie(a)gmail.com>
---
tools/Makefile.am | 1 +
tools/virsh-domain.c | 195 ++++++++++++++++++++++++++++++++++++------------
tools/virsh-edit.c | 97 +++++-------------------
tools/virsh-interface.c | 66 ++++++++++++----
tools/virsh-network.c | 66 ++++++++++++----
tools/virsh-nwfilter.c | 67 +++++++++++++----
tools/virsh-pool.c | 66 ++++++++++++----
tools/virsh-snapshot.c | 78 ++++++++++++++-----
8 files changed, 437 insertions(+), 199 deletions(-)
diff --git a/tools/Makefile.am b/tools/Makefile.am
index d5638d9..88bb1b2 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -205,6 +205,7 @@ virsh_SOURCES = \
virsh-domain.c virsh-domain.h \
virsh-domain-monitor.c virsh-domain-monitor.h \
virsh-host.c virsh-host.h \
+ virsh-edit.c virsh-edit.h \
virsh-interface.c virsh-interface.h \
virsh-network.c virsh-network.h \
virsh-nodedev.c virsh-nodedev.h \
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 12e85e3..648b086 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -56,6 +56,7 @@
#include "virtime.h"
#include "virtypedparam.h"
#include "virxml.h"
+#include "virsh-edit.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
@@ -4622,6 +4623,45 @@ static const vshCmdOptDef opts_save_image_edit[] = {
{.name = NULL}
};
+typedef struct editDomainUniversalStruct
+{
+ vshControl *ctl;
+ virshControlPtr priv;
+ const char *file;
+ virDomainPtr dom;
+ unsigned int getxml_flags;
+ bool *ret;
+ unsigned int *define_flags;
+ const char *key;
+ virDomainPtr *dom_edited;
+} editDomainUniversalStruct;
+
+static char*
+editDomainSaveImageGetXML(void *args)
+{
+ editDomainUniversalStruct *str = (editDomainUniversalStruct*)args;
+ return virDomainSaveImageGetXMLDesc(str->priv->conn, str->file,
str->getxml_flags);
+}
+
+static void
+editDomainSaveImageNotChanged(void *args)
+{
+ editDomainUniversalStruct *str = (editDomainUniversalStruct*)args;
+ vshPrint(str->ctl, _("Saved image %s XML configuration not changed.\n"),
str->file);
+ *(str->ret) = true;
+}
+
+static bool
+editDomainSaveImageDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ editDomainUniversalStruct *str = (editDomainUniversalStruct*)args;
+ return
+ (virDomainSaveImageDefineXML(str->priv->conn, str->file,
+ doc_edited, *(str->define_flags)) == 0);
+}
+
static bool
cmdSaveImageEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -4647,21 +4687,24 @@ cmdSaveImageEdit(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
return false;
-
-#define EDIT_GET_XML \
- virDomainSaveImageGetXMLDesc(priv->conn, file, getxml_flags)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Saved image %s XML configuration " \
- "not changed.\n"), file); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (virDomainSaveImageDefineXML(priv->conn, file, doc_edited, define_flags) == 0)
-#include "virsh-edit.c"
-
- vshPrint(ctl, _("State file %s edited.\n"), file);
+ {
+ editDomainUniversalStruct editDomainArgs = {
+ NULL, priv, file, NULL, getxml_flags,
+ &ret, &define_flags, NULL, NULL
+ };
+
+ vshEditControl editCtl = {
+ &editDomainSaveImageGetXML,
+ &editDomainSaveImageNotChanged,
+ &editDomainSaveImageDefine,
+ NULL,
+ &editDomainArgs,
+ };
+
+ if (!vshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
+ vshPrint(ctl, _("State file %s edited.\n"), file);
ret = true;
cleanup:
@@ -8145,6 +8188,30 @@ virshDomainGetEditMetadata(vshControl *ctl,
return ret;
}
+static char*
+editDomainMetadataGetXML(void *args)
+{
+ editDomainUniversalStruct *str = (editDomainUniversalStruct*)(args);
+ return virshDomainGetEditMetadata(str->ctl, str->dom, str->file,
str->getxml_flags);
+}
+
+static void
+editMetadataNotChanged(void *args)
+{
+ editDomainUniversalStruct *str = (editDomainUniversalStruct*)args;
+ vshPrint(str->ctl, "%s", _("Metadata not changed"));
+ *(str->ret) = true;
+}
+
+static bool
+editMetadataDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ editDomainUniversalStruct *str = (editDomainUniversalStruct*)args;
+ return (virDomainSetMetadata(str->dom, VIR_DOMAIN_METADATA_ELEMENT, doc_edited,
+ str->key, str->file, *(str->define_flags)) == 0);
+}
static bool
cmdMetadata(vshControl *ctl, const vshCmd *cmd)
@@ -8196,20 +8263,21 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd)
else
vshPrint("%s\n", _("Metadata modified"));
} else if (edit) {
-#define EDIT_GET_XML \
- virshDomainGetEditMetadata(ctl, dom, uri, flags)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, "%s", _("Metadata not changed")); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-
-#define EDIT_DEFINE \
- (virDomainSetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, doc_edited, \
- key, uri, flags) == 0)
-#include "virsh-edit.c"
-
+ editDomainUniversalStruct editMetadataArgs = {
+ ctl, NULL, uri, dom,
+ flags, &ret, &flags, key, NULL
+ };
+
+ vshEditControl editCtl = {
+ &editDomainMetadataGetXML,
+ &editMetadataNotChanged,
+ &editMetadataDefine,
+ NULL,
+ &editMetadataArgs,
+ };
+
+ if (!vshEdit(ctl, &editCtl))
+ goto cleanup;
vshPrint("%s\n", _("Metadata modified"));
} else {
char *data;
@@ -11764,6 +11832,40 @@ static const vshCmdOptDef opts_edit[] = {
{.name = NULL}
};
+static char*
+editDomainGetXML(void *args)
+{
+ editDomainUniversalStruct *str = (editDomainUniversalStruct*)args;
+ return virDomainGetXMLDesc(str->dom, str->getxml_flags);
+}
+
+static void
+editDomainNotChanged(void *args)
+{
+ editDomainUniversalStruct *str = (editDomainUniversalStruct*)args;
+ vshPrint(str->ctl, _("Domain %s XML configuration not changed.\n"),
+ virDomainGetName(str->dom));
+ *(str->ret) = true;
+}
+
+static bool
+editDomainDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ editDomainUniversalStruct *str = (editDomainUniversalStruct*)args;
+ return
+ (*(str->dom_edited) = virshDomainDefine(str->priv->conn, doc_edited,
+ *(str->define_flags)));
+}
+
+static void
+editDomainRelax(void *args)
+{
+ editDomainUniversalStruct *str = (editDomainUniversalStruct*)args;
+ *(str->define_flags) &= ~VIR_DOMAIN_DEFINE_VALIDATE;
+}
+
static bool
cmdEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -11780,24 +11882,23 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "skip-validate"))
define_flags &= ~VIR_DOMAIN_DEFINE_VALIDATE;
-
-#define EDIT_GET_XML virDomainGetXMLDesc(dom, query_flags)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Domain %s XML configuration not changed.\n"), \
- virDomainGetName(dom)); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (dom_edited = virshDomainDefine(priv->conn, doc_edited, define_flags))
-#define EDIT_RELAX \
- do { \
- define_flags &= ~VIR_DOMAIN_DEFINE_VALIDATE; \
- } while (0);
-
-#include "virsh-edit.c"
-#undef EDIT_RELAX
+ {
+ editDomainUniversalStruct editDomainArgs = {
+ ctl, priv, NULL, dom,
+ query_flags, &ret, &define_flags, NULL, &dom_edited
+ };
+
+ vshEditControl editCtl = {
+ &editDomainGetXML,
+ &editDomainNotChanged,
+ &editDomainDefine,
+ &editDomainRelax,
+ &editDomainArgs,
+ };
+
+ if (!vshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
vshPrint(ctl, _("Domain %s XML configuration edited.\n"),
virDomainGetName(dom_edited));
diff --git a/tools/virsh-edit.c b/tools/virsh-edit.c
index 1b39cb7..84f4dae 100644
--- a/tools/virsh-edit.c
+++ b/tools/virsh-edit.c
@@ -1,61 +1,7 @@
-/*
- * virsh-edit.c: Implementation of generic virsh *-edit intelligence
- *
- * Copyright (C) 2012, 2015 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
- * 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/>.
- *
- * Usage:
- * Define macros:
- * EDIT_GET_XML - expression which produces a pointer to XML string, e.g:
- * #define EDIT_GET_XML virDomainGetXMLDesc(dom, flags)
- *
- * EDIT_NOT_CHANGED - this action is taken if the XML wasn't changed.
- * Note, that you don't want to jump to cleanup but edit_cleanup label
- * where temporary variables are free()-d and temporary file is deleted:
- * #define EDIT_NOT_CHANGED vshPrint(ctl, _("Domain %s XML not changed"),
\
- * virDomainGetName(dom)); \
- * ret = true; goto edit_cleanup;
- * Note that this is a statement.
- *
- * EDIT_DEFINE - expression which redefines the object. The edited XML from
- * user is in 'doc_edited' variable. Don't overwrite the pointer to the
- * object, as we may iterate once more over and therefore the pointer
- * would be invalid. Hence assign object to a different variable.
- * Moreover, this needs to be an expression where:
- * - 0 is taken as error (our virDefine* APIs often return NULL on error)
- * - everything else is taken as success
- * For example:
- * #define EDIT_DEFINE (dom_edited = virDomainDefineXML(ctl->conn, doc_edited))
- *
- * Michal Privoznik <mprivozn(a)redhat.com>
- */
-
-#ifndef EDIT_GET_XML
-# error Missing EDIT_GET_XML definition
-#endif
-
-#ifndef EDIT_NOT_CHANGED
-# error Missing EDIT_NOT_CHANGED definition
-#endif
-
-#ifndef EDIT_DEFINE
-# error Missing EDIT_DEFINE definition
-#endif
-
-do {
+#include "virsh-edit.h"
+#include "viralloc.h"
+
+bool vshEdit(vshControl *ctl, vshEditControl *editCtl) {
char *tmp = NULL;
char *doc = NULL;
char *doc_edited = NULL;
@@ -65,7 +11,7 @@ do {
bool relax_avail = false;
/* Get the XML configuration of the object. */
- doc = (EDIT_GET_XML);
+ doc = (*editCtl->editGetXML)(editCtl->editArgs);
if (!doc)
goto edit_cleanup;
@@ -76,9 +22,8 @@ do {
reedit:
-#ifdef EDIT_RELAX
- relax_avail = true;
-#endif
+ if (editCtl->editRelax)
+ relax_avail = true;
/* Start the editor. */
if (vshEditFile(ctl, tmp) == -1)
@@ -91,8 +36,10 @@ do {
goto edit_cleanup;
/* Compare original XML with edited. Has it changed at all? */
- if (STREQ(doc, doc_edited))
- EDIT_NOT_CHANGED;
+ if (STREQ(doc, doc_edited)) {
+ (*editCtl->editNotChanged)(editCtl->editArgs);
+ goto edit_cleanup;
+ }
redefine:
msg = NULL;
@@ -102,7 +49,7 @@ do {
* losing a connection or the object going away.
*/
VIR_FREE(doc_reread);
- doc_reread = (EDIT_GET_XML);
+ doc_reread = (*editCtl->editGetXML)(editCtl->editArgs);
if (!doc_reread)
goto edit_cleanup;
@@ -114,7 +61,7 @@ do {
}
/* Everything checks out, so redefine the object. */
- if (!msg && !(EDIT_DEFINE))
+ if (!msg && !((*editCtl->editDefine)(editCtl->editArgs, doc_edited,
doc)))
msg = _("Failed.");
if (msg) {
@@ -132,16 +79,14 @@ do {
goto edit_cleanup;
break;
-#ifdef EDIT_RELAX
case 'i':
if (relax_avail) {
- EDIT_RELAX;
+ (*editCtl->editRelax)(editCtl->editArgs);
relax_avail = false;
goto redefine;
break;
}
/* fall-through */
-#endif
default:
vshError(ctl, "%s", msg);
@@ -160,12 +105,8 @@ do {
VIR_FREE(tmp);
}
- if (!edit_success)
- goto cleanup;
-
-} while (0);
-
-
-#undef EDIT_GET_XML
-#undef EDIT_NOT_CHANGED
-#undef EDIT_DEFINE
+ if (!edit_success) {
+ return false;
+ }
+ return true;
+}
diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c
index b69c685..5bc9392 100644
--- a/tools/virsh-interface.c
+++ b/tools/virsh-interface.c
@@ -39,6 +39,7 @@
#include "virutil.h"
#include "virxml.h"
#include "virstring.h"
+#include "virsh-edit.h"
virInterfacePtr
virshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
@@ -108,6 +109,42 @@ static const vshCmdOptDef opts_interface_edit[] = {
{.name = NULL}
};
+typedef struct editInterfaceStruct
+{
+ vshControl *ctl;
+ virshControlPtr priv;
+ virInterfacePtr iface;
+ virInterfacePtr *iface_edited;
+ unsigned int flags;
+ bool *ret;
+} editInterfaceStruct;
+
+static char*
+editInterfaceGetXML(void *args)
+{
+ editInterfaceStruct *str = (editInterfaceStruct*)args;
+ return virInterfaceGetXMLDesc(str->iface, str->flags);
+}
+
+static void
+editInterfaceNotChanged(void *args)
+{
+ editInterfaceStruct *str = (editInterfaceStruct*)args;
+ vshPrint(str->ctl, _("Interface %s XML configuration not changed.\n"),
+ virInterfaceGetName(str->iface));
+ *(str->ret) = true;
+}
+
+static bool
+editInterfaceDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ editInterfaceStruct *str = (editInterfaceStruct*)args;
+ return (*(str->iface_edited) = virInterfaceDefineXML(str->priv->conn,
+ doc_edited, 0));
+}
+
static bool
cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -120,19 +157,22 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd)
iface = virshCommandOptInterface(ctl, cmd, NULL);
if (iface == NULL)
goto cleanup;
-
-#define EDIT_GET_XML virInterfaceGetXMLDesc(iface, flags)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Interface %s XML configuration not changed.\n"), \
- virInterfaceGetName(iface)); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (iface_edited = virInterfaceDefineXML(priv->conn, doc_edited, 0))
-#include "virsh-edit.c"
-
+ {
+ editInterfaceStruct editInterfaceArgs = {
+ ctl, priv, iface, &iface_edited, flags, &ret
+ };
+
+ vshEditControl editCtl = {
+ &editInterfaceGetXML,
+ &editInterfaceNotChanged,
+ &editInterfaceDefine,
+ NULL,
+ &editInterfaceArgs,
+ };
+
+ if (!vshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
vshPrint(ctl, _("Interface %s XML configuration edited.\n"),
virInterfaceGetName(iface_edited));
diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index a0f7707..b132536 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -32,6 +32,7 @@
#include "virfile.h"
#include "virstring.h"
#include "conf/network_conf.h"
+#include "virsh-edit.h"
virNetworkPtr
virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
@@ -1121,6 +1122,41 @@ static char *virshNetworkGetXMLDesc(virNetworkPtr network)
return doc;
}
+typedef struct editNetworkStruct
+{
+ vshControl *ctl;
+ virNetworkPtr network;
+ virNetworkPtr *network_edited;
+ virshControlPtr priv;
+ bool *ret;
+} editNetworkStruct;
+
+static char*
+editNetworkGetXML(void *args)
+{
+ editNetworkStruct *str = (editNetworkStruct*)args;
+ return virshNetworkGetXMLDesc(str->network);
+}
+
+static void
+editNetworkNotChanged(void *args)
+{
+ editNetworkStruct *str = (editNetworkStruct*)args;
+ vshPrint(str->ctl, _("Network %s XML configuration not changed.\n"),
+ virNetworkGetName(str->network));
+ *(str->ret) = true;
+}
+
+static bool
+editNetworkDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc) {
+ return false;
+ }
+ editNetworkStruct *str = (editNetworkStruct*)args;
+ return (*(str->network_edited) = virNetworkDefineXML(str->priv->conn,
doc_edited));
+}
+
static bool
cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -1133,19 +1169,23 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
if (network == NULL)
goto cleanup;
-#define EDIT_GET_XML virshNetworkGetXMLDesc(network)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Network %s XML configuration not changed.\n"), \
- virNetworkGetName(network)); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (network_edited = virNetworkDefineXML(priv->conn, doc_edited))
-#include "virsh-edit.c"
-
- vshPrint(ctl, _("Network %s XML configuration edited.\n"),
+ {
+ editNetworkStruct editNetworkArgs = {
+ ctl, network, &network_edited, priv, &ret
+ };
+
+ vshEditControl editCtl = {
+ &editNetworkGetXML,
+ &editNetworkNotChanged,
+ &editNetworkDefine,
+ NULL,
+ &editNetworkArgs,
+ };
+
+ if (!vshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
+ vshPrint(ctl, _("Network %s XML configuration edited.\n"),
virNetworkGetName(network_edited));
ret = true;
diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c
index 7732da8..f0078cf 100644
--- a/tools/virsh-nwfilter.c
+++ b/tools/virsh-nwfilter.c
@@ -31,6 +31,7 @@
#include "viralloc.h"
#include "virfile.h"
#include "virutil.h"
+#include "virsh-edit.h"
virNWFilterPtr
virshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd,
@@ -404,6 +405,40 @@ static const vshCmdOptDef opts_nwfilter_edit[] = {
{.name = NULL}
};
+typedef struct editNwFilterStruct
+{
+ vshControl *ctl;
+ virNWFilterPtr nwfilter;
+ virNWFilterPtr *nwfilter_edited;
+ virshControlPtr priv;
+ bool *ret;
+} editNwFilterStruct;
+
+static char*
+editNwFilterGetXML(void *args)
+{
+ editNwFilterStruct *str = (editNwFilterStruct*)args;
+ return virNWFilterGetXMLDesc(str->nwfilter, 0);
+}
+
+static void
+editNwFilterNotChanged(void *args)
+{
+ editNwFilterStruct *str = (editNwFilterStruct*)args;
+ vshPrint(str->ctl, _("Network filter %s XML configuration not
changed.\n"),
+ virNWFilterGetName(str->nwfilter));
+ *(str->ret) = true;
+}
+
+static bool
+editNwFilterDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ editNwFilterStruct *str = (editNwFilterStruct*)args;
+ return (*(str->nwfilter_edited) = virNWFilterDefineXML(str->priv->conn,
doc_edited));
+}
+
static bool
cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -415,21 +450,23 @@ cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL);
if (nwfilter == NULL)
goto cleanup;
-
-#define EDIT_GET_XML virNWFilterGetXMLDesc(nwfilter, 0)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Network filter %s XML " \
- "configuration not changed.\n"), \
- virNWFilterGetName(nwfilter)); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (nwfilter_edited = virNWFilterDefineXML(priv->conn, doc_edited))
-#include "virsh-edit.c"
-
- vshPrint(ctl, _("Network filter %s XML configuration edited.\n"),
+ {
+ editNwFilterStruct editNwFilterArgs = {
+ ctl, nwfilter, &nwfilter_edited, priv, &ret
+ };
+
+ vshEditControl editCtl = {
+ &editNwFilterGetXML,
+ &editNwFilterNotChanged,
+ &editNwFilterDefine,
+ NULL,
+ &editNwFilterArgs,
+ };
+
+ if (!vshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
+ vshPrint(ctl, _("Network filter %s XML configuration edited.\n"),
virNWFilterGetName(nwfilter_edited));
ret = true;
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index cf5a8f3..cb1af3d 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -32,6 +32,7 @@
#include "virfile.h"
#include "conf/storage_conf.h"
#include "virstring.h"
+#include "virsh-edit.h"
virStoragePoolPtr
virshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
@@ -1791,6 +1792,42 @@ static const vshCmdOptDef opts_pool_edit[] = {
{.name = NULL}
};
+typedef struct editStoragePoolStruct
+{
+ vshControl *ctl;
+ virStoragePoolPtr pool;
+ virStoragePoolPtr *pool_edited;
+ virshControlPtr priv;
+ bool *ret;
+ unsigned int flags;
+} editStoragePoolStruct;
+
+static char*
+editStoragePoolGetXML(void *args)
+{
+ editStoragePoolStruct *str = (editStoragePoolStruct*)args;
+ return virStoragePoolGetXMLDesc(str->pool, str->flags);
+}
+
+static void
+editStoragePoolNotChanged(void *args)
+{
+ editStoragePoolStruct *str = (editStoragePoolStruct*)args;
+ vshPrint(str->ctl, _("Pool %s XML configuration not changed.\n"),
+ virStoragePoolGetName(str->pool));
+ *(str->ret) = true;
+}
+
+static bool
+editStoragePoolDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ editStoragePoolStruct *str = (editStoragePoolStruct*)args;
+ return (*(str->pool_edited) =
+ virStoragePoolDefineXML(str->priv->conn, doc_edited, 0));
+}
+
static bool
cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -1816,19 +1853,22 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
} else {
VIR_FREE(tmp_desc);
}
-
-#define EDIT_GET_XML virStoragePoolGetXMLDesc(pool, flags)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Pool %s XML configuration not changed.\n"), \
- virStoragePoolGetName(pool)); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (pool_edited = virStoragePoolDefineXML(priv->conn, doc_edited, 0))
-#include "virsh-edit.c"
-
+ {
+ editStoragePoolStruct editStoragePoolArgs = {
+ ctl, pool, &pool_edited, priv, &ret, flags
+ };
+
+ vshEditControl editCtl = {
+ &editStoragePoolGetXML,
+ &editStoragePoolNotChanged,
+ &editStoragePoolDefine,
+ NULL,
+ &editStoragePoolArgs,
+ };
+
+ if (!vshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
vshPrint(ctl, _("Pool %s XML configuration edited.\n"),
virStoragePoolGetName(pool_edited));
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index 3ab2104..63a81c1 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -41,6 +41,7 @@
#include "virstring.h"
#include "virxml.h"
#include "conf/snapshot_conf.h"
+#include "virsh-edit.h"
/* Helper for snapshot-create and snapshot-create-as */
static bool
@@ -548,6 +549,47 @@ static const vshCmdOptDef opts_snapshot_edit[] = {
{.name = NULL}
};
+typedef struct editSnapshotStruct
+{
+ vshControl *ctl;
+ virDomainSnapshotPtr snapshot;
+ virDomainSnapshotPtr *edited;
+ virDomainPtr dom;
+ bool *ret;
+ unsigned int getxml_flags;
+ unsigned int *define_flags;
+ const char *name;
+} editSnapshotStruct;
+
+static char*
+editSnapshotGetXML(void *args)
+{
+ editSnapshotStruct *str = (editSnapshotStruct*)args;
+ return virDomainSnapshotGetXMLDesc(str->snapshot, str->getxml_flags);
+}
+
+static void
+editSnapshotNotChanged(void *args)
+{
+ editSnapshotStruct *str = (editSnapshotStruct*)args;
+ /* Depending on flags, we re-edit even if XML is unchanged. */
+ if (!(*(str->define_flags) & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)) {
+ vshPrint(str->ctl, _("Snapshot %s XML configuration not changed.\n"),
+ str->name);
+ *(str->ret) = true;
+ }
+}
+
+static bool
+editSnapshotDefine(void *args, char *doc_edited, char *doc)
+{
+ editSnapshotStruct *str = (editSnapshotStruct*)args;
+ (strstr(doc, "<state>disk-snapshot</state>") ?
+ *(str->define_flags) |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY : 0);
+ return (*(str->edited) = virDomainSnapshotCreateXML(str->dom, doc_edited,
+ *(str->define_flags)));
+}
+
static bool
cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -574,26 +616,22 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
if (virshLookupSnapshot(ctl, cmd, "snapshotname", false, dom,
&snapshot, &name) < 0)
goto cleanup;
-
-#define EDIT_GET_XML \
- virDomainSnapshotGetXMLDesc(snapshot, getxml_flags)
-#define EDIT_NOT_CHANGED \
- do { \
- /* Depending on flags, we re-edit even if XML is unchanged. */ \
- if (!(define_flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)) { \
- vshPrint(ctl, \
- _("Snapshot %s XML configuration not changed.\n"), \
- name); \
- ret = true; \
- goto edit_cleanup; \
- } \
- } while (0)
-#define EDIT_DEFINE \
- (strstr(doc, "<state>disk-snapshot</state>") ? \
- define_flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY : 0), \
- edited = virDomainSnapshotCreateXML(dom, doc_edited, define_flags)
-#include "virsh-edit.c"
-
+ {
+ editSnapshotStruct editSnapshotArgs = {
+ ctl, snapshot, &edited, dom, &ret, getxml_flags, &define_flags, name
+ };
+
+ vshEditControl editCtl = {
+ &editSnapshotGetXML,
+ &editSnapshotNotChanged,
+ &editSnapshotDefine,
+ NULL,
+ &editSnapshotArgs,
+ };
+
+ if (!vshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
edited_name = virDomainSnapshotGetName(edited);
if (STREQ(name, edited_name)) {
vshPrint(ctl, _("Snapshot %s edited.\n"), name);
--
2.1.4