linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruenba@redhat.com>
To: cluster-devel <cluster-devel@redhat.com>, Christoph Hellwig <hch@lst.de>
Cc: linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	Andreas Gruenbacher <agruenba@redhat.com>
Subject: Re: [PATCH v10 1/5] gfs2: Further iomap cleanups
Date: Wed, 27 Jun 2018 03:05:05 +0200	[thread overview]
Message-ID: <CAHc6FU7EFmHzRc5KrBhj7i6rEDKYNbsKcQ++np75sPEsX2kcyQ@mail.gmail.com> (raw)
In-Reply-To: <20180624190028.4166-2-agruenba@redhat.com>

On 24 June 2018 at 21:00, Andreas Gruenbacher <agruenba@redhat.com> wrote:
> In gfs2_iomap_alloc, set the type of newly allocated extents to
> IOMAP_MAPPED so that iomap_to_bh will set the bh states correctly:
> otherwise, the bhs would not be marked as mapped, confusing
> __mpage_writepage.  This means that we need to check for the IOMAP_F_NEW
> flag in fallocate_chunk now.
>
> Further clean up gfs2_iomap_get and implement gfs2_stuffed_iomap here
> directly.  For reads beyond the end of the file, return holes instead of
> failing with -ENOENT so that we can get rid of that special case in
> gfs2_block_map.
>
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> ---
>  fs/gfs2/bmap.c | 74 ++++++++++++++++++++++++++++----------------------
>  fs/gfs2/file.c |  2 +-
>  2 files changed, 43 insertions(+), 33 deletions(-)
>
> diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
> index ed6699705c13..4341683015bf 100644
> --- a/fs/gfs2/bmap.c
> +++ b/fs/gfs2/bmap.c
> @@ -750,6 +750,7 @@ static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap,
>                 }
>         } while (iomap->addr == IOMAP_NULL_ADDR);
>
> +       iomap->type = IOMAP_MAPPED;
>         iomap->length = (u64)dblks << inode->i_blkbits;
>         ip->i_height = mp->mp_fheight;
>         gfs2_add_inode_blocks(&ip->i_inode, alloced);
> @@ -759,17 +760,6 @@ static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap,
>         return ret;
>  }
>
> -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_INLINE;
> -}
> -
>  #define IOMAP_F_GFS2_BOUNDARY IOMAP_F_PRIVATE
>
>  /**
> @@ -789,37 +779,61 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
>  {
>         struct gfs2_inode *ip = GFS2_I(inode);
>         struct gfs2_sbd *sdp = GFS2_SB(inode);
> +       loff_t size = i_size_read(inode);
>         __be64 *ptr;
>         sector_t lblock;
>         sector_t lblock_stop;
>         int ret;
>         int eob;
>         u64 len;
> -       struct buffer_head *bh;
> +       struct buffer_head *dibh, *bh;
>         u8 height;
>
>         if (!length)
>                 return -EINVAL;
>
> +       down_read(&ip->i_rw_mutex);
> +
> +       ret = gfs2_meta_inode_buffer(ip, &dibh);
> +       if (ret)
> +               goto unlock;
> +
>         if (gfs2_is_stuffed(ip)) {
> -               if (flags & IOMAP_REPORT) {
> -                       if (pos >= i_size_read(inode))
> -                               return -ENOENT;
> -                       gfs2_stuffed_iomap(inode, iomap);
> -                       return 0;
> +               if (flags & IOMAP_WRITE) {
> +                       loff_t max_size = gfs2_max_stuffed_size(ip);
> +
> +                       if (pos + length > max_size)
> +                               goto unstuff;
> +                       iomap->length = max_size;
> +               } else {
> +                       if (pos >= size) {
> +                               if (flags & IOMAP_REPORT) {
> +                                       ret = -ENOENT;
> +                                       goto unlock;
> +                               } else {
> +                                       /* report a hole */
> +                                       iomap->offset = pos;
> +                                       iomap->length = length;
> +                                       goto do_alloc;
> +                               }
> +                       }
> +                       iomap->length = size;
>                 }
> -               BUG_ON(!(flags & IOMAP_WRITE));
> +               iomap->addr = (ip->i_no_addr << inode->i_blkbits) +
> +                             sizeof(struct gfs2_dinode);
> +               iomap->type = IOMAP_INLINE;
> +               goto unlock;

