From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
George Dunlap <george.dunlap@citrix.com>,
Ian Jackson <iwj@xenproject.org>, Jan Beulich <jbeulich@suse.com>,
Julien Grall <julien@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>
Subject: [PATCH v2 11/17] xen/hypfs: add getsize() and findentry() callbacks to hypfs_funcs
Date: Tue, 1 Dec 2020 09:21:22 +0100 [thread overview]
Message-ID: <20201201082128.15239-12-jgross@suse.com> (raw)
In-Reply-To: <20201201082128.15239-1-jgross@suse.com>
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 <jgross@suse.com>
---
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 <jgross@suse.com>
---
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 = {
.read = hypfs_read_dir,
.write = hypfs_write_deny,
+ .getsize = hypfs_getsize,
+ .findentry = hypfs_dir_findentry,
};
const struct hypfs_funcs hypfs_leaf_ro_funcs = {
.read = hypfs_read_leaf,
.write = hypfs_write_deny,
+ .getsize = hypfs_getsize,
+ .findentry = hypfs_leaf_findentry,
};
const struct hypfs_funcs hypfs_leaf_wr_funcs = {
.read = hypfs_read_leaf,
.write = hypfs_write_leaf,
+ .getsize = hypfs_getsize,
+ .findentry = hypfs_leaf_findentry,
};
const struct hypfs_funcs hypfs_bool_wr_funcs = {
.read = hypfs_read_leaf,
.write = hypfs_write_bool,
+ .getsize = hypfs_getsize,
+ .findentry = hypfs_leaf_findentry,
};
const struct hypfs_funcs hypfs_custom_wr_funcs = {
.read = hypfs_read_leaf,
.write = hypfs_write_custom,
+ .getsize = hypfs_getsize,
+ .findentry = hypfs_leaf_findentry,
};
static DEFINE_RWLOCK(hypfs_lock);
@@ -97,6 +107,8 @@ static int add_entry(struct hypfs_entry_dir *parent, struct hypfs_entry *new)
ASSERT(new->funcs->read);
ASSERT(new->funcs->write);
+ ASSERT(new->funcs->getsize);
+ ASSERT(new->funcs->findentry);
hypfs_write_lock();
@@ -176,15 +188,41 @@ static int hypfs_get_path_user(char *buf,
return 0;
}
+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 = strncmp(name, entry->name, name_len);
+
+ if ( cmp < 0 )
+ return ERR_PTR(-ENOENT);
+
+ if ( !cmp && strlen(entry->name) == 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 = true;
- while ( again )
+ for ( ; ; )
{
if ( dir->e.type != 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 = strchr(path, '\0');
name_len = end - path;
- again = false;
+ entry = dir->e.funcs->findentry(dir, path, name_len);
+ if ( IS_ERR(entry) || !*end )
+ return entry;
- list_for_each_entry ( entry, &dir->dirlist, list )
- {
- int cmp = strncmp(path, entry->name, name_len);
- struct hypfs_entry_dir *d = container_of(entry,
- struct hypfs_entry_dir, e);
-
- if ( cmp < 0 )
- return ERR_PTR(-ENOENT);
- if ( !cmp && strlen(entry->name) == name_len )
- {
- if ( !*end )
- return entry;
-
- again = true;
- dir = d;
- path = end + 1;
-
- break;
- }
- }
+ path = end + 1;
+ dir = container_of(entry, struct hypfs_entry_dir, e);
}
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);
}
+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 = entry->size;
+ unsigned int size = entry->funcs->getsize(entry);
ASSERT(this_cpu(hypfs_locked) != hypfs_unlocked);
@@ -252,7 +279,7 @@ int hypfs_read_dir(const struct hypfs_entry *entry,
direntry.e.pad = 0;
direntry.e.type = e->type;
direntry.e.encoding = e->encoding;
- direntry.e.content_len = e->size;
+ direntry.e.content_len = e->funcs->getsize(e);
direntry.e.max_write_len = e->max_size;
direntry.off_next = 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 = entry->funcs->getsize(entry);
ASSERT(this_cpu(hypfs_locked) != hypfs_unlocked);
l = container_of(entry, const struct hypfs_entry_leaf, e);
- return copy_to_guest(uaddr, l->u.content, entry->size) ? -EFAULT: 0;
+ return copy_to_guest(uaddr, l->u.content, size) ? -EFAULT : 0;
}
static int hypfs_read(const struct hypfs_entry *entry,
XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
{
struct xen_hypfs_direntry e;
+ unsigned int size = entry->funcs->getsize(entry);
long ret = -EINVAL;
if ( ulen < sizeof(e) )
@@ -295,7 +324,7 @@ static int hypfs_read(const struct hypfs_entry *entry,
e.pad = 0;
e.type = entry->type;
e.encoding = entry->encoding;
- e.content_len = entry->size;
+ e.content_len = size;
e.max_write_len = entry->max_size;
ret = -EFAULT;
@@ -303,7 +332,7 @@ static int hypfs_read(const struct hypfs_entry *entry,
goto out;
ret = -ENOBUFS;
- if ( ulen < entry->size + sizeof(e) )
+ if ( ulen < size + sizeof(e) )
goto out;
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 = &leaf->e;
ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked);
ASSERT(leaf->e.max_size);
- if ( ulen > leaf->e.max_size )
+ if ( ulen > e->max_size )
return -ENOSPC;
- if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
- leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
+ if ( e->type != XEN_HYPFS_TYPE_STRING &&
+ e->type != XEN_HYPFS_TYPE_BLOB && ulen != e->funcs->getsize(e) )
return -EDOM;
buf = xmalloc_array(char, ulen);
@@ -339,14 +369,14 @@ int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
goto out;
ret = -EINVAL;
- if ( leaf->e.type == XEN_HYPFS_TYPE_STRING &&
- leaf->e.encoding == XEN_HYPFS_ENC_PLAIN &&
+ if ( e->type == XEN_HYPFS_TYPE_STRING &&
+ e->encoding == XEN_HYPFS_ENC_PLAIN &&
memchr(buf, 0, ulen) != (buf + ulen - 1) )
goto out;
ret = 0;
memcpy(leaf->u.write_ptr, buf, ulen);
- leaf->e.size = ulen;
+ e->size = ulen;
out:
xfree(buf);
@@ -360,7 +390,7 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf,
ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked);
ASSERT(leaf->e.type == XEN_HYPFS_TYPE_BOOL &&
- leaf->e.size == sizeof(bool) &&
+ leaf->e.funcs->getsize(&leaf->e) == sizeof(bool) &&
leaf->e.max_size == sizeof(bool) );
if ( ulen != 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__
#ifdef CONFIG_HYPFS
+#include <xen/lib.h>
#include <xen/list.h>
#include <xen/string.h>
#include <public/hypfs.h>
struct hypfs_entry_leaf;
+struct hypfs_entry_dir;
struct hypfs_entry;
/*
* 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 multiple
+ * 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 traversal
@@ -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 time).
+ *
+ * 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_len);
};
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 ulen);
+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
#endif /* __XEN_HYPFS_H__ */
--
2.26.2
next prev parent reply other threads:[~2020-12-01 8:22 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-01 8:21 [PATCH v2 00/17] xen: support per-cpupool scheduling granularity Juergen Gross
2020-12-01 8:21 ` [PATCH v2 01/17] xen/cpupool: add cpu to sched_res_mask when removing it from cpupool Juergen Gross
2020-12-01 8:21 ` [PATCH v2 02/17] xen/cpupool: add missing bits for per-cpupool scheduling granularity Juergen Gross
2020-12-01 8:21 ` [PATCH v2 03/17] xen/cpupool: sort included headers in cpupool.c Juergen Gross
2020-12-01 8:21 ` [PATCH v2 04/17] xen/cpupool: switch cpupool id to unsigned Juergen Gross
2020-12-01 8:55 ` Jan Beulich
2020-12-01 9:01 ` Jürgen Groß
2020-12-01 9:07 ` Jan Beulich
2020-12-07 9:59 ` Jan Beulich
2020-12-07 14:48 ` Jürgen Groß
2020-12-07 15:00 ` Jan Beulich
2020-12-04 15:52 ` Dario Faggioli
2020-12-07 9:58 ` Jan Beulich
2020-12-07 15:21 ` Jan Beulich
2020-12-01 8:21 ` [PATCH v2 05/17] xen/cpupool: switch cpupool list to normal list interface Juergen Gross
2020-12-01 9:12 ` Jan Beulich
2020-12-01 9:18 ` Jürgen Groß
2020-12-04 16:13 ` Dario Faggioli
2020-12-04 16:16 ` Jürgen Groß
2020-12-04 16:25 ` Dario Faggioli
2020-12-04 16:56 ` Dario Faggioli
2020-12-01 8:21 ` [PATCH v2 06/17] xen/cpupool: use ERR_PTR() for returning error cause from cpupool_create() Juergen Gross
2020-12-02 8:58 ` Jan Beulich
2020-12-02 9:56 ` Jürgen Groß
2020-12-02 10:46 ` Jan Beulich
2020-12-02 10:58 ` Jürgen Groß
2020-12-04 16:29 ` Dario Faggioli
2020-12-01 8:21 ` [PATCH v2 07/17] xen/cpupool: support moving domain between cpupools with different granularity Juergen Gross
2020-12-01 8:21 ` [PATCH v2 08/17] docs: fix hypfs path documentation Juergen Gross
2020-12-01 8:21 ` [PATCH v2 09/17] xen/hypfs: move per-node function pointers into a dedicated struct Juergen Gross
2020-12-02 15:36 ` Jan Beulich
2020-12-02 15:41 ` Jürgen Groß
2020-12-03 8:47 ` Jürgen Groß
2020-12-03 9:12 ` Jan Beulich
2020-12-03 9:51 ` Jürgen Groß
2020-12-01 8:21 ` [PATCH v2 10/17] xen/hypfs: pass real failure reason up from hypfs_get_entry() Juergen Gross
2020-12-01 8:21 ` Juergen Gross [this message]
2020-12-02 15:42 ` [PATCH v2 11/17] xen/hypfs: add getsize() and findentry() callbacks to hypfs_funcs Jan Beulich
2020-12-02 15:51 ` Jürgen Groß
2020-12-03 8:12 ` Jan Beulich
2020-12-03 9:39 ` Jürgen Groß
2020-12-04 8:58 ` Jan Beulich
2020-12-04 11:14 ` Jürgen Groß
2020-12-01 8:21 ` [PATCH v2 12/17] xen/hypfs: add new enter() and exit() per node callbacks Juergen Gross
2020-12-03 14:59 ` Jan Beulich
2020-12-03 15:14 ` Jürgen Groß
2020-12-03 15:29 ` Jan Beulich
2020-12-04 8:33 ` Jürgen Groß
2020-12-04 8:30 ` Jan Beulich
2020-12-04 8:35 ` Jürgen Groß
2020-12-01 8:21 ` [PATCH v2 13/17] xen/hypfs: support dynamic hypfs nodes Juergen Gross
2020-12-03 15:08 ` Jan Beulich
2020-12-03 15:18 ` Jürgen Groß
2020-12-01 8:21 ` [PATCH v2 14/17] xen/hypfs: add support for id-based dynamic directories Juergen Gross
2020-12-03 15:44 ` Jan Beulich
2020-12-04 8:52 ` Jürgen Groß
2020-12-04 9:16 ` Jan Beulich
2020-12-04 13:08 ` Jürgen Groß
2020-12-07 7:54 ` Jan Beulich
2020-12-01 8:21 ` [PATCH v2 15/17] xen/cpupool: add cpupool directories Juergen Gross
2020-12-01 9:00 ` Jan Beulich
2020-12-01 9:03 ` Jürgen Groß
2020-12-02 15:46 ` Jürgen Groß
2020-12-03 14:46 ` Jan Beulich
2020-12-03 15:11 ` Jürgen Groß
2020-12-04 9:10 ` Jan Beulich
2020-12-04 11:08 ` Jürgen Groß
2020-12-04 11:54 ` Jan Beulich
2020-12-01 8:21 ` [PATCH v2 16/17] xen/cpupool: add scheduling granularity entry to cpupool entries Juergen Gross
2020-12-01 8:21 ` [PATCH v2 17/17] xen/cpupool: make per-cpupool sched-gran hypfs node writable Juergen Gross
2020-12-04 23:53 ` [PATCH v2 00/17] xen: support per-cpupool scheduling granularity Andrew Cooper
2020-12-05 7:41 ` Jürgen Groß
2020-12-07 9:00 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201201082128.15239-12-jgross@suse.com \
--to=jgross@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@citrix.com \
--cc=iwj@xenproject.org \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).