aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs/dir.c')
-rw-r--r--fs/nfs/dir.c62
1 files changed, 12 insertions, 50 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index b1940660502f..28a238dab23a 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -139,10 +139,8 @@ nfs_opendir(struct inode *inode, struct file *filp)
139 139
140 nfs_inc_stats(inode, NFSIOS_VFSOPEN); 140 nfs_inc_stats(inode, NFSIOS_VFSOPEN);
141 141
142 lock_kernel();
143 /* Call generic open code in order to cache credentials */ 142 /* Call generic open code in order to cache credentials */
144 res = nfs_open(inode, filp); 143 res = nfs_open(inode, filp);
145 unlock_kernel();
146 return res; 144 return res;
147} 145}
148 146
@@ -536,8 +534,6 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
536 (long long)filp->f_pos); 534 (long long)filp->f_pos);
537 nfs_inc_stats(inode, NFSIOS_VFSGETDENTS); 535 nfs_inc_stats(inode, NFSIOS_VFSGETDENTS);
538 536
539 lock_kernel();
540
541 /* 537 /*
542 * filp->f_pos points to the dirent entry number. 538 * filp->f_pos points to the dirent entry number.
543 * *desc->dir_cookie has the cookie for the next entry. We have 539 * *desc->dir_cookie has the cookie for the next entry. We have
@@ -595,7 +591,6 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
595 } 591 }
596out: 592out:
597 nfs_unblock_sillyrename(dentry); 593 nfs_unblock_sillyrename(dentry);
598 unlock_kernel();
599 if (res > 0) 594 if (res > 0)
600 res = 0; 595 res = 0;
601 dfprintk(FILE, "NFS: readdir(%s/%s) returns %ld\n", 596 dfprintk(FILE, "NFS: readdir(%s/%s) returns %ld\n",
@@ -779,7 +774,6 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
779 struct nfs_fattr fattr; 774 struct nfs_fattr fattr;
780 775
781 parent = dget_parent(dentry); 776 parent = dget_parent(dentry);
782 lock_kernel();
783 dir = parent->d_inode; 777 dir = parent->d_inode;
784 nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE); 778 nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE);
785 inode = dentry->d_inode; 779 inode = dentry->d_inode;
@@ -817,7 +811,6 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
817 811
818 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 812 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
819 out_valid: 813 out_valid:
820 unlock_kernel();
821 dput(parent); 814 dput(parent);
822 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is valid\n", 815 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is valid\n",
823 __func__, dentry->d_parent->d_name.name, 816 __func__, dentry->d_parent->d_name.name,
@@ -836,7 +829,6 @@ out_zap_parent:
836 shrink_dcache_parent(dentry); 829 shrink_dcache_parent(dentry);
837 } 830 }
838 d_drop(dentry); 831 d_drop(dentry);
839 unlock_kernel();
840 dput(parent); 832 dput(parent);
841 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n", 833 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n",
842 __func__, dentry->d_parent->d_name.name, 834 __func__, dentry->d_parent->d_name.name,
@@ -870,6 +862,14 @@ static int nfs_dentry_delete(struct dentry *dentry)
870 862
871} 863}
872 864
865static void nfs_drop_nlink(struct inode *inode)
866{
867 spin_lock(&inode->i_lock);
868 if (inode->i_nlink > 0)
869 drop_nlink(inode);
870 spin_unlock(&inode->i_lock);
871}
872
873/* 873/*
874 * Called when the dentry loses inode. 874 * Called when the dentry loses inode.
875 * We use it to clean up silly-renamed files. 875 * We use it to clean up silly-renamed files.
@@ -881,10 +881,8 @@ static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode)
881 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA; 881 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA;
882 882
883 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) { 883 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
884 lock_kernel();
885 drop_nlink(inode); 884 drop_nlink(inode);
886 nfs_complete_unlink(dentry, inode); 885 nfs_complete_unlink(dentry, inode);
887 unlock_kernel();
888 } 886 }
889 iput(inode); 887 iput(inode);
890} 888}
@@ -915,8 +913,6 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
915 res = ERR_PTR(-ENOMEM); 913 res = ERR_PTR(-ENOMEM);
916 dentry->d_op = NFS_PROTO(dir)->dentry_ops; 914 dentry->d_op = NFS_PROTO(dir)->dentry_ops;
917 915
918 lock_kernel();
919
920 /* 916 /*
921 * If we're doing an exclusive create, optimize away the lookup 917 * If we're doing an exclusive create, optimize away the lookup
922 * but don't hash the dentry. 918 * but don't hash the dentry.
@@ -924,7 +920,7 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
924 if (nfs_is_exclusive_create(dir, nd)) { 920 if (nfs_is_exclusive_create(dir, nd)) {
925 d_instantiate(dentry, NULL); 921 d_instantiate(dentry, NULL);
926 res = NULL; 922 res = NULL;
927 goto out_unlock; 923 goto out;
928 } 924 }
929 925
930 parent = dentry->d_parent; 926 parent = dentry->d_parent;
@@ -952,8 +948,6 @@ no_entry:
952 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 948 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
953out_unblock_sillyrename: 949out_unblock_sillyrename:
954 nfs_unblock_sillyrename(parent); 950 nfs_unblock_sillyrename(parent);
955out_unlock:
956 unlock_kernel();
957out: 951out:
958 return res; 952 return res;
959} 953}
@@ -1011,9 +1005,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1011 } 1005 }
1012 1006
1013 /* Open the file on the server */ 1007 /* Open the file on the server */
1014 lock_kernel();
1015 res = nfs4_atomic_open(dir, dentry, nd); 1008 res = nfs4_atomic_open(dir, dentry, nd);
1016 unlock_kernel();
1017 if (IS_ERR(res)) { 1009 if (IS_ERR(res)) {
1018 error = PTR_ERR(res); 1010 error = PTR_ERR(res);
1019 switch (error) { 1011 switch (error) {
@@ -1075,9 +1067,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1075 * operations that change the directory. We therefore save the 1067 * operations that change the directory. We therefore save the
1076 * change attribute *before* we do the RPC call. 1068 * change attribute *before* we do the RPC call.
1077 */ 1069 */
1078 lock_kernel();
1079 ret = nfs4_open_revalidate(dir, dentry, openflags, nd); 1070 ret = nfs4_open_revalidate(dir, dentry, openflags, nd);
1080 unlock_kernel();
1081out: 1071out:
1082 dput(parent); 1072 dput(parent);
1083 if (!ret) 1073 if (!ret)
@@ -1230,14 +1220,11 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode,
1230 if ((nd->flags & LOOKUP_CREATE) != 0) 1220 if ((nd->flags & LOOKUP_CREATE) != 0)
1231 open_flags = nd->intent.open.flags; 1221 open_flags = nd->intent.open.flags;
1232 1222
1233 lock_kernel();
1234 error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, nd); 1223 error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, nd);
1235 if (error != 0) 1224 if (error != 0)
1236 goto out_err; 1225 goto out_err;
1237 unlock_kernel();
1238 return 0; 1226 return 0;
1239out_err: 1227out_err:
1240 unlock_kernel();
1241 d_drop(dentry); 1228 d_drop(dentry);
1242 return error; 1229 return error;
1243} 1230}
@@ -1260,14 +1247,11 @@ nfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1260 attr.ia_mode = mode; 1247 attr.ia_mode = mode;
1261 attr.ia_valid = ATTR_MODE; 1248 attr.ia_valid = ATTR_MODE;
1262 1249
1263 lock_kernel();
1264 status = NFS_PROTO(dir)->mknod(dir, dentry, &attr, rdev); 1250 status = NFS_PROTO(dir)->mknod(dir, dentry, &attr, rdev);
1265 if (status != 0) 1251 if (status != 0)
1266 goto out_err; 1252 goto out_err;
1267 unlock_kernel();
1268 return 0; 1253 return 0;
1269out_err: 1254out_err:
1270 unlock_kernel();
1271 d_drop(dentry); 1255 d_drop(dentry);
1272 return status; 1256 return status;
1273} 1257}
@@ -1286,15 +1270,12 @@ static int nfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1286 attr.ia_valid = ATTR_MODE; 1270 attr.ia_valid = ATTR_MODE;
1287 attr.ia_mode = mode | S_IFDIR; 1271 attr.ia_mode = mode | S_IFDIR;
1288 1272
1289 lock_kernel();
1290 error = NFS_PROTO(dir)->mkdir(dir, dentry, &attr); 1273 error = NFS_PROTO(dir)->mkdir(dir, dentry, &attr);
1291 if (error != 0) 1274 if (error != 0)
1292 goto out_err; 1275 goto out_err;
1293 unlock_kernel();
1294 return 0; 1276 return 0;
1295out_err: 1277out_err:
1296 d_drop(dentry); 1278 d_drop(dentry);
1297 unlock_kernel();
1298 return error; 1279 return error;
1299} 1280}
1300 1281
@@ -1311,14 +1292,12 @@ static int nfs_rmdir(struct inode *dir, struct dentry *dentry)
1311 dfprintk(VFS, "NFS: rmdir(%s/%ld), %s\n", 1292 dfprintk(VFS, "NFS: rmdir(%s/%ld), %s\n",
1312 dir->i_sb->s_id, dir->i_ino, dentry->d_name.name); 1293 dir->i_sb->s_id, dir->i_ino, dentry->d_name.name);
1313 1294
1314 lock_kernel();
1315 error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name); 1295 error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name);
1316 /* Ensure the VFS deletes this inode */ 1296 /* Ensure the VFS deletes this inode */
1317 if (error == 0 && dentry->d_inode != NULL) 1297 if (error == 0 && dentry->d_inode != NULL)
1318 clear_nlink(dentry->d_inode); 1298 clear_nlink(dentry->d_inode);
1319 else if (error == -ENOENT) 1299 else if (error == -ENOENT)
1320 nfs_dentry_handle_enoent(dentry); 1300 nfs_dentry_handle_enoent(dentry);
1321 unlock_kernel();
1322 1301
1323 return error; 1302 return error;
1324} 1303}
@@ -1420,7 +1399,7 @@ static int nfs_safe_remove(struct dentry *dentry)
1420 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name); 1399 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
1421 /* The VFS may want to delete this inode */ 1400 /* The VFS may want to delete this inode */
1422 if (error == 0) 1401 if (error == 0)
1423 drop_nlink(inode); 1402 nfs_drop_nlink(inode);
1424 nfs_mark_for_revalidate(inode); 1403 nfs_mark_for_revalidate(inode);
1425 } else 1404 } else
1426 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name); 1405 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
@@ -1443,7 +1422,6 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
1443 dfprintk(VFS, "NFS: unlink(%s/%ld, %s)\n", dir->i_sb->s_id, 1422 dfprintk(VFS, "NFS: unlink(%s/%ld, %s)\n", dir->i_sb->s_id,
1444 dir->i_ino, dentry->d_name.name); 1423 dir->i_ino, dentry->d_name.name);
1445 1424
1446 lock_kernel();
1447 spin_lock(&dcache_lock); 1425 spin_lock(&dcache_lock);
1448 spin_lock(&dentry->d_lock); 1426 spin_lock(&dentry->d_lock);
1449 if (atomic_read(&dentry->d_count) > 1) { 1427 if (atomic_read(&dentry->d_count) > 1) {
@@ -1452,7 +1430,6 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
1452 /* Start asynchronous writeout of the inode */ 1430 /* Start asynchronous writeout of the inode */
1453 write_inode_now(dentry->d_inode, 0); 1431 write_inode_now(dentry->d_inode, 0);
1454 error = nfs_sillyrename(dir, dentry); 1432 error = nfs_sillyrename(dir, dentry);
1455 unlock_kernel();
1456 return error; 1433 return error;
1457 } 1434 }
1458 if (!d_unhashed(dentry)) { 1435 if (!d_unhashed(dentry)) {
@@ -1466,7 +1443,6 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
1466 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 1443 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1467 } else if (need_rehash) 1444 } else if (need_rehash)
1468 d_rehash(dentry); 1445 d_rehash(dentry);
1469 unlock_kernel();
1470 return error; 1446 return error;
1471} 1447}
1472 1448
@@ -1503,13 +1479,9 @@ static int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *sym
1503 attr.ia_mode = S_IFLNK | S_IRWXUGO; 1479 attr.ia_mode = S_IFLNK | S_IRWXUGO;
1504 attr.ia_valid = ATTR_MODE; 1480 attr.ia_valid = ATTR_MODE;
1505 1481
1506 lock_kernel();
1507
1508 page = alloc_page(GFP_HIGHUSER); 1482 page = alloc_page(GFP_HIGHUSER);
1509 if (!page) { 1483 if (!page)
1510 unlock_kernel();
1511 return -ENOMEM; 1484 return -ENOMEM;
1512 }
1513 1485
1514 kaddr = kmap_atomic(page, KM_USER0); 1486 kaddr = kmap_atomic(page, KM_USER0);
1515 memcpy(kaddr, symname, pathlen); 1487 memcpy(kaddr, symname, pathlen);
@@ -1524,7 +1496,6 @@ static int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *sym
1524 dentry->d_name.name, symname, error); 1496 dentry->d_name.name, symname, error);
1525 d_drop(dentry); 1497 d_drop(dentry);
1526 __free_page(page); 1498 __free_page(page);
1527 unlock_kernel();
1528 return error; 1499 return error;
1529 } 1500 }
1530 1501
@@ -1542,7 +1513,6 @@ static int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *sym
1542 } else 1513 } else
1543 __free_page(page); 1514 __free_page(page);
1544 1515
1545 unlock_kernel();
1546 return 0; 1516 return 0;
1547} 1517}
1548 1518
@@ -1556,14 +1526,12 @@ nfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
1556 old_dentry->d_parent->d_name.name, old_dentry->d_name.name, 1526 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
1557 dentry->d_parent->d_name.name, dentry->d_name.name); 1527 dentry->d_parent->d_name.name, dentry->d_name.name);
1558 1528
1559 lock_kernel();
1560 d_drop(dentry); 1529 d_drop(dentry);
1561 error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name); 1530 error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name);
1562 if (error == 0) { 1531 if (error == 0) {
1563 atomic_inc(&inode->i_count); 1532 atomic_inc(&inode->i_count);
1564 d_add(dentry, inode); 1533 d_add(dentry, inode);
1565 } 1534 }
1566 unlock_kernel();
1567 return error; 1535 return error;
1568} 1536}
1569 1537
@@ -1603,7 +1571,6 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1603 * To prevent any new references to the target during the rename, 1571 * To prevent any new references to the target during the rename,
1604 * we unhash the dentry and free the inode in advance. 1572 * we unhash the dentry and free the inode in advance.
1605 */ 1573 */
1606 lock_kernel();
1607 if (!d_unhashed(new_dentry)) { 1574 if (!d_unhashed(new_dentry)) {
1608 d_drop(new_dentry); 1575 d_drop(new_dentry);
1609 rehash = new_dentry; 1576 rehash = new_dentry;
@@ -1647,7 +1614,7 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1647 /* dentry still busy? */ 1614 /* dentry still busy? */
1648 goto out; 1615 goto out;
1649 } else 1616 } else
1650 drop_nlink(new_inode); 1617 nfs_drop_nlink(new_inode);
1651 1618
1652go_ahead: 1619go_ahead:
1653 /* 1620 /*
@@ -1681,7 +1648,6 @@ out:
1681 /* new dentry created? */ 1648 /* new dentry created? */
1682 if (dentry) 1649 if (dentry)
1683 dput(dentry); 1650 dput(dentry);
1684 unlock_kernel();
1685 return error; 1651 return error;
1686} 1652}
1687 1653
@@ -1974,8 +1940,6 @@ int nfs_permission(struct inode *inode, int mask, struct nameidata *nd)
1974 } 1940 }
1975 1941
1976force_lookup: 1942force_lookup:
1977 lock_kernel();
1978
1979 if (!NFS_PROTO(inode)->access) 1943 if (!NFS_PROTO(inode)->access)
1980 goto out_notsup; 1944 goto out_notsup;
1981 1945
@@ -1985,7 +1949,6 @@ force_lookup:
1985 put_rpccred(cred); 1949 put_rpccred(cred);
1986 } else 1950 } else
1987 res = PTR_ERR(cred); 1951 res = PTR_ERR(cred);
1988 unlock_kernel();
1989out: 1952out:
1990 dfprintk(VFS, "NFS: permission(%s/%ld), mask=0x%x, res=%d\n", 1953 dfprintk(VFS, "NFS: permission(%s/%ld), mask=0x%x, res=%d\n",
1991 inode->i_sb->s_id, inode->i_ino, mask, res); 1954 inode->i_sb->s_id, inode->i_ino, mask, res);
@@ -1994,7 +1957,6 @@ out_notsup:
1994 res = nfs_revalidate_inode(NFS_SERVER(inode), inode); 1957 res = nfs_revalidate_inode(NFS_SERVER(inode), inode);
1995 if (res == 0) 1958 if (res == 0)
1996 res = generic_permission(inode, mask, NULL); 1959 res = generic_permission(inode, mask, NULL);
1997 unlock_kernel();
1998 goto out; 1960 goto out;
1999} 1961}
2000 1962