Commit 0384264e authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

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: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210624123240.441814-3-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 630161cf
...@@ -120,8 +120,7 @@ static void free_partitions(struct parsed_partitions *state) ...@@ -120,8 +120,7 @@ static void free_partitions(struct parsed_partitions *state)
kfree(state); kfree(state);
} }
static struct parsed_partitions *check_partition(struct gendisk *hd, static struct parsed_partitions *check_partition(struct gendisk *hd)
struct block_device *bdev)
{ {
struct parsed_partitions *state; struct parsed_partitions *state;
int i, res, err; int i, res, err;
...@@ -136,7 +135,7 @@ static struct parsed_partitions *check_partition(struct gendisk *hd, ...@@ -136,7 +135,7 @@ static struct parsed_partitions *check_partition(struct gendisk *hd,
} }
state->pp_buf[0] = '\0'; state->pp_buf[0] = '\0';
state->bdev = bdev; state->bdev = hd->part0;
disk_name(hd, 0, state->name); disk_name(hd, 0, state->name);
snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name); snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name);
if (isdigit(state->name[strlen(state->name)-1])) if (isdigit(state->name[strlen(state->name)-1]))
...@@ -546,7 +545,7 @@ void blk_drop_partitions(struct gendisk *disk) ...@@ -546,7 +545,7 @@ void blk_drop_partitions(struct gendisk *disk)
} }
} }
static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev, static bool blk_add_partition(struct gendisk *disk,
struct parsed_partitions *state, int p) struct parsed_partitions *state, int p)
{ {
sector_t size = state->parts[p].size; sector_t size = state->parts[p].size;
...@@ -596,7 +595,7 @@ static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev, ...@@ -596,7 +595,7 @@ static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,
return true; return true;
} }
static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev) static int blk_add_partitions(struct gendisk *disk)
{ {
struct parsed_partitions *state; struct parsed_partitions *state;
int ret = -EAGAIN, p; int ret = -EAGAIN, p;
...@@ -604,7 +603,7 @@ static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev) ...@@ -604,7 +603,7 @@ static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
if (!disk_part_scan_enabled(disk)) if (!disk_part_scan_enabled(disk))
return 0; return 0;
state = check_partition(disk, bdev); state = check_partition(disk);
if (!state) if (!state)
return 0; return 0;
if (IS_ERR(state)) { if (IS_ERR(state)) {
...@@ -648,7 +647,7 @@ static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev) ...@@ -648,7 +647,7 @@ static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE); kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
for (p = 1; p < state->limit; p++) for (p = 1; p < state->limit; p++)
if (!blk_add_partition(disk, bdev, state, p)) if (!blk_add_partition(disk, state, p))
goto out_free_state; goto out_free_state;
ret = 0; ret = 0;
...@@ -657,9 +656,8 @@ static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev) ...@@ -657,9 +656,8 @@ static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
return ret; return ret;
} }
int bdev_disk_changed(struct block_device *bdev, bool invalidate) int bdev_disk_changed(struct gendisk *disk, bool invalidate)
{ {
struct gendisk *disk = bdev->bd_disk;
int ret = 0; int ret = 0;
lockdep_assert_held(&disk->open_mutex); lockdep_assert_held(&disk->open_mutex);
...@@ -670,8 +668,8 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate) ...@@ -670,8 +668,8 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate)
rescan: rescan:
if (disk->open_partitions) if (disk->open_partitions)
return -EBUSY; return -EBUSY;
sync_blockdev(bdev); sync_blockdev(disk->part0);
invalidate_bdev(bdev); invalidate_bdev(disk->part0);
blk_drop_partitions(disk); blk_drop_partitions(disk);
clear_bit(GD_NEED_PART_SCAN, &disk->state); clear_bit(GD_NEED_PART_SCAN, &disk->state);
...@@ -691,7 +689,7 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate) ...@@ -691,7 +689,7 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate)
} }
if (get_capacity(disk)) { if (get_capacity(disk)) {
ret = blk_add_partitions(disk, bdev); ret = blk_add_partitions(disk);
if (ret == -EAGAIN) if (ret == -EAGAIN)
goto rescan; goto rescan;
} else if (invalidate) { } else if (invalidate) {
......
...@@ -647,14 +647,13 @@ static inline void loop_update_dio(struct loop_device *lo) ...@@ -647,14 +647,13 @@ static inline void loop_update_dio(struct loop_device *lo)
lo->use_dio); lo->use_dio);
} }
static void loop_reread_partitions(struct loop_device *lo, static void loop_reread_partitions(struct loop_device *lo)
struct block_device *bdev)
{ {
int rc; int rc;
mutex_lock(&bdev->bd_disk->open_mutex); mutex_lock(&lo->lo_disk->open_mutex);
rc = bdev_disk_changed(bdev, false); rc = bdev_disk_changed(lo->lo_disk, false);
mutex_unlock(&bdev->bd_disk->open_mutex); mutex_unlock(&lo->lo_disk->open_mutex);
if (rc) if (rc)
pr_warn("%s: partition scan of loop%d (%s) failed (rc=%d)\n", pr_warn("%s: partition scan of loop%d (%s) failed (rc=%d)\n",
__func__, lo->lo_number, lo->lo_file_name, rc); __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, ...@@ -752,7 +751,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
*/ */
fput(old_file); fput(old_file);
if (partscan) if (partscan)
loop_reread_partitions(lo, bdev); loop_reread_partitions(lo);
return 0; return 0;
out_err: out_err:
...@@ -1174,7 +1173,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, ...@@ -1174,7 +1173,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
bdgrab(bdev); bdgrab(bdev);
mutex_unlock(&lo->lo_mutex); mutex_unlock(&lo->lo_mutex);
if (partscan) if (partscan)
loop_reread_partitions(lo, bdev); loop_reread_partitions(lo);
if (!(mode & FMODE_EXCL)) if (!(mode & FMODE_EXCL))
bd_abort_claiming(bdev, loop_configure); bd_abort_claiming(bdev, loop_configure);
return 0; return 0;
...@@ -1268,10 +1267,10 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) ...@@ -1268,10 +1267,10 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
* current holder is released. * current holder is released.
*/ */
if (!release) if (!release)
mutex_lock(&bdev->bd_disk->open_mutex); mutex_lock(&lo->lo_disk->open_mutex);
err = bdev_disk_changed(bdev, false); err = bdev_disk_changed(lo->lo_disk, false);
if (!release) if (!release)
mutex_unlock(&bdev->bd_disk->open_mutex); mutex_unlock(&lo->lo_disk->open_mutex);
if (err) if (err)
pr_warn("%s: partition scan of loop%d failed (rc=%d)\n", pr_warn("%s: partition scan of loop%d failed (rc=%d)\n",
__func__, lo_number, err); __func__, lo_number, err);
...@@ -1416,7 +1415,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) ...@@ -1416,7 +1415,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
out_unlock: out_unlock:
mutex_unlock(&lo->lo_mutex); mutex_unlock(&lo->lo_mutex);
if (partscan) if (partscan)
loop_reread_partitions(lo, bdev); loop_reread_partitions(lo);
return err; return err;
} }
......
...@@ -110,7 +110,7 @@ int dasd_scan_partitions(struct dasd_block *block) ...@@ -110,7 +110,7 @@ int dasd_scan_partitions(struct dasd_block *block)
} }
mutex_lock(&block->gdp->open_mutex); mutex_lock(&block->gdp->open_mutex);
rc = bdev_disk_changed(bdev, false); rc = bdev_disk_changed(block->gdp, false);
mutex_unlock(&block->gdp->open_mutex); mutex_unlock(&block->gdp->open_mutex);
if (rc) if (rc)
DBF_DEV_EVENT(DBF_ERR, block->base, DBF_DEV_EVENT(DBF_ERR, block->base,
...@@ -146,7 +146,7 @@ void dasd_destroy_partitions(struct dasd_block *block) ...@@ -146,7 +146,7 @@ void dasd_destroy_partitions(struct dasd_block *block)
block->bdev = NULL; block->bdev = NULL;
mutex_lock(&bdev->bd_disk->open_mutex); mutex_lock(&bdev->bd_disk->open_mutex);
bdev_disk_changed(bdev, true); bdev_disk_changed(bdev->bd_disk, true);
mutex_unlock(&bdev->bd_disk->open_mutex); mutex_unlock(&bdev->bd_disk->open_mutex);
/* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */ /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
......
...@@ -1253,7 +1253,7 @@ static int blkdev_get_whole(struct block_device *bdev, fmode_t mode) ...@@ -1253,7 +1253,7 @@ static int blkdev_get_whole(struct block_device *bdev, fmode_t mode)
/* avoid ghost partitions on a removed medium */ /* avoid ghost partitions on a removed medium */
if (ret == -ENOMEDIUM && if (ret == -ENOMEDIUM &&
test_bit(GD_NEED_PART_SCAN, &disk->state)) test_bit(GD_NEED_PART_SCAN, &disk->state))
bdev_disk_changed(bdev, true); bdev_disk_changed(disk, true);
return ret; return ret;
} }
} }
...@@ -1264,7 +1264,7 @@ static int blkdev_get_whole(struct block_device *bdev, fmode_t mode) ...@@ -1264,7 +1264,7 @@ static int blkdev_get_whole(struct block_device *bdev, fmode_t mode)
bdev->bd_bdi = bdi_get(disk->queue->backing_dev_info); bdev->bd_bdi = bdi_get(disk->queue->backing_dev_info);
} }
if (test_bit(GD_NEED_PART_SCAN, &disk->state)) if (test_bit(GD_NEED_PART_SCAN, &disk->state))
bdev_disk_changed(bdev, false); bdev_disk_changed(disk, false);
bdev->bd_openers++; bdev->bd_openers++;
return 0;; return 0;;
} }
......
...@@ -256,7 +256,7 @@ static inline sector_t get_capacity(struct gendisk *disk) ...@@ -256,7 +256,7 @@ static inline sector_t get_capacity(struct gendisk *disk)
return bdev_nr_sectors(disk->part0); return bdev_nr_sectors(disk->part0);
} }
int bdev_disk_changed(struct block_device *bdev, bool invalidate); int bdev_disk_changed(struct gendisk *disk, bool invalidate);
void blk_drop_partitions(struct gendisk *disk); void blk_drop_partitions(struct gendisk *disk);
extern struct gendisk *__alloc_disk_node(int minors, int node_id); extern struct gendisk *__alloc_disk_node(int minors, int node_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment