s390: Hypervisor File System
PATCH 1/1 s390: Hypervisor File System
On zSeries machines there exists an interface which allows the operating system to retrieve LPAR hypervisor accounting data. For example, it is possible to get usage data for physical and virtual cpus. In order to provide this information to user space programs, I implemented a new virtual Linux file system named 'hypfs' using the Linux 2.6 libfs framework. The name 'hypfs' stands for 'Hypervisor Filesystem'. All the accounting information is put into different virtual files which can be accessed from user space. All data is represented as ASCII strings.
When the file system is mounted the accounting information is retrieved and a file system tree is created with the attribute files containing the cpu information. The content of the files remains unchanged until a new update is made. An update can be triggered from user space through writing 'something' into a special purpose update file.
We create the following directory structure:
<mount-point>/
update
cpus/
<cpu-id>
type
mgmtime
<cpu-id>
...
hyp/
type
systems/
<lpar-name>
cpus/
<cpu-id>
type
mgmtime
cputime
onlinetime
<cpu-id>
...
<lpar-name>
cpus/
...- update: File to trigger update
- cpus/: Directory for all physical cpus
- cpus/<cpu-id>/: Directory for one physical cpu.
- cpus/<cpu-id>/type: Type name of physical zSeries cpu.
- cpus/<cpu-id>/mgmtime: Physical-LPAR-management time in microseconds.
- hyp/: Directory for hypervisor information
- hyp/type: Typ of hypervisor (currently only 'LPAR Hypervisor')
- systems/: Directory for all LPARs
- systems/<lpar-name>/: Directory for one LPAR.
- systems/<lpar-name>/cpus/<cpu-id>/: Directory for the virtual cpus
- systems/<lpar-name>/cpus/<cpu-id>/type: Typ of cpu.
- systems/<lpar-name>/cpus/<cpu-id>/mgmtime:
Accumulated number of microseconds during which a physical CPU was assigned to the logical cpu and the cpu time was consumed by the hypervisor and was not provided to
the LPAR (LPAR overhead).
- systems/<lpar-name>/cpus/<cpu-id>/cputime:
Accumulated number of microseconds during which a physical CPU was assigned to the logical cpu and the cpu time was consumed by the LPAR.
- systems/<lpar-name>/cpus/<cpu-id>/onlinetime:
Accumulated number of microseconds during which the logical CPU has been online.
As mount point for the filesystem /sys/hypervisor is created.
The update process is triggered when writing 'something' into the 'update' file at the top level hypfs directory. You can do this e.g. with 'echo 1 > update'. During the update the whole directory structure is deleted and built up again.
---
arch/s390/Kconfig | 7 arch/s390/Makefile | 2 arch/s390/hypfs/Makefile | 7 arch/s390/hypfs/hypfs.h | 30 ++ arch/s390/hypfs/hypfs_diag.c | 628 +++++++++++++++++++++++++++++++++++++++++++ arch/s390/hypfs/hypfs_diag.h | 16 + arch/s390/hypfs/inode.c | 462 +++++++++++++++++++++++++++++++ 7 files changed, 1151 insertions(+), 1 deletion(-)
arch/s390/Kconfig +7 -0
@@ -442,6 +442,13 @@ config NO_IDLE_HZ_INIT The HZ timer is switched off in idle by default. That means the HZ timer is already disabled at boot time. +config HYPFS_FS + bool "s390 hypervisor file system support" + default y + help + This is a virtual file system intended to provide accounting + information in a s390 hypervisor environment. + config KEXEC bool "kexec system call (EXPERIMENTAL)" depends on EXPERIMENTAL
arch/s390/Makefile +1 -1
@@ -77,7 +77,7 @@ LDFLAGS_vmlinux := -e start head-y := arch/$(ARCH)/kernel/head.o arch/$(ARCH)/kernel/init_task.o core-y += arch/$(ARCH)/mm/ arch/$(ARCH)/kernel/ arch/$(ARCH)/crypto/ \ - arch/$(ARCH)/appldata/ + arch/$(ARCH)/appldata/ arch/$(ARCH)/hypfs/ libs-y += arch/$(ARCH)/lib/ drivers-y += drivers/s390/ drivers-$(CONFIG_MATHEMU) += arch/$(ARCH)/math-emu/
arch/s390/hypfs/Makefile +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for the linux hypfs filesystem routines. +# + +obj-$(CONFIG_HYPFS_FS) += hypfs.o + +hypfs-objs := inode.o hypfs_diag.o
arch/s390/hypfs/hypfs.h +30 -0
@@ -0,0 +1,30 @@ +/* +* fs/hypfs/hypfs.h +* Hypervisor filesystem for Linux on s390. +* +* Copyright (C) IBM Corp. 2006 +* Author(s): Michael Holzheu <[email protected]> +*/ + +#ifndef _HYPFS_H_ +#define _HYPFS_H_ + +#include <linux/fs.h> +#include <linux/types.h> + +#define REG_FILE_MODE 0440 +#define UPDATE_FILE_MODE 0220 +#define DIR_MODE 0550 + +extern struct dentry *hypfs_mkdir (struct super_block *sb,struct dentry *parent, +const char *name); + +extern struct dentry *hypfs_create_u64 (struct super_block *sb, +struct dentry *dir,const char *name, +__u64 value); + +extern struct dentry *hypfs_create_str (struct super_block *sb, +struct dentry *dir,const char *name, +char *string); + +#endif /* _HYPFS_H_ */
arch/s390/hypfs/hypfs_diag.c +628 -0
628 lines not on this page · raw message
arch/s390/hypfs/hypfs_diag.h +16 -0
@@ -0,0 +1,16 @@ +/* +* fs/hypfs/hypfs_diag.h +* Hypervisor filesystem for Linux on s390. +* +* Copyright (C) IBM Corp. 2006 +* Author(s): Michael Holzheu <[email protected]> +*/ + +#ifndef _HYPFS_DIAG_H_ +#define _HYPFS_DIAG_H_ + +extern int diag_init (void ); +extern void diag_exit (void ); +extern int diag_create_files (struct super_block *sb,struct dentry *root); + +#endif /* _HYPFS_DIAG_H_ */
arch/s390/hypfs/inode.c +462 -0
462 lines not on this page · raw message
Quoted 22 lines · Michael Holzheu
arch/s390/hypfs/hypfs_diag.c +22
-0+ +static inline int info_blk_hdr__size (enum diag204_format type) +{ +if (type ==INFO_SIMPLE ) +return sizeof (struct info_blk_hdr ); +else /* INFO_EXT */ +return sizeof (struct x_info_blk_hdr ); +} + +static inline __u8 info_blk_hdr__npar (enum diag204_format type,void *hdr) +{ +if (type ==INFO_SIMPLE ) +return ((struct info_blk_hdr *)hdr)->npar; +else /* INFO_EXT */ +return ((struct x_info_blk_hdr *)hdr)->npar; +} + +static inline __u8 info_blk_hdr__flags (enum diag204_format type,void *hdr) +{ +if (type ==INFO_SIMPLE ) +return ((struct info_blk_hdr *)hdr)->flags; +else /* INFO_EXT */
arch/s390/hypfs/hypfs_diag.c line 100
Quoted 10 lines
arch/s390/hypfs/hypfs_diag.c +10
-0+return ((struct x_info_blk_hdr *)hdr)->flags; +} + +static inline __u16 info_blk_hdr__pcpus (enum diag204_format type,void *hdr) +{ +if (type ==INFO_SIMPLE ) +return ((struct info_blk_hdr *)hdr)->phys_cpus; +else /* INFO_EXT */ +return ((struct x_info_blk_hdr *)hdr)->phys_cpus; +}
Hmm. Another possible approach would be to create a small struct with a couple of functions, have one function each for type==INFO_SIMPLE and type==INFO_EXT and fill the struct either with one set of functions or the other.
Whether that would make more sense than your current approach, I cannot judge. Iirc, function calls are still fairly expensive on s390, so maybe not.
Jörn
Signature · 3 lines
Courage is not the absence of fear, but rather the judgement that something else is more important than fear. -- Ambrose Redmoon
Hi Jörn,
Jörn Engel <[email protected]> wrote on 04/28/2006 11:43:20 AM:
Quoted 11 lines · Michael Holzheu
arch/s390/hypfs/hypfs_diag.c
Quoted 10 lines
arch/s390/hypfs/hypfs_diag.c +10
-0+ +static inline int info_blk_hdr__size (enum diag204_format type) +{ +if (type ==INFO_SIMPLE ) +return sizeof (struct info_blk_hdr ); +else /* INFO_EXT */ +return sizeof (struct x_info_blk_hdr ); +} + +static inline __u8 info_blk_hdr__npar(enum diag204_format type, void
*hdr)
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c +8
-0+{ +if (type ==INFO_SIMPLE ) +return ((struct info_blk_hdr *)hdr)->npar; +else /* INFO_EXT */ +return ((struct x_info_blk_hdr *)hdr)->npar; +} + +static inline __u8 info_blk_hdr__flags(enum diag204_format type, void
*hdr)
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c +8
-0+{ +if (type ==INFO_SIMPLE ) +return ((struct info_blk_hdr *)hdr)->flags; +else /* INFO_EXT */ +return ((struct x_info_blk_hdr *)hdr)->flags; +} + +static inline __u16 info_blk_hdr__pcpus(enum diag204_format type,void
*hdr)
Quoted 12 lines
arch/s390/hypfs/hypfs_diag.c line 100
Quoted 6 lines
arch/s390/hypfs/hypfs_diag.c +6
-0+{ +if (type ==INFO_SIMPLE ) +return ((struct info_blk_hdr *)hdr)->phys_cpus; +else /* INFO_EXT */ +return ((struct x_info_blk_hdr *)hdr)->phys_cpus; +}Hmm. Another possible approach would be to create a small struct with a couple of functions, have one function each for type==INFO_SIMPLE and type==INFO_EXT and fill the struct either with one set of functions or the other.
Quoted 4 lines
Whether that would make more sense than your current approach, I cannot judge. Iirc, function calls are still fairly expensive on s390, so maybe not.
We discussed that! If we would have more than two data formats we would have taken your approach. But for only two, I think it is ok to do it my way!
Michael
Quoted 4 lines · Michael Holzheu
We discussed that! If we would have more than two data formats we would have taken your approach. But for only two, I think it is ok to do it my way!
Sounds fair. Sorry I missed the previous discussion.
Jörn
Signature · 2 lines
All art is but imitation of nature. -- Lucius Annaeus Seneca
Quoted 10 lines · Michael Holzheu
On zSeries machines there exists an interface which allows the operating system to retrieve LPAR hypervisor accounting data. For example, it is possible to get usage data for physical and virtual cpus. In order to provide this information to user space programs, I implemented a new virtual Linux file system named 'hypfs' using the Linux 2.6 libfs framework. The name 'hypfs' stands for 'Hypervisor Filesystem'. All the accounting information is put into different virtual files which can be accessed from user space. All data is represented as ASCII strings.
Quoted 5 lines
When the file system is mounted the accounting information is retrieved and a file system tree is created with the attribute files containing the cpu information. The content of the files remains unchanged until a new update is made. An update can be triggered from user space through writing 'something' into a special purpose update file.
Looks sane. A few comments, mainly minor, but a few bugs:
arch/s390/Kconfig config NO_IDLE_HZ_INIT · line 451
Quoted 7 lines
arch/s390/Kconfig +7
-0+config HYPFS_FS + bool "s390 hypervisor file system support" + default y + help + This is a virtual file system intended to provide accounting + information in a s390 hypervisor environment. +
"in an s390"?
Quoted 1 line
+static inline int
diag204(unsigned long subcode, unsigned long size, void *addr)
There's a lot of inlining going on. Is it excessive?
arch/s390/hypfs/hypfs_diag.c line 368
Quoted 9 lines
...
arch/s390/hypfs/hypfs_diag.c +7
-0+static int diag204_probe (void ) +{ +void *buf; +int pages, rc; + + pages =diag204 (SUBC_RSI |INFO_EXT ,0 ,0 ); +if (pages >0 ) {
In other places, you return an error if (pages < 0), but not here.
Quoted 26 lines
arch/s390/hypfs/hypfs_diag.c +26
-0+ buf =kmalloc (pages *PAGE_SIZE ,GFP_KERNEL ); +if (!buf) { + rc = -ENOMEM ; + goto err_out; + } +if (diag204 (SUBC_STIB7 |INFO_EXT , pages, buf) >=0 ) { + diag204_store_sc =SUBC_STIB7 ; + diag204_info_type =INFO_EXT ; + goto out; + } +if (diag204 (SUBC_STIB6 |INFO_EXT , pages, buf) >=0 ) { + diag204_store_sc =SUBC_STIB7 ; + diag204_info_type =INFO_EXT ; + goto out; + } +kfree (buf); + } + buf =kmalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!buf) { + rc = -ENOMEM ; + goto err_out; + } +if (diag204 (SUBC_STIB4 |INFO_SIMPLE , pages, buf) >=0 ) { + diag204_store_sc =SUBC_STIB4 ; + diag204_info_type =INFO_SIMPLE ; + goto out;
arch/s390/hypfs/hypfs_diag.c line 404
Quoted 10 lines
arch/s390/hypfs/hypfs_diag.c +10
-0+ }else { + rc = -ENOSYS ; + goto err_out; + } + out: + rc =0 ; + err_out: +kfree (buf); +return rc; +}
The indenting of the labels is a bit unconventional.
Quoted 13 lines
arch/s390/hypfs/hypfs_diag.c +13
-0+static void *diag204_store (void ) +{ +void *buf; +int pages; + +if (diag204_store_sc ==SUBC_STIB4 ) + pages =1 ; +else + pages =diag204 (SUBC_RSI | diag204_info_type,0 ,0 ); + +if (pages <0 ) +return ERR_PTR (-ENOSYS ); +
arch/s390/hypfs/hypfs_diag.c line 428
Quoted 10 lines
arch/s390/hypfs/hypfs_diag.c +10
-0+ buf =kmalloc (pages *PAGE_SIZE ,GFP_KERNEL ); +if (!buf) +return ERR_PTR (-ENOMEM ); + +if (diag204 (diag204_store_sc | diag204_info_type, pages, buf) <0 ) { +kfree (buf); +return ERR_PTR (-ENOSYS ); + } +return buf; +}
One wonders if
pages = diag204(...); return kmalloc(pages * PAGE_SIZE, gfp_flags);
would be a useful helper function.
Quoted 14 lines
arch/s390/hypfs/hypfs_diag.c +14
-0+ asmvolatile (" diag %0,%1,0x224\n" + : :"d" (0 ),"d" (ptr) :"memory" ); +} + +static inline int diag224_get_name_table (void ) +{ +/* memory must be below 2GB */ + diag224_cpu_names =kmalloc (PAGE_SIZE ,GFP_KERNEL |GFP_DMA ); +if (!diag224_cpu_names) +return -ENOMEM ; +diag224 (diag224_cpu_names); +EBCASC (diag224_cpu_names +16 , (*diag224_cpu_names +1 ) *16 ); +return 0 ; +}
arch/s390/hypfs/hypfs_diag.c line 457
Quoted 10 lines
arch/s390/hypfs/hypfs_diag.c +10
-0+ +static inline void diag224_delete_name_table (void ) +{ +kfree (diag224_cpu_names); +} + +static int diag224_idx2name (int index,char *name) +{ +memcpy (name, diag224_cpu_names + ((index +1 ) *16 ),16 ); + name[16 ] =0 ;
Should this be "15"? I guess not...
Quoted 9 lines
arch/s390/hypfs/hypfs_diag.c +9
-0+strstrip (name); +return 0 ; +} + +int diag_init (void ) +{ +int rc; + +if (diag204_probe ()) {
arch/s390/hypfs/hypfs_diag.c line 476
Quoted 10 lines
arch/s390/hypfs/hypfs_diag.c +10
-0+printk (KERN_ERR "hypfs: diag 204 not working." ); +return -ENODATA ; + } + rc =diag224_get_name_table (); +if (rc) { +diag224_delete_name_table (); +printk (KERN_ERR "hypfs: could not get name table.\n" ); + } +return rc; +}
This can be __init
arch/s390/hypfs/hypfs_diag.c line 481
Quoted 4 lines
arch/s390/hypfs/hypfs_diag.c +4
-0+void diag_exit (void ) +{ +diag224_delete_name_table (); +}
And __exit.
arch/s390/hypfs/hypfs_diag.c line 594
Quoted 2 lines
arch/s390/hypfs/hypfs_diag.c +2
-0+int diag_create_files (struct super_block *sb,struct dentry *root) +{
Perhaps as a globally-visible function this should be called hypfs_diag_create_files(). Ditto diag_init() and diag_exit().
Quoted 24 lines
arch/s390/hypfs/hypfs_diag.c +24
-0+struct dentry *systems_dir, *hyp_dir; +void *time_hdr, *part_hdr; +int i; +void *buffer, *rc; + + buffer =diag204_store (); +if (IS_ERR (buffer)) +return PTR_ERR (buffer); + + systems_dir =hypfs_mkdir (sb, root,"systems" ); +if (IS_ERR (systems_dir)) +return PTR_ERR (systems_dir); + time_hdr = (struct x_info_blk_hdr *)buffer; + part_hdr = time_hdr +info_blk_hdr__size (diag204_info_type); +for (i =0 ; i <info_blk_hdr__npar (diag204_info_type, time_hdr); i++) { + part_hdr =hypfs_create_lpar_files (sb, systems_dir, part_hdr); +if (IS_ERR (part_hdr)) +return PTR_ERR (part_hdr); + } +if (info_blk_hdr__flags (diag204_info_type, time_hdr) &LPAR_PHYS_FLG ) { +void *rc; + rc =hypfs_create_phys_files (sb, root, part_hdr); +if (IS_ERR (rc)) +return PTR_ERR (rc);
arch/s390/hypfs/hypfs_diag.c line 628
Quoted 10 lines
arch/s390/hypfs/hypfs_diag.c +10
-0+ } + hyp_dir =hypfs_mkdir (sb, root,"hyp" ); +if (IS_ERR (hyp_dir)) +return PTR_ERR (hyp_dir); + rc =hypfs_create_str (sb, hyp_dir,"type" ,"LPAR Hypervisor" ); +if (IS_ERR (rc)) +return PTR_ERR (rc); +kfree (buffer); +return 0 ; +}
This leaks `buffer' on the error paths, yes?
Quoted 23 lines
arch/s390/hypfs/inode.c +23
-0+/* +* fs/hypfs/inode.c +* Hypervisor filesystem for Linux on s390. +* +* Copyright (C) IBM Corp. 2006 +* Author(s): Michael Holzheu <[email protected]> +*/ + +#include <linux/types.h> +#include <linux/errno.h> +#include <linux/fs.h> +#include <linux/namei.h> +#include <linux/vfs.h> +#include <linux/pagemap.h> +#include <linux/gfp.h> +#include <linux/time.h> +#include <linux/parser.h> +#include <linux/sysfs.h> +#include <linux/module.h> +#include <asm/ebcdic.h> +#include "hypfs.h" +#include "hypfs_diag.h" +
arch/s390/hypfs/inode.c line 33
Quoted 10 lines
arch/s390/hypfs/inode.c +10
-0+#define HYPFS_MAGIC 0x687970/* ASCII 'hyp' */ +#define TMP_SIZE 64/* size of temporary buffers */ + +static struct dentry *hypfs_create_update_file (struct super_block *sb, +struct dentry *dir); + +struct hypfs_sb_info { +int uid;/* uid used for files and dirs */ +int gid;/* gid used for files and dirs */ +};
uid_t?
arch/s390/hypfs/inode.c line 106
Quoted 4 lines
arch/s390/hypfs/inode.c +4
-0+ +static int hypfs_open (struct inode *inode,struct file *filp) +{ +char *data = (char *)filp->f_dentry->d_inode->u.generic_ip;
Unneeded typecast.
arch/s390/hypfs/inode.c line 115
Quoted 8 lines
arch/s390/hypfs/inode.c +8
-0+if (filp->f_mode &FMODE_WRITE ) { +if (!(inode->i_mode &S_IWUGO )) +return -EACCES ; + } +if (filp->f_mode &FMODE_READ ) { +if (!(inode->i_mode &S_IRUGO )) +return -EACCES ; + }
Is the standard VFS permission checking not appropriate?
(A comment should be added here).
arch/s390/hypfs/inode.c line 122
Quoted 7 lines
arch/s390/hypfs/inode.c +7
-0+mutex_lock (&hypfs_lock); + filp->private_data =kmalloc (strlen (data) +1 ,GFP_KERNEL ); +if (!filp->private_data) { +mutex_unlock (&hypfs_lock); +return -ENOMEM ; + } +strcpy (filp->private_data, data);
kstrdup()
arch/s390/hypfs/inode.c line 134
Quoted 12 lines
arch/s390/hypfs/inode.c +12
-0+mutex_unlock (&hypfs_lock); +return 0 ; +} + +static ssize_t hypfs_aio_read (struct kiocb *iocb,__user char *buf, +size_t count,loff_t offset) +{ +char *data; +size_t len; +struct file *filp = iocb->ki_filp; + + data = (char *)filp->private_data;
Unneeded cast.
Quoted 18 lines
arch/s390/hypfs/inode.c +18
-0+ len =strlen (data); +if (offset > len) { + count =0 ; + goto out; + } +if (count > len - offset) + count = len - offset; +if (copy_to_user (buf, data + offset, count)) { + count = -EFAULT ; + goto out; + } + iocb->ki_pos += count; +file_accessed (filp); + out: +return count; +} +static ssize_t hypfs_aio_write (struct kiocb *iocb,const char __user *buf, +size_t count,loff_t pos)
arch/s390/hypfs/inode.c line 162
Quoted 10 lines
arch/s390/hypfs/inode.c +10
-0+{ +int rc; +struct super_block *sb; + +mutex_lock (&hypfs_lock); + sb = iocb->ki_filp->f_dentry->d_inode->i_sb; +if (last_update_time ==get_seconds ()) { + rc = -EBUSY ; + goto out; + }
Why's it looking at the time in this manner?
(Whatever the reason, a comment should be added here).
Quoted 4 lines
arch/s390/hypfs/inode.c +4
-0+static struct dentry *hypfs_create_file (struct super_block *sb, +struct dentry *parent,const char *name, +char *data,mode_t mode) +{
arch/s390/hypfs/inode.c line 304
Quoted 10 lines
arch/s390/hypfs/inode.c +10
-0+struct dentry *dentry; +struct inode *inode; +struct qstr qname; + + qname.name = name; + qname.len =strlen (name); + qname.hash =full_name_hash (name, qname.len); + dentry =lookup_one_len (name, parent,strlen (name)); +if (IS_ERR (dentry)) +return ERR_PTR (-ENOMEM );
return dentry;
Quoted 21 lines
arch/s390/hypfs/inode.c +21
-0+ inode =hypfs_make_inode (sb, mode); +if (!inode) { +dput (dentry); +return ERR_PTR (-ENOMEM ); + } +if (mode &S_IFREG ) { + inode->i_fop = &hypfs_file_ops; +if (data) + inode->i_size =strlen (data); +else + inode->i_size =0 ; + }else if (mode &S_IFDIR ) { + inode->i_op = &simple_dir_inode_operations; + inode->i_fop = &simple_dir_operations; + parent->d_inode->i_nlink++; + }else +BUG (); + inode->u.generic_ip = data; +d_instantiate (dentry, inode); +return dentry; +}
arch/s390/hypfs/inode.c line 348
Quoted 10 lines
arch/s390/hypfs/inode.c +9
-0+static struct dentry *hypfs_create_update_file (struct super_block *sb, +struct dentry *dir) +{ +struct dentry *dentry; + + dentry =hypfs_create_file (sb, dir,"update" ,NULL , +S_IFREG |UPDATE_FILE_MODE ); +if (!dentry) +return ERR_PTR (-ENOMEM );
But hypfs_create_file() will return ERR_PTR(-ENOMEM), never NULL.
Quoted 10 lines
arch/s390/hypfs/inode.c +10
-0+/* +* We do not put the update file on the 'delete' list with +* hypfs_add_dentry(), since it should not be removed when the tree +* is updated. +*/ +return dentry; +} + +struct dentry *hypfs_create_u64 (struct super_block *sb,struct dentry *dir, +const char *name,__u64 value)
arch/s390/hypfs/inode.c line 368
Quoted 10 lines
arch/s390/hypfs/inode.c +10
-0+{ +char *buffer; +char tmp[TMP_SIZE ]; +struct dentry *dentry; + +snprintf (tmp,TMP_SIZE ,"%lld\n" , (unsigned long long int )value); + buffer =kmalloc (strlen (tmp) +1 ,GFP_KERNEL ); +if (!buffer) +return ERR_PTR (-ENOMEM ); +strcpy (buffer, tmp);
kstrdup()
arch/s390/hypfs/inode.c line 371
Quoted 3 lines
arch/s390/hypfs/inode.c +3
-0+ dentry = +hypfs_create_file (sb, dir, name, buffer,S_IFREG |REG_FILE_MODE ); +if (!dentry) {
IS_ERR()
Quoted 10 lines
arch/s390/hypfs/inode.c +10
-0+kfree (buffer); +return ERR_PTR (-ENOMEM ); + } +hypfs_add_dentry (dentry); +return dentry; +} + +struct dentry *hypfs_create_str (struct super_block *sb,struct dentry *dir, +const char *name,char *string) +{
arch/s390/hypfs/inode.c line 391
Quoted 10 lines
arch/s390/hypfs/inode.c +10
-0+char *buffer; +struct dentry *dentry; + + buffer =kmalloc (strlen (string) +2 ,GFP_KERNEL ); +if (!buffer) +return ERR_PTR (-ENOMEM ); +sprintf (buffer,"%s\n" , string); + dentry = +hypfs_create_file (sb, dir, name, buffer,S_IFREG |REG_FILE_MODE ); +if (!dentry) {
IS_ERR()
(Better check the whole patch for this)
Quoted 6 lines
arch/s390/hypfs/inode.c +6
-0+kfree (buffer); +return ERR_PTR (-ENOMEM ); + } +hypfs_add_dentry (dentry); +return dentry; +}
Hi Andrew!
Thanks for the review!
Andrew Morton <[email protected]> wrote on 04/28/2006 11:56:21 AM:
Quoted 1 line
Michael Holzheu <[email protected]> wrote:
[snip]
Quoted 10 lines
arch/s390/Kconfig config NO_IDLE_HZ_INIT · line 451
Quoted 8 lines
arch/s390/Kconfig +7
-0+config HYPFS_FS + bool "s390 hypervisor file system support" + default y + help + This is a virtual file system intended to provide accounting + information in a s390 hypervisor environment. +"in an s390"?
Yes!
Quoted 4 lines
Quoted 1 line
+static inline int diag204(unsigned long subcode, unsigned long
size, void *addr)
There's a lot of inlining going on. Is it excessive?
I will remove the diag inlines. The code is not performance critical anyway, since diag 204 itself is soo slow. But I would like to keep the inlines for the getter functions.
Quoted 11 lines
arch/s390/hypfs/hypfs_diag.c line 368
Quoted 9 lines
...
arch/s390/hypfs/hypfs_diag.c +7
-0+static int diag204_probe (void ) +{ +void *buf; +int pages, rc; + + pages =diag204 (SUBC_RSI |INFO_EXT ,0 ,0 ); +if (pages >0 ) {In other places, you return an error if (pages < 0), but not here.
I make an additional comment to document the code
here!
... and you are right! In diag204_store() we should check not for pages < 0, but for pages <= 0! The other spots are ok.
[snip]
Quoted 9 lines
arch/s390/hypfs/hypfs_diag.c line 404
Quoted 7 lines
arch/s390/hypfs/hypfs_diag.c +7
-0+ } + out: + rc =0 ; + err_out: +kfree (buf); +return rc; +}The indenting of the labels is a bit unconventional.
Sorry, that was lindent...
Quoted 10 lines
Quoted 10 lines
arch/s390/hypfs/hypfs_diag.c +10
-0+static void *diag204_store (void ) +{ +void *buf; +int pages; + +if (diag204_store_sc ==SUBC_STIB4 ) + pages =1 ; +else + pages =diag204 (SUBC_RSI | diag204_info_type,0 ,0 ); +
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c +8
-0+if (pages <0 ) +return ERR_PTR (-ENOSYS ); + + buf =kmalloc (pages *PAGE_SIZE ,GFP_KERNEL ); +if (!buf) +return ERR_PTR (-ENOMEM ); + +if (diag204 (diag204_store_sc | diag204_info_type, pages, buf) <0 )
{
Quoted 6 lines
arch/s390/hypfs/hypfs_diag.c line 428
Quoted 5 lines
arch/s390/hypfs/hypfs_diag.c +5
-0+kfree (buf); +return ERR_PTR (-ENOSYS ); + } +return buf; +}
Quoted 6 lines
One wonders if
pages = diag204(...); return kmalloc(pages * PAGE_SIZE, gfp_flags);would be a useful helper function.
Good idea! I implemented a diag204_get_buffer() function, but I am not sure, if it is better now. At least it is not worse!
Quoted 18 lines
Quoted 18 lines
arch/s390/hypfs/hypfs_diag.c +18
-0+ asmvolatile (" diag %0,%1,0x224\n" + : :"d" (0 ),"d" (ptr) :"memory" ); +} + +static inline int diag224_get_name_table (void ) +{ +/* memory must be below 2GB */ + diag224_cpu_names =kmalloc (PAGE_SIZE ,GFP_KERNEL |GFP_DMA ); +if (!diag224_cpu_names) +return -ENOMEM ; +diag224 (diag224_cpu_names); +EBCASC (diag224_cpu_names +16 , (*diag224_cpu_names +1 ) *16 ); +return 0 ; +} + +static inline void diag224_delete_name_table (void ) +{ +kfree (diag224_cpu_names);
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c line 457
Quoted 6 lines
arch/s390/hypfs/hypfs_diag.c +6
-0+} + +static int diag224_idx2name (int index,char *name) +{ +memcpy (name, diag224_cpu_names + ((index +1 ) *16 ),16 ); + name[16 ] =0 ;Should this be "15"? I guess not...
No bug, our strings here have 16 characters and are not 0 terminated.
Quoted 13 lines
Quoted 13 lines
arch/s390/hypfs/hypfs_diag.c +13
-0+strstrip (name); +return 0 ; +} + +int diag_init (void ) +{ +int rc; + +if (diag204_probe ()) { +printk (KERN_ERR "hypfs: diag 204 not working." ); +return -ENODATA ; + } + rc =diag224_get_name_table ();
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c line 476
Quoted 6 lines
arch/s390/hypfs/hypfs_diag.c +6
-0+if (rc) { +diag224_delete_name_table (); +printk (KERN_ERR "hypfs: could not get name table.\n" ); + } +return rc; +}This can be
__init
Yes!
Quoted 6 lines
arch/s390/hypfs/hypfs_diag.c line 481
Quoted 4 lines
arch/s390/hypfs/hypfs_diag.c +4
-0+void diag_exit (void ) +{ +diag224_delete_name_table (); +}And
__exit.
Yes!
Quoted 5 lines
arch/s390/hypfs/hypfs_diag.c line 594
Quoted 2 lines
arch/s390/hypfs/hypfs_diag.c +2
-0+int diag_create_files (struct super_block *sb,struct dentry *root) +{Perhaps as a globally-visible function this should be called
hypfs_diag_create_files(). Dittodiag_init()anddiag_exit().
Ok, I renamed the functions.
Quoted 7 lines
Quoted 7 lines
arch/s390/hypfs/hypfs_diag.c +7
-0+struct dentry *systems_dir, *hyp_dir; +void *time_hdr, *part_hdr; +int i; +void *buffer, *rc; + + buffer =diag204_store (); +if (IS_ERR (buffer))
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c +8
-0+return PTR_ERR (buffer); + + systems_dir =hypfs_mkdir (sb, root,"systems" ); +if (IS_ERR (systems_dir)) +return PTR_ERR (systems_dir); + time_hdr = (struct x_info_blk_hdr *)buffer; + part_hdr = time_hdr +info_blk_hdr__size (diag204_info_type); + for (i = 0; i < info_blk_hdr__npar(diag204_info_type, time_hdr);
i++) {
Quoted 5 lines
arch/s390/hypfs/hypfs_diag.c
Quoted 5 lines
arch/s390/hypfs/hypfs_diag.c +5
-0+ part_hdr =hypfs_create_lpar_files (sb, systems_dir, part_hdr); +if (IS_ERR (part_hdr)) +return PTR_ERR (part_hdr); + } + if (info_blk_hdr__flags(diag204_info_type, time_hdr) &
LPAR_PHYS_FLG) {
Quoted 15 lines
Quoted 4 lines
arch/s390/hypfs/hypfs_diag.c +4
-0+void *rc; + rc =hypfs_create_phys_files (sb, root, part_hdr); +if (IS_ERR (rc)) +return PTR_ERR (rc);arch/s390/hypfs/hypfs_diag.c line 628
Quoted 10 lines
arch/s390/hypfs/hypfs_diag.c +10
-0+ } + hyp_dir =hypfs_mkdir (sb, root,"hyp" ); +if (IS_ERR (hyp_dir)) +return PTR_ERR (hyp_dir); + rc =hypfs_create_str (sb, hyp_dir,"type" ,"LPAR Hypervisor" ); +if (IS_ERR (rc)) +return PTR_ERR (rc); +kfree (buffer); +return 0 ; +}
Quoted 1 line
This leaks `buffer' on the error paths, yes?
Right! I fixed this!
Quoted 27 lines
Quoted 27 lines
arch/s390/hypfs/inode.c +27
-0+/* +* fs/hypfs/inode.c +* Hypervisor filesystem for Linux on s390. +* +* Copyright (C) IBM Corp. 2006 +* Author(s): Michael Holzheu <[email protected]> +*/ + +#include <linux/types.h> +#include <linux/errno.h> +#include <linux/fs.h> +#include <linux/namei.h> +#include <linux/vfs.h> +#include <linux/pagemap.h> +#include <linux/gfp.h> +#include <linux/time.h> +#include <linux/parser.h> +#include <linux/sysfs.h> +#include <linux/module.h> +#include <asm/ebcdic.h> +#include "hypfs.h" +#include "hypfs_diag.h" + +#define HYPFS_MAGIC 0x687970/* ASCII 'hyp' */ +#define TMP_SIZE 64/* size of temporary buffers */ + +static struct dentry *hypfs_create_update_file(struct super_block *sb,
Quoted 8 lines
arch/s390/hypfs/inode.c line 33
Quoted 6 lines
arch/s390/hypfs/inode.c +6
-0+ struct dentry *dir); + +struct hypfs_sb_info { +int uid;/* uid used for files and dirs */ +int gid;/* gid used for files and dirs */ +};
uid_t?
Good idea!
Quoted 6 lines
arch/s390/hypfs/inode.c line 106
Quoted 4 lines
arch/s390/hypfs/inode.c +4
-0+ +static int hypfs_open (struct inode *inode,struct file *filp) +{ +char *data = (char *)filp->f_dentry->d_inode->u.generic_ip;Unneeded typecast.
Yes
Quoted 9 lines
arch/s390/hypfs/inode.c line 115
Quoted 8 lines
arch/s390/hypfs/inode.c +8
-0+if (filp->f_mode &FMODE_WRITE ) { +if (!(inode->i_mode &S_IWUGO )) +return -EACCES ; + } +if (filp->f_mode &FMODE_READ ) { +if (!(inode->i_mode &S_IRUGO )) +return -EACCES ; + }
Quoted 3 lines
Is the standard VFS permission checking not appropriate?
(A comment should be added here).
You mean using .permission in the inode operations and using the generic_permission() function?
Currently I do not have own inode operations (and
I don't want to have them ...)
Quoted 9 lines
arch/s390/hypfs/inode.c line 122
Quoted 7 lines
arch/s390/hypfs/inode.c +7
-0+mutex_lock (&hypfs_lock); + filp->private_data =kmalloc (strlen (data) +1 ,GFP_KERNEL ); +if (!filp->private_data) { +mutex_unlock (&hypfs_lock); +return -ENOMEM ; + } +strcpy (filp->private_data, data);
kstrdup()
Yes!
Quoted 6 lines
Quoted 6 lines
arch/s390/hypfs/inode.c +6
-0+mutex_unlock (&hypfs_lock); +return 0 ; +} + +static ssize_t hypfs_aio_read (struct kiocb *iocb,__user char *buf, +size_t count,loff_t offset)
Quoted 8 lines
arch/s390/hypfs/inode.c line 134
Quoted 6 lines
arch/s390/hypfs/inode.c +6
-0+{ +char *data; +size_t len; +struct file *filp = iocb->ki_filp; + + data = (char *)filp->private_data;Unneeded cast.
Yes!
Quoted 9 lines
Quoted 9 lines
arch/s390/hypfs/inode.c +9
-0+ len =strlen (data); +if (offset > len) { + count =0 ; + goto out; + } +if (count > len - offset) + count = len - offset; +if (copy_to_user (buf, data + offset, count)) { + count = -EFAULT ;
Quoted 8 lines
arch/s390/hypfs/inode.c
Quoted 8 lines
arch/s390/hypfs/inode.c +8
-0+ goto out; + } + iocb->ki_pos += count; +file_accessed (filp); + out: +return count; +} +static ssize_t hypfs_aio_write(struct kiocb *iocb, const char __user
*buf,
Quoted 14 lines
arch/s390/hypfs/inode.c line 162
Quoted 11 lines
arch/s390/hypfs/inode.c +11
-0+ size_t count, loff_t pos) +{ + int rc; +struct super_block *sb; + +mutex_lock (&hypfs_lock); + sb = iocb->ki_filp->f_dentry->d_inode->i_sb; +if (last_update_time ==get_seconds ()) { + rc = -EBUSY ; + goto out; + }Why's it looking at the time in this manner?
Quoted 1 line
(Whatever the reason, a comment should be added here).
I added the following comment:
/*
* Currently we only allow one update per second for two reasons:
* 1. diag 204 is VERY expensive
* 2. If several processes do updates in parallel and then read the
* hypfs data, the likelihood of collisions is reduced, if we restrict * the minimum update interval. A collision occurs, if during the * data gathering of one process another process triggers an update * If the first process wants to ensure consistent data, it has * to restart data collection in this case.
*/
[snip]
Quoted 11 lines
arch/s390/hypfs/inode.c line 348
Quoted 9 lines
arch/s390/hypfs/inode.c +9
-0+static struct dentry *hypfs_create_update_file (struct super_block *sb, +struct dentry *dir) +{ +struct dentry *dentry; + + dentry =hypfs_create_file (sb, dir,"update" ,NULL , +S_IFREG |UPDATE_FILE_MODE ); +if (!dentry) +return ERR_PTR (-ENOMEM );But
hypfs_create_file()will returnERR_PTR(-ENOMEM), never NULL.
Fixed this!
Quoted 9 lines
arch/s390/hypfs/inode.c
Quoted 9 lines
arch/s390/hypfs/inode.c +9
-0+/* +* We do not put the update file on the 'delete' list with +* hypfs_add_dentry(), since it should not be removed when the tree +* is updated. +*/ +return dentry; +} + +struct dentry *hypfs_create_u64(struct super_block *sb, struct dentry
*dir,
Quoted 5 lines
Quoted 5 lines
arch/s390/hypfs/inode.c +5
-0+ const char *name, __u64 value) +{ + char *buffer; +char tmp[TMP_SIZE ]; +struct dentry *dentry;
Quoted 8 lines
arch/s390/hypfs/inode.c line 368
Quoted 6 lines
arch/s390/hypfs/inode.c +6
-0+ +snprintf (tmp,TMP_SIZE ,"%lld\n" , (unsigned long long int )value); + buffer =kmalloc (strlen (tmp) +1 ,GFP_KERNEL ); +if (!buffer) +return ERR_PTR (-ENOMEM ); +strcpy (buffer, tmp);
kstrdup()
Yes!
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ dentry = + hypfs_create_file(sb, dir, name, buffer, S_IFREG |
REG_FILE_MODE);
Quoted 3 lines
Quoted 1 line
+ if (!dentry) {
IS_ERR()
Yes!
Quoted 8 lines
arch/s390/hypfs/inode.c
Quoted 8 lines
arch/s390/hypfs/inode.c +8
-0+kfree (buffer); +return ERR_PTR (-ENOMEM ); + } +hypfs_add_dentry (dentry); +return dentry; +} + +struct dentry *hypfs_create_str(struct super_block *sb, struct dentry
*dir,
Quoted 11 lines
arch/s390/hypfs/inode.c
Quoted 11 lines
arch/s390/hypfs/inode.c +11
-0+ const char *name, char *string) +{ + char *buffer; +struct dentry *dentry; + + buffer =kmalloc (strlen (string) +2 ,GFP_KERNEL ); +if (!buffer) +return ERR_PTR (-ENOMEM ); +sprintf (buffer,"%s\n" , string); + dentry = + hypfs_create_file(sb, dir, name, buffer, S_IFREG |
REG_FILE_MODE);
Quoted 4 lines
Quoted 1 line
+ if (!dentry) {
IS_ERR()
(Better check the whole patch for this)
Yes!
Thanks again for the review!
Michael
Quoted 10 lines · Michael Holzheu
Andrew Morton <[email protected]> wrote on 04/28/2006 11:56:21 AM:
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c line 457
Quoted 4 lines · Michael Holzheu
arch/s390/hypfs/hypfs_diag.c +4
-0+static int diag224_idx2name (int index,char *name) +{ +memcpy (name, diag224_cpu_names + ((index +1 ) *16 ),16 ); + name[16 ] =0 ;Should this be "15"? I guess not...
Quoted 2 lines
No bug, our strings here have 16 characters and are not 0 terminated.
Hmm. TMP_SIZE is defined to 64 and used for buffers allocated on the stack. It is not too excessive, but in this case 17 would definitely be enough. Not sure if it's worth going through.
Jörn
Signature · 4 lines
My second remark is that our intellectual powers are rather geared to master static relations and that our powers to visualize processes evolving in time are relatively poorly developed. -- Edsger W. Dijkstra
Hi Joern,
Jörn Engel <[email protected]> wrote on 04/28/2006 07:43:02 PM:
Quoted 11 lines · Michael Holzheu
Quoted 10 lines
Andrew Morton <[email protected]> wrote on 04/28/2006 11:56:21 AM:
Quoted 8 lines
arch/s390/hypfs/hypfs_diag.c line 457
Quoted 4 lines · Michael Holzheu
arch/s390/hypfs/hypfs_diag.c +4
-0+static int diag224_idx2name (int index,char *name) +{ +memcpy (name, diag224_cpu_names + ((index +1 ) *16 ),16 ); + name[16 ] =0 ;Should this be "15"? I guess not...
Quoted 8 lines
Quoted 2 lines
No bug, our strings here have 16 characters and are not 0 terminated.
Hmm.
TMP_SIZEis defined to 64 and used for buffers allocated on the stack. It is not too excessive, but in this case 17 would definitely be enough. Not sure if it's worth going through.Jörn
Since I use the buffers with size TMP_SIZE also for other purposes in the same functions, where the cpu types are accessed, I think, it is not useful to define a second buffer with size 17.
But I think it is better to have a define for the buffer size of cpu names. something like:
#define LPAR_NAME_LEN 8 /* lpar name len in diag 204 data
*/
+#define CPU_NAME_LEN 16 /* type name len of a cpu in
diag224 name table */
#define TMP_SIZE 64 /* size of temporary buffers */
static int diag224_idx2name(int index, char *name) {
- memcpy(name, diag224_cpu_names + ((index + 1) * 16), 16);
- name[16] = 0;
+ memcpy(name, diag224_cpu_names + ((index + 1) * CPU_NAME_LEN),
+ CPU_NAME_LEN);
+ name[CPU_NAME_LEN] = 0;
strstrip(name);
return 0;}
Michael
Quoted 12 lines · Michael Holzheu
Quoted 12 lines
arch/s390/hypfs/inode.c line 115
Quoted 9 lines
arch/s390/hypfs/inode.c +8
-0+if (filp->f_mode &FMODE_WRITE ) { +if (!(inode->i_mode &S_IWUGO )) +return -EACCES ; + } +if (filp->f_mode &FMODE_READ ) { +if (!(inode->i_mode &S_IRUGO )) +return -EACCES ; + }Is the standard VFS permission checking not appropriate?
Quoted 7 lines
Quoted 1 line
(A comment should be added here).
You mean using .permission in the inode operations and using the
generic_permission()function?Currently I do not have own inode operations (and I don't want to have them ...)
The VFS-level open() code implements standard permission-checking so I _think_ you don't need to do anything in here. See how ramfs does it.
ramfs does have an inode_operations, for ->getattr() support. So it can return a correct number in stat->blocks.
sysfs implements inode_operations, so it can do stuff in ->setattr().
I don't think hypfs needs either of those, so you still shouldn't need a file_inode_operations.
Hi Michael,
Quoted 3 lines · Michael Holzheu
diff -urpN
linux-2.6.16/arch/s390/hypfs/inode.clinux-2.6.16-hypfs/arch/s390/hypfs/inode.carch/s390/hypfs/inode.c +0
-0
[snip]
arch/s390/hypfs/inode.c line 40
Quoted 6 lines
arch/s390/hypfs/inode.c +6
-0+static struct dentry *update_file_dentry; +static struct file_operations hypfs_file_ops; +static struct file_system_type hypfs_type; +static struct super_operations hypfs_s_ops; +static time_t last_update_time =0 ;/* update time in seconds since 1970 */ +static DEFINE_MUTEX (hypfs_lock);
These should be per-superblock and not global, right?
Pekka
Pekka J Enberg <[email protected]> wrote on 04/28/2006 12:36:59 PM:
Quoted 10 lines
arch/s390/hypfs/inode.c
Quoted 6 lines
arch/s390/hypfs/inode.c +5
-0+static struct dentry *update_file_dentry; +static struct file_operations hypfs_file_ops; +static struct file_system_type hypfs_type; +static struct super_operations hypfs_s_ops; +static time_t last_update_time =0 ;/* update time in seconds since 1970 */
Quoted 1 line
+static
DEFINE_MUTEX(hypfs_lock);These should be per-superblock and not global, right?
Yes! update_file_dentry, last_update_time and hypfs_lock should be per-superblock. I will change this!
hypfs_file_ops, hpyfs_type and hypfs_s_ops should remain global, since this will be the same for all super blocks.
Michael
Quoted 2 lines · Michael Holzheu
As mount point for the filesystem
/sys/hypervisoris created.
What does this mean, btw? I don't see code there creating a new sysfs directory, and userspace cannot do this.
Confused.
Also, "/sys/hypervisor" is probably insufficiently specific. In a few years time people will be asking "Which hypervisor? We have eighteen of them!".
Quoted 6 lines · Andrew Morton
Quoted 2 lines · Michael Holzheu
As mount point for the filesystem
/sys/hypervisoris created.What does this mean, btw? I don't see code there creating a new sysfs directory, and userspace cannot do this.
The call to subsystem_register() does this.
Quoted 2 lines
Also, "
/sys/hypervisor" is probably insufficiently specific. In a few years time people will be asking "Which hypervisor? We have eighteen of them!".
I agree, the xen people are already clammering for some kind of sysfs tree and wanted to create /sys/hypervisor/xen. How about /sys/hypervisor/s390?
thanks,
greg k-h
Quoted 10 lines · Greg KH
Quoted 6 lines · Andrew Morton
Quoted 2 lines · Michael Holzheu
As mount point for the filesystem
/sys/hypervisoris created.What does this mean, btw? I don't see code there creating a new sysfs directory, and userspace cannot do this.
The call to
subsystem_register()does this.
Ah. It's using "hypfs". Michael was tricking us.
Quoted 6 lines
Quoted 2 lines
Also, "
/sys/hypervisor" is probably insufficiently specific. In a few years time people will be asking "Which hypervisor? We have eighteen of them!".I agree, the xen people are already clammering for some kind of sysfs tree and wanted to create
/sys/hypervisor/xen. How about/sys/hypervisor/s390?
Yes, something like that. Even "hypfs" is possibly too generic.
Hi Andrew,
Andrew Morton <[email protected]> wrote on 04/29/2006 10:14:23 AM:
[snip]
Quoted 1 line
Quoted 1 line
Quoted 1 line
Also, "
/sys/hypervisor" is probably insufficiently specific. In a
few
Quoted 6 lines
Quoted 1 line
Quoted 1 line
years time people will be asking "Which hypervisor? We have
eighteen of them!".
Quoted 4 lines
I agree, the xen people are already clammering for some kind of sysfs tree and wanted to create
/sys/hypervisor/xen. How about/sys/hypervisor/s390?
Fine with me! Then I will create /sys/hypervisor/s390. Should I create /sys/hypervisor in the hpyfs code or should it be created somewhere else?
Quoted 1 line
Yes, something like that. Even "hypfs" is possibly too generic.
What about s390-hypfs?
Michael
Quoted 11 lines · Michael Holzheu
Hi Andrew,
Andrew Morton <[email protected]> wrote on 04/29/2006 10:14:23 AM:
[snip]
Quoted 1 line
Quoted 1 line
Quoted 1 line
Also, "
/sys/hypervisor" is probably insufficiently specific. In afew
Quoted 3 lines
Quoted 1 line
Quoted 1 line
years time people will be asking "Which hypervisor? We have
eighteen of them!".
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
I agree, the xen people are already clammering for some kind of sysfs tree and wanted to create
/sys/hypervisor/xen. How about/sys/hypervisor/s390?Fine with me! Then I will create
/sys/hypervisor/s390. Should I create/sys/hypervisorin the hpyfs code or should it be created somewhere else?
Somewhere else is probably best.
drivers/base/hypervisor.c ?
thanks,
greg k-h
Greg KH <[email protected]> wrote on 05/04/2006 12:10:37 AM:
Quoted 8 lines
Quoted 3 lines
Fine with me! Then I will create
/sys/hypervisor/s390. Should I create/sys/hypervisorin the hpyfs code or should it be created somewhere else?Somewhere else is probably best.
drivers/base/hypervisor.c?
We could do that, but then we have to create two new files hypervisor.c and hypervisor.h just for one new mountpoint in sysfs.
I would suggest do do it like /sys/kernel and put the code into kernel/ksysfs.c and include/linux/kobject.h
Michael
Quoted 11 lines · Michael Holzheu
Greg KH <[email protected]> wrote on 05/04/2006 12:10:37 AM:
Quoted 8 lines
Quoted 3 lines
Fine with me! Then I will create
/sys/hypervisor/s390. Should I create/sys/hypervisorin the hpyfs code or should it be created somewhere else?Somewhere else is probably best.
drivers/base/hypervisor.c?
Quoted 6 lines
We could do that, but then we have to create two new files
hypervisor.candhypervisor.hjust for one new mountpoint in sysfs.I would suggest do do it like
/sys/kerneland put the code intokernel/ksysfs.candinclude/linux/kobject.h
No, if you do that then every kernel gets that mount point, when almost no one really wants it :)
If you leave it as a separate file, then the build system can just include the file as needed.
thanks,
greg k-h
Hi Greg,
Greg KH <[email protected]> wrote on 05/04/2006 04:42:59 PM:
Quoted 9 lines
Quoted 2 lines
I would suggest do do it like
/sys/kerneland put the code intokernel/ksysfs.candinclude/linux/kobject.hNo, if you do that then every kernel gets that mount point, when almost no one really wants it :)
If you leave it as a separate file, then the build system can just include the file as needed.
So you want a new config option CONFIG_HYPERVISOR?
When no one except for us wants it, wouldn't it be best then to create /sys/hypervisor first in the hypfs code?
If someone else needs it in the future, we still can move it common code.
Michael
Quoted 6 lines · Michael Holzheu
Hi Greg,
Greg KH <[email protected]> wrote on 05/04/2006 04:42:59 PM:
Quoted 3 lines
Quoted 2 lines
I would suggest do do it like
/sys/kerneland put the code intokernel/ksysfs.candinclude/linux/kobject.h
Quoted 8 lines
Quoted 6 lines
No, if you do that then every kernel gets that mount point, when almost no one really wants it :)
If you leave it as a separate file, then the build system can just include the file as needed.
So you want a new config option
CONFIG_HYPERVISOR?
Sure. But don't make it a user selectable config option, but rather, one your S390 option sets.
That way the Xen and other groups can also set it when they need it.
Quoted 5 lines
When no one except for us wants it, wouldn't it be best then to create
/sys/hypervisorfirst in the hypfs code?If someone else needs it in the future, we still can move it common code.
The Xen people need it too. Now who knows when their code will ever hit mainline...
thanks,
greg k-h
Quoted 67 lines · Michael Holzheu
On zSeries machines there exists an interface which allows the operating system to retrieve LPAR hypervisor accounting data. For example, it is possible to get usage data for physical and virtual cpus. In order to provide this information to user space programs, I implemented a new virtual Linux file system named 'hypfs' using the Linux 2.6 libfs framework. The name 'hypfs' stands for 'Hypervisor Filesystem'. All the accounting information is put into different virtual files which can be accessed from user space. All data is represented as ASCII strings.
When the file system is mounted the accounting information is retrieved and a file system tree is created with the attribute files containing the cpu information. The content of the files remains unchanged until a new update is made. An update can be triggered from user space through writing 'something' into a special purpose update file.
We create the following directory structure:
<mount-point>/
update cpus/ <cpu-id> type mgmtime <cpu-id> ... hyp/ type systems/ <lpar-name> cpus/ <cpu-id> type mgmtime cputime onlinetime <cpu-id> ... <lpar-name> cpus/ ...- update: File to trigger update
- cpus/: Directory for all physical cpus
- cpus/<cpu-id>/: Directory for one physical cpu.
- cpus/<cpu-id>/type: Type name of physical zSeries cpu.
- cpus/<cpu-id>/mgmtime: Physical-LPAR-management time in microseconds.
- hyp/: Directory for hypervisor information
- hyp/type: Typ of hypervisor (currently only 'LPAR Hypervisor')
- systems/: Directory for all LPARs
- systems/<lpar-name>/: Directory for one LPAR.
- systems/<lpar-name>/cpus/<cpu-id>/: Directory for the virtual cpus
- systems/<lpar-name>/cpus/<cpu-id>/type: Typ of cpu.
- systems/<lpar-name>/cpus/<cpu-id>/mgmtime:
Accumulated number of microseconds during which a physical CPU was assigned to the logical cpu and the cpu time was consumed by the hypervisor and was not provided to
the LPAR (LPAR overhead).- systems/<lpar-name>/cpus/<cpu-id>/cputime:
Accumulated number of microseconds during which a physical CPU was assigned to the logical cpu and the cpu time was consumed by the LPAR.- systems/<lpar-name>/cpus/<cpu-id>/onlinetime:
Accumulated number of microseconds during which the logical CPU has been online.
Quoted 6 lines
As mount point for the filesystem
/sys/hypervisoris created.The update process is triggered when writing 'something' into the 'update' file at the top level hypfs directory. You can do this e.g. with 'echo 1 > update'. During the update the whole directory structure is deleted and built up again.
This sounds a lot like configfs. Why not use that instead?
Is there a reason that sysfs can't be used for a lot of these things too?
We already have the different cpus in sysfs, why put things in a different location than that?
thanks,
greg k-h
Quoted 7 lines · Greg KH
Quoted 1 line
The update process is triggered when writing 'something' into the 'update' file at the top level hypfs directory. You can do this e.g. with 'echo 1 > update'. During the update the whole directory structure is deleted and built up again.
This sounds a lot like configfs. Why not use that instead?
Is there a reason that sysfs can't be used for a lot of these things too?
We already have the different cpus in sysfs, why put things in a different location than that?
It sounds like a lot of things need some kind of shell-scriptable transaction interface for sysfs files. You don't want to have more than one value per file, but reading or writing of some values must be done together for consistency reasons. Is there any way to implement something like this? This would work for the framebuffer people and solve the needs of a lot of the people who still want ioctls or some other atomic-multivalued transfer that would otherwise be a great sysfs candidate.
Quoted 12 lines
# Start a transaction
exec 3</sys/hypervisor/s390/transaction# Add another reference to the transaction
exec 4<&3# List CPUs and info
cd/sys/hypervisor/s390/cpus
for i in *; do
echo "CPU $i: type=cat typemgmtime=cat mgmtime"
done
Quoted 8 lines
# Transaction does *not* end here
exec 3<&-# List CPUs again a different way
ls/sys/hypervisor/s390/cpus# Transaction does end here
exec 4<&-
A process that doesn't care about the transaction (Like a user inspecting from a shell), could just cd in and cat random files, and it would run a transaction for each file opened, and end the transaction when the file is closed. Obviously that's inefficient, but it's obviously correct and works. Otherwise, from opening the transaction filehandle for the first time till closing the last open FD to it, the process would get a consistent view of the data, read when the "transaction" file is first opened opened. Perhaps any modifications would be synced and written at the close of that filehandle.
I don't know if that's something doable given the FD model, but if it is, then that's trivial to use for the admin, in shell scripts, perl scripts, C programs, etc. It also works with the one-value-per-file sysfs model.
Cheers,
Kyle Moffett
Quoted 14 lines · Kyle Moffett
Quoted 5 lines · Greg KH
Quoted 4 lines
The update process is triggered when writing 'something' into the 'update' file at the top level hypfs directory. You can do this e.g. with 'echo 1 > update'. During the update the whole directory structure is deleted and built up again.
Quoted 7 lines
This sounds a lot like configfs. Why not use that instead?
Is there a reason that sysfs can't be used for a lot of these things too?
We already have the different cpus in sysfs, why put things in a different location than that?
Quoted 8 lines
It sounds like a lot of things need some kind of shell-scriptable transaction interface for sysfs files. You don't want to have more than one value per file, but reading or writing of some values must be done together for consistency reasons. Is there any way to implement something like this? This would work for the framebuffer people and solve the needs of a lot of the people who still want ioctls or some other atomic-multivalued transfer that would otherwise be a great sysfs candidate.
relayfs is for that. You can now put relayfs files in any ram based file system (procfs, ramfs, sysfs, debugfs, etc.)
thanks,
greg k-h
Quoted 1 line · Greg KH
relayfs is for that. You can now put relayfs files in any ram based file system (procfs, ramfs, sysfs, debugfs, etc.)
But you can't twiddle relayfs with echo and cat; it's more suited to high-bandwidth transfers than anything else, no? The idea here would be to be able to interact with the files in /sys the same way you always do, but provide a sort of consistency system whereby a program _or_ sysadmin can attach its view of the /sys/hypervisor directory tree to a particular snapshot of the system. As far as I can tell (although I'd be happy to be proven wrong), there is no trivial way to manually access or shellscript relayfs files, the way you can "cat /sys/devices/<path-to-device>/dev".
Cheers,
Kyle Moffett
Quoted 6 lines · Kyle Moffett
Quoted 2 lines · Greg KH
relayfs is for that. You can now put relayfs files in any ram based file system (procfs, ramfs, sysfs, debugfs, etc.)
But you can't twiddle relayfs with echo and cat; it's more suited to high-bandwidth transfers than anything else, no?
Yes.
Quoted 7 lines · Greg KH
Quoted 4 lines · Kyle Moffett
Quoted 1 line · Greg KH
relayfs is for that. You can now put relayfs files in any ram based file system (procfs, ramfs, sysfs, debugfs, etc.)
But you can't twiddle relayfs with echo and cat; it's more suited to high-bandwidth transfers than anything else, no?
Yes.
So my question stands: What is the _recommended_ way to handle simple data types in low-bandwidth/frequency multiple-valued transactions to hardware? Examples include reading/modifying framebuffer settings (currently done through IOCTLS), s390 current state (up for discussion), etc. In these cases there needs to be an atomic snapshot or write of multiple values at the same time. Given the situation it would be _nice_ to use sysfs so the admin can do it by hand; makes things shell scriptable and reduces the number of binary compatibility issues.
Cheers,
Kyle Moffett
Quoted 11 lines · Kyle Moffett
Quoted 9 lines · Greg KH
Quoted 6 lines · Kyle Moffett
Quoted 2 lines · Greg KH
relayfs is for that. You can now put relayfs files in any ram based file system (procfs, ramfs, sysfs, debugfs, etc.)
But you can't twiddle relayfs with echo and cat; it's more suited to high-bandwidth transfers than anything else, no?
Yes.
Quoted 9 lines
So my question stands: What is the _recommended_ way to handle simple data types in low-bandwidth/frequency multiple-valued transactions to hardware? Examples include reading/modifying framebuffer settings (currently done through IOCTLS), s390 current state (up for discussion), etc. In these cases there needs to be an atomic snapshot or write of multiple values at the same time. Given the situation it would be _nice_ to use sysfs so the admin can do it by hand; makes things shell scriptable and reduces the number of binary compatibility issues.
I really don't know of a way to use sysfs for this currently, and hence, am not complaining too much about the different /proc files that have this kind of information in it at the moment.
If you or someone else wants to come up with some kind of solution for it, I'm sure that many people would be very happy to see it.
thanks,
greg k-h
Quoted 22 lines · Greg KH
Quoted 11 lines · Kyle Moffett
Quoted 9 lines · Greg KH
Quoted 6 lines · Kyle Moffett
Quoted 2 lines · Greg KH
relayfs is for that. You can now put relayfs files in any ram based file system (procfs, ramfs, sysfs, debugfs, etc.)
But you can't twiddle relayfs with echo and cat; it's more suited to high-bandwidth transfers than anything else, no?
Yes.
Quoted 9 lines
So my question stands: What is the _recommended_ way to handle simple data types in low-bandwidth/frequency multiple-valued transactions to hardware? Examples include reading/modifying framebuffer settings (currently done through IOCTLS), s390 current state (up for discussion), etc. In these cases there needs to be an atomic snapshot or write of multiple values at the same time. Given the situation it would be _nice_ to use sysfs so the admin can do it by hand; makes things shell scriptable and reduces the number of binary compatibility issues.
Quoted 6 lines
I really don't know of a way to use sysfs for this currently, and hence, am not complaining too much about the different /proc files that have this kind of information in it at the moment.
If you or someone else wants to come up with some kind of solution for it, I'm sure that many people would be very happy to see it.
If the count of values handled in a transaction is not to high and it makes sense to group these values logically, why not just create an attribute group for every transaction, which creates dummy attributes to fill the values in, and use an "action" file in that group, that commits all the values at once to whatever target? That should fit into the ioctl use pattern, right?
Kay
Quoted 6 lines · Kay Sievers
If the count of values handled in a transaction is not to high and it makes sense to group these values logically, why not just create an attribute group for every transaction, which creates dummy attributes to fill the values in, and use an "action" file in that group, that commits all the values at once to whatever target? That should fit into the ioctl use pattern, right?
That's what configfs can handle easier. I think the issue is getting stuff from the kernel in one atomic snapshot (all the different file values from the same point in time.)
thanks,
greg k-h
Quoted 11 lines · Greg KH
Quoted 6 lines · Kay Sievers
If the count of values handled in a transaction is not to high and it makes sense to group these values logically, why not just create an attribute group for every transaction, which creates dummy attributes to fill the values in, and use an "action" file in that group, that commits all the values at once to whatever target? That should fit into the ioctl use pattern, right?
That's what configfs can handle easier. I think the issue is getting stuff from the kernel in one atomic snapshot (all the different file values from the same point in time.)
Sure, but just like an ioctl, the kernel could return the values after writing to the "action" file in the dummy attributes. That would be something like a snapshot, right?
Kay
Quoted 9 lines · Kay Sievers
Quoted 8 lines · Greg KH
Quoted 6 lines · Kay Sievers
If the count of values handled in a transaction is not to high and it makes sense to group these values logically, why not just create an attribute group for every transaction, which creates dummy attributes to fill the values in, and use an "action" file in that group, that commits all the values at once to whatever target? That should fit into the ioctl use pattern, right?
Quoted 7 lines
Quoted 3 lines
That's what configfs can handle easier. I think the issue is getting stuff from the kernel in one atomic snapshot (all the different file values from the same point in time.)
Sure, but just like an ioctl, the kernel could return the values after writing to the "action" file in the dummy attributes. That would be something like a snapshot, right?
Yes, but where would the buffer be to return the data to on a write? In the data that the user passed to write?
thanks,
greg k-h
Quoted 14 lines · Greg KH
Quoted 13 lines · Kay Sievers
Quoted 11 lines · Greg KH
Quoted 6 lines · Kay Sievers
If the count of values handled in a transaction is not to high and it makes sense to group these values logically, why not just create an attribute group for every transaction, which creates dummy attributes to fill the values in, and use an "action" file in that group, that commits all the values at once to whatever target? That should fit into the ioctl use pattern, right?
That's what configfs can handle easier. I think the issue is getting stuff from the kernel in one atomic snapshot (all the different file values from the same point in time.)
Quoted 6 lines
Quoted 3 lines
Sure, but just like an ioctl, the kernel could return the values after writing to the "action" file in the dummy attributes. That would be something like a snapshot, right?
Yes, but where would the buffer be to return the data to on a write? In the data that the user passed to write?
In the "dummy attribute", allocated by the device instance.
Kay
Quoted 15 lines · Kay Sievers
Quoted 14 lines · Greg KH
Quoted 13 lines · Kay Sievers
Quoted 11 lines · Greg KH
Quoted 6 lines · Kay Sievers
If the count of values handled in a transaction is not to high and it makes sense to group these values logically, why not just create an attribute group for every transaction, which creates dummy attributes to fill the values in, and use an "action" file in that group, that commits all the values at once to whatever target? That should fit into the ioctl use pattern, right?
That's what configfs can handle easier. I think the issue is getting stuff from the kernel in one atomic snapshot (all the different file values from the same point in time.)
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Sure, but just like an ioctl, the kernel could return the values after writing to the "action" file in the dummy attributes. That would be something like a snapshot, right?
Yes, but where would the buffer be to return the data to on a write? In the data that the user passed to write?
In the "dummy attribute", allocated by the device instance.
Ok, I'm totally confused and don't understand anymore. Care to walk this through again as to how it would work?
sorry,
greg k-h
Quoted 6 lines · Greg KH
Quoted 1 line · Kyle Moffett
So my question stands: What is the _recommended_ way to handle simple data types in low-bandwidth/frequency multiple-valued transactions to hardware? Examples include reading/modifying framebuffer settings (currently done through IOCTLS), s390 current state (up for discussion), etc. In these cases there needs to be an atomic snapshot or write of multiple values at the same time. Given the situation it would be _nice_ to use sysfs so the admin can do it by hand; makes things shell scriptable and reduces the number of binary compatibility issues.
I really don't know of a way to use sysfs for this currently, and hence, am not complaining too much about the different /proc files that have this kind of information in it at the moment.
If you or someone else wants to come up with some kind of solution for it, I'm sure that many people would be very happy to see it.
Hmm, ok; I'll see what I can come up with. Would anybody object to this kind of API (as in my previous email) that uses an open fd as a transaction "handle"?
Example script:
Quoted 28 lines
## Associate this process with an atomic snapshot
## of the/sys/hypervisor/s390filesystem tree.
exec 3>/sys/hypervisor/s390/transaction## Read data from
/sys/hypervisor/s390without
## worrying about atomicity; as that's guaranteed
## by the open FD 3.
ls/sys/hypervisor/s390/cpus
cat/sys/hypervisor/s390/some_data_file## Create another reference in this process to the ## _same_ atomic snapshot
exec 4>&3## Does *not* close out the atomic snapshot
exec 3>&-## Yet another ref; still the _same_ snapshot
exec 6>/sys/hypervisor/s390/transaction
exec 4>&-## Regardless of what has changed in the meantime, ## our filesystem tree still looks the same ls
/sys/hypervisor/s390/cpus## Write out values
echosome_state>/sys/hypervisor/s390/statefile
Quoted 6 lines
## Decide we don't like the changes and abort
echo reset >&6## Release the last copy of the snapshot and
## commit modified values
exec 6>&-
This would allow usages like the following:
Quoted 7 lines
exec 3>/sys/hypervisor/s390/transaction
/bin/s390_change_hypervisor_state
## Look at new state; decide if we like it or not
if [ -z "$I_LIKE_THE_STATE" ]; then
echo reset >&3
fi
exec 3>&-
For actually implementing this; I'm considering a design which hangs a transaction off of a "struct file" such that fork() and clone() preserve the same transaction. When a new process obtains an FD with the given transaction it would add that process' current pointer to a hash-table referencing the transaction data structure so that the open() call could look up the transaction for a given task in the hash table and use the data specified in the transaction. When a transaction is opened it would read the data atomically from the hardware or in-kernel data structures and store an "initial" copy as well as a "current" copy in per-transaction memory. As a user could theoretically pin NPROC * size_of_transaction_data * 2 of kernel memory, transaction files should have fairly strict file modes or some sort of resource-accounting semantic. On a "reset" operation the "initial" copy would be used to overwrite the "current" copy again, and a changed bit would be unset. Changes would result in the changed bit being set. When the transaction is closed, if the changed bit is set then the data would be committed atomically, then all the memory would be freed and the transaction removed from the hash table.
Anything that sounds broken/fishy/"No that's impossible because..." in there? I appreciate your input; if this sounds feasable I'll try to hack up a patch.
Cheers,
Kyle Moffett
Quoted 16 lines · Kyle Moffett
Quoted 15 lines · Greg KH
Quoted 9 lines · Kyle Moffett
So my question stands: What is the _recommended_ way to handle simple data types in low-bandwidth/frequency multiple-valued transactions to hardware? Examples include reading/modifying framebuffer settings (currently done through IOCTLS), s390 current state (up for discussion), etc. In these cases there needs to be an atomic snapshot or write of multiple values at the same time. Given the situation it would be _nice_ to use sysfs so the admin can do it by hand; makes things shell scriptable and reduces the number of binary compatibility issues.
I really don't know of a way to use sysfs for this currently, and hence, am not complaining too much about the different /proc files that have this kind of information in it at the moment.
Quoted 6 lines
Quoted 2 lines
If you or someone else wants to come up with some kind of solution for it, I'm sure that many people would be very happy to see it.
Hmm, ok; I'll see what I can come up with. Would anybody object to this kind of API (as in my previous email) that uses an open fd as a transaction "handle"?
No, I think Kay played around with something like using the open fd of the directory as such a lock (or was he using flock on it, I can't remember now...)
Quoted 67 lines
Example script:
Quoted 28 lines
## Associate this process with an atomic snapshot
## of the/sys/hypervisor/s390filesystem tree.
exec 3>/sys/hypervisor/s390/transaction## Read data from
/sys/hypervisor/s390without
## worrying about atomicity; as that's guaranteed
## by the open FD 3.
ls/sys/hypervisor/s390/cpus
cat/sys/hypervisor/s390/some_data_file## Create another reference in this process to the ## _same_ atomic snapshot
exec 4>&3## Does *not* close out the atomic snapshot
exec 3>&-## Yet another ref; still the _same_ snapshot
exec 6>/sys/hypervisor/s390/transaction
exec 4>&-## Regardless of what has changed in the meantime, ## our filesystem tree still looks the same ls
/sys/hypervisor/s390/cpus## Write out values
echosome_state>/sys/hypervisor/s390/statefileQuoted 6 lines
## Decide we don't like the changes and abort
echo reset >&6## Release the last copy of the snapshot and
## commit modified values
exec 6>&-This would allow usages like the following:
Quoted 7 lines
exec 3>/sys/hypervisor/s390/transaction
/bin/s390_change_hypervisor_state
## Look at new state; decide if we like it or not
if [ -z "$I_LIKE_THE_STATE" ]; then
echo reset >&3
fi
exec 3>&-For actually implementing this; I'm considering a design which hangs a transaction off of a "struct file" such that
fork()andclone()preserve the same transaction. When a new process obtains an FD with the given transaction it would add that process' current pointer to a hash-table referencing the transaction data structure so that the open () call could look up the transaction for a given task in the hash table and use the data specified in the transaction. When a transaction is opened it would read the data atomically from the hardware or in-kernel data structures and store an "initial" copy as well as a "current" copy in per-transaction memory. As a user could theoretically pin NPROC *size_of_transaction_data* 2 of kernel memory, transaction files should have fairly strict file modes or some sort of resource-accounting semantic. On a "reset" operation the "initial" copy would be used to overwrite the "current" copy again, and a changed bit would be unset. Changes would result in the changed bit being set. When the transaction is closed, if the changed bit is set then the data would be committed atomically, then all the memory would be freed and the transaction removed from the hash table.
Quoted 3 lines
Anything that sounds broken/fishy/"No that's impossible because..." in there? I appreciate your input; if this sounds feasable I'll try to hack up a patch.
Sounds a bit complex. Try looking at flock and see if you can pass that info back to the sysfs attribute owners.
thanks,
greg k-h
Quoted 20 lines · Greg KH
Quoted 19 lines · Kyle Moffett
Quoted 17 lines · Greg KH
Quoted 9 lines · Kyle Moffett
So my question stands: What is the _recommended_ way to handle simple data types in low-bandwidth/frequency multiple-valued transactions to hardware? Examples include reading/modifying framebuffer settings (currently done through IOCTLS), s390 current state (up for discussion), etc. In these cases there needs to be an atomic snapshot or write of multiple values at the same time. Given the situation it would be _nice_ to use sysfs so the admin can do it by hand; makes things shell scriptable and reduces the number of binary compatibility issues.
I really don't know of a way to use sysfs for this currently, and hence, am not complaining too much about the different /proc files that have this kind of information in it at the moment.
If you or someone else wants to come up with some kind of solution for it, I'm sure that many people would be very happy to see it.
Quoted 7 lines
Quoted 3 lines
Hmm, ok; I'll see what I can come up with. Would anybody object to this kind of API (as in my previous email) that uses an open fd as a transaction "handle"?
No, I think Kay played around with something like using the open fd of the directory as such a lock (or was he using flock on it, I can't remember now...)
If you can assume that processes accessing the values are cooperative, it already works without any changes:
$ time flock /sys/class/firmware echo 1 > /sys/class/firmware/timeout real 0m0.005s
$ flock /sys/class/firmware sleep 5& [1] 6468
$ time flock /sys/class/firmware echo 1 > /sys/class/firmware/timeout real 0m3.558s
Kay
Quoted 6 lines · Kay Sievers
If you can assume that processes accessing the values are cooperative, it already works without any changes:
$ time flock /sys/class/firmware echo 1 > /sys/class/firmware/ timeout real 0m0.005s
Quoted 6 lines
$ flock /sys/class/firmware sleep 5& [1] 6468$ time flock /sys/class/firmware echo 1 > /sys/class/firmware/ timeout real 0m3.558s
But that doesn't solve the problem for framebuffer devices or for the s390 code. Such transactions have one or more of the following properties:
(1) A read operation is _expensive_ or adds unacceptable latencies and should be done as rarely as possible
(2) The data must be all written to hardware simultaneously by the kernel; a partial update does not make sense and would cause undesired operation from the hardware.
The idea with the transactions would be to create a kernel-memory buffer-layer of sorts on top of the underlying sysfs tree to cache the read data and collect writes for an atomic commit. I'll see if I can make something work.
Cheers,
Kyle Moffett
Kyle Moffett <[email protected]> wrote on 04/29/2006 10:41:05 AM:
|snip]
Quoted 9 lines
It sounds like a lot of things need some kind of shell-scriptable transaction interface for sysfs files. You don't want to have more than one value per file, but reading or writing of some values must be done together for consistency reasons. Is there any way to implement something like this? This would work for the framebuffer people and solve the needs of a lot of the people who still want ioctls or some other atomic-multivalued transfer that would otherwise be a great sysfs candidate.
Martin told me that you will probably kill me for the following, but I neverless would like to post my suggestion:
All the complicated mechanisms with filesystem trees to obtain consistent data and transaction functionality could be avoided, if we would use single files, which contain all the data. When opening the file, the snapshot is created and attached to the struct file.
As far as I know, common sense is to avoid that, because it is ugly and error prone to parse the files in user space.
But If we would provide a standard tag language (I don't say XML here) for all sort of kernel data, which should be exported to user space, one standard parser could be used to obtain the data. This is not error prone since you can always use the standard parser to access the data. It is still human readable, which is an advantage compared with binary files. You can either read
the file directly or use the parser to get the tree structure in a better readable way. E.g in our s390 hypfs example you could call:
standardparser < /sys/hypervisor/s390/accountigdata
which prints a nice tree to stdout. Or you could use the parser in shell scripts to obtain specific attributes. E.g. you could call:
standardparser < .../acountingdata systems.lparxy.cpu0.time
which prints e.g. "32432515" to stdout.
This approach would solve our atomicity problem and also the problem of parsing complicated sysfs files.
Putting the tree into one file using a tag language is from a logical point of view exactly the same as creating a directory tree within a filesystem.
Regarding performance in kernel space it is not more effort to create the tree in one file than creating the tree within a filesystem. It is even less effort, since you do not need hundreds of system calls (open, read, close) to obtain the data from user space.
If you think, that this topic has already been discussed too often on this mailing list and it is not worth discussing this further, please just ignore this posting!
Michael
Quoted 5 lines · Michael Holzheu
All the complicated mechanisms with filesystem trees to obtain consistent data and transaction functionality could be avoided, if we would use single files, which contain all the data. When opening the file, the snapshot is created and attached to the struct file.
If we're going to add new infrastructure, I'd vote for adding snapshotting capability to filesystems. We need it for stuff like LogFS anyway.
Pekka
Pekka J Enberg <[email protected]> wrote on 05/03/2006 11:42:01 AM:
Quoted 8 lines · Michael Holzheu
Quoted 5 lines
All the complicated mechanisms with filesystem trees to obtain consistent data and transaction functionality could be avoided, if we would use single files, which contain all the data. When opening the file, the snapshot is created and attached to the struct file.
If we're going to add new infrastructure, I'd vote for adding
snapshotting
Quoted 2 lines
capability to filesystems. We need it for stuff like LogFS anyway.
Maybe we need that, too. But I think the advantage of the one file solution moves the complexity from the kernel to userspace.
Michael
Quoted 4 lines · Michael Holzheu
Maybe we need that, too. But I think the advantage of the one file solution moves the complexity from the kernel to userspace.
Now might be a time to come back to Martin's prediction. ;)
Having a weird format in some file does _not_ move complexity from the kernel. It may make the userspace more complex, granted. But once you try to change something, you need to keep the ABI stable. And part of the ABI is you file format.
Applications will depend on some arcane detail of your format. They
will depend on exactly five spaces in "foo bar". It does not even
matter if you documented "any amount of whitespace". The application knows that it was five spaces and doesn't care. And once you change it, the blame will be on you, because you broke existing userspace.
If that does not make the kernel complex, I don't know what does.
Jörn
Signature · 2 lines
It does not matter how slowly you go, so long as you do not stop. -- Confucius
Hi Jörn,
Jörn Engel <[email protected]> wrote on 05/03/2006 02:33:39 PM:
Quoted 6 lines · Michael Holzheu
Quoted 4 lines
Maybe we need that, too. But I think the advantage of the one file solution moves the complexity from the kernel to userspace.
Quoted 6 lines
Now might be a time to come back to Martin's prediction. ;)
Having a weird format in some file does _not_ move complexity from the kernel. It may make the userspace more complex, granted. But once you try to change something, you need to keep the ABI stable. And part of the ABI is you file format.
This is also true, if you use a filesystem tree. The tree structure and the content of the files are part of your ABI. There is no difference between a standard tag based file (all kernel files should use the same format of course!) and a filesystem tree.
Quoted 5 lines
Applications will depend on some arcane detail of your format. They
will depend on exactly five spaces in "foo bar". It does not even
matter if you documented "any amount of whitespace". The application knows that it was five spaces and doesn't care. And once you change it, the blame will be on you, because you broke existing userspace.
Again, logically there is no difference between the two solutions. It does not matter, if you have one file with:
<cpu>
<0>
<onlinetime = 4711>
<\0><\cpu>
... or whatever the standard kernel format will be ... and a filesystem tree with:
+cpu
+ 0
+ onlinetime
If you implement a standard userspace parser, you can access the attributes in one file as easyly as the attributes in a filesystem tree.
Michael
Quoted 8 lines · Michael Holzheu
Jörn Engel <[email protected]> wrote on 05/03/2006 02:33:39 PM:
Quoted 5 lines
Applications will depend on some arcane detail of your format. They
will depend on exactly five spaces in "foo bar". It does not even
matter if you documented "any amount of whitespace". The application knows that it was five spaces and doesn't care. And once you change it, the blame will be on you, because you broke existing userspace.
Quoted 8 lines
Again, logically there is no difference between the two solutions. It does not matter, if you have one file with:
<cpu>
<0> <onlinetime = 4711> <\0><\cpu>
Userspace can make your life hell by depending on indentation via 4 spaces. The problem is that you don't necessarily know that it does until you managed to change indentation.
In a filesystem tree, it is fairly hard to make assumptions that are later broken. It is by no means impossible, agreed. But the "indentation" doesn't exist anymore. A file is part of a subdirectory or it isn't. Opening tags without matching closing tags don't exist either. List goes on.
In the end, both formats can get abused in ways you'd never foresee. But the directory tree considerably raises the barrier.
Jörn
Signature · 2 lines
He who knows that enough is enough will always have enough. -- Lao Tsu
Hi Jörn,
Jörn Engel <[email protected]> wrote on 05/03/2006 03:00:43 PM:
Quoted 2 lines · Michael Holzheu
Quoted 1 line
Jörn Engel <[email protected]> wrote on 05/03/2006 02:33:39
PM:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Applications will depend on some arcane detail of your format. They
will depend on exactly five spaces in "foo bar". It does not
even
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
matter if you documented "any amount of whitespace". The application knows that it was five spaces and doesn't care. And once you change it, the blame will be on you, because you broke existing userspace.
Again, logically there is no difference between the two solutions. It
does
Quoted 11 lines
Quoted 7 lines
not matter, if you have one file with:
<cpu>
<0> <onlinetime = 4711> <\0><\cpu>
Userspace can make your life hell by depending on indentation via 4 spaces. The problem is that you don't necessarily know that it does until you managed to change indentation.
Of course! But the convention must be, that If userspace wants to access the data, it has to use our standard linux parser. If it accesses the data directly, this is broken. This ensures, that whitespaces do not matter at all! And as I said before, if you use the parser, you don't have any difference compared to the filesystem solution from a logical perspective.
Michael
Quoted 8 lines · Michael Holzheu
Of course! But the convention must be, that If userspace wants to access the data, it has to use our standard linux parser. If it accesses the data directly, this is broken. This ensures, that whitespaces do not matter at all! And as I said before, if you use the parser, you don't have any difference compared to the filesystem solution from a logical perspective.
o People are not forced to follow the convention. If they don't and you break an existing application, you get the blame.
o Now you have a dependency on the standard parser, which is in userspace. Any bug in any version of the standard parser and...
Jörn
Signature · 3 lines
There's nothing better for promoting creativity in a medium than making an audience feel "Hmm I could do better than that!" -- Douglas Adams in a slashdot interview
Hi Jörn,
Jörn Engel <[email protected]> wrote on 05/03/2006 03:22:39 PM:
Quoted 4 lines · Michael Holzheu
Quoted 1 line
o People are not forced to follow the convention. If they don't and you break an existing application, you get the blame.
Sure, but this is really just a matter of definition. The kernel defines the ABI, right?. User space has to follow the rules. If they break the rules
that's badluck for the userspace tools. Currently you can also get kernel information directly from /dev/mem. If an application does that, nobody would say, that we are not allowed to change kernel data structures because of that user space application.
Quoted 2 lines
o Now you have a dependency on the standard parser, which is in userspace. Any bug in any version of the standard parser and...
At least this parser should be well tested, if everybody uses it.
But maybe I am completely wrong here ....
Michael
Quoted 5 lines · Michael Holzheu
Quoted 4 lines · Michael Holzheu
Quoted 1 line
o People are not forced to follow the convention. If they don't and you break an existing application, you get the blame.
Quoted 7 lines
Sure, but this is really just a matter of definition. The kernel defines the ABI, right?. User space has to follow the rules. If they break the rules
that's badluck for the userspace tools. Currently you can also get kernel information directly from/dev/mem. If an application does that, nobody would say, that we are not allowed to change kernel data structures because of that user space application.
The kernel defines the ABI, but what IS the ABI? Is a single space that the current implementation delivers an indication that there needs to be a single space between two values, or could there be an arbitrary number of spaces and tabs? You certainly can't conclude that from the code. For /proc files people tended to use sscanf to read lines from the output. Is the format of a line fixed, or can it be extended by additional fields? Does certain fields have to start at a specific offset or not? How long can the different fields get? And so on.
Quoted 4 lines
Quoted 2 lines
o Now you have a dependency on the standard parser, which is in userspace. Any bug in any version of the standard parser and...
At least this parser should be well tested, if everybody uses it.
And the user space then uses the parser only? Is now the parser interface the "ABI" or the kernel interface that is in turn used by the parser? And what happens if somebody comes up with a "better" parser that does things subtly different?
In short: keep the kernel interface as simple as you possibly can. That is why the single value approach has been invented. A text file that needs to get parsed is certainly not simple.
Signature · 8 lines
blue skies, Martin. Martin Schwidefsky Linux for zSeries Development & Services IBM Deutschland Entwicklung GmbH "Reality continues to ruin my life." - Calvin.
[email protected] wrote on 05/03/2006 04:17:40 PM:
Quoted 4 lines
And the user space then uses the parser only? Is now the parser interface the "ABI" or the kernel interface that is in turn used by the parser? And what happens if somebody comes up with a "better" parser that does things subtly different?
The ABI is not defined by the Parser. You have to specify the tag language, which is part of the ABI. Any parser, which is comliant to the specification of the tag language can be used.
Quoted 9 lines · Michael Holzheu
[email protected] wrote on 05/03/2006 04:17:40 PM:
Quoted 4 lines
And the user space then uses the parser only? Is now the parser interface the "ABI" or the kernel interface that is in turn used by the parser? And what happens if somebody comes up with a "better" parser that does things subtly different?
The ABI is not defined by the Parser. You have to specify the tag language, which is part of the ABI. Any parser, which is comliant to the specification of the tag language can be used.
Optimist.
Signature · 8 lines
blue skies, Martin. Martin Schwidefsky Linux for zSeries Development & Services IBM Deutschland Entwicklung GmbH "Reality continues to ruin my life." - Calvin.
[email protected] wrote on 05/03/2006 04:58:06 PM:
Quoted 4 lines · Michael Holzheu
Quoted 3 lines
[email protected] wrote on 05/03/2006 04:17:40 PM:
Quoted 2 lines
And the user space then uses the parser only? Is now the parser interface the "ABI" or the kernel interface that is in turn used by
the
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
parser? And what happens if somebody comes up with a "better" parser that does things subtly different?
The ABI is not defined by the Parser. You have to specify the tag language, which is part of the ABI. Any parser, which is comliant to the specification of the tag language can be used.
Optimist.
One very last comment: I think for our problem to ensure consitency of hypervisor data, when an application always wants to get the complete set of information, the "one file" solution with a fully specified ASCII tag language format looks for me to be the easiest way to implement our solution. And I think, if one decides to use one file to provide all the information, it is better to have a standard data format than always invent new formats. And to use a standard ASCII format is
in my eyes also better than to have a binary interface.
If everybody says, that it is in principal not a good idea to use one file, than a snapshot mechanism
for filesystems is probably go good method to provide consitency. And this is definitely not my decission...
Michael
Quoted 3 lines · Michael Holzheu
Of course! But the convention must be, that If userspace wants to access the data, it has to use our standard linux parser. If it accesses the data directly, this is broken.
Yet another case of Eternal Optimism flying in the face of Reality... ;)
a) you can't *force* the use of your parser.
b) this creates a userspace dependency that can get messy if the parser is buggy or requires modification to deal with a kernel change.
Quoted 6 lines · Michael Holzheu
All the complicated mechanisms with filesystem trees to obtain consistent data and transaction functionality could be avoided, if we would use single files, which contain all the data. When opening the file, the snapshot is created and attached to the struct file.
s/single file/single entity/ and this may be useful. Your filesystem exports a directory tree, which is nice and easily parsable. The problem is that it is a single resource for everyone. If different users could have their own views of this filesystem, each with a private snapshot, many problems would be solved.
Spufs might have something similar already. Istr something about returning a directory fd and then using openat(2) and friends.
Jörn
Signature · 4 lines
To my face you have the audacity to advise me to become a thief - the worst kind of thief that is conceivable, a thief of spiritual things, a thief of ideas! It is insufferable, intolerable! -- M. Binet in Scarabouche
Greg KH <[email protected]> wrote on 04/29/2006 09:53:11 AM:
Quoted 2 lines · Michael Holzheu
Quoted 1 line
On zSeries machines there exists an interface which allows the
operating
Quoted 66 lines
Quoted 66 lines
system to retrieve LPAR hypervisor accounting data. For example, it is possible to get usage data for physical and virtual cpus. In order to provide this information to user space programs, I implemented a new virtual Linux file system named 'hypfs' using the Linux 2.6 libfs framework. The name 'hypfs' stands for 'Hypervisor Filesystem'. All the accounting information is put into different virtual files which can be accessed from user space. All data is represented as ASCII strings.
When the file system is mounted the accounting information is retrieved and a file system tree is created with the attribute files containing the cpu information. The content of the files remains unchanged until a new update is made. An update can be triggered from user space through writing 'something' into a special purpose update file.
We create the following directory structure:
<mount-point>/
update cpus/ <cpu-id> type mgmtime <cpu-id> ... hyp/ type systems/ <lpar-name> cpus/ <cpu-id> type mgmtime cputime onlinetime <cpu-id> ... <lpar-name> cpus/ ...- update: File to trigger update
- cpus/: Directory for all physical cpus
- cpus/<cpu-id>/: Directory for one physical cpu.
- cpus/<cpu-id>/type: Type name of physical zSeries cpu.
- cpus/<cpu-id>/mgmtime: Physical-LPAR-management time in microseconds.
- hyp/: Directory for hypervisor information
- hyp/type: Typ of hypervisor (currently only 'LPAR Hypervisor')
- systems/: Directory for all LPARs
- systems/<lpar-name>/: Directory for one LPAR.
- systems/<lpar-name>/cpus/<cpu-id>/: Directory for the virtual cpus
- systems/<lpar-name>/cpus/<cpu-id>/type: Typ of cpu.
- systems/<lpar-name>/cpus/<cpu-id>/mgmtime:
Accumulated number of microseconds during which a physical CPU was assigned to the logical cpu and the cpu time was consumed by the hypervisor and was not provided to
the LPAR (LPAR overhead).- systems/<lpar-name>/cpus/<cpu-id>/cputime:
Accumulated number of microseconds during which a physical CPU was assigned to the logical cpu and the cpu time was consumed by the LPAR.- systems/<lpar-name>/cpus/<cpu-id>/onlinetime:
Accumulated number of microseconds during which the logical CPU has been online.
Quoted 8 lines
Quoted 6 lines
As mount point for the filesystem
/sys/hypervisoris created.The update process is triggered when writing 'something' into the 'update' file at the top level hypfs directory. You can do this e.g. with 'echo 1 > update'. During the update the whole directory structure is deleted and built up again.
This sounds a lot like configfs. Why not use that instead?
Right! I read the documentation of configfs and looks like configfs is exactly what I need.
To get consistend data the user can do the following:
1. mkdir /config/s390-hypervisor/tmpdir
This creates our directory tree with a snapshot of the hypervisor data.
2. cd tmpdir and read all data
3. rmdir /config/s390-hypervisor/tmpdir
It looks a bit odd to get hypervisor accounting data from /config, but who cares ...
Michael
Hi Greg and Joel,
Greg KH <[email protected]> wrote on 04/29/2006 09:53:11 AM:
Quoted 2 lines · Michael Holzheu
Quoted 1 line
On zSeries machines there exists an interface which allows the
operating
Quoted 66 lines
Quoted 66 lines
system to retrieve LPAR hypervisor accounting data. For example, it is possible to get usage data for physical and virtual cpus. In order to provide this information to user space programs, I implemented a new virtual Linux file system named 'hypfs' using the Linux 2.6 libfs framework. The name 'hypfs' stands for 'Hypervisor Filesystem'. All the accounting information is put into different virtual files which can be accessed from user space. All data is represented as ASCII strings.
When the file system is mounted the accounting information is retrieved and a file system tree is created with the attribute files containing the cpu information. The content of the files remains unchanged until a new update is made. An update can be triggered from user space through writing 'something' into a special purpose update file.
We create the following directory structure:
<mount-point>/
update cpus/ <cpu-id> type mgmtime <cpu-id> ... hyp/ type systems/ <lpar-name> cpus/ <cpu-id> type mgmtime cputime onlinetime <cpu-id> ... <lpar-name> cpus/ ...- update: File to trigger update
- cpus/: Directory for all physical cpus
- cpus/<cpu-id>/: Directory for one physical cpu.
- cpus/<cpu-id>/type: Type name of physical zSeries cpu.
- cpus/<cpu-id>/mgmtime: Physical-LPAR-management time in microseconds.
- hyp/: Directory for hypervisor information
- hyp/type: Typ of hypervisor (currently only 'LPAR Hypervisor')
- systems/: Directory for all LPARs
- systems/<lpar-name>/: Directory for one LPAR.
- systems/<lpar-name>/cpus/<cpu-id>/: Directory for the virtual cpus
- systems/<lpar-name>/cpus/<cpu-id>/type: Typ of cpu.
- systems/<lpar-name>/cpus/<cpu-id>/mgmtime:
Accumulated number of microseconds during which a physical CPU was assigned to the logical cpu and the cpu time was consumed by the hypervisor and was not provided to
the LPAR (LPAR overhead).- systems/<lpar-name>/cpus/<cpu-id>/cputime:
Accumulated number of microseconds during which a physical CPU was assigned to the logical cpu and the cpu time was consumed by the LPAR.- systems/<lpar-name>/cpus/<cpu-id>/onlinetime:
Accumulated number of microseconds during which the logical CPU has been online.
Quoted 9 lines
Quoted 6 lines
As mount point for the filesystem
/sys/hypervisoris created.The update process is triggered when writing 'something' into the 'update' file at the top level hypfs directory. You can do this e.g. with 'echo 1 > update'. During the update the whole directory structure is deleted and built up again.
This sounds a lot like configfs. Why not use that instead?
After having a deeper look into configfs, I do not understand how to create a directory tree. Is it somehow possible to create a directory tree as a result of mkdir? Maybe I missed here something...
Michael
Greg KH <[email protected]> wrote on 04/29/2006 09:53:11 AM:
Quoted 2 lines · Michael Holzheu
Quoted 1 line
On zSeries machines there exists an interface which allows the
operating
Quoted 66 lines
Quoted 66 lines
system to retrieve LPAR hypervisor accounting data. For example, it is possible to get usage data for physical and virtual cpus. In order to provide this information to user space programs, I implemented a new virtual Linux file system named 'hypfs' using the Linux 2.6 libfs framework. The name 'hypfs' stands for 'Hypervisor Filesystem'. All the accounting information is put into different virtual files which can be accessed from user space. All data is represented as ASCII strings.
When the file system is mounted the accounting information is retrieved and a file system tree is created with the attribute files containing the cpu information. The content of the files remains unchanged until a new update is made. An update can be triggered from user space through writing 'something' into a special purpose update file.
We create the following directory structure:
<mount-point>/
update cpus/ <cpu-id> type mgmtime <cpu-id> ... hyp/ type systems/ <lpar-name> cpus/ <cpu-id> type mgmtime cputime onlinetime <cpu-id> ... <lpar-name> cpus/ ...- update: File to trigger update
- cpus/: Directory for all physical cpus
- cpus/<cpu-id>/: Directory for one physical cpu.
- cpus/<cpu-id>/type: Type name of physical zSeries cpu.
- cpus/<cpu-id>/mgmtime: Physical-LPAR-management time in microseconds.
- hyp/: Directory for hypervisor information
- hyp/type: Typ of hypervisor (currently only 'LPAR Hypervisor')
- systems/: Directory for all LPARs
- systems/<lpar-name>/: Directory for one LPAR.
- systems/<lpar-name>/cpus/<cpu-id>/: Directory for the virtual cpus
- systems/<lpar-name>/cpus/<cpu-id>/type: Typ of cpu.
- systems/<lpar-name>/cpus/<cpu-id>/mgmtime:
Accumulated number of microseconds during which a physical CPU was assigned to the logical cpu and the cpu time was consumed by the hypervisor and was not provided to
the LPAR (LPAR overhead).- systems/<lpar-name>/cpus/<cpu-id>/cputime:
Accumulated number of microseconds during which a physical CPU was assigned to the logical cpu and the cpu time was consumed by the LPAR.- systems/<lpar-name>/cpus/<cpu-id>/onlinetime:
Accumulated number of microseconds during which the logical CPU has been online.
Quoted 9 lines
Quoted 6 lines
As mount point for the filesystem
/sys/hypervisoris created.The update process is triggered when writing 'something' into the 'update' file at the top level hypfs directory. You can do this e.g. with 'echo 1 > update'. During the update the whole directory structure is deleted and built up again.
This sounds a lot like configfs. Why not use that instead?
I read more about configfs. There seems to be no way to create our complete directory tree, when issuing the mkdir.
Therefore I would like to stay with my current implementation of the Hypervisor Filesystem.
Michael