[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Nbd] nbd-client: (no?) way to find out connected hosts



On Mon, Mar 20, 2017 at 02:24:50AM +0100, Stefan Tauner wrote:
> Hi,
> I am writing backup scripts around nbd-client currently and ran into
> an issue. I would like to be able to determine the remote site of a
> given /dev/nbd*. I could probably hack something with pgrep
> nbd-client and the corresponding /proc/$pid/cmdlines but I would
> definitely prefer a built-in solution that won't explode now and then ;)

Did you consider parsing the output of 'netstat' (or the symlinks under
/proc/$pid/fd) to see where the sockets point?

Otherwise, there's just no way to do that reliably currently. When a
device is running, nbd-client is in IO-wait state and remains there
until the device disconnects, so you can't send it any queries. Asking
the kernel would be possible, but there's no API for that.

At any rate, you don't need to pgrep -- there's nbd-client -c which
tells you the PID of the process that holds a device, if connected.

> Also, it would be nice to be able to call nbd-client so that it uses
> the first free /dev/nbd* if any (similar to losetup -f file).

This will be available with the new netlink interface that Josef wrote
recently, but it's not been merged into Linus' tree AFAICS.

-- 
< ron> I mean, the main *practical* problem with C++, is there's like a dozen
       people in the world who think they really understand all of its rules,
       and pretty much all of them are just lying to themselves too.
 -- #debian-devel, OFTC, 2016-02-12



Reply to: