6

Here's the situation. I have a video device /dev/video0 on a VMware Server and I want to access this device from within a virtual machine. However for whatever reason I can't connect the device directly to the VM, it must be connected to the host.

Since under unix philosophy everything really is just a file, can I share a device under /dev using NFS, Samba, sshfs or some other protocol between two hosts, so that a linux on one server can access devices on a different server?

Josh
  • 8,449

3 Answers3

9

No.

You can export a device file through NFS or some other network filesystems. But the meaning of the device file is dependent on the machine where you open it. If you export /dev/video0 over NFS from a server machine to a client machine, the client machine just sees “character device 81:0”, and interprets it as its own video capture device. The client machine doesn't even need to have the same device number assignment as the server; for example an OpenBSD client would see the same file as the pseudo-terminal driver, because that's what char 81:0 is under OpenBSD.

What you're asking for would be very nice, but also very hard. Every request on the client would have to be forwarded to the server and vice versa. There would have to be specific support in individual drivers. For example some drivers rely on shared memory between the process and the kernel, and supporting transparently across the network would be hard and prohibitively expensive in many cases. I don't know if the video capture driver does use shared memory, but given that it's likely to transfer large amounts of data asynchronously, I expect it to.

Linux has some specific support for network block devices. They do not rely on a network filesystem; the device file exists only on the client, and a daemon on the server emulates a physical block device (it might relay the operations to and from a real physical device, but often it reads and writes to an image file).

You should look for a solution that's specific to video capture. Try to run as much of the data-intensive part on the machine to which the physical device is attached. Or find a virtual machine solution that supports direct access to the physical device from inside the virtual machine (I don't know if any host/guest solution does; hypervisor-based solutions are more likely to).

  • Network block device. Thanks for that tip! Exactly what I was searching for. It's a great way to kinda dd a disk to another machine without using a screwdriver. – Christian Mar 08 '14 at 14:18
  • 1
    @Christian ssh root@othermachine cat /dev/sdb >/dev/sdc – Gilles 'SO- stop being evil' Mar 08 '14 at 14:25
  • 1
    I know it's stupid but somehow I don't trust cat with important binary data. Must be some deeply buried trauma that I don't consciously remember. And no, I'm not a dog person; that's not it. – Christian Mar 08 '14 at 14:55
  • 2
    @Christian Some older Unix systems had text processing tools that didn't treat binary data correctly, but I doubt that ever applied to cat, and in any case cat will work on all current systems. GNU utilities (the ones on Linux) have always treated binary data correctly, it was a design goal from the start. The use of dd for binary data is a habit inherited from the days of magnetic tapes; on contemporary Linux systems, not only is it a needless complication, it even tends to be slower. – Gilles 'SO- stop being evil' Mar 08 '14 at 15:11
  • Ok, maybe I will actively work against my irrational objections then ;) – Christian Mar 08 '14 at 15:17
4

In addition to Gilles answer - as long as you do not intend to do ioctls on file it is simply a stream. So if you ran from guest

# mkfifo /dev/fakevideo0
# ssh host cat /dev/video0 > /dev/fakevideo0

/dev/fakevideo0 will behave as a buffor so if you read from it you will get stream from camera.

  • Would this procedure work for dual way communications? For instance I would like to do this with a serial port. – benathon Feb 05 '14 at 01:10
  • 1
    @portforwardpodcast I don't think it will work straightforwardly - you would probably need to wrap it in unix pipe so you might need to write a program/script on both sides. – Maja Piechotka Feb 05 '14 at 01:24
  • 1
    Thanks for the feedback. I just found this page which works great for dual direction serial over tcp/ip http://www.dest-unreach.org/socat/doc/socat-ttyovertcp.txt – benathon Feb 05 '14 at 02:27
  • this won't work well for video, since the default pipe buffer is 4K – h4unt3r Aug 18 '14 at 22:48
1

This doesn't answer OP's question but there is this tool called netevent at https://github.com/Blub/netevent which allows you to share ioctl devices located in /dev/input/event* between machines. I've personally tried it myself and it worked for me.

ritiek
  • 251
  • The OP’s original question about /dev/video is long since irrelevant ;) I have long moved in from that old setup. But netevent looks interesting for other situations... – Josh Feb 24 '19 at 15:58