dir.c (facc3530fb5c89a40bc83045422add392b8db4a1) dir.c (fa3c56bbda6c2ac2a57d96ba501dbe85cccd312b)
1/*
2 * linux/fs/nfs/dir.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs directory handling functions
7 *
8 * 10 Apr 1996 Added silly rename for unlink --okir

--- 1017 unchanged lines hidden (view full) ---

1026 if (nfs_revalidate_inode(NFS_SERVER(dir), dir) < 0)
1027 return 0;
1028 if (!nfs_verify_change_attribute(dir, dentry->d_time))
1029 return 0;
1030 return 1;
1031}
1032
1033/*
1/*
2 * linux/fs/nfs/dir.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs directory handling functions
7 *
8 * 10 Apr 1996 Added silly rename for unlink --okir

--- 1017 unchanged lines hidden (view full) ---

1026 if (nfs_revalidate_inode(NFS_SERVER(dir), dir) < 0)
1027 return 0;
1028 if (!nfs_verify_change_attribute(dir, dentry->d_time))
1029 return 0;
1030 return 1;
1031}
1032
1033/*
1034 * Return the intent data that applies to this particular path component
1035 *
1036 * Note that the current set of intents only apply to the very last
1037 * component of the path and none of them is set before that last
1038 * component.
1039 */
1040static inline unsigned int nfs_lookup_check_intent(unsigned int flags,
1041 unsigned int mask)
1042{
1043 return flags & mask;
1044}
1045
1046/*
1047 * Use intent information to check whether or not we're going to do
1048 * an O_EXCL create using this path component.
1049 */
1034 * Use intent information to check whether or not we're going to do
1035 * an O_EXCL create using this path component.
1036 */
1050static int nfs_is_exclusive_create(struct inode *dir, struct nameidata *nd)
1037static int nfs_is_exclusive_create(struct inode *dir, unsigned int flags)
1051{
1052 if (NFS_PROTO(dir)->version == 2)
1053 return 0;
1038{
1039 if (NFS_PROTO(dir)->version == 2)
1040 return 0;
1054 return nd && nfs_lookup_check_intent(nd->flags, LOOKUP_EXCL);
1041 return flags & LOOKUP_EXCL;
1055}
1056
1057/*
1058 * Inode and filehandle revalidation for lookups.
1059 *
1060 * We force revalidation in the cases where the VFS sets LOOKUP_REVAL,
1061 * or if the intent information indicates that we're about to open this
1062 * particular file and the "nocto" mount flag is not set.
1063 *
1064 */
1065static inline
1042}
1043
1044/*
1045 * Inode and filehandle revalidation for lookups.
1046 *
1047 * We force revalidation in the cases where the VFS sets LOOKUP_REVAL,
1048 * or if the intent information indicates that we're about to open this
1049 * particular file and the "nocto" mount flag is not set.
1050 *
1051 */
1052static inline
1066int nfs_lookup_verify_inode(struct inode *inode, struct nameidata *nd)
1053int nfs_lookup_verify_inode(struct inode *inode, unsigned int flags)
1067{
1068 struct nfs_server *server = NFS_SERVER(inode);
1069
1070 if (IS_AUTOMOUNT(inode))
1071 return 0;
1072 /* VFS wants an on-the-wire revalidation */
1054{
1055 struct nfs_server *server = NFS_SERVER(inode);
1056
1057 if (IS_AUTOMOUNT(inode))
1058 return 0;
1059 /* VFS wants an on-the-wire revalidation */
1073 if (nd->flags & LOOKUP_REVAL)
1060 if (flags & LOOKUP_REVAL)
1074 goto out_force;
1075 /* This is an open(2) */
1061 goto out_force;
1062 /* This is an open(2) */
1076 if (nfs_lookup_check_intent(nd->flags, LOOKUP_OPEN) != 0 &&
1077 !(server->flags & NFS_MOUNT_NOCTO) &&
1078 (S_ISREG(inode->i_mode) ||
1079 S_ISDIR(inode->i_mode)))
1063 if ((flags & LOOKUP_OPEN) && !(server->flags & NFS_MOUNT_NOCTO) &&
1064 (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)))
1080 goto out_force;
1081 return 0;
1082out_force:
1083 return __nfs_revalidate_inode(server, inode);
1084}
1085
1086/*
1087 * We judge how long we want to trust negative
1088 * dentries by looking at the parent inode mtime.
1089 *
1090 * If parent mtime has changed, we revalidate, else we wait for a
1091 * period corresponding to the parent's attribute cache timeout value.
1092 */
1093static inline
1094int nfs_neg_need_reval(struct inode *dir, struct dentry *dentry,
1065 goto out_force;
1066 return 0;
1067out_force:
1068 return __nfs_revalidate_inode(server, inode);
1069}
1070
1071/*
1072 * We judge how long we want to trust negative
1073 * dentries by looking at the parent inode mtime.
1074 *
1075 * If parent mtime has changed, we revalidate, else we wait for a
1076 * period corresponding to the parent's attribute cache timeout value.
1077 */
1078static inline
1079int nfs_neg_need_reval(struct inode *dir, struct dentry *dentry,
1095 struct nameidata *nd)
1080 unsigned int flags)
1096{
1097 /* Don't revalidate a negative dentry if we're creating a new file */
1081{
1082 /* Don't revalidate a negative dentry if we're creating a new file */
1098 if (nd != NULL && nfs_lookup_check_intent(nd->flags, LOOKUP_CREATE) != 0)
1083 if (flags & LOOKUP_CREATE)
1099 return 0;
1100 if (NFS_SERVER(dir)->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG)
1101 return 1;
1102 return !nfs_check_verifier(dir, dentry);
1103}
1104
1105/*
1106 * This is called every time the dcache has a lookup hit,
1107 * and we should check whether we can really trust that
1108 * lookup.
1109 *
1110 * NOTE! The hit can be a negative hit too, don't assume
1111 * we have an inode!
1112 *
1113 * If the parent directory is seen to have changed, we throw out the
1114 * cached dentry and do a new lookup.
1115 */
1116static int nfs_lookup_revalidate(struct dentry *dentry, struct nameidata *nd)
1117{
1084 return 0;
1085 if (NFS_SERVER(dir)->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG)
1086 return 1;
1087 return !nfs_check_verifier(dir, dentry);
1088}
1089
1090/*
1091 * This is called every time the dcache has a lookup hit,
1092 * and we should check whether we can really trust that
1093 * lookup.
1094 *
1095 * NOTE! The hit can be a negative hit too, don't assume
1096 * we have an inode!
1097 *
1098 * If the parent directory is seen to have changed, we throw out the
1099 * cached dentry and do a new lookup.
1100 */
1101static int nfs_lookup_revalidate(struct dentry *dentry, struct nameidata *nd)
1102{
1103 unsigned int flags = nd->flags;
1118 struct inode *dir;
1119 struct inode *inode;
1120 struct dentry *parent;
1121 struct nfs_fh *fhandle = NULL;
1122 struct nfs_fattr *fattr = NULL;
1123 int error;
1124
1104 struct inode *dir;
1105 struct inode *inode;
1106 struct dentry *parent;
1107 struct nfs_fh *fhandle = NULL;
1108 struct nfs_fattr *fattr = NULL;
1109 int error;
1110
1125 if (nd->flags & LOOKUP_RCU)
1111 if (flags & LOOKUP_RCU)
1126 return -ECHILD;
1127
1128 parent = dget_parent(dentry);
1129 dir = parent->d_inode;
1130 nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE);
1131 inode = dentry->d_inode;
1132
1133 if (!inode) {
1112 return -ECHILD;
1113
1114 parent = dget_parent(dentry);
1115 dir = parent->d_inode;
1116 nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE);
1117 inode = dentry->d_inode;
1118
1119 if (!inode) {
1134 if (nfs_neg_need_reval(dir, dentry, nd))
1120 if (nfs_neg_need_reval(dir, dentry, flags))
1135 goto out_bad;
1136 goto out_valid_noent;
1137 }
1138
1139 if (is_bad_inode(inode)) {
1140 dfprintk(LOOKUPCACHE, "%s: %s/%s has dud inode\n",
1141 __func__, dentry->d_parent->d_name.name,
1142 dentry->d_name.name);
1143 goto out_bad;
1144 }
1145
1146 if (nfs_have_delegation(inode, FMODE_READ))
1147 goto out_set_verifier;
1148
1149 /* Force a full look up iff the parent directory has changed */
1121 goto out_bad;
1122 goto out_valid_noent;
1123 }
1124
1125 if (is_bad_inode(inode)) {
1126 dfprintk(LOOKUPCACHE, "%s: %s/%s has dud inode\n",
1127 __func__, dentry->d_parent->d_name.name,
1128 dentry->d_name.name);
1129 goto out_bad;
1130 }
1131
1132 if (nfs_have_delegation(inode, FMODE_READ))
1133 goto out_set_verifier;
1134
1135 /* Force a full look up iff the parent directory has changed */
1150 if (!nfs_is_exclusive_create(dir, nd) && nfs_check_verifier(dir, dentry)) {
1151 if (nfs_lookup_verify_inode(inode, nd))
1136 if (!nfs_is_exclusive_create(dir, flags) && nfs_check_verifier(dir, dentry)) {
1137 if (nfs_lookup_verify_inode(inode, flags))
1152 goto out_zap_parent;
1153 goto out_valid;
1154 }
1155
1156 if (NFS_STALE(inode))
1157 goto out_bad;
1158
1159 error = -ENOMEM;

--- 141 unchanged lines hidden (view full) ---

1301 res = ERR_PTR(-ENAMETOOLONG);
1302 if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
1303 goto out;
1304
1305 /*
1306 * If we're doing an exclusive create, optimize away the lookup
1307 * but don't hash the dentry.
1308 */
1138 goto out_zap_parent;
1139 goto out_valid;
1140 }
1141
1142 if (NFS_STALE(inode))
1143 goto out_bad;
1144
1145 error = -ENOMEM;

