public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Markus Frank <m.frank@proxmox.com>
Cc: pve-devel@lists.proxmox.com
Subject: Re: [pve-devel] [PATCH qemu-server v2 6/6] feature #1027: virtio-9p & virtio-fs support
Date: Tue, 27 Dec 2022 12:12:47 +0100	[thread overview]
Message-ID: <20221227111247.tn63tebf4jwwtv3d@casey.proxmox.com> (raw)
In-Reply-To: <20221223131007.130310-7-m.frank@proxmox.com>

Without going too much into this series itself, I've been using
virtiofsd manually myself lately and immediately ran into an issue that
we also need to address, see below:

On Fri, Dec 23, 2022 at 02:10:07PM +0100, Markus Frank wrote:
> adds support for sharing directorys with a guest vm
> 
> virtio-9p can be simply started with qemu.
> virtio-fs needs virtiofsd to be started before qemu.
> 
> Signed-off-by: Markus Frank <m.frank@proxmox.com>
> ---
>  PVE/API2/Qemu.pm  |  20 ++++++-
>  PVE/QemuServer.pm | 135 ++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 154 insertions(+), 1 deletion(-)
> 
> @@ -4158,6 +4244,40 @@ sub config_to_command {
>      return wantarray ? ($cmd, $vollist, $spice_port) : $cmd;
>  }
>  
> +sub extract_dir_path {
> +    my ($nodename, $dirid) = @_;
> +    my $dir_config = PVE::DirConfig::load_config($nodename);
> +    my $path = $dir_config->{$dirid};
> +    if (!$path) {
> +	die "Directory ID $dirid does not exist\n";
> +    }
> +    if (! -e $path) {
> +	die "Path $path does not exist\n";
> +    }
> +    if ((-e $path) && (! -d $path)) {
> +	die "Path $path exists but is not a directory\n"
> +    }
> +    return $path;
> +}
> +
> +sub start_virtiofs {
> +    my ($vmid, $path, $fsid) = @_;
> +    # virtiofsd does not run in background until vhost-user connects
> +    # to the socket, so it has to be started in a fork or with a tool
> +    # like daemonize

This is not really useful. The code now basically daemonizes it twice
and we have a race between virtiofsd opening the socket and qemu
connecting to it, which will cause qemu to fail and virtiofsd to linger.

Instead of using `--socket-path we should setup the socket ourselves and
pass `--fd` to virtiofsd, and not pass `--daemonize` because the point
where it happens is completely useless.

One *hacky* alternative would be to wait for its "Waiting for ..."
message.
Alternatively we could take this upstream and perhaps end up patching
it to daemonize between listen() and accept() as that would be a lot
more useful. If we do that, we should also consider a few more changes,
like an option to pass an already `accept()`ed fd, or an option to allow
multiple connections (so that each accept() will just fork off a new
instance - not necessarily useful for PVE, but useful for regular VMs,
iff done in a way that one can write a systemd service unit for shares
where virtiofsd is *correctly* daemonizing for it...)

> +
> +    my $pid = fork();
> +    my $socketstr = "--socket-path=/var/run/virtiofsd/vm$vmid-fs$fsid";
> +
> +    if ($pid == 0) {
> +	run_command(['/usr/lib/kvm/virtiofsd', '--daemonize', $socketstr,
> +		'-o', "source=$path", '-o', 'cache=always']);
> +	POSIX::_exit(0);
> +    } elsif (!defined($pid)) {
> +        die "could not fork to start virtiofsd";
> +    }
> +}
> +
>  sub check_rng_source {
>      my ($source) = @_;
>  




      reply	other threads:[~2022-12-27 11:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-23 13:10 [pve-devel] [PATCH qemu-server/manager/access-control/docs v2 0/6] feature #1027 virtio-9p/virtio-fs Markus Frank
2022-12-23 13:10 ` [pve-devel] [PATCH docs v2 1/6] added shared filesystem doc for virtio-fs & virtio-9p Markus Frank
2022-12-23 13:10 ` [pve-devel] [PATCH access-control v2 2/6] added acls for Shared Filesystem Directories Markus Frank
2023-01-16 15:45   ` Thomas Lamprecht
2022-12-23 13:10 ` [pve-devel] [PATCH manager v2 3/6] added Config " Markus Frank
2022-12-23 13:10 ` [pve-devel] [PATCH qemu-server v2 4/6] added Shared Files tab in Node Settings Markus Frank
2022-12-23 13:10 ` [pve-devel] [PATCH qemu-server v2 5/6] added options to add virtio-9p & virtio-fs Shared Filesystems to qemu config Markus Frank
2022-12-23 13:10 ` [pve-devel] [PATCH qemu-server v2 6/6] feature #1027: virtio-9p & virtio-fs support Markus Frank
2022-12-27 11:12   ` Wolfgang Bumiller [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221227111247.tn63tebf4jwwtv3d@casey.proxmox.com \
    --to=w.bumiller@proxmox.com \
    --cc=m.frank@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal