Add hypervisor sysfs-like support
v2 cover Add hypervisor sysfs-like support
On the 2019 Xen developer summit there was agreement that the Xen hypervisor should gain support for a hierarchical name-value store similar to the Linux kernel's sysfs.
This is a first implementation of that idea adding the basic functionality to hypervisor and tools side. The interface to any user program making use of that "xen-hypfs" is a new library "libxenhypfs" with a stable interface.
Changes in V2:
- all comments to V1 addressed
- added man-page for xenhypfs tool
- added runtime parameter read access for string parameters
Changes in V1:
- renamed xenfs ->xenhypfs
- added writable entries support at the interface level and in the xenhypfs tool
- added runtime parameter read access (integer type only for now)
- added docs/misc/hypfs-paths.pandoc for path descriptions
Juergen Gross (6):
docs: add feature document for Xen hypervisor sysfs-like support
xen: add basic hypervisor filesystem support
libs: add libxenhypfs
tools: add xenfs tool
xen: add /buildinfo/config entry to hypervisor filesystem
xen: add runtime parameter reading support to hypfs
.gitignore | 3 + docs/features/hypervisorfs.pandoc | 87 ++++++++++ docs/man/xenhypfs.1.pod | 61 +++++++ docs/misc/hypfs-paths.pandoc | 113 ++++++++++++ tools/Rules.mk | 6 + tools/libs/Makefile | 1 + tools/libs/hypfs/Makefile | 14 ++ tools/libs/hypfs/core.c | 252 +++++++++++++++++++++++++++ tools/libs/hypfs/include/xenhypfs.h | 60 +++++++ tools/libs/hypfs/libxenhypfs.map | 9 + tools/libs/hypfs/xenhypfs.pc.in | 10 ++ tools/misc/Makefile | 6 + tools/misc/xenhypfs.c | 160 +++++++++++++++++ xen/arch/arm/traps.c | 1 + xen/arch/x86/hvm/hypercall.c | 1 + xen/arch/x86/hypercall.c | 1 + xen/arch/x86/pv/hypercall.c | 1 + xen/common/Makefile | 10 ++ xen/common/hypfs.c | 335 ++++++++++++++++++++++++++++++++++++ xen/common/kernel.c | 39 +++++ xen/include/public/errno.h | 1 + xen/include/public/hypfs.h | 123 +++++++++++++ xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 8 + xen/include/xen/hypfs.h | 40 +++++ xen/include/xen/kernel.h | 2 + xen/tools/Makefile | 9 +- xen/tools/bin2c.c | 28 +++ 28 files changed, 1380 insertions(+), 2 deletions(-) create mode 100644 docs/features/hypervisorfs.pandoc create mode 100644 docs/man/xenhypfs.1.pod create mode 100644 docs/misc/hypfs-paths.pandoc create mode 100644 tools/libs/hypfs/Makefile create mode 100644 tools/libs/hypfs/core.c create mode 100644 tools/libs/hypfs/include/xenhypfs.h create mode 100644 tools/libs/hypfs/libxenhypfs.map create mode 100644 tools/libs/hypfs/xenhypfs.pc.in create mode 100644 tools/misc/xenhypfs.c create mode 100644 xen/common/hypfs.c create mode 100644 xen/include/public/hypfs.h create mode 100644 xen/include/xen/hypfs.h create mode 100644 xen/tools/bin2c.c
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 1/6 docs: add feature document for Xen hypervisor sysfs-like support
On the 2019 Xen developer summit there was agreement that the Xen hypervisor should gain support for a hierarchical name-value store similar to the Linux kernel's sysfs.
In the beginning there should only be basic support: entries can be added from the hypervisor itself only, there is a simple hypercall interface to read the data.
Add a feature document for setting the base of a discussion regarding the desired functionality and the entries to add.
---
V1:
- remove the "--" prefixes of the sub-commands of the user tool (Jan Beulich)
- rename xenfs to xenhypfs (Jan Beulich)
- add "tree" and "write" options to user tool
V2:
- move example tree to the paths description (Ian Jackson)
- specify allowed characters for keys and values (Ian Jackson)
--- docs/features/hypervisorfs.pandoc | 87 +++++++++++++++++++++++++++++++++++ docs/misc/hypfs-paths.pandoc | 95 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 docs/features/hypervisorfs.pandoc create mode 100644 docs/misc/hypfs-paths.pandoc
docs/features/hypervisorfs.pandoc new file +87 -0
@@ -0,0 +1,87 @@ +% Hypervisor FS +% Revision 1 + +\clearpage + +# Basics +---------------- --------------------- + Status: **Supported** + + Architectures: all + + Components: Hypervisor, toolstack +---------------- --------------------- + +# Overview + +The Hypervisor FS is a hierarchical name-value store for reporting +information to guests, especially dom0. It is similar to the Linux +kernel's sysfs, but without the functionality to directly alter +entries values. Entries and directories are created by the hypervisor, +while the toolstack is able to use a hypercall to query the entry +values. + +# User details + +With: + + xenhypfs ls <path> + +the user can list the entries of a specific path of the FS. Using: + + xenhypfs cat <path> + +the content of an entry can be retrieved. Using: + + xenhypfs write <path> <string> + +a writable entry can be modified. With: + + xenhypfs tree + +the complete Hypervisor FS entry tree can be printed. + +The FS paths are documented in `docs/misc/hypfs-paths.pandoc`. + +# Technical details + +Access to the hypervisor filesystem is done via the stable new hypercall +__HYPERVISOR_filesystem_op. + +* hypercall interface specification + * `xen/include/public/filesystem.h` +* hypervisor internal files + * `xen/include/xen/filesystem.h` + * `xen/common/filesystem.c` +* `libxenhypfs` + * `tools/libs/libxenhypfs/*` +* `xenhypfs` + * `tools/misc/xenhypfs.c` +* path documentation + * `docs/misc/hypfs-paths.pandoc` + +# Testing + +Any new parameters or hardware mitigations should be verified to show up +correctly in the filesystem. + +# Areas for improvement + +* More detailed access rights +* Entries per domain and/or per cpupool + +# Known issues + +* None + +# References + +* None + +# History + +------------------------------------------------------------------------ +Date Revision Version Notes +---------- -------- -------- ------------------------------------------- +2019-10-02 1 Xen 4.13 Document written +---------- -------- -------- -------------------------------------------
docs/misc/hypfs-paths.pandoc new file +95 -0
95 lines not on this page · raw message
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/6 xen: add basic hypervisor filesystem support
In reply to Juergen GrossAdd the infrastructure for the hypervisor filesystem.
This includes the hypercall interface and the base functions for entry creation, deletion and modification.
Initially we support string and unsigned integer entry types. The saved entry size is an upper bound, so for unsigned integer entries we always set the value "11".
---
V1:
- rename files from filesystem.* to hypfs.*
- add dummy write entry support
- rename hypercall filesystem_op to hypfs_op
- add support for unsigned integer entries
V2:
- test new entry name to be valid
--- xen/arch/arm/traps.c | 1 + xen/arch/x86/hvm/hypercall.c | 1 + xen/arch/x86/hypercall.c | 1 + xen/arch/x86/pv/hypercall.c | 1 + xen/common/Makefile | 1 + xen/common/hypfs.c | 318 +++++++++++++++++++++++++++++++++++++++++++ xen/include/public/errno.h | 1 + xen/include/public/hypfs.h | 123 +++++++++++++++++ xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 8 ++ xen/include/xen/hypfs.h | 40 ++++++ 11 files changed, 496 insertions(+) create mode 100644 xen/common/hypfs.c create mode 100644 xen/include/public/hypfs.h create mode 100644 xen/include/xen/hypfs.h
xen/arch/arm/traps.c +1 -0
@@ -1401,6 +1401,7 @@ static arm_hypercall_t arm_hypercall_table[] = {#ifdef CONFIG_ARGO HYPERCALL (argo_op,5 ), #endif + HYPERCALL(hypfs_op, 5), };#ifndef NDEBUG
xen/arch/x86/hvm/hypercall.c +1 -0
@@ -144,6 +144,7 @@ static const hypercall_table_t hvm_hypercall_table[] = {#endif HYPERCALL (xenpmu_op),COMPAT_CALL (dm_op), +HYPERCALL (hypfs_op), HYPERCALL(arch_1) };
xen/arch/x86/hypercall.c +1 -0
@@ -73,6 +73,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =ARGS (hvm_op,2 ),ARGS (dm_op,3 ), #endif +ARGS (hypfs_op,5 ),ARGS (mca,1 ), ARGS(arch_1, 1), };
xen/arch/x86/pv/hypercall.c +1 -0
@@ -84,6 +84,7 @@ const hypercall_table_t pv_hypercall_table[] = {HYPERCALL (hvm_op),COMPAT_CALL (dm_op), #endif +HYPERCALL (hypfs_op),HYPERCALL (mca), HYPERCALL(arch_1), };
xen/common/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-y += domain.o obj-y += event_2l.o obj-y += event_channel.o obj-y += event_fifo.o +obj-y += hypfs.o obj-$(CONFIG_CRASH_DEBUG) += gdbstub.o obj-$(CONFIG_GRANT_TABLE) += grant_table.o obj-y += guestcopy.o
xen/common/hypfs.c new file +318 -0
318 lines not on this page · raw message
xen/include/public/errno.h +1 -0
@@ -78,6 +78,7 @@ XEN_ERRNO(EBUSY, 16) /* Device or resource busy */ XEN_ERRNO(EEXIST, 17) /* File exists */ XEN_ERRNO(EXDEV, 18) /* Cross-device link */ XEN_ERRNO(ENODEV, 19) /* No such device */ +XEN_ERRNO(ENOTDIR, 20) /* Not a directory */ XEN_ERRNO(EISDIR, 21) /* Is a directory */ XEN_ERRNO(EINVAL, 22) /* Invalid argument */XEN_ERRNO (ENFILE ,23 )/* File table overflow */
xen/include/public/hypfs.h new file +123 -0
123 lines not on this page · raw message
xen/include/public/xen.h +1 -0
@@ -130,6 +130,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);#define __HYPERVISOR_argo_op 39#define __HYPERVISOR_xenpmu_op 40#define __HYPERVISOR_dm_op 41 +#define __HYPERVISOR_hypfs_op 42/* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48
xen/include/xen/hypercall.h +8 -0
@@ -150,6 +150,14 @@ do_dm_op( unsigned int nr_bufs, XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs); +extern long +do_hypfs_op ( +unsigned int cmd, +XEN_GUEST_HANDLE_PARAM (void ) arg1, +unsigned long arg2, +XEN_GUEST_HANDLE_PARAM (void ) arg3, +unsigned long arg4); +#ifdef CONFIG_COMPAT extern int
xen/include/xen/hypfs.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef __XEN_HYPFS_H__ +#define __XEN_HYPFS_H__ + +#include <xen/list.h> + +struct hypfs_dir { +unsigned int content_size; +struct list_head list; +}; + +enum hypfs_entry_type { + hypfs_type_dir, + hypfs_type_string, + hypfs_type_uint +}; + +struct hypfs_entry { +enum hypfs_entry_type type; +const char *name; +struct list_head list; +struct hypfs_dir *parent; +union { +void *content; +struct hypfs_dir *dir; +char *str_val; +unsigned int *uint_val; + }; +}; + +extern struct hypfs_dir hypfs_root; + +int hypfs_new_dir (struct hypfs_dir *parent,const char *name, +struct hypfs_dir *dir); +int hypfs_new_entry_string (struct hypfs_dir *parent,const char *name, +char *val); +int hypfs_new_entry_uint (struct hypfs_dir *parent,const char *name, +unsigned int *val); +struct hypfs_entry *hypfs_get_entry (char *path); + +#endif /* __XEN_HYPFS_H__ */
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/6] xen: add basic hypervisor filesystem support
Quoted 19 lines · Juergen Gross
xen/common/hypfs.c new file +16
-0@@ -0,0 +1,318 @@ +/****************************************************************************** +* +* hypfs.c +* +* Simple sysfs-like file system for the hypervisor. +*/ + +#include <xen/lib.h> +#include <xen/hypfs.h> +#include <xen/guest_access.h> +#include <xen/hypercall.h> +#include <public/hypfs.h> + +static DEFINE_SPINLOCK (hypfs_lock); + +struct hypfs_dir hypfs_root = {
xen/common/hypfs.c line 26
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+ .list = LIST_HEAD_INIT(hypfs_root.list), +}; + +static struct hypfs_entry hypfs_root_entry = { + .type = hypfs_type_dir, + .name ="" , + .list =LIST_HEAD_INIT (hypfs_root_entry.list), + .parent = &hypfs_root, + .dir = &hypfs_root, +};
This looks to be used only in hypfs_get_entry(). Unless there are plans to have further uses, it should be moved there.
I'm also somewhat puzzled by "name" being an empty string; this too would look less suspicious if this wasn't a file scope variable.
xen/common/hypfs.c line 40
Quoted 13 lines
xen/common/hypfs.c new file +13
-0+static int hypfs_add_entry (struct hypfs_dir *parent,struct hypfs_entry *new) +{ +int ret = -ENOENT ; +struct list_head *l; + +if ( !new->content ) +return -EINVAL ; + +spin_lock (&hypfs_lock); + + list_for_each ( l, &parent->list ) + { + struct hypfs_entry *e = list_entry(l, struct hypfs_entry, list);
const?
Quoted 17 lines
xen/common/hypfs.c new file +17
-0+int cmp =strcmp (e->name, new->name); + +if ( cmp >0 ) + { + ret =0 ; +list_add_tail (&new->list, l); +break ; + } +if ( cmp ==0 ) + { + ret = -EEXIST ; +break ; + } + } + +if ( ret == -ENOENT ) + {
xen/common/hypfs.c line 67
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+ ret =0 ; +list_add_tail (&new->list, &parent->list); + } + +if ( !ret ) + { +unsigned int sz =strlen (new->name) +1 ; + + parent->content_size +=sizeof (struct xen_hypfs_direntry ) + +ROUNDUP (sz,4 );
What is this literal 4 coming from? DYM alignof(struct xen_hypfs_direntry)?
xen/common/hypfs.c line 77
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+ new->parent = parent; + } + +spin_unlock (&hypfs_lock); + +return ret; +} + +int hypfs_new_entry_any (struct hypfs_dir *parent,const char *name, +enum hypfs_entry_type type,void *content)
Perhaps drop the _any suffix?
Quoted 15 lines
xen/common/hypfs.c new file +15
-0+{ +int ret; +struct hypfs_entry *new; + +if (strchr (name,'/' ) || !strcmp (name,"." ) || !strcmp (name,".." ) ) +return -EINVAL ; + + new = xzalloc(struct hypfs_entry); +if ( !new ) +return -ENOMEM ; + + new->name = name; + new->type = type; + new->content = content; +
xen/common/hypfs.c line 102
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+ ret =hypfs_add_entry (parent, new); + +if ( ret ) +xfree (new); + +return ret; +} + +int hypfs_new_entry_string (struct hypfs_dir *parent,const char *name, +char *val)
The last parameter here and below being non-const is because of the intended write support?
Quoted 19 lines
xen/common/hypfs.c new file +19
-0+{ +return hypfs_new_entry_any (parent, name, hypfs_type_string, val); +} + +int hypfs_new_entry_uint (struct hypfs_dir *parent,const char *name, +unsigned int *val) +{ +return hypfs_new_entry_any (parent, name, hypfs_type_uint, val); +} + +int hypfs_new_dir (struct hypfs_dir *parent,const char *name, +struct hypfs_dir *dir) +{ +if ( !dir ) + dir = xzalloc(struct hypfs_dir); + +return hypfs_new_entry_any (parent, name, hypfs_type_dir, dir); +} +
xen/common/hypfs.c line 131
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+static int hypfs_get_path_user (char *buf,XEN_GUEST_HANDLE_PARAM (void ) uaddr, +unsigned long len) +{ +if ( len >XEN_HYPFS_MAX_PATHLEN ) +return -EINVAL ; + +if (copy_from_guest (buf, uaddr, len) ) +return -EFAULT ; + + buf[len -1 ] =0 ;
In the public interface description you have "including trailing zero byte". I think instead of putting one there you should check there's one.
xen/common/hypfs.c line 137
Quoted 5 lines
xen/common/hypfs.c new file +5
-0+return 0 ; +} + +static struct hypfs_entry *hypfs_get_entry_rel (struct hypfs_entry *dir, +char *path)
const?
xen/common/hypfs.c line 137
Quoted 2 lines
xen/common/hypfs.c new file +2
-0+{ +char *slash;
const?
xen/common/hypfs.c line 144
Quoted 5 lines
xen/common/hypfs.c new file +5
-0+struct hypfs_entry *entry; +struct list_head *l; +unsigned int name_len; + +if ( *path ==0 )
Please either use !*path or be consistent with code a few lines down and use '\0'.
xen/common/hypfs.c line 152
Quoted 8 lines
xen/common/hypfs.c new file +8
-0+return dir; + +if ( dir->type != hypfs_type_dir ) +return NULL ; + + slash =strchr (path,'/' ); +if ( !slash ) + slash =strchr (path,'\0' );
With this better name the variable "end" or some such?
xen/common/hypfs.c line 159
Quoted 7 lines
xen/common/hypfs.c new file +7
-0+ name_len = slash - path; + + list_for_each ( l, &dir->dir->list ) + { +int cmp; + + entry = list_entry(l, struct hypfs_entry, list);
Why not list_for_each_entry(), eliminating the need for the "l" helper variable?
xen/common/hypfs.c line 166
Quoted 7 lines
xen/common/hypfs.c new file +7
-0+ cmp =strncmp (path, entry->name, name_len); +if ( cmp <0 ) +return NULL ; +if ( cmp >0 ) +continue ; +if (strlen (entry->name) == name_len ) +return *slash ?hypfs_get_entry_rel (entry, slash +1 ) : entry;
Perhaps slightly shorter
if ( cmp == 0 && strlen(entry->name) == name_len )
return *slash ? hypfs_get_entry_rel(entry, slash + 1) : entry;?
xen/common/hypfs.c line 172
Quoted 6 lines
xen/common/hypfs.c new file +6
-0+ } + +return NULL ; +} + +struct hypfs_entry *hypfs_get_entry (char *path)
const?
Quoted 11 lines
xen/common/hypfs.c new file +11
-0+{ +if ( path[0 ] !='/' ) +return NULL ; + +return hypfs_get_entry_rel (&hypfs_root_entry, path +1 ); +} + +static unsigned int hypfs_get_entry_len (struct hypfs_entry *entry) +{ +unsigned int len =0 ; +
xen/common/hypfs.c line 193
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+switch ( entry->type ) + { +case hypfs_type_dir: + len = entry->dir->content_size; +break ; +case hypfs_type_string: + len =strlen (entry->str_val) +1 ; +break ; +case hypfs_type_uint: + len =11 ;/* longest possible printed value + 1 */
Why would uint values be restricted to 32 bits? There are plenty of 64-bit numbers that might be of interest exposing through this interface (and even more so if down the road we were to re-use this for something debugfs-like). And even without this I think it would be better to not have a literal number here - it'll be close to unnoticeable (without someone remembering) when porting to an arch with unsigned int wider than 32 bits.
Quoted 8 lines
xen/common/hypfs.c new file +8
-0+break ; + } + +return len; +} + +long do_hypfs_op(unsigned int cmd, + XEN_GUEST_HANDLE_PARAM(void) arg1, unsigned long arg2,
xen/common/hypfs.c line 211
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+ XEN_GUEST_HANDLE_PARAM(void) arg3, unsigned long arg4) +{ + int ret; +struct hypfs_entry *entry; +unsigned int len; +static char path[XEN_HYPFS_MAX_PATHLEN ]; + +if ( !is_control_domain (current->domain) && + !is_hardware_domain (current->domain) ) +return -EPERM ;
Replace by an XSM check?
xen/common/hypfs.c line 210
Quoted 1 line
xen/common/hypfs.c new file +1
-0+spin_lock (&hypfs_lock);
Wouldn't this better be an r/w lock from the beginning, requiring only read access here?
Quoted 7 lines
xen/common/hypfs.c new file +7
-0+ ret =hypfs_get_path_user (path, arg1, arg2); +if ( ret ) + goto out; + + entry =hypfs_get_entry (path); +if ( !entry ) + {
xen/common/hypfs.c line 231
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+ ret = -ENOENT ; + goto out; + } + +switch ( cmd ) + { +case XEN_HYPFS_OP_read_contents: + { +char buf[12 ]; +char *val = buf;
const void *?
Quoted 34 lines
xen/common/hypfs.c new file +34
-0+ len =hypfs_get_entry_len (entry); +if ( len > arg4 ) + { + ret = len; +break ; + } + +switch ( entry->type ) + { +case hypfs_type_dir: + ret = -EISDIR ; +break ; +case hypfs_type_string: + val = entry->str_val; +break ; +case hypfs_type_uint: + len =snprintf (buf,sizeof (buf),"%u" , *entry->uint_val) +1 ; +break ; + } + +if ( !ret &©_to_guest (arg3, val, len) ) + ret = -EFAULT ; + +break ; + } + +case XEN_HYPFS_OP_read_dir: + { +struct list_head *l; + +if ( entry->type != hypfs_type_dir ) + { + ret = -ENOTDIR ; +break ;
xen/common/hypfs.c line 276
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+ } + + len = entry->dir->content_size; +if ( len > arg4 ) + { + ret = len; +break ; + } + +list_for_each ( l, &entry->dir->list )
list_for_each_entry() again?
xen/common/hypfs.c line 282
Quoted 6 lines
xen/common/hypfs.c new file +6
-0+ { +struct xen_hypfs_direntry direntry; + struct hypfs_entry *e = list_entry(l, struct hypfs_entry, list); +unsigned int e_len =strlen (e->name) +1 ; + + e_len =sizeof (direntry) +ROUNDUP (e_len,4 );
Literal 4 again. Perhaps you want to put the entire ROUNDUP(, 4) construct in a macro or function?
xen/common/hypfs.c line 293
Quoted 11 lines
xen/common/hypfs.c new file +11
-0+ direntry.flags = (e->type == hypfs_type_dir) ?XEN_HYPFS_ISDIR :0 ; + direntry.off_next =list_is_last (l, &entry->dir->list) ?0 : e_len; + direntry.content_len =hypfs_get_entry_len (e); +if (copy_to_guest (arg3, &direntry,1 ) ) + { + ret = -EFAULT ; + goto out; + } + +if (copy_to_guest_offset (arg3,sizeof (direntry), e->name, +strlen (e->name) +1 ) )
You calculate the length once already a few lines up. Please store into another local variable and reuse here.
xen/common/hypfs.c line 299
Quoted 6 lines
xen/common/hypfs.c new file +6
-0+ { + ret = -EFAULT ; + goto out; + } + +guest_handle_add_offset (arg3, e_len);
I think it would be good to assert somewhere here that you don't go beyond the dir's stored content_size.
Quoted 39 lines
xen/include/public/hypfs.h new file +36
-0@@ -0,0 +1,123 @@ +/****************************************************************************** +* Xen Hypervisor Filesystem +* +* Copyright (c) 2019, SUSE Software Solutions Germany GmbH +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to +* deal in the Software without restriction, including without limitation the +* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +* sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +* +*/ + +#ifndef __XEN_PUBLIC_HYPFS_H__ +#define __XEN_PUBLIC_HYPFS_H__ + +#include "xen.h" + +/* +* Definitions for the __HYPERVISOR_hypfs_op hypercall. +*/ + +/* Maximum length of a path in the filesystem. */ +#define XEN_HYPFS_MAX_PATHLEN 1024
xen/include/public/hypfs.h line 46
Quoted 10 lines
xen/include/public/hypfs.h new file +10
-0+ +struct xen_hypfs_direntry { +uint16_t flags; +#define XEN_HYPFS_ISDIR 0x0001 +#define XEN_HYPFS_WRITEABLE 0x0002 +/* Offset in bytes to next entry (0 == this is the last entry). */ +uint16_t off_next; +uint32_t content_len; +char name[XEN_FLEX_ARRAY_DIM ]; +};
Are you certain we won't soon need further fields here? Expressing symlinks can perhaps be done via a new XEN_HYPFS_* flag, but there may be other things that would be better to provide for even if there's no implementation from the beginning. It's just the case that changing this structure after the fact is going to be impossible, and it'll take new sub-ops then instead.
Quoted 14 lines
xen/include/public/hypfs.h new file +14
-0+/* +* Hypercall operations. +*/ + +/* +* XEN_HYPFS_OP_read_contents +* +* Read contents of a filesystem entry. +* +* Returns the contents of an entry in the buffer supplied by the caller. +* Only text data with a trailing zero byte is returned. +* +* arg1: XEN_GUEST_HANDLE(path name) +* arg2: length of path name (including trailing zero byte)
xen/include/public/hypfs.h line 71
Quoted 10 lines
xen/include/public/hypfs.h new file +10
-0+* arg3: XEN_GUEST_HANDLE(content buffer) +* arg4: content buffer size +* +* Possible return values: +* 0: success +* -EPERM: operation not permitted +* -ENOENT: entry not found +* -EACCESS: access to entry not permitted +* -EISDIR: entry is a directory +* -EINVAL: invalid parameter
I'm not convinced enumerating possible return value is a good idea. Down the road we're certain to forget extending this list. Plus extension would, strictly speaking, not even be allowed if these enumerations are considered part of the interface.
xen/include/public/hypfs.h line 71
Quoted 1 line
xen/include/public/hypfs.h new file +1
-0+* positive value: content buffer was too small, returned value is needed size
Positive return values are problematic when reaching INT_MAX. Are you convinced we want to have yet another instance?
Quoted 18 lines
xen/include/public/hypfs.h new file +18
-0+*/ +#define XEN_HYPFS_OP_read_contents 1 + +/* +* XEN_HYPFS_OP_read_dir +* +* Read directory entries of a directory. +* +* Returns a struct xen_fs_direntry for each entry in a directory. +* +* arg1: XEN_GUEST_HANDLE(path name) +* arg2: length of path name (including trailing zero byte) +* arg3: XEN_GUEST_HANDLE(content buffer) +* arg4: content buffer size +* +* Possible return values: +* 0: success +* -EPERM: operation not permitted
xen/include/public/hypfs.h line 100
Quoted 10 lines
xen/include/public/hypfs.h new file +10
-0+* -ENOENT: entry not found +* -EACCESS: access to entry not permitted +* -ENOTDIR: entry is not a directory +* -EINVAL: invalid parameter +* positive value: content buffer was too small, returned value is needed size +*/ +#define XEN_HYPFS_OP_read_dir 2 + +/* +* XEN_HYPFS_OP_read_contents
XEN_HYPFS_OP_write_contents
xen/include/public/hypfs.h line 110
Quoted 9 lines
xen/include/public/hypfs.h new file +9
-0+* Write contents of a filesystem entry. +* +* Writes an entry with the contents of a buffer supplied by the caller. +* Only text data with a trailing zero byte can be written. +* +* arg1: XEN_GUEST_HANDLE(path name) +* arg2: length of path name (including trailing zero byte) +* arg3: XEN_GUEST_HANDLE(content buffer) +* arg4: content buffer size
The latest here (in contrast to the read counterpart) I think it becomes desirable to identify what's IN and what's OUT.
Quoted 14 lines
xen/include/xen/hypfs.h new file +11
-0@@ -0,0 +1,40 @@ +#ifndef __XEN_HYPFS_H__ +#define __XEN_HYPFS_H__ + +#include <xen/list.h> + +struct hypfs_dir { +unsigned int content_size; +struct list_head list; +}; + +enum hypfs_entry_type {
xen/include/xen/hypfs.h line 21
Quoted 10 lines
xen/include/xen/hypfs.h new file +10
-0+ hypfs_type_dir, + hypfs_type_string, + hypfs_type_uint +}; + +struct hypfs_entry { +enum hypfs_entry_type type; +const char *name; +struct list_head list; +struct hypfs_dir *parent;
Afaict you set this field, but you never use it anywhere. Why do you add it in the first place? (Initially I meant to ask whether this can be pointer-to-const.)
xen/include/xen/hypfs.h line 23
Quoted 2 lines
xen/include/xen/hypfs.h new file +2
-0+union { +void *content;
const?
xen/include/xen/hypfs.h line 24
Quoted 1 line
xen/include/xen/hypfs.h new file +1
-0+struct hypfs_dir *dir;
const?
xen/include/xen/hypfs.h line 37
Quoted 13 lines
xen/include/xen/hypfs.h new file +13
-0+char *str_val; +unsigned int *uint_val; + }; +}; + +extern struct hypfs_dir hypfs_root; + +int hypfs_new_dir (struct hypfs_dir *parent,const char *name, +struct hypfs_dir *dir); +int hypfs_new_entry_string (struct hypfs_dir *parent,const char *name, +char *val); +int hypfs_new_entry_uint (struct hypfs_dir *parent,const char *name, +unsigned int *val);
Thinking about the lack of const on the last parameters here again - if these are for the pointed to values to be modifiable through this interface, then how would the "owning" component learn of the value having changed? Not everyone may need this, but I think there would want to be a callback. Until then perhaps better to add const here, promising that the values won't change behind the backs of the owners.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/6] xen: add basic hypervisor filesystem support
Quoted 25 lines · Jan Beulich
Quoted 24 lines · Juergen Gross
xen/common/hypfs.c new file +21
-0@@ -0,0 +1,318 @@ +/****************************************************************************** +* +* hypfs.c +* +* Simple sysfs-like file system for the hypervisor. +*/ + +#include <xen/lib.h> +#include <xen/hypfs.h> +#include <xen/guest_access.h> +#include <xen/hypercall.h> +#include <public/hypfs.h> + +static DEFINE_SPINLOCK (hypfs_lock); + +struct hypfs_dir hypfs_root = { + .list =LIST_HEAD_INIT (hypfs_root.list), +}; + +static struct hypfs_entry hypfs_root_entry = { + .type = hypfs_type_dir,
Quoted 8 lines
xen/common/hypfs.c line 26
Quoted 5 lines
xen/common/hypfs.c new file +5
-0+ .name = "", + .list = LIST_HEAD_INIT(hypfs_root_entry.list), + .parent = &hypfs_root, + .dir = &hypfs_root, +};This looks to be used only in
hypfs_get_entry(). Unless there are plans to have further uses, it should be moved there.
Okay.
Quoted 4 lines
I'm also somewhat puzzled by "name" being an empty string; this too would look less suspicious if this wasn't a file scope variable.
Quoted 15 lines
xen/common/hypfs.c line 40
Quoted 13 lines
xen/common/hypfs.c new file +13
-0+static int hypfs_add_entry (struct hypfs_dir *parent,struct hypfs_entry *new) +{ +int ret = -ENOENT ; +struct list_head *l; + +if ( !new->content ) +return -EINVAL ; + +spin_lock (&hypfs_lock); + + list_for_each ( l, &parent->list ) + { + struct hypfs_entry *e = list_entry(l, struct hypfs_entry, list);const?
Hmm, is this true when I add a new entry to it? l is part of *e after all.
Quoted 22 lines
Quoted 22 lines
xen/common/hypfs.c new file +21
-0+int cmp =strcmp (e->name, new->name); + +if ( cmp >0 ) + { + ret =0 ; +list_add_tail (&new->list, l); +break ; + } +if ( cmp ==0 ) + { + ret = -EEXIST ; +break ; + } + } + +if ( ret == -ENOENT ) + { + ret =0 ; +list_add_tail (&new->list, &parent->list); + } +
Quoted 8 lines
xen/common/hypfs.c line 67
Quoted 6 lines
xen/common/hypfs.c new file +6
-0+if ( !ret ) + { +unsigned int sz =strlen (new->name) +1 ; + + parent->content_size +=sizeof (struct xen_hypfs_direntry ) + +ROUNDUP (sz,4 );What is this literal 4 coming from? DYM
alignof(struct xen_hypfs_direntry)?
Yes.
Quoted 13 lines
xen/common/hypfs.c line 77
Quoted 11 lines
xen/common/hypfs.c new file +10
-0+ new->parent = parent; + } + +spin_unlock (&hypfs_lock); + +return ret; +} + +int hypfs_new_entry_any (struct hypfs_dir *parent,const char *name, +enum hypfs_entry_type type,void *content)Perhaps drop the
_anysuffix?
Okay.
Quoted 21 lines
Quoted 21 lines
xen/common/hypfs.c new file +20
-0+{ +int ret; +struct hypfs_entry *new; + +if (strchr (name,'/' ) || !strcmp (name,"." ) || !strcmp (name,".." ) ) +return -EINVAL ; + + new = xzalloc(struct hypfs_entry); +if ( !new ) +return -ENOMEM ; + + new->name = name; + new->type = type; + new->content = content; + + ret =hypfs_add_entry (parent, new); + +if ( ret ) +xfree (new); +
Quoted 8 lines
xen/common/hypfs.c line 102
Quoted 5 lines
xen/common/hypfs.c new file +5
-0+return ret; +} + +int hypfs_new_entry_string (struct hypfs_dir *parent,const char *name, +char *val)The last parameter here and below being non-const is because of the intended write support?
Yes.
Quoted 26 lines
Quoted 26 lines
xen/common/hypfs.c new file +25
-0+{ +return hypfs_new_entry_any (parent, name, hypfs_type_string, val); +} + +int hypfs_new_entry_uint (struct hypfs_dir *parent,const char *name, +unsigned int *val) +{ +return hypfs_new_entry_any (parent, name, hypfs_type_uint, val); +} + +int hypfs_new_dir (struct hypfs_dir *parent,const char *name, +struct hypfs_dir *dir) +{ +if ( !dir ) + dir = xzalloc(struct hypfs_dir); + +return hypfs_new_entry_any (parent, name, hypfs_type_dir, dir); +} + +static int hypfs_get_path_user (char *buf,XEN_GUEST_HANDLE_PARAM (void ) uaddr, +unsigned long len) +{ +if ( len >XEN_HYPFS_MAX_PATHLEN ) +return -EINVAL ; +
Quoted 8 lines
xen/common/hypfs.c line 131
Quoted 4 lines
xen/common/hypfs.c new file +4
-0+if (copy_from_guest (buf, uaddr, len) ) +return -EFAULT ; + + buf[len -1 ] =0 ;In the public interface description you have "including trailing zero byte". I think instead of putting one there you should check there's one.
Okay.
Quoted 8 lines
xen/common/hypfs.c line 137
Quoted 6 lines
xen/common/hypfs.c new file +5
-0+return 0 ; +} + +static struct hypfs_entry *hypfs_get_entry_rel (struct hypfs_entry *dir, +char *path)const?
Yes.
Quoted 5 lines
xen/common/hypfs.c line 137
Quoted 3 lines
xen/common/hypfs.c new file +2
-0+{ +char *slash;const?
Okay.
Quoted 9 lines
xen/common/hypfs.c line 144
Quoted 6 lines
xen/common/hypfs.c new file +5
-0+struct hypfs_entry *entry; +struct list_head *l; +unsigned int name_len; + +if ( *path ==0 )Please either use !*path or be consistent with code a few lines down and use '\0'.
Okay.
Quoted 11 lines
xen/common/hypfs.c line 152
Quoted 9 lines
xen/common/hypfs.c new file +8
-0+return dir; + +if ( dir->type != hypfs_type_dir ) +return NULL ; + + slash =strchr (path,'/' ); +if ( !slash ) + slash =strchr (path,'\0' );With this better name the variable "end" or some such?
Fine with me.
Quoted 11 lines
xen/common/hypfs.c line 159
Quoted 8 lines
xen/common/hypfs.c new file +7
-0+ name_len = slash - path; + + list_for_each ( l, &dir->dir->list ) + { +int cmp; + + entry = list_entry(l, struct hypfs_entry, list);Why not
list_for_each_entry(), eliminating the need for the "l" helper variable?
Ah, of course!
Quoted 9 lines
xen/common/hypfs.c line 166
Quoted 8 lines
xen/common/hypfs.c new file +7
-0+ cmp =strncmp (path, entry->name, name_len); +if ( cmp <0 ) +return NULL ; +if ( cmp >0 ) +continue ; +if (strlen (entry->name) == name_len ) +return *slash ?hypfs_get_entry_rel (entry, slash +1 ) : entry;
Quoted 6 lines
Perhaps slightly shorter
if ( cmp == 0 && strlen(entry->name) == name_len ) return *slash ? hypfs_get_entry_rel(entry, slash + 1) : entry;?
Okay.
Quoted 9 lines
xen/common/hypfs.c line 172
Quoted 7 lines
xen/common/hypfs.c new file +6
-0+ } + +return NULL ; +} + +struct hypfs_entry *hypfs_get_entry (char *path)const?
Yes.
Quoted 23 lines
Quoted 12 lines
xen/common/hypfs.c new file +11
-0+{ +if ( path[0 ] !='/' ) +return NULL ; + +return hypfs_get_entry_rel (&hypfs_root_entry, path +1 ); +} + +static unsigned int hypfs_get_entry_len (struct hypfs_entry *entry) +{ +unsigned int len =0 ; +xen/common/hypfs.c line 193
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+switch ( entry->type ) + { +case hypfs_type_dir: + len = entry->dir->content_size; +break ; +case hypfs_type_string: + len =strlen (entry->str_val) +1 ; +break ; +case hypfs_type_uint: + len =11 ;/* longest possible printed value + 1 */
Quoted 7 lines
Why would uint values be restricted to 32 bits? There are plenty of 64-bit numbers that might be of interest exposing through this interface (and even more so if down the road we were to re-use this for something debugfs-like). And even without this I think it would be better to not have a literal number here - it'll be close to unnoticeable (without someone remembering) when porting to an arch with unsigned int wider than 32 bits.
Support of 64-bit numbers would add "hypfs_type_ulong".
So basically something like "(sizeof(type) * 8 * 3 + 9) / 10 + 1" ? (equivalent to: 10 bits make roughly 3 digits, round that up and add 0-Byte). This is correct for 1, 2, 4 and 8 byte values. For 16 byte values the result is 40, but it should be 41.
Quoted 13 lines
Quoted 13 lines
xen/common/hypfs.c new file +12
-0+break ; + } + +return len; +} + +long do_hypfs_op (unsigned int cmd, +XEN_GUEST_HANDLE_PARAM (void ) arg1,unsigned long arg2, +XEN_GUEST_HANDLE_PARAM (void ) arg3,unsigned long arg4) +{ +int ret; +struct hypfs_entry *entry;
Quoted 8 lines
xen/common/hypfs.c line 211
Quoted 6 lines
xen/common/hypfs.c new file +6
-0+unsigned int len; +static char path[XEN_HYPFS_MAX_PATHLEN ]; + +if ( !is_control_domain (current->domain) && + !is_hardware_domain (current->domain) ) +return -EPERM ;Replace by an XSM check?
Yes, but I could need some help here. How do I add a new hypercall in XSM?
Quoted 5 lines
xen/common/hypfs.c line 210
Quoted 2 lines
xen/common/hypfs.c new file +1
-0+spin_lock (&hypfs_lock);Wouldn't this better be an r/w lock from the beginning, requiring only read access here?
Depending on the further use cases we might even end up with per-element locks. I'm fine using a r/w lock for now.
Quoted 12 lines
Quoted 12 lines
xen/common/hypfs.c new file +11
-0+ ret =hypfs_get_path_user (path, arg1, arg2); +if ( ret ) + goto out; + + entry =hypfs_get_entry (path); +if ( !entry ) + { + ret = -ENOENT ; + goto out; + } +
Quoted 8 lines
xen/common/hypfs.c line 231
Quoted 6 lines
xen/common/hypfs.c new file +6
-0+switch ( cmd ) + { +case XEN_HYPFS_OP_read_contents: + { +char buf[12 ]; +char *val = buf;const void *?
Why void *? The result is always a string.
Quoted 39 lines
Quoted 39 lines
xen/common/hypfs.c new file +38
-0+ len =hypfs_get_entry_len (entry); +if ( len > arg4 ) + { + ret = len; +break ; + } + +switch ( entry->type ) + { +case hypfs_type_dir: + ret = -EISDIR ; +break ; +case hypfs_type_string: + val = entry->str_val; +break ; +case hypfs_type_uint: + len =snprintf (buf,sizeof (buf),"%u" , *entry->uint_val) +1 ; +break ; + } + +if ( !ret &©_to_guest (arg3, val, len) ) + ret = -EFAULT ; + +break ; + } + +case XEN_HYPFS_OP_read_dir: + { +struct list_head *l; + +if ( entry->type != hypfs_type_dir ) + { + ret = -ENOTDIR ; +break ; + } + + len = entry->dir->content_size; +if ( len > arg4 )
Quoted 8 lines
xen/common/hypfs.c line 276
Quoted 6 lines
xen/common/hypfs.c new file +6
-0+ { + ret = len; +break ; + } + +list_for_each ( l, &entry->dir->list )
list_for_each_entry()again?
Yes.
Quoted 10 lines
xen/common/hypfs.c line 282
Quoted 7 lines
xen/common/hypfs.c new file +6
-0+ { +struct xen_hypfs_direntry direntry; + struct hypfs_entry *e = list_entry(l, struct hypfs_entry, list); +unsigned int e_len =strlen (e->name) +1 ; + + e_len =sizeof (direntry) +ROUNDUP (e_len,4 );Literal 4 again. Perhaps you want to put the entire
ROUNDUP(, 4)construct in a macro or function?
Yes, might be better in a function.
Quoted 13 lines
xen/common/hypfs.c line 293
Quoted 12 lines
xen/common/hypfs.c new file +11
-0+ direntry.flags = (e->type == hypfs_type_dir) ?XEN_HYPFS_ISDIR :0 ; + direntry.off_next =list_is_last (l, &entry->dir->list) ?0 : e_len; + direntry.content_len =hypfs_get_entry_len (e); +if (copy_to_guest (arg3, &direntry,1 ) ) + { + ret = -EFAULT ; + goto out; + } + +if (copy_to_guest_offset (arg3,sizeof (direntry), e->name, +strlen (e->name) +1 ) )
Quoted 2 lines
You calculate the length once already a few lines up. Please store into another local variable and reuse here.
Okay.
Quoted 10 lines
xen/common/hypfs.c line 299
Quoted 7 lines
xen/common/hypfs.c new file +6
-0+ { + ret = -EFAULT ; + goto out; + } + +guest_handle_add_offset (arg3, e_len);I think it would be good to assert somewhere here that you don't go beyond the dir's stored
content_size.
Fine with me.
Quoted 49 lines
Quoted 49 lines
xen/include/public/hypfs.h new file +45
-0@@ -0,0 +1,123 @@ +/****************************************************************************** +* Xen Hypervisor Filesystem +* +* Copyright (c) 2019, SUSE Software Solutions Germany GmbH +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to +* deal in the Software without restriction, including without limitation the +* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +* sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +* +*/ + +#ifndef __XEN_PUBLIC_HYPFS_H__ +#define __XEN_PUBLIC_HYPFS_H__ + +#include "xen.h" + +/* + * Definitions for the __HYPERVISOR_hypfs_op hypercall. + */ + +/* Maximum length of a path in the filesystem. */ +#define XEN_HYPFS_MAX_PATHLEN 1024 + +struct xen_hypfs_direntry { + uint16_t flags; +#define XEN_HYPFS_ISDIR 0x0001 +#define XEN_HYPFS_WRITEABLE 0x0002 + /* Offset in bytes to next entry (0 == this is the last entry). */ + uint16_t off_next; + uint32_t content_len; + char name[XEN_FLEX_ARRAY_DIM];
Quoted 8 lines
xen/include/public/hypfs.h line 46
Quoted 1 line
xen/include/public/hypfs.h new file +1
-0+};Are you certain we won't soon need further fields here? Expressing symlinks can perhaps be done via a new XEN_HYPFS_* flag, but there may be other things that would be better to provide for even if there's no implementation from the beginning. It's just the case that changing this structure after the fact is going to be impossible, and it'll take new sub-ops then instead.
Okay, I'll make flags uint32_t and add a "uint16_t off_name". This allows adding more fields later (e.g. depending on flags).
Quoted 22 lines
Quoted 22 lines
xen/include/public/hypfs.h new file +21
-0+/* +* Hypercall operations. +*/ + +/* +* XEN_HYPFS_OP_read_contents +* +* Read contents of a filesystem entry. +* +* Returns the contents of an entry in the buffer supplied by the caller. +* Only text data with a trailing zero byte is returned. +* +* arg1: XEN_GUEST_HANDLE(path name) +* arg2: length of path name (including trailing zero byte) +* arg3: XEN_GUEST_HANDLE(content buffer) +* arg4: content buffer size +* +* Possible return values: +* 0: success +* -EPERM: operation not permitted +* -ENOENT: entry not found
Quoted 8 lines
xen/include/public/hypfs.h line 71
Quoted 3 lines
xen/include/public/hypfs.h new file +3
-0+* -EACCESS: access to entry not permitted +* -EISDIR: entry is a directory +* -EINVAL: invalid parameter I'm not convinced enumerating possible return value is a good idea. Down the road we're certain to forget extending this list. Plus extension would, strictly speaking, not even be allowed if these enumerations are considered part of the interface.
Okay, I'll drop listing them.
Quoted 5 lines
xen/include/public/hypfs.h line 71
Quoted 2 lines
xen/include/public/hypfs.h new file +1
-0+* positive value: content buffer was too small, returned value is needed size Positive return values are problematic when reaching
INT_MAX. Are you convinced we want to have yet another instance?
Are you convinced we want to return more then 2G long strings in one go?
Quoted 23 lines
Quoted 23 lines
xen/include/public/hypfs.h new file +22
-0+*/ +#define XEN_HYPFS_OP_read_contents 1 + +/* +* XEN_HYPFS_OP_read_dir +* +* Read directory entries of a directory. +* +* Returns a struct xen_fs_direntry for each entry in a directory. +* +* arg1: XEN_GUEST_HANDLE(path name) +* arg2: length of path name (including trailing zero byte) +* arg3: XEN_GUEST_HANDLE(content buffer) +* arg4: content buffer size +* +* Possible return values: +* 0: success +* -EPERM: operation not permitted +* -ENOENT: entry not found +* -EACCESS: access to entry not permitted +* -ENOTDIR: entry is not a directory +* -EINVAL: invalid parameter
Quoted 8 lines
xen/include/public/hypfs.h line 100
Quoted 6 lines
xen/include/public/hypfs.h new file +6
-0+* positive value: content buffer was too small, returned value is needed size +*/ +#define XEN_HYPFS_OP_read_dir 2 + +/* +* XEN_HYPFS_OP_read_contents
XEN_HYPFS_OP_write_contents
Oh, of yourse!
Quoted 11 lines
xen/include/public/hypfs.h line 110
Quoted 10 lines
xen/include/public/hypfs.h new file +9
-0+* Write contents of a filesystem entry. +* +* Writes an entry with the contents of a buffer supplied by the caller. +* Only text data with a trailing zero byte can be written. +* +* arg1: XEN_GUEST_HANDLE(path name) +* arg2: length of path name (including trailing zero byte) +* arg3: XEN_GUEST_HANDLE(content buffer) +* arg4: content buffer size
Quoted 2 lines
The latest here (in contrast to the read counterpart) I think it becomes desirable to identify what's IN and what's OUT.
Yes.
Quoted 21 lines
Quoted 21 lines
xen/include/xen/hypfs.h new file +17
-0@@ -0,0 +1,40 @@ +#ifndef __XEN_HYPFS_H__ +#define __XEN_HYPFS_H__ + +#include <xen/list.h> + +struct hypfs_dir { +unsigned int content_size; +struct list_head list; +}; + +enum hypfs_entry_type { + hypfs_type_dir, + hypfs_type_string, + hypfs_type_uint +}; + +struct hypfs_entry {
Quoted 8 lines
xen/include/xen/hypfs.h line 21
Quoted 4 lines
xen/include/xen/hypfs.h new file +4
-0+enum hypfs_entry_type type; +const char *name; +struct list_head list; +struct hypfs_dir *parent;Afaict you set this field, but you never use it anywhere. Why do you add it in the first place? (Initially I meant to ask whether this can be pointer-to-const.)
It will be needed for cases where the entry is being changed, e.g. when support for custom runtime parameters is added.
Quoted 9 lines
xen/include/xen/hypfs.h line 23
Quoted 3 lines
xen/include/xen/hypfs.h new file +2
-0+union { +void *content;const?
xen/include/xen/hypfs.h line 24
Quoted 1 line
xen/include/xen/hypfs.h new file +1
-0+struct hypfs_dir *dir;const?
As already said above: mixing const and non-const pointers in a union looks fishy to me.
Quoted 15 lines
Quoted 4 lines
xen/include/xen/hypfs.h new file +3
-0+char *str_val; +unsigned int *uint_val; + };xen/include/xen/hypfs.h line 37
Quoted 10 lines
xen/include/xen/hypfs.h new file +10
-0+}; + +extern struct hypfs_dir hypfs_root; + +int hypfs_new_dir (struct hypfs_dir *parent,const char *name, +struct hypfs_dir *dir); +int hypfs_new_entry_string (struct hypfs_dir *parent,const char *name, +char *val); +int hypfs_new_entry_uint (struct hypfs_dir *parent,const char *name, +unsigned int *val);
Quoted 7 lines
Thinking about the lack of const on the last parameters here again - if these are for the pointed to values to be modifiable through this interface, then how would the "owning" component learn of the value having changed? Not everyone may need this, but I think there would want to be a callback. Until then perhaps better to add const here, promising that the values won't change behind the backs of the owners.
That's what hypfs_lock is for (and maybe later per-element locks).
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/6] xen: add basic hypervisor filesystem support
Quoted 18 lines · Jürgen Groß
Quoted 16 lines · Jan Beulich
xen/common/hypfs.c line 40
Quoted 13 lines · Juergen Gross
xen/common/hypfs.c new file +13
-0+static int hypfs_add_entry (struct hypfs_dir *parent,struct hypfs_entry *new) +{ +int ret = -ENOENT ; +struct list_head *l; + +if ( !new->content ) +return -EINVAL ; + +spin_lock (&hypfs_lock); + + list_for_each ( l, &parent->list ) + { + struct hypfs_entry *e = list_entry(l, struct hypfs_entry, list);const?
Quoted 2 lines
Hmm, is this true when I add a new entry to it? l is part of *e after all.
But you don't use e in a way requiring it to be non-const. Question is (as I did ask elsewhere already) whether you wouldn't better use list_for_each_entry() here in the first place.
Quoted 23 lines
Quoted 15 lines
Quoted 4 lines
xen/common/hypfs.c new file +4
-0+static unsigned int hypfs_get_entry_len (struct hypfs_entry *entry) +{ +unsigned int len =0 ; +xen/common/hypfs.c line 193
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+switch ( entry->type ) + { +case hypfs_type_dir: + len = entry->dir->content_size; +break ; +case hypfs_type_string: + len =strlen (entry->str_val) +1 ; +break ; +case hypfs_type_uint: + len =11 ;/* longest possible printed value + 1 */ Quoted 7 lines
Why would uint values be restricted to 32 bits? There are plenty of 64-bit numbers that might be of interest exposing through this interface (and even more so if down the road we were to re-use this for something debugfs-like). And even without this I think it would be better to not have a literal number here - it'll be close to unnoticeable (without someone remembering) when porting to an arch with unsigned int wider than 32 bits.
Quoted 1 line
Support of 64-bit numbers would add "
hypfs_type_ulong".
At this layer I dislike making assumptions on the bitness of int or long. Can we settle on either a type that's suitable for all sensible values (would likely be unsigned long long) or use fixed with identifications (hypfs_type_u32 et al)?
Quoted 4 lines
So basically something like "(sizeof(type) * 8 * 3 + 9) / 10 + 1" ? (equivalent to: 10 bits make roughly 3 digits, round that up and add 0-Byte). This is correct for 1, 2, 4 and 8 byte values. For 16 byte values the result is 40, but it should be 41.
That's one option. The other - especially worthwhile to consider for large numbers - is to represent them in hex.
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
xen/common/hypfs.c new file +12
-0+break ; + } + +return len; +} + +long do_hypfs_op (unsigned int cmd, +XEN_GUEST_HANDLE_PARAM (void ) arg1,unsigned long arg2, +XEN_GUEST_HANDLE_PARAM (void ) arg3,unsigned long arg4) +{ +int ret; +struct hypfs_entry *entry;Quoted 8 lines
xen/common/hypfs.c line 211
Quoted 6 lines
xen/common/hypfs.c new file +6
-0+unsigned int len; +static char path[XEN_HYPFS_MAX_PATHLEN ]; + +if ( !is_control_domain (current->domain) && + !is_hardware_domain (current->domain) ) +return -EPERM ;Replace by an XSM check?
Quoted 2 lines
Yes, but I could need some help here. How do I add a new hypercall in XSM?
I guess we should rope in Daniel (now Cc-ed).
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
+
spin_lock(&hypfs_lock);Wouldn't this better be an r/w lock from the beginning, requiring only read access here?
Depending on the further use cases we might even end up with per-element locks. I'm fine using a r/w lock for now.
Indeed I was thinking that write-value support would want a per-entry lock, with the global one only guarding the directory tree.
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
xen/common/hypfs.c new file +11
-0+ ret =hypfs_get_path_user (path, arg1, arg2); +if ( ret ) + goto out; + + entry =hypfs_get_entry (path); +if ( !entry ) + { + ret = -ENOENT ; + goto out; + } +Quoted 8 lines
xen/common/hypfs.c line 231
Quoted 6 lines
xen/common/hypfs.c new file +6
-0+switch ( cmd ) + { +case XEN_HYPFS_OP_read_contents: + { +char buf[12 ]; +char *val = buf;const void *?
Quoted 1 line
Why void *? The result is always a string.
const char * might be fine too, but the code really doesn't depend on this being other than void afaics.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+ * positive value: content buffer was too small, returned value is needed size
Positive return values are problematic when reaching
INT_MAX. Are you convinced we want to have yet another instance?Are you convinced we want to return more then 2G long strings in one go?
Counter question: Are you convinced we'll stick to just strings? See the gzip-ing question on the later patch for example.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
xen/include/xen/hypfs.h new file +5
-0+struct hypfs_entry { +enum hypfs_entry_type type; +const char *name; +struct list_head list; +struct hypfs_dir *parent;
Quoted 6 lines
Quoted 3 lines
Afaict you set this field, but you never use it anywhere. Why do you add it in the first place? (Initially I meant to ask whether this can be pointer-to-const.)
It will be needed for cases where the entry is being changed, e.g. when support for custom runtime parameters is added.
Can we defer its introduction until then?
Quoted 11 lines
Quoted 8 lines
xen/include/xen/hypfs.h line 23
Quoted 2 lines
xen/include/xen/hypfs.h new file +2
-0+union { +void *content;const?
Quoted 1 line
+ struct
hypfs_dir*dir;const?
As already said above: mixing const and non-const pointers in a union looks fishy to me.
Hmm, well, I can see your point, but I think it still can be viewed to have its (perhaps largely documentation) value.
Quoted 22 lines
Quoted 14 lines
xen/include/xen/hypfs.h line 37
Quoted 13 lines
xen/include/xen/hypfs.h new file +13
-0+char *str_val; +unsigned int *uint_val; + }; +}; + +extern struct hypfs_dir hypfs_root; + +int hypfs_new_dir (struct hypfs_dir *parent,const char *name, +struct hypfs_dir *dir); +int hypfs_new_entry_string (struct hypfs_dir *parent,const char *name, +char *val); +int hypfs_new_entry_uint (struct hypfs_dir *parent,const char *name, +unsigned int *val);Quoted 7 lines
Thinking about the lack of const on the last parameters here again - if these are for the pointed to values to be modifiable through this interface, then how would the "owning" component learn of the value having changed? Not everyone may need this, but I think there would want to be a callback. Until then perhaps better to add const here, promising that the values won't change behind the backs of the owners.
Quoted 1 line
That's what
hypfs_lockis for (and maybe later per-element locks).
I don't understand: Are you intending random code to acquire this lock?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/6] xen: add basic hypervisor filesystem support
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Jürgen Groß
Quoted 16 lines · Jan Beulich
xen/common/hypfs.c line 40
Quoted 13 lines · Juergen Gross
xen/common/hypfs.c new file +13
-0+static int hypfs_add_entry (struct hypfs_dir *parent,struct hypfs_entry *new) +{ +int ret = -ENOENT ; +struct list_head *l; + +if ( !new->content ) +return -EINVAL ; + +spin_lock (&hypfs_lock); + + list_for_each ( l, &parent->list ) + { + struct hypfs_entry *e = list_entry(l, struct hypfs_entry, list);const?
Quoted 6 lines
Quoted 2 lines
Hmm, is this true when I add a new entry to it? l is part of *e after all.
But you don't use e in a way requiring it to be non-const. Question is (as I did ask elsewhere already) whether you wouldn't better use
list_for_each_entry()here in the first place.
I already agreed on doing that.
Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 5 lines
xen/common/hypfs.c new file +4
-0+static unsigned int hypfs_get_entry_len (struct hypfs_entry *entry) +{ +unsigned int len =0 ; +xen/common/hypfs.c line 193
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+switch ( entry->type ) + { +case hypfs_type_dir: + len = entry->dir->content_size; +break ; +case hypfs_type_string: + len =strlen (entry->str_val) +1 ; +break ; +case hypfs_type_uint: + len =11 ;/* longest possible printed value + 1 */ Why would uint values be restricted to 32 bits? There are plenty of 64-bit numbers that might be of interest exposing through this interface (and even more so if down the road we were to re-use this for something debugfs-like). And even without this I think it would be better to not have a literal number here - it'll be close to unnoticeable (without someone remembering) when porting to an arch with unsigned int wider than 32 bits.
Quoted 6 lines
Quoted 1 line
Support of 64-bit numbers would add "
hypfs_type_ulong".At this layer I dislike making assumptions on the bitness of int or long. Can we settle on either a type that's suitable for all sensible values (would likely be unsigned long long) or use fixed with identifications (
hypfs_type_u32et al)?
This is a problem with e.g. runtime parameters. The current int type parameters are unsigned int. So changing the type to hypfs_type_u32 would then make assumptions about unsigned int bitness.
My plan was to have hypfs_type_* according to the definitions of the variables pointed to. Maybe the sensible way to handle that would be to have hypfs_type_u(sz) similar to boot/runtime parameter handling.
Quoted 7 lines
Quoted 4 lines
So basically something like "(sizeof(type) * 8 * 3 + 9) / 10 + 1" ? (equivalent to: 10 bits make roughly 3 digits, round that up and add 0-Byte). This is correct for 1, 2, 4 and 8 byte values. For 16 byte values the result is 40, but it should be 41.
That's one option. The other - especially worthwhile to consider for large numbers - is to represent them in hex.
Hmm, with your request regarding .config, maybe just transferring the binary value and size might be the best option.
Quoted 66 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
xen/common/hypfs.c new file +12
-0+break ; + } + +return len; +} + +long do_hypfs_op (unsigned int cmd, +XEN_GUEST_HANDLE_PARAM (void ) arg1,unsigned long arg2, +XEN_GUEST_HANDLE_PARAM (void ) arg3,unsigned long arg4) +{ +int ret; +struct hypfs_entry *entry;Quoted 8 lines
xen/common/hypfs.c line 211
Quoted 6 lines
xen/common/hypfs.c new file +6
-0+unsigned int len; +static char path[XEN_HYPFS_MAX_PATHLEN ]; + +if ( !is_control_domain (current->domain) && + !is_hardware_domain (current->domain) ) +return -EPERM ;Replace by an XSM check?
Quoted 2 lines
Yes, but I could need some help here. How do I add a new hypercall in XSM?
I guess we should rope in Daniel (now Cc-ed).
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
+
spin_lock(&hypfs_lock);Wouldn't this better be an r/w lock from the beginning, requiring only read access here?
Depending on the further use cases we might even end up with per-element locks. I'm fine using a r/w lock for now.
Indeed I was thinking that write-value support would want a per-entry lock, with the global one only guarding the directory tree.
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
xen/common/hypfs.c new file +11
-0+ ret =hypfs_get_path_user (path, arg1, arg2); +if ( ret ) + goto out; + + entry =hypfs_get_entry (path); +if ( !entry ) + { + ret = -ENOENT ; + goto out; + } +Quoted 8 lines
xen/common/hypfs.c line 231
Quoted 6 lines
xen/common/hypfs.c new file +6
-0+switch ( cmd ) + { +case XEN_HYPFS_OP_read_contents: + { +char buf[12 ]; +char *val = buf;const void *?
Quoted 1 line
Why void *? The result is always a string.
const char * might be fine too, but the code really doesn't depend on this being other than void afaics.
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
+ * positive value: content buffer was too small, returned value is needed size
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Positive return values are problematic when reaching
INT_MAX. Are you convinced we want to have yet another instance?Are you convinced we want to return more then 2G long strings in one go?
Counter question: Are you convinced we'll stick to just strings? See the gzip-ing question on the later patch for example.
Nevertheless I'm questioning the idea to support GB sized buffers. This seems to be a perfect way to ask for problems.
But with binary value support we'd need a size reported anyway, so this should be settled then.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
xen/include/xen/hypfs.h new file +5
-0+struct hypfs_entry { +enum hypfs_entry_type type; +const char *name; +struct list_head list; +struct hypfs_dir *parent;
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Afaict you set this field, but you never use it anywhere. Why do you add it in the first place? (Initially I meant to ask whether this can be pointer-to-const.)
It will be needed for cases where the entry is being changed, e.g. when support for custom runtime parameters is added.
Can we defer its introduction until then?
Okay.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
xen/include/xen/hypfs.h line 23
Quoted 3 lines
xen/include/xen/hypfs.h new file +2
-0+union { +void *content;const?
Quoted 1 line
+ struct
hypfs_dir*dir;
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
const?
As already said above: mixing const and non-const pointers in a union looks fishy to me.
Hmm, well, I can see your point, but I think it still can be viewed to have its (perhaps largely documentation) value.
So the void pointer shouldn't be const IMO as it can be used as a replacement for all of the other union members. And the dir member is used as non const in case of adding an entry.
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 4 lines
xen/include/xen/hypfs.h new file +3
-0+char *str_val; +unsigned int *uint_val; + };xen/include/xen/hypfs.h line 37
Quoted 10 lines
xen/include/xen/hypfs.h new file +10
-0+}; + +extern struct hypfs_dir hypfs_root; + +int hypfs_new_dir (struct hypfs_dir *parent,const char *name, +struct hypfs_dir *dir); +int hypfs_new_entry_string (struct hypfs_dir *parent,const char *name, +char *val); +int hypfs_new_entry_uint (struct hypfs_dir *parent,const char *name, +unsigned int *val);Thinking about the lack of const on the last parameters here again - if these are for the pointed to values to be modifiable through this interface, then how would the "owning" component learn of the value having changed? Not everyone may need this, but I think there would want to be a callback. Until then perhaps better to add const here, promising that the values won't change behind the backs of the owners.
Quoted 4 lines
Quoted 1 line
That's what
hypfs_lockis for (and maybe later per-element locks).I don't understand: Are you intending random code to acquire this lock?
Oh, now I understand your initial question better.
You are right, in general cases a callback might be needed (just the same as with custom parameters).
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 2/6] xen: add basic hypervisor filesystem support
Quoted 34 lines · Jürgen Groß
Quoted 26 lines · Jan Beulich
Quoted 25 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 4 lines · Juergen Gross
xen/common/hypfs.c new file +4
-0+static unsigned int hypfs_get_entry_len (struct hypfs_entry *entry) +{ +unsigned int len =0 ; +xen/common/hypfs.c line 193
Quoted 10 lines
xen/common/hypfs.c new file +10
-0+switch ( entry->type ) + { +case hypfs_type_dir: + len = entry->dir->content_size; +break ; +case hypfs_type_string: + len =strlen (entry->str_val) +1 ; +break ; +case hypfs_type_uint: + len =11 ;/* longest possible printed value + 1 */ Why would uint values be restricted to 32 bits? There are plenty of 64-bit numbers that might be of interest exposing through this interface (and even more so if down the road we were to re-use this for something debugfs-like). And even without this I think it would be better to not have a literal number here - it'll be close to unnoticeable (without someone remembering) when porting to an arch with unsigned int wider than 32 bits.
Quoted 6 lines
Quoted 1 line
Support of 64-bit numbers would add "
hypfs_type_ulong".At this layer I dislike making assumptions on the bitness of int or long. Can we settle on either a type that's suitable for all sensible values (would likely be unsigned long long) or use fixed with identifications (
hypfs_type_u32et al)?
Quoted 7 lines
This is a problem with e.g. runtime parameters. The current int type parameters are unsigned int. So changing the type to
hypfs_type_u32would then make assumptions about unsigned int bitness.My plan was to have hypfs_type_* according to the definitions of the variables pointed to. Maybe the sensible way to handle that would be to have
hypfs_type_u(sz)similar to boot/runtime parameter handling.
Agreed.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
xen/include/xen/hypfs.h line 23
Quoted 2 lines
xen/include/xen/hypfs.h new file +2
-0+union { +void *content;const?
Quoted 1 line
+ struct
hypfs_dir*dir;const?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
As already said above: mixing const and non-const pointers in a union looks fishy to me.
Hmm, well, I can see your point, but I think it still can be viewed to have its (perhaps largely documentation) value.
So the void pointer shouldn't be const IMO as it can be used as a replacement for all of the other union members.
But this was exactly the reason why I considered it to become const - to disallow such use when it's about changing a value.
Quoted 2 lines
And the dir member is
used as non const in case of adding an entry.
Well, if there indeed is such a use (which I had looked for but apparently overlooked), then of course const shouldn't be added. Hence the question mark in my initial reply.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 3/6 libs: add libxenhypfs
In reply to Juergen GrossAdd the new library libxenhypfs for access to the hypervisor filesystem.
---
V1:
- rename to libxenhypfs
- add xenhypfs_write()
--- tools/Rules.mk | 6 + tools/libs/Makefile | 1 + tools/libs/hypfs/Makefile | 14 ++ tools/libs/hypfs/core.c | 252 ++++++++++++++++++++++++++++++++++++ tools/libs/hypfs/include/xenhypfs.h | 60 +++++++++ tools/libs/hypfs/libxenhypfs.map | 9 ++ tools/libs/hypfs/xenhypfs.pc.in | 10 ++ 7 files changed, 352 insertions(+) create mode 100644 tools/libs/hypfs/Makefile create mode 100644 tools/libs/hypfs/core.c create mode 100644 tools/libs/hypfs/include/xenhypfs.h create mode 100644 tools/libs/hypfs/libxenhypfs.map create mode 100644 tools/libs/hypfs/xenhypfs.pc.in
tools/Rules.mk +6 -0
@@ -19,6 +19,7 @@ XEN_LIBXENGNTTAB = $(XEN_ROOT)/tools/libs/gnttab XEN_LIBXENCALL = $(XEN_ROOT)/tools/libs/call XEN_LIBXENFOREIGNMEMORY = $(XEN_ROOT)/tools/libs/foreignmemory XEN_LIBXENDEVICEMODEL = $(XEN_ROOT)/tools/libs/devicemodel +XEN_LIBXENHYPFS = $(XEN_ROOT)/tools/libs/hypfs XEN_LIBXC = $(XEN_ROOT)/tools/libxc XEN_XENLIGHT = $(XEN_ROOT)/tools/libxl # Currently libxlutil lives in the same directory as libxenlight
@@ -134,6 +135,11 @@ SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLI LDLIBS_libxendevicemodel = $(SHDEPS_libxendevicemodel) $(XEN_LIBXENDEVICEMODEL)/libxendevicemodel$(libextension) SHLIB_libxendevicemodel = $(SHDEPS_libxendevicemodel) -Wl,-rpath-link=$(XEN_LIBXENDEVICEMODEL) +CFLAGS_libxenhypfs = -I$(XEN_LIBXENHYPFS)/include $(CFLAGS_xeninclude) +SHDEPS_libxenhypfs = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLIB_xencall) +LDLIBS_libxenhypfs = $(SHDEPS_libxenhypfs) $(XEN_LIBXENHYPFS)/libxenhypfs$(libextension) +SHLIB_libxenhypfs = $(SHDEPS_libxenhypfs) -Wl,-rpath-link=$(XEN_LIBXENHYPFS) + # code which compiles against libxenctrl get __XEN_TOOLS__ and # therefore sees the unstable hypercall interfaces. CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) $(CFLAGS_xeninclude) -D__XEN_TOOLS__
tools/libs/Makefile +1 -0
@@ -9,6 +9,7 @@ SUBDIRS-y += gnttab SUBDIRS-y += call SUBDIRS-y += foreignmemory SUBDIRS-y += devicemodel +SUBDIRS-y += hypfs ifeq ($(CONFIG_RUMP),y) SUBDIRS-y := toolcore
tools/libs/hypfs/Makefile new file +14 -0
@@ -0,0 +1,14 @@ +XEN_ROOT = $(CURDIR)/../../.. +include $(XEN_ROOT)/tools/Rules.mk + +MAJOR = 1 +MINOR = 0 +LIBNAME := hypfs +USELIBS := toollog toolcore call + +SRCS-y += core.c + +include ../libs.mk + +$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENHYPFS)/include +$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
tools/libs/hypfs/core.c new file +252 -0
252 lines not on this page · raw message
tools/libs/hypfs/include/xenhypfs.h new file +60 -0
60 lines not on this page · raw message
tools/libs/hypfs/libxenhypfs.map new file +9 -0
@@ -0,0 +1,9 @@ +VERS_1.0 { + global: + xenhypfs_open; + xenhypfs_close; + xenhypfs_read; + xenhypfs_readdir; + xenhypfs_write; + local: *; /* Do not expose anything by default */ +};
tools/libs/hypfs/xenhypfs.pc.in new file +10 -0
@@ -0,0 +1,10 @@ +prefix=@@prefix@@ +includedir=@@incdir@@ +libdir=@@libdir@@ + +Name: Xenhypfs +Description: The Xenhypfs library for Xen hypervisor +Version: @@version@@ +Cflags: -I${includedir} @@cflagslocal@@ +Libs: @@libsflag@@${libdir} -lxenhypfs +Requires.private: xentoolcore,xentoollog,xencall
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 4/6 tools: add xenfs tool
In reply to Juergen GrossAdd the xenfs tool for accessing the hypervisor filesystem.
---
V1:
- rename to xenhypfs
- don't use "--" for subcommands
- add write support
V2:
- escape non-printable characters per default with cat szbcommand (Ian Jackson)
- add -b option to cat subcommand (Ian Jackson)
- add man page
--- .gitignore | 1 + docs/man/xenhypfs.1.pod | 61 ++++++++++++++++++ tools/misc/Makefile | 6 ++ tools/misc/xenhypfs.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 228 insertions(+) create mode 100644 docs/man/xenhypfs.1.pod create mode 100644 tools/misc/xenhypfs.c
.gitignore +1 -0
@@ -370,6 +370,7 @@ tools/libxl/test_timedereg tools/libxl/test_fdderegrace tools/firmware/etherboot/eb-roms.h tools/firmware/etherboot/gpxe-git-snapshot.tar.gz +tools/misc/xenhypfs tools/misc/xenwatchdogd tools/misc/xen-hvmcrash tools/misc/xen-lowmemd
docs/man/xenhypfs.1.pod new file +61 -0
61 lines not on this page · raw message
tools/misc/Makefile +6 -0
@@ -24,6 +24,7 @@ INSTALL_SBIN-$(CONFIG_X86) += xen-lowmemd INSTALL_SBIN-$(CONFIG_X86) += xen-mfndump INSTALL_SBIN-$(CONFIG_X86) += xen-ucode INSTALL_SBIN += xencov +INSTALL_SBIN += xenhypfs INSTALL_SBIN += xenlockprof INSTALL_SBIN += xenperf INSTALL_SBIN += xenpm
@@ -86,6 +87,9 @@ xenperf: xenperf.o xenpm: xenpm.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) +xenhypfs: xenhypfs.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenhypfs) $(APPEND_LDFLAGS) + xenlockprof: xenlockprof.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
@@ -94,6 +98,8 @@ xen-hptool.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall) xen-hptool: xen-hptool.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) +xenhypfs.o: CFLAGS += $(CFLAGS_libxenhypfs) + # xen-mfndump incorrectly uses libxc internals xen-mfndump.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall) xen-mfndump: xen-mfndump.o
tools/misc/xenhypfs.c new file +160 -0
160 lines not on this page · raw message
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 5/6 xen: add /buildinfo/config entry to hypervisor filesystem
In reply to Juergen GrossAdd the /buildinfo/config entry to the hypervisor filesystem. This entry contains the .config file used to build the hypervisor.
--- .gitignore | 2 ++ docs/misc/hypfs-paths.pandoc | 9 +++++++++ xen/common/Makefile | 9 +++++++++ xen/common/hypfs.c | 17 +++++++++++++++++ xen/include/xen/kernel.h | 2 ++ xen/tools/Makefile | 9 +++++++-- xen/tools/bin2c.c | 28 ++++++++++++++++++++++++++++ 7 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 xen/tools/bin2c.c
.gitignore +2 -0
@@ -295,6 +295,7 @@ xen/arch/*/efi/boot.c xen/arch/*/efi/compat.c xen/arch/*/efi/efi.h xen/arch/*/efi/runtime.c +xen/common/config_data.c xen/include/headers*.chk xen/include/asm xen/include/asm-*/asm-offsets.h
@@ -312,6 +313,7 @@ xen/test/livepatch/xen_bye_world.livepatch xen/test/livepatch/xen_hello_world.livepatch xen/test/livepatch/xen_nop.livepatch xen/test/livepatch/xen_replace_world.livepatch +xen/tools/bin2c xen/tools/kconfig/.tmp_gtkcheck xen/tools/kconfig/.tmp_qtcheck xen/tools/symbols
docs/misc/hypfs-paths.pandoc +9 -0
@@ -93,3 +93,12 @@ A populated Xen hypervisor file system might look like the following example: #### / The root of the hypervisor file system. + +#### /buildinfo/ + +A directory containing static information generated while building the +hypervisor. + +#### /buildinfo/config = STRING + +The contents of the `xen/.config` file at the time of the hypervisor build.
xen/common/Makefile +9 -0
@@ -1,6 +1,7 @@ obj-$(CONFIG_ARGO) += argo.o obj-y += bitmap.o obj-y += bsearch.o +obj-y += config_data.o obj-$(CONFIG_CORE_PARKING) += core_parking.o obj-y += cpu.o obj-y += cpupool.o
@@ -79,3 +80,11 @@ subdir-$(CONFIG_UBSAN) += ubsan subdir-$(CONFIG_NEEDS_LIBELF) += libelf subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt + +config_data.c: ../.config + ( echo "char xen_config_data[] ="; \ + ../tools/bin2c <$<; \ + echo ";" ) > $@ + +clean:: + rm config_data.c 2>/dev/null || true
xen/common/hypfs.c +17 -0
@@ -25,6 +25,10 @@ static struct hypfs_entry hypfs_root_entry = { .dir = &hypfs_root, }; +static struct hypfs_dir hypfs_buildinfo = { + .list =LIST_HEAD_INIT (hypfs_buildinfo.list), +}; +static int hypfs_add_entry (struct hypfs_dir *parent,struct hypfs_entry *new) {int ret = -ENOENT ;
@@ -316,3 +320,16 @@ long do_hypfs_op(unsigned int cmd,return ret; } + +static int __init hypfs_init (void ) +{ +int ret; + + ret =hypfs_new_dir (&hypfs_root,"buildinfo" , &hypfs_buildinfo); +BUG_ON (ret); + ret =hypfs_new_entry_string (&hypfs_buildinfo,"config" , xen_config_data); +BUG_ON (ret); + +return 0 ; +} +__initcall (hypfs_init);
xen/include/xen/kernel.h +2 -0
@@ -100,5 +100,7 @@ extern enum system_state {bool_t is_active_kernel_text (unsigned long addr); +extern char xen_config_data[]; +#endif /* _LINUX_KERNEL_H */
xen/tools/Makefile +7 -2
@@ -1,13 +1,18 @@ include $(XEN_ROOT)/Config.mk +PROGS = symbols bin2c + .PHONY: default default: - $(MAKE) symbols + $(MAKE) $(PROGS) .PHONY: clean clean: - rm -f *.o symbols + rm -f *.o $(PROGS) symbols: symbols.c $(HOSTCC) $(HOSTCFLAGS) -o $@ $< + +bin2c: bin2c.c + $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
xen/tools/bin2c.c new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Unloved program to convert a binary on stdin to a C include on stdout +* +* Jan 1999 Matt Mackall <[email protected]> +* +* This software may be used and distributed according to the terms +* of the GNU General Public License, incorporated herein by reference. +*/ + +#include <stdio.h> + +int main (int argc,char *argv[]) +{ +int ch, total =0 ; + +do { +printf ("\t\"" ); +while ((ch =getchar ()) !=EOF ) { + total++; +printf ("\\x%02x" , ch); +if (total %16 ==0 ) +break ; + } +printf ("\"\n" ); + }while (ch !=EOF ); + +return 0 ; +}
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 5/6] xen: add /buildinfo/config entry to hypervisor filesystem
Quoted 2 lines · Juergen Gross
Add the /buildinfo/config entry to the hypervisor filesystem. This entry contains the .config file used to build the hypervisor.
I think this is the 2nd step ahead of the 1st: Much of the stuff exposed as XENVER_* sub-ops should manifest itself here ahead of exposing xen/.config.
xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 87
Quoted 9 lines
xen/common/Makefile +5
-0@@ -79,3 +80,11 @@ subdir-$(CONFIG_UBSAN) += ubsan subdir-$(CONFIG_NEEDS_LIBELF) += libelf subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt + +config_data.c: ../.config + ( echo "char xen_config_data[] ="; \ + ../tools/bin2c <$<; \ + echo ";" ) > $@
This is the typical kind of construct that may break (a subsequent build attempt) when interrupted in the middle. This pretty clearly is a move-if-changed candidate, at the same time also avoiding a (cheap, but anyway) pointless re-build in case .config was touched without actually changing.
Furthermore is there a reason to expose this as plain text, when Linux exposes a gzip-ed version in /proc? The file isn't very large now, but this was also the case for Linux many years ago.
Quoted 20 lines
xen/common/hypfs.c +7
-0@@ -25,6 +25,10 @@ static struct hypfs_entry hypfs_root_entry = { .dir = &hypfs_root, }; +static struct hypfs_dir hypfs_buildinfo = { + .list =LIST_HEAD_INIT (hypfs_buildinfo.list), +}; +static int hypfs_add_entry (struct hypfs_dir *parent,struct hypfs_entry *new) {int ret = -ENOENT ;@@ -316,3 +320,16 @@ long do_hypfs_op(unsigned int cmd,return ret; } + +static int __init hypfs_init (void ) +{
xen/common/hypfs.c long do_hypfs_op(unsigned int cmd, · line 335
Quoted 10 lines
xen/common/hypfs.c +10
-0+int ret; + + ret =hypfs_new_dir (&hypfs_root,"buildinfo" , &hypfs_buildinfo); +BUG_ON (ret); + ret =hypfs_new_entry_string (&hypfs_buildinfo,"config" , xen_config_data); +BUG_ON (ret); + +return 0 ; +} +__initcall (hypfs_init);
Hmm, do you really want to centralize population of the file system here, rather than having the individual components take care of it?
xen/tools/Makefile line 8
Quoted 12 lines
xen/tools/Makefile +3
-1@@ -1,13 +1,18 @@ include $(XEN_ROOT)/Config.mk +PROGS = symbols bin2c + .PHONY: default default: - $(MAKE) symbols + $(MAKE) $(PROGS)
Could I ask you to take the opportunity and do away with the unnecessary (as it seems to me) make recursion? $(PROGS) could easily become a dependency of "default" afaict.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 5/6] xen: add /buildinfo/config entry to hypervisor filesystem
Quoted 7 lines · Jan Beulich
Quoted 2 lines · Juergen Gross
Add the /buildinfo/config entry to the hypervisor filesystem. This entry contains the .config file used to build the hypervisor.
I think this is the 2nd step ahead of the 1st: Much of the stuff exposed as XENVER_* sub-ops should manifest itself here ahead of exposing xen/.config.
Yes and no. This is meant as a replacement for my previous patch series adding .config read support.
It is no problem to add other data as well, but the need for being able to read .config contents was already agreed on.
Quoted 16 lines
xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 87
Quoted 10 lines
xen/common/Makefile +5
-0@@ -79,3 +80,11 @@ subdir-$(CONFIG_UBSAN) += ubsan subdir-$(CONFIG_NEEDS_LIBELF) += libelf subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt + +config_data.c: ../.config + ( echo "char xen_config_data[] ="; \ + ../tools/bin2c <$<; \ + echo ";" ) > $@This is the typical kind of construct that may break (a subsequent build attempt) when interrupted in the middle. This pretty clearly is a move-if-changed candidate, at the same time also avoiding a (cheap, but anyway) pointless re-build in case .config was touched without actually changing.
Okay.
Quoted 4 lines
Furthermore is there a reason to expose this as plain text, when Linux exposes a gzip-ed version in /proc? The file isn't very large now, but this was also the case for Linux many years ago.
gzip data may contain bytes with 0x00. Supporting that would require a different interface at all levels.
Quoted 26 lines
Quoted 26 lines
xen/common/hypfs.c +12
-0@@ -25,6 +25,10 @@ static struct hypfs_entry hypfs_root_entry = { .dir = &hypfs_root, }; +static struct hypfs_dir hypfs_buildinfo = { + .list =LIST_HEAD_INIT (hypfs_buildinfo.list), +}; +static int hypfs_add_entry (struct hypfs_dir *parent,struct hypfs_entry *new) {int ret = -ENOENT ;@@ -316,3 +320,16 @@ long do_hypfs_op(unsigned int cmd,return ret; } + +static int __init hypfs_init (void ) +{ +int ret; + + ret =hypfs_new_dir (&hypfs_root,"buildinfo" , &hypfs_buildinfo); +BUG_ON (ret); + ret =hypfs_new_entry_string (&hypfs_buildinfo,"config" , xen_config_data);
Quoted 8 lines
xen/common/hypfs.c long do_hypfs_op(unsigned int cmd, · line 335
Quoted 5 lines
xen/common/hypfs.c +5
-0+BUG_ON (ret); + +return 0 ; +} +__initcall (hypfs_init);Hmm, do you really want to centralize population of the file system here, rather than having the individual components take care of it?
I can add a new source, e.g. common/buildinfo.c if you like that better.
Quoted 7 lines
Quoted 7 lines
xen/tools/Makefile +0
-0@@ -1,13 +1,18 @@ include $(XEN_ROOT)/Config.mk
Quoted 10 lines
xen/tools/Makefile line 8
Quoted 6 lines
xen/tools/Makefile +3
-1+PROGS = symbols bin2c + .PHONY: default default: - $(MAKE) symbols + $(MAKE) $(PROGS)Could I ask you to take the opportunity and do away with the unnecessary (as it seems to me) make recursion? $(PROGS) could easily become a dependency of "default" afaict.
Fine with me.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 5/6] xen: add /buildinfo/config entry to hypervisor filesystem
Quoted 16 lines · Jürgen Groß
Quoted 14 lines · Jan Beulich
xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 87
Quoted 9 lines · Juergen Gross
xen/common/Makefile +5
-0@@ -79,3 +80,11 @@ subdir-$(CONFIG_UBSAN) += ubsan subdir-$(CONFIG_NEEDS_LIBELF) += libelf subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt + +config_data.c: ../.config + ( echo "char xen_config_data[] ="; \ + ../tools/bin2c <$<; \ + echo ";" ) > $@Furthermore is there a reason to expose this as plain text, when Linux exposes a gzip-ed version in /proc? The file isn't very large now, but this was also the case for Linux many years ago.
Quoted 2 lines
gzip data may contain bytes with
0x00. Supporting that would require a different interface at all levels.
Then perhaps better do so now, when the code is still in flux, than after the fact, especially if "at all levels" is meant to also include the public interface?
Quoted 34 lines
Quoted 25 lines
Quoted 25 lines
xen/common/hypfs.c +12
-0@@ -25,6 +25,10 @@ static struct hypfs_entry hypfs_root_entry = { .dir = &hypfs_root, }; +static struct hypfs_dir hypfs_buildinfo = { + .list =LIST_HEAD_INIT (hypfs_buildinfo.list), +}; +static int hypfs_add_entry (struct hypfs_dir *parent,struct hypfs_entry *new) {int ret = -ENOENT ;@@ -316,3 +320,16 @@ long do_hypfs_op(unsigned int cmd,return ret; } + +static int __init hypfs_init (void ) +{ +int ret; + + ret =hypfs_new_dir (&hypfs_root,"buildinfo" , &hypfs_buildinfo); +BUG_ON (ret); + ret =hypfs_new_entry_string (&hypfs_buildinfo,"config" , xen_config_data);Quoted 8 lines
xen/common/hypfs.c long do_hypfs_op(unsigned int cmd, · line 335
Quoted 5 lines
xen/common/hypfs.c +5
-0+BUG_ON (ret); + +return 0 ; +} +__initcall (hypfs_init);Hmm, do you really want to centralize population of the file system here, rather than having the individual components take care of it?
Quoted 1 line
I can add a new source, e.g.
common/buildinfo.cif you like that better.
I was rather thinking of moving this into common/kernel.c, next to the version hypercall handling, and together with exposing the suggested values here ahead of exposing .config.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 5/6] xen: add /buildinfo/config entry to hypervisor filesystem
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Jürgen Groß
Quoted 14 lines · Jan Beulich
xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 87
Quoted 9 lines · Juergen Gross
xen/common/Makefile +5
-0@@ -79,3 +80,11 @@ subdir-$(CONFIG_UBSAN) += ubsan subdir-$(CONFIG_NEEDS_LIBELF) += libelf subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt + +config_data.c: ../.config + ( echo "char xen_config_data[] ="; \ + ../tools/bin2c <$<; \ + echo ";" ) > $@Furthermore is there a reason to expose this as plain text, when Linux exposes a gzip-ed version in /proc? The file isn't very large now, but this was also the case for Linux many years ago.
Quoted 6 lines
Quoted 2 lines
gzip data may contain bytes with
0x00. Supporting that would require a different interface at all levels.Then perhaps better do so now, when the code is still in flux, than after the fact, especially if "at all levels" is meant to also include the public interface?
I'll have a look into that.
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 21 lines
xen/common/hypfs.c +7
-0@@ -25,6 +25,10 @@ static struct hypfs_entry hypfs_root_entry = { .dir = &hypfs_root, }; +static struct hypfs_dir hypfs_buildinfo = { + .list =LIST_HEAD_INIT (hypfs_buildinfo.list), +}; +static int hypfs_add_entry (struct hypfs_dir *parent,struct hypfs_entry *new) {int ret = -ENOENT ;@@ -316,3 +320,16 @@ long do_hypfs_op(unsigned int cmd,return ret; } + +static int __init hypfs_init (void ) +{xen/common/hypfs.c long do_hypfs_op(unsigned int cmd, · line 335
Quoted 10 lines
xen/common/hypfs.c +10
-0+int ret; + + ret =hypfs_new_dir (&hypfs_root,"buildinfo" , &hypfs_buildinfo); +BUG_ON (ret); + ret =hypfs_new_entry_string (&hypfs_buildinfo,"config" , xen_config_data); +BUG_ON (ret); + +return 0 ; +} +__initcall (hypfs_init);Hmm, do you really want to centralize population of the file system here, rather than having the individual components take care of it?
Quoted 5 lines
Quoted 1 line
I can add a new source, e.g.
common/buildinfo.cif you like that better.I was rather thinking of moving this into
common/kernel.c, next to the version hypercall handling, and together with exposing the suggested values here ahead of exposing .config.
Okay.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 6/6 xen: add runtime parameter reading support to hypfs
In reply to Juergen GrossAdd support to read values of hypervisor runtime parameters via the hypervisor file system for all unsigned integer type runtime parameters.
--- docs/misc/hypfs-paths.pandoc | 9 +++++++++ xen/common/kernel.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
docs/misc/hypfs-paths.pandoc +9 -0
@@ -102,3 +102,12 @@ hypervisor. #### /buildinfo/config = STRING The contents of the `xen/.config` file at the time of the hypervisor build. + +#### /params/ + +A directory of runtime parameters (those can be set via xl set-parameters). + +#### /params/* + +The single parameters. The description of the different parameters can be +found in `docs/misc/xen-command-line.pandoc`.
xen/common/kernel.c +39 -0
@@ -7,6 +7,7 @@#include <xen/init.h> #include <xen/lib.h> #include <xen/errno.h> +#include <xen/hypfs.h> #include <xen/version.h> #include <xen/sched.h> #include <xen/paging.h>
@@ -320,6 +321,44 @@ int cmdline_strcmp(const char *frag, const char *name) } } +static struct hypfs_dir hypfs_params = { + .list =LIST_HEAD_INIT (hypfs_params.list), +}; + +static int __init runtime_param_hypfs_add (void ) +{ +const struct kernel_param *param; +int ret; + + ret =hypfs_new_dir (&hypfs_root,"params" , &hypfs_params); +BUG_ON (ret); + +for ( param = __param_start; param < __param_end; param++ ) + { +switch ( param->type ) + { +case OPT_UINT : +if ( param->len ==sizeof (unsigned int ) ) + ret =hypfs_new_entry_uint (&hypfs_params, param->name, + (unsigned int *)(param->par.var)); +break ; + +case OPT_STR : + ret =hypfs_new_entry_uint (&hypfs_params, param->name, + param->par.var); +break ; + +default : +break ; + } + +BUG_ON (ret); + } + +return 0 ; +} +__initcall (runtime_param_hypfs_add); +unsigned int tainted;/**
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 6/6] xen: add runtime parameter reading support to hypfs
Quoted 2 lines · Juergen Gross
Add support to read values of hypervisor runtime parameters via the hypervisor file system for all unsigned integer type runtime parameters.
What about string ones (which you seem to handle in the code, but see also there)?
Quoted 14 lines
xen/common/kernel.c +10
-0@@ -320,6 +321,44 @@ int cmdline_strcmp(const char *frag, const char *name) } } +static struct hypfs_dir hypfs_params = { + .list =LIST_HEAD_INIT (hypfs_params.list), +}; + +static int __init runtime_param_hypfs_add (void ) +{ +const struct kernel_param *param; +int ret; + + ret =hypfs_new_dir (&hypfs_root,"params" , &hypfs_params);
xen/common/kernel.c int cmdline_strcmp(const char *frag, const char *name) · line 343
Quoted 10 lines
xen/common/kernel.c +10
-0+BUG_ON (ret); + +for ( param = __param_start; param < __param_end; param++ ) + { +switch ( param->type ) + { +case OPT_UINT : +if ( param->len ==sizeof (unsigned int ) ) + ret =hypfs_new_entry_uint (&hypfs_params, param->name, + (unsigned int *)(param->par.var));
Stray pair or parentheses. I also don't see the need for the cast, with the "var" union member being "void *".
xen/common/kernel.c int cmdline_strcmp(const char *frag, const char *name) · line 348
Quoted 5 lines
xen/common/kernel.c +5
-0+break ; + +case OPT_STR : + ret =hypfs_new_entry_uint (&hypfs_params, param->name, + param->par.var);
hypfs_new_entry_string()?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH v2 6/6] xen: add runtime parameter reading support to hypfs
Quoted 6 lines · Jan Beulich
Quoted 2 lines · Juergen Gross
Add support to read values of hypervisor runtime parameters via the hypervisor file system for all unsigned integer type runtime parameters.
What about string ones (which you seem to handle in the code, but see also there)?
Oh, right, this was a late addition.
Quoted 20 lines
Quoted 20 lines
xen/common/kernel.c +15
-0@@ -320,6 +321,44 @@ int cmdline_strcmp(const char *frag, const char *name) } } +static struct hypfs_dir hypfs_params = { + .list =LIST_HEAD_INIT (hypfs_params.list), +}; + +static int __init runtime_param_hypfs_add (void ) +{ +const struct kernel_param *param; +int ret; + + ret =hypfs_new_dir (&hypfs_root,"params" , &hypfs_params); +BUG_ON (ret); + +for ( param = __param_start; param < __param_end; param++ ) + { + switch ( param->type )
Quoted 8 lines
xen/common/kernel.c int cmdline_strcmp(const char *frag, const char *name) · line 343
Quoted 5 lines
xen/common/kernel.c +5
-0+ { +case OPT_UINT : +if ( param->len ==sizeof (unsigned int ) ) + ret =hypfs_new_entry_uint (&hypfs_params, param->name, + (unsigned int *)(param->par.var));Stray pair or parentheses. I also don't see the need for the cast, with the "var" union member being "void *".
Right, will drop the cast.
Quoted 8 lines
xen/common/kernel.c int cmdline_strcmp(const char *frag, const char *name) · line 348
Quoted 6 lines
xen/common/kernel.c +5
-0+break ; + +case OPT_STR : + ret =hypfs_new_entry_uint (&hypfs_params, param->name, + param->par.var);
hypfs_new_entry_string()?
Yes.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel