diff options
author | Trond Myklebust <Trond.Myklebust@netapp.com> | 2009-08-09 15:06:19 -0400 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2009-08-09 15:06:19 -0400 |
commit | 62ab460cf5e450e1d207a98a9c6cf2e4a6a78fd1 (patch) | |
tree | 595ca70261f46b93bda1998285e5f5c7da684cbc /fs/nfs/inode.c | |
parent | a78cb57a106fceeba26da2907db9d8886700e1dc (diff) |
NFSv4: Add 'server capability' flags for NFSv4 recommended attributes
If the NFSv4 server doesn't support a POSIX attribute, the generic NFS code
needs to know that, so that it don't keep trying to poll for it.
However, by the same count, if the NFSv4 server does support that
attribute, then we should ensure that the inode metadata is appropriately
labelled as being untrusted. For instance, if we don't know the correct
value of the file's uid, we should certainly not be caching ACLs or ACCESS
results.
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/inode.c')
-rw-r--r-- | fs/nfs/inode.c | 92 |
1 files changed, 78 insertions, 14 deletions
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index bd7938eda6a8..fe5a8b45d867 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
@@ -286,6 +286,11 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) | |||
286 | /* We can't support update_atime(), since the server will reset it */ | 286 | /* We can't support update_atime(), since the server will reset it */ |
287 | inode->i_flags |= S_NOATIME|S_NOCMTIME; | 287 | inode->i_flags |= S_NOATIME|S_NOCMTIME; |
288 | inode->i_mode = fattr->mode; | 288 | inode->i_mode = fattr->mode; |
289 | if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0 | ||
290 | && nfs_server_capable(inode, NFS_CAP_MODE)) | ||
291 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
292 | | NFS_INO_INVALID_ACCESS | ||
293 | | NFS_INO_INVALID_ACL; | ||
289 | /* Why so? Because we want revalidate for devices/FIFOs, and | 294 | /* Why so? Because we want revalidate for devices/FIFOs, and |
290 | * that's precisely what we have in nfs_file_inode_operations. | 295 | * that's precisely what we have in nfs_file_inode_operations. |
291 | */ | 296 | */ |
@@ -330,20 +335,46 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) | |||
330 | nfsi->attr_gencount = fattr->gencount; | 335 | nfsi->attr_gencount = fattr->gencount; |
331 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) | 336 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) |
332 | inode->i_atime = fattr->atime; | 337 | inode->i_atime = fattr->atime; |
338 | else if (nfs_server_capable(inode, NFS_CAP_ATIME)) | ||
339 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | ||
333 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) | 340 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) |
334 | inode->i_mtime = fattr->mtime; | 341 | inode->i_mtime = fattr->mtime; |
342 | else if (nfs_server_capable(inode, NFS_CAP_MTIME)) | ||
343 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
344 | | NFS_INO_INVALID_DATA; | ||
335 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) | 345 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) |
336 | inode->i_ctime = fattr->ctime; | 346 | inode->i_ctime = fattr->ctime; |
347 | else if (nfs_server_capable(inode, NFS_CAP_CTIME)) | ||
348 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
349 | | NFS_INO_INVALID_ACCESS | ||
350 | | NFS_INO_INVALID_ACL; | ||
337 | if (fattr->valid & NFS_ATTR_FATTR_CHANGE) | 351 | if (fattr->valid & NFS_ATTR_FATTR_CHANGE) |
338 | nfsi->change_attr = fattr->change_attr; | 352 | nfsi->change_attr = fattr->change_attr; |
353 | else if (nfs_server_capable(inode, NFS_CAP_CHANGE_ATTR)) | ||
354 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
355 | | NFS_INO_INVALID_DATA; | ||
339 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) | 356 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) |
340 | inode->i_size = nfs_size_to_loff_t(fattr->size); | 357 | inode->i_size = nfs_size_to_loff_t(fattr->size); |
358 | else | ||
359 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
360 | | NFS_INO_INVALID_DATA | ||
361 | | NFS_INO_REVAL_PAGECACHE; | ||
341 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) | 362 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) |
342 | inode->i_nlink = fattr->nlink; | 363 | inode->i_nlink = fattr->nlink; |
364 | else if (nfs_server_capable(inode, NFS_CAP_NLINK)) | ||
365 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | ||
343 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) | 366 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) |
344 | inode->i_uid = fattr->uid; | 367 | inode->i_uid = fattr->uid; |
368 | else if (nfs_server_capable(inode, NFS_CAP_OWNER)) | ||
369 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
370 | | NFS_INO_INVALID_ACCESS | ||
371 | | NFS_INO_INVALID_ACL; | ||
345 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) | 372 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) |
346 | inode->i_gid = fattr->gid; | 373 | inode->i_gid = fattr->gid; |
374 | else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP)) | ||
375 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
376 | | NFS_INO_INVALID_ACCESS | ||
377 | | NFS_INO_INVALID_ACL; | ||
347 | if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) | 378 | if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) |
348 | inode->i_blocks = fattr->du.nfs2.blocks; | 379 | inode->i_blocks = fattr->du.nfs2.blocks; |
349 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { | 380 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { |
@@ -1145,6 +1176,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1145 | loff_t cur_isize, new_isize; | 1176 | loff_t cur_isize, new_isize; |
1146 | unsigned long invalid = 0; | 1177 | unsigned long invalid = 0; |
1147 | unsigned long now = jiffies; | 1178 | unsigned long now = jiffies; |
1179 | unsigned long save_cache_validity; | ||
1148 | 1180 | ||
1149 | dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n", | 1181 | dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n", |
1150 | __func__, inode->i_sb->s_id, inode->i_ino, | 1182 | __func__, inode->i_sb->s_id, inode->i_ino, |
@@ -1171,10 +1203,11 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1171 | */ | 1203 | */ |
1172 | nfsi->read_cache_jiffies = fattr->time_start; | 1204 | nfsi->read_cache_jiffies = fattr->time_start; |
1173 | 1205 | ||
1174 | if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) || (fattr->valid & (NFS_ATTR_FATTR_MTIME|NFS_ATTR_FATTR_CTIME))) | 1206 | save_cache_validity = nfsi->cache_validity; |
1175 | nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR | 1207 | nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR |
1176 | | NFS_INO_INVALID_ATIME | 1208 | | NFS_INO_INVALID_ATIME |
1177 | | NFS_INO_REVAL_PAGECACHE); | 1209 | | NFS_INO_REVAL_FORCED |
1210 | | NFS_INO_REVAL_PAGECACHE); | ||
1178 | 1211 | ||
1179 | /* Do atomic weak cache consistency updates */ | 1212 | /* Do atomic weak cache consistency updates */ |
1180 | nfs_wcc_update_inode(inode, fattr); | 1213 | nfs_wcc_update_inode(inode, fattr); |
@@ -1189,7 +1222,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1189 | nfs_force_lookup_revalidate(inode); | 1222 | nfs_force_lookup_revalidate(inode); |
1190 | nfsi->change_attr = fattr->change_attr; | 1223 | nfsi->change_attr = fattr->change_attr; |
1191 | } | 1224 | } |
1192 | } | 1225 | } else if (server->caps & NFS_CAP_CHANGE_ATTR) |
1226 | invalid |= save_cache_validity; | ||
1193 | 1227 | ||
1194 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) { | 1228 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) { |
1195 | /* NFSv2/v3: Check if the mtime agrees */ | 1229 | /* NFSv2/v3: Check if the mtime agrees */ |
@@ -1201,7 +1235,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1201 | nfs_force_lookup_revalidate(inode); | 1235 | nfs_force_lookup_revalidate(inode); |
1202 | memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); | 1236 | memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); |
1203 | } | 1237 | } |
1204 | } | 1238 | } else if (server->caps & NFS_CAP_MTIME) |
1239 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
1240 | | NFS_INO_INVALID_DATA | ||
1241 | | NFS_INO_REVAL_PAGECACHE | ||
1242 | | NFS_INO_REVAL_FORCED); | ||
1243 | |||
1205 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) { | 1244 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) { |
1206 | /* If ctime has changed we should definitely clear access+acl caches */ | 1245 | /* If ctime has changed we should definitely clear access+acl caches */ |
1207 | if (!timespec_equal(&inode->i_ctime, &fattr->ctime)) { | 1246 | if (!timespec_equal(&inode->i_ctime, &fattr->ctime)) { |
@@ -1215,7 +1254,11 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1215 | } | 1254 | } |
1216 | memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime)); | 1255 | memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime)); |
1217 | } | 1256 | } |
1218 | } | 1257 | } else if (server->caps & NFS_CAP_CTIME) |
1258 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
1259 | | NFS_INO_INVALID_ACCESS | ||
1260 | | NFS_INO_INVALID_ACL | ||
1261 | | NFS_INO_REVAL_FORCED); | ||
1219 | 1262 | ||
1220 | /* Check if our cached file size is stale */ | 1263 | /* Check if our cached file size is stale */ |
1221 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) { | 1264 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) { |
@@ -1231,30 +1274,50 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1231 | dprintk("NFS: isize change on server for file %s/%ld\n", | 1274 | dprintk("NFS: isize change on server for file %s/%ld\n", |
1232 | inode->i_sb->s_id, inode->i_ino); | 1275 | inode->i_sb->s_id, inode->i_ino); |
1233 | } | 1276 | } |
1234 | } | 1277 | } else |
1278 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
1279 | | NFS_INO_REVAL_PAGECACHE | ||
1280 | | NFS_INO_REVAL_FORCED); | ||
1235 | 1281 | ||
1236 | 1282 | ||
1237 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) | 1283 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) |
1238 | memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime)); | 1284 | memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime)); |
1285 | else if (server->caps & NFS_CAP_ATIME) | ||
1286 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATIME | ||
1287 | | NFS_INO_REVAL_FORCED); | ||
1239 | 1288 | ||
1240 | if (fattr->valid & NFS_ATTR_FATTR_MODE) { | 1289 | if (fattr->valid & NFS_ATTR_FATTR_MODE) { |
1241 | if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) { | 1290 | if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) { |
1242 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; | 1291 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; |
1243 | inode->i_mode = fattr->mode; | 1292 | inode->i_mode = fattr->mode; |
1244 | } | 1293 | } |
1245 | } | 1294 | } else if (server->caps & NFS_CAP_MODE) |
1295 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
1296 | | NFS_INO_INVALID_ACCESS | ||
1297 | | NFS_INO_INVALID_ACL | ||
1298 | | NFS_INO_REVAL_FORCED); | ||
1299 | |||
1246 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) { | 1300 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) { |
1247 | if (inode->i_uid != fattr->uid) { | 1301 | if (inode->i_uid != fattr->uid) { |
1248 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; | 1302 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; |
1249 | inode->i_uid = fattr->uid; | 1303 | inode->i_uid = fattr->uid; |
1250 | } | 1304 | } |
1251 | } | 1305 | } else if (server->caps & NFS_CAP_OWNER) |
1306 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
1307 | | NFS_INO_INVALID_ACCESS | ||
1308 | | NFS_INO_INVALID_ACL | ||
1309 | | NFS_INO_REVAL_FORCED); | ||
1310 | |||
1252 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) { | 1311 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) { |
1253 | if (inode->i_gid != fattr->gid) { | 1312 | if (inode->i_gid != fattr->gid) { |
1254 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; | 1313 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; |
1255 | inode->i_gid = fattr->gid; | 1314 | inode->i_gid = fattr->gid; |
1256 | } | 1315 | } |
1257 | } | 1316 | } else if (server->caps & NFS_CAP_OWNER_GROUP) |
1317 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
1318 | | NFS_INO_INVALID_ACCESS | ||
1319 | | NFS_INO_INVALID_ACL | ||
1320 | | NFS_INO_REVAL_FORCED); | ||
1258 | 1321 | ||
1259 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) { | 1322 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) { |
1260 | if (inode->i_nlink != fattr->nlink) { | 1323 | if (inode->i_nlink != fattr->nlink) { |
@@ -1263,7 +1326,9 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1263 | invalid |= NFS_INO_INVALID_DATA; | 1326 | invalid |= NFS_INO_INVALID_DATA; |
1264 | inode->i_nlink = fattr->nlink; | 1327 | inode->i_nlink = fattr->nlink; |
1265 | } | 1328 | } |
1266 | } | 1329 | } else if (server->caps & NFS_CAP_NLINK) |
1330 | invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR | ||
1331 | | NFS_INO_REVAL_FORCED); | ||
1267 | 1332 | ||
1268 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { | 1333 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { |
1269 | /* | 1334 | /* |
@@ -1293,9 +1358,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1293 | || S_ISLNK(inode->i_mode))) | 1358 | || S_ISLNK(inode->i_mode))) |
1294 | invalid &= ~NFS_INO_INVALID_DATA; | 1359 | invalid &= ~NFS_INO_INVALID_DATA; |
1295 | if (!nfs_have_delegation(inode, FMODE_READ) || | 1360 | if (!nfs_have_delegation(inode, FMODE_READ) || |
1296 | (nfsi->cache_validity & NFS_INO_REVAL_FORCED)) | 1361 | (save_cache_validity & NFS_INO_REVAL_FORCED)) |
1297 | nfsi->cache_validity |= invalid; | 1362 | nfsi->cache_validity |= invalid; |
1298 | nfsi->cache_validity &= ~NFS_INO_REVAL_FORCED; | ||
1299 | 1363 | ||
1300 | return 0; | 1364 | return 0; |
1301 | out_changed: | 1365 | out_changed: |