* (no subject)
@ 2020-04-08 19:44 Christoph Hellwig
2020-04-08 19:44 ` [PATCH 01/10] block: refactor blkpg_ioctl Christoph Hellwig
` (9 more replies)
0 siblings, 10 replies; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-08 19:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
Subject: more partition handling cleanups
Hi Jens,
this series cleans up more lose ends in the partitioning code. It also
removes a rather annoying use of ioctl_by_bdev in the s390 dasd driver.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 01/10] block: refactor blkpg_ioctl
2020-04-08 19:44 Christoph Hellwig
@ 2020-04-08 19:44 ` Christoph Hellwig
2020-04-09 11:21 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 02/10] block: pass a hd_struct to delete_partition Christoph Hellwig
` (8 subsequent siblings)
9 siblings, 1 reply; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-08 19:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
Split each sub-command out into a separate helper, and move those helpers
to block/partitions/core.c instead of having a lot of partition
manipulation logic open coded in block/ioctl.c.
Signed-off-by: Christoph Hellwig <hch@lst.de
---
block/blk.h | 8 ++-
block/ioctl.c | 150 +++++++---------------------------------
block/partitions/core.c | 115 +++++++++++++++++++++++++++++-
3 files changed, 145 insertions(+), 128 deletions(-)
diff --git a/block/blk.h b/block/blk.h
index 0a94ec68af32..305e0ac22bf7 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -389,11 +389,13 @@ char *disk_name(struct gendisk *hd, int partno, char *buf);
#define ADDPART_FLAG_NONE 0
#define ADDPART_FLAG_RAID 1
#define ADDPART_FLAG_WHOLEDISK 2
-struct hd_struct *__must_check add_partition(struct gendisk *disk, int partno,
- sector_t start, sector_t len, int flags,
- struct partition_meta_info *info);
void __delete_partition(struct percpu_ref *ref);
void delete_partition(struct gendisk *disk, int partno);
+int bdev_add_partition(struct block_device *bdev, int partno,
+ sector_t start, sector_t length);
+int bdev_del_partition(struct block_device *bdev, int partno);
+int bdev_resize_partition(struct block_device *bdev, int partno,
+ sector_t start, sector_t length);
int disk_expand_part_tbl(struct gendisk *disk, int target);
static inline int hd_ref_init(struct hd_struct *part)
diff --git a/block/ioctl.c b/block/ioctl.c
index 6e827de1a4c4..3de5b29c839e 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -16,142 +16,44 @@
static int blkpg_do_ioctl(struct block_device *bdev,
struct blkpg_partition __user *upart, int op)
{
- struct block_device *bdevp;
- struct gendisk *disk;
- struct hd_struct *part, *lpart;
struct blkpg_partition p;
- struct disk_part_iter piter;
long long start, length;
- int partno;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
if (copy_from_user(&p, upart, sizeof(struct blkpg_partition)))
return -EFAULT;
- disk = bdev->bd_disk;
if (bdev != bdev->bd_contains)
return -EINVAL;
- partno = p.pno;
- if (partno <= 0)
+
+ if (p.pno <= 0)
return -EINVAL;
+
+ if (op == BLKPG_DEL_PARTITION)
+ return bdev_del_partition(bdev, p.pno);
+
+ start = p.start >> SECTOR_SHIFT;
+ length = p.length >> SECTOR_SHIFT;
+
+ /* check for fit in a hd_struct */
+ if (sizeof(sector_t) < sizeof(long long)) {
+ long pstart = start, plength = length;
+
+ if (pstart != start || plength != length || pstart < 0 ||
+ plength < 0 || p.pno > 65535)
+ return -EINVAL;
+ }
+
switch (op) {
- case BLKPG_ADD_PARTITION:
- start = p.start >> 9;
- length = p.length >> 9;
- /* check for fit in a hd_struct */
- if (sizeof(sector_t) == sizeof(long) &&
- sizeof(long long) > sizeof(long)) {
- long pstart = start, plength = length;
- if (pstart != start || plength != length
- || pstart < 0 || plength < 0 || partno > 65535)
- return -EINVAL;
- }
- /* check if partition is aligned to blocksize */
- if (p.start & (bdev_logical_block_size(bdev) - 1))
- return -EINVAL;
-
- mutex_lock(&bdev->bd_mutex);
-
- /* overlap? */
- disk_part_iter_init(&piter, disk,
- DISK_PITER_INCL_EMPTY);
- while ((part = disk_part_iter_next(&piter))) {
- if (!(start + length <= part->start_sect ||
- start >= part->start_sect + part->nr_sects)) {
- disk_part_iter_exit(&piter);
- mutex_unlock(&bdev->bd_mutex);
- return -EBUSY;
- }
- }
- disk_part_iter_exit(&piter);
-
- /* all seems OK */
- part = add_partition(disk, partno, start, length,
- ADDPART_FLAG_NONE, NULL);
- mutex_unlock(&bdev->bd_mutex);
- return PTR_ERR_OR_ZERO(part);
- case BLKPG_DEL_PARTITION:
- part = disk_get_part(disk, partno);
- if (!part)
- return -ENXIO;
-
- bdevp = bdget(part_devt(part));
- disk_put_part(part);
- if (!bdevp)
- return -ENOMEM;
-
- mutex_lock(&bdevp->bd_mutex);
- if (bdevp->bd_openers) {
- mutex_unlock(&bdevp->bd_mutex);
- bdput(bdevp);
- return -EBUSY;
- }
- /* all seems OK */
- fsync_bdev(bdevp);
- invalidate_bdev(bdevp);
-
- mutex_lock_nested(&bdev->bd_mutex, 1);
- delete_partition(disk, partno);
- mutex_unlock(&bdev->bd_mutex);
- mutex_unlock(&bdevp->bd_mutex);
- bdput(bdevp);
-
- return 0;
- case BLKPG_RESIZE_PARTITION:
- start = p.start >> 9;
- /* new length of partition in bytes */
- length = p.length >> 9;
- /* check for fit in a hd_struct */
- if (sizeof(sector_t) == sizeof(long) &&
- sizeof(long long) > sizeof(long)) {
- long pstart = start, plength = length;
- if (pstart != start || plength != length
- || pstart < 0 || plength < 0)
- return -EINVAL;
- }
- part = disk_get_part(disk, partno);
- if (!part)
- return -ENXIO;
- bdevp = bdget(part_devt(part));
- if (!bdevp) {
- disk_put_part(part);
- return -ENOMEM;
- }
- mutex_lock(&bdevp->bd_mutex);
- mutex_lock_nested(&bdev->bd_mutex, 1);
- if (start != part->start_sect) {
- mutex_unlock(&bdevp->bd_mutex);
- mutex_unlock(&bdev->bd_mutex);
- bdput(bdevp);
- disk_put_part(part);
- return -EINVAL;
- }
- /* overlap? */
- disk_part_iter_init(&piter, disk,
- DISK_PITER_INCL_EMPTY);
- while ((lpart = disk_part_iter_next(&piter))) {
- if (lpart->partno != partno &&
- !(start + length <= lpart->start_sect ||
- start >= lpart->start_sect + lpart->nr_sects)
- ) {
- disk_part_iter_exit(&piter);
- mutex_unlock(&bdevp->bd_mutex);
- mutex_unlock(&bdev->bd_mutex);
- bdput(bdevp);
- disk_put_part(part);
- return -EBUSY;
- }
- }
- disk_part_iter_exit(&piter);
- part_nr_sects_write(part, (sector_t)length);
- i_size_write(bdevp->bd_inode, p.length);
- mutex_unlock(&bdevp->bd_mutex);
- mutex_unlock(&bdev->bd_mutex);
- bdput(bdevp);
- disk_put_part(part);
- return 0;
- default:
+ case BLKPG_ADD_PARTITION:
+ /* check if partition is aligned to blocksize */
+ if (p.start & (bdev_logical_block_size(bdev) - 1))
return -EINVAL;
+ return bdev_add_partition(bdev, p.pno, start, length);
+ case BLKPG_DEL_PARTITION:
+ return bdev_resize_partition(bdev, p.pno, start, length);
+ default:
+ return -EINVAL;
}
}
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 1a0a829d8416..7577bdba3b2b 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -335,7 +335,7 @@ static DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL);
* Must be called either with bd_mutex held, before a disk can be opened or
* after all disk users are gone.
*/
-struct hd_struct *add_partition(struct gendisk *disk, int partno,
+static struct hd_struct *add_partition(struct gendisk *disk, int partno,
sector_t start, sector_t len, int flags,
struct partition_meta_info *info)
{
@@ -472,6 +472,119 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
return ERR_PTR(err);
}
+static bool partition_overlaps(struct gendisk *disk, sector_t start,
+ sector_t length, int skip_partno)
+{
+ struct disk_part_iter piter;
+ struct hd_struct *part;
+ bool overlap = false;
+
+ disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
+ while ((part = disk_part_iter_next(&piter))) {
+ if (part->partno == skip_partno ||
+ start >= part->start_sect + part->nr_sects ||
+ start + length <= part->start_sect)
+ continue;
+ overlap = true;
+ break;
+ }
+
+ disk_part_iter_exit(&piter);
+ return overlap;
+}
+
+int bdev_add_partition(struct block_device *bdev, int partno,
+ sector_t start, sector_t length)
+{
+ struct hd_struct *part;
+
+ mutex_lock(&bdev->bd_mutex);
+ if (partition_overlaps(bdev->bd_disk, start, length, -1)) {
+ mutex_unlock(&bdev->bd_mutex);
+ return -EBUSY;
+ }
+
+ part = add_partition(bdev->bd_disk, partno, start, length,
+ ADDPART_FLAG_NONE, NULL);
+ mutex_unlock(&bdev->bd_mutex);
+ return PTR_ERR_OR_ZERO(part);
+}
+
+int bdev_del_partition(struct block_device *bdev, int partno)
+{
+ struct block_device *bdevp;
+ struct hd_struct *part;
+ int ret = 0;
+
+ part = disk_get_part(bdev->bd_disk, partno);
+ if (!part)
+ return -ENXIO;
+
+ bdevp = bdget(part_devt(part));
+ disk_put_part(part);
+ if (!bdevp)
+ return -ENOMEM;
+
+ mutex_lock(&bdevp->bd_mutex);
+
+ ret = -EBUSY;
+ if (bdevp->bd_openers)
+ goto out_unlock;
+
+ fsync_bdev(bdevp);
+ invalidate_bdev(bdevp);
+
+ mutex_lock_nested(&bdev->bd_mutex, 1);
+ delete_partition(bdev->bd_disk, partno);
+ mutex_unlock(&bdev->bd_mutex);
+
+ ret = 0;
+out_unlock:
+ mutex_unlock(&bdevp->bd_mutex);
+ bdput(bdevp);
+ return ret;
+}
+
+int bdev_resize_partition(struct block_device *bdev, int partno,
+ sector_t start, sector_t length)
+{
+ struct block_device *bdevp;
+ struct hd_struct *part;
+ int ret = 0;
+
+ part = disk_get_part(bdev->bd_disk, partno);
+ if (!part)
+ return -ENXIO;
+
+ ret = -ENOMEM;
+ bdevp = bdget(part_devt(part));
+ if (!bdevp)
+ goto out_put_part;
+
+ mutex_lock(&bdevp->bd_mutex);
+ mutex_lock_nested(&bdev->bd_mutex, 1);
+
+ ret = -EINVAL;
+ if (start != part->start_sect)
+ goto out_unlock;
+
+ ret = -EBUSY;
+ if (partition_overlaps(bdev->bd_disk, start, length, partno))
+ goto out_unlock;
+
+ part_nr_sects_write(part, (sector_t)length);
+ i_size_write(bdevp->bd_inode, length << SECTOR_SHIFT);
+
+ ret = 0;
+out_unlock:
+ mutex_unlock(&bdevp->bd_mutex);
+ mutex_unlock(&bdev->bd_mutex);
+ bdput(bdevp);
+out_put_part:
+ disk_put_part(part);
+ return ret;
+}
+
static bool disk_unlock_native_capacity(struct gendisk *disk)
{
const struct block_device_operations *bdops = disk->fops;
--
2.25.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 02/10] block: pass a hd_struct to delete_partition
2020-04-08 19:44 Christoph Hellwig
2020-04-08 19:44 ` [PATCH 01/10] block: refactor blkpg_ioctl Christoph Hellwig
@ 2020-04-08 19:44 ` Christoph Hellwig
2020-04-09 11:27 ` Johannes Thumshirn
2020-04-09 12:02 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 03/10] block: cleanup hd_struct freeing Christoph Hellwig
` (7 subsequent siblings)
9 siblings, 2 replies; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-08 19:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
All callers have the hd_strut at hand, so pass it instead of doing
another lookup.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk.h | 2 +-
block/genhd.c | 2 +-
block/partitions/core.c | 22 ++++++++--------------
3 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/block/blk.h b/block/blk.h
index 305e0ac22bf7..0cbf64108922 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -390,7 +390,7 @@ char *disk_name(struct gendisk *hd, int partno, char *buf);
#define ADDPART_FLAG_RAID 1
#define ADDPART_FLAG_WHOLEDISK 2
void __delete_partition(struct percpu_ref *ref);
-void delete_partition(struct gendisk *disk, int partno);
+void delete_partition(struct gendisk *disk, struct hd_struct *part);
int bdev_add_partition(struct block_device *bdev, int partno,
sector_t start, sector_t length);
int bdev_del_partition(struct block_device *bdev, int partno);
diff --git a/block/genhd.c b/block/genhd.c
index 06b642b23a07..1cc50ad5b191 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -897,7 +897,7 @@ void del_gendisk(struct gendisk *disk)
while ((part = disk_part_iter_next(&piter))) {
invalidate_partition(disk, part->partno);
bdev_unhash_inode(part_devt(part));
- delete_partition(disk, part->partno);
+ delete_partition(disk, part);
}
disk_part_iter_exit(&piter);
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 7577bdba3b2b..0b1b67f50652 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -296,20 +296,12 @@ void __delete_partition(struct percpu_ref *ref)
* Must be called either with bd_mutex held, before a disk can be opened or
* after all disk users are gone.
*/
-void delete_partition(struct gendisk *disk, int partno)
+void delete_partition(struct gendisk *disk, struct hd_struct *part)
{
struct disk_part_tbl *ptbl =
rcu_dereference_protected(disk->part_tbl, 1);
- struct hd_struct *part;
-
- if (partno >= ptbl->len)
- return;
- part = rcu_dereference_protected(ptbl->part[partno], 1);
- if (!part)
- return;
-
- rcu_assign_pointer(ptbl->part[partno], NULL);
+ rcu_assign_pointer(ptbl->part[part->partno], NULL);
rcu_assign_pointer(ptbl->last_lookup, NULL);
kobject_put(part->holder_dir);
device_del(part_to_dev(part));
@@ -520,10 +512,10 @@ int bdev_del_partition(struct block_device *bdev, int partno)
if (!part)
return -ENXIO;
+ ret = -ENOMEM;
bdevp = bdget(part_devt(part));
- disk_put_part(part);
if (!bdevp)
- return -ENOMEM;
+ goto out_put_part;
mutex_lock(&bdevp->bd_mutex);
@@ -535,13 +527,15 @@ int bdev_del_partition(struct block_device *bdev, int partno)
invalidate_bdev(bdevp);
mutex_lock_nested(&bdev->bd_mutex, 1);
- delete_partition(bdev->bd_disk, partno);
+ delete_partition(bdev->bd_disk, part);
mutex_unlock(&bdev->bd_mutex);
ret = 0;
out_unlock:
mutex_unlock(&bdevp->bd_mutex);
bdput(bdevp);
+out_put_part:
+ disk_put_part(part);
return ret;
}
@@ -617,7 +611,7 @@ int blk_drop_partitions(struct gendisk *disk, struct block_device *bdev)
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
while ((part = disk_part_iter_next(&piter)))
- delete_partition(disk, part->partno);
+ delete_partition(disk, part);
disk_part_iter_exit(&piter);
return 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 03/10] block: cleanup hd_struct freeing
2020-04-08 19:44 Christoph Hellwig
2020-04-08 19:44 ` [PATCH 01/10] block: refactor blkpg_ioctl Christoph Hellwig
2020-04-08 19:44 ` [PATCH 02/10] block: pass a hd_struct to delete_partition Christoph Hellwig
@ 2020-04-08 19:44 ` Christoph Hellwig
2020-04-09 11:30 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 04/10] block: remove hd_struct_kill Christoph Hellwig
` (6 subsequent siblings)
9 siblings, 1 reply; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-08 19:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
Move hd_ref_init out of line as there it isn't anywhere near a fast path,
and rename the rcu ref freeing callbacks to be more descriptive.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk.h | 10 +---------
block/partitions/core.c | 18 +++++++++++++-----
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/block/blk.h b/block/blk.h
index 0cbf64108922..b1a0b8cd87f0 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -389,7 +389,6 @@ char *disk_name(struct gendisk *hd, int partno, char *buf);
#define ADDPART_FLAG_NONE 0
#define ADDPART_FLAG_RAID 1
#define ADDPART_FLAG_WHOLEDISK 2
-void __delete_partition(struct percpu_ref *ref);
void delete_partition(struct gendisk *disk, struct hd_struct *part);
int bdev_add_partition(struct block_device *bdev, int partno,
sector_t start, sector_t length);
@@ -397,14 +396,7 @@ int bdev_del_partition(struct block_device *bdev, int partno);
int bdev_resize_partition(struct block_device *bdev, int partno,
sector_t start, sector_t length);
int disk_expand_part_tbl(struct gendisk *disk, int target);
-
-static inline int hd_ref_init(struct hd_struct *part)
-{
- if (percpu_ref_init(&part->ref, __delete_partition, 0,
- GFP_KERNEL))
- return -ENOMEM;
- return 0;
-}
+int hd_ref_init(struct hd_struct *part);
static inline void hd_struct_get(struct hd_struct *part)
{
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 0b1b67f50652..13d61ed76e0e 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -274,10 +274,10 @@ struct device_type part_type = {
.uevent = part_uevent,
};
-static void delete_partition_work_fn(struct work_struct *work)
+static void hd_struct_free_work(struct work_struct *work)
{
- struct hd_struct *part = container_of(to_rcu_work(work), struct hd_struct,
- rcu_work);
+ struct hd_struct *part =
+ container_of(to_rcu_work(work), struct hd_struct, rcu_work);
part->start_sect = 0;
part->nr_sects = 0;
@@ -285,13 +285,21 @@ static void delete_partition_work_fn(struct work_struct *work)
put_device(part_to_dev(part));
}
-void __delete_partition(struct percpu_ref *ref)
+static void hd_struct_free(struct percpu_ref *ref)
{
struct hd_struct *part = container_of(ref, struct hd_struct, ref);
- INIT_RCU_WORK(&part->rcu_work, delete_partition_work_fn);
+
+ INIT_RCU_WORK(&part->rcu_work, hd_struct_free_work);
queue_rcu_work(system_wq, &part->rcu_work);
}
+int hd_ref_init(struct hd_struct *part)
+{
+ if (percpu_ref_init(&part->ref, hd_struct_free, 0, GFP_KERNEL))
+ return -ENOMEM;
+ return 0;
+}
+
/*
* Must be called either with bd_mutex held, before a disk can be opened or
* after all disk users are gone.
--
2.25.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 04/10] block: remove hd_struct_kill
2020-04-08 19:44 Christoph Hellwig
` (2 preceding siblings ...)
2020-04-08 19:44 ` [PATCH 03/10] block: cleanup hd_struct freeing Christoph Hellwig
@ 2020-04-08 19:44 ` Christoph Hellwig
2020-04-09 11:31 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 05/10] block: remove the disk argument from blk_drop_partitions Christoph Hellwig
` (5 subsequent siblings)
9 siblings, 1 reply; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-08 19:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
The function has a single caller, so just open code it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk.h | 5 -----
block/partitions/core.c | 2 +-
2 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/block/blk.h b/block/blk.h
index b1a0b8cd87f0..204963bb03e8 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -413,11 +413,6 @@ static inline void hd_struct_put(struct hd_struct *part)
percpu_ref_put(&part->ref);
}
-static inline void hd_struct_kill(struct hd_struct *part)
-{
- percpu_ref_kill(&part->ref);
-}
-
static inline void hd_free_part(struct hd_struct *part)
{
free_part_stats(part);
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 13d61ed76e0e..f10968b601be 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -321,7 +321,7 @@ void delete_partition(struct gendisk *disk, struct hd_struct *part)
* "in-use" until we really free the gendisk.
*/
blk_invalidate_devt(part_devt(part));
- hd_struct_kill(part);
+ percpu_ref_kill(&part->ref);
}
static ssize_t whole_disk_show(struct device *dev,
--
2.25.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 05/10] block: remove the disk argument from blk_drop_partitions
2020-04-08 19:44 Christoph Hellwig
` (3 preceding siblings ...)
2020-04-08 19:44 ` [PATCH 04/10] block: remove hd_struct_kill Christoph Hellwig
@ 2020-04-08 19:44 ` Christoph Hellwig
2020-04-09 11:33 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 06/10] dasd: use blk_drop_partitions instead of badly reimplementing it Christoph Hellwig
` (4 subsequent siblings)
9 siblings, 1 reply; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-08 19:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
The gendisk can be trivially deducted from the block_device.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/partitions/core.c | 10 +++++-----
fs/block_dev.c | 2 +-
include/linux/genhd.h | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/block/partitions/core.c b/block/partitions/core.c
index f10968b601be..e0ff8a49279f 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -603,23 +603,23 @@ static bool disk_unlock_native_capacity(struct gendisk *disk)
}
}
-int blk_drop_partitions(struct gendisk *disk, struct block_device *bdev)
+int blk_drop_partitions(struct block_device *bdev)
{
struct disk_part_iter piter;
struct hd_struct *part;
int res;
- if (!disk_part_scan_enabled(disk))
+ if (!disk_part_scan_enabled(bdev->bd_disk))
return 0;
if (bdev->bd_part_count || bdev->bd_openers)
return -EBUSY;
- res = invalidate_partition(disk, 0);
+ res = invalidate_partition(bdev->bd_disk, 0);
if (res)
return res;
- disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
+ disk_part_iter_init(&piter, bdev->bd_disk, DISK_PITER_INCL_EMPTY);
while ((part = disk_part_iter_next(&piter)))
- delete_partition(disk, part);
+ delete_partition(bdev->bd_disk, part);
disk_part_iter_exit(&piter);
return 0;
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 52b6f646cdbd..9c8de54fa0c9 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1517,7 +1517,7 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate)
lockdep_assert_held(&bdev->bd_mutex);
rescan:
- ret = blk_drop_partitions(disk, bdev);
+ ret = blk_drop_partitions(bdev);
if (ret)
return ret;
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 9b3fffdf4011..058d895544c7 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -339,7 +339,7 @@ extern dev_t blk_lookup_devt(const char *name, int partno);
int bdev_disk_changed(struct block_device *bdev, bool invalidate);
int blk_add_partitions(struct gendisk *disk, struct block_device *bdev);
-int blk_drop_partitions(struct gendisk *disk, struct block_device *bdev);
+int blk_drop_partitions(struct block_device *bdev);
extern void printk_all_partitions(void);
extern struct gendisk *__alloc_disk_node(int minors, int node_id);
--
2.25.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 06/10] dasd: use blk_drop_partitions instead of badly reimplementing it
2020-04-08 19:44 Christoph Hellwig
` (4 preceding siblings ...)
2020-04-08 19:44 ` [PATCH 05/10] block: remove the disk argument from blk_drop_partitions Christoph Hellwig
@ 2020-04-08 19:44 ` Christoph Hellwig
2020-04-08 19:44 ` [PATCH 07/10] block: don't call invalidate_partition from blk_drop_partitions Christoph Hellwig
` (3 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-08 19:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
Use the blk_drop_partitions function instead of messing around with
ioctls that get kernel pointers. For this blk_drop_partitions needs
to be exported, which it normally shouldn't - make an exception for
s390 only.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/partitions/core.c | 4 ++++
drivers/s390/block/dasd_genhd.c | 20 ++++----------------
2 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/block/partitions/core.c b/block/partitions/core.c
index e0ff8a49279f..8a41c25022ab 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -624,6 +624,10 @@ int blk_drop_partitions(struct block_device *bdev)
return 0;
}
+#ifdef CONFIG_S390
+/* for historic reasons in the DASD driver */
+EXPORT_SYMBOL_GPL(blk_drop_partitions);
+#endif
static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,
struct parsed_partitions *state, int p)
diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c
index 7d079154f849..af5b0ecb8f89 100644
--- a/drivers/s390/block/dasd_genhd.c
+++ b/drivers/s390/block/dasd_genhd.c
@@ -143,9 +143,6 @@ int dasd_scan_partitions(struct dasd_block *block)
*/
void dasd_destroy_partitions(struct dasd_block *block)
{
- /* The two structs have 168/176 byte on 31/64 bit. */
- struct blkpg_partition bpart;
- struct blkpg_ioctl_arg barg;
struct block_device *bdev;
/*
@@ -155,19 +152,10 @@ void dasd_destroy_partitions(struct dasd_block *block)
bdev = block->bdev;
block->bdev = NULL;
- /*
- * See fs/partition/check.c:delete_partition
- * Can't call delete_partitions directly. Use ioctl.
- * The ioctl also does locking and invalidation.
- */
- memset(&bpart, 0, sizeof(struct blkpg_partition));
- memset(&barg, 0, sizeof(struct blkpg_ioctl_arg));
- barg.data = (void __force __user *) &bpart;
- barg.op = BLKPG_DEL_PARTITION;
- for (bpart.pno = block->gdp->minors - 1; bpart.pno > 0; bpart.pno--)
- ioctl_by_bdev(bdev, BLKPG, (unsigned long) &barg);
-
- invalidate_partition(block->gdp, 0);
+ mutex_lock(&bdev->bd_mutex);
+ blk_drop_partitions(bdev);
+ mutex_unlock(&bdev->bd_mutex);
+
/* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
blkdev_put(bdev, FMODE_READ);
set_capacity(block->gdp, 0);
--
2.25.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 07/10] block: don't call invalidate_partition from blk_drop_partitions
2020-04-08 19:44 Christoph Hellwig
` (5 preceding siblings ...)
2020-04-08 19:44 ` [PATCH 06/10] dasd: use blk_drop_partitions instead of badly reimplementing it Christoph Hellwig
@ 2020-04-08 19:44 ` Christoph Hellwig
2020-04-08 19:44 ` [PATCH 08/10] block: simplify block device syncing in bdev_del_partition Christoph Hellwig
` (2 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-08 19:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
Given that the device must not be busy, most of the calls from
invalidate_partition that are related to file system metadata are
guranteed to not happen. Just open code the calls to sync_blockdev
and invalidate_bdev instead.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/partitions/core.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 8a41c25022ab..3fe383adb42a 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -607,15 +607,14 @@ int blk_drop_partitions(struct block_device *bdev)
{
struct disk_part_iter piter;
struct hd_struct *part;
- int res;
if (!disk_part_scan_enabled(bdev->bd_disk))
return 0;
if (bdev->bd_part_count || bdev->bd_openers)
return -EBUSY;
- res = invalidate_partition(bdev->bd_disk, 0);
- if (res)
- return res;
+
+ sync_blockdev(bdev);
+ invalidate_bdev(bdev);
disk_part_iter_init(&piter, bdev->bd_disk, DISK_PITER_INCL_EMPTY);
while ((part = disk_part_iter_next(&piter)))
--
2.25.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 08/10] block: simplify block device syncing in bdev_del_partition
2020-04-08 19:44 Christoph Hellwig
` (6 preceding siblings ...)
2020-04-08 19:44 ` [PATCH 07/10] block: don't call invalidate_partition from blk_drop_partitions Christoph Hellwig
@ 2020-04-08 19:44 ` Christoph Hellwig
2020-04-09 12:01 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 09/10] block: mark invalidate_partition static Christoph Hellwig
2020-04-08 19:44 ` [PATCH 10/10] block: fold bdev_unhash_inode into invalidate_partition Christoph Hellwig
9 siblings, 1 reply; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-08 19:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
We just checked a little above that the block device for the partition
im busy. That implies no file system is mounted, and thus the only
thing in fsync_bdev that actually is used is sync_blockdev. Just call
sync_blockdev directly.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/partitions/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 3fe383adb42a..9c402edee4a4 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -531,7 +531,7 @@ int bdev_del_partition(struct block_device *bdev, int partno)
if (bdevp->bd_openers)
goto out_unlock;
- fsync_bdev(bdevp);
+ sync_blockdev(bdevp);
invalidate_bdev(bdevp);
mutex_lock_nested(&bdev->bd_mutex, 1);
--
2.25.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 09/10] block: mark invalidate_partition static
2020-04-08 19:44 Christoph Hellwig
` (7 preceding siblings ...)
2020-04-08 19:44 ` [PATCH 08/10] block: simplify block device syncing in bdev_del_partition Christoph Hellwig
@ 2020-04-08 19:44 ` Christoph Hellwig
2020-04-09 12:04 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 10/10] block: fold bdev_unhash_inode into invalidate_partition Christoph Hellwig
9 siblings, 1 reply; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-08 19:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
invalidate_partition is only used in genhd.c, so mark it static. Also
drop the return value given that is is always ignored.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 27 +++++++++++++--------------
include/linux/fs.h | 1 -
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index 1cc50ad5b191..980a4609d4a5 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -878,6 +878,19 @@ void device_add_disk_no_queue_reg(struct device *parent, struct gendisk *disk)
}
EXPORT_SYMBOL(device_add_disk_no_queue_reg);
+static void invalidate_partition(struct gendisk *disk, int partno)
+{
+ struct block_device *bdev;
+
+ bdev = bdget_disk(disk, partno);
+ if (!bdev)
+ return;
+
+ fsync_bdev(bdev);
+ __invalidate_device(bdev, true);
+ bdput(bdev);
+}
+
void del_gendisk(struct gendisk *disk)
{
struct disk_part_iter piter;
@@ -1806,20 +1819,6 @@ int bdev_read_only(struct block_device *bdev)
EXPORT_SYMBOL(bdev_read_only);
-int invalidate_partition(struct gendisk *disk, int partno)
-{
- int res = 0;
- struct block_device *bdev = bdget_disk(disk, partno);
- if (bdev) {
- fsync_bdev(bdev);
- res = __invalidate_device(bdev, true);
- bdput(bdev);
- }
- return res;
-}
-
-EXPORT_SYMBOL(invalidate_partition);
-
/*
* Disk events - monitor disk events like media change and eject request.
*/
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 4f6f59b4f22a..2b4e9f86b151 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2723,7 +2723,6 @@ extern bool is_bad_inode(struct inode *);
extern int revalidate_disk(struct gendisk *);
extern int check_disk_change(struct block_device *);
extern int __invalidate_device(struct block_device *, bool);
-extern int invalidate_partition(struct gendisk *, int);
#endif
unsigned long invalidate_mapping_pages(struct address_space *mapping,
pgoff_t start, pgoff_t end);
--
2.25.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 10/10] block: fold bdev_unhash_inode into invalidate_partition
2020-04-08 19:44 Christoph Hellwig
` (8 preceding siblings ...)
2020-04-08 19:44 ` [PATCH 09/10] block: mark invalidate_partition static Christoph Hellwig
@ 2020-04-08 19:44 ` Christoph Hellwig
2020-04-09 12:06 ` Johannes Thumshirn
9 siblings, 1 reply; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-08 19:44 UTC (permalink / raw)
To: Jens Axboe; +Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
invalidate_partition and bdev_unhash_inode are always paired, and
invalidate_partition already does an icache lookup for the block device
inode. Piggy back on that to remove the inode from the hash.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 8 ++++++--
fs/block_dev.c | 15 ---------------
include/linux/fs.h | 1 -
3 files changed, 6 insertions(+), 18 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index 980a4609d4a5..c05d509877fa 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -888,6 +888,12 @@ static void invalidate_partition(struct gendisk *disk, int partno)
fsync_bdev(bdev);
__invalidate_device(bdev, true);
+
+ /*
+ * Unhash the bdev inode for this device so that it gets evicted as soon
+ * as last inode reference is dropped.
+ */
+ remove_inode_hash(bdev->bd_inode);
bdput(bdev);
}
@@ -909,13 +915,11 @@ void del_gendisk(struct gendisk *disk)
DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);
while ((part = disk_part_iter_next(&piter))) {
invalidate_partition(disk, part->partno);
- bdev_unhash_inode(part_devt(part));
delete_partition(disk, part);
}
disk_part_iter_exit(&piter);
invalidate_partition(disk, 0);
- bdev_unhash_inode(disk_devt(disk));
set_capacity(disk, 0);
disk->flags &= ~GENHD_FL_UP;
up_write(&disk->lookup_sem);
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 9c8de54fa0c9..998820174d3e 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -883,21 +883,6 @@ static int bdev_set(struct inode *inode, void *data)
static LIST_HEAD(all_bdevs);
-/*
- * If there is a bdev inode for this device, unhash it so that it gets evicted
- * as soon as last inode reference is dropped.
- */
-void bdev_unhash_inode(dev_t dev)
-{
- struct inode *inode;
-
- inode = ilookup5(blockdev_superblock, hash(dev), bdev_test, &dev);
- if (inode) {
- remove_inode_hash(inode);
- iput(inode);
- }
-}
-
struct block_device *bdget(dev_t dev)
{
struct block_device *bdev;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 2b4e9f86b151..1a95e5158811 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2581,7 +2581,6 @@ extern struct kmem_cache *names_cachep;
#ifdef CONFIG_BLOCK
extern int register_blkdev(unsigned int, const char *);
extern void unregister_blkdev(unsigned int, const char *);
-extern void bdev_unhash_inode(dev_t dev);
extern struct block_device *bdget(dev_t);
extern struct block_device *bdgrab(struct block_device *bdev);
extern void bd_set_size(struct block_device *, loff_t size);
--
2.25.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH 01/10] block: refactor blkpg_ioctl
2020-04-08 19:44 ` [PATCH 01/10] block: refactor blkpg_ioctl Christoph Hellwig
@ 2020-04-09 11:21 ` Johannes Thumshirn
0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2020-04-09 11:21 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
On 08/04/2020 21:45, Christoph Hellwig wrote:
> + case BLKPG_DEL_PARTITION:
> + return bdev_resize_partition(bdev, p.pno, start, length);
This needs to be BLKPG_RESIZE_PARTITION.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 02/10] block: pass a hd_struct to delete_partition
2020-04-08 19:44 ` [PATCH 02/10] block: pass a hd_struct to delete_partition Christoph Hellwig
@ 2020-04-09 11:27 ` Johannes Thumshirn
2020-04-09 12:02 ` Johannes Thumshirn
1 sibling, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2020-04-09 11:27 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 03/10] block: cleanup hd_struct freeing
2020-04-08 19:44 ` [PATCH 03/10] block: cleanup hd_struct freeing Christoph Hellwig
@ 2020-04-09 11:30 ` Johannes Thumshirn
2020-04-13 13:41 ` Christoph Hellwig
0 siblings, 1 reply; 22+ messages in thread
From: Johannes Thumshirn @ 2020-04-09 11:30 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
On 08/04/2020 21:45, Christoph Hellwig wrote:
> - struct hd_struct *part = container_of(to_rcu_work(work), struct hd_struct,
> - rcu_work);
> + struct hd_struct *part =
> + container_of(to_rcu_work(work), struct hd_struct, rcu_work);
That looks like an unneeded white space only change
Otherwise,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 04/10] block: remove hd_struct_kill
2020-04-08 19:44 ` [PATCH 04/10] block: remove hd_struct_kill Christoph Hellwig
@ 2020-04-09 11:31 ` Johannes Thumshirn
0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2020-04-09 11:31 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
Easy enough,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 05/10] block: remove the disk argument from blk_drop_partitions
2020-04-08 19:44 ` [PATCH 05/10] block: remove the disk argument from blk_drop_partitions Christoph Hellwig
@ 2020-04-09 11:33 ` Johannes Thumshirn
0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2020-04-09 11:33 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
On 08/04/2020 21:45, Christoph Hellwig wrote:
> -int blk_drop_partitions(struct gendisk *disk, struct block_device *bdev)
> +int blk_drop_partitions(struct block_device *bdev)
> {
> struct disk_part_iter piter;
> struct hd_struct *part;
> int res;
>
> - if (!disk_part_scan_enabled(disk))
> + if (!disk_part_scan_enabled(bdev->bd_disk))
> return 0;
> if (bdev->bd_part_count || bdev->bd_openers)
> return -EBUSY;
> - res = invalidate_partition(disk, 0);
> + res = invalidate_partition(bdev->bd_disk, 0);
> if (res)
> return res;
>
> - disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
> + disk_part_iter_init(&piter, bdev->bd_disk, DISK_PITER_INCL_EMPTY);
> while ((part = disk_part_iter_next(&piter)))
> - delete_partition(disk, part);
> + delete_partition(bdev->bd_disk, part);
> disk_part_iter_exit(&piter);
I would have probably added a local 'struct gendisk *disk' variable, but
that's personal preference I guess.
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 08/10] block: simplify block device syncing in bdev_del_partition
2020-04-08 19:44 ` [PATCH 08/10] block: simplify block device syncing in bdev_del_partition Christoph Hellwig
@ 2020-04-09 12:01 ` Johannes Thumshirn
0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2020-04-09 12:01 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 02/10] block: pass a hd_struct to delete_partition
2020-04-08 19:44 ` [PATCH 02/10] block: pass a hd_struct to delete_partition Christoph Hellwig
2020-04-09 11:27 ` Johannes Thumshirn
@ 2020-04-09 12:02 ` Johannes Thumshirn
1 sibling, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2020-04-09 12:02 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
On 08/04/2020 21:45, Christoph Hellwig wrote:
> All callers have the hd_strut at hand, so pass it instead of doing
Nit: hd_struct
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 09/10] block: mark invalidate_partition static
2020-04-08 19:44 ` [PATCH 09/10] block: mark invalidate_partition static Christoph Hellwig
@ 2020-04-09 12:04 ` Johannes Thumshirn
0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2020-04-09 12:04 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 10/10] block: fold bdev_unhash_inode into invalidate_partition
2020-04-08 19:44 ` [PATCH 10/10] block: fold bdev_unhash_inode into invalidate_partition Christoph Hellwig
@ 2020-04-09 12:06 ` Johannes Thumshirn
0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2020-04-09 12:06 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe
Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 03/10] block: cleanup hd_struct freeing
2020-04-09 11:30 ` Johannes Thumshirn
@ 2020-04-13 13:41 ` Christoph Hellwig
0 siblings, 0 replies; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-13 13:41 UTC (permalink / raw)
To: Johannes Thumshirn
Cc: Christoph Hellwig, Jens Axboe, Stefan Haberland, Jan Hoeppner,
linux-block, linux-s390
On Thu, Apr 09, 2020 at 11:30:19AM +0000, Johannes Thumshirn wrote:
> On 08/04/2020 21:45, Christoph Hellwig wrote:
> > - struct hd_struct *part = container_of(to_rcu_work(work), struct hd_struct,
> > - rcu_work);
> > + struct hd_struct *part =
> > + container_of(to_rcu_work(work), struct hd_struct, rcu_work);
>
> That looks like an unneeded white space only change
It was intentional as I was touching the code right next to it anyway..
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 02/10] block: pass a hd_struct to delete_partition
2020-04-14 7:28 more partition handling cleanups v2 Christoph Hellwig
@ 2020-04-14 7:28 ` Christoph Hellwig
0 siblings, 0 replies; 22+ messages in thread
From: Christoph Hellwig @ 2020-04-14 7:28 UTC (permalink / raw)
To: Jens Axboe
Cc: Stefan Haberland, Jan Hoeppner, linux-block, linux-s390,
Johannes Thumshirn
All callers have the hd_struct at hand, so pass it instead of performing
another lookup.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
block/blk.h | 2 +-
block/genhd.c | 2 +-
block/partitions/core.c | 22 ++++++++--------------
3 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/block/blk.h b/block/blk.h
index 305e0ac22bf7..0cbf64108922 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -390,7 +390,7 @@ char *disk_name(struct gendisk *hd, int partno, char *buf);
#define ADDPART_FLAG_RAID 1
#define ADDPART_FLAG_WHOLEDISK 2
void __delete_partition(struct percpu_ref *ref);
-void delete_partition(struct gendisk *disk, int partno);
+void delete_partition(struct gendisk *disk, struct hd_struct *part);
int bdev_add_partition(struct block_device *bdev, int partno,
sector_t start, sector_t length);
int bdev_del_partition(struct block_device *bdev, int partno);
diff --git a/block/genhd.c b/block/genhd.c
index 06b642b23a07..1cc50ad5b191 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -897,7 +897,7 @@ void del_gendisk(struct gendisk *disk)
while ((part = disk_part_iter_next(&piter))) {
invalidate_partition(disk, part->partno);
bdev_unhash_inode(part_devt(part));
- delete_partition(disk, part->partno);
+ delete_partition(disk, part);
}
disk_part_iter_exit(&piter);
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 7e2f40875166..6dc534b502a9 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -296,20 +296,12 @@ void __delete_partition(struct percpu_ref *ref)
* Must be called either with bd_mutex held, before a disk can be opened or
* after all disk users are gone.
*/
-void delete_partition(struct gendisk *disk, int partno)
+void delete_partition(struct gendisk *disk, struct hd_struct *part)
{
struct disk_part_tbl *ptbl =
rcu_dereference_protected(disk->part_tbl, 1);
- struct hd_struct *part;
-
- if (partno >= ptbl->len)
- return;
- part = rcu_dereference_protected(ptbl->part[partno], 1);
- if (!part)
- return;
-
- rcu_assign_pointer(ptbl->part[partno], NULL);
+ rcu_assign_pointer(ptbl->part[part->partno], NULL);
rcu_assign_pointer(ptbl->last_lookup, NULL);
kobject_put(part->holder_dir);
device_del(part_to_dev(part));
@@ -520,10 +512,10 @@ int bdev_del_partition(struct block_device *bdev, int partno)
if (!part)
return -ENXIO;
+ ret = -ENOMEM;
bdevp = bdget(part_devt(part));
- disk_put_part(part);
if (!bdevp)
- return -ENOMEM;
+ goto out_put_part;
mutex_lock(&bdevp->bd_mutex);
@@ -535,13 +527,15 @@ int bdev_del_partition(struct block_device *bdev, int partno)
invalidate_bdev(bdevp);
mutex_lock_nested(&bdev->bd_mutex, 1);
- delete_partition(bdev->bd_disk, partno);
+ delete_partition(bdev->bd_disk, part);
mutex_unlock(&bdev->bd_mutex);
ret = 0;
out_unlock:
mutex_unlock(&bdevp->bd_mutex);
bdput(bdevp);
+out_put_part:
+ disk_put_part(part);
return ret;
}
@@ -617,7 +611,7 @@ int blk_drop_partitions(struct gendisk *disk, struct block_device *bdev)
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
while ((part = disk_part_iter_next(&piter)))
- delete_partition(disk, part->partno);
+ delete_partition(disk, part);
disk_part_iter_exit(&piter);
return 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
end of thread, other threads:[~2020-04-14 7:29 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-08 19:44 Christoph Hellwig
2020-04-08 19:44 ` [PATCH 01/10] block: refactor blkpg_ioctl Christoph Hellwig
2020-04-09 11:21 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 02/10] block: pass a hd_struct to delete_partition Christoph Hellwig
2020-04-09 11:27 ` Johannes Thumshirn
2020-04-09 12:02 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 03/10] block: cleanup hd_struct freeing Christoph Hellwig
2020-04-09 11:30 ` Johannes Thumshirn
2020-04-13 13:41 ` Christoph Hellwig
2020-04-08 19:44 ` [PATCH 04/10] block: remove hd_struct_kill Christoph Hellwig
2020-04-09 11:31 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 05/10] block: remove the disk argument from blk_drop_partitions Christoph Hellwig
2020-04-09 11:33 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 06/10] dasd: use blk_drop_partitions instead of badly reimplementing it Christoph Hellwig
2020-04-08 19:44 ` [PATCH 07/10] block: don't call invalidate_partition from blk_drop_partitions Christoph Hellwig
2020-04-08 19:44 ` [PATCH 08/10] block: simplify block device syncing in bdev_del_partition Christoph Hellwig
2020-04-09 12:01 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 09/10] block: mark invalidate_partition static Christoph Hellwig
2020-04-09 12:04 ` Johannes Thumshirn
2020-04-08 19:44 ` [PATCH 10/10] block: fold bdev_unhash_inode into invalidate_partition Christoph Hellwig
2020-04-09 12:06 ` Johannes Thumshirn
2020-04-14 7:28 more partition handling cleanups v2 Christoph Hellwig
2020-04-14 7:28 ` [PATCH 02/10] block: pass a hd_struct to delete_partition Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).