[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y/y+UFEHn1F1sg4i@x1-carbon>
Date: Mon, 27 Feb 2023 14:29:37 +0000
From: Niklas Cassel <Niklas.Cassel@....com>
To: Andreas Hindborg <nmi@...aspace.dk>
CC: "linux-block@...r.kernel.org" <linux-block@...r.kernel.org>,
Hans Holmberg <Hans.Holmberg@....com>,
Matias Bjørling <Matias.Bjorling@....com>,
kernel test robot <lkp@...el.com>,
Ming Lei <ming.lei@...hat.com>, Jens Axboe <axboe@...nel.dk>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] block: ublk: enable zoned storage support
On Mon, Feb 27, 2023 at 12:59:45PM +0100, Andreas Hindborg wrote:
(snip)
> >> +#else
> >> +void ublk_set_nr_zones(struct ublk_device *ub);
> >> +void ublk_dev_param_zoned_apply(struct ublk_device *ub);
> >> +int ublk_revalidate_disk_zones(struct gendisk *disk);
> >
> > These are declarations, shouldn't they be dummy definitions instead?
>
> I looked at how nvme host defines nvme_revalidate_zones() when I did
> this. The functions become undefined symbols but because the call sites
> are optimized out they go away.
Looking at e.g. nvme_revalidate_zones
$ git grep nvme_revalidate_zones
drivers/nvme/host/core.c: ret = nvme_revalidate_zones(ns);
drivers/nvme/host/nvme.h:int nvme_revalidate_zones(struct nvme_ns *ns);
drivers/nvme/host/zns.c:int nvme_revalidate_zones(struct nvme_ns *ns)
The function is declared in nvme.h, but like you say, without any definition.
zns.c provides a definition, but that file is only build if
CONFIG_BLK_DEV_ZONED is set.
> > https://github.com/torvalds/linux/blob/v6.2/fs/btrfs/Makefile#L39
> > https://github.com/torvalds/linux/blob/v6.2/drivers/block/null_blk/Makefile#L11
> >
> > They have put the zoned stuff in a separate C file that is only compiled
> > when CONFIG_BLK_DEV_ZONED is set.
> >
> > I'm not sure if a similar design is desired for ublk or not.
> >
> > However, if a similar design pattern was used, it could probably avoid
> > some of these unpleasant dummy definitions altogether.
>
> This is the same as I do here, except I put the declarations in the c
> file instead of a header. I did this for two reasons 1) there is no ublk
> header besides the uapi header (I would add a header just for this), 2)
> the declarations need only exist inside ublk_drv.c. For btrfs, null_blk,
> nvme, the declarations go in a header file and the functions in question
> do not have static linkage.
>
> I could move the function declarations out of the #else block, but then
> they would need to be declared static and that gives a compiler warning
> when the implementation is not present.
I would love to hear someone else's opinion about this as well, but I do
think that having #ifdef and #else with both a declaration and a definition
in the C file is quite ugly.
If having an internal only header (in the same directory as the C file),
makes the C code easier to read, I'm all for it.
It seems to work for nvme to only have a declaration in an internal header
file, and only provide a definition if CONFIG_BLK_DEV_ZONED is set,
presumably without giving a warning. Perhaps ublk can do the same?
Kind regards,
Niklas
Powered by blists - more mailing lists