Skip to content

Commit 0384264

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: pass a gendisk to bdev_disk_changed
bdev_disk_changed can only operate on whole devices. Make that clear by passing a gendisk instead of the struct block_device. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 630161c commit 0384264

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

block/partitions/core.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ static void free_partitions(struct parsed_partitions *state)
120120
kfree(state);
121121
}
122122

123-
static struct parsed_partitions *check_partition(struct gendisk *hd,
124-
struct block_device *bdev)
123+
static struct parsed_partitions *check_partition(struct gendisk *hd)
125124
{
126125
struct parsed_partitions *state;
127126
int i, res, err;
@@ -136,7 +135,7 @@ static struct parsed_partitions *check_partition(struct gendisk *hd,
136135
}
137136
state->pp_buf[0] = '\0';
138137

139-
state->bdev = bdev;
138+
state->bdev = hd->part0;
140139
disk_name(hd, 0, state->name);
141140
snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name);
142141
if (isdigit(state->name[strlen(state->name)-1]))
@@ -546,7 +545,7 @@ void blk_drop_partitions(struct gendisk *disk)
546545
}
547546
}
548547

549-
static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,
548+
static bool blk_add_partition(struct gendisk *disk,
550549
struct parsed_partitions *state, int p)
551550
{
552551
sector_t size = state->parts[p].size;
@@ -596,15 +595,15 @@ static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,
596595
return true;
597596
}
598597

599-
static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
598+
static int blk_add_partitions(struct gendisk *disk)
600599
{
601600
struct parsed_partitions *state;
602601
int ret = -EAGAIN, p;
603602

604603
if (!disk_part_scan_enabled(disk))
605604
return 0;
606605

607-
state = check_partition(disk, bdev);
606+
state = check_partition(disk);
608607
if (!state)
609608
return 0;
610609
if (IS_ERR(state)) {
@@ -648,7 +647,7 @@ static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
648647
kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
649648

650649
for (p = 1; p < state->limit; p++)
651-
if (!blk_add_partition(disk, bdev, state, p))
650+
if (!blk_add_partition(disk, state, p))
652651
goto out_free_state;
653652

654653
ret = 0;
@@ -657,9 +656,8 @@ static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
657656
return ret;
658657
}
659658

660-
int bdev_disk_changed(struct block_device *bdev, bool invalidate)
659+
int bdev_disk_changed(struct gendisk *disk, bool invalidate)
661660
{
662-
struct gendisk *disk = bdev->bd_disk;
663661
int ret = 0;
664662

665663
lockdep_assert_held(&disk->open_mutex);
@@ -670,8 +668,8 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate)
670668
rescan:
671669
if (disk->open_partitions)
672670
return -EBUSY;
673-
sync_blockdev(bdev);
674-
invalidate_bdev(bdev);
671+
sync_blockdev(disk->part0);
672+
invalidate_bdev(disk->part0);
675673
blk_drop_partitions(disk);
676674

677675
clear_bit(GD_NEED_PART_SCAN, &disk->state);
@@ -691,7 +689,7 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate)
691689
}
692690

693691
if (get_capacity(disk)) {
694-
ret = blk_add_partitions(disk, bdev);
692+
ret = blk_add_partitions(disk);
695693
if (ret == -EAGAIN)
696694
goto rescan;
697695
} else if (invalidate) {

drivers/block/loop.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -647,14 +647,13 @@ static inline void loop_update_dio(struct loop_device *lo)
647647
lo->use_dio);
648648
}
649649

