aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/reiserfs/inode.c')
-rw-r--r--fs/reiserfs/inode.c203
1 files changed, 99 insertions, 104 deletions
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 823227a7662a..6fd0f47e45db 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -363,7 +363,7 @@ static int _get_block_create_0(struct inode *inode, sector_t block,
363 } 363 }
364 /* make sure we don't read more bytes than actually exist in 364 /* make sure we don't read more bytes than actually exist in
365 ** the file. This can happen in odd cases where i_size isn't 365 ** the file. This can happen in odd cases where i_size isn't
366 ** correct, and when direct item padding results in a few 366 ** correct, and when direct item padding results in a few
367 ** extra bytes at the end of the direct item 367 ** extra bytes at the end of the direct item
368 */ 368 */
369 if ((le_ih_k_offset(ih) + path.pos_in_item) > inode->i_size) 369 if ((le_ih_k_offset(ih) + path.pos_in_item) > inode->i_size)
@@ -438,15 +438,15 @@ static int reiserfs_bmap(struct inode *inode, sector_t block,
438** -ENOENT instead of a valid buffer. block_prepare_write expects to 438** -ENOENT instead of a valid buffer. block_prepare_write expects to
439** be able to do i/o on the buffers returned, unless an error value 439** be able to do i/o on the buffers returned, unless an error value
440** is also returned. 440** is also returned.
441** 441**
442** So, this allows block_prepare_write to be used for reading a single block 442** So, this allows block_prepare_write to be used for reading a single block
443** in a page. Where it does not produce a valid page for holes, or past the 443** in a page. Where it does not produce a valid page for holes, or past the
444** end of the file. This turns out to be exactly what we need for reading 444** end of the file. This turns out to be exactly what we need for reading
445** tails for conversion. 445** tails for conversion.
446** 446**
447** The point of the wrapper is forcing a certain value for create, even 447** The point of the wrapper is forcing a certain value for create, even
448** though the VFS layer is calling this function with create==1. If you 448** though the VFS layer is calling this function with create==1. If you
449** don't want to send create == GET_BLOCK_NO_HOLE to reiserfs_get_block, 449** don't want to send create == GET_BLOCK_NO_HOLE to reiserfs_get_block,
450** don't use this function. 450** don't use this function.
451*/ 451*/
452static int reiserfs_get_block_create_0(struct inode *inode, sector_t block, 452static int reiserfs_get_block_create_0(struct inode *inode, sector_t block,
@@ -602,7 +602,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
602 int done; 602 int done;
603 int fs_gen; 603 int fs_gen;
604 struct reiserfs_transaction_handle *th = NULL; 604 struct reiserfs_transaction_handle *th = NULL;
605 /* space reserved in transaction batch: 605 /* space reserved in transaction batch:
606 . 3 balancings in direct->indirect conversion 606 . 3 balancings in direct->indirect conversion
607 . 1 block involved into reiserfs_update_sd() 607 . 1 block involved into reiserfs_update_sd()
608 XXX in practically impossible worst case direct2indirect() 608 XXX in practically impossible worst case direct2indirect()
@@ -754,7 +754,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
754 reiserfs_write_unlock(inode->i_sb); 754 reiserfs_write_unlock(inode->i_sb);
755 755
756 /* the item was found, so new blocks were not added to the file 756 /* the item was found, so new blocks were not added to the file
757 ** there is no need to make sure the inode is updated with this 757 ** there is no need to make sure the inode is updated with this
758 ** transaction 758 ** transaction
759 */ 759 */
760 return retval; 760 return retval;
@@ -841,10 +841,12 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
841 tail_offset); 841 tail_offset);
842 if (retval) { 842 if (retval) {
843 if (retval != -ENOSPC) 843 if (retval != -ENOSPC)
844 reiserfs_warning(inode->i_sb, 844 reiserfs_error(inode->i_sb,
845 "clm-6004: convert tail failed inode %lu, error %d", 845 "clm-6004",
846 inode->i_ino, 846 "convert tail failed "
847 retval); 847 "inode %lu, error %d",
848 inode->i_ino,
849 retval);
848 if (allocated_block_nr) { 850 if (allocated_block_nr) {
849 /* the bitmap, the super, and the stat data == 3 */ 851 /* the bitmap, the super, and the stat data == 3 */
850 if (!th) 852 if (!th)
@@ -984,7 +986,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
984 986
985 /* this loop could log more blocks than we had originally asked 987 /* this loop could log more blocks than we had originally asked
986 ** for. So, we have to allow the transaction to end if it is 988 ** for. So, we have to allow the transaction to end if it is
987 ** too big or too full. Update the inode so things are 989 ** too big or too full. Update the inode so things are
988 ** consistent if we crash before the function returns 990 ** consistent if we crash before the function returns
989 ** 991 **
990 ** release the path so that anybody waiting on the path before 992 ** release the path so that anybody waiting on the path before
@@ -995,7 +997,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
995 if (retval) 997 if (retval)
996 goto failure; 998 goto failure;
997 } 999 }
998 /* inserting indirect pointers for a hole can take a 1000 /* inserting indirect pointers for a hole can take a
999 ** long time. reschedule if needed 1001 ** long time. reschedule if needed
1000 */ 1002 */
1001 cond_resched(); 1003 cond_resched();
@@ -1006,8 +1008,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
1006 goto failure; 1008 goto failure;
1007 } 1009 }
1008 if (retval == POSITION_FOUND) { 1010 if (retval == POSITION_FOUND) {
1009 reiserfs_warning(inode->i_sb, 1011 reiserfs_warning(inode->i_sb, "vs-825",
1010 "vs-825: reiserfs_get_block: "
1011 "%K should not be found", &key); 1012 "%K should not be found", &key);
1012 retval = -EEXIST; 1013 retval = -EEXIST;
1013 if (allocated_block_nr) 1014 if (allocated_block_nr)
@@ -1299,8 +1300,7 @@ static void update_stat_data(struct treepath *path, struct inode *inode,
1299 ih = PATH_PITEM_HEAD(path); 1300 ih = PATH_PITEM_HEAD(path);
1300 1301
1301 if (!is_statdata_le_ih(ih)) 1302 if (!is_statdata_le_ih(ih))
1302 reiserfs_panic(inode->i_sb, 1303 reiserfs_panic(inode->i_sb, "vs-13065", "key %k, found item %h",
1303 "vs-13065: update_stat_data: key %k, found item %h",
1304 INODE_PKEY(inode), ih); 1304 INODE_PKEY(inode), ih);
1305 1305
1306 if (stat_data_v1(ih)) { 1306 if (stat_data_v1(ih)) {
@@ -1332,10 +1332,9 @@ void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
1332 /* look for the object's stat data */ 1332 /* look for the object's stat data */
1333 retval = search_item(inode->i_sb, &key, &path); 1333 retval = search_item(inode->i_sb, &key, &path);
1334 if (retval == IO_ERROR) { 1334 if (retval == IO_ERROR) {
1335 reiserfs_warning(inode->i_sb, 1335 reiserfs_error(inode->i_sb, "vs-13050",
1336 "vs-13050: reiserfs_update_sd: " 1336 "i/o failure occurred trying to "
1337 "i/o failure occurred trying to update %K stat data", 1337 "update %K stat data", &key);
1338 &key);
1339 return; 1338 return;
1340 } 1339 }
1341 if (retval == ITEM_NOT_FOUND) { 1340 if (retval == ITEM_NOT_FOUND) {
@@ -1345,9 +1344,9 @@ void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
1345 /*reiserfs_warning (inode->i_sb, "vs-13050: reiserfs_update_sd: i_nlink == 0, stat data not found"); */ 1344 /*reiserfs_warning (inode->i_sb, "vs-13050: reiserfs_update_sd: i_nlink == 0, stat data not found"); */
1346 return; 1345 return;
1347 } 1346 }
1348 reiserfs_warning(inode->i_sb, 1347 reiserfs_warning(inode->i_sb, "vs-13060",
1349 "vs-13060: reiserfs_update_sd: " 1348 "stat data of object %k (nlink == %d) "
1350 "stat data of object %k (nlink == %d) not found (pos %d)", 1349 "not found (pos %d)",
1351 INODE_PKEY(inode), inode->i_nlink, 1350 INODE_PKEY(inode), inode->i_nlink,
1352 pos); 1351 pos);
1353 reiserfs_check_path(&path); 1352 reiserfs_check_path(&path);
@@ -1424,10 +1423,9 @@ void reiserfs_read_locked_inode(struct inode *inode,
1424 /* look for the object's stat data */ 1423 /* look for the object's stat data */
1425 retval = search_item(inode->i_sb, &key, &path_to_sd); 1424 retval = search_item(inode->i_sb, &key, &path_to_sd);
1426 if (retval == IO_ERROR) { 1425 if (retval == IO_ERROR) {
1427 reiserfs_warning(inode->i_sb, 1426 reiserfs_error(inode->i_sb, "vs-13070",
1428 "vs-13070: reiserfs_read_locked_inode: " 1427 "i/o failure occurred trying to find "
1429 "i/o failure occurred trying to find stat data of %K", 1428 "stat data of %K", &key);
1430 &key);
1431 reiserfs_make_bad_inode(inode); 1429 reiserfs_make_bad_inode(inode);
1432 return; 1430 return;
1433 } 1431 }
@@ -1446,7 +1444,7 @@ void reiserfs_read_locked_inode(struct inode *inode,
1446 update sd on unlink all that is required is to check for nlink 1444 update sd on unlink all that is required is to check for nlink
1447 here. This bug was first found by Sizif when debugging 1445 here. This bug was first found by Sizif when debugging
1448 SquidNG/Butterfly, forgotten, and found again after Philippe 1446 SquidNG/Butterfly, forgotten, and found again after Philippe
1449 Gramoulle <philippe.gramoulle@mmania.com> reproduced it. 1447 Gramoulle <philippe.gramoulle@mmania.com> reproduced it.
1450 1448
1451 More logical fix would require changes in fs/inode.c:iput() to 1449 More logical fix would require changes in fs/inode.c:iput() to
1452 remove inode from hash-table _after_ fs cleaned disk stuff up and 1450 remove inode from hash-table _after_ fs cleaned disk stuff up and
@@ -1457,8 +1455,7 @@ void reiserfs_read_locked_inode(struct inode *inode,
1457 during mount (fs/reiserfs/super.c:finish_unfinished()). */ 1455 during mount (fs/reiserfs/super.c:finish_unfinished()). */
1458 if ((inode->i_nlink == 0) && 1456 if ((inode->i_nlink == 0) &&
1459 !REISERFS_SB(inode->i_sb)->s_is_unlinked_ok) { 1457 !REISERFS_SB(inode->i_sb)->s_is_unlinked_ok) {
1460 reiserfs_warning(inode->i_sb, 1458 reiserfs_warning(inode->i_sb, "vs-13075",
1461 "vs-13075: reiserfs_read_locked_inode: "
1462 "dead inode read from disk %K. " 1459 "dead inode read from disk %K. "
1463 "This is likely to be race with knfsd. Ignore", 1460 "This is likely to be race with knfsd. Ignore",
1464 &key); 1461 &key);
@@ -1555,7 +1552,7 @@ struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
1555 */ 1552 */
1556 if (fh_type > fh_len) { 1553 if (fh_type > fh_len) {
1557 if (fh_type != 6 || fh_len != 5) 1554 if (fh_type != 6 || fh_len != 5)
1558 reiserfs_warning(sb, 1555 reiserfs_warning(sb, "reiserfs-13077",
1559 "nfsd/reiserfs, fhtype=%d, len=%d - odd", 1556 "nfsd/reiserfs, fhtype=%d, len=%d - odd",
1560 fh_type, fh_len); 1557 fh_type, fh_len);
1561 fh_type = 5; 1558 fh_type = 5;
@@ -1622,7 +1619,7 @@ int reiserfs_write_inode(struct inode *inode, int do_sync)
1622 if (inode->i_sb->s_flags & MS_RDONLY) 1619 if (inode->i_sb->s_flags & MS_RDONLY)
1623 return -EROFS; 1620 return -EROFS;
1624 /* memory pressure can sometimes initiate write_inode calls with sync == 1, 1621 /* memory pressure can sometimes initiate write_inode calls with sync == 1,
1625 ** these cases are just when the system needs ram, not when the 1622 ** these cases are just when the system needs ram, not when the
1626 ** inode needs to reach disk for safety, and they can safely be 1623 ** inode needs to reach disk for safety, and they can safely be
1627 ** ignored because the altered inode has already been logged. 1624 ** ignored because the altered inode has already been logged.
1628 */ 1625 */
@@ -1680,13 +1677,13 @@ static int reiserfs_new_directory(struct reiserfs_transaction_handle *th,
1680 /* look for place in the tree for new item */ 1677 /* look for place in the tree for new item */
1681 retval = search_item(sb, &key, path); 1678 retval = search_item(sb, &key, path);
1682 if (retval == IO_ERROR) { 1679 if (retval == IO_ERROR) {
1683 reiserfs_warning(sb, "vs-13080: reiserfs_new_directory: " 1680 reiserfs_error(sb, "vs-13080",
1684 "i/o failure occurred creating new directory"); 1681 "i/o failure occurred creating new directory");
1685 return -EIO; 1682 return -EIO;
1686 } 1683 }
1687 if (retval == ITEM_FOUND) { 1684 if (retval == ITEM_FOUND) {
1688 pathrelse(path); 1685 pathrelse(path);
1689 reiserfs_warning(sb, "vs-13070: reiserfs_new_directory: " 1686 reiserfs_warning(sb, "vs-13070",
1690 "object with this key exists (%k)", 1687 "object with this key exists (%k)",
1691 &(ih->ih_key)); 1688 &(ih->ih_key));
1692 return -EEXIST; 1689 return -EEXIST;
@@ -1720,13 +1717,13 @@ static int reiserfs_new_symlink(struct reiserfs_transaction_handle *th, struct i
1720 /* look for place in the tree for new item */ 1717 /* look for place in the tree for new item */
1721 retval = search_item(sb, &key, path); 1718 retval = search_item(sb, &key, path);
1722 if (retval == IO_ERROR) { 1719 if (retval == IO_ERROR) {
1723 reiserfs_warning(sb, "vs-13080: reiserfs_new_symlinik: " 1720 reiserfs_error(sb, "vs-13080",
1724 "i/o failure occurred creating new symlink"); 1721 "i/o failure occurred creating new symlink");
1725 return -EIO; 1722 return -EIO;
1726 } 1723 }
1727 if (retval == ITEM_FOUND) { 1724 if (retval == ITEM_FOUND) {
1728 pathrelse(path); 1725 pathrelse(path);
1729 reiserfs_warning(sb, "vs-13080: reiserfs_new_symlink: " 1726 reiserfs_warning(sb, "vs-13080",
1730 "object with this key exists (%k)", 1727 "object with this key exists (%k)",
1731 &(ih->ih_key)); 1728 &(ih->ih_key));
1732 return -EEXIST; 1729 return -EEXIST;
@@ -1739,7 +1736,7 @@ static int reiserfs_new_symlink(struct reiserfs_transaction_handle *th, struct i
1739/* inserts the stat data into the tree, and then calls 1736/* inserts the stat data into the tree, and then calls
1740 reiserfs_new_directory (to insert ".", ".." item if new object is 1737 reiserfs_new_directory (to insert ".", ".." item if new object is
1741 directory) or reiserfs_new_symlink (to insert symlink body if new 1738 directory) or reiserfs_new_symlink (to insert symlink body if new
1742 object is symlink) or nothing (if new object is regular file) 1739 object is symlink) or nothing (if new object is regular file)
1743 1740
1744 NOTE! uid and gid must already be set in the inode. If we return 1741 NOTE! uid and gid must already be set in the inode. If we return
1745 non-zero due to an error, we have to drop the quota previously allocated 1742 non-zero due to an error, we have to drop the quota previously allocated
@@ -1747,10 +1744,11 @@ static int reiserfs_new_symlink(struct reiserfs_transaction_handle *th, struct i
1747 if we return non-zero, we also end the transaction. */ 1744 if we return non-zero, we also end the transaction. */
1748int reiserfs_new_inode(struct reiserfs_transaction_handle *th, 1745int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1749 struct inode *dir, int mode, const char *symname, 1746 struct inode *dir, int mode, const char *symname,
1750 /* 0 for regular, EMTRY_DIR_SIZE for dirs, 1747 /* 0 for regular, EMTRY_DIR_SIZE for dirs,
1751 strlen (symname) for symlinks) */ 1748 strlen (symname) for symlinks) */
1752 loff_t i_size, struct dentry *dentry, 1749 loff_t i_size, struct dentry *dentry,
1753 struct inode *inode) 1750 struct inode *inode,
1751 struct reiserfs_security_handle *security)
1754{ 1752{
1755 struct super_block *sb; 1753 struct super_block *sb;
1756 struct reiserfs_iget_args args; 1754 struct reiserfs_iget_args args;
@@ -1796,7 +1794,7 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1796 goto out_bad_inode; 1794 goto out_bad_inode;
1797 } 1795 }
1798 if (old_format_only(sb)) 1796 if (old_format_only(sb))
1799 /* not a perfect generation count, as object ids can be reused, but 1797 /* not a perfect generation count, as object ids can be reused, but
1800 ** this is as good as reiserfs can do right now. 1798 ** this is as good as reiserfs can do right now.
1801 ** note that the private part of inode isn't filled in yet, we have 1799 ** note that the private part of inode isn't filled in yet, we have
1802 ** to use the directory. 1800 ** to use the directory.
@@ -1917,9 +1915,8 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1917 goto out_inserted_sd; 1915 goto out_inserted_sd;
1918 } 1916 }
1919 1917
1920 /* XXX CHECK THIS */
1921 if (reiserfs_posixacl(inode->i_sb)) { 1918 if (reiserfs_posixacl(inode->i_sb)) {
1922 retval = reiserfs_inherit_default_acl(dir, dentry, inode); 1919 retval = reiserfs_inherit_default_acl(th, dir, dentry, inode);
1923 if (retval) { 1920 if (retval) {
1924 err = retval; 1921 err = retval;
1925 reiserfs_check_path(&path_to_key); 1922 reiserfs_check_path(&path_to_key);
@@ -1927,10 +1924,23 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1927 goto out_inserted_sd; 1924 goto out_inserted_sd;
1928 } 1925 }
1929 } else if (inode->i_sb->s_flags & MS_POSIXACL) { 1926 } else if (inode->i_sb->s_flags & MS_POSIXACL) {
1930 reiserfs_warning(inode->i_sb, "ACLs aren't enabled in the fs, " 1927 reiserfs_warning(inode->i_sb, "jdm-13090",
1928 "ACLs aren't enabled in the fs, "
1931 "but vfs thinks they are!"); 1929 "but vfs thinks they are!");
1932 } else if (is_reiserfs_priv_object(dir)) { 1930 } else if (IS_PRIVATE(dir))
1933 reiserfs_mark_inode_private(inode); 1931 inode->i_flags |= S_PRIVATE;
1932
1933 if (security->name) {
1934 retval = reiserfs_security_write(th, inode, security);
1935 if (retval) {
1936 err = retval;
1937 reiserfs_check_path(&path_to_key);
1938 retval = journal_end(th, th->t_super,
1939 th->t_blocks_allocated);
1940 if (retval)
1941 err = retval;
1942 goto out_inserted_sd;
1943 }
1934 } 1944 }
1935 1945
1936 reiserfs_update_sd(th, inode); 1946 reiserfs_update_sd(th, inode);
@@ -1960,19 +1970,7 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1960 inode->i_nlink = 0; 1970 inode->i_nlink = 0;
1961 th->t_trans_id = 0; /* so the caller can't use this handle later */ 1971 th->t_trans_id = 0; /* so the caller can't use this handle later */
1962 unlock_new_inode(inode); /* OK to do even if we hadn't locked it */ 1972 unlock_new_inode(inode); /* OK to do even if we hadn't locked it */
1963 1973 iput(inode);
1964 /* If we were inheriting an ACL, we need to release the lock so that
1965 * iput doesn't deadlock in reiserfs_delete_xattrs. The locking
1966 * code really needs to be reworked, but this will take care of it
1967 * for now. -jeffm */
1968#ifdef CONFIG_REISERFS_FS_POSIX_ACL
1969 if (REISERFS_I(dir)->i_acl_default && !IS_ERR(REISERFS_I(dir)->i_acl_default)) {
1970 reiserfs_write_unlock_xattrs(dir->i_sb);
1971 iput(inode);
1972 reiserfs_write_lock_xattrs(dir->i_sb);
1973 } else
1974#endif
1975 iput(inode);
1976 return err; 1974 return err;
1977} 1975}
1978 1976
@@ -1989,7 +1987,7 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1989** 1987**
1990** on failure, nonzero is returned, page_result and bh_result are untouched. 1988** on failure, nonzero is returned, page_result and bh_result are untouched.
1991*/ 1989*/
1992static int grab_tail_page(struct inode *p_s_inode, 1990static int grab_tail_page(struct inode *inode,
1993 struct page **page_result, 1991 struct page **page_result,
1994 struct buffer_head **bh_result) 1992 struct buffer_head **bh_result)
1995{ 1993{
@@ -1997,11 +1995,11 @@ static int grab_tail_page(struct inode *p_s_inode,
1997 /* we want the page with the last byte in the file, 1995 /* we want the page with the last byte in the file,
1998 ** not the page that will hold the next byte for appending 1996 ** not the page that will hold the next byte for appending
1999 */ 1997 */
2000 unsigned long index = (p_s_inode->i_size - 1) >> PAGE_CACHE_SHIFT; 1998 unsigned long index = (inode->i_size - 1) >> PAGE_CACHE_SHIFT;
2001 unsigned long pos = 0; 1999 unsigned long pos = 0;
2002 unsigned long start = 0; 2000 unsigned long start = 0;
2003 unsigned long blocksize = p_s_inode->i_sb->s_blocksize; 2001 unsigned long blocksize = inode->i_sb->s_blocksize;
2004 unsigned long offset = (p_s_inode->i_size) & (PAGE_CACHE_SIZE - 1); 2002 unsigned long offset = (inode->i_size) & (PAGE_CACHE_SIZE - 1);
2005 struct buffer_head *bh; 2003 struct buffer_head *bh;
2006 struct buffer_head *head; 2004 struct buffer_head *head;
2007 struct page *page; 2005 struct page *page;
@@ -2015,7 +2013,7 @@ static int grab_tail_page(struct inode *p_s_inode,
2015 if ((offset & (blocksize - 1)) == 0) { 2013 if ((offset & (blocksize - 1)) == 0) {
2016 return -ENOENT; 2014 return -ENOENT;
2017 } 2015 }
2018 page = grab_cache_page(p_s_inode->i_mapping, index); 2016 page = grab_cache_page(inode->i_mapping, index);
2019 error = -ENOMEM; 2017 error = -ENOMEM;
2020 if (!page) { 2018 if (!page) {
2021 goto out; 2019 goto out;
@@ -2044,10 +2042,8 @@ static int grab_tail_page(struct inode *p_s_inode,
2044 ** I've screwed up the code to find the buffer, or the code to 2042 ** I've screwed up the code to find the buffer, or the code to
2045 ** call prepare_write 2043 ** call prepare_write
2046 */ 2044 */
2047 reiserfs_warning(p_s_inode->i_sb, 2045 reiserfs_error(inode->i_sb, "clm-6000",
2048 "clm-6000: error reading block %lu on dev %s", 2046 "error reading block %lu", bh->b_blocknr);
2049 bh->b_blocknr,
2050 reiserfs_bdevname(p_s_inode->i_sb));
2051 error = -EIO; 2047 error = -EIO;
2052 goto unlock; 2048 goto unlock;
2053 } 2049 }
@@ -2069,57 +2065,58 @@ static int grab_tail_page(struct inode *p_s_inode,
2069** 2065**
2070** some code taken from block_truncate_page 2066** some code taken from block_truncate_page
2071*/ 2067*/
2072int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps) 2068int reiserfs_truncate_file(struct inode *inode, int update_timestamps)
2073{ 2069{
2074 struct reiserfs_transaction_handle th; 2070 struct reiserfs_transaction_handle th;
2075 /* we want the offset for the first byte after the end of the file */ 2071 /* we want the offset for the first byte after the end of the file */
2076 unsigned long offset = p_s_inode->i_size & (PAGE_CACHE_SIZE - 1); 2072 unsigned long offset = inode->i_size & (PAGE_CACHE_SIZE - 1);
2077 unsigned blocksize = p_s_inode->i_sb->s_blocksize; 2073 unsigned blocksize = inode->i_sb->s_blocksize;
2078 unsigned length; 2074 unsigned length;
2079 struct page *page = NULL; 2075 struct page *page = NULL;
2080 int error; 2076 int error;
2081 struct buffer_head *bh = NULL; 2077 struct buffer_head *bh = NULL;
2082 int err2; 2078 int err2;
2083 2079
2084 reiserfs_write_lock(p_s_inode->i_sb); 2080 reiserfs_write_lock(inode->i_sb);
2085 2081
2086 if (p_s_inode->i_size > 0) { 2082 if (inode->i_size > 0) {
2087 if ((error = grab_tail_page(p_s_inode, &page, &bh))) { 2083 error = grab_tail_page(inode, &page, &bh);
2088 // -ENOENT means we truncated past the end of the file, 2084 if (error) {
2085 // -ENOENT means we truncated past the end of the file,
2089 // and get_block_create_0 could not find a block to read in, 2086 // and get_block_create_0 could not find a block to read in,
2090 // which is ok. 2087 // which is ok.
2091 if (error != -ENOENT) 2088 if (error != -ENOENT)
2092 reiserfs_warning(p_s_inode->i_sb, 2089 reiserfs_error(inode->i_sb, "clm-6001",
2093 "clm-6001: grab_tail_page failed %d", 2090 "grab_tail_page failed %d",
2094 error); 2091 error);
2095 page = NULL; 2092 page = NULL;
2096 bh = NULL; 2093 bh = NULL;
2097 } 2094 }
2098 } 2095 }
2099 2096
2100 /* so, if page != NULL, we have a buffer head for the offset at 2097 /* so, if page != NULL, we have a buffer head for the offset at
2101 ** the end of the file. if the bh is mapped, and bh->b_blocknr != 0, 2098 ** the end of the file. if the bh is mapped, and bh->b_blocknr != 0,
2102 ** then we have an unformatted node. Otherwise, we have a direct item, 2099 ** then we have an unformatted node. Otherwise, we have a direct item,
2103 ** and no zeroing is required on disk. We zero after the truncate, 2100 ** and no zeroing is required on disk. We zero after the truncate,
2104 ** because the truncate might pack the item anyway 2101 ** because the truncate might pack the item anyway
2105 ** (it will unmap bh if it packs). 2102 ** (it will unmap bh if it packs).
2106 */ 2103 */
2107 /* it is enough to reserve space in transaction for 2 balancings: 2104 /* it is enough to reserve space in transaction for 2 balancings:
2108 one for "save" link adding and another for the first 2105 one for "save" link adding and another for the first
2109 cut_from_item. 1 is for update_sd */ 2106 cut_from_item. 1 is for update_sd */
2110 error = journal_begin(&th, p_s_inode->i_sb, 2107 error = journal_begin(&th, inode->i_sb,
2111 JOURNAL_PER_BALANCE_CNT * 2 + 1); 2108 JOURNAL_PER_BALANCE_CNT * 2 + 1);
2112 if (error) 2109 if (error)
2113 goto out; 2110 goto out;
2114 reiserfs_update_inode_transaction(p_s_inode); 2111 reiserfs_update_inode_transaction(inode);
2115 if (update_timestamps) 2112 if (update_timestamps)
2116 /* we are doing real truncate: if the system crashes before the last 2113 /* we are doing real truncate: if the system crashes before the last
2117 transaction of truncating gets committed - on reboot the file 2114 transaction of truncating gets committed - on reboot the file
2118 either appears truncated properly or not truncated at all */ 2115 either appears truncated properly or not truncated at all */
2119 add_save_link(&th, p_s_inode, 1); 2116 add_save_link(&th, inode, 1);
2120 err2 = reiserfs_do_truncate(&th, p_s_inode, page, update_timestamps); 2117 err2 = reiserfs_do_truncate(&th, inode, page, update_timestamps);
2121 error = 2118 error =
2122 journal_end(&th, p_s_inode->i_sb, JOURNAL_PER_BALANCE_CNT * 2 + 1); 2119 journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT * 2 + 1);
2123 if (error) 2120 if (error)
2124 goto out; 2121 goto out;
2125 2122
@@ -2130,7 +2127,7 @@ int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps)
2130 } 2127 }
2131 2128
2132 if (update_timestamps) { 2129 if (update_timestamps) {
2133 error = remove_save_link(p_s_inode, 1 /* truncate */ ); 2130 error = remove_save_link(inode, 1 /* truncate */);
2134 if (error) 2131 if (error)
2135 goto out; 2132 goto out;
2136 } 2133 }
@@ -2149,14 +2146,14 @@ int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps)
2149 page_cache_release(page); 2146 page_cache_release(page);
2150 } 2147 }
2151 2148
2152 reiserfs_write_unlock(p_s_inode->i_sb); 2149 reiserfs_write_unlock(inode->i_sb);
2153 return 0; 2150 return 0;
2154 out: 2151 out:
2155 if (page) { 2152 if (page) {
2156 unlock_page(page); 2153 unlock_page(page);
2157 page_cache_release(page); 2154 page_cache_release(page);
2158 } 2155 }
2159 reiserfs_write_unlock(p_s_inode->i_sb); 2156 reiserfs_write_unlock(inode->i_sb);
2160 return error; 2157 return error;
2161} 2158}
2162 2159
@@ -2208,9 +2205,8 @@ static int map_block_for_writepage(struct inode *inode,
2208 /* we've found an unformatted node */ 2205 /* we've found an unformatted node */
2209 if (indirect_item_found(retval, ih)) { 2206 if (indirect_item_found(retval, ih)) {
2210 if (bytes_copied > 0) { 2207 if (bytes_copied > 0) {
2211 reiserfs_warning(inode->i_sb, 2208 reiserfs_warning(inode->i_sb, "clm-6002",
2212 "clm-6002: bytes_copied %d", 2209 "bytes_copied %d", bytes_copied);
2213 bytes_copied);
2214 } 2210 }
2215 if (!get_block_num(item, pos_in_item)) { 2211 if (!get_block_num(item, pos_in_item)) {
2216 /* crap, we are writing to a hole */ 2212 /* crap, we are writing to a hole */
@@ -2267,9 +2263,8 @@ static int map_block_for_writepage(struct inode *inode,
2267 goto research; 2263 goto research;
2268 } 2264 }
2269 } else { 2265 } else {
2270 reiserfs_warning(inode->i_sb, 2266 reiserfs_warning(inode->i_sb, "clm-6003",
2271 "clm-6003: bad item inode %lu, device %s", 2267 "bad item inode %lu", inode->i_ino);
2272 inode->i_ino, reiserfs_bdevname(inode->i_sb));
2273 retval = -EIO; 2268 retval = -EIO;
2274 goto out; 2269 goto out;
2275 } 2270 }
@@ -2312,8 +2307,8 @@ static int map_block_for_writepage(struct inode *inode,
2312 return retval; 2307 return retval;
2313} 2308}
2314 2309
2315/* 2310/*
2316 * mason@suse.com: updated in 2.5.54 to follow the same general io 2311 * mason@suse.com: updated in 2.5.54 to follow the same general io
2317 * start/recovery path as __block_write_full_page, along with special 2312 * start/recovery path as __block_write_full_page, along with special
2318 * code to handle reiserfs tails. 2313 * code to handle reiserfs tails.
2319 */ 2314 */
@@ -2453,7 +2448,7 @@ static int reiserfs_write_full_page(struct page *page,
2453 unlock_page(page); 2448 unlock_page(page);
2454 2449
2455 /* 2450 /*
2456 * since any buffer might be the only dirty buffer on the page, 2451 * since any buffer might be the only dirty buffer on the page,
2457 * the first submit_bh can bring the page out of writeback. 2452 * the first submit_bh can bring the page out of writeback.
2458 * be careful with the buffers. 2453 * be careful with the buffers.
2459 */ 2454 */
@@ -2472,8 +2467,8 @@ static int reiserfs_write_full_page(struct page *page,
2472 if (nr == 0) { 2467 if (nr == 0) {
2473 /* 2468 /*
2474 * if this page only had a direct item, it is very possible for 2469 * if this page only had a direct item, it is very possible for
2475 * no io to be required without there being an error. Or, 2470 * no io to be required without there being an error. Or,
2476 * someone else could have locked them and sent them down the 2471 * someone else could have locked them and sent them down the
2477 * pipe without locking the page 2472 * pipe without locking the page
2478 */ 2473 */
2479 bh = head; 2474 bh = head;
@@ -2492,7 +2487,7 @@ static int reiserfs_write_full_page(struct page *page,
2492 2487
2493 fail: 2488 fail:
2494 /* catches various errors, we need to make sure any valid dirty blocks 2489 /* catches various errors, we need to make sure any valid dirty blocks
2495 * get to the media. The page is currently locked and not marked for 2490 * get to the media. The page is currently locked and not marked for
2496 * writeback 2491 * writeback
2497 */ 2492 */
2498 ClearPageUptodate(page); 2493 ClearPageUptodate(page);