gfs2: Partial iomap support
Subsystems (2)
Andreas Gruenbacher
maintainercover gfs2: Partial iomap support
Here is an update on Bob Peterson's gfs2 iomap patches:
From Bob (3):
1. GFS2: Make height info part of metapath Prepare the block mapping functions to using iomap.
2 GFS2: Implement iomap for block_map
Switch to iomap for mapping logical to physical blocks; implement gfs2_block_map on top of gfs2_iomap_begin. This covers reads and writes, but does not switch to multi-page write support, yet.
3. GFS2: Switch fiemap implementation to use iomap Switch to iomap_fiemap + gfs2_iomap_begin in gfs2_fiemap.
From myself (1):
4. gfs2: Implement SEEK_HOLE / SEEK_DATA via iomap Like fiemap, switch to iomap_seek_{hole,data} in gfs2_llseek.
The patches apply on top of the iomap infrastructure patches posted as part of the "ext4: SEEK_HOLE / SEEK_DATA via iomap" patch queue a week ago (https://lwn.net/Articles/734027/).
The patches have been carefully reviewed by Bob and myself, and they have passed xfstests with no regressions. We can queue them up for the next merge window as soon as Theodore Ts'o has merged the ext4 patches into his ext4 queue.
Thanks,
Andreas
fs/gfs2/Kconfig | 1 + fs/gfs2/bmap.c | 309 +++++++++++++++++++++++++++++++++++++------------- fs/gfs2/bmap.h | 4 + fs/gfs2/file.c | 17 ++- fs/gfs2/inode.c | 72 ++++++++---- fs/gfs2/inode.h | 2 + fs/gfs2/trace_gfs2.h | 65 +++++++++++ include/linux/iomap.h | 3 +- 8 files changed, 365 insertions(+), 108 deletions(-)
Signature · 1 line
2.13.3
Andreas Gruenbacher
maintainerPATCH 1/4 GFS2: Make height info part of metapath
From: Bob Peterson <[email protected]>
This patch eliminates height parameters from function gfs2_bmap_alloc. Function find_metapath determines the metapath's "find height", also known as the desired height. Function lookup_metapath determines the metapath's "actual height", previously known as starting height or sheight. Function gfs2_bmap_alloc now gets both height values from the metapath. This simplification was done as a step toward switching the block_map functions to using iomap. The bh_map responsibilities are also removed from function gfs2_bmap_alloc for the same reason.
--- fs/gfs2/bmap.c | 109 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 47 deletions(-)
fs/gfs2/bmap.c +62 -47
@@ -36,6 +36,8 @@struct metapath {struct buffer_head *mp_bh[GFS2_MAX_META_HEIGHT ];__u16 mp_list[GFS2_MAX_META_HEIGHT ]; +int mp_fheight;/* find_metapath height */ +int mp_aheight;/* actual height (lookup height) */ };/**
@@ -235,9 +237,9 @@ static void find_metapath(const struct gfs2_sbd *sdp, u64 block, {unsigned int i; + mp->mp_fheight = height;for (i = height; i--;) mp->mp_list[i] =do_div (block, sdp->sd_inptrs); - }static inline unsigned int metapath_branch_start (const struct metapath *mp)
@@ -345,10 +347,13 @@ static int lookup_metapath(struct gfs2_inode *ip, struct metapath *mp)for (x =0 ; x < end_of_metadata; x++) { ret =lookup_mp_height (ip, mp, x);if (ret) -return ret; + goto out; } -return ip->i_height; + ret = ip->i_height; +out: + mp->mp_aheight = ret; +return ret; }/**
@@ -480,10 +485,11 @@ static inline unsigned int hptrs(struct gfs2_sbd *sdp, const unsigned int hgt)* @inode: The GFS2 inode * @lblock: The logical starting block of the extent * @bh_map: This is used to return the mapping details -* @mp: The metapath -* @sheight: The starting height (i.e. whats already mapped) -* @height: The height to build to +* @zero_new: True if newly allocated blocks should be zeroed +* @mp: The metapath, with proper height information calculated * @maxlen: The max number of data blocks to alloc +* @dblock: Pointer to return the resulting new block +* @dblks: Pointer to return the number of blocks allocated * * In this routine we may have to alloc: * i) Indirect blocks to grow the metadata tree height
@@ -500,62 +506,63 @@ static inline unsigned int hptrs(struct gfs2_sbd *sdp, const unsigned int hgt)*/ static int gfs2_bmap_alloc (struct inode *inode,const sector_t lblock, -struct buffer_head *bh_map,struct metapath *mp, -const unsigned int sheight, -const unsigned int height, -const size_t maxlen) +bool zero_new,struct metapath *mp, +const size_t maxlen,sector_t *dblock, +unsigned *dblks) {struct gfs2_inode *ip =GFS2_I (inode);struct gfs2_sbd *sdp =GFS2_SB (inode);struct super_block *sb = sdp->sd_vfs;struct buffer_head *dibh = mp->mp_bh[0 ]; -u64 bn, dblock =0 ; +u64 bn;unsigned n, i, blks, alloced =0 , iblks =0 , branch_start =0 ; -unsigned dblks =0 ;unsigned ptrs_per_blk; -const unsigned end_of_metadata = height -1 ; +const unsigned end_of_metadata = mp->mp_fheight -1 ;int ret;int eob =0 ;enum alloc_state state;__be64 *ptr;__be64 zero_bn =0 ; -BUG_ON (sheight <1 ); +BUG_ON (mp->mp_aheight <1 );BUG_ON (dibh ==NULL ); + *dblock =0 ; + *dblks =0 ;gfs2_trans_add_meta (ip->i_gl, dibh); -if (height == sheight) { +if (mp->mp_fheight == mp->mp_aheight) {struct buffer_head *bh;/* Bottom indirect block exists, find unalloced extent size */ ptr =metapointer (end_of_metadata, mp); bh = mp->mp_bh[end_of_metadata]; - dblks =gfs2_extent_length (bh->b_data, bh->b_size, ptr, maxlen, - &eob); -BUG_ON (dblks <1 ); + *dblks =gfs2_extent_length (bh->b_data, bh->b_size, ptr, + maxlen, &eob); +BUG_ON (*dblks <1 ); state =ALLOC_DATA ; }else {/* Need to allocate indirect blocks */ - ptrs_per_blk = height >1 ? sdp->sd_inptrs : sdp->sd_diptrs; - dblks =min (maxlen, (size_t )(ptrs_per_blk - - mp->mp_list[end_of_metadata])); -if (height == ip->i_height) { + ptrs_per_blk = mp->mp_fheight >1 ? sdp->sd_inptrs : + sdp->sd_diptrs; + *dblks =min (maxlen, (size_t )(ptrs_per_blk - + mp->mp_list[end_of_metadata])); +if (mp->mp_fheight == ip->i_height) {/* Writing into existing tree, extend tree down */ - iblks = height - sheight; + iblks = mp->mp_fheight - mp->mp_aheight; state =ALLOC_GROW_DEPTH ; }else {/* Building up tree height */ state =ALLOC_GROW_HEIGHT ; - iblks = height - ip->i_height; + iblks = mp->mp_fheight - ip->i_height; branch_start =metapath_branch_start (mp); - iblks += (height - branch_start); + iblks += (mp->mp_fheight - branch_start); } }/* start of the second part of the function (state machine) */ - blks = dblks + iblks; - i = sheight; + blks = *dblks + iblks; + i = mp->mp_aheight; do { int error; n = blks - alloced;
@@ -573,9 +580,10 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, sizeof(struct gfs2_dinode)); zero_bn = *ptr; } -for (; i -1 < height - ip->i_height && n >0 ; i++, n--) +for (; i -1 < mp->mp_fheight - ip->i_height && n >0 ; + i++, n--)gfs2_indirect_init (mp, ip->i_gl, i,0 , bn++); -if (i -1 == height - ip->i_height) { +if (i -1 == mp->mp_fheight - ip->i_height) { i--; gfs2_buffer_copy_tail(mp->mp_bh[i], sizeof(struct gfs2_meta_header),
@@ -587,7 +595,7 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, sizeof(struct gfs2_meta_header)); *ptr = zero_bn; state =ALLOC_GROW_DEPTH ; -for (i = branch_start; i < height; i++) { +for (i = branch_start; i < mp->mp_fheight; i++) {if (mp->mp_bh[i] ==NULL )break ;brelse (mp->mp_bh[i]);
@@ -599,44 +607,40 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,break ;/* Branching from existing tree */ case ALLOC_GROW_DEPTH : -if (i >1 && i < height) +if (i >1 && i < mp->mp_fheight)gfs2_trans_add_meta (ip->i_gl, mp->mp_bh[i-1 ]); -for (; i < height && n >0 ; i++, n--) +for (; i < mp->mp_fheight && n >0 ; i++, n--)gfs2_indirect_init (mp, ip->i_gl, i, mp->mp_list[i-1 ], bn++); -if (i == height) +if (i == mp->mp_fheight) state =ALLOC_DATA ;if (n ==0 )break ;/* Tree complete, adding data blocks */ case ALLOC_DATA : -BUG_ON (n > dblks); +BUG_ON (n > *dblks);BUG_ON (mp->mp_bh[end_of_metadata] ==NULL );gfs2_trans_add_meta (ip->i_gl, mp->mp_bh[end_of_metadata]); - dblks = n; + *dblks = n; ptr =metapointer (end_of_metadata, mp); - dblock = bn; + *dblock = bn;while (n-- >0 ) *ptr++ =cpu_to_be64 (bn++); -if (buffer_zeronew (bh_map)) { - ret =sb_issue_zeroout (sb, dblock, dblks, +if (zero_new) { + ret =sb_issue_zeroout (sb, *dblock, *dblks,GFP_NOFS );if (ret) {fs_err (sdp,"Failed to zero data buffers\n" ); -clear_buffer_zeronew (bh_map); } }break ; } - }while ((state !=ALLOC_DATA ) || !dblock); + }while ((state !=ALLOC_DATA ) || !(*dblock)); - ip->i_height = height; + ip->i_height = mp->mp_fheight;gfs2_add_inode_blocks (&ip->i_inode, alloced);gfs2_dinode_out (ip, mp->mp_bh[0 ]->b_data); -map_bh (bh_map, inode->i_sb, dblock); - bh_map->b_size = dblks << inode->i_blkbits; -set_buffer_new (bh_map);return 0 ; }
@@ -670,6 +674,9 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,unsigned int len;struct buffer_head *bh;u8 height; +bool zero_new = false; +sector_t dblock =0 ; +unsigned dblks;BUG_ON (maxlen ==0 );
@@ -699,13 +706,13 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,while (size > arr[height]) height++;find_metapath (sdp, lblock, &mp, height); - ret =1 ; + mp.mp_aheight =1 ;if (height > ip->i_height ||gfs2_is_stuffed (ip)) goto do_alloc; ret =lookup_metapath (ip, &mp);if (ret <0 ) goto out; -if (ret != ip->i_height) +if (mp.mp_aheight != ip->i_height) goto do_alloc; ptr =metapointer (ip->i_height -1 , &mp);if (*ptr ==0 )
@@ -732,7 +739,15 @@ int gfs2_block_map(struct inode *inode, sector_t lblock, }/* At this point ret is the tree depth of already allocated blocks */ - ret =gfs2_bmap_alloc (inode, lblock, bh_map, &mp, ret, height, maxlen); +if (buffer_zeronew (bh_map)) + zero_new = true; + ret =gfs2_bmap_alloc (inode, lblock, zero_new, &mp, maxlen, &dblock, + &dblks); +if (ret ==0 ) { +map_bh (bh_map, inode->i_sb, dblock); + bh_map->b_size = dblks << inode->i_blkbits; +set_buffer_new (bh_map); + } goto out; }
Signature · 1 line
2.13.3
Andreas Gruenbacher
maintainerPATCH 2/4 GFS2: Implement iomap for block_map
In reply to Andreas GruenbacherFrom: Bob Peterson <[email protected]>
This patch implements iomap for block mapping, and switches the block_map function to use it under the covers.
The additional IOMAP_F_BOUNDARY iomap flag indicates when iomap has reached a "metadata boundary" and fetching the next mapping is likely to incur an additional I/O. This flag is used for setting the bh buffer boundary flag.
--- fs/gfs2/bmap.c | 272 +++++++++++++++++++++++++++++++++++++------------- fs/gfs2/bmap.h | 4 + fs/gfs2/trace_gfs2.h | 65 ++++++++++++ include/linux/iomap.h | 3 +- 4 files changed, 275 insertions(+), 69 deletions(-)
fs/gfs2/bmap.c +204 -68
@@ -13,6 +13,7 @@#include <linux/blkdev.h> #include <linux/gfs2_ondisk.h> #include <linux/crc32.h> +#include <linux/iomap.h> #include "gfs2.h" #include "incore.h"
@@ -505,10 +506,8 @@ static inline unsigned int hptrs(struct gfs2_sbd *sdp, const unsigned int hgt)* Returns: errno on error */ -static int gfs2_bmap_alloc (struct inode *inode,const sector_t lblock, -bool zero_new,struct metapath *mp, -const size_t maxlen,sector_t *dblock, -unsigned *dblks) +static int gfs2_iomap_alloc (struct inode *inode,struct iomap *iomap, +unsigned flags,struct metapath *mp) {struct gfs2_inode *ip =GFS2_I (inode);struct gfs2_sbd *sdp =GFS2_SB (inode);
@@ -516,36 +515,37 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,struct buffer_head *dibh = mp->mp_bh[0 ];u64 bn;unsigned n, i, blks, alloced =0 , iblks =0 , branch_start =0 ; +unsigned dblks =0 ;unsigned ptrs_per_blk;const unsigned end_of_metadata = mp->mp_fheight -1 ;int ret; -int eob =0 ;enum alloc_state state;__be64 *ptr;__be64 zero_bn =0 ; +size_t maxlen = iomap->length >> inode->i_blkbits;BUG_ON (mp->mp_aheight <1 );BUG_ON (dibh ==NULL ); - *dblock =0 ; - *dblks =0 ;gfs2_trans_add_meta (ip->i_gl, dibh);if (mp->mp_fheight == mp->mp_aheight) {struct buffer_head *bh; +int eob; +/* Bottom indirect block exists, find unalloced extent size */ ptr =metapointer (end_of_metadata, mp); bh = mp->mp_bh[end_of_metadata]; - *dblks =gfs2_extent_length (bh->b_data, bh->b_size, ptr, - maxlen, &eob); -BUG_ON (*dblks <1 ); + dblks =gfs2_extent_length (bh->b_data, bh->b_size, ptr, + maxlen, &eob); +BUG_ON (dblks <1 ); state =ALLOC_DATA ; }else {/* Need to allocate indirect blocks */ ptrs_per_blk = mp->mp_fheight >1 ? sdp->sd_inptrs : sdp->sd_diptrs; - *dblks =min (maxlen, (size_t )(ptrs_per_blk - - mp->mp_list[end_of_metadata])); + dblks =min (maxlen, (size_t )(ptrs_per_blk - + mp->mp_list[end_of_metadata]));if (mp->mp_fheight == ip->i_height) {/* Writing into existing tree, extend tree down */ iblks = mp->mp_fheight - mp->mp_aheight;
@@ -561,7 +561,7 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,/* start of the second part of the function (state machine) */ - blks = *dblks + iblks; + blks = dblks + iblks; i = mp->mp_aheight; do { int error;
@@ -618,26 +618,29 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,break ;/* Tree complete, adding data blocks */ case ALLOC_DATA : -BUG_ON (n > *dblks); +BUG_ON (n > dblks);BUG_ON (mp->mp_bh[end_of_metadata] ==NULL );gfs2_trans_add_meta (ip->i_gl, mp->mp_bh[end_of_metadata]); - *dblks = n; + dblks = n; ptr =metapointer (end_of_metadata, mp); - *dblock = bn; + iomap->addr = bn << inode->i_blkbits; + iomap->flags |=IOMAP_F_NEW ;while (n-- >0 ) *ptr++ =cpu_to_be64 (bn++); -if (zero_new) { - ret =sb_issue_zeroout (sb, *dblock, *dblks, -GFP_NOFS ); +if (flags &IOMAP_ZERO ) { + ret =sb_issue_zeroout (sb, iomap->addr >> inode->i_blkbits, + dblks,GFP_NOFS );if (ret) {fs_err (sdp,"Failed to zero data buffers\n" ); + flags &= ~IOMAP_ZERO ; } }break ; } - }while ((state !=ALLOC_DATA ) || !(*dblock)); + }while (iomap->addr ==IOMAP_NULL_ADDR ); + iomap->length = (u64 )dblks << inode->i_blkbits; ip->i_height = mp->mp_fheight;gfs2_add_inode_blocks (&ip->i_inode, alloced);gfs2_dinode_out (ip, mp->mp_bh[0 ]->b_data);
@@ -645,47 +648,123 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, }/** -* gfs2_block_map - Map a block from an inode to a disk block +* hole_size - figure out the size of a hole * @inode: The inode -* @lblock: The logical block number -* @bh_map: The bh to be mapped -* @create: True if its ok to alloc blocks to satify the request +* @lblock: The logical starting block number +* @mp: The metapath * -* Sets buffer_mapped() if successful, sets buffer_boundary() if a -* read of metadata will be required before the next block can be -* mapped. Sets buffer_new() if new blocks were allocated. +* Returns: The hole size in bytes * -* Returns: errno */ +static u64 hole_size (struct inode *inode,sector_t lblock,struct metapath *mp) +{ +struct gfs2_inode *ip =GFS2_I (inode); +struct gfs2_sbd *sdp =GFS2_SB (inode); +struct metapath mp_eof; +u64 factor =1 ; +int hgt; +u64 holesz =0 ; +const __be64 *first, *end, *ptr; +const struct buffer_head *bh; +u64 lblock_stop = (i_size_read (inode) -1 ) >> inode->i_blkbits; +int zeroptrs; +bool done = false; + +/* Get another metapath, to the very last byte */ +find_metapath (sdp, lblock_stop, &mp_eof, ip->i_height); +for (hgt = ip->i_height -1 ; hgt >=0 && !done; hgt--) { + bh = mp->mp_bh[hgt]; +if (bh) { + zeroptrs =0 ; + first =metapointer (hgt, mp); + end = (const __be64 *)(bh->b_data + bh->b_size); + +for (ptr = first; ptr < end; ptr++) { +if (*ptr) { + done = true; +break ; + }else { + zeroptrs++; + } + } + }else { + zeroptrs = sdp->sd_inptrs; + } +if (factor * zeroptrs >= lblock_stop - lblock +1 ) { + holesz = lblock_stop - lblock +1 ; +break ; + } + holesz += factor * zeroptrs; -int gfs2_block_map (struct inode *inode,sector_t lblock, -struct buffer_head *bh_map,int create) + factor *= sdp->sd_inptrs; +if (hgt && (mp->mp_list[hgt -1 ] < mp_eof.mp_list[hgt -1 ])) + (mp->mp_list[hgt -1 ])++; + } +return holesz << inode->i_blkbits; +} + +static void gfs2_stuffed_iomap (struct inode *inode,struct iomap *iomap) +{ +struct gfs2_inode *ip =GFS2_I (inode); + + iomap->addr = (ip->i_no_addr << inode->i_blkbits) + +sizeof (struct gfs2_dinode ); + iomap->offset =0 ; + iomap->length =i_size_read (inode); + iomap->type =IOMAP_MAPPED ; + iomap->flags =IOMAP_F_DATA_INLINE ; +} + +/** +* gfs2_iomap_begin - Map blocks from an inode to disk blocks +* @inode: The inode +* @pos: Starting position in bytes +* @length: Length to map, in bytes +* @flags: iomap flags +* @iomap: The iomap structure +* +* Returns: errno +*/ +int gfs2_iomap_begin (struct inode *inode,loff_t pos,loff_t length, +unsigned flags,struct iomap *iomap) {struct gfs2_inode *ip =GFS2_I (inode);struct gfs2_sbd *sdp =GFS2_SB (inode); +struct metapath mp = { .mp_aheight =1 , };unsigned int factor = sdp->sd_sb.sb_bsize; -const size_t maxlen = bh_map->b_size >> inode->i_blkbits;const u64 *arr = sdp->sd_heightsize;__be64 *ptr; -u64 size; -struct metapath mp; +sector_t lblock; +sector_t lend;int ret;int eob;unsigned int len;struct buffer_head *bh;u8 height; -bool zero_new = false; -sector_t dblock =0 ; -unsigned dblks; -BUG_ON (maxlen ==0 ); +trace_gfs2_iomap_start (ip, pos, length, flags); +if (!length) { + ret = -EINVAL ; + goto out; + } -memset (&mp,0 ,sizeof (mp)); -bmap_lock (ip, create); -clear_buffer_mapped (bh_map); -clear_buffer_new (bh_map); -clear_buffer_boundary (bh_map); -trace_gfs2_bmap (ip, bh_map, lblock, create,1 ); +if ((flags &IOMAP_REPORT ) &&gfs2_is_stuffed (ip)) { +gfs2_stuffed_iomap (inode, iomap); +if (pos >= iomap->length) +return -ENOENT ; + ret =0 ; + goto out; + } + + lblock = pos >> inode->i_blkbits; + lend = (pos + length + sdp->sd_sb.sb_bsize -1 ) >> inode->i_blkbits; + + iomap->offset = lblock << inode->i_blkbits; + iomap->addr =IOMAP_NULL_ADDR ; + iomap->type =IOMAP_HOLE ; + iomap->length = (u64)(lend - lblock) << inode->i_blkbits; + iomap->flags =IOMAP_F_MERGED ; +bmap_lock (ip,0 );/* * Directory data blocks have a struct gfs2_meta_header header, so the
@@ -699,56 +778,113 @@ int gfs2_block_map(struct inode *inode, sector_t lblock, ret =gfs2_meta_inode_buffer (ip, &mp.mp_bh[0 ]);if (ret) - goto out; + goto out_release; height = ip->i_height; - size = (lblock +1 ) * factor; -while (size > arr[height]) +while ((lblock +1 ) * factor > arr[height]) height++;find_metapath (sdp, lblock, &mp, height); - mp.mp_aheight =1 ;if (height > ip->i_height ||gfs2_is_stuffed (ip)) goto do_alloc; + ret =lookup_metapath (ip, &mp);if (ret <0 ) - goto out; + goto out_release; +if (mp.mp_aheight != ip->i_height) goto do_alloc; + ptr =metapointer (ip->i_height -1 , &mp);if (*ptr ==0 ) goto do_alloc; -map_bh (bh_map, inode->i_sb,be64_to_cpu (*ptr)); + + iomap->type =IOMAP_MAPPED ; + iomap->addr =be64_to_cpu (*ptr) << inode->i_blkbits; + bh = mp.mp_bh[ip->i_height -1 ]; - len =gfs2_extent_length (bh->b_data, bh->b_size, ptr, maxlen, &eob); - bh_map->b_size = (len << inode->i_blkbits); + len =gfs2_extent_length (bh->b_data, bh->b_size, ptr, lend - lblock, &eob);if (eob) -set_buffer_boundary (bh_map); + iomap->flags |=IOMAP_F_BOUNDARY ; + iomap->length = (u64 )len << inode->i_blkbits; + ret =0 ; -out: + +out_release:release_metapath (&mp); -trace_gfs2_bmap (ip, bh_map, lblock, create, ret); -bmap_unlock (ip, create); +bmap_unlock (ip,0 ); +out: +trace_gfs2_iomap_end (ip, iomap, ret);return ret; do_alloc: -/* All allocations are done here, firstly check create flag */ -if (!create) { -BUG_ON (gfs2_is_stuffed (ip)); +if (!(flags &IOMAP_WRITE )) { +if (pos >=i_size_read (inode)) { + ret = -ENOENT ; + goto out_release; + } ret =0 ; - goto out; + iomap->length =hole_size (inode, lblock, &mp); + goto out_release; } -/* At this point ret is the tree depth of already allocated blocks */ + ret =gfs2_iomap_alloc (inode, iomap, flags, &mp); + goto out_release; +} + +/** +* gfs2_block_map - Map a block from an inode to a disk block +* @inode: The inode +* @lblock: The logical block number +* @bh_map: The bh to be mapped +* @create: True if its ok to alloc blocks to satify the request +* +* Sets buffer_mapped() if successful, sets buffer_boundary() if a +* read of metadata will be required before the next block can be +* mapped. Sets buffer_new() if new blocks were allocated. +* +* Returns: errno +*/ + +int gfs2_block_map (struct inode *inode,sector_t lblock, +struct buffer_head *bh_map,int create) +{ +struct gfs2_inode *ip =GFS2_I (inode); +struct gfs2_sbd *sdp =GFS2_SB (inode); +struct iomap iomap; +int ret, flags =0 ; + +clear_buffer_mapped (bh_map); +clear_buffer_new (bh_map); +clear_buffer_boundary (bh_map); +trace_gfs2_bmap (ip, bh_map, lblock, create,1 ); + +if (create) + flags |=IOMAP_WRITE ;if (buffer_zeronew (bh_map)) - zero_new = true; - ret =gfs2_bmap_alloc (inode, lblock, zero_new, &mp, maxlen, &dblock, - &dblks); -if (ret ==0 ) { -map_bh (bh_map, inode->i_sb, dblock); - bh_map->b_size = dblks << inode->i_blkbits; -set_buffer_new (bh_map); + flags |=IOMAP_ZERO ; + ret =gfs2_iomap_begin (inode, (loff_t )lblock << sdp->sd_sb.sb_bsize_shift, + bh_map->b_size, flags, &iomap); +if (ret) { +if (!create && ret == -ENOENT ) { +/* Return unmapped buffer beyond the end of file. */ + ret =0 ; + } + goto out; } - goto out; + +WARN_ON (iomap.length % sdp->sd_sb.sb_bsize); +if (iomap.length < bh_map->b_size) + bh_map->b_size = iomap.length; +if (iomap.flags &IOMAP_F_BOUNDARY ) +set_buffer_boundary (bh_map); +if (iomap.addr !=IOMAP_NULL_ADDR ) +map_bh (bh_map, inode->i_sb, iomap.addr >> inode->i_blkbits); +if (iomap.flags &IOMAP_F_NEW ) +set_buffer_new (bh_map); + +out: +trace_gfs2_bmap (ip, bh_map, lblock, create, ret); +return ret; }/*
fs/gfs2/bmap.h +4 -0
@@ -10,6 +10,8 @@#ifndef __BMAP_DOT_H__#define __BMAP_DOT_H__ +#include <linux/iomap.h> +#include "inode.h" struct inode ;
@@ -47,6 +49,8 @@ static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip,extern int gfs2_unstuff_dinode (struct gfs2_inode *ip,struct page *page);extern int gfs2_block_map (struct inode *inode,sector_t lblock,struct buffer_head *bh,int create); +extern int gfs2_iomap_begin (struct inode *inode,loff_t pos,loff_t length, +unsigned flags,struct iomap *iomap);extern int gfs2_extent_map (struct inode *inode,u64 lblock,int *new,u64 *dblock,unsigned *extlen);extern int gfs2_setattr_size (struct inode *inode,u64 size);
fs/gfs2/trace_gfs2.h +65 -0
77 lines not on this page · raw message
include/linux/iomap.h +2 -1
@@ -21,7 +21,8 @@ struct vm_fault;/* * Flags for all iomap mappings: */ -#define IOMAP_F_NEW 0x01/* blocks have been newly allocated */ +#define IOMAP_F_NEW 0x01/* blocks have been newly allocated */ +#define IOMAP_F_BOUNDARY 0x02/* mapping ends at metadata boundary */ /* * Flags that only need to be reported for IOMAP_REPORT requests:
Signature · 1 line
2.13.3
Andreas Gruenbacher
maintainerPATCH 3/4 GFS2: Switch fiemap implementation to use iomap
In reply to Andreas GruenbacherFrom: Bob Peterson <[email protected]>
This patch switches GFS2's implementation of fiemap from the old block_map code to the new iomap interface.
--- fs/gfs2/Kconfig | 1 + fs/gfs2/inode.c | 34 +++++++++------------------------- 2 files changed, 10 insertions(+), 25 deletions(-)
fs/gfs2/Kconfig +1 -0
@@ -4,6 +4,7 @@ config GFS2_FS select FS_POSIX_ACL select CRC32 select QUOTACTL + select FS_IOMAP help A cluster filesystem.
fs/gfs2/inode.c +9 -25
@@ -18,7 +18,7 @@#include <linux/posix_acl.h> #include <linux/gfs2_ondisk.h> #include <linux/crc32.h> -#include <linux/fiemap.h> +#include <linux/iomap.h> #include <linux/security.h> #include <linux/uaccess.h>
@@ -2002,6 +2002,10 @@ static int gfs2_getattr(const struct path *path, struct kstat *stat,return 0 ; } +const struct iomap_ops gfs2_iomap_ops = { + .iomap_begin = gfs2_iomap_begin, +}; +static int gfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len) {
@@ -2009,38 +2013,18 @@ static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,struct gfs2_holder gh;int ret; - ret =fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC ); -if (ret) -return ret; - -inode_lock (inode); +inode_lock_shared (inode); ret =gfs2_glock_nq_init (ip->i_gl,LM_ST_SHARED ,0 , &gh);if (ret) goto out; -if (gfs2_is_stuffed (ip)) { -u64 phys = ip->i_no_addr << inode->i_blkbits; -u64 size =i_size_read (inode); -u32 flags =FIEMAP_EXTENT_LAST |FIEMAP_EXTENT_NOT_ALIGNED | -FIEMAP_EXTENT_DATA_INLINE ; - phys +=sizeof (struct gfs2_dinode ); - phys += start; -if (start + len > size) - len = size - start; -if (start < size) - ret =fiemap_fill_next_extent (fieinfo, start, phys, - len, flags); -if (ret ==1 ) - ret =0 ; - }else { - ret =__generic_block_fiemap (inode, fieinfo, start, len, - gfs2_block_map); - } + ret =iomap_fiemap (inode, fieinfo, start, len, &gfs2_iomap_ops);gfs2_glock_dq_uninit (&gh); + out: -inode_unlock (inode); +inode_unlock_shared (inode);return ret; }
Signature · 1 line
2.13.3
Andreas Gruenbacher
maintainerPATCH 4/4 gfs2: Implement SEEK_HOLE / SEEK_DATA via iomap
In reply to Andreas GruenbacherSo far, lseek on gfs2 did not report holes.
--- fs/gfs2/file.c | 17 ++++++++++++++--- fs/gfs2/inode.c | 38 ++++++++++++++++++++++++++++++++++++++ fs/gfs2/inode.h | 2 ++ 3 files changed, 54 insertions(+), 3 deletions(-)
fs/gfs2/file.c +14 -3
@@ -60,9 +60,7 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int whence)loff_t error;switch (whence) { -case SEEK_END :/* These reference inode->i_size */ -case SEEK_DATA : -case SEEK_HOLE : +case SEEK_END : error =gfs2_glock_nq_init (ip->i_gl,LM_ST_SHARED ,LM_FLAG_ANY , &i_gh);if (!error) {
@@ -70,8 +68,21 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int whence)gfs2_glock_dq_uninit (&i_gh); }break ; + +case SEEK_DATA : + error =gfs2_seek_data (file, offset); +break ; + +case SEEK_HOLE : + error =gfs2_seek_hole (file, offset); +break ; +case SEEK_CUR :case SEEK_SET : +/* +* These don't reference inode->i_size and don't depend on the +* block mapping, so we don't need the glock. +*/ error =generic_file_llseek (file, offset, whence);break ;default :
fs/gfs2/inode.c +38 -0
@@ -2028,6 +2028,44 @@ static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,return ret; } +loff_t gfs2_seek_data (struct file *file,loff_t offset) +{ +struct inode *inode = file->f_mapping->host; +struct gfs2_inode *ip =GFS2_I (inode); +struct gfs2_holder gh; +loff_t ret; + +inode_lock_shared (inode); + ret =gfs2_glock_nq_init (ip->i_gl,LM_ST_SHARED ,0 , &gh); +if (!ret) + ret =iomap_seek_data (inode, offset, &gfs2_iomap_ops); +gfs2_glock_dq_uninit (&gh); +inode_unlock_shared (inode); + +if (ret <0 ) +return ret; +return vfs_setpos (file, ret, inode->i_sb->s_maxbytes); +} + +loff_t gfs2_seek_hole (struct file *file,loff_t offset) +{ +struct inode *inode = file->f_mapping->host; +struct gfs2_inode *ip =GFS2_I (inode); +struct gfs2_holder gh; +loff_t ret; + +inode_lock_shared (inode); + ret =gfs2_glock_nq_init (ip->i_gl,LM_ST_SHARED ,0 , &gh); +if (!ret) + ret =iomap_seek_hole (inode, offset, &gfs2_iomap_ops); +gfs2_glock_dq_uninit (&gh); +inode_unlock_shared (inode); + +if (ret <0 ) +return ret; +return vfs_setpos (file, ret, inode->i_sb->s_maxbytes); +} +const struct inode_operations gfs2_file_iops = { .permission = gfs2_permission, .setattr = gfs2_setattr,
fs/gfs2/inode.h +2 -0
@@ -109,6 +109,8 @@ extern int gfs2_setattr_simple(struct inode *inode, struct iattr *attr);extern struct inode *gfs2_lookup_simple (struct inode *dip,const char *name);extern void gfs2_dinode_out (const struct gfs2_inode *ip,void *buf);extern int gfs2_open_common (struct inode *inode,struct file *file); +extern loff_t gfs2_seek_data (struct file *file,loff_t offset); +extern loff_t gfs2_seek_hole (struct file *file,loff_t offset);extern const struct inode_operations gfs2_file_iops;extern const struct inode_operations gfs2_dir_iops;
Signature · 1 line
2.13.3