aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/stree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/reiserfs/stree.c')
-rw-r--r--fs/reiserfs/stree.c3369
1 files changed, 1743 insertions, 1626 deletions
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
index 63158491e152..e2d08d7bcffc 100644
--- a/fs/reiserfs/stree.c
+++ b/fs/reiserfs/stree.c
@@ -59,46 +59,45 @@
59#include <linux/quotaops.h> 59#include <linux/quotaops.h>
60 60
61/* Does the buffer contain a disk block which is in the tree. */ 61/* Does the buffer contain a disk block which is in the tree. */
62inline int B_IS_IN_TREE (const struct buffer_head * p_s_bh) 62inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
63{ 63{
64 64
65 RFALSE( B_LEVEL (p_s_bh) > MAX_HEIGHT, 65 RFALSE(B_LEVEL(p_s_bh) > MAX_HEIGHT,
66 "PAP-1010: block (%b) has too big level (%z)", p_s_bh, p_s_bh); 66 "PAP-1010: block (%b) has too big level (%z)", p_s_bh, p_s_bh);
67 67
68 return ( B_LEVEL (p_s_bh) != FREE_LEVEL ); 68 return (B_LEVEL(p_s_bh) != FREE_LEVEL);
69} 69}
70 70
71// 71//
72// to gets item head in le form 72// to gets item head in le form
73// 73//
74inline void copy_item_head(struct item_head * p_v_to, 74inline void copy_item_head(struct item_head *p_v_to,
75 const struct item_head * p_v_from) 75 const struct item_head *p_v_from)
76{ 76{
77 memcpy (p_v_to, p_v_from, IH_SIZE); 77 memcpy(p_v_to, p_v_from, IH_SIZE);
78} 78}
79 79
80
81/* k1 is pointer to on-disk structure which is stored in little-endian 80/* k1 is pointer to on-disk structure which is stored in little-endian
82 form. k2 is pointer to cpu variable. For key of items of the same 81 form. k2 is pointer to cpu variable. For key of items of the same
83 object this returns 0. 82 object this returns 0.
84 Returns: -1 if key1 < key2 83 Returns: -1 if key1 < key2
85 0 if key1 == key2 84 0 if key1 == key2
86 1 if key1 > key2 */ 85 1 if key1 > key2 */
87inline int comp_short_keys (const struct reiserfs_key * le_key, 86inline int comp_short_keys(const struct reiserfs_key *le_key,
88 const struct cpu_key * cpu_key) 87 const struct cpu_key *cpu_key)
89{ 88{
90 __u32 n; 89 __u32 n;
91 n = le32_to_cpu(le_key->k_dir_id); 90 n = le32_to_cpu(le_key->k_dir_id);
92 if (n < cpu_key->on_disk_key.k_dir_id) 91 if (n < cpu_key->on_disk_key.k_dir_id)
93 return -1; 92 return -1;
94 if (n > cpu_key->on_disk_key.k_dir_id) 93 if (n > cpu_key->on_disk_key.k_dir_id)
95 return 1; 94 return 1;
96 n = le32_to_cpu(le_key->k_objectid); 95 n = le32_to_cpu(le_key->k_objectid);
97 if (n < cpu_key->on_disk_key.k_objectid) 96 if (n < cpu_key->on_disk_key.k_objectid)
98 return -1; 97 return -1;
99 if (n > cpu_key->on_disk_key.k_objectid) 98 if (n > cpu_key->on_disk_key.k_objectid)
100 return 1; 99 return 1;
101 return 0; 100 return 0;
102} 101}
103 102
104/* k1 is pointer to on-disk structure which is stored in little-endian 103/* k1 is pointer to on-disk structure which is stored in little-endian
@@ -106,68 +105,72 @@ inline int comp_short_keys (const struct reiserfs_key * le_key,
106 Compare keys using all 4 key fields. 105 Compare keys using all 4 key fields.
107 Returns: -1 if key1 < key2 0 106 Returns: -1 if key1 < key2 0
108 if key1 = key2 1 if key1 > key2 */ 107 if key1 = key2 1 if key1 > key2 */
109static inline int comp_keys (const struct reiserfs_key * le_key, const struct cpu_key * cpu_key) 108static inline int comp_keys(const struct reiserfs_key *le_key,
109 const struct cpu_key *cpu_key)
110{ 110{
111 int retval; 111 int retval;
112 112
113 retval = comp_short_keys (le_key, cpu_key); 113 retval = comp_short_keys(le_key, cpu_key);
114 if (retval) 114 if (retval)
115 return retval; 115 return retval;
116 if (le_key_k_offset (le_key_version(le_key), le_key) < cpu_key_k_offset (cpu_key)) 116 if (le_key_k_offset(le_key_version(le_key), le_key) <
117 return -1; 117 cpu_key_k_offset(cpu_key))
118 if (le_key_k_offset (le_key_version(le_key), le_key) > cpu_key_k_offset (cpu_key)) 118 return -1;
119 return 1; 119 if (le_key_k_offset(le_key_version(le_key), le_key) >
120 120 cpu_key_k_offset(cpu_key))
121 if (cpu_key->key_length == 3) 121 return 1;
122 return 0; 122
123 123 if (cpu_key->key_length == 3)
124 /* this part is needed only when tail conversion is in progress */ 124 return 0;
125 if (le_key_k_type (le_key_version(le_key), le_key) < cpu_key_k_type (cpu_key)) 125
126 return -1; 126 /* this part is needed only when tail conversion is in progress */
127 if (le_key_k_type(le_key_version(le_key), le_key) <
128 cpu_key_k_type(cpu_key))
129 return -1;
130
131 if (le_key_k_type(le_key_version(le_key), le_key) >
132 cpu_key_k_type(cpu_key))
133 return 1;
127 134
128 if (le_key_k_type (le_key_version(le_key), le_key) > cpu_key_k_type (cpu_key)) 135 return 0;
129 return 1;
130
131 return 0;
132} 136}
133 137
134 138inline int comp_short_le_keys(const struct reiserfs_key *key1,
135inline int comp_short_le_keys (const struct reiserfs_key * key1, const struct reiserfs_key * key2) 139 const struct reiserfs_key *key2)
136{ 140{
137 __u32 * p_s_1_u32, * p_s_2_u32; 141 __u32 *p_s_1_u32, *p_s_2_u32;
138 int n_key_length = REISERFS_SHORT_KEY_LEN; 142 int n_key_length = REISERFS_SHORT_KEY_LEN;
139 143
140 p_s_1_u32 = (__u32 *)key1; 144 p_s_1_u32 = (__u32 *) key1;
141 p_s_2_u32 = (__u32 *)key2; 145 p_s_2_u32 = (__u32 *) key2;
142 for( ; n_key_length--; ++p_s_1_u32, ++p_s_2_u32 ) { 146 for (; n_key_length--; ++p_s_1_u32, ++p_s_2_u32) {
143 if ( le32_to_cpu (*p_s_1_u32) < le32_to_cpu (*p_s_2_u32) ) 147 if (le32_to_cpu(*p_s_1_u32) < le32_to_cpu(*p_s_2_u32))
144 return -1; 148 return -1;
145 if ( le32_to_cpu (*p_s_1_u32) > le32_to_cpu (*p_s_2_u32) ) 149 if (le32_to_cpu(*p_s_1_u32) > le32_to_cpu(*p_s_2_u32))
146 return 1; 150 return 1;
147 } 151 }
148 return 0; 152 return 0;
149} 153}
150 154
151inline void le_key2cpu_key (struct cpu_key * to, const struct reiserfs_key * from) 155inline void le_key2cpu_key(struct cpu_key *to, const struct reiserfs_key *from)
152{ 156{
153 int version; 157 int version;
154 to->on_disk_key.k_dir_id = le32_to_cpu (from->k_dir_id); 158 to->on_disk_key.k_dir_id = le32_to_cpu(from->k_dir_id);
155 to->on_disk_key.k_objectid = le32_to_cpu (from->k_objectid); 159 to->on_disk_key.k_objectid = le32_to_cpu(from->k_objectid);
156 160
157 // find out version of the key 161 // find out version of the key
158 version = le_key_version (from); 162 version = le_key_version(from);
159 to->version = version; 163 to->version = version;
160 to->on_disk_key.k_offset = le_key_k_offset(version, from); 164 to->on_disk_key.k_offset = le_key_k_offset(version, from);
161 to->on_disk_key.k_type = le_key_k_type(version, from); 165 to->on_disk_key.k_type = le_key_k_type(version, from);
162} 166}
163 167
164
165
166// this does not say which one is bigger, it only returns 1 if keys 168// this does not say which one is bigger, it only returns 1 if keys
167// are not equal, 0 otherwise 169// are not equal, 0 otherwise
168inline int comp_le_keys (const struct reiserfs_key * k1, const struct reiserfs_key * k2) 170inline int comp_le_keys(const struct reiserfs_key *k1,
171 const struct reiserfs_key *k2)
169{ 172{
170 return memcmp (k1, k2, sizeof (struct reiserfs_key)); 173 return memcmp(k1, k2, sizeof(struct reiserfs_key));
171} 174}
172 175
173/************************************************************************** 176/**************************************************************************
@@ -184,373 +187,396 @@ inline int comp_le_keys (const struct reiserfs_key * k1, const struct reiserfs_k
184 there are no possible items, and we have not found it. With each examination we 187 there are no possible items, and we have not found it. With each examination we
185 cut the number of possible items it could be by one more than half rounded down, 188 cut the number of possible items it could be by one more than half rounded down,
186 or we find it. */ 189 or we find it. */
187static inline int bin_search ( 190static inline int bin_search(const void *p_v_key, /* Key to search for. */
188 const void * p_v_key, /* Key to search for. */ 191 const void *p_v_base, /* First item in the array. */
189 const void * p_v_base,/* First item in the array. */ 192 int p_n_num, /* Number of items in the array. */
190 int p_n_num, /* Number of items in the array. */ 193 int p_n_width, /* Item size in the array.
191 int p_n_width, /* Item size in the array. 194 searched. Lest the reader be
192 searched. Lest the reader be 195 confused, note that this is crafted
193 confused, note that this is crafted 196 as a general function, and when it
194 as a general function, and when it 197 is applied specifically to the array
195 is applied specifically to the array 198 of item headers in a node, p_n_width
196 of item headers in a node, p_n_width 199 is actually the item header size not
197 is actually the item header size not 200 the item size. */
198 the item size. */ 201 int *p_n_pos /* Number of the searched for element. */
199 int * p_n_pos /* Number of the searched for element. */ 202 )
200 ) { 203{
201 int n_rbound, n_lbound, n_j; 204 int n_rbound, n_lbound, n_j;
202 205
203 for ( n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0))/2; n_lbound <= n_rbound; n_j = (n_rbound + n_lbound)/2 ) 206 for (n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0)) / 2;
204 switch( comp_keys((struct reiserfs_key *)((char * )p_v_base + n_j * p_n_width), (struct cpu_key *)p_v_key) ) { 207 n_lbound <= n_rbound; n_j = (n_rbound + n_lbound) / 2)
205 case -1: n_lbound = n_j + 1; continue; 208 switch (comp_keys
206 case 1: n_rbound = n_j - 1; continue; 209 ((struct reiserfs_key *)((char *)p_v_base +
207 case 0: *p_n_pos = n_j; return ITEM_FOUND; /* Key found in the array. */ 210 n_j * p_n_width),
208 } 211 (struct cpu_key *)p_v_key)) {
209 212 case -1:
210 /* bin_search did not find given key, it returns position of key, 213 n_lbound = n_j + 1;
211 that is minimal and greater than the given one. */ 214 continue;
212 *p_n_pos = n_lbound; 215 case 1:
213 return ITEM_NOT_FOUND; 216 n_rbound = n_j - 1;
217 continue;
218 case 0:
219 *p_n_pos = n_j;
220 return ITEM_FOUND; /* Key found in the array. */
221 }
222
223 /* bin_search did not find given key, it returns position of key,
224 that is minimal and greater than the given one. */
225 *p_n_pos = n_lbound;
226 return ITEM_NOT_FOUND;
214} 227}
215 228
216#ifdef CONFIG_REISERFS_CHECK 229#ifdef CONFIG_REISERFS_CHECK
217extern struct tree_balance * cur_tb; 230extern struct tree_balance *cur_tb;
218#endif 231#endif
219 232
220
221
222/* Minimal possible key. It is never in the tree. */ 233/* Minimal possible key. It is never in the tree. */
223const struct reiserfs_key MIN_KEY = {0, 0, {{0, 0},}}; 234const struct reiserfs_key MIN_KEY = { 0, 0, {{0, 0},} };
224 235
225/* Maximal possible key. It is never in the tree. */ 236/* Maximal possible key. It is never in the tree. */
226static const struct reiserfs_key MAX_KEY = { 237static const struct reiserfs_key MAX_KEY = {
227 __constant_cpu_to_le32(0xffffffff), 238 __constant_cpu_to_le32(0xffffffff),
228 __constant_cpu_to_le32(0xffffffff), 239 __constant_cpu_to_le32(0xffffffff),
229 {{__constant_cpu_to_le32(0xffffffff), 240 {{__constant_cpu_to_le32(0xffffffff),
230 __constant_cpu_to_le32(0xffffffff)},} 241 __constant_cpu_to_le32(0xffffffff)},}
231}; 242};
232 243
233
234/* Get delimiting key of the buffer by looking for it in the buffers in the path, starting from the bottom 244/* Get delimiting key of the buffer by looking for it in the buffers in the path, starting from the bottom
235 of the path, and going upwards. We must check the path's validity at each step. If the key is not in 245 of the path, and going upwards. We must check the path's validity at each step. If the key is not in
236 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this 246 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this
237 case we return a special key, either MIN_KEY or MAX_KEY. */ 247 case we return a special key, either MIN_KEY or MAX_KEY. */
238static inline const struct reiserfs_key * get_lkey ( 248static inline const struct reiserfs_key *get_lkey(const struct path
239 const struct path * p_s_chk_path, 249 *p_s_chk_path,
240 const struct super_block * p_s_sb 250 const struct super_block
241 ) { 251 *p_s_sb)
242 int n_position, n_path_offset = p_s_chk_path->path_length; 252{
243 struct buffer_head * p_s_parent; 253 int n_position, n_path_offset = p_s_chk_path->path_length;
244 254 struct buffer_head *p_s_parent;
245 RFALSE( n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 255
246 "PAP-5010: invalid offset in the path"); 256 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET,
247 257 "PAP-5010: invalid offset in the path");
248 /* While not higher in path than first element. */ 258
249 while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) { 259 /* While not higher in path than first element. */
250 260 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
251 RFALSE( ! buffer_uptodate(PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)), 261
252 "PAP-5020: parent is not uptodate"); 262 RFALSE(!buffer_uptodate
253 263 (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)),
254 /* Parent at the path is not in the tree now. */ 264 "PAP-5020: parent is not uptodate");
255 if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) ) 265
256 return &MAX_KEY; 266 /* Parent at the path is not in the tree now. */
257 /* Check whether position in the parent is correct. */ 267 if (!B_IS_IN_TREE
258 if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) ) 268 (p_s_parent =
259 return &MAX_KEY; 269 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)))
260 /* Check whether parent at the path really points to the child. */ 270 return &MAX_KEY;
261 if ( B_N_CHILD_NUM(p_s_parent, n_position) != 271 /* Check whether position in the parent is correct. */
262 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr ) 272 if ((n_position =
263 return &MAX_KEY; 273 PATH_OFFSET_POSITION(p_s_chk_path,
264 /* Return delimiting key if position in the parent is not equal to zero. */ 274 n_path_offset)) >
265 if ( n_position ) 275 B_NR_ITEMS(p_s_parent))
266 return B_N_PDELIM_KEY(p_s_parent, n_position - 1); 276 return &MAX_KEY;
267 } 277 /* Check whether parent at the path really points to the child. */
268 /* Return MIN_KEY if we are in the root of the buffer tree. */ 278 if (B_N_CHILD_NUM(p_s_parent, n_position) !=
269 if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr == 279 PATH_OFFSET_PBUFFER(p_s_chk_path,
270 SB_ROOT_BLOCK (p_s_sb) ) 280 n_path_offset + 1)->b_blocknr)
271 return &MIN_KEY; 281 return &MAX_KEY;
272 return &MAX_KEY; 282 /* Return delimiting key if position in the parent is not equal to zero. */
283 if (n_position)
284 return B_N_PDELIM_KEY(p_s_parent, n_position - 1);
285 }
286 /* Return MIN_KEY if we are in the root of the buffer tree. */
287 if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->
288 b_blocknr == SB_ROOT_BLOCK(p_s_sb))
289 return &MIN_KEY;
290 return &MAX_KEY;
273} 291}
274 292
275
276/* Get delimiting key of the buffer at the path and its right neighbor. */ 293/* Get delimiting key of the buffer at the path and its right neighbor. */
277inline const struct reiserfs_key * get_rkey ( 294inline const struct reiserfs_key *get_rkey(const struct path *p_s_chk_path,
278 const struct path * p_s_chk_path, 295 const struct super_block *p_s_sb)
279 const struct super_block * p_s_sb 296{
280 ) { 297 int n_position, n_path_offset = p_s_chk_path->path_length;
281 int n_position, 298 struct buffer_head *p_s_parent;
282 n_path_offset = p_s_chk_path->path_length; 299
283 struct buffer_head * p_s_parent; 300 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET,
284 301 "PAP-5030: invalid offset in the path");
285 RFALSE( n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 302
286 "PAP-5030: invalid offset in the path"); 303 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
287 304
288 while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) { 305 RFALSE(!buffer_uptodate
289 306 (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)),
290 RFALSE( ! buffer_uptodate(PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)), 307 "PAP-5040: parent is not uptodate");
291 "PAP-5040: parent is not uptodate"); 308
292 309 /* Parent at the path is not in the tree now. */
293 /* Parent at the path is not in the tree now. */ 310 if (!B_IS_IN_TREE
294 if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) ) 311 (p_s_parent =
295 return &MIN_KEY; 312 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)))
296 /* Check whether position in the parent is correct. */ 313 return &MIN_KEY;
297 if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) ) 314 /* Check whether position in the parent is correct. */
298 return &MIN_KEY; 315 if ((n_position =
299 /* Check whether parent at the path really points to the child. */ 316 PATH_OFFSET_POSITION(p_s_chk_path,
300 if ( B_N_CHILD_NUM(p_s_parent, n_position) != 317 n_path_offset)) >
301 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr ) 318 B_NR_ITEMS(p_s_parent))
302 return &MIN_KEY; 319 return &MIN_KEY;
303 /* Return delimiting key if position in the parent is not the last one. */ 320 /* Check whether parent at the path really points to the child. */
304 if ( n_position != B_NR_ITEMS(p_s_parent) ) 321 if (B_N_CHILD_NUM(p_s_parent, n_position) !=
305 return B_N_PDELIM_KEY(p_s_parent, n_position); 322 PATH_OFFSET_PBUFFER(p_s_chk_path,
306 } 323 n_path_offset + 1)->b_blocknr)
307 /* Return MAX_KEY if we are in the root of the buffer tree. */ 324 return &MIN_KEY;
308 if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr == 325 /* Return delimiting key if position in the parent is not the last one. */
309 SB_ROOT_BLOCK (p_s_sb) ) 326 if (n_position != B_NR_ITEMS(p_s_parent))
310 return &MAX_KEY; 327 return B_N_PDELIM_KEY(p_s_parent, n_position);
311 return &MIN_KEY; 328 }
329 /* Return MAX_KEY if we are in the root of the buffer tree. */
330 if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->
331 b_blocknr == SB_ROOT_BLOCK(p_s_sb))
332 return &MAX_KEY;
333 return &MIN_KEY;
312} 334}
313 335
314
315/* Check whether a key is contained in the tree rooted from a buffer at a path. */ 336/* Check whether a key is contained in the tree rooted from a buffer at a path. */
316/* This works by looking at the left and right delimiting keys for the buffer in the last path_element in 337/* This works by looking at the left and right delimiting keys for the buffer in the last path_element in
317 the path. These delimiting keys are stored at least one level above that buffer in the tree. If the 338 the path. These delimiting keys are stored at least one level above that buffer in the tree. If the
318 buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in 339 buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in
319 this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */ 340 this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */
320static inline int key_in_buffer ( 341static inline int key_in_buffer(struct path *p_s_chk_path, /* Path which should be checked. */
321 struct path * p_s_chk_path, /* Path which should be checked. */ 342 const struct cpu_key *p_s_key, /* Key which should be checked. */
322 const struct cpu_key * p_s_key, /* Key which should be checked. */ 343 struct super_block *p_s_sb /* Super block pointer. */
323 struct super_block * p_s_sb /* Super block pointer. */ 344 )
324 ) { 345{
325
326 RFALSE( ! p_s_key || p_s_chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET ||
327 p_s_chk_path->path_length > MAX_HEIGHT,
328 "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)",
329 p_s_key, p_s_chk_path->path_length);
330 RFALSE( !PATH_PLAST_BUFFER(p_s_chk_path)->b_bdev,
331 "PAP-5060: device must not be NODEV");
332
333 if ( comp_keys(get_lkey(p_s_chk_path, p_s_sb), p_s_key) == 1 )
334 /* left delimiting key is bigger, that the key we look for */
335 return 0;
336 // if ( comp_keys(p_s_key, get_rkey(p_s_chk_path, p_s_sb)) != -1 )
337 if ( comp_keys(get_rkey(p_s_chk_path, p_s_sb), p_s_key) != 1 )
338 /* p_s_key must be less than right delimitiing key */
339 return 0;
340 return 1;
341}
342
343 346
344inline void decrement_bcount( 347 RFALSE(!p_s_key || p_s_chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET
345 struct buffer_head * p_s_bh 348 || p_s_chk_path->path_length > MAX_HEIGHT,
346 ) { 349 "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)",
347 if ( p_s_bh ) { 350 p_s_key, p_s_chk_path->path_length);
348 if ( atomic_read (&(p_s_bh->b_count)) ) { 351 RFALSE(!PATH_PLAST_BUFFER(p_s_chk_path)->b_bdev,
349 put_bh(p_s_bh) ; 352 "PAP-5060: device must not be NODEV");
350 return; 353
351 } 354 if (comp_keys(get_lkey(p_s_chk_path, p_s_sb), p_s_key) == 1)
352 reiserfs_panic(NULL, "PAP-5070: decrement_bcount: trying to free free buffer %b", p_s_bh); 355 /* left delimiting key is bigger, that the key we look for */
353 } 356 return 0;
357 // if ( comp_keys(p_s_key, get_rkey(p_s_chk_path, p_s_sb)) != -1 )
358 if (comp_keys(get_rkey(p_s_chk_path, p_s_sb), p_s_key) != 1)
359 /* p_s_key must be less than right delimitiing key */
360 return 0;
361 return 1;
354} 362}
355 363
364inline void decrement_bcount(struct buffer_head *p_s_bh)
365{
366 if (p_s_bh) {
367 if (atomic_read(&(p_s_bh->b_count))) {
368 put_bh(p_s_bh);
369 return;
370 }
371 reiserfs_panic(NULL,
372 "PAP-5070: decrement_bcount: trying to free free buffer %b",
373 p_s_bh);
374 }
375}
356 376
357/* Decrement b_count field of the all buffers in the path. */ 377/* Decrement b_count field of the all buffers in the path. */
358void decrement_counters_in_path ( 378void decrement_counters_in_path(struct path *p_s_search_path)
359 struct path * p_s_search_path 379{
360 ) { 380 int n_path_offset = p_s_search_path->path_length;
361 int n_path_offset = p_s_search_path->path_length; 381
362 382 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET ||
363 RFALSE( n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET || 383 n_path_offset > EXTENDED_MAX_HEIGHT - 1,
364 n_path_offset > EXTENDED_MAX_HEIGHT - 1, 384 "PAP-5080: invalid path offset of %d", n_path_offset);
365 "PAP-5080: invalid path offset of %d", n_path_offset);
366
367 while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET ) {
368 struct buffer_head * bh;
369
370 bh = PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--);
371 decrement_bcount (bh);
372 }
373 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
374}
375 385
386 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
387 struct buffer_head *bh;
376 388
377int reiserfs_check_path(struct path *p) { 389 bh = PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--);
378 RFALSE( p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET, 390 decrement_bcount(bh);
379 "path not properly relsed") ; 391 }
380 return 0 ; 392 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
381} 393}
382 394
395int reiserfs_check_path(struct path *p)
396{
397 RFALSE(p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET,
398 "path not properly relsed");
399 return 0;
400}
383 401
384/* Release all buffers in the path. Restore dirty bits clean 402/* Release all buffers in the path. Restore dirty bits clean
385** when preparing the buffer for the log 403** when preparing the buffer for the log
386** 404**
387** only called from fix_nodes() 405** only called from fix_nodes()
388*/ 406*/
389void pathrelse_and_restore ( 407void pathrelse_and_restore(struct super_block *s, struct path *p_s_search_path)
390 struct super_block *s, 408{
391 struct path * p_s_search_path 409 int n_path_offset = p_s_search_path->path_length;
392 ) { 410
393 int n_path_offset = p_s_search_path->path_length; 411 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
394 412 "clm-4000: invalid path offset");
395 RFALSE( n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, 413
396 "clm-4000: invalid path offset"); 414 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
397 415 reiserfs_restore_prepared_buffer(s,
398 while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET ) { 416 PATH_OFFSET_PBUFFER
399 reiserfs_restore_prepared_buffer(s, PATH_OFFSET_PBUFFER(p_s_search_path, 417 (p_s_search_path,
400 n_path_offset)); 418 n_path_offset));
401 brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--)); 419 brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
402 } 420 }
403 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; 421 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
404} 422}
405 423
406/* Release all buffers in the path. */ 424/* Release all buffers in the path. */
407void pathrelse ( 425void pathrelse(struct path *p_s_search_path)
408 struct path * p_s_search_path 426{
409 ) { 427 int n_path_offset = p_s_search_path->path_length;
410 int n_path_offset = p_s_search_path->path_length;
411
412 RFALSE( n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
413 "PAP-5090: invalid path offset");
414
415 while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET )
416 brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
417
418 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
419}
420 428
429 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
430 "PAP-5090: invalid path offset");
421 431
432 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET)
433 brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
422 434
423static int is_leaf (char * buf, int blocksize, struct buffer_head * bh) 435 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
424{ 436}
425 struct block_head * blkh;
426 struct item_head * ih;
427 int used_space;
428 int prev_location;
429 int i;
430 int nr;
431
432 blkh = (struct block_head *)buf;
433 if ( blkh_level(blkh) != DISK_LEAF_NODE_LEVEL) {
434 reiserfs_warning (NULL, "is_leaf: this should be caught earlier");
435 return 0;
436 }
437 437
438 nr = blkh_nr_item(blkh); 438static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
439 if (nr < 1 || nr > ((blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN))) { 439{
440 /* item number is too big or too small */ 440 struct block_head *blkh;
441 reiserfs_warning (NULL, "is_leaf: nr_item seems wrong: %z", bh); 441 struct item_head *ih;
442 return 0; 442 int used_space;
443 } 443 int prev_location;
444 ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1; 444 int i;
445 used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location (ih)); 445 int nr;
446 if (used_space != blocksize - blkh_free_space(blkh)) { 446
447 /* free space does not match to calculated amount of use space */ 447 blkh = (struct block_head *)buf;
448 reiserfs_warning (NULL, "is_leaf: free space seems wrong: %z", bh); 448 if (blkh_level(blkh) != DISK_LEAF_NODE_LEVEL) {
449 return 0; 449 reiserfs_warning(NULL,
450 } 450 "is_leaf: this should be caught earlier");
451 451 return 0;
452 // FIXME: it is_leaf will hit performance too much - we may have
453 // return 1 here
454
455 /* check tables of item heads */
456 ih = (struct item_head *)(buf + BLKH_SIZE);
457 prev_location = blocksize;
458 for (i = 0; i < nr; i ++, ih ++) {
459 if ( le_ih_k_type(ih) == TYPE_ANY) {
460 reiserfs_warning (NULL, "is_leaf: wrong item type for item %h",ih);
461 return 0;
462 } 452 }
463 if (ih_location (ih) >= blocksize || ih_location (ih) < IH_SIZE * nr) { 453
464 reiserfs_warning (NULL, "is_leaf: item location seems wrong: %h", ih); 454 nr = blkh_nr_item(blkh);
465 return 0; 455 if (nr < 1 || nr > ((blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN))) {
456 /* item number is too big or too small */
457 reiserfs_warning(NULL, "is_leaf: nr_item seems wrong: %z", bh);
458 return 0;
466 } 459 }
467 if (ih_item_len (ih) < 1 || ih_item_len (ih) > MAX_ITEM_LEN (blocksize)) { 460 ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1;
468 reiserfs_warning (NULL, "is_leaf: item length seems wrong: %h", ih); 461 used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location(ih));
469 return 0; 462 if (used_space != blocksize - blkh_free_space(blkh)) {
463 /* free space does not match to calculated amount of use space */
464 reiserfs_warning(NULL, "is_leaf: free space seems wrong: %z",
465 bh);
466 return 0;
470 } 467 }
471 if (prev_location - ih_location (ih) != ih_item_len (ih)) { 468 // FIXME: it is_leaf will hit performance too much - we may have
472 reiserfs_warning (NULL, "is_leaf: item location seems wrong (second one): %h", ih); 469 // return 1 here
473 return 0; 470
471 /* check tables of item heads */
472 ih = (struct item_head *)(buf + BLKH_SIZE);
473 prev_location = blocksize;
474 for (i = 0; i < nr; i++, ih++) {
475 if (le_ih_k_type(ih) == TYPE_ANY) {
476 reiserfs_warning(NULL,
477 "is_leaf: wrong item type for item %h",
478 ih);
479 return 0;
480 }
481 if (ih_location(ih) >= blocksize
482 || ih_location(ih) < IH_SIZE * nr) {
483 reiserfs_warning(NULL,
484 "is_leaf: item location seems wrong: %h",
485 ih);
486 return 0;
487 }
488 if (ih_item_len(ih) < 1
489 || ih_item_len(ih) > MAX_ITEM_LEN(blocksize)) {
490 reiserfs_warning(NULL,
491 "is_leaf: item length seems wrong: %h",
492 ih);
493 return 0;
494 }
495 if (prev_location - ih_location(ih) != ih_item_len(ih)) {
496 reiserfs_warning(NULL,
497 "is_leaf: item location seems wrong (second one): %h",
498 ih);
499 return 0;
500 }
501 prev_location = ih_location(ih);
474 } 502 }
475 prev_location = ih_location (ih);
476 }
477 503
478 // one may imagine much more checks 504 // one may imagine much more checks
479 return 1; 505 return 1;
480} 506}
481 507
482
483/* returns 1 if buf looks like an internal node, 0 otherwise */ 508/* returns 1 if buf looks like an internal node, 0 otherwise */
484static int is_internal (char * buf, int blocksize, struct buffer_head * bh) 509static int is_internal(char *buf, int blocksize, struct buffer_head *bh)
485{ 510{
486 struct block_head * blkh; 511 struct block_head *blkh;
487 int nr; 512 int nr;
488 int used_space; 513 int used_space;
489 514
490 blkh = (struct block_head *)buf; 515 blkh = (struct block_head *)buf;
491 nr = blkh_level(blkh); 516 nr = blkh_level(blkh);
492 if (nr <= DISK_LEAF_NODE_LEVEL || nr > MAX_HEIGHT) { 517 if (nr <= DISK_LEAF_NODE_LEVEL || nr > MAX_HEIGHT) {
493 /* this level is not possible for internal nodes */ 518 /* this level is not possible for internal nodes */
494 reiserfs_warning (NULL, "is_internal: this should be caught earlier"); 519 reiserfs_warning(NULL,
495 return 0; 520 "is_internal: this should be caught earlier");
496 } 521 return 0;
497 522 }
498 nr = blkh_nr_item(blkh);
499 if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) {
500 /* for internal which is not root we might check min number of keys */
501 reiserfs_warning (NULL, "is_internal: number of key seems wrong: %z", bh);
502 return 0;
503 }
504 523
505 used_space = BLKH_SIZE + KEY_SIZE * nr + DC_SIZE * (nr + 1); 524 nr = blkh_nr_item(blkh);
506 if (used_space != blocksize - blkh_free_space(blkh)) { 525 if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) {
507 reiserfs_warning (NULL, "is_internal: free space seems wrong: %z", bh); 526 /* for internal which is not root we might check min number of keys */
508 return 0; 527 reiserfs_warning(NULL,
509 } 528 "is_internal: number of key seems wrong: %z",
529 bh);
530 return 0;
531 }
510 532
511 // one may imagine much more checks 533 used_space = BLKH_SIZE + KEY_SIZE * nr + DC_SIZE * (nr + 1);
512 return 1; 534 if (used_space != blocksize - blkh_free_space(blkh)) {
535 reiserfs_warning(NULL,
536 "is_internal: free space seems wrong: %z", bh);
537 return 0;
538 }
539 // one may imagine much more checks
540 return 1;
513} 541}
514 542
515
516// make sure that bh contains formatted node of reiserfs tree of 543// make sure that bh contains formatted node of reiserfs tree of
517// 'level'-th level 544// 'level'-th level
518static int is_tree_node (struct buffer_head * bh, int level) 545static int is_tree_node(struct buffer_head *bh, int level)
519{ 546{
520 if (B_LEVEL (bh) != level) { 547 if (B_LEVEL(bh) != level) {
521 reiserfs_warning (NULL, "is_tree_node: node level %d does not match to the expected one %d", 548 reiserfs_warning(NULL,
522 B_LEVEL (bh), level); 549 "is_tree_node: node level %d does not match to the expected one %d",
523 return 0; 550 B_LEVEL(bh), level);
524 } 551 return 0;
525 if (level == DISK_LEAF_NODE_LEVEL) 552 }
526 return is_leaf (bh->b_data, bh->b_size, bh); 553 if (level == DISK_LEAF_NODE_LEVEL)
554 return is_leaf(bh->b_data, bh->b_size, bh);
527 555
528 return is_internal (bh->b_data, bh->b_size, bh); 556 return is_internal(bh->b_data, bh->b_size, bh);
529} 557}
530 558
531
532
533#define SEARCH_BY_KEY_READA 16 559#define SEARCH_BY_KEY_READA 16
534 560
535/* The function is NOT SCHEDULE-SAFE! */ 561/* The function is NOT SCHEDULE-SAFE! */
536static void search_by_key_reada (struct super_block * s, 562static void search_by_key_reada(struct super_block *s,
537 struct buffer_head **bh, 563 struct buffer_head **bh,
538 unsigned long *b, int num) 564 unsigned long *b, int num)
539{ 565{
540 int i,j; 566 int i, j;
541 567
542 for (i = 0 ; i < num ; i++) { 568 for (i = 0; i < num; i++) {
543 bh[i] = sb_getblk (s, b[i]); 569 bh[i] = sb_getblk(s, b[i]);
544 } 570 }
545 for (j = 0 ; j < i ; j++) { 571 for (j = 0; j < i; j++) {
546 /* 572 /*
547 * note, this needs attention if we are getting rid of the BKL 573 * note, this needs attention if we are getting rid of the BKL
548 * you have to make sure the prepared bit isn't set on this buffer 574 * you have to make sure the prepared bit isn't set on this buffer
549 */ 575 */
550 if (!buffer_uptodate(bh[j])) 576 if (!buffer_uptodate(bh[j]))
551 ll_rw_block(READA, 1, bh + j); 577 ll_rw_block(READA, 1, bh + j);
552 brelse(bh[j]); 578 brelse(bh[j]);
553 } 579 }
554} 580}
555 581
556/************************************************************************** 582/**************************************************************************
@@ -576,194 +602,200 @@ static void search_by_key_reada (struct super_block * s,
576 correctness of the top of the path but need not be checked for the 602 correctness of the top of the path but need not be checked for the
577 correctness of the bottom of the path */ 603 correctness of the bottom of the path */
578/* The function is NOT SCHEDULE-SAFE! */ 604/* The function is NOT SCHEDULE-SAFE! */
579int search_by_key (struct super_block * p_s_sb, 605int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* Key to search. */
580 const struct cpu_key * p_s_key, /* Key to search. */ 606 struct path *p_s_search_path, /* This structure was
581 struct path * p_s_search_path, /* This structure was 607 allocated and initialized
582 allocated and initialized 608 by the calling
583 by the calling 609 function. It is filled up
584 function. It is filled up 610 by this function. */
585 by this function. */ 611 int n_stop_level /* How far down the tree to search. To
586 int n_stop_level /* How far down the tree to search. To 612 stop at leaf level - set to
587 stop at leaf level - set to 613 DISK_LEAF_NODE_LEVEL */
588 DISK_LEAF_NODE_LEVEL */ 614 )
589 ) { 615{
590 int n_block_number; 616 int n_block_number;
591 int expected_level; 617 int expected_level;
592 struct buffer_head * p_s_bh; 618 struct buffer_head *p_s_bh;
593 struct path_element * p_s_last_element; 619 struct path_element *p_s_last_element;
594 int n_node_level, n_retval; 620 int n_node_level, n_retval;
595 int right_neighbor_of_leaf_node; 621 int right_neighbor_of_leaf_node;
596 int fs_gen; 622 int fs_gen;
597 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA]; 623 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA];
598 unsigned long reada_blocks[SEARCH_BY_KEY_READA]; 624 unsigned long reada_blocks[SEARCH_BY_KEY_READA];
599 int reada_count = 0; 625 int reada_count = 0;
600 626
601#ifdef CONFIG_REISERFS_CHECK 627#ifdef CONFIG_REISERFS_CHECK
602 int n_repeat_counter = 0; 628 int n_repeat_counter = 0;
603#endif 629#endif
604
605 PROC_INFO_INC( p_s_sb, search_by_key );
606
607 /* As we add each node to a path we increase its count. This means that
608 we must be careful to release all nodes in a path before we either
609 discard the path struct or re-use the path struct, as we do here. */
610 630
611 decrement_counters_in_path(p_s_search_path); 631 PROC_INFO_INC(p_s_sb, search_by_key);
632
633 /* As we add each node to a path we increase its count. This means that
634 we must be careful to release all nodes in a path before we either
635 discard the path struct or re-use the path struct, as we do here. */
612 636
613 right_neighbor_of_leaf_node = 0; 637 decrement_counters_in_path(p_s_search_path);
614 638
615 /* With each iteration of this loop we search through the items in the 639 right_neighbor_of_leaf_node = 0;
616 current node, and calculate the next current node(next path element) 640
617 for the next iteration of this loop.. */ 641 /* With each iteration of this loop we search through the items in the
618 n_block_number = SB_ROOT_BLOCK (p_s_sb); 642 current node, and calculate the next current node(next path element)
619 expected_level = -1; 643 for the next iteration of this loop.. */
620 while ( 1 ) { 644 n_block_number = SB_ROOT_BLOCK(p_s_sb);
645 expected_level = -1;
646 while (1) {
621 647
622#ifdef CONFIG_REISERFS_CHECK 648#ifdef CONFIG_REISERFS_CHECK
623 if ( !(++n_repeat_counter % 50000) ) 649 if (!(++n_repeat_counter % 50000))
624 reiserfs_warning (p_s_sb, "PAP-5100: search_by_key: %s:" 650 reiserfs_warning(p_s_sb, "PAP-5100: search_by_key: %s:"
625 "there were %d iterations of while loop " 651 "there were %d iterations of while loop "
626 "looking for key %K", 652 "looking for key %K",
627 current->comm, n_repeat_counter, p_s_key); 653 current->comm, n_repeat_counter,
654 p_s_key);
628#endif 655#endif
629 656
630 /* prep path to have another element added to it. */ 657 /* prep path to have another element added to it. */
631 p_s_last_element = PATH_OFFSET_PELEMENT(p_s_search_path, ++p_s_search_path->path_length); 658 p_s_last_element =
632 fs_gen = get_generation (p_s_sb); 659 PATH_OFFSET_PELEMENT(p_s_search_path,
633 660 ++p_s_search_path->path_length);
634 /* Read the next tree node, and set the last element in the path to 661 fs_gen = get_generation(p_s_sb);
635 have a pointer to it. */ 662
636 if ((p_s_bh = p_s_last_element->pe_buffer = 663 /* Read the next tree node, and set the last element in the path to
637 sb_getblk(p_s_sb, n_block_number)) ) { 664 have a pointer to it. */
638 if (!buffer_uptodate(p_s_bh) && reada_count > 1) { 665 if ((p_s_bh = p_s_last_element->pe_buffer =
639 search_by_key_reada (p_s_sb, reada_bh, 666 sb_getblk(p_s_sb, n_block_number))) {
640 reada_blocks, reada_count); 667 if (!buffer_uptodate(p_s_bh) && reada_count > 1) {
641 } 668 search_by_key_reada(p_s_sb, reada_bh,
642 ll_rw_block(READ, 1, &p_s_bh); 669 reada_blocks, reada_count);
643 wait_on_buffer(p_s_bh); 670 }
644 if (!buffer_uptodate(p_s_bh)) 671 ll_rw_block(READ, 1, &p_s_bh);
645 goto io_error; 672 wait_on_buffer(p_s_bh);
646 } else { 673 if (!buffer_uptodate(p_s_bh))
647io_error: 674 goto io_error;
648 p_s_search_path->path_length --; 675 } else {
649 pathrelse(p_s_search_path); 676 io_error:
650 return IO_ERROR; 677 p_s_search_path->path_length--;
651 } 678 pathrelse(p_s_search_path);
652 reada_count = 0; 679 return IO_ERROR;
653 if (expected_level == -1) 680 }
654 expected_level = SB_TREE_HEIGHT (p_s_sb); 681 reada_count = 0;
655 expected_level --; 682 if (expected_level == -1)
656 683 expected_level = SB_TREE_HEIGHT(p_s_sb);
657 /* It is possible that schedule occurred. We must check whether the key 684 expected_level--;
658 to search is still in the tree rooted from the current buffer. If 685
659 not then repeat search from the root. */ 686 /* It is possible that schedule occurred. We must check whether the key
660 if ( fs_changed (fs_gen, p_s_sb) && 687 to search is still in the tree rooted from the current buffer. If
661 (!B_IS_IN_TREE (p_s_bh) || 688 not then repeat search from the root. */
662 B_LEVEL(p_s_bh) != expected_level || 689 if (fs_changed(fs_gen, p_s_sb) &&
663 !key_in_buffer(p_s_search_path, p_s_key, p_s_sb))) { 690 (!B_IS_IN_TREE(p_s_bh) ||
664 PROC_INFO_INC( p_s_sb, search_by_key_fs_changed ); 691 B_LEVEL(p_s_bh) != expected_level ||
665 PROC_INFO_INC( p_s_sb, search_by_key_restarted ); 692 !key_in_buffer(p_s_search_path, p_s_key, p_s_sb))) {
666 PROC_INFO_INC( p_s_sb, sbk_restarted[ expected_level - 1 ] ); 693 PROC_INFO_INC(p_s_sb, search_by_key_fs_changed);
667 decrement_counters_in_path(p_s_search_path); 694 PROC_INFO_INC(p_s_sb, search_by_key_restarted);
668 695 PROC_INFO_INC(p_s_sb,
669 /* Get the root block number so that we can repeat the search 696 sbk_restarted[expected_level - 1]);
670 starting from the root. */ 697 decrement_counters_in_path(p_s_search_path);
671 n_block_number = SB_ROOT_BLOCK (p_s_sb); 698
672 expected_level = -1; 699 /* Get the root block number so that we can repeat the search
673 right_neighbor_of_leaf_node = 0; 700 starting from the root. */
674 701 n_block_number = SB_ROOT_BLOCK(p_s_sb);
675 /* repeat search from the root */ 702 expected_level = -1;
676 continue; 703 right_neighbor_of_leaf_node = 0;
677 } 704
705 /* repeat search from the root */
706 continue;
707 }
678 708
679 /* only check that the key is in the buffer if p_s_key is not 709 /* only check that the key is in the buffer if p_s_key is not
680 equal to the MAX_KEY. Latter case is only possible in 710 equal to the MAX_KEY. Latter case is only possible in
681 "finish_unfinished()" processing during mount. */ 711 "finish_unfinished()" processing during mount. */
682 RFALSE( comp_keys( &MAX_KEY, p_s_key ) && 712 RFALSE(comp_keys(&MAX_KEY, p_s_key) &&
683 ! key_in_buffer(p_s_search_path, p_s_key, p_s_sb), 713 !key_in_buffer(p_s_search_path, p_s_key, p_s_sb),
684 "PAP-5130: key is not in the buffer"); 714 "PAP-5130: key is not in the buffer");
685#ifdef CONFIG_REISERFS_CHECK 715#ifdef CONFIG_REISERFS_CHECK
686 if ( cur_tb ) { 716 if (cur_tb) {
687 print_cur_tb ("5140"); 717 print_cur_tb("5140");
688 reiserfs_panic(p_s_sb, "PAP-5140: search_by_key: schedule occurred in do_balance!"); 718 reiserfs_panic(p_s_sb,
689 } 719 "PAP-5140: search_by_key: schedule occurred in do_balance!");
720 }
690#endif 721#endif
691 722
692 // make sure, that the node contents look like a node of 723 // make sure, that the node contents look like a node of
693 // certain level 724 // certain level
694 if (!is_tree_node (p_s_bh, expected_level)) { 725 if (!is_tree_node(p_s_bh, expected_level)) {
695 reiserfs_warning (p_s_sb, "vs-5150: search_by_key: " 726 reiserfs_warning(p_s_sb, "vs-5150: search_by_key: "
696 "invalid format found in block %ld. Fsck?", 727 "invalid format found in block %ld. Fsck?",
697 p_s_bh->b_blocknr); 728 p_s_bh->b_blocknr);
698 pathrelse (p_s_search_path); 729 pathrelse(p_s_search_path);
699 return IO_ERROR; 730 return IO_ERROR;
700 } 731 }
701
702 /* ok, we have acquired next formatted node in the tree */
703 n_node_level = B_LEVEL (p_s_bh);
704
705 PROC_INFO_BH_STAT( p_s_sb, p_s_bh, n_node_level - 1 );
706
707 RFALSE( n_node_level < n_stop_level,
708 "vs-5152: tree level (%d) is less than stop level (%d)",
709 n_node_level, n_stop_level);
710
711 n_retval = bin_search( p_s_key, B_N_PITEM_HEAD(p_s_bh, 0),
712 B_NR_ITEMS(p_s_bh),
713 ( n_node_level == DISK_LEAF_NODE_LEVEL ) ? IH_SIZE : KEY_SIZE,
714 &(p_s_last_element->pe_position));
715 if (n_node_level == n_stop_level) {
716 return n_retval;
717 }
718 732
719 /* we are not in the stop level */ 733 /* ok, we have acquired next formatted node in the tree */
720 if (n_retval == ITEM_FOUND) 734 n_node_level = B_LEVEL(p_s_bh);
721 /* item has been found, so we choose the pointer which is to the right of the found one */
722 p_s_last_element->pe_position++;
723 735
724 /* if item was not found we choose the position which is to 736 PROC_INFO_BH_STAT(p_s_sb, p_s_bh, n_node_level - 1);
725 the left of the found item. This requires no code,
726 bin_search did it already.*/
727 737
728 /* So we have chosen a position in the current node which is 738 RFALSE(n_node_level < n_stop_level,
729 an internal node. Now we calculate child block number by 739 "vs-5152: tree level (%d) is less than stop level (%d)",
730 position in the node. */ 740 n_node_level, n_stop_level);
731 n_block_number = B_N_CHILD_NUM(p_s_bh, p_s_last_element->pe_position);
732 741
733 /* if we are going to read leaf nodes, try for read ahead as well */ 742 n_retval = bin_search(p_s_key, B_N_PITEM_HEAD(p_s_bh, 0),
734 if ((p_s_search_path->reada & PATH_READA) && 743 B_NR_ITEMS(p_s_bh),
735 n_node_level == DISK_LEAF_NODE_LEVEL + 1) 744 (n_node_level ==
736 { 745 DISK_LEAF_NODE_LEVEL) ? IH_SIZE :
737 int pos = p_s_last_element->pe_position; 746 KEY_SIZE,
738 int limit = B_NR_ITEMS(p_s_bh); 747 &(p_s_last_element->pe_position));
739 struct reiserfs_key *le_key; 748 if (n_node_level == n_stop_level) {
740 749 return n_retval;
741 if (p_s_search_path->reada & PATH_READA_BACK) 750 }
742 limit = 0;
743 while(reada_count < SEARCH_BY_KEY_READA) {
744 if (pos == limit)
745 break;
746 reada_blocks[reada_count++] = B_N_CHILD_NUM(p_s_bh, pos);
747 if (p_s_search_path->reada & PATH_READA_BACK)
748 pos--;
749 else
750 pos++;
751 751
752 /* 752 /* we are not in the stop level */
753 * check to make sure we're in the same object 753 if (n_retval == ITEM_FOUND)
754 */ 754 /* item has been found, so we choose the pointer which is to the right of the found one */
755 le_key = B_N_PDELIM_KEY(p_s_bh, pos); 755 p_s_last_element->pe_position++;
756 if (le32_to_cpu(le_key->k_objectid) != 756
757 p_s_key->on_disk_key.k_objectid) 757 /* if item was not found we choose the position which is to
758 { 758 the left of the found item. This requires no code,
759 break; 759 bin_search did it already. */
760
761 /* So we have chosen a position in the current node which is
762 an internal node. Now we calculate child block number by
763 position in the node. */
764 n_block_number =
765 B_N_CHILD_NUM(p_s_bh, p_s_last_element->pe_position);
766
767 /* if we are going to read leaf nodes, try for read ahead as well */
768 if ((p_s_search_path->reada & PATH_READA) &&
769 n_node_level == DISK_LEAF_NODE_LEVEL + 1) {
770 int pos = p_s_last_element->pe_position;
771 int limit = B_NR_ITEMS(p_s_bh);
772 struct reiserfs_key *le_key;
773
774 if (p_s_search_path->reada & PATH_READA_BACK)
775 limit = 0;
776 while (reada_count < SEARCH_BY_KEY_READA) {
777 if (pos == limit)
778 break;
779 reada_blocks[reada_count++] =
780 B_N_CHILD_NUM(p_s_bh, pos);
781 if (p_s_search_path->reada & PATH_READA_BACK)
782 pos--;
783 else
784 pos++;
785
786 /*
787 * check to make sure we're in the same object
788 */
789 le_key = B_N_PDELIM_KEY(p_s_bh, pos);
790 if (le32_to_cpu(le_key->k_objectid) !=
791 p_s_key->on_disk_key.k_objectid) {
792 break;
793 }
794 }
760 } 795 }
761 } 796 }
762 }
763 }
764} 797}
765 798
766
767/* Form the path to an item and position in this item which contains 799/* Form the path to an item and position in this item which contains
768 file byte defined by p_s_key. If there is no such item 800 file byte defined by p_s_key. If there is no such item
769 corresponding to the key, we point the path to the item with 801 corresponding to the key, we point the path to the item with
@@ -780,94 +812,97 @@ io_error:
780 units of directory entries. */ 812 units of directory entries. */
781 813
782/* The function is NOT SCHEDULE-SAFE! */ 814/* The function is NOT SCHEDULE-SAFE! */
783int search_for_position_by_key (struct super_block * p_s_sb, /* Pointer to the super block. */ 815int search_for_position_by_key(struct super_block *p_s_sb, /* Pointer to the super block. */
784 const struct cpu_key * p_cpu_key, /* Key to search (cpu variable) */ 816 const struct cpu_key *p_cpu_key, /* Key to search (cpu variable) */
785 struct path * p_s_search_path /* Filled up by this function. */ 817 struct path *p_s_search_path /* Filled up by this function. */
786 ) { 818 )
787 struct item_head * p_le_ih; /* pointer to on-disk structure */ 819{
788 int n_blk_size; 820 struct item_head *p_le_ih; /* pointer to on-disk structure */
789 loff_t item_offset, offset; 821 int n_blk_size;
790 struct reiserfs_dir_entry de; 822 loff_t item_offset, offset;
791 int retval; 823 struct reiserfs_dir_entry de;
792 824 int retval;
793 /* If searching for directory entry. */ 825
794 if ( is_direntry_cpu_key (p_cpu_key) ) 826 /* If searching for directory entry. */
795 return search_by_entry_key (p_s_sb, p_cpu_key, p_s_search_path, &de); 827 if (is_direntry_cpu_key(p_cpu_key))
796 828 return search_by_entry_key(p_s_sb, p_cpu_key, p_s_search_path,
797 /* If not searching for directory entry. */ 829 &de);
798 830
799 /* If item is found. */ 831 /* If not searching for directory entry. */
800 retval = search_item (p_s_sb, p_cpu_key, p_s_search_path); 832
801 if (retval == IO_ERROR) 833 /* If item is found. */
802 return retval; 834 retval = search_item(p_s_sb, p_cpu_key, p_s_search_path);
803 if ( retval == ITEM_FOUND ) { 835 if (retval == IO_ERROR)
804 836 return retval;
805 RFALSE( ! ih_item_len( 837 if (retval == ITEM_FOUND) {
806 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_search_path),
807 PATH_LAST_POSITION(p_s_search_path))),
808 "PAP-5165: item length equals zero");
809 838
810 pos_in_item(p_s_search_path) = 0; 839 RFALSE(!ih_item_len
811 return POSITION_FOUND; 840 (B_N_PITEM_HEAD
812 } 841 (PATH_PLAST_BUFFER(p_s_search_path),
842 PATH_LAST_POSITION(p_s_search_path))),
843 "PAP-5165: item length equals zero");
813 844
814 RFALSE( ! PATH_LAST_POSITION(p_s_search_path), 845 pos_in_item(p_s_search_path) = 0;
815 "PAP-5170: position equals zero"); 846 return POSITION_FOUND;
847 }
816 848
817 /* Item is not found. Set path to the previous item. */ 849 RFALSE(!PATH_LAST_POSITION(p_s_search_path),
818 p_le_ih = B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_search_path), --PATH_LAST_POSITION(p_s_search_path)); 850 "PAP-5170: position equals zero");
819 n_blk_size = p_s_sb->s_blocksize;
820 851
821 if (comp_short_keys (&(p_le_ih->ih_key), p_cpu_key)) { 852 /* Item is not found. Set path to the previous item. */
822 return FILE_NOT_FOUND; 853 p_le_ih =
823 } 854 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_search_path),
855 --PATH_LAST_POSITION(p_s_search_path));
856 n_blk_size = p_s_sb->s_blocksize;
824 857
825 // FIXME: quite ugly this far 858 if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) {
859 return FILE_NOT_FOUND;
860 }
861 // FIXME: quite ugly this far
826 862
827 item_offset = le_ih_k_offset (p_le_ih); 863 item_offset = le_ih_k_offset(p_le_ih);
828 offset = cpu_key_k_offset (p_cpu_key); 864 offset = cpu_key_k_offset(p_cpu_key);
829 865
830 /* Needed byte is contained in the item pointed to by the path.*/ 866 /* Needed byte is contained in the item pointed to by the path. */
831 if (item_offset <= offset && 867 if (item_offset <= offset &&
832 item_offset + op_bytes_number (p_le_ih, n_blk_size) > offset) { 868 item_offset + op_bytes_number(p_le_ih, n_blk_size) > offset) {
833 pos_in_item (p_s_search_path) = offset - item_offset; 869 pos_in_item(p_s_search_path) = offset - item_offset;
834 if ( is_indirect_le_ih(p_le_ih) ) { 870 if (is_indirect_le_ih(p_le_ih)) {
835 pos_in_item (p_s_search_path) /= n_blk_size; 871 pos_in_item(p_s_search_path) /= n_blk_size;
872 }
873 return POSITION_FOUND;
836 } 874 }
837 return POSITION_FOUND;
838 }
839
840 /* Needed byte is not contained in the item pointed to by the
841 path. Set pos_in_item out of the item. */
842 if ( is_indirect_le_ih (p_le_ih) )
843 pos_in_item (p_s_search_path) = ih_item_len(p_le_ih) / UNFM_P_SIZE;
844 else
845 pos_in_item (p_s_search_path) = ih_item_len( p_le_ih );
846
847 return POSITION_NOT_FOUND;
848}
849 875
876 /* Needed byte is not contained in the item pointed to by the
877 path. Set pos_in_item out of the item. */
878 if (is_indirect_le_ih(p_le_ih))
879 pos_in_item(p_s_search_path) =
880 ih_item_len(p_le_ih) / UNFM_P_SIZE;
881 else
882 pos_in_item(p_s_search_path) = ih_item_len(p_le_ih);
883
884 return POSITION_NOT_FOUND;
885}
850 886
851/* Compare given item and item pointed to by the path. */ 887/* Compare given item and item pointed to by the path. */
852int comp_items (const struct item_head * stored_ih, const struct path * p_s_path) 888int comp_items(const struct item_head *stored_ih, const struct path *p_s_path)
853{ 889{
854 struct buffer_head * p_s_bh; 890 struct buffer_head *p_s_bh;
855 struct item_head * ih; 891 struct item_head *ih;
856 892
857 /* Last buffer at the path is not in the tree. */ 893 /* Last buffer at the path is not in the tree. */
858 if ( ! B_IS_IN_TREE(p_s_bh = PATH_PLAST_BUFFER(p_s_path)) ) 894 if (!B_IS_IN_TREE(p_s_bh = PATH_PLAST_BUFFER(p_s_path)))
859 return 1; 895 return 1;
860 896
861 /* Last path position is invalid. */ 897 /* Last path position is invalid. */
862 if ( PATH_LAST_POSITION(p_s_path) >= B_NR_ITEMS(p_s_bh) ) 898 if (PATH_LAST_POSITION(p_s_path) >= B_NR_ITEMS(p_s_bh))
863 return 1; 899 return 1;
864 900
865 /* we need only to know, whether it is the same item */ 901 /* we need only to know, whether it is the same item */
866 ih = get_ih (p_s_path); 902 ih = get_ih(p_s_path);
867 return memcmp (stored_ih, ih, IH_SIZE); 903 return memcmp(stored_ih, ih, IH_SIZE);
868} 904}
869 905
870
871/* unformatted nodes are not logged anymore, ever. This is safe 906/* unformatted nodes are not logged anymore, ever. This is safe
872** now 907** now
873*/ 908*/
@@ -876,461 +911,466 @@ int comp_items (const struct item_head * stored_ih, const struct path * p_s_path
876// block can not be forgotten as it is in I/O or held by someone 911// block can not be forgotten as it is in I/O or held by someone
877#define block_in_use(bh) (buffer_locked(bh) || (held_by_others(bh))) 912#define block_in_use(bh) (buffer_locked(bh) || (held_by_others(bh)))
878 913
879
880
881// prepare for delete or cut of direct item 914// prepare for delete or cut of direct item
882static inline int prepare_for_direct_item (struct path * path, 915static inline int prepare_for_direct_item(struct path *path,
883 struct item_head * le_ih, 916 struct item_head *le_ih,
884 struct inode * inode, 917 struct inode *inode,
885 loff_t new_file_length, 918 loff_t new_file_length, int *cut_size)
886 int * cut_size)
887{ 919{
888 loff_t round_len; 920 loff_t round_len;
889 921
890 922 if (new_file_length == max_reiserfs_offset(inode)) {
891 if ( new_file_length == max_reiserfs_offset (inode) ) { 923 /* item has to be deleted */
892 /* item has to be deleted */ 924 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
893 *cut_size = -(IH_SIZE + ih_item_len(le_ih)); 925 return M_DELETE;
894 return M_DELETE; 926 }
895 } 927 // new file gets truncated
896 928 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) {
897 // new file gets truncated 929 //
898 if (get_inode_item_key_version (inode) == KEY_FORMAT_3_6) { 930 round_len = ROUND_UP(new_file_length);
899 // 931 /* this was n_new_file_length < le_ih ... */
900 round_len = ROUND_UP (new_file_length); 932 if (round_len < le_ih_k_offset(le_ih)) {
901 /* this was n_new_file_length < le_ih ... */ 933 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
902 if ( round_len < le_ih_k_offset (le_ih) ) { 934 return M_DELETE; /* Delete this item. */
903 *cut_size = -(IH_SIZE + ih_item_len(le_ih)); 935 }
904 return M_DELETE; /* Delete this item. */ 936 /* Calculate first position and size for cutting from item. */
937 pos_in_item(path) = round_len - (le_ih_k_offset(le_ih) - 1);
938 *cut_size = -(ih_item_len(le_ih) - pos_in_item(path));
939
940 return M_CUT; /* Cut from this item. */
941 }
942
943 // old file: items may have any length
944
945 if (new_file_length < le_ih_k_offset(le_ih)) {
946 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
947 return M_DELETE; /* Delete this item. */
905 } 948 }
906 /* Calculate first position and size for cutting from item. */ 949 /* Calculate first position and size for cutting from item. */
907 pos_in_item (path) = round_len - (le_ih_k_offset (le_ih) - 1); 950 *cut_size = -(ih_item_len(le_ih) -
908 *cut_size = -(ih_item_len(le_ih) - pos_in_item(path)); 951 (pos_in_item(path) =
909 952 new_file_length + 1 - le_ih_k_offset(le_ih)));
910 return M_CUT; /* Cut from this item. */ 953 return M_CUT; /* Cut from this item. */
911 }
912
913
914 // old file: items may have any length
915
916 if ( new_file_length < le_ih_k_offset (le_ih) ) {
917 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
918 return M_DELETE; /* Delete this item. */
919 }
920 /* Calculate first position and size for cutting from item. */
921 *cut_size = -(ih_item_len(le_ih) -
922 (pos_in_item (path) = new_file_length + 1 - le_ih_k_offset (le_ih)));
923 return M_CUT; /* Cut from this item. */
924} 954}
925 955
926 956static inline int prepare_for_direntry_item(struct path *path,
927static inline int prepare_for_direntry_item (struct path * path, 957 struct item_head *le_ih,
928 struct item_head * le_ih, 958 struct inode *inode,
929 struct inode * inode, 959 loff_t new_file_length,
930 loff_t new_file_length, 960 int *cut_size)
931 int * cut_size)
932{ 961{
933 if (le_ih_k_offset (le_ih) == DOT_OFFSET && 962 if (le_ih_k_offset(le_ih) == DOT_OFFSET &&
934 new_file_length == max_reiserfs_offset (inode)) { 963 new_file_length == max_reiserfs_offset(inode)) {
935 RFALSE( ih_entry_count (le_ih) != 2, 964 RFALSE(ih_entry_count(le_ih) != 2,
936 "PAP-5220: incorrect empty directory item (%h)", le_ih); 965 "PAP-5220: incorrect empty directory item (%h)", le_ih);
937 *cut_size = -(IH_SIZE + ih_item_len(le_ih)); 966 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
938 return M_DELETE; /* Delete the directory item containing "." and ".." entry. */ 967 return M_DELETE; /* Delete the directory item containing "." and ".." entry. */
939 } 968 }
940
941 if ( ih_entry_count (le_ih) == 1 ) {
942 /* Delete the directory item such as there is one record only
943 in this item*/
944 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
945 return M_DELETE;
946 }
947
948 /* Cut one record from the directory item. */
949 *cut_size = -(DEH_SIZE + entry_length (get_last_bh (path), le_ih, pos_in_item (path)));
950 return M_CUT;
951}
952 969
970 if (ih_entry_count(le_ih) == 1) {
971 /* Delete the directory item such as there is one record only
972 in this item */
973 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
974 return M_DELETE;
975 }
976
977 /* Cut one record from the directory item. */
978 *cut_size =
979 -(DEH_SIZE +
980 entry_length(get_last_bh(path), le_ih, pos_in_item(path)));
981 return M_CUT;
982}
953 983
954/* If the path points to a directory or direct item, calculate mode and the size cut, for balance. 984/* If the path points to a directory or direct item, calculate mode and the size cut, for balance.
955 If the path points to an indirect item, remove some number of its unformatted nodes. 985 If the path points to an indirect item, remove some number of its unformatted nodes.
956 In case of file truncate calculate whether this item must be deleted/truncated or last 986 In case of file truncate calculate whether this item must be deleted/truncated or last
957 unformatted node of this item will be converted to a direct item. 987 unformatted node of this item will be converted to a direct item.
958 This function returns a determination of what balance mode the calling function should employ. */ 988 This function returns a determination of what balance mode the calling function should employ. */
959static char prepare_for_delete_or_cut( 989static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct path *p_s_path, const struct cpu_key *p_s_item_key, int *p_n_removed, /* Number of unformatted nodes which were removed
960 struct reiserfs_transaction_handle *th, 990 from end of the file. */
961 struct inode * inode, 991 int *p_n_cut_size, unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */
962 struct path * p_s_path, 992 )
963 const struct cpu_key * p_s_item_key, 993{
964 int * p_n_removed, /* Number of unformatted nodes which were removed 994 struct super_block *p_s_sb = inode->i_sb;
965 from end of the file. */ 995 struct item_head *p_le_ih = PATH_PITEM_HEAD(p_s_path);
966 int * p_n_cut_size, 996 struct buffer_head *p_s_bh = PATH_PLAST_BUFFER(p_s_path);
967 unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */
968 ) {
969 struct super_block * p_s_sb = inode->i_sb;
970 struct item_head * p_le_ih = PATH_PITEM_HEAD(p_s_path);
971 struct buffer_head * p_s_bh = PATH_PLAST_BUFFER(p_s_path);
972
973 BUG_ON (!th->t_trans_id);
974
975 /* Stat_data item. */
976 if ( is_statdata_le_ih (p_le_ih) ) {
977
978 RFALSE( n_new_file_length != max_reiserfs_offset (inode),
979 "PAP-5210: mode must be M_DELETE");
980
981 *p_n_cut_size = -(IH_SIZE + ih_item_len(p_le_ih));
982 return M_DELETE;
983 }
984
985
986 /* Directory item. */
987 if ( is_direntry_le_ih (p_le_ih) )
988 return prepare_for_direntry_item (p_s_path, p_le_ih, inode, n_new_file_length, p_n_cut_size);
989
990 /* Direct item. */
991 if ( is_direct_le_ih (p_le_ih) )
992 return prepare_for_direct_item (p_s_path, p_le_ih, inode, n_new_file_length, p_n_cut_size);
993
994
995 /* Case of an indirect item. */
996 {
997 int n_unfm_number, /* Number of the item unformatted nodes. */
998 n_counter,
999 n_blk_size;
1000 __le32 * p_n_unfm_pointer; /* Pointer to the unformatted node number. */
1001 __u32 tmp;
1002 struct item_head s_ih; /* Item header. */
1003 char c_mode; /* Returned mode of the balance. */
1004 int need_research;
1005 997
998 BUG_ON(!th->t_trans_id);
1006 999
1007 n_blk_size = p_s_sb->s_blocksize; 1000 /* Stat_data item. */
1001 if (is_statdata_le_ih(p_le_ih)) {
1008 1002
1009 /* Search for the needed object indirect item until there are no unformatted nodes to be removed. */ 1003 RFALSE(n_new_file_length != max_reiserfs_offset(inode),
1010 do { 1004 "PAP-5210: mode must be M_DELETE");
1011 need_research = 0;
1012 p_s_bh = PATH_PLAST_BUFFER(p_s_path);
1013 /* Copy indirect item header to a temp variable. */
1014 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
1015 /* Calculate number of unformatted nodes in this item. */
1016 n_unfm_number = I_UNFM_NUM(&s_ih);
1017
1018 RFALSE( ! is_indirect_le_ih(&s_ih) || ! n_unfm_number ||
1019 pos_in_item (p_s_path) + 1 != n_unfm_number,
1020 "PAP-5240: invalid item %h "
1021 "n_unfm_number = %d *p_n_pos_in_item = %d",
1022 &s_ih, n_unfm_number, pos_in_item (p_s_path));
1023
1024 /* Calculate balance mode and position in the item to remove unformatted nodes. */
1025 if ( n_new_file_length == max_reiserfs_offset (inode) ) {/* Case of delete. */
1026 pos_in_item (p_s_path) = 0;
1027 *p_n_cut_size = -(IH_SIZE + ih_item_len(&s_ih));
1028 c_mode = M_DELETE;
1029 }
1030 else { /* Case of truncate. */
1031 if ( n_new_file_length < le_ih_k_offset (&s_ih) ) {
1032 pos_in_item (p_s_path) = 0;
1033 *p_n_cut_size = -(IH_SIZE + ih_item_len(&s_ih));
1034 c_mode = M_DELETE; /* Delete this item. */
1035 }
1036 else {
1037 /* indirect item must be truncated starting from *p_n_pos_in_item-th position */
1038 pos_in_item (p_s_path) = (n_new_file_length + n_blk_size - le_ih_k_offset (&s_ih) ) >> p_s_sb->s_blocksize_bits;
1039
1040 RFALSE( pos_in_item (p_s_path) > n_unfm_number,
1041 "PAP-5250: invalid position in the item");
1042
1043 /* Either convert last unformatted node of indirect item to direct item or increase
1044 its free space. */
1045 if ( pos_in_item (p_s_path) == n_unfm_number ) {
1046 *p_n_cut_size = 0; /* Nothing to cut. */
1047 return M_CONVERT; /* Maybe convert last unformatted node to the direct item. */
1048 }
1049 /* Calculate size to cut. */
1050 *p_n_cut_size = -(ih_item_len(&s_ih) - pos_in_item(p_s_path) * UNFM_P_SIZE);
1051
1052 c_mode = M_CUT; /* Cut from this indirect item. */
1053 }
1054 }
1055
1056 RFALSE( n_unfm_number <= pos_in_item (p_s_path),
1057 "PAP-5260: invalid position in the indirect item");
1058
1059 /* pointers to be cut */
1060 n_unfm_number -= pos_in_item (p_s_path);
1061 /* Set pointer to the last unformatted node pointer that is to be cut. */
1062 p_n_unfm_pointer = (__le32 *)B_I_PITEM(p_s_bh, &s_ih) + I_UNFM_NUM(&s_ih) - 1 - *p_n_removed;
1063
1064
1065 /* We go through the unformatted nodes pointers of the indirect
1066 item and look for the unformatted nodes in the cache. If we
1067 found some of them we free it, zero corresponding indirect item
1068 entry and log buffer containing that indirect item. For this we
1069 need to prepare last path element for logging. If some
1070 unformatted node has b_count > 1 we must not free this
1071 unformatted node since it is in use. */
1072 reiserfs_prepare_for_journal(p_s_sb, p_s_bh, 1);
1073 // note: path could be changed, first line in for loop takes care
1074 // of it
1075
1076 for (n_counter = *p_n_removed;
1077 n_counter < n_unfm_number; n_counter++, p_n_unfm_pointer-- ) {
1078
1079 cond_resched();
1080 if (item_moved (&s_ih, p_s_path)) {
1081 need_research = 1 ;
1082 break;
1083 }
1084 RFALSE( p_n_unfm_pointer < (__le32 *)B_I_PITEM(p_s_bh, &s_ih) ||
1085 p_n_unfm_pointer > (__le32 *)B_I_PITEM(p_s_bh, &s_ih) + I_UNFM_NUM(&s_ih) - 1,
1086 "vs-5265: pointer out of range");
1087 1005
1088 /* Hole, nothing to remove. */ 1006 *p_n_cut_size = -(IH_SIZE + ih_item_len(p_le_ih));
1089 if ( ! get_block_num(p_n_unfm_pointer,0) ) { 1007 return M_DELETE;
1090 (*p_n_removed)++; 1008 }
1091 continue;
1092 }
1093 1009
1094 (*p_n_removed)++; 1010 /* Directory item. */
1011 if (is_direntry_le_ih(p_le_ih))
1012 return prepare_for_direntry_item(p_s_path, p_le_ih, inode,
1013 n_new_file_length,
1014 p_n_cut_size);
1095 1015
1096 tmp = get_block_num(p_n_unfm_pointer,0); 1016 /* Direct item. */
1097 put_block_num(p_n_unfm_pointer, 0, 0); 1017 if (is_direct_le_ih(p_le_ih))
1098 journal_mark_dirty (th, p_s_sb, p_s_bh); 1018 return prepare_for_direct_item(p_s_path, p_le_ih, inode,
1099 reiserfs_free_block(th, inode, tmp, 1); 1019 n_new_file_length, p_n_cut_size);
1100 if ( item_moved (&s_ih, p_s_path) ) { 1020
1101 need_research = 1; 1021 /* Case of an indirect item. */
1102 break ; 1022 {
1103 } 1023 int n_unfm_number, /* Number of the item unformatted nodes. */
1104 } 1024 n_counter, n_blk_size;
1105 1025 __le32 *p_n_unfm_pointer; /* Pointer to the unformatted node number. */
1106 /* a trick. If the buffer has been logged, this 1026 __u32 tmp;
1107 ** will do nothing. If we've broken the loop without 1027 struct item_head s_ih; /* Item header. */
1108 ** logging it, it will restore the buffer 1028 char c_mode; /* Returned mode of the balance. */
1109 ** 1029 int need_research;
1110 */ 1030
1111 reiserfs_restore_prepared_buffer(p_s_sb, p_s_bh); 1031 n_blk_size = p_s_sb->s_blocksize;
1112 1032
1113 /* This loop can be optimized. */ 1033 /* Search for the needed object indirect item until there are no unformatted nodes to be removed. */
1114 } while ( (*p_n_removed < n_unfm_number || need_research) && 1034 do {
1115 search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path) == POSITION_FOUND ); 1035 need_research = 0;
1116 1036 p_s_bh = PATH_PLAST_BUFFER(p_s_path);
1117 RFALSE( *p_n_removed < n_unfm_number, 1037 /* Copy indirect item header to a temp variable. */
1118 "PAP-5310: indirect item is not found"); 1038 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
1119 RFALSE( item_moved (&s_ih, p_s_path), 1039 /* Calculate number of unformatted nodes in this item. */
1120 "after while, comp failed, retry") ; 1040 n_unfm_number = I_UNFM_NUM(&s_ih);
1121 1041
1122 if (c_mode == M_CUT) 1042 RFALSE(!is_indirect_le_ih(&s_ih) || !n_unfm_number ||
1123 pos_in_item (p_s_path) *= UNFM_P_SIZE; 1043 pos_in_item(p_s_path) + 1 != n_unfm_number,
1124 return c_mode; 1044 "PAP-5240: invalid item %h "
1125 } 1045 "n_unfm_number = %d *p_n_pos_in_item = %d",
1046 &s_ih, n_unfm_number, pos_in_item(p_s_path));
1047
1048 /* Calculate balance mode and position in the item to remove unformatted nodes. */
1049 if (n_new_file_length == max_reiserfs_offset(inode)) { /* Case of delete. */
1050 pos_in_item(p_s_path) = 0;
1051 *p_n_cut_size = -(IH_SIZE + ih_item_len(&s_ih));
1052 c_mode = M_DELETE;
1053 } else { /* Case of truncate. */
1054 if (n_new_file_length < le_ih_k_offset(&s_ih)) {
1055 pos_in_item(p_s_path) = 0;
1056 *p_n_cut_size =
1057 -(IH_SIZE + ih_item_len(&s_ih));
1058 c_mode = M_DELETE; /* Delete this item. */
1059 } else {
1060 /* indirect item must be truncated starting from *p_n_pos_in_item-th position */
1061 pos_in_item(p_s_path) =
1062 (n_new_file_length + n_blk_size -
1063 le_ih_k_offset(&s_ih)) >> p_s_sb->
1064 s_blocksize_bits;
1065
1066 RFALSE(pos_in_item(p_s_path) >
1067 n_unfm_number,
1068 "PAP-5250: invalid position in the item");
1069
1070 /* Either convert last unformatted node of indirect item to direct item or increase
1071 its free space. */
1072 if (pos_in_item(p_s_path) ==
1073 n_unfm_number) {
1074 *p_n_cut_size = 0; /* Nothing to cut. */
1075 return M_CONVERT; /* Maybe convert last unformatted node to the direct item. */
1076 }
1077 /* Calculate size to cut. */
1078 *p_n_cut_size =
1079 -(ih_item_len(&s_ih) -
1080 pos_in_item(p_s_path) *
1081 UNFM_P_SIZE);
1082
1083 c_mode = M_CUT; /* Cut from this indirect item. */
1084 }
1085 }
1086
1087 RFALSE(n_unfm_number <= pos_in_item(p_s_path),
1088 "PAP-5260: invalid position in the indirect item");
1089
1090 /* pointers to be cut */
1091 n_unfm_number -= pos_in_item(p_s_path);
1092 /* Set pointer to the last unformatted node pointer that is to be cut. */
1093 p_n_unfm_pointer =
1094 (__le32 *) B_I_PITEM(p_s_bh,
1095 &s_ih) + I_UNFM_NUM(&s_ih) -
1096 1 - *p_n_removed;
1097
1098 /* We go through the unformatted nodes pointers of the indirect
1099 item and look for the unformatted nodes in the cache. If we
1100 found some of them we free it, zero corresponding indirect item
1101 entry and log buffer containing that indirect item. For this we
1102 need to prepare last path element for logging. If some
1103 unformatted node has b_count > 1 we must not free this
1104 unformatted node since it is in use. */
1105 reiserfs_prepare_for_journal(p_s_sb, p_s_bh, 1);
1106 // note: path could be changed, first line in for loop takes care
1107 // of it
1108
1109 for (n_counter = *p_n_removed;
1110 n_counter < n_unfm_number;
1111 n_counter++, p_n_unfm_pointer--) {
1112
1113 cond_resched();
1114 if (item_moved(&s_ih, p_s_path)) {
1115 need_research = 1;
1116 break;
1117 }
1118 RFALSE(p_n_unfm_pointer <
1119 (__le32 *) B_I_PITEM(p_s_bh, &s_ih)
1120 || p_n_unfm_pointer >
1121 (__le32 *) B_I_PITEM(p_s_bh,
1122 &s_ih) +
1123 I_UNFM_NUM(&s_ih) - 1,
1124 "vs-5265: pointer out of range");
1125
1126 /* Hole, nothing to remove. */
1127 if (!get_block_num(p_n_unfm_pointer, 0)) {
1128 (*p_n_removed)++;
1129 continue;
1130 }
1131
1132 (*p_n_removed)++;
1133
1134 tmp = get_block_num(p_n_unfm_pointer, 0);
1135 put_block_num(p_n_unfm_pointer, 0, 0);
1136 journal_mark_dirty(th, p_s_sb, p_s_bh);
1137 reiserfs_free_block(th, inode, tmp, 1);
1138 if (item_moved(&s_ih, p_s_path)) {
1139 need_research = 1;
1140 break;
1141 }
1142 }
1143
1144 /* a trick. If the buffer has been logged, this
1145 ** will do nothing. If we've broken the loop without
1146 ** logging it, it will restore the buffer
1147 **
1148 */
1149 reiserfs_restore_prepared_buffer(p_s_sb, p_s_bh);
1150
1151 /* This loop can be optimized. */
1152 } while ((*p_n_removed < n_unfm_number || need_research) &&
1153 search_for_position_by_key(p_s_sb, p_s_item_key,
1154 p_s_path) ==
1155 POSITION_FOUND);
1156
1157 RFALSE(*p_n_removed < n_unfm_number,
1158 "PAP-5310: indirect item is not found");
1159 RFALSE(item_moved(&s_ih, p_s_path),
1160 "after while, comp failed, retry");
1161
1162 if (c_mode == M_CUT)
1163 pos_in_item(p_s_path) *= UNFM_P_SIZE;
1164 return c_mode;
1165 }
1126} 1166}
1127 1167
1128/* Calculate number of bytes which will be deleted or cut during balance */ 1168/* Calculate number of bytes which will be deleted or cut during balance */
1129static int calc_deleted_bytes_number( 1169static int calc_deleted_bytes_number(struct tree_balance *p_s_tb, char c_mode)
1130 struct tree_balance * p_s_tb, 1170{
1131 char c_mode 1171 int n_del_size;
1132 ) { 1172 struct item_head *p_le_ih = PATH_PITEM_HEAD(p_s_tb->tb_path);
1133 int n_del_size; 1173
1134 struct item_head * p_le_ih = PATH_PITEM_HEAD(p_s_tb->tb_path); 1174 if (is_statdata_le_ih(p_le_ih))
1135 1175 return 0;
1136 if ( is_statdata_le_ih (p_le_ih) ) 1176
1137 return 0; 1177 n_del_size =
1178 (c_mode ==
1179 M_DELETE) ? ih_item_len(p_le_ih) : -p_s_tb->insert_size[0];
1180 if (is_direntry_le_ih(p_le_ih)) {
1181 // return EMPTY_DIR_SIZE; /* We delete emty directoris only. */
1182 // we can't use EMPTY_DIR_SIZE, as old format dirs have a different
1183 // empty size. ick. FIXME, is this right?
1184 //
1185 return n_del_size;
1186 }
1138 1187
1139 n_del_size = ( c_mode == M_DELETE ) ? ih_item_len(p_le_ih) : -p_s_tb->insert_size[0]; 1188 if (is_indirect_le_ih(p_le_ih))
1140 if ( is_direntry_le_ih (p_le_ih) ) { 1189 n_del_size = (n_del_size / UNFM_P_SIZE) * (PATH_PLAST_BUFFER(p_s_tb->tb_path)->b_size); // - get_ih_free_space (p_le_ih);
1141 // return EMPTY_DIR_SIZE; /* We delete emty directoris only. */ 1190 return n_del_size;
1142 // we can't use EMPTY_DIR_SIZE, as old format dirs have a different
1143 // empty size. ick. FIXME, is this right?
1144 //
1145 return n_del_size ;
1146 }
1147
1148 if ( is_indirect_le_ih (p_le_ih) )
1149 n_del_size = (n_del_size/UNFM_P_SIZE)*
1150 (PATH_PLAST_BUFFER(p_s_tb->tb_path)->b_size);// - get_ih_free_space (p_le_ih);
1151 return n_del_size;
1152} 1191}
1153 1192
1154static void init_tb_struct( 1193static void init_tb_struct(struct reiserfs_transaction_handle *th,
1155 struct reiserfs_transaction_handle *th, 1194 struct tree_balance *p_s_tb,
1156 struct tree_balance * p_s_tb, 1195 struct super_block *p_s_sb,
1157 struct super_block * p_s_sb, 1196 struct path *p_s_path, int n_size)
1158 struct path * p_s_path, 1197{
1159 int n_size
1160 ) {
1161
1162 BUG_ON (!th->t_trans_id);
1163
1164 memset (p_s_tb,'\0',sizeof(struct tree_balance));
1165 p_s_tb->transaction_handle = th ;
1166 p_s_tb->tb_sb = p_s_sb;
1167 p_s_tb->tb_path = p_s_path;
1168 PATH_OFFSET_PBUFFER(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL;
1169 PATH_OFFSET_POSITION(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0;
1170 p_s_tb->insert_size[0] = n_size;
1171}
1172 1198
1199 BUG_ON(!th->t_trans_id);
1173 1200
1201 memset(p_s_tb, '\0', sizeof(struct tree_balance));
1202 p_s_tb->transaction_handle = th;
1203 p_s_tb->tb_sb = p_s_sb;
1204 p_s_tb->tb_path = p_s_path;
1205 PATH_OFFSET_PBUFFER(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL;
1206 PATH_OFFSET_POSITION(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0;
1207 p_s_tb->insert_size[0] = n_size;
1208}
1174 1209
1175void padd_item (char * item, int total_length, int length) 1210void padd_item(char *item, int total_length, int length)
1176{ 1211{
1177 int i; 1212 int i;
1178 1213
1179 for (i = total_length; i > length; ) 1214 for (i = total_length; i > length;)
1180 item [--i] = 0; 1215 item[--i] = 0;
1181} 1216}
1182 1217
1183#ifdef REISERQUOTA_DEBUG 1218#ifdef REISERQUOTA_DEBUG
1184char key2type(struct reiserfs_key *ih) 1219char key2type(struct reiserfs_key *ih)
1185{ 1220{
1186 if (is_direntry_le_key(2, ih)) 1221 if (is_direntry_le_key(2, ih))
1187 return 'd'; 1222 return 'd';
1188 if (is_direct_le_key(2, ih)) 1223 if (is_direct_le_key(2, ih))
1189 return 'D'; 1224 return 'D';
1190 if (is_indirect_le_key(2, ih)) 1225 if (is_indirect_le_key(2, ih))
1191 return 'i'; 1226 return 'i';
1192 if (is_statdata_le_key(2, ih)) 1227 if (is_statdata_le_key(2, ih))
1193 return 's'; 1228 return 's';
1194 return 'u'; 1229 return 'u';
1195} 1230}
1196 1231
1197char head2type(struct item_head *ih) 1232char head2type(struct item_head *ih)
1198{ 1233{
1199 if (is_direntry_le_ih(ih)) 1234 if (is_direntry_le_ih(ih))
1200 return 'd'; 1235 return 'd';
1201 if (is_direct_le_ih(ih)) 1236 if (is_direct_le_ih(ih))
1202 return 'D'; 1237 return 'D';
1203 if (is_indirect_le_ih(ih)) 1238 if (is_indirect_le_ih(ih))
1204 return 'i'; 1239 return 'i';
1205 if (is_statdata_le_ih(ih)) 1240 if (is_statdata_le_ih(ih))
1206 return 's'; 1241 return 's';
1207 return 'u'; 1242 return 'u';
1208} 1243}
1209#endif 1244#endif
1210 1245
1211/* Delete object item. */ 1246/* Delete object item. */
1212int reiserfs_delete_item (struct reiserfs_transaction_handle *th, 1247int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct path *p_s_path, /* Path to the deleted item. */
1213 struct path * p_s_path, /* Path to the deleted item. */ 1248 const struct cpu_key *p_s_item_key, /* Key to search for the deleted item. */
1214 const struct cpu_key * p_s_item_key, /* Key to search for the deleted item. */ 1249 struct inode *p_s_inode, /* inode is here just to update i_blocks and quotas */
1215 struct inode * p_s_inode,/* inode is here just to update i_blocks and quotas */ 1250 struct buffer_head *p_s_un_bh)
1216 struct buffer_head * p_s_un_bh) /* NULL or unformatted node pointer. */ 1251{ /* NULL or unformatted node pointer. */
1217{ 1252 struct super_block *p_s_sb = p_s_inode->i_sb;
1218 struct super_block * p_s_sb = p_s_inode->i_sb; 1253 struct tree_balance s_del_balance;
1219 struct tree_balance s_del_balance; 1254 struct item_head s_ih;
1220 struct item_head s_ih; 1255 struct item_head *q_ih;
1221 struct item_head *q_ih; 1256 int quota_cut_bytes;
1222 int quota_cut_bytes; 1257 int n_ret_value, n_del_size, n_removed;
1223 int n_ret_value,
1224 n_del_size,
1225 n_removed;
1226 1258
1227#ifdef CONFIG_REISERFS_CHECK 1259#ifdef CONFIG_REISERFS_CHECK
1228 char c_mode; 1260 char c_mode;
1229 int n_iter = 0; 1261 int n_iter = 0;
1230#endif 1262#endif
1231 1263
1232 BUG_ON (!th->t_trans_id); 1264 BUG_ON(!th->t_trans_id);
1233 1265
1234 init_tb_struct(th, &s_del_balance, p_s_sb, p_s_path, 0/*size is unknown*/); 1266 init_tb_struct(th, &s_del_balance, p_s_sb, p_s_path,
1267 0 /*size is unknown */ );
1235 1268
1236 while ( 1 ) { 1269 while (1) {
1237 n_removed = 0; 1270 n_removed = 0;
1238 1271
1239#ifdef CONFIG_REISERFS_CHECK 1272#ifdef CONFIG_REISERFS_CHECK
1240 n_iter++; 1273 n_iter++;
1241 c_mode = 1274 c_mode =
1242#endif 1275#endif
1243 prepare_for_delete_or_cut(th, p_s_inode, p_s_path, p_s_item_key, &n_removed, &n_del_size, max_reiserfs_offset (p_s_inode)); 1276 prepare_for_delete_or_cut(th, p_s_inode, p_s_path,
1244 1277 p_s_item_key, &n_removed,
1245 RFALSE( c_mode != M_DELETE, "PAP-5320: mode must be M_DELETE"); 1278 &n_del_size,
1246 1279 max_reiserfs_offset(p_s_inode));
1247 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); 1280
1248 s_del_balance.insert_size[0] = n_del_size; 1281 RFALSE(c_mode != M_DELETE, "PAP-5320: mode must be M_DELETE");
1249 1282
1250 n_ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL); 1283 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path));
1251 if ( n_ret_value != REPEAT_SEARCH ) 1284 s_del_balance.insert_size[0] = n_del_size;
1252 break; 1285
1253 1286 n_ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL);
1254 PROC_INFO_INC( p_s_sb, delete_item_restarted ); 1287 if (n_ret_value != REPEAT_SEARCH)
1288 break;
1289
1290 PROC_INFO_INC(p_s_sb, delete_item_restarted);
1291
1292 // file system changed, repeat search
1293 n_ret_value =
1294 search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path);
1295 if (n_ret_value == IO_ERROR)
1296 break;
1297 if (n_ret_value == FILE_NOT_FOUND) {
1298 reiserfs_warning(p_s_sb,
1299 "vs-5340: reiserfs_delete_item: "
1300 "no items of the file %K found",
1301 p_s_item_key);
1302 break;
1303 }
1304 } /* while (1) */
1255 1305
1256 // file system changed, repeat search 1306 if (n_ret_value != CARRY_ON) {
1257 n_ret_value = search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path); 1307 unfix_nodes(&s_del_balance);
1258 if (n_ret_value == IO_ERROR) 1308 return 0;
1259 break; 1309 }
1260 if (n_ret_value == FILE_NOT_FOUND) { 1310 // reiserfs_delete_item returns item length when success
1261 reiserfs_warning (p_s_sb, "vs-5340: reiserfs_delete_item: " 1311 n_ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE);
1262 "no items of the file %K found", p_s_item_key); 1312 q_ih = get_ih(p_s_path);
1263 break; 1313 quota_cut_bytes = ih_item_len(q_ih);
1314
1315 /* hack so the quota code doesn't have to guess if the file
1316 ** has a tail. On tail insert, we allocate quota for 1 unformatted node.
1317 ** We test the offset because the tail might have been
1318 ** split into multiple items, and we only want to decrement for
1319 ** the unfm node once
1320 */
1321 if (!S_ISLNK(p_s_inode->i_mode) && is_direct_le_ih(q_ih)) {
1322 if ((le_ih_k_offset(q_ih) & (p_s_sb->s_blocksize - 1)) == 1) {
1323 quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE;
1324 } else {
1325 quota_cut_bytes = 0;
1326 }
1264 } 1327 }
1265 } /* while (1) */
1266 1328
1267 if ( n_ret_value != CARRY_ON ) { 1329 if (p_s_un_bh) {
1268 unfix_nodes(&s_del_balance); 1330 int off;
1269 return 0; 1331 char *data;
1270 } 1332
1271 1333 /* We are in direct2indirect conversion, so move tail contents
1272 // reiserfs_delete_item returns item length when success 1334 to the unformatted node */
1273 n_ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE); 1335 /* note, we do the copy before preparing the buffer because we
1274 q_ih = get_ih(p_s_path) ; 1336 ** don't care about the contents of the unformatted node yet.
1275 quota_cut_bytes = ih_item_len(q_ih) ; 1337 ** the only thing we really care about is the direct item's data
1276 1338 ** is in the unformatted node.
1277 /* hack so the quota code doesn't have to guess if the file 1339 **
1278 ** has a tail. On tail insert, we allocate quota for 1 unformatted node. 1340 ** Otherwise, we would have to call reiserfs_prepare_for_journal on
1279 ** We test the offset because the tail might have been 1341 ** the unformatted node, which might schedule, meaning we'd have to
1280 ** split into multiple items, and we only want to decrement for 1342 ** loop all the way back up to the start of the while loop.
1281 ** the unfm node once 1343 **
1282 */ 1344 ** The unformatted node must be dirtied later on. We can't be
1283 if (!S_ISLNK (p_s_inode->i_mode) && is_direct_le_ih(q_ih)) { 1345 ** sure here if the entire tail has been deleted yet.
1284 if ((le_ih_k_offset(q_ih) & (p_s_sb->s_blocksize - 1)) == 1) { 1346 **
1285 quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE; 1347 ** p_s_un_bh is from the page cache (all unformatted nodes are
1286 } else { 1348 ** from the page cache) and might be a highmem page. So, we
1287 quota_cut_bytes = 0 ; 1349 ** can't use p_s_un_bh->b_data.
1350 ** -clm
1351 */
1352
1353 data = kmap_atomic(p_s_un_bh->b_page, KM_USER0);
1354 off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1));
1355 memcpy(data + off,
1356 B_I_PITEM(PATH_PLAST_BUFFER(p_s_path), &s_ih),
1357 n_ret_value);
1358 kunmap_atomic(data, KM_USER0);
1288 } 1359 }
1289 } 1360 /* Perform balancing after all resources have been collected at once. */
1290 1361 do_balance(&s_del_balance, NULL, NULL, M_DELETE);
1291 if ( p_s_un_bh ) {
1292 int off;
1293 char *data ;
1294
1295 /* We are in direct2indirect conversion, so move tail contents
1296 to the unformatted node */
1297 /* note, we do the copy before preparing the buffer because we
1298 ** don't care about the contents of the unformatted node yet.
1299 ** the only thing we really care about is the direct item's data
1300 ** is in the unformatted node.
1301 **
1302 ** Otherwise, we would have to call reiserfs_prepare_for_journal on
1303 ** the unformatted node, which might schedule, meaning we'd have to
1304 ** loop all the way back up to the start of the while loop.
1305 **
1306 ** The unformatted node must be dirtied later on. We can't be
1307 ** sure here if the entire tail has been deleted yet.
1308 **
1309 ** p_s_un_bh is from the page cache (all unformatted nodes are
1310 ** from the page cache) and might be a highmem page. So, we
1311 ** can't use p_s_un_bh->b_data.
1312 ** -clm
1313 */
1314
1315 data = kmap_atomic(p_s_un_bh->b_page, KM_USER0);
1316 off = ((le_ih_k_offset (&s_ih) - 1) & (PAGE_CACHE_SIZE - 1));
1317 memcpy(data + off,
1318 B_I_PITEM(PATH_PLAST_BUFFER(p_s_path), &s_ih), n_ret_value);
1319 kunmap_atomic(data, KM_USER0);
1320 }
1321 /* Perform balancing after all resources have been collected at once. */
1322 do_balance(&s_del_balance, NULL, NULL, M_DELETE);
1323 1362
1324#ifdef REISERQUOTA_DEBUG 1363#ifdef REISERQUOTA_DEBUG
1325 reiserfs_debug (p_s_sb, REISERFS_DEBUG_CODE, "reiserquota delete_item(): freeing %u, id=%u type=%c", quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih)); 1364 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
1365 "reiserquota delete_item(): freeing %u, id=%u type=%c",
1366 quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
1326#endif 1367#endif
1327 DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes); 1368 DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
1328 1369
1329 /* Return deleted body length */ 1370 /* Return deleted body length */
1330 return n_ret_value; 1371 return n_ret_value;
1331} 1372}
1332 1373
1333
1334/* Summary Of Mechanisms For Handling Collisions Between Processes: 1374/* Summary Of Mechanisms For Handling Collisions Between Processes:
1335 1375
1336 deletion of the body of the object is performed by iput(), with the 1376 deletion of the body of the object is performed by iput(), with the
@@ -1347,727 +1387,804 @@ int reiserfs_delete_item (struct reiserfs_transaction_handle *th,
1347 - Hans 1387 - Hans
1348*/ 1388*/
1349 1389
1350
1351/* this deletes item which never gets split */ 1390/* this deletes item which never gets split */
1352void reiserfs_delete_solid_item (struct reiserfs_transaction_handle *th, 1391void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
1353 struct inode *inode, 1392 struct inode *inode, struct reiserfs_key *key)
1354 struct reiserfs_key * key)
1355{ 1393{
1356 struct tree_balance tb; 1394 struct tree_balance tb;
1357 INITIALIZE_PATH (path); 1395 INITIALIZE_PATH(path);
1358 int item_len = 0; 1396 int item_len = 0;
1359 int tb_init = 0 ; 1397 int tb_init = 0;
1360 struct cpu_key cpu_key; 1398 struct cpu_key cpu_key;
1361 int retval; 1399 int retval;
1362 int quota_cut_bytes = 0; 1400 int quota_cut_bytes = 0;
1363 1401
1364 BUG_ON (!th->t_trans_id); 1402 BUG_ON(!th->t_trans_id);
1365 1403
1366 le_key2cpu_key (&cpu_key, key); 1404 le_key2cpu_key(&cpu_key, key);
1367 1405
1368 while (1) { 1406 while (1) {
1369 retval = search_item (th->t_super, &cpu_key, &path); 1407 retval = search_item(th->t_super, &cpu_key, &path);
1370 if (retval == IO_ERROR) { 1408 if (retval == IO_ERROR) {
1371 reiserfs_warning (th->t_super, 1409 reiserfs_warning(th->t_super,
1372 "vs-5350: reiserfs_delete_solid_item: " 1410 "vs-5350: reiserfs_delete_solid_item: "
1373 "i/o failure occurred trying to delete %K", 1411 "i/o failure occurred trying to delete %K",
1374 &cpu_key); 1412 &cpu_key);
1375 break; 1413 break;
1376 } 1414 }
1377 if (retval != ITEM_FOUND) { 1415 if (retval != ITEM_FOUND) {
1378 pathrelse (&path); 1416 pathrelse(&path);
1379 // No need for a warning, if there is just no free space to insert '..' item into the newly-created subdir 1417 // No need for a warning, if there is just no free space to insert '..' item into the newly-created subdir
1380 if ( !( (unsigned long long) GET_HASH_VALUE (le_key_k_offset (le_key_version (key), key)) == 0 && \ 1418 if (!
1381 (unsigned long long) GET_GENERATION_NUMBER (le_key_k_offset (le_key_version (key), key)) == 1 ) ) 1419 ((unsigned long long)
1382 reiserfs_warning (th->t_super, "vs-5355: reiserfs_delete_solid_item: %k not found", key); 1420 GET_HASH_VALUE(le_key_k_offset
1383 break; 1421 (le_key_version(key), key)) == 0
1384 } 1422 && (unsigned long long)
1385 if (!tb_init) { 1423 GET_GENERATION_NUMBER(le_key_k_offset
1386 tb_init = 1 ; 1424 (le_key_version(key),
1387 item_len = ih_item_len( PATH_PITEM_HEAD(&path) ); 1425 key)) == 1))
1388 init_tb_struct (th, &tb, th->t_super, &path, - (IH_SIZE + item_len)); 1426 reiserfs_warning(th->t_super,
1389 } 1427 "vs-5355: reiserfs_delete_solid_item: %k not found",
1390 quota_cut_bytes = ih_item_len(PATH_PITEM_HEAD(&path)) ; 1428 key);
1429 break;
1430 }
1431 if (!tb_init) {
1432 tb_init = 1;
1433 item_len = ih_item_len(PATH_PITEM_HEAD(&path));
1434 init_tb_struct(th, &tb, th->t_super, &path,
1435 -(IH_SIZE + item_len));
1436 }
1437 quota_cut_bytes = ih_item_len(PATH_PITEM_HEAD(&path));
1391 1438
1392 retval = fix_nodes (M_DELETE, &tb, NULL, NULL); 1439 retval = fix_nodes(M_DELETE, &tb, NULL, NULL);
1393 if (retval == REPEAT_SEARCH) { 1440 if (retval == REPEAT_SEARCH) {
1394 PROC_INFO_INC( th -> t_super, delete_solid_item_restarted ); 1441 PROC_INFO_INC(th->t_super, delete_solid_item_restarted);
1395 continue; 1442 continue;
1396 } 1443 }
1397 1444
1398 if (retval == CARRY_ON) { 1445 if (retval == CARRY_ON) {
1399 do_balance (&tb, NULL, NULL, M_DELETE); 1446 do_balance(&tb, NULL, NULL, M_DELETE);
1400 if (inode) { /* Should we count quota for item? (we don't count quotas for save-links) */ 1447 if (inode) { /* Should we count quota for item? (we don't count quotas for save-links) */
1401#ifdef REISERQUOTA_DEBUG 1448#ifdef REISERQUOTA_DEBUG
1402 reiserfs_debug (th->t_super, REISERFS_DEBUG_CODE, "reiserquota delete_solid_item(): freeing %u id=%u type=%c", quota_cut_bytes, inode->i_uid, key2type(key)); 1449 reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE,
1450 "reiserquota delete_solid_item(): freeing %u id=%u type=%c",
1451 quota_cut_bytes, inode->i_uid,
1452 key2type(key));
1403#endif 1453#endif
1404 DQUOT_FREE_SPACE_NODIRTY(inode, quota_cut_bytes); 1454 DQUOT_FREE_SPACE_NODIRTY(inode,
1405 } 1455 quota_cut_bytes);
1406 break; 1456 }
1457 break;
1458 }
1459 // IO_ERROR, NO_DISK_SPACE, etc
1460 reiserfs_warning(th->t_super,
1461 "vs-5360: reiserfs_delete_solid_item: "
1462 "could not delete %K due to fix_nodes failure",
1463 &cpu_key);
1464 unfix_nodes(&tb);
1465 break;
1407 } 1466 }
1408 1467
1409 // IO_ERROR, NO_DISK_SPACE, etc 1468 reiserfs_check_path(&path);
1410 reiserfs_warning (th->t_super, "vs-5360: reiserfs_delete_solid_item: "
1411 "could not delete %K due to fix_nodes failure", &cpu_key);
1412 unfix_nodes (&tb);
1413 break;
1414 }
1415
1416 reiserfs_check_path(&path) ;
1417} 1469}
1418 1470
1419 1471int reiserfs_delete_object(struct reiserfs_transaction_handle *th,
1420int reiserfs_delete_object (struct reiserfs_transaction_handle *th, struct inode * inode) 1472 struct inode *inode)
1421{ 1473{
1422 int err; 1474 int err;
1423 inode->i_size = 0; 1475 inode->i_size = 0;
1424 BUG_ON (!th->t_trans_id); 1476 BUG_ON(!th->t_trans_id);
1425 1477
1426 /* for directory this deletes item containing "." and ".." */ 1478 /* for directory this deletes item containing "." and ".." */
1427 err = reiserfs_do_truncate (th, inode, NULL, 0/*no timestamp updates*/); 1479 err =
1428 if (err) 1480 reiserfs_do_truncate(th, inode, NULL, 0 /*no timestamp updates */ );
1429 return err; 1481 if (err)
1430 1482 return err;
1483
1431#if defined( USE_INODE_GENERATION_COUNTER ) 1484#if defined( USE_INODE_GENERATION_COUNTER )
1432 if( !old_format_only ( th -> t_super ) ) 1485 if (!old_format_only(th->t_super)) {
1433 { 1486 __le32 *inode_generation;
1434 __le32 *inode_generation; 1487
1435 1488 inode_generation =
1436 inode_generation = 1489 &REISERFS_SB(th->t_super)->s_rs->s_inode_generation;
1437 &REISERFS_SB(th -> t_super) -> s_rs -> s_inode_generation; 1490 *inode_generation =
1438 *inode_generation = cpu_to_le32( le32_to_cpu( *inode_generation ) + 1 ); 1491 cpu_to_le32(le32_to_cpu(*inode_generation) + 1);
1439 } 1492 }
1440/* USE_INODE_GENERATION_COUNTER */ 1493/* USE_INODE_GENERATION_COUNTER */
1441#endif 1494#endif
1442 reiserfs_delete_solid_item (th, inode, INODE_PKEY (inode)); 1495 reiserfs_delete_solid_item(th, inode, INODE_PKEY(inode));
1443 1496
1444 return err; 1497 return err;
1445} 1498}
1446 1499
1447static void 1500static void unmap_buffers(struct page *page, loff_t pos)
1448unmap_buffers(struct page *page, loff_t pos) { 1501{
1449 struct buffer_head *bh ; 1502 struct buffer_head *bh;
1450 struct buffer_head *head ; 1503 struct buffer_head *head;
1451 struct buffer_head *next ; 1504 struct buffer_head *next;
1452 unsigned long tail_index ; 1505 unsigned long tail_index;
1453 unsigned long cur_index ; 1506 unsigned long cur_index;
1454 1507
1455 if (page) { 1508 if (page) {
1456 if (page_has_buffers(page)) { 1509 if (page_has_buffers(page)) {
1457 tail_index = pos & (PAGE_CACHE_SIZE - 1) ; 1510 tail_index = pos & (PAGE_CACHE_SIZE - 1);
1458 cur_index = 0 ; 1511 cur_index = 0;
1459 head = page_buffers(page) ; 1512 head = page_buffers(page);
1460 bh = head ; 1513 bh = head;
1461 do { 1514 do {
1462 next = bh->b_this_page ; 1515 next = bh->b_this_page;
1463 1516
1464 /* we want to unmap the buffers that contain the tail, and 1517 /* we want to unmap the buffers that contain the tail, and
1465 ** all the buffers after it (since the tail must be at the 1518 ** all the buffers after it (since the tail must be at the
1466 ** end of the file). We don't want to unmap file data 1519 ** end of the file). We don't want to unmap file data
1467 ** before the tail, since it might be dirty and waiting to 1520 ** before the tail, since it might be dirty and waiting to
1468 ** reach disk 1521 ** reach disk
1469 */ 1522 */
1470 cur_index += bh->b_size ; 1523 cur_index += bh->b_size;
1471 if (cur_index > tail_index) { 1524 if (cur_index > tail_index) {
1472 reiserfs_unmap_buffer(bh) ; 1525 reiserfs_unmap_buffer(bh);
1526 }
1527 bh = next;
1528 } while (bh != head);
1529 if (PAGE_SIZE == bh->b_size) {
1530 clear_page_dirty(page);
1531 }
1473 } 1532 }
1474 bh = next ;
1475 } while (bh != head) ;
1476 if ( PAGE_SIZE == bh->b_size ) {
1477 clear_page_dirty(page);
1478 }
1479 } 1533 }
1480 }
1481} 1534}
1482 1535
1483static int maybe_indirect_to_direct (struct reiserfs_transaction_handle *th, 1536static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
1484 struct inode * p_s_inode, 1537 struct inode *p_s_inode,
1485 struct page *page, 1538 struct page *page,
1486 struct path * p_s_path, 1539 struct path *p_s_path,
1487 const struct cpu_key * p_s_item_key, 1540 const struct cpu_key *p_s_item_key,
1488 loff_t n_new_file_size, 1541 loff_t n_new_file_size, char *p_c_mode)
1489 char * p_c_mode 1542{
1490 ) { 1543 struct super_block *p_s_sb = p_s_inode->i_sb;
1491 struct super_block * p_s_sb = p_s_inode->i_sb; 1544 int n_block_size = p_s_sb->s_blocksize;
1492 int n_block_size = p_s_sb->s_blocksize; 1545 int cut_bytes;
1493 int cut_bytes; 1546 BUG_ON(!th->t_trans_id);
1494 BUG_ON (!th->t_trans_id); 1547
1495 1548 if (n_new_file_size != p_s_inode->i_size)
1496 if (n_new_file_size != p_s_inode->i_size) 1549 BUG();
1497 BUG ();
1498
1499 /* the page being sent in could be NULL if there was an i/o error
1500 ** reading in the last block. The user will hit problems trying to
1501 ** read the file, but for now we just skip the indirect2direct
1502 */
1503 if (atomic_read(&p_s_inode->i_count) > 1 ||
1504 !tail_has_to_be_packed (p_s_inode) ||
1505 !page || (REISERFS_I(p_s_inode)->i_flags & i_nopack_mask)) {
1506 // leave tail in an unformatted node
1507 *p_c_mode = M_SKIP_BALANCING;
1508 cut_bytes = n_block_size - (n_new_file_size & (n_block_size - 1));
1509 pathrelse(p_s_path);
1510 return cut_bytes;
1511 }
1512 /* Permorm the conversion to a direct_item. */
1513 /*return indirect_to_direct (p_s_inode, p_s_path, p_s_item_key, n_new_file_size, p_c_mode);*/
1514 return indirect2direct (th, p_s_inode, page, p_s_path, p_s_item_key, n_new_file_size, p_c_mode);
1515}
1516 1550
1551 /* the page being sent in could be NULL if there was an i/o error
1552 ** reading in the last block. The user will hit problems trying to
1553 ** read the file, but for now we just skip the indirect2direct
1554 */
1555 if (atomic_read(&p_s_inode->i_count) > 1 ||
1556 !tail_has_to_be_packed(p_s_inode) ||
1557 !page || (REISERFS_I(p_s_inode)->i_flags & i_nopack_mask)) {
1558 // leave tail in an unformatted node
1559 *p_c_mode = M_SKIP_BALANCING;
1560 cut_bytes =
1561 n_block_size - (n_new_file_size & (n_block_size - 1));
1562 pathrelse(p_s_path);
1563 return cut_bytes;
1564 }
1565 /* Permorm the conversion to a direct_item. */
1566 /*return indirect_to_direct (p_s_inode, p_s_path, p_s_item_key, n_new_file_size, p_c_mode); */
1567 return indirect2direct(th, p_s_inode, page, p_s_path, p_s_item_key,
1568 n_new_file_size, p_c_mode);
1569}
1517 1570
1518/* we did indirect_to_direct conversion. And we have inserted direct 1571/* we did indirect_to_direct conversion. And we have inserted direct
1519 item successesfully, but there were no disk space to cut unfm 1572 item successesfully, but there were no disk space to cut unfm
1520 pointer being converted. Therefore we have to delete inserted 1573 pointer being converted. Therefore we have to delete inserted
1521 direct item(s) */ 1574 direct item(s) */
1522static void indirect_to_direct_roll_back (struct reiserfs_transaction_handle *th, struct inode * inode, struct path * path) 1575static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th,
1576 struct inode *inode, struct path *path)
1523{ 1577{
1524 struct cpu_key tail_key; 1578 struct cpu_key tail_key;
1525 int tail_len; 1579 int tail_len;
1526 int removed; 1580 int removed;
1527 BUG_ON (!th->t_trans_id); 1581 BUG_ON(!th->t_trans_id);
1528 1582
1529 make_cpu_key (&tail_key, inode, inode->i_size + 1, TYPE_DIRECT, 4);// !!!! 1583 make_cpu_key(&tail_key, inode, inode->i_size + 1, TYPE_DIRECT, 4); // !!!!
1530 tail_key.key_length = 4; 1584 tail_key.key_length = 4;
1531 1585
1532 tail_len = (cpu_key_k_offset (&tail_key) & (inode->i_sb->s_blocksize - 1)) - 1; 1586 tail_len =
1533 while (tail_len) { 1587 (cpu_key_k_offset(&tail_key) & (inode->i_sb->s_blocksize - 1)) - 1;
1534 /* look for the last byte of the tail */ 1588 while (tail_len) {
1535 if (search_for_position_by_key (inode->i_sb, &tail_key, path) == POSITION_NOT_FOUND) 1589 /* look for the last byte of the tail */
1536 reiserfs_panic (inode->i_sb, "vs-5615: indirect_to_direct_roll_back: found invalid item"); 1590 if (search_for_position_by_key(inode->i_sb, &tail_key, path) ==
1537 RFALSE( path->pos_in_item != ih_item_len(PATH_PITEM_HEAD (path)) - 1, 1591 POSITION_NOT_FOUND)
1538 "vs-5616: appended bytes found"); 1592 reiserfs_panic(inode->i_sb,
1539 PATH_LAST_POSITION (path) --; 1593 "vs-5615: indirect_to_direct_roll_back: found invalid item");
1540 1594 RFALSE(path->pos_in_item !=
1541 removed = reiserfs_delete_item (th, path, &tail_key, inode, NULL/*unbh not needed*/); 1595 ih_item_len(PATH_PITEM_HEAD(path)) - 1,
1542 RFALSE( removed <= 0 || removed > tail_len, 1596 "vs-5616: appended bytes found");
1543 "vs-5617: there was tail %d bytes, removed item length %d bytes", 1597 PATH_LAST_POSITION(path)--;
1544 tail_len, removed); 1598
1545 tail_len -= removed; 1599 removed =
1546 set_cpu_key_k_offset (&tail_key, cpu_key_k_offset (&tail_key) - removed); 1600 reiserfs_delete_item(th, path, &tail_key, inode,
1547 } 1601 NULL /*unbh not needed */ );
1548 reiserfs_warning (inode->i_sb, "indirect_to_direct_roll_back: indirect_to_direct conversion has been rolled back due to lack of disk space"); 1602 RFALSE(removed <= 0
1549 //mark_file_without_tail (inode); 1603 || removed > tail_len,
1550 mark_inode_dirty (inode); 1604 "vs-5617: there was tail %d bytes, removed item length %d bytes",
1605 tail_len, removed);
1606 tail_len -= removed;
1607 set_cpu_key_k_offset(&tail_key,
1608 cpu_key_k_offset(&tail_key) - removed);
1609 }
1610 reiserfs_warning(inode->i_sb,
1611 "indirect_to_direct_roll_back: indirect_to_direct conversion has been rolled back due to lack of disk space");
1612 //mark_file_without_tail (inode);
1613 mark_inode_dirty(inode);
1551} 1614}
1552 1615
1553
1554/* (Truncate or cut entry) or delete object item. Returns < 0 on failure */ 1616/* (Truncate or cut entry) or delete object item. Returns < 0 on failure */
1555int reiserfs_cut_from_item (struct reiserfs_transaction_handle *th, 1617int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1556 struct path * p_s_path, 1618 struct path *p_s_path,
1557 struct cpu_key * p_s_item_key, 1619 struct cpu_key *p_s_item_key,
1558 struct inode * p_s_inode, 1620 struct inode *p_s_inode,
1559 struct page *page, 1621 struct page *page, loff_t n_new_file_size)
1560 loff_t n_new_file_size)
1561{ 1622{
1562 struct super_block * p_s_sb = p_s_inode->i_sb; 1623 struct super_block *p_s_sb = p_s_inode->i_sb;
1563 /* Every function which is going to call do_balance must first 1624 /* Every function which is going to call do_balance must first
1564 create a tree_balance structure. Then it must fill up this 1625 create a tree_balance structure. Then it must fill up this
1565 structure by using the init_tb_struct and fix_nodes functions. 1626 structure by using the init_tb_struct and fix_nodes functions.
1566 After that we can make tree balancing. */ 1627 After that we can make tree balancing. */
1567 struct tree_balance s_cut_balance; 1628 struct tree_balance s_cut_balance;
1568 struct item_head *p_le_ih; 1629 struct item_head *p_le_ih;
1569 int n_cut_size = 0, /* Amount to be cut. */ 1630 int n_cut_size = 0, /* Amount to be cut. */
1570 n_ret_value = CARRY_ON, 1631 n_ret_value = CARRY_ON, n_removed = 0, /* Number of the removed unformatted nodes. */
1571 n_removed = 0, /* Number of the removed unformatted nodes. */ 1632 n_is_inode_locked = 0;
1572 n_is_inode_locked = 0; 1633 char c_mode; /* Mode of the balance. */
1573 char c_mode; /* Mode of the balance. */ 1634 int retval2 = -1;
1574 int retval2 = -1; 1635 int quota_cut_bytes;
1575 int quota_cut_bytes; 1636 loff_t tail_pos = 0;
1576 loff_t tail_pos = 0; 1637
1577 1638 BUG_ON(!th->t_trans_id);
1578 BUG_ON (!th->t_trans_id); 1639
1579 1640 init_tb_struct(th, &s_cut_balance, p_s_inode->i_sb, p_s_path,
1580 init_tb_struct(th, &s_cut_balance, p_s_inode->i_sb, p_s_path, n_cut_size); 1641 n_cut_size);
1581 1642
1582 1643 /* Repeat this loop until we either cut the item without needing
1583 /* Repeat this loop until we either cut the item without needing 1644 to balance, or we fix_nodes without schedule occurring */
1584 to balance, or we fix_nodes without schedule occurring */ 1645 while (1) {
1585 while ( 1 ) { 1646 /* Determine the balance mode, position of the first byte to
1586 /* Determine the balance mode, position of the first byte to 1647 be cut, and size to be cut. In case of the indirect item
1587 be cut, and size to be cut. In case of the indirect item 1648 free unformatted nodes which are pointed to by the cut
1588 free unformatted nodes which are pointed to by the cut 1649 pointers. */
1589 pointers. */ 1650
1590 1651 c_mode =
1591 c_mode = prepare_for_delete_or_cut(th, p_s_inode, p_s_path, p_s_item_key, &n_removed, 1652 prepare_for_delete_or_cut(th, p_s_inode, p_s_path,
1592 &n_cut_size, n_new_file_size); 1653 p_s_item_key, &n_removed,
1593 if ( c_mode == M_CONVERT ) { 1654 &n_cut_size, n_new_file_size);
1594 /* convert last unformatted node to direct item or leave 1655 if (c_mode == M_CONVERT) {
1595 tail in the unformatted node */ 1656 /* convert last unformatted node to direct item or leave
1596 RFALSE( n_ret_value != CARRY_ON, "PAP-5570: can not convert twice"); 1657 tail in the unformatted node */
1597 1658 RFALSE(n_ret_value != CARRY_ON,
1598 n_ret_value = maybe_indirect_to_direct (th, p_s_inode, page, p_s_path, p_s_item_key, 1659 "PAP-5570: can not convert twice");
1599 n_new_file_size, &c_mode); 1660
1600 if ( c_mode == M_SKIP_BALANCING ) 1661 n_ret_value =
1601 /* tail has been left in the unformatted node */ 1662 maybe_indirect_to_direct(th, p_s_inode, page,
1602 return n_ret_value; 1663 p_s_path, p_s_item_key,
1603 1664 n_new_file_size, &c_mode);
1604 n_is_inode_locked = 1; 1665 if (c_mode == M_SKIP_BALANCING)
1605 1666 /* tail has been left in the unformatted node */
1606 /* removing of last unformatted node will change value we 1667 return n_ret_value;
1607 have to return to truncate. Save it */ 1668
1608 retval2 = n_ret_value; 1669 n_is_inode_locked = 1;
1609 /*retval2 = p_s_sb->s_blocksize - (n_new_file_size & (p_s_sb->s_blocksize - 1));*/ 1670
1610 1671 /* removing of last unformatted node will change value we
1611 /* So, we have performed the first part of the conversion: 1672 have to return to truncate. Save it */
1612 inserting the new direct item. Now we are removing the 1673 retval2 = n_ret_value;
1613 last unformatted node pointer. Set key to search for 1674 /*retval2 = p_s_sb->s_blocksize - (n_new_file_size & (p_s_sb->s_blocksize - 1)); */
1614 it. */ 1675
1615 set_cpu_key_k_type (p_s_item_key, TYPE_INDIRECT); 1676 /* So, we have performed the first part of the conversion:
1616 p_s_item_key->key_length = 4; 1677 inserting the new direct item. Now we are removing the
1617 n_new_file_size -= (n_new_file_size & (p_s_sb->s_blocksize - 1)); 1678 last unformatted node pointer. Set key to search for
1618 tail_pos = n_new_file_size; 1679 it. */
1619 set_cpu_key_k_offset (p_s_item_key, n_new_file_size + 1); 1680 set_cpu_key_k_type(p_s_item_key, TYPE_INDIRECT);
1620 if ( search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path) == POSITION_NOT_FOUND ){ 1681 p_s_item_key->key_length = 4;
1621 print_block (PATH_PLAST_BUFFER (p_s_path), 3, PATH_LAST_POSITION (p_s_path) - 1, PATH_LAST_POSITION (p_s_path) + 1); 1682 n_new_file_size -=
1622 reiserfs_panic(p_s_sb, "PAP-5580: reiserfs_cut_from_item: item to convert does not exist (%K)", p_s_item_key); 1683 (n_new_file_size & (p_s_sb->s_blocksize - 1));
1623 } 1684 tail_pos = n_new_file_size;
1624 continue; 1685 set_cpu_key_k_offset(p_s_item_key, n_new_file_size + 1);
1625 } 1686 if (search_for_position_by_key
1626 if (n_cut_size == 0) { 1687 (p_s_sb, p_s_item_key,
1627 pathrelse (p_s_path); 1688 p_s_path) == POSITION_NOT_FOUND) {
1628 return 0; 1689 print_block(PATH_PLAST_BUFFER(p_s_path), 3,
1629 } 1690 PATH_LAST_POSITION(p_s_path) - 1,
1691 PATH_LAST_POSITION(p_s_path) + 1);
1692 reiserfs_panic(p_s_sb,
1693 "PAP-5580: reiserfs_cut_from_item: item to convert does not exist (%K)",
1694 p_s_item_key);
1695 }
1696 continue;
1697 }
1698 if (n_cut_size == 0) {
1699 pathrelse(p_s_path);
1700 return 0;
1701 }
1702
1703 s_cut_balance.insert_size[0] = n_cut_size;
1704
1705 n_ret_value = fix_nodes(c_mode, &s_cut_balance, NULL, NULL);
1706 if (n_ret_value != REPEAT_SEARCH)
1707 break;
1708
1709 PROC_INFO_INC(p_s_sb, cut_from_item_restarted);
1710
1711 n_ret_value =
1712 search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path);
1713 if (n_ret_value == POSITION_FOUND)
1714 continue;
1630 1715
1631 s_cut_balance.insert_size[0] = n_cut_size; 1716 reiserfs_warning(p_s_sb,
1632 1717 "PAP-5610: reiserfs_cut_from_item: item %K not found",
1633 n_ret_value = fix_nodes(c_mode, &s_cut_balance, NULL, NULL); 1718 p_s_item_key);
1634 if ( n_ret_value != REPEAT_SEARCH ) 1719 unfix_nodes(&s_cut_balance);
1635 break; 1720 return (n_ret_value == IO_ERROR) ? -EIO : -ENOENT;
1636 1721 } /* while */
1637 PROC_INFO_INC( p_s_sb, cut_from_item_restarted ); 1722
1638 1723 // check fix_nodes results (IO_ERROR or NO_DISK_SPACE)
1639 n_ret_value = search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path); 1724 if (n_ret_value != CARRY_ON) {
1640 if (n_ret_value == POSITION_FOUND) 1725 if (n_is_inode_locked) {
1641 continue; 1726 // FIXME: this seems to be not needed: we are always able
1642 1727 // to cut item
1643 reiserfs_warning (p_s_sb, "PAP-5610: reiserfs_cut_from_item: item %K not found", p_s_item_key); 1728 indirect_to_direct_roll_back(th, p_s_inode, p_s_path);
1644 unfix_nodes (&s_cut_balance); 1729 }
1645 return (n_ret_value == IO_ERROR) ? -EIO : -ENOENT; 1730 if (n_ret_value == NO_DISK_SPACE)
1646 } /* while */ 1731 reiserfs_warning(p_s_sb, "NO_DISK_SPACE");
1647 1732 unfix_nodes(&s_cut_balance);
1648 // check fix_nodes results (IO_ERROR or NO_DISK_SPACE) 1733 return -EIO;
1649 if ( n_ret_value != CARRY_ON ) {
1650 if ( n_is_inode_locked ) {
1651 // FIXME: this seems to be not needed: we are always able
1652 // to cut item
1653 indirect_to_direct_roll_back (th, p_s_inode, p_s_path);
1654 } 1734 }
1655 if (n_ret_value == NO_DISK_SPACE) 1735
1656 reiserfs_warning (p_s_sb, "NO_DISK_SPACE"); 1736 /* go ahead and perform balancing */
1657 unfix_nodes (&s_cut_balance); 1737
1658 return -EIO; 1738 RFALSE(c_mode == M_PASTE || c_mode == M_INSERT, "invalid mode");
1659 } 1739
1660 1740 /* Calculate number of bytes that need to be cut from the item. */
1661 /* go ahead and perform balancing */ 1741 quota_cut_bytes =
1662 1742 (c_mode ==
1663 RFALSE( c_mode == M_PASTE || c_mode == M_INSERT, "invalid mode"); 1743 M_DELETE) ? ih_item_len(get_ih(p_s_path)) : -s_cut_balance.
1664 1744 insert_size[0];
1665 /* Calculate number of bytes that need to be cut from the item. */ 1745 if (retval2 == -1)
1666 quota_cut_bytes = ( c_mode == M_DELETE ) ? ih_item_len(get_ih(p_s_path)) : -s_cut_balance.insert_size[0]; 1746 n_ret_value = calc_deleted_bytes_number(&s_cut_balance, c_mode);
1667 if (retval2 == -1) 1747 else
1668 n_ret_value = calc_deleted_bytes_number(&s_cut_balance, c_mode); 1748 n_ret_value = retval2;
1669 else 1749
1670 n_ret_value = retval2; 1750 /* For direct items, we only change the quota when deleting the last
1671 1751 ** item.
1672 1752 */
1673 /* For direct items, we only change the quota when deleting the last 1753 p_le_ih = PATH_PITEM_HEAD(s_cut_balance.tb_path);
1674 ** item. 1754 if (!S_ISLNK(p_s_inode->i_mode) && is_direct_le_ih(p_le_ih)) {
1675 */ 1755 if (c_mode == M_DELETE &&
1676 p_le_ih = PATH_PITEM_HEAD (s_cut_balance.tb_path); 1756 (le_ih_k_offset(p_le_ih) & (p_s_sb->s_blocksize - 1)) ==
1677 if (!S_ISLNK (p_s_inode->i_mode) && is_direct_le_ih(p_le_ih)) { 1757 1) {
1678 if (c_mode == M_DELETE && 1758 // FIXME: this is to keep 3.5 happy
1679 (le_ih_k_offset (p_le_ih) & (p_s_sb->s_blocksize - 1)) == 1 ) { 1759 REISERFS_I(p_s_inode)->i_first_direct_byte = U32_MAX;
1680 // FIXME: this is to keep 3.5 happy 1760 quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE;
1681 REISERFS_I(p_s_inode)->i_first_direct_byte = U32_MAX; 1761 } else {
1682 quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE ; 1762 quota_cut_bytes = 0;
1683 } else { 1763 }
1684 quota_cut_bytes = 0 ;
1685 } 1764 }
1686 }
1687#ifdef CONFIG_REISERFS_CHECK 1765#ifdef CONFIG_REISERFS_CHECK
1688 if (n_is_inode_locked) { 1766 if (n_is_inode_locked) {
1689 struct item_head * le_ih = PATH_PITEM_HEAD (s_cut_balance.tb_path); 1767 struct item_head *le_ih =
1690 /* we are going to complete indirect2direct conversion. Make 1768 PATH_PITEM_HEAD(s_cut_balance.tb_path);
1691 sure, that we exactly remove last unformatted node pointer 1769 /* we are going to complete indirect2direct conversion. Make
1692 of the item */ 1770 sure, that we exactly remove last unformatted node pointer
1693 if (!is_indirect_le_ih (le_ih)) 1771 of the item */
1694 reiserfs_panic (p_s_sb, "vs-5652: reiserfs_cut_from_item: " 1772 if (!is_indirect_le_ih(le_ih))
1695 "item must be indirect %h", le_ih); 1773 reiserfs_panic(p_s_sb,
1696 1774 "vs-5652: reiserfs_cut_from_item: "
1697 if (c_mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE) 1775 "item must be indirect %h", le_ih);
1698 reiserfs_panic (p_s_sb, "vs-5653: reiserfs_cut_from_item: " 1776
1699 "completing indirect2direct conversion indirect item %h " 1777 if (c_mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE)
1700 "being deleted must be of 4 byte long", le_ih); 1778 reiserfs_panic(p_s_sb,
1701 1779 "vs-5653: reiserfs_cut_from_item: "
1702 if (c_mode == M_CUT && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) { 1780 "completing indirect2direct conversion indirect item %h "
1703 reiserfs_panic (p_s_sb, "vs-5654: reiserfs_cut_from_item: " 1781 "being deleted must be of 4 byte long",
1704 "can not complete indirect2direct conversion of %h (CUT, insert_size==%d)", 1782 le_ih);
1705 le_ih, s_cut_balance.insert_size[0]); 1783
1784 if (c_mode == M_CUT
1785 && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) {
1786 reiserfs_panic(p_s_sb,
1787 "vs-5654: reiserfs_cut_from_item: "
1788 "can not complete indirect2direct conversion of %h (CUT, insert_size==%d)",
1789 le_ih, s_cut_balance.insert_size[0]);
1790 }
1791 /* it would be useful to make sure, that right neighboring
1792 item is direct item of this file */
1706 } 1793 }
1707 /* it would be useful to make sure, that right neighboring
1708 item is direct item of this file */
1709 }
1710#endif 1794#endif
1711 1795
1712 do_balance(&s_cut_balance, NULL, NULL, c_mode); 1796 do_balance(&s_cut_balance, NULL, NULL, c_mode);
1713 if ( n_is_inode_locked ) { 1797 if (n_is_inode_locked) {
1714 /* we've done an indirect->direct conversion. when the data block 1798 /* we've done an indirect->direct conversion. when the data block
1715 ** was freed, it was removed from the list of blocks that must 1799 ** was freed, it was removed from the list of blocks that must
1716 ** be flushed before the transaction commits, make sure to 1800 ** be flushed before the transaction commits, make sure to
1717 ** unmap and invalidate it 1801 ** unmap and invalidate it
1718 */ 1802 */
1719 unmap_buffers(page, tail_pos); 1803 unmap_buffers(page, tail_pos);
1720 REISERFS_I(p_s_inode)->i_flags &= ~i_pack_on_close_mask ; 1804 REISERFS_I(p_s_inode)->i_flags &= ~i_pack_on_close_mask;
1721 } 1805 }
1722#ifdef REISERQUOTA_DEBUG 1806#ifdef REISERQUOTA_DEBUG
1723 reiserfs_debug (p_s_inode->i_sb, REISERFS_DEBUG_CODE, "reiserquota cut_from_item(): freeing %u id=%u type=%c", quota_cut_bytes, p_s_inode->i_uid, '?'); 1807 reiserfs_debug(p_s_inode->i_sb, REISERFS_DEBUG_CODE,
1808 "reiserquota cut_from_item(): freeing %u id=%u type=%c",
1809 quota_cut_bytes, p_s_inode->i_uid, '?');
1724#endif 1810#endif
1725 DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes); 1811 DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
1726 return n_ret_value; 1812 return n_ret_value;
1727} 1813}
1728 1814
1729static void truncate_directory (struct reiserfs_transaction_handle *th, struct inode * inode) 1815static void truncate_directory(struct reiserfs_transaction_handle *th,
1816 struct inode *inode)
1730{ 1817{
1731 BUG_ON (!th->t_trans_id); 1818 BUG_ON(!th->t_trans_id);
1732 if (inode->i_nlink) 1819 if (inode->i_nlink)
1733 reiserfs_warning (inode->i_sb, 1820 reiserfs_warning(inode->i_sb,
1734 "vs-5655: truncate_directory: link count != 0"); 1821 "vs-5655: truncate_directory: link count != 0");
1735 1822
1736 set_le_key_k_offset (KEY_FORMAT_3_5, INODE_PKEY (inode), DOT_OFFSET); 1823 set_le_key_k_offset(KEY_FORMAT_3_5, INODE_PKEY(inode), DOT_OFFSET);
1737 set_le_key_k_type (KEY_FORMAT_3_5, INODE_PKEY (inode), TYPE_DIRENTRY); 1824 set_le_key_k_type(KEY_FORMAT_3_5, INODE_PKEY(inode), TYPE_DIRENTRY);
1738 reiserfs_delete_solid_item (th, inode, INODE_PKEY (inode)); 1825 reiserfs_delete_solid_item(th, inode, INODE_PKEY(inode));
1739 reiserfs_update_sd(th, inode) ; 1826 reiserfs_update_sd(th, inode);
1740 set_le_key_k_offset (KEY_FORMAT_3_5, INODE_PKEY (inode), SD_OFFSET); 1827 set_le_key_k_offset(KEY_FORMAT_3_5, INODE_PKEY(inode), SD_OFFSET);
1741 set_le_key_k_type (KEY_FORMAT_3_5, INODE_PKEY (inode), TYPE_STAT_DATA); 1828 set_le_key_k_type(KEY_FORMAT_3_5, INODE_PKEY(inode), TYPE_STAT_DATA);
1742} 1829}
1743 1830
1831/* Truncate file to the new size. Note, this must be called with a transaction
1832 already started */
1833int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p_s_inode, /* ->i_size contains new
1834 size */
1835 struct page *page, /* up to date for last block */
1836 int update_timestamps /* when it is called by
1837 file_release to convert
1838 the tail - no timestamps
1839 should be updated */
1840 )
1841{
1842 INITIALIZE_PATH(s_search_path); /* Path to the current object item. */
1843 struct item_head *p_le_ih; /* Pointer to an item header. */
1844 struct cpu_key s_item_key; /* Key to search for a previous file item. */
1845 loff_t n_file_size, /* Old file size. */
1846 n_new_file_size; /* New file size. */
1847 int n_deleted; /* Number of deleted or truncated bytes. */
1848 int retval;
1849 int err = 0;
1850
1851 BUG_ON(!th->t_trans_id);
1852 if (!
1853 (S_ISREG(p_s_inode->i_mode) || S_ISDIR(p_s_inode->i_mode)
1854 || S_ISLNK(p_s_inode->i_mode)))
1855 return 0;
1856
1857 if (S_ISDIR(p_s_inode->i_mode)) {
1858 // deletion of directory - no need to update timestamps
1859 truncate_directory(th, p_s_inode);
1860 return 0;
1861 }
1744 1862
1863 /* Get new file size. */
1864 n_new_file_size = p_s_inode->i_size;
1745 1865
1866 // FIXME: note, that key type is unimportant here
1867 make_cpu_key(&s_item_key, p_s_inode, max_reiserfs_offset(p_s_inode),
1868 TYPE_DIRECT, 3);
1746 1869
1747/* Truncate file to the new size. Note, this must be called with a transaction 1870 retval =
1748 already started */ 1871 search_for_position_by_key(p_s_inode->i_sb, &s_item_key,
1749int reiserfs_do_truncate (struct reiserfs_transaction_handle *th, 1872 &s_search_path);
1750 struct inode * p_s_inode, /* ->i_size contains new 1873 if (retval == IO_ERROR) {
1751 size */ 1874 reiserfs_warning(p_s_inode->i_sb,
1752 struct page *page, /* up to date for last block */ 1875 "vs-5657: reiserfs_do_truncate: "
1753 int update_timestamps /* when it is called by 1876 "i/o failure occurred trying to truncate %K",
1754 file_release to convert 1877 &s_item_key);
1755 the tail - no timestamps 1878 err = -EIO;
1756 should be updated */ 1879 goto out;
1757 ) { 1880 }
1758 INITIALIZE_PATH (s_search_path); /* Path to the current object item. */ 1881 if (retval == POSITION_FOUND || retval == FILE_NOT_FOUND) {
1759 struct item_head * p_le_ih; /* Pointer to an item header. */ 1882 reiserfs_warning(p_s_inode->i_sb,
1760 struct cpu_key s_item_key; /* Key to search for a previous file item. */ 1883 "PAP-5660: reiserfs_do_truncate: "
1761 loff_t n_file_size, /* Old file size. */ 1884 "wrong result %d of search for %K", retval,
1762 n_new_file_size;/* New file size. */ 1885 &s_item_key);
1763 int n_deleted; /* Number of deleted or truncated bytes. */ 1886
1764 int retval; 1887 err = -EIO;
1765 int err = 0; 1888 goto out;
1766 1889 }
1767 BUG_ON (!th->t_trans_id);
1768 if ( ! (S_ISREG(p_s_inode->i_mode) || S_ISDIR(p_s_inode->i_mode) || S_ISLNK(p_s_inode->i_mode)) )
1769 return 0;
1770 1890
1771 if (S_ISDIR(p_s_inode->i_mode)) { 1891 s_search_path.pos_in_item--;
1772 // deletion of directory - no need to update timestamps 1892
1773 truncate_directory (th, p_s_inode); 1893 /* Get real file size (total length of all file items) */
1774 return 0; 1894 p_le_ih = PATH_PITEM_HEAD(&s_search_path);
1775 } 1895 if (is_statdata_le_ih(p_le_ih))
1776 1896 n_file_size = 0;
1777 /* Get new file size. */ 1897 else {
1778 n_new_file_size = p_s_inode->i_size; 1898 loff_t offset = le_ih_k_offset(p_le_ih);
1779 1899 int bytes =
1780 // FIXME: note, that key type is unimportant here 1900 op_bytes_number(p_le_ih, p_s_inode->i_sb->s_blocksize);
1781 make_cpu_key (&s_item_key, p_s_inode, max_reiserfs_offset (p_s_inode), TYPE_DIRECT, 3); 1901
1782 1902 /* this may mismatch with real file size: if last direct item
1783 retval = search_for_position_by_key(p_s_inode->i_sb, &s_item_key, &s_search_path); 1903 had no padding zeros and last unformatted node had no free
1784 if (retval == IO_ERROR) { 1904 space, this file would have this file size */
1785 reiserfs_warning (p_s_inode->i_sb, "vs-5657: reiserfs_do_truncate: " 1905 n_file_size = offset + bytes - 1;
1786 "i/o failure occurred trying to truncate %K", &s_item_key); 1906 }
1787 err = -EIO; 1907 /*
1788 goto out; 1908 * are we doing a full truncate or delete, if so
1789 } 1909 * kick in the reada code
1790 if (retval == POSITION_FOUND || retval == FILE_NOT_FOUND) { 1910 */
1791 reiserfs_warning (p_s_inode->i_sb, "PAP-5660: reiserfs_do_truncate: " 1911 if (n_new_file_size == 0)
1792 "wrong result %d of search for %K", retval, &s_item_key); 1912 s_search_path.reada = PATH_READA | PATH_READA_BACK;
1793 1913
1794 err = -EIO; 1914 if (n_file_size == 0 || n_file_size < n_new_file_size) {
1795 goto out; 1915 goto update_and_out;
1796 }
1797
1798 s_search_path.pos_in_item --;
1799
1800 /* Get real file size (total length of all file items) */
1801 p_le_ih = PATH_PITEM_HEAD(&s_search_path);
1802 if ( is_statdata_le_ih (p_le_ih) )
1803 n_file_size = 0;
1804 else {
1805 loff_t offset = le_ih_k_offset (p_le_ih);
1806 int bytes = op_bytes_number (p_le_ih,p_s_inode->i_sb->s_blocksize);
1807
1808 /* this may mismatch with real file size: if last direct item
1809 had no padding zeros and last unformatted node had no free
1810 space, this file would have this file size */
1811 n_file_size = offset + bytes - 1;
1812 }
1813 /*
1814 * are we doing a full truncate or delete, if so
1815 * kick in the reada code
1816 */
1817 if (n_new_file_size == 0)
1818 s_search_path.reada = PATH_READA | PATH_READA_BACK;
1819
1820 if ( n_file_size == 0 || n_file_size < n_new_file_size ) {
1821 goto update_and_out ;
1822 }
1823
1824 /* Update key to search for the last file item. */
1825 set_cpu_key_k_offset (&s_item_key, n_file_size);
1826
1827 do {
1828 /* Cut or delete file item. */
1829 n_deleted = reiserfs_cut_from_item(th, &s_search_path, &s_item_key, p_s_inode, page, n_new_file_size);
1830 if (n_deleted < 0) {
1831 reiserfs_warning (p_s_inode->i_sb, "vs-5665: reiserfs_do_truncate: reiserfs_cut_from_item failed");
1832 reiserfs_check_path(&s_search_path) ;
1833 return 0;
1834 } 1916 }
1835 1917
1836 RFALSE( n_deleted > n_file_size, 1918 /* Update key to search for the last file item. */
1837 "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K", 1919 set_cpu_key_k_offset(&s_item_key, n_file_size);
1838 n_deleted, n_file_size, &s_item_key); 1920
1921 do {
1922 /* Cut or delete file item. */
1923 n_deleted =
1924 reiserfs_cut_from_item(th, &s_search_path, &s_item_key,
1925 p_s_inode, page, n_new_file_size);
1926 if (n_deleted < 0) {
1927 reiserfs_warning(p_s_inode->i_sb,
1928 "vs-5665: reiserfs_do_truncate: reiserfs_cut_from_item failed");
1929 reiserfs_check_path(&s_search_path);
1930 return 0;
1931 }
1839 1932
1840 /* Change key to search the last file item. */ 1933 RFALSE(n_deleted > n_file_size,
1841 n_file_size -= n_deleted; 1934 "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K",
1935 n_deleted, n_file_size, &s_item_key);
1842 1936
1843 set_cpu_key_k_offset (&s_item_key, n_file_size); 1937 /* Change key to search the last file item. */
1938 n_file_size -= n_deleted;
1844 1939
1845 /* While there are bytes to truncate and previous file item is presented in the tree. */ 1940 set_cpu_key_k_offset(&s_item_key, n_file_size);
1846 1941
1847 /* 1942 /* While there are bytes to truncate and previous file item is presented in the tree. */
1848 ** This loop could take a really long time, and could log 1943
1849 ** many more blocks than a transaction can hold. So, we do a polite 1944 /*
1850 ** journal end here, and if the transaction needs ending, we make 1945 ** This loop could take a really long time, and could log
1851 ** sure the file is consistent before ending the current trans 1946 ** many more blocks than a transaction can hold. So, we do a polite
1852 ** and starting a new one 1947 ** journal end here, and if the transaction needs ending, we make
1853 */ 1948 ** sure the file is consistent before ending the current trans
1854 if (journal_transaction_should_end(th, th->t_blocks_allocated)) { 1949 ** and starting a new one
1855 int orig_len_alloc = th->t_blocks_allocated ; 1950 */
1856 decrement_counters_in_path(&s_search_path) ; 1951 if (journal_transaction_should_end(th, th->t_blocks_allocated)) {
1857 1952 int orig_len_alloc = th->t_blocks_allocated;
1858 if (update_timestamps) { 1953 decrement_counters_in_path(&s_search_path);
1859 p_s_inode->i_mtime = p_s_inode->i_ctime = CURRENT_TIME_SEC; 1954
1860 } 1955 if (update_timestamps) {
1861 reiserfs_update_sd(th, p_s_inode) ; 1956 p_s_inode->i_mtime = p_s_inode->i_ctime =
1862 1957 CURRENT_TIME_SEC;
1863 err = journal_end(th, p_s_inode->i_sb, orig_len_alloc) ; 1958 }
1864 if (err) 1959 reiserfs_update_sd(th, p_s_inode);
1865 goto out; 1960
1866 err = journal_begin (th, p_s_inode->i_sb, 1961 err = journal_end(th, p_s_inode->i_sb, orig_len_alloc);
1867 JOURNAL_PER_BALANCE_CNT * 6); 1962 if (err)
1868 if (err) 1963 goto out;
1869 goto out; 1964 err = journal_begin(th, p_s_inode->i_sb,
1870 reiserfs_update_inode_transaction(p_s_inode) ; 1965 JOURNAL_PER_BALANCE_CNT * 6);
1966 if (err)
1967 goto out;
1968 reiserfs_update_inode_transaction(p_s_inode);
1969 }
1970 } while (n_file_size > ROUND_UP(n_new_file_size) &&
1971 search_for_position_by_key(p_s_inode->i_sb, &s_item_key,
1972 &s_search_path) == POSITION_FOUND);
1973
1974 RFALSE(n_file_size > ROUND_UP(n_new_file_size),
1975 "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d",
1976 n_new_file_size, n_file_size, s_item_key.on_disk_key.k_objectid);
1977
1978 update_and_out:
1979 if (update_timestamps) {
1980 // this is truncate, not file closing
1981 p_s_inode->i_mtime = p_s_inode->i_ctime = CURRENT_TIME_SEC;
1871 } 1982 }
1872 } while ( n_file_size > ROUND_UP (n_new_file_size) && 1983 reiserfs_update_sd(th, p_s_inode);
1873 search_for_position_by_key(p_s_inode->i_sb, &s_item_key, &s_search_path) == POSITION_FOUND ) ;
1874
1875 RFALSE( n_file_size > ROUND_UP (n_new_file_size),
1876 "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d",
1877 n_new_file_size, n_file_size, s_item_key.on_disk_key.k_objectid);
1878
1879update_and_out:
1880 if (update_timestamps) {
1881 // this is truncate, not file closing
1882 p_s_inode->i_mtime = p_s_inode->i_ctime = CURRENT_TIME_SEC;
1883 }
1884 reiserfs_update_sd (th, p_s_inode);
1885
1886out:
1887 pathrelse(&s_search_path) ;
1888 return err;
1889}
1890 1984
1985 out:
1986 pathrelse(&s_search_path);
1987 return err;
1988}
1891 1989
1892#ifdef CONFIG_REISERFS_CHECK 1990#ifdef CONFIG_REISERFS_CHECK
1893// this makes sure, that we __append__, not overwrite or add holes 1991// this makes sure, that we __append__, not overwrite or add holes
1894static void check_research_for_paste (struct path * path, 1992static void check_research_for_paste(struct path *path,
1895 const struct cpu_key * p_s_key) 1993 const struct cpu_key *p_s_key)
1896{ 1994{
1897 struct item_head * found_ih = get_ih (path); 1995 struct item_head *found_ih = get_ih(path);
1898 1996
1899 if (is_direct_le_ih (found_ih)) { 1997 if (is_direct_le_ih(found_ih)) {
1900 if (le_ih_k_offset (found_ih) + op_bytes_number (found_ih, get_last_bh (path)->b_size) != 1998 if (le_ih_k_offset(found_ih) +
1901 cpu_key_k_offset (p_s_key) || 1999 op_bytes_number(found_ih,
1902 op_bytes_number (found_ih, get_last_bh (path)->b_size) != pos_in_item (path)) 2000 get_last_bh(path)->b_size) !=
1903 reiserfs_panic (NULL, "PAP-5720: check_research_for_paste: " 2001 cpu_key_k_offset(p_s_key)
1904 "found direct item %h or position (%d) does not match to key %K", 2002 || op_bytes_number(found_ih,
1905 found_ih, pos_in_item (path), p_s_key); 2003 get_last_bh(path)->b_size) !=
1906 } 2004 pos_in_item(path))
1907 if (is_indirect_le_ih (found_ih)) { 2005 reiserfs_panic(NULL,
1908 if (le_ih_k_offset (found_ih) + op_bytes_number (found_ih, get_last_bh (path)->b_size) != cpu_key_k_offset (p_s_key) || 2006 "PAP-5720: check_research_for_paste: "
1909 I_UNFM_NUM (found_ih) != pos_in_item (path) || 2007 "found direct item %h or position (%d) does not match to key %K",
1910 get_ih_free_space (found_ih) != 0) 2008 found_ih, pos_in_item(path), p_s_key);
1911 reiserfs_panic (NULL, "PAP-5730: check_research_for_paste: " 2009 }
1912 "found indirect item (%h) or position (%d) does not match to key (%K)", 2010 if (is_indirect_le_ih(found_ih)) {
1913 found_ih, pos_in_item (path), p_s_key); 2011 if (le_ih_k_offset(found_ih) +
1914 } 2012 op_bytes_number(found_ih,
2013 get_last_bh(path)->b_size) !=
2014 cpu_key_k_offset(p_s_key)
2015 || I_UNFM_NUM(found_ih) != pos_in_item(path)
2016 || get_ih_free_space(found_ih) != 0)
2017 reiserfs_panic(NULL,
2018 "PAP-5730: check_research_for_paste: "
2019 "found indirect item (%h) or position (%d) does not match to key (%K)",
2020 found_ih, pos_in_item(path), p_s_key);
2021 }
1915} 2022}
1916#endif /* config reiserfs check */ 2023#endif /* config reiserfs check */
1917
1918 2024
1919/* Paste bytes to the existing item. Returns bytes number pasted into the item. */ 2025/* Paste bytes to the existing item. Returns bytes number pasted into the item. */
1920int reiserfs_paste_into_item (struct reiserfs_transaction_handle *th, 2026int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct path *p_s_search_path, /* Path to the pasted item. */
1921 struct path * p_s_search_path, /* Path to the pasted item. */ 2027 const struct cpu_key *p_s_key, /* Key to search for the needed item. */
1922 const struct cpu_key * p_s_key, /* Key to search for the needed item.*/ 2028 struct inode *inode, /* Inode item belongs to */
1923 struct inode * inode, /* Inode item belongs to */ 2029 const char *p_c_body, /* Pointer to the bytes to paste. */
1924 const char * p_c_body, /* Pointer to the bytes to paste. */ 2030 int n_pasted_size)
1925 int n_pasted_size) /* Size of pasted bytes. */ 2031{ /* Size of pasted bytes. */
1926{ 2032 struct tree_balance s_paste_balance;
1927 struct tree_balance s_paste_balance; 2033 int retval;
1928 int retval; 2034 int fs_gen;
1929 int fs_gen; 2035
2036 BUG_ON(!th->t_trans_id);
1930 2037
1931 BUG_ON (!th->t_trans_id); 2038 fs_gen = get_generation(inode->i_sb);
1932
1933 fs_gen = get_generation(inode->i_sb) ;
1934 2039
1935#ifdef REISERQUOTA_DEBUG 2040#ifdef REISERQUOTA_DEBUG
1936 reiserfs_debug (inode->i_sb, REISERFS_DEBUG_CODE, "reiserquota paste_into_item(): allocating %u id=%u type=%c", n_pasted_size, inode->i_uid, key2type(&(p_s_key->on_disk_key))); 2041 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
2042 "reiserquota paste_into_item(): allocating %u id=%u type=%c",
2043 n_pasted_size, inode->i_uid,
2044 key2type(&(p_s_key->on_disk_key)));
1937#endif 2045#endif
1938 2046
1939 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, n_pasted_size)) { 2047 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, n_pasted_size)) {
1940 pathrelse(p_s_search_path); 2048 pathrelse(p_s_search_path);
1941 return -EDQUOT; 2049 return -EDQUOT;
1942 } 2050 }
1943 init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path, n_pasted_size); 2051 init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
2052 n_pasted_size);
1944#ifdef DISPLACE_NEW_PACKING_LOCALITIES 2053#ifdef DISPLACE_NEW_PACKING_LOCALITIES
1945 s_paste_balance.key = p_s_key->on_disk_key; 2054 s_paste_balance.key = p_s_key->on_disk_key;
1946#endif 2055#endif
1947 2056
1948 /* DQUOT_* can schedule, must check before the fix_nodes */ 2057 /* DQUOT_* can schedule, must check before the fix_nodes */
1949 if (fs_changed(fs_gen, inode->i_sb)) { 2058 if (fs_changed(fs_gen, inode->i_sb)) {
1950 goto search_again; 2059 goto search_again;
1951 }
1952
1953 while ((retval = fix_nodes(M_PASTE, &s_paste_balance, NULL, p_c_body)) ==
1954REPEAT_SEARCH ) {
1955search_again:
1956 /* file system changed while we were in the fix_nodes */
1957 PROC_INFO_INC( th -> t_super, paste_into_item_restarted );
1958 retval = search_for_position_by_key (th->t_super, p_s_key, p_s_search_path);
1959 if (retval == IO_ERROR) {
1960 retval = -EIO ;
1961 goto error_out ;
1962 } 2060 }
1963 if (retval == POSITION_FOUND) { 2061
1964 reiserfs_warning (inode->i_sb, "PAP-5710: reiserfs_paste_into_item: entry or pasted byte (%K) exists", p_s_key); 2062 while ((retval =
1965 retval = -EEXIST ; 2063 fix_nodes(M_PASTE, &s_paste_balance, NULL,
1966 goto error_out ; 2064 p_c_body)) == REPEAT_SEARCH) {
1967 } 2065 search_again:
1968 2066 /* file system changed while we were in the fix_nodes */
2067 PROC_INFO_INC(th->t_super, paste_into_item_restarted);
2068 retval =
2069 search_for_position_by_key(th->t_super, p_s_key,
2070 p_s_search_path);
2071 if (retval == IO_ERROR) {
2072 retval = -EIO;
2073 goto error_out;
2074 }
2075 if (retval == POSITION_FOUND) {
2076 reiserfs_warning(inode->i_sb,
2077 "PAP-5710: reiserfs_paste_into_item: entry or pasted byte (%K) exists",
2078 p_s_key);
2079 retval = -EEXIST;
2080 goto error_out;
2081 }
1969#ifdef CONFIG_REISERFS_CHECK 2082#ifdef CONFIG_REISERFS_CHECK
1970 check_research_for_paste (p_s_search_path, p_s_key); 2083 check_research_for_paste(p_s_search_path, p_s_key);
1971#endif 2084#endif
1972 } 2085 }
1973 2086
1974 /* Perform balancing after all resources are collected by fix_nodes, and 2087 /* Perform balancing after all resources are collected by fix_nodes, and
1975 accessing them will not risk triggering schedule. */ 2088 accessing them will not risk triggering schedule. */
1976 if ( retval == CARRY_ON ) { 2089 if (retval == CARRY_ON) {
1977 do_balance(&s_paste_balance, NULL/*ih*/, p_c_body, M_PASTE); 2090 do_balance(&s_paste_balance, NULL /*ih */ , p_c_body, M_PASTE);
1978 return 0; 2091 return 0;
1979 } 2092 }
1980 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO; 2093 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO;
1981error_out: 2094 error_out:
1982 /* this also releases the path */ 2095 /* this also releases the path */
1983 unfix_nodes(&s_paste_balance); 2096 unfix_nodes(&s_paste_balance);
1984#ifdef REISERQUOTA_DEBUG 2097#ifdef REISERQUOTA_DEBUG
1985 reiserfs_debug (inode->i_sb, REISERFS_DEBUG_CODE, "reiserquota paste_into_item(): freeing %u id=%u type=%c", n_pasted_size, inode->i_uid, key2type(&(p_s_key->on_disk_key))); 2098 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
2099 "reiserquota paste_into_item(): freeing %u id=%u type=%c",
2100 n_pasted_size, inode->i_uid,
2101 key2type(&(p_s_key->on_disk_key)));
1986#endif 2102#endif
1987 DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size); 2103 DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
1988 return retval ; 2104 return retval;
1989} 2105}
1990 2106
1991
1992/* Insert new item into the buffer at the path. */ 2107/* Insert new item into the buffer at the path. */
1993int reiserfs_insert_item(struct reiserfs_transaction_handle *th, 2108int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct path *p_s_path, /* Path to the inserteded item. */
1994 struct path * p_s_path, /* Path to the inserteded item. */ 2109 const struct cpu_key *key, struct item_head *p_s_ih, /* Pointer to the item header to insert. */
1995 const struct cpu_key * key, 2110 struct inode *inode, const char *p_c_body)
1996 struct item_head * p_s_ih, /* Pointer to the item header to insert.*/ 2111{ /* Pointer to the bytes to insert. */
1997 struct inode * inode, 2112 struct tree_balance s_ins_balance;
1998 const char * p_c_body) /* Pointer to the bytes to insert. */ 2113 int retval;
1999{ 2114 int fs_gen = 0;
2000 struct tree_balance s_ins_balance; 2115 int quota_bytes = 0;
2001 int retval; 2116
2002 int fs_gen = 0 ; 2117 BUG_ON(!th->t_trans_id);
2003 int quota_bytes = 0 ; 2118
2004 2119 if (inode) { /* Do we count quotas for item? */
2005 BUG_ON (!th->t_trans_id); 2120 fs_gen = get_generation(inode->i_sb);
2006 2121 quota_bytes = ih_item_len(p_s_ih);
2007 if (inode) { /* Do we count quotas for item? */ 2122
2008 fs_gen = get_generation(inode->i_sb); 2123 /* hack so the quota code doesn't have to guess if the file has
2009 quota_bytes = ih_item_len(p_s_ih); 2124 ** a tail, links are always tails, so there's no guessing needed
2010 2125 */
2011 /* hack so the quota code doesn't have to guess if the file has 2126 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_s_ih)) {
2012 ** a tail, links are always tails, so there's no guessing needed 2127 quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE;
2013 */ 2128 }
2014 if (!S_ISLNK (inode->i_mode) && is_direct_le_ih(p_s_ih)) {
2015 quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE ;
2016 }
2017#ifdef REISERQUOTA_DEBUG 2129#ifdef REISERQUOTA_DEBUG
2018 reiserfs_debug (inode->i_sb, REISERFS_DEBUG_CODE, "reiserquota insert_item(): allocating %u id=%u type=%c", quota_bytes, inode->i_uid, head2type(p_s_ih)); 2130 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
2131 "reiserquota insert_item(): allocating %u id=%u type=%c",
2132 quota_bytes, inode->i_uid, head2type(p_s_ih));
2019#endif 2133#endif
2020 /* We can't dirty inode here. It would be immediately written but 2134 /* We can't dirty inode here. It would be immediately written but
2021 * appropriate stat item isn't inserted yet... */ 2135 * appropriate stat item isn't inserted yet... */
2022 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, quota_bytes)) { 2136 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, quota_bytes)) {
2023 pathrelse(p_s_path); 2137 pathrelse(p_s_path);
2024 return -EDQUOT; 2138 return -EDQUOT;
2139 }
2025 } 2140 }
2026 } 2141 init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
2027 init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path, IH_SIZE + ih_item_len(p_s_ih)); 2142 IH_SIZE + ih_item_len(p_s_ih));
2028#ifdef DISPLACE_NEW_PACKING_LOCALITIES 2143#ifdef DISPLACE_NEW_PACKING_LOCALITIES
2029 s_ins_balance.key = key->on_disk_key; 2144 s_ins_balance.key = key->on_disk_key;
2030#endif 2145#endif
2031 /* DQUOT_* can schedule, must check to be sure calling fix_nodes is safe */ 2146 /* DQUOT_* can schedule, must check to be sure calling fix_nodes is safe */
2032 if (inode && fs_changed(fs_gen, inode->i_sb)) { 2147 if (inode && fs_changed(fs_gen, inode->i_sb)) {
2033 goto search_again; 2148 goto search_again;
2034 }
2035
2036 while ( (retval = fix_nodes(M_INSERT, &s_ins_balance, p_s_ih, p_c_body)) == REPEAT_SEARCH) {
2037search_again:
2038 /* file system changed while we were in the fix_nodes */
2039 PROC_INFO_INC( th -> t_super, insert_item_restarted );
2040 retval = search_item (th->t_super, key, p_s_path);
2041 if (retval == IO_ERROR) {
2042 retval = -EIO;
2043 goto error_out ;
2044 } 2149 }
2045 if (retval == ITEM_FOUND) { 2150
2046 reiserfs_warning (th->t_super, "PAP-5760: reiserfs_insert_item: " 2151 while ((retval =
2047 "key %K already exists in the tree", key); 2152 fix_nodes(M_INSERT, &s_ins_balance, p_s_ih,
2048 retval = -EEXIST ; 2153 p_c_body)) == REPEAT_SEARCH) {
2049 goto error_out; 2154 search_again:
2155 /* file system changed while we were in the fix_nodes */
2156 PROC_INFO_INC(th->t_super, insert_item_restarted);
2157 retval = search_item(th->t_super, key, p_s_path);
2158 if (retval == IO_ERROR) {
2159 retval = -EIO;
2160 goto error_out;
2161 }
2162 if (retval == ITEM_FOUND) {
2163 reiserfs_warning(th->t_super,
2164 "PAP-5760: reiserfs_insert_item: "
2165 "key %K already exists in the tree",
2166 key);
2167 retval = -EEXIST;
2168 goto error_out;
2169 }
2050 } 2170 }
2051 }
2052 2171
2053 /* make balancing after all resources will be collected at a time */ 2172 /* make balancing after all resources will be collected at a time */
2054 if ( retval == CARRY_ON ) { 2173 if (retval == CARRY_ON) {
2055 do_balance (&s_ins_balance, p_s_ih, p_c_body, M_INSERT); 2174 do_balance(&s_ins_balance, p_s_ih, p_c_body, M_INSERT);
2056 return 0; 2175 return 0;
2057 } 2176 }
2058 2177
2059 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO; 2178 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO;
2060error_out: 2179 error_out:
2061 /* also releases the path */ 2180 /* also releases the path */
2062 unfix_nodes(&s_ins_balance); 2181 unfix_nodes(&s_ins_balance);
2063#ifdef REISERQUOTA_DEBUG 2182#ifdef REISERQUOTA_DEBUG
2064 reiserfs_debug (th->t_super, REISERFS_DEBUG_CODE, "reiserquota insert_item(): freeing %u id=%u type=%c", quota_bytes, inode->i_uid, head2type(p_s_ih)); 2183 reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE,
2184 "reiserquota insert_item(): freeing %u id=%u type=%c",
2185 quota_bytes, inode->i_uid, head2type(p_s_ih));
2065#endif 2186#endif
2066 if (inode) 2187 if (inode)
2067 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes) ; 2188 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
2068 return retval; 2189 return retval;
2069} 2190}
2070
2071
2072
2073