aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext3
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /fs/ext3
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'fs/ext3')
-rw-r--r--fs/ext3/acl.c13
-rw-r--r--fs/ext3/acl.h2
-rw-r--r--fs/ext3/balloc.c296
-rw-r--r--fs/ext3/dir.c15
-rw-r--r--fs/ext3/fsync.c3
-rw-r--r--fs/ext3/ialloc.c16
-rw-r--r--fs/ext3/inode.c43
-rw-r--r--fs/ext3/ioctl.c28
-rw-r--r--fs/ext3/namei.c237
-rw-r--r--fs/ext3/resize.c78
-rw-r--r--fs/ext3/super.c185
-rw-r--r--fs/ext3/xattr.c2
-rw-r--r--fs/ext3/xattr.h4
-rw-r--r--fs/ext3/xattr_security.c5
14 files changed, 686 insertions, 241 deletions
diff --git a/fs/ext3/acl.c b/fs/ext3/acl.c
index 8a11fe212183..9d021c0d472a 100644
--- a/fs/ext3/acl.c
+++ b/fs/ext3/acl.c
@@ -240,10 +240,17 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
240} 240}
241 241
242int 242int
243ext3_check_acl(struct inode *inode, int mask) 243ext3_check_acl(struct inode *inode, int mask, unsigned int flags)
244{ 244{
245 struct posix_acl *acl = ext3_get_acl(inode, ACL_TYPE_ACCESS); 245 struct posix_acl *acl;
246
247 if (flags & IPERM_FLAG_RCU) {
248 if (!negative_cached_acl(inode, ACL_TYPE_ACCESS))
249 return -ECHILD;
250 return -EAGAIN;
251 }
246 252
253 acl = ext3_get_acl(inode, ACL_TYPE_ACCESS);
247 if (IS_ERR(acl)) 254 if (IS_ERR(acl))
248 return PTR_ERR(acl); 255 return PTR_ERR(acl);
249 if (acl) { 256 if (acl) {
@@ -428,7 +435,7 @@ ext3_xattr_set_acl(struct dentry *dentry, const char *name, const void *value,
428 return -EINVAL; 435 return -EINVAL;
429 if (!test_opt(inode->i_sb, POSIX_ACL)) 436 if (!test_opt(inode->i_sb, POSIX_ACL))
430 return -EOPNOTSUPP; 437 return -EOPNOTSUPP;
431 if (!is_owner_or_cap(inode)) 438 if (!inode_owner_or_capable(inode))
432 return -EPERM; 439 return -EPERM;
433 440
434 if (value) { 441 if (value) {
diff --git a/fs/ext3/acl.h b/fs/ext3/acl.h
index 597334626de9..5faf8048e906 100644
--- a/fs/ext3/acl.h
+++ b/fs/ext3/acl.h
@@ -54,7 +54,7 @@ static inline int ext3_acl_count(size_t size)
54#ifdef CONFIG_EXT3_FS_POSIX_ACL 54#ifdef CONFIG_EXT3_FS_POSIX_ACL
55 55
56/* acl.c */ 56/* acl.c */
57extern int ext3_check_acl (struct inode *, int); 57extern int ext3_check_acl (struct inode *, int, unsigned int);
58extern int ext3_acl_chmod (struct inode *); 58extern int ext3_acl_chmod (struct inode *);
59extern int ext3_init_acl (handle_t *, struct inode *, struct inode *); 59extern int ext3_init_acl (handle_t *, struct inode *, struct inode *);
60 60
diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
index 4a32511f4ded..fe52297e31ad 100644
--- a/fs/ext3/balloc.c
+++ b/fs/ext3/balloc.c
@@ -20,6 +20,7 @@
20#include <linux/ext3_jbd.h> 20#include <linux/ext3_jbd.h>
21#include <linux/quotaops.h> 21#include <linux/quotaops.h>
22#include <linux/buffer_head.h> 22#include <linux/buffer_head.h>
23#include <linux/blkdev.h>
23 24
24/* 25/*
25 * balloc.c contains the blocks allocation and deallocation routines 26 * balloc.c contains the blocks allocation and deallocation routines
@@ -39,6 +40,21 @@
39 40
40#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1) 41#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
41 42
43/*
44 * Calculate the block group number and offset, given a block number
45 */
46static void ext3_get_group_no_and_offset(struct super_block *sb,
47 ext3_fsblk_t blocknr, unsigned long *blockgrpp, ext3_grpblk_t *offsetp)
48{
49 struct ext3_super_block *es = EXT3_SB(sb)->s_es;
50
51 blocknr = blocknr - le32_to_cpu(es->s_first_data_block);
52 if (offsetp)
53 *offsetp = blocknr % EXT3_BLOCKS_PER_GROUP(sb);
54 if (blockgrpp)
55 *blockgrpp = blocknr / EXT3_BLOCKS_PER_GROUP(sb);
56}
57
42/** 58/**
43 * ext3_get_group_desc() -- load group descriptor from disk 59 * ext3_get_group_desc() -- load group descriptor from disk
44 * @sb: super block 60 * @sb: super block
@@ -574,7 +590,7 @@ do_more:
574 BUFFER_TRACE(debug_bh, "Deleted!"); 590 BUFFER_TRACE(debug_bh, "Deleted!");
575 if (!bh2jh(bitmap_bh)->b_committed_data) 591 if (!bh2jh(bitmap_bh)->b_committed_data)
576 BUFFER_TRACE(debug_bh, 592 BUFFER_TRACE(debug_bh,
577 "No commited data in bitmap"); 593 "No committed data in bitmap");
578 BUFFER_TRACE2(debug_bh, bitmap_bh, "bitmap"); 594 BUFFER_TRACE2(debug_bh, bitmap_bh, "bitmap");
579 __brelse(debug_bh); 595 __brelse(debug_bh);
580 } 596 }
@@ -792,9 +808,9 @@ find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh,
792 if (here < 0) 808 if (here < 0)
793 here = 0; 809 here = 0;
794 810
795 p = ((char *)bh->b_data) + (here >> 3); 811 p = bh->b_data + (here >> 3);
796 r = memscan(p, 0, ((maxblocks + 7) >> 3) - (here >> 3)); 812 r = memscan(p, 0, ((maxblocks + 7) >> 3) - (here >> 3));
797 next = (r - ((char *)bh->b_data)) << 3; 813 next = (r - bh->b_data) << 3;
798 814
799 if (next < maxblocks && next >= start && ext3_test_allocatable(next, bh)) 815 if (next < maxblocks && next >= start && ext3_test_allocatable(next, bh))
800 return next; 816 return next;
@@ -810,8 +826,9 @@ find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh,
810 826
811/** 827/**
812 * claim_block() 828 * claim_block()
829 * @lock: the spin lock for this block group
813 * @block: the free block (group relative) to allocate 830 * @block: the free block (group relative) to allocate
814 * @bh: the bufferhead containts the block group bitmap 831 * @bh: the buffer_head contains the block group bitmap
815 * 832 *
816 * We think we can allocate this block in this bitmap. Try to set the bit. 833 * We think we can allocate this block in this bitmap. Try to set the bit.
817 * If that succeeds then check that nobody has allocated and then freed the 834 * If that succeeds then check that nobody has allocated and then freed the
@@ -956,9 +973,11 @@ fail_access:
956 * but we will shift to the place where start_block is, 973 * but we will shift to the place where start_block is,
957 * then start from there, when looking for a reservable space. 974 * then start from there, when looking for a reservable space.
958 * 975 *
959 * @size: the target new reservation window size 976 * @my_rsv: the reservation window
977 *
978 * @sb: the super block
960 * 979 *
961 * @group_first_block: the first block we consider to start 980 * @start_block: the first block we consider to start
962 * the real search from 981 * the real search from
963 * 982 *
964 * @last_block: 983 * @last_block:
@@ -1044,7 +1063,7 @@ static int find_next_reservable_window(
1044 rsv_window_remove(sb, my_rsv); 1063 rsv_window_remove(sb, my_rsv);
1045 1064
1046 /* 1065 /*
1047 * Let's book the whole avaliable window for now. We will check the 1066 * Let's book the whole available window for now. We will check the
1048 * disk bitmap later and then, if there are free blocks then we adjust 1067 * disk bitmap later and then, if there are free blocks then we adjust
1049 * the window size if it's larger than requested. 1068 * the window size if it's larger than requested.
1050 * Otherwise, we will remove this node from the tree next time 1069 * Otherwise, we will remove this node from the tree next time
@@ -1084,7 +1103,7 @@ static int find_next_reservable_window(
1084 * 1103 *
1085 * failed: we failed to find a reservation window in this group 1104 * failed: we failed to find a reservation window in this group
1086 * 1105 *
1087 * @rsv: the reservation 1106 * @my_rsv: the reservation window
1088 * 1107 *
1089 * @grp_goal: The goal (group-relative). It is where the search for a 1108 * @grp_goal: The goal (group-relative). It is where the search for a
1090 * free reservable space should start from. 1109 * free reservable space should start from.
@@ -1273,8 +1292,8 @@ static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv,
1273 * @group: given allocation block group 1292 * @group: given allocation block group
1274 * @bitmap_bh: bufferhead holds the block bitmap 1293 * @bitmap_bh: bufferhead holds the block bitmap
1275 * @grp_goal: given target block within the group 1294 * @grp_goal: given target block within the group
1276 * @count: target number of blocks to allocate
1277 * @my_rsv: reservation window 1295 * @my_rsv: reservation window
1296 * @count: target number of blocks to allocate
1278 * @errp: pointer to store the error code 1297 * @errp: pointer to store the error code
1279 * 1298 *
1280 * This is the main function used to allocate a new block and its reservation 1299 * This is the main function used to allocate a new block and its reservation
@@ -1437,7 +1456,7 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
1437 * 1456 *
1438 * ext3_should_retry_alloc() is called when ENOSPC is returned, and if 1457 * ext3_should_retry_alloc() is called when ENOSPC is returned, and if
1439 * it is profitable to retry the operation, this function will wait 1458 * it is profitable to retry the operation, this function will wait
1440 * for the current or commiting transaction to complete, and then 1459 * for the current or committing transaction to complete, and then
1441 * return TRUE. 1460 * return TRUE.
1442 * 1461 *
1443 * if the total number of retries exceed three times, return FALSE. 1462 * if the total number of retries exceed three times, return FALSE.
@@ -1613,9 +1632,9 @@ retry_alloc:
1613 goto allocated; 1632 goto allocated;
1614 } 1633 }
1615 /* 1634 /*
1616 * We may end up a bogus ealier ENOSPC error due to 1635 * We may end up a bogus earlier ENOSPC error due to
1617 * filesystem is "full" of reservations, but 1636 * filesystem is "full" of reservations, but
1618 * there maybe indeed free blocks avaliable on disk 1637 * there maybe indeed free blocks available on disk
1619 * In this case, we just forget about the reservations 1638 * In this case, we just forget about the reservations
1620 * just do block allocation as without reservations. 1639 * just do block allocation as without reservations.
1621 */ 1640 */
@@ -1882,3 +1901,256 @@ unsigned long ext3_bg_num_gdb(struct super_block *sb, int group)
1882 return ext3_bg_num_gdb_meta(sb,group); 1901 return ext3_bg_num_gdb_meta(sb,group);
1883 1902
1884} 1903}
1904
1905/**
1906 * ext3_trim_all_free -- function to trim all free space in alloc. group
1907 * @sb: super block for file system
1908 * @group: allocation group to trim
1909 * @start: first group block to examine
1910 * @max: last group block to examine
1911 * @gdp: allocation group description structure
1912 * @minblocks: minimum extent block count
1913 *
1914 * ext3_trim_all_free walks through group's block bitmap searching for free
1915 * blocks. When the free block is found, it tries to allocate this block and
1916 * consequent free block to get the biggest free extent possible, until it
1917 * reaches any used block. Then issue a TRIM command on this extent and free
1918 * the extent in the block bitmap. This is done until whole group is scanned.
1919 */
1920ext3_grpblk_t ext3_trim_all_free(struct super_block *sb, unsigned int group,
1921 ext3_grpblk_t start, ext3_grpblk_t max,
1922 ext3_grpblk_t minblocks)
1923{
1924 handle_t *handle;
1925 ext3_grpblk_t next, free_blocks, bit, freed, count = 0;
1926 ext3_fsblk_t discard_block;
1927 struct ext3_sb_info *sbi;
1928 struct buffer_head *gdp_bh, *bitmap_bh = NULL;
1929 struct ext3_group_desc *gdp;
1930 int err = 0, ret = 0;
1931
1932 /*
1933 * We will update one block bitmap, and one group descriptor
1934 */
1935 handle = ext3_journal_start_sb(sb, 2);
1936 if (IS_ERR(handle))
1937 return PTR_ERR(handle);
1938
1939 bitmap_bh = read_block_bitmap(sb, group);
1940 if (!bitmap_bh) {
1941 err = -EIO;
1942 goto err_out;
1943 }
1944
1945 BUFFER_TRACE(bitmap_bh, "getting undo access");
1946 err = ext3_journal_get_undo_access(handle, bitmap_bh);
1947 if (err)
1948 goto err_out;
1949
1950 gdp = ext3_get_group_desc(sb, group, &gdp_bh);
1951 if (!gdp) {
1952 err = -EIO;
1953 goto err_out;
1954 }
1955
1956 BUFFER_TRACE(gdp_bh, "get_write_access");
1957 err = ext3_journal_get_write_access(handle, gdp_bh);
1958 if (err)
1959 goto err_out;
1960
1961 free_blocks = le16_to_cpu(gdp->bg_free_blocks_count);
1962 sbi = EXT3_SB(sb);
1963
1964 /* Walk through the whole group */
1965 while (start < max) {
1966 start = bitmap_search_next_usable_block(start, bitmap_bh, max);
1967 if (start < 0)
1968 break;
1969 next = start;
1970
1971 /*
1972 * Allocate contiguous free extents by setting bits in the
1973 * block bitmap
1974 */
1975 while (next < max
1976 && claim_block(sb_bgl_lock(sbi, group),
1977 next, bitmap_bh)) {
1978 next++;
1979 }
1980
1981 /* We did not claim any blocks */
1982 if (next == start)
1983 continue;
1984
1985 discard_block = (ext3_fsblk_t)start +
1986 ext3_group_first_block_no(sb, group);
1987
1988 /* Update counters */
1989 spin_lock(sb_bgl_lock(sbi, group));
1990 le16_add_cpu(&gdp->bg_free_blocks_count, start - next);
1991 spin_unlock(sb_bgl_lock(sbi, group));
1992 percpu_counter_sub(&sbi->s_freeblocks_counter, next - start);
1993
1994 free_blocks -= next - start;
1995 /* Do not issue a TRIM on extents smaller than minblocks */
1996 if ((next - start) < minblocks)
1997 goto free_extent;
1998
1999 /* Send the TRIM command down to the device */
2000 err = sb_issue_discard(sb, discard_block, next - start,
2001 GFP_NOFS, 0);
2002 count += (next - start);
2003free_extent:
2004 freed = 0;
2005
2006 /*
2007 * Clear bits in the bitmap
2008 */
2009 for (bit = start; bit < next; bit++) {
2010 BUFFER_TRACE(bitmap_bh, "clear bit");
2011 if (!ext3_clear_bit_atomic(sb_bgl_lock(sbi, group),
2012 bit, bitmap_bh->b_data)) {
2013 ext3_error(sb, __func__,
2014 "bit already cleared for block "E3FSBLK,
2015 (unsigned long)bit);
2016 BUFFER_TRACE(bitmap_bh, "bit already cleared");
2017 } else {
2018 freed++;
2019 }
2020 }
2021
2022 /* Update couters */
2023 spin_lock(sb_bgl_lock(sbi, group));
2024 le16_add_cpu(&gdp->bg_free_blocks_count, freed);
2025 spin_unlock(sb_bgl_lock(sbi, group));
2026 percpu_counter_add(&sbi->s_freeblocks_counter, freed);
2027
2028 start = next;
2029 if (err < 0) {
2030 if (err != -EOPNOTSUPP)
2031 ext3_warning(sb, __func__, "Discard command "
2032 "returned error %d\n", err);
2033 break;
2034 }
2035
2036 if (fatal_signal_pending(current)) {
2037 err = -ERESTARTSYS;
2038 break;
2039 }
2040
2041 cond_resched();
2042
2043 /* No more suitable extents */
2044 if (free_blocks < minblocks)
2045 break;
2046 }
2047
2048 /* We dirtied the bitmap block */
2049 BUFFER_TRACE(bitmap_bh, "dirtied bitmap block");
2050 ret = ext3_journal_dirty_metadata(handle, bitmap_bh);
2051 if (!err)
2052 err = ret;
2053
2054 /* And the group descriptor block */
2055 BUFFER_TRACE(gdp_bh, "dirtied group descriptor block");
2056 ret = ext3_journal_dirty_metadata(handle, gdp_bh);
2057 if (!err)
2058 err = ret;
2059
2060 ext3_debug("trimmed %d blocks in the group %d\n",
2061 count, group);
2062
2063err_out:
2064 if (err)
2065 count = err;
2066 ext3_journal_stop(handle);
2067 brelse(bitmap_bh);
2068
2069 return count;
2070}
2071
2072/**
2073 * ext3_trim_fs() -- trim ioctl handle function
2074 * @sb: superblock for filesystem
2075 * @start: First Byte to trim
2076 * @len: number of Bytes to trim from start
2077 * @minlen: minimum extent length in Bytes
2078 *
2079 * ext3_trim_fs goes through all allocation groups containing Bytes from
2080 * start to start+len. For each such a group ext3_trim_all_free function
2081 * is invoked to trim all free space.
2082 */
2083int ext3_trim_fs(struct super_block *sb, struct fstrim_range *range)
2084{
2085 ext3_grpblk_t last_block, first_block, free_blocks;
2086 unsigned long first_group, last_group;
2087 unsigned long group, ngroups;
2088 struct ext3_group_desc *gdp;
2089 struct ext3_super_block *es = EXT3_SB(sb)->s_es;
2090 uint64_t start, len, minlen, trimmed;
2091 ext3_fsblk_t max_blks = le32_to_cpu(es->s_blocks_count);
2092 int ret = 0;
2093
2094 start = (range->start >> sb->s_blocksize_bits) +
2095 le32_to_cpu(es->s_first_data_block);
2096 len = range->len >> sb->s_blocksize_bits;
2097 minlen = range->minlen >> sb->s_blocksize_bits;
2098 trimmed = 0;
2099
2100 if (unlikely(minlen > EXT3_BLOCKS_PER_GROUP(sb)))
2101 return -EINVAL;
2102 if (start >= max_blks)
2103 goto out;
2104 if (start + len > max_blks)
2105 len = max_blks - start;
2106
2107 ngroups = EXT3_SB(sb)->s_groups_count;
2108 smp_rmb();
2109
2110 /* Determine first and last group to examine based on start and len */
2111 ext3_get_group_no_and_offset(sb, (ext3_fsblk_t) start,
2112 &first_group, &first_block);
2113 ext3_get_group_no_and_offset(sb, (ext3_fsblk_t) (start + len),
2114 &last_group, &last_block);
2115 last_group = (last_group > ngroups - 1) ? ngroups - 1 : last_group;
2116 last_block = EXT3_BLOCKS_PER_GROUP(sb);
2117
2118 if (first_group > last_group)
2119 return -EINVAL;
2120
2121 for (group = first_group; group <= last_group; group++) {
2122 gdp = ext3_get_group_desc(sb, group, NULL);
2123 if (!gdp)
2124 break;
2125
2126 free_blocks = le16_to_cpu(gdp->bg_free_blocks_count);
2127 if (free_blocks < minlen)
2128 continue;
2129
2130 /*
2131 * For all the groups except the last one, last block will
2132 * always be EXT3_BLOCKS_PER_GROUP(sb), so we only need to
2133 * change it for the last group in which case first_block +
2134 * len < EXT3_BLOCKS_PER_GROUP(sb).
2135 */
2136 if (first_block + len < EXT3_BLOCKS_PER_GROUP(sb))
2137 last_block = first_block + len;
2138 len -= last_block - first_block;
2139
2140 ret = ext3_trim_all_free(sb, group, first_block,
2141 last_block, minlen);
2142 if (ret < 0)
2143 break;
2144
2145 trimmed += ret;
2146 first_block = 0;
2147 }
2148
2149 if (ret >= 0)
2150 ret = 0;
2151
2152out:
2153 range->len = trimmed * sb->s_blocksize;
2154
2155 return ret;
2156}
diff --git a/fs/ext3/dir.c b/fs/ext3/dir.c
index e2e72c367cf6..34f0a072b935 100644
--- a/fs/ext3/dir.c
+++ b/fs/ext3/dir.c
@@ -69,25 +69,26 @@ int ext3_check_dir_entry (const char * function, struct inode * dir,
69 const char * error_msg = NULL; 69 const char * error_msg = NULL;
70 const int rlen = ext3_rec_len_from_disk(de->rec_len); 70 const int rlen = ext3_rec_len_from_disk(de->rec_len);
71 71
72 if (rlen < EXT3_DIR_REC_LEN(1)) 72 if (unlikely(rlen < EXT3_DIR_REC_LEN(1)))
73 error_msg = "rec_len is smaller than minimal"; 73 error_msg = "rec_len is smaller than minimal";
74 else if (rlen % 4 != 0) 74 else if (unlikely(rlen % 4 != 0))
75 error_msg = "rec_len % 4 != 0"; 75 error_msg = "rec_len % 4 != 0";
76 else if (rlen < EXT3_DIR_REC_LEN(de->name_len)) 76 else if (unlikely(rlen < EXT3_DIR_REC_LEN(de->name_len)))
77 error_msg = "rec_len is too small for name_len"; 77 error_msg = "rec_len is too small for name_len";
78 else if (((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize) 78 else if (unlikely((((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)))
79 error_msg = "directory entry across blocks"; 79 error_msg = "directory entry across blocks";
80 else if (le32_to_cpu(de->inode) > 80 else if (unlikely(le32_to_cpu(de->inode) >
81 le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count)) 81 le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count)))
82 error_msg = "inode out of bounds"; 82 error_msg = "inode out of bounds";
83 83
84 if (error_msg != NULL) 84 if (unlikely(error_msg != NULL))
85 ext3_error (dir->i_sb, function, 85 ext3_error (dir->i_sb, function,
86 "bad entry in directory #%lu: %s - " 86 "bad entry in directory #%lu: %s - "
87 "offset=%lu, inode=%lu, rec_len=%d, name_len=%d", 87 "offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
88 dir->i_ino, error_msg, offset, 88 dir->i_ino, error_msg, offset,
89 (unsigned long) le32_to_cpu(de->inode), 89 (unsigned long) le32_to_cpu(de->inode),
90 rlen, de->name_len); 90 rlen, de->name_len);
91
91 return error_msg == NULL ? 1 : 0; 92 return error_msg == NULL ? 1 : 0;
92} 93}
93 94
diff --git a/fs/ext3/fsync.c b/fs/ext3/fsync.c
index d7e9f74dc3a6..09b13bb34c94 100644
--- a/fs/ext3/fsync.c
+++ b/fs/ext3/fsync.c
@@ -90,7 +90,6 @@ int ext3_sync_file(struct file *file, int datasync)
90 * storage 90 * storage
91 */ 91 */
92 if (needs_barrier) 92 if (needs_barrier)
93 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL, 93 blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
94 BLKDEV_IFL_WAIT);
95 return ret; 94 return ret;
96} 95}
diff --git a/fs/ext3/ialloc.c b/fs/ext3/ialloc.c
index 4ab72db3559e..bfc2dc43681d 100644
--- a/fs/ext3/ialloc.c
+++ b/fs/ext3/ialloc.c
@@ -404,7 +404,8 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
404 * For other inodes, search forward from the parent directory's block 404 * For other inodes, search forward from the parent directory's block
405 * group to find a free inode. 405 * group to find a free inode.
406 */ 406 */
407struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) 407struct inode *ext3_new_inode(handle_t *handle, struct inode * dir,
408 const struct qstr *qstr, int mode)
408{ 409{
409 struct super_block *sb; 410 struct super_block *sb;
410 struct buffer_head *bitmap_bh = NULL; 411 struct buffer_head *bitmap_bh = NULL;
@@ -570,9 +571,14 @@ got:
570 ei->i_state_flags = 0; 571 ei->i_state_flags = 0;
571 ext3_set_inode_state(inode, EXT3_STATE_NEW); 572 ext3_set_inode_state(inode, EXT3_STATE_NEW);
572 573
573 ei->i_extra_isize = 574 /* See comment in ext3_iget for explanation */
574 (EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) ? 575 if (ino >= EXT3_FIRST_INO(sb) + 1 &&
575 sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE : 0; 576 EXT3_INODE_SIZE(sb) > EXT3_GOOD_OLD_INODE_SIZE) {
577 ei->i_extra_isize =
578 sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE;
579 } else {
580 ei->i_extra_isize = 0;
581 }
576 582
577 ret = inode; 583 ret = inode;
578 dquot_initialize(inode); 584 dquot_initialize(inode);
@@ -584,7 +590,7 @@ got:
584 if (err) 590 if (err)
585 goto fail_free_drop; 591 goto fail_free_drop;
586 592
587 err = ext3_init_security(handle,inode, dir); 593 err = ext3_init_security(handle, inode, dir, qstr);
588 if (err) 594 if (err)
589 goto fail_free_drop; 595 goto fail_free_drop;
590 596
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 5e0faf4cda79..3451d23c3bae 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -498,7 +498,7 @@ static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block,
498} 498}
499 499
500/** 500/**
501 * ext3_blks_to_allocate: Look up the block map and count the number 501 * ext3_blks_to_allocate - Look up the block map and count the number
502 * of direct blocks need to be allocated for the given branch. 502 * of direct blocks need to be allocated for the given branch.
503 * 503 *
504 * @branch: chain of indirect blocks 504 * @branch: chain of indirect blocks
@@ -536,14 +536,18 @@ static int ext3_blks_to_allocate(Indirect *branch, int k, unsigned long blks,
536} 536}
537 537
538/** 538/**
539 * ext3_alloc_blocks: multiple allocate blocks needed for a branch 539 * ext3_alloc_blocks - multiple allocate blocks needed for a branch
540 * @handle: handle for this transaction
541 * @inode: owner
542 * @goal: preferred place for allocation
540 * @indirect_blks: the number of blocks need to allocate for indirect 543 * @indirect_blks: the number of blocks need to allocate for indirect
541 * blocks 544 * blocks
542 * 545 * @blks: number of blocks need to allocated for direct blocks
543 * @new_blocks: on return it will store the new block numbers for 546 * @new_blocks: on return it will store the new block numbers for
544 * the indirect blocks(if needed) and the first direct block, 547 * the indirect blocks(if needed) and the first direct block,
545 * @blks: on return it will store the total number of allocated 548 * @err: here we store the error value
546 * direct blocks 549 *
550 * return the number of direct blocks allocated
547 */ 551 */
548static int ext3_alloc_blocks(handle_t *handle, struct inode *inode, 552static int ext3_alloc_blocks(handle_t *handle, struct inode *inode,
549 ext3_fsblk_t goal, int indirect_blks, int blks, 553 ext3_fsblk_t goal, int indirect_blks, int blks,
@@ -598,9 +602,11 @@ failed_out:
598 602
599/** 603/**
600 * ext3_alloc_branch - allocate and set up a chain of blocks. 604 * ext3_alloc_branch - allocate and set up a chain of blocks.
605 * @handle: handle for this transaction
601 * @inode: owner 606 * @inode: owner
602 * @indirect_blks: number of allocated indirect blocks 607 * @indirect_blks: number of allocated indirect blocks
603 * @blks: number of allocated direct blocks 608 * @blks: number of allocated direct blocks
609 * @goal: preferred place for allocation
604 * @offsets: offsets (in the blocks) to store the pointers to next. 610 * @offsets: offsets (in the blocks) to store the pointers to next.
605 * @branch: place to store the chain in. 611 * @branch: place to store the chain in.
606 * 612 *
@@ -700,10 +706,9 @@ failed:
700 706
701/** 707/**
702 * ext3_splice_branch - splice the allocated branch onto inode. 708 * ext3_splice_branch - splice the allocated branch onto inode.
709 * @handle: handle for this transaction
703 * @inode: owner 710 * @inode: owner
704 * @block: (logical) number of block we are adding 711 * @block: (logical) number of block we are adding
705 * @chain: chain of indirect blocks (with a missing link - see
706 * ext3_alloc_branch)
707 * @where: location of missing link 712 * @where: location of missing link
708 * @num: number of indirect blocks we are adding 713 * @num: number of indirect blocks we are adding
709 * @blks: number of direct blocks we are adding 714 * @blks: number of direct blocks we are adding
@@ -1696,8 +1701,8 @@ static int ext3_journalled_writepage(struct page *page,
1696 * doesn't seem much point in redirtying the page here. 1701 * doesn't seem much point in redirtying the page here.
1697 */ 1702 */
1698 ClearPageChecked(page); 1703 ClearPageChecked(page);
1699 ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, 1704 ret = __block_write_begin(page, 0, PAGE_CACHE_SIZE,
1700 ext3_get_block); 1705 ext3_get_block);
1701 if (ret != 0) { 1706 if (ret != 0) {
1702 ext3_journal_stop(handle); 1707 ext3_journal_stop(handle);
1703 goto out_unlock; 1708 goto out_unlock;
@@ -1889,7 +1894,6 @@ static const struct address_space_operations ext3_ordered_aops = {
1889 .readpage = ext3_readpage, 1894 .readpage = ext3_readpage,
1890 .readpages = ext3_readpages, 1895 .readpages = ext3_readpages,
1891 .writepage = ext3_ordered_writepage, 1896 .writepage = ext3_ordered_writepage,
1892 .sync_page = block_sync_page,
1893 .write_begin = ext3_write_begin, 1897 .write_begin = ext3_write_begin,
1894 .write_end = ext3_ordered_write_end, 1898 .write_end = ext3_ordered_write_end,
1895 .bmap = ext3_bmap, 1899 .bmap = ext3_bmap,
@@ -1905,7 +1909,6 @@ static const struct address_space_operations ext3_writeback_aops = {
1905 .readpage = ext3_readpage, 1909 .readpage = ext3_readpage,
1906 .readpages = ext3_readpages, 1910 .readpages = ext3_readpages,
1907 .writepage = ext3_writeback_writepage, 1911 .writepage = ext3_writeback_writepage,
1908 .sync_page = block_sync_page,
1909 .write_begin = ext3_write_begin, 1912 .write_begin = ext3_write_begin,
1910 .write_end = ext3_writeback_write_end, 1913 .write_end = ext3_writeback_write_end,
1911 .bmap = ext3_bmap, 1914 .bmap = ext3_bmap,
@@ -1921,7 +1924,6 @@ static const struct address_space_operations ext3_journalled_aops = {
1921 .readpage = ext3_readpage, 1924 .readpage = ext3_readpage,
1922 .readpages = ext3_readpages, 1925 .readpages = ext3_readpages,
1923 .writepage = ext3_journalled_writepage, 1926 .writepage = ext3_journalled_writepage,
1924 .sync_page = block_sync_page,
1925 .write_begin = ext3_write_begin, 1927 .write_begin = ext3_write_begin,
1926 .write_end = ext3_journalled_write_end, 1928 .write_end = ext3_journalled_write_end,
1927 .set_page_dirty = ext3_journalled_set_page_dirty, 1929 .set_page_dirty = ext3_journalled_set_page_dirty,
@@ -2053,7 +2055,7 @@ static inline int all_zeroes(__le32 *p, __le32 *q)
2053 * 2055 *
2054 * When we do truncate() we may have to clean the ends of several 2056 * When we do truncate() we may have to clean the ends of several
2055 * indirect blocks but leave the blocks themselves alive. Block is 2057 * indirect blocks but leave the blocks themselves alive. Block is
2056 * partially truncated if some data below the new i_size is refered 2058 * partially truncated if some data below the new i_size is referred
2057 * from it (and it is on the path to the first completely truncated 2059 * from it (and it is on the path to the first completely truncated
2058 * data block, indeed). We have to free the top of that path along 2060 * data block, indeed). We have to free the top of that path along
2059 * with everything to the right of the path. Since no allocation 2061 * with everything to the right of the path. Since no allocation
@@ -2140,13 +2142,15 @@ static void ext3_clear_blocks(handle_t *handle, struct inode *inode,
2140 if (try_to_extend_transaction(handle, inode)) { 2142 if (try_to_extend_transaction(handle, inode)) {
2141 if (bh) { 2143 if (bh) {
2142 BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); 2144 BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata");
2143 ext3_journal_dirty_metadata(handle, bh); 2145 if (ext3_journal_dirty_metadata(handle, bh))
2146 return;
2144 } 2147 }
2145 ext3_mark_inode_dirty(handle, inode); 2148 ext3_mark_inode_dirty(handle, inode);
2146 truncate_restart_transaction(handle, inode); 2149 truncate_restart_transaction(handle, inode);
2147 if (bh) { 2150 if (bh) {
2148 BUFFER_TRACE(bh, "retaking write access"); 2151 BUFFER_TRACE(bh, "retaking write access");
2149 ext3_journal_get_write_access(handle, bh); 2152 if (ext3_journal_get_write_access(handle, bh))
2153 return;
2150 } 2154 }
2151 } 2155 }
2152 2156
@@ -2180,7 +2184,7 @@ static void ext3_clear_blocks(handle_t *handle, struct inode *inode,
2180 * @first: array of block numbers 2184 * @first: array of block numbers
2181 * @last: points immediately past the end of array 2185 * @last: points immediately past the end of array
2182 * 2186 *
2183 * We are freeing all blocks refered from that array (numbers are stored as 2187 * We are freeing all blocks referred from that array (numbers are stored as
2184 * little-endian 32-bit) and updating @inode->i_blocks appropriately. 2188 * little-endian 32-bit) and updating @inode->i_blocks appropriately.
2185 * 2189 *
2186 * We accumulate contiguous runs of blocks to free. Conveniently, if these 2190 * We accumulate contiguous runs of blocks to free. Conveniently, if these
@@ -2268,7 +2272,7 @@ static void ext3_free_data(handle_t *handle, struct inode *inode,
2268 * @last: pointer immediately past the end of array 2272 * @last: pointer immediately past the end of array
2269 * @depth: depth of the branches to free 2273 * @depth: depth of the branches to free
2270 * 2274 *
2271 * We are freeing all blocks refered from these branches (numbers are 2275 * We are freeing all blocks referred from these branches (numbers are
2272 * stored as little-endian 32-bit) and updating @inode->i_blocks 2276 * stored as little-endian 32-bit) and updating @inode->i_blocks
2273 * appropriately. 2277 * appropriately.
2274 */ 2278 */
@@ -2530,7 +2534,6 @@ void ext3_truncate(struct inode *inode)
2530 */ 2534 */
2531 } else { 2535 } else {
2532 /* Shared branch grows from an indirect block */ 2536 /* Shared branch grows from an indirect block */
2533 BUFFER_TRACE(partial->bh, "get_write_access");
2534 ext3_free_branches(handle, inode, partial->bh, 2537 ext3_free_branches(handle, inode, partial->bh,
2535 partial->p, 2538 partial->p,
2536 partial->p+1, (chain+n-1) - partial); 2539 partial->p+1, (chain+n-1) - partial);
@@ -3288,7 +3291,7 @@ static int ext3_writepage_trans_blocks(struct inode *inode)
3288 if (ext3_should_journal_data(inode)) 3291 if (ext3_should_journal_data(inode))
3289 ret = 3 * (bpp + indirects) + 2; 3292 ret = 3 * (bpp + indirects) + 2;
3290 else 3293 else
3291 ret = 2 * (bpp + indirects) + 2; 3294 ret = 2 * (bpp + indirects) + indirects + 2;
3292 3295
3293#ifdef CONFIG_QUOTA 3296#ifdef CONFIG_QUOTA
3294 /* We know that structure was already allocated during dquot_initialize so 3297 /* We know that structure was already allocated during dquot_initialize so
@@ -3389,7 +3392,7 @@ int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode)
3389 * so would cause a commit on atime updates, which we don't bother doing. 3392 * so would cause a commit on atime updates, which we don't bother doing.
3390 * We handle synchronous inodes at the highest possible level. 3393 * We handle synchronous inodes at the highest possible level.
3391 */ 3394 */
3392void ext3_dirty_inode(struct inode *inode) 3395void ext3_dirty_inode(struct inode *inode, int flags)
3393{ 3396{
3394 handle_t *current_handle = ext3_journal_current_handle(); 3397 handle_t *current_handle = ext3_journal_current_handle();
3395 handle_t *handle; 3398 handle_t *handle;
diff --git a/fs/ext3/ioctl.c b/fs/ext3/ioctl.c
index 88974814783a..f4090bd2f345 100644
--- a/fs/ext3/ioctl.c
+++ b/fs/ext3/ioctl.c
@@ -38,7 +38,7 @@ long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38 unsigned int oldflags; 38 unsigned int oldflags;
39 unsigned int jflag; 39 unsigned int jflag;
40 40
41 if (!is_owner_or_cap(inode)) 41 if (!inode_owner_or_capable(inode))
42 return -EACCES; 42 return -EACCES;
43 43
44 if (get_user(flags, (int __user *) arg)) 44 if (get_user(flags, (int __user *) arg))
@@ -123,7 +123,7 @@ flags_out:
123 __u32 generation; 123 __u32 generation;
124 int err; 124 int err;
125 125
126 if (!is_owner_or_cap(inode)) 126 if (!inode_owner_or_capable(inode))
127 return -EPERM; 127 return -EPERM;
128 128
129 err = mnt_want_write(filp->f_path.mnt); 129 err = mnt_want_write(filp->f_path.mnt);
@@ -192,7 +192,7 @@ setversion_out:
192 if (err) 192 if (err)
193 return err; 193 return err;
194 194
195 if (!is_owner_or_cap(inode)) { 195 if (!inode_owner_or_capable(inode)) {
196 err = -EACCES; 196 err = -EACCES;
197 goto setrsvsz_out; 197 goto setrsvsz_out;
198 } 198 }
@@ -276,7 +276,29 @@ group_add_out:
276 mnt_drop_write(filp->f_path.mnt); 276 mnt_drop_write(filp->f_path.mnt);
277 return err; 277 return err;
278 } 278 }
279 case FITRIM: {
279 280
281 struct super_block *sb = inode->i_sb;
282 struct fstrim_range range;
283 int ret = 0;
284
285 if (!capable(CAP_SYS_ADMIN))
286 return -EPERM;
287
288 if (copy_from_user(&range, (struct fstrim_range *)arg,
289 sizeof(range)))
290 return -EFAULT;
291
292 ret = ext3_trim_fs(sb, &range);
293 if (ret < 0)
294 return ret;
295
296 if (copy_to_user((struct fstrim_range *)arg, &range,
297 sizeof(range)))
298 return -EFAULT;
299
300 return 0;
301 }
280 302
281 default: 303 default:
282 return -ENOTTY; 304 return -ENOTTY;
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index 2b35ddb70d65..34b6d9bfc48a 100644
--- a/fs/ext3/namei.c
+++ b/fs/ext3/namei.c
@@ -858,6 +858,7 @@ static struct buffer_head *ext3_find_entry(struct inode *dir,
858 struct buffer_head * bh_use[NAMEI_RA_SIZE]; 858 struct buffer_head * bh_use[NAMEI_RA_SIZE];
859 struct buffer_head * bh, *ret = NULL; 859 struct buffer_head * bh, *ret = NULL;
860 unsigned long start, block, b; 860 unsigned long start, block, b;
861 const u8 *name = entry->name;
861 int ra_max = 0; /* Number of bh's in the readahead 862 int ra_max = 0; /* Number of bh's in the readahead
862 buffer, bh_use[] */ 863 buffer, bh_use[] */
863 int ra_ptr = 0; /* Current index into readahead 864 int ra_ptr = 0; /* Current index into readahead
@@ -871,6 +872,16 @@ static struct buffer_head *ext3_find_entry(struct inode *dir,
871 namelen = entry->len; 872 namelen = entry->len;
872 if (namelen > EXT3_NAME_LEN) 873 if (namelen > EXT3_NAME_LEN)
873 return NULL; 874 return NULL;
875 if ((namelen <= 2) && (name[0] == '.') &&
876 (name[1] == '.' || name[1] == 0)) {
877 /*
878 * "." or ".." will only be in the first block
879 * NFS may look up ".."; "." should be handled by the VFS
880 */
881 block = start = 0;
882 nblocks = 1;
883 goto restart;
884 }
874 if (is_dx(dir)) { 885 if (is_dx(dir)) {
875 bh = ext3_dx_find_entry(dir, entry, res_dir, &err); 886 bh = ext3_dx_find_entry(dir, entry, res_dir, &err);
876 /* 887 /*
@@ -961,55 +972,35 @@ static struct buffer_head * ext3_dx_find_entry(struct inode *dir,
961 struct qstr *entry, struct ext3_dir_entry_2 **res_dir, 972 struct qstr *entry, struct ext3_dir_entry_2 **res_dir,
962 int *err) 973 int *err)
963{ 974{
964 struct super_block * sb; 975 struct super_block *sb = dir->i_sb;
965 struct dx_hash_info hinfo; 976 struct dx_hash_info hinfo;
966 u32 hash;
967 struct dx_frame frames[2], *frame; 977 struct dx_frame frames[2], *frame;
968 struct ext3_dir_entry_2 *de, *top;
969 struct buffer_head *bh; 978 struct buffer_head *bh;
970 unsigned long block; 979 unsigned long block;
971 int retval; 980 int retval;
972 int namelen = entry->len;
973 const u8 *name = entry->name;
974 981
975 sb = dir->i_sb; 982 if (!(frame = dx_probe(entry, dir, &hinfo, frames, err)))
976 /* NFS may look up ".." - look at dx_root directory block */ 983 return NULL;
977 if (namelen > 2 || name[0] != '.'|| (namelen == 2 && name[1] != '.')) {
978 if (!(frame = dx_probe(entry, dir, &hinfo, frames, err)))
979 return NULL;
980 } else {
981 frame = frames;
982 frame->bh = NULL; /* for dx_release() */
983 frame->at = (struct dx_entry *)frames; /* hack for zero entry*/
984 dx_set_block(frame->at, 0); /* dx_root block is 0 */
985 }
986 hash = hinfo.hash;
987 do { 984 do {
988 block = dx_get_block(frame->at); 985 block = dx_get_block(frame->at);
989 if (!(bh = ext3_bread (NULL,dir, block, 0, err))) 986 if (!(bh = ext3_bread (NULL,dir, block, 0, err)))
990 goto errout; 987 goto errout;
991 de = (struct ext3_dir_entry_2 *) bh->b_data;
992 top = (struct ext3_dir_entry_2 *) ((char *) de + sb->s_blocksize -
993 EXT3_DIR_REC_LEN(0));
994 for (; de < top; de = ext3_next_entry(de)) {
995 int off = (block << EXT3_BLOCK_SIZE_BITS(sb))
996 + ((char *) de - bh->b_data);
997
998 if (!ext3_check_dir_entry(__func__, dir, de, bh, off)) {
999 brelse(bh);
1000 *err = ERR_BAD_DX_DIR;
1001 goto errout;
1002 }
1003 988
1004 if (ext3_match(namelen, name, de)) { 989 retval = search_dirblock(bh, dir, entry,
1005 *res_dir = de; 990 block << EXT3_BLOCK_SIZE_BITS(sb),
1006 dx_release(frames); 991 res_dir);
1007 return bh; 992 if (retval == 1) {
1008 } 993 dx_release(frames);
994 return bh;
1009 } 995 }
1010 brelse (bh); 996 brelse(bh);
997 if (retval == -1) {
998 *err = ERR_BAD_DX_DIR;
999 goto errout;
1000 }
1001
1011 /* Check to see if we should continue to search */ 1002 /* Check to see if we should continue to search */
1012 retval = ext3_htree_next_block(dir, hash, frame, 1003 retval = ext3_htree_next_block(dir, hinfo.hash, frame,
1013 frames, NULL); 1004 frames, NULL);
1014 if (retval < 0) { 1005 if (retval < 0) {
1015 ext3_warning(sb, __func__, 1006 ext3_warning(sb, __func__,
@@ -1047,7 +1038,7 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, str
1047 return ERR_PTR(-EIO); 1038 return ERR_PTR(-EIO);
1048 } 1039 }
1049 inode = ext3_iget(dir->i_sb, ino); 1040 inode = ext3_iget(dir->i_sb, ino);
1050 if (unlikely(IS_ERR(inode))) { 1041 if (IS_ERR(inode)) {
1051 if (PTR_ERR(inode) == -ESTALE) { 1042 if (PTR_ERR(inode) == -ESTALE) {
1052 ext3_error(dir->i_sb, __func__, 1043 ext3_error(dir->i_sb, __func__,
1053 "deleted inode referenced: %lu", 1044 "deleted inode referenced: %lu",
@@ -1425,10 +1416,19 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1425 frame->at = entries; 1416 frame->at = entries;
1426 frame->bh = bh; 1417 frame->bh = bh;
1427 bh = bh2; 1418 bh = bh2;
1419 /*
1420 * Mark buffers dirty here so that if do_split() fails we write a
1421 * consistent set of buffers to disk.
1422 */
1423 ext3_journal_dirty_metadata(handle, frame->bh);
1424 ext3_journal_dirty_metadata(handle, bh);
1428 de = do_split(handle,dir, &bh, frame, &hinfo, &retval); 1425 de = do_split(handle,dir, &bh, frame, &hinfo, &retval);
1429 dx_release (frames); 1426 if (!de) {
1430 if (!(de)) 1427 ext3_mark_inode_dirty(handle, dir);
1428 dx_release(frames);
1431 return retval; 1429 return retval;
1430 }
1431 dx_release(frames);
1432 1432
1433 return add_dirent_to_buf(handle, dentry, inode, de, bh); 1433 return add_dirent_to_buf(handle, dentry, inode, de, bh);
1434} 1434}
@@ -1549,8 +1549,8 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1549 goto cleanup; 1549 goto cleanup;
1550 node2 = (struct dx_node *)(bh2->b_data); 1550 node2 = (struct dx_node *)(bh2->b_data);
1551 entries2 = node2->entries; 1551 entries2 = node2->entries;
1552 memset(&node2->fake, 0, sizeof(struct fake_dirent));
1552 node2->fake.rec_len = ext3_rec_len_to_disk(sb->s_blocksize); 1553 node2->fake.rec_len = ext3_rec_len_to_disk(sb->s_blocksize);
1553 node2->fake.inode = 0;
1554 BUFFER_TRACE(frame->bh, "get_write_access"); 1554 BUFFER_TRACE(frame->bh, "get_write_access");
1555 err = ext3_journal_get_write_access(handle, frame->bh); 1555 err = ext3_journal_get_write_access(handle, frame->bh);
1556 if (err) 1556 if (err)
@@ -1607,7 +1607,9 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1607 if (err) 1607 if (err)
1608 goto journal_error; 1608 goto journal_error;
1609 } 1609 }
1610 ext3_journal_dirty_metadata(handle, frames[0].bh); 1610 err = ext3_journal_dirty_metadata(handle, frames[0].bh);
1611 if (err)
1612 goto journal_error;
1611 } 1613 }
1612 de = do_split(handle, dir, &bh, frame, &hinfo, &err); 1614 de = do_split(handle, dir, &bh, frame, &hinfo, &err);
1613 if (!de) 1615 if (!de)
@@ -1644,8 +1646,13 @@ static int ext3_delete_entry (handle_t *handle,
1644 if (!ext3_check_dir_entry("ext3_delete_entry", dir, de, bh, i)) 1646 if (!ext3_check_dir_entry("ext3_delete_entry", dir, de, bh, i))
1645 return -EIO; 1647 return -EIO;
1646 if (de == de_del) { 1648 if (de == de_del) {
1649 int err;
1650
1647 BUFFER_TRACE(bh, "get_write_access"); 1651 BUFFER_TRACE(bh, "get_write_access");
1648 ext3_journal_get_write_access(handle, bh); 1652 err = ext3_journal_get_write_access(handle, bh);
1653 if (err)
1654 goto journal_error;
1655
1649 if (pde) 1656 if (pde)
1650 pde->rec_len = ext3_rec_len_to_disk( 1657 pde->rec_len = ext3_rec_len_to_disk(
1651 ext3_rec_len_from_disk(pde->rec_len) + 1658 ext3_rec_len_from_disk(pde->rec_len) +
@@ -1654,7 +1661,12 @@ static int ext3_delete_entry (handle_t *handle,
1654 de->inode = 0; 1661 de->inode = 0;
1655 dir->i_version++; 1662 dir->i_version++;
1656 BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); 1663 BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata");
1657 ext3_journal_dirty_metadata(handle, bh); 1664 err = ext3_journal_dirty_metadata(handle, bh);
1665 if (err) {
1666journal_error:
1667 ext3_std_error(dir->i_sb, err);
1668 return err;
1669 }
1658 return 0; 1670 return 0;
1659 } 1671 }
1660 i += ext3_rec_len_from_disk(de->rec_len); 1672 i += ext3_rec_len_from_disk(de->rec_len);
@@ -1707,7 +1719,7 @@ retry:
1707 if (IS_DIRSYNC(dir)) 1719 if (IS_DIRSYNC(dir))
1708 handle->h_sync = 1; 1720 handle->h_sync = 1;
1709 1721
1710 inode = ext3_new_inode (handle, dir, mode); 1722 inode = ext3_new_inode (handle, dir, &dentry->d_name, mode);
1711 err = PTR_ERR(inode); 1723 err = PTR_ERR(inode);
1712 if (!IS_ERR(inode)) { 1724 if (!IS_ERR(inode)) {
1713 inode->i_op = &ext3_file_inode_operations; 1725 inode->i_op = &ext3_file_inode_operations;
@@ -1743,7 +1755,7 @@ retry:
1743 if (IS_DIRSYNC(dir)) 1755 if (IS_DIRSYNC(dir))
1744 handle->h_sync = 1; 1756 handle->h_sync = 1;
1745 1757
1746 inode = ext3_new_inode (handle, dir, mode); 1758 inode = ext3_new_inode (handle, dir, &dentry->d_name, mode);
1747 err = PTR_ERR(inode); 1759 err = PTR_ERR(inode);
1748 if (!IS_ERR(inode)) { 1760 if (!IS_ERR(inode)) {
1749 init_special_inode(inode, inode->i_mode, rdev); 1761 init_special_inode(inode, inode->i_mode, rdev);
@@ -1762,7 +1774,7 @@ static int ext3_mkdir(struct inode * dir, struct dentry * dentry, int mode)
1762{ 1774{
1763 handle_t *handle; 1775 handle_t *handle;
1764 struct inode * inode; 1776 struct inode * inode;
1765 struct buffer_head * dir_block; 1777 struct buffer_head * dir_block = NULL;
1766 struct ext3_dir_entry_2 * de; 1778 struct ext3_dir_entry_2 * de;
1767 int err, retries = 0; 1779 int err, retries = 0;
1768 1780
@@ -1781,7 +1793,7 @@ retry:
1781 if (IS_DIRSYNC(dir)) 1793 if (IS_DIRSYNC(dir))
1782 handle->h_sync = 1; 1794 handle->h_sync = 1;
1783 1795
1784 inode = ext3_new_inode (handle, dir, S_IFDIR | mode); 1796 inode = ext3_new_inode (handle, dir, &dentry->d_name, S_IFDIR | mode);
1785 err = PTR_ERR(inode); 1797 err = PTR_ERR(inode);
1786 if (IS_ERR(inode)) 1798 if (IS_ERR(inode))
1787 goto out_stop; 1799 goto out_stop;
@@ -1790,15 +1802,14 @@ retry:
1790 inode->i_fop = &ext3_dir_operations; 1802 inode->i_fop = &ext3_dir_operations;
1791 inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize; 1803 inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
1792 dir_block = ext3_bread (handle, inode, 0, 1, &err); 1804 dir_block = ext3_bread (handle, inode, 0, 1, &err);
1793 if (!dir_block) { 1805 if (!dir_block)
1794 drop_nlink(inode); /* is this nlink == 0? */ 1806 goto out_clear_inode;
1795 unlock_new_inode(inode); 1807
1796 ext3_mark_inode_dirty(handle, inode);
1797 iput (inode);
1798 goto out_stop;
1799 }
1800 BUFFER_TRACE(dir_block, "get_write_access"); 1808 BUFFER_TRACE(dir_block, "get_write_access");
1801 ext3_journal_get_write_access(handle, dir_block); 1809 err = ext3_journal_get_write_access(handle, dir_block);
1810 if (err)
1811 goto out_clear_inode;
1812
1802 de = (struct ext3_dir_entry_2 *) dir_block->b_data; 1813 de = (struct ext3_dir_entry_2 *) dir_block->b_data;
1803 de->inode = cpu_to_le32(inode->i_ino); 1814 de->inode = cpu_to_le32(inode->i_ino);
1804 de->name_len = 1; 1815 de->name_len = 1;
@@ -1814,11 +1825,16 @@ retry:
1814 ext3_set_de_type(dir->i_sb, de, S_IFDIR); 1825 ext3_set_de_type(dir->i_sb, de, S_IFDIR);
1815 inode->i_nlink = 2; 1826 inode->i_nlink = 2;
1816 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata"); 1827 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata");
1817 ext3_journal_dirty_metadata(handle, dir_block); 1828 err = ext3_journal_dirty_metadata(handle, dir_block);
1818 brelse (dir_block); 1829 if (err)
1819 ext3_mark_inode_dirty(handle, inode); 1830 goto out_clear_inode;
1820 err = ext3_add_entry (handle, dentry, inode); 1831
1832 err = ext3_mark_inode_dirty(handle, inode);
1833 if (!err)
1834 err = ext3_add_entry (handle, dentry, inode);
1835
1821 if (err) { 1836 if (err) {
1837out_clear_inode:
1822 inode->i_nlink = 0; 1838 inode->i_nlink = 0;
1823 unlock_new_inode(inode); 1839 unlock_new_inode(inode);
1824 ext3_mark_inode_dirty(handle, inode); 1840 ext3_mark_inode_dirty(handle, inode);
@@ -1827,10 +1843,14 @@ retry:
1827 } 1843 }
1828 inc_nlink(dir); 1844 inc_nlink(dir);
1829 ext3_update_dx_flag(dir); 1845 ext3_update_dx_flag(dir);
1830 ext3_mark_inode_dirty(handle, dir); 1846 err = ext3_mark_inode_dirty(handle, dir);
1847 if (err)
1848 goto out_clear_inode;
1849
1831 d_instantiate(dentry, inode); 1850 d_instantiate(dentry, inode);
1832 unlock_new_inode(inode); 1851 unlock_new_inode(inode);
1833out_stop: 1852out_stop:
1853 brelse(dir_block);
1834 ext3_journal_stop(handle); 1854 ext3_journal_stop(handle);
1835 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) 1855 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
1836 goto retry; 1856 goto retry;
@@ -2178,6 +2198,7 @@ static int ext3_symlink (struct inode * dir,
2178 handle_t *handle; 2198 handle_t *handle;
2179 struct inode * inode; 2199 struct inode * inode;
2180 int l, err, retries = 0; 2200 int l, err, retries = 0;
2201 int credits;
2181 2202
2182 l = strlen(symname)+1; 2203 l = strlen(symname)+1;
2183 if (l > dir->i_sb->s_blocksize) 2204 if (l > dir->i_sb->s_blocksize)
@@ -2185,36 +2206,76 @@ static int ext3_symlink (struct inode * dir,
2185 2206
2186 dquot_initialize(dir); 2207 dquot_initialize(dir);
2187 2208
2209 if (l > EXT3_N_BLOCKS * 4) {
2210 /*
2211 * For non-fast symlinks, we just allocate inode and put it on
2212 * orphan list in the first transaction => we need bitmap,
2213 * group descriptor, sb, inode block, quota blocks.
2214 */
2215 credits = 4 + EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb);
2216 } else {
2217 /*
2218 * Fast symlink. We have to add entry to directory
2219 * (EXT3_DATA_TRANS_BLOCKS + EXT3_INDEX_EXTRA_TRANS_BLOCKS),
2220 * allocate new inode (bitmap, group descriptor, inode block,
2221 * quota blocks, sb is already counted in previous macros).
2222 */
2223 credits = EXT3_DATA_TRANS_BLOCKS(dir->i_sb) +
2224 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 +
2225 EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb);
2226 }
2188retry: 2227retry:
2189 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 2228 handle = ext3_journal_start(dir, credits);
2190 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 5 +
2191 EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
2192 if (IS_ERR(handle)) 2229 if (IS_ERR(handle))
2193 return PTR_ERR(handle); 2230 return PTR_ERR(handle);
2194 2231
2195 if (IS_DIRSYNC(dir)) 2232 if (IS_DIRSYNC(dir))
2196 handle->h_sync = 1; 2233 handle->h_sync = 1;
2197 2234
2198 inode = ext3_new_inode (handle, dir, S_IFLNK|S_IRWXUGO); 2235 inode = ext3_new_inode (handle, dir, &dentry->d_name, S_IFLNK|S_IRWXUGO);
2199 err = PTR_ERR(inode); 2236 err = PTR_ERR(inode);
2200 if (IS_ERR(inode)) 2237 if (IS_ERR(inode))
2201 goto out_stop; 2238 goto out_stop;
2202 2239
2203 if (l > sizeof (EXT3_I(inode)->i_data)) { 2240 if (l > EXT3_N_BLOCKS * 4) {
2204 inode->i_op = &ext3_symlink_inode_operations; 2241 inode->i_op = &ext3_symlink_inode_operations;
2205 ext3_set_aops(inode); 2242 ext3_set_aops(inode);
2206 /* 2243 /*
2207 * page_symlink() calls into ext3_prepare/commit_write. 2244 * We cannot call page_symlink() with transaction started
2208 * We have a transaction open. All is sweetness. It also sets 2245 * because it calls into ext3_write_begin() which acquires page
2209 * i_size in generic_commit_write(). 2246 * lock which ranks below transaction start (and it can also
2247 * wait for journal commit if we are running out of space). So
2248 * we have to stop transaction now and restart it when symlink
2249 * contents is written.
2250 *
2251 * To keep fs consistent in case of crash, we have to put inode
2252 * to orphan list in the mean time.
2210 */ 2253 */
2254 drop_nlink(inode);
2255 err = ext3_orphan_add(handle, inode);
2256 ext3_journal_stop(handle);
2257 if (err)
2258 goto err_drop_inode;
2211 err = __page_symlink(inode, symname, l, 1); 2259 err = __page_symlink(inode, symname, l, 1);
2260 if (err)
2261 goto err_drop_inode;
2262 /*
2263 * Now inode is being linked into dir (EXT3_DATA_TRANS_BLOCKS
2264 * + EXT3_INDEX_EXTRA_TRANS_BLOCKS), inode is also modified
2265 */
2266 handle = ext3_journal_start(dir,
2267 EXT3_DATA_TRANS_BLOCKS(dir->i_sb) +
2268 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 1);
2269 if (IS_ERR(handle)) {
2270 err = PTR_ERR(handle);
2271 goto err_drop_inode;
2272 }
2273 inc_nlink(inode);
2274 err = ext3_orphan_del(handle, inode);
2212 if (err) { 2275 if (err) {
2276 ext3_journal_stop(handle);
2213 drop_nlink(inode); 2277 drop_nlink(inode);
2214 unlock_new_inode(inode); 2278 goto err_drop_inode;
2215 ext3_mark_inode_dirty(handle, inode);
2216 iput (inode);
2217 goto out_stop;
2218 } 2279 }
2219 } else { 2280 } else {
2220 inode->i_op = &ext3_fast_symlink_inode_operations; 2281 inode->i_op = &ext3_fast_symlink_inode_operations;
@@ -2228,6 +2289,10 @@ out_stop:
2228 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) 2289 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
2229 goto retry; 2290 goto retry;
2230 return err; 2291 return err;
2292err_drop_inode:
2293 unlock_new_inode(inode);
2294 iput(inode);
2295 return err;
2231} 2296}
2232 2297
2233static int ext3_link (struct dentry * old_dentry, 2298static int ext3_link (struct dentry * old_dentry,
@@ -2242,13 +2307,6 @@ static int ext3_link (struct dentry * old_dentry,
2242 2307
2243 dquot_initialize(dir); 2308 dquot_initialize(dir);
2244 2309
2245 /*
2246 * Return -ENOENT if we've raced with unlink and i_nlink is 0. Doing
2247 * otherwise has the potential to corrupt the orphan inode list.
2248 */
2249 if (inode->i_nlink == 0)
2250 return -ENOENT;
2251
2252retry: 2310retry:
2253 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 2311 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) +
2254 EXT3_INDEX_EXTRA_TRANS_BLOCKS); 2312 EXT3_INDEX_EXTRA_TRANS_BLOCKS);
@@ -2260,7 +2318,7 @@ retry:
2260 2318
2261 inode->i_ctime = CURRENT_TIME_SEC; 2319 inode->i_ctime = CURRENT_TIME_SEC;
2262 inc_nlink(inode); 2320 inc_nlink(inode);
2263 atomic_inc(&inode->i_count); 2321 ihold(inode);
2264 2322
2265 err = ext3_add_entry(handle, dentry, inode); 2323 err = ext3_add_entry(handle, dentry, inode);
2266 if (!err) { 2324 if (!err) {
@@ -2353,7 +2411,9 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2353 goto end_rename; 2411 goto end_rename;
2354 } else { 2412 } else {
2355 BUFFER_TRACE(new_bh, "get write access"); 2413 BUFFER_TRACE(new_bh, "get write access");
2356 ext3_journal_get_write_access(handle, new_bh); 2414 retval = ext3_journal_get_write_access(handle, new_bh);
2415 if (retval)
2416 goto journal_error;
2357 new_de->inode = cpu_to_le32(old_inode->i_ino); 2417 new_de->inode = cpu_to_le32(old_inode->i_ino);
2358 if (EXT3_HAS_INCOMPAT_FEATURE(new_dir->i_sb, 2418 if (EXT3_HAS_INCOMPAT_FEATURE(new_dir->i_sb,
2359 EXT3_FEATURE_INCOMPAT_FILETYPE)) 2419 EXT3_FEATURE_INCOMPAT_FILETYPE))
@@ -2362,7 +2422,9 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2362 new_dir->i_ctime = new_dir->i_mtime = CURRENT_TIME_SEC; 2422 new_dir->i_ctime = new_dir->i_mtime = CURRENT_TIME_SEC;
2363 ext3_mark_inode_dirty(handle, new_dir); 2423 ext3_mark_inode_dirty(handle, new_dir);
2364 BUFFER_TRACE(new_bh, "call ext3_journal_dirty_metadata"); 2424 BUFFER_TRACE(new_bh, "call ext3_journal_dirty_metadata");
2365 ext3_journal_dirty_metadata(handle, new_bh); 2425 retval = ext3_journal_dirty_metadata(handle, new_bh);
2426 if (retval)
2427 goto journal_error;
2366 brelse(new_bh); 2428 brelse(new_bh);
2367 new_bh = NULL; 2429 new_bh = NULL;
2368 } 2430 }
@@ -2411,10 +2473,17 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2411 ext3_update_dx_flag(old_dir); 2473 ext3_update_dx_flag(old_dir);
2412 if (dir_bh) { 2474 if (dir_bh) {
2413 BUFFER_TRACE(dir_bh, "get_write_access"); 2475 BUFFER_TRACE(dir_bh, "get_write_access");
2414 ext3_journal_get_write_access(handle, dir_bh); 2476 retval = ext3_journal_get_write_access(handle, dir_bh);
2477 if (retval)
2478 goto journal_error;
2415 PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino); 2479 PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino);
2416 BUFFER_TRACE(dir_bh, "call ext3_journal_dirty_metadata"); 2480 BUFFER_TRACE(dir_bh, "call ext3_journal_dirty_metadata");
2417 ext3_journal_dirty_metadata(handle, dir_bh); 2481 retval = ext3_journal_dirty_metadata(handle, dir_bh);
2482 if (retval) {
2483journal_error:
2484 ext3_std_error(new_dir->i_sb, retval);
2485 goto end_rename;
2486 }
2418 drop_nlink(old_dir); 2487 drop_nlink(old_dir);
2419 if (new_inode) { 2488 if (new_inode) {
2420 drop_nlink(new_inode); 2489 drop_nlink(new_inode);
diff --git a/fs/ext3/resize.c b/fs/ext3/resize.c
index 0ccd7b12b73c..7916e4ce166a 100644
--- a/fs/ext3/resize.c
+++ b/fs/ext3/resize.c
@@ -249,7 +249,11 @@ static int setup_new_group_blocks(struct super_block *sb,
249 memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, gdb->b_size); 249 memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, gdb->b_size);
250 set_buffer_uptodate(gdb); 250 set_buffer_uptodate(gdb);
251 unlock_buffer(gdb); 251 unlock_buffer(gdb);
252 ext3_journal_dirty_metadata(handle, gdb); 252 err = ext3_journal_dirty_metadata(handle, gdb);
253 if (err) {
254 brelse(gdb);
255 goto exit_bh;
256 }
253 ext3_set_bit(bit, bh->b_data); 257 ext3_set_bit(bit, bh->b_data);
254 brelse(gdb); 258 brelse(gdb);
255 } 259 }
@@ -269,7 +273,11 @@ static int setup_new_group_blocks(struct super_block *sb,
269 err = PTR_ERR(gdb); 273 err = PTR_ERR(gdb);
270 goto exit_bh; 274 goto exit_bh;
271 } 275 }
272 ext3_journal_dirty_metadata(handle, gdb); 276 err = ext3_journal_dirty_metadata(handle, gdb);
277 if (err) {
278 brelse(gdb);
279 goto exit_bh;
280 }
273 ext3_set_bit(bit, bh->b_data); 281 ext3_set_bit(bit, bh->b_data);
274 brelse(gdb); 282 brelse(gdb);
275 } 283 }
@@ -295,7 +303,11 @@ static int setup_new_group_blocks(struct super_block *sb,
295 err = PTR_ERR(it); 303 err = PTR_ERR(it);
296 goto exit_bh; 304 goto exit_bh;
297 } 305 }
298 ext3_journal_dirty_metadata(handle, it); 306 err = ext3_journal_dirty_metadata(handle, it);
307 if (err) {
308 brelse(it);
309 goto exit_bh;
310 }
299 brelse(it); 311 brelse(it);
300 ext3_set_bit(bit, bh->b_data); 312 ext3_set_bit(bit, bh->b_data);
301 } 313 }
@@ -306,7 +318,9 @@ static int setup_new_group_blocks(struct super_block *sb,
306 318
307 mark_bitmap_end(input->blocks_count, EXT3_BLOCKS_PER_GROUP(sb), 319 mark_bitmap_end(input->blocks_count, EXT3_BLOCKS_PER_GROUP(sb),
308 bh->b_data); 320 bh->b_data);
309 ext3_journal_dirty_metadata(handle, bh); 321 err = ext3_journal_dirty_metadata(handle, bh);
322 if (err)
323 goto exit_bh;
310 brelse(bh); 324 brelse(bh);
311 325
312 /* Mark unused entries in inode bitmap used */ 326 /* Mark unused entries in inode bitmap used */
@@ -319,7 +333,7 @@ static int setup_new_group_blocks(struct super_block *sb,
319 333
320 mark_bitmap_end(EXT3_INODES_PER_GROUP(sb), EXT3_BLOCKS_PER_GROUP(sb), 334 mark_bitmap_end(EXT3_INODES_PER_GROUP(sb), EXT3_BLOCKS_PER_GROUP(sb),
321 bh->b_data); 335 bh->b_data);
322 ext3_journal_dirty_metadata(handle, bh); 336 err = ext3_journal_dirty_metadata(handle, bh);
323exit_bh: 337exit_bh:
324 brelse(bh); 338 brelse(bh);
325 339
@@ -503,12 +517,19 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
503 * reserved inode, and will become GDT blocks (primary and backup). 517 * reserved inode, and will become GDT blocks (primary and backup).
504 */ 518 */
505 data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)] = 0; 519 data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)] = 0;
506 ext3_journal_dirty_metadata(handle, dind); 520 err = ext3_journal_dirty_metadata(handle, dind);
521 if (err)
522 goto exit_group_desc;
507 brelse(dind); 523 brelse(dind);
524 dind = NULL;
508 inode->i_blocks -= (gdbackups + 1) * sb->s_blocksize >> 9; 525 inode->i_blocks -= (gdbackups + 1) * sb->s_blocksize >> 9;
509 ext3_mark_iloc_dirty(handle, inode, &iloc); 526 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
527 if (err)
528 goto exit_group_desc;
510 memset((*primary)->b_data, 0, sb->s_blocksize); 529 memset((*primary)->b_data, 0, sb->s_blocksize);
511 ext3_journal_dirty_metadata(handle, *primary); 530 err = ext3_journal_dirty_metadata(handle, *primary);
531 if (err)
532 goto exit_group_desc;
512 533
513 o_group_desc = EXT3_SB(sb)->s_group_desc; 534 o_group_desc = EXT3_SB(sb)->s_group_desc;
514 memcpy(n_group_desc, o_group_desc, 535 memcpy(n_group_desc, o_group_desc,
@@ -519,10 +540,14 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
519 kfree(o_group_desc); 540 kfree(o_group_desc);
520 541
521 le16_add_cpu(&es->s_reserved_gdt_blocks, -1); 542 le16_add_cpu(&es->s_reserved_gdt_blocks, -1);
522 ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); 543 err = ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
544 if (err)
545 goto exit_inode;
523 546
524 return 0; 547 return 0;
525 548
549exit_group_desc:
550 kfree(n_group_desc);
526exit_inode: 551exit_inode:
527 //ext3_journal_release_buffer(handle, iloc.bh); 552 //ext3_journal_release_buffer(handle, iloc.bh);
528 brelse(iloc.bh); 553 brelse(iloc.bh);
@@ -706,16 +731,20 @@ static void update_backups(struct super_block *sb,
706 } 731 }
707 ext3_debug("update metadata backup %#04lx\n", 732 ext3_debug("update metadata backup %#04lx\n",
708 (unsigned long)bh->b_blocknr); 733 (unsigned long)bh->b_blocknr);
709 if ((err = ext3_journal_get_write_access(handle, bh))) 734 if ((err = ext3_journal_get_write_access(handle, bh))) {
735 brelse(bh);
710 break; 736 break;
737 }
711 lock_buffer(bh); 738 lock_buffer(bh);
712 memcpy(bh->b_data, data, size); 739 memcpy(bh->b_data, data, size);
713 if (rest) 740 if (rest)
714 memset(bh->b_data + size, 0, rest); 741 memset(bh->b_data + size, 0, rest);
715 set_buffer_uptodate(bh); 742 set_buffer_uptodate(bh);
716 unlock_buffer(bh); 743 unlock_buffer(bh);
717 ext3_journal_dirty_metadata(handle, bh); 744 err = ext3_journal_dirty_metadata(handle, bh);
718 brelse(bh); 745 brelse(bh);
746 if (err)
747 break;
719 } 748 }
720 if ((err2 = ext3_journal_stop(handle)) && !err) 749 if ((err2 = ext3_journal_stop(handle)) && !err)
721 err = err2; 750 err = err2;
@@ -922,7 +951,9 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
922 /* Update the global fs size fields */ 951 /* Update the global fs size fields */
923 sbi->s_groups_count++; 952 sbi->s_groups_count++;
924 953
925 ext3_journal_dirty_metadata(handle, primary); 954 err = ext3_journal_dirty_metadata(handle, primary);
955 if (err)
956 goto exit_journal;
926 957
927 /* Update the reserved block counts only once the new group is 958 /* Update the reserved block counts only once the new group is
928 * active. */ 959 * active. */
@@ -934,7 +965,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
934 percpu_counter_add(&sbi->s_freeinodes_counter, 965 percpu_counter_add(&sbi->s_freeinodes_counter,
935 EXT3_INODES_PER_GROUP(sb)); 966 EXT3_INODES_PER_GROUP(sb));
936 967
937 ext3_journal_dirty_metadata(handle, sbi->s_sbh); 968 err = ext3_journal_dirty_metadata(handle, sbi->s_sbh);
938 969
939exit_journal: 970exit_journal:
940 mutex_unlock(&sbi->s_resize_lock); 971 mutex_unlock(&sbi->s_resize_lock);
@@ -977,7 +1008,8 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
977 o_blocks_count = le32_to_cpu(es->s_blocks_count); 1008 o_blocks_count = le32_to_cpu(es->s_blocks_count);
978 1009
979 if (test_opt(sb, DEBUG)) 1010 if (test_opt(sb, DEBUG))
980 printk(KERN_DEBUG "EXT3-fs: extending last group from "E3FSBLK" uto "E3FSBLK" blocks\n", 1011 printk(KERN_DEBUG "EXT3-fs: extending last group from "E3FSBLK
1012 " up to "E3FSBLK" blocks\n",
981 o_blocks_count, n_blocks_count); 1013 o_blocks_count, n_blocks_count);
982 1014
983 if (n_blocks_count == 0 || n_blocks_count == o_blocks_count) 1015 if (n_blocks_count == 0 || n_blocks_count == o_blocks_count)
@@ -985,7 +1017,7 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
985 1017
986 if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { 1018 if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
987 printk(KERN_ERR "EXT3-fs: filesystem on %s:" 1019 printk(KERN_ERR "EXT3-fs: filesystem on %s:"
988 " too large to resize to %lu blocks safely\n", 1020 " too large to resize to "E3FSBLK" blocks safely\n",
989 sb->s_id, n_blocks_count); 1021 sb->s_id, n_blocks_count);
990 if (sizeof(sector_t) < 8) 1022 if (sizeof(sector_t) < 8)
991 ext3_warning(sb, __func__, 1023 ext3_warning(sb, __func__,
@@ -1063,13 +1095,19 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
1063 goto exit_put; 1095 goto exit_put;
1064 } 1096 }
1065 es->s_blocks_count = cpu_to_le32(o_blocks_count + add); 1097 es->s_blocks_count = cpu_to_le32(o_blocks_count + add);
1066 ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); 1098 err = ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
1067 mutex_unlock(&EXT3_SB(sb)->s_resize_lock); 1099 mutex_unlock(&EXT3_SB(sb)->s_resize_lock);
1068 ext3_debug("freeing blocks %lu through "E3FSBLK"\n", o_blocks_count, 1100 if (err) {
1069 o_blocks_count + add); 1101 ext3_warning(sb, __func__,
1102 "error %d on journal dirty metadata", err);
1103 ext3_journal_stop(handle);
1104 goto exit_put;
1105 }
1106 ext3_debug("freeing blocks "E3FSBLK" through "E3FSBLK"\n",
1107 o_blocks_count, o_blocks_count + add);
1070 ext3_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks); 1108 ext3_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks);
1071 ext3_debug("freed blocks "E3FSBLK" through "E3FSBLK"\n", o_blocks_count, 1109 ext3_debug("freed blocks "E3FSBLK" through "E3FSBLK"\n",
1072 o_blocks_count + add); 1110 o_blocks_count, o_blocks_count + add);
1073 if ((err = ext3_journal_stop(handle))) 1111 if ((err = ext3_journal_stop(handle)))
1074 goto exit_put; 1112 goto exit_put;
1075 if (test_opt(sb, DEBUG)) 1113 if (test_opt(sb, DEBUG))
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 5dbf4dba03c4..aad153ef6b78 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -27,7 +27,6 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/blkdev.h> 28#include <linux/blkdev.h>
29#include <linux/parser.h> 29#include <linux/parser.h>
30#include <linux/smp_lock.h>
31#include <linux/buffer_head.h> 30#include <linux/buffer_head.h>
32#include <linux/exportfs.h> 31#include <linux/exportfs.h>
33#include <linux/vfs.h> 32#include <linux/vfs.h>
@@ -37,6 +36,7 @@
37#include <linux/quotaops.h> 36#include <linux/quotaops.h>
38#include <linux/seq_file.h> 37#include <linux/seq_file.h>
39#include <linux/log2.h> 38#include <linux/log2.h>
39#include <linux/cleancache.h>
40 40
41#include <asm/uaccess.h> 41#include <asm/uaccess.h>
42 42
@@ -144,12 +144,16 @@ void ext3_journal_abort_handle(const char *caller, const char *err_fn,
144void ext3_msg(struct super_block *sb, const char *prefix, 144void ext3_msg(struct super_block *sb, const char *prefix,
145 const char *fmt, ...) 145 const char *fmt, ...)
146{ 146{
147 struct va_format vaf;
147 va_list args; 148 va_list args;
148 149
149 va_start(args, fmt); 150 va_start(args, fmt);
150 printk("%sEXT3-fs (%s): ", prefix, sb->s_id); 151
151 vprintk(fmt, args); 152 vaf.fmt = fmt;
152 printk("\n"); 153 vaf.va = &args;
154
155 printk("%sEXT3-fs (%s): %pV\n", prefix, sb->s_id, &vaf);
156
153 va_end(args); 157 va_end(args);
154} 158}
155 159
@@ -196,15 +200,20 @@ static void ext3_handle_error(struct super_block *sb)
196 sb->s_id); 200 sb->s_id);
197} 201}
198 202
199void ext3_error (struct super_block * sb, const char * function, 203void ext3_error(struct super_block *sb, const char *function,
200 const char * fmt, ...) 204 const char *fmt, ...)
201{ 205{
206 struct va_format vaf;
202 va_list args; 207 va_list args;
203 208
204 va_start(args, fmt); 209 va_start(args, fmt);
205 printk(KERN_CRIT "EXT3-fs error (device %s): %s: ",sb->s_id, function); 210
206 vprintk(fmt, args); 211 vaf.fmt = fmt;
207 printk("\n"); 212 vaf.va = &args;
213
214 printk(KERN_CRIT "EXT3-fs error (device %s): %s: %pV\n",
215 sb->s_id, function, &vaf);
216
208 va_end(args); 217 va_end(args);
209 218
210 ext3_handle_error(sb); 219 ext3_handle_error(sb);
@@ -275,15 +284,20 @@ void __ext3_std_error (struct super_block * sb, const char * function,
275 * case we take the easy way out and panic immediately. 284 * case we take the easy way out and panic immediately.
276 */ 285 */
277 286
278void ext3_abort (struct super_block * sb, const char * function, 287void ext3_abort(struct super_block *sb, const char *function,
279 const char * fmt, ...) 288 const char *fmt, ...)
280{ 289{
290 struct va_format vaf;
281 va_list args; 291 va_list args;
282 292
283 va_start(args, fmt); 293 va_start(args, fmt);
284 printk(KERN_CRIT "EXT3-fs (%s): error: %s: ", sb->s_id, function); 294
285 vprintk(fmt, args); 295 vaf.fmt = fmt;
286 printk("\n"); 296 vaf.va = &args;
297
298 printk(KERN_CRIT "EXT3-fs (%s): error: %s: %pV\n",
299 sb->s_id, function, &vaf);
300
287 va_end(args); 301 va_end(args);
288 302
289 if (test_opt(sb, ERRORS_PANIC)) 303 if (test_opt(sb, ERRORS_PANIC))
@@ -301,16 +315,20 @@ void ext3_abort (struct super_block * sb, const char * function,
301 journal_abort(EXT3_SB(sb)->s_journal, -EIO); 315 journal_abort(EXT3_SB(sb)->s_journal, -EIO);
302} 316}
303 317
304void ext3_warning (struct super_block * sb, const char * function, 318void ext3_warning(struct super_block *sb, const char *function,
305 const char * fmt, ...) 319 const char *fmt, ...)
306{ 320{
321 struct va_format vaf;
307 va_list args; 322 va_list args;
308 323
309 va_start(args, fmt); 324 va_start(args, fmt);
310 printk(KERN_WARNING "EXT3-fs (%s): warning: %s: ", 325
311 sb->s_id, function); 326 vaf.fmt = fmt;
312 vprintk(fmt, args); 327 vaf.va = &args;
313 printk("\n"); 328
329 printk(KERN_WARNING "EXT3-fs (%s): warning: %s: %pV\n",
330 sb->s_id, function, &vaf);
331
314 va_end(args); 332 va_end(args);
315} 333}
316 334
@@ -347,7 +365,7 @@ static struct block_device *ext3_blkdev_get(dev_t dev, struct super_block *sb)
347 struct block_device *bdev; 365 struct block_device *bdev;
348 char b[BDEVNAME_SIZE]; 366 char b[BDEVNAME_SIZE];
349 367
350 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); 368 bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb);
351 if (IS_ERR(bdev)) 369 if (IS_ERR(bdev))
352 goto fail; 370 goto fail;
353 return bdev; 371 return bdev;
@@ -364,8 +382,7 @@ fail:
364 */ 382 */
365static int ext3_blkdev_put(struct block_device *bdev) 383static int ext3_blkdev_put(struct block_device *bdev)
366{ 384{
367 bd_release(bdev); 385 return blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
368 return blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
369} 386}
370 387
371static int ext3_blkdev_remove(struct ext3_sb_info *sbi) 388static int ext3_blkdev_remove(struct ext3_sb_info *sbi)
@@ -411,9 +428,6 @@ static void ext3_put_super (struct super_block * sb)
411 int i, err; 428 int i, err;
412 429
413 dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); 430 dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
414
415 lock_kernel();
416
417 ext3_xattr_put_super(sb); 431 ext3_xattr_put_super(sb);
418 err = journal_destroy(sbi->s_journal); 432 err = journal_destroy(sbi->s_journal);
419 sbi->s_journal = NULL; 433 sbi->s_journal = NULL;
@@ -462,8 +476,6 @@ static void ext3_put_super (struct super_block * sb)
462 sb->s_fs_info = NULL; 476 sb->s_fs_info = NULL;
463 kfree(sbi->s_blockgroup_lock); 477 kfree(sbi->s_blockgroup_lock);
464 kfree(sbi); 478 kfree(sbi);
465
466 unlock_kernel();
467} 479}
468 480
469static struct kmem_cache *ext3_inode_cachep; 481static struct kmem_cache *ext3_inode_cachep;
@@ -485,6 +497,13 @@ static struct inode *ext3_alloc_inode(struct super_block *sb)
485 return &ei->vfs_inode; 497 return &ei->vfs_inode;
486} 498}
487 499
500static void ext3_i_callback(struct rcu_head *head)
501{
502 struct inode *inode = container_of(head, struct inode, i_rcu);
503 INIT_LIST_HEAD(&inode->i_dentry);
504 kmem_cache_free(ext3_inode_cachep, EXT3_I(inode));
505}
506
488static void ext3_destroy_inode(struct inode *inode) 507static void ext3_destroy_inode(struct inode *inode)
489{ 508{
490 if (!list_empty(&(EXT3_I(inode)->i_orphan))) { 509 if (!list_empty(&(EXT3_I(inode)->i_orphan))) {
@@ -495,7 +514,7 @@ static void ext3_destroy_inode(struct inode *inode)
495 false); 514 false);
496 dump_stack(); 515 dump_stack();
497 } 516 }
498 kmem_cache_free(ext3_inode_cachep, EXT3_I(inode)); 517 call_rcu(&inode->i_rcu, ext3_i_callback);
499} 518}
500 519
501static void init_once(void *foo) 520static void init_once(void *foo)
@@ -736,7 +755,7 @@ static int ext3_release_dquot(struct dquot *dquot);
736static int ext3_mark_dquot_dirty(struct dquot *dquot); 755static int ext3_mark_dquot_dirty(struct dquot *dquot);
737static int ext3_write_info(struct super_block *sb, int type); 756static int ext3_write_info(struct super_block *sb, int type);
738static int ext3_quota_on(struct super_block *sb, int type, int format_id, 757static int ext3_quota_on(struct super_block *sb, int type, int format_id,
739 char *path); 758 struct path *path);
740static int ext3_quota_on_mount(struct super_block *sb, int type); 759static int ext3_quota_on_mount(struct super_block *sb, int type);
741static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data, 760static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data,
742 size_t len, loff_t off); 761 size_t len, loff_t off);
@@ -1306,9 +1325,9 @@ static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es,
1306 ext3_msg(sb, KERN_WARNING, 1325 ext3_msg(sb, KERN_WARNING,
1307 "warning: mounting fs with errors, " 1326 "warning: mounting fs with errors, "
1308 "running e2fsck is recommended"); 1327 "running e2fsck is recommended");
1309 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 && 1328 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) > 0 &&
1310 le16_to_cpu(es->s_mnt_count) >= 1329 le16_to_cpu(es->s_mnt_count) >=
1311 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count)) 1330 le16_to_cpu(es->s_max_mnt_count))
1312 ext3_msg(sb, KERN_WARNING, 1331 ext3_msg(sb, KERN_WARNING,
1313 "warning: maximal mount count reached, " 1332 "warning: maximal mount count reached, "
1314 "running e2fsck is recommended"); 1333 "running e2fsck is recommended");
@@ -1325,7 +1344,7 @@ static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es,
1325 valid forever! :) */ 1344 valid forever! :) */
1326 es->s_state &= cpu_to_le16(~EXT3_VALID_FS); 1345 es->s_state &= cpu_to_le16(~EXT3_VALID_FS);
1327#endif 1346#endif
1328 if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) 1347 if (!le16_to_cpu(es->s_max_mnt_count))
1329 es->s_max_mnt_count = cpu_to_le16(EXT3_DFL_MAX_MNT_COUNT); 1348 es->s_max_mnt_count = cpu_to_le16(EXT3_DFL_MAX_MNT_COUNT);
1330 le16_add_cpu(&es->s_mnt_count, 1); 1349 le16_add_cpu(&es->s_mnt_count, 1);
1331 es->s_mtime = cpu_to_le32(get_seconds()); 1350 es->s_mtime = cpu_to_le32(get_seconds());
@@ -1349,6 +1368,7 @@ static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es,
1349 } else { 1368 } else {
1350 ext3_msg(sb, KERN_INFO, "using internal journal"); 1369 ext3_msg(sb, KERN_INFO, "using internal journal");
1351 } 1370 }
1371 cleancache_init_fs(sb);
1352 return res; 1372 return res;
1353} 1373}
1354 1374
@@ -1446,6 +1466,13 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1446 return; 1466 return;
1447 } 1467 }
1448 1468
1469 /* Check if feature set allows readwrite operations */
1470 if (EXT3_HAS_RO_COMPAT_FEATURE(sb, ~EXT3_FEATURE_RO_COMPAT_SUPP)) {
1471 ext3_msg(sb, KERN_INFO, "Skipping orphan cleanup due to "
1472 "unknown ROCOMPAT features");
1473 return;
1474 }
1475
1449 if (EXT3_SB(sb)->s_mount_state & EXT3_ERROR_FS) { 1476 if (EXT3_SB(sb)->s_mount_state & EXT3_ERROR_FS) {
1450 if (es->s_last_orphan) 1477 if (es->s_last_orphan)
1451 jbd_debug(1, "Errors on filesystem, " 1478 jbd_debug(1, "Errors on filesystem, "
@@ -1627,8 +1654,6 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1627 sbi->s_resgid = EXT3_DEF_RESGID; 1654 sbi->s_resgid = EXT3_DEF_RESGID;
1628 sbi->s_sb_block = sb_block; 1655 sbi->s_sb_block = sb_block;
1629 1656
1630 unlock_kernel();
1631
1632 blocksize = sb_min_blocksize(sb, EXT3_MIN_BLOCK_SIZE); 1657 blocksize = sb_min_blocksize(sb, EXT3_MIN_BLOCK_SIZE);
1633 if (!blocksize) { 1658 if (!blocksize) {
1634 ext3_msg(sb, KERN_ERR, "error: unable to set blocksize"); 1659 ext3_msg(sb, KERN_ERR, "error: unable to set blocksize");
@@ -1654,7 +1679,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1654 * Note: s_es must be initialized as soon as possible because 1679 * Note: s_es must be initialized as soon as possible because
1655 * some ext3 macro-instructions depend on its value 1680 * some ext3 macro-instructions depend on its value
1656 */ 1681 */
1657 es = (struct ext3_super_block *) (((char *)bh->b_data) + offset); 1682 es = (struct ext3_super_block *) (bh->b_data + offset);
1658 sbi->s_es = es; 1683 sbi->s_es = es;
1659 sb->s_magic = le16_to_cpu(es->s_magic); 1684 sb->s_magic = le16_to_cpu(es->s_magic);
1660 if (sb->s_magic != EXT3_SUPER_MAGIC) 1685 if (sb->s_magic != EXT3_SUPER_MAGIC)
@@ -1765,7 +1790,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1765 "error: can't read superblock on 2nd try"); 1790 "error: can't read superblock on 2nd try");
1766 goto failed_mount; 1791 goto failed_mount;
1767 } 1792 }
1768 es = (struct ext3_super_block *)(((char *)bh->b_data) + offset); 1793 es = (struct ext3_super_block *)(bh->b_data + offset);
1769 sbi->s_es = es; 1794 sbi->s_es = es;
1770 if (es->s_magic != cpu_to_le16(EXT3_SUPER_MAGIC)) { 1795 if (es->s_magic != cpu_to_le16(EXT3_SUPER_MAGIC)) {
1771 ext3_msg(sb, KERN_ERR, 1796 ext3_msg(sb, KERN_ERR,
@@ -1849,13 +1874,15 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1849 goto failed_mount; 1874 goto failed_mount;
1850 } 1875 }
1851 1876
1852 if (le32_to_cpu(es->s_blocks_count) > 1877 err = generic_check_addressable(sb->s_blocksize_bits,
1853 (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { 1878 le32_to_cpu(es->s_blocks_count));
1879 if (err) {
1854 ext3_msg(sb, KERN_ERR, 1880 ext3_msg(sb, KERN_ERR,
1855 "error: filesystem is too large to mount safely"); 1881 "error: filesystem is too large to mount safely");
1856 if (sizeof(sector_t) < 8) 1882 if (sizeof(sector_t) < 8)
1857 ext3_msg(sb, KERN_ERR, 1883 ext3_msg(sb, KERN_ERR,
1858 "error: CONFIG_LBDAF not enabled"); 1884 "error: CONFIG_LBDAF not enabled");
1885 ret = err;
1859 goto failed_mount; 1886 goto failed_mount;
1860 } 1887 }
1861 1888
@@ -1864,13 +1891,13 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1864 sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) - 1891 sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) -
1865 le32_to_cpu(es->s_first_data_block) - 1) 1892 le32_to_cpu(es->s_first_data_block) - 1)
1866 / EXT3_BLOCKS_PER_GROUP(sb)) + 1; 1893 / EXT3_BLOCKS_PER_GROUP(sb)) + 1;
1867 db_count = (sbi->s_groups_count + EXT3_DESC_PER_BLOCK(sb) - 1) / 1894 db_count = DIV_ROUND_UP(sbi->s_groups_count, EXT3_DESC_PER_BLOCK(sb));
1868 EXT3_DESC_PER_BLOCK(sb);
1869 sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *), 1895 sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *),
1870 GFP_KERNEL); 1896 GFP_KERNEL);
1871 if (sbi->s_group_desc == NULL) { 1897 if (sbi->s_group_desc == NULL) {
1872 ext3_msg(sb, KERN_ERR, 1898 ext3_msg(sb, KERN_ERR,
1873 "error: not enough memory"); 1899 "error: not enough memory");
1900 ret = -ENOMEM;
1874 goto failed_mount; 1901 goto failed_mount;
1875 } 1902 }
1876 1903
@@ -1918,6 +1945,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1918 sb->s_qcop = &ext3_qctl_operations; 1945 sb->s_qcop = &ext3_qctl_operations;
1919 sb->dq_op = &ext3_quota_operations; 1946 sb->dq_op = &ext3_quota_operations;
1920#endif 1947#endif
1948 memcpy(sb->s_uuid, es->s_uuid, sizeof(es->s_uuid));
1921 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ 1949 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
1922 mutex_init(&sbi->s_orphan_lock); 1950 mutex_init(&sbi->s_orphan_lock);
1923 mutex_init(&sbi->s_resize_lock); 1951 mutex_init(&sbi->s_resize_lock);
@@ -1958,6 +1986,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1958 } 1986 }
1959 if (err) { 1987 if (err) {
1960 ext3_msg(sb, KERN_ERR, "error: insufficient memory"); 1988 ext3_msg(sb, KERN_ERR, "error: insufficient memory");
1989 ret = err;
1961 goto failed_mount3; 1990 goto failed_mount3;
1962 } 1991 }
1963 1992
@@ -2025,7 +2054,6 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
2025 test_opt(sb,DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA ? "ordered": 2054 test_opt(sb,DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA ? "ordered":
2026 "writeback"); 2055 "writeback");
2027 2056
2028 lock_kernel();
2029 return 0; 2057 return 0;
2030 2058
2031cantfind_ext3: 2059cantfind_ext3:
@@ -2055,7 +2083,6 @@ out_fail:
2055 sb->s_fs_info = NULL; 2083 sb->s_fs_info = NULL;
2056 kfree(sbi->s_blockgroup_lock); 2084 kfree(sbi->s_blockgroup_lock);
2057 kfree(sbi); 2085 kfree(sbi);
2058 lock_kernel();
2059 return ret; 2086 return ret;
2060} 2087}
2061 2088
@@ -2144,13 +2171,6 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb,
2144 if (bdev == NULL) 2171 if (bdev == NULL)
2145 return NULL; 2172 return NULL;
2146 2173
2147 if (bd_claim(bdev, sb)) {
2148 ext3_msg(sb, KERN_ERR,
2149 "error: failed to claim external journal device");
2150 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
2151 return NULL;
2152 }
2153
2154 blocksize = sb->s_blocksize; 2174 blocksize = sb->s_blocksize;
2155 hblock = bdev_logical_block_size(bdev); 2175 hblock = bdev_logical_block_size(bdev);
2156 if (blocksize < hblock) { 2176 if (blocksize < hblock) {
@@ -2168,7 +2188,7 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb,
2168 goto out_bdev; 2188 goto out_bdev;
2169 } 2189 }
2170 2190
2171 es = (struct ext3_super_block *) (((char *)bh->b_data) + offset); 2191 es = (struct ext3_super_block *) (bh->b_data + offset);
2172 if ((le16_to_cpu(es->s_magic) != EXT3_SUPER_MAGIC) || 2192 if ((le16_to_cpu(es->s_magic) != EXT3_SUPER_MAGIC) ||
2173 !(le32_to_cpu(es->s_feature_incompat) & 2193 !(le32_to_cpu(es->s_feature_incompat) &
2174 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { 2194 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) {
@@ -2299,7 +2319,7 @@ static int ext3_load_journal(struct super_block *sb,
2299 EXT3_SB(sb)->s_journal = journal; 2319 EXT3_SB(sb)->s_journal = journal;
2300 ext3_clear_journal_err(sb, es); 2320 ext3_clear_journal_err(sb, es);
2301 2321
2302 if (journal_devnum && 2322 if (!really_read_only && journal_devnum &&
2303 journal_devnum != le32_to_cpu(es->s_journal_dev)) { 2323 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
2304 es->s_journal_dev = cpu_to_le32(journal_devnum); 2324 es->s_journal_dev = cpu_to_le32(journal_devnum);
2305 2325
@@ -2361,6 +2381,21 @@ static int ext3_commit_super(struct super_block *sb,
2361 2381
2362 if (!sbh) 2382 if (!sbh)
2363 return error; 2383 return error;
2384
2385 if (buffer_write_io_error(sbh)) {
2386 /*
2387 * Oh, dear. A previous attempt to write the
2388 * superblock failed. This could happen because the
2389 * USB device was yanked out. Or it could happen to
2390 * be a transient write error and maybe the block will
2391 * be remapped. Nothing we can do but to retry the
2392 * write and hope for the best.
2393 */
2394 ext3_msg(sb, KERN_ERR, "previous I/O error to "
2395 "superblock detected");
2396 clear_buffer_write_io_error(sbh);
2397 set_buffer_uptodate(sbh);
2398 }
2364 /* 2399 /*
2365 * If the file system is mounted read-only, don't update the 2400 * If the file system is mounted read-only, don't update the
2366 * superblock write time. This avoids updating the superblock 2401 * superblock write time. This avoids updating the superblock
@@ -2377,8 +2412,15 @@ static int ext3_commit_super(struct super_block *sb,
2377 es->s_free_inodes_count = cpu_to_le32(ext3_count_free_inodes(sb)); 2412 es->s_free_inodes_count = cpu_to_le32(ext3_count_free_inodes(sb));
2378 BUFFER_TRACE(sbh, "marking dirty"); 2413 BUFFER_TRACE(sbh, "marking dirty");
2379 mark_buffer_dirty(sbh); 2414 mark_buffer_dirty(sbh);
2380 if (sync) 2415 if (sync) {
2381 error = sync_dirty_buffer(sbh); 2416 error = sync_dirty_buffer(sbh);
2417 if (buffer_write_io_error(sbh)) {
2418 ext3_msg(sb, KERN_ERR, "I/O error while writing "
2419 "superblock");
2420 clear_buffer_write_io_error(sbh);
2421 set_buffer_uptodate(sbh);
2422 }
2423 }
2382 return error; 2424 return error;
2383} 2425}
2384 2426
@@ -2538,8 +2580,6 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
2538 int i; 2580 int i;
2539#endif 2581#endif
2540 2582
2541 lock_kernel();
2542
2543 /* Store the original options */ 2583 /* Store the original options */
2544 lock_super(sb); 2584 lock_super(sb);
2545 old_sb_flags = sb->s_flags; 2585 old_sb_flags = sb->s_flags;
@@ -2648,7 +2688,6 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
2648 kfree(old_opts.s_qf_names[i]); 2688 kfree(old_opts.s_qf_names[i]);
2649#endif 2689#endif
2650 unlock_super(sb); 2690 unlock_super(sb);
2651 unlock_kernel();
2652 2691
2653 if (enable_quota) 2692 if (enable_quota)
2654 dquot_resume(sb, -1); 2693 dquot_resume(sb, -1);
@@ -2669,7 +2708,6 @@ restore_opts:
2669 } 2708 }
2670#endif 2709#endif
2671 unlock_super(sb); 2710 unlock_super(sb);
2672 unlock_kernel();
2673 return err; 2711 return err;
2674} 2712}
2675 2713
@@ -2849,27 +2887,20 @@ static int ext3_quota_on_mount(struct super_block *sb, int type)
2849 * Standard function to be called on quota_on 2887 * Standard function to be called on quota_on
2850 */ 2888 */
2851static int ext3_quota_on(struct super_block *sb, int type, int format_id, 2889static int ext3_quota_on(struct super_block *sb, int type, int format_id,
2852 char *name) 2890 struct path *path)
2853{ 2891{
2854 int err; 2892 int err;
2855 struct path path;
2856 2893
2857 if (!test_opt(sb, QUOTA)) 2894 if (!test_opt(sb, QUOTA))
2858 return -EINVAL; 2895 return -EINVAL;
2859 2896
2860 err = kern_path(name, LOOKUP_FOLLOW, &path);
2861 if (err)
2862 return err;
2863
2864 /* Quotafile not on the same filesystem? */ 2897 /* Quotafile not on the same filesystem? */
2865 if (path.mnt->mnt_sb != sb) { 2898 if (path->mnt->mnt_sb != sb)
2866 path_put(&path);
2867 return -EXDEV; 2899 return -EXDEV;
2868 }
2869 /* Journaling quota? */ 2900 /* Journaling quota? */
2870 if (EXT3_SB(sb)->s_qf_names[type]) { 2901 if (EXT3_SB(sb)->s_qf_names[type]) {
2871 /* Quotafile not of fs root? */ 2902 /* Quotafile not of fs root? */
2872 if (path.dentry->d_parent != sb->s_root) 2903 if (path->dentry->d_parent != sb->s_root)
2873 ext3_msg(sb, KERN_WARNING, 2904 ext3_msg(sb, KERN_WARNING,
2874 "warning: Quota file not on filesystem root. " 2905 "warning: Quota file not on filesystem root. "
2875 "Journaled quota will not work."); 2906 "Journaled quota will not work.");
@@ -2879,7 +2910,7 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
2879 * When we journal data on quota file, we have to flush journal to see 2910 * When we journal data on quota file, we have to flush journal to see
2880 * all updates to the file when we bypass pagecache... 2911 * all updates to the file when we bypass pagecache...
2881 */ 2912 */
2882 if (ext3_should_journal_data(path.dentry->d_inode)) { 2913 if (ext3_should_journal_data(path->dentry->d_inode)) {
2883 /* 2914 /*
2884 * We don't need to lock updates but journal_flush() could 2915 * We don't need to lock updates but journal_flush() could
2885 * otherwise be livelocked... 2916 * otherwise be livelocked...
@@ -2887,20 +2918,16 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
2887 journal_lock_updates(EXT3_SB(sb)->s_journal); 2918 journal_lock_updates(EXT3_SB(sb)->s_journal);
2888 err = journal_flush(EXT3_SB(sb)->s_journal); 2919 err = journal_flush(EXT3_SB(sb)->s_journal);
2889 journal_unlock_updates(EXT3_SB(sb)->s_journal); 2920 journal_unlock_updates(EXT3_SB(sb)->s_journal);
2890 if (err) { 2921 if (err)
2891 path_put(&path);
2892 return err; 2922 return err;
2893 }
2894 } 2923 }
2895 2924
2896 err = dquot_quota_on_path(sb, type, format_id, &path); 2925 return dquot_quota_on(sb, type, format_id, path);
2897 path_put(&path);
2898 return err;
2899} 2926}
2900 2927
2901/* Read data from quotafile - avoid pagecache and such because we cannot afford 2928/* Read data from quotafile - avoid pagecache and such because we cannot afford
2902 * acquiring the locks... As quota files are never truncated and quota code 2929 * acquiring the locks... As quota files are never truncated and quota code
2903 * itself serializes the operations (and noone else should touch the files) 2930 * itself serializes the operations (and no one else should touch the files)
2904 * we don't have to be afraid of races */ 2931 * we don't have to be afraid of races */
2905static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data, 2932static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data,
2906 size_t len, loff_t off) 2933 size_t len, loff_t off)
@@ -3010,16 +3037,16 @@ out:
3010 3037
3011#endif 3038#endif
3012 3039
3013static int ext3_get_sb(struct file_system_type *fs_type, 3040static struct dentry *ext3_mount(struct file_system_type *fs_type,
3014 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 3041 int flags, const char *dev_name, void *data)
3015{ 3042{
3016 return get_sb_bdev(fs_type, flags, dev_name, data, ext3_fill_super, mnt); 3043 return mount_bdev(fs_type, flags, dev_name, data, ext3_fill_super);
3017} 3044}
3018 3045
3019static struct file_system_type ext3_fs_type = { 3046static struct file_system_type ext3_fs_type = {
3020 .owner = THIS_MODULE, 3047 .owner = THIS_MODULE,
3021 .name = "ext3", 3048 .name = "ext3",
3022 .get_sb = ext3_get_sb, 3049 .mount = ext3_mount,
3023 .kill_sb = kill_block_super, 3050 .kill_sb = kill_block_super,
3024 .fs_flags = FS_REQUIRES_DEV, 3051 .fs_flags = FS_REQUIRES_DEV,
3025}; 3052};
diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
index e69dc6dfaa89..32e6cc23bd9a 100644
--- a/fs/ext3/xattr.c
+++ b/fs/ext3/xattr.c
@@ -925,7 +925,7 @@ ext3_xattr_ibody_set(handle_t *handle, struct inode *inode,
925/* 925/*
926 * ext3_xattr_set_handle() 926 * ext3_xattr_set_handle()
927 * 927 *
928 * Create, replace or remove an extended attribute for this inode. Buffer 928 * Create, replace or remove an extended attribute for this inode. Value
929 * is NULL to remove an existing extended attribute, and non-NULL to 929 * is NULL to remove an existing extended attribute, and non-NULL to
930 * either replace an existing extended attribute, or create a new extended 930 * either replace an existing extended attribute, or create a new extended
931 * attribute. The flags XATTR_REPLACE and XATTR_CREATE 931 * attribute. The flags XATTR_REPLACE and XATTR_CREATE
diff --git a/fs/ext3/xattr.h b/fs/ext3/xattr.h
index 377fe7201169..2be4f69bfa64 100644
--- a/fs/ext3/xattr.h
+++ b/fs/ext3/xattr.h
@@ -128,10 +128,10 @@ exit_ext3_xattr(void)
128 128
129#ifdef CONFIG_EXT3_FS_SECURITY 129#ifdef CONFIG_EXT3_FS_SECURITY
130extern int ext3_init_security(handle_t *handle, struct inode *inode, 130extern int ext3_init_security(handle_t *handle, struct inode *inode,
131 struct inode *dir); 131 struct inode *dir, const struct qstr *qstr);
132#else 132#else
133static inline int ext3_init_security(handle_t *handle, struct inode *inode, 133static inline int ext3_init_security(handle_t *handle, struct inode *inode,
134 struct inode *dir) 134 struct inode *dir, const struct qstr *qstr)
135{ 135{
136 return 0; 136 return 0;
137} 137}
diff --git a/fs/ext3/xattr_security.c b/fs/ext3/xattr_security.c
index 03a99bfc59f9..b8d9f83aa5c5 100644
--- a/fs/ext3/xattr_security.c
+++ b/fs/ext3/xattr_security.c
@@ -49,14 +49,15 @@ ext3_xattr_security_set(struct dentry *dentry, const char *name,
49} 49}
50 50
51int 51int
52ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir) 52ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir,
53 const struct qstr *qstr)
53{ 54{
54 int err; 55 int err;
55 size_t len; 56 size_t len;
56 void *value; 57 void *value;
57 char *name; 58 char *name;
58 59
59 err = security_inode_init_security(inode, dir, &name, &value, &len); 60 err = security_inode_init_security(inode, dir, qstr, &name, &value, &len);
60 if (err) { 61 if (err) {
61 if (err == -EOPNOTSUPP) 62 if (err == -EOPNOTSUPP)
62 return 0; 63 return 0;