Commit d7c103d0 authored by Steven Whitehouse's avatar Steven Whitehouse

[GFS2] Fix recursive locking attempt with NFS

In certain cases, its possible for NFS to call the lookup code while
holding the glock (when doing a readdirplus operation) so we need to
check for that and not try and lock the glock twice. This also fixes a
typo in a previous NFS related GFS2 patch.
Signed-off-by: default avatarSteven Whitehouse <swhiteho@redhat.com>
parent b790c3b7
...@@ -395,8 +395,10 @@ struct inode *gfs2_lookup_simple(struct inode *dip, const char *name) ...@@ -395,8 +395,10 @@ struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
* @is_root: If 1, ignore the caller's permissions * @is_root: If 1, ignore the caller's permissions
* @i_gh: An uninitialized holder for the new inode glock * @i_gh: An uninitialized holder for the new inode glock
* *
* There will always be a vnode (Linux VFS inode) for the d_gh inode unless * This can be called via the VFS filldir function when NFS is doing
* @is_root is true. * a readdirplus and the inode which its intending to stat isn't
* already in cache. In this case we must not take the directory glock
* again, since the readdir call will have already taken that lock.
* *
* Returns: errno * Returns: errno
*/ */
...@@ -409,8 +411,9 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, ...@@ -409,8 +411,9 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
struct gfs2_holder d_gh; struct gfs2_holder d_gh;
struct gfs2_inum_host inum; struct gfs2_inum_host inum;
unsigned int type; unsigned int type;
int error = 0; int error;
struct inode *inode = NULL; struct inode *inode = NULL;
int unlock = 0;
if (!name->len || name->len > GFS2_FNAMESIZE) if (!name->len || name->len > GFS2_FNAMESIZE)
return ERR_PTR(-ENAMETOOLONG); return ERR_PTR(-ENAMETOOLONG);
...@@ -422,9 +425,12 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, ...@@ -422,9 +425,12 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
return dir; return dir;
} }
error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); if (gfs2_glock_is_locked_by_me(dip->i_gl) == 0) {
if (error) error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
return ERR_PTR(error); if (error)
return ERR_PTR(error);
unlock = 1;
}
if (!is_root) { if (!is_root) {
error = permission(dir, MAY_EXEC, NULL); error = permission(dir, MAY_EXEC, NULL);
...@@ -439,10 +445,11 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, ...@@ -439,10 +445,11 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
inode = gfs2_inode_lookup(sb, &inum, type); inode = gfs2_inode_lookup(sb, &inum, type);
out: out:
gfs2_glock_dq_uninit(&d_gh); if (unlock)
gfs2_glock_dq_uninit(&d_gh);
if (error == -ENOENT) if (error == -ENOENT)
return NULL; return NULL;
return inode; return inode ? inode : ERR_PTR(error);
} }
static int pick_formal_ino_1(struct gfs2_sbd *sdp, u64 *formal_ino) static int pick_formal_ino_1(struct gfs2_sbd *sdp, u64 *formal_ino)
......
...@@ -1018,7 +1018,7 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, ...@@ -1018,7 +1018,7 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
} }
generic_fillattr(inode, stat); generic_fillattr(inode, stat);
if (unlock); if (unlock)
gfs2_glock_dq_uninit(&gh); gfs2_glock_dq_uninit(&gh);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment