From nobody Mon Feb 9 14:33:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1606810938; cv=none; d=zohomail.com; s=zohoarc; b=nQtSEGsBKHDRFDKS15Reg1zHOa8urXdhv4jVCRdI93kE843Q8exW1V+CJXG+oA59GqyS1axNz505BgRXUX+ZFpjQDsAXFCmJ8bby8MBI0qJ974edzv/anqX46yXGLYWi4I5li1sdgJnRi9cpiXKSFbkCEGgDqqP7RaBYvCs82AQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606810938; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8P3UHikA7pHBmIcZYgCpCp4RulCN+1OvDj1DbtBRNCk=; b=bKSF9LSvbWeUoyMoVQ2cr8MqVt9YczAug5Q22TI03GpF+rZgmcqP5V8RhfzpGc7VTPD2ddUWHB5FMHA+uhExAOlQBocrRIbZDMKucWY3uawyjX1jQ0pxDfEJ1t2e+52X3zP7fAwLp51k3zlfaxWC75Azcew7BIIb3P3OG2eDl58= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1606810938032388.37444908709665; Tue, 1 Dec 2020 00:22:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.41650.75053 (Exim 4.92) (envelope-from ) id 1kk0vE-0005QC-1y; Tue, 01 Dec 2020 08:22:04 +0000 Received: by outflank-mailman (output) from mailman id 41650.75053; Tue, 01 Dec 2020 08:22:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kk0vD-0005Q1-TB; Tue, 01 Dec 2020 08:22:03 +0000 Received: by outflank-mailman (input) for mailman id 41650; Tue, 01 Dec 2020 08:22:02 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kk0vC-0004VK-64 for xen-devel@lists.xenproject.org; Tue, 01 Dec 2020 08:22:02 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8fe17956-cceb-44ac-9b50-da0c9bf4e05d; Tue, 01 Dec 2020 08:21:34 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3CA09AF19; Tue, 1 Dec 2020 08:21:33 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8fe17956-cceb-44ac-9b50-da0c9bf4e05d X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1606810893; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8P3UHikA7pHBmIcZYgCpCp4RulCN+1OvDj1DbtBRNCk=; b=GNqocWCji7UO4coxDFPLzqvgECSysm/zPrIqYeFIp17FIBp0Lmx77eaUclfLp9dIhxOLDo K/uRNZsOtQ38yUwi4g8WJfTzYWq7x95fDw2X4gmoK/hD68vYUsXFvKolmxWGdg+JJQ8hC+ vHR6gfebNf+TnpCr1qn4NJbUqjeTniE= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v2 11/17] xen/hypfs: add getsize() and findentry() callbacks to hypfs_funcs Date: Tue, 1 Dec 2020 09:21:22 +0100 Message-Id: <20201201082128.15239-12-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201201082128.15239-1-jgross@suse.com> References: <20201201082128.15239-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add a getsize() function pointer to struct hypfs_funcs for being able to have dynamically filled entries without the need to take the hypfs lock each time the contents are being generated. For directories add a findentry callback to the vector and modify hypfs_get_entry_rel() to use it. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V2: - add a dummy findentry function (Jan Beulich) - add const to findentry dir parameter - don't move DIRENTRY_SIZE() to hypfs.h (Jan Beulich) - split dyndir support off into new patch Signed-off-by: Juergen Gross --- xen/common/hypfs.c | 100 ++++++++++++++++++++++++++-------------- xen/include/xen/hypfs.h | 25 +++++++++- 2 files changed, 89 insertions(+), 36 deletions(-) diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c index fdfd0f764a..83c5cacdca 100644 --- a/xen/common/hypfs.c +++ b/xen/common/hypfs.c @@ -27,22 +27,32 @@ CHECK_hypfs_dirlistentry; const struct hypfs_funcs hypfs_dir_funcs =3D { .read =3D hypfs_read_dir, .write =3D hypfs_write_deny, + .getsize =3D hypfs_getsize, + .findentry =3D hypfs_dir_findentry, }; const struct hypfs_funcs hypfs_leaf_ro_funcs =3D { .read =3D hypfs_read_leaf, .write =3D hypfs_write_deny, + .getsize =3D hypfs_getsize, + .findentry =3D hypfs_leaf_findentry, }; const struct hypfs_funcs hypfs_leaf_wr_funcs =3D { .read =3D hypfs_read_leaf, .write =3D hypfs_write_leaf, + .getsize =3D hypfs_getsize, + .findentry =3D hypfs_leaf_findentry, }; const struct hypfs_funcs hypfs_bool_wr_funcs =3D { .read =3D hypfs_read_leaf, .write =3D hypfs_write_bool, + .getsize =3D hypfs_getsize, + .findentry =3D hypfs_leaf_findentry, }; const struct hypfs_funcs hypfs_custom_wr_funcs =3D { .read =3D hypfs_read_leaf, .write =3D hypfs_write_custom, + .getsize =3D hypfs_getsize, + .findentry =3D hypfs_leaf_findentry, }; =20 static DEFINE_RWLOCK(hypfs_lock); @@ -97,6 +107,8 @@ static int add_entry(struct hypfs_entry_dir *parent, str= uct hypfs_entry *new) =20 ASSERT(new->funcs->read); ASSERT(new->funcs->write); + ASSERT(new->funcs->getsize); + ASSERT(new->funcs->findentry); =20 hypfs_write_lock(); =20 @@ -176,15 +188,41 @@ static int hypfs_get_path_user(char *buf, return 0; } =20 +struct hypfs_entry *hypfs_leaf_findentry(const struct hypfs_entry_dir *dir, + const char *name, + unsigned int name_len) +{ + return ERR_PTR(-ENOENT); +} + +struct hypfs_entry *hypfs_dir_findentry(const struct hypfs_entry_dir *dir, + const char *name, + unsigned int name_len) +{ + struct hypfs_entry *entry; + + list_for_each_entry ( entry, &dir->dirlist, list ) + { + int cmp =3D strncmp(name, entry->name, name_len); + + if ( cmp < 0 ) + return ERR_PTR(-ENOENT); + + if ( !cmp && strlen(entry->name) =3D=3D name_len ) + return entry; + } + + return ERR_PTR(-ENOENT); +} + static struct hypfs_entry *hypfs_get_entry_rel(struct hypfs_entry_dir *dir, const char *path) { const char *end; struct hypfs_entry *entry; unsigned int name_len; - bool again =3D true; =20 - while ( again ) + for ( ; ; ) { if ( dir->e.type !=3D XEN_HYPFS_TYPE_DIR ) return ERR_PTR(-ENOENT); @@ -197,28 +235,12 @@ static struct hypfs_entry *hypfs_get_entry_rel(struct= hypfs_entry_dir *dir, end =3D strchr(path, '\0'); name_len =3D end - path; =20 - again =3D false; + entry =3D dir->e.funcs->findentry(dir, path, name_len); + if ( IS_ERR(entry) || !*end ) + return entry; =20 - list_for_each_entry ( entry, &dir->dirlist, list ) - { - int cmp =3D strncmp(path, entry->name, name_len); - struct hypfs_entry_dir *d =3D container_of(entry, - struct hypfs_entry_di= r, e); - - if ( cmp < 0 ) - return ERR_PTR(-ENOENT); - if ( !cmp && strlen(entry->name) =3D=3D name_len ) - { - if ( !*end ) - return entry; - - again =3D true; - dir =3D d; - path =3D end + 1; - - break; - } - } + path =3D end + 1; + dir =3D container_of(entry, struct hypfs_entry_dir, e); } =20 return ERR_PTR(-ENOENT); @@ -232,12 +254,17 @@ static struct hypfs_entry *hypfs_get_entry(const char= *path) return hypfs_get_entry_rel(&hypfs_root, path + 1); } =20 +unsigned int hypfs_getsize(const struct hypfs_entry *entry) +{ + return entry->size; +} + int hypfs_read_dir(const struct hypfs_entry *entry, XEN_GUEST_HANDLE_PARAM(void) uaddr) { const struct hypfs_entry_dir *d; const struct hypfs_entry *e; - unsigned int size =3D entry->size; + unsigned int size =3D entry->funcs->getsize(entry); =20 ASSERT(this_cpu(hypfs_locked) !=3D hypfs_unlocked); =20 @@ -252,7 +279,7 @@ int hypfs_read_dir(const struct hypfs_entry *entry, direntry.e.pad =3D 0; direntry.e.type =3D e->type; direntry.e.encoding =3D e->encoding; - direntry.e.content_len =3D e->size; + direntry.e.content_len =3D e->funcs->getsize(e); direntry.e.max_write_len =3D e->max_size; direntry.off_next =3D list_is_last(&e->list, &d->dirlist) ? 0 : e_= len; if ( copy_to_guest(uaddr, &direntry, 1) ) @@ -275,18 +302,20 @@ int hypfs_read_leaf(const struct hypfs_entry *entry, XEN_GUEST_HANDLE_PARAM(void) uaddr) { const struct hypfs_entry_leaf *l; + unsigned int size =3D entry->funcs->getsize(entry); =20 ASSERT(this_cpu(hypfs_locked) !=3D hypfs_unlocked); =20 l =3D container_of(entry, const struct hypfs_entry_leaf, e); =20 - return copy_to_guest(uaddr, l->u.content, entry->size) ? -EFAULT: 0; + return copy_to_guest(uaddr, l->u.content, size) ? -EFAULT : 0; } =20 static int hypfs_read(const struct hypfs_entry *entry, XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ul= en) { struct xen_hypfs_direntry e; + unsigned int size =3D entry->funcs->getsize(entry); long ret =3D -EINVAL; =20 if ( ulen < sizeof(e) ) @@ -295,7 +324,7 @@ static int hypfs_read(const struct hypfs_entry *entry, e.pad =3D 0; e.type =3D entry->type; e.encoding =3D entry->encoding; - e.content_len =3D entry->size; + e.content_len =3D size; e.max_write_len =3D entry->max_size; =20 ret =3D -EFAULT; @@ -303,7 +332,7 @@ static int hypfs_read(const struct hypfs_entry *entry, goto out; =20 ret =3D -ENOBUFS; - if ( ulen < entry->size + sizeof(e) ) + if ( ulen < size + sizeof(e) ) goto out; =20 guest_handle_add_offset(uaddr, sizeof(e)); @@ -319,15 +348,16 @@ int hypfs_write_leaf(struct hypfs_entry_leaf *leaf, { char *buf; int ret; + struct hypfs_entry *e =3D &leaf->e; =20 ASSERT(this_cpu(hypfs_locked) =3D=3D hypfs_write_locked); ASSERT(leaf->e.max_size); =20 - if ( ulen > leaf->e.max_size ) + if ( ulen > e->max_size ) return -ENOSPC; =20 - if ( leaf->e.type !=3D XEN_HYPFS_TYPE_STRING && - leaf->e.type !=3D XEN_HYPFS_TYPE_BLOB && ulen !=3D leaf->e.size ) + if ( e->type !=3D XEN_HYPFS_TYPE_STRING && + e->type !=3D XEN_HYPFS_TYPE_BLOB && ulen !=3D e->funcs->getsize(e= ) ) return -EDOM; =20 buf =3D xmalloc_array(char, ulen); @@ -339,14 +369,14 @@ int hypfs_write_leaf(struct hypfs_entry_leaf *leaf, goto out; =20 ret =3D -EINVAL; - if ( leaf->e.type =3D=3D XEN_HYPFS_TYPE_STRING && - leaf->e.encoding =3D=3D XEN_HYPFS_ENC_PLAIN && + if ( e->type =3D=3D XEN_HYPFS_TYPE_STRING && + e->encoding =3D=3D XEN_HYPFS_ENC_PLAIN && memchr(buf, 0, ulen) !=3D (buf + ulen - 1) ) goto out; =20 ret =3D 0; memcpy(leaf->u.write_ptr, buf, ulen); - leaf->e.size =3D ulen; + e->size =3D ulen; =20 out: xfree(buf); @@ -360,7 +390,7 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf, =20 ASSERT(this_cpu(hypfs_locked) =3D=3D hypfs_write_locked); ASSERT(leaf->e.type =3D=3D XEN_HYPFS_TYPE_BOOL && - leaf->e.size =3D=3D sizeof(bool) && + leaf->e.funcs->getsize(&leaf->e) =3D=3D sizeof(bool) && leaf->e.max_size =3D=3D sizeof(bool) ); =20 if ( ulen !=3D leaf->e.max_size ) diff --git a/xen/include/xen/hypfs.h b/xen/include/xen/hypfs.h index 25fdf3ead7..53f50772b4 100644 --- a/xen/include/xen/hypfs.h +++ b/xen/include/xen/hypfs.h @@ -2,17 +2,21 @@ #define __XEN_HYPFS_H__ =20 #ifdef CONFIG_HYPFS +#include #include #include #include =20 struct hypfs_entry_leaf; +struct hypfs_entry_dir; struct hypfs_entry; =20 /* * Per-node callbacks: * - * The callbacks are always called with the hypfs lock held. + * The callbacks are always called with the hypfs lock held. In case multi= ple + * callbacks are called for a single operation the lock is held across all + * those callbacks. * * The read() callback is used to return the contents of a node (either * directory or leaf). It is NOT used to get directory entries during trav= ersal @@ -20,12 +24,24 @@ struct hypfs_entry; * * The write() callback is used to modify the contents of a node. Writing * directories is not supported (this means all nodes are added at boot ti= me). + * + * getsize() is called in two cases: + * - when reading a node (directory or leaf) for filling in the size of the + * node into the returned direntry + * - when reading a directory for each node in this directory + * + * findentry() is called for traversing a path from the root node to a node + * for all nodes on that path excluding the final node (so for looking up + * "/a/b/c" findentry() will be called for "/", "/a", and "/a/b"). */ struct hypfs_funcs { int (*read)(const struct hypfs_entry *entry, XEN_GUEST_HANDLE_PARAM(void) uaddr); int (*write)(struct hypfs_entry_leaf *leaf, XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned int ulen); + unsigned int (*getsize)(const struct hypfs_entry *entry); + struct hypfs_entry *(*findentry)(const struct hypfs_entry_dir *dir, + const char *name, unsigned int name_l= en); }; =20 extern const struct hypfs_funcs hypfs_dir_funcs; @@ -145,6 +161,13 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf, XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned int ulen= ); int hypfs_write_custom(struct hypfs_entry_leaf *leaf, XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned int ul= en); +unsigned int hypfs_getsize(const struct hypfs_entry *entry); +struct hypfs_entry *hypfs_leaf_findentry(const struct hypfs_entry_dir *dir, + const char *name, + unsigned int name_len); +struct hypfs_entry *hypfs_dir_findentry(const struct hypfs_entry_dir *dir, + const char *name, + unsigned int name_len); #endif =20 #endif /* __XEN_HYPFS_H__ */ --=20 2.26.2