fsstack updates
Subsystems (2)
cover fsstack updates
These are some more updates to fsstack.
The first patch makes fsstack_copy_attr_all copy the inode size in addition to all the other attributes.
The second patch introduces generic structures and functions to get/set lower objects.
The third patch converts eCryptfs to use the generic structures and functions introduced by the second patch.
For those interested, I set up a git repo with all the fsstack related patches currently in mm and these three (they're still being mirrored):
git://git.kernel.org/pub/scm/linux/kernel/git/jsipek/fsstack-2.6.git for-2.6.20
Josef "Jeff" Sipek.
PATCH 1/3 fsstack: Make fsstack_copy_attr_all copy inode size
From: Josef "Jeff" Sipek <[email protected]>
fsstack_copy_attr_all should copy the inode size in addition to all the other attributes.
---
fs/stack.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
fs/stack.c +2 -0
@@ -33,5 +33,7 @@ void fsstack_copy_attr_all(struct inode dest->i_ctime = src->i_ctime; dest->i_blkbits = src->i_blkbits; dest->i_flags = src->i_flags; + +fsstack_copy_inode_size (dest, src); }EXPORT_SYMBOL_GPL (fsstack_copy_attr_all);
PATCH 2/3 fsstack: Generic get/set lower object functions
In reply to JosefJeff SipekFrom: Josef "Jeff" Sipek <[email protected]>
Every stackable filesystem needs to track what the corresponding lower objects are. The stackable fs superblock needs to maintain pointers to the lower superblock(s); the inodes need to maintain pointers to the lower inodes; dentries need to maintain pointers to the lower dentries and vfsmounts.
Currently, every stackable filesystem maintains this information in the private data of the object in question (the inode pointers may be also stored in the inode's container - which is what the following patch requires.)
This patch introduces generic structures to maintain the lower object references, and functions to get/set the lower object structure members. These functions are the generalized forms, which work with both linear and fanout stackable filesystem (eCryptfs and Unionfs to name some).
The patch is loosely based on Pekka Enberg's patches from October 13th
(http://lkml.org/lkml/2006/10/13/82).
---
include/linux/fs_stack.h | 264 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 264 insertions(+), 0 deletions(-)
include/linux/fs_stack.h +264 -0
@@ -5,8 +5,272 @@ #define _LINUX_FS_STACK_H* filesystems; none of these functions require i_mutex to be held. */ +#include <linux/namei.h> #include <linux/fs.h> +/* structs to maintain pointers to the lower VFS objects */ +struct fsstack_sb_info { +union { +struct super_block *sb; +struct super_block **sbs; + }; +}; + +struct fsstack_inode_info { +union { +struct inode *inode; +struct inode **inodes; + }; +}; + +struct fsstack_dentry_info { +union { +struct path path; +struct path *paths; + }; +}; + +struct fsstack_file_info { +union { +struct file *file; +struct file **files; + }; +}; + +/* DO NOT USE! +* +* The following structure is used during the container_of calls to allow +* for as generic as possible way of accessing fsstack_inode_info given a +* pointer to the inode. +*/ +struct __fsstack_inode_generic_info { +struct inode vfs_inode;/* vfs inode */ +struct fsstack_inode_info info;/* fsstack inode info */ +}; + +/* +* Functions to get lower objects from an upper one. +* +* NOTE: The filesystem specific info structures (for dentries, superblocks +* and files) _must_ have the following layout: +* +* struct foo { +* struct fsstack_{dentry,sb,file}_info info; +* ... +* }; +* +* Because of the usage of containers, the inode container structure _must_ +* have the following layout: +* +* struct bar { +* struct inode vfs_inode; +* struct fsstack_inode_info info; +* ... +* }; +*/ +static inline struct super_block * +__fsstack_lower_sb (struct super_block *sb,unsigned long branch_idx) +{ +struct fsstack_sb_info *info = sb->s_fs_info; +return info->sbs[branch_idx]; +} + +static inline struct super_block ** +__fsstack_lower_sbs (struct super_block *sb) +{ +struct fsstack_sb_info *info = sb->s_fs_info; +return info->sbs; +} + +static inline void +__fsstack_set_lower_sb (struct super_block *sb,unsigned long branch_idx, +struct super_block *lower_sb) +{ +struct fsstack_sb_info *info = sb->s_fs_info; + info->sbs[branch_idx] = lower_sb; +} + +static inline void +__fsstack_set_lower_sbs (struct super_block *sb,struct super_block **lower_sbs) +{ +struct fsstack_sb_info *info = sb->s_fs_info; + info->sbs = lower_sbs; +} + +static inline struct super_block *fsstack_lower_sb (struct super_block *sb) +{ +struct fsstack_sb_info *info = sb->s_fs_info; +return info->sb; +} + +static inline void +fsstack_set_lower_sb (struct super_block *sb,struct super_block *lower_sb) +{ +struct fsstack_sb_info *info = sb->s_fs_info; + info->sb = lower_sb; +} + +/* get the fs dependent data */ +static inline void *fsstack_inode_data (struct inode *inode) +{ +return &((struct __fsstack_inode_generic_info *) inode)->info; +} + +static inline struct inode * +__fsstack_lower_inode (struct inode *inode,unsigned long branch_idx) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); + +return info->inodes[branch_idx]; +} + +static inline struct inode ** +__fsstack_lower_inodes (struct inode *inode) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); +return info->inodes; +} + +static inline void +__fsstack_set_lower_inode (struct inode *inode,unsigned long branch_idx, +struct inode *lower_inode) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); + info->inodes[branch_idx] = lower_inode; +} + +static inline void +__fsstack_set_lower_inodes (struct inode *inode,struct inode **lower_inodes) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); + info->inodes = lower_inodes; +} + +static inline struct inode *fsstack_lower_inode (struct inode *inode) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); +return info->inode; +} + +static inline void +fsstack_set_lower_inode (struct inode *inode,struct inode *lower_inode) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); + info->inode = lower_inode; +} + +static inline struct dentry * +__fsstack_lower_dentry (struct dentry *dentry,unsigned long branch_idx) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; +return info->paths[branch_idx].dentry; +} + +static inline struct path * +__fsstack_lower_paths (struct dentry *dentry) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; +return info->paths; +} + +static inline void +__fsstack_set_lower_dentry (struct dentry *dentry,unsigned long branch_idx, +struct dentry *lower_dentry) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; + info->paths[branch_idx].dentry = lower_dentry; +} + +static inline void +__fsstack_set_lower_paths (struct dentry *dentry,struct path *lower_paths) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; + info->paths = lower_paths; +} + +static inline struct dentry *fsstack_lower_dentry (struct dentry *dentry) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; +return info->path.dentry; +} + +static inline void +fsstack_set_lower_dentry (struct dentry *dentry,struct dentry *lower_dentry) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; + info->path.dentry = lower_dentry; +} + +static inline struct vfsmount * +__fsstack_lower_mnt (struct dentry *dentry,unsigned long branch_idx) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; +return info->paths[branch_idx].mnt; +} + +static inline void +__fsstack_set_lower_mnt (struct dentry *dentry,unsigned long branch_idx, +struct vfsmount *lower_mnt) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; + info->paths[branch_idx].mnt = lower_mnt; +} + +static inline struct vfsmount *fsstack_lower_mnt (struct dentry *dentry) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; +return info->path.mnt; +} + +static inline void +fsstack_set_lower_mnt (struct dentry *dentry,struct vfsmount *lower_mnt) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; + info->path.mnt = lower_mnt; +} + +static inline struct file * +__fsstack_lower_file (struct file *file,unsigned long branch_idx) +{ +struct fsstack_file_info *info = file->private_data; +return info->files[branch_idx]; +} + +static inline struct file ** +__fsstack_lower_files (struct file *file) +{ +struct fsstack_file_info *info = file->private_data; +return info->files; +} + +static inline void +__fsstack_set_lower_file (struct file *file,unsigned long branch_idx, +struct file *lower_file) +{ +struct fsstack_file_info *info = file->private_data; + info->files[branch_idx] = lower_file; +} + +static inline void +__fsstack_set_lower_files (struct file *file,struct file **lower_files) +{ +struct fsstack_file_info *info = file->private_data; + info->files = lower_files; +} + +static inline struct file *fsstack_lower_file (struct file *file) +{ +struct fsstack_file_info *info = file->private_data; +return info->file; +} + +static inline void +fsstack_set_lower_file (struct file *file,struct file *lower_file) +{ +struct fsstack_file_info *info = file->private_data; + info->file = lower_file; +} +/* externs for fs/stack.c */ extern void fsstack_copy_attr_all (struct inode *dest,const struct inode *src,int (*get_nlinks)(struct inode *));
Re: [PATCH 2/3] fsstack: Generic get/set lower object functions
Quoted 41 lines · Josef Jeff Sipek
From: Josef "Jeff" Sipek <[email protected]>
Every stackable filesystem needs to track what the corresponding lower objects are. The stackable fs superblock needs to maintain pointers to the lower superblock(s); the inodes need to maintain pointers to the lower inodes; dentries need to maintain pointers to the lower dentries and vfsmounts.
Currently, every stackable filesystem maintains this information in the private data of the object in question (the inode pointers may be also stored in the inode's container - which is what the following patch requires.)
This patch introduces generic structures to maintain the lower object references, and functions to get/set the lower object structure members. These functions are the generalized forms, which work with both linear and fanout stackable filesystem (eCryptfs and Unionfs to name some).
The patch is loosely based on Pekka Enberg's patches from October 13th
(http://lkml.org/lkml/2006/10/13/82).Cc Pekka Enberg <[email protected]>Cc Michael Halcrow <[email protected]>Cc Erez Zadok <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Al Viro <[email protected]>Cc Andrew Morton <[email protected]>Signed-off-by Josef "Jeff" Sipek <[email protected]>---
include/linux/fs_stack.h | 264 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 264 insertions(+), 0 deletions(-)include/linux/fs_stack.h +0
-0@@ -5,8 +5,272 @@ #define _LINUX_FS_STACK_H* filesystems; none of these functions require i_mutex to be held. */
include/linux/fs_stack.h #define _LINUX_FS_STACK_H · line 17
Quoted 10 lines
include/linux/fs_stack.h +8
-0+#include <linux/namei.h> #include <linux/fs.h> +/* structs to maintain pointers to the lower VFS objects */ +struct fsstack_sb_info { +union { +struct super_block *sb; +struct super_block **sbs; + }; +};
Why are you defining all these structs that are just wrapping unions?
Quoted 89 lines
include/linux/fs_stack.h +89
-0+ +struct fsstack_inode_info { +union { +struct inode *inode; +struct inode **inodes; + }; +}; + +struct fsstack_dentry_info { +union { +struct path path; +struct path *paths; + }; +}; + +struct fsstack_file_info { +union { +struct file *file; +struct file **files; + }; +}; + +/* DO NOT USE! +* +* The following structure is used during the container_of calls to allow +* for as generic as possible way of accessing fsstack_inode_info given a +* pointer to the inode. +*/ +struct __fsstack_inode_generic_info { +struct inode vfs_inode;/* vfs inode */ +struct fsstack_inode_info info;/* fsstack inode info */ +}; + +/* +* Functions to get lower objects from an upper one. +* +* NOTE: The filesystem specific info structures (for dentries, superblocks +* and files) _must_ have the following layout: +* +* struct foo { +* struct fsstack_{dentry,sb,file}_info info; +* ... +* }; +* +* Because of the usage of containers, the inode container structure _must_ +* have the following layout: +* +* struct bar { +* struct inode vfs_inode; +* struct fsstack_inode_info info; +* ... +* }; +*/ +static inline struct super_block * +__fsstack_lower_sb (struct super_block *sb,unsigned long branch_idx) +{ +struct fsstack_sb_info *info = sb->s_fs_info; +return info->sbs[branch_idx]; +} + +static inline struct super_block ** +__fsstack_lower_sbs (struct super_block *sb) +{ +struct fsstack_sb_info *info = sb->s_fs_info; +return info->sbs; +} + +static inline void +__fsstack_set_lower_sb (struct super_block *sb,unsigned long branch_idx, +struct super_block *lower_sb) +{ +struct fsstack_sb_info *info = sb->s_fs_info; + info->sbs[branch_idx] = lower_sb; +} + +static inline void +__fsstack_set_lower_sbs (struct super_block *sb,struct super_block **lower_sbs) +{ +struct fsstack_sb_info *info = sb->s_fs_info; + info->sbs = lower_sbs; +} + +static inline struct super_block *fsstack_lower_sb (struct super_block *sb) +{ +struct fsstack_sb_info *info = sb->s_fs_info; +return info->sb; +} + +static inline void
include/linux/fs_stack.h #define _LINUX_FS_STACK_H · line 116
Quoted 10 lines
include/linux/fs_stack.h +10
-0+fsstack_set_lower_sb(struct super_block *sb, struct super_block *lower_sb) +{ + struct fsstack_sb_info *info = sb->s_fs_info; + info->sb = lower_sb; +} + +/* get the fs dependent data */ +static inline void *fsstack_inode_data (struct inode *inode) +{ +return &((struct __fsstack_inode_generic_info *) inode)->info;
Please make this wrap container_of() instead of rolling your own. Also note that the naming convention for such a wrapper in almost all other filesystems would be FSSTACK_I()
include/linux/fs_stack.h #define _LINUX_FS_STACK_H · line 125
Quoted 9 lines
include/linux/fs_stack.h +9
-0+} + +static inline struct inode * +__fsstack_lower_inode (struct inode *inode,unsigned long branch_idx) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); + +return info->inodes[branch_idx]; +}
What is the value of "functions" like the above? They appear just to obfuscate the code. Unless your aim is to hide the internals of the struct __fsstack_inode_generic_info (sort of futile, since you are asking users to include that structure in their private inode structs) then it is much more obvious to see what is going on when you write
inode = FSSTACK_I(inode)->inodes[branch];
rather than
inode = __fsstack_lower_inode(inode, branch);
Quoted 156 lines
include/linux/fs_stack.h +148
-1+ +static inline struct inode ** +__fsstack_lower_inodes (struct inode *inode) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); +return info->inodes; +} + +static inline void +__fsstack_set_lower_inode (struct inode *inode,unsigned long branch_idx, +struct inode *lower_inode) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); + info->inodes[branch_idx] = lower_inode; +} + +static inline void +__fsstack_set_lower_inodes (struct inode *inode,struct inode **lower_inodes) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); + info->inodes = lower_inodes; +} + +static inline struct inode *fsstack_lower_inode (struct inode *inode) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); +return info->inode; +} + +static inline void +fsstack_set_lower_inode (struct inode *inode,struct inode *lower_inode) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); + info->inode = lower_inode; +} + +static inline struct dentry * +__fsstack_lower_dentry (struct dentry *dentry,unsigned long branch_idx) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; +return info->paths[branch_idx].dentry; +} + +static inline struct path * +__fsstack_lower_paths (struct dentry *dentry) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; +return info->paths; +} + +static inline void +__fsstack_set_lower_dentry (struct dentry *dentry,unsigned long branch_idx, +struct dentry *lower_dentry) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; + info->paths[branch_idx].dentry = lower_dentry; +} + +static inline void +__fsstack_set_lower_paths (struct dentry *dentry,struct path *lower_paths) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; + info->paths = lower_paths; +} + +static inline struct dentry *fsstack_lower_dentry (struct dentry *dentry) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; +return info->path.dentry; +} + +static inline void +fsstack_set_lower_dentry (struct dentry *dentry,struct dentry *lower_dentry) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; + info->path.dentry = lower_dentry; +} + +static inline struct vfsmount * +__fsstack_lower_mnt (struct dentry *dentry,unsigned long branch_idx) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; +return info->paths[branch_idx].mnt; +} + +static inline void +__fsstack_set_lower_mnt (struct dentry *dentry,unsigned long branch_idx, +struct vfsmount *lower_mnt) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; + info->paths[branch_idx].mnt = lower_mnt; +} + +static inline struct vfsmount *fsstack_lower_mnt (struct dentry *dentry) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; +return info->path.mnt; +} + +static inline void +fsstack_set_lower_mnt (struct dentry *dentry,struct vfsmount *lower_mnt) +{ +struct fsstack_dentry_info *info = dentry->d_fsdata; + info->path.mnt = lower_mnt; +} + +static inline struct file * +__fsstack_lower_file (struct file *file,unsigned long branch_idx) +{ +struct fsstack_file_info *info = file->private_data; +return info->files[branch_idx]; +} + +static inline struct file ** +__fsstack_lower_files (struct file *file) +{ +struct fsstack_file_info *info = file->private_data; +return info->files; +} + +static inline void +__fsstack_set_lower_file (struct file *file,unsigned long branch_idx, +struct file *lower_file) +{ +struct fsstack_file_info *info = file->private_data; + info->files[branch_idx] = lower_file; +} + +static inline void +__fsstack_set_lower_files (struct file *file,struct file **lower_files) +{ +struct fsstack_file_info *info = file->private_data; + info->files = lower_files; +} + +static inline struct file *fsstack_lower_file (struct file *file) +{ +struct fsstack_file_info *info = file->private_data; +return info->file; +} + +static inline void +fsstack_set_lower_file (struct file *file,struct file *lower_file) +{ +struct fsstack_file_info *info = file->private_data; + info->file = lower_file; +} +/* externs for fs/stack.c */ extern void fsstack_copy_attr_all (struct inode *dest,const struct inode *src,int (*get_nlinks)(struct inode *)); -To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/3] fsstack: Generic get/set lower object functions
Quoted 1 line · Trond Myklebust
On Wed, 2006-11-01 at 22:59 -0500, Josef Jeff Sipek wrote:
...
Quoted 9 lines
include/linux/fs_stack.h #define _LINUX_FS_STACK_H · line 17
Quoted 7 lines
include/linux/fs_stack.h +7
-0+/* structs to maintain pointers to the lower VFS objects */ +struct fsstack_sb_info { +union { +struct super_block *sb; +struct super_block **sbs; + }; +};Why are you defining all these structs that are just wrapping unions?
The reason for the union is simple...
1) if you have a linear stackable filesystem (e.g., ecryptfs), your objects need to point to only one lower object (sb -> lower sb, etc.)
2) if you have a fanout stackable filesystem (e.g., unionfs), your objects need to point to n lower objects
Since we don't want to hurt linear stacks by declaring arrays of pointers, I think the best way is to have the lower pointer (e.g., *sb) in a union with the lower double pointer (e.g., **sbs) - this works simply because linear stacks will always
Quoted 6 lines
include/linux/fs_stack.h #define _LINUX_FS_STACK_H · line 116
Quoted 4 lines
include/linux/fs_stack.h +4
-0+/* get the fs dependent data */ +static inline void *fsstack_inode_data (struct inode *inode) +{ +return &((struct __fsstack_inode_generic_info *) inode)->info;Please make this wrap
container_of()instead of rolling your own.
Will do.
Quoted 2 lines
Also note that the naming convention for such a wrapper in almost all other filesystems would be
FSSTACK_I()
Very true, I'll change it to match.
I suppose the function to get the dentry private data should be called FSSTACK_D() and for the superblock FSSTACK_SB() ?
Quoted 4 lines
Quoted 4 lines
include/linux/fs_stack.h +4
-0+static inline struct inode * +__fsstack_lower_inode (struct inode *inode,unsigned long branch_idx) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode);
Quoted 8 lines
include/linux/fs_stack.h #define _LINUX_FS_STACK_H · line 125
Quoted 3 lines
include/linux/fs_stack.h +3
-0+ +return info->inodes[branch_idx]; +}What is the value of "functions" like the above? They appear just to obfuscate the code. Unless your aim is to hide the internals of the struct
__fsstack_inode_generic_info(sort of futile, since you are asking users to include that structure in their private inode structs
Another idea is to move the fsstack_foo_info structure elsewhere...
For stackable filesystems it makes sense to have the pointers right in the inode, but we don't want to penalize the rest if the filesystems. One solution would be to have a special stackable_inode which contains the lower inode pointers. This would still hide the details from the user...
Quoted 8 lines
)
then it is much more obvious to see what is going on when you writeinode = FSSTACK_I(inode)->inodes[branch];rather than
inode = __fsstack_lower_inode(inode, branch);
Point taken. You need to know what's going to anyway, so we might as well make it painfully obvious.
Josef "Jeff" Sipek.
Signature · 2 lines
If I have trouble installing Linux, something is wrong. Very wrong. - Linus Torvalds
Re: [PATCH 2/3] fsstack: Generic get/set lower object functions
Quoted 3 lines
Quoted 1 line
Why are you defining all these structs that are just wrapping unions?
The reason for the union is simple...
I think the query was more about why you'd need a struct which contains only an anonymous union - why not just have a named union? Or do you anticipate adding extra fields to the struct later?
I guess that having a union foo * rather than a struct foo * would be a bit unconventional in the kernel. The named struct / anonymous union combo does hide the union as merely an implementation detail, which is nice. Was this your motivation?
Cheers,
Mark
Quoted 61 lines
1) if you have a linear stackable filesystem (e.g., ecryptfs), your objects need to point to only one lower object (sb -> lower sb, etc.)
2) if you have a fanout stackable filesystem (e.g., unionfs), your objects need to point to n lower objects
Since we don't want to hurt linear stacks by declaring arrays of pointers, I think the best way is to have the lower pointer (e.g., *sb) in a union with the lower double pointer (e.g., **sbs) - this works simply because linear stacks will always
Quoted 6 lines
include/linux/fs_stack.h #define _LINUX_FS_STACK_H · line 116
Quoted 4 lines
include/linux/fs_stack.h +4
-0+/* get the fs dependent data */ +static inline void *fsstack_inode_data (struct inode *inode) +{ +return &((struct __fsstack_inode_generic_info *) inode)->info;Please make this wrap
container_of()instead of rolling your own.Will do.
Quoted 2 lines
Also note that the naming convention for such a wrapper in almost all other filesystems would be
FSSTACK_I()Very true, I'll change it to match.
I suppose the function to get the dentry private data should be called
FSSTACK_D()and for the superblockFSSTACK_SB()?Quoted 4 lines
Quoted 4 lines
include/linux/fs_stack.h +4
-0+static inline struct inode * +__fsstack_lower_inode (struct inode *inode,unsigned long branch_idx) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode);Quoted 8 lines
include/linux/fs_stack.h #define _LINUX_FS_STACK_H · line 125
Quoted 3 lines
include/linux/fs_stack.h +3
-0+ +return info->inodes[branch_idx]; +}What is the value of "functions" like the above? They appear just to obfuscate the code. Unless your aim is to hide the internals of the struct
__fsstack_inode_generic_info(sort of futile, since you are asking users to include that structure in their private inode structsAnother idea is to move the
fsstack_foo_infostructure elsewhere...For stackable filesystems it makes sense to have the pointers right in the inode, but we don't want to penalize the rest if the filesystems. One solution would be to have a special
stackable_inodewhich contains the lower inode pointers. This would still hide the details from the user...Quoted 8 lines
)
then it is much more obvious to see what is going on when you writeinode = FSSTACK_I(inode)->inodes[branch];rather than
inode = __fsstack_lower_inode(inode, branch);Point taken. You need to know what's going to anyway, so we might as well make it painfully obvious.
Josef "Jeff" Sipek.
Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat? And no pedals! Mark: To answer a question with a question: What use is a skateboard? Dave: Skateboards have wheels. Mark: My wheel has a wheel!
Re: [PATCH 2/3] fsstack: Generic get/set lower object functions
Quoted 3 lines · Mark Williamson
Quoted 3 lines
Quoted 1 line
Why are you defining all these structs that are just wrapping unions?
The reason for the union is simple...
...
Quoted 4 lines
I guess that having a union foo * rather than a struct foo * would be a bit unconventional in the kernel. The named struct / anonymous union combo does hide the union as merely an implementation detail, which is nice. Was this your motivation?
That's exactly it. Save space & hide the details.
Josef "Jeff" Sipek.
Signature · 2 lines
Once you have their hardware. Never give it back. (The First Rule of Hardware Acquisition)
Re: [PATCH 2/3] fsstack: Generic get/set lower object functions
Quoted 11 lines · Josef Sipek
Quoted 3 lines · Mark Williamson
Quoted 3 lines
Quoted 1 line
Why are you defining all these structs that are just wrapping unions?
The reason for the union is simple...
...
Quoted 4 lines
I guess that having a union foo * rather than a struct foo * would be a bit unconventional in the kernel. The named struct / anonymous union combo does hide the union as merely an implementation detail, which is nice. Was this your motivation?
That's exactly it. Save space & hide the details.
Why? What is so special about the details that you need to hide them? This is a union that will always be part of a structure anyway.
Trond
Re: [PATCH 2/3] fsstack: Generic get/set lower object functions
Quoted 2 lines · Trond Myklebust
Why? What is so special about the details that you need to hide them? This is a union that will always be part of a structure anyway.
Nothing. Josef, I think we should make them unions.
Re: [PATCH 2/3] fsstack: Generic get/set lower object functions
Quoted 5 lines
Quoted 3 lines
Why? What is so special about the details that you need to hide them? This is a union that will always be part of a structure anyway.
Nothing. Josef, I think we should make them unions.
In other words,
/* structs to maintain pointers to the lower VFS objects */
struct fsstack_sb_info {
union {
struct super_block *sb;
struct super_block **sbs;
};
}; should become:
union fsstack_sb_info {
struct super_block *sb;
struct super_block **sbs;
};-`J'
Re: [PATCH 2/3] fsstack: Generic get/set lower object functions
In reply to Trond MyklebustQuoted 1 line · Trond Myklebust
On Wed, 2006-11-01 at 22:59 -0500, Josef Jeff Sipek wrote:
...
Quoted 14 lines
include/linux/fs_stack.h #define _LINUX_FS_STACK_H · line 125
Quoted 7 lines
include/linux/fs_stack.h +7
-0+static inline struct inode * +__fsstack_lower_inode (struct inode *inode,unsigned long branch_idx) +{ +struct fsstack_inode_info *info =fsstack_inode_data (inode); + +return info->inodes[branch_idx]; +}What is the value of "functions" like the above? They appear just to obfuscate the code. Unless your aim is to hide the internals of the struct
__fsstack_inode_generic_info(sort of futile, since you are asking users to include that structure in their private inode structs) then it is much more obvious to see what is going on when you write
Quoted 5 lines
inode = FSSTACK_I(inode)->inodes[branch];rather than
inode = __fsstack_lower_inode(inode, branch);
I was thinking about this a bit, and it would seem that not having get/set function pretty much kills the reson to have generic pointer structures at all.
Would it make sense to change filesystems like ecryptfs to open-code all these things instead of using _their own_ get/set functions (e.g., ecryptfs_inode_to_lower)?
Other posibility is to move the lower pointers into generic VFS objects in some clever way (not to waste memory on regular filesystems) - this way, the stackable filesystems can still share some parts.
Josef "Jeff" Sipek.
Signature · 1 line
A computer without Microsoft is like chocolate cake without mustard.
Re: [PATCH 2/3] fsstack: Generic get/set lower object functions
Quoted 11 lines · Josef Sipek
I was thinking about this a bit, and it would seem that not having get/set function pretty much kills the reson to have generic pointer structures at all.
Would it make sense to change filesystems like ecryptfs to open-code all these things instead of using
_theirown_get/set functions (e.g.,ecryptfs_inode_to_lower)?Other posibility is to move the lower pointers into generic VFS objects in some clever way (not to waste memory on regular filesystems) - this way, the stackable filesystems can still share some parts.
In order for this to be useful, you and the ecryptfs folks need to sit down and figure out what functionality all these stackable filesystems want to share.
For instance, there is nothing wrong with moving ecryptfs_d_revalidate() into a common libstackfs.c if it turns out that several filesystems want to do the same thing. This is particularly true if you find common locking needs (as is the case with ecryptfs_do_create(), for instance) since locks are a good example of something you never want to debug more than once.
Given all the fun things that can happen with intents in the lower_level filesystem lookup() code, then that is probably a prime candidate for some nice helper functions to make everyone's lives easy too...
Cheers,
Trond
PATCH 3/3 fsstack: Make ecryptfs a user of new fsstack_* functions
In reply to JosefJeff SipekFrom: Josef "Jeff" Sipek <[email protected]>
This patch makes eCryptfs a user of the generic fsstack lower object fsstack structures and functions.
---
fs/ecryptfs/crypto.c | 4 +- fs/ecryptfs/dentry.c | 6 +-- fs/ecryptfs/ecryptfs_kernel.h | 84 ++++++------------------------------------ fs/ecryptfs/file.c | 34 ++++++++--------- fs/ecryptfs/inode.c | 72 ++++++++++++++++++------------------ fs/ecryptfs/main.c | 8 ++-- fs/ecryptfs/mmap.c | 18 ++++----- fs/ecryptfs/super.c | 10 ++--- 8 files changed, 89 insertions(+), 147 deletions(-)
fs/ecryptfs/crypto.c +2 -2
@@ -482,7 +482,7 @@ #define ECRYPTFS_PAGE_STATE_MODIFIED 2#define ECRYPTFS_PAGE_STATE_WRITTEN 3int page_state; - lower_inode =ecryptfs_inode_to_lower (ctx->page->mapping->host); + lower_inode =fsstack_lower_inode (ctx->page->mapping->host); inode_info =ecryptfs_inode_to_private (ctx->page->mapping->host); crypt_stat = &inode_info->crypt_stat;if (!ECRYPTFS_CHECK_FLAG (crypt_stat->flags,ECRYPTFS_ENCRYPTED )) {
@@ -616,7 +616,7 @@ int ecryptfs_decrypt_page(struct file *f crypt_stat = &(ecryptfs_inode_to_private ( page->mapping->host)->crypt_stat); - lower_inode =ecryptfs_inode_to_lower (page->mapping->host); + lower_inode =fsstack_lower_inode (page->mapping->host);if (!ECRYPTFS_CHECK_FLAG (crypt_stat->flags,ECRYPTFS_ENCRYPTED )) { rc =ecryptfs_do_readpage (file, page, page->index);if (rc)
fs/ecryptfs/dentry.c +3 -3
@@ -42,8 +42,8 @@ #include "ecryptfs_kernel.h"*/ static int ecryptfs_d_revalidate (struct dentry *dentry,struct nameidata *nd) { -struct dentry *lower_dentry =ecryptfs_dentry_to_lower (dentry); -struct vfsmount *lower_mnt =ecryptfs_dentry_to_lower_mnt (dentry); +struct dentry *lower_dentry =fsstack_lower_dentry (dentry); +struct vfsmount *lower_mnt =fsstack_lower_mnt (dentry);struct dentry *dentry_save;struct vfsmount *vfsmount_save;int rc =1 ;
@@ -73,7 +73,7 @@ static void ecryptfs_d_release(struct de {struct dentry *lower_dentry; - lower_dentry =ecryptfs_dentry_to_lower (dentry); + lower_dentry =fsstack_lower_dentry (dentry);if (ecryptfs_dentry_to_private (dentry))kmem_cache_free (ecryptfs_dentry_info_cache,ecryptfs_dentry_to_private (dentry));
fs/ecryptfs/ecryptfs_kernel.h +13 -71
141 lines not on this page · raw message
fs/ecryptfs/file.c +17 -17
@@ -117,8 +117,8 @@ static ssize_t ecryptfs_read_update_atimif (-EIOCBQUEUED == rc) rc =wait_on_sync_kiocb (iocb);if (rc >=0 ) { - lower_dentry =ecryptfs_dentry_to_lower (file->f_path.dentry); - lower_vfsmount =ecryptfs_dentry_to_lower_mnt (file->f_path.dentry); + lower_dentry =fsstack_lower_dentry (file->f_path.dentry); + lower_vfsmount =fsstack_lower_mnt (file->f_path.dentry);touch_atime (lower_vfsmount, lower_dentry); }return rc;
@@ -175,7 +175,7 @@ static int ecryptfs_readdir(struct filestruct inode *inode;struct ecryptfs_getdents_callback buf; - lower_file =ecryptfs_file_to_lower (file); + lower_file =fsstack_lower_file (file); lower_file->f_pos = file->f_pos; inode = file->f_path.dentry->d_inode;memset (&buf,0 ,sizeof (buf));
@@ -243,7 +243,7 @@ static int ecryptfs_open(struct inode *istruct dentry *ecryptfs_dentry = file->f_path.dentry;/* Private value of ecryptfs_dentry allocated in * ecryptfs_lookup() */ -struct dentry *lower_dentry =ecryptfs_dentry_to_lower (ecryptfs_dentry); +struct dentry *lower_dentry =fsstack_lower_dentry (ecryptfs_dentry);struct inode *lower_inode =NULL ;struct file *lower_file =NULL ;struct vfsmount *lower_mnt;
@@ -260,7 +260,7 @@ static int ecryptfs_open(struct inode *i goto out; }memset (file_info,0 ,sizeof (*file_info)); - lower_dentry =ecryptfs_dentry_to_lower (ecryptfs_dentry); + lower_dentry =fsstack_lower_dentry (ecryptfs_dentry); crypt_stat = &ecryptfs_inode_to_private (inode)->crypt_stat; mount_crypt_stat = &ecryptfs_superblock_to_private ( ecryptfs_dentry->d_sb)->mount_crypt_stat;
@@ -277,14 +277,14 @@ static int ecryptfs_open(struct inode *i lower_flags = (lower_flags &O_ACCMODE ) |O_RDWR ;if (file->f_flags &O_APPEND ) lower_flags &= ~O_APPEND ; - lower_mnt =ecryptfs_dentry_to_lower_mnt (ecryptfs_dentry); + lower_mnt =fsstack_lower_mnt (ecryptfs_dentry);/* Corresponding fput() in ecryptfs_release() */ if ((rc =ecryptfs_open_lower_file (&lower_file, lower_dentry, lower_mnt, lower_flags))) {ecryptfs_printk (KERN_ERR ,"Error opening lower file\n" ); goto out_puts; } -ecryptfs_set_file_lower (file, lower_file); +fsstack_set_lower_file (file, lower_file);/* Isn't this check the same as the one in lookup? */ lower_inode = lower_dentry->d_inode;if (S_ISDIR (ecryptfs_dentry->d_inode->i_mode)) {
@@ -338,7 +338,7 @@ static int ecryptfs_open(struct inode *iecryptfs_printk (KERN_DEBUG ,"inode w/ addr = [0x%p], i_ino = [0x%.16x] " "size: [0x%.16x]\n" , inode, inode->i_ino,i_size_read (inode)); -ecryptfs_set_file_lower (file, lower_file); +fsstack_set_lower_file (file, lower_file); goto out; out_puts:mntput (lower_mnt);
@@ -354,7 +354,7 @@ static int ecryptfs_flush(struct file *fint rc =0 ;struct file *lower_file =NULL ; - lower_file =ecryptfs_file_to_lower (file); + lower_file =fsstack_lower_file (file);if (lower_file->f_op && lower_file->f_op->flush) rc = lower_file->f_op->flush (lower_file, td);return rc;
@@ -362,9 +362,9 @@ static int ecryptfs_flush(struct file *fstatic int ecryptfs_release (struct inode *inode,struct file *file) { -struct file *lower_file =ecryptfs_file_to_lower (file); +struct file *lower_file =fsstack_lower_file (file);struct ecryptfs_file_info *file_info =ecryptfs_file_to_private (file); -struct inode *lower_inode =ecryptfs_inode_to_lower (inode); +struct inode *lower_inode =fsstack_lower_inode (inode);int rc;if ((rc =ecryptfs_close_lower_file (lower_file))) {
@@ -380,8 +380,8 @@ out:static int ecryptfs_fsync (struct file *file,struct dentry *dentry,int datasync) { -struct file *lower_file =ecryptfs_file_to_lower (file); -struct dentry *lower_dentry =ecryptfs_dentry_to_lower (dentry); +struct file *lower_file =fsstack_lower_file (file); +struct dentry *lower_dentry =fsstack_lower_dentry (dentry);struct inode *lower_inode = lower_dentry->d_inode;int rc = -EINVAL ;
@@ -399,7 +399,7 @@ static int ecryptfs_fasync(int fd, strucint rc =0 ;struct file *lower_file =NULL ; - lower_file =ecryptfs_file_to_lower (file); + lower_file =fsstack_lower_file (file);if (lower_file->f_op && lower_file->f_op->fasync) rc = lower_file->f_op->fasync (fd, lower_file, flag);return rc;
@@ -411,7 +411,7 @@ static ssize_t ecryptfs_sendfile(structstruct file *lower_file =NULL ;int rc = -EINVAL ; - lower_file =ecryptfs_file_to_lower (file); + lower_file =fsstack_lower_file (file);if (lower_file->f_op && lower_file->f_op->sendfile) rc = lower_file->f_op->sendfile (lower_file, ppos, count, actor, target);
@@ -459,9 +459,9 @@ ecryptfs_ioctl(struct inode *inode, strustruct file *lower_file =NULL ;if (ecryptfs_file_to_private (file)) - lower_file =ecryptfs_file_to_lower (file); + lower_file =fsstack_lower_file (file);if (lower_file && lower_file->f_op && lower_file->f_op->ioctl) - rc = lower_file->f_op->ioctl (ecryptfs_inode_to_lower (inode), + rc = lower_file->f_op->ioctl (fsstack_lower_inode (inode), lower_file, cmd, arg);else rc = -ENOTTY ;
fs/ecryptfs/inode.c +36 -36
233 lines not on this page · raw message
fs/ecryptfs/main.c +4 -4
@@ -79,7 +79,7 @@ int ecryptfs_interpose(struct dentry *loint rc =0 ; lower_inode = lower_dentry->d_inode; -if (lower_inode->i_sb !=ecryptfs_superblock_to_lower (sb)) { +if (lower_inode->i_sb !=fsstack_lower_sb (sb)) { rc = -EXDEV ; goto out; }
@@ -449,10 +449,10 @@ static int ecryptfs_read_super(struct su goto out_free; } lower_mnt = nd.mnt; -ecryptfs_set_superblock_lower (sb, lower_root->d_sb); +fsstack_set_lower_sb (sb, lower_root->d_sb); sb->s_maxbytes = lower_root->d_sb->s_maxbytes; -ecryptfs_set_dentry_lower (sb->s_root, lower_root); -ecryptfs_set_dentry_lower_mnt (sb->s_root, lower_mnt); +fsstack_set_lower_dentry (sb->s_root, lower_root); +fsstack_set_lower_mnt (sb->s_root, lower_mnt);if ((rc =ecryptfs_interpose (lower_root, sb->s_root, sb,0 ))) goto out_free; rc =0 ;
fs/ecryptfs/mmap.c +9 -9
@@ -219,10 +219,10 @@ int ecryptfs_do_readpage(struct file *ficonst struct address_space_operations *lower_a_ops; dentry = file->f_path.dentry; - lower_file =ecryptfs_file_to_lower (file); - lower_dentry =ecryptfs_dentry_to_lower (dentry); + lower_file =fsstack_lower_file (file); + lower_dentry =fsstack_lower_dentry (dentry); inode = dentry->d_inode; - lower_inode =ecryptfs_inode_to_lower (inode); + lower_inode =fsstack_lower_inode (inode); lower_a_ops = lower_inode->i_mapping->a_ops; lower_page = read_cache_page(lower_inode->i_mapping, lower_page_index, (filler_t *)lower_a_ops->readpage,
@@ -542,8 +542,8 @@ process_new_file(struct ecryptfs_crypt_sint header_pages;int more_header_data_to_be_written =1 ; - lower_inode =ecryptfs_inode_to_lower (inode); - lower_file =ecryptfs_file_to_lower (file); + lower_inode =fsstack_lower_inode (inode); + lower_file =fsstack_lower_file (file); lower_a_ops = lower_inode->i_mapping->a_ops; header_pages = ((crypt_stat->header_extent_size * crypt_stat->num_header_extents_at_front)
@@ -635,8 +635,8 @@ static int ecryptfs_commit_write(structint rc; inode = page->mapping->host; - lower_inode =ecryptfs_inode_to_lower (inode); - lower_file =ecryptfs_file_to_lower (file); + lower_inode =fsstack_lower_inode (inode); + lower_file =fsstack_lower_file (file);mutex_lock (&lower_inode->i_mutex); crypt_stat = &ecryptfs_inode_to_private (file->f_path.dentry->d_inode) ->crypt_stat;
@@ -749,7 +749,7 @@ static sector_t ecryptfs_bmap(struct addstruct inode *lower_inode; inode = (struct inode *)mapping->host; - lower_inode =ecryptfs_inode_to_lower (inode); + lower_inode =fsstack_lower_inode (inode);if (lower_inode->i_mapping->a_ops->bmap) rc = lower_inode->i_mapping->a_ops->bmap (lower_inode->i_mapping, block);
@@ -763,7 +763,7 @@ static void ecryptfs_sync_page(struct pastruct page *lower_page; inode = page->mapping->host; - lower_inode =ecryptfs_inode_to_lower (inode); + lower_inode =fsstack_lower_inode (inode);/* NOTE: Recently swapped with grab_cache_page(), since * sync_page() just makes sure that pending I/O gets done. */ lower_page =find_lock_page (lower_inode->i_mapping, page->index);
fs/ecryptfs/super.c +5 -5
@@ -85,7 +85,7 @@ static void ecryptfs_destroy_inode(struc*/ void ecryptfs_init_inode (struct inode *inode,struct inode *lower_inode) { -ecryptfs_set_inode_lower (inode, lower_inode); +fsstack_set_lower_inode (inode, lower_inode); inode->i_ino = lower_inode->i_ino; inode->i_version++; inode->i_op = &ecryptfs_main_iops;
@@ -119,7 +119,7 @@ static void ecryptfs_put_super(struct su*/ static int ecryptfs_statfs (struct dentry *dentry,struct kstatfs *buf) { -return vfs_statfs (ecryptfs_dentry_to_lower (dentry), buf); +return vfs_statfs (fsstack_lower_dentry (dentry), buf); }/**
@@ -134,7 +134,7 @@ static int ecryptfs_statfs(struct dentry*/ static void ecryptfs_clear_inode (struct inode *inode) { -iput (ecryptfs_inode_to_lower (inode)); +iput (fsstack_lower_inode (inode)); }/**
@@ -146,8 +146,8 @@ static void ecryptfs_clear_inode(structstatic int ecryptfs_show_options (struct seq_file *m,struct vfsmount *mnt) {struct super_block *sb = mnt->mnt_sb; -struct dentry *lower_root_dentry =ecryptfs_dentry_to_lower (sb->s_root); -struct vfsmount *lower_mnt =ecryptfs_dentry_to_lower_mnt (sb->s_root); +struct dentry *lower_root_dentry =fsstack_lower_dentry (sb->s_root); +struct vfsmount *lower_mnt =fsstack_lower_mnt (sb->s_root);char *tmp_page;char *path;int rc =0 ;