To get things right even with the "iomap: direct I/O for inline data"
patch just posted, we want to change the above to "goto out".

>         }
> +
> +unstuff:
>         lblock = pos >> inode->i_blkbits;
>         iomap->offset = lblock << inode->i_blkbits;
>         lblock_stop = (pos + length - 1) >> inode->i_blkbits;
>         len = lblock_stop - lblock + 1;
> +       iomap->length = len << inode->i_blkbits;
>
> -       down_read(&ip->i_rw_mutex);
> -
> -       ret = gfs2_meta_inode_buffer(ip, &mp->mp_bh[0]);
> -       if (ret)
> -               goto unlock;
> +       get_bh(dibh);
> +       mp->mp_bh[0] = dibh;
>
>         height = ip->i_height;
>         while ((lblock + 1) * sdp->sd_sb.sb_bsize > sdp->sd_heightsize[height])
> @@ -853,21 +867,23 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
>         iomap->bdev = inode->i_sb->s_bdev;
>  unlock:
>         up_read(&ip->i_rw_mutex);
> +       if (dibh)
> +               brelse(dibh);
>         return ret;
>
>  do_alloc:
>         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)
>                         ret = gfs2_hole_size(inode, lblock, len, mp, iomap);
>                 else
>                         iomap->length = size - pos;
> +       } else if (!(flags & IOMAP_WRITE)) {
> +               if (pos < size && height == ip->i_height)
> +                       ret = gfs2_hole_size(inode, lblock, len, mp, iomap);
>         }
>         goto out;
>  }
> @@ -941,12 +957,6 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,
>         } 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;
> -               }
>         }
>         if (ret)
>                 goto out;
> diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
> index 7137db7b0119..6f6bbfbff13d 100644
> --- a/fs/gfs2/file.c
> +++ b/fs/gfs2/file.c
> @@ -754,7 +754,7 @@ static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len,
>                 if (error)
>                         goto out;
>                 offset = iomap.offset + iomap.length;
> -               if (iomap.type != IOMAP_HOLE)
> +               if (!(iomap.flags & IOMAP_F_NEW))
>                         continue;
>                 error = sb_issue_zeroout(sb, iomap.addr >> inode->i_blkbits,
>                                          iomap.length >> inode->i_blkbits,
> --
> 2.17.1
>

Andreas

  parent reply	other threads:[~2018-06-27  1:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-24 19:00 [PATCH v10 0/5] gfs2 iomap write support Andreas Gruenbacher
2018-06-24 19:00 ` [PATCH v10 1/5] gfs2: Further iomap cleanups Andreas Gruenbacher
2018-06-25 13:27   ` Andreas Gruenbacher
2018-06-27  1:05   ` Andreas Gruenbacher [this message]
2018-06-24 19:00 ` [PATCH v10 2/5] gfs2: iomap buffered write support Andreas Gruenbacher
2018-06-24 19:00 ` [PATCH v10 3/5] gfs2: gfs2_extent_length cleanup Andreas Gruenbacher
2018-06-24 19:00 ` [PATCH v10 4/5] gfs2: iomap direct I/O support Andreas Gruenbacher
2018-06-24 19:00 ` [PATCH v10 5/5] gfs2: Remove gfs2_write_{begin,end} Andreas Gruenbacher
2018-06-29 19:51 ` [Cluster-devel] [PATCH v10 0/5] gfs2 iomap write support Bob Peterson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHc6FU7EFmHzRc5KrBhj7i6rEDKYNbsKcQ++np75sPEsX2kcyQ@mail.gmail.com \
    --to=agruenba@redhat.com \
    --cc=cluster-devel@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).