s390: Hypervisor File System
Subsystems (3)
From: [email protected]
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.
Regarding the mount point I am not sure what to use. Currently I would suggest /sys/hypervisor. Any better ideas for the mount point?
Currently this is a zSeries specific solution but if other virtualization platforms like e.g. Xen are interested in exporting hypervisor data to user space, we can think of a more generic approach.
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: Time of last update in seconds since 1970.
- cpus/: Directory for all physical cpus
- cpus/<cpu-id>/: Directory for one physical cpu. <cpu-id> is a logical (decimal) cpu number
- 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: Type 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 for one LPAR. <cpu-id> is a logical (decimal) cpu number.
- systems/<lpar-name>/cpus/<cpu-id>/type: Type name of the logical zSeries cpu.
- systems/<lpar-name>/cpus/<cpu-id>/mgmtime: LPAR-management time. 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.
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. The update file contains the time of the last update in seconds since 1970.
---
fs/Kconfig | 11 fs/Makefile | 1 fs/hypfs/Makefile | 7 fs/hypfs/hypfs.h | 43 +++ fs/hypfs/hypfs_diag.c | 628 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/hypfs/hypfs_diag.h | 16 + fs/hypfs/inode.c | 469 +++++++++++++++++++++++++++++++++++++ 7 files changed, 1175 insertions(+)
fs/Kconfig +11 -0
@@ -802,6 +802,17 @@ config PROC_VMCORE help Exports the dump image of crashed kernel in ELF format. +config HYPFS_FS + bool "zseries hypervisor file system support" + depends on S390 + default y + help + This is a virtual file system intended to provide accounting + information in a zSeries hypervisor environment. + + If you don't know whether you need it, then you don't need it: + answer N. + config SYSFS bool "sysfs file system support" if EMBEDDED default y
fs/Makefile +1 -0
@@ -54,6 +54,7 @@ obj-$(CONFIG_REISERFS_FS) += reiserfs/ obj-$(CONFIG_EXT3_FS) += ext3/ # Before ext2 so root fs can be ext3 obj-$(CONFIG_JBD) += jbd/ obj-$(CONFIG_EXT2_FS) += ext2/ +obj-$(CONFIG_HYPFS_FS) += hypfs/ obj-$(CONFIG_CRAMFS) += cramfs/ obj-$(CONFIG_RAMFS) += ramfs/ obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
fs/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
fs/hypfs/hypfs.h +43 -0
43 lines not on this page · raw message
fs/hypfs/hypfs_diag.c +628 -0
628 lines not on this page · raw message
fs/hypfs/hypfs_diag.h +16 -0
@@ -0,0 +1,16 @@ +/* +* fs/hypfs/hypfs_diag.h +* Hypervisor filesystem for Linux on zSeries. +* +* 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_ */
fs/hypfs/inode.c +469 -0
469 lines not on this page · raw message
Hi Michael,
Quoted 2 lines · Michael Holzheu
On zSeries machines there exists an interface which allows the operating system to retrieve LPAR hypervisor accounting data.
[snip]
Quoted 8 lines
fs/Kconfig | 11 fs/Makefile | 1 fs/hypfs/Makefile | 7 fs/hypfs/hypfs.h | 43 +++ fs/hypfs/hypfs_diag.c | 628 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/hypfs/hypfs_diag.h | 16 + fs/hypfs/inode.c | 469 +++++++++++++++++++++++++++++++++++++ 7 files changed, 1175 insertions(+)
This filesystem makes no sense for anything but s390 so please put it under arch/s390/ (following the convention set by cell specific spufs). Thanks.
Pekka
Hi Pekka,
Quoted 3 lines
This filesystem makes no sense for anything but s390 so please put it under
arch/s390/(following the convention set by cell specific spufs). Thanks.
Agreed! As long as the filesystem is s390 specifc, we probably should put it put it under arch/s390/hypfs. But in general one could imagine, that also other hypervisor platforms want to have such a filesystem in the future. In that case, we could make the filesystem more generic. E.g. we could split it into the filesystem part and an architecture specific backend which provides the hypervisor data. But you are right, until no other platform supports it, we should keep it simple, leave it s390 specific and move it to arch/s390.
Michael
Quoted 4 lines · Michael Holzheu
Quoted 3 lines
This filesystem makes no sense for anything but s390 so please put it under
arch/s390/(following the convention set by cell specific spufs). Thanks.
Quoted 9 lines
Agreed! As long as the filesystem is s390 specifc, we probably should put it put it under
arch/s390/hypfs. But in general one could imagine, that also other hypervisor platforms want to have such a filesystem in the future. In that case, we could make the filesystem more generic. E.g. we could split it into the filesystem part and an architecture specific backend which provides the hypervisor data. But you are right, until no other platform supports it, we should keep it simple, leave it s390 specific and move it toarch/s390.
There was some discussion about a sysfs hierarchy for hypervisor data some time ago, see also http://lwn.net/Articles/176365/.
The idea was rather similar, just for other attributes. Maybe this can be consolidated in some way.
Is there a strong reason why you made your own file system instead of using subsystem_register to add /sys/hypervisor?
Arnd <><
Hi Arnd,
Arnd Bergmann <[email protected]> wrote on 04/21/2006 04:55:46 PM:
Quoted 4 lines
There was some discussion about a sysfs hierarchy for hypervisor data some time ago, see also http://lwn.net/Articles/176365/.
The idea was rather similar, just for other attributes. Maybe this can be consolidated in some way.
Thank you for the hint! Maybe we can find someone from the xen team to discuss this.
Quoted 2 lines
Is there a strong reason why you made your own file system instead of using
subsystem_registerto add/sys/hypervisor?
The main argument was that in sysfs normally operating system local data is provided like data for busses or devices. The hypervisor data does not belong to one machine. It is data for several machines within a hypervisor environment.
Michael
Quoted 5 lines · Michael Holzheu
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.
Why are you caching the data?
Pekka
Quoted 7 lines
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.
Why are you caching the data?
We had two problems:
The first one was, that the hardware interface for getting the data is very expensive. We always get back the data for all LPARs and all cpus. Therefore
we do not want to get the data every time an attribute file is read.
The second problem was, that we want to provide a consistent snapshot of the hypervisor data for the user space application. The mechanism to achieve that is that the application first reads the update file. If the data is too old, it triggers an update. Then we get the new hypervisor data and update the whole filesystem tree. Then the application can read file for file all data it needs. After all data is read and the application wants to have a consistent snapshot, it has to read the update attribute again. If the time value has changed, another process has triggered another update in the meantime. In this case the application has repeat the whole process.
Currently we allow only one update per second.
Michael
Hi Michael,
Quoted 4 lines · Michael Holzheu
The first one was, that the hardware interface for getting the data is very expensive. We always get back the data for all LPARs and all cpus. Therefore we do not want to get the data every time an attribute file is read.
You can cache the results in userspace. So I don't see this one as an argument for making the kernel more complex.
Quoted 2 lines · Michael Holzheu
The second problem was, that we want to provide a consistent snapshot of the hypervisor data for the user space application.
How do you ensure consistency now? And how is that different from an userspace process reading the whole directory hierarchy into cache in one go?
The update-on-write to special file thing seems bit strange to me. What if two processes ask for it at the same time?
Pekka
Quoted 10 lines · Pekka Enberg
Hi Michael,
Quoted 4 lines · Michael Holzheu
The first one was, that the hardware interface for getting the data is very expensive. We always get back the data for all LPARs and all cpus. Therefore we do not want to get the data every time an attribute file is read.
You can cache the results in userspace. So I don't see this one as an argument for making the kernel more complex.
Unfortunately we can't cache them in user-space. To read a file you do open/read/close an the attributes you are interested in. If we do not cache the content of the attributes in the kernel we have to issue a diag204 for each open/read/close sequence. But the data that is deliverd by diag204 will have changed between the two calls. In addition the number of active lpars and the lpar names might have changed.
Quoted 7 lines · Michael Holzheu
Quoted 2 lines
The second problem was, that we want to provide a consistent snapshot of the hypervisor data for the user space application.
How do you ensure consistency now? And how is that different from an userspace process reading the whole directory hierarchy into cache in one go?
We ensure the consistency by the following sequence:
1) read the update attribute to get the timestamp of the last update
2) decide if the data is new enough, if it is to old write something to the update attribute and restart with 1)
3) read the information you are interested in
4) read the update attribute again and compare it with the one read in step 1). If the timestamp has changed restart the whole thing with 1)
Quoted 2 lines
The update-on-write to special file thing seems bit strange to me. What if two processes ask for it at the same time?
Yes, we had that discussion as well. Any sensible suggestion how to do it in a more clever way would be greatly appreciated. We haven't found something better so far.
Signature · 8 lines
blue skies, Martin. Martin Schwidefsky Linux for zSeries Development & Services IBM Deutschland Entwicklung GmbH "Reality continues to ruin my life." - Calvin.
Hi Martin,
Quoted 2 lines · Pekka Enberg
Quoted 2 lines
The update-on-write to special file thing seems bit strange to me. What if two processes ask for it at the same time?
Quoted 3 lines · Martin Schwidefsky
Yes, we had that discussion as well. Any sensible suggestion how to do it in a more clever way would be greatly appreciated. We haven't found something better so far.
The only way I can think of is via s_ops->remount_fs. That's bit safer anyway, as sb->s_lock protects us from concurrent updates. I am cc'ing fsdevel to see if they can come up with a better suggestion.
Pekka
Hi Michael,
I have included some review comments below.
Pekka
fs/hypfs/hypfs.h line 39
Quoted 13 lines · Michael Holzheu
diff -urpN
linux-2.6.16/fs/hypfs/hypfs.hlinux-2.6.16-hypfs/fs/hypfs/hypfs.hfs/hypfs/hypfs.h +10
-0+static void inline remove_trailing_blanks (char *string) +{ +char *ptr; +for (ptr = string +strlen (string) -1 ; ptr > string; ptr--) { +if (*ptr ==' ' ) + *ptr =0 ; +else +break ; + } +}
Please consider moving this to lib/string.c and perhaps renaming it to strstrip().
Quoted 6 lines
diff -urpN
linux-2.6.16/fs/hypfs/hypfs_diag.clinux-2.6.16-hypfs/fs/hypfs/hypfs_diag.cfs/hypfs/hypfs_diag.c +3
-0+/* diag 204 subcodes */ +typedef enum { + SUBC_STIB4 = 4,
fs/hypfs/hypfs_diag.c line 30
Quoted 10 lines
fs/hypfs/hypfs_diag.c +10
-0+SUBC_RSI =5 , +SUBC_STIB6 =6 , + SUBC_STIB7 = 7 +} diag204_subc_t; + +/* The two available diag 204 data formats */ +typedef enum { +INFO_SIMPLE =0 , +INFO_EXT =0x00010000 +}diag204_info_t ;
Please kill the typedefs.
Quoted 11 lines
fs/hypfs/hypfs_diag.c +11
-0+/* Time information block */ + +struct info_blk_hdr { +__u8 npar; +__u8 flags; +__u16 tslice; +__u16 phys_cpus; +__u16 this_part; +__u64 curtod; +} __attribute__ ((packed)); +
fs/hypfs/hypfs_diag.c line 67
Quoted 10 lines
fs/hypfs/hypfs_diag.c +10
-0+struct x_info_blk_hdr { +__u8 npar; +__u8 flags; +__u16 tslice; +__u16 phys_cpus; +__u16 this_part; +__u64 curtod1; +__u64 curtod2; +char reserved[40 ]; +} __attribute__ ((packed));
Couldn't you use endianess annotated types for these?
Quoted 16 lines
fs/hypfs/hypfs_diag.c +16
-0+/* Partition header */ + +struct part_hdr { +__u8 pn; +__u8 cpus; +char reserved[6 ]; +char part_name[LPAR_NAME_LEN ]; +} __attribute__ ((packed)); + +struct x_part_hdr { +__u8 pn; +__u8 cpus; +__u8 rcpus; +__u8 pflag; +__u32 mlu; +char part_name[LPAR_NAME_LEN ];
fs/hypfs/hypfs_diag.c line 126
Quoted 10 lines
fs/hypfs/hypfs_diag.c +10
-0+char lpc_name[8 ]; +char os_name[8 ]; +__u64 online_cs; +__u64 online_es; +__u8 upid; +char reserved1[3 ]; +__u32 group_mlu; +char group_name[8 ]; +char reserved2[32 ]; +} __attribute__ ((packed));
Same here.
fs/hypfs/hypfs_diag.c
Quoted 2 lines
fs/hypfs/hypfs_diag.c +2
-0+ +static inline int part_hdr__size (diag204_info_t type)
Please drop the extra underscore from function name.
Quoted 1 line
+static inline
__u8part_hdr__cpus(diag204_info_t type, void *hdr)
Ditto. Appears in various other places as well.
Quoted 18 lines
fs/hypfs/hypfs_diag.c +18
-0+struct cpu_info { +__u16 cpu_addr; +char reserved1[2 ]; +__u8 ctidx; +__u8 cflag; +__u16 weight; +__u64 acc_time; +__u64 lp_time; +} __attribute__ ((packed)); + +struct x_cpu_info { +__u16 cpu_addr; +char reserved1[2 ]; +__u8 ctidx; +__u8 cflag; +__u16 weight; +__u64 acc_time; +__u64 lp_time;
fs/hypfs/hypfs_diag.c line 185
Quoted 10 lines
fs/hypfs/hypfs_diag.c +10
-0+__u16 min_weight; +__u16 cur_weight; +__u16 max_weight; +char reseved2[2 ]; +__u64 online_time; +__u64 wait_time; +__u32 pma_weight; +__u32 polar_weight; +char reserved3[40 ]; +} __attribute__ ((packed));
Endianess annotated types?
Quoted 6 lines
fs/hypfs/hypfs_diag.c +6
-0+/* Physical header */ + +struct phys_hdr { +char reserved1[1 ]; +__u8 cpus; +char reserved2[6 ];
fs/hypfs/hypfs_diag.c line 252
Quoted 10 lines
fs/hypfs/hypfs_diag.c +10
-0+char mgm_name[8 ]; +} __attribute__ ((packed)); + +struct x_phys_hdr { +char reserved1[1 ]; +__u8 cpus; +char reserved2[6 ]; +char mgm_name[8 ]; +char reserved3[80 ]; +} __attribute__ ((packed));
Here.
Quoted 9 lines
fs/hypfs/hypfs_diag.c +9
-0+/* Physical CPU info block */ + +struct phys_cpu { +__u16 cpu_addr; +char reserved1[2 ]; +__u8 ctidx; +char reserved2[3 ]; +__u64 mgm_time; +char reserved3[8 ];
fs/hypfs/hypfs_diag.c line 288
Quoted 10 lines
fs/hypfs/hypfs_diag.c +10
-0+} __attribute__ ((packed)); + +struct x_phys_cpu { +__u16 cpu_addr; +char reserved1[2 ]; +__u8 ctidx; +char reserved2[3 ]; +__u64 mgm_time; +char reserved3[80 ]; +} __attribute__ ((packed));
Here.
Quoted 7 lines
fs/hypfs/hypfs_diag.c +7
-0+static inline int diag204 (unsigned long subcode,unsigned long size,void *addr) +{ + register unsigned long _subcode asm("0") = subcode; + register unsigned long _size asm("1") = size; + + asmvolatile (" diag %2,%0,0x204\n" + "0: \n" ".section __ex_table,\"a\"\n"
fs/hypfs/hypfs_diag.c line 340
Quoted 10 lines
fs/hypfs/hypfs_diag.c +10
-0+#ifndef __s390x__ +" .align 4\n" + " .long 0b,0b\n" +#else +" .align 8\n" + " .quad 0b,0b\n" +#endif + ".previous":"+d" (_subcode), "+d"(_size) + :"d"(addr) + :"memory");
Please note that the above is a big clue for this fs to go into arch/s390/.
fs/hypfs/hypfs_diag.c line 371
Quoted 8 lines
fs/hypfs/hypfs_diag.c +8
-0+static int diag204_probe (void ) +{ +void *buf; +int pages, rc; + + pages =diag204 (SUBC_RSI |INFO_EXT ,0 ,0 ); +if (pages >0 ) { +if (!(buf =kmalloc (pages *PAGE_SIZE ,GFP_KERNEL ))) {
Please move the assignment out of the if expression for readability.
Quoted 6 lines
fs/hypfs/hypfs_diag.c +6
-0+ rc = -ENOMEM ; + goto err_out; + } +if (diag204 (SUBC_STIB7 |INFO_EXT , pages, buf) >=0 ) { + diag204_store_sc =SUBC_STIB7 ; + diag204_info_type =INFO_EXT ;
fs/hypfs/hypfs_diag.c line 387
Quoted 10 lines
fs/hypfs/hypfs_diag.c +10
-0+ 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); + } +if (!(buf =kmalloc (PAGE_SIZE ,GFP_KERNEL ))) {
Same here.
Quoted 7 lines
fs/hypfs/hypfs_diag.c +7
-0+ 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;
fs/hypfs/hypfs_diag.c line 404
Quoted 10 lines
fs/hypfs/hypfs_diag.c +10
-0+ }else { + rc = -ENOSYS ; + goto err_out; + } + out: +kfree (buf); +return 0 ; + err_out: +kfree (buf); +return rc;
Please drop the duplicate error path.
Quoted 4 lines
fs/hypfs/hypfs_diag.c +4
-0+static void *diag204_store (void ) +{ +void *buf; +int pages;
fs/hypfs/hypfs_diag.c line 420
Quoted 10 lines
fs/hypfs/hypfs_diag.c +10
-0+ +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 ); + +if (!(buf =kmalloc (pages *PAGE_SIZE ,GFP_KERNEL )))
And here.
fs/hypfs/inode.c
Quoted 5 lines
diff -urpN
linux-2.6.16/fs/hypfs/inode.clinux-2.6.16-hypfs/fs/hypfs/inode.cfs/hypfs/inode.c +1
-0+static DECLARE_MUTEX (hypfs_lock);// XXX DEFINE_MUTEX in 2.6.16 !
Yes, please!
Quoted 4 lines
fs/hypfs/inode.c +4
-0+ +/* start of list of all dentries, which have to be deleted on update */ +static struct dentry *hypfs_last_dentry; +
fs/hypfs/inode.c line 56
Quoted 10 lines
fs/hypfs/inode.c +10
-0+static void hypfs_update_update (void ) +{ + last_update_time =get_seconds (); +snprintf ((char *)update_file_dentry->d_inode->u.generic_ip, +UPDATE_DATA_SIZE ,"%ld\n" , last_update_time); + update_file_dentry->d_inode->i_size = +strlen ((char *)update_file_dentry->d_inode->u.generic_ip); + update_file_dentry->d_inode->i_atime = + update_file_dentry->d_inode->i_mtime = + update_file_dentry->d_inode->i_ctime =CURRENT_TIME ;
Please introduce local variable for update_file_dentry->d_inode for readability. Perhaps for generic_ip as well.
Quoted 25 lines
fs/hypfs/inode.c +25
-0+} + +/* directory tree removal functions */ + +static void hypfs_add_dentry (struct dentry *dentry) +{ + dentry->d_fsdata = hypfs_last_dentry; + hypfs_last_dentry = dentry; +} + +static void hypfs_delete_tree (struct dentry *root) +{ +while (hypfs_last_dentry) { +struct dentry *parent, *next_dentry; + + parent = hypfs_last_dentry->d_parent; +if (S_ISDIR (hypfs_last_dentry->d_inode->i_mode)) +simple_rmdir (parent->d_inode, hypfs_last_dentry); +else +simple_unlink (parent->d_inode, hypfs_last_dentry); +d_delete (hypfs_last_dentry); + next_dentry = hypfs_last_dentry->d_fsdata; +dput (hypfs_last_dentry); + hypfs_last_dentry = next_dentry; + }
fs/hypfs/inode.c line 91
Quoted 10 lines
fs/hypfs/inode.c +10
-0+} + +static struct inode *hypfs_make_inode (struct super_block *sb,int mode) +{ +struct inode *ret =new_inode (sb); + +if (ret) { + ret->i_mode = mode; + ret->i_uid = ((struct hypfs_sb_info *)sb->s_fs_info)->uid; + ret->i_gid = ((struct hypfs_sb_info *)sb->s_fs_info)->gid;
Reduce casting by introducing a local variable for hypfs_sb_info.
Quoted 4 lines
fs/hypfs/inode.c +4
-0+ ret->i_blksize =PAGE_CACHE_SIZE ; + ret->i_blocks =0 ; + ret->i_atime = ret->i_mtime = ret->i_ctime =CURRENT_TIME ; +if (mode &S_IFDIR )
fs/hypfs/inode.c line 105
Quoted 10 lines
fs/hypfs/inode.c +10
-0+ ret->i_nlink =2 ; + else + ret->i_nlink = 1; + } +return ret; +} + +static void hypfs_drop_inode (struct inode *inode) +{ +kfree ((void *)inode->u.generic_ip);
Please drop the redundant cast. Consider moving this to inode_ops->clear_inode.
Quoted 17 lines
fs/hypfs/inode.c +16
-0+generic_delete_inode (inode); +} +static int hypfs_parse_options (char *options) +{ +char *str; +substring_t args[MAX_OPT_ARGS ]; + +if (!options) +return 0 ; +while ((str =strsep (&options,"," )) !=NULL ) { +int token, option; +if (!*str) +continue ; + token =match_token (str, hypfs_tokens, args); +switch (token) { +case opt_uid:
fs/hypfs/inode.c line 213
Quoted 10 lines
fs/hypfs/inode.c +10
-0+if (match_int (&args[0 ], &option)) +return -EINVAL ; + ((struct hypfs_sb_info *)hypfs_sblk->s_fs_info)->uid + = option; +break ; +case opt_gid: +if (match_int (&args[0 ], &option)) +return -EINVAL ; + ((struct hypfs_sb_info *)hypfs_sblk->s_fs_info)->gid + = option;
Please reduce casting by introducing a local variable for hypfs_sb_info.
Quoted 40 lines
fs/hypfs/inode.c +40
-0+static int hypfs_fill_super (struct super_block *sb,void *data,int silent) +{ +struct inode *root_inode; +int rc =0 ; +struct hypfs_sb_info *sbi; + + sbi =kmalloc (sizeof (struct hypfs_sb_info ),GFP_KERNEL ); +if (!sbi) +return -ENOMEM ; + sbi->uid = current->uid; + sbi->gid = current->gid; + sb->s_fs_info = sbi; + sb->s_blocksize =PAGE_CACHE_SIZE ; + sb->s_blocksize_bits =PAGE_CACHE_SHIFT ; + sb->s_magic =HYPFS_MAGIC ; + sb->s_op = &hypfs_s_ops; +if (hypfs_parse_options (data)) { + rc = -EINVAL ; + goto err_alloc; + } + root_inode =hypfs_make_inode (sb,S_IFDIR |0755 ); +if (!root_inode) { + rc = -ENOMEM ; + goto err_alloc; + } + root_inode->i_op = &simple_dir_inode_operations; + root_inode->i_fop = &simple_dir_operations; + sb->s_root =d_alloc_root (root_inode); +if (!sb->s_root) { + rc = -ENOMEM ; + goto err_inode; + } + hypfs_sblk = sb; + rc =diag_create_files (hypfs_sblk, hypfs_sblk->s_root); +if (rc) + goto err_tree; + update_file_dentry =hypfs_create_update_file (hypfs_sblk, + hypfs_sblk->s_root); +if (IS_ERR (update_file_dentry)) { + rc =PTR_ERR (update_file_dentry);
fs/hypfs/inode.c line 274
Quoted 10 lines
fs/hypfs/inode.c +10
-0+ goto err_tree; + } +hypfs_update_update (); +return 0 ; + + err_tree: +hypfs_delete_tree (hypfs_sblk->s_root); +dput (hypfs_sblk->s_root); + err_inode: +hypfs_drop_inode (root_inode);
You should use iput() here.
fs/hypfs/inode.c line 281
Quoted 7 lines
fs/hypfs/inode.c +7
-0+ err_alloc: +kfree (sbi); +return rc; +} +static void hypfs_kill_super (struct super_block *sb) +{ +kfree (sb->s_fs_info);
Please use super_operations->put_super instead for freeing s_fs_info.
fs/hypfs/inode.c line 428
Quoted 6 lines
fs/hypfs/inode.c +5
-0+kill_litter_super (sb); +/* +* init and exit +* ************* +*/
Consider dropping the above useless comment.
Quoted 14 lines
fs/hypfs/inode.c +14
-0+ +static decl_subsys(hypervisor, NULL, NULL); + +static int __init hypfs_init (void ) +{ +int rc; + +if (MACHINE_IS_VM ) { +return -ENODATA ; + } +if (diag_init ()) { +printk (KERN_ERR "hypfs: diag init failed.\n" ); +return -ENODATA ; + }
fs/hypfs/inode.c line 452
Quoted 10 lines
fs/hypfs/inode.c +10
-0+ rc =subsystem_register (&hypervisor_subsys); +if (rc) { +diag_exit (); +return rc; + } + rc =register_filesystem (&hypfs_type); +if (rc) { +subsystem_unregister (&hypervisor_subsys); +diag_exit (); +return rc;
Please use gotos for error handling here to reduce duplication.
Hi Pekka,
Quoted 1 line
I have included some review comments below.
First of all thank you very much for the code review! You suggestions sound reasonable! I will post an updated patch on Monday!
[snip]
Quoted 4 lines
Quoted 4 lines
fs/hypfs/hypfs_diag.c +4
-0+struct x_info_blk_hdr { +__u8 npar; +__u8 flags; +__u16 tslice;
Quoted 9 lines
fs/hypfs/hypfs_diag.c line 67
Quoted 6 lines
fs/hypfs/hypfs_diag.c +6
-0+__u16 phys_cpus; +__u16 this_part; +__u64 curtod1; +__u64 curtod2; +char reserved[40 ]; +} __attribute__ ((packed));Couldn't you use endianess annotated types for these?
What are "endianess annotated types" ?
Michael
Quoted 13 lines · Michael Holzheu
Quoted 4 lines
Quoted 4 lines
fs/hypfs/hypfs_diag.c +4
-0+struct x_info_blk_hdr { +__u8 npar; +__u8 flags; +__u16 tslice;Quoted 8 lines
fs/hypfs/hypfs_diag.c line 67
Quoted 6 lines
fs/hypfs/hypfs_diag.c +6
-0+__u16 phys_cpus; +__u16 this_part; +__u64 curtod1; +__u64 curtod2; +char reserved[40 ]; +} __attribute__ ((packed));Couldn't you use endianess annotated types for these?
Quoted 1 line
What are "endianess annotated types" ?
For example, __le16 and __be16 (search for __bitwise in <linux/types.h>). You can use sparse to check for endianess erros in your code if you us them.
Pekka
Quoted 17 lines · Pekka Enberg
fs/hypfs/hypfs.h line 39
Quoted 13 lines · Michael Holzheu
diff -urpN
linux-2.6.16/fs/hypfs/hypfs.hlinux-2.6.16-hypfs/fs/hypfs/hypfs.hfs/hypfs/hypfs.h +10
-0+static void inline remove_trailing_blanks (char *string) +{ +char *ptr; +for (ptr = string +strlen (string) -1 ; ptr > string; ptr--) { +if (*ptr ==' ' ) + *ptr =0 ; +else +break ; + } +}Please consider moving this to
lib/string.cand perhaps renaming it tostrstrip().
If you do that, could you strip all whitespace? I have a special function to kill a single newline, if present. Looks to me like those two could be combined.
Jörn
Signature · 3 lines
The wise man seeks everything in himself; the ignorant man tries to get everything from somebody else. -- unknown
Hi Jörn
Jörn Engel <[email protected]> wrote on 04/21/2006 05:18:00 PM:
Quoted 5 lines · Pekka Enberg
Quoted 2 lines · Michael Holzheu
Quoted 1 line
diff -urpN
linux-2.6.16/fs/hypfs/hypfs.hlinux-2.6.16-
hypfs/fs/hypfs/hypfs.hQuoted 1 line
Quoted 1 line
---
linux-2.6.16/fs/hypfs/hypfs.h1970-01-01 01:00:00.000000000
+0100
Quoted 16 lines
Quoted 1 line
Quoted 1 line
+++
linux-2.6.16-hypfs/fs/hypfs/hypfs.h2006-04-21 12:56:58.000000000 +0200
Quoted 5 lines
Quoted 5 lines
fs/hypfs/hypfs.h +5
-0+static void inline remove_trailing_blanks (char *string) +{ +char *ptr; +for (ptr = string +strlen (string) -1 ; ptr > string; ptr--) { +if (*ptr ==' ' )Quoted 8 lines
fs/hypfs/hypfs.h line 39
Quoted 5 lines
fs/hypfs/hypfs.h +5
-0+ *ptr =0 ; + else + break; + } +}Please consider moving this to
lib/string.cand perhaps renaming it tostrstrip().
Quoted 3 lines
If you do that, could you strip all whitespace? I have a special function to kill a single newline, if present. Looks to me like those two could be combined.
That would be ok for us, since we do not have any newlines in our strings. I will include this in the next patch!
Michael
Quoted 3 lines · Michael Holzheu
That would be ok for us, since we do not have any newlines in our strings. I will include this in the next patch!
Thanks!
It would be nice to seperate this patch out from the rest. It is useful independently of when and whether hypfs gets merged.
Jörn
Signature · 4 lines
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
Hi Pekka,
Quoted 17 lines · Pekka Enberg
fs/hypfs/hypfs.h
Quoted 13 lines · Michael Holzheu
diff -urpN
linux-2.6.16/fs/hypfs/hypfs.hlinux-2.6.16-hypfs/fs/hypfs/hypfs.hfs/hypfs/hypfs.h +10
-0+static void inline remove_trailing_blanks (char *string) +{ +char *ptr; +for (ptr = string +strlen (string) -1 ; ptr > string; ptr--) { +if (*ptr ==' ' ) + *ptr =0 ; +else +break ; + } +}Please consider moving this to
lib/string.cand perhaps renaming it tostrstrip().
Nearly.
- Just return the *ptr and let the caller modify the string.
- Take a string with characters to reject
Reasons:
- string might be read only
- caller wants to copy it anyway
- string might be a substring or sth. we like to parse further
- Symmetry with strchr()
Otherwise it is a very good idea implemented in a patch similiar to this untested one below against Linus' current tree.
use case would be:
char *s = strltrim(string, " \t");
char *e = strrtrim(s, " \t\n\r");
*e = '\0';
Regards
Ingo Oeser
----
include/linux/string.h +6 -0
@@ -68,6 +68,12 @@ extern __kernel_size_t strnlen(const cha#ifndef __HAVE_ARCH_STRPBRKextern char *strpbrk (const char *,const char *);#endif +#ifndef __HAVE_ARCH_STRLTRIM +extern char *strltrim (const char *,const char *); +#endif +#ifndef __HAVE_ARCH_STRRTRIM +extern char *strrtrim (const char *,const char *); +#endif #ifndef __HAVE_ARCH_STRSEPextern char *strsep (char **,const char *);#endif
lib/string.c +49 -0
55 lines not on this page · raw message
Hi Ingo,
Ingo Oeser <[email protected]> wrote on 04/22/2006 12:30:28 AM:
Quoted 12 lines
Nearly.
- Just return the *ptr and let the caller modify the string.
- Take a string with characters to rejectReasons:
- string might be read only
- caller wants to copy it anyway
- string might be a substring or sth. we like to parse further
- Symmetry withstrchr()
Quoted 7 lines
Otherwise it is a very good idea implemented in a patch similiar to this untested one below against Linus' current tree.
use case would be:
char *s =strltrim(string, " \t");
char *e =strrtrim(s, " \t\n\r");
*e = '\0';
I agree that it is a good idea to specify the characters to reject, but I would like to use the function without having an additional local pointer variable. In my opinion this functionality is enough for most cases.
What about something like that:
/**
* strrtrim - Remove trailing characters specified in @reject
* @s: The string to be searched
* @reject: The string of letters to avoid
*/
static inline void strrtrim(char *s, const char *reject)
{
char *p;
const char *r;
for (p = s + strlen(s) - 1; s <= p; p--) {
for (r = reject; (*r != '\0') && (*p != *r); r++)
/* nothing */;
if (*r == '\0')
break;
}
*(p + 1) = '\0';
}Regards
Michael
Hi Michael,
Quoted 4 lines · you
I agree that it is a good idea to specify the characters to reject, but I would like to use the function without having an additional local pointer variable. In my opinion this functionality is enough for most cases.
AFAIK there is no Standard for this kind of functions.
Yes, it might be ok, if you like to destroy the string. But I prefer non-destructive string handling :-)
Might be a matter of taste. So go wild, if nobody else objects.
Regards
Ingo Oeser
Quoted 8 lines · Michael Holzheu
What about something like that:
/**
* strrtrim - Remove trailing characters specified in @reject
* @s: The string to be searched
* @reject: The string of letters to avoid
*/
static inline voidstrrtrim(char *s, const char *reject)
Better to make it out-of-line to save kernel text.
Quoted 16 lines
{ char *p; const char *r; for (p = s + strlen(s) - 1; s <= p; p--) { for (r = reject; (*r != '\0') && (*p != *r); r++) /* nothing */; if (*r == '\0') break; } *(p + 1) = '\0'; }Regards
Michael
Hi Pekka, Hi Ingo,
I included your comments in my new patch
(which comes with the next posting):
[email protected] wrote on 04/21/2006 04:42:28 PM:
Quoted 4 lines
I have included some review comments below.
Quoted 1 line · Michael Holzheu
diff -urpN
linux-2.6.16/fs/hypfs/hypfs.h
linux-2.6.16-hypfs/fs/hypfs/hypfs.h
Quoted 16 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58.
Quoted 2 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +0
-0000000000 +0200
fs/hypfs/hypfs.h 2006-04-21 12:56:58.
Quoted 10 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +10
-0+static void inline remove_trailing_blanks(char *string) +{ + char *ptr; + for (ptr = string + strlen(string) - 1; ptr > string; ptr--) { + if (*ptr == ' ') + *ptr = 0; + else + break; + } +}Please consider moving this to
lib/string.cand perhaps renaming it tostrstrip().
I Implemented a strrtrim() function in string.c
Quoted 3 lines
Quoted 1 line
diff -urpN
linux-2.6.16/fs/hypfs/hypfs_diag.clinux-2.6.16-
hypfs/fs/hypfs/hypfs_diag.cQuoted 1 line
---
linux-2.6.16/fs/hypfs/hypfs_diag.c1970-01-01 01:00:00.000000000
+0100
Quoted 17 lines
Quoted 1 line
+++
linux-2.6.16-hypfs/fs/hypfs/hypfs_diag.c2006-04-21 12:56:58.000000000 +0200
fs/hypfs/hypfs.h 2006-04-21 12:56:58.
Quoted 13 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +13
-0+/* diag 204 subcodes */ +typedef enum { + SUBC_STIB4 = 4, + SUBC_RSI = 5, + SUBC_STIB6 = 6, + SUBC_STIB7 = 7 +} diag204_subc_t; + +/* The two available diag 204 data formats */ +typedef enum { + INFO_SIMPLE = 0, + INFO_EXT = 0x00010000 +} diag204_info_t;Please kill the typedefs.
Done.
Quoted 15 lines
Quoted 15 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +15
-0+/* Time information block */ + +struct info_blk_hdr { + __u8 npar; + __u8 flags; + __u16 tslice; + __u16 phys_cpus; + __u16 this_part; + __u64 curtod; +} __attribute__ ((packed)); + +struct x_info_blk_hdr { + __u8 npar; + __u8 flags; + __u16 tslice;
Quoted 8 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58.
Quoted 6 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +6
-0+ __u16 phys_cpus; + __u16 this_part; + __u64 curtod1; + __u64 curtod2; + char reserved[40]; +} __attribute__ ((packed));Couldn't you use endianess annotated types for these?
Since we have a s390 only implementation, I think this is not necessary.
Quoted 3 lines
Quoted 1 line
+static inline
__u8part_hdr__cpus(diag204_info_t type, void *hdr)Ditto. Appears in various other places as well.
I used the extra underscore for the "getter" functions to separate the member part from the rest of the function name. E.g. "part_hdr" is the structure name and "cpus" is the member name. I really would like to keep that.
Quoted 12 lines
Quoted 1 line
+static inline int diag204(unsigned long subcode, unsigned long
size, void *addr)
Quoted 10 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +10
-0+{ + register unsigned long _subcode asm("0") = subcode; + register unsigned long _size asm("1") = size; + + asm volatile (" diag %2,%0,0x204\n" + "0: \n" ".section __ex_table,\"a\"\n" +#ifndef __s390x__ + " .align 4\n" + " .long 0b,0b\n" +#else
Quoted 8 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58.
Quoted 6 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +6
-0+ " .align 8\n" + " .quad 0b,0b\n" +#endif + ".previous":"+d" (_subcode), "+d"(_size) + :"d"(addr) + :"memory");Please note that the above is a big clue for this fs to go into
arch/s390/.
Right! I moved the code to arch/s390/hypfs.
Quoted 11 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58.
Quoted 9 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +8
-0+static int diag204_probe(void) +{ + void *buf; + int pages, rc; + + pages = diag204(SUBC_RSI | INFO_EXT, 0, 0); + if (pages > 0) { + if (!(buf = kmalloc(pages * PAGE_SIZE, GFP_KERNEL))) {Please move the assignment out of the if expression for readability.
Done.
Quoted 17 lines
Quoted 6 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +6
-0+ rc = -ENOMEM; + goto err_out; + } + if (diag204(SUBC_STIB7 | INFO_EXT, pages, buf) >= 0) { + diag204_store_sc = SUBC_STIB7; + diag204_info_type = INFO_EXT;fs/hypfs/hypfs.h 2006-04-21 12:56:58.
Quoted 10 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +10
-0+ 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); + } + if (!(buf = kmalloc(PAGE_SIZE, GFP_KERNEL))) {
Quoted 1 line
Same here.
Done.
Quoted 18 lines
Quoted 7 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +7
-0+ 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;fs/hypfs/hypfs.h 2006-04-21 12:56:58.
Quoted 10 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +10
-0+ } else { + rc = -ENOSYS; + goto err_out; + } + out: + kfree(buf); + return 0; + err_out: + kfree(buf); + return rc;
Quoted 1 line
Please drop the duplicate error path.
Done. I use now "rc = 0" for the good path.
Quoted 8 lines
Quoted 8 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +8
-0+static void *diag204_store(void) +{ + void *buf; + int pages; + + if (diag204_store_sc == SUBC_STIB4) + pages = 1; + else
Quoted 8 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58.
Quoted 6 lines
fs/hypfs/hypfs.h 2006-04-21 12:56:58. renamed from fs/hypfs/hypfs.h 1970-01-01 01:00:00.000000000 +0100 +6
-0+ pages = diag204(SUBC_RSI | diag204_info_type, 0, 0); + + if (pages < 0) + return ERR_PTR(-ENOSYS); + + if (!(buf = kmalloc(pages * PAGE_SIZE, GFP_KERNEL)))And here.
Done.
Quoted 1 line
Quoted 1 line
diff -urpN
linux-2.6.16/fs/hypfs/inode.c
linux-2.6.16-hypfs/fs/hypfs/inode.c
Quoted 7 lines
fs/hypfs/inode.c 2006-04-21 12:56:58.
Quoted 2 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +0
-0000000000 +0200
Quoted 1 line
+static
DECLARE_MUTEX(hypfs_lock); // XXXDEFINE_MUTEXin 2.6.16 !Yes, please!
Done.
Quoted 2 lines
fs/hypfs/inode.c 2006-04-21 12:56:58.
Quoted 2 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +2
-0+ +/* start of list of all dentries, which have to be deleted on update
*/
Quoted 7 lines
Quoted 7 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +7
-0+static struct dentry *hypfs_last_dentry; + +static void hypfs_update_update(void) +{ + last_update_time = get_seconds(); + snprintf((char *)update_file_dentry->d_inode->u.generic_ip, + UPDATE_DATA_SIZE, "%ld\n", last_update_time);
Quoted 8 lines
fs/hypfs/inode.c 2006-04-21 12:56:58.
Quoted 5 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +5
-0+ update_file_dentry->d_inode->i_size = + strlen((char *)update_file_dentry->d_inode->u.generic_ip); + update_file_dentry->d_inode->i_atime = + update_file_dentry->d_inode->i_mtime = + update_file_dentry->d_inode->i_ctime = CURRENT_TIME;Please introduce local variable for
update_file_dentry->d_inodefor readability. Perhaps forgeneric_ipas well.
Done. Much better now!
Quoted 20 lines
Quoted 20 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +20
-0+} + +/* directory tree removal functions */ + +static void hypfs_add_dentry(struct dentry *dentry) +{ + dentry->d_fsdata = hypfs_last_dentry; + hypfs_last_dentry = dentry; +} + +static void hypfs_delete_tree(struct dentry *root) +{ + while (hypfs_last_dentry) { + struct dentry *parent, *next_dentry; + + parent = hypfs_last_dentry->d_parent; + if (S_ISDIR(hypfs_last_dentry->d_inode->i_mode)) + simple_rmdir(parent->d_inode, hypfs_last_dentry); + else + simple_unlink(parent->d_inode, hypfs_last_dentry);
Quoted 8 lines
fs/hypfs/inode.c 2006-04-21 12:56:58.
Quoted 8 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +8
-0+ d_delete(hypfs_last_dentry); + next_dentry = hypfs_last_dentry->d_fsdata; + dput(hypfs_last_dentry); + hypfs_last_dentry = next_dentry; + } +} + +static struct inode *hypfs_make_inode(struct super_block *sb, int
mode)
Quoted 9 lines
fs/hypfs/inode.c 2006-04-21 12:56:58.
Quoted 7 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +7
-0+{ + struct inode *ret = new_inode(sb); + + if (ret) { + ret->i_mode = mode; + ret->i_uid = ((struct hypfs_sb_info *)sb->s_fs_info)->uid; + ret->i_gid = ((struct hypfs_sb_info *)sb->s_fs_info)->gid;Reduce casting by introducing a local variable for
hypfs_sb_info.
Done.
Quoted 9 lines
Quoted 9 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +9
-0+ ret->i_blksize = PAGE_CACHE_SIZE; + ret->i_blocks = 0; + ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME; + if (mode & S_IFDIR) + ret->i_nlink = 2; + else + ret->i_nlink = 1; + } + return ret;
Quoted 8 lines
fs/hypfs/inode.c 2006-04-21 12:56:58.
Quoted 5 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +5
-0+} + +static void hypfs_drop_inode(struct inode *inode) +{ + kfree((void *)inode->u.generic_ip);Please drop the redundant cast. Consider moving this to
inode_ops->clear_inode.
I removed the cast, but I keep the code in drop_inode() until someone tells me that this terribly wrong.
Quoted 18 lines
Quoted 18 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +18
-0+static int hypfs_parse_options(char *options) +{ + char *str; + substring_t args[MAX_OPT_ARGS]; + + if (!options) + return 0; + while ((str = strsep(&options, ",")) != NULL) { + int token, option; + if (!*str) + continue; + token = match_token(str, hypfs_tokens, args); + switch (token) { + case opt_uid: + if (match_int(&args[0], &option)) + return -EINVAL; + ((struct hypfs_sb_info *)hypfs_sblk->s_fs_info)->uid + = option;
Quoted 8 lines
fs/hypfs/inode.c 2006-04-21 12:56:58.
Quoted 6 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +6
-0+ break; + case opt_gid: + if (match_int(&args[0], &option)) + return -EINVAL; + ((struct hypfs_sb_info *)hypfs_sblk->s_fs_info)->gid + = option;Please reduce casting by introducing a local variable for
hypfs_sb_info.
Done.
Quoted 1 line
Quoted 1 line
+static int hypfs_fill_super(struct
super_block*sb, void *data, int
silent)
Quoted 43 lines
Quoted 43 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +43
-0+{ + struct inode *root_inode; + int rc = 0; + struct hypfs_sb_info *sbi; + + sbi = kmalloc(sizeof(struct hypfs_sb_info), GFP_KERNEL); + if (!sbi) + return -ENOMEM; + sbi->uid = current->uid; + sbi->gid = current->gid; + sb->s_fs_info = sbi; + sb->s_blocksize = PAGE_CACHE_SIZE; + sb->s_blocksize_bits = PAGE_CACHE_SHIFT; + sb->s_magic = HYPFS_MAGIC; + sb->s_op = &hypfs_s_ops; + if (hypfs_parse_options(data)) { + rc = -EINVAL; + goto err_alloc; + } + root_inode = hypfs_make_inode(sb, S_IFDIR | 0755); + if (!root_inode) { + rc = -ENOMEM; + goto err_alloc; + } + root_inode->i_op = &simple_dir_inode_operations; + root_inode->i_fop = &simple_dir_operations; + sb->s_root = d_alloc_root(root_inode); + if (!sb->s_root) { + rc = -ENOMEM; + goto err_inode; + } + hypfs_sblk = sb; + rc = diag_create_files(hypfs_sblk, hypfs_sblk->s_root); + if (rc) + goto err_tree; + update_file_dentry = hypfs_create_update_file(hypfs_sblk, + hypfs_sblk->s_root); + if (IS_ERR(update_file_dentry)) { + rc = PTR_ERR(update_file_dentry); + goto err_tree; + } + hypfs_update_update(); + return 0;
Quoted 8 lines
fs/hypfs/inode.c 2006-04-21 12:56:58.
Quoted 6 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +6
-0+ + err_tree: + hypfs_delete_tree(hypfs_sblk->s_root); + dput(hypfs_sblk->s_root); + err_inode: + hypfs_drop_inode(root_inode);You should use
iput()here.
Done.
Quoted 9 lines
fs/hypfs/inode.c 2006-04-21 12:56:58.
Quoted 7 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +7
-0+ err_alloc: + kfree(sbi); + return rc; +} +static void hypfs_kill_super(struct super_block *sb) +{ + kfree(sb->s_fs_info);Please use
super_operations->put_superinstead for freeings_fs_info.
Done.
Quoted 6 lines
Quoted 4 lines
+/*
+ * init and exit
+ * *************
+ */Consider dropping the above useless comment.
Done.
Quoted 18 lines
Quoted 18 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +18
-0+ +static decl_subsys(hypervisor, NULL, NULL); + +static int __init hypfs_init(void) +{ + int rc; + + if (MACHINE_IS_VM) { + return -ENODATA; + } + if (diag_init()) { + printk(KERN_ERR "hypfs: diag init failed.\n"); + return -ENODATA; + } + rc = subsystem_register(&hypervisor_subsys); + if (rc) { + diag_exit(); + return rc;
Quoted 8 lines
fs/hypfs/inode.c 2006-04-21 12:56:58.
Quoted 6 lines
fs/hypfs/inode.c 2006-04-21 12:56:58. renamed from fs/hypfs/inode.c 1970-01-01 01:00:00.000000000 +0100 +6
-0+ } + rc = register_filesystem(&hypfs_type); + if (rc) { + subsystem_unregister(&hypervisor_subsys); + diag_exit(); + return rc;Please use gotos for error handling here to reduce duplication.
Done.