From nobody Mon Feb 9 16:12:39 2026 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627657486012957.7302735137448; Fri, 30 Jul 2021 08:04:46 -0700 (PDT) Received: from localhost ([::1]:55122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9U44-0008GN-PO for importer@patchew.org; Fri, 30 Jul 2021 11:04:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9U2B-0005bH-MV for qemu-devel@nongnu.org; Fri, 30 Jul 2021 11:02:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40635) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9U29-0007oi-TO for qemu-devel@nongnu.org; Fri, 30 Jul 2021 11:02:47 -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-463-x0SzNmqJPIuQkRYOvvDo_Q-1; Fri, 30 Jul 2021 11:02:43 -0400 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 BD40384F20E for ; Fri, 30 Jul 2021 15:02:18 +0000 (UTC) Received: from localhost (unknown [10.39.193.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 79BDE5C1D1; Fri, 30 Jul 2021 15:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627657365; 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=4Ih1KdDIwl8x1l9qljSNCVjeeiBQljD/ocdwa7SAgfA=; b=Y9oOeaCBTKO3urXFClcvQqe/KZunpvG/dvJLC915XxszY892hIEGO/kWDnB5krZsyjH8rV BjcWyW5n/3ZiPTwBwon3lxTE4amAvqVzWshoTqidRkPFcByQBgau3WVuoCnPhbRtYa+1GI y4y/vkekGbasMnx4uT4dM+olKJvQkS8= X-MC-Unique: x0SzNmqJPIuQkRYOvvDo_Q-1 From: Max Reitz To: qemu-devel@nongnu.org, virtio-fs@redhat.com Subject: [PATCH v3 05/10] virtiofsd: Let lo_fd() return a TempFd Date: Fri, 30 Jul 2021 17:01:29 +0200 Message-Id: <20210730150134.216126-6-mreitz@redhat.com> In-Reply-To: <20210730150134.216126-1-mreitz@redhat.com> References: <20210730150134.216126-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 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=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.717, 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_H3=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: Stefan Hajnoczi , "Dr . David Alan Gilbert" , Vivek Goyal , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627657529990100001 Content-Type: text/plain; charset="utf-8" Accessing lo_inode.fd must generally happen through lo_inode_fd(), and lo_fd() is no exception; and then it must pass on the TempFd it has received from lo_inode_fd(). (Note that all lo_fd() calls now use proper error handling, where all of them were in-line before; i.e. they were used in place of the fd argument of some function call. This only worked because the only error that could occur was that lo_inode() failed to find the inode ID: Then -1 would be passed as the fd, which would result in an EBADF error, which is precisely what we would want to return to the guest for an invalid inode ID. Now, though, lo_inode_fd() might potentially invoke open_by_handle_at(), which can return many different errors, and they should be properly handled and returned to the guest. So we can no longer allow lo_fd() to be used in-line, and instead need to do proper error handling for it.) Signed-off-by: Max Reitz Reviewed-by: Connor Kuehl --- tools/virtiofsd/passthrough_ll.c | 55 +++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 86b901cf19..9e1bc37af8 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -650,18 +650,19 @@ static int lo_inode_fd(const struct lo_inode *inode, = TempFd *tfd) * they are done with the fd. This will be done in a later patch to make * review easier. */ -static int lo_fd(fuse_req_t req, fuse_ino_t ino) +static int lo_fd(fuse_req_t req, fuse_ino_t ino, TempFd *tfd) { struct lo_inode *inode =3D lo_inode(req, ino); - int fd; + int res; =20 if (!inode) { - return -1; + return -EBADF; } =20 - fd =3D inode->fd; + res =3D lo_inode_fd(inode, tfd); + lo_inode_put(lo_data(req), &inode); - return fd; + return res; } =20 /* @@ -798,14 +799,19 @@ static void lo_init(void *userdata, struct fuse_conn_= info *conn) static void lo_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) { + g_auto(TempFd) ino_fd =3D TEMP_FD_INIT; int res; struct stat buf; struct lo_data *lo =3D lo_data(req); =20 (void)fi; =20 - res =3D - fstatat(lo_fd(req, ino), "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFO= LLOW); + res =3D lo_fd(req, ino, &ino_fd); + if (res < 0) { + return (void)fuse_reply_err(req, -res); + } + + res =3D fstatat(ino_fd.fd, "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFOLL= OW); if (res =3D=3D -1) { return (void)fuse_reply_err(req, errno); } @@ -1529,6 +1535,7 @@ out: =20 static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name) { + g_auto(TempFd) parent_fd =3D TEMP_FD_INIT; int res; struct lo_inode *inode; struct lo_data *lo =3D lo_data(req); @@ -1543,13 +1550,19 @@ static void lo_rmdir(fuse_req_t req, fuse_ino_t par= ent, const char *name) return; } =20 + res =3D lo_fd(req, parent, &parent_fd); + if (res < 0) { + fuse_reply_err(req, -res); + return; + } + inode =3D lookup_name(req, parent, name); if (!inode) { fuse_reply_err(req, EIO); return; } =20 - res =3D unlinkat(lo_fd(req, parent), name, AT_REMOVEDIR); + res =3D unlinkat(parent_fd.fd, name, AT_REMOVEDIR); =20 fuse_reply_err(req, res =3D=3D -1 ? errno : 0); unref_inode_lolocked(lo, inode, 1); @@ -1635,6 +1648,7 @@ out: =20 static void lo_unlink(fuse_req_t req, fuse_ino_t parent, const char *name) { + g_auto(TempFd) parent_fd =3D TEMP_FD_INIT; int res; struct lo_inode *inode; struct lo_data *lo =3D lo_data(req); @@ -1649,13 +1663,19 @@ static void lo_unlink(fuse_req_t req, fuse_ino_t pa= rent, const char *name) return; } =20 + res =3D lo_fd(req, parent, &parent_fd); + if (res < 0) { + fuse_reply_err(req, -res); + return; + } + inode =3D lookup_name(req, parent, name); if (!inode) { fuse_reply_err(req, EIO); return; } =20 - res =3D unlinkat(lo_fd(req, parent), name, 0); + res =3D unlinkat(parent_fd.fd, name, 0); =20 fuse_reply_err(req, res =3D=3D -1 ? errno : 0); unref_inode_lolocked(lo, inode, 1); @@ -1735,10 +1755,16 @@ static void lo_forget_multi(fuse_req_t req, size_t = count, =20 static void lo_readlink(fuse_req_t req, fuse_ino_t ino) { + g_auto(TempFd) ino_fd =3D TEMP_FD_INIT; char buf[PATH_MAX + 1]; int res; =20 - res =3D readlinkat(lo_fd(req, ino), "", buf, sizeof(buf)); + res =3D lo_fd(req, ino, &ino_fd); + if (res < 0) { + return (void)fuse_reply_err(req, -res); + } + + res =3D readlinkat(ino_fd.fd, "", buf, sizeof(buf)); if (res =3D=3D -1) { return (void)fuse_reply_err(req, errno); } @@ -2535,10 +2561,17 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t= ino, =20 static void lo_statfs(fuse_req_t req, fuse_ino_t ino) { + g_auto(TempFd) ino_fd =3D TEMP_FD_INIT; int res; struct statvfs stbuf; =20 - res =3D fstatvfs(lo_fd(req, ino), &stbuf); + res =3D lo_fd(req, ino, &ino_fd); + if (res < 0) { + fuse_reply_err(req, -res); + return; + } + + res =3D fstatvfs(ino_fd.fd, &stbuf); if (res =3D=3D -1) { fuse_reply_err(req, errno); } else { --=20 2.31.1