ensure unique i_ino in filesystems without permanent inode numbers (libfs superblock cleanup)
Subsystems (8)
PATCH 2/3 ensure unique i_ino in filesystems without permanent inode numbers (libfs superblock cleanup)
This patch ensures that the inodes allocated by the functions get_sb_pseudo and simple_fill_super are unique, provided of course, that the filesystems calling them play by the rules. Currently that isn't the case, but will be as I get to each of the filesystems.
The patch itself is pretty simple, but I also had to fix up the callers of simple_fill_super to make sure they passed in the seq flag. For this first pass, I set it on any filesystem with an empty "files" struct to 0. That may need to be revised as I review each filesystem, but should be OK for now.
drivers/infiniband/hw/ipath/ipath_fs.c +1 -1
@@ -514,7 +514,7 @@ static int ipathfs_fill_super(struct sup {""}, }; - ret =simple_fill_super (sb,IPATHFS_MAGIC , files); + ret =simple_fill_super (sb,IPATHFS_MAGIC , files,1 );if (ret) {printk (KERN_ERR "simple_fill_super failed: %d\n" , ret); goto bail;
fs/binfmt_misc.c +1 -1
@@ -731,7 +731,7 @@ static int bm_fill_super(struct super_bl [2] = {"register", &bm_register_operations, S_IWUSR}, /* last one */ {""} }; -int err =simple_fill_super (sb,0x42494e4d , bm_files); +int err =simple_fill_super (sb,0x42494e4d , bm_files,1 );if (!err) sb->s_op = &s_ops;return err;
fs/debugfs/inode.c +1 -1
@@ -107,7 +107,7 @@ static int debug_fill_super(struct super {static struct tree_descr debug_files[] = {{"" }}; -return simple_fill_super (sb,DEBUGFS_MAGIC , debug_files); +return simple_fill_super (sb,DEBUGFS_MAGIC , debug_files,0 ); } static int debug_get_sb(struct file_system_type *fs_type,
fs/fuse/control.c +1 -1
@@ -163,7 +163,7 @@ static int fuse_ctl_fill_super(struct sustruct fuse_conn *fc;int err; - err =simple_fill_super (sb,FUSE_CTL_SUPER_MAGIC , &empty_descr); + err =simple_fill_super (sb,FUSE_CTL_SUPER_MAGIC , &empty_descr,0 );if (err)return err;
fs/libfs.c +14 -3
@@ -215,7 +215,7 @@ int get_sb_pseudo(struct file_system_typ s->s_op = ops ? ops : &default_ops; s->s_time_gran =1 ; root =new_inode (s); -if (!root) +if (!root ||iunique_register (root,0 )) goto Enomem; root->i_mode =S_IFDIR |S_IRUSR |S_IWUSR ; root->i_uid = root->i_gid =0 ;
@@ -356,7 +356,12 @@ int simple_commit_write(struct file *filreturn 0 ; } -int simple_fill_super (struct super_block *s,int magic,struct tree_descr *files) +/* +* Some filesystems require that particular entries have particular i_ino values. Those +* callers need to set the "seq" flag to make sure that i_ino is assigned sequentially +* to the files starting with 0. +*/ +int simple_fill_super (struct super_block *s,int magic,struct tree_descr *files,int seq) {static struct super_operations s_ops = {.statfs = simple_statfs};struct inode *inode;
@@ -380,6 +385,9 @@ int simple_fill_super(struct super_block inode->i_op = &simple_dir_inode_operations; inode->i_fop = &simple_dir_operations; inode->i_nlink =2 ; +/* set this as high as a 32 bit val as possible to avoid collisions. This is also +* well above the highest value that iunique_register will assign to an inode */ + inode->i_ino =0xffffffff ; root =d_alloc_root (inode);if (!root) {iput (inode);
@@ -399,7 +407,10 @@ int simple_fill_super(struct super_block inode->i_blocks =0 ; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ; inode->i_fop = files->ops; - inode->i_ino = i; +if (seq) + inode->i_ino = i; +else if (iunique_register (inode,0 )) + goto out;d_add (dentry, inode); } s->s_root = root;
fs/nfsd/nfsctl.c +1 -1
@@ -659,7 +659,7 @@ #ifdef CONFIG_NFSD_V4#endif /* last one */ {""} }; -return simple_fill_super (sb,0x6e667364 , nfsd_files); +return simple_fill_super (sb,0x6e667364 , nfsd_files,1 ); } static int nfsd_get_sb(struct file_system_type *fs_type,
include/linux/fs.h +1 -1
@@ -1890,7 +1890,7 @@ extern const struct file_operations simpextern struct inode_operations simple_dir_inode_operations;struct tree_descr {char *name;const struct file_operations *ops;int mode; };struct dentry *d_alloc_name (struct dentry *,const char *); -extern int simple_fill_super (struct super_block *,int ,struct tree_descr *); +extern int simple_fill_super (struct super_block *,int ,struct tree_descr *,int );extern int simple_pin_fs (struct file_system_type *,struct vfsmount **mount,int *count);extern void simple_release_fs (struct vfsmount **mount,int *count);
security/inode.c +1 -1
@@ -130,7 +130,7 @@ static int fill_super(struct super_block {static struct tree_descr files[] = {{"" }}; -return simple_fill_super (sb,SECURITYFS_MAGIC , files); +return simple_fill_super (sb,SECURITYFS_MAGIC , files,0 ); } static int get_sb(struct file_system_type *fs_type,
security/selinux/selinuxfs.c +1 -1
@@ -1285,7 +1285,7 @@ static int sel_fill_super(struct super_b [SEL_COMPAT_NET] = {"compat_net", &sel_compat_net_ops, S_IRUGO|S_IWUSR}, /* last one */ {""} }; - ret =simple_fill_super (sb,SELINUX_MAGIC , selinux_files); + ret =simple_fill_super (sb,SELINUX_MAGIC , selinux_files,1 );if (ret) goto err;
Quoted 18 lines · Jeff Layton
This patch ensures that the inodes allocated by the functions
get_sb_pseudoandsimple_fill_superare unique, provided of course, that the filesystems calling them play by the rules. Currently that isn't the case, but will be as I get to each of the filesystems.The patch itself is pretty simple, but I also had to fix up the callers of
simple_fill_superto make sure they passed in the seq flag. For this first pass, I set it on any filesystem with an empty "files" struct to 0. That may need to be revised as I review each filesystem, but should be OK for now.Signed-off-by Jeff Layton <[email protected]>drivers/infiniband/hw/ipath/ipath_fs.c +0
-0
drivers/infiniband/hw/ipath/ipath_fs.c static int ipathfs_fill_super(struct sup · line 517
Quoted 5 lines
drivers/infiniband/hw/ipath/ipath_fs.c +1
-1@@ -514,7 +514,7 @@ static int ipathfs_fill_super(struct sup {""}, }; - ret =simple_fill_super (sb,IPATHFS_MAGIC , files); + ret =simple_fill_super (sb,IPATHFS_MAGIC , files,1 );
I don't know...the magic looking 1 and 0 (later in the patch) seem a bit arbitrary. Maybe a #define is in order?
Quoted 11 lines
drivers/infiniband/hw/ipath/ipath_fs.c +2
-1-int simple_fill_super (struct super_block *s,int magic,struct tree_descr *files) +/* +* Some filesystems require that particular entries have particular i_ino values. Those
+ * callers need to set the "seq" flag to make sure thati_inois assigned sequentially
+ * to the files starting with 0.
+ */
+intsimple_fill_super(struct super_block *s, int magic, struct tree_descr *files, int seq)
Line wraped.
drivers/infiniband/hw/ipath/ipath_fs.c int simple_fill_super(struct super_block · line 409
Quoted 4 lines
drivers/infiniband/hw/ipath/ipath_fs.c +0
-0@@ -399,7 +407,10 @@ int simple_fill_super(struct super_block inode->i_blocks =0 ; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;
I'd indent CURRENT_TIME a bit.
Josef "Jeff" Sipek.
Signature · 2 lines
If I have trouble installing Linux, something is wrong. Very wrong. - Linus Torvalds
Quoted 5 lines · Josef Sipek
drivers/infiniband/hw/ipath/ipath_fs.c static int ipathfs_fill_super(struct sup · line 517
Quoted 2 lines
drivers/infiniband/hw/ipath/ipath_fs.c +1
-1- ret =simple_fill_super (sb,IPATHFS_MAGIC , files); + ret =simple_fill_super (sb,IPATHFS_MAGIC , files,1 );I don't know...the magic looking 1 and 0 (later in the patch) seem a bit arbitrary. Maybe a #define is in order?
Yeah, I'm not fond of that, though the comments on simple_fill_super should explain it. Basically, I need simple_fill_super to operate in two different "modes", and I was using the extra flag to key this. I'm not clear on what sort of #define would make sense here. Can you suggest something?
Quoted 5 lines
Quoted 5 lines
-int
simple_fill_super(struct super_block *s, int magic, struct tree_descr *files)
+/*
+ * Some filesystems require that particular entries have particulari_inovalues. Those
Quoted 9 lines
Quoted 6 lines
+ * callers need to set the "seq" flag to make sure that
i_inois assigned sequentially
+ * to the files starting with 0.
+ */
+intsimple_fill_super(struct super_block *s, int magic, struct tree_descr *files, int seq)Line wraped.
I thought those were under 80 columns but perhaps they weren't. I'll clean them up and repost, once you clarify what you'd like to see in the #define.
Quoted 6 lines
Review int simple_fill_super(struct super_block · line 409
Quoted 4 lines
(quoted diff) +0
-0@@ -399,7 +407,10 @@ int simple_fill_super(struct super_block inode->i_blocks = 0; inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;I'd indent
CURRENT_TIMEa bit.
I wasn't planning on touching those parts of the code that don't need to be changed, since formatting deltas can make it harder to see the "actual" changes in the patch. That should probably be addressed in a follow-on patch if you think it needs to be changed.
-- Jeff Layton
Quoted 11 lines · Jeff Layton
Quoted 5 lines · Josef Sipek
drivers/infiniband/hw/ipath/ipath_fs.c static int ipathfs_fill_super(struct sup · line 517
Quoted 2 lines
drivers/infiniband/hw/ipath/ipath_fs.c +1
-1- ret =simple_fill_super (sb,IPATHFS_MAGIC , files); + ret =simple_fill_super (sb,IPATHFS_MAGIC , files,1 );I don't know...the magic looking 1 and 0 (later in the patch) seem a bit arbitrary. Maybe a #define is in order?
Yeah, I'm not fond of that, though the comments on
simple_fill_supershould explain it. Basically, I needsimple_fill_superto operate in two different "modes", and I was using the extra flag to key this. I'm not clear on what sort of #define would make sense here. Can you suggest something?
First I was thinking about defining 2 constats, but maybe the better thing to do would be to
1) rename simple_fill_super to __simple_fill_super
2) #define simple_fill_super_foo(...) to __siple_fill_super(....., 0)
3) #define simple_fill_super_bar(...) to __siple_fill_super(....., 1)
(Or equivalent thing using inline functions.)
I can't really think of any good name for #define'd flag.
Beware, I'm pretty much just thinking out loud.. :)
Quoted 11 lines
Quoted 6 lines
Review int simple_fill_super(struct super_block · line 409
Quoted 4 lines
(quoted diff) +0
-0@@ -399,7 +407,10 @@ int simple_fill_super(struct super_block inode->i_blocks = 0; inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;I'd indent
CURRENT_TIMEa bit.I wasn't planning on touching those parts of the code that don't need to be changed, since formatting deltas can make it harder to see the "actual" changes in the patch. That should probably be addressed in a follow-on patch if you think it needs to be changed.
Oh, sorry, that wasn't your code. You're right about it not being the the right thing to fix in your patch.
Actually, it looks like another problem created by line-wrapping.
Josef "Jeff" Sipek.
Signature · 1 line
NT is to UNIX what a doughnut is to a particle accelerator.
Quoted 5 lines · Jeff Layton
This patch ensures that the inodes allocated by the functions
get_sb_pseudoandsimple_fill_superare unique, provided of course, that the filesystems calling them play by the rules. Currently that isn't the case, but will be as I get to each of the filesystems.
This patch is respun based on some suggestions by Josef Sipek. The different modes of simple_fill_super are different enough that they probably ought to be different functions. This makes that so.
With this patch it's not necessary to change some of the callers of simple_fill_super yet, but they'll need to be changed sometime so I left that in place.
drivers/infiniband/hw/ipath/ipath_fs.c +0 -0
fs/binfmt_misc.c +0 -0
fs/debugfs/inode.c +1 -1
@@ -107,7 +107,7 @@ static int debug_fill_super(struct super {static struct tree_descr debug_files[] = {{"" }}; -return simple_fill_super (sb,DEBUGFS_MAGIC , debug_files); +return registered_fill_super (sb,DEBUGFS_MAGIC , debug_files); } static int debug_get_sb(struct file_system_type *fs_type,
fs/fuse/control.c +1 -1
@@ -163,7 +163,7 @@ static int fuse_ctl_fill_super(struct sustruct fuse_conn *fc;int err; - err =simple_fill_super (sb,FUSE_CTL_SUPER_MAGIC , &empty_descr); + err =registered_fill_super (sb,FUSE_CTL_SUPER_MAGIC , &empty_descr);if (err)return err;
fs/libfs.c +38 -3
82 lines not on this page · raw message
fs/nfsd/nfsctl.c +0 -0
include/linux/fs.h +4 -1
@@ -1879,7 +1879,10 @@ extern const struct file_operations simpextern struct inode_operations simple_dir_inode_operations;struct tree_descr {char *name;const struct file_operations *ops;int mode; };struct dentry *d_alloc_name (struct dentry *,const char *); -extern int simple_fill_super (struct super_block *,int ,struct tree_descr *); +extern int simple_fill_super (struct super_block *s,int magic, +struct tree_descr *files); +extern int registered_fill_super (struct super_block *s,int magic, +struct tree_descr *files);extern int simple_pin_fs (struct file_system_type *,struct vfsmount **mount,int *count);extern void simple_release_fs (struct vfsmount **mount,int *count);
security/inode.c +1 -1
@@ -130,7 +130,7 @@ static int fill_super(struct super_block {static struct tree_descr files[] = {{"" }}; -return simple_fill_super (sb,SECURITYFS_MAGIC , files); +return registered_fill_super (sb,SECURITYFS_MAGIC , files); } static int get_sb(struct file_system_type *fs_type,