34 static int ext3_writepage_trans_blocks(
struct inode *
inode);
35 static int ext3_block_truncate_page(
struct inode *
inode, loff_t
from);
40 static int ext3_inode_is_fast_symlink(
struct inode *
inode)
42 int ea_blocks = EXT3_I(inode)->i_file_acl ?
43 (inode->
i_sb->s_blocksize >> 9) : 0;
64 trace_ext3_forget(inode, is_metadata, blocknr);
65 BUFFER_TRACE(bh,
"enter");
67 jbd_debug(4,
"forgetting bh %p: is_metadata = %d, mode %o, "
69 bh, is_metadata, inode->
i_mode,
78 (!is_metadata && !ext3_should_journal_data(inode))) {
80 BUFFER_TRACE(bh,
"call journal_forget");
89 BUFFER_TRACE(bh,
"call ext3_journal_revoke");
93 "error %d when attempting revoke", err);
94 BUFFER_TRACE(bh,
"exit");
102 static unsigned long blocks_for_truncate(
struct inode *inode)
104 unsigned long needed;
106 needed = inode->
i_blocks >> (inode->
i_sb->s_blocksize_bits - 9);
135 static handle_t *start_transaction(
struct inode *inode)
139 result = ext3_journal_start(inode, blocks_for_truncate(inode));
153 static int try_to_extend_transaction(handle_t *
handle,
struct inode *inode)
157 if (!ext3_journal_extend(handle, blocks_for_truncate(inode)))
167 static int truncate_restart_transaction(handle_t *handle,
struct inode *inode)
171 jbd_debug(2,
"restarting handle %p\n", handle);
179 ret = ext3_journal_restart(handle, blocks_for_truncate(inode));
194 trace_ext3_evict_inode(inode);
219 if (inode->
i_nlink && ext3_should_journal_data(inode) &&
220 EXT3_SB(inode->
i_sb)->s_journal &&
223 journal_t *journal = EXT3_SB(inode->
i_sb)->s_journal;
240 handle = start_transaction(inode);
241 if (IS_ERR(handle)) {
293 struct buffer_head *bh;
296 static inline void add_chain(
Indirect *
p,
struct buffer_head *bh,
__le32 *
v)
298 p->
key = *(p->
p =
v);
304 while (from <= to && from->
key == *from->
p)
340 static int ext3_block_to_path(
struct inode *inode,
341 long i_block,
int offsets[4],
int *boundary)
346 indirect_blocks =
ptrs,
347 double_blocks = (1 << (ptrs_bits * 2));
353 }
else if (i_block < direct_blocks) {
354 offsets[n++] = i_block;
355 final = direct_blocks;
356 }
else if ( (i_block -= direct_blocks) < indirect_blocks) {
358 offsets[n++] = i_block;
360 }
else if ((i_block -= indirect_blocks) < double_blocks) {
362 offsets[n++] = i_block >> ptrs_bits;
363 offsets[n++] = i_block & (ptrs - 1);
365 }
else if (((i_block -= double_blocks) >> (ptrs_bits * 2)) <
ptrs) {
367 offsets[n++] = i_block >> (ptrs_bits * 2);
368 offsets[n++] = (i_block >> ptrs_bits) & (ptrs - 1);
369 offsets[n++] = i_block & (ptrs - 1);
375 *boundary =
final - 1 - (i_block & (ptrs - 1));
408 static Indirect *ext3_get_branch(
struct inode *inode,
int depth,
int *offsets,
413 struct buffer_head *bh;
417 add_chain (chain,
NULL, EXT3_I(inode)->i_data + *offsets);
425 if (!verify_chain(chain, p))
427 add_chain(++p, bh, (
__le32*)bh->b_data + *++offsets);
473 for (p = ind->
p - 1; p >= start; p--) {
480 return ind->
bh->b_blocknr;
489 return bg_start + colour;
507 block_i = EXT3_I(inode)->i_block_alloc_info;
518 return ext3_find_near(inode, partial);
533 static int ext3_blks_to_allocate(
Indirect *
branch,
int k,
unsigned long blks,
534 int blocks_to_boundary)
536 unsigned long count = 0;
544 if (blks < blocks_to_boundary + 1)
547 count += blocks_to_boundary + 1;
552 while (count < blks && count <= blocks_to_boundary &&
573 static int ext3_alloc_blocks(handle_t *handle,
struct inode *inode,
578 unsigned long count = 0;
591 target = blks + indirect_blks;
602 while (index < indirect_blks && count) {
603 new_blocks[index++] = current_block++;
612 new_blocks[
index] = current_block;
619 for (i = 0; i <
index; i++)
651 static int ext3_alloc_branch(handle_t *handle,
struct inode *inode,
655 int blocksize = inode->
i_sb->s_blocksize;
658 struct buffer_head *bh;
663 num = ext3_alloc_blocks(handle, inode, goal, indirect_blks,
664 *blks, new_blocks, &err);
672 for (n = 1; n <= indirect_blks; n++) {
678 bh = sb_getblk(inode->
i_sb, new_blocks[n-1]);
681 BUFFER_TRACE(bh,
"call get_create_access");
689 memset(bh->b_data, 0, blocksize);
690 branch[
n].
p = (
__le32 *) bh->b_data + offsets[n];
692 *branch[
n].
p = branch[
n].
key;
693 if ( n == indirect_blks) {
694 current_block = new_blocks[
n];
700 for (i=1; i < num; i++)
703 BUFFER_TRACE(bh,
"marking uptodate");
704 set_buffer_uptodate(bh);
707 BUFFER_TRACE(bh,
"call ext3_journal_dirty_metadata");
716 for (i = 1; i <=
n ; i++) {
717 BUFFER_TRACE(branch[i].bh,
"call journal_forget");
720 for (i = 0; i <indirect_blks; i++)
741 static int ext3_splice_branch(handle_t *handle,
struct inode *inode,
742 long block,
Indirect *where,
int num,
int blks)
758 BUFFER_TRACE(where->
bh,
"get_write_access");
765 *where->
p = where->
key;
771 if (num == 0 && blks > 1) {
773 for (i = 1; i < blks; i++)
783 block_i->last_alloc_logical_block = block + blks - 1;
784 block_i->last_alloc_physical_block =
790 if (!timespec_equal(&inode->
i_ctime, &now) || !where->
bh) {
807 jbd_debug(5,
"splicing indirect only\n");
808 BUFFER_TRACE(where->
bh,
"call ext3_journal_dirty_metadata");
822 for (i = 1; i <= num; i++) {
823 BUFFER_TRACE(where[i].bh,
"call journal_forget");
852 sector_t iblock,
unsigned long maxblocks,
853 struct buffer_head *bh_result,
862 int blocks_to_boundary = 0;
869 trace_ext3_get_blocks_enter(inode, iblock, maxblocks, create);
870 J_ASSERT(handle !=
NULL || create == 0);
871 depth = ext3_block_to_path(inode,iblock,offsets,&blocks_to_boundary);
876 partial = ext3_get_branch(inode, depth, offsets, chain, &err);
881 clear_buffer_new(bh_result);
884 while (count < maxblocks && count <= blocks_to_boundary) {
887 if (!verify_chain(chain, chain + depth - 1)) {
901 if (blk == first_block + count)
911 if (!create || err == -
EIO)
931 if (err == -
EAGAIN || !verify_chain(chain, partial)) {
932 while (partial > chain) {
936 partial = ext3_get_branch(inode, depth, offsets, chain, &err);
942 clear_buffer_new(bh_result);
954 goal = ext3_find_goal(inode, iblock, partial);
957 indirect_blks = (chain +
depth) - partial - 1;
963 count = ext3_blks_to_allocate(partial, indirect_blks,
964 maxblocks, blocks_to_boundary);
965 err = ext3_alloc_branch(handle, inode, indirect_blks, &count, goal,
966 offsets + (partial - chain), partial);
976 err = ext3_splice_branch(handle, inode, iblock,
977 partial, indirect_blks, count);
982 set_buffer_new(bh_result);
985 if (count > blocks_to_boundary)
986 set_buffer_boundary(bh_result);
989 partial = chain + depth - 1;
991 while (partial > chain) {
992 BUFFER_TRACE(partial->
bh,
"call brelse");
996 BUFFER_TRACE(bh_result,
"returned");
998 trace_ext3_get_blocks_exit(inode, iblock,
1005 #define DIO_MAX_BLOCKS 4096
1013 #define DIO_CREDITS 25
1015 static int ext3_get_block(
struct inode *inode,
sector_t iblock,
1016 struct buffer_head *bh_result,
int create)
1018 handle_t *handle = ext3_journal_current_handle();
1020 unsigned max_blocks = bh_result->b_size >> inode->
i_blkbits;
1022 if (create && !handle) {
1027 if (IS_ERR(handle)) {
1028 ret = PTR_ERR(handle);
1035 max_blocks, bh_result, create);
1037 bh_result->b_size = (ret << inode->
i_blkbits);
1056 struct buffer_head *
ext3_getblk(handle_t *handle,
struct inode *inode,
1057 long block,
int create,
int *errp)
1059 struct buffer_head dummy;
1062 J_ASSERT(handle !=
NULL || create == 0);
1065 dummy.b_blocknr = -1000;
1066 buffer_trace_init(&dummy.b_history);
1079 if (!err && buffer_mapped(&dummy)) {
1080 struct buffer_head *bh;
1081 bh = sb_getblk(inode->
i_sb, dummy.b_blocknr);
1086 if (buffer_new(&dummy)) {
1087 J_ASSERT(create != 0);
1088 J_ASSERT(handle !=
NULL);
1098 BUFFER_TRACE(bh,
"call get_create_access");
1100 if (!fatal && !buffer_uptodate(bh)) {
1101 memset(bh->b_data,0,inode->
i_sb->s_blocksize);
1102 set_buffer_uptodate(bh);
1105 BUFFER_TRACE(bh,
"call ext3_journal_dirty_metadata");
1110 BUFFER_TRACE(bh,
"not a new buffer");
1123 struct buffer_head *
ext3_bread(handle_t *handle,
struct inode *inode,
1124 int block,
int create,
int *err)
1126 struct buffer_head * bh;
1128 bh =
ext3_getblk(handle, inode, block, create, err);
1137 if (buffer_uptodate(bh))
1144 static int walk_page_buffers( handle_t *handle,
1145 struct buffer_head *
head,
1149 int (*
fn)( handle_t *handle,
1150 struct buffer_head *bh))
1152 struct buffer_head *bh;
1153 unsigned block_start, block_end;
1154 unsigned blocksize = head->b_size;
1156 struct buffer_head *
next;
1158 for ( bh = head, block_start = 0;
1159 ret == 0 && (bh != head || !block_start);
1160 block_start = block_end, bh =
next)
1162 next = bh->b_this_page;
1163 block_end = block_start + blocksize;
1164 if (block_end <= from || block_start >= to) {
1165 if (partial && !buffer_uptodate(bh))
1201 static int do_journal_get_write_access(handle_t *handle,
1202 struct buffer_head *bh)
1204 int dirty = buffer_dirty(bh);
1207 if (!buffer_mapped(bh) || buffer_freed(bh))
1218 clear_buffer_dirty(bh);
1229 static void ext3_truncate_failed_write(
struct inode *inode)
1239 static void ext3_truncate_failed_direct_write(
struct inode *inode)
1241 ext3_block_truncate_page(inode, inode->
i_size);
1246 loff_t
pos,
unsigned len,
unsigned flags,
1247 struct page **pagep,
void **fsdata)
1249 struct inode *inode = mapping->
host;
1258 int needed_blocks = ext3_writepage_trans_blocks(inode) + 1;
1260 trace_ext3_write_begin(inode, pos, len, flags);
1272 handle = ext3_journal_start(inode, needed_blocks);
1273 if (IS_ERR(handle)) {
1276 ret = PTR_ERR(handle);
1281 goto write_begin_failed;
1283 if (ext3_should_journal_data(inode)) {
1284 ret = walk_page_buffers(handle, page_buffers(page),
1285 from, to,
NULL, do_journal_get_write_access);
1303 if (pos + len > inode->
i_size)
1304 ext3_truncate_failed_write(inode);
1323 static int journal_dirty_data_fn(handle_t *handle,
struct buffer_head *bh)
1329 if (buffer_mapped(bh) && buffer_uptodate(bh))
1335 static int write_end_fn(handle_t *handle,
struct buffer_head *bh)
1337 if (!buffer_mapped(bh) || buffer_freed(bh))
1339 set_buffer_uptodate(bh);
1349 static void update_file_sizes(
struct inode *inode, loff_t pos,
unsigned copied)
1352 if (pos + copied > inode->
i_size)
1353 i_size_write(inode, pos + copied);
1354 if (pos + copied > EXT3_I(inode)->i_disksize) {
1355 EXT3_I(inode)->i_disksize = pos + copied;
1356 mark_inode_dirty(inode);
1367 static int ext3_ordered_write_end(
struct file *file,
1369 loff_t pos,
unsigned len,
unsigned copied,
1370 struct page *page,
void *fsdata)
1372 handle_t *handle = ext3_journal_current_handle();
1373 struct inode *inode = file->
f_mapping->host;
1377 trace_ext3_ordered_write_end(inode, pos, len, copied);
1378 copied =
block_write_end(file, mapping, pos, len, copied, page, fsdata);
1382 ret = walk_page_buffers(handle, page_buffers(page),
1383 from, to,
NULL, journal_dirty_data_fn);
1386 update_file_sizes(inode, pos, copied);
1399 if (pos + len > inode->
i_size)
1400 ext3_truncate_failed_write(inode);
1401 return ret ? ret : copied;
1404 static int ext3_writeback_write_end(
struct file *file,
1406 loff_t pos,
unsigned len,
unsigned copied,
1407 struct page *page,
void *fsdata)
1409 handle_t *handle = ext3_journal_current_handle();
1410 struct inode *inode = file->
f_mapping->host;
1413 trace_ext3_writeback_write_end(inode, pos, len, copied);
1414 copied =
block_write_end(file, mapping, pos, len, copied, page, fsdata);
1415 update_file_sizes(inode, pos, copied);
1426 if (pos + len > inode->
i_size)
1427 ext3_truncate_failed_write(inode);
1428 return ret ? ret : copied;
1431 static int ext3_journalled_write_end(
struct file *file,
1433 loff_t pos,
unsigned len,
unsigned copied,
1434 struct page *page,
void *fsdata)
1436 handle_t *handle = ext3_journal_current_handle();
1437 struct inode *inode = mapping->
host;
1443 trace_ext3_journalled_write_end(inode, pos, len, copied);
1448 if (!PageUptodate(page))
1454 ret = walk_page_buffers(handle, page_buffers(page), from,
1455 to, &partial, write_end_fn);
1457 SetPageUptodate(page);
1459 if (pos + copied > inode->
i_size)
1460 i_size_write(inode, pos + copied);
1482 if (pos + len > inode->
i_size)
1483 ext3_truncate_failed_write(inode);
1484 return ret ? ret : copied;
1503 struct inode *inode = mapping->
host;
1539 static int bget_one(handle_t *handle,
struct buffer_head *bh)
1545 static int bput_one(handle_t *handle,
struct buffer_head *bh)
1551 static int buffer_unmapped(handle_t *handle,
struct buffer_head *bh)
1553 return !buffer_mapped(bh);
1608 static int ext3_ordered_writepage(
struct page *page,
1611 struct inode *inode = page->
mapping->host;
1612 struct buffer_head *page_bufs;
1613 handle_t *handle =
NULL;
1617 J_ASSERT(PageLocked(page));
1630 if (ext3_journal_current_handle())
1633 trace_ext3_ordered_writepage(page);
1634 if (!page_has_buffers(page)) {
1636 (1 << BH_Dirty)|(1 << BH_Uptodate));
1637 page_bufs = page_buffers(page);
1639 page_bufs = page_buffers(page);
1641 NULL, buffer_unmapped)) {
1647 handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode));
1649 if (IS_ERR(handle)) {
1650 ret = PTR_ERR(handle);
1654 walk_page_buffers(handle, page_bufs, 0,
1673 NULL, journal_dirty_data_fn);
1677 walk_page_buffers(handle, page_bufs, 0,
1690 static int ext3_writeback_writepage(
struct page *page,
1693 struct inode *inode = page->
mapping->host;
1694 handle_t *handle =
NULL;
1698 J_ASSERT(PageLocked(page));
1707 if (ext3_journal_current_handle())
1710 trace_ext3_writeback_writepage(page);
1711 if (page_has_buffers(page)) {
1712 if (!walk_page_buffers(
NULL, page_buffers(page), 0,
1720 handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode));
1721 if (IS_ERR(handle)) {
1722 ret = PTR_ERR(handle);
1739 static int ext3_journalled_writepage(
struct page *page,
1742 struct inode *inode = page->
mapping->host;
1743 handle_t *handle =
NULL;
1747 J_ASSERT(PageLocked(page));
1756 if (ext3_journal_current_handle())
1759 trace_ext3_journalled_writepage(page);
1760 handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode));
1761 if (IS_ERR(handle)) {
1762 ret = PTR_ERR(handle);
1766 if (!page_has_buffers(page) || PageChecked(page)) {
1771 ClearPageChecked(page);
1778 ret = walk_page_buffers(handle, page_buffers(page), 0,
1781 err = walk_page_buffers(handle, page_buffers(page), 0,
1787 handle->h_transaction->t_tid);
1810 static int ext3_readpage(
struct file *file,
struct page *page)
1812 trace_ext3_readpage(page);
1817 ext3_readpages(
struct file *file,
struct address_space *mapping,
1823 static void ext3_invalidatepage(
struct page *page,
unsigned long offset)
1827 trace_ext3_invalidatepage(page, offset);
1833 ClearPageChecked(page);
1838 static int ext3_releasepage(
struct page *page,
gfp_t wait)
1842 trace_ext3_releasepage(page);
1844 if (!page_has_buffers(page))
1859 const struct iovec *iov, loff_t offset,
1860 unsigned long nr_segs)
1862 struct file *file = iocb->
ki_filp;
1863 struct inode *inode = file->
f_mapping->host;
1868 size_t count = iov_length(iov, nr_segs);
1871 trace_ext3_direct_IO_enter(inode, offset, iov_length(iov, nr_segs), rw);
1874 loff_t final_size = offset +
count;
1876 if (final_size > inode->
i_size) {
1878 handle = ext3_journal_start(inode, 2);
1879 if (IS_ERR(handle)) {
1880 ret = PTR_ERR(handle);
1895 ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs,
1902 loff_t isize = i_size_read(inode);
1903 loff_t
end = offset + iov_length(iov, nr_segs);
1906 ext3_truncate_failed_direct_write(inode);
1915 handle = ext3_journal_start(inode, 2);
1916 if (IS_ERR(handle)) {
1920 ext3_truncate_failed_direct_write(inode);
1921 ret = PTR_ERR(handle);
1927 loff_t end = offset +
ret;
1928 if (end > inode->
i_size) {
1930 i_size_write(inode, end);
1946 trace_ext3_direct_IO_exit(inode, offset,
1947 iov_length(iov, nr_segs), rw, ret);
1964 static int ext3_journalled_set_page_dirty(
struct page *page)
1966 SetPageChecked(page);
1971 .readpage = ext3_readpage,
1972 .readpages = ext3_readpages,
1973 .writepage = ext3_ordered_writepage,
1974 .write_begin = ext3_write_begin,
1975 .write_end = ext3_ordered_write_end,
1977 .invalidatepage = ext3_invalidatepage,
1978 .releasepage = ext3_releasepage,
1979 .direct_IO = ext3_direct_IO,
1986 .readpage = ext3_readpage,
1987 .readpages = ext3_readpages,
1988 .writepage = ext3_writeback_writepage,
1989 .write_begin = ext3_write_begin,
1990 .write_end = ext3_writeback_write_end,
1992 .invalidatepage = ext3_invalidatepage,
1993 .releasepage = ext3_releasepage,
1994 .direct_IO = ext3_direct_IO,
2001 .readpage = ext3_readpage,
2002 .readpages = ext3_readpages,
2003 .writepage = ext3_journalled_writepage,
2004 .write_begin = ext3_write_begin,
2005 .write_end = ext3_journalled_write_end,
2006 .set_page_dirty = ext3_journalled_set_page_dirty,
2008 .invalidatepage = ext3_invalidatepage,
2009 .releasepage = ext3_releasepage,
2016 if (ext3_should_order_data(inode))
2017 inode->
i_mapping->a_ops = &ext3_ordered_aops;
2018 else if (ext3_should_writeback_data(inode))
2019 inode->
i_mapping->a_ops = &ext3_writeback_aops;
2021 inode->
i_mapping->a_ops = &ext3_journalled_aops;
2030 static int ext3_block_truncate_page(
struct inode *inode, loff_t from)
2034 unsigned blocksize, iblock,
length,
pos;
2036 handle_t *handle =
NULL;
2037 struct buffer_head *bh;
2041 blocksize = inode->
i_sb->s_blocksize;
2042 if ((from & (blocksize - 1)) == 0)
2045 page = grab_cache_page(inode->
i_mapping, index);
2048 length = blocksize - (offset & (blocksize - 1));
2049 iblock = index << (PAGE_CACHE_SHIFT - inode->
i_sb->s_blocksize_bits);
2051 if (!page_has_buffers(page))
2055 bh = page_buffers(page);
2057 while (offset >= pos) {
2058 bh = bh->b_this_page;
2064 if (buffer_freed(bh)) {
2065 BUFFER_TRACE(bh,
"freed: skip");
2069 if (!buffer_mapped(bh)) {
2070 BUFFER_TRACE(bh,
"unmapped");
2071 ext3_get_block(inode, iblock, bh, 0);
2073 if (!buffer_mapped(bh)) {
2074 BUFFER_TRACE(bh,
"still unmapped");
2080 if (PageUptodate(page))
2081 set_buffer_uptodate(bh);
2091 if (!ext3_should_writeback_data(inode)) {
2093 handle = ext3_journal_start(inode, 1);
2094 if (IS_ERR(handle)) {
2095 clear_highpage(page);
2097 err = PTR_ERR(handle);
2102 if (ext3_should_journal_data(inode)) {
2103 BUFFER_TRACE(bh,
"get write access");
2109 zero_user(page, offset, length);
2110 BUFFER_TRACE(bh,
"zeroed end of block");
2113 if (ext3_should_journal_data(inode)) {
2116 if (ext3_should_order_data(inode))
2178 static Indirect *ext3_find_shared(
struct inode *inode,
int depth,
2186 for (k = depth; k > 1 && !offsets[k-1]; k--)
2188 partial = ext3_get_branch(inode, k, offsets, chain, &err);
2191 partial = chain + k-1;
2196 if (!partial->
key && *partial->
p)
2199 for (p=partial; p>chain && all_zeroes((
__le32*)p->
bh->b_data,p->
p); p--)
2207 if (p == chain + k - 1 && p > chain) {
2218 while(partial > p) {
2219 brelse(partial->
bh);
2234 static void ext3_clear_blocks(handle_t *handle,
struct inode *inode,
2239 if (try_to_extend_transaction(handle, inode)) {
2241 BUFFER_TRACE(bh,
"call ext3_journal_dirty_metadata");
2246 truncate_restart_transaction(handle, inode);
2248 BUFFER_TRACE(bh,
"retaking write access");
2262 for (p = first; p < last; p++) {
2265 struct buffer_head *bh;
2268 bh = sb_find_get_block(inode->
i_sb, nr);
2295 static void ext3_free_data(handle_t *handle,
struct inode *inode,
2296 struct buffer_head *this_bh,
2300 unsigned long count = 0;
2310 BUFFER_TRACE(this_bh,
"get_write_access");
2318 for (p = first; p < last; p++) {
2324 block_to_free_p =
p;
2326 }
else if (nr == block_to_free + count) {
2329 ext3_clear_blocks(handle, inode, this_bh,
2331 count, block_to_free_p, p);
2333 block_to_free_p =
p;
2340 ext3_clear_blocks(handle, inode, this_bh, block_to_free,
2341 count, block_to_free_p, p);
2344 BUFFER_TRACE(this_bh,
"call ext3_journal_dirty_metadata");
2356 "circular indirect block detected, "
2357 "inode=%lu, block=%llu",
2359 (
unsigned long long)this_bh->b_blocknr);
2376 static void ext3_free_branches(handle_t *handle,
struct inode *inode,
2377 struct buffer_head *parent_bh,
2383 if (is_handle_aborted(handle))
2387 struct buffer_head *bh;
2390 while (--p >= first) {
2396 bh = sb_bread(inode->
i_sb, nr);
2404 "Read failure, inode=%lu, block="E3FSBLK,
2410 BUFFER_TRACE(bh,
"free child branches");
2411 ext3_free_branches(handle, inode, bh,
2413 (
__le32*)bh->b_data + addr_per_block,
2432 if (is_handle_aborted(handle))
2434 if (try_to_extend_transaction(handle, inode)) {
2436 truncate_restart_transaction(handle, inode);
2471 BUFFER_TRACE(parent_bh,
"get_write_access");
2475 BUFFER_TRACE(parent_bh,
2476 "call ext3_journal_dirty_metadata");
2484 BUFFER_TRACE(parent_bh,
"free data blocks");
2485 ext3_free_data(handle, inode, parent_bh, first, last);
2496 return !ext3_inode_is_fast_symlink(inode);
2540 unsigned blocksize = inode->
i_sb->s_blocksize;
2542 trace_ext3_truncate_enter(inode);
2547 if (inode->
i_size == 0 && ext3_should_writeback_data(inode))
2550 handle = start_transaction(inode);
2554 last_block = (inode->
i_size + blocksize-1)
2556 n = ext3_block_to_path(inode, last_block, offsets,
NULL);
2588 ext3_free_data(handle, inode,
NULL, i_data+offsets[0],
2593 partial = ext3_find_shared(inode, n, offsets, chain, &nr);
2596 if (partial == chain) {
2598 ext3_free_branches(handle, inode,
NULL,
2599 &nr, &nr+1, (chain+n-1) - partial);
2607 ext3_free_branches(handle, inode, partial->
bh,
2609 partial->
p+1, (chain+n-1) - partial);
2613 while (partial > chain) {
2614 ext3_free_branches(handle, inode, partial->
bh, partial->
p + 1,
2615 (
__le32*)partial->
bh->b_data+addr_per_block,
2616 (chain+n-1) - partial);
2617 BUFFER_TRACE(partial->
bh,
"call brelse");
2618 brelse (partial->
bh);
2623 switch (offsets[0]) {
2627 ext3_free_branches(handle, inode,
NULL, &nr, &nr+1, 1);
2633 ext3_free_branches(handle, inode,
NULL, &nr, &nr+1, 2);
2639 ext3_free_branches(handle, inode,
NULL, &nr, &nr+1, 3);
2670 trace_ext3_truncate_exit(inode);
2679 trace_ext3_truncate_exit(inode);
2690 if (!ext3_valid_inum(sb, ino)) {
2722 static int __ext3_get_inode_loc(
struct inode *inode,
2726 struct buffer_head *bh;
2728 block = ext3_get_inode_block(inode->
i_sb, inode->
i_ino, iloc);
2732 bh = sb_getblk(inode->
i_sb, block);
2735 "unable to read inode block - "
2737 inode->
i_ino, block);
2740 if (!buffer_uptodate(bh)) {
2749 if (buffer_write_io_error(bh) && !buffer_uptodate(bh))
2750 set_buffer_uptodate(bh);
2752 if (buffer_uptodate(bh)) {
2764 struct buffer_head *bitmap_bh;
2766 int inodes_per_buffer;
2767 int inode_offset,
i;
2771 block_group = (inode->
i_ino - 1) /
2773 inodes_per_buffer = bh->b_size /
2775 inode_offset = ((inode->
i_ino - 1) %
2777 start = inode_offset & ~(inodes_per_buffer - 1);
2785 bitmap_bh = sb_getblk(inode->
i_sb,
2795 if (!buffer_uptodate(bitmap_bh)) {
2799 for (i = start; i < start + inodes_per_buffer; i++) {
2800 if (i == inode_offset)
2806 if (i == start + inodes_per_buffer) {
2808 memset(bh->b_data, 0, bh->b_size);
2809 set_buffer_uptodate(bh);
2821 trace_ext3_load_inode(inode);
2826 if (!buffer_uptodate(bh)) {
2828 "unable to read inode block - "
2830 inode->
i_ino, block);
2843 return __ext3_get_inode_loc(inode, iloc,
2849 unsigned int flags = EXT3_I(inode)->i_flags;
2867 unsigned int flags = ei->
vfs_inode.i_flags;
2888 struct buffer_head *bh;
2889 struct inode *
inode;
2890 journal_t *journal = EXT3_SB(sb)->s_journal;
2906 ret = __ext3_get_inode_loc(inode, &iloc, 0);
2910 raw_inode = ext3_raw_inode(&iloc);
2915 i_uid |=
le16_to_cpu(raw_inode->i_uid_high) << 16;
2916 i_gid |=
le16_to_cpu(raw_inode->i_gid_high) << 16;
2918 i_uid_write(inode, i_uid);
2919 i_gid_write(inode, i_gid);
2936 if (inode->
i_mode == 0 ||
2950 #ifdef EXT3_FRAGMENTS
2952 ei->i_frag_no = raw_inode->i_frag;
2953 ei->i_frag_size = raw_inode->i_fsize;
2983 spin_lock(&journal->j_state_lock);
2984 if (journal->j_running_transaction)
2985 transaction = journal->j_running_transaction;
2987 transaction = journal->j_committing_transaction;
2989 tid = transaction->t_tid;
2991 tid = journal->j_commit_sequence;
2992 spin_unlock(&journal->j_state_lock);
3014 EXT3_GOOD_OLD_INODE_SIZE;
3033 if (ext3_inode_is_fast_symlink(inode)) {
3057 return ERR_PTR(ret);
3067 static int ext3_do_update_inode(handle_t *handle,
3068 struct inode *inode,
3071 struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3073 struct buffer_head *bh = iloc->
bh;
3075 int need_datasync = 0;
3087 memset(raw_inode, 0, EXT3_SB(inode->
i_sb)->s_inode_size);
3091 i_uid = i_uid_read(inode);
3092 i_gid = i_gid_read(inode);
3101 raw_inode->i_uid_high =
3103 raw_inode->i_gid_high =
3106 raw_inode->i_uid_high = 0;
3107 raw_inode->i_gid_high = 0;
3110 raw_inode->i_uid_low =
3112 raw_inode->i_gid_low =
3114 raw_inode->i_uid_high = 0;
3115 raw_inode->i_gid_high = 0;
3119 if (disksize != raw_inode->
i_size) {
3121 raw_inode->
i_size = disksize;
3129 #ifdef EXT3_FRAGMENTS
3131 raw_inode->i_frag = ei->i_frag_no;
3132 raw_inode->i_fsize = ei->i_frag_size;
3139 if (disksize != raw_inode->i_size_high) {
3140 raw_inode->i_size_high = disksize;
3147 EXT3_SB(sb)->s_es->s_rev_level ==
3154 EXT3_SB(sb)->s_sbh);
3163 EXT3_SB(sb)->s_sbh);
3171 if (old_valid_dev(inode->
i_rdev)) {
3187 BUFFER_TRACE(bh,
"call ext3_journal_dirty_metadata");
3243 if (ext3_journal_current_handle()) {
3244 jbd_debug(1,
"called recursively, non-PF_MEMALLOC!\n");
3274 struct inode *inode = dentry->
d_inode;
3276 const unsigned int ia_valid = attr->
ia_valid;
3282 if (is_quota_modification(inode, attr))
3292 if (IS_ERR(handle)) {
3293 error = PTR_ERR(handle);
3318 handle = ext3_journal_start(inode, 3);
3319 if (IS_ERR(handle)) {
3320 error = PTR_ERR(handle);
3329 EXT3_I(inode)->i_disksize = attr->
ia_size;
3337 rc = ext3_block_truncate_page(inode, attr->
ia_size);
3340 handle = ext3_journal_start(inode, 3);
3341 if (IS_ERR(handle)) {
3352 attr->
ia_size != i_size_read(inode)) {
3358 mark_inode_dirty(inode);
3398 static int ext3_writepage_trans_blocks(
struct inode *inode)
3400 int bpp = ext3_journal_blocks_per_page(inode);
3404 if (ext3_should_journal_data(inode))
3405 ret = 3 * (bpp + indirects) + 2;
3407 ret = 2 * (bpp + indirects) + indirects + 2;
3423 struct inode *inode,
struct ext3_iloc *iloc)
3431 err = ext3_do_update_inode(handle, inode, iloc);
3449 BUFFER_TRACE(iloc->
bh,
"get_write_access");
3480 trace_ext3_mark_inode_dirty(inode,
_RET_IP_);
3503 handle_t *current_handle = ext3_journal_current_handle();
3506 handle = ext3_journal_start(inode, 2);
3509 if (current_handle &&
3510 current_handle->h_transaction != handle->h_transaction) {
3515 jbd_debug(5,
"marking dirty. outer handle=%p\n",
3532 static int ext3_pin_inode(handle_t *handle,
struct inode *inode)
3540 BUFFER_TRACE(iloc.
bh,
"get_write_access");
3570 if (is_journal_aborted(journal))
3594 handle = ext3_journal_start(inode, 1);
3596 return PTR_ERR(handle);