Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Viacheslav Dubeyko <slava@dubeyko.com>
Cc: glaubitz@physik.fu-berlin.de, frank.li@vivo.com, hch@lst.de,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	vdubeyko@coreweave.com, brauner@kernel.org,
	linux-xfs@vger.kernel.org
Subject: Re: [PATCH v5 5/5] hfsplus: convert regular file I/O to iomap
Date: Fri, 20 Nov 2026 19:26:48 +0100	[thread overview]
Message-ID: <20261120182648.GE2183@lst.de> (raw)
In-Reply-To: <20261118004844.3849979-6-slava@dubeyko.com>

On Tue, Nov 17, 2026 at 04:48:44PM -0800, Viacheslav Dubeyko wrote:
> Switch the HFS+ regular file data path from buffer heads and
> blockdev_direct_IO() to iomap.
> 
> Add iomap.h and iomap.c with hfsplus_iomap_ops,
> hfsplus_write_iomap_ops, hfsplus_writeback_ops and
> hfsplus_write_dio_ops. iomap.c implements __hfsplus_iomap_begin(),
> hfsplus_write_iomap_end(), hfsplus_iomap_cont_expand() and
> hfsplus_writeback_range(), which are the basis of the HFS+ iomap
> operations. Direct write completion uses the generic
> iomap_dio_end_io() helper.
> 
> Implement iomap-based hfsplus_file_llseek(), hfsplus_file_read_iter()
> and hfsplus_file_write_iter(). The volume capacity limit for writes is
> enforced by generic_write_checks(), since s_maxbytes is already set
> from the volume capacity.
> 
> Redefine hfsplus_aops as iomap-based operations for regular files.
> As a result, hfsplus_direct_IO() is removed as a user of
> blockdev_direct_IO(), and the LEGACY_DIRECT_IO dependency is dropped
> from Kconfig. hfsplus_file_truncate() extends regular files by means
> of hfsplus_iomap_cont_expand(), while other inodes still use the
> write_begin/write_end path.
> 
> HFS+ does not support holes, so a write or truncate that extends a
> file first zero-fills the range between the old end-of-file and the
> new one by means of hfsplus_iomap_cont_expand(). Introduce
> hfsplus_iomap_extend_size() that grows i_size, zero-fills the gap and
> rolls back on failure, and use it in hfsplus_file_write_iter() and
> hfsplus_setattr(). Introduce hfsplus_iomap_size_rollback() that waits
> for in-flight direct I/O, sets i_size, truncates the page cache beyond
> it and calls hfsplus_file_truncate() to release the blocks allocated
> past it. It is not called when phys_size is below the new size, since
> hfsplus_file_truncate() would zero-fill again in that case.
> 
> In hfsplus_file_write_iter(), roll back after the data write if fewer
> bytes than requested were written: to the original size if nothing
> was written, or to the current i_size after a short write. Queued
> asynchronous direct I/O is skipped, because direct I/O beyond
> phys_size is forced to be synchronous, so a queued request never
> extends the file.
> 
> cc: Christoph Hellwig <hch@lst.de>
> cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
> cc: Yangtao Li <frank.li@vivo.com>
> cc: linux-fsdevel@vger.kernel.org
> Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
> ---
>  fs/hfsplus/Kconfig      |   2 +-
>  fs/hfsplus/Makefile     |   6 +-
>  fs/hfsplus/extents.c    |  40 +++++--
>  fs/hfsplus/file.c       | 187 ++++++++++++++++++++++++++++-
>  fs/hfsplus/hfsplus_fs.h |  17 +++
>  fs/hfsplus/inode.c      | 155 ++++++++++++------------
>  fs/hfsplus/iomap.c      | 254 ++++++++++++++++++++++++++++++++++++++++
>  fs/hfsplus/iomap.h      |  17 +++
>  8 files changed, 583 insertions(+), 95 deletions(-)
>  create mode 100644 fs/hfsplus/iomap.c
>  create mode 100644 fs/hfsplus/iomap.h
> 
> diff --git a/fs/hfsplus/Kconfig b/fs/hfsplus/Kconfig
> index ca8401cb6954..b4432c64db3b 100644
> --- a/fs/hfsplus/Kconfig
> +++ b/fs/hfsplus/Kconfig
> @@ -5,7 +5,7 @@ config HFSPLUS_FS
>  	select BUFFER_HEAD
>  	select NLS
>  	select NLS_UTF8
> -	select LEGACY_DIRECT_IO
> +	select FS_IOMAP
>  	help
>  	  If you say Y here, you will be able to mount extended format
>  	  Macintosh-formatted hard drive partitions with full read-write access.
> diff --git a/fs/hfsplus/Makefile b/fs/hfsplus/Makefile
> index 82738ce7ca4d..3ddea69a9c69 100644
> --- a/fs/hfsplus/Makefile
> +++ b/fs/hfsplus/Makefile
> @@ -5,9 +5,9 @@
>  
>  obj-$(CONFIG_HFSPLUS_FS) += hfsplus.o
>  
> -hfsplus-objs := super.o options.o inode.o file.o ioctl.o extents.o catalog.o dir.o \
> -		btree.o bnode.o brec.o bfind.o tables.o unicode.o wrapper.o bitmap.o \
> -		part_tbl.o \
> +hfsplus-objs := super.o options.o inode.o file.o iomap.o ioctl.o extents.o \
> +		catalog.o dir.o btree.o bnode.o brec.o bfind.o tables.o \
> +		unicode.o wrapper.o bitmap.o part_tbl.o \
>  		attributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o
>  
>  # KUnit tests
> diff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c
> index bb5a1508498d..0928d64684aa 100644
> --- a/fs/hfsplus/extents.c
> +++ b/fs/hfsplus/extents.c
> @@ -15,6 +15,7 @@
>  
>  #include "hfsplus_fs.h"
>  #include "hfsplus_raw.h"
> +#include "iomap.h"
>  
>  /* Compare two extents keys, returns 0 on same, pos/neg for difference */
>  int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1,
> @@ -610,20 +611,33 @@ void hfsplus_file_truncate(struct inode *inode)
>  		inode->i_ino, (long long)hip->phys_size, inode->i_size);
>  
>  	if (inode->i_size > hip->phys_size) {
> -		struct address_space *mapping = inode->i_mapping;
> -		struct folio *folio;
> -		void *fsdata = NULL;
> -		loff_t size = inode->i_size;
> +		if (S_ISREG(inode->i_mode)) {
> +			res = hfsplus_iomap_cont_expand(inode, hip->phys_size,
> +							inode->i_size);
> +			if (res)
> +				return;
> +
> +			mark_inode_dirty(inode);
> +		} else {
> +			struct address_space *mapping = inode->i_mapping;
> +			struct folio *folio;
> +			void *fsdata = NULL;
> +
> +			res = hfsplus_write_begin(NULL, mapping,
> +						  inode->i_size, 0,
> +						  &folio, &fsdata);
> +			if (res)
> +				return;
> +
> +			res = generic_write_end(NULL, mapping,
> +						inode->i_size, 0, 0,
> +						folio, fsdata);
> +			if (res < 0)
> +				return;
> +
> +			mark_inode_dirty(inode);
> +		}
>  
> -		res = hfsplus_write_begin(NULL, mapping, size, 0,
> -					  &folio, &fsdata);
> -		if (res)
> -			return;
> -		res = generic_write_end(NULL, mapping, size, 0, 0,
> -					folio, fsdata);
> -		if (res < 0)
> -			return;
> -		mark_inode_dirty(inode);
>  		return;
>  	}
>  
> diff --git a/fs/hfsplus/file.c b/fs/hfsplus/file.c
> index 6b14095b2aa6..f34cd80351e5 100644
> --- a/fs/hfsplus/file.c
> +++ b/fs/hfsplus/file.c
> @@ -3,9 +3,11 @@
>  #include <linux/fs.h>
>  #include <linux/uio.h>
>  #include <linux/mount.h>
> +#include <linux/iomap.h>
>  
>  #include "hfsplus_fs.h"
>  #include "hfsplus_raw.h"
> +#include "iomap.h"
>  
>  static int hfsplus_file_open(struct inode *inode, struct file *file)
>  {
> @@ -14,6 +16,7 @@ static int hfsplus_file_open(struct inode *inode, struct file *file)
>  	if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
>  		return -EOVERFLOW;
>  	atomic_inc(&HFSPLUS_I(inode)->opencnt);
> +	file->f_mode |= FMODE_CAN_ODIRECT;
>  	return 0;
>  }
>  
> @@ -113,10 +116,188 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
>  	return error;
>  }
>  
> +/*
> + * Fall back to buffered I/O for the tail of a write that
> + * iomap_dio_rw() could not perform directly (unaligned tail,
> + * or no blocks could be mapped without allocation
> + * outside the direct path).
> + */

