diff options
| author | Patrick McHardy <kaber@trash.net> | 2010-04-20 10:02:01 -0400 |
|---|---|---|
| committer | Patrick McHardy <kaber@trash.net> | 2010-04-20 10:02:01 -0400 |
| commit | 62910554656cdcd6b6f84a5154c4155aae4ca231 (patch) | |
| tree | dcf14004f6fd2ef7154362ff948bfeba0f3ea92d /fs/cifs/inode.c | |
| parent | 22265a5c3c103cf8c50be62e6c90d045eb649e6d (diff) | |
| parent | ab9304717f7624c41927f442e6b6d418b2d8b3e4 (diff) | |
Merge branch 'master' of /repos/git/net-next-2.6
Conflicts:
Documentation/feature-removal-schedule.txt
net/ipv6/netfilter/ip6t_REJECT.c
net/netfilter/xt_limit.c
Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'fs/cifs/inode.c')
| -rw-r--r-- | fs/cifs/inode.c | 298 |
1 files changed, 185 insertions, 113 deletions
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 8bdbc818164c..35ec11716213 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | */ | 20 | */ |
| 21 | #include <linux/fs.h> | 21 | #include <linux/fs.h> |
| 22 | #include <linux/stat.h> | 22 | #include <linux/stat.h> |
| 23 | #include <linux/slab.h> | ||
| 23 | #include <linux/pagemap.h> | 24 | #include <linux/pagemap.h> |
| 24 | #include <asm/div64.h> | 25 | #include <asm/div64.h> |
| 25 | #include "cifsfs.h" | 26 | #include "cifsfs.h" |
| @@ -77,6 +78,41 @@ static void cifs_set_ops(struct inode *inode, const bool is_dfs_referral) | |||
| 77 | } | 78 | } |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 81 | /* check inode attributes against fattr. If they don't match, tag the | ||
| 82 | * inode for cache invalidation | ||
| 83 | */ | ||
| 84 | static void | ||
| 85 | cifs_revalidate_cache(struct inode *inode, struct cifs_fattr *fattr) | ||
| 86 | { | ||
| 87 | struct cifsInodeInfo *cifs_i = CIFS_I(inode); | ||
| 88 | |||
| 89 | cFYI(1, ("%s: revalidating inode %llu", __func__, cifs_i->uniqueid)); | ||
| 90 | |||
| 91 | if (inode->i_state & I_NEW) { | ||
| 92 | cFYI(1, ("%s: inode %llu is new", __func__, cifs_i->uniqueid)); | ||
| 93 | return; | ||
| 94 | } | ||
| 95 | |||
| 96 | /* don't bother with revalidation if we have an oplock */ | ||
| 97 | if (cifs_i->clientCanCacheRead) { | ||
| 98 | cFYI(1, ("%s: inode %llu is oplocked", __func__, | ||
| 99 | cifs_i->uniqueid)); | ||
| 100 | return; | ||
| 101 | } | ||
| 102 | |||
| 103 | /* revalidate if mtime or size have changed */ | ||
| 104 | if (timespec_equal(&inode->i_mtime, &fattr->cf_mtime) && | ||
| 105 | cifs_i->server_eof == fattr->cf_eof) { | ||
| 106 | cFYI(1, ("%s: inode %llu is unchanged", __func__, | ||
| 107 | cifs_i->uniqueid)); | ||
| 108 | return; | ||
| 109 | } | ||
| 110 | |||
| 111 | cFYI(1, ("%s: invalidating inode %llu mapping", __func__, | ||
| 112 | cifs_i->uniqueid)); | ||
| 113 | cifs_i->invalid_mapping = true; | ||
| 114 | } | ||
| 115 | |||
| 80 | /* populate an inode with info from a cifs_fattr struct */ | 116 | /* populate an inode with info from a cifs_fattr struct */ |
| 81 | void | 117 | void |
| 82 | cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr) | 118 | cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr) |
| @@ -85,6 +121,8 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr) | |||
| 85 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 121 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 86 | unsigned long oldtime = cifs_i->time; | 122 | unsigned long oldtime = cifs_i->time; |
| 87 | 123 | ||
| 124 | cifs_revalidate_cache(inode, fattr); | ||
| 125 | |||
| 88 | inode->i_atime = fattr->cf_atime; | 126 | inode->i_atime = fattr->cf_atime; |
| 89 | inode->i_mtime = fattr->cf_mtime; | 127 | inode->i_mtime = fattr->cf_mtime; |
| 90 | inode->i_ctime = fattr->cf_ctime; | 128 | inode->i_ctime = fattr->cf_ctime; |
| @@ -231,6 +269,31 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb) | |||
| 231 | fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL; | 269 | fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL; |
| 232 | } | 270 | } |
| 233 | 271 | ||
| 272 | int cifs_get_file_info_unix(struct file *filp) | ||
| 273 | { | ||
| 274 | int rc; | ||
| 275 | int xid; | ||
| 276 | FILE_UNIX_BASIC_INFO find_data; | ||
| 277 | struct cifs_fattr fattr; | ||
| 278 | struct inode *inode = filp->f_path.dentry->d_inode; | ||
| 279 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | ||
| 280 | struct cifsTconInfo *tcon = cifs_sb->tcon; | ||
| 281 | struct cifsFileInfo *cfile = (struct cifsFileInfo *) filp->private_data; | ||
| 282 | |||
| 283 | xid = GetXid(); | ||
| 284 | rc = CIFSSMBUnixQFileInfo(xid, tcon, cfile->netfid, &find_data); | ||
| 285 | if (!rc) { | ||
| 286 | cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb); | ||
| 287 | } else if (rc == -EREMOTE) { | ||
| 288 | cifs_create_dfs_fattr(&fattr, inode->i_sb); | ||
| 289 | rc = 0; | ||
| 290 | } | ||
| 291 | |||
| 292 | cifs_fattr_to_inode(inode, &fattr); | ||
| 293 | FreeXid(xid); | ||
| 294 | return rc; | ||
| 295 | } | ||
| 296 | |||
| 234 | int cifs_get_inode_info_unix(struct inode **pinode, | 297 | int cifs_get_inode_info_unix(struct inode **pinode, |
| 235 | const unsigned char *full_path, | 298 | const unsigned char *full_path, |
| 236 | struct super_block *sb, int xid) | 299 | struct super_block *sb, int xid) |
| @@ -432,6 +495,47 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info, | |||
| 432 | fattr->cf_gid = cifs_sb->mnt_gid; | 495 | fattr->cf_gid = cifs_sb->mnt_gid; |
| 433 | } | 496 | } |
| 434 | 497 | ||
| 498 | int cifs_get_file_info(struct file *filp) | ||
| 499 | { | ||
| 500 | int rc; | ||
| 501 | int xid; | ||
| 502 | FILE_ALL_INFO find_data; | ||
| 503 | struct cifs_fattr fattr; | ||
| 504 | struct inode *inode = filp->f_path.dentry->d_inode; | ||
| 505 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | ||
| 506 | struct cifsTconInfo *tcon = cifs_sb->tcon; | ||
| 507 | struct cifsFileInfo *cfile = (struct cifsFileInfo *) filp->private_data; | ||
| 508 | |||
| 509 | xid = GetXid(); | ||
| 510 | rc = CIFSSMBQFileInfo(xid, tcon, cfile->netfid, &find_data); | ||
| 511 | if (rc == -EOPNOTSUPP || rc == -EINVAL) { | ||
| 512 | /* | ||
| 513 | * FIXME: legacy server -- fall back to path-based call? | ||
| 514 | * for now, just skip revalidating and mark inode for | ||
| 515 | * immediate reval. | ||
| 516 | */ | ||
| 517 | rc = 0; | ||
| 518 | CIFS_I(inode)->time = 0; | ||
| 519 | goto cgfi_exit; | ||
| 520 | } else if (rc == -EREMOTE) { | ||
| 521 | cifs_create_dfs_fattr(&fattr, inode->i_sb); | ||
| 522 | rc = 0; | ||
| 523 | } else if (rc) | ||
| 524 | goto cgfi_exit; | ||
| 525 | |||
| 526 | /* | ||
| 527 | * don't bother with SFU junk here -- just mark inode as needing | ||
| 528 | * revalidation. | ||
| 529 | */ | ||
| 530 | cifs_all_info_to_fattr(&fattr, &find_data, cifs_sb, false); | ||
| 531 | fattr.cf_uniqueid = CIFS_I(inode)->uniqueid; | ||
| 532 | fattr.cf_flags |= CIFS_FATTR_NEED_REVAL; | ||
| 533 | cifs_fattr_to_inode(inode, &fattr); | ||
| 534 | cgfi_exit: | ||
| 535 | FreeXid(xid); | ||
| 536 | return rc; | ||
| 537 | } | ||
| 538 | |||
| 435 | int cifs_get_inode_info(struct inode **pinode, | 539 | int cifs_get_inode_info(struct inode **pinode, |
| 436 | const unsigned char *full_path, FILE_ALL_INFO *pfindData, | 540 | const unsigned char *full_path, FILE_ALL_INFO *pfindData, |
| 437 | struct super_block *sb, int xid, const __u16 *pfid) | 541 | struct super_block *sb, int xid, const __u16 *pfid) |
| @@ -1389,135 +1493,103 @@ cifs_rename_exit: | |||
| 1389 | return rc; | 1493 | return rc; |
| 1390 | } | 1494 | } |
| 1391 | 1495 | ||
| 1392 | int cifs_revalidate(struct dentry *direntry) | 1496 | static bool |
| 1497 | cifs_inode_needs_reval(struct inode *inode) | ||
| 1393 | { | 1498 | { |
| 1394 | int xid; | 1499 | struct cifsInodeInfo *cifs_i = CIFS_I(inode); |
| 1395 | int rc = 0, wbrc = 0; | ||
| 1396 | char *full_path; | ||
| 1397 | struct cifs_sb_info *cifs_sb; | ||
| 1398 | struct cifsInodeInfo *cifsInode; | ||
| 1399 | loff_t local_size; | ||
| 1400 | struct timespec local_mtime; | ||
| 1401 | bool invalidate_inode = false; | ||
| 1402 | 1500 | ||
| 1403 | if (direntry->d_inode == NULL) | 1501 | if (cifs_i->clientCanCacheRead) |
| 1404 | return -ENOENT; | 1502 | return false; |
| 1405 | 1503 | ||
| 1406 | cifsInode = CIFS_I(direntry->d_inode); | 1504 | if (!lookupCacheEnabled) |
| 1505 | return true; | ||
| 1407 | 1506 | ||
| 1408 | if (cifsInode == NULL) | 1507 | if (cifs_i->time == 0) |
| 1409 | return -ENOENT; | 1508 | return true; |
| 1410 | 1509 | ||
| 1411 | /* no sense revalidating inode info on file that no one can write */ | 1510 | /* FIXME: the actimeo should be tunable */ |
| 1412 | if (CIFS_I(direntry->d_inode)->clientCanCacheRead) | 1511 | if (time_after_eq(jiffies, cifs_i->time + HZ)) |
| 1413 | return rc; | 1512 | return true; |
| 1513 | |||
| 1514 | return false; | ||
| 1515 | } | ||
| 1516 | |||
| 1517 | /* check invalid_mapping flag and zap the cache if it's set */ | ||
| 1518 | static void | ||
| 1519 | cifs_invalidate_mapping(struct inode *inode) | ||
| 1520 | { | ||
| 1521 | int rc; | ||
| 1522 | struct cifsInodeInfo *cifs_i = CIFS_I(inode); | ||
| 1523 | |||
| 1524 | cifs_i->invalid_mapping = false; | ||
| 1525 | |||
| 1526 | /* write back any cached data */ | ||
| 1527 | if (inode->i_mapping && inode->i_mapping->nrpages != 0) { | ||
| 1528 | rc = filemap_write_and_wait(inode->i_mapping); | ||
| 1529 | if (rc) | ||
| 1530 | cifs_i->write_behind_rc = rc; | ||
| 1531 | } | ||
| 1532 | invalidate_remote_inode(inode); | ||
| 1533 | } | ||
| 1534 | |||
| 1535 | int cifs_revalidate_file(struct file *filp) | ||
| 1536 | { | ||
| 1537 | int rc = 0; | ||
| 1538 | struct inode *inode = filp->f_path.dentry->d_inode; | ||
| 1539 | |||
| 1540 | if (!cifs_inode_needs_reval(inode)) | ||
| 1541 | goto check_inval; | ||
| 1542 | |||
| 1543 | if (CIFS_SB(inode->i_sb)->tcon->unix_ext) | ||
| 1544 | rc = cifs_get_file_info_unix(filp); | ||
| 1545 | else | ||
| 1546 | rc = cifs_get_file_info(filp); | ||
| 1547 | |||
| 1548 | check_inval: | ||
| 1549 | if (CIFS_I(inode)->invalid_mapping) | ||
| 1550 | cifs_invalidate_mapping(inode); | ||
| 1551 | |||
| 1552 | return rc; | ||
| 1553 | } | ||
| 1554 | |||
| 1555 | /* revalidate a dentry's inode attributes */ | ||
| 1556 | int cifs_revalidate_dentry(struct dentry *dentry) | ||
| 1557 | { | ||
| 1558 | int xid; | ||
| 1559 | int rc = 0; | ||
| 1560 | char *full_path = NULL; | ||
| 1561 | struct inode *inode = dentry->d_inode; | ||
| 1562 | struct super_block *sb = dentry->d_sb; | ||
| 1563 | |||
| 1564 | if (inode == NULL) | ||
| 1565 | return -ENOENT; | ||
| 1414 | 1566 | ||
| 1415 | xid = GetXid(); | 1567 | xid = GetXid(); |
| 1416 | 1568 | ||
| 1417 | cifs_sb = CIFS_SB(direntry->d_sb); | 1569 | if (!cifs_inode_needs_reval(inode)) |
| 1570 | goto check_inval; | ||
| 1418 | 1571 | ||
| 1419 | /* can not safely grab the rename sem here if rename calls revalidate | 1572 | /* can not safely grab the rename sem here if rename calls revalidate |
| 1420 | since that would deadlock */ | 1573 | since that would deadlock */ |
| 1421 | full_path = build_path_from_dentry(direntry); | 1574 | full_path = build_path_from_dentry(dentry); |
| 1422 | if (full_path == NULL) { | 1575 | if (full_path == NULL) { |
| 1423 | rc = -ENOMEM; | 1576 | rc = -ENOMEM; |
| 1424 | FreeXid(xid); | 1577 | goto check_inval; |
| 1425 | return rc; | ||
| 1426 | } | ||
| 1427 | cFYI(1, ("Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld " | ||
| 1428 | "jiffies %ld", full_path, direntry->d_inode, | ||
| 1429 | direntry->d_inode->i_count.counter, direntry, | ||
| 1430 | direntry->d_time, jiffies)); | ||
| 1431 | |||
| 1432 | if (cifsInode->time == 0) { | ||
| 1433 | /* was set to zero previously to force revalidate */ | ||
| 1434 | } else if (time_before(jiffies, cifsInode->time + HZ) && | ||
| 1435 | lookupCacheEnabled) { | ||
| 1436 | if ((S_ISREG(direntry->d_inode->i_mode) == 0) || | ||
| 1437 | (direntry->d_inode->i_nlink == 1)) { | ||
| 1438 | kfree(full_path); | ||
| 1439 | FreeXid(xid); | ||
| 1440 | return rc; | ||
| 1441 | } else { | ||
| 1442 | cFYI(1, ("Have to revalidate file due to hardlinks")); | ||
| 1443 | } | ||
| 1444 | } | ||
| 1445 | |||
| 1446 | /* save mtime and size */ | ||
| 1447 | local_mtime = direntry->d_inode->i_mtime; | ||
| 1448 | local_size = direntry->d_inode->i_size; | ||
| 1449 | |||
| 1450 | if (cifs_sb->tcon->unix_ext) { | ||
| 1451 | rc = cifs_get_inode_info_unix(&direntry->d_inode, full_path, | ||
| 1452 | direntry->d_sb, xid); | ||
| 1453 | if (rc) { | ||
| 1454 | cFYI(1, ("error on getting revalidate info %d", rc)); | ||
| 1455 | /* if (rc != -ENOENT) | ||
| 1456 | rc = 0; */ /* BB should we cache info on | ||
| 1457 | certain errors? */ | ||
| 1458 | } | ||
| 1459 | } else { | ||
| 1460 | rc = cifs_get_inode_info(&direntry->d_inode, full_path, NULL, | ||
| 1461 | direntry->d_sb, xid, NULL); | ||
| 1462 | if (rc) { | ||
| 1463 | cFYI(1, ("error on getting revalidate info %d", rc)); | ||
| 1464 | /* if (rc != -ENOENT) | ||
| 1465 | rc = 0; */ /* BB should we cache info on | ||
| 1466 | certain errors? */ | ||
| 1467 | } | ||
| 1468 | } | 1578 | } |
| 1469 | /* should we remap certain errors, access denied?, to zero */ | ||
| 1470 | 1579 | ||
| 1471 | /* if not oplocked, we invalidate inode pages if mtime or file size | 1580 | cFYI(1, ("Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld " |
| 1472 | had changed on server */ | 1581 | "jiffies %ld", full_path, inode, inode->i_count.counter, |
| 1582 | dentry, dentry->d_time, jiffies)); | ||
| 1473 | 1583 | ||
| 1474 | if (timespec_equal(&local_mtime, &direntry->d_inode->i_mtime) && | 1584 | if (CIFS_SB(sb)->tcon->unix_ext) |
| 1475 | (local_size == direntry->d_inode->i_size)) { | 1585 | rc = cifs_get_inode_info_unix(&inode, full_path, sb, xid); |
| 1476 | cFYI(1, ("cifs_revalidate - inode unchanged")); | 1586 | else |
| 1477 | } else { | 1587 | rc = cifs_get_inode_info(&inode, full_path, NULL, sb, |
| 1478 | /* file may have changed on server */ | 1588 | xid, NULL); |
| 1479 | if (cifsInode->clientCanCacheRead) { | ||
| 1480 | /* no need to invalidate inode pages since we were the | ||
| 1481 | only ones who could have modified the file and the | ||
| 1482 | server copy is staler than ours */ | ||
| 1483 | } else { | ||
| 1484 | invalidate_inode = true; | ||
| 1485 | } | ||
| 1486 | } | ||
| 1487 | 1589 | ||
| 1488 | /* can not grab this sem since kernel filesys locking documentation | 1590 | check_inval: |
| 1489 | indicates i_mutex may be taken by the kernel on lookup and rename | 1591 | if (CIFS_I(inode)->invalid_mapping) |
| 1490 | which could deadlock if we grab the i_mutex here as well */ | 1592 | cifs_invalidate_mapping(inode); |
| 1491 | /* mutex_lock(&direntry->d_inode->i_mutex);*/ | ||
| 1492 | /* need to write out dirty pages here */ | ||
| 1493 | if (direntry->d_inode->i_mapping) { | ||
| 1494 | /* do we need to lock inode until after invalidate completes | ||
| 1495 | below? */ | ||
| 1496 | wbrc = filemap_fdatawrite(direntry->d_inode->i_mapping); | ||
| 1497 | if (wbrc) | ||
| 1498 | CIFS_I(direntry->d_inode)->write_behind_rc = wbrc; | ||
| 1499 | } | ||
| 1500 | if (invalidate_inode) { | ||
| 1501 | /* shrink_dcache not necessary now that cifs dentry ops | ||
| 1502 | are exported for negative dentries */ | ||
| 1503 | /* if (S_ISDIR(direntry->d_inode->i_mode)) | ||
| 1504 | shrink_dcache_parent(direntry); */ | ||
| 1505 | if (S_ISREG(direntry->d_inode->i_mode)) { | ||
| 1506 | if (direntry->d_inode->i_mapping) { | ||
| 1507 | wbrc = filemap_fdatawait(direntry->d_inode->i_mapping); | ||
| 1508 | if (wbrc) | ||
| 1509 | CIFS_I(direntry->d_inode)->write_behind_rc = wbrc; | ||
| 1510 | } | ||
| 1511 | /* may eventually have to do this for open files too */ | ||
| 1512 | if (list_empty(&(cifsInode->openFileList))) { | ||
| 1513 | /* changed on server - flush read ahead pages */ | ||
| 1514 | cFYI(1, ("Invalidating read ahead data on " | ||
| 1515 | "closed file")); | ||
| 1516 | invalidate_remote_inode(direntry->d_inode); | ||
| 1517 | } | ||
| 1518 | } | ||
| 1519 | } | ||
| 1520 | /* mutex_unlock(&direntry->d_inode->i_mutex); */ | ||
| 1521 | 1593 | ||
| 1522 | kfree(full_path); | 1594 | kfree(full_path); |
| 1523 | FreeXid(xid); | 1595 | FreeXid(xid); |
| @@ -1527,7 +1599,7 @@ int cifs_revalidate(struct dentry *direntry) | |||
| 1527 | int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry, | 1599 | int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 1528 | struct kstat *stat) | 1600 | struct kstat *stat) |
| 1529 | { | 1601 | { |
| 1530 | int err = cifs_revalidate(dentry); | 1602 | int err = cifs_revalidate_dentry(dentry); |
| 1531 | if (!err) { | 1603 | if (!err) { |
| 1532 | generic_fillattr(dentry->d_inode, stat); | 1604 | generic_fillattr(dentry->d_inode, stat); |
| 1533 | stat->blksize = CIFS_MAX_MSGSIZE; | 1605 | stat->blksize = CIFS_MAX_MSGSIZE; |
