Lines Matching +full:ip +full:- +full:block

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
4 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
33 * block is 512, so __u16 is fine for that. It saves stack space to
43 static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length);
46 * gfs2_unstuffer_page - unstuff a stuffed inode into a block cached by a page
47 * @ip: the inode
49 * @block: the block number that was allocated
55 static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, in gfs2_unstuffer_page() argument
56 u64 block, struct page *page) in gfs2_unstuffer_page() argument
58 struct inode *inode = &ip->i_inode; in gfs2_unstuffer_page()
61 if (!page || page->index) { in gfs2_unstuffer_page()
62 page = find_or_create_page(inode->i_mapping, 0, GFP_NOFS); in gfs2_unstuffer_page()
64 return -ENOMEM; in gfs2_unstuffer_page()
72 if (dsize > gfs2_max_stuffed_size(ip)) in gfs2_unstuffer_page()
73 dsize = gfs2_max_stuffed_size(ip); in gfs2_unstuffer_page()
75 memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), dsize); in gfs2_unstuffer_page()
76 memset(kaddr + dsize, 0, PAGE_SIZE - dsize); in gfs2_unstuffer_page()
82 if (gfs2_is_jdata(ip)) { in gfs2_unstuffer_page()
86 create_empty_buffers(page, BIT(inode->i_blkbits), in gfs2_unstuffer_page()
91 map_bh(bh, inode->i_sb, block); in gfs2_unstuffer_page()
94 gfs2_trans_add_data(ip->i_gl, bh); in gfs2_unstuffer_page()
97 gfs2_ordered_add_inode(ip); in gfs2_unstuffer_page()
109 * gfs2_unstuff_dinode - Unstuff a dinode when the data has grown too big
110 * @ip: The GFS2 inode to unstuff
119 int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page) in gfs2_unstuff_dinode() argument
123 u64 block = 0; in gfs2_unstuff_dinode() local
124 int isdir = gfs2_is_dir(ip); in gfs2_unstuff_dinode()
127 down_write(&ip->i_rw_mutex); in gfs2_unstuff_dinode()
129 error = gfs2_meta_inode_buffer(ip, &dibh); in gfs2_unstuff_dinode()
133 if (i_size_read(&ip->i_inode)) { in gfs2_unstuff_dinode()
134 /* Get a free block, fill it with the stuffed data, in gfs2_unstuff_dinode()
138 error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL); in gfs2_unstuff_dinode()
142 gfs2_trans_remove_revoke(GFS2_SB(&ip->i_inode), block, 1); in gfs2_unstuff_dinode()
143 error = gfs2_dir_get_new_buffer(ip, block, &bh); in gfs2_unstuff_dinode()
150 error = gfs2_unstuffer_page(ip, dibh, block, page); in gfs2_unstuff_dinode()
156 /* Set up the pointer to the new block */ in gfs2_unstuff_dinode()
158 gfs2_trans_add_meta(ip->i_gl, dibh); in gfs2_unstuff_dinode()
159 di = (struct gfs2_dinode *)dibh->b_data; in gfs2_unstuff_dinode()
162 if (i_size_read(&ip->i_inode)) { in gfs2_unstuff_dinode()
163 *(__be64 *)(di + 1) = cpu_to_be64(block); in gfs2_unstuff_dinode()
164 gfs2_add_inode_blocks(&ip->i_inode, 1); in gfs2_unstuff_dinode()
165 di->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode)); in gfs2_unstuff_dinode()
168 ip->i_height = 1; in gfs2_unstuff_dinode()
169 di->di_height = cpu_to_be16(1); in gfs2_unstuff_dinode()
174 up_write(&ip->i_rw_mutex); in gfs2_unstuff_dinode()
180 * find_metapath - Find path through the metadata tree
182 * @block: The disk block to look up
184 * @height: The pre-calculated height of the metadata tree
187 * through the metadata of inode "ip" to get to block "block".
190 * Given: "ip" is a height 3 file, "offset" is 101342453, and this is a
196 * That means that in order to get to the block containing the byte at
197 * offset 101342453, we would load the indirect block pointed to by pointer
198 * 0 in the dinode. We would then load the indirect block pointed to by
199 * pointer 48 in that indirect block. We would then load the data block
200 * pointed to by pointer 165 in that indirect block.
202 * ----------------------------------------
207 * ----------------------------------------
211 * ----------------------------------------
212 * | Indirect Block |
216 * ----------------------------------------
220 * ----------------------------------------
221 * | Indirect Block |
225 * ----------------------------------------
229 * ----------------------------------------
230 * | Data block containing offset |
234 * ----------------------------------------
238 static void find_metapath(const struct gfs2_sbd *sdp, u64 block, in find_metapath() argument
243 mp->mp_fheight = height; in find_metapath()
244 for (i = height; i--;) in find_metapath()
245 mp->mp_list[i] = do_div(block, sdp->sd_inptrs); in find_metapath()
250 if (mp->mp_list[0] == 0) in metapath_branch_start()
256 * metaptr1 - Return the first possible metadata pointer in a metapath buffer
262 struct buffer_head *bh = mp->mp_bh[height]; in metaptr1()
264 return ((__be64 *)(bh->b_data + sizeof(struct gfs2_dinode))); in metaptr1()
265 return ((__be64 *)(bh->b_data + sizeof(struct gfs2_meta_header))); in metaptr1()
269 * metapointer - Return pointer to start of metadata in a buffer
273 * Return a pointer to the block number of the next height of the metadata
281 return p + mp->mp_list[height]; in metapointer()
286 const struct buffer_head *bh = mp->mp_bh[height]; in metaend()
287 return (const __be64 *)(bh->b_data + bh->b_size); in metaend()
295 for (hgt = 0; hgt < mp->mp_aheight; hgt++) in clone_metapath()
296 get_bh(clone->mp_bh[hgt]); in clone_metapath()
312 rabh->b_end_io = end_buffer_read_sync; in gfs2_metapath_ra()
324 static int __fillup_metapath(struct gfs2_inode *ip, struct metapath *mp, in __fillup_metapath() argument
334 ret = gfs2_meta_indirect_buffer(ip, x + 1, dblock, &mp->mp_bh[x + 1]); in __fillup_metapath()
338 mp->mp_aheight = x + 1; in __fillup_metapath()
343 * lookup_metapath - Walk the metadata tree to a specific point
344 * @ip: The inode
348 * hooked onto mp->mp_bh[0] and that the metapath has been initialised
353 * at which it found the unallocated block. Blocks which are found are
354 * added to the mp->mp_bh[] list.
359 static int lookup_metapath(struct gfs2_inode *ip, struct metapath *mp) in lookup_metapath() argument
361 return __fillup_metapath(ip, mp, 0, ip->i_height - 1); in lookup_metapath()
365 * fillup_metapath - fill up buffers for the metadata path to a specific height
366 * @ip: The inode
375 static int fillup_metapath(struct gfs2_inode *ip, struct metapath *mp, int h) in fillup_metapath() argument
382 for (x = h - 1; x > 0; x--) { in fillup_metapath()
383 if (mp->mp_bh[x]) in fillup_metapath()
387 ret = __fillup_metapath(ip, mp, x, h); in fillup_metapath()
390 return mp->mp_aheight - x - 1; in fillup_metapath()
395 sector_t factor = 1, block = 0; in metapath_to_block() local
398 for (hgt = mp->mp_fheight - 1; hgt >= 0; hgt--) { in metapath_to_block()
399 if (hgt < mp->mp_aheight) in metapath_to_block()
400 block += mp->mp_list[hgt] * factor; in metapath_to_block()
401 factor *= sdp->sd_inptrs; in metapath_to_block()
403 return block; in metapath_to_block()
411 if (mp->mp_bh[i] == NULL) in release_metapath()
413 brelse(mp->mp_bh[i]); in release_metapath()
414 mp->mp_bh[i] = NULL; in release_metapath()
419 * gfs2_extent_length - Returns length of an extent of blocks
420 * @bh: The metadata block
423 * @eob: Set to 1 if we hit "end of block"
425 * Returns: The length of the extent (minimum of one block)
430 const __be64 *end = (__be64 *)(bh->b_data + bh->b_size); in gfs2_extent_length()
443 return ptr - first; in gfs2_extent_length()
449 * gfs2_metadata_walker - walk an indirect block
450 * @mp: Metapath to indirect block
454 * indirect block to follow.
460 * gfs2_walk_metadata - walk a tree of indirect blocks
473 struct gfs2_inode *ip = GFS2_I(inode);
480 * The walk starts in the lowest allocated indirect block, which may be
484 for (hgt = mp->mp_fheight - 1; hgt >= mp->mp_aheight; hgt--) {
485 max_len += mp->mp_list[hgt] * factor;
486 mp->mp_list[hgt] = 0;
487 factor *= sdp->sd_inptrs;
491 u16 start = mp->mp_list[hgt];
496 /* Walk indirect block. */
497 ptrs = (hgt >= 1 ? sdp->sd_inptrs : sdp->sd_diptrs) - start;
506 BUG_ON(mp->mp_aheight == mp->mp_fheight);
507 ptrs = mp->mp_list[hgt] - start;
515 max_len -= len;
521 brelse(mp->mp_bh[hgt]);
522 mp->mp_bh[hgt] = NULL;
523 mp->mp_list[hgt] = 0;
526 hgt--;
527 factor *= sdp->sd_inptrs;
530 (mp->mp_list[hgt])++;
532 if (mp->mp_list[hgt] >= sdp->sd_inptrs)
535 if (mp->mp_list[hgt] >= sdp->sd_diptrs)
541 ret = fillup_metapath(ip, mp, ip->i_height - 1);
545 for (; ret; ret--)
546 do_div(factor, sdp->sd_inptrs);
547 mp->mp_aheight = hgt + 1;
558 hgt = mp->mp_aheight - 1; in gfs2_hole_walker()
564 mp->mp_list[hgt] += ptr - start; in gfs2_hole_walker()
565 if (mp->mp_aheight == mp->mp_fheight) in gfs2_hole_walker()
574 * gfs2_hole_size - figure out the size of a hole
576 * @lblock: The logical starting block number
598 hole_size = metapath_to_block(GFS2_SB(inode), &clone) - lblock; in gfs2_hole_size()
601 iomap->length = hole_size << inode->i_blkbits; in gfs2_hole_size()
613 __be64 *ptr = (__be64 *)(mp->mp_bh[i - 1]->b_data + in gfs2_indirect_init()
617 BUG_ON(mp->mp_bh[i] != NULL); in gfs2_indirect_init()
618 mp->mp_bh[i] = gfs2_meta_new(gl, bn); in gfs2_indirect_init()
619 gfs2_trans_add_meta(gl, mp->mp_bh[i]); in gfs2_indirect_init()
620 gfs2_metatype_set(mp->mp_bh[i], GFS2_METATYPE_IN, GFS2_FORMAT_IN); in gfs2_indirect_init()
621 gfs2_buffer_clear_tail(mp->mp_bh[i], sizeof(struct gfs2_meta_header)); in gfs2_indirect_init()
635 * gfs2_iomap_alloc - Build a metadata tree of the requested height
653 * Right now, this function will allocate at most one indirect block
654 * worth of data -- with a default block size of 4K, that's slightly
666 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_iomap_alloc() local
668 struct buffer_head *dibh = mp->mp_bh[0]; in gfs2_iomap_alloc()
671 size_t dblks = iomap->length >> inode->i_blkbits; in gfs2_iomap_alloc()
672 const unsigned end_of_metadata = mp->mp_fheight - 1; in gfs2_iomap_alloc()
678 BUG_ON(mp->mp_aheight < 1); in gfs2_iomap_alloc()
682 gfs2_trans_add_meta(ip->i_gl, dibh); in gfs2_iomap_alloc()
684 down_write(&ip->i_rw_mutex); in gfs2_iomap_alloc()
686 if (mp->mp_fheight == mp->mp_aheight) { in gfs2_iomap_alloc()
687 /* Bottom indirect block exists */ in gfs2_iomap_alloc()
691 if (mp->mp_fheight == ip->i_height) { in gfs2_iomap_alloc()
693 iblks = mp->mp_fheight - mp->mp_aheight; in gfs2_iomap_alloc()
698 iblks = mp->mp_fheight - ip->i_height; in gfs2_iomap_alloc()
700 iblks += (mp->mp_fheight - branch_start); in gfs2_iomap_alloc()
707 i = mp->mp_aheight; in gfs2_iomap_alloc()
709 n = blks - alloced; in gfs2_iomap_alloc()
710 ret = gfs2_alloc_blocks(ip, &bn, &n, 0, NULL); in gfs2_iomap_alloc()
714 if (state != ALLOC_DATA || gfs2_is_jdata(ip)) in gfs2_iomap_alloc()
720 ptr = (__be64 *)(dibh->b_data + in gfs2_iomap_alloc()
724 for (; i - 1 < mp->mp_fheight - ip->i_height && n > 0; in gfs2_iomap_alloc()
725 i++, n--) in gfs2_iomap_alloc()
726 gfs2_indirect_init(mp, ip->i_gl, i, 0, bn++); in gfs2_iomap_alloc()
727 if (i - 1 == mp->mp_fheight - ip->i_height) { in gfs2_iomap_alloc()
728 i--; in gfs2_iomap_alloc()
729 gfs2_buffer_copy_tail(mp->mp_bh[i], in gfs2_iomap_alloc()
735 ptr = (__be64 *)(mp->mp_bh[i]->b_data + in gfs2_iomap_alloc()
739 for(i = branch_start; i < mp->mp_fheight; i++) { in gfs2_iomap_alloc()
740 if (mp->mp_bh[i] == NULL) in gfs2_iomap_alloc()
742 brelse(mp->mp_bh[i]); in gfs2_iomap_alloc()
743 mp->mp_bh[i] = NULL; in gfs2_iomap_alloc()
751 if (i > 1 && i < mp->mp_fheight) in gfs2_iomap_alloc()
752 gfs2_trans_add_meta(ip->i_gl, mp->mp_bh[i-1]); in gfs2_iomap_alloc()
753 for (; i < mp->mp_fheight && n > 0; i++, n--) in gfs2_iomap_alloc()
754 gfs2_indirect_init(mp, ip->i_gl, i, in gfs2_iomap_alloc()
755 mp->mp_list[i-1], bn++); in gfs2_iomap_alloc()
756 if (i == mp->mp_fheight) in gfs2_iomap_alloc()
763 BUG_ON(mp->mp_bh[end_of_metadata] == NULL); in gfs2_iomap_alloc()
764 gfs2_trans_add_meta(ip->i_gl, mp->mp_bh[end_of_metadata]); in gfs2_iomap_alloc()
767 iomap->addr = bn << inode->i_blkbits; in gfs2_iomap_alloc()
768 iomap->flags |= IOMAP_F_MERGED | IOMAP_F_NEW; in gfs2_iomap_alloc()
769 while (n-- > 0) in gfs2_iomap_alloc()
773 } while (iomap->addr == IOMAP_NULL_ADDR); in gfs2_iomap_alloc()
775 iomap->type = IOMAP_MAPPED; in gfs2_iomap_alloc()
776 iomap->length = (u64)dblks << inode->i_blkbits; in gfs2_iomap_alloc()
777 ip->i_height = mp->mp_fheight; in gfs2_iomap_alloc()
778 gfs2_add_inode_blocks(&ip->i_inode, alloced); in gfs2_iomap_alloc()
779 gfs2_dinode_out(ip, dibh->b_data); in gfs2_iomap_alloc()
781 up_write(&ip->i_rw_mutex); in gfs2_iomap_alloc()
788 * gfs2_alloc_size - Compute the maximum allocation size
799 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_alloc_size() local
811 if (gfs2_is_stuffed(ip) || mp->mp_fheight != mp->mp_aheight) { in gfs2_alloc_size()
812 unsigned int maxsize = mp->mp_fheight > 1 ? in gfs2_alloc_size()
813 sdp->sd_inptrs : sdp->sd_diptrs; in gfs2_alloc_size()
814 maxsize -= mp->mp_list[mp->mp_fheight - 1]; in gfs2_alloc_size()
820 first = metapointer(ip->i_height - 1, mp); in gfs2_alloc_size()
821 end = metaend(ip->i_height - 1, mp); in gfs2_alloc_size()
822 if (end - first > size) in gfs2_alloc_size()
828 return ptr - first; in gfs2_alloc_size()
832 * gfs2_iomap_get - Map blocks from an inode to disk blocks
846 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_iomap_get() local
859 return -EINVAL; in gfs2_iomap_get()
861 down_read(&ip->i_rw_mutex); in gfs2_iomap_get()
863 ret = gfs2_meta_inode_buffer(ip, &dibh); in gfs2_iomap_get()
866 mp->mp_bh[0] = dibh; in gfs2_iomap_get()
868 if (gfs2_is_stuffed(ip)) { in gfs2_iomap_get()
870 loff_t max_size = gfs2_max_stuffed_size(ip); in gfs2_iomap_get()
874 iomap->length = max_size; in gfs2_iomap_get()
878 ret = -ENOENT; in gfs2_iomap_get()
881 iomap->offset = pos; in gfs2_iomap_get()
882 iomap->length = length; in gfs2_iomap_get()
886 iomap->length = size; in gfs2_iomap_get()
888 iomap->addr = (ip->i_no_addr << inode->i_blkbits) + in gfs2_iomap_get()
890 iomap->type = IOMAP_INLINE; in gfs2_iomap_get()
891 iomap->inline_data = dibh->b_data + sizeof(struct gfs2_dinode); in gfs2_iomap_get()
896 lblock = pos >> inode->i_blkbits; in gfs2_iomap_get()
897 iomap->offset = lblock << inode->i_blkbits; in gfs2_iomap_get()
898 lblock_stop = (pos + length - 1) >> inode->i_blkbits; in gfs2_iomap_get()
899 len = lblock_stop - lblock + 1; in gfs2_iomap_get()
900 iomap->length = len << inode->i_blkbits; in gfs2_iomap_get()
902 height = ip->i_height; in gfs2_iomap_get()
903 while ((lblock + 1) * sdp->sd_sb.sb_bsize > sdp->sd_heightsize[height]) in gfs2_iomap_get()
906 if (height > ip->i_height || gfs2_is_stuffed(ip)) in gfs2_iomap_get()
909 ret = lookup_metapath(ip, mp); in gfs2_iomap_get()
913 if (mp->mp_aheight != ip->i_height) in gfs2_iomap_get()
916 ptr = metapointer(ip->i_height - 1, mp); in gfs2_iomap_get()
920 bh = mp->mp_bh[ip->i_height - 1]; in gfs2_iomap_get()
923 iomap->addr = be64_to_cpu(*ptr) << inode->i_blkbits; in gfs2_iomap_get()
924 iomap->length = len << inode->i_blkbits; in gfs2_iomap_get()
925 iomap->type = IOMAP_MAPPED; in gfs2_iomap_get()
926 iomap->flags |= IOMAP_F_MERGED; in gfs2_iomap_get()
928 iomap->flags |= IOMAP_F_GFS2_BOUNDARY; in gfs2_iomap_get()
931 iomap->bdev = inode->i_sb->s_bdev; in gfs2_iomap_get()
933 up_read(&ip->i_rw_mutex); in gfs2_iomap_get()
939 ret = -ENOENT; in gfs2_iomap_get()
940 else if (height == ip->i_height) in gfs2_iomap_get()
943 iomap->length = size - pos; in gfs2_iomap_get()
951 alloc_size = len << inode->i_blkbits; in gfs2_iomap_get()
952 if (alloc_size < iomap->length) in gfs2_iomap_get()
953 iomap->length = alloc_size; in gfs2_iomap_get()
955 if (pos < size && height == ip->i_height) in gfs2_iomap_get()
959 iomap->addr = IOMAP_NULL_ADDR; in gfs2_iomap_get()
960 iomap->type = IOMAP_HOLE; in gfs2_iomap_get()
965 * gfs2_lblk_to_dblk - convert logical block to disk block
967 * @lblock: the block relative to the start of the file
970 * This function maps a single block from a file logical block (relative to
971 * the start of the file) to a file system absolute block using iomap.
973 * Returns: the absolute file system block, or an error
979 loff_t pos = (loff_t)lblock << inode->i_blkbits; in gfs2_lblk_to_dblk()
985 *dblock = iomap.addr >> inode->i_blkbits; in gfs2_lblk_to_dblk()
992 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_write_lock() local
996 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &ip->i_gh); in gfs2_write_lock()
997 error = gfs2_glock_nq(&ip->i_gh); in gfs2_write_lock()
1000 if (&ip->i_inode == sdp->sd_rindex) { in gfs2_write_lock()
1001 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); in gfs2_write_lock()
1003 error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, in gfs2_write_lock()
1004 GL_NOCACHE, &m_ip->i_gh); in gfs2_write_lock()
1011 gfs2_glock_dq(&ip->i_gh); in gfs2_write_lock()
1013 gfs2_holder_uninit(&ip->i_gh); in gfs2_write_lock()
1019 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_write_unlock() local
1022 if (&ip->i_inode == sdp->sd_rindex) { in gfs2_write_unlock()
1023 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); in gfs2_write_unlock()
1025 gfs2_glock_dq_uninit(&m_ip->i_gh); in gfs2_write_unlock()
1027 gfs2_glock_dq_uninit(&ip->i_gh); in gfs2_write_unlock()
1033 unsigned int blockmask = i_blocksize(inode) - 1; in gfs2_iomap_page_prepare()
1037 blocks = ((pos & blockmask) + len + blockmask) >> inode->i_blkbits; in gfs2_iomap_page_prepare()
1045 struct gfs2_trans *tr = current->journal_info; in gfs2_iomap_page_done()
1046 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_iomap_page_done() local
1049 if (page && !gfs2_is_stuffed(ip)) in gfs2_iomap_page_done()
1050 gfs2_page_add_databufs(ip, page, offset_in_page(pos), copied); in gfs2_iomap_page_done()
1052 if (tr->tr_num_buf_new) in gfs2_iomap_page_done()
1068 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_iomap_begin_write() local
1073 unstuff = gfs2_is_stuffed(ip) && in gfs2_iomap_begin_write()
1074 pos + length > gfs2_max_stuffed_size(ip); in gfs2_iomap_begin_write()
1076 if (unstuff || iomap->type == IOMAP_HOLE) { in gfs2_iomap_begin_write()
1082 gfs2_write_calc_reserv(ip, iomap->length, &data_blocks, in gfs2_iomap_begin_write()
1085 ret = gfs2_quota_lock_check(ip, &ap); in gfs2_iomap_begin_write()
1089 ret = gfs2_inplace_reserve(ip, &ap); in gfs2_iomap_begin_write()
1094 if (gfs2_is_jdata(ip)) in gfs2_iomap_begin_write()
1098 if (inode == sdp->sd_rindex) in gfs2_iomap_begin_write()
1100 rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks); in gfs2_iomap_begin_write()
1103 iomap->length >> inode->i_blkbits); in gfs2_iomap_begin_write()
1108 ret = gfs2_unstuff_dinode(ip, NULL); in gfs2_iomap_begin_write()
1112 ret = gfs2_iomap_get(inode, iomap->offset, in gfs2_iomap_begin_write()
1113 iomap->length, flags, iomap, mp); in gfs2_iomap_begin_write()
1118 if (iomap->type == IOMAP_HOLE) { in gfs2_iomap_begin_write()
1122 gfs2_inplace_release(ip); in gfs2_iomap_begin_write()
1123 punch_hole(ip, iomap->offset, iomap->length); in gfs2_iomap_begin_write()
1128 tr = current->journal_info; in gfs2_iomap_begin_write()
1129 if (tr->tr_num_buf_new) in gfs2_iomap_begin_write()
1135 if (gfs2_is_stuffed(ip) || gfs2_is_jdata(ip)) in gfs2_iomap_begin_write()
1136 iomap->page_ops = &gfs2_iomap_page_ops; in gfs2_iomap_begin_write()
1142 gfs2_inplace_release(ip); in gfs2_iomap_begin_write()
1144 gfs2_quota_unlock(ip); in gfs2_iomap_begin_write()
1157 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_iomap_begin() local
1161 if (gfs2_is_jdata(ip)) in gfs2_iomap_begin()
1162 iomap->flags |= IOMAP_F_BUFFER_HEAD; in gfs2_iomap_begin()
1164 trace_gfs2_iomap_start(ip, pos, length, flags); in gfs2_iomap_begin()
1182 if (iomap->type != IOMAP_MAPPED) in gfs2_iomap_begin()
1183 ret = -ENOTBLK; in gfs2_iomap_begin()
1188 if (iomap->type == IOMAP_HOLE) in gfs2_iomap_begin()
1202 trace_gfs2_iomap_end(ip, iomap, ret); in gfs2_iomap_begin()
1209 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_iomap_end() local
1218 if (iomap->type == IOMAP_HOLE) in gfs2_iomap_end()
1225 if (!gfs2_is_stuffed(ip)) in gfs2_iomap_end()
1226 gfs2_ordered_add_inode(ip); in gfs2_iomap_end()
1228 if (inode == sdp->sd_rindex) in gfs2_iomap_end()
1231 gfs2_inplace_release(ip); in gfs2_iomap_end()
1233 if (length != written && (iomap->flags & IOMAP_F_NEW)) { in gfs2_iomap_end()
1235 loff_t blockmask = i_blocksize(inode) - 1; in gfs2_iomap_end()
1240 truncate_pagecache_range(inode, pos, end - 1); in gfs2_iomap_end()
1241 punch_hole(ip, pos, end - pos); in gfs2_iomap_end()
1245 if (ip->i_qadata && ip->i_qadata->qa_qd_num) in gfs2_iomap_end()
1246 gfs2_quota_unlock(ip); in gfs2_iomap_end()
1251 if (iomap->flags & IOMAP_F_SIZE_CHANGED) in gfs2_iomap_end()
1253 set_bit(GLF_DIRTY, &ip->i_gl->gl_flags); in gfs2_iomap_end()
1267 * gfs2_block_map - Map one or more blocks of an inode to a disk block
1269 * @lblock: The logical block number
1273 * The size of the requested mapping is defined in bh_map->b_size.
1275 * Clears buffer_mapped(bh_map) and leaves bh_map->b_size unchanged
1277 * bh_map->b_size to indicate the size of the mapping when @lblock and
1281 * before the next block can be mapped. Sets buffer_new() if new
1290 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_block_map() local
1291 loff_t pos = (loff_t)lblock << inode->i_blkbits; in gfs2_block_map()
1292 loff_t length = bh_map->b_size; in gfs2_block_map()
1301 trace_gfs2_bmap(ip, bh_map, lblock, create, 1); in gfs2_block_map()
1310 if (iomap.length > bh_map->b_size) { in gfs2_block_map()
1311 iomap.length = bh_map->b_size; in gfs2_block_map()
1315 map_bh(bh_map, inode->i_sb, iomap.addr >> inode->i_blkbits); in gfs2_block_map()
1316 bh_map->b_size = iomap.length; in gfs2_block_map()
1323 trace_gfs2_bmap(ip, bh_map, lblock, create, ret); in gfs2_block_map()
1340 bh.b_size = BIT(inode->i_blkbits + (create ? 0 : 5)); in gfs2_extent_map()
1342 *extlen = bh.b_size >> inode->i_blkbits; in gfs2_extent_map()
1359 BUG_ON(current->journal_info); in gfs2_block_zero_range()
1366 * gfs2_journaled_truncate - Wrapper for truncate_pagecache for jdata files
1371 * With jdata files, we have to journal a revoke for each block which is
1379 u64 max_chunk = GFS2_JTRUNC_REVOKES * sdp->sd_vfs->s_blocksize; in gfs2_journaled_truncate()
1387 chunk = oldsize - newsize; in gfs2_journaled_truncate()
1393 chunk = offs + ((chunk - offs) & PAGE_MASK); in gfs2_journaled_truncate()
1395 truncate_pagecache(inode, oldsize - chunk); in gfs2_journaled_truncate()
1396 oldsize -= chunk; in gfs2_journaled_truncate()
1398 tr = current->journal_info; in gfs2_journaled_truncate()
1399 if (!test_bit(TR_TOUCHED, &tr->tr_flags)) in gfs2_journaled_truncate()
1413 struct gfs2_inode *ip = GFS2_I(inode); in trunc_start() local
1416 int journaled = gfs2_is_jdata(ip); in trunc_start()
1417 u64 oldsize = inode->i_size; in trunc_start()
1420 if (!gfs2_is_stuffed(ip)) { in trunc_start()
1422 unsigned int offs = newsize & (blocksize - 1); in trunc_start()
1425 blocksize - offs); in trunc_start()
1437 error = gfs2_meta_inode_buffer(ip, &dibh); in trunc_start()
1441 gfs2_trans_add_meta(ip->i_gl, dibh); in trunc_start()
1443 if (gfs2_is_stuffed(ip)) in trunc_start()
1446 ip->i_diskflags |= GFS2_DIF_TRUNC_IN_PROG; in trunc_start()
1449 ip->i_inode.i_mtime = ip->i_inode.i_ctime = current_time(&ip->i_inode); in trunc_start()
1450 gfs2_dinode_out(ip, dibh->b_data); in trunc_start()
1459 if (current->journal_info) in trunc_start()
1471 if (!ret && iomap->type == IOMAP_HOLE) in gfs2_iomap_get_alloc()
1478 * sweep_bh_for_rgrps - find an rgrp in a meta buffer and free blocks therein
1479 * @ip: inode
1489 * block has references to multiple rgrps, we break it into individual
1494 * if we're interrupted by power-outages.
1499 static int sweep_bh_for_rgrps(struct gfs2_inode *ip, struct gfs2_holder *rd_gh, in sweep_bh_for_rgrps() argument
1503 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in sweep_bh_for_rgrps()
1516 rgd = gfs2_glock2rgrp(rd_gh->gh_gl); in sweep_bh_for_rgrps()
1518 gfs2_glock_is_locked_by_me(rd_gh->gh_gl)); in sweep_bh_for_rgrps()
1537 ret = -EIO; in sweep_bh_for_rgrps()
1540 ret = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, in sweep_bh_for_rgrps()
1546 if (gfs2_rs_active(&ip->i_res) && in sweep_bh_for_rgrps()
1547 rgd == ip->i_res.rs_rbm.rgd) in sweep_bh_for_rgrps()
1548 gfs2_rs_deltree(&ip->i_res); in sweep_bh_for_rgrps()
1556 if (current->journal_info == NULL) { in sweep_bh_for_rgrps()
1559 jblocks_rqsted = rgd->rd_length + RES_DINODE + in sweep_bh_for_rgrps()
1561 isize_blks = gfs2_get_inode_blocks(&ip->i_inode); in sweep_bh_for_rgrps()
1562 if (isize_blks > atomic_read(&sdp->sd_log_thresh2)) in sweep_bh_for_rgrps()
1564 atomic_read(&sdp->sd_log_thresh2); in sweep_bh_for_rgrps()
1569 revokes += end - start; in sweep_bh_for_rgrps()
1570 else if (ip->i_depth) in sweep_bh_for_rgrps()
1571 revokes += sdp->sd_inptrs; in sweep_bh_for_rgrps()
1575 down_write(&ip->i_rw_mutex); in sweep_bh_for_rgrps()
1578 tr = current->journal_info; in sweep_bh_for_rgrps()
1579 if (tr->tr_num_buf_new + RES_STATFS + in sweep_bh_for_rgrps()
1580 RES_QUOTA >= atomic_read(&sdp->sd_log_thresh2)) { in sweep_bh_for_rgrps()
1586 to the transaction, we've already set some block in sweep_bh_for_rgrps()
1602 gfs2_trans_add_meta(ip->i_gl, bh); in sweep_bh_for_rgrps()
1610 __gfs2_free_blocks(ip, rgd, bstart, (u32)blen, meta); in sweep_bh_for_rgrps()
1612 gfs2_add_inode_blocks(&ip->i_inode, -blen); in sweep_bh_for_rgrps()
1618 __gfs2_free_blocks(ip, rgd, bstart, (u32)blen, meta); in sweep_bh_for_rgrps()
1620 gfs2_add_inode_blocks(&ip->i_inode, -blen); in sweep_bh_for_rgrps()
1623 if (!ret && blks_outside_rgrp) { /* If buffer still has non-zero blocks in sweep_bh_for_rgrps()
1626 if (current->journal_info) { in sweep_bh_for_rgrps()
1629 ret = gfs2_meta_inode_buffer(ip, &dibh); in sweep_bh_for_rgrps()
1635 ip->i_inode.i_mtime = ip->i_inode.i_ctime = in sweep_bh_for_rgrps()
1636 current_time(&ip->i_inode); in sweep_bh_for_rgrps()
1637 gfs2_trans_add_meta(ip->i_gl, dibh); in sweep_bh_for_rgrps()
1638 gfs2_dinode_out(ip, dibh->b_data); in sweep_bh_for_rgrps()
1640 up_write(&ip->i_rw_mutex); in sweep_bh_for_rgrps()
1654 if (memcmp(mp->mp_list, list, h * sizeof(mp->mp_list[0]))) in mp_eq_to_hgt()
1660 * find_nonnull_ptr - find a non-null pointer given a metapath and height
1665 * Returns: true if a non-null pointer was found in the metapath buffer
1672 struct buffer_head *bh = mp->mp_bh[h]; in find_nonnull_ptr()
1676 ptr = first + mp->mp_list[h]; in find_nonnull_ptr()
1677 end = (__be64 *)(bh->b_data + bh->b_size); in find_nonnull_ptr()
1684 if (*ptr) { /* if we have a non-null pointer */ in find_nonnull_ptr()
1685 mp->mp_list[h] = ptr - first; in find_nonnull_ptr()
1688 mp->mp_list[h] = 0; in find_nonnull_ptr()
1709 struct buffer_head *bh = mp->mp_bh[height]; in metapointer_range()
1718 *end = (__be64 *)(bh->b_data + bh->b_size); in metapointer_range()
1737 end = (height > 0) ? sdp->sd_inptrs : sdp->sd_diptrs; in walk_done()
1738 return mp->mp_list[height] >= end; in walk_done()
1742 * punch_hole - deallocate blocks in a file
1743 * @ip: inode to truncate
1757 static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length) in punch_hole() argument
1759 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in punch_hole()
1760 u64 maxsize = sdp->sd_heightsize[ip->i_height]; in punch_hole()
1764 unsigned int bsize_shift = sdp->sd_sb.sb_bsize_shift; in punch_hole()
1765 u64 lblock = (offset + (1 << bsize_shift) - 1) >> bsize_shift; in punch_hole()
1769 unsigned int strip_h = ip->i_height - 1; in punch_hole()
1778 * The starting point lies beyond the allocated meta-data; in punch_hole()
1812 find_metapath(sdp, lend, &mp, ip->i_height); in punch_hole()
1816 for (mp_h = ip->i_height - 1; mp_h > 0; mp_h--) { in punch_hole()
1823 find_metapath(sdp, lblock, &mp, ip->i_height); in punch_hole()
1826 for (mp_h = ip->i_height - 1; mp_h > 0; mp_h--) { in punch_hole()
1832 ret = gfs2_meta_inode_buffer(ip, &dibh); in punch_hole()
1837 ret = lookup_metapath(ip, &mp); in punch_hole()
1841 /* issue read-ahead on metadata */ in punch_hole()
1842 for (mp_h = 0; mp_h < mp.mp_aheight - 1; mp_h++) { in punch_hole()
1845 gfs2_metapath_ra(ip->i_gl, start, end); in punch_hole()
1848 if (mp.mp_aheight == ip->i_height) in punch_hole()
1857 ret = gfs2_quota_hold(ip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE); in punch_hole()
1872 prev_bnr != bh->b_blocknr)) { in punch_hole()
1873 fs_emerg(sdp, "inode %llu, block:%llu, i_h:%u," in punch_hole()
1875 (unsigned long long)ip->i_no_addr, in punch_hole()
1876 prev_bnr, ip->i_height, strip_h, mp_h); in punch_hole()
1878 prev_bnr = bh->b_blocknr; in punch_hole()
1883 ret = -EIO; in punch_hole()
1896 ret = sweep_bh_for_rgrps(ip, &rd_gh, mp.mp_bh[mp_h], in punch_hole()
1898 mp_h != ip->i_height - 1, in punch_hole()
1923 strip_h--; in punch_hole()
1930 mp_h--; /* search one metadata height down */ in punch_hole()
1936 * next non-null pointer. */ in punch_hole()
1941 /* No more non-null pointers at this height. Back up in punch_hole()
1948 ret = fillup_metapath(ip, &mp, mp_h); in punch_hole()
1952 /* On the first pass, issue read-ahead on metadata. */ in punch_hole()
1953 if (mp.mp_aheight > 1 && strip_h == ip->i_height - 1) { in punch_hole()
1954 unsigned int height = mp.mp_aheight - 1; in punch_hole()
1956 /* No read-ahead for data blocks. */ in punch_hole()
1957 if (mp.mp_aheight - 1 == strip_h) in punch_hole()
1958 height--; in punch_hole()
1960 for (; height >= mp.mp_aheight - ret; height--) { in punch_hole()
1965 gfs2_metapath_ra(ip->i_gl, start, end); in punch_hole()
1970 if (mp.mp_aheight - 1 == strip_h) { in punch_hole()
1974 if (mp.mp_aheight < ip->i_height) /* We have a partial height */ in punch_hole()
1975 mp_h = mp.mp_aheight - 1; in punch_hole()
1977 /* If we find a non-null block pointer, crawl a bit in punch_hole()
1989 if (current->journal_info == NULL) { in punch_hole()
1994 down_write(&ip->i_rw_mutex); in punch_hole()
1997 gfs2_quota_change(ip, -(s64)btotal, ip->i_inode.i_uid, in punch_hole()
1998 ip->i_inode.i_gid); in punch_hole()
1999 ip->i_inode.i_mtime = ip->i_inode.i_ctime = current_time(&ip->i_inode); in punch_hole()
2000 gfs2_trans_add_meta(ip->i_gl, dibh); in punch_hole()
2001 gfs2_dinode_out(ip, dibh->b_data); in punch_hole()
2002 up_write(&ip->i_rw_mutex); in punch_hole()
2009 if (current->journal_info) { in punch_hole()
2010 up_write(&ip->i_rw_mutex); in punch_hole()
2014 gfs2_quota_unhold(ip); in punch_hole()
2020 static int trunc_end(struct gfs2_inode *ip) in trunc_end() argument
2022 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in trunc_end()
2030 down_write(&ip->i_rw_mutex); in trunc_end()
2032 error = gfs2_meta_inode_buffer(ip, &dibh); in trunc_end()
2036 if (!i_size_read(&ip->i_inode)) { in trunc_end()
2037 ip->i_height = 0; in trunc_end()
2038 ip->i_goal = ip->i_no_addr; in trunc_end()
2040 gfs2_ordered_del_inode(ip); in trunc_end()
2042 ip->i_inode.i_mtime = ip->i_inode.i_ctime = current_time(&ip->i_inode); in trunc_end()
2043 ip->i_diskflags &= ~GFS2_DIF_TRUNC_IN_PROG; in trunc_end()
2045 gfs2_trans_add_meta(ip->i_gl, dibh); in trunc_end()
2046 gfs2_dinode_out(ip, dibh->b_data); in trunc_end()
2050 up_write(&ip->i_rw_mutex); in trunc_end()
2056 * do_shrink - make a file smaller
2068 struct gfs2_inode *ip = GFS2_I(inode); in do_shrink() local
2074 if (gfs2_is_stuffed(ip)) in do_shrink()
2077 error = punch_hole(ip, newsize, 0); in do_shrink()
2079 error = trunc_end(ip); in do_shrink()
2088 ret = do_shrink(inode, inode->i_size); in gfs2_trim_blocks()
2093 * do_grow - Touch and update inode size
2109 * Returns: 0 on success, or -ve on error
2114 struct gfs2_inode *ip = GFS2_I(inode); in do_grow() local
2121 if (gfs2_is_stuffed(ip) && size > gfs2_max_stuffed_size(ip)) { in do_grow()
2122 error = gfs2_quota_lock_check(ip, &ap); in do_grow()
2126 error = gfs2_inplace_reserve(ip, &ap); in do_grow()
2134 gfs2_is_jdata(ip) ? RES_JDATA : 0) + in do_grow()
2135 (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF ? in do_grow()
2141 error = gfs2_unstuff_dinode(ip, NULL); in do_grow()
2146 error = gfs2_meta_inode_buffer(ip, &dibh); in do_grow()
2151 ip->i_inode.i_mtime = ip->i_inode.i_ctime = current_time(&ip->i_inode); in do_grow()
2152 gfs2_trans_add_meta(ip->i_gl, dibh); in do_grow()
2153 gfs2_dinode_out(ip, dibh->b_data); in do_grow()
2160 gfs2_inplace_release(ip); in do_grow()
2162 gfs2_quota_unlock(ip); in do_grow()
2168 * gfs2_setattr_size - make a file a given size
2181 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_setattr_size() local
2184 BUG_ON(!S_ISREG(inode->i_mode)); in gfs2_setattr_size()
2192 ret = gfs2_qa_get(ip); in gfs2_setattr_size()
2196 if (newsize >= inode->i_size) { in gfs2_setattr_size()
2203 gfs2_rs_delete(ip, NULL); in gfs2_setattr_size()
2204 gfs2_qa_put(ip); in gfs2_setattr_size()
2208 int gfs2_truncatei_resume(struct gfs2_inode *ip) in gfs2_truncatei_resume() argument
2211 error = punch_hole(ip, i_size_read(&ip->i_inode), 0); in gfs2_truncatei_resume()
2213 error = trunc_end(ip); in gfs2_truncatei_resume()
2217 int gfs2_file_dealloc(struct gfs2_inode *ip) in gfs2_file_dealloc() argument
2219 return punch_hole(ip, 0, 0); in gfs2_file_dealloc()
2223 * gfs2_free_journal_extents - Free cached journal bmap info
2232 while(!list_empty(&jd->extent_list)) { in gfs2_free_journal_extents()
2233 jext = list_first_entry(&jd->extent_list, struct gfs2_journal_extent, list); in gfs2_free_journal_extents()
2234 list_del(&jext->list); in gfs2_free_journal_extents()
2240 * gfs2_add_jextent - Add or merge a new extent to extent cache
2242 * @lblock: The logical block at start of new extent
2243 * @dblock: The physical block at start of new extent
2246 * Returns: 0 on success or -ENOMEM
2253 if (!list_empty(&jd->extent_list)) { in gfs2_add_jextent()
2254 jext = list_last_entry(&jd->extent_list, struct gfs2_journal_extent, list); in gfs2_add_jextent()
2255 if ((jext->dblock + jext->blocks) == dblock) { in gfs2_add_jextent()
2256 jext->blocks += blocks; in gfs2_add_jextent()
2263 return -ENOMEM; in gfs2_add_jextent()
2264 jext->dblock = dblock; in gfs2_add_jextent()
2265 jext->lblock = lblock; in gfs2_add_jextent()
2266 jext->blocks = blocks; in gfs2_add_jextent()
2267 list_add_tail(&jext->list, &jd->extent_list); in gfs2_add_jextent()
2268 jd->nr_extents++; in gfs2_add_jextent()
2273 * gfs2_map_journal_extents - Cache journal bmap info
2274 * @sdp: The super block
2282 * So the extent would map the first block for the entire file length.
2296 struct gfs2_inode *ip = GFS2_I(jd->jd_inode); in gfs2_map_journal_extents() local
2298 unsigned int shift = sdp->sd_sb.sb_bsize_shift; in gfs2_map_journal_extents()
2304 lblock_stop = i_size_read(jd->jd_inode) >> shift; in gfs2_map_journal_extents()
2305 size = (lblock_stop - lblock) << shift; in gfs2_map_journal_extents()
2306 jd->nr_extents = 0; in gfs2_map_journal_extents()
2307 WARN_ON(!list_empty(&jd->extent_list)); in gfs2_map_journal_extents()
2313 rc = gfs2_block_map(jd->jd_inode, lblock, &bh, 0); in gfs2_map_journal_extents()
2319 size -= bh.b_size; in gfs2_map_journal_extents()
2320 lblock += (bh.b_size >> ip->i_inode.i_blkbits); in gfs2_map_journal_extents()
2324 fs_info(sdp, "journal %d mapped with %u extents in %lldms\n", jd->jd_jid, in gfs2_map_journal_extents()
2325 jd->nr_extents, ktime_ms_delta(end, start)); in gfs2_map_journal_extents()
2330 rc, jd->jd_jid, in gfs2_map_journal_extents()
2331 (unsigned long long)(i_size_read(jd->jd_inode) - size), in gfs2_map_journal_extents()
2332 jd->nr_extents); in gfs2_map_journal_extents()
2333 fs_warn(sdp, "bmap=%d lblock=%llu block=%llu, state=0x%08lx, size=%llu\n", in gfs2_map_journal_extents()
2341 * gfs2_write_alloc_required - figure out if a write will require an allocation
2342 * @ip: the file being written to
2349 int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset, in gfs2_write_alloc_required() argument
2352 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_write_alloc_required()
2361 if (gfs2_is_stuffed(ip)) { in gfs2_write_alloc_required()
2362 if (offset + len > gfs2_max_stuffed_size(ip)) in gfs2_write_alloc_required()
2367 shift = sdp->sd_sb.sb_bsize_shift; in gfs2_write_alloc_required()
2368 BUG_ON(gfs2_is_dir(ip)); in gfs2_write_alloc_required()
2369 end_of_file = (i_size_read(&ip->i_inode) + sdp->sd_sb.sb_bsize - 1) >> shift; in gfs2_write_alloc_required()
2371 lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift; in gfs2_write_alloc_required()
2372 if (lblock_stop > end_of_file && ip != GFS2_I(sdp->sd_rindex)) in gfs2_write_alloc_required()
2375 size = (lblock_stop - lblock) << shift; in gfs2_write_alloc_required()
2379 gfs2_block_map(&ip->i_inode, lblock, &bh, 0); in gfs2_write_alloc_required()
2382 size -= bh.b_size; in gfs2_write_alloc_required()
2383 lblock += (bh.b_size >> ip->i_inode.i_blkbits); in gfs2_write_alloc_required()
2391 struct gfs2_inode *ip = GFS2_I(inode); in stuffed_zero_range() local
2395 if (offset >= inode->i_size) in stuffed_zero_range()
2397 if (offset + length > inode->i_size) in stuffed_zero_range()
2398 length = inode->i_size - offset; in stuffed_zero_range()
2400 error = gfs2_meta_inode_buffer(ip, &dibh); in stuffed_zero_range()
2403 gfs2_trans_add_meta(ip->i_gl, dibh); in stuffed_zero_range()
2404 memset(dibh->b_data + sizeof(struct gfs2_dinode) + offset, 0, in stuffed_zero_range()
2414 loff_t max_chunk = GFS2_JTRUNC_REVOKES * sdp->sd_vfs->s_blocksize; in gfs2_journaled_truncate_range()
2428 chunk = offs + ((chunk - offs) & PAGE_MASK); in gfs2_journaled_truncate_range()
2432 length -= chunk; in gfs2_journaled_truncate_range()
2434 tr = current->journal_info; in gfs2_journaled_truncate_range()
2435 if (!test_bit(TR_TOUCHED, &tr->tr_flags)) in gfs2_journaled_truncate_range()
2449 struct gfs2_inode *ip = GFS2_I(inode); in __gfs2_punch_hole() local
2455 if (!gfs2_is_stuffed(ip)) { in __gfs2_punch_hole()
2458 start_off = offset & (blocksize - 1); in __gfs2_punch_hole()
2459 end_len = (offset + length) & (blocksize - 1); in __gfs2_punch_hole()
2462 if (length > blocksize - start_off) in __gfs2_punch_hole()
2463 len = blocksize - start_off; in __gfs2_punch_hole()
2472 offset + length - end_len, end_len); in __gfs2_punch_hole()
2479 end = round_up(offset + length, blocksize) - 1; in __gfs2_punch_hole()
2480 error = filemap_write_and_wait_range(inode->i_mapping, start, end); in __gfs2_punch_hole()
2484 if (gfs2_is_jdata(ip)) in __gfs2_punch_hole()
2492 if (gfs2_is_stuffed(ip)) { in __gfs2_punch_hole()
2498 if (gfs2_is_jdata(ip)) { in __gfs2_punch_hole()
2499 BUG_ON(!current->journal_info); in __gfs2_punch_hole()
2502 truncate_pagecache_range(inode, offset, offset + length - 1); in __gfs2_punch_hole()
2507 if (current->journal_info) in __gfs2_punch_hole()
2510 if (!gfs2_is_stuffed(ip)) in __gfs2_punch_hole()
2511 error = punch_hole(ip, offset, length); in __gfs2_punch_hole()
2514 if (current->journal_info) in __gfs2_punch_hole()
2526 return -EIO; in gfs2_map_blocks()
2528 if (offset >= wpc->iomap.offset && in gfs2_map_blocks()
2529 offset < wpc->iomap.offset + wpc->iomap.length) in gfs2_map_blocks()
2532 memset(&wpc->iomap, 0, sizeof(wpc->iomap)); in gfs2_map_blocks()
2533 ret = gfs2_iomap_get(inode, offset, INT_MAX, 0, &wpc->iomap, &mp); in gfs2_map_blocks()