Commit 75e27d37 authored by Jan Kara's avatar Jan Kara Committed by Christian Brauner

drdb: Convert to use bdev_open_by_path()

Convert drdb to use bdev_open_by_path().

CC: drbd-dev@lists.linbit.com
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230927093442.25915-4-jack@suse.czSigned-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent acb083b5
...@@ -524,7 +524,9 @@ struct drbd_md { ...@@ -524,7 +524,9 @@ struct drbd_md {
struct drbd_backing_dev { struct drbd_backing_dev {
struct block_device *backing_bdev; struct block_device *backing_bdev;
struct bdev_handle *backing_bdev_handle;
struct block_device *md_bdev; struct block_device *md_bdev;
struct bdev_handle *md_bdev_handle;
struct drbd_md md; struct drbd_md md;
struct disk_conf *disk_conf; /* RCU, for updates: resource->conf_update */ struct disk_conf *disk_conf; /* RCU, for updates: resource->conf_update */
sector_t known_size; /* last known size of that backing device */ sector_t known_size; /* last known size of that backing device */
......
...@@ -82,7 +82,7 @@ static atomic_t notify_genl_seq = ATOMIC_INIT(2); /* two. */ ...@@ -82,7 +82,7 @@ static atomic_t notify_genl_seq = ATOMIC_INIT(2); /* two. */
DEFINE_MUTEX(notification_mutex); DEFINE_MUTEX(notification_mutex);
/* used blkdev_get_by_path, to claim our meta data device(s) */ /* used bdev_open_by_path, to claim our meta data device(s) */
static char *drbd_m_holder = "Hands off! this is DRBD's meta data device."; static char *drbd_m_holder = "Hands off! this is DRBD's meta data device.";
static void drbd_adm_send_reply(struct sk_buff *skb, struct genl_info *info) static void drbd_adm_send_reply(struct sk_buff *skb, struct genl_info *info)
...@@ -1635,43 +1635,45 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) ...@@ -1635,43 +1635,45 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
return 0; return 0;
} }
static struct block_device *open_backing_dev(struct drbd_device *device, static struct bdev_handle *open_backing_dev(struct drbd_device *device,
const char *bdev_path, void *claim_ptr, bool do_bd_link) const char *bdev_path, void *claim_ptr, bool do_bd_link)
{ {
struct block_device *bdev; struct bdev_handle *handle;
int err = 0; int err = 0;
bdev = blkdev_get_by_path(bdev_path, BLK_OPEN_READ | BLK_OPEN_WRITE, handle = bdev_open_by_path(bdev_path, BLK_OPEN_READ | BLK_OPEN_WRITE,
claim_ptr, NULL); claim_ptr, NULL);
if (IS_ERR(bdev)) { if (IS_ERR(handle)) {
drbd_err(device, "open(\"%s\") failed with %ld\n", drbd_err(device, "open(\"%s\") failed with %ld\n",
bdev_path, PTR_ERR(bdev)); bdev_path, PTR_ERR(handle));
return bdev; return handle;
} }
if (!do_bd_link) if (!do_bd_link)
return bdev; return handle;
err = bd_link_disk_holder(bdev, device->vdisk); err = bd_link_disk_holder(handle->bdev, device->vdisk);
if (err) { if (err) {
blkdev_put(bdev, claim_ptr); bdev_release(handle);
drbd_err(device, "bd_link_disk_holder(\"%s\", ...) failed with %d\n", drbd_err(device, "bd_link_disk_holder(\"%s\", ...) failed with %d\n",
bdev_path, err); bdev_path, err);
bdev = ERR_PTR(err); handle = ERR_PTR(err);
} }
return bdev; return handle;
} }
static int open_backing_devices(struct drbd_device *device, static int open_backing_devices(struct drbd_device *device,
struct disk_conf *new_disk_conf, struct disk_conf *new_disk_conf,
struct drbd_backing_dev *nbc) struct drbd_backing_dev *nbc)
{ {
struct block_device *bdev; struct bdev_handle *handle;
bdev = open_backing_dev(device, new_disk_conf->backing_dev, device, true); handle = open_backing_dev(device, new_disk_conf->backing_dev, device,
if (IS_ERR(bdev)) true);
if (IS_ERR(handle))
return ERR_OPEN_DISK; return ERR_OPEN_DISK;
nbc->backing_bdev = bdev; nbc->backing_bdev = handle->bdev;
nbc->backing_bdev_handle = handle;
/* /*
* meta_dev_idx >= 0: external fixed size, possibly multiple * meta_dev_idx >= 0: external fixed size, possibly multiple
...@@ -1681,7 +1683,7 @@ static int open_backing_devices(struct drbd_device *device, ...@@ -1681,7 +1683,7 @@ static int open_backing_devices(struct drbd_device *device,
* should check it for you already; but if you don't, or * should check it for you already; but if you don't, or
* someone fooled it, we need to double check here) * someone fooled it, we need to double check here)
*/ */
bdev = open_backing_dev(device, new_disk_conf->meta_dev, handle = open_backing_dev(device, new_disk_conf->meta_dev,
/* claim ptr: device, if claimed exclusively; shared drbd_m_holder, /* claim ptr: device, if claimed exclusively; shared drbd_m_holder,
* if potentially shared with other drbd minors */ * if potentially shared with other drbd minors */
(new_disk_conf->meta_dev_idx < 0) ? (void*)device : (void*)drbd_m_holder, (new_disk_conf->meta_dev_idx < 0) ? (void*)device : (void*)drbd_m_holder,
...@@ -1689,20 +1691,21 @@ static int open_backing_devices(struct drbd_device *device, ...@@ -1689,20 +1691,21 @@ static int open_backing_devices(struct drbd_device *device,
* as would happen with internal metadata. */ * as would happen with internal metadata. */
(new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_FLEX_INT && (new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_FLEX_INT &&
new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_INTERNAL)); new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_INTERNAL));
if (IS_ERR(bdev)) if (IS_ERR(handle))
return ERR_OPEN_MD_DISK; return ERR_OPEN_MD_DISK;
nbc->md_bdev = bdev; nbc->md_bdev = handle->bdev;
nbc->md_bdev_handle = handle;
return NO_ERROR; return NO_ERROR;
} }
static void close_backing_dev(struct drbd_device *device, struct block_device *bdev, static void close_backing_dev(struct drbd_device *device,
void *claim_ptr, bool do_bd_unlink) struct bdev_handle *handle, bool do_bd_unlink)
{ {
if (!bdev) if (!handle)
return; return;
if (do_bd_unlink) if (do_bd_unlink)
bd_unlink_disk_holder(bdev, device->vdisk); bd_unlink_disk_holder(handle->bdev, device->vdisk);
blkdev_put(bdev, claim_ptr); bdev_release(handle);
} }
void drbd_backing_dev_free(struct drbd_device *device, struct drbd_backing_dev *ldev) void drbd_backing_dev_free(struct drbd_device *device, struct drbd_backing_dev *ldev)
...@@ -1710,11 +1713,9 @@ void drbd_backing_dev_free(struct drbd_device *device, struct drbd_backing_dev * ...@@ -1710,11 +1713,9 @@ void drbd_backing_dev_free(struct drbd_device *device, struct drbd_backing_dev *
if (ldev == NULL) if (ldev == NULL)
return; return;
close_backing_dev(device, ldev->md_bdev, close_backing_dev(device, ldev->md_bdev_handle,
ldev->md.meta_dev_idx < 0 ?
(void *)device : (void *)drbd_m_holder,
ldev->md_bdev != ldev->backing_bdev); ldev->md_bdev != ldev->backing_bdev);
close_backing_dev(device, ldev->backing_bdev, device, true); close_backing_dev(device, ldev->backing_bdev_handle, true);
kfree(ldev->disk_conf); kfree(ldev->disk_conf);
kfree(ldev); kfree(ldev);
...@@ -2130,11 +2131,9 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) ...@@ -2130,11 +2131,9 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
fail: fail:
conn_reconfig_done(connection); conn_reconfig_done(connection);
if (nbc) { if (nbc) {
close_backing_dev(device, nbc->md_bdev, close_backing_dev(device, nbc->md_bdev_handle,
nbc->disk_conf->meta_dev_idx < 0 ?
(void *)device : (void *)drbd_m_holder,
nbc->md_bdev != nbc->backing_bdev); nbc->md_bdev != nbc->backing_bdev);
close_backing_dev(device, nbc->backing_bdev, device, true); close_backing_dev(device, nbc->backing_bdev_handle, true);
kfree(nbc); kfree(nbc);
} }
kfree(new_disk_conf); kfree(new_disk_conf);
......
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