diff options
Diffstat (limited to 'fs/reiserfs/resize.c')
-rw-r--r-- | fs/reiserfs/resize.c | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/fs/reiserfs/resize.c b/fs/reiserfs/resize.c index a4ef5cd606eb..6052d323bc9a 100644 --- a/fs/reiserfs/resize.c +++ b/fs/reiserfs/resize.c | |||
@@ -53,8 +53,10 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new) | |||
53 | } | 53 | } |
54 | bforget(bh); | 54 | bforget(bh); |
55 | 55 | ||
56 | /* old disk layout detection; those partitions can be mounted, but | 56 | /* |
57 | * cannot be resized */ | 57 | * old disk layout detection; those partitions can be mounted, but |
58 | * cannot be resized | ||
59 | */ | ||
58 | if (SB_BUFFER_WITH_SB(s)->b_blocknr * SB_BUFFER_WITH_SB(s)->b_size | 60 | if (SB_BUFFER_WITH_SB(s)->b_blocknr * SB_BUFFER_WITH_SB(s)->b_size |
59 | != REISERFS_DISK_OFFSET_IN_BYTES) { | 61 | != REISERFS_DISK_OFFSET_IN_BYTES) { |
60 | printk | 62 | printk |
@@ -86,12 +88,14 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new) | |||
86 | ("reiserfs_resize: unable to allocate memory for journal bitmaps\n"); | 88 | ("reiserfs_resize: unable to allocate memory for journal bitmaps\n"); |
87 | return -ENOMEM; | 89 | return -ENOMEM; |
88 | } | 90 | } |
89 | /* the new journal bitmaps are zero filled, now we copy in the bitmap | 91 | /* |
90 | ** node pointers from the old journal bitmap structs, and then | 92 | * the new journal bitmaps are zero filled, now we copy i |
91 | ** transfer the new data structures into the journal struct. | 93 | * the bitmap node pointers from the old journal bitmap |
92 | ** | 94 | * structs, and then transfer the new data structures |
93 | ** using the copy_size var below allows this code to work for | 95 | * into the journal struct. |
94 | ** both shrinking and expanding the FS. | 96 | * |
97 | * using the copy_size var below allows this code to work for | ||
98 | * both shrinking and expanding the FS. | ||
95 | */ | 99 | */ |
96 | copy_size = bmap_nr_new < bmap_nr ? bmap_nr_new : bmap_nr; | 100 | copy_size = bmap_nr_new < bmap_nr ? bmap_nr_new : bmap_nr; |
97 | copy_size = | 101 | copy_size = |
@@ -101,36 +105,45 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new) | |||
101 | jb = SB_JOURNAL(s)->j_list_bitmap + i; | 105 | jb = SB_JOURNAL(s)->j_list_bitmap + i; |
102 | memcpy(jbitmap[i].bitmaps, jb->bitmaps, copy_size); | 106 | memcpy(jbitmap[i].bitmaps, jb->bitmaps, copy_size); |
103 | 107 | ||
104 | /* just in case vfree schedules on us, copy the new | 108 | /* |
105 | ** pointer into the journal struct before freeing the | 109 | * just in case vfree schedules on us, copy the new |
106 | ** old one | 110 | * pointer into the journal struct before freeing the |
111 | * old one | ||
107 | */ | 112 | */ |
108 | node_tmp = jb->bitmaps; | 113 | node_tmp = jb->bitmaps; |
109 | jb->bitmaps = jbitmap[i].bitmaps; | 114 | jb->bitmaps = jbitmap[i].bitmaps; |
110 | vfree(node_tmp); | 115 | vfree(node_tmp); |
111 | } | 116 | } |
112 | 117 | ||
113 | /* allocate additional bitmap blocks, reallocate array of bitmap | 118 | /* |
114 | * block pointers */ | 119 | * allocate additional bitmap blocks, reallocate |
120 | * array of bitmap block pointers | ||
121 | */ | ||
115 | bitmap = | 122 | bitmap = |
116 | vzalloc(sizeof(struct reiserfs_bitmap_info) * bmap_nr_new); | 123 | vzalloc(sizeof(struct reiserfs_bitmap_info) * bmap_nr_new); |
117 | if (!bitmap) { | 124 | if (!bitmap) { |
118 | /* Journal bitmaps are still supersized, but the memory isn't | 125 | /* |
119 | * leaked, so I guess it's ok */ | 126 | * Journal bitmaps are still supersized, but the |
127 | * memory isn't leaked, so I guess it's ok | ||
128 | */ | ||
120 | printk("reiserfs_resize: unable to allocate memory.\n"); | 129 | printk("reiserfs_resize: unable to allocate memory.\n"); |
121 | return -ENOMEM; | 130 | return -ENOMEM; |
122 | } | 131 | } |
123 | for (i = 0; i < bmap_nr; i++) | 132 | for (i = 0; i < bmap_nr; i++) |
124 | bitmap[i] = old_bitmap[i]; | 133 | bitmap[i] = old_bitmap[i]; |
125 | 134 | ||
126 | /* This doesn't go through the journal, but it doesn't have to. | 135 | /* |
127 | * The changes are still atomic: We're synced up when the journal | 136 | * This doesn't go through the journal, but it doesn't have to. |
128 | * transaction begins, and the new bitmaps don't matter if the | 137 | * The changes are still atomic: We're synced up when the |
129 | * transaction fails. */ | 138 | * journal transaction begins, and the new bitmaps don't |
139 | * matter if the transaction fails. | ||
140 | */ | ||
130 | for (i = bmap_nr; i < bmap_nr_new; i++) { | 141 | for (i = bmap_nr; i < bmap_nr_new; i++) { |
131 | int depth; | 142 | int depth; |
132 | /* don't use read_bitmap_block since it will cache | 143 | /* |
133 | * the uninitialized bitmap */ | 144 | * don't use read_bitmap_block since it will cache |
145 | * the uninitialized bitmap | ||
146 | */ | ||
134 | depth = reiserfs_write_unlock_nested(s); | 147 | depth = reiserfs_write_unlock_nested(s); |
135 | bh = sb_bread(s, i * s->s_blocksize * 8); | 148 | bh = sb_bread(s, i * s->s_blocksize * 8); |
136 | reiserfs_write_lock_nested(s, depth); | 149 | reiserfs_write_lock_nested(s, depth); |
@@ -147,7 +160,7 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new) | |||
147 | depth = reiserfs_write_unlock_nested(s); | 160 | depth = reiserfs_write_unlock_nested(s); |
148 | sync_dirty_buffer(bh); | 161 | sync_dirty_buffer(bh); |
149 | reiserfs_write_lock_nested(s, depth); | 162 | reiserfs_write_lock_nested(s, depth); |
150 | // update bitmap_info stuff | 163 | /* update bitmap_info stuff */ |
151 | bitmap[i].free_count = sb_blocksize(sb) * 8 - 1; | 164 | bitmap[i].free_count = sb_blocksize(sb) * 8 - 1; |
152 | brelse(bh); | 165 | brelse(bh); |
153 | } | 166 | } |
@@ -156,9 +169,11 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new) | |||
156 | vfree(old_bitmap); | 169 | vfree(old_bitmap); |
157 | } | 170 | } |
158 | 171 | ||
159 | /* begin transaction, if there was an error, it's fine. Yes, we have | 172 | /* |
173 | * begin transaction, if there was an error, it's fine. Yes, we have | ||
160 | * incorrect bitmaps now, but none of it is ever going to touch the | 174 | * incorrect bitmaps now, but none of it is ever going to touch the |
161 | * disk anyway. */ | 175 | * disk anyway. |
176 | */ | ||
162 | err = journal_begin(&th, s, 10); | 177 | err = journal_begin(&th, s, 10); |
163 | if (err) | 178 | if (err) |
164 | return err; | 179 | return err; |
@@ -167,7 +182,7 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new) | |||
167 | info = SB_AP_BITMAP(s) + bmap_nr - 1; | 182 | info = SB_AP_BITMAP(s) + bmap_nr - 1; |
168 | bh = reiserfs_read_bitmap_block(s, bmap_nr - 1); | 183 | bh = reiserfs_read_bitmap_block(s, bmap_nr - 1); |
169 | if (!bh) { | 184 | if (!bh) { |
170 | int jerr = journal_end(&th, s, 10); | 185 | int jerr = journal_end(&th); |
171 | if (jerr) | 186 | if (jerr) |
172 | return jerr; | 187 | return jerr; |
173 | return -EIO; | 188 | return -EIO; |
@@ -178,14 +193,14 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new) | |||
178 | reiserfs_clear_le_bit(i, bh->b_data); | 193 | reiserfs_clear_le_bit(i, bh->b_data); |
179 | info->free_count += s->s_blocksize * 8 - block_r; | 194 | info->free_count += s->s_blocksize * 8 - block_r; |
180 | 195 | ||
181 | journal_mark_dirty(&th, s, bh); | 196 | journal_mark_dirty(&th, bh); |
182 | brelse(bh); | 197 | brelse(bh); |
183 | 198 | ||
184 | /* Correct new last bitmap block - It may not be full */ | 199 | /* Correct new last bitmap block - It may not be full */ |
185 | info = SB_AP_BITMAP(s) + bmap_nr_new - 1; | 200 | info = SB_AP_BITMAP(s) + bmap_nr_new - 1; |
186 | bh = reiserfs_read_bitmap_block(s, bmap_nr_new - 1); | 201 | bh = reiserfs_read_bitmap_block(s, bmap_nr_new - 1); |
187 | if (!bh) { | 202 | if (!bh) { |
188 | int jerr = journal_end(&th, s, 10); | 203 | int jerr = journal_end(&th); |
189 | if (jerr) | 204 | if (jerr) |
190 | return jerr; | 205 | return jerr; |
191 | return -EIO; | 206 | return -EIO; |
@@ -194,7 +209,7 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new) | |||
194 | reiserfs_prepare_for_journal(s, bh, 1); | 209 | reiserfs_prepare_for_journal(s, bh, 1); |
195 | for (i = block_r_new; i < s->s_blocksize * 8; i++) | 210 | for (i = block_r_new; i < s->s_blocksize * 8; i++) |
196 | reiserfs_set_le_bit(i, bh->b_data); | 211 | reiserfs_set_le_bit(i, bh->b_data); |
197 | journal_mark_dirty(&th, s, bh); | 212 | journal_mark_dirty(&th, bh); |
198 | brelse(bh); | 213 | brelse(bh); |
199 | 214 | ||
200 | info->free_count -= s->s_blocksize * 8 - block_r_new; | 215 | info->free_count -= s->s_blocksize * 8 - block_r_new; |
@@ -207,8 +222,8 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new) | |||
207 | PUT_SB_BLOCK_COUNT(s, block_count_new); | 222 | PUT_SB_BLOCK_COUNT(s, block_count_new); |
208 | PUT_SB_BMAP_NR(s, bmap_would_wrap(bmap_nr_new) ? : bmap_nr_new); | 223 | PUT_SB_BMAP_NR(s, bmap_would_wrap(bmap_nr_new) ? : bmap_nr_new); |
209 | 224 | ||
210 | journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s)); | 225 | journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s)); |
211 | 226 | ||
212 | SB_JOURNAL(s)->j_must_wait = 1; | 227 | SB_JOURNAL(s)->j_must_wait = 1; |
213 | return journal_end(&th, s, 10); | 228 | return journal_end(&th); |
214 | } | 229 | } |