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.c90
1 files changed, 32 insertions, 58 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 58d43daec084..28a238dab23a 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -133,13 +133,14 @@ nfs_opendir(struct inode *inode, struct file *filp)
133{ 133{
134 int res; 134 int res;
135 135
136 dfprintk(VFS, "NFS: opendir(%s/%ld)\n", 136 dfprintk(FILE, "NFS: open dir(%s/%s)\n",
137 inode->i_sb->s_id, inode->i_ino); 137 filp->f_path.dentry->d_parent->d_name.name,
138 filp->f_path.dentry->d_name.name);
139
140 nfs_inc_stats(inode, NFSIOS_VFSOPEN);
138 141
139 lock_kernel();
140 /* Call generic open code in order to cache credentials */ 142 /* Call generic open code in order to cache credentials */
141 res = nfs_open(inode, filp); 143 res = nfs_open(inode, filp);
142 unlock_kernel();
143 return res; 144 return res;
144} 145}
145 146
@@ -204,7 +205,7 @@ int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page *page)
204 * Note: assumes we have exclusive access to this mapping either 205 * Note: assumes we have exclusive access to this mapping either
205 * through inode->i_mutex or some other mechanism. 206 * through inode->i_mutex or some other mechanism.
206 */ 207 */
207 if (page->index == 0 && invalidate_inode_pages2_range(inode->i_mapping, PAGE_CACHE_SIZE, -1) < 0) { 208 if (invalidate_inode_pages2_range(inode->i_mapping, page->index + 1, -1) < 0) {
208 /* Should never happen */ 209 /* Should never happen */
209 nfs_zap_mapping(inode, inode->i_mapping); 210 nfs_zap_mapping(inode, inode->i_mapping);
210 } 211 }
@@ -528,13 +529,11 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
528 struct nfs_fattr fattr; 529 struct nfs_fattr fattr;
529 long res; 530 long res;
530 531
531 dfprintk(VFS, "NFS: readdir(%s/%s) starting at cookie %Lu\n", 532 dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n",
532 dentry->d_parent->d_name.name, dentry->d_name.name, 533 dentry->d_parent->d_name.name, dentry->d_name.name,
533 (long long)filp->f_pos); 534 (long long)filp->f_pos);
534 nfs_inc_stats(inode, NFSIOS_VFSGETDENTS); 535 nfs_inc_stats(inode, NFSIOS_VFSGETDENTS);
535 536
536 lock_kernel();
537
538 /* 537 /*
539 * filp->f_pos points to the dirent entry number. 538 * filp->f_pos points to the dirent entry number.
540 * *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
@@ -592,10 +591,9 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
592 } 591 }
593out: 592out:
594 nfs_unblock_sillyrename(dentry); 593 nfs_unblock_sillyrename(dentry);
595 unlock_kernel();
596 if (res > 0) 594 if (res > 0)
597 res = 0; 595 res = 0;
598 dfprintk(VFS, "NFS: readdir(%s/%s) returns %ld\n", 596 dfprintk(FILE, "NFS: readdir(%s/%s) returns %ld\n",
599 dentry->d_parent->d_name.name, dentry->d_name.name, 597 dentry->d_parent->d_name.name, dentry->d_name.name,
600 res); 598 res);
601 return res; 599 return res;
@@ -603,7 +601,15 @@ out:
603 601
604static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int origin) 602static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int origin)
605{ 603{
606 mutex_lock(&filp->f_path.dentry->d_inode->i_mutex); 604 struct dentry *dentry = filp->f_path.dentry;
605 struct inode *inode = dentry->d_inode;
606
607 dfprintk(FILE, "NFS: llseek dir(%s/%s, %lld, %d)\n",
608 dentry->d_parent->d_name.name,
609 dentry->d_name.name,
610 offset, origin);
611
612 mutex_lock(&inode->i_mutex);
607 switch (origin) { 613 switch (origin) {
608 case 1: 614 case 1:
609 offset += filp->f_pos; 615 offset += filp->f_pos;
@@ -619,7 +625,7 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int origin)
619 nfs_file_open_context(filp)->dir_cookie = 0; 625 nfs_file_open_context(filp)->dir_cookie = 0;
620 } 626 }
621out: 627out:
622 mutex_unlock(&filp->f_path.dentry->d_inode->i_mutex); 628 mutex_unlock(&inode->i_mutex);
623 return offset; 629 return offset;
624} 630}
625 631
@@ -629,10 +635,11 @@ out:
629 */ 635 */
630static int nfs_fsync_dir(struct file *filp, struct dentry *dentry, int datasync) 636static int nfs_fsync_dir(struct file *filp, struct dentry *dentry, int datasync)
631{ 637{
632 dfprintk(VFS, "NFS: fsync_dir(%s/%s) datasync %d\n", 638 dfprintk(FILE, "NFS: fsync dir(%s/%s) datasync %d\n",
633 dentry->d_parent->d_name.name, dentry->d_name.name, 639 dentry->d_parent->d_name.name, dentry->d_name.name,
634 datasync); 640 datasync);
635 641
642 nfs_inc_stats(dentry->d_inode, NFSIOS_VFSFSYNC);
636 return 0; 643 return 0;
637} 644}
638 645
@@ -767,7 +774,6 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
767 struct nfs_fattr fattr; 774 struct nfs_fattr fattr;
768 775
769 parent = dget_parent(dentry); 776 parent = dget_parent(dentry);
770 lock_kernel();
771 dir = parent->d_inode; 777 dir = parent->d_inode;
772 nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE); 778 nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE);
773 inode = dentry->d_inode; 779 inode = dentry->d_inode;
@@ -805,7 +811,6 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
805 811
806 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 812 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
807 out_valid: 813 out_valid:
808 unlock_kernel();
809 dput(parent); 814 dput(parent);
810 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is valid\n", 815 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is valid\n",
811 __func__, dentry->d_parent->d_name.name, 816 __func__, dentry->d_parent->d_name.name,
@@ -824,7 +829,6 @@ out_zap_parent:
824 shrink_dcache_parent(dentry); 829 shrink_dcache_parent(dentry);
825 } 830 }
826 d_drop(dentry); 831 d_drop(dentry);
827 unlock_kernel();
828 dput(parent); 832 dput(parent);
829 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n", 833 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n",
830 __func__, dentry->d_parent->d_name.name, 834 __func__, dentry->d_parent->d_name.name,
@@ -858,6 +862,14 @@ static int nfs_dentry_delete(struct dentry *dentry)
858 862
859} 863}
860 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
861/* 873/*
862 * Called when the dentry loses inode. 874 * Called when the dentry loses inode.
863 * We use it to clean up silly-renamed files. 875 * We use it to clean up silly-renamed files.
@@ -869,10 +881,8 @@ static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode)
869 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA; 881 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA;
870 882
871 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) { 883 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
872 lock_kernel();
873 drop_nlink(inode); 884 drop_nlink(inode);
874 nfs_complete_unlink(dentry, inode); 885 nfs_complete_unlink(dentry, inode);
875 unlock_kernel();
876 } 886 }
877 iput(inode); 887 iput(inode);
878} 888}
@@ -903,8 +913,6 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
903 res = ERR_PTR(-ENOMEM); 913 res = ERR_PTR(-ENOMEM);
904 dentry->d_op = NFS_PROTO(dir)->dentry_ops; 914 dentry->d_op = NFS_PROTO(dir)->dentry_ops;
905 915
906 lock_kernel();
907
908 /* 916 /*
909 * If we're doing an exclusive create, optimize away the lookup 917 * If we're doing an exclusive create, optimize away the lookup
910 * but don't hash the dentry. 918 * but don't hash the dentry.
@@ -912,7 +920,7 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
912 if (nfs_is_exclusive_create(dir, nd)) { 920 if (nfs_is_exclusive_create(dir, nd)) {
913 d_instantiate(dentry, NULL); 921 d_instantiate(dentry, NULL);
914 res = NULL; 922 res = NULL;
915 goto out_unlock; 923 goto out;
916 } 924 }
917 925
918 parent = dentry->d_parent; 926 parent = dentry->d_parent;
@@ -940,8 +948,6 @@ no_entry:
940 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 948 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
941out_unblock_sillyrename: 949out_unblock_sillyrename:
942 nfs_unblock_sillyrename(parent); 950 nfs_unblock_sillyrename(parent);
943out_unlock:
944 unlock_kernel();
945out: 951out:
946 return res; 952 return res;
947} 953}
@@ -999,9 +1005,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
999 } 1005 }
1000 1006
1001 /* Open the file on the server */ 1007 /* Open the file on the server */
1002 lock_kernel();
1003 res = nfs4_atomic_open(dir, dentry, nd); 1008 res = nfs4_atomic_open(dir, dentry, nd);
1004 unlock_kernel();
1005 if (IS_ERR(res)) { 1009 if (IS_ERR(res)) {
1006 error = PTR_ERR(res); 1010 error = PTR_ERR(res);
1007 switch (error) { 1011 switch (error) {
@@ -1063,9 +1067,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1063 * operations that change the directory. We therefore save the 1067 * operations that change the directory. We therefore save the
1064 * change attribute *before* we do the RPC call. 1068 * change attribute *before* we do the RPC call.
1065 */ 1069 */
1066 lock_kernel();
1067 ret = nfs4_open_revalidate(dir, dentry, openflags, nd); 1070 ret = nfs4_open_revalidate(dir, dentry, openflags, nd);
1068 unlock_kernel();
1069out: 1071out:
1070 dput(parent); 1072 dput(parent);
1071 if (!ret) 1073 if (!ret)
@@ -1218,14 +1220,11 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode,
1218 if ((nd->flags & LOOKUP_CREATE) != 0) 1220 if ((nd->flags & LOOKUP_CREATE) != 0)
1219 open_flags = nd->intent.open.flags; 1221 open_flags = nd->intent.open.flags;
1220 1222
1221 lock_kernel();
1222 error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, nd); 1223 error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, nd);
1223 if (error != 0) 1224 if (error != 0)
1224 goto out_err; 1225 goto out_err;
1225 unlock_kernel();
1226 return 0; 1226 return 0;
1227out_err: 1227out_err:
1228 unlock_kernel();
1229 d_drop(dentry); 1228 d_drop(dentry);
1230 return error; 1229 return error;
1231} 1230}
@@ -1248,14 +1247,11 @@ nfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1248 attr.ia_mode = mode; 1247 attr.ia_mode = mode;
1249 attr.ia_valid = ATTR_MODE; 1248 attr.ia_valid = ATTR_MODE;
1250 1249
1251 lock_kernel();
1252 status = NFS_PROTO(dir)->mknod(dir, dentry, &attr, rdev); 1250 status = NFS_PROTO(dir)->mknod(dir, dentry, &attr, rdev);
1253 if (status != 0) 1251 if (status != 0)
1254 goto out_err; 1252 goto out_err;
1255 unlock_kernel();
1256 return 0; 1253 return 0;
1257out_err: 1254out_err:
1258 unlock_kernel();
1259 d_drop(dentry); 1255 d_drop(dentry);
1260 return status; 1256 return status;
1261} 1257}
@@ -1274,15 +1270,12 @@ static int nfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1274 attr.ia_valid = ATTR_MODE; 1270 attr.ia_valid = ATTR_MODE;
1275 attr.ia_mode = mode | S_IFDIR; 1271 attr.ia_mode = mode | S_IFDIR;
1276 1272
1277 lock_kernel();
1278 error = NFS_PROTO(dir)->mkdir(dir, dentry, &attr); 1273 error = NFS_PROTO(dir)->mkdir(dir, dentry, &attr);
1279 if (error != 0) 1274 if (error != 0)
1280 goto out_err; 1275 goto out_err;
1281 unlock_kernel();
1282 return 0; 1276 return 0;
1283out_err: 1277out_err:
1284 d_drop(dentry); 1278 d_drop(dentry);
1285 unlock_kernel();
1286 return error; 1279 return error;
1287} 1280}
1288 1281
@@ -1299,14 +1292,12 @@ static int nfs_rmdir(struct inode *dir, struct dentry *dentry)
1299 dfprintk(VFS, "NFS: rmdir(%s/%ld), %s\n", 1292 dfprintk(VFS, "NFS: rmdir(%s/%ld), %s\n",
1300 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);
1301 1294
1302 lock_kernel();
1303 error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name); 1295 error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name);
1304 /* Ensure the VFS deletes this inode */ 1296 /* Ensure the VFS deletes this inode */
1305 if (error == 0 && dentry->d_inode != NULL) 1297 if (error == 0 && dentry->d_inode != NULL)
1306 clear_nlink(dentry->d_inode); 1298 clear_nlink(dentry->d_inode);
1307 else if (error == -ENOENT) 1299 else if (error == -ENOENT)
1308 nfs_dentry_handle_enoent(dentry); 1300 nfs_dentry_handle_enoent(dentry);
1309 unlock_kernel();
1310 1301
1311 return error; 1302 return error;
1312} 1303}
@@ -1408,7 +1399,7 @@ static int nfs_safe_remove(struct dentry *dentry)
1408 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name); 1399 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
1409 /* The VFS may want to delete this inode */ 1400 /* The VFS may want to delete this inode */
1410 if (error == 0) 1401 if (error == 0)
1411 drop_nlink(inode); 1402 nfs_drop_nlink(inode);
1412 nfs_mark_for_revalidate(inode); 1403 nfs_mark_for_revalidate(inode);
1413 } else 1404 } else
1414 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name); 1405 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
@@ -1431,7 +1422,6 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
1431 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,
1432 dir->i_ino, dentry->d_name.name); 1423 dir->i_ino, dentry->d_name.name);
1433 1424
1434 lock_kernel();
1435 spin_lock(&dcache_lock); 1425 spin_lock(&dcache_lock);
1436 spin_lock(&dentry->d_lock); 1426 spin_lock(&dentry->d_lock);
1437 if (atomic_read(&dentry->d_count) > 1) { 1427 if (atomic_read(&dentry->d_count) > 1) {
@@ -1440,7 +1430,6 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
1440 /* Start asynchronous writeout of the inode */ 1430 /* Start asynchronous writeout of the inode */
1441 write_inode_now(dentry->d_inode, 0); 1431 write_inode_now(dentry->d_inode, 0);
1442 error = nfs_sillyrename(dir, dentry); 1432 error = nfs_sillyrename(dir, dentry);
1443 unlock_kernel();
1444 return error; 1433 return error;
1445 } 1434 }
1446 if (!d_unhashed(dentry)) { 1435 if (!d_unhashed(dentry)) {
@@ -1454,7 +1443,6 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
1454 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 1443 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1455 } else if (need_rehash) 1444 } else if (need_rehash)
1456 d_rehash(dentry); 1445 d_rehash(dentry);
1457 unlock_kernel();
1458 return error; 1446 return error;
1459} 1447}
1460 1448
@@ -1491,13 +1479,9 @@ static int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *sym
1491 attr.ia_mode = S_IFLNK | S_IRWXUGO; 1479 attr.ia_mode = S_IFLNK | S_IRWXUGO;
1492 attr.ia_valid = ATTR_MODE; 1480 attr.ia_valid = ATTR_MODE;
1493 1481
1494 lock_kernel();
1495
1496 page = alloc_page(GFP_HIGHUSER); 1482 page = alloc_page(GFP_HIGHUSER);
1497 if (!page) { 1483 if (!page)
1498 unlock_kernel();
1499 return -ENOMEM; 1484 return -ENOMEM;
1500 }
1501 1485
1502 kaddr = kmap_atomic(page, KM_USER0); 1486 kaddr = kmap_atomic(page, KM_USER0);
1503 memcpy(kaddr, symname, pathlen); 1487 memcpy(kaddr, symname, pathlen);
@@ -1512,7 +1496,6 @@ static int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *sym
1512 dentry->d_name.name, symname, error); 1496 dentry->d_name.name, symname, error);
1513 d_drop(dentry); 1497 d_drop(dentry);
1514 __free_page(page); 1498 __free_page(page);
1515 unlock_kernel();
1516 return error; 1499 return error;
1517 } 1500 }
1518 1501
@@ -1530,7 +1513,6 @@ static int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *sym
1530 } else 1513 } else
1531 __free_page(page); 1514 __free_page(page);
1532 1515
1533 unlock_kernel();
1534 return 0; 1516 return 0;
1535} 1517}
1536 1518
@@ -1544,14 +1526,12 @@ nfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
1544 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,
1545 dentry->d_parent->d_name.name, dentry->d_name.name); 1527 dentry->d_parent->d_name.name, dentry->d_name.name);
1546 1528
1547 lock_kernel();
1548 d_drop(dentry); 1529 d_drop(dentry);
1549 error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name); 1530 error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name);
1550 if (error == 0) { 1531 if (error == 0) {
1551 atomic_inc(&inode->i_count); 1532 atomic_inc(&inode->i_count);
1552 d_add(dentry, inode); 1533 d_add(dentry, inode);
1553 } 1534 }
1554 unlock_kernel();
1555 return error; 1535 return error;
1556} 1536}
1557 1537
@@ -1591,7 +1571,6 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1591 * To prevent any new references to the target during the rename, 1571 * To prevent any new references to the target during the rename,
1592 * we unhash the dentry and free the inode in advance. 1572 * we unhash the dentry and free the inode in advance.
1593 */ 1573 */
1594 lock_kernel();
1595 if (!d_unhashed(new_dentry)) { 1574 if (!d_unhashed(new_dentry)) {
1596 d_drop(new_dentry); 1575 d_drop(new_dentry);
1597 rehash = new_dentry; 1576 rehash = new_dentry;
@@ -1635,7 +1614,7 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1635 /* dentry still busy? */ 1614 /* dentry still busy? */
1636 goto out; 1615 goto out;
1637 } else 1616 } else
1638 drop_nlink(new_inode); 1617 nfs_drop_nlink(new_inode);
1639 1618
1640go_ahead: 1619go_ahead:
1641 /* 1620 /*
@@ -1669,7 +1648,6 @@ out:
1669 /* new dentry created? */ 1648 /* new dentry created? */
1670 if (dentry) 1649 if (dentry)
1671 dput(dentry); 1650 dput(dentry);
1672 unlock_kernel();
1673 return error; 1651 return error;
1674} 1652}
1675 1653
@@ -1962,8 +1940,6 @@ int nfs_permission(struct inode *inode, int mask, struct nameidata *nd)
1962 } 1940 }
1963 1941
1964force_lookup: 1942force_lookup:
1965 lock_kernel();
1966
1967 if (!NFS_PROTO(inode)->access) 1943 if (!NFS_PROTO(inode)->access)
1968 goto out_notsup; 1944 goto out_notsup;
1969 1945
@@ -1973,7 +1949,6 @@ force_lookup:
1973 put_rpccred(cred); 1949 put_rpccred(cred);
1974 } else 1950 } else
1975 res = PTR_ERR(cred); 1951 res = PTR_ERR(cred);
1976 unlock_kernel();
1977out: 1952out:
1978 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",
1979 inode->i_sb->s_id, inode->i_ino, mask, res); 1954 inode->i_sb->s_id, inode->i_ino, mask, res);
@@ -1982,7 +1957,6 @@ out_notsup:
1982 res = nfs_revalidate_inode(NFS_SERVER(inode), inode); 1957 res = nfs_revalidate_inode(NFS_SERVER(inode), inode);
1983 if (res == 0) 1958 if (res == 0)
1984 res = generic_permission(inode, mask, NULL); 1959 res = generic_permission(inode, mask, NULL);
1985 unlock_kernel();
1986 goto out; 1960 goto out;
1987} 1961}
1988 1962