From nobody Mon Feb 9 11:06:05 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 ARC-Seal: i=1; a=rsa-sha256; t=1622826979; cv=none; d=zohomail.com; s=zohoarc; b=dTBkinEYIIIOLI9MAJw+dqRGZMm5Csfdeg1iLgEq7pzLh3fvH4GgYeQUn+gliFP35dYlwimiqnp43qkalW3To7aeIgofpbUVt3xkgQNnHIUuJ9diM11tLWBJOPAjZKYWW5VPzotiA3TdzKUJxonvDwhqIJyCG1oLOmEmfCvMQso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622826979; 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=Aa+rfStaf8w5x2UOeKiIt+pggHRxPjdzsOaBqfTxIzI=; b=GV+gD/SfH56+PaR335nyevyJhM7MxCAlhciO0mvCa4BQSIbJPUtCf1KOGVQPGKWneh0x6Wu3AzWcCqsH+dbVJY79e57Etc9mmZPToNxt7zrpAQO58yrtDktWn/I9TG2rBXrWd+PpxNF5ItEK/QB2B4VqYJiiPu+ESWuqfp+1+80= 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 1622826979900966.4744816161052; Fri, 4 Jun 2021 10:16:19 -0700 (PDT) Received: from localhost ([::1]:34632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpDQh-0006au-6o for importer@patchew.org; Fri, 04 Jun 2021 13:16:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpCTg-0007uG-BB for qemu-devel@nongnu.org; Fri, 04 Jun 2021 12:15:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48280) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpCTe-0004Fy-8c for qemu-devel@nongnu.org; Fri, 04 Jun 2021 12:15: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-487-ZqN_8vCzOOO2f9k_X6oyvw-1; Fri, 04 Jun 2021 12:15:15 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0824DF8A0 for ; Fri, 4 Jun 2021 16:15:14 +0000 (UTC) Received: from localhost (ovpn-114-199.ams2.redhat.com [10.36.114.199]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 27B1939A66; Fri, 4 Jun 2021 16:15:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622823317; 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=Aa+rfStaf8w5x2UOeKiIt+pggHRxPjdzsOaBqfTxIzI=; b=NEieSl4scMRRV/P34fi3/kB0gCEOvBcKv9nU6OZR8n2cKHbQh4QdG21x1dQo3tZn9Wl04k Z+OrrPbEtgzWTQOVP4NbkBLqYynF2mVzI3NqkVTkdOS1JVMAUUB5cldJqsgwsXmOqM+LQk YPpXuaA/HAKUgYzAj/cj9RgkAiWbwIs= X-MC-Unique: ZqN_8vCzOOO2f9k_X6oyvw-1 From: Max Reitz To: qemu-devel@nongnu.org, virtio-fs@redhat.com Subject: [PATCH 9/9] virtiofsd: Add lazy lo_do_find() Date: Fri, 4 Jun 2021 18:13:37 +0200 Message-Id: <20210604161337.16048-10-mreitz@redhat.com> In-Reply-To: <20210604161337.16048-1-mreitz@redhat.com> References: <20210604161337.16048-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.373, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" lo_find() right now takes two lookup keys for two maps, namely the file handle for inodes_by_handle and the statx information for inodes_by_ids. However, we only need the statx information if looking up the inode by the file handle failed. There are two callers of lo_find(): The first one, lo_do_lookup(), has both keys anyway, so passing them does not incur any additional cost. The second one, lookup_name(), though, needs to explicitly invoke name_to_handle_at() (through get_file_handle()) and statx() (through do_statx()). We need to try to get a file handle as the primary key, so we cannot get rid of get_file_handle(), but we only need the statx information if looking up an inode by handle failed; so we can defer that until the lookup has indeed failed. To this end, replace lo_find()'s st/mnt_id parameters by a get_ids() closure that is invoked to fill the lo_key struct if necessary. Also, lo_find() is renamed to lo_do_find(), so we can add a new lo_find() wrapper whose closure just initializes the lo_key from the st/mnt_id parameters, just like the old lo_find() did. lookup_name() directly calls lo_do_find() now and passes its own closure, which performs the do_statx() call. Signed-off-by: Max Reitz --- tools/virtiofsd/passthrough_ll.c | 93 ++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index d01f9d3a59..ef10a3ace6 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -1141,22 +1141,23 @@ out_err: fuse_reply_err(req, saverr); } =20 -static struct lo_inode *lo_find(struct lo_data *lo, - const struct lo_fhandle *fhandle, - struct stat *st, uint64_t mnt_id) +/* + * get_ids() will be called to get the key for lo->inodes_by_ids if + * the lookup by file handle has failed. + */ +static struct lo_inode *lo_do_find(struct lo_data *lo, + const struct lo_fhandle *fhandle, + int (*get_ids)(struct lo_key *, const void *), + const void *get_ids_opaque) { struct lo_inode *p =3D NULL; - struct lo_key ids_key =3D { - .ino =3D st->st_ino, - .dev =3D st->st_dev, - .mnt_id =3D mnt_id, - }; + struct lo_key ids_key; =20 pthread_mutex_lock(&lo->mutex); if (fhandle) { p =3D g_hash_table_lookup(lo->inodes_by_handle, fhandle); } - if (!p) { + if (!p && get_ids(&ids_key, get_ids_opaque) =3D=3D 0) { p =3D g_hash_table_lookup(lo->inodes_by_ids, &ids_key); /* * When we had to fall back to looking up an inode by its IDs, @@ -1184,6 +1185,36 @@ static struct lo_inode *lo_find(struct lo_data *lo, return p; } =20 +struct lo_find_get_ids_key_opaque { + const struct stat *st; + uint64_t mnt_id; +}; + +static int lo_find_get_ids_key(struct lo_key *ids_key, const void *opaque) +{ + const struct lo_find_get_ids_key_opaque *stat_info =3D opaque; + + *ids_key =3D (struct lo_key){ + .ino =3D stat_info->st->st_ino, + .dev =3D stat_info->st->st_dev, + .mnt_id =3D stat_info->mnt_id, + }; + + return 0; +} + +static struct lo_inode *lo_find(struct lo_data *lo, + const struct lo_fhandle *fhandle, + struct stat *st, uint64_t mnt_id) +{ + const struct lo_find_get_ids_key_opaque stat_info =3D { + .st =3D st, + .mnt_id =3D mnt_id, + }; + + return lo_do_find(lo, fhandle, lo_find_get_ids_key, &stat_info); +} + /* value_destroy_func for posix_locks GHashTable */ static void posix_locks_value_destroy(gpointer data) { @@ -1655,14 +1686,41 @@ out_err: fuse_reply_err(req, saverr); } =20 +struct lookup_name_get_ids_key_opaque { + struct lo_data *lo; + int parent_fd; + const char *name; +}; + +static int lookup_name_get_ids_key(struct lo_key *ids_key, const void *opa= que) +{ + const struct lookup_name_get_ids_key_opaque *stat_params =3D opaque; + uint64_t mnt_id; + struct stat attr; + int res; + + res =3D do_statx(stat_params->lo, stat_params->parent_fd, stat_params-= >name, + &attr, AT_SYMLINK_NOFOLLOW, &mnt_id); + if (res < 0) { + return -errno; + } + + *ids_key =3D (struct lo_key){ + .ino =3D attr.st_ino, + .dev =3D attr.st_dev, + .mnt_id =3D mnt_id, + }; + + return 0; +} + /* Increments nlookup and caller must release refcount using lo_inode_put(= ) */ static struct lo_inode *lookup_name(fuse_req_t req, fuse_ino_t parent, const char *name) { g_auto(TempFd) dir_fd =3D TEMP_FD_INIT; int res; - uint64_t mnt_id; - struct stat attr; + struct lookup_name_get_ids_key_opaque stat_params; struct lo_fhandle *fh; struct lo_data *lo =3D lo_data(req); struct lo_inode *dir =3D lo_inode(req, parent); @@ -1680,13 +1738,14 @@ static struct lo_inode *lookup_name(fuse_req_t req,= fuse_ino_t parent, fh =3D get_file_handle(lo, dir_fd.fd, name); /* Ignore errors, this is just an optional key for the lookup */ =20 - res =3D do_statx(lo, dir_fd.fd, name, &attr, AT_SYMLINK_NOFOLLOW, &mnt= _id); - lo_inode_put(lo, &dir); - if (res =3D=3D -1) { - return NULL; - } + stat_params =3D (struct lookup_name_get_ids_key_opaque){ + .lo =3D lo, + .parent_fd =3D dir_fd.fd, + .name =3D name, + }; =20 - inode =3D lo_find(lo, fh, &attr, mnt_id); + inode =3D lo_do_find(lo, fh, lookup_name_get_ids_key, &stat_params); + lo_inode_put(lo, &dir); g_free(fh); =20 return inode; --=20 2.31.1