aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/resize.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2005-07-12 23:21:28 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-12 23:21:28 -0400
commitbd4c625c061c2a38568d0add3478f59172455159 (patch)
tree1c44a17c55bce2ee7ad5ea3d15a208ecc0955f74 /fs/reiserfs/resize.c
parent7fa94c8868edfef8cb6a201fcc9a5078b7b961da (diff)
reiserfs: run scripts/Lindent on reiserfs code
This was a pure indentation change, using: scripts/Lindent fs/reiserfs/*.c include/linux/reiserfs_*.h to make reiserfs match the regular Linux indentation style. As Jeff Mahoney <jeffm@suse.com> writes: The ReiserFS code is a mix of a number of different coding styles, sometimes different even from line-to-line. Since the code has been relatively stable for quite some time and there are few outstanding patches to be applied, it is time to reformat the code to conform to the Linux style standard outlined in Documentation/CodingStyle. This patch contains the result of running scripts/Lindent against fs/reiserfs/*.c and include/linux/reiserfs_*.h. There are places where the code can be made to look better, but I'd rather keep those patches separate so that there isn't a subtle by-hand hand accident in the middle of a huge patch. To be clear: This patch is reformatting *only*. A number of patches may follow that continue to make the code more consistent with the Linux coding style. Hans wasn't particularly enthusiastic about these patches, but said he wouldn't really oppose them either. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/reiserfs/resize.c')
-rw-r--r--fs/reiserfs/resize.c207
1 files changed, 108 insertions, 99 deletions
diff --git a/fs/reiserfs/resize.c b/fs/reiserfs/resize.c
index 170012078b76..39cc7f47f5dc 100644
--- a/fs/reiserfs/resize.c
+++ b/fs/reiserfs/resize.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README 2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
3 */ 3 */
4 4
5/* 5/*
6 * Written by Alexander Zarochentcev. 6 * Written by Alexander Zarochentcev.
7 * 7 *
@@ -17,23 +17,23 @@
17#include <linux/reiserfs_fs_sb.h> 17#include <linux/reiserfs_fs_sb.h>
18#include <linux/buffer_head.h> 18#include <linux/buffer_head.h>
19 19
20int reiserfs_resize (struct super_block * s, unsigned long block_count_new) 20int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
21{ 21{
22 int err = 0; 22 int err = 0;
23 struct reiserfs_super_block * sb; 23 struct reiserfs_super_block *sb;
24 struct reiserfs_bitmap_info *bitmap; 24 struct reiserfs_bitmap_info *bitmap;
25 struct reiserfs_bitmap_info *old_bitmap = SB_AP_BITMAP(s); 25 struct reiserfs_bitmap_info *old_bitmap = SB_AP_BITMAP(s);
26 struct buffer_head * bh; 26 struct buffer_head *bh;
27 struct reiserfs_transaction_handle th; 27 struct reiserfs_transaction_handle th;
28 unsigned int bmap_nr_new, bmap_nr; 28 unsigned int bmap_nr_new, bmap_nr;
29 unsigned int block_r_new, block_r; 29 unsigned int block_r_new, block_r;
30 30
31 struct reiserfs_list_bitmap * jb; 31 struct reiserfs_list_bitmap *jb;
32 struct reiserfs_list_bitmap jbitmap[JOURNAL_NUM_BITMAPS]; 32 struct reiserfs_list_bitmap jbitmap[JOURNAL_NUM_BITMAPS];
33 33
34 unsigned long int block_count, free_blocks; 34 unsigned long int block_count, free_blocks;
35 int i; 35 int i;
36 int copy_size ; 36 int copy_size;
37 37
38 sb = SB_DISK_SUPER_BLOCK(s); 38 sb = SB_DISK_SUPER_BLOCK(s);
39 39
@@ -47,136 +47,145 @@ int reiserfs_resize (struct super_block * s, unsigned long block_count_new)
47 if (!bh) { 47 if (!bh) {
48 printk("reiserfs_resize: can\'t read last block\n"); 48 printk("reiserfs_resize: can\'t read last block\n");
49 return -EINVAL; 49 return -EINVAL;
50 } 50 }
51 bforget(bh); 51 bforget(bh);
52 52
53 /* old disk layout detection; those partitions can be mounted, but 53 /* old disk layout detection; those partitions can be mounted, but
54 * cannot be resized */ 54 * cannot be resized */
55 if (SB_BUFFER_WITH_SB(s)->b_blocknr * SB_BUFFER_WITH_SB(s)->b_size 55 if (SB_BUFFER_WITH_SB(s)->b_blocknr * SB_BUFFER_WITH_SB(s)->b_size
56 != REISERFS_DISK_OFFSET_IN_BYTES ) { 56 != REISERFS_DISK_OFFSET_IN_BYTES) {
57 printk("reiserfs_resize: unable to resize a reiserfs without distributed bitmap (fs version < 3.5.12)\n"); 57 printk
58 ("reiserfs_resize: unable to resize a reiserfs without distributed bitmap (fs version < 3.5.12)\n");
58 return -ENOTSUPP; 59 return -ENOTSUPP;
59 } 60 }
60 61
61 /* count used bits in last bitmap block */ 62 /* count used bits in last bitmap block */
62 block_r = SB_BLOCK_COUNT(s) - 63 block_r = SB_BLOCK_COUNT(s) - (SB_BMAP_NR(s) - 1) * s->s_blocksize * 8;
63 (SB_BMAP_NR(s) - 1) * s->s_blocksize * 8; 64
64
65 /* count bitmap blocks in new fs */ 65 /* count bitmap blocks in new fs */
66 bmap_nr_new = block_count_new / ( s->s_blocksize * 8 ); 66 bmap_nr_new = block_count_new / (s->s_blocksize * 8);
67 block_r_new = block_count_new - bmap_nr_new * s->s_blocksize * 8; 67 block_r_new = block_count_new - bmap_nr_new * s->s_blocksize * 8;
68 if (block_r_new) 68 if (block_r_new)
69 bmap_nr_new++; 69 bmap_nr_new++;
70 else 70 else
71 block_r_new = s->s_blocksize * 8; 71 block_r_new = s->s_blocksize * 8;
72 72
73 /* save old values */ 73 /* save old values */
74 block_count = SB_BLOCK_COUNT(s); 74 block_count = SB_BLOCK_COUNT(s);
75 bmap_nr = SB_BMAP_NR(s); 75 bmap_nr = SB_BMAP_NR(s);
76 76
77 /* resizing of reiserfs bitmaps (journal and real), if needed */ 77 /* resizing of reiserfs bitmaps (journal and real), if needed */
78 if (bmap_nr_new > bmap_nr) { 78 if (bmap_nr_new > bmap_nr) {
79 /* reallocate journal bitmaps */ 79 /* reallocate journal bitmaps */
80 if (reiserfs_allocate_list_bitmaps(s, jbitmap, bmap_nr_new) < 0) { 80 if (reiserfs_allocate_list_bitmaps(s, jbitmap, bmap_nr_new) < 0) {
81 printk("reiserfs_resize: unable to allocate memory for journal bitmaps\n"); 81 printk
82 unlock_super(s) ; 82 ("reiserfs_resize: unable to allocate memory for journal bitmaps\n");
83 return -ENOMEM ; 83 unlock_super(s);
84 } 84 return -ENOMEM;
85 /* the new journal bitmaps are zero filled, now we copy in the bitmap 85 }
86 ** node pointers from the old journal bitmap structs, and then 86 /* the new journal bitmaps are zero filled, now we copy in the bitmap
87 ** transfer the new data structures into the journal struct. 87 ** node pointers from the old journal bitmap structs, and then
88 ** 88 ** transfer the new data structures into the journal struct.
89 ** using the copy_size var below allows this code to work for 89 **
90 ** both shrinking and expanding the FS. 90 ** using the copy_size var below allows this code to work for
91 */ 91 ** both shrinking and expanding the FS.
92 copy_size = bmap_nr_new < bmap_nr ? bmap_nr_new : bmap_nr ; 92 */
93 copy_size = copy_size * sizeof(struct reiserfs_list_bitmap_node *) ; 93 copy_size = bmap_nr_new < bmap_nr ? bmap_nr_new : bmap_nr;
94 for (i = 0 ; i < JOURNAL_NUM_BITMAPS ; i++) { 94 copy_size =
95 struct reiserfs_bitmap_node **node_tmp ; 95 copy_size * sizeof(struct reiserfs_list_bitmap_node *);
96 jb = SB_JOURNAL(s)->j_list_bitmap + i ; 96 for (i = 0; i < JOURNAL_NUM_BITMAPS; i++) {
97 memcpy(jbitmap[i].bitmaps, jb->bitmaps, copy_size) ; 97 struct reiserfs_bitmap_node **node_tmp;
98 98 jb = SB_JOURNAL(s)->j_list_bitmap + i;
99 /* just in case vfree schedules on us, copy the new 99 memcpy(jbitmap[i].bitmaps, jb->bitmaps, copy_size);
100 ** pointer into the journal struct before freeing the 100
101 ** old one 101 /* just in case vfree schedules on us, copy the new
102 */ 102 ** pointer into the journal struct before freeing the
103 node_tmp = jb->bitmaps ; 103 ** old one
104 jb->bitmaps = jbitmap[i].bitmaps ; 104 */
105 vfree(node_tmp) ; 105 node_tmp = jb->bitmaps;
106 } 106 jb->bitmaps = jbitmap[i].bitmaps;
107 107 vfree(node_tmp);
108 /* allocate additional bitmap blocks, reallocate array of bitmap 108 }
109 * block pointers */ 109
110 bitmap = vmalloc(sizeof(struct reiserfs_bitmap_info) * bmap_nr_new); 110 /* allocate additional bitmap blocks, reallocate array of bitmap
111 if (!bitmap) { 111 * block pointers */
112 /* Journal bitmaps are still supersized, but the memory isn't 112 bitmap =
113 * leaked, so I guess it's ok */ 113 vmalloc(sizeof(struct reiserfs_bitmap_info) * bmap_nr_new);
114 printk("reiserfs_resize: unable to allocate memory.\n"); 114 if (!bitmap) {
115 return -ENOMEM; 115 /* Journal bitmaps are still supersized, but the memory isn't
116 } 116 * leaked, so I guess it's ok */
117 memset (bitmap, 0, sizeof (struct reiserfs_bitmap_info) * SB_BMAP_NR(s)); 117 printk("reiserfs_resize: unable to allocate memory.\n");
118 for (i = 0; i < bmap_nr; i++) 118 return -ENOMEM;
119 bitmap[i] = old_bitmap[i]; 119 }
120 120 memset(bitmap, 0,
121 /* This doesn't go through the journal, but it doesn't have to. 121 sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
122 * The changes are still atomic: We're synced up when the journal 122 for (i = 0; i < bmap_nr; i++)
123 * transaction begins, and the new bitmaps don't matter if the 123 bitmap[i] = old_bitmap[i];
124 * transaction fails. */ 124
125 for (i = bmap_nr; i < bmap_nr_new; i++) { 125 /* This doesn't go through the journal, but it doesn't have to.
126 bitmap[i].bh = sb_getblk(s, i * s->s_blocksize * 8); 126 * The changes are still atomic: We're synced up when the journal
127 memset(bitmap[i].bh->b_data, 0, sb_blocksize(sb)); 127 * transaction begins, and the new bitmaps don't matter if the
128 reiserfs_test_and_set_le_bit(0, bitmap[i].bh->b_data); 128 * transaction fails. */
129 129 for (i = bmap_nr; i < bmap_nr_new; i++) {
130 set_buffer_uptodate(bitmap[i].bh); 130 bitmap[i].bh = sb_getblk(s, i * s->s_blocksize * 8);
131 mark_buffer_dirty(bitmap[i].bh) ; 131 memset(bitmap[i].bh->b_data, 0, sb_blocksize(sb));
132 sync_dirty_buffer(bitmap[i].bh); 132 reiserfs_test_and_set_le_bit(0, bitmap[i].bh->b_data);
133 // update bitmap_info stuff 133
134 bitmap[i].first_zero_hint=1; 134 set_buffer_uptodate(bitmap[i].bh);
135 bitmap[i].free_count = sb_blocksize(sb) * 8 - 1; 135 mark_buffer_dirty(bitmap[i].bh);
136 } 136 sync_dirty_buffer(bitmap[i].bh);
137 /* free old bitmap blocks array */ 137 // update bitmap_info stuff
138 SB_AP_BITMAP(s) = bitmap; 138 bitmap[i].first_zero_hint = 1;
139 vfree (old_bitmap); 139 bitmap[i].free_count = sb_blocksize(sb) * 8 - 1;
140 }
141 /* free old bitmap blocks array */
142 SB_AP_BITMAP(s) = bitmap;
143 vfree(old_bitmap);
140 } 144 }
141 145
142 /* begin transaction, if there was an error, it's fine. Yes, we have 146 /* begin transaction, if there was an error, it's fine. Yes, we have
143 * incorrect bitmaps now, but none of it is ever going to touch the 147 * incorrect bitmaps now, but none of it is ever going to touch the
144 * disk anyway. */ 148 * disk anyway. */
145 err = journal_begin(&th, s, 10); 149 err = journal_begin(&th, s, 10);
146 if (err) 150 if (err)
147 return err; 151 return err;
148 152
149 /* correct last bitmap blocks in old and new disk layout */ 153 /* correct last bitmap blocks in old and new disk layout */
150 reiserfs_prepare_for_journal(s, SB_AP_BITMAP(s)[bmap_nr - 1].bh, 1); 154 reiserfs_prepare_for_journal(s, SB_AP_BITMAP(s)[bmap_nr - 1].bh, 1);
151 for (i = block_r; i < s->s_blocksize * 8; i++) 155 for (i = block_r; i < s->s_blocksize * 8; i++)
152 reiserfs_test_and_clear_le_bit(i, 156 reiserfs_test_and_clear_le_bit(i,
153 SB_AP_BITMAP(s)[bmap_nr - 1].bh->b_data); 157 SB_AP_BITMAP(s)[bmap_nr -
158 1].bh->b_data);
154 SB_AP_BITMAP(s)[bmap_nr - 1].free_count += s->s_blocksize * 8 - block_r; 159 SB_AP_BITMAP(s)[bmap_nr - 1].free_count += s->s_blocksize * 8 - block_r;
155 if ( !SB_AP_BITMAP(s)[bmap_nr - 1].first_zero_hint) 160 if (!SB_AP_BITMAP(s)[bmap_nr - 1].first_zero_hint)
156 SB_AP_BITMAP(s)[bmap_nr - 1].first_zero_hint = block_r; 161 SB_AP_BITMAP(s)[bmap_nr - 1].first_zero_hint = block_r;
157 162
158 journal_mark_dirty(&th, s, SB_AP_BITMAP(s)[bmap_nr - 1].bh); 163 journal_mark_dirty(&th, s, SB_AP_BITMAP(s)[bmap_nr - 1].bh);
159 164
160 reiserfs_prepare_for_journal(s, SB_AP_BITMAP(s)[bmap_nr_new - 1].bh, 1); 165 reiserfs_prepare_for_journal(s, SB_AP_BITMAP(s)[bmap_nr_new - 1].bh, 1);
161 for (i = block_r_new; i < s->s_blocksize * 8; i++) 166 for (i = block_r_new; i < s->s_blocksize * 8; i++)
162 reiserfs_test_and_set_le_bit(i, 167 reiserfs_test_and_set_le_bit(i,
163 SB_AP_BITMAP(s)[bmap_nr_new - 1].bh->b_data); 168 SB_AP_BITMAP(s)[bmap_nr_new -
169 1].bh->b_data);
164 journal_mark_dirty(&th, s, SB_AP_BITMAP(s)[bmap_nr_new - 1].bh); 170 journal_mark_dirty(&th, s, SB_AP_BITMAP(s)[bmap_nr_new - 1].bh);
165 171
166 SB_AP_BITMAP(s)[bmap_nr_new - 1].free_count -= s->s_blocksize * 8 - block_r_new; 172 SB_AP_BITMAP(s)[bmap_nr_new - 1].free_count -=
173 s->s_blocksize * 8 - block_r_new;
167 /* Extreme case where last bitmap is the only valid block in itself. */ 174 /* Extreme case where last bitmap is the only valid block in itself. */
168 if ( !SB_AP_BITMAP(s)[bmap_nr_new - 1].free_count ) 175 if (!SB_AP_BITMAP(s)[bmap_nr_new - 1].free_count)
169 SB_AP_BITMAP(s)[bmap_nr_new - 1].first_zero_hint = 0; 176 SB_AP_BITMAP(s)[bmap_nr_new - 1].first_zero_hint = 0;
170 /* update super */ 177 /* update super */
171 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ; 178 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
172 free_blocks = SB_FREE_BLOCKS(s); 179 free_blocks = SB_FREE_BLOCKS(s);
173 PUT_SB_FREE_BLOCKS(s, free_blocks + (block_count_new - block_count - (bmap_nr_new - bmap_nr))); 180 PUT_SB_FREE_BLOCKS(s,
181 free_blocks + (block_count_new - block_count -
182 (bmap_nr_new - bmap_nr)));
174 PUT_SB_BLOCK_COUNT(s, block_count_new); 183 PUT_SB_BLOCK_COUNT(s, block_count_new);
175 PUT_SB_BMAP_NR(s, bmap_nr_new); 184 PUT_SB_BMAP_NR(s, bmap_nr_new);
176 s->s_dirt = 1; 185 s->s_dirt = 1;
177 186
178 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s)); 187 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
179 188
180 SB_JOURNAL(s)->j_must_wait = 1; 189 SB_JOURNAL(s)->j_must_wait = 1;
181 return journal_end(&th, s, 10); 190 return journal_end(&th, s, 10);
182} 191}