gfs2 iomap write support
Subsystems (6)
Andreas Gruenbacher
maintainerv3 cover gfs2 iomap write support
Here is an update of my gfs2 iomap write patch queue, with support for buffered writes as well as direct I/O reads and writes through iomap. The patches seem to be working well; please review so that we can merge them in due time.
Apply on top of the current gfs2 for-next branch:
https://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2.git/log/?h=for-next
Thanks,
Andreas
Andreas Gruenbacher (8):
gfs2: gfs2_stuffed_write_end cleanup
gfs2: Remove ordered write mode handling from gfs2_trans_add_data
gfs2: Iomap cleanups and improvements
iomap: Add write_{begin,end} iomap operations
gfs2: Implement iomap buffered write support
gfs2: Implement iomap direct I/O support
gfs2: Remove gfs2_write_{begin,end}
iomap: Complete partial direct I/O writes synchronously
fs/ext2/inode.c | 2 + fs/ext4/inode.c | 2 + fs/gfs2/aops.c | 336 ++---------------------------------- fs/gfs2/aops.h | 22 +++ fs/gfs2/bmap.c | 470 ++++++++++++++++++++++++++++++++++++++++---------- fs/gfs2/bmap.h | 4 +- fs/gfs2/file.c | 197 ++++++++++++++++++++- fs/gfs2/inode.c | 4 - fs/gfs2/log.h | 7 +- fs/gfs2/quota.c | 5 +- fs/gfs2/trans.c | 27 +-- fs/iomap.c | 86 +++++---- fs/xfs/xfs_iomap.c | 2 + include/linux/iomap.h | 22 +++ 14 files changed, 705 insertions(+), 481 deletions(-) create mode 100644 fs/gfs2/aops.h
Signature · 1 line
2.14.3
Andreas Gruenbacher
maintainerPATCH v3 1/8 gfs2: gfs2_stuffed_write_end cleanup
First, change the sanity check in gfs2_stuffed_write_end to check for the actual write size instead of the requested write size.
Second, use the existing teardown code in gfs2_write_end instead of duplicating it in gfs2_stuffed_write_end.
--- fs/gfs2/aops.c | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-)
fs/gfs2/aops.c +18 -31
@@ -814,7 +814,6 @@ static void adjust_fs_space(struct inode *inode)* @inode: The inode * @dibh: The buffer_head containing the on-disk inode * @pos: The file position -* @len: The length of the write * @copied: How much was actually copied by the VFS * @page: The page *
@@ -824,17 +823,15 @@ static void adjust_fs_space(struct inode *inode)* Returns: errno */ static int gfs2_stuffed_write_end (struct inode *inode,struct buffer_head *dibh, -loff_t pos,unsigned len,unsigned copied, +loff_t pos,unsigned copied,struct page *page) {struct gfs2_inode *ip =GFS2_I (inode); -struct gfs2_sbd *sdp =GFS2_SB (inode); -struct gfs2_inode *m_ip =GFS2_I (sdp->sd_statfs_inode);u64 to = pos + copied;void *kaddr;unsigned char *buf = dibh->b_data +sizeof (struct gfs2_dinode ); -BUG_ON (pos + len >gfs2_max_stuffed_size (ip)); +BUG_ON (pos + copied >gfs2_max_stuffed_size (ip)); kaddr =kmap_atomic (page);memcpy (buf + pos, kaddr + pos, copied);
@@ -850,20 +847,6 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,i_size_write (inode, to);mark_inode_dirty (inode); } - -if (inode == sdp->sd_rindex) { -adjust_fs_space (inode); - sdp->sd_rindex_uptodate =0 ; - } - -brelse (dibh); -gfs2_trans_end (sdp); -if (inode == sdp->sd_rindex) { -gfs2_glock_dq (&m_ip->i_gh); -gfs2_holder_uninit (&m_ip->i_gh); - } -gfs2_glock_dq (&ip->i_gh); -gfs2_holder_uninit (&ip->i_gh);return copied; }
@@ -877,9 +860,8 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,* @page: The page that has been written * @fsdata: The fsdata (unused in GFS2) * -* The main write_end function for GFS2. We have a separate one for -* stuffed files as they are slightly different, otherwise we just -* put our locking around the VFS provided functions. +* The main write_end function for GFS2. We just put our locking around the VFS +* provided functions. * * Returns: errno */
@@ -900,32 +882,37 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,BUG_ON (gfs2_glock_is_locked_by_me (ip->i_gl) ==NULL ); ret =gfs2_meta_inode_buffer (ip, &dibh); -if (unlikely (ret)) { -unlock_page (page); -put_page (page); - goto failed; - } +if (unlikely (ret)) + goto out; -if (gfs2_is_stuffed (ip)) -return gfs2_stuffed_write_end (inode, dibh, pos, len, copied, page); +if (gfs2_is_stuffed (ip)) { + ret =gfs2_stuffed_write_end (inode, dibh, pos, copied, page); + page =NULL ; + goto out2; + }if (!gfs2_is_writeback (ip))gfs2_page_add_databufs (ip, page, pos & ~PAGE_MASK , len); ret =generic_write_end (file, mapping, pos, len, copied, page, fsdata); + page =NULL ;if (tr->tr_num_buf_new)__mark_inode_dirty (inode,I_DIRTY_DATASYNC );else gfs2_trans_add_meta (ip->i_gl, dibh); - +out2:if (inode == sdp->sd_rindex) {adjust_fs_space (inode); sdp->sd_rindex_uptodate =0 ; }brelse (dibh); -failed: +out: +if (page) { +unlock_page (page); +put_page (page); + }gfs2_trans_end (sdp);gfs2_inplace_release (ip);if (ip->i_qadata && ip->i_qadata->qa_qd_num)
Signature · 1 line
2.14.3
Andreas Gruenbacher
maintainerPATCH v3 2/8 gfs2: Remove ordered write mode handling from gfs2_trans_add_data
In reply to Andreas GruenbacherIn journaled data mode, we need to add each buffer head to the current transaction. In ordered write mode, we only need to add the inode to the ordered inode list. So far, both cases are handled in gfs2_trans_add_data. This makes the code look misleading and is inefficient for small block sizes as well. Handle both cases separately instead.
--- fs/gfs2/aops.c | 7 ++++--- fs/gfs2/bmap.c | 12 ++++++++---- fs/gfs2/log.h | 7 ++++++- fs/gfs2/quota.c | 5 ++++- fs/gfs2/trans.c | 27 ++++++++------------------- 5 files changed, 30 insertions(+), 28 deletions(-)
fs/gfs2/aops.c +4 -3
@@ -54,8 +54,7 @@ static void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page,continue ;if (start >= to)break ; -if (gfs2_is_jdata (ip)) -set_buffer_uptodate (bh); +set_buffer_uptodate (bh);gfs2_trans_add_data (ip->i_gl, bh); } }
@@ -891,8 +890,10 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping, goto out2; } -if (!gfs2_is_writeback (ip)) +if (gfs2_is_jdata (ip))gfs2_page_add_databufs (ip, page, pos & ~PAGE_MASK , len); +else +gfs2_ordered_add_inode (ip); ret =generic_write_end (file, mapping, pos, len, copied, page, fsdata); page =NULL ;
fs/gfs2/bmap.c +8 -4
@@ -89,10 +89,12 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,map_bh (bh, inode->i_sb, block);set_buffer_uptodate (bh); -if (!gfs2_is_jdata (ip)) -mark_buffer_dirty (bh); -if (!gfs2_is_writeback (ip)) +if (gfs2_is_jdata (ip))gfs2_trans_add_data (ip->i_gl, bh); +else { +mark_buffer_dirty (bh); +gfs2_ordered_add_inode (ip); + }if (release) {unlock_page (page);
@@ -958,8 +960,10 @@ static int gfs2_block_zero_range(struct inode *inode, loff_t from, err =0 ; } -if (!gfs2_is_writeback (ip)) +if (gfs2_is_jdata (ip))gfs2_trans_add_data (ip->i_gl, bh); +else +gfs2_ordered_add_inode (ip);zero_user (page, offset, length);mark_buffer_dirty (bh);
fs/gfs2/log.h +6 -1
@@ -14,6 +14,7 @@#include <linux/spinlock.h> #include <linux/writeback.h> #include "incore.h" +#include "inode.h" /** * gfs2_log_lock - acquire the right to mess with the log manager
@@ -50,8 +51,12 @@ static inline void gfs2_log_pointers_init(struct gfs2_sbd *sdp,static inline void gfs2_ordered_add_inode (struct gfs2_inode *ip) { -struct gfs2_sbd *sdp =GFS2_SB (&ip->i_inode); +struct gfs2_sbd *sdp; +if (!gfs2_is_ordered (ip)) +return ; + + sdp =GFS2_SB (&ip->i_inode);if (!test_bit (GIF_ORDERED , &ip->i_flags)) {spin_lock (&sdp->sd_ordered_lock);if (!test_and_set_bit (GIF_ORDERED , &ip->i_flags))
fs/gfs2/quota.c +4 -1
@@ -735,7 +735,10 @@ static int gfs2_write_buf_to_page(struct gfs2_inode *ip, unsigned long index,if (!buffer_uptodate (bh)) goto unlock_out; } -gfs2_trans_add_data (ip->i_gl, bh); +if (gfs2_is_jdata (ip)) +gfs2_trans_add_data (ip->i_gl, bh); +else +gfs2_ordered_add_inode (ip);/* If we need to write to the next block as well */ if (to_write > (bsize - boff)) {
fs/gfs2/trans.c +8 -19
@@ -143,32 +143,21 @@ static struct gfs2_bufdata *gfs2_alloc_bufdata(struct gfs2_glock *gl,* @gl: The inode glock associated with the buffer * @bh: The buffer to add * -* This is used in two distinct cases: -* i) In ordered write mode -* We put the data buffer on a list so that we can ensure that it's -* synced to disk at the right time -* ii) In journaled data mode -* We need to journal the data block in the same way as metadata in -* the functions above. The difference is that here we have a tag -* which is two __be64's being the block number (as per meta data) -* and a flag which says whether the data block needs escaping or -* not. This means we need a new log entry for each 251 or so data -* blocks, which isn't an enormous overhead but twice as much as -* for normal metadata blocks. +* This is used in journaled data mode. +* We need to journal the data block in the same way as metadata in +* the functions above. The difference is that here we have a tag +* which is two __be64's being the block number (as per meta data) +* and a flag which says whether the data block needs escaping or +* not. This means we need a new log entry for each 251 or so data +* blocks, which isn't an enormous overhead but twice as much as +* for normal metadata blocks. */ void gfs2_trans_add_data (struct gfs2_glock *gl,struct buffer_head *bh) {struct gfs2_trans *tr = current->journal_info;struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; -struct address_space *mapping = bh->b_page->mapping; -struct gfs2_inode *ip =GFS2_I (mapping->host);struct gfs2_bufdata *bd; -if (!gfs2_is_jdata (ip)) { -gfs2_ordered_add_inode (ip); -return ; - } -lock_buffer (bh);if (buffer_pinned (bh)) {set_bit (TR_TOUCHED , &tr->tr_flags);
Signature · 1 line
2.14.3
Andreas Gruenbacher
maintainerPATCH v3 3/8 gfs2: Iomap cleanups and improvements
In reply to Andreas GruenbacherClean up gfs2_iomap_alloc and gfs2_iomap_get. Document how gfs2_iomap_alloc works: it now needs to be called separately after gfs2_iomap_get where necessary; this will be used later by iomap write. Move gfs2_iomap_ops into bmap.c.
--- fs/gfs2/bmap.c | 193 +++++++++++++++++++++++++++++++------------------------- fs/gfs2/bmap.h | 4 +- fs/gfs2/inode.c | 4 -- 3 files changed, 109 insertions(+), 92 deletions(-)
fs/gfs2/bmap.c +107 -86
@@ -422,22 +422,6 @@ static inline unsigned int gfs2_extent_length(void *start, unsigned int len, __breturn (ptr - first); } -static inline void bmap_lock (struct gfs2_inode *ip,int create) -{ -if (create) -down_write (&ip->i_rw_mutex); -else -down_read (&ip->i_rw_mutex); -} - -static inline void bmap_unlock (struct gfs2_inode *ip,int create) -{ -if (create) -up_write (&ip->i_rw_mutex); -else -up_read (&ip->i_rw_mutex); -} -static inline __be64 *gfs2_indirect_init (struct metapath *mp,struct gfs2_glock *gl,unsigned int i,unsigned offset,u64 bn)
@@ -464,15 +448,11 @@ enum alloc_state { };/** -* gfs2_bmap_alloc - Build a metadata tree of the requested height +* gfs2_iomap_alloc - Build a metadata tree of the requested height * @inode: The GFS2 inode -* @lblock: The logical starting block of the extent -* @bh_map: This is used to return the mapping details -* @zero_new: True if newly allocated blocks should be zeroed +* @iomap: The iomap structure +* @flags: iomap flags * @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
@@ -485,6 +465,13 @@ enum alloc_state {* blocks are available, there will only be one request per bmap call) * and uses the state machine to initialise the blocks in order. * +* Right now, this function will allocate at most one indirect block +* worth of data -- with a default block size of 4K, that's slightly +* less than 2M. If this limitation is ever removed to allow huge +* allocations, we would probably still want to limit the iomap size we +* return to avoid stalling other tasks during huge writes; the next +* iomap iteration would then find the blocks already allocated. +* * Returns: errno on error */
@@ -511,6 +498,8 @@ static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap,gfs2_trans_add_meta (ip->i_gl, dibh); +down_write (&ip->i_rw_mutex); +if (mp->mp_fheight == mp->mp_aheight) {struct buffer_head *bh;int eob;
@@ -546,11 +535,10 @@ static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap, blks = dblks + iblks; i = mp->mp_aheight; do { - int error; n = blks - alloced; - error = gfs2_alloc_blocks(ip, &bn, &n, 0, NULL); - if (error) - return error; + ret = gfs2_alloc_blocks(ip, &bn, &n, 0, NULL); + if (ret) + goto out; alloced += n; if (state != ALLOC_DATA || gfs2_is_jdata(ip)) gfs2_trans_add_unrevoke(sdp, bn, n);
@@ -606,7 +594,7 @@ static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap, dblks = n; ptr =metapointer (end_of_metadata, mp); iomap->addr = bn << inode->i_blkbits; - iomap->flags |=IOMAP_F_NEW ; + iomap->flags |=IOMAP_F_MERGED |IOMAP_F_NEW ;while (n-- >0 ) *ptr++ =cpu_to_be64 (bn++);if (flags &IOMAP_ZERO ) {
@@ -625,8 +613,10 @@ static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap, 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); -return 0 ; +gfs2_dinode_out (ip, dibh->b_data); +out: +up_write (&ip->i_rw_mutex); +return ret; }/**
@@ -698,57 +688,48 @@ static void gfs2_stuffed_iomap(struct inode *inode, struct iomap *iomap) }/** -* gfs2_iomap_begin - Map blocks from an inode to disk blocks +* gfs2_iomap_get - 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 +* @mp: The metapath * * Returns: errno */ -int gfs2_iomap_begin (struct inode *inode,loff_t pos,loff_t length, -unsigned flags,struct iomap *iomap) +static int gfs2_iomap_get (struct inode *inode,loff_t pos,loff_t length, +unsigned flags,struct iomap *iomap, +struct metapath *mp) {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 u64 *arr = sdp->sd_heightsize;__be64 *ptr;sector_t lblock; -sector_t lend; +sector_t lblock_stop;int ret =0 ;int eob; -unsigned int len; +u64 len;struct buffer_head *bh;u8 height; -trace_gfs2_iomap_start (ip, pos, length, flags); -if (!length) { - ret = -EINVAL ; - goto out; - } +if (!length) +return -EINVAL ;if (gfs2_is_stuffed (ip)) {if (flags &IOMAP_REPORT ) { +if (pos >=i_size_read (inode)) +return -ENOENT ;gfs2_stuffed_iomap (inode, iomap); -if (pos >= iomap->length) - ret = -ENOENT ; - goto out; +return 0 ; }BUG_ON (!(flags &IOMAP_WRITE )); } - 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, flags &IOMAP_WRITE ); + lblock_stop = (pos + length -1 ) >> inode->i_blkbits; + len = lblock_stop - lblock +1 ;/* * Directory data blocks have a struct gfs2_meta_header header, so the
@@ -760,59 +741,89 @@ int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length, arr = sdp->sd_jheightsize; } - ret =gfs2_meta_inode_buffer (ip, &mp.mp_bh[0 ]); +down_read (&ip->i_rw_mutex); + + ret =gfs2_meta_inode_buffer (ip, &mp->mp_bh[0 ]);if (ret) - goto out_release; + goto unlock; height = ip->i_height;while ((lblock +1 ) * factor > arr[height]) height++; -find_metapath (sdp, lblock, &mp, height); +find_metapath (sdp, lblock, mp, height);if (height > ip->i_height ||gfs2_is_stuffed (ip)) goto do_alloc; - ret =lookup_metapath (ip, &mp); + ret =lookup_metapath (ip, mp);if (ret) - goto out_release; + goto unlock; -if (mp.mp_aheight != ip->i_height) +if (mp->mp_aheight != ip->i_height) goto do_alloc; - ptr =metapointer (ip->i_height -1 , &mp); + ptr =metapointer (ip->i_height -1 , mp);if (*ptr ==0 ) goto do_alloc; - 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, len, &eob); - bh = mp.mp_bh[ip->i_height -1 ]; - len =gfs2_extent_length (bh->b_data, bh->b_size, ptr, lend - lblock, &eob); + iomap->addr =be64_to_cpu (*ptr) << inode->i_blkbits; + iomap->length = len << inode->i_blkbits; + iomap->type =IOMAP_MAPPED ; + iomap->flags =IOMAP_F_MERGED ;if (eob) iomap->flags |=IOMAP_F_BOUNDARY ; - iomap->length = (u64 )len << inode->i_blkbits; -out_release: -release_metapath (&mp); -bmap_unlock (ip, flags &IOMAP_WRITE ); out: -trace_gfs2_iomap_end (ip, iomap, ret); + iomap->offset = lblock << inode->i_blkbits; + iomap->bdev = inode->i_sb->s_bdev; +unlock: +up_read (&ip->i_rw_mutex);return ret; do_alloc: -if (flags &IOMAP_WRITE ) { - ret =gfs2_iomap_alloc (inode, iomap, flags, &mp); - }else if (flags &IOMAP_REPORT ) { + iomap->addr =IOMAP_NULL_ADDR ; + iomap->length = len << inode->i_blkbits; + iomap->type =IOMAP_HOLE ; + iomap->flags =0 ; +if (flags &IOMAP_REPORT ) {loff_t size =i_size_read (inode);if (pos >= size) ret = -ENOENT ; -else if (height <= ip->i_height) - iomap->length =hole_size (inode, lblock, &mp); +else if (height == ip->i_height) + iomap->length =hole_size (inode, lblock, mp);else iomap->length = size - pos; } - goto out_release; + goto out; +} + +static 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 metapath mp = { .mp_aheight =1 , }; +int ret; + +trace_gfs2_iomap_start (ip, pos, length, flags); +if (flags &IOMAP_WRITE ) { + ret =gfs2_iomap_get (inode, pos, length, flags, iomap, &mp); +if (!ret && iomap->type ==IOMAP_HOLE ) + ret =gfs2_iomap_alloc (inode, iomap, flags, &mp); +release_metapath (&mp); + }else { + ret =gfs2_iomap_get (inode, pos, length, flags, iomap, &mp); +release_metapath (&mp); + } +trace_gfs2_iomap_end (ip, iomap, ret); +return ret; } +const struct iomap_ops gfs2_iomap_ops = { + .iomap_begin = gfs2_iomap_begin, +}; +/** * gfs2_block_map - Map one or more blocks of an inode to a disk block * @inode: The inode
@@ -838,27 +849,37 @@ int gfs2_block_map(struct inode *inode, sector_t lblock, struct buffer_head *bh_map, int create) {struct gfs2_inode *ip =GFS2_I (inode); +loff_t pos = (loff_t )lblock << inode->i_blkbits; +loff_t length = bh_map->b_size; +struct metapath mp = { .mp_aheight =1 , };struct iomap iomap; -int ret, flags =0 ; +int ret;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)) - flags |=IOMAP_ZERO ; - ret =gfs2_iomap_begin (inode, (loff_t )lblock << inode->i_blkbits, - bh_map->b_size, flags, &iomap); -if (ret) { -if (!create && ret == -ENOENT ) { -/* Return unmapped buffer beyond the end of file. */ +if (create) { +int flags =IOMAP_WRITE ; +if (buffer_zeronew (bh_map)) + flags |=IOMAP_ZERO ; + ret =gfs2_iomap_get (inode, pos, length, flags, &iomap, &mp); +if (!ret && iomap.type ==IOMAP_HOLE ) + ret =gfs2_iomap_alloc (inode, &iomap, flags, &mp); +release_metapath (&mp); + }else { + ret =gfs2_iomap_get (inode, pos, length,0 , &iomap, &mp); +release_metapath (&mp); + +/* Return unmapped buffer beyond the end of file. */ +if (ret == -ENOENT ) { ret =0 ; + goto out; } - goto out; } +if (ret) + goto out;if (iomap.length > bh_map->b_size) { iomap.length = bh_map->b_size;
fs/gfs2/bmap.h +2 -2
@@ -46,11 +46,11 @@ static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip, } } +extern const struct iomap_ops gfs2_iomap_ops; +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/inode.c +0 -4
@@ -2006,10 +2006,6 @@ 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) {
Signature · 1 line
2.14.3
Re: [Cluster-devel] [PATCH v3 3/8] gfs2: Iomap cleanups and improvements
Hi,
----- Original Message -----
(snip)
Quoted 7 lines
fs/gfs2/bmap.c +7
-0+static 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 metapath mp = { .mp_aheight =1 , }; +int ret; +
fs/gfs2/bmap.c int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length, · line 818
Quoted 10 lines
fs/gfs2/bmap.c +10
-0+trace_gfs2_iomap_start (ip, pos, length, flags); +if (flags &IOMAP_WRITE ) { + ret =gfs2_iomap_get (inode, pos, length, flags, iomap, &mp); +if (!ret && iomap->type ==IOMAP_HOLE ) + ret =gfs2_iomap_alloc (inode, iomap, flags, &mp); +release_metapath (&mp); + }else { + ret =gfs2_iomap_get (inode, pos, length, flags, iomap, &mp); +release_metapath (&mp); + }
Why the redundancy? Why not just move gfs2_iomap_get before the if, and release_metapath after the if? Something like:
+ ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp);
+
+ if (!ret && flags & IOMAP_WRITE && iomap->type == IOMAP_HOLE))
+ ret = gfs2_iomap_alloc(inode, iomap, flags, &mp);
+
+ release_metapath(&mp);
(snip)
Bob Peterson
Andreas Gruenbacher
maintainerRe: [Cluster-devel] [PATCH v3 3/8] gfs2: Iomap cleanups and improvements
Quoted 24 lines · Bob Peterson
Hi,
----- Original Message -----
(snip)Quoted 7 lines
fs/gfs2/bmap.c +7
-0+static 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 metapath mp = { .mp_aheight =1 , }; +int ret; +fs/gfs2/bmap.c int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length, · line 818
Quoted 10 lines
fs/gfs2/bmap.c +10
-0+trace_gfs2_iomap_start (ip, pos, length, flags); +if (flags &IOMAP_WRITE ) { + ret =gfs2_iomap_get (inode, pos, length, flags, iomap, &mp); +if (!ret && iomap->type ==IOMAP_HOLE ) + ret =gfs2_iomap_alloc (inode, iomap, flags, &mp); +release_metapath (&mp); + }else { + ret =gfs2_iomap_get (inode, pos, length, flags, iomap, &mp); +release_metapath (&mp); + }Why the redundancy? Why not just move
gfs2_iomap_getbefore the if, andrelease_metapathafter the if? Something like:
fs/gfs2/bmap.c int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
Quoted 7 lines
fs/gfs2/bmap.c +6
-0+ ret =gfs2_iomap_get (inode, pos, length, flags, iomap, &mp); + + if (!ret && flags & IOMAP_WRITE && iomap->type == IOMAP_HOLE)) + ret =gfs2_iomap_alloc (inode, iomap, flags, &mp); + +release_metapath (&mp);
That's certainly possible as well.
Thanks,
Andreas
Andreas Gruenbacher
maintainerPATCH v3 4/8 iomap: Add write_{begin,end} iomap operations
In reply to Andreas GruenbacherAdd write_begin and write_end operations to struct iomap_ops to provide a way of overriding the default behavior of iomap_write_begin and iomap_write_end. This is needed for implementing data journaling: in the data journaling case, pages are written into the journal before being written back to their proper on-disk locations.
--- fs/ext2/inode.c | 2 ++ fs/ext4/inode.c | 2 ++ fs/iomap.c | 62 +++++++++++++++++++++++++++++++++++---------------- fs/xfs/xfs_iomap.c | 2 ++ include/linux/iomap.h | 22 ++++++++++++++++++ 5 files changed, 71 insertions(+), 19 deletions(-)
fs/ext2/inode.c +2 -0
@@ -848,6 +848,8 @@ ext2_iomap_end(struct inode *inode, loff_t offset, loff_t length,const struct iomap_ops ext2_iomap_ops = { .iomap_begin = ext2_iomap_begin, + .write_begin = iomap_write_begin, + .write_end = iomap_write_end, .iomap_end = ext2_iomap_end, };#else
fs/ext4/inode.c +2 -0
@@ -3602,6 +3602,8 @@ static int ext4_iomap_end(struct inode *inode, loff_t offset, loff_t length,const struct iomap_ops ext4_iomap_ops = { .iomap_begin = ext4_iomap_begin, + .write_begin = iomap_write_begin, + .write_end = iomap_write_end, .iomap_end = ext4_iomap_end, };
fs/iomap.c +43 -19
179 lines not on this page · raw message
fs/xfs/xfs_iomap.c +2 -0
@@ -1181,6 +1181,8 @@ xfs_file_iomap_end(const struct iomap_ops xfs_iomap_ops = { .iomap_begin = xfs_file_iomap_begin, + .write_begin = iomap_write_begin, + .write_end = iomap_write_end, .iomap_end = xfs_file_iomap_end, };
include/linux/iomap.h +22 -0
@@ -61,6 +61,8 @@ struct iomap {#define IOMAP_DIRECT (1 << 4)/* direct I/O */ #define IOMAP_NOWAIT (1 << 5)/* Don't wait for writeback */ +struct page ; +struct iomap_ops {/* * Return the existing mapping@pos, or reserve space starting at
@@ -70,6 +72,21 @@ struct iomap_ops {int (*iomap_begin)(struct inode *inode,loff_t pos,loff_t length,unsigned flags,struct iomap *iomap); +/* +* Begin writing to a page, similar to block_write_begin but in a +* mapping returned by iomap_begin. Usually initialized to +* iomap_write_begin. +*/ +int (*write_begin)(struct inode *inode,loff_t pos,unsigned len, +unsigned flags,struct page **pagep, +struct iomap *iomap); + +/* +* End writing to a page. Usually initialized to iomap_write_end. +*/ +int (*write_end)(struct inode *inode,loff_t pos,unsigned len, +unsigned copied,struct page *page); +/* * Commit and/or unreserve space previous allocated using iomap_begin. * Written indicates the length of the successful write operation which
@@ -80,6 +97,11 @@ struct iomap_ops { ssize_t written, unsigned flags, struct iomap *iomap); }; +int iomap_write_begin (struct inode *inode,loff_t pos,unsigned len, +unsigned flags,struct page **pagep,struct iomap *iomap); +int iomap_write_end (struct inode *inode,loff_t pos,unsigned len, +unsigned copied,struct page *page); +ssize_t iomap_file_buffered_write (struct kiocb *iocb,struct iov_iter *from,const struct iomap_ops *ops); int iomap_file_dirty(struct inode *inode, loff_t pos, loff_t len,
Signature · 1 line
2.14.3
Andreas Gruenbacher
maintainerPATCH v3 5/8 gfs2: Implement iomap buffered write support
In reply to Andreas GruenbacherWith the traditional page-based writes, blocks are allocated separately for each page written to. With iomap writes, we can allocate a lot more blocks at once, with a fraction of the allocation overhead for each page.
--- fs/gfs2/aops.c | 20 +++-- fs/gfs2/aops.h | 22 +++++ fs/gfs2/bmap.c | 263 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- fs/gfs2/file.c | 44 ++++++++-- 4 files changed, 325 insertions(+), 24 deletions(-) create mode 100644 fs/gfs2/aops.h
fs/gfs2/aops.c +11 -9
@@ -22,6 +22,7 @@#include <linux/backing-dev.h> #include <linux/uio.h> #include <trace/events/writeback.h> +#include <linux/sched/signal.h> #include "gfs2.h" #include "incore.h"
@@ -36,10 +37,11 @@#include "super.h" #include "util.h" #include "glops.h" +#include "aops.h" -static void gfs2_page_add_databufs (struct gfs2_inode *ip,struct page *page, -unsigned int from,unsigned int len) +void gfs2_page_add_databufs (struct gfs2_inode *ip,struct page *page, +unsigned int from,unsigned int len) {struct buffer_head *head =page_buffers (page);unsigned int bsize = head->b_size;
@@ -462,7 +464,7 @@ static int gfs2_jdata_writepages(struct address_space *mapping,* Returns: errno */ -static int stuffed_readpage (struct gfs2_inode *ip,struct page *page) +int stuffed_readpage (struct gfs2_inode *ip,struct page *page) {struct buffer_head *dibh;u64 dsize =i_size_read (&ip->i_inode);
@@ -773,7 +775,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,* adjust_fs_space - Adjusts the free space available due to gfs2_grow * @inode: the rindex inode */ -static void adjust_fs_space (struct inode *inode) +void adjust_fs_space (struct inode *inode) {struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;struct gfs2_inode *m_ip =GFS2_I (sdp->sd_statfs_inode);
@@ -819,11 +821,11 @@ static void adjust_fs_space(struct inode *inode)* This copies the data from the page into the inode block after * the inode data structure itself. * -* Returns: errno +* Returns: copied bytes or errno */ -static int gfs2_stuffed_write_end (struct inode *inode,struct buffer_head *dibh, -loff_t pos,unsigned copied, -struct page *page) +int gfs2_stuffed_write_end (struct inode *inode,struct buffer_head *dibh, +loff_t pos,unsigned copied, +struct page *page) {struct gfs2_inode *ip =GFS2_I (inode);u64 to = pos + copied;
@@ -862,7 +864,7 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,* The main write_end function for GFS2. We just put our locking around the VFS * provided functions. * -* Returns: errno +* Returns: copied bytes or errno */ static int gfs2_write_end(struct file *file, struct address_space *mapping,
fs/gfs2/aops.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2017 Red Hat, Inc. All rights reserved. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License version 2. +*/ + +#ifndef __AOPS_DOT_H__ +#define __AOPS_DOT_H__ + +#include "incore.h" + +extern int stuffed_readpage (struct gfs2_inode *ip,struct page *page); +extern int gfs2_stuffed_write_end (struct inode *inode,struct buffer_head *dibh, +loff_t pos,unsigned copied, +struct page *page); +extern void adjust_fs_space (struct inode *inode); +extern void gfs2_page_add_databufs (struct gfs2_inode *ip,struct page *page, +unsigned int from,unsigned int len); + +#endif /* __AOPS_DOT_H__ */
fs/gfs2/bmap.c +254 -9
330 lines not on this page · raw message
fs/gfs2/file.c +38 -6
72 lines not on this page · raw message
Signature · 1 line
2.14.3
Re: [Cluster-devel] [PATCH v3 5/8] gfs2: Implement iomap buffered write support
Hi,
----- Original Message -----
(snip)
Quoted 3 lines
+static int gfs2_iomap_begin_write(struct inode *inode,
loff_tpos,loff_tlength,fs/gfs2/bmap.c +1
-0+ unsigned flags, struct iomap *iomap)
(snip)
Quoted 13 lines
fs/gfs2/bmap.c +13
-0+{ +struct metapath mp = { .mp_aheight =1 , }; +struct gfs2_inode *ip =GFS2_I (inode); +struct gfs2_sbd *sdp =GFS2_SB (inode); +unsigned int data_blocks =0 , ind_blocks =0 , rblocks; +bool unstuff, alloc_required; +int ret; + + ret =gfs2_write_lock (inode); +if (ret) +return ret; + + unstuff = gfs2_is_stuffed(ip) &&
fs/gfs2/bmap.c static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, · line 878
Quoted 10 lines
fs/gfs2/bmap.c +10
-0+ pos + length >gfs2_max_stuffed_size (ip); + + ret =gfs2_iomap_get (inode, pos, length, flags, iomap, &mp); +if (ret) + goto out_release; + + alloc_required = unstuff || iomap->type !=IOMAP_MAPPED ; + +if (alloc_required ||gfs2_is_jdata (ip)) +gfs2_write_calc_reserv (ip, iomap->length, &data_blocks, &ind_blocks);
It would be ideal if the iomap_get could tell us how many blocks are mapped and how many are unmapped, if it wouldn't cause unnecessary IO.
If we could use the number of unmapped blocks rather than iomap->length, it could potentially save us from reserving unnecessary journal space, for example, on rewrites (iow where the metadata for the writes already exists). (snip)
Bob Peterson
Re: [Cluster-devel] [PATCH v3 5/8] gfs2: Implement iomap buffered write support
2018-04-06 16:44 GMT+02:00 Bob Peterson <[email protected]>:
Quoted 30 lines
Hi,
----- Original Message -----
(snip)Quoted 3 lines
+static int gfs2_iomap_begin_write(struct inode *inode,
loff_tpos,loff_tlength,
+ unsigned flags, struct iomap *iomap)(snip)
Quoted 22 lines
fs/gfs2/bmap.c +22
-0+{ +struct metapath mp = { .mp_aheight =1 , }; +struct gfs2_inode *ip =GFS2_I (inode); +struct gfs2_sbd *sdp =GFS2_SB (inode); +unsigned int data_blocks =0 , ind_blocks =0 , rblocks; +bool unstuff, alloc_required; +int ret; + + ret =gfs2_write_lock (inode); +if (ret) +return ret; + + unstuff =gfs2_is_stuffed (ip) && + pos + length >gfs2_max_stuffed_size (ip); + + ret =gfs2_iomap_get (inode, pos, length, flags, iomap, &mp); +if (ret) + goto out_release; + + alloc_required = unstuff || iomap->type !=IOMAP_MAPPED ; + +if (alloc_required ||gfs2_is_jdata (ip))
Quoted 8 lines
Quoted 1 line
+
gfs2_write_calc_reserv(ip, iomap->length, &data_blocks, &ind_blocks);It would be ideal if the
iomap_getcould tell us how many blocks are mapped and how many are unmapped, if it wouldn't cause unnecessary IO.
If we could use the number of unmapped blocks rather thaniomap->length, it could potentially save us from reserving unnecessary journal space, for example, on rewrites (iow where the metadata for the writes already exists). (snip)
Yes, I'll change gfs2_iomap_get to return the number of blocks gfs2_iomap_alloc should be able to allocate. It's a simple variant of hole_size; the maximum will be an entire indirect block worth of data.
Thanks,
Andreas
Andreas Gruenbacher
maintainerPATCH v3 6/8 gfs2: Implement iomap direct I/O support
In reply to Andreas GruenbacherWith that, the direct_IO address space operation can be all but
eliminated: only a dummy remains which indicates that the filesystem supports direct I/O.
--- fs/gfs2/aops.c | 92 +------------------------------ fs/gfs2/bmap.c | 14 ++++- fs/gfs2/file.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 174 insertions(+), 103 deletions(-)
fs/gfs2/aops.c +2 -90
@@ -84,12 +84,6 @@ static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock,return 0 ; } -static int gfs2_get_block_direct (struct inode *inode,sector_t lblock, -struct buffer_head *bh_result,int create) -{ -return gfs2_block_map (inode, lblock, bh_result,0 ); -} -/** * gfs2_writepage_common - Common bits of writepage * @page: The page to be written
@@ -1021,94 +1015,12 @@ static void gfs2_invalidatepage(struct page *page, unsigned int offset,try_to_release_page (page,0 ); } -/** -* gfs2_ok_for_dio - check that dio is valid on this file -* @ip: The inode -* @offset: The offset at which we are reading or writing -* -* Returns: 0 (to ignore the i/o request and thus fall back to buffered i/o) -* 1 (to accept the i/o request) -*/ -static int gfs2_ok_for_dio (struct gfs2_inode *ip,loff_t offset) -{ -/* -* Should we return an error here? I can't see that O_DIRECT for -* a stuffed file makes any sense. For now we'll silently fall -* back to buffered I/O -*/ -if (gfs2_is_stuffed (ip)) -return 0 ; - -if (offset >=i_size_read (&ip->i_inode)) -return 0 ; -return 1 ; -} - - -static ssize_t gfs2_direct_IO (struct kiocb *iocb,struct iov_iter *iter) { -struct file *file = iocb->ki_filp; -struct inode *inode = file->f_mapping->host; -struct address_space *mapping = inode->i_mapping; -struct gfs2_inode *ip =GFS2_I (inode); -loff_t offset = iocb->ki_pos; -struct gfs2_holder gh; -int rv; -/* -* Deferred lock, even if its a write, since we do no allocation -* on this path. All we need change is atime, and this lock mode -* ensures that other nodes have flushed their buffered read caches -* (i.e. their page cache entries for this inode). We do not, -* unfortunately have the option of only flushing a range like -* the VFS does. +* We just need the method present so that open/fcntl allow direct I/O. */ -gfs2_holder_init (ip->i_gl,LM_ST_DEFERRED ,0 , &gh); - rv =gfs2_glock_nq (&gh); -if (rv) - goto out_uninit; - rv =gfs2_ok_for_dio (ip, offset); -if (rv !=1 ) - goto out;/* dio not valid, fall back to buffered i/o */ - -/* -* Now since we are holding a deferred (CW) lock at this point, you -* might be wondering why this is ever needed. There is a case however -* where we've granted a deferred local lock against a cached exclusive -* glock. That is ok provided all granted local locks are deferred, but -* it also means that it is possible to encounter pages which are -* cached and possibly also mapped. So here we check for that and sort -* them out ahead of the dio. The glock state machine will take care of -* everything else. -* -* If in fact the cached glock state (gl->gl_state) is deferred (CW) in -* the first place, mapping->nr_pages will always be zero. -*/ -if (mapping->nrpages) { -loff_t lstart = offset & ~(PAGE_SIZE -1 ); -loff_t len =iov_iter_count (iter); -loff_t end =PAGE_ALIGN (offset + len) -1 ; - - rv =0 ; -if (len ==0 ) - goto out; -if (test_and_clear_bit (GIF_SW_PAGED , &ip->i_flags)) -unmap_shared_mapping_range (ip->i_inode.i_mapping, offset, len); - rv =filemap_write_and_wait_range (mapping, lstart, end); -if (rv) - goto out; -if (iov_iter_rw (iter) ==WRITE ) -truncate_inode_pages_range (mapping, lstart, end); - } - - rv =__blockdev_direct_IO (iocb, inode, inode->i_sb->s_bdev, iter, - gfs2_get_block_direct,NULL ,NULL ,0 ); -out: -gfs2_glock_dq (&gh); -out_uninit: -gfs2_holder_uninit (&gh); -return rv; +return -EINVAL ; }/**
fs/gfs2/bmap.c +12 -2
@@ -805,6 +805,9 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, iomap->length =hole_size (inode, lblock, mp); else iomap->length = size - pos; + }else if (!(flags &IOMAP_WRITE )) { +if (height == ip->i_height) + iomap->length =hole_size (inode, lblock, mp); }/* FIXME: Should we limit iomap->length to the maximum allocation size * here according to how gfs2_iomap_alloc allocates blocks? */
@@ -949,7 +952,14 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,trace_gfs2_iomap_start (ip, pos, length, flags);if (flags &IOMAP_WRITE ) { - ret =gfs2_iomap_begin_write (inode, pos, length, flags, iomap); +if (flags &IOMAP_DIRECT ) { + ret =gfs2_iomap_get (inode, pos, length, flags, iomap, &mp); +release_metapath (&mp); +if (iomap->type !=IOMAP_MAPPED ) + ret = -ENOTBLK ; + }else { + ret =gfs2_iomap_begin_write (inode, pos, length, flags, iomap); + } }else { ret =gfs2_iomap_get (inode, pos, length, flags, iomap, &mp);release_metapath (&mp);
@@ -1020,7 +1030,7 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,struct gfs2_sbd *sdp =GFS2_SB (inode);struct gfs2_trans *tr = current->journal_info; -if (!(flags &IOMAP_WRITE )) +if ((flags & (IOMAP_WRITE |IOMAP_DIRECT )) !=IOMAP_WRITE )return 0 ;gfs2_ordered_add_inode (ip);
fs/gfs2/file.c +160 -11
215 lines not on this page · raw message
Signature · 1 line
2.14.3
Re: [Cluster-devel] [PATCH v3 6/8] gfs2: Implement iomap direct I/O support
Hi,
----- Original Message -----
Quoted 11 lines
With that, the
direct_IOaddress space operation can be all but
eliminated: only a dummy remains which indicates that the filesystem supports direct I/O.Signed-off-by Andreas Gruenbacher <[email protected]>--- fs/gfs2/aops.c | 92 +------------------------------ fs/gfs2/bmap.c | 14 ++++- fs/gfs2/file.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 174 insertions(+), 103 deletions(-)
(snip)
Quoted 4 lines
fs/gfs2/file.c +4
-0+ pos = iocb->ki_pos; + endbyte = pos + buffered -1 ; + ret =filemap_write_and_wait_range (mapping, pos, endbyte); +if (!ret) {
fs/gfs2/file.c static ssize_t gfs2_file_write_iter(struct kiocb *iocb, struct iov_iter *from) · line 891
Quoted 10 lines
fs/gfs2/file.c +10
-0+ iocb->ki_pos += buffered; + written += buffered; +invalidate_mapping_pages (mapping, + pos >>PAGE_SHIFT , + endbyte >>PAGE_SHIFT ); + }else { +/* +* We don't know how much we wrote, so just return +* the number of bytes which were direct-written +*/
Can't we get in trouble here because we don't update iocb->io_pos?
Regards,
Bob Peterson
Andreas Gruenbacher
maintainerPATCH v3 7/8 gfs2: Remove gfs2_write_{begin,end}
In reply to Andreas GruenbacherNow that generic_file_write_iter is no longer used, there are no remaining users of these address space operations.
--- fs/gfs2/aops.c | 210 --------------------------------------------------------- 1 file changed, 210 deletions(-)
fs/gfs2/aops.c +0 -210
@@ -639,132 +639,6 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping,return ret; } -/** -* gfs2_write_begin - Begin to write to a file -* @file: The file to write to -* @mapping: The mapping in which to write -* @pos: The file offset at which to start writing -* @len: Length of the write -* @flags: Various flags -* @pagep: Pointer to return the page -* @fsdata: Pointer to return fs data (unused by GFS2) -* -* Returns: errno -*/ - -static int gfs2_write_begin (struct file *file,struct address_space *mapping, -loff_t pos,unsigned len,unsigned flags, -struct page **pagep,void **fsdata) -{ -struct gfs2_inode *ip =GFS2_I (mapping->host); -struct gfs2_sbd *sdp =GFS2_SB (mapping->host); -struct gfs2_inode *m_ip =GFS2_I (sdp->sd_statfs_inode); -unsigned int data_blocks =0 , ind_blocks =0 , rblocks; -unsigned requested =0 ; -int alloc_required; -int error =0 ; -pgoff_t index = pos >>PAGE_SHIFT ; -unsigned from = pos & (PAGE_SIZE -1 ); -struct page *page; - -gfs2_holder_init (ip->i_gl,LM_ST_EXCLUSIVE ,0 , &ip->i_gh); - error =gfs2_glock_nq (&ip->i_gh); -if (unlikely (error)) - goto out_uninit; -if (&ip->i_inode == sdp->sd_rindex) { - error =gfs2_glock_nq_init (m_ip->i_gl,LM_ST_EXCLUSIVE , -GL_NOCACHE , &m_ip->i_gh); -if (unlikely (error)) { -gfs2_glock_dq (&ip->i_gh); - goto out_uninit; - } - } - - alloc_required =gfs2_write_alloc_required (ip, pos, len); - -if (alloc_required ||gfs2_is_jdata (ip)) -gfs2_write_calc_reserv (ip, len, &data_blocks, &ind_blocks); - -if (alloc_required) { -struct gfs2_alloc_parms ap = { .aflags =0 , }; - requested = data_blocks + ind_blocks; - ap.target = requested; - error =gfs2_quota_lock_check (ip, &ap); -if (error) - goto out_unlock; - - error =gfs2_inplace_reserve (ip, &ap); -if (error) - goto out_qunlock; - } - - rblocks =RES_DINODE + ind_blocks; -if (gfs2_is_jdata (ip)) - rblocks += data_blocks ? data_blocks :1 ; -if (ind_blocks || data_blocks) - rblocks +=RES_STATFS +RES_QUOTA ; -if (&ip->i_inode == sdp->sd_rindex) - rblocks +=2 *RES_STATFS ; -if (alloc_required) - rblocks +=gfs2_rg_blocks (ip, requested); - - error =gfs2_trans_begin (sdp, rblocks, -PAGE_SIZE /sdp->sd_sb.sb_bsize); -if (error) - goto out_trans_fail; - - error = -ENOMEM ; - flags |=AOP_FLAG_NOFS ; - page =grab_cache_page_write_begin (mapping, index, flags); - *pagep = page; -if (unlikely (!page)) - goto out_endtrans; - -if (gfs2_is_stuffed (ip)) { - error =0 ; -if (pos + len >gfs2_max_stuffed_size (ip)) { - error =gfs2_unstuff_dinode (ip, page); -if (error ==0 ) - goto prepare_write; - }else if (!PageUptodate (page)) { - error =stuffed_readpage (ip, page); - } - goto out; - } - -prepare_write: - error =__block_write_begin (page, from, len, gfs2_block_map); -out: -if (error ==0 ) -return 0 ; - -unlock_page (page); -put_page (page); - -gfs2_trans_end (sdp); -if (pos + len > ip->i_inode.i_size) -gfs2_trim_blocks (&ip->i_inode); - goto out_trans_fail; - -out_endtrans: -gfs2_trans_end (sdp); -out_trans_fail: -if (alloc_required) { -gfs2_inplace_release (ip); -out_qunlock: -gfs2_quota_unlock (ip); - } -out_unlock: -if (&ip->i_inode == sdp->sd_rindex) { -gfs2_glock_dq (&m_ip->i_gh); -gfs2_holder_uninit (&m_ip->i_gh); - } -gfs2_glock_dq (&ip->i_gh); -out_uninit: -gfs2_holder_uninit (&ip->i_gh); -return error; -} -/** * adjust_fs_space - Adjusts the free space available due to gfs2_grow * @inode: the rindex inode
@@ -845,84 +719,6 @@ int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,return copied; } -/** -* gfs2_write_end -* @file: The file to write to -* @mapping: The address space to write to -* @pos: The file position -* @len: The length of the data -* @copied: How much was actually copied by the VFS -* @page: The page that has been written -* @fsdata: The fsdata (unused in GFS2) -* -* The main write_end function for GFS2. We just put our locking around the VFS -* provided functions. -* -* Returns: copied bytes or errno -*/ - -static int gfs2_write_end (struct file *file,struct address_space *mapping, -loff_t pos,unsigned len,unsigned copied, -struct page *page,void *fsdata) -{ -struct inode *inode = page->mapping->host; -struct gfs2_inode *ip =GFS2_I (inode); -struct gfs2_sbd *sdp =GFS2_SB (inode); -struct gfs2_inode *m_ip =GFS2_I (sdp->sd_statfs_inode); -struct buffer_head *dibh; -int ret; -struct gfs2_trans *tr = current->journal_info; -BUG_ON (!tr); - -BUG_ON (gfs2_glock_is_locked_by_me (ip->i_gl) ==NULL ); - - ret =gfs2_meta_inode_buffer (ip, &dibh); -if (unlikely (ret)) - goto out; - -if (gfs2_is_stuffed (ip)) { - ret =gfs2_stuffed_write_end (inode, dibh, pos, copied, page); - page =NULL ; - goto out2; - } - -if (gfs2_is_jdata (ip)) -gfs2_page_add_databufs (ip, page, pos & ~PAGE_MASK , len); -else -gfs2_ordered_add_inode (ip); - - ret =generic_write_end (file, mapping, pos, len, copied, page, fsdata); - page =NULL ; -if (tr->tr_num_buf_new) -__mark_inode_dirty (inode,I_DIRTY_DATASYNC ); -else -gfs2_trans_add_meta (ip->i_gl, dibh); - -out2: -if (inode == sdp->sd_rindex) { -adjust_fs_space (inode); - sdp->sd_rindex_uptodate =0 ; - } - -brelse (dibh); -out: -if (page) { -unlock_page (page); -put_page (page); - } -gfs2_trans_end (sdp); -gfs2_inplace_release (ip); -if (ip->i_qadata && ip->i_qadata->qa_qd_num) -gfs2_quota_unlock (ip); -if (inode == sdp->sd_rindex) { -gfs2_glock_dq (&m_ip->i_gh); -gfs2_holder_uninit (&m_ip->i_gh); - } -gfs2_glock_dq (&ip->i_gh); -gfs2_holder_uninit (&ip->i_gh); -return ret; -} -/** * jdata_set_page_dirty - Page dirtying function * @page: The page to dirty
@@ -1098,8 +894,6 @@ static const struct address_space_operations gfs2_writeback_aops = { .writepages = gfs2_writepages, .readpage = gfs2_readpage, .readpages = gfs2_readpages, - .write_begin = gfs2_write_begin, - .write_end = gfs2_write_end, .bmap = gfs2_bmap, .invalidatepage = gfs2_invalidatepage, .releasepage = gfs2_releasepage,
@@ -1114,8 +908,6 @@ static const struct address_space_operations gfs2_ordered_aops = { .writepages = gfs2_writepages, .readpage = gfs2_readpage, .readpages = gfs2_readpages, - .write_begin = gfs2_write_begin, - .write_end = gfs2_write_end, .set_page_dirty = __set_page_dirty_buffers, .bmap = gfs2_bmap, .invalidatepage = gfs2_invalidatepage,
@@ -1131,8 +923,6 @@ static const struct address_space_operations gfs2_jdata_aops = { .writepages = gfs2_jdata_writepages, .readpage = gfs2_readpage, .readpages = gfs2_readpages, - .write_begin = gfs2_write_begin, - .write_end = gfs2_write_end, .set_page_dirty = jdata_set_page_dirty, .bmap = gfs2_bmap, .invalidatepage = gfs2_invalidatepage,
Signature · 1 line
2.14.3
Andreas Gruenbacher
maintainerPATCH v3 8/8 iomap: Complete partial direct I/O writes synchronously
In reply to Andreas GruenbacherAccording to xfstest generic/240, applications see, to expect direct I/O writes to either complete as a whole or to fail; short direct I/O writes are apparently not appreciated. This means that when only part of an asynchronous direct I/O write succeeds, we can either fail the entire write, or we can wait wait for the partial write to complete and retry the remaining write using buffered I/O. The old __blockdev_direct_IO helper has code for waiting for partial writes to complete; the new iomap_dio_rw iomap helper does not.
The above mentioned fallback mode is used by gfs2, which doesn't allow block allocations under direct I/O to avoid taking cluster-wide exclusive locks. As a consequence, an asynchronous direct I/O write to a file range that ends in a hole will result in a short write. When that happens, we want to retry the remaining write using buffered I/O.
To allow that, change iomap_dio_rw to wait for short direct I/O writes like __blockdev_direct_IO does instead of returning -EIOCBQUEUED.
This fixes xfstest generic/240 on gfs2.
--- fs/iomap.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
fs/iomap.c +14 -10
@@ -821,9 +821,8 @@ static void iomap_dio_bio_end_io(struct bio *bio)iomap_dio_set_error (dio,blk_status_to_errno (bio->bi_status));if (atomic_dec_and_test (&dio->ref)) { -if (is_sync_kiocb (dio->iocb)) { -struct task_struct *waiter = dio->submit.waiter; - +struct task_struct *waiter = dio->submit.waiter; +if (waiter) {WRITE_ONCE (dio->submit.waiter,NULL );wake_up_process (waiter); }else if (dio->flags &IOMAP_DIO_WRITE ) {
@@ -997,6 +996,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,unsigned int flags =IOMAP_DIRECT ;struct blk_plug plug;struct iomap_dio *dio; +bool wait_for_completion =is_sync_kiocb (iocb);lockdep_assert_held (&inode->i_rwsem);
@@ -1016,11 +1016,6 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->flags =0 ; dio->submit.iter = iter; -if (is_sync_kiocb (iocb)) { - dio->submit.waiter = current; - dio->submit.cookie =BLK_QC_T_NONE ; - dio->submit.last_queue =NULL ; - }if (iov_iter_rw (iter) ==READ ) {if (pos >= dio->i_size)
@@ -1057,7 +1052,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,dio_warn_stale_pagecache (iocb->ki_filp); ret =0 ; -if (iov_iter_rw (iter) ==WRITE && !is_sync_kiocb (iocb) && +if (iov_iter_rw (iter) ==WRITE && !wait_for_completion && !inode->i_sb->s_dio_done_wq) { ret =sb_init_dio_done_wq (inode->i_sb);if (ret <0 )
@@ -1074,6 +1069,8 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,/* magic error code to fall back to buffered I/O */ if (ret == -ENOTBLK ) ret =0 ; +if (iov_iter_rw (iter) ==WRITE ) + wait_for_completion = true;break ; } pos += ret;
@@ -1081,13 +1078,20 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,if (iov_iter_rw (iter) ==READ && pos >= dio->i_size)break ; }while ((count =iov_iter_count (iter)) >0 ); + + dio->submit.waiter =NULL ; +if (wait_for_completion) { + dio->submit.waiter = current; + dio->submit.cookie =BLK_QC_T_NONE ; + dio->submit.last_queue =NULL ; + }blk_finish_plug (&plug);if (ret <0 )iomap_dio_set_error (dio, ret);if (!atomic_dec_and_test (&dio->ref)) { -if (!is_sync_kiocb (iocb)) +if (!wait_for_completion)return -EIOCBQUEUED ;for (;;) {
Signature · 1 line
2.14.3