--- 141 unchanged lines hidden (view full) ---

1287 res = ERR_PTR(-ENAMETOOLONG);
1288 if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
1289 goto out;
1290
1291 /*
1292 * If we're doing an exclusive create, optimize away the lookup
1293 * but don't hash the dentry.
1294 */
1309 if (nfs_is_exclusive_create(dir, nd)) {
1295 if (nd && nfs_is_exclusive_create(dir, nd->flags)) {
1310 d_instantiate(dentry, NULL);
1311 res = NULL;
1312 goto out;
1313 }
1314
1315 res = ERR_PTR(-ENOMEM);
1316 fhandle = nfs_alloc_fhandle();
1317 fattr = nfs_alloc_fattr();

--- 184 unchanged lines hidden (view full) ---

1502 if (IS_ERR(res))
1503 goto out;
1504
1505 return finish_no_open(file, res);
1506}
1507
1508static int nfs4_lookup_revalidate(struct dentry *dentry, struct nameidata *nd)
1509{
1296 d_instantiate(dentry, NULL);
1297 res = NULL;
1298 goto out;
1299 }
1300
1301 res = ERR_PTR(-ENOMEM);
1302 fhandle = nfs_alloc_fhandle();
1303 fattr = nfs_alloc_fattr();

--- 184 unchanged lines hidden (view full) ---

