Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / ext3-truncate_blocks.patch
1 --- ./fs/ext3/inode.c.orig      Wed Mar 12 02:44:06 2003
2 +++ ./fs/ext3/inode.c   Wed Mar 12 11:55:20 2003
3 @@ -99,7 +99,35 @@ int ext3_forget(handle_t *handle, int is
4         return err;
5  }
6  
7 -/* 
8 +/*
9 + * Work out how many blocks we need to progress with the next chunk of a
10 + * truncate transaction.
11 + */
12 +
13 +static unsigned long blocks_for_truncate(struct inode *inode)
14 +{
15 +       unsigned long needed;
16 +
17 +       needed = inode->i_blocks >> (inode->i_sb->s_blocksize_bits - 9);
18 +
19 +       /* Give ourselves just enough room to cope with inodes in which
20 +        * i_blocks is corrupt: we've seen disk corruptions in the past
21 +        * which resulted in random data in an inode which looked enough
22 +        * like a regular file for ext3 to try to delete it.  Things
23 +        * will go a bit crazy if that happens, but at least we should
24 +        * try not to panic the whole kernel. */
25 +       if (needed < 2)
26 +               needed = 2;
27 +
28 +       /* But we need to bound the transaction so we don't overflow the
29 +        * journal. */
30 +       if (needed > EXT3_MAX_TRANS_DATA)
31 +               needed = EXT3_MAX_TRANS_DATA;
32 +
33 +       return EXT3_DATA_TRANS_BLOCKS + needed;
34 +}
35 +
36 +/*
37   * Truncate transactions can be complex and absolutely huge.  So we need to
38   * be able to restart the transaction at a conventient checkpoint to make
39   * sure we don't overflow the journal.
40 @@ -110,19 +138,14 @@ int ext3_forget(handle_t *handle, int is
41   * transaction in the top-level truncate loop. --sct 
42   */
43  
44 -static handle_t *start_transaction(struct inode *inode) 
45 +static handle_t *start_transaction(struct inode *inode)
46  {
47 -       long needed;
48         handle_t *result;
49 -       
50 -       needed = inode->i_blocks;
51 -       if (needed > EXT3_MAX_TRANS_DATA) 
52 -               needed = EXT3_MAX_TRANS_DATA;
53 -       
54 -       result = ext3_journal_start(inode, EXT3_DATA_TRANS_BLOCKS + needed);
55 +
56 +       result = ext3_journal_start(inode, blocks_for_truncate(inode));
57         if (!IS_ERR(result))
58                 return result;
59 -       
60 +
61         ext3_std_error(inode->i_sb, PTR_ERR(result));
62         return result;
63  }
64 @@ -135,14 +158,9 @@ static handle_t *start_transaction(struc
65   */
66  static int try_to_extend_transaction(handle_t *handle, struct inode *inode)
67  {
68 -       long needed;
69 -       
70         if (handle->h_buffer_credits > EXT3_RESERVE_TRANS_BLOCKS)
71                 return 0;
72 -       needed = inode->i_blocks;
73 -       if (needed > EXT3_MAX_TRANS_DATA) 
74 -               needed = EXT3_MAX_TRANS_DATA;
75 -       if (!ext3_journal_extend(handle, EXT3_RESERVE_TRANS_BLOCKS + needed))
76 +       if (!ext3_journal_extend(handle, blocks_for_truncate(inode)))
77                 return 0;
78         return 1;
79  }
80 @@ -154,11 +172,8 @@ static int try_to_extend_transaction(han
81   */
82  static int ext3_journal_test_restart(handle_t *handle, struct inode *inode)
83  {
84 -       long needed = inode->i_blocks;
85 -       if (needed > EXT3_MAX_TRANS_DATA) 
86 -               needed = EXT3_MAX_TRANS_DATA;
87         jbd_debug(2, "restarting handle %p\n", handle);
88 -       return ext3_journal_restart(handle, EXT3_DATA_TRANS_BLOCKS + needed);
89 +       return ext3_journal_restart(handle, blocks_for_truncate(inode));
90  }
91  
92  /*