Signed-off-by: Wei Jiangang <weijg.fnst(a)cn.fujitsu.com>
---
src/libvirt-domain.c | 55 ++++++++++++++--------------------------------------
1 file changed, 15 insertions(+), 40 deletions(-)
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 6e1aacd..ed07c9e 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -33,6 +33,13 @@ VIR_LOG_INIT("libvirt.domain");
#define VIR_FROM_THIS VIR_FROM_DOMAIN
+#define VIR_ABSOLUTIZE_PATH(PATH, ABSPATH) \
+ if (virFileAbsPath(PATH, ABSPATH) < 0) { \
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \
+ _("could not build absolute input file path")); \
+ goto error; \
+ }
+
/**
* virConnectListDomains:
@@ -830,11 +837,7 @@ virDomainSave(virDomainPtr domain, const char *to)
char *absolute_to;
/* We must absolutize the file path as the save is done out of process */
- if (virFileAbsPath(to, &absolute_to) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("could not build absolute output file path"));
- goto error;
- }
+ VIR_ABSOLUTIZE_PATH(to, &absolute_to);
ret = conn->driver->domainSave(domain, absolute_to);
@@ -918,11 +921,7 @@ virDomainSaveFlags(virDomainPtr domain, const char *to,
char *absolute_to;
/* We must absolutize the file path as the save is done out of process */
- if (virFileAbsPath(to, &absolute_to) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("could not build absolute output file path"));
- goto error;
- }
+ VIR_ABSOLUTIZE_PATH(to, &absolute_to);
ret = conn->driver->domainSaveFlags(domain, absolute_to, dxml, flags);
@@ -968,11 +967,7 @@ virDomainRestore(virConnectPtr conn, const char *from)
char *absolute_from;
/* We must absolutize the file path as the restore is done out of process */
- if (virFileAbsPath(from, &absolute_from) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("could not build absolute input file path"));
- goto error;
- }
+ VIR_ABSOLUTIZE_PATH(from, &absolute_from);
ret = conn->driver->domainRestore(conn, absolute_from);
@@ -1042,11 +1037,7 @@ virDomainRestoreFlags(virConnectPtr conn, const char *from, const
char *dxml,
char *absolute_from;
/* We must absolutize the file path as the restore is done out of process */
- if (virFileAbsPath(from, &absolute_from) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("could not build absolute input file path"));
- goto error;
- }
+ VIR_ABSOLUTIZE_PATH(from, &absolute_from);
ret = conn->driver->domainRestoreFlags(conn, absolute_from, dxml,
flags);
@@ -1107,11 +1098,7 @@ virDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *file,
char *absolute_file;
/* We must absolutize the file path as the read is done out of process */
- if (virFileAbsPath(file, &absolute_file) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("could not build absolute input file path"));
- goto error;
- }
+ VIR_ABSOLUTIZE_PATH(file, &absolute_file);
ret = conn->driver->domainSaveImageGetXMLDesc(conn, absolute_file,
flags);
@@ -1180,11 +1167,7 @@ virDomainSaveImageDefineXML(virConnectPtr conn, const char *file,
char *absolute_file;
/* We must absolutize the file path as the read is done out of process */
- if (virFileAbsPath(file, &absolute_file) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("could not build absolute input file path"));
- goto error;
- }
+ VIR_ABSOLUTIZE_PATH(file, &absolute_file);
ret = conn->driver->domainSaveImageDefineXML(conn, absolute_file,
dxml, flags);
@@ -1255,11 +1238,7 @@ virDomainCoreDump(virDomainPtr domain, const char *to, unsigned int
flags)
char *absolute_to;
/* We must absolutize the file path as the save is done out of process */
- if (virFileAbsPath(to, &absolute_to) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("could not build absolute core file path"));
- goto error;
- }
+ VIR_ABSOLUTIZE_PATH(to, &absolute_to);
ret = conn->driver->domainCoreDump(domain, absolute_to, flags);
@@ -1339,11 +1318,7 @@ virDomainCoreDumpWithFormat(virDomainPtr domain, const char *to,
char *absolute_to;
/* We must absolutize the file path as the save is done out of process */
- if (virFileAbsPath(to, &absolute_to) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("could not build absolute core file path"));
- goto error;
- }
+ VIR_ABSOLUTIZE_PATH(to, &absolute_to);
ret = conn->driver->domainCoreDumpWithFormat(domain, absolute_to,
dumpformat, flags);
--
1.9.3