]>
Commit | Line | Data |
---|---|---|
b3b94faa DT |
1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | |
3a8a9a10 | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
b3b94faa DT |
4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | |
6 | * modify, copy, or redistribute it subject to the terms and conditions | |
7 | * of the GNU General Public License v.2. | |
8 | */ | |
9 | ||
10 | #include <linux/sched.h> | |
11 | #include <linux/slab.h> | |
12 | #include <linux/spinlock.h> | |
13 | #include <linux/completion.h> | |
14 | #include <linux/buffer_head.h> | |
5c676f6d | 15 | #include <linux/gfs2_ondisk.h> |
71b86f56 | 16 | #include <linux/crc32.h> |
b3b94faa DT |
17 | |
18 | #include "gfs2.h" | |
5c676f6d SW |
19 | #include "lm_interface.h" |
20 | #include "incore.h" | |
b3b94faa DT |
21 | #include "bmap.h" |
22 | #include "glock.h" | |
23 | #include "inode.h" | |
b3b94faa DT |
24 | #include "meta_io.h" |
25 | #include "page.h" | |
26 | #include "quota.h" | |
27 | #include "rgrp.h" | |
28 | #include "trans.h" | |
18ec7d5c | 29 | #include "dir.h" |
5c676f6d | 30 | #include "util.h" |
b3b94faa DT |
31 | |
32 | /* This doesn't need to be that large as max 64 bit pointers in a 4k | |
33 | * block is 512, so __u16 is fine for that. It saves stack space to | |
34 | * keep it small. | |
35 | */ | |
36 | struct metapath { | |
37 | __u16 mp_list[GFS2_MAX_META_HEIGHT]; | |
38 | }; | |
39 | ||
40 | typedef int (*block_call_t) (struct gfs2_inode *ip, struct buffer_head *dibh, | |
41 | struct buffer_head *bh, uint64_t *top, | |
42 | uint64_t *bottom, unsigned int height, | |
43 | void *data); | |
44 | ||
45 | struct strip_mine { | |
46 | int sm_first; | |
47 | unsigned int sm_height; | |
48 | }; | |
49 | ||
f25ef0c1 SW |
50 | /** |
51 | * gfs2_unstuffer_page - unstuff a stuffed inode into a block cached by a page | |
52 | * @ip: the inode | |
53 | * @dibh: the dinode buffer | |
54 | * @block: the block number that was allocated | |
55 | * @private: any locked page held by the caller process | |
56 | * | |
57 | * Returns: errno | |
58 | */ | |
59 | ||
60 | static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, | |
61 | uint64_t block, struct page *page) | |
62 | { | |
63 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | |
64 | struct inode *inode = &ip->i_inode; | |
65 | struct buffer_head *bh; | |
66 | int release = 0; | |
67 | ||
68 | if (!page || page->index) { | |
69 | page = grab_cache_page(inode->i_mapping, 0); | |
70 | if (!page) | |
71 | return -ENOMEM; | |
72 | release = 1; | |
73 | } | |
74 | ||
75 | if (!PageUptodate(page)) { | |
76 | void *kaddr = kmap(page); | |
77 | ||
78 | memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), | |
79 | ip->i_di.di_size); | |
80 | memset(kaddr + ip->i_di.di_size, 0, | |
81 | PAGE_CACHE_SIZE - ip->i_di.di_size); | |
82 | kunmap(page); | |
83 | ||
84 | SetPageUptodate(page); | |
85 | } | |
86 | ||
87 | if (!page_has_buffers(page)) | |
88 | create_empty_buffers(page, 1 << inode->i_blkbits, | |
89 | (1 << BH_Uptodate)); | |
90 | ||
91 | bh = page_buffers(page); | |
92 | ||
93 | if (!buffer_mapped(bh)) | |
94 | map_bh(bh, inode->i_sb, block); | |
95 | ||
96 | set_buffer_uptodate(bh); | |
97 | if ((sdp->sd_args.ar_data == GFS2_DATA_ORDERED) || gfs2_is_jdata(ip)) | |
98 | gfs2_trans_add_bh(ip->i_gl, bh, 0); | |
99 | mark_buffer_dirty(bh); | |
100 | ||
101 | if (release) { | |
102 | unlock_page(page); | |
103 | page_cache_release(page); | |
104 | } | |
105 | ||
106 | return 0; | |
107 | } | |
108 | ||
b3b94faa DT |
109 | /** |
110 | * gfs2_unstuff_dinode - Unstuff a dinode when the data has grown too big | |
111 | * @ip: The GFS2 inode to unstuff | |
112 | * @unstuffer: the routine that handles unstuffing a non-zero length file | |
113 | * @private: private data for the unstuffer | |
114 | * | |
115 | * This routine unstuffs a dinode and returns it to a "normal" state such | |
116 | * that the height can be grown in the traditional way. | |
117 | * | |
118 | * Returns: errno | |
119 | */ | |
120 | ||
f25ef0c1 | 121 | int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) |
b3b94faa DT |
122 | { |
123 | struct buffer_head *bh, *dibh; | |
124 | uint64_t block = 0; | |
18ec7d5c | 125 | int isdir = gfs2_is_dir(ip); |
b3b94faa DT |
126 | int error; |
127 | ||
128 | down_write(&ip->i_rw_mutex); | |
129 | ||
130 | error = gfs2_meta_inode_buffer(ip, &dibh); | |
131 | if (error) | |
132 | goto out; | |
133 | ||
134 | if (ip->i_di.di_size) { | |
135 | /* Get a free block, fill it with the stuffed data, | |
136 | and write it out to disk */ | |
137 | ||
18ec7d5c | 138 | if (isdir) { |
b3b94faa DT |
139 | block = gfs2_alloc_meta(ip); |
140 | ||
61e085a8 | 141 | error = gfs2_dir_get_new_buffer(ip, block, &bh); |
b3b94faa DT |
142 | if (error) |
143 | goto out_brelse; | |
144 | gfs2_buffer_copy_tail(bh, | |
145 | sizeof(struct gfs2_meta_header), | |
146 | dibh, sizeof(struct gfs2_dinode)); | |
147 | brelse(bh); | |
148 | } else { | |
149 | block = gfs2_alloc_data(ip); | |
150 | ||
f25ef0c1 | 151 | error = gfs2_unstuffer_page(ip, dibh, block, page); |
b3b94faa DT |
152 | if (error) |
153 | goto out_brelse; | |
154 | } | |
155 | } | |
156 | ||
157 | /* Set up the pointer to the new block */ | |
158 | ||
d4e9c4c3 | 159 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
b3b94faa DT |
160 | |
161 | gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); | |
162 | ||
163 | if (ip->i_di.di_size) { | |
568f4c96 SW |
164 | *(uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)) = |
165 | cpu_to_be64(block); | |
b3b94faa DT |
166 | ip->i_di.di_blocks++; |
167 | } | |
168 | ||
169 | ip->i_di.di_height = 1; | |
170 | ||
171 | gfs2_dinode_out(&ip->i_di, dibh->b_data); | |
172 | ||
173 | out_brelse: | |
174 | brelse(dibh); | |
175 | ||
176 | out: | |
177 | up_write(&ip->i_rw_mutex); | |
178 | ||
179 | return error; | |
180 | } | |
181 | ||
182 | /** | |
183 | * calc_tree_height - Calculate the height of a metadata tree | |
184 | * @ip: The GFS2 inode | |
185 | * @size: The proposed size of the file | |
186 | * | |
187 | * Work out how tall a metadata tree needs to be in order to accommodate a | |
188 | * file of a particular size. If size is less than the current size of | |
189 | * the inode, then the current size of the inode is used instead of the | |
190 | * supplied one. | |
191 | * | |
192 | * Returns: the height the tree should be | |
193 | */ | |
194 | ||
195 | static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size) | |
196 | { | |
feaa7bba | 197 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
b3b94faa DT |
198 | uint64_t *arr; |
199 | unsigned int max, height; | |
200 | ||
201 | if (ip->i_di.di_size > size) | |
202 | size = ip->i_di.di_size; | |
203 | ||
18ec7d5c | 204 | if (gfs2_is_dir(ip)) { |
b3b94faa DT |
205 | arr = sdp->sd_jheightsize; |
206 | max = sdp->sd_max_jheight; | |
207 | } else { | |
208 | arr = sdp->sd_heightsize; | |
209 | max = sdp->sd_max_height; | |
210 | } | |
211 | ||
212 | for (height = 0; height < max; height++) | |
213 | if (arr[height] >= size) | |
214 | break; | |
215 | ||
216 | return height; | |
217 | } | |
218 | ||
219 | /** | |
220 | * build_height - Build a metadata tree of the requested height | |
221 | * @ip: The GFS2 inode | |
222 | * @height: The height to build to | |
223 | * | |
b3b94faa DT |
224 | * |
225 | * Returns: errno | |
226 | */ | |
227 | ||
e90c01e1 | 228 | static int build_height(struct inode *inode, unsigned height) |
b3b94faa | 229 | { |
feaa7bba | 230 | struct gfs2_inode *ip = GFS2_I(inode); |
e90c01e1 SW |
231 | unsigned new_height = height - ip->i_di.di_height; |
232 | struct buffer_head *dibh; | |
233 | struct buffer_head *blocks[GFS2_MAX_META_HEIGHT]; | |
b3b94faa | 234 | int error; |
e90c01e1 SW |
235 | u64 *bp; |
236 | u64 bn; | |
237 | unsigned n; | |
b3b94faa | 238 | |
e90c01e1 SW |
239 | if (height <= ip->i_di.di_height) |
240 | return 0; | |
b3b94faa | 241 | |
e90c01e1 SW |
242 | error = gfs2_meta_inode_buffer(ip, &dibh); |
243 | if (error) | |
244 | return error; | |
b3b94faa | 245 | |
e90c01e1 SW |
246 | for(n = 0; n < new_height; n++) { |
247 | bn = gfs2_alloc_meta(ip); | |
248 | blocks[n] = gfs2_meta_new(ip->i_gl, bn); | |
249 | gfs2_trans_add_bh(ip->i_gl, blocks[n], 1); | |
250 | } | |
251 | ||
252 | n = 0; | |
253 | bn = blocks[0]->b_blocknr; | |
254 | if (new_height > 1) { | |
255 | for(; n < new_height-1; n++) { | |
256 | gfs2_metatype_set(blocks[n], GFS2_METATYPE_IN, | |
b3b94faa | 257 | GFS2_FORMAT_IN); |
e90c01e1 SW |
258 | gfs2_buffer_clear_tail(blocks[n], |
259 | sizeof(struct gfs2_meta_header)); | |
260 | bp = (u64 *)(blocks[n]->b_data + | |
261 | sizeof(struct gfs2_meta_header)); | |
262 | *bp = cpu_to_be64(blocks[n+1]->b_blocknr); | |
263 | brelse(blocks[n]); | |
264 | blocks[n] = NULL; | |
b3b94faa | 265 | } |
b3b94faa | 266 | } |
e90c01e1 SW |
267 | gfs2_metatype_set(blocks[n], GFS2_METATYPE_IN, GFS2_FORMAT_IN); |
268 | gfs2_buffer_copy_tail(blocks[n], sizeof(struct gfs2_meta_header), | |
269 | dibh, sizeof(struct gfs2_dinode)); | |
270 | brelse(blocks[n]); | |
271 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); | |
272 | gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); | |
273 | bp = (u64 *)(dibh->b_data + sizeof(struct gfs2_dinode)); | |
274 | *bp = cpu_to_be64(bn); | |
275 | ip->i_di.di_height += new_height; | |
276 | ip->i_di.di_blocks += new_height; | |
277 | gfs2_dinode_out(&ip->i_di, dibh->b_data); | |
278 | brelse(dibh); | |
279 | return error; | |
b3b94faa DT |
280 | } |
281 | ||
282 | /** | |
283 | * find_metapath - Find path through the metadata tree | |
284 | * @ip: The inode pointer | |
285 | * @mp: The metapath to return the result in | |
286 | * @block: The disk block to look up | |
287 | * | |
288 | * This routine returns a struct metapath structure that defines a path | |
289 | * through the metadata of inode "ip" to get to block "block". | |
290 | * | |
291 | * Example: | |
292 | * Given: "ip" is a height 3 file, "offset" is 101342453, and this is a | |
293 | * filesystem with a blocksize of 4096. | |
294 | * | |
295 | * find_metapath() would return a struct metapath structure set to: | |
296 | * mp_offset = 101342453, mp_height = 3, mp_list[0] = 0, mp_list[1] = 48, | |
297 | * and mp_list[2] = 165. | |
298 | * | |
299 | * That means that in order to get to the block containing the byte at | |
300 | * offset 101342453, we would load the indirect block pointed to by pointer | |
301 | * 0 in the dinode. We would then load the indirect block pointed to by | |
302 | * pointer 48 in that indirect block. We would then load the data block | |
303 | * pointed to by pointer 165 in that indirect block. | |
304 | * | |
305 | * ---------------------------------------- | |
306 | * | Dinode | | | |
307 | * | | 4| | |
308 | * | |0 1 2 3 4 5 9| | |
309 | * | | 6| | |
310 | * ---------------------------------------- | |
311 | * | | |
312 | * | | |
313 | * V | |
314 | * ---------------------------------------- | |
315 | * | Indirect Block | | |
316 | * | 5| | |
317 | * | 4 4 4 4 4 5 5 1| | |
318 | * |0 5 6 7 8 9 0 1 2| | |
319 | * ---------------------------------------- | |
320 | * | | |
321 | * | | |
322 | * V | |
323 | * ---------------------------------------- | |
324 | * | Indirect Block | | |
325 | * | 1 1 1 1 1 5| | |
326 | * | 6 6 6 6 6 1| | |
327 | * |0 3 4 5 6 7 2| | |
328 | * ---------------------------------------- | |
329 | * | | |
330 | * | | |
331 | * V | |
332 | * ---------------------------------------- | |
333 | * | Data block containing offset | | |
334 | * | 101342453 | | |
335 | * | | | |
336 | * | | | |
337 | * ---------------------------------------- | |
338 | * | |
339 | */ | |
340 | ||
568f4c96 SW |
341 | static void find_metapath(struct gfs2_inode *ip, uint64_t block, |
342 | struct metapath *mp) | |
b3b94faa | 343 | { |
feaa7bba | 344 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
b3b94faa DT |
345 | uint64_t b = block; |
346 | unsigned int i; | |
347 | ||
348 | for (i = ip->i_di.di_height; i--;) | |
349 | mp->mp_list[i] = (__u16)do_div(b, sdp->sd_inptrs); | |
350 | ||
351 | } | |
352 | ||
353 | /** | |
354 | * metapointer - Return pointer to start of metadata in a buffer | |
355 | * @bh: The buffer | |
356 | * @height: The metadata height (0 = dinode) | |
357 | * @mp: The metapath | |
358 | * | |
359 | * Return a pointer to the block number of the next height of the metadata | |
360 | * tree given a buffer containing the pointer to the current height of the | |
361 | * metadata tree. | |
362 | */ | |
363 | ||
fd88de56 SW |
364 | static inline u64 *metapointer(struct buffer_head *bh, int *boundary, |
365 | unsigned int height, const struct metapath *mp) | |
b3b94faa DT |
366 | { |
367 | unsigned int head_size = (height > 0) ? | |
368 | sizeof(struct gfs2_meta_header) : sizeof(struct gfs2_dinode); | |
fd88de56 SW |
369 | u64 *ptr; |
370 | *boundary = 0; | |
371 | ptr = ((u64 *)(bh->b_data + head_size)) + mp->mp_list[height]; | |
372 | if (ptr + 1 == (u64*)(bh->b_data + bh->b_size)) | |
373 | *boundary = 1; | |
374 | return ptr; | |
b3b94faa DT |
375 | } |
376 | ||
377 | /** | |
378 | * lookup_block - Get the next metadata block in metadata tree | |
379 | * @ip: The GFS2 inode | |
380 | * @bh: Buffer containing the pointers to metadata blocks | |
381 | * @height: The height of the tree (0 = dinode) | |
382 | * @mp: The metapath | |
383 | * @create: Non-zero if we may create a new meatdata block | |
384 | * @new: Used to indicate if we did create a new metadata block | |
385 | * @block: the returned disk block number | |
386 | * | |
387 | * Given a metatree, complete to a particular height, checks to see if the next | |
388 | * height of the tree exists. If not the next height of the tree is created. | |
389 | * The block number of the next height of the metadata tree is returned. | |
390 | * | |
391 | */ | |
392 | ||
fd88de56 SW |
393 | static int lookup_block(struct gfs2_inode *ip, struct buffer_head *bh, |
394 | unsigned int height, struct metapath *mp, int create, | |
395 | int *new, uint64_t *block) | |
b3b94faa | 396 | { |
fd88de56 SW |
397 | int boundary; |
398 | uint64_t *ptr = metapointer(bh, &boundary, height, mp); | |
b3b94faa DT |
399 | |
400 | if (*ptr) { | |
401 | *block = be64_to_cpu(*ptr); | |
fd88de56 | 402 | return boundary; |
b3b94faa DT |
403 | } |
404 | ||
405 | *block = 0; | |
406 | ||
407 | if (!create) | |
fd88de56 | 408 | return 0; |
b3b94faa | 409 | |
fd88de56 | 410 | if (height == ip->i_di.di_height - 1 && !gfs2_is_dir(ip)) |
b3b94faa DT |
411 | *block = gfs2_alloc_data(ip); |
412 | else | |
413 | *block = gfs2_alloc_meta(ip); | |
414 | ||
d4e9c4c3 | 415 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
b3b94faa DT |
416 | |
417 | *ptr = cpu_to_be64(*block); | |
418 | ip->i_di.di_blocks++; | |
419 | ||
420 | *new = 1; | |
fd88de56 | 421 | return 0; |
b3b94faa DT |
422 | } |
423 | ||
424 | /** | |
fd88de56 SW |
425 | * gfs2_block_pointers - Map a block from an inode to a disk block |
426 | * @inode: The inode | |
b3b94faa DT |
427 | * @lblock: The logical block number |
428 | * @new: Value/Result argument (1 = may create/did create new blocks) | |
fd88de56 SW |
429 | * @boundary: gets set if we've hit a block boundary |
430 | * @mp: metapath to use | |
b3b94faa DT |
431 | * |
432 | * Find the block number on the current device which corresponds to an | |
433 | * inode's block. If the block had to be created, "new" will be set. | |
434 | * | |
435 | * Returns: errno | |
436 | */ | |
437 | ||
fd88de56 SW |
438 | static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock, |
439 | int *new, u64 *dblock, | |
440 | int *boundary, | |
441 | struct metapath *mp) | |
b3b94faa | 442 | { |
feaa7bba SW |
443 | struct gfs2_inode *ip = GFS2_I(inode); |
444 | struct gfs2_sbd *sdp = GFS2_SB(inode); | |
b3b94faa | 445 | struct buffer_head *bh; |
b3b94faa DT |
446 | int create = *new; |
447 | unsigned int bsize; | |
448 | unsigned int height; | |
449 | unsigned int end_of_metadata; | |
450 | unsigned int x; | |
451 | int error = 0; | |
452 | ||
453 | *new = 0; | |
454 | *dblock = 0; | |
b3b94faa DT |
455 | |
456 | if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip))) | |
457 | goto out; | |
458 | ||
18ec7d5c | 459 | bsize = (gfs2_is_dir(ip)) ? sdp->sd_jbsize : sdp->sd_sb.sb_bsize; |
b3b94faa DT |
460 | |
461 | height = calc_tree_height(ip, (lblock + 1) * bsize); | |
462 | if (ip->i_di.di_height < height) { | |
463 | if (!create) | |
464 | goto out; | |
465 | ||
e90c01e1 | 466 | error = build_height(inode, height); |
b3b94faa DT |
467 | if (error) |
468 | goto out; | |
469 | } | |
470 | ||
fd88de56 | 471 | find_metapath(ip, lblock, mp); |
b3b94faa DT |
472 | end_of_metadata = ip->i_di.di_height - 1; |
473 | ||
474 | error = gfs2_meta_inode_buffer(ip, &bh); | |
475 | if (error) | |
476 | goto out; | |
477 | ||
478 | for (x = 0; x < end_of_metadata; x++) { | |
fd88de56 | 479 | lookup_block(ip, bh, x, mp, create, new, dblock); |
b3b94faa DT |
480 | brelse(bh); |
481 | if (!*dblock) | |
482 | goto out; | |
483 | ||
484 | error = gfs2_meta_indirect_buffer(ip, x+1, *dblock, *new, &bh); | |
485 | if (error) | |
486 | goto out; | |
487 | } | |
488 | ||
fd88de56 | 489 | *boundary = lookup_block(ip, bh, end_of_metadata, mp, create, new, dblock); |
b3b94faa | 490 | if (*new) { |
fd88de56 SW |
491 | struct buffer_head *dibh; |
492 | error = gfs2_meta_inode_buffer(ip, &dibh); | |
b3b94faa | 493 | if (!error) { |
fd88de56 SW |
494 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
495 | gfs2_dinode_out(&ip->i_di, dibh->b_data); | |
496 | brelse(dibh); | |
b3b94faa DT |
497 | } |
498 | } | |
fd88de56 SW |
499 | return bh; |
500 | out: | |
501 | return ERR_PTR(error); | |
502 | } | |
b3b94faa | 503 | |
fd88de56 SW |
504 | |
505 | static inline void bmap_lock(struct inode *inode, int create) | |
506 | { | |
feaa7bba | 507 | struct gfs2_inode *ip = GFS2_I(inode); |
fd88de56 SW |
508 | if (create) |
509 | down_write(&ip->i_rw_mutex); | |
510 | else | |
511 | down_read(&ip->i_rw_mutex); | |
512 | } | |
513 | ||
514 | static inline void bmap_unlock(struct inode *inode, int create) | |
515 | { | |
feaa7bba | 516 | struct gfs2_inode *ip = GFS2_I(inode); |
b3b94faa DT |
517 | if (create) |
518 | up_write(&ip->i_rw_mutex); | |
519 | else | |
520 | up_read(&ip->i_rw_mutex); | |
fd88de56 | 521 | } |
b3b94faa | 522 | |
fd88de56 SW |
523 | int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *boundary) |
524 | { | |
525 | struct metapath mp; | |
526 | struct buffer_head *bh; | |
527 | int create = *new; | |
528 | ||
529 | bmap_lock(inode, create); | |
530 | bh = gfs2_block_pointers(inode, lblock, new, dblock, boundary, &mp); | |
531 | bmap_unlock(inode, create); | |
532 | if (!bh) | |
533 | return 0; | |
534 | if (IS_ERR(bh)) | |
535 | return PTR_ERR(bh); | |
536 | brelse(bh); | |
537 | return 0; | |
538 | } | |
539 | ||
540 | int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen) | |
541 | { | |
feaa7bba SW |
542 | struct gfs2_inode *ip = GFS2_I(inode); |
543 | struct gfs2_sbd *sdp = GFS2_SB(inode); | |
fd88de56 SW |
544 | struct metapath mp; |
545 | struct buffer_head *bh; | |
546 | int boundary; | |
547 | int create = *new; | |
548 | ||
549 | BUG_ON(!extlen); | |
550 | BUG_ON(!dblock); | |
551 | BUG_ON(!new); | |
552 | ||
553 | bmap_lock(inode, create); | |
554 | bh = gfs2_block_pointers(inode, lblock, new, dblock, &boundary, &mp); | |
555 | *extlen = 1; | |
556 | ||
557 | if (bh && !IS_ERR(bh) && *dblock && !*new) { | |
558 | u64 tmp_dblock; | |
559 | int tmp_new; | |
560 | unsigned int nptrs; | |
561 | unsigned end_of_metadata = ip->i_di.di_height - 1; | |
562 | ||
563 | nptrs = (end_of_metadata) ? sdp->sd_inptrs : sdp->sd_diptrs; | |
564 | while (++mp.mp_list[end_of_metadata] < nptrs) { | |
565 | lookup_block(ip, bh, end_of_metadata, &mp, 0, &tmp_new, &tmp_dblock); | |
566 | if (*dblock + *extlen != tmp_dblock) | |
567 | break; | |
568 | (*extlen)++; | |
569 | } | |
570 | } | |
571 | bmap_unlock(inode, create); | |
572 | if (!bh) | |
573 | return 0; | |
574 | if (IS_ERR(bh)) | |
575 | return PTR_ERR(bh); | |
576 | brelse(bh); | |
577 | return 0; | |
b3b94faa DT |
578 | } |
579 | ||
580 | /** | |
581 | * recursive_scan - recursively scan through the end of a file | |
582 | * @ip: the inode | |
583 | * @dibh: the dinode buffer | |
584 | * @mp: the path through the metadata to the point to start | |
585 | * @height: the height the recursion is at | |
586 | * @block: the indirect block to look at | |
587 | * @first: 1 if this is the first block | |
588 | * @bc: the call to make for each piece of metadata | |
589 | * @data: data opaque to this function to pass to @bc | |
590 | * | |
591 | * When this is first called @height and @block should be zero and | |
592 | * @first should be 1. | |
593 | * | |
594 | * Returns: errno | |
595 | */ | |
596 | ||
597 | static int recursive_scan(struct gfs2_inode *ip, struct buffer_head *dibh, | |
598 | struct metapath *mp, unsigned int height, | |
599 | uint64_t block, int first, block_call_t bc, | |
600 | void *data) | |
601 | { | |
feaa7bba | 602 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
b3b94faa DT |
603 | struct buffer_head *bh = NULL; |
604 | uint64_t *top, *bottom; | |
605 | uint64_t bn; | |
606 | int error; | |
607 | int mh_size = sizeof(struct gfs2_meta_header); | |
608 | ||
609 | if (!height) { | |
610 | error = gfs2_meta_inode_buffer(ip, &bh); | |
611 | if (error) | |
612 | return error; | |
613 | dibh = bh; | |
614 | ||
615 | top = (uint64_t *)(bh->b_data + sizeof(struct gfs2_dinode)) + | |
616 | mp->mp_list[0]; | |
617 | bottom = (uint64_t *)(bh->b_data + sizeof(struct gfs2_dinode)) + | |
618 | sdp->sd_diptrs; | |
619 | } else { | |
620 | error = gfs2_meta_indirect_buffer(ip, height, block, 0, &bh); | |
621 | if (error) | |
622 | return error; | |
623 | ||
624 | top = (uint64_t *)(bh->b_data + mh_size) + | |
625 | ((first) ? mp->mp_list[height] : 0); | |
626 | ||
627 | bottom = (uint64_t *)(bh->b_data + mh_size) + sdp->sd_inptrs; | |
628 | } | |
629 | ||
630 | error = bc(ip, dibh, bh, top, bottom, height, data); | |
631 | if (error) | |
632 | goto out; | |
633 | ||
634 | if (height < ip->i_di.di_height - 1) | |
635 | for (; top < bottom; top++, first = 0) { | |
636 | if (!*top) | |
637 | continue; | |
638 | ||
639 | bn = be64_to_cpu(*top); | |
640 | ||
641 | error = recursive_scan(ip, dibh, mp, height + 1, bn, | |
642 | first, bc, data); | |
643 | if (error) | |
644 | break; | |
645 | } | |
646 | ||
647 | out: | |
648 | brelse(bh); | |
649 | ||
650 | return error; | |
651 | } | |
652 | ||
653 | /** | |
654 | * do_strip - Look for a layer a particular layer of the file and strip it off | |
655 | * @ip: the inode | |
656 | * @dibh: the dinode buffer | |
657 | * @bh: A buffer of pointers | |
658 | * @top: The first pointer in the buffer | |
659 | * @bottom: One more than the last pointer | |
660 | * @height: the height this buffer is at | |
661 | * @data: a pointer to a struct strip_mine | |
662 | * | |
663 | * Returns: errno | |
664 | */ | |
665 | ||
666 | static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, | |
667 | struct buffer_head *bh, uint64_t *top, uint64_t *bottom, | |
668 | unsigned int height, void *data) | |
669 | { | |
feaa7bba SW |
670 | struct strip_mine *sm = data; |
671 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | |
b3b94faa DT |
672 | struct gfs2_rgrp_list rlist; |
673 | uint64_t bn, bstart; | |
674 | uint32_t blen; | |
675 | uint64_t *p; | |
676 | unsigned int rg_blocks = 0; | |
677 | int metadata; | |
678 | unsigned int revokes = 0; | |
679 | int x; | |
680 | int error; | |
681 | ||
682 | if (!*top) | |
683 | sm->sm_first = 0; | |
684 | ||
685 | if (height != sm->sm_height) | |
686 | return 0; | |
687 | ||
688 | if (sm->sm_first) { | |
689 | top++; | |
690 | sm->sm_first = 0; | |
691 | } | |
692 | ||
18ec7d5c | 693 | metadata = (height != ip->i_di.di_height - 1); |
b3b94faa DT |
694 | if (metadata) |
695 | revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs; | |
696 | ||
697 | error = gfs2_rindex_hold(sdp, &ip->i_alloc.al_ri_gh); | |
698 | if (error) | |
699 | return error; | |
700 | ||
701 | memset(&rlist, 0, sizeof(struct gfs2_rgrp_list)); | |
702 | bstart = 0; | |
703 | blen = 0; | |
704 | ||
705 | for (p = top; p < bottom; p++) { | |
706 | if (!*p) | |
707 | continue; | |
708 | ||
709 | bn = be64_to_cpu(*p); | |
710 | ||
711 | if (bstart + blen == bn) | |
712 | blen++; | |
713 | else { | |
714 | if (bstart) | |
715 | gfs2_rlist_add(sdp, &rlist, bstart); | |
716 | ||
717 | bstart = bn; | |
718 | blen = 1; | |
719 | } | |
720 | } | |
721 | ||
722 | if (bstart) | |
723 | gfs2_rlist_add(sdp, &rlist, bstart); | |
724 | else | |
725 | goto out; /* Nothing to do */ | |
726 | ||
727 | gfs2_rlist_alloc(&rlist, LM_ST_EXCLUSIVE, 0); | |
728 | ||
729 | for (x = 0; x < rlist.rl_rgrps; x++) { | |
730 | struct gfs2_rgrpd *rgd; | |
5c676f6d | 731 | rgd = rlist.rl_ghs[x].gh_gl->gl_object; |
b3b94faa DT |
732 | rg_blocks += rgd->rd_ri.ri_length; |
733 | } | |
734 | ||
735 | error = gfs2_glock_nq_m(rlist.rl_rgrps, rlist.rl_ghs); | |
736 | if (error) | |
737 | goto out_rlist; | |
738 | ||
739 | error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + | |
740 | RES_INDIRECT + RES_STATFS + RES_QUOTA, | |
741 | revokes); | |
742 | if (error) | |
743 | goto out_rg_gunlock; | |
744 | ||
745 | down_write(&ip->i_rw_mutex); | |
746 | ||
d4e9c4c3 SW |
747 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
748 | gfs2_trans_add_bh(ip->i_gl, bh, 1); | |
b3b94faa DT |
749 | |
750 | bstart = 0; | |
751 | blen = 0; | |
752 | ||
753 | for (p = top; p < bottom; p++) { | |
754 | if (!*p) | |
755 | continue; | |
756 | ||
757 | bn = be64_to_cpu(*p); | |
758 | ||
759 | if (bstart + blen == bn) | |
760 | blen++; | |
761 | else { | |
762 | if (bstart) { | |
763 | if (metadata) | |
764 | gfs2_free_meta(ip, bstart, blen); | |
765 | else | |
766 | gfs2_free_data(ip, bstart, blen); | |
767 | } | |
768 | ||
769 | bstart = bn; | |
770 | blen = 1; | |
771 | } | |
772 | ||
773 | *p = 0; | |
774 | if (!ip->i_di.di_blocks) | |
775 | gfs2_consist_inode(ip); | |
776 | ip->i_di.di_blocks--; | |
777 | } | |
778 | if (bstart) { | |
779 | if (metadata) | |
780 | gfs2_free_meta(ip, bstart, blen); | |
781 | else | |
782 | gfs2_free_data(ip, bstart, blen); | |
783 | } | |
784 | ||
785 | ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); | |
786 | ||
787 | gfs2_dinode_out(&ip->i_di, dibh->b_data); | |
788 | ||
789 | up_write(&ip->i_rw_mutex); | |
790 | ||
791 | gfs2_trans_end(sdp); | |
792 | ||
793 | out_rg_gunlock: | |
794 | gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs); | |
795 | ||
796 | out_rlist: | |
797 | gfs2_rlist_free(&rlist); | |
798 | ||
799 | out: | |
800 | gfs2_glock_dq_uninit(&ip->i_alloc.al_ri_gh); | |
801 | ||
802 | return error; | |
803 | } | |
804 | ||
805 | /** | |
806 | * do_grow - Make a file look bigger than it is | |
807 | * @ip: the inode | |
808 | * @size: the size to set the file to | |
809 | * | |
810 | * Called with an exclusive lock on @ip. | |
811 | * | |
812 | * Returns: errno | |
813 | */ | |
814 | ||
815 | static int do_grow(struct gfs2_inode *ip, uint64_t size) | |
816 | { | |
feaa7bba | 817 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
b3b94faa DT |
818 | struct gfs2_alloc *al; |
819 | struct buffer_head *dibh; | |
820 | unsigned int h; | |
821 | int error; | |
822 | ||
823 | al = gfs2_alloc_get(ip); | |
824 | ||
825 | error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); | |
826 | if (error) | |
827 | goto out; | |
828 | ||
829 | error = gfs2_quota_check(ip, ip->i_di.di_uid, ip->i_di.di_gid); | |
830 | if (error) | |
831 | goto out_gunlock_q; | |
832 | ||
833 | al->al_requested = sdp->sd_max_height + RES_DATA; | |
834 | ||
835 | error = gfs2_inplace_reserve(ip); | |
836 | if (error) | |
837 | goto out_gunlock_q; | |
838 | ||
839 | error = gfs2_trans_begin(sdp, | |
840 | sdp->sd_max_height + al->al_rgd->rd_ri.ri_length + | |
841 | RES_JDATA + RES_DINODE + RES_STATFS + RES_QUOTA, 0); | |
842 | if (error) | |
843 | goto out_ipres; | |
844 | ||
845 | if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) { | |
846 | if (gfs2_is_stuffed(ip)) { | |
f25ef0c1 | 847 | error = gfs2_unstuff_dinode(ip, NULL); |
b3b94faa DT |
848 | if (error) |
849 | goto out_end_trans; | |
850 | } | |
851 | ||
852 | h = calc_tree_height(ip, size); | |
853 | if (ip->i_di.di_height < h) { | |
854 | down_write(&ip->i_rw_mutex); | |
feaa7bba | 855 | error = build_height(&ip->i_inode, h); |
b3b94faa DT |
856 | up_write(&ip->i_rw_mutex); |
857 | if (error) | |
858 | goto out_end_trans; | |
859 | } | |
860 | } | |
861 | ||
862 | ip->i_di.di_size = size; | |
863 | ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); | |
864 | ||
865 | error = gfs2_meta_inode_buffer(ip, &dibh); | |
866 | if (error) | |
867 | goto out_end_trans; | |
868 | ||
d4e9c4c3 | 869 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
b3b94faa DT |
870 | gfs2_dinode_out(&ip->i_di, dibh->b_data); |
871 | brelse(dibh); | |
872 | ||
873 | out_end_trans: | |
874 | gfs2_trans_end(sdp); | |
875 | ||
876 | out_ipres: | |
877 | gfs2_inplace_release(ip); | |
878 | ||
879 | out_gunlock_q: | |
880 | gfs2_quota_unlock(ip); | |
881 | ||
882 | out: | |
883 | gfs2_alloc_put(ip); | |
884 | ||
885 | return error; | |
886 | } | |
887 | ||
aa6a85a9 | 888 | static int trunc_start(struct gfs2_inode *ip, uint64_t size) |
b3b94faa | 889 | { |
feaa7bba | 890 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
b3b94faa DT |
891 | struct buffer_head *dibh; |
892 | int journaled = gfs2_is_jdata(ip); | |
893 | int error; | |
894 | ||
895 | error = gfs2_trans_begin(sdp, | |
896 | RES_DINODE + ((journaled) ? RES_JDATA : 0), 0); | |
897 | if (error) | |
898 | return error; | |
899 | ||
900 | error = gfs2_meta_inode_buffer(ip, &dibh); | |
901 | if (error) | |
902 | goto out; | |
903 | ||
904 | if (gfs2_is_stuffed(ip)) { | |
905 | ip->i_di.di_size = size; | |
906 | ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); | |
d4e9c4c3 | 907 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
b3b94faa DT |
908 | gfs2_dinode_out(&ip->i_di, dibh->b_data); |
909 | gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode) + size); | |
910 | error = 1; | |
911 | ||
912 | } else { | |
18ec7d5c | 913 | if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1)) |
feaa7bba | 914 | error = gfs2_block_truncate_page(ip->i_inode.i_mapping); |
b3b94faa DT |
915 | |
916 | if (!error) { | |
917 | ip->i_di.di_size = size; | |
918 | ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); | |
919 | ip->i_di.di_flags |= GFS2_DIF_TRUNC_IN_PROG; | |
d4e9c4c3 | 920 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
b3b94faa DT |
921 | gfs2_dinode_out(&ip->i_di, dibh->b_data); |
922 | } | |
923 | } | |
924 | ||
925 | brelse(dibh); | |
926 | ||
927 | out: | |
928 | gfs2_trans_end(sdp); | |
929 | ||
930 | return error; | |
931 | } | |
932 | ||
933 | static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size) | |
934 | { | |
935 | unsigned int height = ip->i_di.di_height; | |
936 | uint64_t lblock; | |
937 | struct metapath mp; | |
938 | int error; | |
939 | ||
940 | if (!size) | |
941 | lblock = 0; | |
18ec7d5c | 942 | else |
feaa7bba | 943 | lblock = (size - 1) >> GFS2_SB(&ip->i_inode)->sd_sb.sb_bsize_shift; |
b3b94faa DT |
944 | |
945 | find_metapath(ip, lblock, &mp); | |
946 | gfs2_alloc_get(ip); | |
947 | ||
948 | error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); | |
949 | if (error) | |
950 | goto out; | |
951 | ||
952 | while (height--) { | |
953 | struct strip_mine sm; | |
954 | sm.sm_first = !!size; | |
955 | sm.sm_height = height; | |
956 | ||
957 | error = recursive_scan(ip, NULL, &mp, 0, 0, 1, do_strip, &sm); | |
958 | if (error) | |
959 | break; | |
960 | } | |
961 | ||
962 | gfs2_quota_unhold(ip); | |
963 | ||
964 | out: | |
965 | gfs2_alloc_put(ip); | |
966 | return error; | |
967 | } | |
968 | ||
969 | static int trunc_end(struct gfs2_inode *ip) | |
970 | { | |
feaa7bba | 971 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
b3b94faa DT |
972 | struct buffer_head *dibh; |
973 | int error; | |
974 | ||
975 | error = gfs2_trans_begin(sdp, RES_DINODE, 0); | |
976 | if (error) | |
977 | return error; | |
978 | ||
979 | down_write(&ip->i_rw_mutex); | |
980 | ||
981 | error = gfs2_meta_inode_buffer(ip, &dibh); | |
982 | if (error) | |
983 | goto out; | |
984 | ||
985 | if (!ip->i_di.di_size) { | |
986 | ip->i_di.di_height = 0; | |
987 | ip->i_di.di_goal_meta = | |
988 | ip->i_di.di_goal_data = | |
989 | ip->i_num.no_addr; | |
990 | gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); | |
991 | } | |
992 | ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds(); | |
993 | ip->i_di.di_flags &= ~GFS2_DIF_TRUNC_IN_PROG; | |
994 | ||
d4e9c4c3 | 995 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
b3b94faa DT |
996 | gfs2_dinode_out(&ip->i_di, dibh->b_data); |
997 | brelse(dibh); | |
998 | ||
999 | out: | |
1000 | up_write(&ip->i_rw_mutex); | |
1001 | ||
1002 | gfs2_trans_end(sdp); | |
1003 | ||
1004 | return error; | |
1005 | } | |
1006 | ||
1007 | /** | |
1008 | * do_shrink - make a file smaller | |
1009 | * @ip: the inode | |
1010 | * @size: the size to make the file | |
1011 | * @truncator: function to truncate the last partial block | |
1012 | * | |
1013 | * Called with an exclusive lock on @ip. | |
1014 | * | |
1015 | * Returns: errno | |
1016 | */ | |
1017 | ||
aa6a85a9 | 1018 | static int do_shrink(struct gfs2_inode *ip, uint64_t size) |
b3b94faa DT |
1019 | { |
1020 | int error; | |
1021 | ||
aa6a85a9 | 1022 | error = trunc_start(ip, size); |
b3b94faa DT |
1023 | if (error < 0) |
1024 | return error; | |
1025 | if (error > 0) | |
1026 | return 0; | |
1027 | ||
1028 | error = trunc_dealloc(ip, size); | |
1029 | if (!error) | |
1030 | error = trunc_end(ip); | |
1031 | ||
1032 | return error; | |
1033 | } | |
1034 | ||
1035 | /** | |
666a2c53 | 1036 | * gfs2_truncatei - make a file a given size |
b3b94faa DT |
1037 | * @ip: the inode |
1038 | * @size: the size to make the file | |
1039 | * @truncator: function to truncate the last partial block | |
1040 | * | |
1041 | * The file size can grow, shrink, or stay the same size. | |
1042 | * | |
1043 | * Returns: errno | |
1044 | */ | |
1045 | ||
aa6a85a9 | 1046 | int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size) |
b3b94faa DT |
1047 | { |
1048 | int error; | |
1049 | ||
feaa7bba | 1050 | if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), S_ISREG(ip->i_di.di_mode))) |
b3b94faa DT |
1051 | return -EINVAL; |
1052 | ||
1053 | if (size > ip->i_di.di_size) | |
1054 | error = do_grow(ip, size); | |
1055 | else | |
aa6a85a9 | 1056 | error = do_shrink(ip, size); |
b3b94faa DT |
1057 | |
1058 | return error; | |
1059 | } | |
1060 | ||
1061 | int gfs2_truncatei_resume(struct gfs2_inode *ip) | |
1062 | { | |
1063 | int error; | |
1064 | error = trunc_dealloc(ip, ip->i_di.di_size); | |
1065 | if (!error) | |
1066 | error = trunc_end(ip); | |
1067 | return error; | |
1068 | } | |
1069 | ||
1070 | int gfs2_file_dealloc(struct gfs2_inode *ip) | |
1071 | { | |
1072 | return trunc_dealloc(ip, 0); | |
1073 | } | |
1074 | ||
1075 | /** | |
1076 | * gfs2_write_calc_reserv - calculate number of blocks needed to write to a file | |
1077 | * @ip: the file | |
1078 | * @len: the number of bytes to be written to the file | |
1079 | * @data_blocks: returns the number of data blocks required | |
1080 | * @ind_blocks: returns the number of indirect blocks required | |
1081 | * | |
1082 | */ | |
1083 | ||
1084 | void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, | |
1085 | unsigned int *data_blocks, unsigned int *ind_blocks) | |
1086 | { | |
feaa7bba | 1087 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
b3b94faa DT |
1088 | unsigned int tmp; |
1089 | ||
18ec7d5c | 1090 | if (gfs2_is_dir(ip)) { |
5c676f6d | 1091 | *data_blocks = DIV_ROUND_UP(len, sdp->sd_jbsize) + 2; |
b3b94faa DT |
1092 | *ind_blocks = 3 * (sdp->sd_max_jheight - 1); |
1093 | } else { | |
1094 | *data_blocks = (len >> sdp->sd_sb.sb_bsize_shift) + 3; | |
1095 | *ind_blocks = 3 * (sdp->sd_max_height - 1); | |
1096 | } | |
1097 | ||
1098 | for (tmp = *data_blocks; tmp > sdp->sd_diptrs;) { | |
5c676f6d | 1099 | tmp = DIV_ROUND_UP(tmp, sdp->sd_inptrs); |
b3b94faa DT |
1100 | *ind_blocks += tmp; |
1101 | } | |
1102 | } | |
1103 | ||
1104 | /** | |
1105 | * gfs2_write_alloc_required - figure out if a write will require an allocation | |
1106 | * @ip: the file being written to | |
1107 | * @offset: the offset to write to | |
1108 | * @len: the number of bytes being written | |
1109 | * @alloc_required: set to 1 if an alloc is required, 0 otherwise | |
1110 | * | |
1111 | * Returns: errno | |
1112 | */ | |
1113 | ||
1114 | int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, | |
1115 | unsigned int len, int *alloc_required) | |
1116 | { | |
feaa7bba | 1117 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
b3b94faa DT |
1118 | uint64_t lblock, lblock_stop, dblock; |
1119 | uint32_t extlen; | |
1120 | int new = 0; | |
1121 | int error = 0; | |
1122 | ||
1123 | *alloc_required = 0; | |
1124 | ||
1125 | if (!len) | |
1126 | return 0; | |
1127 | ||
1128 | if (gfs2_is_stuffed(ip)) { | |
1129 | if (offset + len > | |
1130 | sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) | |
1131 | *alloc_required = 1; | |
1132 | return 0; | |
1133 | } | |
1134 | ||
18ec7d5c | 1135 | if (gfs2_is_dir(ip)) { |
b3b94faa DT |
1136 | unsigned int bsize = sdp->sd_jbsize; |
1137 | lblock = offset; | |
1138 | do_div(lblock, bsize); | |
1139 | lblock_stop = offset + len + bsize - 1; | |
1140 | do_div(lblock_stop, bsize); | |
1141 | } else { | |
1142 | unsigned int shift = sdp->sd_sb.sb_bsize_shift; | |
1143 | lblock = offset >> shift; | |
1144 | lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift; | |
1145 | } | |
1146 | ||
1147 | for (; lblock < lblock_stop; lblock += extlen) { | |
feaa7bba | 1148 | error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen); |
b3b94faa DT |
1149 | if (error) |
1150 | return error; | |
1151 | ||
1152 | if (!dblock) { | |
1153 | *alloc_required = 1; | |
1154 | return 0; | |
1155 | } | |
1156 | } | |
1157 | ||
1158 | return 0; | |
1159 | } | |
1160 |