I've changed over 200 uses of <some_error_function> with the
VIR_ERR_NO_MEMORY flag to call virReportOOMError with whatever
"conn"-like argument (if any) was in the original call.
I don't claim to have tested these changes (OOM is a pain to simulate,
and besides, testing so many failure points would take more
infrastructure than we have right now).
However, I did automate most of the process.
most of the changes were performed automatically via this:
perl -0x0 -pi -e \
's/\w+( ?)\(([\w>-]+), *(?:(?:VIR_FROM_NONE|domcode|vm|dom|net|NULL),
?){0,3}VIR_ERR_NO_MEMORY,.*?\);/virReportOOMError$1($2);/sg' \
$(g grep -l VIR_ERR_NO_MEMORY|grep '\.c$'|grep -vF virterror.c)
Exceptions:
======================
Exceptions (as noted in ChangeLog) were to add the now-required
definitions of VIR_FROM_THIS, as needed, e.g.,
#define VIR_FROM_THIS VIR_FROM_OPENVZ
in openvz-related files.
Also, I replaced uses of qparam_report_oom automatically:
perl -pi -e 's/qparam_report_oom\(\);/virReportOOMError(NULL);/' \
src/qparams.c
and removed the definition of that macro manually.
I spotted and manually adjusted one misuse of VIR_ERR_NO_MEMORY:
remote_internal.c: fix typo that would mistakenly report OOM
* src/remote_internal.c (addrToString): Report VIR_ERR_UNKNOWN_HOST,
not VIR_ERR_NO_MEMORY.
ctxt in src/conf.c is not usable:
perl -pi -e 's/virReportOOMError\(ctxt\);/virReportOOMError(NULL);/' \
src/conf.c
I manually converted two uses of virSexprError(VIR_ERR_NO_MEMORY in
src/sexpr.c.
And of course, copyright dates were updated via an emacs write hook.
The first iteration involved applying the perl-based xforms
more of less file by file, and making sure everything still compiled.
Once done, I repeated the process on a new branch, automating as much
as possible, and then diff'd the branches. The diff was nearly empty,
modulo copyright dates and added VIR_FROM_THIS definitions.
I'm posting two small sort-of-different changes here.
I'll post this big first one separately.
From 099536470ae2cbe9503ed471d391e403fb2587a4 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Tue, 27 Jan 2009 12:20:06 +0100
Subject: [PATCH 1/3] error-reporting calls using VIR_ERR_NO_MEMORY: use virReportOOMError
instead
* src/uml_conf.c (VIR_FROM_THIS): Define to VIR_FROM_UML.
* src/xs_internal.c (VIR_FROM_THIS): Define to VIR_FROM_XEN.
* src/xml.c (VIR_FROM_THIS): Define to VIR_FROM_XML.
* src/stats_linux.c (VIR_FROM_THIS): Define to VIR_FROM_STATS_LINUX.
* src/datatypes.c (VIR_FROM_THIS): Define to VIR_FROM_NONE.
* src/lxc_conf.c (VIR_FROM_THIS): Define to VIR_FROM_LXC.
* src/libvirt.c (VIR_FROM_THIS): Define to VIR_FROM_NONE.
* src/node_device_conf.c (VIR_FROM_THIS): Define to VIR_FROM_NODEDEV.
* src/openvz_conf.c (VIR_FROM_THIS): Define to VIR_FROM_OPENVZ.
* src/openvz_driver.c (VIR_FROM_THIS): Define to VIR_FROM_OPENVZ.
* src/conf.c (VIR_FROM_THIS): Define to VIR_FROM_CONF.
Note: this loses config_filename:config_lineno diagnostics,
but that's ok.
* src/node_device.c (VIR_FROM_THIS): Define to VIR_FROM_NODEDEV.
* src/sexpr.c (VIR_FROM_THIS): Define to VIR_FROM_SEXPR.
---
...
From a223b8f6064e867d304df9a0a1498ef2940631ef Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Tue, 27 Jan 2009 15:58:07 +0100
Subject: [PATCH 2/3] qparams.c: Use virReportOOMError(NULL), not qparam_report_oom()
* src/qparams.c (VIR_FROM_THIS): Define to VIR_FROM_NONE.
(qparam_report_oom): Remove definition.
Replace all uses.
---
src/qparams.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/qparams.c b/src/qparams.c
index 22c5853..d0a84b3 100644
--- a/src/qparams.c
+++ b/src/qparams.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007 Red Hat, Inc.
+/* Copyright (C) 2007, 2009 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
@@ -33,9 +33,7 @@
#include "memory.h"
#include "qparams.h"
-#define qparam_report_oom(void) \
- virReportErrorHelper(NULL, VIR_FROM_NONE, VIR_ERR_NO_MEMORY, \
- __FILE__, __FUNCTION__, __LINE__, NULL)
+#define VIR_FROM_THIS VIR_FROM_NONE
struct qparam_set *
new_qparam_set (int init_alloc, ...)
@@ -47,14 +45,14 @@ new_qparam_set (int init_alloc, ...)
if (init_alloc <= 0) init_alloc = 1;
if (VIR_ALLOC(ps) < 0) {
- qparam_report_oom();
+ virReportOOMError(NULL);
return NULL;
}
ps->n = 0;
ps->alloc = init_alloc;
if (VIR_ALLOC_N(ps->p, ps->alloc) < 0) {
VIR_FREE (ps);
- qparam_report_oom();
+ virReportOOMError(NULL);
return NULL;
}
@@ -98,7 +96,7 @@ grow_qparam_set (struct qparam_set *ps)
{
if (ps->n >= ps->alloc) {
if (VIR_REALLOC_N(ps->p, ps->alloc * 2) < 0) {
- qparam_report_oom();
+ virReportOOMError(NULL);
return -1;
}
ps->alloc *= 2;
@@ -115,14 +113,14 @@ append_qparam (struct qparam_set *ps,
pname = strdup (name);
if (!pname) {
- qparam_report_oom();
+ virReportOOMError(NULL);
return -1;
}
pvalue = strdup (value);
if (!pvalue) {
VIR_FREE (pname);
- qparam_report_oom();
+ virReportOOMError(NULL);
return -1;
}
@@ -156,7 +154,7 @@ qparam_get_query (const struct qparam_set *ps)
}
if (virBufferError(&buf)) {
- qparam_report_oom();
+ virReportOOMError(NULL);
return NULL;
}
@@ -184,7 +182,7 @@ qparam_query_parse (const char *query)
ps = new_qparam_set (0, NULL);
if (!ps) {
- qparam_report_oom();
+ virReportOOMError(NULL);
return NULL;
}
@@ -257,7 +255,7 @@ qparam_query_parse (const char *query)
return ps;
out_of_memory:
- qparam_report_oom();
+ virReportOOMError(NULL);
free_qparam_set (ps);
return NULL;
}
--
1.6.1.1.363.g2a3bd
From dd9477353e930ba75dea1e06ccbced5b1cb61e09 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Tue, 27 Jan 2009 15:53:27 +0100
Subject: [PATCH 3/3] remote_internal.c: fix typo that would mistakenly report OOM
* src/remote_internal.c (addrToString): Report VIR_ERR_UNKNOWN_HOST,
not VIR_ERR_NO_MEMORY.
---
src/remote_internal.c | 11 +++++------
1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/remote_internal.c b/src/remote_internal.c
index 8ed52bc..5c2e705 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -2,7 +2,7 @@
* remote_internal.c: driver to provide access to libvirtd running
* on a remote machine
*
- * Copyright (C) 2007-2008 Red Hat, Inc.
+ * Copyright (C) 2007-2009 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
@@ -4949,10 +4949,10 @@ static char *addrToString(struct sockaddr_storage *sa, socklen_t
salen)
port, sizeof(port),
NI_NUMERICHOST | NI_NUMERICSERV)) != 0) {
virRaiseError (NULL, NULL, NULL, VIR_FROM_REMOTE,
- VIR_ERR_NO_MEMORY, VIR_ERR_ERROR,
- NULL, NULL, NULL, 0, 0,
- _("Cannot resolve address %d: %s"),
- err, gai_strerror(err));
+ VIR_ERR_UNKNOWN_HOST, VIR_ERR_ERROR,
+ NULL, NULL, NULL, 0, 0,
+ _("Cannot resolve address %d: %s"),
+ err, gai_strerror(err));
return NULL;
}
@@ -6836,4 +6836,3 @@ remoteRegister (void)
return 0;
}
-
--
1.6.1.1.363.g2a3bd