RE: [PATCH v3] block: ublk: enable zoned storage support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Andreas Hindborg (Samsung) <nmi@xxxxxxxxxxxx>
> Sent: Wednesday, 28 June 2023 13.52
> To: Niklas Cassel <Niklas.Cassel@xxxxxxx>
> Cc: linux-block@xxxxxxxxxxxxxxx; Hans Holmberg <Hans.Holmberg@xxxxxxx>;
> Matias Bjørling <Matias.Bjorling@xxxxxxx>; Minwoo Im
> <minwoo.im.dev@xxxxxxxxx>; Damien Le Moal
> <damien.lemoal@xxxxxxxxxxxxxxxxxx>; Jens Axboe <axboe@xxxxxxxxx>;
> Ming Lei <ming.lei@xxxxxxxxxx>; open list <linux-kernel@xxxxxxxxxxxxxxx>
> Subject: Re: [PATCH v3] block: ublk: enable zoned storage support
> 
> 
> Niklas Cassel <Niklas.Cassel@xxxxxxx> writes:
> 
> > On Thu, Mar 16, 2023 at 03:55:38PM +0100, Andreas Hindborg wrote:
> >> From: Andreas Hindborg <a.hindborg@xxxxxxxxxxx>
> >
> > Hello Andreas,
> >
> >
> > I think that this patch is starting to look very nice!
> 
> Thanks!
> 
> >
> >
> <snip>
> >> +
> >> +int ublk_report_zones(struct gendisk *disk, sector_t sector,
> >> +		      unsigned int nr_zones, report_zones_cb cb, void *data) {
> >> +	unsigned int done_zones = 0;
> >> +	struct ublk_device *ub = disk->private_data;
> >> +	unsigned int zone_size_sectors = disk->queue->limits.chunk_sectors;
> >> +	unsigned int first_zone = sector >> ilog2(zone_size_sectors);
> >> +	struct blk_zone *buffer;
> >> +	size_t buffer_length;
> >> +	unsigned int max_zones_per_request;
> >
> > Nit: I would sort the variables differently.
> >
> > Perhaps:
> >> +	struct ublk_device *ub = disk->private_data;
> >> +	unsigned int zone_size_sectors = disk->queue->limits.chunk_sectors;
> >> +	unsigned int first_zone = sector >> ilog2(zone_size_sectors);
> >> +	unsigned int done_zones = 0;
> >> +	unsigned int max_zones_per_request;
> >> +	struct blk_zone *buffer;
> >> +	size_t buffer_length;
> >
> 
> Can I ask what is the reasoning behind this? I think they way you propose looks
> better, but are there any rules one can follow for this?

There aren't many hard rules to my knowledge. One rule of thumb, which I use, is to group variables of the same data type. Another one, I personally prefer having the complex data structures first, followed by the simple data types at the end. However, it isn't that easy, as I usually also take the code flow of the function into account, such that the data structures that are used together are also declared together and follows the flow of the code (if it is getting too complex, its probably because the function needs to be split). Finally, it always helps keeping things as simple as possible. 

Other suggestions might be to look at existing code and get a feel for how other structures it. I've found Code Complete by Steve McConnell a classic on maintaining good code style. Obviously, each advice in the book should be weighted towards how its typically done in the kernel.

> 
> Best regards
> Andreas




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux