[Libguestfs] [PATCH libnbd] nbdfuse: New tool to present a network block device in a FUSE filesystem.

Richard W.M. Jones rjones at redhat.com
Mon Oct 14 22:12:55 UTC 2019


On Mon, Oct 14, 2019 at 04:06:27PM -0500, Eric Blake wrote:
> >+ * FUSE to build the nbdfuse program.
> 
> Minimum version?

libguestfs contains a workaround for missing fuse_opt_add_opt_escaped,
but that function has been present in libfuse since 2008, so I'm not
exactly sure why that was needed.  RHEL 5??

FUSE_USE_VERSION 26 has been present since at least 2006 when the
current libfuse git repo runs out.

So I guess "any" :-) until proven otherwise.

> >+  const char *short_options = "+o:P:rV";
> >+  const struct option long_options[] = {
> >+    { "fuse-help",          no_argument,       NULL, FUSE_HELP_OPTION },
> >+    { "help",               no_argument,       NULL, HELP_OPTION },
> >+    { "pidfile",            required_argument, NULL, 'P' },
> >+    { "pid-file",           required_argument, NULL, 'P' },
> >+    { "readonly",           no_argument,       NULL, 'r' },
> >+    { "read-only",          no_argument,       NULL, 'r' },
> >+    { "version",            no_argument,       NULL, 'V' },
> 
> Worth a long-option synonym for -o?

As it stands this is the same as guestmount and indeed plain mount(8).

> >+  else if (strcmp (argv[optind], "--socket-activation") == 0 ||
> >+           strcmp (argv[optind], "--systemd-socket-activation") == 0) {
> >+    mode = MODE_SOCKET_ACTIVATION;
> >+    optind++;
> >+  }
> 
> On the same theme, '--socket' as a synonym is easier to type than
> --socket-activation.

Hmm, sounds like that should be a synonym for --fd !

> >+static int
> >+nbdfuse_readdir (const char *path, void *buf,
> >+                 fuse_fill_dir_t filler,
> >+                 off_t offset, struct fuse_file_info *fi)
> >+{
> >+  if (strcmp (path, "/") != 0)
> >+    return -ENOENT;
> >+
> >+  filler (buf, ".", NULL, 0);
> >+  filler (buf, "..", NULL, 0);
> >+  filler (buf, filename, NULL, 0);
> >+
> 
> Does FUSE have a way to populate d_type during readdir (DT_DIR for
> '.', '..', DT_REG for filename)?

Yes.  IIRC that is the fourth field.  However we have got away with
never setting this in libguestfs, and the usage here is barely
performance sensitive so ...

> >+static int
> >+nbdfuse_write (const char *path, const char *buf,
> >+               size_t count, off_t offset,
> >+               struct fuse_file_info *fi)
> >+{
> >+  /* Probably shouldn't happen because of nbdfuse_open check. */
> >+  if (readonly)
> >+    return -EACCES;
> 
> Is EROFS any better here?

This case should probably never happen.  However it does remind me of
a thing we might one day want to implement in libnbd: connections
which are forced (at the client end) to be read-only.  Libnbd would
implement this by intercepting any write operation and immediately
returning EROFS or similar.

> >+The NBD device itself can be local or remote and is specified by an
> >+NBD URI (like C<nbd://localhost>, see L<nbd_connect_uri(3)>) or
> >+various other modes.
> >+
> >+Use C<fusermount -u MOUNTPOINT> to unmount the filesystem after you
> >+have used it.
> 
> Does umount(8) call into fusermount correctly?

I think the other way around.  AFAICT fusermount is a slightly verbose
wrapper around umount2(2).  However it is quite problematic for
various reasons, some outside the control of FUSE (eg. GNOME utilities
jumping into new mountpoints and preventing them from being unmounted,
which is especially a problem in scripts).  In libguestfs we wrote a
quite sophisticated wrapper around fusermount:

  https://github.com/libguestfs/libguestfs/blob/master/fuse/guestunmount.c

> >+=item B<-o> B<uid=>N B<-o> B<gid=>N
> >+
> >+Use these options to map UIDs and GIDs.
> 
> Does this line up with the stats we reported earlier in getattr()?

I didn't test - I might drop this bit.

> >+=item B<--tcp> HOST PORT
> >+
> >+Select TCP mode.  Connect to an NBD server on a host and port over an
> >+unencrypted TCP socket.  See also L<nbd_connect_tcp(3)>.
> 
> How hard would it be to support encryption?  Obviously, the
> fuse-mounted file will be unencrypted, but libnbd connect to an
> encrypted nbd server could prove useful.

URI mode should support encryption I think (I didn't actually test
that).  The reason to have the --tcp and --unix modes is to allow
shell scripts to use the tool without having to worry about URI
escaping.

I pushed a few other changes based on the rest of your feedback.

Thanks,

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v




More information about the Libguestfs mailing list