650-
static void loop_reread_partitions(struct loop_device *lo,
651-
struct block_device *bdev)
650+
static void loop_reread_partitions(struct loop_device *lo)
652651
{
653652
int rc;
654653

655-
mutex_lock(&bdev->bd_disk->open_mutex);
656-
rc = bdev_disk_changed(bdev, false);
657-
mutex_unlock(&bdev->bd_disk->open_mutex);
654+
mutex_lock(&lo->lo_disk->open_mutex);
655+
rc = bdev_disk_changed(lo->lo_disk, false);
656+
mutex_unlock(&lo->lo_disk->open_mutex);
658657
if (rc)
659658
pr_warn("%s: partition scan of loop%d (%s) failed (rc=%d)\n",
660659
__func__, lo->lo_number, lo->lo_file_name, rc);
@@ -752,7 +751,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
752751
*/
753752
fput(old_file);
754753
if (partscan)
755-
loop_reread_partitions(lo, bdev);
754+
loop_reread_partitions(lo);
756755
return 0;
757756

758757
out_err:
@@ -1174,7 +1173,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
11741173
bdgrab(bdev);
11751174
mutex_unlock(&lo->lo_mutex);
11761175
if (partscan)
1177-
loop_reread_partitions(lo, bdev);
1176+
loop_reread_partitions(lo);
11781177
if (!(mode & FMODE_EXCL))
11791178
bd_abort_claiming(bdev, loop_configure);
11801179
return 0;
@@ -1268,10 +1267,10 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
12681267
* current holder is released.
12691268
*/
12701269
if (!release)
1271-
mutex_lock(&bdev->bd_disk->open_mutex);
1272-
err = bdev_disk_changed(bdev, false);
1270+
mutex_lock(&lo->lo_disk->open_mutex);
1271+
err = bdev_disk_changed(lo->lo_disk, false);
12731272
if (!release)
1274-
mutex_unlock(&bdev->bd_disk->open_mutex);
1273+
mutex_unlock(&lo->lo_disk->open_mutex);
12751274
if (err)
12761275
pr_warn("%s: partition scan of loop%d failed (rc=%d)\n",
12771276
__func__, lo_number, err);
@@ -1416,7 +1415,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
14161415
out_unlock:
14171416
mutex_unlock(&lo->lo_mutex);
14181417
if (partscan)
1419-
loop_reread_partitions(lo, bdev);
1418+
loop_reread_partitions(lo);
14201419

14211420
return err;
14221421
}

drivers/s390/block/dasd_genhd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int dasd_scan_partitions(struct dasd_block *block)
110110
}
111111

112112
mutex_lock(&block->gdp->open_mutex);
113-
rc = bdev_disk_changed(bdev, false);
113+
rc = bdev_disk_changed(block->gdp, false);
114114
mutex_unlock(&block->gdp->open_mutex);
115115
if (rc)
116116
DBF_DEV_EVENT(DBF_ERR, block->base,
@@ -146,7 +146,7 @@ void dasd_destroy_partitions(struct dasd_block *block)
146146
block->bdev = NULL;
147147

148148
mutex_lock(&bdev->bd_disk->open_mutex);
149-
bdev_disk_changed(bdev, true);
149+
bdev_disk_changed(bdev->bd_disk, true);
150150
mutex_unlock(&bdev->bd_disk->open_mutex);
151151

152152
/* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */

fs/block_dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ static int blkdev_get_whole(struct block_device *bdev, fmode_t mode)
12531253
/* avoid ghost partitions on a removed medium */
12541254
if (ret == -ENOMEDIUM &&
12551255
test_bit(GD_NEED_PART_SCAN, &disk->state))
1256-
bdev_disk_changed(bdev, true);
1256+
bdev_disk_changed(disk, true);
12571257
return ret;
12581258
}
12591259
}
@@ -1264,7 +1264,7 @@ static int blkdev_get_whole(struct block_device *bdev, fmode_t mode)
12641264
bdev->bd_bdi = bdi_get(disk->queue->backing_dev_info);
12651265
}
12661266
if (test_bit(GD_NEED_PART_SCAN, &disk->state))
1267-
bdev_disk_changed(bdev, false);
1267+
bdev_disk_changed(disk, false);
12681268
bdev->bd_openers++;
12691269
return 0;;
12701270
}

include/linux/genhd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static inline sector_t get_capacity(struct gendisk *disk)
256256
return bdev_nr_sectors(disk->part0);
257257
}
258258

259-
int bdev_disk_changed(struct block_device *bdev, bool invalidate);
259+
int bdev_disk_changed(struct gendisk *disk, bool invalidate);
260260
void blk_drop_partitions(struct gendisk *disk);
261261

262262
extern struct gendisk *__alloc_disk_node(int minors, int node_id);

0 commit comments

Comments
 (0)