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


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to