Hi,

On Tue, Oct 1, 2013 at 9:27 AM, Raphael Bauduin <[email protected]> wrote:

>
> How can I determine which is the first free nbd device?
>

By free do you mean not connected?


> Currently I have 2 ways to check if an device is connected: the first is
> calling file on the device and check if it is empty or not. The second is
> call lsblk and see if the device is in the list.
>

Neither of these distinguishes between connected and non-connected...


>
> Rather than looping over all nbd devices until I find one free to use, I
> wondered if there's a way to immediately get the first free nbd device.
>

Not directly, that I know of, but there are two ways to determine which
nbds are connected or not:

/proc/partitions lists only active nbds:

debian-i386~$ cat /proc/partitions
major minor  #blocks  name

   7        1     409600 loop1
   7        5    2560000 loop5
   8        0   16777216 sda
   8        1   16043008 sda1
   8        2          1 sda2
   8        5     731136 sda5
  11        0    1048575 sr0
   9        1     409588 md1
  43        5    2560000 nbd5

Also, the sysfs pid file is only present when the nbd is connected (i.e.,
an nbd-client is running):

debian-i386~$ cat /sys/block/nbd5/pid
18172

debian-i386~$ ls -l /sys/block/nbd0/pid
ls: cannot access /sys/block/nbd0/pid: No such file or directory

--
Paul
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk
_______________________________________________
Nbd-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nbd-general

Reply via email to