diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf index 5fd6263c8fa73afc7cff74cf7b74817f862e9330..98383389809e4567e062232a6832cd4af220d464 100644 --- a/src/qemu/qemu.conf +++ b/src/qemu/qemu.conf @@ -424,3 +424,14 @@ # Defaults to -1. # #seccomp_sandbox = 1 + + +# Override the port range used for incoming migrations. +# +# Minimum must be greater than 0, however when QEMU is not running as root, +# setting the minimum to be lower than 1024 will not work. +# +# Maximum must not be greater than 65535. +# +#migration_port_min = 49152 +#migration_port_max = 49215 diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 1a41caf93f631d6dbe1434943603dec58353eb72..7896411019adabfc7804f303db237d0e0af7943a 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -225,6 +225,9 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) cfg->webSocketPortMin = QEMU_WEBSOCKET_PORT_MIN; cfg->webSocketPortMax = QEMU_WEBSOCKET_PORT_MAX; + cfg->migrationPortMin = QEMU_MIGRATION_PORT_MIN; + cfg->migrationPortMax = QEMU_MIGRATION_PORT_MAX; + #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R /* For privileged driver, try and find hugepage mount automatically. * Non-privileged driver requires admin to create a dir for the @@ -459,6 +462,24 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, goto cleanup; } + GET_VALUE_LONG("migration_port_min", cfg->migrationPortMin); + if (cfg->migrationPortMin <= 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("%s: migration_port_min: port must be greater than 0"), + filename); + goto cleanup; + } + + GET_VALUE_LONG("migration_port_max", cfg->migrationPortMax); + if (cfg->migrationPortMax > 65535 || + cfg->migrationPortMax < cfg->migrationPortMin) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("%s: migration_port_max: port must be between " + "the minimal port %d and 65535"), + filename, cfg->migrationPortMin); + goto cleanup; + } + p = virConfGetValue(conf, "user"); CHECK_TYPE("user", VIR_CONF_STRING); if (p && p->str && diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 3176085adcae50194cc66f75b3312b1291560cfa..409072fbbf9701d2cd6e9b038d887b1928e19a6c 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -155,6 +155,9 @@ struct _virQEMUDriverConfig { unsigned int keepAliveCount; int seccompSandbox; + + int migrationPortMin; + int migrationPortMax; }; /* Main driver state */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f22106a94efa176d715d4d4a14e02cb4b70a338a..be2cd68b16f3d06c4bdd443ea5462d456b8bc7db 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -688,8 +688,8 @@ qemuStateInitialize(bool privileged, goto error; if ((qemu_driver->migrationPorts = - virPortAllocatorNew(QEMU_MIGRATION_PORT_MIN, - QEMU_MIGRATION_PORT_MAX)) == NULL) + virPortAllocatorNew(cfg->migrationPortMin, + cfg->migrationPortMax)) == NULL) goto error; if (qemuSecurityInit(qemu_driver) < 0) diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in index ea770dc5a49fb341b89d328d505f56b29b46534f..42b9e863ea189347f93ce518512c8651ee59cc32 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -66,3 +66,5 @@ module Test_libvirtd_qemu = { "keepalive_interval" = "5" } { "keepalive_count" = "5" } { "seccomp_sandbox" = "1" } +{ "migration_port_min" = "1234" } +{ "migration_port_max" = "12345" }