[libvirt] [PATCH] deprecate fclose() and introduce VIR_{FORCE_}FCLOSE()
by Stefan Berger
Similarly to deprecating close(), I am now deprecating fclose() and
introduce VIR_FORCE_FCLOSE() and VIR_FCLOSE().
Most of the files are opened in read-only mode, so usage of
VIR_FORCE_CLOSE() seemed appropriate. Others that are opened in write
mode already had the fclose() < 0 check and I converted those to
VIR_FCLOSE() < 0.
I did not find occurences of possible double-closed files on the way.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
HACKING | 22 ++++++++++++++++------
daemon/libvirtd.c | 4 ++--
docs/hacking.html.in | 20 +++++++++++++++-----
src/libvirt_private.syms | 1 +
src/nodeinfo.c | 8 ++++----
src/openvz/openvz_conf.c | 8 ++++----
src/openvz/openvz_driver.c | 4 ++--
src/qemu/qemu_driver.c | 4 ++--
src/storage/storage_backend.c | 6 ++----
src/storage/storage_backend_fs.c | 4 ++--
src/storage/storage_backend_iscsi.c | 7 ++-----
src/storage/storage_backend_scsi.c | 2 +-
src/uml/uml_driver.c | 8 ++++----
src/util/cgroup.c | 10 +++++-----
src/util/dnsmasq.c | 5 +++--
src/util/files.c | 18 ++++++++++++++++++
src/util/files.h | 4 ++++
src/util/macvtap.c | 4 ++--
src/util/util.c | 8 +++-----
src/xen/xen_driver.c | 3 ++-
src/xen/xen_hypervisor.c | 8 +++-----
tests/nodeinfotest.c | 5 +++--
tests/testutils.c | 8 ++++----
tests/xencapstest.c | 7 +++----
24 files changed, 107 insertions(+), 71 deletions(-)
Index: libvirt-acl/src/util/files.c
===================================================================
--- libvirt-acl.orig/src/util/files.c
+++ libvirt-acl/src/util/files.c
@@ -44,3 +44,21 @@ int virClose(int *fdptr, bool preserve_e
return rc;
}
+
+
+int virFClose(FILE **file, bool preserve_errno)
+{
+ int saved_errno;
+ int rc = 0;
+
+ if (*file) {
+ if (preserve_errno)
+ saved_errno = errno;
+ rc = fclose(*file);
+ *file = NULL;
+ if (preserve_errno)
+ errno = saved_errno;
+ }
+
+ return rc;
+}
Index: libvirt-acl/src/util/files.h
===================================================================
--- libvirt-acl.orig/src/util/files.h
+++ libvirt-acl/src/util/files.h
@@ -27,6 +27,7 @@
# define __VIR_FILES_H_
# include <stdbool.h>
+# include <stdio.h>
# include "internal.h"
# include "ignore-value.h"
@@ -34,13 +35,16 @@
/* Don't call this directly - use the macros below */
int virClose(int *fdptr, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
+int virFClose(FILE **file, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
/* For use on normal paths; caller must check return value,
and failure sets errno per close(). */
# define VIR_CLOSE(FD) virClose(&(FD), false)
+# define VIR_FCLOSE(FILE) virFClose(&(FILE), false)
/* For use on cleanup paths; errno is unaffected by close,
and no return value to worry about. */
# define VIR_FORCE_CLOSE(FD) ignore_value(virClose(&(FD), true))
+# define VIR_FORCE_FCLOSE(FILE) ignore_value(virFClose(&(FILE), true))
#endif /* __VIR_FILES_H */
Index: libvirt-acl/src/libvirt_private.syms
===================================================================
--- libvirt-acl.orig/src/libvirt_private.syms
+++ libvirt-acl/src/libvirt_private.syms
@@ -344,6 +344,7 @@ virFDStreamCreateFile;
# files.h
virClose;
+virFClose;
# hash.h
Index: libvirt-acl/daemon/libvirtd.c
===================================================================
--- libvirt-acl.orig/daemon/libvirtd.c
+++ libvirt-acl/daemon/libvirtd.c
@@ -522,11 +522,11 @@ static int qemudWritePidFile(const char
if (fprintf(fh, "%lu\n", (unsigned long)getpid()) < 0) {
VIR_ERROR(_("%s: Failed to write to pid file '%s' : %s"),
argv0, pidFile, virStrerror(errno, ebuf, sizeof ebuf));
- fclose(fh);
+ VIR_FORCE_FCLOSE(fh);
return -1;
}
- if (fclose(fh) == EOF) {
+ if (VIR_FCLOSE(fh) == EOF) {
VIR_ERROR(_("%s: Failed to close pid file '%s' : %s"),
argv0, pidFile, virStrerror(errno, ebuf, sizeof ebuf));
return -1;
Index: libvirt-acl/src/nodeinfo.c
===================================================================
--- libvirt-acl.orig/src/nodeinfo.c
+++ libvirt-acl/src/nodeinfo.c
@@ -46,6 +46,7 @@
#include "virterror_internal.h"
#include "count-one-bits.h"
#include "intprops.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_NONE
@@ -102,8 +103,7 @@ get_cpu_value(unsigned int cpu, const ch
}
cleanup:
- if (pathfp)
- fclose(pathfp);
+ VIR_FORCE_FCLOSE(pathfp);
VIR_FREE(path);
return value;
@@ -155,7 +155,7 @@ static unsigned long count_thread_siblin
}
cleanup:
- fclose(pathfp);
+ VIR_FORCE_FCLOSE(pathfp);
VIR_FREE(path);
return ret;
@@ -329,7 +329,7 @@ int nodeGetInfo(virConnectPtr conn ATTRI
return -1;
}
ret = linuxNodeInfoCPUPopulate(cpuinfo, nodeinfo);
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
if (ret < 0)
return -1;
Index: libvirt-acl/src/openvz/openvz_conf.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_conf.c
+++ libvirt-acl/src/openvz/openvz_conf.c
@@ -528,7 +528,7 @@ int openvzLoadDomains(struct openvz_driv
dom = NULL;
}
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return 0;
@@ -536,7 +536,7 @@ int openvzLoadDomains(struct openvz_driv
virReportOOMError();
cleanup:
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (dom)
virDomainObjUnref(dom);
return -1;
@@ -909,7 +909,7 @@ openvzSetDefinedUUID(int vpsid, unsigned
/* Record failure if fprintf or fclose fails,
and be careful always to close the stream. */
if ((fprintf(fp, "\n#UUID: %s\n", uuidstr) < 0)
- + (fclose(fp) == EOF))
+ + (VIR_FCLOSE(fp) == EOF))
goto cleanup;
}
@@ -996,7 +996,7 @@ int openvzGetVEID(const char *name) {
}
ok = fscanf(fp, "%d\n", &veid ) == 1;
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (ok && veid >= 0)
return veid;
Index: libvirt-acl/src/openvz/openvz_driver.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_driver.c
+++ libvirt-acl/src/openvz/openvz_driver.c
@@ -154,7 +154,7 @@ openvzDomainDefineCmd(const char *args[]
max_veid = veid;
}
}
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (max_veid == 0) {
max_veid = 100;
@@ -189,7 +189,7 @@ no_memory:
return -1;
cleanup:
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
#undef ADD_ARG
Index: libvirt-acl/src/qemu/qemu_driver.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_driver.c
+++ libvirt-acl/src/qemu/qemu_driver.c
@@ -4588,7 +4588,7 @@ static int qemudGetProcessInfo(unsigned
/* startstack -> processor */
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*d %d",
&usertime, &systime, &cpu) != 3) {
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
VIR_WARN0("cannot parse process status data");
errno = -EINVAL;
return -1;
@@ -4608,7 +4608,7 @@ static int qemudGetProcessInfo(unsigned
VIR_DEBUG("Got status for %d/%d user=%llu sys=%llu cpu=%d",
pid, tid, usertime, systime, cpu);
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return 0;
}
Index: libvirt-acl/src/storage/storage_backend.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend.c
+++ libvirt-acl/src/storage/storage_backend.c
@@ -1458,10 +1458,8 @@ virStorageBackendRunProgRegex(virStorage
VIR_FREE(reg);
- if (list)
- fclose(list);
- else
- VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(list);
+ VIR_FORCE_CLOSE(fd);
while ((err = waitpid(child, &exitstatus, 0) == -1) && errno == EINTR);
Index: libvirt-acl/src/storage/storage_backend_fs.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_fs.c
+++ libvirt-acl/src/storage/storage_backend_fs.c
@@ -284,12 +284,12 @@ virStorageBackendFileSystemIsMounted(vir
while ((getmntent_r(mtab, &ent, buf, sizeof(buf))) != NULL) {
if (STREQ(ent.mnt_dir, pool->def->target.path)) {
- fclose(mtab);
+ VIR_FORCE_FCLOSE(mtab);
return 1;
}
}
- fclose(mtab);
+ VIR_FORCE_FCLOSE(mtab);
return 0;
}
Index: libvirt-acl/src/storage/storage_backend_iscsi.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_iscsi.c
+++ libvirt-acl/src/storage/storage_backend_iscsi.c
@@ -235,11 +235,8 @@ out:
}
VIR_FREE(line);
- if (fp != NULL) {
- fclose(fp);
- } else {
- VIR_FORCE_CLOSE(fd);
- }
+ VIR_FORCE_FCLOSE(fp);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/storage/storage_backend_scsi.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_scsi.c
+++ libvirt-acl/src/storage/storage_backend_scsi.c
@@ -70,7 +70,7 @@ getDeviceType(uint32_t host,
}
gottype = fgets(typestr, 3, typefile);
- fclose(typefile);
+ VIR_FORCE_FCLOSE(typefile);
if (gottype == NULL) {
virReportSystemError(errno,
Index: libvirt-acl/src/uml/uml_driver.c
===================================================================
--- libvirt-acl.orig/src/uml/uml_driver.c
+++ libvirt-acl/src/uml/uml_driver.c
@@ -587,11 +587,11 @@ reopen:
if (fscanf(file, "%d", &vm->pid) != 1) {
errno = EINVAL;
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
goto cleanup;
}
- if (fclose(file) < 0)
+ if (VIR_FCLOSE(file) < 0)
goto cleanup;
rc = 0;
@@ -1096,7 +1096,7 @@ static int umlGetProcessInfo(unsigned lo
if (fscanf(pidinfo, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu", &usertime, &systime) != 2) {
umlDebug("not enough arg");
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return -1;
}
@@ -1109,7 +1109,7 @@ static int umlGetProcessInfo(unsigned lo
umlDebug("Got %llu %llu %llu", usertime, systime, *cpuTime);
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return 0;
}
Index: libvirt-acl/src/util/cgroup.c
===================================================================
--- libvirt-acl.orig/src/util/cgroup.c
+++ libvirt-acl/src/util/cgroup.c
@@ -31,6 +31,7 @@
#include "memory.h"
#include "cgroup.h"
#include "logging.h"
+#include "files.h"
#define CGROUP_MAX_VAL 512
@@ -127,13 +128,12 @@ static int virCgroupDetectMounts(virCgro
}
}
- fclose(mounts);
+ VIR_FORCE_FCLOSE(mounts);
return 0;
no_memory:
- if (mounts)
- fclose(mounts);
+ VIR_FORCE_FCLOSE(mounts);
return -ENOMEM;
}
@@ -192,12 +192,12 @@ static int virCgroupDetectPlacement(virC
}
}
- fclose(mapping);
+ VIR_FORCE_FCLOSE(mapping);
return 0;
no_memory:
- fclose(mapping);
+ VIR_FORCE_FCLOSE(mapping);
return -ENOMEM;
}
Index: libvirt-acl/src/util/dnsmasq.c
===================================================================
--- libvirt-acl.orig/src/util/dnsmasq.c
+++ libvirt-acl/src/util/dnsmasq.c
@@ -44,6 +44,7 @@
#include "memory.h"
#include "virterror_internal.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_NETWORK
#define DNSMASQ_HOSTSFILE_SUFFIX "hostsfile"
@@ -171,7 +172,7 @@ hostsfileWrite(const char *path,
for (i = 0; i < nhosts; i++) {
if (fputs(hosts[i].host, f) == EOF || fputc('\n', f) == EOF) {
rc = errno;
- fclose(f);
+ VIR_FORCE_FCLOSE(f);
if (istmp)
unlink(tmp);
@@ -180,7 +181,7 @@ hostsfileWrite(const char *path,
}
}
- if (fclose(f) == EOF) {
+ if (VIR_FCLOSE(f) == EOF) {
rc = errno;
goto cleanup;
}
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -436,11 +436,11 @@ int openTap(const char *ifname,
virReportSystemError(errno,
"%s",_("cannot determine macvtap's tap device "
"interface index"));
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
return -1;
}
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
if (snprintf(tapname, sizeof(tapname),
"/dev/tap%d", ifindex) >= sizeof(tapname)) {
Index: libvirt-acl/src/util/util.c
===================================================================
--- libvirt-acl.orig/src/util/util.c
+++ libvirt-acl/src/util/util.c
@@ -1830,10 +1830,8 @@ int virFileWritePidPath(const char *pidf
rc = 0;
cleanup:
- if (file &&
- fclose(file) < 0) {
+ if (VIR_FCLOSE(file) < 0)
rc = errno;
- }
return rc;
}
@@ -1864,11 +1862,11 @@ int virFileReadPid(const char *dir,
if (fscanf(file, "%d", pid) != 1) {
rc = EINVAL;
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
goto cleanup;
}
- if (fclose(file) < 0) {
+ if (VIR_FCLOSE(file) < 0) {
rc = errno;
goto cleanup;
}
Index: libvirt-acl/src/xen/xen_driver.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_driver.c
+++ libvirt-acl/src/xen/xen_driver.c
@@ -47,6 +47,7 @@
#include "pci.h"
#include "uuid.h"
#include "fdstream.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_XEN
@@ -219,7 +220,7 @@ xenUnifiedProbe (void)
FILE *fh;
if (fh = fopen("/dev/xen/domcaps", "r")) {
- fclose(fh);
+ VIR_FORCE_FCLOSE(fh);
return 1;
}
#endif
Index: libvirt-acl/src/xen/xen_hypervisor.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_hypervisor.c
+++ libvirt-acl/src/xen/xen_hypervisor.c
@@ -2641,7 +2641,7 @@ xenHypervisorMakeCapabilities(virConnect
capabilities = fopen ("/sys/hypervisor/properties/capabilities", "r");
if (capabilities == NULL) {
if (errno != ENOENT) {
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
virReportSystemError(errno,
_("cannot read file %s"),
"/sys/hypervisor/properties/capabilities");
@@ -2654,10 +2654,8 @@ xenHypervisorMakeCapabilities(virConnect
cpuinfo,
capabilities);
- if (cpuinfo)
- fclose(cpuinfo);
- if (capabilities)
- fclose(capabilities);
+ VIR_FORCE_FCLOSE(cpuinfo);
+ VIR_FORCE_FCLOSE(capabilities);
return caps;
#endif /* __sun */
Index: libvirt-acl/tests/nodeinfotest.c
===================================================================
--- libvirt-acl.orig/tests/nodeinfotest.c
+++ libvirt-acl/tests/nodeinfotest.c
@@ -9,6 +9,7 @@
#include "internal.h"
#include "nodeinfo.h"
#include "util.h"
+#include "files.h"
#ifndef __linux__
@@ -49,10 +50,10 @@ static int linuxTestCompareFiles(const c
fprintf(stderr, "\n%s\n", error->message);
virFreeError(error);
}
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
return -1;
}
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
/* 'nodes' is filled using libnuma.so from current machine
* topology, which makes it unsuitable for the test suite
Index: libvirt-acl/tests/testutils.c
===================================================================
--- libvirt-acl.orig/tests/testutils.c
+++ libvirt-acl/tests/testutils.c
@@ -180,26 +180,26 @@ int virtTestLoadFile(const char *file,
if (fstat(fileno(fp), &st) < 0) {
fprintf (stderr, "%s: failed to fstat: %s\n", file, strerror(errno));
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
if (st.st_size > (buflen-1)) {
fprintf (stderr, "%s: larger than buffer (> %d)\n", file, buflen-1);
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
if (st.st_size) {
if (fread(*buf, st.st_size, 1, fp) != 1) {
fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno));
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
}
(*buf)[st.st_size] = '\0';
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return st.st_size;
}
Index: libvirt-acl/tests/xencapstest.c
===================================================================
--- libvirt-acl.orig/tests/xencapstest.c
+++ libvirt-acl/tests/xencapstest.c
@@ -9,6 +9,7 @@
#include "xml.h"
#include "testutils.h"
#include "xen/xen_hypervisor.h"
+#include "files.h"
static char *progname;
static char *abs_srcdir;
@@ -63,10 +64,8 @@ static int testCompareFiles(const char *
fail:
free(actualxml);
- if (fp1)
- fclose(fp1);
- if (fp2)
- fclose(fp2);
+ VIR_FORCE_FCLOSE(fp1);
+ VIR_FORCE_FCLOSE(fp2);
virCapabilitiesFree(caps);
return ret;
Index: libvirt-acl/HACKING
===================================================================
--- libvirt-acl.orig/HACKING
+++ libvirt-acl/HACKING
@@ -321,20 +321,30 @@ routines, use the macros from memory.h
File handling
=============
-Use of the close() API is deprecated in libvirt code base to help avoiding
-double-closing of a file descriptor. Instead of this API, use the macro from
-files.h
+Usage of the close() and fclose() APIs is deprecated in libvirt code base to help
+avoiding double-closing of files or file descriptors, which is particulary
+dangerous in multi-threaded applications. Instead of these APIs, use the
+macros from files.h
- eg close a file descriptor
if (VIR_CLOSE(fd) < 0) {
- virReportSystemError(errno, _("failed to close file"));
+ virReportSystemError(errno, "%s", _("failed to close file"));
}
- - eg close a file descriptor in an error path, without losing the previous
- errno value
+ - eg close a file
+
+ if (VIR_FCLOSE(file) < 0) {
+ virReportSystemError(errno, "%s", _("failed to close file"));
+ }
+
+ - eg close a file or file descriptor in an error path, without losing the
+ previous errno value
VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(file);
+
+
String comparisons
==================
Index: libvirt-acl/docs/hacking.html.in
===================================================================
--- libvirt-acl.orig/docs/hacking.html.in
+++ libvirt-acl/docs/hacking.html.in
@@ -392,9 +392,10 @@
<h2><a name="file_handling">File handling</a></h2>
<p>
- Use of the close() API is deprecated in libvirt code base to help
- avoiding double-closing of a file descriptor. Instead of this API,
- use the macro from files.h
+ Usage of the close() and fclose() APIs is deprecated in libvirt code base to help
+ avoiding double-closing of files or file descriptors, which is particulary
+ dangerous in a multi-threaded applications. Instead of these APIs, use the
+ macros from files.h
</p>
<ul>
@@ -402,15 +403,24 @@
<pre>
if (VIR_CLOSE(fd) < 0) {
- virReportSystemError(errno, _("failed to close file"));
+ virReportSystemError(errno, "%s", _("failed to close file"));
}
</pre></li>
- <li><p>eg close a file descriptor in an error path, without losing
+ <li><p>eg close a file</p>
+
+<pre>
+ if (VIR_FCLOSE(file) < 0) {
+ virReportSystemError(errno, "%s", _("failed to close file"));
+ }
+</pre></li>
+
+ <li><p>eg close a file or file descriptor in an error path, without losing
the previous errno value</p>
<pre>
VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(file);
</pre></li>
</ul>
14 years
[libvirt] [PATCH] phyp: Don't do a flags check in the storage driver
by Matthias Bolte
This makes the storage driver fail when the connection is
opened with the VIR_CONNECT_RO flag, resulting in a read-only
connection with no storage driver.
---
src/phyp/phyp_driver.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index a685bd1..4c723a2 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -3927,10 +3927,8 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus)
static virDrvOpenStatus
phypVIOSDriverOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
- int flags)
+ int flags ATTRIBUTE_UNUSED)
{
- virCheckFlags(0, VIR_DRV_OPEN_ERROR);
-
if (conn->driver->no != VIR_DRV_PHYP)
return VIR_DRV_OPEN_DECLINED;
--
1.7.0.4
14 years
[libvirt] New save/restore api proposal
by Jean-Baptiste Rouault
Hello all,
I'd like to add support for save and restore to the OpenVZ and VirtualBox
drivers because I have to support these operations in the application I'm
working on.
However, the save/restore API in its current state doesn't fit well to our
needs. The main problem is that the domain definition is included inside the
save file. This is problematic because between the save and the restore
operations, the names of the network interfaces on the host side are likely to
have changed and we can't modify them before restoring the domain.
To summarize, what we would like to be able to do is:
- save a domain and undefine it
- update the domain definition to use the new names of host side interfaces
- restore the domain
This is why I would like to add two new functions with the following
signatures (better names are probably needed):
int virDomainSaveState(virDomainPtr domain, const char *to);
int virDomainRestoreState(virDomainPtr domain, const char *from);
The first one would do the same as virDomainSave but without prepending the
domain's definition to the save file.
The other function would be able to restore a domain saved by the first one.
What do you think ?
Regards,
Jean-Baptiste
14 years
[libvirt] [PATCH] rpm: Fix summary wording
by Cole Robinson
---
libvirt.spec.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index f77626e..9a64fda 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -186,7 +186,7 @@
%endif
-Summary: Library providing a simple API virtualization
+Summary: Library providing a simple virtualization API
Name: libvirt
Version: @VERSION@
Release: 1%{?dist}%{?extra_release}
--
1.7.3.2
14 years
[libvirt] Release of libvirt-0.8.5
by Daniel Veillard
So the release it out ! And hopefully we are back on our 'end of month'
release cycle. The libvirt-0.8.5 release is available from
ftp://libvirt.org/libvirt/
So we have a number of features in this new release, I will also note
the rather large mount of documentation fixes (thanks Justin and others!)
and portability. Hopefully this will help people to use libvirt in a
veriety of context !
Features:
- Enable JSON and netdev features in QEMU >= 0.13 (Daniel P. Berrange)
- framework for auditing integration (Daniel P. Berrange)
- framework for DTrace/SystemTap integration (Daniel P. Berrange)
- Setting the number of vcpu at boot (Eric Blake)
- Enable support for nested SVM (Daniel P. Berrange)
- Virtio plan9fs filesystem QEMU (Daniel P. Berrange)
- Memory parameter controls (Nikunj A. Dadhania)
- portability to OS-X (Justin Clift)
Documentation:
- virsh: improve the help description for managedsave and start (Justin Clift)
- docs: updated the C# bindings page with arnauds latest changes (Justin Clift)
- docs: update ruby bindings maintainer to chris lalancette (Justin Clift)
- docs: reworded and reordered the bindings page, plus minor tweaks (Justin Clift)
- Fix xen API documentation (Philipp Hahn)
- docs: added a table of contents to the first 11 docs files (Justin Clift)
- docs: reformated the bindings page html markup to match other pages (Justin Clift)
- docs: revamp api_extension example, using vcpu patch series (Eric Blake)
- docs: install the generated html files when make install is run (Justin Clift)
- Fix documentation for virEventAddTimeout() (Philipp Hahn)
- esx: Add documentation about certificates and connection problems (Matthias Bolte)
- docs: added a table of contents to the new c sharp bindings page (Justin Clift)
- docs: removed old changelog file, as it is no longer relevant (Justin Clift)
- Update comments for the memory tunables macros (Nikunj A. Dadhania)
- docs: added initial page for c# binding, with links to it (Justin Clift)
- virsh: consolidate memtune docs (Eric Blake)
- Update docs for memory parameters and memtune command (Nikunj A. Dadhania)
- docs: document how to disable memballoon (Eric Blake)
- Update todo list file to point at bugzilla/website (Daniel P. Berrange)
- virsh: update comment about parsing (Eric Blake)
- virsh: document options in man page (Eric Blake)
- Fixes for documentation extraction (Daniel Veillard)
- Add automatic generation of a todo item page (Daniel P. Berrange)
- nwfilter: Add 2nd example to the html docs (Stefan Berger)
- nwfilter: Extend docs with info about the state attribute (Stefan Berger)
- vcpu: improve cpuset attribute (Eric Blake)
- nwfilter: Extend docs with information about comment attr. (Stefan Berger)
- docs: grammar cleanups on logging examples (Eric Blake)
- Fix spelling of Xen in comments (Philipp Hahn)
- docs: reworked the policykit patch submitted by Patrick Dignan (Justin Clift)
- docs: fix the xml validity errors regarding name and id (Justin Clift)
- docs: improve wording for the dev guide (Justin Clift)
- docs: add the app dev guide (Justin Clift)
Portability:
- mingw: Add body for virFork and remove double virDriverLoadModule export (Matthias Bolte)
- daemon: exclude requirement for probes.h on systems without systemtap (Justin Clift)
- build: skip xenapi driver when building for RHEL (Eric Blake)
- build: fix mingw build (Eric Blake)
- build: require pkg-config for bootstrap (Eric Blake)
- configure: disable network and storage-fs drivers on mac os x (Justin Clift)
- build: fix example build on MacOS X (Eric Blake)
- mpath: disable devmapper-multipath checking on non-linux (Justin Clift)
- mac os x: use awk selected by build system rather than first in path (Justin Clift)
- virtualbox: fix a typo in the expected location on mac os x (Justin Clift)
- nwfilter: Don't compile nwfilter driver on other systems than Linux (Stefan Berger)
- nwfilter: add a missing define, so libvirtd builds on macos x (Justin Clift)
- build: avoid non-portable IPv6 struct member, for MacOS X (Eric Blake)
- virsh: change wexitstatus order to allow compilation on mac osx (Justin Clift)
- build: use portable sed expressions (Eric Blake)
Bug Fixes:
- eliminate possibility of a double-closed file descriptor (Stefan Berger)
- qemu: check for vm after starting a job (Eric Blake)
- Only attempt removal of the rule allowing tftp if it was added (Laine Stump)
- qemu: don't use %.3d format for bus/addr of USB devices (Diego Elio Pettenò)
- virsh: fix range of memtune command (Eric Blake)
- qemu: work around dash 0.5.5 bug in managed save (Eric Blake)
- Avoid squashing errors during network startup cleanup path (Daniel P. Berrange)
- xen: Fix domain dump (Jiri Denemark)
- dnsmasq: avoid potential crash (Eric Blake)
- Fix netmask checks for IPv6 in virSocketCheckNetmask (Daniel P. Berrange)
- Don't fail lxc domain start when memory controller support is missing (Guido Günther)
- root_squash: virFileOperation may fail with EPERM too (Dan Kenigsberg)
- qemu: let qemu group look below /var/lib/libvirt/qemu/ (Dan Kenigsberg)
- qemu: Prohibit migration of guests with host devices (Jiri Denemark)
- cpu: Use vendor in baseline CPU only if all hosts use it (Jiri Denemark)
- cpu: Fix vendor for recent CPU models (Jiri Denemark)
- Fix Xen SEXPR generation to properly quote strings containing () (Daniel P. Berrange)
- nwfilter: resolve deadlock between VM ops and filter update (Stefan Berger)
- Don't fail on missing D-Bus (Guido Günther)
- cpu: Remove redundant features (Jiri Denemark)
- xen: Fix virDomain{At,De}tachDevice (Jiri Denemark)
- xen: xenXMDomain*DeviceFlags should obey all flags (Jiri Denemark)
- nwfilter: fix memory leaks (Stefan Berger)
- phyp: Checking for NULL values when building new guest (Eduardo Otubo)
- libvirt-guests: start late and stop early (Jiri Denemark)
- nwfilter bug appearing on big endian machines (Stefan Berger)
- Rebuild network filter for UML guests on updates (Soren Hansen)
Improvements:
- vbox: Stop hardcoding a single path for VBoxXPCOMC.so (Matthias Bolte)
- Add disk/net resource auditing to QEMU driver (Daniel P. Berrange)
- Add auditing of security label in QEMU driver (Daniel P. Berrange)
- Add auditing of start/stop events to the QEMU driver (Daniel P. Berrange)
- Add printf format attribute annotation to virAuditSend method (Daniel P. Berrange)
- Add audit helper for escaping log message strings (Daniel P. Berrange)
- virsh: use - not _ in memtune option names (Eric Blake)
- build: fix shell detection bug (Eric Blake)
- virsh: improve help text where integers are expected (Eric Blake)
- docs: make the location of the xml catalog file a configure option (Justin Clift)
- Fix build for SystemTap 1.0 (Matthias Bolte)
- Fix formatting of network address in iptables helpers (Daniel P. Berrange)
- virsh: Add option 'model' for attach-interface (Osier Yang)
- qemu: Fix detection of drive readonly option (Jiri Denemark)
- vbox: Fix compile errors due to the virSocketAddr series (Matthias Bolte)
- Don't try to parse a NULL ip address for boot server (Daniel P. Berrange)
- Convert virNetwork to use virSocketAddr everywhere (Daniel P. Berrange)
- Include socket address in client probe data (Daniel P. Berrange)
- Add dtrace static probes in libvirtd (Daniel P. Berrange)
- Add test suite for virSocket APIs (Daniel P. Berrange)
- Ban use of all inet_* functions (Daniel P. Berrange)
- Fix error reporting for virSocketParse (Daniel P. Berrange)
- Expand virSocketFormat to be more flexible (Daniel P. Berrange)
- Fix passing of address family to virSocketParseAddr (Daniel P. Berrange)
- Include length with virSocketAddr data (Daniel P. Berrange)
- audit: simplify declaration (Eric Blake)
- qemu: Exit on first error in qemuDomainGetMemoryParameters (Matthias Bolte)
- virsh: Don't read nparams when virDomainGetMemoryParameters fails (Matthias Bolte)
- Fix formatting of the memtune XML element (Matthias Bolte)
- Add process= support for 'qemu-kvm -name' (John Morrissey)
- nwfilter: avoid dir. enforcement for certain types of rules (Stefan Berger)
- Audit SELinux label assignment. (Miloslav Trmač)
- Audit VM start/stop/suspend/resume (Miloslav Trmač)
- vcpu: remove dead xen code (Eric Blake)
- vcpu: improve support for setting xen vcpu counts (Eric Blake)
- vcpu: improve support for getting xen vcpu counts (Eric Blake)
- vcpu: improve vcpu support in xen command line (Eric Blake)
- vcpu: complete vcpu support in qemu driver (Eric Blake)
- vcpu: improve vcpu support in qemu command line (Eric Blake)
- vcpu: support all flags in test driver (Eric Blake)
- vcpu: add virsh support (Eric Blake)
- vcpu: support maxvcpu in domain_conf (Eric Blake)
- vcpu: make old API trivially wrap to new API (Eric Blake)
- vcpu: implement the remote protocol (Eric Blake)
- vcpu: implement the public APIs (Eric Blake)
- vcpu: define internal driver API (Eric Blake)
- vcpu: add new public API (Eric Blake)
- nwfilter: changes to rules in VM->host table (Stefan Berger)
- esx: Handle non-UTF-8 encoded VMX files (Matthias Bolte)
- Run initgroups() in qemudOpenAsUID() (Dan Kenigsberg)
- memtune: Add min_guarantee to the virsh memtune command (Nikunj A. Dadhania)
- esx: Fix check in esxDomainGetInfo's perf metric handling (Matthias Bolte)
- virsh: add tests for recent cli improvements (Eric Blake)
- virsh: new echo command (Eric Blake)
- virsh: add support for accepting arbitrary argv (Eric Blake)
- esx: Explictly declare VMX file content as UTF-8 (Matthias Bolte)
- esx: Handle name escaping properly (Matthias Bolte)
- nwfilter: prevent filters with different name but same UUID (Stefan Berger)
- new attribute accessmode to filesystem element (Harsh Prateek Bora)
- nwfilter: cut off connections after changing filters (Stefan Berger)
- build: provide URL in 'configure --help' (Eric Blake)
- tests: Honor LIBVIRT_{DEBUG,LOG_*} variables (Jiri Denemark)
- tests: Do not override LIBVIRT_DEBUG variable (Jiri Denemark)
- Improve error reporting in test suites (Daniel P. Berrange)
- virsh: move code into topological order (Eric Blake)
- virsh: simplify top-level option parsing (Eric Blake)
- virsh: add -- support (Lai Jiangshan)
- virsh: support single quote (Lai Jiangshan)
- virsh: add escaper \ for command string parsing (Lai Jiangshan)
- virsh: rework command parsing (Lai Jiangshan)
- virsh: add vshCommandParser abstraction (Lai Jiangshan)
- virsh: better handling the boolean option (Lai Jiangshan)
- virsh: allow zero length arguments (Lai Jiangshan)
- virsh: better support double quote (Lai Jiangshan)
- Add todo.pl and config example to EXTRA_DIST (Daniel P. Berrange)
- Fix several minor problems introduced by the memtune series (Matthias Bolte)
- Remote protocol implementation of virDomainSet/GetMemoryParameters (Nikunj A. Dadhania)
- Adding memtune command to virsh tool (Nikunj A. Dadhania)
- Implement domainGetMemoryParamters for LXC (Nikunj A. Dadhania)
- Implement domainSetMemoryParamters for LXC (Nikunj A. Dadhania)
- Adding memtunables to libvirt-lxc command (Nikunj A. Dadhania)
- Adding memtunables to qemuSetupCgroup (Nikunj A. Dadhania)
- Implement domainGetMemoryParamters for QEmu (Nikunj A. Dadhania)
- Implement domainSetMemoryParamters for QEmu (Nikunj A. Dadhania)
- Implement cgroup memory controller tunables (Nikunj A. Dadhania)
- XML parsing for memory tunables (Nikunj A. Dadhania)
- Adds xml entries for memory tunables in domain schema (Nikunj A. Dadhania)
- Adding structure and defines for virDomainSet/GetMemoryParameters (Nikunj A. Dadhania)
- Set sensible defaults for cpu match and feature policy (Daniel P. Berrange)
- xen: Fix logic bug in xenDaemon*DeviceFlags (Jiri Denemark)
- xen: Make xenDaemon*DeviceFlags errors less confusing (Jiri Denemark)
- Return a suitable error message if we can't find a matching emulator (Guido Günther)
- Pass -n to ip(6)tables (Guido Günther)
- nwfilter: Extend schema to accept state attribute (Stefan Berger)
- nwfilter: Add test case for testing the state attribute (Stefan Berger)
- nwfilter: Instantiate state match in ip(6)tables rules (Stefan Berger)
- nwfilter: Extend XML parser and gen. to support state attr. (Stefan Berger)
- xen: Fix bogus error when attaching a device (Jiri Denemark)
- esx: Add support for virtual serial device network backing (Matthias Bolte)
- phyp: Verify that domain XML contains at least one disk element (Matthias Bolte)
- implement usb and pci hot attach in AppArmor driver (Jamie Strandboge)
- nwfilter: Add a test case for testing the comment attribute (Stefan Berger)
- nwfilter: Extend nwfilter schema to accept comment attrib. (Stefan Berger)
- nwfilter: Instantiate comments in ip(6)tables rules (Stefan Berger)
- nwfilter: Extend XML parser and generator w/ comment attribute (Stefan Berger)
- configure: tweak logic flow of virtport check (Justin Clift)
- Rework configure logic for virtualport support (Stefan Berger)
- nwfilter: report if ip(6)tables rules would not be active (Stefan Berger)
- app-armor: add 'rw' for appropriate devices (Jamie Strandboge)
- add extra tests to virt-aa-helper-test for new '-p' option (Jamie Strandboge)
- esx: Allow '-' in VMX entry names (Matthias Bolte)
- Make SASL work over UNIX domain sockets (Daniel P. Berrange)
- Refactor some daemon code to facilitate introduction of static probes (Daniel P. Berrange)
- nodeinfo: work when hot-plugging is disabled (Eric Blake)
- libvirtd: improve the error message displayed on tls client auth failure (Justin Clift)
- virsh: Use virBuffer for generating XML (Jiri Denemark)
Cleanups:
- audit: printf warning fix (KAMEZAWA Hiroyuki)
- build: use shorter file names for 'make dist' (Eric Blake)
- maint: fix syntax-check failure of previous patch (Eric Blake)
- maint: ignore new test executable (Eric Blake)
- tests: Silence qemuxml2argv test (Jiri Denemark)
- Remove all use of inet_pton and inet_ntop (Daniel P. Berrange)
- Remove both addrToString methods (Daniel P. Berrange)
- Remove pointless nwIPAddress struct & void *casts (Daniel P. Berrange)
- Remove useless code in error path of getnameinfo() (Daniel P. Berrange)
- maint: sort private sym lists (Eric Blake)
- Rename VIR_DOMAIN_SWAP_HARD_LIMIT to VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT (Matthias Bolte)
- Fix make check on RHEL-5 (Jiri Denemark)
- Don't let daemon-conf test fail when auditing is disabled (Matthias Bolte)
- Fix compile errors in remote.c and newly added audit code (Matthias Bolte)
- Fix symbol exports & remove duplicated libvirt_util.la linkage (Daniel P. Berrange)
- Fix statstest when driver modules are enabled (Daniel P. Berrange)
- build: avoid false positive syntax-check failure (Eric Blake)
- proxy: Fix undefined reference to virClose (Matthias Bolte)
- Introduce VIR_CLOSE to be used rather than close() (Stefan Berger)
- Fix warning about a non-literal format string in qemu_driver.c (Laine Stump)
- test: silence nwfilter test (Stefan Berger)
- tests: fix spurious test failure (Eric Blake)
- memory: fix remote protocol compilation (Eric Blake)
- virsh: poison raw allocation routines (Eric Blake)
- Avoid checking against strncpy in virsh.c (Daniel Veillard)
- Cleanup some tabs issues (Daniel Veillard)
- util: add missing export (Eric Blake)
- virt-aa-helper-test cleanups (Jamie Strandboge)
- python: drop unnecessary conn assignment (Dan Kenigsberg)
- pciFindStubDriver should return NULL on error (Chris Wright)
- tests: silence qemuargv2xmltest noise (Eric Blake)
- tests: clean up qemuargv2xmltest (Eric Blake)
- maint: silence warning from libtool (Eric Blake)
- tests: Fix preprocessor indentation (Jiri Denemark)
Thanks everybody who helped for this release !
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel(a)veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
14 years
[libvirt] [PATCH] deprecate fclose() and introduce VIR_{FORCE_}FCLOSE()
by Stefan Berger
Similarly to deprecating close(), I am now deprecating fclose() and
introduce VIR_FORCE_FCLOSE() and VIR_FCLOSE().
Most of the files are opened in read-only mode, so usage of
VIR_FORCE_CLOSE() seemed appropriate. Others that are opened in write
mode already had the fclose() < 0 check and I converted those to
VIR_FCLOSE() < 0.
I did not find occurences of possible double-closed files on the way.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
HACKING | 22 ++++++++++++++++------
daemon/libvirtd.c | 4 ++--
docs/hacking.html.in | 20 +++++++++++++++-----
src/libvirt_private.syms | 1 +
src/nodeinfo.c | 8 ++++----
src/openvz/openvz_conf.c | 8 ++++----
src/openvz/openvz_driver.c | 4 ++--
src/qemu/qemu_driver.c | 4 ++--
src/storage/storage_backend.c | 6 ++----
src/storage/storage_backend_fs.c | 4 ++--
src/storage/storage_backend_iscsi.c | 7 ++-----
src/storage/storage_backend_scsi.c | 2 +-
src/uml/uml_driver.c | 8 ++++----
src/util/cgroup.c | 10 +++++-----
src/util/dnsmasq.c | 5 +++--
src/util/files.c | 18 ++++++++++++++++++
src/util/files.h | 4 ++++
src/util/macvtap.c | 4 ++--
src/util/util.c | 8 +++-----
src/xen/xen_driver.c | 3 ++-
src/xen/xen_hypervisor.c | 8 +++-----
tests/nodeinfotest.c | 5 +++--
tests/testutils.c | 8 ++++----
tests/xencapstest.c | 7 +++----
24 files changed, 107 insertions(+), 71 deletions(-)
Index: libvirt-acl/src/util/files.c
===================================================================
--- libvirt-acl.orig/src/util/files.c
+++ libvirt-acl/src/util/files.c
@@ -44,3 +44,21 @@ int virClose(int *fdptr, bool preserve_e
return rc;
}
+
+
+int virFClose(FILE **file, bool preserve_errno)
+{
+ int saved_errno;
+ int rc = 0;
+
+ if (*file) {
+ if (preserve_errno)
+ saved_errno = errno;
+ rc = fclose(*file);
+ *file = NULL;
+ if (preserve_errno)
+ errno = saved_errno;
+ }
+
+ return rc;
+}
Index: libvirt-acl/src/util/files.h
===================================================================
--- libvirt-acl.orig/src/util/files.h
+++ libvirt-acl/src/util/files.h
@@ -27,6 +27,7 @@
# define __VIR_FILES_H_
# include <stdbool.h>
+# include <stdio.h>
# include "internal.h"
# include "ignore-value.h"
@@ -34,13 +35,16 @@
/* Don't call this directly - use the macros below */
int virClose(int *fdptr, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
+int virFClose(FILE **file, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
/* For use on normal paths; caller must check return value,
and failure sets errno per close(). */
# define VIR_CLOSE(FD) virClose(&(FD), false)
+# define VIR_FCLOSE(FILE) virFClose(&(FILE), false)
/* For use on cleanup paths; errno is unaffected by close,
and no return value to worry about. */
# define VIR_FORCE_CLOSE(FD) ignore_value(virClose(&(FD), true))
+# define VIR_FORCE_FCLOSE(FILE) ignore_value(virFClose(&(FILE), true))
#endif /* __VIR_FILES_H */
Index: libvirt-acl/src/libvirt_private.syms
===================================================================
--- libvirt-acl.orig/src/libvirt_private.syms
+++ libvirt-acl/src/libvirt_private.syms
@@ -344,6 +344,7 @@ virFDStreamCreateFile;
# files.h
virClose;
+virFClose;
# hash.h
Index: libvirt-acl/daemon/libvirtd.c
===================================================================
--- libvirt-acl.orig/daemon/libvirtd.c
+++ libvirt-acl/daemon/libvirtd.c
@@ -522,11 +522,11 @@ static int qemudWritePidFile(const char
if (fprintf(fh, "%lu\n", (unsigned long)getpid()) < 0) {
VIR_ERROR(_("%s: Failed to write to pid file '%s' : %s"),
argv0, pidFile, virStrerror(errno, ebuf, sizeof ebuf));
- fclose(fh);
+ VIR_FORCE_FCLOSE(fh);
return -1;
}
- if (fclose(fh) == EOF) {
+ if (VIR_FCLOSE(fh) == EOF) {
VIR_ERROR(_("%s: Failed to close pid file '%s' : %s"),
argv0, pidFile, virStrerror(errno, ebuf, sizeof ebuf));
return -1;
Index: libvirt-acl/src/nodeinfo.c
===================================================================
--- libvirt-acl.orig/src/nodeinfo.c
+++ libvirt-acl/src/nodeinfo.c
@@ -46,6 +46,7 @@
#include "virterror_internal.h"
#include "count-one-bits.h"
#include "intprops.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_NONE
@@ -102,8 +103,7 @@ get_cpu_value(unsigned int cpu, const ch
}
cleanup:
- if (pathfp)
- fclose(pathfp);
+ VIR_FORCE_FCLOSE(pathfp);
VIR_FREE(path);
return value;
@@ -155,7 +155,7 @@ static unsigned long count_thread_siblin
}
cleanup:
- fclose(pathfp);
+ VIR_FORCE_FCLOSE(pathfp);
VIR_FREE(path);
return ret;
@@ -329,7 +329,7 @@ int nodeGetInfo(virConnectPtr conn ATTRI
return -1;
}
ret = linuxNodeInfoCPUPopulate(cpuinfo, nodeinfo);
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
if (ret < 0)
return -1;
Index: libvirt-acl/src/openvz/openvz_conf.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_conf.c
+++ libvirt-acl/src/openvz/openvz_conf.c
@@ -528,7 +528,7 @@ int openvzLoadDomains(struct openvz_driv
dom = NULL;
}
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return 0;
@@ -536,7 +536,7 @@ int openvzLoadDomains(struct openvz_driv
virReportOOMError();
cleanup:
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (dom)
virDomainObjUnref(dom);
return -1;
@@ -909,7 +909,7 @@ openvzSetDefinedUUID(int vpsid, unsigned
/* Record failure if fprintf or fclose fails,
and be careful always to close the stream. */
if ((fprintf(fp, "\n#UUID: %s\n", uuidstr) < 0)
- + (fclose(fp) == EOF))
+ + (VIR_FCLOSE(fp) == EOF))
goto cleanup;
}
@@ -996,7 +996,7 @@ int openvzGetVEID(const char *name) {
}
ok = fscanf(fp, "%d\n", &veid ) == 1;
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (ok && veid >= 0)
return veid;
Index: libvirt-acl/src/openvz/openvz_driver.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_driver.c
+++ libvirt-acl/src/openvz/openvz_driver.c
@@ -154,7 +154,7 @@ openvzDomainDefineCmd(const char *args[]
max_veid = veid;
}
}
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (max_veid == 0) {
max_veid = 100;
@@ -189,7 +189,7 @@ no_memory:
return -1;
cleanup:
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
#undef ADD_ARG
Index: libvirt-acl/src/qemu/qemu_driver.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_driver.c
+++ libvirt-acl/src/qemu/qemu_driver.c
@@ -4588,7 +4588,7 @@ static int qemudGetProcessInfo(unsigned
/* startstack -> processor */
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*d %d",
&usertime, &systime, &cpu) != 3) {
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
VIR_WARN0("cannot parse process status data");
errno = -EINVAL;
return -1;
@@ -4608,7 +4608,7 @@ static int qemudGetProcessInfo(unsigned
VIR_DEBUG("Got status for %d/%d user=%llu sys=%llu cpu=%d",
pid, tid, usertime, systime, cpu);
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return 0;
}
Index: libvirt-acl/src/storage/storage_backend.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend.c
+++ libvirt-acl/src/storage/storage_backend.c
@@ -1458,10 +1458,8 @@ virStorageBackendRunProgRegex(virStorage
VIR_FREE(reg);
- if (list)
- fclose(list);
- else
- VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(list);
+ VIR_FORCE_CLOSE(fd);
while ((err = waitpid(child, &exitstatus, 0) == -1) && errno == EINTR);
Index: libvirt-acl/src/storage/storage_backend_fs.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_fs.c
+++ libvirt-acl/src/storage/storage_backend_fs.c
@@ -284,12 +284,12 @@ virStorageBackendFileSystemIsMounted(vir
while ((getmntent_r(mtab, &ent, buf, sizeof(buf))) != NULL) {
if (STREQ(ent.mnt_dir, pool->def->target.path)) {
- fclose(mtab);
+ VIR_FORCE_FCLOSE(mtab);
return 1;
}
}
- fclose(mtab);
+ VIR_FORCE_FCLOSE(mtab);
return 0;
}
Index: libvirt-acl/src/storage/storage_backend_iscsi.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_iscsi.c
+++ libvirt-acl/src/storage/storage_backend_iscsi.c
@@ -235,11 +235,8 @@ out:
}
VIR_FREE(line);
- if (fp != NULL) {
- fclose(fp);
- } else {
- VIR_FORCE_CLOSE(fd);
- }
+ VIR_FORCE_FCLOSE(fp);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/storage/storage_backend_scsi.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_scsi.c
+++ libvirt-acl/src/storage/storage_backend_scsi.c
@@ -70,7 +70,7 @@ getDeviceType(uint32_t host,
}
gottype = fgets(typestr, 3, typefile);
- fclose(typefile);
+ VIR_FORCE_FCLOSE(typefile);
if (gottype == NULL) {
virReportSystemError(errno,
Index: libvirt-acl/src/uml/uml_driver.c
===================================================================
--- libvirt-acl.orig/src/uml/uml_driver.c
+++ libvirt-acl/src/uml/uml_driver.c
@@ -587,11 +587,11 @@ reopen:
if (fscanf(file, "%d", &vm->pid) != 1) {
errno = EINVAL;
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
goto cleanup;
}
- if (fclose(file) < 0)
+ if (VIR_FCLOSE(file) < 0)
goto cleanup;
rc = 0;
@@ -1096,7 +1096,7 @@ static int umlGetProcessInfo(unsigned lo
if (fscanf(pidinfo, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu", &usertime, &systime) != 2) {
umlDebug("not enough arg");
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return -1;
}
@@ -1109,7 +1109,7 @@ static int umlGetProcessInfo(unsigned lo
umlDebug("Got %llu %llu %llu", usertime, systime, *cpuTime);
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return 0;
}
Index: libvirt-acl/src/util/cgroup.c
===================================================================
--- libvirt-acl.orig/src/util/cgroup.c
+++ libvirt-acl/src/util/cgroup.c
@@ -31,6 +31,7 @@
#include "memory.h"
#include "cgroup.h"
#include "logging.h"
+#include "files.h"
#define CGROUP_MAX_VAL 512
@@ -127,13 +128,12 @@ static int virCgroupDetectMounts(virCgro
}
}
- fclose(mounts);
+ VIR_FORCE_FCLOSE(mounts);
return 0;
no_memory:
- if (mounts)
- fclose(mounts);
+ VIR_FORCE_FCLOSE(mounts);
return -ENOMEM;
}
@@ -192,12 +192,12 @@ static int virCgroupDetectPlacement(virC
}
}
- fclose(mapping);
+ VIR_FORCE_FCLOSE(mapping);
return 0;
no_memory:
- fclose(mapping);
+ VIR_FORCE_FCLOSE(mapping);
return -ENOMEM;
}
Index: libvirt-acl/src/util/dnsmasq.c
===================================================================
--- libvirt-acl.orig/src/util/dnsmasq.c
+++ libvirt-acl/src/util/dnsmasq.c
@@ -44,6 +44,7 @@
#include "memory.h"
#include "virterror_internal.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_NETWORK
#define DNSMASQ_HOSTSFILE_SUFFIX "hostsfile"
@@ -171,7 +172,7 @@ hostsfileWrite(const char *path,
for (i = 0; i < nhosts; i++) {
if (fputs(hosts[i].host, f) == EOF || fputc('\n', f) == EOF) {
rc = errno;
- fclose(f);
+ VIR_FORCE_FCLOSE(f);
if (istmp)
unlink(tmp);
@@ -180,7 +181,7 @@ hostsfileWrite(const char *path,
}
}
- if (fclose(f) == EOF) {
+ if (VIR_FCLOSE(f) == EOF) {
rc = errno;
goto cleanup;
}
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -436,11 +436,11 @@ int openTap(const char *ifname,
virReportSystemError(errno,
"%s",_("cannot determine macvtap's tap device "
"interface index"));
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
return -1;
}
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
if (snprintf(tapname, sizeof(tapname),
"/dev/tap%d", ifindex) >= sizeof(tapname)) {
Index: libvirt-acl/src/util/util.c
===================================================================
--- libvirt-acl.orig/src/util/util.c
+++ libvirt-acl/src/util/util.c
@@ -1830,10 +1830,8 @@ int virFileWritePidPath(const char *pidf
rc = 0;
cleanup:
- if (file &&
- fclose(file) < 0) {
+ if (VIR_FCLOSE(file) < 0)
rc = errno;
- }
return rc;
}
@@ -1864,11 +1862,11 @@ int virFileReadPid(const char *dir,
if (fscanf(file, "%d", pid) != 1) {
rc = EINVAL;
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
goto cleanup;
}
- if (fclose(file) < 0) {
+ if (VIR_FCLOSE(file) < 0) {
rc = errno;
goto cleanup;
}
Index: libvirt-acl/src/xen/xen_driver.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_driver.c
+++ libvirt-acl/src/xen/xen_driver.c
@@ -47,6 +47,7 @@
#include "pci.h"
#include "uuid.h"
#include "fdstream.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_XEN
@@ -219,7 +220,7 @@ xenUnifiedProbe (void)
FILE *fh;
if (fh = fopen("/dev/xen/domcaps", "r")) {
- fclose(fh);
+ VIR_FORCE_FCLOSE(fh);
return 1;
}
#endif
Index: libvirt-acl/src/xen/xen_hypervisor.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_hypervisor.c
+++ libvirt-acl/src/xen/xen_hypervisor.c
@@ -2641,7 +2641,7 @@ xenHypervisorMakeCapabilities(virConnect
capabilities = fopen ("/sys/hypervisor/properties/capabilities", "r");
if (capabilities == NULL) {
if (errno != ENOENT) {
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
virReportSystemError(errno,
_("cannot read file %s"),
"/sys/hypervisor/properties/capabilities");
@@ -2654,10 +2654,8 @@ xenHypervisorMakeCapabilities(virConnect
cpuinfo,
capabilities);
- if (cpuinfo)
- fclose(cpuinfo);
- if (capabilities)
- fclose(capabilities);
+ VIR_FORCE_FCLOSE(cpuinfo);
+ VIR_FORCE_FCLOSE(capabilities);
return caps;
#endif /* __sun */
Index: libvirt-acl/tests/nodeinfotest.c
===================================================================
--- libvirt-acl.orig/tests/nodeinfotest.c
+++ libvirt-acl/tests/nodeinfotest.c
@@ -9,6 +9,7 @@
#include "internal.h"
#include "nodeinfo.h"
#include "util.h"
+#include "files.h"
#ifndef __linux__
@@ -49,10 +50,10 @@ static int linuxTestCompareFiles(const c
fprintf(stderr, "\n%s\n", error->message);
virFreeError(error);
}
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
return -1;
}
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
/* 'nodes' is filled using libnuma.so from current machine
* topology, which makes it unsuitable for the test suite
Index: libvirt-acl/tests/testutils.c
===================================================================
--- libvirt-acl.orig/tests/testutils.c
+++ libvirt-acl/tests/testutils.c
@@ -180,26 +180,26 @@ int virtTestLoadFile(const char *file,
if (fstat(fileno(fp), &st) < 0) {
fprintf (stderr, "%s: failed to fstat: %s\n", file, strerror(errno));
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
if (st.st_size > (buflen-1)) {
fprintf (stderr, "%s: larger than buffer (> %d)\n", file, buflen-1);
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
if (st.st_size) {
if (fread(*buf, st.st_size, 1, fp) != 1) {
fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno));
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
}
(*buf)[st.st_size] = '\0';
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return st.st_size;
}
Index: libvirt-acl/tests/xencapstest.c
===================================================================
--- libvirt-acl.orig/tests/xencapstest.c
+++ libvirt-acl/tests/xencapstest.c
@@ -9,6 +9,7 @@
#include "xml.h"
#include "testutils.h"
#include "xen/xen_hypervisor.h"
+#include "files.h"
static char *progname;
static char *abs_srcdir;
@@ -63,10 +64,8 @@ static int testCompareFiles(const char *
fail:
free(actualxml);
- if (fp1)
- fclose(fp1);
- if (fp2)
- fclose(fp2);
+ VIR_FORCE_FCLOSE(fp1);
+ VIR_FORCE_FCLOSE(fp2);
virCapabilitiesFree(caps);
return ret;
Index: libvirt-acl/HACKING
===================================================================
--- libvirt-acl.orig/HACKING
+++ libvirt-acl/HACKING
@@ -321,20 +321,30 @@ routines, use the macros from memory.h
File handling
=============
-Use of the close() API is deprecated in libvirt code base to help avoiding
-double-closing of a file descriptor. Instead of this API, use the macro from
-files.h
+Usage of the close() and fclose() APIs is deprecated in libvirt code base to help
+avoiding double-closing of files or file descriptors, which is particulary
+dangerous in multi-threaded applications. Instead of these APIs, use the
+macros from files.h
- eg close a file descriptor
if (VIR_CLOSE(fd) < 0) {
- virReportSystemError(errno, _("failed to close file"));
+ virReportSystemError(errno, "%s", _("failed to close file"));
}
- - eg close a file descriptor in an error path, without losing the previous
- errno value
+ - eg close a file
+
+ if (VIR_FCLOSE(file) < 0) {
+ virReportSystemError(errno, "%s", _("failed to close file"));
+ }
+
+ - eg close a file or file descriptor in an error path, without losing the
+ previous errno value
VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(file);
+
+
String comparisons
==================
Index: libvirt-acl/docs/hacking.html.in
===================================================================
--- libvirt-acl.orig/docs/hacking.html.in
+++ libvirt-acl/docs/hacking.html.in
@@ -392,9 +392,10 @@
<h2><a name="file_handling">File handling</a></h2>
<p>
- Use of the close() API is deprecated in libvirt code base to help
- avoiding double-closing of a file descriptor. Instead of this API,
- use the macro from files.h
+ Usage of the close() and fclose() APIs is deprecated in libvirt code base to help
+ avoiding double-closing of files or file descriptors, which is particulary
+ dangerous in a multi-threaded applications. Instead of these APIs, use the
+ macros from files.h
</p>
<ul>
@@ -402,15 +403,24 @@
<pre>
if (VIR_CLOSE(fd) < 0) {
- virReportSystemError(errno, _("failed to close file"));
+ virReportSystemError(errno, "%s", _("failed to close file"));
}
</pre></li>
- <li><p>eg close a file descriptor in an error path, without losing
+ <li><p>eg close a file</p>
+
+<pre>
+ if (VIR_FCLOSE(file) < 0) {
+ virReportSystemError(errno, "%s", _("failed to close file"));
+ }
+</pre></li>
+
+ <li><p>eg close a file or file descriptor in an error path, without losing
the previous errno value</p>
<pre>
VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(file);
</pre></li>
</ul>
14 years
[libvirt] [PATCH] qemu: Add qemu-system-s390x to the emulators list
by Matthias Bolte
---
src/qemu/qemu_conf.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 9974cf4..92797f1 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -478,6 +478,7 @@ static const struct qemu_arch_info const arch_info_hvm[] = {
{ "sparc", 32, NULL, "qemu-system-sparc", NULL, NULL, 0 },
{ "ppc", 32, NULL, "qemu-system-ppc", NULL, NULL, 0 },
{ "itanium", 64, NULL, "qemu-system-ia64", NULL, NULL, 0 },
+ { "s390x", 64, NULL, "qemu-system-s390x", NULL, NULL, 0 },
};
static const struct qemu_arch_info const arch_info_xen[] = {
--
1.7.0.4
14 years
[libvirt] [PATCH v2] macvtap: convert send / recv function to use libnl
by Stefan Berger
V2:
- rebasing the patch following changes to the same file by another
patch
In a second step I am converting the netlink send/receive functions to
use libnl.
I tested this with 802.1Qbg profiles and my test server and did not see
a regression.
Caveat: The online documentation of libnl talks about nl_socket_alloc()
but the header file provides nl_handle_alloc() -- this could be a hint
to a possible problem between libnl versions...
http://www.infradead.org/~tgr/libnl/doc/group__socket.html
versus
http://libnl.sourcearchive.com/documentation/1.1/group__socket_gf903c9ea0...
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/util/macvtap.c | 82 +++++++++++++++++++----------------------------------
1 file changed, 30 insertions(+), 52 deletions(-)
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -83,16 +83,6 @@ enum virVirtualPortOp {
};
-static int nlOpen(void)
-{
- int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
- if (fd < 0)
- virReportSystemError(errno,
- "%s",_("cannot open netlink socket"));
- return fd;
-}
-
-
/**
* nlComm:
* @nlmsg: pointer to netlink message
@@ -106,8 +96,8 @@ static int nlOpen(void)
* buffer will be returned.
*/
static
-int nlComm(struct nlmsghdr *nlmsg,
- char **respbuf, unsigned int *respbuflen,
+int nlComm(struct nl_msg *nl_msg,
+ unsigned char **respbuf, unsigned int *respbuflen,
int nl_pid)
{
int rc = 0;
@@ -116,24 +106,29 @@ int nlComm(struct nlmsghdr *nlmsg,
.nl_pid = nl_pid,
.nl_groups = 0,
};
- int rcvChunkSize = 1024; // expecting less than that
- int rcvoffset = 0;
ssize_t nbytes;
struct timeval tv = {
.tv_sec = NETLINK_ACK_TIMEOUT_S,
};
fd_set readfds;
- int fd = nlOpen();
+ int fd;
int n;
+ struct nl_handle *nlhandle = nl_handle_alloc();
+ struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg);
- if (fd < 0)
+ if (!nlhandle)
return -1;
+ if (nl_connect(nlhandle, NETLINK_ROUTE) < 0) {
+ rc = -1;
+ goto err_exit;
+ }
+
+ nlmsg_set_dst(nl_msg, &nladdr);
+
nlmsg->nlmsg_pid = getpid();
- nlmsg->nlmsg_flags |= NLM_F_ACK;
- nbytes = sendto(fd, (void *)nlmsg, nlmsg->nlmsg_len, 0,
- (struct sockaddr *)&nladdr, sizeof(nladdr));
+ nbytes = nl_send_auto_complete(nlhandle, nl_msg);
if (nbytes < 0) {
virReportSystemError(errno,
"%s", _("cannot send to netlink socket"));
@@ -141,6 +136,8 @@ int nlComm(struct nlmsghdr *nlmsg,
goto err_exit;
}
+ fd = nl_socket_get_fd(nlhandle);
+
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
@@ -156,28 +153,9 @@ int nlComm(struct nlmsghdr *nlmsg,
goto err_exit;
}
- while (1) {
- if (VIR_REALLOC_N(*respbuf, rcvoffset+rcvChunkSize) < 0) {
- virReportOOMError();
- rc = -1;
- goto err_exit;
- }
-
- socklen_t addrlen = sizeof(nladdr);
- nbytes = recvfrom(fd, &((*respbuf)[rcvoffset]), rcvChunkSize, 0,
- (struct sockaddr *)&nladdr, &addrlen);
- if (nbytes < 0) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
- virReportSystemError(errno, "%s",
- _("error receiving from netlink socket"));
- rc = -1;
- goto err_exit;
- }
- rcvoffset += nbytes;
- break;
- }
- *respbuflen = rcvoffset;
+ *respbuflen = nl_recv(nlhandle, &nladdr, respbuf, NULL);
+ if (*respbuflen <= 0)
+ rc = -1;
err_exit:
if (rc == -1) {
@@ -186,7 +164,7 @@ err_exit:
*respbuflen = 0;
}
- VIR_FORCE_CLOSE(fd);
+ nl_handle_destroy(nlhandle);
return rc;
}
@@ -206,7 +184,7 @@ link_add(const char *type,
struct nlmsgerr *err;
struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
int ifindex;
- char *recvbuf = NULL;
+ unsigned char *recvbuf = NULL;
unsigned int recvbuflen;
struct nl_msg *nl_msg;
struct nlattr *linkinfo, *info_data;
@@ -255,7 +233,7 @@ link_add(const char *type,
nla_nest_end(nl_msg, linkinfo);
- if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, 0) < 0) {
+ if (nlComm(nl_msg, &recvbuf, &recvbuflen, 0) < 0) {
rc = -1;
goto err_exit;
}
@@ -327,7 +305,7 @@ link_del(const char *ifname)
struct nlmsghdr *resp;
struct nlmsgerr *err;
struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
- char *recvbuf = NULL;
+ unsigned char *recvbuf = NULL;
unsigned int recvbuflen;
struct nl_msg *nl_msg;
@@ -344,7 +322,7 @@ link_del(const char *ifname)
if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
goto buffer_too_small;
- if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, 0) < 0) {
+ if (nlComm(nl_msg, &recvbuf, &recvbuflen, 0) < 0) {
rc = -1;
goto err_exit;
}
@@ -739,7 +717,7 @@ getLldpadPid(void) {
static int
link_dump(bool nltarget_kernel, const char *ifname, int ifindex,
- struct nlattr **tb, char **recvbuf)
+ struct nlattr **tb, unsigned char **recvbuf)
{
int rc = 0;
struct nlmsghdr *resp;
@@ -776,7 +754,7 @@ link_dump(bool nltarget_kernel, const ch
}
}
- if (nlComm(nlmsg_hdr(nl_msg), recvbuf, &recvbuflen, pid) < 0) {
+ if (nlComm(nl_msg, recvbuf, &recvbuflen, pid) < 0) {
rc = -1;
goto err_exit;
}
@@ -862,7 +840,7 @@ ifaceGetNthParent(int ifindex, const cha
{
int rc;
struct nlattr *tb[IFLA_MAX + 1] = { NULL, };
- char *recvbuf = NULL;
+ unsigned char *recvbuf = NULL;
bool end = false;
unsigned int i = 0;
@@ -1022,7 +1000,7 @@ doPortProfileOpSetLink(bool nltarget_ker
.ifi_family = AF_UNSPEC,
.ifi_index = ifindex,
};
- char *recvbuf = NULL;
+ unsigned char *recvbuf = NULL;
unsigned int recvbuflen = 0;
uint32_t pid = 0;
struct nl_msg *nl_msg;
@@ -1133,7 +1111,7 @@ doPortProfileOpSetLink(bool nltarget_ker
}
}
- if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, pid) < 0) {
+ if (nlComm(nl_msg, &recvbuf, &recvbuflen, pid) < 0) {
rc = -1;
goto err_exit;
}
@@ -1201,7 +1179,7 @@ doPortProfileOpCommon(bool nltarget_kern
uint8_t op)
{
int rc;
- char *recvbuf = NULL;
+ unsigned char *recvbuf = NULL;
struct nlattr *tb[IFLA_MAX + 1] = { NULL , };
int repeats = STATUS_POLL_TIMEOUT_USEC / STATUS_POLL_INTERVL_USEC;
uint16_t status = 0;
14 years
[libvirt] [PATCH v2] macvtap: convert nl msg construction to use libnl
by Stefan Berger
V2:
- forgot to convert two more function that were hidden in #defines
- small nits
In a first step I am converting the netlink message construction in
macvtap code to use libnl. It's pretty much a 1:1 conversion except that
now the message needs to be allocated and deallocated.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/util/macvtap.c | 321
++++++++++++++++++++++-------------------------------
1 file changed, 137 insertions(+), 184 deletions(-)
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -196,51 +196,6 @@ err_exit:
}
-static struct rtattr *
-rtattrCreate(char *buffer, int bufsize, int type,
- const void *data, int datalen)
-{
- struct rtattr *r = (struct rtattr *)buffer;
- r->rta_type = type;
- r->rta_len = RTA_LENGTH(datalen);
- if (r->rta_len > bufsize)
- return NULL;
- memcpy(RTA_DATA(r), data, datalen);
- return r;
-}
-
-
-static void
-nlInit(struct nlmsghdr *nlm, int flags, int type)
-{
- nlm->nlmsg_len = NLMSG_LENGTH(0);
- nlm->nlmsg_flags = flags;
- nlm->nlmsg_type = type;
-}
-
-
-static void
-nlAlign(struct nlmsghdr *nlm)
-{
- nlm->nlmsg_len = NLMSG_ALIGN(nlm->nlmsg_len);
-}
-
-
-static void *
-nlAppend(struct nlmsghdr *nlm, int totlen, const void *data, int datalen)
-{
- char *pos;
- nlAlign(nlm);
- if (nlm->nlmsg_len + NLMSG_ALIGN(datalen) > totlen)
- return NULL;
- pos = (char *)nlm + nlm->nlmsg_len;
- memcpy(pos, data, datalen);
- nlm->nlmsg_len += datalen;
- nlAlign(nlm);
- return pos;
-}
-
-
# if WITH_MACVTAP
static int
@@ -252,74 +207,63 @@ link_add(const char *type,
int *retry)
{
int rc = 0;
- char nlmsgbuf[NLMSGBUF_SIZE];
- struct nlmsghdr *nlm = (struct nlmsghdr *)nlmsgbuf, *resp;
+ struct nlmsghdr *resp;
struct nlmsgerr *err;
- char rtattbuf[RATTBUF_SIZE];
- struct rtattr *rta, *rta1, *li;
struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
int ifindex;
char *recvbuf = NULL;
unsigned int recvbuflen;
+ struct nl_msg *nl_msg;
+ struct nlattr *linkinfo, *info_data;
if (ifaceGetIndex(true, srcdev, &ifindex) != 0)
return -1;
*retry = 0;
- memset(&nlmsgbuf, 0, sizeof(nlmsgbuf));
-
- nlInit(nlm, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL, RTM_NEWLINK);
+ nl_msg = nlmsg_alloc_simple(RTM_NEWLINK,
+ NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL);
+ if (!nl_msg) {
+ virReportOOMError();
+ return -1;
+ }
- if (!nlAppend(nlm, sizeof(nlmsgbuf), &ifinfo, sizeof(ifinfo)))
+ if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_LINK,
- &ifindex, sizeof(ifindex));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put_u32(nl_msg, IFLA_LINK, ifindex) < 0)
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_ADDRESS,
- macaddress, macaddrsize);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_ADDRESS, macaddrsize, macaddress) < 0)
goto buffer_too_small;
- if (ifname) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_IFNAME,
- ifname, strlen(ifname) + 1);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
- goto buffer_too_small;
- }
+ if (ifname &&
+ nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
+ goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_LINKINFO, NULL, 0);
- if (!rta ||
- !(li = nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len)))
+ if (!(linkinfo = nla_nest_start(nl_msg, IFLA_LINKINFO)))
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_INFO_KIND,
- type, strlen(type));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_INFO_KIND, strlen(type), type) < 0)
goto buffer_too_small;
if (macvlan_mode > 0) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_INFO_DATA,
- NULL, 0);
- if (!rta ||
- !(rta1 = nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len)))
+ if (!(info_data = nla_nest_start(nl_msg, IFLA_INFO_DATA)))
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_MACVLAN_MODE,
- &macvlan_mode, sizeof(macvlan_mode));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
+ if (nla_put(nl_msg, IFLA_MACVLAN_MODE, sizeof(macvlan_mode),
+ &macvlan_mode) < 0)
goto buffer_too_small;
- rta1->rta_len = (char *)nlm + nlm->nlmsg_len - (char *)rta1;
+ nla_nest_end(nl_msg, info_data);
}
- li->rta_len = (char *)nlm + nlm->nlmsg_len - (char *)li;
+ nla_nest_end(nl_msg, linkinfo);
- if (nlComm(nlm, &recvbuf, &recvbuflen, 0) < 0)
- return -1;
+ if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, 0) < 0) {
+ rc = -1;
+ goto err_exit;
+ }
if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
goto malformed_resp;
@@ -357,50 +301,58 @@ link_add(const char *type,
goto malformed_resp;
}
+err_exit:
+ nlmsg_free(nl_msg);
+
VIR_FREE(recvbuf);
return rc;
malformed_resp:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed netlink response message"));
VIR_FREE(recvbuf);
return -1;
buffer_too_small:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("internal buffer is too small"));
+ _("allocated netlink buffer is too small"));
return -1;
}
static int
-link_del(const char *name)
+link_del(const char *ifname)
{
int rc = 0;
- char nlmsgbuf[NLMSGBUF_SIZE];
- struct nlmsghdr *nlm = (struct nlmsghdr *)nlmsgbuf, *resp;
+ struct nlmsghdr *resp;
struct nlmsgerr *err;
- char rtattbuf[RATTBUF_SIZE];
- struct rtattr *rta;
struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
char *recvbuf = NULL;
unsigned int recvbuflen;
+ struct nl_msg *nl_msg;
- memset(&nlmsgbuf, 0, sizeof(nlmsgbuf));
-
- nlInit(nlm, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL, RTM_DELLINK);
+ nl_msg = nlmsg_alloc_simple(RTM_DELLINK,
+ NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL);
+ if (!nl_msg) {
+ virReportOOMError();
+ return -1;
+ }
- if (!nlAppend(nlm, sizeof(nlmsgbuf), &ifinfo, sizeof(ifinfo)))
+ if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_IFNAME,
- name, strlen(name)+1);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
goto buffer_too_small;
- if (nlComm(nlm, &recvbuf, &recvbuflen, 0) < 0)
- return -1;
+ if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, 0) < 0) {
+ rc = -1;
+ goto err_exit;
+ }
if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
goto malformed_resp;
@@ -416,7 +368,7 @@ link_del(const char *name)
if (err->error) {
virReportSystemError(-err->error,
_("error destroying %s interface"),
- name);
+ ifname);
rc = -1;
}
break;
@@ -428,19 +380,26 @@ link_del(const char *name)
goto malformed_resp;
}
+err_exit:
+ nlmsg_free(nl_msg);
+
VIR_FREE(recvbuf);
return rc;
malformed_resp:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed netlink response message"));
VIR_FREE(recvbuf);
return -1;
buffer_too_small:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("internal buffer is too small"));
+ _("allocated netlink buffer is too small"));
return -1;
}
@@ -790,40 +749,44 @@ link_dump(bool nltarget_kernel, const ch
struct nlattr **tb, char **recvbuf)
{
int rc = 0;
- char nlmsgbuf[NLMSGBUF_SIZE] = { 0, };
- struct nlmsghdr *nlm = (struct nlmsghdr *)nlmsgbuf, *resp;
+ struct nlmsghdr *resp;
struct nlmsgerr *err;
- char rtattbuf[RATTBUF_SIZE];
- struct rtattr *rta;
struct ifinfomsg ifinfo = {
.ifi_family = AF_UNSPEC,
.ifi_index = ifindex
};
unsigned int recvbuflen;
uint32_t pid = 0;
+ struct nl_msg *nl_msg;
*recvbuf = NULL;
- nlInit(nlm, NLM_F_REQUEST, RTM_GETLINK);
+ nl_msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_REQUEST);
+ if (!nl_msg) {
+ virReportOOMError();
+ return -1;
+ }
- if (!nlAppend(nlm, sizeof(nlmsgbuf), &ifinfo, sizeof(ifinfo)))
+ if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
goto buffer_too_small;
if (ifindex < 0 && ifname) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_IFNAME,
- ifname, strlen(ifname) + 1);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
+ if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
goto buffer_too_small;
}
if (!nltarget_kernel) {
pid = getLldpadPid();
- if (pid == 0)
- return -1;
+ if (pid == 0) {
+ rc = -1;
+ goto err_exit;
+ }
}
- if (nlComm(nlm, recvbuf, &recvbuflen, pid) < 0)
- return -1;
+ if (nlComm(nlmsg_hdr(nl_msg), recvbuf, &recvbuflen, pid) < 0) {
+ rc = -1;
+ goto err_exit;
+ }
if (recvbuflen < NLMSG_LENGTH(0) || *recvbuf == NULL)
goto malformed_resp;
@@ -859,17 +822,24 @@ link_dump(bool nltarget_kernel, const ch
if (rc != 0)
VIR_FREE(*recvbuf);
+err_exit:
+ nlmsg_free(nl_msg);
+
return rc;
malformed_resp:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed netlink response message"));
VIR_FREE(*recvbuf);
return -1;
buffer_too_small:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("internal buffer is too small"));
+ _("allocated netlink buffer is too small"));
return -1;
}
@@ -1053,11 +1023,8 @@ doPortProfileOpSetLink(bool nltarget_ker
uint8_t op)
{
int rc = 0;
- char nlmsgbuf[NLMSGBUF_SIZE];
- struct nlmsghdr *nlm = (struct nlmsghdr *)nlmsgbuf, *resp;
+ struct nlmsghdr *resp;
struct nlmsgerr *err;
- char rtattbuf[RATTBUF_SIZE];
- struct rtattr *rta, *vfports = NULL, *vfport;
struct ifinfomsg ifinfo = {
.ifi_family = AF_UNSPEC,
.ifi_index = ifindex,
@@ -1065,23 +1032,24 @@ doPortProfileOpSetLink(bool nltarget_ker
char *recvbuf = NULL;
unsigned int recvbuflen = 0;
uint32_t pid = 0;
+ struct nl_msg *nl_msg;
+ struct nlattr *vfports = NULL, *vfport;
- memset(&nlmsgbuf, 0, sizeof(nlmsgbuf));
-
- nlInit(nlm, NLM_F_REQUEST, RTM_SETLINK);
+ nl_msg = nlmsg_alloc_simple(RTM_SETLINK, NLM_F_REQUEST);
+ if (!nl_msg) {
+ virReportOOMError();
+ return -1;
+ }
- if (!nlAppend(nlm, sizeof(nlmsgbuf), &ifinfo, sizeof(ifinfo)))
+ if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
goto buffer_too_small;
- if (ifname) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_IFNAME,
- ifname, strlen(ifname) + 1);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
- goto buffer_too_small;
- }
+ if (ifname &&
+ nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
+ goto buffer_too_small;
if (macaddr && vlanid >= 0) {
- struct rtattr *vfinfolist, *vfinfo;
+ struct nlattr *vfinfolist, *vfinfo;
struct ifla_vf_mac ifla_vf_mac = {
.vf = vf,
.mac = { 0, },
@@ -1094,110 +1062,88 @@ doPortProfileOpSetLink(bool nltarget_ker
memcpy(ifla_vf_mac.mac, macaddr, 6);
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VFINFO_LIST,
- NULL, 0);
- if (!rta ||
- !(vfinfolist = nlAppend(nlm, sizeof(nlmsgbuf),
- rtattbuf, rta->rta_len)))
+ if (!(vfinfolist = nla_nest_start(nl_msg, IFLA_VFINFO_LIST)))
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VF_INFO,
- NULL, 0);
- if (!rta ||
- !(vfinfo = nlAppend(nlm, sizeof(nlmsgbuf),
- rtattbuf, rta->rta_len)))
+ if (!(vfinfo = nla_nest_start(nl_msg, IFLA_VF_INFO)))
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VF_MAC,
- &ifla_vf_mac, sizeof(ifla_vf_mac));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
+ if (!nla_put(nl_msg, IFLA_VF_MAC, sizeof(ifla_vf_mac),
+ &ifla_vf_mac) < 0)
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VF_VLAN,
- &ifla_vf_vlan, sizeof(ifla_vf_vlan));
-
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
+ if (!nla_put(nl_msg, IFLA_VF_VLAN, sizeof(ifla_vf_vlan),
+ &ifla_vf_vlan) < 0)
goto buffer_too_small;
- vfinfo->rta_len = (char *)nlm + nlm->nlmsg_len - (char *)vfinfo;
-
- vfinfolist->rta_len = (char *)nlm + nlm->nlmsg_len -
- (char *)vfinfolist;
+ nla_nest_end(nl_msg, vfinfo);
+ nla_nest_end(nl_msg, vfinfolist);
}
if (vf == PORT_SELF_VF && nltarget_kernel) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_SELF,
NULL, 0);
+ if (!(vfport = nla_nest_start(nl_msg, IFLA_PORT_SELF)))
+ goto buffer_too_small;
} else {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VF_PORTS,
NULL, 0);
- if (!rta ||
- !(vfports = nlAppend(nlm, sizeof(nlmsgbuf),
- rtattbuf, rta->rta_len)))
+ if (!(vfports = nla_nest_start(nl_msg, IFLA_VF_PORTS)))
goto buffer_too_small;
/* begin nesting vfports */
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VF_PORT,
NULL, 0);
+ if (!(vfport = nla_nest_start(nl_msg, IFLA_VF_PORT)))
+ goto buffer_too_small;
}
- if (!rta ||
- !(vfport = nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len)))
- goto buffer_too_small;
-
if (profileId) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_PROFILE,
- profileId, strlen(profileId) + 1);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_PROFILE, strlen(profileId) + 1,
+ profileId) < 0)
goto buffer_too_small;
}
if (portVsi) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_VSI_TYPE,
- portVsi, sizeof(*portVsi));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_VSI_TYPE, sizeof(*portVsi),
+ portVsi) < 0)
goto buffer_too_small;
}
if (instanceId) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf),
IFLA_PORT_INSTANCE_UUID,
- instanceId, VIR_UUID_BUFLEN);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_INSTANCE_UUID, VIR_UUID_BUFLEN,
+ instanceId) < 0)
goto buffer_too_small;
}
if (hostUUID) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_HOST_UUID,
- hostUUID, VIR_UUID_BUFLEN);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_HOST_UUID, VIR_UUID_BUFLEN,
+ hostUUID) < 0)
goto buffer_too_small;
}
if (vf != PORT_SELF_VF) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_VF,
- &vf, sizeof(vf));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_VF, sizeof(vf), &vf) < 0)
goto buffer_too_small;
}
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_REQUEST,
- &op, sizeof(op));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_REQUEST, sizeof(op), &op) < 0)
goto buffer_too_small;
/* end nesting of vport */
- vfport->rta_len = (char *)nlm + nlm->nlmsg_len - (char *)vfport;
+ nla_nest_end(nl_msg, vfport);
if (vfports) {
/* end nesting of vfports */
- vfports->rta_len = (char *)nlm + nlm->nlmsg_len - (char *)vfports;
+ nla_nest_end(nl_msg, vfports);
}
if (!nltarget_kernel) {
pid = getLldpadPid();
- if (pid == 0)
- return -1;
+ if (pid == 0) {
+ rc = -1;
+ goto err_exit;
+ }
}
- if (nlComm(nlm, &recvbuf, &recvbuflen, pid) < 0)
- return -1;
+ if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, pid) < 0) {
+ rc = -1;
+ goto err_exit;
+ }
if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
goto malformed_resp;
@@ -1225,19 +1171,26 @@ doPortProfileOpSetLink(bool nltarget_ker
goto malformed_resp;
}
+err_exit:
+ nlmsg_free(nl_msg);
+
VIR_FREE(recvbuf);
return rc;
malformed_resp:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed netlink response message"));
VIR_FREE(recvbuf);
return -1;
buffer_too_small:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("internal buffer is too small"));
+ _("allocated netlink buffer is too small"));
return -1;
}
14 years
[libvirt] [PATCH 0/3] Add proper validation of IP/MAC addresses to network.rng
by Laine Stump
I needed to add more elements to network.rng, and modify the possible
values for some existing elements, but noticed that there was
currently no validation of IP addresses or MAC addresses. As a first
stpe in my modifications, I'm bringing network.rng's validation/format
more in line with what's in, eg, interface.rng.
I'll be adding the new elements later, in a complete patcheset to add
IPv6 support, but since these patches stand on their own, I figured
I'd get them out of the way first.
The first patch puts the entire definition of network inside a
<grammer>, which seemed like the right thing to do in order to be able
to define refs for ipv4-addr/mac-addr outside the element def itself. I
copied the way that it's done in other libvirt RNG files (not sure why
this one wasn't like that already). Although this changed the nesting
of almost the entire file, I left the indentation of existing lines
as-is so the actual change wouldn't be obscured.
The 2nd patch looks very long and confused, but it actually is just
whitespace changes (as verified by diff -b).
The 3rd patch adds the refs for ipv4-addr & mac-addr, and makes use of
them.
networkschematest continues to succeed after these changes, so it
looks like it's all correct.
14 years