[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fc7d88a5-f65b-3962-22e5-cc393535d66d@samsung.com>
Date: Wed, 21 Sep 2022 19:32:45 +0200
From: Pankaj Raghav <p.raghav@...sung.com>
To: Mike Snitzer <snitzer@...hat.com>
CC: <agk@...hat.com>, <snitzer@...nel.org>, <axboe@...nel.dk>,
<damien.lemoal@...nsource.wdc.com>, <hch@....de>,
Damien Le Moal <damien.lemoal@....com>, <bvanassche@....org>,
<pankydev8@...il.com>, <gost.dev@...sung.com>,
<linux-kernel@...r.kernel.org>, <linux-nvme@...ts.infradead.org>,
<linux-block@...r.kernel.org>, <dm-devel@...hat.com>,
Johannes Thumshirn <johannes.thumshirn@....com>,
<jaegeuk@...nel.org>, <matias.bjorling@....com>
Subject: Re: [PATCH v14 13/13] dm: add power-of-2 target for zoned devices
with non power-of-2 zone sizes
>> +/*
>> + * This target works on the complete zoned device. Partial mapping is not
>> + * supported.
>> + * Construct a zoned po2 logical device: <dev-path>
>> + */
>> +static int dm_po2z_ctr(struct dm_target *ti, unsigned int argc, char **argv)
>> +{
>> + struct dm_po2z_target *dmh = NULL;
>> + int ret;
>> + sector_t zone_size;
>> + sector_t dev_capacity;
>> +
>> + if (argc != 1)
>> + return -EINVAL;
>> +
>> + dmh = kmalloc(sizeof(*dmh), GFP_KERNEL);
>> + if (!dmh)
>> + return -ENOMEM;
>> +
>> + ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table),
>> + &dmh->dev);
>> + if (ret) {
>> + ti->error = "Device lookup failed";
>> + goto bad;
>> + }
>> +
>> + if (!bdev_is_zoned(dmh->dev->bdev)) {
>> + DMERR("%pg is not a zoned device", dmh->dev->bdev);
>> + ret = -EINVAL;
>> + goto bad;
>> + }
>> +
>> + zone_size = bdev_zone_sectors(dmh->dev->bdev);
>> + dev_capacity = get_capacity(dmh->dev->bdev->bd_disk);
>> + if (ti->len != dev_capacity) {
>> + DMERR("%pg Partial mapping of the target is not supported",
>> + dmh->dev->bdev);
>> + ret = -EINVAL;
>> + goto bad;
>> + }
>> +
>> + if (is_power_of_2(zone_size))
>> + DMWARN("%pg: underlying device has a power-of-2 number of sectors per zone",
>> + dmh->dev->bdev);
>> +
>> + dmh->zone_size = zone_size;
>> + dmh->zone_size_po2 = 1 << get_count_order_long(zone_size);
>> + dmh->zone_size_po2_shift = ilog2(dmh->zone_size_po2);
>> + dmh->zone_size_diff = dmh->zone_size_po2 - dmh->zone_size;
>> + ti->private = dmh;
>> + ti->max_io_len = dmh->zone_size_po2;
>> + dmh->nr_zones = npo2_zone_no(dmh, ti->len);
>> + ti->len = dmh->zone_size_po2 * dmh->nr_zones;
>> + return 0;
>> +
>> +bad:
>> + kfree(dmh);
>> + return ret;
>> +}
>
> This error handling still isn't correct. You're using
> dm_get_device(). If you return early due to error, _after_
> dm_get_device(), you need to dm_put_device().
>
> Basically you need a new label above "bad:" that calls dm_put_device()
> then falls through to "bad:". Or you need to explcitly call
> dm_put_device() before "goto bad;" in the if (ti->len != dev_capacity)
> error branch.
>
Ah. I naively assumed dtr will be called to cleanup but not in this case as
the ctr itself fails.
I will add an extra label on top of `bad` and use it for errors that
happens after `dm_get_device`. Thanks for pointing it out Mike.
Powered by blists - more mailing lists