aboutsummaryrefslogtreecommitdiff
path: root/drivers/block/drbd/drbd_main.c
diff options
context:
space:
mode:
authorPhilipp Reisner <philipp.reisner@linbit.com>2011-05-04 15:10:30 +0200
committerPhilipp Reisner <philipp.reisner@linbit.com>2012-11-08 16:55:47 +0100
commit81fa2e675ccf88035d9308a3c98fe2c2928ace00 (patch)
tree492bb7110ef874bbb455fc395f7700f0c7c8277f /drivers/block/drbd/drbd_main.c
parentbb77d34ecc6fe6cdc3f4f0841a516695c2eacc04 (diff)
downloadvexpress-lsk-81fa2e675ccf88035d9308a3c98fe2c2928ace00.tar.gz
drbd: Refcounting for mdev objects
Preparing removal of drbd_cfg_rwsem Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com> Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Diffstat (limited to 'drivers/block/drbd/drbd_main.c')
-rw-r--r--drivers/block/drbd/drbd_main.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index 240319ce865..8da0e99ee7e 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -2052,7 +2052,6 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
init_waitqueue_head(&mdev->al_wait);
init_waitqueue_head(&mdev->seq_wait);
- /* mdev->tconn->agreed_pro_version gets initialized in drbd_connect() */
mdev->write_ordering = WO_bdev_flush;
mdev->resync_wenr = LC_FREE;
mdev->peer_max_bio_size = DRBD_MAX_BIO_SIZE_SAFE;
@@ -2272,21 +2271,16 @@ static void drbd_release_all_peer_reqs(struct drbd_conf *mdev)
}
/* caution. no locking. */
-void drbd_delete_device(struct drbd_conf *mdev)
+void drbd_minor_destroy(struct kref *kref)
{
+ struct drbd_conf *mdev = container_of(kref, struct drbd_conf, kref);
struct drbd_tconn *tconn = mdev->tconn;
- idr_remove(&mdev->tconn->volumes, mdev->vnr);
- idr_remove(&minors, mdev_to_minor(mdev));
- synchronize_rcu();
-
/* paranoia asserts */
D_ASSERT(mdev->open_cnt == 0);
D_ASSERT(list_empty(&mdev->tconn->data.work.q));
/* end paranoia asserts */
- del_gendisk(mdev->vdisk);
-
/* cleanup stuff that may have been allocated during
* device (re-)configuration or state changes */
@@ -2320,6 +2314,7 @@ static void drbd_cleanup(void)
{
unsigned int i;
struct drbd_conf *mdev;
+ struct drbd_tconn *tconn, *tmp;
unregister_reboot_notifier(&drbd_notifier);
@@ -2337,8 +2332,19 @@ static void drbd_cleanup(void)
drbd_genl_unregister();
down_write(&drbd_cfg_rwsem);
- idr_for_each_entry(&minors, mdev, i)
- drbd_delete_device(mdev);
+ idr_for_each_entry(&minors, mdev, i) {
+ idr_remove(&minors, mdev_to_minor(mdev));
+ idr_remove(&mdev->tconn->volumes, mdev->vnr);
+ del_gendisk(mdev->vdisk);
+ synchronize_rcu();
+ kref_put(&mdev->kref, &drbd_minor_destroy);
+ }
+
+ list_for_each_entry_safe(tconn, tmp, &drbd_tconns, all_tconn) {
+ list_del(&tconn->all_tconn);
+ synchronize_rcu();
+ kref_put(&tconn->kref, &conn_destroy);
+ }
up_write(&drbd_cfg_rwsem);
drbd_destroy_mempools();
@@ -2625,6 +2631,7 @@ enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor,
goto out_idr_remove_vol;
}
add_disk(disk);
+ kref_init(&mdev->kref); /* one ref for both idrs and the the add_disk */
/* inherit the connection state */
mdev->state.conn = tconn->cstate;