[libvirt] [PATCH v2] Fix performance problem of virStorageVolCreateXMLFrom()
by Minoru Usui
This patch changes zerobuf variable from array to VIR_ALLOC_N().
Signed-off-by: Minoru Usui <usui(a)mxm.nes.nec.co.jp>
---
src/storage/storage_backend.c | 38 +++++++++++++++++++++++++++++---------
1 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 2eede74..3a22da4 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -36,6 +36,10 @@
#include <sys/stat.h>
#include <sys/param.h>
#include <dirent.h>
+#ifdef __linux__
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+#endif
#if HAVE_SELINUX
# include <selinux/selinux.h>
@@ -108,6 +112,9 @@ enum {
TOOL_QCOW_CREATE,
};
+#define READ_BLOCK_SIZE_DEFAULT (1024 * 1024)
+#define WRITE_BLOCK_SIZE_DEFAULT (512)
+
static int ATTRIBUTE_NONNULL (2)
virStorageBackendCopyToFD(virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol,
@@ -119,8 +126,10 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol,
int amtread = -1;
int ret = 0;
unsigned long long remain;
- size_t bytes = 1024 * 1024;
- char zerobuf[512];
+ size_t rbytes = READ_BLOCK_SIZE_DEFAULT;
+ size_t wbytes = WRITE_BLOCK_SIZE_DEFAULT;
+ int interval;
+ char *zerobuf;
char *buf = NULL;
if ((inputfd = open(inputvol->target.path, O_RDONLY)) < 0) {
@@ -131,9 +140,19 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol,
goto cleanup;
}
- bzero(&zerobuf, sizeof(zerobuf));
+#ifdef __linux__
+ if (ioctl(fd, BLKBSZGET, &wbytes) < 0) {
+ wbytes = WRITE_BLOCK_SIZE_DEFAULT;
+ }
+#endif
+
+ if (VIR_ALLOC_N(zerobuf, wbytes) < 0) {
+ ret = -errno;
+ virReportOOMError();
+ goto cleanup;
+ }
- if (VIR_ALLOC_N(buf, bytes) < 0) {
+ if (VIR_ALLOC_N(buf, rbytes) < 0) {
ret = -errno;
virReportOOMError();
goto cleanup;
@@ -144,10 +163,10 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol,
while (amtread != 0) {
int amtleft;
- if (remain < bytes)
- bytes = remain;
+ if (remain < rbytes)
+ rbytes = remain;
- if ((amtread = saferead(inputfd, buf, bytes)) < 0) {
+ if ((amtread = saferead(inputfd, buf, rbytes)) < 0) {
ret = -errno;
virReportSystemError(errno,
_("failed reading from file '%s'"),
@@ -160,7 +179,7 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol,
* blocks */
amtleft = amtread;
do {
- int interval = ((512 > amtleft) ? amtleft : 512);
+ interval = ((wbytes > amtleft) ? amtleft : wbytes);
int offset = amtread - amtleft;
if (is_dest_file && memcmp(buf+offset, zerobuf, interval) == 0) {
@@ -179,7 +198,7 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol,
goto cleanup;
}
- } while ((amtleft -= 512) > 0);
+ } while ((amtleft -= interval) > 0);
}
if (VIR_CLOSE(inputfd) < 0) {
@@ -196,6 +215,7 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol,
cleanup:
VIR_FORCE_CLOSE(inputfd);
+ VIR_FREE(zerobuf);
VIR_FREE(buf);
return ret;
--
Minoru Usui <usui(a)mxm.nes.nec.co.jp>
13 years, 8 months
[libvirt] [PATCH] maint: make spacing in .sh files easier
by Eric Blake
Commit 7f193757 renamed libvirt-guests.init from .in to .sh, which
made it slip past sc_TAB_in_indentation. I nearly reintroduced a
tab, so I'm pushing this to prevent that from happening.
* cfg.mk (sc_TAB_in_indentation): Update rule to include .sh files.
* .dir-locals.el: List spacing preference for .sh files.
---
Pushing this under the trivial rule.
.dir-locals.el | 3 +++
cfg.mk | 5 +++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/.dir-locals.el b/.dir-locals.el
index f24ec61..d5eba86 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -8,4 +8,7 @@
(html-mode . (
(indent-tabs-mode . nil)
))
+ (sh-mode . (
+ (indent-tabs-mode . nil)
+ ))
)
diff --git a/cfg.mk b/cfg.mk
index 5cb2ead..c12f199 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -327,10 +327,11 @@ sc_prohibit_ctype_h:
# Ensure that no C source file, docs, or rng schema uses TABs for
# indentation. Also match *.h.in files, to get libvirt.h.in. Exclude
# files in gnulib, since they're imported.
+space_indent_files=(\.(rng|s?[ch](\.in)?|html.in|py)|(daemon|tools)/.*\.in)
sc_TAB_in_indentation:
@prohibit='^ * ' \
- in_vc_files='(\.(rng|[ch](\.in)?|html.in|py)|(daemon|tools)/.*\.in)$$' \
- halt='use leading spaces, not TAB, in C, sh, html, py, and RNG schemas' \
+ in_vc_files='$(space_indent_files)$$' \
+ halt='indent with space, not TAB, in C, sh, html, py, and RNG schemas' \
$(_sc_search_regexp)
ctype_re = isalnum|isalpha|isascii|isblank|iscntrl|isdigit|isgraph|islower\
--
1.7.4
13 years, 8 months
[libvirt] [PATCH] virsh: optimize creation of default connection
by Eric Blake
Ramon de Carvalho Valle reported a problem with:
virsh connect qemu:///system
as a non-root user. The real root problem appears to be a regression
in libvirtd being auto-started on the default qemu:///session URI;
however, the symptom points to an independent flaw in virsh - we
shouldn't be wasting efforts on making a connection if we aren't going
to be using that connection. Fixing virsh avoids Ramon's issue, while
I work in the meantime to fix the real libvirtd regression.
This patch looks big, but that's because 'gcc -Wmissing-field-initializers'
gets triggered by './autobuild.sh --enable-compile-warnings=error', so I
had to add 0 initialization to everyone (rather than my preference of
just adding the non-zero flags to virshCmds and to cmdConnect).
Meanwhile, if you use 'virsh -c URI', the connection must succeed; this
patch _only_ optimizes the default connection to be deferred to a later
point where we know if a particular command to be run needs a connection.
* tools/virsh.c (VSH_CMD_FLAG_NOCONNECT): New flag.
(vshCmdDef): Add new flags field.
(vshCommandRun): Honor new flag.
(domManagementCmds, domMonitoringCmds, storagePoolCmds)
(storageVolCmds, networkCmds, nodedevCmds, ifaceCmds)
(nwfilterCmds, secretCmds, virshCmds, snapshotCmds)
(hostAndHypervisorCmds): Populate new field.
(vshReconnect): Don't warn on initial connection.
---
This is https://bugzilla.redhat.com/show_bug.cgi?id=684848
It depends on this patch as a prereq:
https://www.redhat.com/archives/libvir-list/2011-March/msg00629.html
tools/virsh.c | 423 +++++++++++++++++++++++++++++++++------------------------
1 files changed, 247 insertions(+), 176 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 8ac32fc..33ba968 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -190,6 +190,13 @@ typedef struct vshCmdOpt {
} vshCmdOpt;
/*
+ * Command Usage Flags
+ */
+enum {
+ VSH_CMD_FLAG_NOCONNECT = (1 << 0), /* no prior connection needed */
+};
+
+/*
* vshCmdDef - command definition
*/
typedef struct {
@@ -197,6 +204,7 @@ typedef struct {
int (*handler) (vshControl *, const vshCmd *); /* command handler */
const vshCmdOptDef *opts; /* definition of command options */
const vshCmdInfo *info; /* details about command */
+ int flags; /* bitwise OR of VSH_CMD_FLAG */
} vshCmdDef;
/*
@@ -558,16 +566,21 @@ vshSetupSignals(void) {
*
*/
static void
-vshReconnect(vshControl *ctl) {
- if (ctl->conn != NULL)
+vshReconnect(vshControl *ctl)
+{
+ bool connected = false;
+
+ if (ctl->conn != NULL) {
+ connected = true;
virConnectClose(ctl->conn);
+ }
ctl->conn = virConnectOpenAuth(ctl->name,
virConnectAuthPtrDefault,
ctl->readonly ? VIR_CONNECT_RO : 0);
if (!ctl->conn)
vshError(ctl, "%s", _("Failed to reconnect to the hypervisor"));
- else
+ else if (connected)
vshError(ctl, "%s", _("Reconnected to the hypervisor"));
disconnected = 0;
}
@@ -9659,7 +9672,7 @@ static const vshCmdOptDef opts_cd[] = {
};
static int
-cmdCd(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
+cmdCd(vshControl *ctl, const vshCmd *cmd)
{
const char *dir = NULL;
char *dir_malloced = NULL;
@@ -10442,206 +10455,260 @@ cleanup:
}
static const vshCmdDef domManagementCmds[] = {
- {"attach-device", cmdAttachDevice, opts_attach_device, info_attach_device},
- {"attach-disk", cmdAttachDisk, opts_attach_disk, info_attach_disk},
- {"attach-interface", cmdAttachInterface, opts_attach_interface, info_attach_interface},
- {"autostart", cmdAutostart, opts_autostart, info_autostart},
- {"blkiotune", cmdBlkiotune, opts_blkiotune, info_blkiotune},
+ {"attach-device", cmdAttachDevice, opts_attach_device,
+ info_attach_device, 0},
+ {"attach-disk", cmdAttachDisk, opts_attach_disk,
+ info_attach_disk, 0},
+ {"attach-interface", cmdAttachInterface, opts_attach_interface,
+ info_attach_interface, 0},
+ {"autostart", cmdAutostart, opts_autostart, info_autostart, 0},
+ {"blkiotune", cmdBlkiotune, opts_blkiotune, info_blkiotune, 0},
#ifndef WIN32
- {"console", cmdConsole, opts_console, info_console},
+ {"console", cmdConsole, opts_console, info_console, 0},
#endif
- {"cpu-baseline", cmdCPUBaseline, opts_cpu_baseline, info_cpu_baseline},
- {"cpu-compare", cmdCPUCompare, opts_cpu_compare, info_cpu_compare},
- {"create", cmdCreate, opts_create, info_create},
- {"define", cmdDefine, opts_define, info_define},
- {"destroy", cmdDestroy, opts_destroy, info_destroy},
- {"detach-device", cmdDetachDevice, opts_detach_device, info_detach_device},
- {"detach-disk", cmdDetachDisk, opts_detach_disk, info_detach_disk},
- {"detach-interface", cmdDetachInterface, opts_detach_interface, info_detach_interface},
- {"domid", cmdDomid, opts_domid, info_domid},
- {"domjobabort", cmdDomjobabort, opts_domjobabort, info_domjobabort},
- {"domjobinfo", cmdDomjobinfo, opts_domjobinfo, info_domjobinfo},
- {"domname", cmdDomname, opts_domname, info_domname},
- {"domuuid", cmdDomuuid, opts_domuuid, info_domuuid},
- {"domxml-from-native", cmdDomXMLFromNative, opts_domxmlfromnative, info_domxmlfromnative},
- {"domxml-to-native", cmdDomXMLToNative, opts_domxmltonative, info_domxmltonative},
- {"dump", cmdDump, opts_dump, info_dump},
- {"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml},
- {"edit", cmdEdit, opts_edit, info_edit},
- {"managedsave", cmdManagedSave, opts_managedsave, info_managedsave},
- {"managedsave-remove", cmdManagedSaveRemove, opts_managedsaveremove, info_managedsaveremove},
- {"maxvcpus", cmdMaxvcpus, opts_maxvcpus, info_maxvcpus},
- {"memtune", cmdMemtune, opts_memtune, info_memtune},
- {"migrate", cmdMigrate, opts_migrate, info_migrate},
- {"migrate-setmaxdowntime", cmdMigrateSetMaxDowntime, opts_migrate_setmaxdowntime, info_migrate_setmaxdowntime},
- {"reboot", cmdReboot, opts_reboot, info_reboot},
- {"restore", cmdRestore, opts_restore, info_restore},
- {"resume", cmdResume, opts_resume, info_resume},
- {"save", cmdSave, opts_save, info_save},
- {"schedinfo", cmdSchedinfo, opts_schedinfo, info_schedinfo},
- {"setmaxmem", cmdSetmaxmem, opts_setmaxmem, info_setmaxmem},
- {"setmem", cmdSetmem, opts_setmem, info_setmem},
- {"setvcpus", cmdSetvcpus, opts_setvcpus, info_setvcpus},
- {"shutdown", cmdShutdown, opts_shutdown, info_shutdown},
- {"start", cmdStart, opts_start, info_start},
- {"suspend", cmdSuspend, opts_suspend, info_suspend},
- {"ttyconsole", cmdTTYConsole, opts_ttyconsole, info_ttyconsole},
- {"undefine", cmdUndefine, opts_undefine, info_undefine},
- {"update-device", cmdUpdateDevice, opts_update_device, info_update_device},
- {"vcpucount", cmdVcpucount, opts_vcpucount, info_vcpucount},
- {"vcpuinfo", cmdVcpuinfo, opts_vcpuinfo, info_vcpuinfo},
- {"vcpupin", cmdVcpupin, opts_vcpupin, info_vcpupin},
- {"version", cmdVersion, NULL, info_version},
- {"vncdisplay", cmdVNCDisplay, opts_vncdisplay, info_vncdisplay},
- {NULL, NULL, NULL, NULL}
+ {"cpu-baseline", cmdCPUBaseline, opts_cpu_baseline, info_cpu_baseline, 0},
+ {"cpu-compare", cmdCPUCompare, opts_cpu_compare, info_cpu_compare, 0},
+ {"create", cmdCreate, opts_create, info_create, 0},
+ {"define", cmdDefine, opts_define, info_define, 0},
+ {"destroy", cmdDestroy, opts_destroy, info_destroy, 0},
+ {"detach-device", cmdDetachDevice, opts_detach_device,
+ info_detach_device, 0},
+ {"detach-disk", cmdDetachDisk, opts_detach_disk, info_detach_disk, 0},
+ {"detach-interface", cmdDetachInterface, opts_detach_interface,
+ info_detach_interface, 0},
+ {"domid", cmdDomid, opts_domid, info_domid, 0},
+ {"domjobabort", cmdDomjobabort, opts_domjobabort, info_domjobabort, 0},
+ {"domjobinfo", cmdDomjobinfo, opts_domjobinfo, info_domjobinfo, 0},
+ {"domname", cmdDomname, opts_domname, info_domname, 0},
+ {"domuuid", cmdDomuuid, opts_domuuid, info_domuuid, 0},
+ {"domxml-from-native", cmdDomXMLFromNative, opts_domxmlfromnative,
+ info_domxmlfromnative, 0},
+ {"domxml-to-native", cmdDomXMLToNative, opts_domxmltonative,
+ info_domxmltonative, 0},
+ {"dump", cmdDump, opts_dump, info_dump, 0},
+ {"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml, 0},
+ {"edit", cmdEdit, opts_edit, info_edit, 0},
+ {"managedsave", cmdManagedSave, opts_managedsave, info_managedsave, 0},
+ {"managedsave-remove", cmdManagedSaveRemove, opts_managedsaveremove,
+ info_managedsaveremove, 0},
+ {"maxvcpus", cmdMaxvcpus, opts_maxvcpus, info_maxvcpus, 0},
+ {"memtune", cmdMemtune, opts_memtune, info_memtune, 0},
+ {"migrate", cmdMigrate, opts_migrate, info_migrate, 0},
+ {"migrate-setmaxdowntime", cmdMigrateSetMaxDowntime,
+ opts_migrate_setmaxdowntime, info_migrate_setmaxdowntime, 0},
+ {"reboot", cmdReboot, opts_reboot, info_reboot, 0},
+ {"restore", cmdRestore, opts_restore, info_restore, 0},
+ {"resume", cmdResume, opts_resume, info_resume, 0},
+ {"save", cmdSave, opts_save, info_save, 0},
+ {"schedinfo", cmdSchedinfo, opts_schedinfo, info_schedinfo, 0},
+ {"setmaxmem", cmdSetmaxmem, opts_setmaxmem, info_setmaxmem, 0},
+ {"setmem", cmdSetmem, opts_setmem, info_setmem, 0},
+ {"setvcpus", cmdSetvcpus, opts_setvcpus, info_setvcpus, 0},
+ {"shutdown", cmdShutdown, opts_shutdown, info_shutdown, 0},
+ {"start", cmdStart, opts_start, info_start, 0},
+ {"suspend", cmdSuspend, opts_suspend, info_suspend, 0},
+ {"ttyconsole", cmdTTYConsole, opts_ttyconsole, info_ttyconsole, 0},
+ {"undefine", cmdUndefine, opts_undefine, info_undefine, 0},
+ {"update-device", cmdUpdateDevice, opts_update_device,
+ info_update_device, 0},
+ {"vcpucount", cmdVcpucount, opts_vcpucount, info_vcpucount, 0},
+ {"vcpuinfo", cmdVcpuinfo, opts_vcpuinfo, info_vcpuinfo, 0},
+ {"vcpupin", cmdVcpupin, opts_vcpupin, info_vcpupin, 0},
+ {"version", cmdVersion, NULL, info_version, 0},
+ {"vncdisplay", cmdVNCDisplay, opts_vncdisplay, info_vncdisplay, 0},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdDef domMonitoringCmds[] = {
- {"domblkinfo", cmdDomblkinfo, opts_domblkinfo, info_domblkinfo},
- {"domblkstat", cmdDomblkstat, opts_domblkstat, info_domblkstat},
- {"domifstat", cmdDomIfstat, opts_domifstat, info_domifstat},
- {"dominfo", cmdDominfo, opts_dominfo, info_dominfo},
- {"dommemstat", cmdDomMemStat, opts_dommemstat, info_dommemstat},
- {"domstate", cmdDomstate, opts_domstate, info_domstate},
- {"list", cmdList, opts_list, info_list},
- {NULL, NULL, NULL, NULL}
+ {"domblkinfo", cmdDomblkinfo, opts_domblkinfo, info_domblkinfo, 0},
+ {"domblkstat", cmdDomblkstat, opts_domblkstat, info_domblkstat, 0},
+ {"domifstat", cmdDomIfstat, opts_domifstat, info_domifstat, 0},
+ {"dominfo", cmdDominfo, opts_dominfo, info_dominfo, 0},
+ {"dommemstat", cmdDomMemStat, opts_dommemstat, info_dommemstat, 0},
+ {"domstate", cmdDomstate, opts_domstate, info_domstate, 0},
+ {"list", cmdList, opts_list, info_list, 0},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdDef storagePoolCmds[] = {
{"find-storage-pool-sources-as", cmdPoolDiscoverSourcesAs,
- opts_find_storage_pool_sources_as, info_find_storage_pool_sources_as},
+ opts_find_storage_pool_sources_as, info_find_storage_pool_sources_as, 0},
{"find-storage-pool-sources", cmdPoolDiscoverSources,
- opts_find_storage_pool_sources, info_find_storage_pool_sources},
- {"pool-autostart", cmdPoolAutostart, opts_pool_autostart, info_pool_autostart},
- {"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build},
- {"pool-create-as", cmdPoolCreateAs, opts_pool_X_as, info_pool_create_as},
- {"pool-create", cmdPoolCreate, opts_pool_create, info_pool_create},
- {"pool-define-as", cmdPoolDefineAs, opts_pool_X_as, info_pool_define_as},
- {"pool-define", cmdPoolDefine, opts_pool_define, info_pool_define},
- {"pool-delete", cmdPoolDelete, opts_pool_delete, info_pool_delete},
- {"pool-destroy", cmdPoolDestroy, opts_pool_destroy, info_pool_destroy},
- {"pool-dumpxml", cmdPoolDumpXML, opts_pool_dumpxml, info_pool_dumpxml},
- {"pool-edit", cmdPoolEdit, opts_pool_edit, info_pool_edit},
- {"pool-info", cmdPoolInfo, opts_pool_info, info_pool_info},
- {"pool-list", cmdPoolList, opts_pool_list, info_pool_list},
- {"pool-name", cmdPoolName, opts_pool_name, info_pool_name},
- {"pool-refresh", cmdPoolRefresh, opts_pool_refresh, info_pool_refresh},
- {"pool-start", cmdPoolStart, opts_pool_start, info_pool_start},
- {"pool-undefine", cmdPoolUndefine, opts_pool_undefine, info_pool_undefine},
- {"pool-uuid", cmdPoolUuid, opts_pool_uuid, info_pool_uuid},
- {NULL, NULL, NULL, NULL}
+ opts_find_storage_pool_sources, info_find_storage_pool_sources, 0},
+ {"pool-autostart", cmdPoolAutostart, opts_pool_autostart,
+ info_pool_autostart, 0},
+ {"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build, 0},
+ {"pool-create-as", cmdPoolCreateAs, opts_pool_X_as, info_pool_create_as, 0},
+ {"pool-create", cmdPoolCreate, opts_pool_create, info_pool_create, 0},
+ {"pool-define-as", cmdPoolDefineAs, opts_pool_X_as, info_pool_define_as, 0},
+ {"pool-define", cmdPoolDefine, opts_pool_define, info_pool_define, 0},
+ {"pool-delete", cmdPoolDelete, opts_pool_delete, info_pool_delete, 0},
+ {"pool-destroy", cmdPoolDestroy, opts_pool_destroy, info_pool_destroy, 0},
+ {"pool-dumpxml", cmdPoolDumpXML, opts_pool_dumpxml, info_pool_dumpxml, 0},
+ {"pool-edit", cmdPoolEdit, opts_pool_edit, info_pool_edit, 0},
+ {"pool-info", cmdPoolInfo, opts_pool_info, info_pool_info, 0},
+ {"pool-list", cmdPoolList, opts_pool_list, info_pool_list, 0},
+ {"pool-name", cmdPoolName, opts_pool_name, info_pool_name, 0},
+ {"pool-refresh", cmdPoolRefresh, opts_pool_refresh, info_pool_refresh, 0},
+ {"pool-start", cmdPoolStart, opts_pool_start, info_pool_start, 0},
+ {"pool-undefine", cmdPoolUndefine, opts_pool_undefine,
+ info_pool_undefine, 0},
+ {"pool-uuid", cmdPoolUuid, opts_pool_uuid, info_pool_uuid, 0},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdDef storageVolCmds[] = {
- {"vol-clone", cmdVolClone, opts_vol_clone, info_vol_clone},
- {"vol-create-as", cmdVolCreateAs, opts_vol_create_as, info_vol_create_as},
- {"vol-create", cmdVolCreate, opts_vol_create, info_vol_create},
- {"vol-create-from", cmdVolCreateFrom, opts_vol_create_from, info_vol_create_from},
- {"vol-delete", cmdVolDelete, opts_vol_delete, info_vol_delete},
- {"vol-dumpxml", cmdVolDumpXML, opts_vol_dumpxml, info_vol_dumpxml},
- {"vol-info", cmdVolInfo, opts_vol_info, info_vol_info},
- {"vol-key", cmdVolKey, opts_vol_key, info_vol_key},
- {"vol-list", cmdVolList, opts_vol_list, info_vol_list},
- {"vol-name", cmdVolName, opts_vol_name, info_vol_name},
- {"vol-path", cmdVolPath, opts_vol_path, info_vol_path},
- {"vol-pool", cmdVolPool, opts_vol_pool, info_vol_pool},
- {"vol-wipe", cmdVolWipe, opts_vol_wipe, info_vol_wipe},
- {NULL, NULL, NULL, NULL}
+ {"vol-clone", cmdVolClone, opts_vol_clone, info_vol_clone, 0},
+ {"vol-create-as", cmdVolCreateAs, opts_vol_create_as,
+ info_vol_create_as, 0},
+ {"vol-create", cmdVolCreate, opts_vol_create, info_vol_create, 0},
+ {"vol-create-from", cmdVolCreateFrom, opts_vol_create_from,
+ info_vol_create_from, 0},
+ {"vol-delete", cmdVolDelete, opts_vol_delete, info_vol_delete, 0},
+ {"vol-dumpxml", cmdVolDumpXML, opts_vol_dumpxml, info_vol_dumpxml, 0},
+ {"vol-info", cmdVolInfo, opts_vol_info, info_vol_info, 0},
+ {"vol-key", cmdVolKey, opts_vol_key, info_vol_key, 0},
+ {"vol-list", cmdVolList, opts_vol_list, info_vol_list, 0},
+ {"vol-name", cmdVolName, opts_vol_name, info_vol_name, 0},
+ {"vol-path", cmdVolPath, opts_vol_path, info_vol_path, 0},
+ {"vol-pool", cmdVolPool, opts_vol_pool, info_vol_pool, 0},
+ {"vol-wipe", cmdVolWipe, opts_vol_wipe, info_vol_wipe, 0},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdDef networkCmds[] = {
- {"net-autostart", cmdNetworkAutostart, opts_network_autostart, info_network_autostart},
- {"net-create", cmdNetworkCreate, opts_network_create, info_network_create},
- {"net-define", cmdNetworkDefine, opts_network_define, info_network_define},
- {"net-destroy", cmdNetworkDestroy, opts_network_destroy, info_network_destroy},
- {"net-dumpxml", cmdNetworkDumpXML, opts_network_dumpxml, info_network_dumpxml},
- {"net-edit", cmdNetworkEdit, opts_network_edit, info_network_edit},
- {"net-info", cmdNetworkInfo, opts_network_info, info_network_info},
- {"net-list", cmdNetworkList, opts_network_list, info_network_list},
- {"net-name", cmdNetworkName, opts_network_name, info_network_name},
- {"net-start", cmdNetworkStart, opts_network_start, info_network_start},
- {"net-undefine", cmdNetworkUndefine, opts_network_undefine, info_network_undefine},
- {"net-uuid", cmdNetworkUuid, opts_network_uuid, info_network_uuid},
- {NULL, NULL, NULL, NULL}
+ {"net-autostart", cmdNetworkAutostart, opts_network_autostart,
+ info_network_autostart, 0},
+ {"net-create", cmdNetworkCreate, opts_network_create,
+ info_network_create, 0},
+ {"net-define", cmdNetworkDefine, opts_network_define,
+ info_network_define, 0},
+ {"net-destroy", cmdNetworkDestroy, opts_network_destroy,
+ info_network_destroy, 0},
+ {"net-dumpxml", cmdNetworkDumpXML, opts_network_dumpxml,
+ info_network_dumpxml, 0},
+ {"net-edit", cmdNetworkEdit, opts_network_edit, info_network_edit, 0},
+ {"net-info", cmdNetworkInfo, opts_network_info, info_network_info, 0},
+ {"net-list", cmdNetworkList, opts_network_list, info_network_list, 0},
+ {"net-name", cmdNetworkName, opts_network_name, info_network_name, 0},
+ {"net-start", cmdNetworkStart, opts_network_start, info_network_start, 0},
+ {"net-undefine", cmdNetworkUndefine, opts_network_undefine,
+ info_network_undefine, 0},
+ {"net-uuid", cmdNetworkUuid, opts_network_uuid, info_network_uuid, 0},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdDef nodedevCmds[] = {
- {"nodedev-create", cmdNodeDeviceCreate, opts_node_device_create, info_node_device_create},
- {"nodedev-destroy", cmdNodeDeviceDestroy, opts_node_device_destroy, info_node_device_destroy},
- {"nodedev-dettach", cmdNodeDeviceDettach, opts_node_device_dettach, info_node_device_dettach},
- {"nodedev-dumpxml", cmdNodeDeviceDumpXML, opts_node_device_dumpxml, info_node_device_dumpxml},
- {"nodedev-list", cmdNodeListDevices, opts_node_list_devices, info_node_list_devices},
- {"nodedev-reattach", cmdNodeDeviceReAttach, opts_node_device_reattach, info_node_device_reattach},
- {"nodedev-reset", cmdNodeDeviceReset, opts_node_device_reset, info_node_device_reset},
- {NULL, NULL, NULL, NULL}
+ {"nodedev-create", cmdNodeDeviceCreate, opts_node_device_create,
+ info_node_device_create, 0},
+ {"nodedev-destroy", cmdNodeDeviceDestroy, opts_node_device_destroy,
+ info_node_device_destroy, 0},
+ {"nodedev-dettach", cmdNodeDeviceDettach, opts_node_device_dettach,
+ info_node_device_dettach, 0},
+ {"nodedev-dumpxml", cmdNodeDeviceDumpXML, opts_node_device_dumpxml,
+ info_node_device_dumpxml, 0},
+ {"nodedev-list", cmdNodeListDevices, opts_node_list_devices,
+ info_node_list_devices, 0},
+ {"nodedev-reattach", cmdNodeDeviceReAttach, opts_node_device_reattach,
+ info_node_device_reattach, 0},
+ {"nodedev-reset", cmdNodeDeviceReset, opts_node_device_reset,
+ info_node_device_reset, 0},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdDef ifaceCmds[] = {
- {"iface-define", cmdInterfaceDefine, opts_interface_define, info_interface_define},
- {"iface-destroy", cmdInterfaceDestroy, opts_interface_destroy, info_interface_destroy},
- {"iface-dumpxml", cmdInterfaceDumpXML, opts_interface_dumpxml, info_interface_dumpxml},
- {"iface-edit", cmdInterfaceEdit, opts_interface_edit, info_interface_edit},
- {"iface-list", cmdInterfaceList, opts_interface_list, info_interface_list},
- {"iface-mac", cmdInterfaceMAC, opts_interface_mac, info_interface_mac},
- {"iface-name", cmdInterfaceName, opts_interface_name, info_interface_name},
- {"iface-start", cmdInterfaceStart, opts_interface_start, info_interface_start},
- {"iface-undefine", cmdInterfaceUndefine, opts_interface_undefine, info_interface_undefine},
- {NULL, NULL, NULL, NULL}
+ {"iface-define", cmdInterfaceDefine, opts_interface_define,
+ info_interface_define, 0},
+ {"iface-destroy", cmdInterfaceDestroy, opts_interface_destroy,
+ info_interface_destroy, 0},
+ {"iface-dumpxml", cmdInterfaceDumpXML, opts_interface_dumpxml,
+ info_interface_dumpxml, 0},
+ {"iface-edit", cmdInterfaceEdit, opts_interface_edit,
+ info_interface_edit, 0},
+ {"iface-list", cmdInterfaceList, opts_interface_list,
+ info_interface_list, 0},
+ {"iface-mac", cmdInterfaceMAC, opts_interface_mac,
+ info_interface_mac, 0},
+ {"iface-name", cmdInterfaceName, opts_interface_name,
+ info_interface_name, 0},
+ {"iface-start", cmdInterfaceStart, opts_interface_start,
+ info_interface_start, 0},
+ {"iface-undefine", cmdInterfaceUndefine, opts_interface_undefine,
+ info_interface_undefine, 0},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdDef nwfilterCmds[] = {
- {"nwfilter-define", cmdNWFilterDefine, opts_nwfilter_define, info_nwfilter_define},
- {"nwfilter-dumpxml", cmdNWFilterDumpXML, opts_nwfilter_dumpxml, info_nwfilter_dumpxml},
- {"nwfilter-edit", cmdNWFilterEdit, opts_nwfilter_edit, info_nwfilter_edit},
- {"nwfilter-list", cmdNWFilterList, opts_nwfilter_list, info_nwfilter_list},
- {"nwfilter-undefine", cmdNWFilterUndefine, opts_nwfilter_undefine, info_nwfilter_undefine},
- {NULL, NULL, NULL, NULL}
+ {"nwfilter-define", cmdNWFilterDefine, opts_nwfilter_define,
+ info_nwfilter_define, 0},
+ {"nwfilter-dumpxml", cmdNWFilterDumpXML, opts_nwfilter_dumpxml,
+ info_nwfilter_dumpxml, 0},
+ {"nwfilter-edit", cmdNWFilterEdit, opts_nwfilter_edit,
+ info_nwfilter_edit, 0},
+ {"nwfilter-list", cmdNWFilterList, opts_nwfilter_list,
+ info_nwfilter_list, 0},
+ {"nwfilter-undefine", cmdNWFilterUndefine, opts_nwfilter_undefine,
+ info_nwfilter_undefine, 0},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdDef secretCmds[] = {
- {"secret-define", cmdSecretDefine, opts_secret_define, info_secret_define},
- {"secret-dumpxml", cmdSecretDumpXML, opts_secret_dumpxml, info_secret_dumpxml},
- {"secret-get-value", cmdSecretGetValue, opts_secret_get_value, info_secret_get_value},
- {"secret-list", cmdSecretList, NULL, info_secret_list},
- {"secret-set-value", cmdSecretSetValue, opts_secret_set_value, info_secret_set_value},
- {"secret-undefine", cmdSecretUndefine, opts_secret_undefine, info_secret_undefine},
- {NULL, NULL, NULL, NULL}
+ {"secret-define", cmdSecretDefine, opts_secret_define,
+ info_secret_define, 0},
+ {"secret-dumpxml", cmdSecretDumpXML, opts_secret_dumpxml,
+ info_secret_dumpxml, 0},
+ {"secret-get-value", cmdSecretGetValue, opts_secret_get_value,
+ info_secret_get_value, 0},
+ {"secret-list", cmdSecretList, NULL, info_secret_list, 0},
+ {"secret-set-value", cmdSecretSetValue, opts_secret_set_value,
+ info_secret_set_value, 0},
+ {"secret-undefine", cmdSecretUndefine, opts_secret_undefine,
+ info_secret_undefine, 0},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdDef virshCmds[] = {
#ifndef WIN32
- {"cd", cmdCd, opts_cd, info_cd},
+ {"cd", cmdCd, opts_cd, info_cd, VSH_CMD_FLAG_NOCONNECT},
#endif
- {"echo", cmdEcho, opts_echo, info_echo},
- {"exit", cmdQuit, NULL, info_quit},
- {"help", cmdHelp, opts_help, info_help},
+ {"echo", cmdEcho, opts_echo, info_echo, VSH_CMD_FLAG_NOCONNECT},
+ {"exit", cmdQuit, NULL, info_quit, VSH_CMD_FLAG_NOCONNECT},
+ {"help", cmdHelp, opts_help, info_help, VSH_CMD_FLAG_NOCONNECT},
#ifndef WIN32
- {"pwd", cmdPwd, NULL, info_pwd},
+ {"pwd", cmdPwd, NULL, info_pwd, VSH_CMD_FLAG_NOCONNECT},
#endif
- {"quit", cmdQuit, NULL, info_quit},
- {NULL, NULL, NULL, NULL}
+ {"quit", cmdQuit, NULL, info_quit, VSH_CMD_FLAG_NOCONNECT},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdDef snapshotCmds[] = {
- {"snapshot-create", cmdSnapshotCreate, opts_snapshot_create, info_snapshot_create},
- {"snapshot-current", cmdSnapshotCurrent, opts_snapshot_current, info_snapshot_current},
- {"snapshot-delete", cmdSnapshotDelete, opts_snapshot_delete, info_snapshot_delete},
- {"snapshot-dumpxml", cmdSnapshotDumpXML, opts_snapshot_dumpxml, info_snapshot_dumpxml},
- {"snapshot-list", cmdSnapshotList, opts_snapshot_list, info_snapshot_list},
- {"snapshot-revert", cmdDomainSnapshotRevert, opts_snapshot_revert, info_snapshot_revert},
- {NULL, NULL, NULL, NULL}
+ {"snapshot-create", cmdSnapshotCreate, opts_snapshot_create,
+ info_snapshot_create, 0},
+ {"snapshot-current", cmdSnapshotCurrent, opts_snapshot_current,
+ info_snapshot_current, 0},
+ {"snapshot-delete", cmdSnapshotDelete, opts_snapshot_delete,
+ info_snapshot_delete, 0},
+ {"snapshot-dumpxml", cmdSnapshotDumpXML, opts_snapshot_dumpxml,
+ info_snapshot_dumpxml, 0},
+ {"snapshot-list", cmdSnapshotList, opts_snapshot_list,
+ info_snapshot_list, 0},
+ {"snapshot-revert", cmdDomainSnapshotRevert, opts_snapshot_revert,
+ info_snapshot_revert, 0},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdDef hostAndHypervisorCmds[] = {
- {"capabilities", cmdCapabilities, NULL, info_capabilities},
- {"connect", cmdConnect, opts_connect, info_connect},
- {"freecell", cmdFreecell, opts_freecell, info_freecell},
- {"hostname", cmdHostname, NULL, info_hostname},
- {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo},
- {"qemu-monitor-command", cmdQemuMonitorCommand, opts_qemu_monitor_command, info_qemu_monitor_command},
- {"sysinfo", cmdSysinfo, NULL, info_sysinfo},
- {"uri", cmdURI, NULL, info_uri},
- {NULL, NULL, NULL, NULL}
+ {"capabilities", cmdCapabilities, NULL, info_capabilities, 0},
+ {"connect", cmdConnect, opts_connect, info_connect,
+ VSH_CMD_FLAG_NOCONNECT},
+ {"freecell", cmdFreecell, opts_freecell, info_freecell, 0},
+ {"hostname", cmdHostname, NULL, info_hostname, 0},
+ {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0},
+ {"qemu-monitor-command", cmdQemuMonitorCommand, opts_qemu_monitor_command,
+ info_qemu_monitor_command, 0},
+ {"sysinfo", cmdSysinfo, NULL, info_sysinfo, 0},
+ {"uri", cmdURI, NULL, info_uri, 0},
+ {NULL, NULL, NULL, NULL, 0}
};
static const vshCmdGrp cmdGroups[] = {
@@ -11380,7 +11447,8 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd)
struct timeval before, after;
bool enable_timing = ctl->timing;
- if ((ctl->conn == NULL) || (disconnected != 0))
+ if ((ctl->conn == NULL || disconnected) &&
+ !(cmd->def->flags & VSH_CMD_FLAG_NOCONNECT))
vshReconnect(ctl);
if (enable_timing)
@@ -11840,19 +11908,22 @@ vshInit(vshControl *ctl)
if (virEventRegisterDefaultImpl() < 0)
return FALSE;
- ctl->conn = virConnectOpenAuth(ctl->name,
- virConnectAuthPtrDefault,
- ctl->readonly ? VIR_CONNECT_RO : 0);
-
+ if (ctl->name) {
+ ctl->conn = virConnectOpenAuth(ctl->name,
+ virConnectAuthPtrDefault,
+ ctl->readonly ? VIR_CONNECT_RO : 0);
- /* This is not necessarily fatal. All the individual commands check
- * vshConnectionUsability, except ones which don't need a connection
- * such as "help".
- */
- if (!ctl->conn) {
- virshReportError(ctl);
- vshError(ctl, "%s", _("failed to connect to the hypervisor"));
- return FALSE;
+ /* Connecting to a named connection must succeed, but we delay
+ * connecting to the default connection until we need it
+ * (since the first command might be 'connect' which allows a
+ * non-default connection, or might be 'help' which needs no
+ * connection).
+ */
+ if (!ctl->conn) {
+ virshReportError(ctl);
+ vshError(ctl, "%s", _("failed to connect to the hypervisor"));
+ return FALSE;
+ }
}
return TRUE;
--
1.7.4
13 years, 8 months
[libvirt] [PATCH v2] domain.rng vs. formatdomain.html#elementsUSB
by Philipp Hahn
The Relax-NG schema for domains regarding <hostdev> doesn't match what's
implemented in src/conf/domain_conf.c#virDomainHostdevDefFormat(): The
implementation only requires @type, but the schema currently either
required none or all three attributes (@mode, @type, and @managed) to be
defined together, because they are declared in the same
<optional)-section. (@managed is currently even undocumented on
<http://libvirt.org/formatdomain.html#elementsUSB>).
Thus the following minimal <hostdev>-example fails to validate:
<domain type='test'>
<name>N</name>
<memory>4096</memory>
<bootloader>/bin/false</bootloader>
<os>
<type arch='x86_64' machine='xenpv'>linux</type>
</os>
<devices>
<hostdev type='pci'>
<source>
<address bus='0x06' slot='0x00' function='0x0'/>
</source>
</hostdev>
</devices>
</domain>
The schema is changed to match the current implementation:
1. @mode is optional (which defaults to 'subsystem')
2. @type is required
3. @managed is optional (which defaults to 'no')
Signed-off-by: Philipp Hahn <hahn(a)univention.de>
---
docs/schemas/domain.rng | 14 ++++++++------
1 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index 8b215f3..21c4380 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -1731,12 +1731,14 @@
<value>capabilities</value>
</choice>
</attribute>
- <attribute name="type">
- <choice>
- <value>usb</value>
- <value>pci</value>
- </choice>
- </attribute>
+ </optional>
+ <attribute name="type">
+ <choice>
+ <value>usb</value>
+ <value>pci</value>
+ </choice>
+ </attribute>
+ <optional>
<attribute name="managed">
<choice>
<value>yes</value>
--
1.7.1
13 years, 8 months
[libvirt] [PATCH] audit: eliminate potential null pointer deref when auditing macvtap devices
by Laine Stump
The newly added call to qemuAuditNetDevice in qemuPhysIfaceConnect was
assuming that res_ifname (the name of the macvtap device) was always
valid, but this isn't the case. If openMacvtapTap fails, it always
returns NULL, which would result in a segv.
Since the audit log only needs a record of devices that are actually
sent to qemu, and a failure to open the macvtap device means that no
device will be sent to qemu, we can solve this problem by only doing
the audit if openMacvtapTap is successful (in which case res_ifname is
guaranteed valid).
---
src/qemu/qemu_command.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8ca656a..72f55d0 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -128,8 +128,8 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
net->data.direct.mode, vnet_hdr, def->uuid,
&net->data.direct.virtPortProfile, &res_ifname,
vmop);
- qemuAuditNetDevice(def, net, res_ifname, rc >= 0);
if (rc >= 0) {
+ qemuAuditNetDevice(def, net, res_ifname, true);
VIR_FREE(net->ifname);
net->ifname = res_ifname;
}
--
1.7.3.4
13 years, 8 months
[libvirt] [PATCH] python: Use hardcoded python path in libvirt.py
by Jiri Denemark
This partially reverts (and fixes that part in a different way) commit
e4384459c93e3e786aa483c7f077d1d22148f689, which replaced all
examples or scripts used during build to generate other files.
However, python bindings module is compiled and linked against a
specific python discovered or explicitly provided in configure phase.
Thus libvirt.py which is generated and installed into the system we
should use the same python binary for which the module has been built.
The hunk in Makefile.am replaces $(srcdir) with $(PYTHON), which might
seem wrong but it is not. generator.py didn't use any of its command
line arguments so passing $(srcdir) to it was redundant.
---
python/Makefile.am | 2 +-
python/generator.py | 7 ++++++-
python/libvirt-override.py | 5 -----
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/python/Makefile.am b/python/Makefile.am
index eda2866..432ad70 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -53,7 +53,7 @@ GENERATED= libvirt-export.c \
libvirt.py
generated.stamp: $(srcdir)/$(GENERATE) $(API_DESC)
- $(PYTHON) $(srcdir)/$(GENERATE) $(srcdir)
+ $(PYTHON) $(srcdir)/$(GENERATE) $(PYTHON)
touch $@
$(GENERATED): generated.stamp
diff --git a/python/generator.py b/python/generator.py
index 6f4bb40..4fa4f65 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -14,6 +14,11 @@ import re
if __name__ == "__main__":
# launched as a script
srcPref = os.path.dirname(sys.argv[0])
+ if len(sys.argv) > 1:
+ python = sys.argv[1]
+ else:
+ print "Python binary not specified"
+ sys.exit(1)
else:
# imported
srcPref = os.path.dirname(__file__)
@@ -1012,7 +1017,7 @@ def buildWrappers():
classes = open("libvirt.py", "w")
extra = open(os.path.join(srcPref,"libvirt-override.py"), "r")
- classes.write("#!/usr/bin/env python\n")
+ classes.write("#! " + python + " -i\n")
classes.write("#\n")
classes.write("# WARNING WARNING WARNING WARNING\n")
classes.write("#\n")
diff --git a/python/libvirt-override.py b/python/libvirt-override.py
index 909ebe3..d544a0e 100644
--- a/python/libvirt-override.py
+++ b/python/libvirt-override.py
@@ -2,11 +2,6 @@
# Manually written part of python bindings for libvirt
#
-# Specify -i commandline option after python was started
-if __name__ == "__main__":
- import os
- os.environ["PYTHONINSPECT"] = "1"
-
# On cygwin, the DLL is called cygvirtmod.dll
try:
import libvirtmod
--
1.7.4.1
13 years, 8 months
[libvirt] [PATCH] virsh: Allow starting domains by UUID
by Jiri Denemark
---
tools/libvirt-guests.init.sh | 2 +-
tools/virsh.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/libvirt-guests.init.sh b/tools/libvirt-guests.init.sh
index 8823d06..e37e55f 100644
--- a/tools/libvirt-guests.init.sh
+++ b/tools/libvirt-guests.init.sh
@@ -164,7 +164,7 @@ start() {
if $guest_running; then
gettext "already active"; echo
else
- retval run_virsh $uri start "$name" >/dev/null && \
+ retval run_virsh $uri start "$guest" >/dev/null && \
gettext "done"; echo
fi
fi
diff --git a/tools/virsh.c b/tools/virsh.c
index a5e9c4f..b42aac4 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1402,7 +1402,8 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn))
return FALSE;
- if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL, VSH_BYNAME)))
+ if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
+ VSH_BYNAME | VSH_BYUUID)))
return FALSE;
if (virDomainGetID(dom) != (unsigned int)-1) {
--
1.7.4.1
13 years, 8 months
[libvirt] [PATCH] network driver: don't send default route to clients on isolated networks
by Laine Stump
Normally dnsmasq will send a default route (the address of the host in
the network definition) to any client requesting an address via
DHCP. On an isolated network this makes no sense, as we have iptables
to prevent any traffic going out via that interface, so anything sent
that way would be dropped anyway.
This extra/unusable default route becomes problematic if you have
setup a guest with multiple network interfaces, with one connected to
an isolated network and another that provides connectivity to the
outside (example - one interface directly connecting to a physical
interface via macvtap, with a second connected to an isolated network
so that the host and guest can communicate (macvtap doesn't support
guest<->host communication without an external switch that supports
vepa, or reflecting all traffic back)). In this case, if the guest
chooses the default route of the isolated network, the guest will not
be able to get network traffic beyond the host.
To prevent dnsmasq from sending a default route, you can tell it to
send 0 bytes of data for the default route option (option number 3)
with --dhcp-option=3 (normally the data to send for the option would
follow the option number; no extra data means "don't send this option").
I have checked on RHEL5 (a good representative of the oldest supported
libvirt platforms) and its version of dnsmasq (2.45) does support
--dhcp-option, so this shouldn't create any compatibility problems.
---
src/network/bridge_driver.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index ca2ae8d..6a02df1 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -490,6 +490,13 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
"--except-interface", "lo",
NULL);
+ /* If this is an isolated network, set the default route option
+ * (3) to be empty to avoid setting a default route that's
+ * guaranteed to not work.
+ */
+ if (network->def->forwardType == VIR_NETWORK_FORWARD_NONE)
+ virCommandAddArg(cmd, "--dhcp-option=3");
+
/*
* --interface does not actually work with dnsmasq < 2.47,
* due to DAD for ipv6 addresses on the interface.
--
1.7.3.4
13 years, 8 months