Here you can use up the entire 80 characters as well.

> +static ssize_t hfsplus_fallback_buffered_write(struct kiocb *iocb,
> +						struct iov_iter *from)
> +{
> +	loff_t offset = iocb->ki_pos, end;
> +	ssize_t written;
> +	int ret;
> +
> +	iocb->ki_flags &= ~IOCB_DIRECT;

Does this need to wait for a zero i_dio_count just as it has been fixed
in various files recently?

It would be kinda nice to factor all this fallback logic into a helper
so that we have one maintained set of this logic instead of a copy in
various file systems.

> +	ret = iomap_dio_rw(iocb, from,
> +			   &hfsplus_write_iomap_ops,
> +			   &hfsplus_write_dio_ops,
> +			   dio_flags, NULL, 0);

You can use up the space available:

	ret = iomap_dio_rw(iocb, from, &hfsplus_write_iomap_ops,
			&hfsplus_write_dio_ops, dio_flags, NULL, 0);

> +		if (iocb->ki_pos + iov_iter_count(iter) >
> +		    HFSPLUS_I(inode)->phys_size)
> +			dio_flags |= IOMAP_DIO_FORCE_WAIT;

Add a comment on why the wait is forced?


      reply	other threads:[~2026-11-20 18:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  0:48 [PATCH v5 0/5] hfsplus: convert regular file I/O to iomap Viacheslav Dubeyko
2026-11-18  0:48 ` [PATCH v5 1/5] iomap: add iomap_dio_end_io() helper Viacheslav Dubeyko
2026-11-20 13:48   ` Christian Brauner
2026-11-20 18:21     ` Christoph Hellwig
2026-11-18  0:48 ` [PATCH v5 2/5] hfsplus: move file related operations to file.c Viacheslav Dubeyko
2026-11-20 18:22   ` Christoph Hellwig
2026-11-18  0:48 ` [PATCH v5 3/5] hfsplus: rework hfsplus_get_block() logic Viacheslav Dubeyko
2026-11-20 18:23   ` Christoph Hellwig
2026-11-18  0:48 ` [PATCH v5 4/5] hfsplus: return -EIO from hfsplus_map_extent() if no extent covers the block Viacheslav Dubeyko
2026-11-20 18:23   ` Christoph Hellwig
2026-11-18  0:48 ` [PATCH v5 5/5] hfsplus: convert regular file I/O to iomap Viacheslav Dubeyko
2026-11-20 18:26   ` Christoph Hellwig [this message]

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=20261120182648.GE2183@lst.de \
    --to=hch@lst.de \
    --cc=brauner@kernel.org \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=slava@dubeyko.com \
    --cc=vdubeyko@coreweave.com \
    /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