struct drbd_conf {
struct drbd_tconn *tconn;
int vnr; /* volume number within the connection */
+ struct kref kref;
/* things that are stored as / read from meta data on disk */
unsigned long flags;
extern int conn_lowest_minor(struct drbd_tconn *tconn);
enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor, int vnr);
-extern void drbd_delete_device(struct drbd_conf *mdev);
+extern void drbd_minor_destroy(struct kref *kref);
struct drbd_tconn *conn_create(const char *name);
extern void conn_destroy(struct kref *kref);
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;
}
/* 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 */
{
unsigned int i;
struct drbd_conf *mdev;
+ struct drbd_tconn *tconn, *tmp;
unregister_reboot_notifier(&drbd_notifier);
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();
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;
spin_unlock_irq(&tconn->req_lock);
if (stop_threads) {
/* asender is implicitly stopped by receiver
- * in drbd_disconnect() */
+ * in conn_disconnect() */
drbd_thread_stop(&tconn->receiver);
drbd_thread_stop(&tconn->worker);
}
* we may want to delete a minor from a live replication group.
*/
mdev->state.role == R_SECONDARY) {
- drbd_delete_device(mdev);
+ idr_remove(&mdev->tconn->volumes, mdev->vnr);
+ idr_remove(&minors, mdev_to_minor(mdev));
+ del_gendisk(mdev->vdisk);
+ synchronize_rcu();
+ kref_put(&mdev->kref, &drbd_minor_destroy);
return NO_ERROR;
} else
return ERR_MINOR_CONFIGURED;
* no point in trying again, please go standalone.
* -2 We do not have a network config...
*/
-static int drbd_connect(struct drbd_tconn *tconn)
+static int conn_connect(struct drbd_tconn *tconn)
{
struct socket *sock, *msock;
struct net_conf *nc;
tconn->meta.socket = s;
send_first_packet(tconn, &tconn->meta, P_INITIAL_META);
} else {
- conn_err(tconn, "Logic error in drbd_connect()\n");
+ conn_err(tconn, "Logic error in conn_connect()\n");
goto out_release_sockets;
}
}
wait_for_completion(&barr.done);
}
-static void drbd_disconnect(struct drbd_tconn *tconn)
+static void conn_disconnect(struct drbd_tconn *tconn)
{
enum drbd_conns oc;
int rv = SS_UNKNOWN_ERROR;
conn_info(tconn, "receiver (re)started\n");
do {
- h = drbd_connect(tconn);
+ h = conn_connect(tconn);
if (h == 0) {
- drbd_disconnect(tconn);
+ conn_disconnect(tconn);
schedule_timeout_interruptible(HZ);
}
if (h == -1) {
if (h > 0)
drbdd(tconn);
- drbd_disconnect(tconn);
+ conn_disconnect(tconn);
conn_info(tconn, "receiver terminated\n");
return 0;