From nobody Mon Nov 17 12:03:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603738503; cv=none; d=zohomail.com; s=zohoarc; b=YegDu5gmcoFhlqJ8ZNXhyQIZkQAJfwo/dfH/k5VcASjczZZKR6GYJIkmM9pGnFwg27PXL7632IuEM/Dt0snU4pxCXNam6Dpy6KiCdQRm8h9+nhI59XqMhCO0CEHzYFzec6m/tstv1xpu7VVoRc/rV0/ypPPOO0mnCD+8MP59xKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603738503; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SuRSSzyf8b+9XH+gLT608at4jR7/gO2V/yGyhY+6rv4=; b=hD+PBipGiGui7xdgDgRt/s0Q9ofaCqO5jCBKUeiDsQbzHkoM5e/H5Tt1UaSkiwe5BdB9AK+x8nrz64G7nHdkn4l4Is1KifaEoiJTDWd0TsM/Ug0aWAwtF8C/4VU3Dn0MDFjVe017yr+nTaq4UuPJ98RQKM8rKjCqFNATm6s7Ris= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603738503747808.8764383172805; Mon, 26 Oct 2020 11:55:03 -0700 (PDT) Received: from localhost ([::1]:49596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kX7e2-0005Wi-Gd for importer@patchew.org; Mon, 26 Oct 2020 14:55:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kX7Tg-0002ml-ST for qemu-devel@nongnu.org; Mon, 26 Oct 2020 14:44:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60722) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kX7Te-0003eQ-Gt for qemu-devel@nongnu.org; Mon, 26 Oct 2020 14:44:20 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-419-R4H-cCUlMTmT2S_Pab4osg-1; Mon, 26 Oct 2020 14:44:12 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77597809DD1; Mon, 26 Oct 2020 18:44:11 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-112-208.ams2.redhat.com [10.36.112.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id 257AA5D9CA; Mon, 26 Oct 2020 18:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603737857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SuRSSzyf8b+9XH+gLT608at4jR7/gO2V/yGyhY+6rv4=; b=gUB3mWGBU8d3CGzNkk4qjKQaF95hoYXg4lqRdkkof7WduML9HAdTqSsRmgR8enzrA4tW4j LOiD8oNsvq1kS/G/juRO2TxJqM5W2S+F88/spv5otZzNBsA3Q8lm/3tQMFRgQG9GjBpdLm RrVo6fUofhIerZvGWmCCQVxJ0DH8ByQ= X-MC-Unique: R4H-cCUlMTmT2S_Pab4osg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com, misono.tomohiro@jp.fujitsu.com Subject: [PULL 14/16] virtiofsd: Announce sub-mount points Date: Mon, 26 Oct 2020 18:43:29 +0000 Message-Id: <20201026184331.272953-15-dgilbert@redhat.com> In-Reply-To: <20201026184331.272953-1-dgilbert@redhat.com> References: <20201026184331.272953-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/26 02:39:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: virtio-fs@redhat.com, vgoyal@Redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Max Reitz Whenever we encounter a directory with an st_dev that differs from that of its parent, we set the FUSE_ATTR_SUBMOUNT flag so the guest can create a submount for it. Make this behavior optional, so submounts are only announced to the guest with the announce_submounts option. Some users may prefer the current behavior, so that the guest learns nothing about the host mount structure. Signed-off-by: Max Reitz Message-Id: <20200909184028.262297-7-mreitz@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Dr. David Alan Gilbert Manual merge --- tools/virtiofsd/helper.c | 1 + tools/virtiofsd/passthrough_ll.c | 67 ++++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/tools/virtiofsd/helper.c b/tools/virtiofsd/helper.c index 2e181a49b5..a212f32931 100644 --- a/tools/virtiofsd/helper.c +++ b/tools/virtiofsd/helper.c @@ -178,6 +178,7 @@ void fuse_cmdline_help(void) " default: depends on cache=3D op= tion.\n" " -o writeback|no_writeback enable/disable writeback cache\= n" " default: no_writeback\n" + " -o announce_submounts Announce sub-mount points to th= e guest\n" " -o xattr|no_xattr enable/disable xattr\n" " default: no_xattr\n" " -o modcaps=3DCAPLIST Modify the list of capabiliti= es\n" diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 4188bf3ad2..4db50046d4 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -40,6 +40,7 @@ #include "fuse_virtio.h" #include "fuse_log.h" #include "fuse_lowlevel.h" +#include "standard-headers/linux/fuse.h" #include #include #include @@ -173,6 +174,7 @@ struct lo_data { int timeout_set; int readdirplus_set; int readdirplus_clear; + int announce_submounts; int allow_direct_io; struct lo_inode root; GHashTable *inodes; /* protected by lo->mutex */ @@ -211,6 +213,7 @@ static const struct fuse_opt lo_opts[] =3D { { "cache=3Dalways", offsetof(struct lo_data, cache), CACHE_ALWAYS }, { "readdirplus", offsetof(struct lo_data, readdirplus_set), 1 }, { "no_readdirplus", offsetof(struct lo_data, readdirplus_clear), 1 }, + { "announce_submounts", offsetof(struct lo_data, announce_submounts), = 1 }, { "allow_direct_io", offsetof(struct lo_data, allow_direct_io), 1 }, { "no_allow_direct_io", offsetof(struct lo_data, allow_direct_io), 0 }, FUSE_OPT_END @@ -608,22 +611,52 @@ static void lo_init(void *userdata, struct fuse_conn_= info *conn) } } =20 +/** + * Call fstatat() and set st_rdev whenever a directory's st_dev + * differs from the rparent's st_dev (@parent_dev). This will + * announce submounts to the FUSE client (unless @announce_submounts + * is false). + */ +static int do_fstatat(int dirfd, const char *pathname, struct stat *statbu= f, + int flags, dev_t parent_dev, uint32_t *fuse_attr_fla= gs) +{ + int res =3D fstatat(dirfd, pathname, statbuf, flags); + if (res =3D=3D -1) { + return res; + } + + if (statbuf->st_dev !=3D parent_dev && S_ISDIR(statbuf->st_mode) && + fuse_attr_flags) + { + *fuse_attr_flags |=3D FUSE_ATTR_SUBMOUNT; + } + + return 0; +} + static void lo_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) { int res; struct stat buf; struct lo_data *lo =3D lo_data(req); + struct lo_inode *inode =3D lo_inode(req, ino); + uint32_t fuse_attr_flags =3D 0; =20 (void)fi; =20 - res =3D - fstatat(lo_fd(req, ino), "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFO= LLOW); + res =3D do_fstatat(inode->fd, "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOF= OLLOW, + inode->parent_dev, &fuse_attr_flags); + lo_inode_put(lo, &inode); if (res =3D=3D -1) { return (void)fuse_reply_err(req, errno); } =20 - fuse_reply_attr(req, &buf, lo->timeout); + if (!lo->announce_submounts) { + fuse_attr_flags &=3D ~FUSE_ATTR_SUBMOUNT; + } + + fuse_reply_attr_with_flags(req, &buf, lo->timeout, fuse_attr_flags); } =20 static int lo_fi_fd(fuse_req_t req, struct fuse_file_info *fi) @@ -819,11 +852,16 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t pa= rent, const char *name, goto out_err; } =20 - res =3D fstatat(newfd, "", &e->attr, AT_EMPTY_PATH | AT_SYMLINK_NOFOLL= OW); + res =3D do_fstatat(newfd, "", &e->attr, AT_EMPTY_PATH | AT_SYMLINK_NOF= OLLOW, + dir->key.dev, &e->attr_flags); if (res =3D=3D -1) { goto out_err; } =20 + if (!lo->announce_submounts) { + e->attr_flags &=3D ~FUSE_ATTR_SUBMOUNT; + } + inode =3D lo_find(lo, &e->attr); if (inode) { close(newfd); @@ -1069,11 +1107,17 @@ static void lo_link(fuse_req_t req, fuse_ino_t ino,= fuse_ino_t parent, goto out_err; } =20 - res =3D fstatat(inode->fd, "", &e.attr, AT_EMPTY_PATH | AT_SYMLINK_NOF= OLLOW); + res =3D do_fstatat(inode->fd, "", &e.attr, + AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW, + parent_inode->key.dev, &e.attr_flags); if (res =3D=3D -1) { goto out_err; } =20 + if (!lo->announce_submounts) { + e.attr_flags &=3D ~FUSE_ATTR_SUBMOUNT; + } + pthread_mutex_lock(&lo->mutex); inode->nlookup++; pthread_mutex_unlock(&lo->mutex); @@ -1108,14 +1152,21 @@ static struct lo_inode *lookup_name(fuse_req_t req,= fuse_ino_t parent, { int res; struct stat attr; + struct lo_data *lo =3D lo_data(req); + struct lo_inode *dir =3D lo_inode(req, parent); + + if (!dir) { + return NULL; + } =20 - res =3D fstatat(lo_fd(req, parent), name, &attr, - AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW); + res =3D do_fstatat(dir->fd, name, &attr, + AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW, dir->key.dev, NU= LL); + lo_inode_put(lo, &dir); if (res =3D=3D -1) { return NULL; } =20 - return lo_find(lo_data(req), &attr); + return lo_find(lo, &attr); } =20 static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name) --=20 2.28.0