[libvirt] [PATCH] esx: Handle non-UTF-8 encoded VMX files
by Matthias Bolte
ESX(i) uses UTF-8, but a Windows based GSX server writes
Windows-1252 encoded VMX files.
Add a test case to ensure that libxml2 provides Windows-1252
to UTF-8 conversion.
---
This more general patch is a replacement for this patch:
https://www.redhat.com/archives/libvir-list/2010-October/msg00516.html
src/esx/esx_util.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
src/esx/esx_util.h | 2 ++
src/esx/esx_vmx.c | 30 ++++++++++++++++++++++++++++++
tests/esxutilstest.c | 42 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 119 insertions(+), 3 deletions(-)
diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
index 5fe72fc..24b931f 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -612,9 +612,9 @@ esxUtil_ReformatUuid(const char *input, char *output)
unsigned char uuid[VIR_UUID_BUFLEN];
if (virUUIDParse(input, uuid) < 0) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
- _("Could not parse UUID from string '%s'"),
- input);
+ ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
+ _("Could not parse UUID from string '%s'"),
+ input);
return -1;
}
@@ -819,3 +819,45 @@ esxUtil_EscapeDatastoreItem(const char *string)
return escaped2;
}
+
+
+
+char *
+esxUtil_ConvertToUTF8(const char *encoding, const char *string)
+{
+ char *result = NULL;
+ xmlCharEncodingHandlerPtr handler;
+ xmlBufferPtr input;
+ xmlBufferPtr utf8;
+
+ handler = xmlFindCharEncodingHandler(encoding);
+
+ if (handler == NULL) {
+ ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
+ _("libxml2 doesn't handle %s encoding"), encoding);
+ return NULL;
+ }
+
+ input = xmlBufferCreateStatic((char *)string, strlen(string));
+ utf8 = xmlBufferCreate();
+
+ if (xmlCharEncInFunc(handler, utf8, input) < 0) {
+ ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
+ _("Could not convert from %s to UTF-8 encoding"), encoding);
+ goto cleanup;
+ }
+
+ result = strdup((const char *)xmlBufferContent(utf8));
+
+ if (result == NULL) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ cleanup:
+ xmlCharEncCloseFunc(handler);
+ xmlBufferFree(input);
+ xmlBufferFree(utf8);
+
+ return result;
+}
diff --git a/src/esx/esx_util.h b/src/esx/esx_util.h
index 669a4f2..694e935 100644
--- a/src/esx/esx_util.h
+++ b/src/esx/esx_util.h
@@ -89,4 +89,6 @@ void esxUtil_ReplaceSpecialWindowsPathChars(char *string);
char *esxUtil_EscapeDatastoreItem(const char *string);
+char *esxUtil_ConvertToUTF8(const char *encoding, const char *string);
+
#endif /* __ESX_UTIL_H__ */
diff --git a/src/esx/esx_vmx.c b/src/esx/esx_vmx.c
index 7dc8e60..7ec8c0e 100644
--- a/src/esx/esx_vmx.c
+++ b/src/esx/esx_vmx.c
@@ -868,6 +868,8 @@ esxVMX_ParseConfig(esxVMX_Context *ctx, virCapsPtr caps, const char *vmx,
{
bool success = false;
virConfPtr conf = NULL;
+ char *encoding = NULL;
+ char *utf8;
virDomainDefPtr def = NULL;
long long config_version = 0;
long long virtualHW_version = 0;
@@ -895,6 +897,33 @@ esxVMX_ParseConfig(esxVMX_Context *ctx, virCapsPtr caps, const char *vmx,
return NULL;
}
+ /* vmx:.encoding */
+ if (esxUtil_GetConfigString(conf, ".encoding", &encoding, true) < 0) {
+ goto cleanup;
+ }
+
+ if (encoding == NULL || STRCASEEQ(encoding, "UTF-8")) {
+ /* nothing */
+ } else {
+ virConfFree(conf);
+ conf = NULL;
+
+ utf8 = esxUtil_ConvertToUTF8(encoding, vmx);
+
+ if (utf8 == NULL) {
+ goto cleanup;
+ }
+
+ conf = virConfReadMem(utf8, strlen(utf8), VIR_CONF_FLAG_VMX_FORMAT);
+
+ VIR_FREE(utf8);
+
+ if (conf == NULL) {
+ goto cleanup;
+ }
+ }
+
+ /* Allocate domain def */
if (VIR_ALLOC(def) < 0) {
virReportOOMError();
return NULL;
@@ -1359,6 +1388,7 @@ esxVMX_ParseConfig(esxVMX_Context *ctx, virCapsPtr caps, const char *vmx,
}
virConfFree(conf);
+ VIR_FREE(encoding);
VIR_FREE(sched_cpu_affinity);
VIR_FREE(guestOS);
diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c
index d4042c2..97e154e 100644
--- a/tests/esxutilstest.c
+++ b/tests/esxutilstest.c
@@ -280,6 +280,47 @@ testEscapeDatastoreItem(const void *data ATTRIBUTE_UNUSED)
+struct testWindows1252ToUTF8 {
+ const char *windows1252;
+ const char *utf8;
+};
+
+static struct testWindows1252ToUTF8 windows1252ToUTF8[] = {
+ { "normal", "normal" },
+ { /* "A€Z" */ "A\200Z", "A\342\202\254Z" },
+ { /* "Aä1ö2ü3ß4#5~6!7§8/9%Z" */ "A\3441\3662\3743\3374#5~6!7\2478/9%Z",
+ "A\303\2441\303\2662\303\2743\303\2374#5~6!7\302\2478/9%Z" },
+ { /* "hÀÁÂÃÄÅH" */ "h\300\301\302\303\304\305H",
+ "h\303\200\303\201\303\202\303\203\303\204\303\205H" },
+};
+
+static int
+testConvertWindows1252ToUTF8(const void *data ATTRIBUTE_UNUSED)
+{
+ int i;
+ char *utf8 = NULL;
+
+ for (i = 0; i < ARRAY_CARDINALITY(windows1252ToUTF8); ++i) {
+ VIR_FREE(utf8);
+
+ utf8 = esxUtil_ConvertToUTF8("Windows-1252",
+ windows1252ToUTF8[i].windows1252);
+
+ if (utf8 == NULL) {
+ return -1;
+ }
+
+ if (STRNEQ(windows1252ToUTF8[i].utf8, utf8)) {
+ VIR_FREE(utf8);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+
+
static int
mymain(int argc, char **argv)
{
@@ -312,6 +353,7 @@ mymain(int argc, char **argv)
DO_TEST(ParseDatastorePath);
DO_TEST(ConvertDateTimeToCalendarTime);
DO_TEST(EscapeDatastoreItem);
+ DO_TEST(ConvertWindows1252ToUTF8);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
--
1.7.0.4
14 years, 3 months
[libvirt] libvirt library binary name for linux
by arnaud.champion@devatom.fr
?Hi,
I'm currently working on .Net / Mono bindings of libvirt. I know that under windows environment, the libvirt library binary is named "libvirt-0.dll", what is it under linux ? I suppose libvirt.so, but I can't find it...
Arnaud
14 years, 3 months
[libvirt] [PATCH v3] introduce VIR_CLOSE to be used rather than close()
by Stefan Berger
V3:
- many small nits addressed
V2:
- following Eric's suggestions and picking up his code suggestions
Since bugs due to double-closed file descriptors are difficult to track
down in a multi-threaded system, I am introducing the VIR_CLOSE(fd)
macro to help avoid mistakes here.
There are lots of places where close() is being used. In this patch I am
only cleaning up usage of close() in src/conf where the problems were.
I also dare to declare close() as being deprecated in libvirt code base
(HACKING).
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
HACKING | 17 +++++++++++++
docs/hacking.html.in | 23 ++++++++++++++++++
src/Makefile.am | 3 +-
src/conf/domain_conf.c | 15 ++++++++----
src/conf/network_conf.c | 7 +++--
src/conf/nwfilter_conf.c | 13 ++++------
src/conf/storage_conf.c | 8 +++---
src/conf/storage_encryption_conf.c | 6 +++-
src/libvirt_private.syms | 3 ++
src/util/files.c | 46
+++++++++++++++++++++++++++++++++++++
src/util/files.h | 45
++++++++++++++++++++++++++++++++++++
11 files changed, 164 insertions(+), 22 deletions(-)
Index: libvirt-acl/src/util/files.c
===================================================================
--- /dev/null
+++ libvirt-acl/src/util/files.c
@@ -0,0 +1,46 @@
+/*
+ * memory.c: safer file handling
+ *
+ * Copyright (C) 2010 IBM Corporation
+ * Copyright (C) 2010 Stefan Berger
+ * Copyright (C) 2010 RedHat, Inc.
+ * Copyright (C) 2010 Eric Blake
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "files.h"
+
+int virClose(int *fdptr, bool preserve_errno)
+{
+ int saved_errno;
+ int rc = 0;
+
+ if (*fdptr >= 0) {
+ if (preserve_errno)
+ saved_errno = errno;
+ rc = close(*fdptr);
+ *fdptr = -1;
+ if (preserve_errno)
+ errno = saved_errno;
+ }
+
+ return rc;
+}
Index: libvirt-acl/src/util/files.h
===================================================================
--- /dev/null
+++ libvirt-acl/src/util/files.h
@@ -0,0 +1,45 @@
+/*
+ * files.h: safer file handling
+ *
+ * Copyright (C) 2010 IBM Corporation
+ * Copyright (C) 2010 Stefan Berger
+ * Copyright (C) 2010 RedHat, Inc.
+ * Copyright (C) 2010 Eric Blake
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+
+#ifndef __VIR_FILES_H_
+# define __VIR_FILES_H_
+
+# include <stdbool.h>
+
+# include "internal.h"
+
+
+/* Don't call this directly - use the macros below */
+int virClose(int *fdptr, 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)
+
+/* 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))
+
+#endif /* __VIR_FILES_H */
Index: libvirt-acl/src/Makefile.am
===================================================================
--- libvirt-acl.orig/src/Makefile.am
+++ libvirt-acl/src/Makefile.am
@@ -82,7 +82,8 @@ UTIL_SOURCES = \
util/uuid.c util/uuid.h \
util/util.c util/util.h \
util/xml.c util/xml.h \
- util/virterror.c util/virterror_internal.h
+ util/virterror.c util/virterror_internal.h \
+ util/files.c util/files.h
EXTRA_DIST += util/threads-pthread.c util/threads-win32.c
Index: libvirt-acl/src/conf/domain_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/domain_conf.c
+++ libvirt-acl/src/conf/domain_conf.c
@@ -46,6 +46,7 @@
#include "nwfilter_conf.h"
#include "ignore-value.h"
#include "storage_file.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_DOMAIN
@@ -6798,7 +6799,7 @@ int virDomainSaveXML(const char *configD
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot save config file '%s'"),
configFile);
@@ -6807,8 +6808,8 @@ int virDomainSaveXML(const char *configD
ret = 0;
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
+
VIR_FREE(configFile);
return ret;
}
@@ -7765,10 +7766,14 @@ int virDomainDiskDefForeachPath(virDomai
}
if (virStorageFileGetMetadataFromFD(path, fd, format, &meta) <
0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto cleanup;
}
- close(fd);
+
+ if (VIR_CLOSE(fd) < 0)
+ virReportSystemError(errno,
+ _("could not close file %s"),
+ path);
if (virHashAddEntry(paths, path, (void*)0x1) < 0) {
virReportOOMError();
Index: libvirt-acl/src/conf/nwfilter_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_conf.c
+++ libvirt-acl/src/conf/nwfilter_conf.c
@@ -45,6 +45,8 @@
#include "nwfilter_conf.h"
#include "domain_conf.h"
#include "c-ctype.h"
+#include "files.h"
+#include "ignore-value.h"
#define VIR_FROM_THIS VIR_FROM_NWFILTER
@@ -2193,7 +2195,7 @@ int virNWFilterSaveXML(const char *confi
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot save config file '%s'"),
configFile);
@@ -2203,9 +2205,7 @@ int virNWFilterSaveXML(const char *confi
ret = 0;
cleanup:
- if (fd != -1)
- close(fd);
-
+ VIR_FORCE_CLOSE(fd);
VIR_FREE(configFile);
return ret;
@@ -2604,7 +2604,7 @@ virNWFilterPoolObjSaveDef(virNWFilterDri
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot save config file %s"),
pool->configFile);
@@ -2614,8 +2614,7 @@ virNWFilterPoolObjSaveDef(virNWFilterDri
ret = 0;
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
VIR_FREE(xml);
Index: libvirt-acl/src/conf/storage_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/storage_conf.c
+++ libvirt-acl/src/conf/storage_conf.c
@@ -43,6 +43,8 @@
#include "buf.h"
#include "util.h"
#include "memory.h"
+#include "files.h"
+#include "ignore-value.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -1560,7 +1562,7 @@ virStoragePoolObjSaveDef(virStorageDrive
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot save config file %s"),
pool->configFile);
@@ -1570,9 +1572,7 @@ virStoragePoolObjSaveDef(virStorageDrive
ret = 0;
cleanup:
- if (fd != -1)
- close(fd);
-
+ VIR_FORCE_CLOSE(fd);
VIR_FREE(xml);
return ret;
Index: libvirt-acl/src/conf/network_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/network_conf.c
+++ libvirt-acl/src/conf/network_conf.c
@@ -43,6 +43,8 @@
#include "util.h"
#include "buf.h"
#include "c-ctype.h"
+#include "files.h"
+#include "ignore-value.h"
#define MAX_BRIDGE_ID 256
#define VIR_FROM_THIS VIR_FROM_NETWORK
@@ -687,7 +689,7 @@ int virNetworkSaveXML(const char *config
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot save config file '%s'"),
configFile);
@@ -697,8 +699,7 @@ int virNetworkSaveXML(const char *config
ret = 0;
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
VIR_FREE(configFile);
Index: libvirt-acl/src/conf/storage_encryption_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/storage_encryption_conf.c
+++ libvirt-acl/src/conf/storage_encryption_conf.c
@@ -35,6 +35,8 @@
#include "xml.h"
#include "virterror_internal.h"
#include "uuid.h"
+#include "files.h"
+#include "ignore-value.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -286,12 +288,12 @@ virStorageGenerateQcowPassphrase(unsigne
if (r <= 0) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot read from /dev/urandom"));
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
if (dest[i] >= 0x20 && dest[i] <= 0x7E)
i++; /* Got an acceptable character */
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
}
Index: libvirt-acl/HACKING
===================================================================
--- libvirt-acl.orig/HACKING
+++ libvirt-acl/HACKING
@@ -318,6 +318,23 @@ routines, use the macros from memory.h
VIR_FREE(domain);
+File handling
+=============
+
+Use of the close() API is deprecated in libvirt code base to help avoiding
+double-closing of a filedescriptor. Instead of this API, use the macro from
+files.h
+
+ - eg close a file descriptor
+
+ if (VIR_CLOSE(fd) < 0) {
+ virReportSystemError(errno, _("failed to close file"));
+ }
+
+ - eg close a file descriptor in an error path, without losing the
previous
+ errno value
+
+ VIR_FORCE_CLOSE(fd)
String comparisons
==================
Index: libvirt-acl/docs/hacking.html.in
===================================================================
--- libvirt-acl.orig/docs/hacking.html.in
+++ libvirt-acl/docs/hacking.html.in
@@ -389,7 +389,30 @@
</pre></li>
</ul>
+ <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 filedescriptor. Instead of this API,
+ use the macro from files.h
+ </p>
+
+ <ul>
+ <li><p>eg close a file descriptor</p>
+
+<pre>
+ if (VIR_CLOSE(fd) < 0) {
+ virReportSystemError(errno, _("failed to close file"));
+ }
+</pre></li>
+
+ <li><p>eg close a file descriptor in an error path, without losing
+ the previous errno value</p>
+
+<pre>
+ VIR_FORCE_CLOSE(fd);
+</pre></li>
+ </ul>
<h2><a name="string_comparision">String comparisons</a></h2>
Index: libvirt-acl/src/libvirt_private.syms
===================================================================
--- libvirt-acl.orig/src/libvirt_private.syms
+++ libvirt-acl/src/libvirt_private.syms
@@ -769,3 +769,6 @@ virXPathLongLong;
virXPathULongLong;
virXPathLongHex;
virXPathULongHex;
+
+# files.h
+virClose;
14 years, 3 months
[libvirt] [PATCH 0/4] Support auditing of guests
by Daniel P. Berrange
This patch series introduces basic support for auditing of guest
operations. The auditing hooks are primarily done in the libvirtd
dispatch layer, because we want to hook all stateful drivers
like QEMU, LXC, UML, etc. We don't want to audit the remote driver,
VMWare, XenAPI etc which are just plain RPC drivers.
There is an exception for auditing of the SELinux label assignment.
That has to be done right inside the sVirt code since the neccessary
info isn't available in the libvirtd dispatch layer.
This patch series focuses on lifecycle operations, but there are
quite alot of other things that are desirable to audit in the
future, so further patches will likely follow.
The last patch is semi-related, it fixes up a major screwup in
the linking of the daemon that caused duplicated copies of the
code to be linked. This was exposed by the audit work.
The patches are a combination of work by myself and Miloslav
NB, it should compile and run fine with any reasonably recent
audit package, but if you want correctly identified log messages
you need audit 2.0.5
Also, audit logs only appear if running libvirtd as root. Non
root users don't have permissions to generate audit logs.
Daniel
14 years, 3 months
[libvirt] [PATCH] Update docs for memory parameters and memtune command
by Nikunj A. Dadhania
From: Nikunj A. Dadhania <nikunj(a)linux.vnet.ibm.com>
docs/formatdomain.html.in: Add memtune element details
src/libvirt.c: Update virDomainGetMemoryParameters api description, make it
more clear that the user first needs to call the api to get the number of
parameters supported and then call again to get the values.
tools/virsh.pod: Add usage of new command memtune in
virsh manpage
Signed-off-by: Nikunj A. Dadhania <nikunj(a)linux.vnet.ibm.com>
---
docs/formatdomain.html.in | 21 +++++++++++++++++++++
src/libvirt.c | 20 +++++++++++++++++---
tools/virsh.pod | 8 ++++++++
3 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8ec7446..9b4c6d7 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -194,6 +194,11 @@
<memoryBacking>
<hugepages/>
</memoryBacking>
+ <memtune>
+ <hard_limit>1048576</hard_limit>
+ <soft_limit>131072</soft_limit>
+ <swap_hard_limit>2097152</swap_hard_limit>
+ </memtune>
<vcpu cpuset="1-4,^3,6">2</vcpu>
...</pre>
@@ -211,6 +216,22 @@
<code>hugepages</code> element set within it. This tells the
hypervisor that the guest should have its memory allocated using
hugepages instead of the normal native page size.</dd>
+ <dt><code>memtune</code></dt>
+ <dd> The optional <code>memtune</code> element provides details
+ regarding the memory tuneable parameters for the domain. If this is
+ omitted, it defaults to the OS provided defaults.</dd>
+ <dt><code>hard_limit</code></dt>
+ <dd> The optional <code>hard_limit</code> element is the maximum memory
+ the guest can use. The units for this value are kilobytes (i.e. blocks
+ of 1024 bytes)</dd>
+ <dt><code>soft_limit</code></dt>
+ <dd> The optional <code>soft_limit</code> element is the memory limit to
+ enforce during memory contention. The units for this value are
+ kilobytes (i.e. blocks of 1024 bytes)</dd>
+ <dt><code>swap_hard_limit</code></dt>
+ <dd> The optional <code>swap_hard_limit</code> element is the maximum
+ swap the guest can use. The units for this value are kilobytes
+ (i.e. blocks of 1024 bytes)</dd>
<dt><code>vcpu</code></dt>
<dd>The content of this element defines the number of virtual
CPUs allocated for the guest OS, which must be between 1 and
diff --git a/src/libvirt.c b/src/libvirt.c
index 2868460..629d97b 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3063,9 +3063,23 @@ error:
* Get the memory parameters, the @params array will be filled with the values
* equal to the number of parameters suggested by @nparams
*
- * As a special case, if @nparams is zero and @params is NULL, the API will
- * set the number of parameters supported by the HV in @nparams and return
- * SUCCESS.
+ * As the value of @nparams is dynamic, call the API setting @nparams to 0 and
+ * @params as NULL, the API returns the number of parameters supported by the
+ * HV by updating @nparams on SUCCESS. The caller should then allocate @params
+ * array, i.e. (sizeof(@virMemoryParameter) * @nparams) bytes and call the API
+ * again.
+ *
+ * Here is the sample code snippet:
+ *
+ * if ((virDomainGetMemoryParameters(dom, NULL, &nparams, 0) == 0) &&
+ * (nparams != 0)) {
+ * params = vshMalloc(ctl, sizeof(virMemoryParameter) * nparams);
+ * memset(params, 0, sizeof(virMemoryParameter) * nparams);
+ * if (virDomainGetMemoryParameters(dom, params, &nparams, 0)) {
+ * vshError(ctl, "%s", _("Unable to get memory parameters"));
+ * goto error;
+ * }
+ * }
*
* This function requires privileged access to the hypervisor. This function
* expects the caller to allocate the @param
diff --git a/tools/virsh.pod b/tools/virsh.pod
index e0471b1..cb8e942 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -456,6 +456,14 @@ Change the maximum memory allocation limit in the guest domain. This should
not change the current memory use. The memory limit is specified in
kilobytes.
+=item B<memtune> I<domain-id>
+
+Displays the domain memory parameters.
+
+=item B<memtune> I<domain-id> optional I<--hard-limit> B<kilobytes> optional I<--soft-limit> B<kilobytes> optional I<--swap-hard-limit> B<kilobytes>
+
+Allows you to set the domain memory parameters. LXC and QEMU/KVM supports these parameters.
+
=item B<setvcpus> I<domain-id> I<count>
Change the number of virtual CPUs active in the guest domain. Note that
14 years, 3 months
Re: [libvirt] [libvirt-tck 3/3] Add test case for daemon hook testing
by Osier
----- "Daniel P. Berrange" <berrange(a)redhat.com> wrote:
> On Mon, Oct 18, 2010 at 07:18:09AM +0800, Osier Yang wrote:
> > Validate daemon hook is invocated correctly while start, restart,
> > stop, reload libvirtd
> > ---
> > scripts/hooks/051-daemon-hook.t | 156
> +++++++++++++++++++++++++++++++++++++++
> > 1 files changed, 156 insertions(+), 0 deletions(-)
> > create mode 100644 scripts/hooks/051-daemon-hook.t
> >
> > diff --git a/scripts/hooks/051-daemon-hook.t
> b/scripts/hooks/051-daemon-hook.t
> > new file mode 100644
> > index 0000000..2d44e45
> > --- /dev/null
> > +++ b/scripts/hooks/051-daemon-hook.t
> > @@ -0,0 +1,156 @@
> > +# -*- perl -*-
> > +#
> > +# Copyright (C) 203 Red Hat, Inc.
> > +# Copyright (C) 203 Osier Yang <jyang(a)redhat.com>
> > +#
> > +# This program is free software; You can redistribute it and/or
> modify
> > +# it under the GNU General Public License as published by the Free
> > +# Software Foundation; either version 2, or (at your option) any
> > +# later version
> > +#
> > +# The file "LICENSE" distributed along with this file provides
> full
> > +# details of the terms and conditions
> > +#
> > +
> > +=pod
> > +
> > +=head1 NAME
> > +
> > +domain/051-start-daemon.t - hooks testing for daemon
> > +
> > +=head1 DESCRIPTION
> > +
> > +The test case validates that the hook script is invocated while
> > +start, stop, or reload daemon.
> > +
> > +=cut
> > +
> > +use strict;
> > +use warnings;
> > +
> > +use Test::More tests => 12;
> > +
> > +use Sys::Virt::TCK::Hooks;
> > +
> > +my $hook = Sys::Virt::TCK::Hooks->new(type => 'daemon',
> > + conf_dir =>
> '/etc/libvirt/hooks',
> > + log_name =>
> '/tmp/daemon.log');
> > +
> > +$hook->libvirtd_status;
> > +BAIL_OUT "libvirtd is not running, Exit..."
> > + if ($hook->{libvirtd_status} eq 'stopped');
> > +
> > +eval { $hook->prepare; };
> > +BAIL_OUT "failed to setup hooks testing ENV: $@" if $@;
> > +
> > +diag "restart libvirtd for hooks scripts taking effect";
> > +$hook->action('restart');
> > +$hook->service_libvirtd;
> > +unlink $hook->{log_name} unless -f $hook->{log_name};
> > +
> > +# stop libvirtd
> > +$hook->action('stop');
> > +$hook->expect_log;
> > +
> > +diag "$hook->{action} libvirtd";
> > +$hook->service_libvirtd;
> > +
> > +diag "hook script: $hook->{name}";
> > +system "cat $hook->{name}";
>
> These 'cat' calls should all really be reported as diagnostics
> rather than just sent to stdout directly. We should probably
> just use the standard 'Slurp' module from CPAN.
yes, indeed.
>
> eg, put a 'use Slurp' at the top of the script then
> replace those 2 lines with
>
> my $hookdata = slurp($hook->{name});
> diag "hook script: $hook->{name} '$hookdata'";
>
Thanks. will update.. think need to add it in 'Build.pl' as a
requirement at the meantime..
>
> > +
> > +sleep 3;
> > +diag "check if $hook->{name} is invocated";
> > +ok(-f "$hook->{name}", "$hook->{name} is invocated");
>
> s/invocated/invoked/ (and in a few other places later)
yep, will update.
>
> > +
> > +diag "actual log: $hook->{log_name}";
> > +system "cat $hook->{log_name}";
> > +
> > +diag "expected log:";
> > +print $hook->{expect_log}."\n";
> > +
> > +diag "check if the actual log is same with expected log";
> > +ok($hook->compare_log, "$hook->{name} is invocated correctly while
> $hook->{action} libvirtd");
> > +
> > +diag "check if libvirtd is stopped";
> > +ok(`service libvirtd status` =~ /stopped/, "libvirtd is stopped");
>
> > +
> > +# start libvirtd
> > +$hook->action('start');
> > +$hook->expect_log;
> > +
> > +diag "$hook->{action} libvirtd";
> > +$hook->service_libvirtd;
> > +
> > +diag "hook script: $hook->{name}";
> > +system "cat $hook->{name}";
> > +
> > +sleep 3;
> > +diag "check if $hook->{name} is invocated";
> > +ok(-f "$hook->{name}", "$hook->{name} is invocated");
> > +
> > +diag "actual log: $hook->{log_name}";
> > +system "cat $hook->{log_name}";
> > +
> > +diag "expected log:";
> > +print $hook->{expect_log}."\n";
> > +
> > +diag "check if the actual log is same with expected log";
> > +ok($hook->compare_log, "$hook->{name} is invocated correctly while
> $hook->{action} libvirtd");
> > +
> > +diag "check if libvirtd is still running";
> > +ok(`service libvirtd status` =~ /running/, "libvirtd is running");
>
> > +
> > +# restart libvirtd
> > +$hook->action('restart');
> > +$hook->expect_log;
> > +
> > +diag "$hook->{action} libvirtd";
> > +$hook->service_libvirtd;
> > +
> > +diag "hook script: $hook->{name}";
> > +system "cat $hook->{name}";
> > +
> > +sleep 3;
> > +diag "check if $hook->{name} is invocated";
> > +ok(-f "$hook->{name}", "$hook->{name} is invocated");
> > +
> > +diag "actual log: $hook->{log_name}";
> > +system "cat $hook->{log_name}";
> > +
> > +diag "expected log:";
> > +print $hook->{expect_log}."\n";
> > +
> > +diag "check if the actual log is same with expected log";
> > +ok($hook->compare_log, "$hook->{name} is invocated correctly while
> $hook->{action} libvirtd");
> > +
> > +diag "check if libvirtd is still running";
> > +ok(`service libvirtd status` =~ /running/, "libvirtd is running");
>
> > +
> > +# reload libvirtd
> > +$hook->action('reload');
> > +$hook->expect_log;
> > +
> > +diag "$hook->{action} libvirtd";
> > +$hook->service_libvirtd;
> > +
> > +diag "hook script: $hook->{name}";
> > +system "cat $hook->{name}";
> > +
> > +sleep 3;
> > +diag "check if $hook->{name} is invocated";
> > +ok(-f "$hook->{name}", "$hook->{name} is invocated");
> > +
> > +diag "actual log: $hook->{log_name}";
> > +system "cat $hook->{log_name}";
> > +
> > +diag "expected log:";
> > +print $hook->{expect_log}."\n";
> > +
> > +diag "check if the actual log is same with expected log";
> > +ok($hook->compare_log, "$hook->{name} is invocated correctly while
> $hook->{action} libvirtd");
> > +
> > +diag "check if libvirtd is still running";
> > +ok(`service libvirtd status` =~ /running/, "libvirtd is running");
>
> > +
> > +$hook->cleanup;
>
> As mentioned in the previous patch, it is probably best to wrap the
> entire test block in a
>
> SKIP: {
> my $uri = $conn->get_uri();
> skip 12, "Not using QEMU/LXC driver" unless
> $uri eq "qemu:///system" or $uri eq "lxc:///";
>
> ....all test cases...
> }
>
As explained in previous mail. will not "SKIP" it. :-/
- Osier
> Regards,
> Daniel
> --
> |: Red Hat, Engineering, London -o-
> http://people.redhat.com/berrange/ :|
> |: http://libvirt.org -o- http://virt-manager.org -o-
> http://deltacloud.org :|
> |: http://autobuild.org -o-
> http://search.cpan.org/~danberr/ :|
> |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B
> 9505 :|
14 years, 3 months
[libvirt] [PATCH] docs: added initial page for c# binding, with links to it
by Justin Clift
---
docs/bindings.html.in | 2 +-
docs/csharp.html.in | 128 +++++++++++++++++++++++++++++++++++++++++++++++++
docs/sitemap.html.in | 4 ++
3 files changed, 133 insertions(+), 1 deletions(-)
create mode 100644 docs/csharp.html.in
diff --git a/docs/bindings.html.in b/docs/bindings.html.in
index ee63ce3..bdcd231 100644
--- a/docs/bindings.html.in
+++ b/docs/bindings.html.in
@@ -15,7 +15,7 @@ higher level kind of languages:</p>
<li><strong>OCaml</strong>: Richard Jones supplies <a href="http://libvirt.org/ocaml/">bindings for OCaml</a>.</li>
<li><strong>Ruby</strong>: David Lutterkort provides <a href="http://libvirt.org/ruby/">bindings for Ruby</a>.</li>
<li><strong>Java</strong>: Daniel Veillard maintains <a href="java.html">Java bindings</a>.</li>
- <li><strong>C#</strong>: Jaromír Červenka maintains <a href="http://svn.i-tux.cz/listing.php?repname=SharpLibVirt">C# bindings here</a>.</li>
+ <li><strong>C#</strong>: Arnaud Champion maintains <a href="csharp.html">C# bindings</a>.</li>
<li><strong>PHP</strong>: Radek Hladik is developing <a href="http://phplibvirt.cybersales.cz/">PHP bindings</a>.</li>
</ul>
<p>For information on using libvirt on <strong>Windows</strong>
diff --git a/docs/csharp.html.in b/docs/csharp.html.in
new file mode 100644
index 0000000..771b8ca
--- /dev/null
+++ b/docs/csharp.html.in
@@ -0,0 +1,128 @@
+<?xml version="1.0"?>
+<html>
+ <body>
+ <h1>C# API bindings</h1>
+
+<!-- 2010-10-19 JC: Commented out until we have C# tarballs to download
+ <h2>Getting them</h2>
+
+ <p>
+ The latest versions of the libvirt C# bindings can be downloaded from:
+ </p>
+
+ <ul>
+ <li><a href="ftp://libvirt.org/libvirt/csharp/">libvirt.org FTP server</a></li>
+ <li><a href="http://libvirt.org/sources/csharp/">libvirt.org HTTP server</a></li>
+ </ul>
+-->
+
+ <h2>GIT source repository</h2>
+ <p>
+ The C# bindings source code is maintained in a <a
+ href="http://git-scm.com/">git</a> repository available on
+ <a href="http://libvirt.org/git/">libvirt.org</a>:
+ </p>
+
+<pre>
+git clone git://libvirt.org/libvirt-csharp.git
+</pre>
+
+ <p>
+ They can also be browsed online:
+ </p>
+
+<pre>
+<a href="http://libvirt.org/git/?p=libvirt-csharp.git;a=summary">http://libvirt.org/git/?p=libvirt-csharp.git;a=summary</a>
+</pre>
+
+ <p> </p>
+
+ <h2>Authors</h2>
+
+ <p>
+ The C# bindings are the work of Arnaud Champion
+ <<a href="mailto:arnaud.champion AT devatom.fr">arnaud.champion AT devatom.fr</a>>,
+ based upon the previous work of Jaromír Červenka.
+ </p>
+
+ <p> </p>
+
+ <h2>Function Coverage</h2>
+
+ <p>
+ Coverage for the C# functions is:
+ </p>
+ <table>
+ <tr><th>Type</th><th>Name</th><th>Binding available?</th><th>Tested?</th><th>Works?</th></tr>
+ <tr><td>enum</td><td>virCPUCompareResult</td><td>No</td></tr>
+ <tr><td>struct</td><td>virConnect</td><td>Yes, an IntPtr as the struct is not public</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>struct</td><td>virConnectAuth</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>struct</td><td>virConnectCredential</td><td>Yes</td><td>Yes</td><td>Partially, pack problem</td></tr>
+ <tr><td>enum</td><td>virConnectCredentialType</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>enum</td><td>virConnectFlags</td><td>No</td></tr>
+ <tr><td>struct</td><td>virDomain</td><td>Yes, an IntPtr as the struct is not public</td></tr>
+ <tr><td>struct</td><td>virDomainBlockInfo</td><td>No</td></tr>
+ <tr><td>struct</td><td>virDomainBlockStatsInfo</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainCoreDumpFlags</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainCreateFlags</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainDeviceModifyFlags</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainEventDefinedDetailType</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>struct</td><td>virDomainEventGraphicsAddress</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainEventGraphicsAddressType</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainEventGraphicsPhase</td><td>No</td></tr>
+ <tr><td>struct</td><td>virDomainEventGraphicsSubject</td><td>No</td></tr>
+ <tr><td>struct</td><td>virDomainEventGraphicsSubjectIdentity</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainEventID</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainEventIOErrorAction</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainEventResumedDetailType</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>enum</td><td>virDomainEventStartedDetailType</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>enum</td><td>virDomainEventStoppedDetailType</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>enum</td><td>virDomainEventSuspendedDetailType</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>enum</td><td>virDomainEventType</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>enum</td><td>virDomainEventUndefinedDetailType</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>enum</td><td>virDomainEventWatchdogAction</td><td>No</td></tr>
+ <tr><td>struct</td><td>virDomainInfo</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>struct</td><td>virDomainInterfaceStatsStruct</td><td>Yes</td><td>No</td><td>Maybe</td></tr>
+ <tr><td>struct</td><td>virDomainJobInfo</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainJobType</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainMemoryFlags</td><td>No</td></tr>
+ <tr><td>struct</td><td>virDomainMemoryStatStruct</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainMemoryStatTags</td><td>Yes</td><td>No</td><td>Maybe</td></tr>
+ <tr><td>enum</td><td>virDomainMigrateFlags</td><td>No</td></tr>
+ <tr><td>struct</td><td>virDomainSnapshot</td><td>No</td></tr>
+ <tr><td>enum</td><td>virDomainSnapshotDeleteFlags</td></tr>
+ <tr><td>enum</td><td>virDomainState</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>enum</td><td>virDomainXMLFlags</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>enum</td><td>virEventHandleType</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>struct</td><td>virInterface</td><td>Yes, an IntPtr as the struct is not public</td></tr>
+ <tr><td>enum</td><td>virInterfaceXMLFlags</td><td>No</td></tr>
+ <tr><td>struct</td><td>virNWFilter</td><td>No</td></tr>
+ <tr><td>struct</td><td>virNetwork</td><td>Yes, an IntPtr as the struct is not public</td></tr>
+ <tr><td>struct</td><td>virNodeDevice</td><td>Yes, an IntPtr as the struct is not public</td></tr>
+ <tr><td>struct</td><td>virNodeInfo</td><td>Yes</td><td>No</td><td>Maybe</td></tr>
+ <tr><td>struct</td><td>virSchedParameter</td><td>No</td></tr>
+ <tr><td>enum</td><td>virSchedParameterType</td><td>No</td></tr>
+ <tr><td>struct</td><td>virSecret</td><td>No</td></tr>
+ <tr><td>enum</td><td>virSecretUsageType</td><td>No</td></tr>
+ <tr><td>struct</td><td>virSecurityLabel</td><td>No</td></tr>
+ <tr><td>struct</td><td>virSecurityModel</td><td>No</td></tr>
+ <tr><td>struct</td><td>virStoragePool</td><td>Yes, an IntPtr as the struct is not public</td></tr>
+ <tr><td>enum</td><td>virStoragePoolBuildFlags</td><td>Yes</td><td>No</td><td>Maybe</td></tr>
+ <tr><td>enum</td><td>virStoragePoolDeleteFlags</td><td>Yes</td><td>No</td><td>Maybe</td></tr>
+ <tr><td>struct</td><td>virStoragePoolInfo</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>struct</td><td>virStoragePool</td><td>Yes, an IntPtr as the struct is not public</td></tr>
+ <tr><td>enum</td><td>virStoragePoolState</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>struct</td><td>virStorageVol</td><td>Yes, an IntPtr as the struct is not public</td></tr>
+ <tr><td>enum</td><td>virStorageVolDeleteFlags</td><td>No</td></tr>
+ <tr><td>struct</td><td>virStorageVolInfo</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>struct</td><td>virStorageVol</td><td>Yes, an IntPtr as the struct is not public</td></tr>
+ <tr><td>enum</td><td>virStorageVolType</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
+ <tr><td>struct</td><td>virStream</td><td>No</td></tr>
+ <tr><td>enum</td><td>virStreamEventType</td><td>No</td></tr>
+ <tr><td>enum</td><td>virStreamFlags</td><td>No</td></tr>
+ <tr><td>struct</td><td>virVcpuInfo</td><td>No</td></tr>
+ <tr><td>enum</td><td>virVcpuState</td><td>No</td></tr>
+ </table>
+
+ </body>
+</html>
diff --git a/docs/sitemap.html.in b/docs/sitemap.html.in
index 481507e..5f46b59 100644
--- a/docs/sitemap.html.in
+++ b/docs/sitemap.html.in
@@ -242,6 +242,10 @@
<a href="java.html">Java</a>
<span>overview of the Java API bindings</span>
</li>
+ <li>
+ <a href="csharp.html">C#</a>
+ <span>overview of the C# API bindings</span>
+ </li>
</ul>
</li>
<li>
--
1.7.2.3
14 years, 3 months
[libvirt] [PATCH] qemu: let qemu group look below /var/lib/libvirt/qemu/
by Eric Blake
From: Dan Kenigsberg <danken(a)redhat.com>
Vdsm needs to communicate with its guest agent via unix domain socket,
which qemu creates due to the following domain xml device:
<channel type='unix'>
<target type='virtio' name='com.redhat.rhevm.vdsm'/>
<source mode='bind' path='/var/lib/libvirt/qemu/channels/fcp-xp-1.com.redhat.rhevm.vdsm'/>
</channel>
The location of the socket below /var/lib/libvirt/qemu/channels makes
sense, to humans and selinux policy alike. However, that socket should
be accessible to vdsm, too.
Due to other (storage) reasons, vdsm is to join the "qemu" group. With
this patch, vdsm can look below /var/lib/libvirt/qemu and connect to the
socket.
The socket itself should be chmod'ed to allow qemu group read/write, but
that's for another project.
BZ#643407
---
libvirt.spec.in | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index e8126b4..55e368e 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -782,8 +782,8 @@ fi
%if %{with_qemu}
%dir %attr(0700, root, root) %{_localstatedir}/run/libvirt/qemu/
-%dir %attr(0700, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/
-%dir %attr(0700, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
+%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/
+%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
%endif
%if %{with_lxc}
%dir %{_localstatedir}/run/libvirt/lxc/
--
1.7.1
14 years, 3 months
[libvirt] RFC: automatic setting of ip_forwarding (or not)
by Laine Stump
Currently libvirt will turn on net.ipv4.ip_forward by writing "1\n" to
/proc/sys/net/ipv4/ip_forward whenever a virtual network of with a
forward mode of "nat" or "route" is started. This is problematic for two
reasons: 1) /etc/sysctl.conf is not updated with this information, so
any other process reprocessing /etc/sysctl.conf (with "sysctl -a -p")
will potentially turn ip forward back to 0, leaving libvirt-created
virtual networks in a non-working state, and 2) it's possible the
administrator turned off ip forwarding on purpose for security reasons,
and our silently turning it on leaves them mistakenly believing it is
still off.
We've discussed a few ways of remedying this situation lately, and I
thought I should summarize all the mentioned ideas, and take a poll to
try and determine which way we should fix this.
1) Leave it as is. The simplest solution, but has the problems outlines
above.
2) Turn it on in the same place, but do it by writing
net.ipv4.ip_forward = 1
to /etc/sysctl.conf and calling "sysctl -a -p". This gives us the same
behavior as currently, but with the advantages that a) our change to the
config is documented in /etc/sysctl.conf and b) virtual networked guests
won't suddenly have their network fail when some other process runs
"sysconfig -a -p".
However, it seems rather drastic to be turning this on every time a
virtual network is started, especially without alerting the admin that
this has been done.
3) Whenever a virtual network that would require ip_forward = 1 to
operate properly is started (ie at libvirtd start time, and when a
network is newly defined), check if it's currently on, and if not log a
warning message, informing the admin that they should turn on ip_forward
in sysctl.conf and reload it in order to have properly working networking.
This would assure that the admin was informed of the necessity for
ip_forward, but eliminate the possibility of two processes fighting over
the setting of ip_forward, leaving it up to the admin to make the
decision and do the right thing. On the other hand, it would prevent
libvirt's networking from "just working" on a new install.
4) Turn ip_forward on during libvirt install.
This one doesn't make sense to me, because you don't know at the time of
libvirt install whether or not the installation if going to end up with
any virtual networks that need forwarding.
5) Make ip_forward a tunable in /etc/libvirt/libvirtd.conf, and set it
accordingly every time libvirtd is started.
I don't know if this makes sense either - if you have NATed or routed
virtual networks, you will need ip_forward=1 for them to work properly,
and if you don't have them, you don't care, so it's really redundant.
****
I think the important things to accomplish are:
1) Avoid having networking magically stop working when someone else
reloads sysctl.conf
2) Make sure that the admin realizes that ip_forward is being turned on
(or needs to be turned on).
3) If we're going to turn it on, at least don't do it if it's not needed.
4) Something else we need to consider is the ability to provision a host
for proper guest networking purely through the libvirt API, and if we
were to stop turning on ip_forward automatically when a network was
started, that wouldn't work anymore (unless ip_forward happened to be
turned on already).
So, what are your opinions?
(BTW, the firewall rules added for virtual networks suffer from a
similar problem - because they're loaded into the kernel directly with
the iptables command, there is no external record of them, and some
other process reloading the firewall will flush out all libvirt's rules,
leaving the guests with nonworking networking. But that discussion is a
bigger one, that probably needs to go outside just libvirt, so I'll
avoid that here...)
14 years, 3 months