1488 if (IS_ERR(res))
1489 goto out;
1490
1491 return finish_no_open(file, res);
1492}
1493
1494static int nfs4_lookup_revalidate(struct dentry *dentry, struct nameidata *nd)
1495{
1496 unsigned int flags = nd->flags;
1510 struct dentry *parent = NULL;
1511 struct inode *inode;
1512 struct inode *dir;
1513 int ret = 0;
1514
1497 struct dentry *parent = NULL;
1498 struct inode *inode;
1499 struct inode *dir;
1500 int ret = 0;
1501
1515 if (nd->flags & LOOKUP_RCU)
1502 if (flags & LOOKUP_RCU)
1516 return -ECHILD;
1517
1503 return -ECHILD;
1504
1518 if (!(nd->flags & LOOKUP_OPEN) || (nd->flags & LOOKUP_DIRECTORY))
1505 if (!(flags & LOOKUP_OPEN) || (flags & LOOKUP_DIRECTORY))
1519 goto no_open;
1520 if (d_mountpoint(dentry))
1521 goto no_open;
1522
1523 inode = dentry->d_inode;
1524 parent = dget_parent(dentry);
1525 dir = parent->d_inode;
1526
1527 /* We can't create new files in nfs_open_revalidate(), so we
1528 * optimize away revalidation of negative dentries.
1529 */
1530 if (inode == NULL) {
1506 goto no_open;
1507 if (d_mountpoint(dentry))
1508 goto no_open;
1509
1510 inode = dentry->d_inode;
1511 parent = dget_parent(dentry);
1512 dir = parent->d_inode;
1513
1514 /* We can't create new files in nfs_open_revalidate(), so we
1515 * optimize away revalidation of negative dentries.
1516 */
1517 if (inode == NULL) {
1531 if (!nfs_neg_need_reval(dir, dentry, nd))
1518 if (!nfs_neg_need_reval(dir, dentry, flags))
1532 ret = 1;
1533 goto out;
1534 }
1535
1536 /* NFS only supports OPEN on regular files */
1537 if (!S_ISREG(inode->i_mode))
1538 goto no_open_dput;
1539 /* We cannot do exclusive creation on a positive dentry */
1519 ret = 1;
1520 goto out;
1521 }
1522
1523 /* NFS only supports OPEN on regular files */
1524 if (!S_ISREG(inode->i_mode))
1525 goto no_open_dput;
1526 /* We cannot do exclusive creation on a positive dentry */
1540 if (nd && nd->flags & LOOKUP_EXCL)
1527 if (flags & LOOKUP_EXCL)
1541 goto no_open_dput;
1542
1543 /* Let f_op->open() actually open (and revalidate) the file */
1544 ret = 1;
1545
1546out:
1547 dput(parent);
1548 return ret;

--- 740 unchanged lines hidden ---
1528 goto no_open_dput;
1529
1530 /* Let f_op->open() actually open (and revalidate) the file */
1531 ret = 1;
1532
1533out:
1534 dput(parent);
1535 return ret;

--- 740 unchanged lines hidden ---