aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/objectid.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/reiserfs/objectid.c')
-rw-r--r--fs/reiserfs/objectid.c303
1 files changed, 152 insertions, 151 deletions
diff --git a/fs/reiserfs/objectid.c b/fs/reiserfs/objectid.c
index bfe8e25ef293..f62590aa9c95 100644
--- a/fs/reiserfs/objectid.c
+++ b/fs/reiserfs/objectid.c
@@ -14,24 +14,24 @@
14 (__le32 *)((struct reiserfs_super_block_v1 *)(rs) + 1) :\ 14 (__le32 *)((struct reiserfs_super_block_v1 *)(rs) + 1) :\
15 (__le32 *)((rs) + 1)) 15 (__le32 *)((rs) + 1))
16 16
17
18#ifdef CONFIG_REISERFS_CHECK 17#ifdef CONFIG_REISERFS_CHECK
19 18
20static void check_objectid_map (struct super_block * s, __le32 * map) 19static void check_objectid_map(struct super_block *s, __le32 * map)
21{ 20{
22 if (le32_to_cpu (map[0]) != 1) 21 if (le32_to_cpu(map[0]) != 1)
23 reiserfs_panic (s, "vs-15010: check_objectid_map: map corrupted: %lx", 22 reiserfs_panic(s,
24 ( long unsigned int ) le32_to_cpu (map[0])); 23 "vs-15010: check_objectid_map: map corrupted: %lx",
24 (long unsigned int)le32_to_cpu(map[0]));
25 25
26 // FIXME: add something else here 26 // FIXME: add something else here
27} 27}
28 28
29#else 29#else
30static void check_objectid_map (struct super_block * s, __le32 * map) 30static void check_objectid_map(struct super_block *s, __le32 * map)
31{;} 31{;
32}
32#endif 33#endif
33 34
34
35/* When we allocate objectids we allocate the first unused objectid. 35/* When we allocate objectids we allocate the first unused objectid.
36 Each sequence of objectids in use (the odd sequences) is followed 36 Each sequence of objectids in use (the odd sequences) is followed
37 by a sequence of objectids not in use (the even sequences). We 37 by a sequence of objectids not in use (the even sequences). We
@@ -46,161 +46,162 @@ static void check_objectid_map (struct super_block * s, __le32 * map)
46 interesting optimizations of layout could result from complicating 46 interesting optimizations of layout could result from complicating
47 objectid assignment, but we have deferred making them for now. */ 47 objectid assignment, but we have deferred making them for now. */
48 48
49
50/* get unique object identifier */ 49/* get unique object identifier */
51__u32 reiserfs_get_unused_objectid (struct reiserfs_transaction_handle *th) 50__u32 reiserfs_get_unused_objectid(struct reiserfs_transaction_handle *th)
52{ 51{
53 struct super_block * s = th->t_super; 52 struct super_block *s = th->t_super;
54 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s); 53 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
55 __le32 * map = objectid_map (s, rs); 54 __le32 *map = objectid_map(s, rs);
56 __u32 unused_objectid; 55 __u32 unused_objectid;
57 56
58 BUG_ON (!th->t_trans_id); 57 BUG_ON(!th->t_trans_id);
58
59 check_objectid_map(s, map);
60
61 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
62 /* comment needed -Hans */
63 unused_objectid = le32_to_cpu(map[1]);
64 if (unused_objectid == U32_MAX) {
65 reiserfs_warning(s, "%s: no more object ids", __FUNCTION__);
66 reiserfs_restore_prepared_buffer(s, SB_BUFFER_WITH_SB(s));
67 return 0;
68 }
59 69
60 check_objectid_map (s, map); 70 /* This incrementation allocates the first unused objectid. That
71 is to say, the first entry on the objectid map is the first
72 unused objectid, and by incrementing it we use it. See below
73 where we check to see if we eliminated a sequence of unused
74 objectids.... */
75 map[1] = cpu_to_le32(unused_objectid + 1);
76
77 /* Now we check to see if we eliminated the last remaining member of
78 the first even sequence (and can eliminate the sequence by
79 eliminating its last objectid from oids), and can collapse the
80 first two odd sequences into one sequence. If so, then the net
81 result is to eliminate a pair of objectids from oids. We do this
82 by shifting the entire map to the left. */
83 if (sb_oid_cursize(rs) > 2 && map[1] == map[2]) {
84 memmove(map + 1, map + 3,
85 (sb_oid_cursize(rs) - 3) * sizeof(__u32));
86 set_sb_oid_cursize(rs, sb_oid_cursize(rs) - 2);
87 }
61 88
62 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ; 89 journal_mark_dirty(th, s, SB_BUFFER_WITH_SB(s));
63 /* comment needed -Hans */ 90 return unused_objectid;
64 unused_objectid = le32_to_cpu (map[1]);
65 if (unused_objectid == U32_MAX) {
66 reiserfs_warning (s, "%s: no more object ids", __FUNCTION__);
67 reiserfs_restore_prepared_buffer(s, SB_BUFFER_WITH_SB(s)) ;
68 return 0;
69 }
70
71 /* This incrementation allocates the first unused objectid. That
72 is to say, the first entry on the objectid map is the first
73 unused objectid, and by incrementing it we use it. See below
74 where we check to see if we eliminated a sequence of unused
75 objectids.... */
76 map[1] = cpu_to_le32 (unused_objectid + 1);
77
78 /* Now we check to see if we eliminated the last remaining member of
79 the first even sequence (and can eliminate the sequence by
80 eliminating its last objectid from oids), and can collapse the
81 first two odd sequences into one sequence. If so, then the net
82 result is to eliminate a pair of objectids from oids. We do this
83 by shifting the entire map to the left. */
84 if (sb_oid_cursize(rs) > 2 && map[1] == map[2]) {
85 memmove (map + 1, map + 3, (sb_oid_cursize(rs) - 3) * sizeof(__u32));
86 set_sb_oid_cursize( rs, sb_oid_cursize(rs) - 2 );
87 }
88
89 journal_mark_dirty(th, s, SB_BUFFER_WITH_SB (s));
90 return unused_objectid;
91} 91}
92 92
93
94/* makes object identifier unused */ 93/* makes object identifier unused */
95void reiserfs_release_objectid (struct reiserfs_transaction_handle *th, 94void reiserfs_release_objectid(struct reiserfs_transaction_handle *th,
96 __u32 objectid_to_release) 95 __u32 objectid_to_release)
97{ 96{
98 struct super_block * s = th->t_super; 97 struct super_block *s = th->t_super;
99 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s); 98 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
100 __le32 * map = objectid_map (s, rs); 99 __le32 *map = objectid_map(s, rs);
101 int i = 0; 100 int i = 0;
102 101
103 BUG_ON (!th->t_trans_id); 102 BUG_ON(!th->t_trans_id);
104 //return; 103 //return;
105 check_objectid_map (s, map); 104 check_objectid_map(s, map);
106 105
107 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ; 106 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
108 journal_mark_dirty(th, s, SB_BUFFER_WITH_SB (s)); 107 journal_mark_dirty(th, s, SB_BUFFER_WITH_SB(s));
109 108
110 /* start at the beginning of the objectid map (i = 0) and go to 109 /* start at the beginning of the objectid map (i = 0) and go to
111 the end of it (i = disk_sb->s_oid_cursize). Linear search is 110 the end of it (i = disk_sb->s_oid_cursize). Linear search is
112 what we use, though it is possible that binary search would be 111 what we use, though it is possible that binary search would be
113 more efficient after performing lots of deletions (which is 112 more efficient after performing lots of deletions (which is
114 when oids is large.) We only check even i's. */ 113 when oids is large.) We only check even i's. */
115 while (i < sb_oid_cursize(rs)) { 114 while (i < sb_oid_cursize(rs)) {
116 if (objectid_to_release == le32_to_cpu (map[i])) { 115 if (objectid_to_release == le32_to_cpu(map[i])) {
117 /* This incrementation unallocates the objectid. */ 116 /* This incrementation unallocates the objectid. */
118 //map[i]++; 117 //map[i]++;
119 map[i] = cpu_to_le32 (le32_to_cpu (map[i]) + 1); 118 map[i] = cpu_to_le32(le32_to_cpu(map[i]) + 1);
120 119
121 /* Did we unallocate the last member of an odd sequence, and can shrink oids? */ 120 /* Did we unallocate the last member of an odd sequence, and can shrink oids? */
122 if (map[i] == map[i+1]) { 121 if (map[i] == map[i + 1]) {
123 /* shrink objectid map */ 122 /* shrink objectid map */
124 memmove (map + i, map + i + 2, 123 memmove(map + i, map + i + 2,
125 (sb_oid_cursize(rs) - i - 2) * sizeof (__u32)); 124 (sb_oid_cursize(rs) - i -
126 //disk_sb->s_oid_cursize -= 2; 125 2) * sizeof(__u32));
127 set_sb_oid_cursize( rs, sb_oid_cursize(rs) - 2 ); 126 //disk_sb->s_oid_cursize -= 2;
128 127 set_sb_oid_cursize(rs, sb_oid_cursize(rs) - 2);
129 RFALSE( sb_oid_cursize(rs) < 2 || 128
130 sb_oid_cursize(rs) > sb_oid_maxsize(rs), 129 RFALSE(sb_oid_cursize(rs) < 2 ||
131 "vs-15005: objectid map corrupted cur_size == %d (max == %d)", 130 sb_oid_cursize(rs) > sb_oid_maxsize(rs),
132 sb_oid_cursize(rs), sb_oid_maxsize(rs)); 131 "vs-15005: objectid map corrupted cur_size == %d (max == %d)",
133 } 132 sb_oid_cursize(rs), sb_oid_maxsize(rs));
134 return; 133 }
134 return;
135 }
136
137 if (objectid_to_release > le32_to_cpu(map[i]) &&
138 objectid_to_release < le32_to_cpu(map[i + 1])) {
139 /* size of objectid map is not changed */
140 if (objectid_to_release + 1 == le32_to_cpu(map[i + 1])) {
141 //objectid_map[i+1]--;
142 map[i + 1] =
143 cpu_to_le32(le32_to_cpu(map[i + 1]) - 1);
144 return;
145 }
146
147 /* JDM comparing two little-endian values for equality -- safe */
148 if (sb_oid_cursize(rs) == sb_oid_maxsize(rs)) {
149 /* objectid map must be expanded, but there is no space */
150 PROC_INFO_INC(s, leaked_oid);
151 return;
152 }
153
154 /* expand the objectid map */
155 memmove(map + i + 3, map + i + 1,
156 (sb_oid_cursize(rs) - i - 1) * sizeof(__u32));
157 map[i + 1] = cpu_to_le32(objectid_to_release);
158 map[i + 2] = cpu_to_le32(objectid_to_release + 1);
159 set_sb_oid_cursize(rs, sb_oid_cursize(rs) + 2);
160 return;
161 }
162 i += 2;
135 } 163 }
136 164
137 if (objectid_to_release > le32_to_cpu (map[i]) && 165 reiserfs_warning(s,
138 objectid_to_release < le32_to_cpu (map[i + 1])) { 166 "vs-15011: reiserfs_release_objectid: tried to free free object id (%lu)",
139 /* size of objectid map is not changed */ 167 (long unsigned)objectid_to_release);
140 if (objectid_to_release + 1 == le32_to_cpu (map[i + 1])) { 168}
141 //objectid_map[i+1]--;
142 map[i + 1] = cpu_to_le32 (le32_to_cpu (map[i + 1]) - 1);
143 return;
144 }
145
146 /* JDM comparing two little-endian values for equality -- safe */
147 if (sb_oid_cursize(rs) == sb_oid_maxsize(rs)) {
148 /* objectid map must be expanded, but there is no space */
149 PROC_INFO_INC( s, leaked_oid );
150 return;
151 }
152 169
153 /* expand the objectid map*/ 170int reiserfs_convert_objectid_map_v1(struct super_block *s)
154 memmove (map + i + 3, map + i + 1, 171{
155 (sb_oid_cursize(rs) - i - 1) * sizeof(__u32)); 172 struct reiserfs_super_block *disk_sb = SB_DISK_SUPER_BLOCK(s);
156 map[i + 1] = cpu_to_le32 (objectid_to_release); 173 int cur_size = sb_oid_cursize(disk_sb);
157 map[i + 2] = cpu_to_le32 (objectid_to_release + 1); 174 int new_size = (s->s_blocksize - SB_SIZE) / sizeof(__u32) / 2 * 2;
158 set_sb_oid_cursize( rs, sb_oid_cursize(rs) + 2 ); 175 int old_max = sb_oid_maxsize(disk_sb);
159 return; 176 struct reiserfs_super_block_v1 *disk_sb_v1;
177 __le32 *objectid_map, *new_objectid_map;
178 int i;
179
180 disk_sb_v1 =
181 (struct reiserfs_super_block_v1 *)(SB_BUFFER_WITH_SB(s)->b_data);
182 objectid_map = (__le32 *) (disk_sb_v1 + 1);
183 new_objectid_map = (__le32 *) (disk_sb + 1);
184
185 if (cur_size > new_size) {
186 /* mark everyone used that was listed as free at the end of the objectid
187 ** map
188 */
189 objectid_map[new_size - 1] = objectid_map[cur_size - 1];
190 set_sb_oid_cursize(disk_sb, new_size);
191 }
192 /* move the smaller objectid map past the end of the new super */
193 for (i = new_size - 1; i >= 0; i--) {
194 objectid_map[i + (old_max - new_size)] = objectid_map[i];
160 } 195 }
161 i += 2;
162 }
163 196
164 reiserfs_warning (s, "vs-15011: reiserfs_release_objectid: tried to free free object id (%lu)", 197 /* set the max size so we don't overflow later */
165 ( long unsigned ) objectid_to_release); 198 set_sb_oid_maxsize(disk_sb, new_size);
166}
167 199
200 /* Zero out label and generate random UUID */
201 memset(disk_sb->s_label, 0, sizeof(disk_sb->s_label));
202 generate_random_uuid(disk_sb->s_uuid);
168 203
169int reiserfs_convert_objectid_map_v1(struct super_block *s) { 204 /* finally, zero out the unused chunk of the new super */
170 struct reiserfs_super_block *disk_sb = SB_DISK_SUPER_BLOCK (s); 205 memset(disk_sb->s_unused, 0, sizeof(disk_sb->s_unused));
171 int cur_size = sb_oid_cursize(disk_sb); 206 return 0;
172 int new_size = (s->s_blocksize - SB_SIZE) / sizeof(__u32) / 2 * 2 ;
173 int old_max = sb_oid_maxsize(disk_sb);
174 struct reiserfs_super_block_v1 *disk_sb_v1 ;
175 __le32 *objectid_map, *new_objectid_map ;
176 int i ;
177
178 disk_sb_v1=(struct reiserfs_super_block_v1 *)(SB_BUFFER_WITH_SB(s)->b_data);
179 objectid_map = (__le32 *)(disk_sb_v1 + 1) ;
180 new_objectid_map = (__le32 *)(disk_sb + 1) ;
181
182 if (cur_size > new_size) {
183 /* mark everyone used that was listed as free at the end of the objectid
184 ** map
185 */
186 objectid_map[new_size - 1] = objectid_map[cur_size - 1] ;
187 set_sb_oid_cursize(disk_sb,new_size) ;
188 }
189 /* move the smaller objectid map past the end of the new super */
190 for (i = new_size - 1 ; i >= 0 ; i--) {
191 objectid_map[i + (old_max - new_size)] = objectid_map[i] ;
192 }
193
194
195 /* set the max size so we don't overflow later */
196 set_sb_oid_maxsize(disk_sb,new_size) ;
197
198 /* Zero out label and generate random UUID */
199 memset(disk_sb->s_label, 0, sizeof(disk_sb->s_label)) ;
200 generate_random_uuid(disk_sb->s_uuid);
201
202 /* finally, zero out the unused chunk of the new super */
203 memset(disk_sb->s_unused, 0, sizeof(disk_sb->s_unused)) ;
204 return 0 ;
205} 207}
206