Re: [PATCH RFC v3 03/44] target: fileio: check that the backing file supports ->{read,write}_iter
From: Alexander Mikhalitsyn
Date: Tue Nov 17 2026 - 03:26:58 EST
On Mon, 2026-11-16 at 12:04 +0100, Christian Brauner wrote:
> With fd_async_io=1 the fileio backend calls ->read_iter() and
> ->write_iter() of the backing file directly. The synchronous path
> goes
> through vfs_iter_read() and vfs_iter_write() which check for them but
> the aio path doesn't. So a backing file without them calls a NULL
> pointer on its first I/O.
>
> Refuse such files when configuring the device. On the synchronous
> path
> every read or write that needed the missing method failed with EINVAL
> anyway.
>
> Fixes: 769031c92c8b ("scsi: target: target/file: Add support of
> direct and async I/O")
> Reviewed-by: Jan Kara <jack@xxxxxxx>
> Reviewed-by: Christoph Hellwig <hch@xxxxxx>
> Reviewed-by: Chris Down <chris@xxxxxxxxxxxxxx>
Reviewed-by: Alexander Mikhalitsyn <alex@xxxxxxxxxxxx>
> Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
> ---
> drivers/target/target_core_file.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/target/target_core_file.c
> b/drivers/target/target_core_file.c
> index ab9824a4852f1..a5391e57e9aa5 100644
> --- a/drivers/target/target_core_file.c
> +++ b/drivers/target/target_core_file.c
> @@ -144,6 +144,14 @@ static int fd_configure_device(struct se_device
> *dev)
> goto fail;
> }
> fd_dev->fd_file = file;
> +
> + if (!file->f_op->read_iter || !file->f_op->write_iter) {
> + pr_err("FILEIO: %s lacks ->read_iter or -
> >write_iter\n",
> + fd_dev->fd_dev_name);
> + ret = -EINVAL;
> + goto fail;
> + }
> +
> /*
> * If using a block backend with this struct file, we
> extract
> * fd_dev->fd_[block,dev]_size from struct block_device.