[Libguestfs] nbdkit, Windows, Wine, scripts and tests

Richard W.M. Jones rjones at redhat.com
Sat Aug 29 07:37:49 UTC 2020


I spent a bit of my holiday trying to get some more tests working on
the Windows port.  Unfortunately I hit some unexpected and deep snags.
I'm writing down these thoughts before I forget them.

nbdkit runs shell scripts from a lot of places.  The places which are
important for tests are:

(a) nbdkit --run 'script'.

(b) linuxdisk plugin (used to create tests/disk, so important for
tests) runs "du" and "mke2fs -d" commands.

On Unix-like platforms these use system(3), and they also do in the
Windows port since Win32 also has system().  When running on actual
Windows the commands are run through CMD.EXE as you'd expect.  Of
course Windows doesn't have the rich and powerful shell environment
that Unix has so there's no way for nbdkit --run to work exactly the
same on Windows as it does on Unix, but that's all to be expected.

More interesting for running the tests is what happens when running
under Wine on Linux.

I imagined that Linux -> Wine nbdkit.exe -> system ("qemu-img ...")
would work by the Windows process running the Unix command directly.
Unfortunately that's not how it works at all.  In fact Wine emulates
system() using CMD.EXE, and so none of the tests as written will work.
It's possible to get system() under Wine to run Unix commands, but
complicated to say the least: https://stackoverflow.com/a/45545068

However even if we get that lot to work, there's still a big catch.
Paths are generally rewritten using nbdkit_realpath which on Windows
returns paths like "C:\Windows\Temp\socket".  Wheneven these appear in
variables (eg. $unixsocket, $uri, and variables passed to the
linuxdisk plugin subcommands) these will make no sense to the Unix
commands we want to run.

In summary, a test which does:

  nbdkit .. --run 'qemu-img info "$uri"'

will currently try to run:

  CMD.EXE /C qemu-img info 'nbd+unix:///?socket=C:\Windows\Temp\sock'

[Note that on actual Windows, assuming qemu-img.exe is available, I
would expect this to work, although we still need to adjust how
variables are set in the script fragment we pass to system().  The
problem is not how to get this to work on Windows, but how to get it
to work under Wine on Linux so we can run more tests.]

Even if we resolve the problem with running shell commands, it will
still not work because it will run:

  qemu-img info 'nbd+unix:///?socket=C:\Windows\Temp\sock'

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list