aboutsummaryrefslogtreecommitdiffstats
path: root/module/zfs/zpl_inode.c
diff options
context:
space:
mode:
authorRichard Sharpe <[email protected]>2015-12-27 16:08:05 -0800
committerBrian Behlendorf <[email protected]>2016-01-08 11:05:07 -0800
commitc5d0287011679d76288c2617c409252245172a32 (patch)
tree756e4dac4ca8f871bcaab9879ca3c3c29606fad0 /module/zfs/zpl_inode.c
parent7cf2ffa02065fe0cbec13bfb7bf4fcfaabb3d40a (diff)
Fix casesensitivity=insensitive deadlock
When casesensitivity=insensitive is set for the file system, we can deadlock in a rename if the user uses different case for each path. For example rename("A/some-file.txt", "a/some-file.txt"). The simple test for this is: 1. mkdir some-dir in a ZFS file system 2. touch some-dir/some-file.txt 3. mv Some-dir/some-file.txt some-dir/some-other-file.txt This last request deadlocks trying to relock the i_mutex on the inode for the parent directory. The solution is to use d_add_ci in zpl_lookup if we are on a file system that has the casesensitivity=insensitive attribute set. This patch checks if we are working on a case insensitive file system and if so, allocates storage for the case insensitive name and passes it to zfs_lookup and then calls d_add_ci instead of d_splice_alias. The performance impact seems to be minimal even though we have introduced a kmalloc and kfree in the lookup path. The problem was found when running Microsoft's FSCT against Samba on top of ZFS On Linux. Signed-off-by: Richard Sharpe <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #4136
Diffstat (limited to 'module/zfs/zpl_inode.c')
-rw-r--r--module/zfs/zpl_inode.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/module/zfs/zpl_inode.c b/module/zfs/zpl_inode.c
index e0e8ee3ac..69a5db4da 100644
--- a/module/zfs/zpl_inode.c
+++ b/module/zfs/zpl_inode.c
@@ -44,13 +44,24 @@ zpl_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
struct inode *ip;
int error;
fstrans_cookie_t cookie;
+ pathname_t *ppn = NULL;
+ pathname_t pn;
+ zfs_sb_t *zsb = dentry->d_sb->s_fs_info;
if (dlen(dentry) > ZFS_MAXNAMELEN)
return (ERR_PTR(-ENAMETOOLONG));
crhold(cr);
cookie = spl_fstrans_mark();
- error = -zfs_lookup(dir, dname(dentry), &ip, 0, cr, NULL, NULL);
+
+ /* If we are a case insensitive fs, we need the real name */
+ if (zsb->z_case == ZFS_CASE_INSENSITIVE) {
+ pn.pn_bufsize = ZFS_MAXNAMELEN;
+ pn.pn_buf = kmem_zalloc(ZFS_MAXNAMELEN, KM_SLEEP);
+ ppn = &pn;
+ }
+
+ error = -zfs_lookup(dir, dname(dentry), &ip, 0, cr, NULL, ppn);
spl_fstrans_unmark(cookie);
ASSERT3S(error, <=, 0);
crfree(cr);
@@ -63,13 +74,30 @@ zpl_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
spin_unlock(&dentry->d_lock);
if (error) {
+ if (ppn)
+ kmem_free(pn.pn_buf, ZFS_MAXNAMELEN);
if (error == -ENOENT)
return (d_splice_alias(NULL, dentry));
else
return (ERR_PTR(error));
}
- return (d_splice_alias(ip, dentry));
+ /*
+ * If we are case insensitive, call the correct function
+ * to install the name.
+ */
+ if (ppn) {
+ struct dentry *new_dentry;
+ struct qstr ci_name;
+
+ ci_name.name = pn.pn_buf;
+ ci_name.len = strlen(pn.pn_buf);
+ new_dentry = d_add_ci(dentry, ip, &ci_name);
+ kmem_free(pn.pn_buf, ZFS_MAXNAMELEN);
+ return (new_dentry);
+ } else {
+ return (d_splice_alias(ip, dentry));
+ }
}
void