From patchwork Wed May 12 12:55:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 1477577 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Wguk26Wx; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FgFCx4mLXz9sW8 for ; Wed, 12 May 2021 22:56:29 +1000 (AEST) Received: from localhost ([::1]:59460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgoPb-0005tl-Kw for incoming@patchwork.ozlabs.org; Wed, 12 May 2021 08:56:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgoPB-0005rv-Ua for qemu-devel@nongnu.org; Wed, 12 May 2021 08:56:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42169) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgoPA-0004Ox-0A for qemu-devel@nongnu.org; Wed, 12 May 2021 08:56:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620824159; 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=iHqch7dt8hGMmsrFm3yGZrFixz04SjMM3avRpX1cQQw=; b=Wguk26Wx3NIFnHZk6z8NjB7VWs3GaEZ0tuJkmoyuHo+fiQaKstyfe9vT+1Dt5qu8XY8Yqx +7M5r6somPVkkq1F3cJOxbJi70dtUZLhebH+M/YM8BuCBPgc0ypY1kGuuS8U08S/+Z0Nop OgfUQ8lCBZQX+3jJ73/DzjYUiDvxYDU= 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-569-WwCx50HYPHOlIcK8p1pwNQ-1; Wed, 12 May 2021 08:55:56 -0400 X-MC-Unique: WwCx50HYPHOlIcK8p1pwNQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0F6D107ACC7 for ; Wed, 12 May 2021 12:55:55 +0000 (UTC) Received: from localhost (ovpn-114-121.ams2.redhat.com [10.36.114.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70BA16091A; Wed, 12 May 2021 12:55:51 +0000 (UTC) From: Max Reitz To: qemu-devel@nongnu.org Subject: [PATCH 1/3] virtiofsd: Find original inode ID of mount points Date: Wed, 12 May 2021 14:55:42 +0200 Message-Id: <20210512125544.9536-2-mreitz@redhat.com> In-Reply-To: <20210512125544.9536-1-mreitz@redhat.com> References: <20210512125544.9536-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: "Dr . David Alan Gilbert" , Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Mount point directories represent two inodes: On one hand, they are a normal directory on their parent filesystem. On the other, they are the root node of the filesystem mounted there. Thus, they have two inode IDs. Right now, we only report the latter inode ID (i.e. the inode ID of the mounted filesystem's root node). This is fine once the guest has auto-mounted a submount there (so this inode ID goes with a device ID that is distinct from the parent filesystem), but before the auto-mount, they have the device ID of the parent and the inode ID for the submount. This is problematic because this is likely exactly the same st_dev/st_ino combination as the parent filesystem's root node. This leads to problems for example with `find`, which will thus complain about a filesystem loop if it has visited the parent filesystem's root node before, and then refuse to descend into the submount. There is a way to find the mount directory's original inode ID, and that is to readdir(3) the parent directory, look for the mount directory, and read the dirent.d_ino field. Using this, we can let lookup and readdirplus return that original inode ID, which the guest will thus show until the submount is auto-mounted. (Then, it will invoke getattr and that stat(2) call will return the inode ID for the submount.) Signed-off-by: Max Reitz Reviewed-by: Connor Kuehl --- tools/virtiofsd/passthrough_ll.c | 104 +++++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 5 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c index 1553d2ef45..110b6e7e5b 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -968,14 +968,87 @@ static int do_statx(struct lo_data *lo, int dirfd, const char *pathname, return 0; } +/* + * Use readdir() to find mp_name's inode ID on the parent's filesystem. + * (For mount points, stat() will only return the inode ID on the + * filesystem mounted there, i.e. the root directory's inode ID. The + * mount point originally was a directory on the parent filesystem, + * though, and so has a different inode ID there. When passing + * submount information to the guest, we need to pass this other ID, + * so the guest can use it as the inode ID until the submount is + * auto-mounted. (At which point the guest will invoke getattr and + * find the inode ID on the submount.)) + * + * Return 0 on success, and -errno otherwise. *pino is set only in + * case of success. + */ +static int get_mp_ino_on_parent(const struct lo_inode *dir, const char *mp_name, + ino_t *pino) +{ + int dirfd = -1; + int ret; + DIR *dp = NULL; + + dirfd = openat(dir->fd, ".", O_RDONLY); + if (dirfd < 0) { + ret = -errno; + goto out; + } + + dp = fdopendir(dirfd); + if (!dp) { + ret = -errno; + goto out; + } + /* Owned by dp now */ + dirfd = -1; + + while (true) { + struct dirent *de; + + errno = 0; + de = readdir(dp); + if (!de) { + ret = errno ? -errno : -ENOENT; + goto out; + } + + if (!strcmp(de->d_name, mp_name)) { + *pino = de->d_ino; + ret = 0; + goto out; + } + } + +out: + if (dp) { + closedir(dp); + } + if (dirfd >= 0) { + close(dirfd); + } + return ret; +} + /* * Increments nlookup on the inode on success. unref_inode_lolocked() must be * called eventually to decrement nlookup again. If inodep is non-NULL, the * inode pointer is stored and the caller must call lo_inode_put(). + * + * If parent_fs_st_ino is true, the entry is a mount point, and submounts are + * announced to the guest, set e->attr.st_ino to the entry's inode ID on its + * parent filesystem instead of its inode ID on the filesystem mounted on it. + * (For mount points, the entry encompasses two inodes: One on the parent FS, + * and one on the mounted FS (where it is the root node), so it has two inode + * IDs. When looking up entries, we should show the guest the parent FS's inode + * ID, because as long as the guest has not auto-mounted the submount, it should + * see that original ID. Once it does perform the auto-mount, it will invoke + * getattr and see the root node's inode ID.) */ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name, struct fuse_entry_param *e, - struct lo_inode **inodep) + struct lo_inode **inodep, + bool parent_fs_st_ino) { int newfd; int res; @@ -984,6 +1057,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name, struct lo_data *lo = lo_data(req); struct lo_inode *inode = NULL; struct lo_inode *dir = lo_inode(req, parent); + ino_t ino_id_for_guest; if (inodep) { *inodep = NULL; /* in case there is an error */ @@ -1018,9 +1092,22 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name, goto out_err; } + ino_id_for_guest = e->attr.st_ino; + if (S_ISDIR(e->attr.st_mode) && lo->announce_submounts && (e->attr.st_dev != dir->key.dev || mnt_id != dir->key.mnt_id)) { e->attr_flags |= FUSE_ATTR_SUBMOUNT; + + if (parent_fs_st_ino) { + /* + * Best effort, so ignore errors. + * Also note that using readdir() means there may be races: + * The directory entry we find (if any) may be different + * from newfd. Again, this is a best effort. Reporting + * the wrong inode ID to the guest is not catastrophic. + */ + get_mp_ino_on_parent(dir, name, &ino_id_for_guest); + } } inode = lo_find(lo, &e->attr, mnt_id); @@ -1043,6 +1130,10 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name, inode->nlookup = 1; inode->fd = newfd; + /* + * For the inode key, use the dev/ino/mnt ID as reported by stat() + * (i.e. not ino_id_for_guest) + */ inode->key.ino = e->attr.st_ino; inode->key.dev = e->attr.st_dev; inode->key.mnt_id = mnt_id; @@ -1058,6 +1149,9 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name, } e->ino = inode->fuse_ino; + /* Report ino_id_for_guest to the guest */ + e->attr.st_ino = ino_id_for_guest; + /* Transfer ownership of inode pointer to caller or drop it */ if (inodep) { *inodep = inode; @@ -1104,7 +1198,7 @@ static void lo_lookup(fuse_req_t req, fuse_ino_t parent, const char *name) return; } - err = lo_do_lookup(req, parent, name, &e, NULL); + err = lo_do_lookup(req, parent, name, &e, NULL, true); if (err) { fuse_reply_err(req, err); } else { @@ -1217,7 +1311,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent, goto out; } - saverr = lo_do_lookup(req, parent, name, &e, NULL); + saverr = lo_do_lookup(req, parent, name, &e, NULL, false); if (saverr) { goto out; } @@ -1714,7 +1808,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, if (plus) { if (!is_dot_or_dotdot(name)) { - err = lo_do_lookup(req, ino, name, &e, NULL); + err = lo_do_lookup(req, ino, name, &e, NULL, true); if (err) { goto error; } @@ -1936,7 +2030,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name, goto out; } - err = lo_do_lookup(req, parent, name, &e, &inode); + err = lo_do_lookup(req, parent, name, &e, &inode, false); if (err) { goto out; } From patchwork Wed May 12 12:55:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 1477578 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Y7GV1tPr; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FgFD36cFNz9sW4 for ; Wed, 12 May 2021 22:56:35 +1000 (AEST) Received: from localhost ([::1]:59876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgoPh-0006CA-QQ for incoming@patchwork.ozlabs.org; Wed, 12 May 2021 08:56:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgoPH-000691-NU for qemu-devel@nongnu.org; Wed, 12 May 2021 08:56:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32462) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgoPG-0004Sm-6o for qemu-devel@nongnu.org; Wed, 12 May 2021 08:56:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620824165; 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=qW4v8ujhk2YL650fydsXQYORVHhFLYhaTKVkpRR4S0Q=; b=Y7GV1tPrldThzYu4EsxSzELA7PGnVl7GtUKQCnAIjB66tjKxye3dqhitN+ww3CkTVOdB69 wriFsqY7aY+gQfTHUHGCd1GLlYuUJX92q6DuQdRybAcFweCzSTT1zrkJhKE8DHqxzo1ypD kWEmAcQQV+WOVHOjhg90xMIq62U6QQE= 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-572-lzbxFgemNvqaulyhL3va9g-1; Wed, 12 May 2021 08:56:02 -0400 X-MC-Unique: lzbxFgemNvqaulyhL3va9g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A15D38018AD for ; Wed, 12 May 2021 12:56:01 +0000 (UTC) Received: from localhost (ovpn-114-121.ams2.redhat.com [10.36.114.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DEBE1100EBAF; Wed, 12 May 2021 12:55:57 +0000 (UTC) From: Max Reitz To: qemu-devel@nongnu.org Subject: [PATCH 2/3] virtiofs_submounts.py: Do not generate ssh key Date: Wed, 12 May 2021 14:55:43 +0200 Message-Id: <20210512125544.9536-3-mreitz@redhat.com> In-Reply-To: <20210512125544.9536-1-mreitz@redhat.com> References: <20210512125544.9536-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: "Dr . David Alan Gilbert" , Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Since c0c5a7f18e623b8f6eb, avocado_qemu provides an ssh key by default. There is no need to generate one in the virtiofs_submounts test. (In fact, it currently is harmful, because e8197c6e0c56aff83 made LinuxTest expect ssh_pubkey to be a file path and not the file content, but virtiofs_submounts provides the latter.) Signed-off-by: Max Reitz --- tests/acceptance/virtiofs_submounts.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virtiofs_submounts.py index 46fa65392a..22fe14b661 100644 --- a/tests/acceptance/virtiofs_submounts.py +++ b/tests/acceptance/virtiofs_submounts.py @@ -220,7 +220,7 @@ def live_cleanup(self): self.run(('bash', self.get_data('cleanup.sh'), scratch_dir)) @skipUnless(*has_cmds(('sudo -n', ('sudo', '-n', 'true')), - 'ssh-keygen', 'bash', 'losetup', 'mkfs.xfs', 'mount')) + 'bash', 'losetup', 'mkfs.xfs', 'mount')) def setUp(self): vmlinuz = self.params.get('vmlinuz') if vmlinuz is None: @@ -242,13 +242,7 @@ def setUp(self): self.seed = self.params.get('seed') - self.ssh_key = os.path.join(self.workdir, 'id_ed25519') - - self.run(('ssh-keygen', '-N', '', '-t', 'ed25519', '-f', self.ssh_key)) - - pubkey = open(self.ssh_key + '.pub').read() - - super(VirtiofsSubmountsTest, self).setUp(pubkey) + super(VirtiofsSubmountsTest, self).setUp() if len(vmlinuz) > 0: self.vm.add_args('-kernel', vmlinuz, From patchwork Wed May 12 12:55:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 1477579 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OBbQHGXG; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FgFD83NJ3z9sW8 for ; Wed, 12 May 2021 22:56:40 +1000 (AEST) Received: from localhost ([::1]:60244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgoPm-0006RG-BD for incoming@patchwork.ozlabs.org; Wed, 12 May 2021 08:56:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgoPM-0006No-Eb for qemu-devel@nongnu.org; Wed, 12 May 2021 08:56:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53660) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgoPK-0004Vd-KN for qemu-devel@nongnu.org; Wed, 12 May 2021 08:56:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620824170; 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=3WckbXumWYqg+9D7Wb38z2FS+cEW+R++zDZxT5sTGkA=; b=OBbQHGXGUPD1Q2VCDaUAPBYg/VeAvbNgCKh+3Xawly3WetJVrF73EFnsecIb5D/sTY4/hR nfkNdglb/aodybeA/xx4OxEbslRrnORIL6uEyMSFxUkavkstmKMtWt9xKjl4zbDs3OBEJ+ 3yRktljJaE51QFtJ86SjBMq1MQ6xIJk= 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-483-DB9WwAKNMG-hb7gQzS5uwA-1; Wed, 12 May 2021 08:56:08 -0400 X-MC-Unique: DB9WwAKNMG-hb7gQzS5uwA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F9B110082E0 for ; Wed, 12 May 2021 12:56:07 +0000 (UTC) Received: from localhost (ovpn-114-121.ams2.redhat.com [10.36.114.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E3B31E6; Wed, 12 May 2021 12:56:03 +0000 (UTC) From: Max Reitz To: qemu-devel@nongnu.org Subject: [PATCH 3/3] virtiofs_submounts.py: Check `find` Date: Wed, 12 May 2021 14:55:44 +0200 Message-Id: <20210512125544.9536-4-mreitz@redhat.com> In-Reply-To: <20210512125544.9536-1-mreitz@redhat.com> References: <20210512125544.9536-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: "Dr . David Alan Gilbert" , Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The guest test script contained a lengthy section on why we cannot just run `find` to auto-mount all submounts. With HEAD^^, that should work now, so replace it and the recursively_visit() function by a lengthy section explaining the history, and a `find`. (Also really check that `find` will not complain about anything.) Signed-off-by: Max Reitz --- .../virtiofs_submounts.py.data/guest.sh | 56 +++++++------------ 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/tests/acceptance/virtiofs_submounts.py.data/guest.sh b/tests/acceptance/virtiofs_submounts.py.data/guest.sh index 59ba40fde1..a3e9dc02f2 100644 --- a/tests/acceptance/virtiofs_submounts.py.data/guest.sh +++ b/tests/acceptance/virtiofs_submounts.py.data/guest.sh @@ -19,41 +19,27 @@ fi cd "$shared_dir" -# FIXME: This should not be necessary, but it is. In order for all -# submounts to be proper mount points, we need to visit them. -# (Before we visit them, they will not be auto-mounted, and so just -# appear as normal directories, with the catch that their st_ino will -# be the st_ino of the filesystem they host, while the st_dev will -# still be the st_dev of the parent.) -# `find` does not work, because it will refuse to touch the mount -# points as long as they are not mounted; their st_dev being shared -# with the parent and st_ino just being the root node's inode ID -# will practically ensure that this node exists elsewhere on the -# filesystem, and `find` is required to recognize loops and not to -# follow them. -# Thus, we have to manually visit all nodes first. - -mnt_i=0 - -function recursively_visit() -{ - pushd "$1" >/dev/null - for entry in *; do - if [[ "$entry" == mnt* ]]; then - mnt_i=$((mnt_i + 1)) - printf "Triggering auto-mount $mnt_i...\r" - fi - - if [ -d "$entry" ]; then - recursively_visit "$entry" - fi - done - popd >/dev/null -} - -recursively_visit . -echo - +# See whether `find` complains about anything, like file system loops, +# by looking for a file that does not exist (so the output should be +# empty). +# (Historically, for mount points, virtiofsd reported only the inode ID +# in submount, i.e. the submount root's inode ID. However, while the +# submount is not yet auto-mounted in the guest, it would have the +# parent's device ID, and so would have the same st_dev/st_ino +# combination as the parent filesystem's root. This would lead to +# `find` reporting file system loops. +# This has been fixed so that virtiofsd reports the mount point node's +# inode ID in the parent filesystem, and when the guest auto-mounts the +# submount, it will only then see the inode ID in that FS.) +# +# As a side-effect, this `find` auto-mounts all submounts by visiting +# the whole tree. +find_output=$(find -name there-is-no-such-file 2>&1) +if [ -n "$find_output" ]; then + echo "Error: find has reported errors or warnings:" >&2 + echo "$find_output" >&2 + exit 1 +fi if [ -n "$(find -name not-mounted)" ]; then echo "Error: not-mounted files visible on mount points:" >&2