]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: conf: add setup for automatic port allocation for pull-mode backup NBD servers
authorLucas Amaral <lucaaamaral@gmail.com>
Mon, 23 Feb 2026 22:52:22 +0000 (19:52 -0300)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 20 Mar 2026 13:32:14 +0000 (14:32 +0100)
Add backup_port_min and backup_port_max configuration options to
qemu.conf, defaulting to 10809-10872 (10809 is the IANA-assigned
NBD port; range of 64 matches the migration port pattern).

Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/libvirtd_qemu.aug
src/qemu/qemu.conf.in
src/qemu/qemu_conf.c
src/qemu/qemu_conf.h
src/qemu/test_libvirtd_qemu.aug.in

index 0286582169fa4d42ce966cfdf0729cb74529f993..eb790d48bed78e279076d6fc9609de0b538c4937 100644 (file)
@@ -146,6 +146,8 @@ module Libvirtd_qemu =
                  | int_entry "migration_port_min"
                  | int_entry "migration_port_max"
                  | str_entry "migration_host"
+                 | int_entry "backup_port_min"
+                 | int_entry "backup_port_max"
 
    let log_entry = bool_entry "log_timestamp"
 
index 2d1c67034d4eb3c5471f2c77cd6b4179a6a05f49..5eacd700221db58f6353a8dc8a80ff1738dd56bb 100644 (file)
 #migration_port_max = 49215
 
 
+# Port range used for automatic allocation of NBD backup server ports.
+# When a pull-mode backup is started without specifying a TCP port, a
+# port from this range will be assigned automatically. The NBD standard
+# port is 10809.
+#
+#backup_port_min = 10809
+#backup_port_max = 10872
+
+
 # Timestamp QEMU's log messages (if QEMU supports it)
 #
 # Defaults to 1.
index 3ea42da50260450ea76dbcf81161e28b13c3b747..d43e0c2b9780ae8b2c39ee8f7e317ed82358a988 100644 (file)
@@ -74,6 +74,9 @@ VIR_LOG_INIT("qemu.qemu_conf");
 #define QEMU_MIGRATION_PORT_MIN 49152
 #define QEMU_MIGRATION_PORT_MAX 49215
 
+#define QEMU_BACKUP_PORT_MIN 10809
+#define QEMU_BACKUP_PORT_MAX 10872
+
 VIR_ENUM_IMPL(virQEMUSchedCore,
               QEMU_SCHED_CORE_LAST,
               "none",
@@ -268,6 +271,9 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged,
     cfg->migrationPortMin = QEMU_MIGRATION_PORT_MIN;
     cfg->migrationPortMax = QEMU_MIGRATION_PORT_MAX;
 
+    cfg->backupPortMin = QEMU_BACKUP_PORT_MIN;
+    cfg->backupPortMax = QEMU_BACKUP_PORT_MAX;
+
     /* For privileged driver, try and find hugetlbfs mounts automatically.
      * Non-privileged driver requires admin to create a dir for the
      * user, chown it, and then let user configure it manually. */
@@ -989,6 +995,25 @@ virQEMUDriverConfigLoadNetworkEntry(virQEMUDriverConfig *cfg,
         return -1;
     }
 
+    if (virConfGetValueUInt(conf, "backup_port_min", &cfg->backupPortMin) < 0)
+        return -1;
+    if (cfg->backupPortMin <= 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("%1$s: backup_port_min: port must be greater than 0"),
+                        filename);
+        return -1;
+    }
+
+    if (virConfGetValueUInt(conf, "backup_port_max", &cfg->backupPortMax) < 0)
+        return -1;
+    if (cfg->backupPortMax > 65535 ||
+        cfg->backupPortMax < cfg->backupPortMin) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                        _("%1$s: backup_port_max: port must be between the minimal port %2$d and 65535"),
+                       filename, cfg->backupPortMin);
+        return -1;
+    }
+
     if (virConfGetValueString(conf, "migration_host", &cfg->migrateHost) < 0)
         return -1;
     virStringStripIPv6Brackets(cfg->migrateHost);
index aa2bac6891ea96f90c4edcbfc3e1ffb5494a8b33..af1e7ee503b07f396040e25e278e8f4f54fc7b0f 100644 (file)
@@ -241,6 +241,9 @@ struct _virQEMUDriverConfig {
     unsigned int migrationPortMin;
     unsigned int migrationPortMax;
 
+    unsigned int backupPortMin;
+    unsigned int backupPortMax;
+
     bool logTimestamp;
     bool stdioLogD;
 
index 82cfec3b4b57a75c81de039c81d01b10e0401d6b..2582c6a09c762cf60e397204a2c69e3527053a38 100644 (file)
@@ -110,6 +110,8 @@ module Test_libvirtd_qemu =
 { "migration_host" = "host.example.com" }
 { "migration_port_min" = "49152" }
 { "migration_port_max" = "49215" }
+{ "backup_port_min" = "10809" }
+{ "backup_port_max" = "10872" }
 { "log_timestamp" = "0" }
 { "nvram"
     { "1" = "/usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd" }