[pve-devel] [PATCH pve-common] added PVE::Tools::next_free_nbd_dev

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Aug 6 11:52:33 CEST 2015


This comes from pve-container and will be used in
qemu-server with cloudinit.
---
 src/PVE/Tools.pm | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index a7bcd35..9b6a3e4 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -740,6 +740,16 @@ sub next_spice_port {
     return next_unused_port(61000, 61099, $family);
 }
 
+sub next_free_nbd_dev {
+    for(my $i = 0;;$i++) {
+	my $dev = "/dev/nbd$i";
+	last if ! -b $dev;
+	next if -f "/sys/block/nbd$i/pid"; # busy
+	return $dev;
+    }
+    die "unable to find free nbd device\n";
+}
+
 # NOTE: NFS syscall can't be interrupted, so alarm does 
 # not work to provide timeouts.
 # from 'man nfs': "Only SIGKILL can interrupt a pending NFS operation"
-- 
2.1.4





More information about the pve-devel mailing list