GFS2: Add atomic_open support
Subsystems (2)
The following patch implements atomic_open for GFS2. This is mostly straightforward, however there is one corner case which I've had to deal with, beyond what would normally be expected for a local filesystem.
The ->atomic_open function can be passed negative dentries, which in most cases means either ENOENT (->lookup) or a call to d_instantiate (->create). In the GFS2 case though, we need to actually perform the look up, since we do not know whether there has been a new inode created on another node. The look up calls d_splice_alias which then tries to rehash the dentry - so the solution here is to simply check for that in d_splice_alias. The same issue is likely to affect any other cluster filesystem implementing ->atomic_open
fs/dcache.c +9 -2
@@ -1612,6 +1612,10 @@ EXPORT_SYMBOL(d_obtain_alias);* If a dentry was found and moved, then it is returned. Otherwise NULL * is returned. This matches the expected return value of ->lookup. * +* Cluster filesystems may call this function with a negative, hashed dentry. +* In that case, we know that the inode will be a regular file, and also this +* will only occur during atomic_open. So we need to check for the dentry +* being already hashed only in the final case. */ struct dentry *d_splice_alias (struct inode *inode,struct dentry *dentry) {
@@ -1636,8 +1640,11 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)security_d_instantiate (dentry, inode);d_rehash (dentry); } - }else -d_add (dentry, inode); + }else { +d_instantiate (dentry, inode); +if (d_unhashed (dentry)) +d_rehash (dentry); + }return new; }EXPORT_SYMBOL (d_splice_alias);
fs/gfs2/file.c +46 -23
96 lines not on this page · raw message
fs/gfs2/inode.c +85 -25
187 lines not on this page · raw message
fs/gfs2/inode.h +1 -0
@@ -109,6 +109,7 @@ extern int gfs2_permission(struct inode *inode, int mask);extern int gfs2_setattr_simple (struct inode *inode,struct iattr *attr);extern struct inode *gfs2_lookup_simple (struct inode *dip,const char *name);extern void gfs2_dinode_out (const struct gfs2_inode *ip,void *buf); +extern int gfs2_open_common (struct inode *inode,struct file *file);extern const struct inode_operations gfs2_file_iops;extern const struct inode_operations gfs2_dir_iops;
Al Viro
maintainerQuoted 5 lines · Steven Whitehouse
The following patch implements
atomic_openfor GFS2. This is mostly straightforward, however there is one corner case which I've had to deal with, beyond what would normally be expected for a local filesystem.
Broken - what will happen if you hit a symlink, for starters? On everything handled locally you should just return finish_no_open(file, dentry) and let the caller deal with that; the only cases that might make sense to handle in ->atomic_open() are regular files and directories. For gfs2 it should be just regular files. While we are at it, do you even need ->private_data for gfs2 directories?
Hi,
Quoted 7 lines · Al Viro
Quoted 5 lines · Steven Whitehouse
The following patch implements
atomic_openfor GFS2. This is mostly straightforward, however there is one corner case which I've had to deal with, beyond what would normally be expected for a local filesystem.
Quoted 6 lines
Broken - what will happen if you hit a symlink, for starters? On everything handled locally you should just return
finish_no_open(file, dentry)and let the caller deal with that; the only cases that might make sense to handle in ->atomic_open() are regular files and directories. For gfs2 it should be just regular files. While we are at it, do you even need ->private_data for gfs2 directories?
I'm brewing up another version of the patch at the moment, which I will post shortly. I don't understand why GFS2 specifically would not want to do this with both files and directories? Why would it be different to other filesystems in that respect?
We do need private data for gfs2 directories because that is required for flock which should work equally well on directories as on regular files. Potentially we might allocate it later, on the first call to flock for example, but it has been done at open time so that we don't have to test for it on every flock call. Also I was hoping to put some info in there to assist with directory readahead at some stage too,
Steve.
This is the second attempt at an atomic_open patch for GFS2, now updated in the light of Al's comments on the first patch.
Also, this patch is designed to apply over this one:
https://www.redhat.com/archives/cluster-devel/2013-June/msg00098.html
I've restricted atomic_open to only operate on regular files, although I still don't understand why atomic_open should not be possible also for directories on GFS2. That can always be added in later though, if it makes sense.
The ->atomic_open function can be passed negative dentries, which in most cases means either ENOENT (->lookup) or a call to d_instantiate (->create). In the GFS2 case though, we need to actually perform the look up, since we do not know whether there has been a new inode created on another node. The look up calls d_splice_alias which then tries to rehash the dentry - so the solution here is to simply check for that in d_splice_alias. The same issue is likely to affect any other cluster filesystem implementing ->atomic_open
fs/dcache.c +9 -2
@@ -1612,6 +1612,10 @@ EXPORT_SYMBOL(d_obtain_alias);* If a dentry was found and moved, then it is returned. Otherwise NULL * is returned. This matches the expected return value of ->lookup. * +* Cluster filesystems may call this function with a negative, hashed dentry. +* In that case, we know that the inode will be a regular file, and also this +* will only occur during atomic_open. So we need to check for the dentry +* being already hashed only in the final case. */ struct dentry *d_splice_alias (struct inode *inode,struct dentry *dentry) {
@@ -1636,8 +1640,11 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)security_d_instantiate (dentry, inode);d_rehash (dentry); } - }else -d_add (dentry, inode); + }else { +d_instantiate (dentry, inode); +if (d_unhashed (dentry)) +d_rehash (dentry); + }return new; }EXPORT_SYMBOL (d_splice_alias);
fs/gfs2/file.c +46 -23
96 lines not on this page · raw message
fs/gfs2/inode.c +99 -26
201 lines not on this page · raw message
fs/gfs2/inode.h +1 -0
@@ -109,6 +109,7 @@ extern int gfs2_permission(struct inode *inode, int mask);extern int gfs2_setattr_simple (struct inode *inode,struct iattr *attr);extern struct inode *gfs2_lookup_simple (struct inode *dip,const char *name);extern void gfs2_dinode_out (const struct gfs2_inode *ip,void *buf); +extern int gfs2_open_common (struct inode *inode,struct file *file);extern const struct inode_operations gfs2_file_iops;extern const struct inode_operations gfs2_dir_iops;