Skip to content

Commit

Permalink
Mark all NFS and xattr functions as PF_FSTRANS
Browse files Browse the repository at this point in the history
Prevent deadlocks by disabling direct reclaim during all NFS and
xattr calls.  This is related to 40d06e3.

Signed-off-by: Brian Behlendorf <[email protected]>
Issue #3225
  • Loading branch information
behlendorf committed Apr 14, 2015
1 parent d07a163 commit 1cf8f03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions module/zfs/zpl_export.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ zpl_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len, int connectable)
{
struct inode *ip = dentry->d_inode;
#endif /* HAVE_ENCODE_FH_WITH_INODE */
fstrans_cookie_t cookie;
fid_t *fid = (fid_t *)fh;
int len_bytes, rc;

Expand All @@ -48,12 +49,14 @@ zpl_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len, int connectable)
return (255);

fid->fid_len = len_bytes - offsetof(fid_t, fid_data);
cookie = spl_fstrans_mark();

if (zfsctl_is_node(ip))
rc = zfsctl_fid(ip, fid);
else
rc = zfs_fid(ip, fid);

spl_fstrans_unmark(cookie);
len_bytes = offsetof(fid_t, fid_data) + fid->fid_len;
*max_len = roundup(len_bytes, sizeof (__u32)) / sizeof (__u32);

Expand Down Expand Up @@ -84,6 +87,7 @@ zpl_fh_to_dentry(struct super_block *sb, struct fid *fh,
int fh_len, int fh_type)
{
fid_t *fid = (fid_t *)fh;
fstrans_cookie_t cookie;
struct inode *ip;
int len_bytes, rc;

Expand All @@ -94,7 +98,9 @@ zpl_fh_to_dentry(struct super_block *sb, struct fid *fh,
len_bytes < offsetof(fid_t, fid_data) + fid->fid_len)
return (ERR_PTR(-EINVAL));

cookie = spl_fstrans_mark();
rc = zfs_vget(sb, &ip, fid);
spl_fstrans_unmark(cookie);

if (rc != 0)
return (ERR_PTR(-rc));
Expand All @@ -108,11 +114,14 @@ static struct dentry *
zpl_get_parent(struct dentry *child)
{
cred_t *cr = CRED();
fstrans_cookie_t cookie;
struct inode *ip;
int error;

crhold(cr);
cookie = spl_fstrans_mark();
error = -zfs_lookup(child->d_inode, "..", &ip, 0, cr, NULL, NULL);
spl_fstrans_unmark(cookie);
crfree(cr);
ASSERT3S(error, <=, 0);

Expand All @@ -127,10 +136,13 @@ static int
zpl_commit_metadata(struct inode *inode)
{
cred_t *cr = CRED();
fstrans_cookie_t cookie;
int error;

crhold(cr);
cookie = spl_fstrans_mark();
error = -zfs_fsync(inode, 0, cr);
spl_fstrans_unmark(cookie);
crfree(cr);
ASSERT3S(error, <=, 0);

Expand Down
9 changes: 9 additions & 0 deletions module/zfs/zpl_xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ zpl_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
zfs_sb_t *zsb = ZTOZSB(zp);
xattr_filldir_t xf = { buffer_size, 0, buffer, dentry->d_inode };
cred_t *cr = CRED();
fstrans_cookie_t cookie;
int error = 0;

crhold(cr);
cookie = spl_fstrans_mark();
rw_enter(&zp->z_xattr_lock, RW_READER);

if (zsb->z_use_sa && zp->z_is_sa) {
Expand All @@ -228,6 +230,7 @@ zpl_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
out:

rw_exit(&zp->z_xattr_lock);
spl_fstrans_unmark(cookie);
crfree(cr);

return (error);
Expand Down Expand Up @@ -337,12 +340,15 @@ zpl_xattr_get(struct inode *ip, const char *name, void *value, size_t size)
{
znode_t *zp = ITOZ(ip);
cred_t *cr = CRED();
fstrans_cookie_t cookie;
int error;

crhold(cr);
cookie = spl_fstrans_mark();
rw_enter(&zp->z_xattr_lock, RW_READER);
error = __zpl_xattr_get(ip, name, value, size, cr);
rw_exit(&zp->z_xattr_lock);
spl_fstrans_unmark(cookie);
crfree(cr);

return (error);
Expand Down Expand Up @@ -482,9 +488,11 @@ zpl_xattr_set(struct inode *ip, const char *name, const void *value,
znode_t *zp = ITOZ(ip);
zfs_sb_t *zsb = ZTOZSB(zp);
cred_t *cr = CRED();
fstrans_cookie_t cookie;
int error;

crhold(cr);
cookie = spl_fstrans_mark();
rw_enter(&ITOZ(ip)->z_xattr_lock, RW_WRITER);

/*
Expand Down Expand Up @@ -522,6 +530,7 @@ zpl_xattr_set(struct inode *ip, const char *name, const void *value,
error = zpl_xattr_set_dir(ip, name, value, size, flags, cr);
out:
rw_exit(&ITOZ(ip)->z_xattr_lock);
spl_fstrans_unmark(cookie);
crfree(cr);
ASSERT3S(error, <=, 0);

Expand Down

0 comments on commit 1cf8f03

Please sign in to comment.