Re: [PATCH RFC v3 02/44] nvmet: check that the file backend supports ->{read,write}_iter

From: Alexander Mikhalitsyn

Date: Tue Nov 17 2026 - 03:25:49 EST


On Mon, 2026-11-16 at 12:04 +0100, Christian Brauner wrote:
> The file backend calls ->read_iter() and ->write_iter() of the
> backing
> file directly but never checks that they exist. Everything that isn't
> a
> block device ends up in the file backend. So a namespace pointing to
> a
> file without them calls a NULL pointer on its first I/O. Only
> buffered_io=1 gets that far as the O_DIRECT open fails for such
> files.
>
> Refuse them when the namespace is enabled the same way zloop does
> since
> commit 0c10f8a1a7ae ("zloop: check that the zone backing file support
> ->{read,write}_iter").
>
> Fixes: d5eff33ee6f8 ("nvmet: add simple file backed ns support")
> 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/nvme/target/io-cmd-file.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/nvme/target/io-cmd-file.c
> b/drivers/nvme/target/io-cmd-file.c
> index 695963dd932ee..dfa8aa46188c8 100644
> --- a/drivers/nvme/target/io-cmd-file.c
> +++ b/drivers/nvme/target/io-cmd-file.c
> @@ -47,6 +47,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
>   return ret;
>   }
>  
> + if (!ns->file->f_op->read_iter || !ns->file->f_op-
> >write_iter) {
> + ret = -EINVAL;
> + goto err;
> + }
> +
>   nvmet_file_ns_revalidate(ns);
>  
>   /*