Skip to content

Commit 56de210

Browse files
htejuntorvalds
authored andcommitted
drbd: convert to idr_alloc()
Convert to the much saner new idr interface. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b051f6e commit 56de210

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

‎drivers/block/drbd/drbd_main.c‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,25 +2660,24 @@ enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor,
26602660
mdev->read_requests = RB_ROOT;
26612661
mdev->write_requests = RB_ROOT;
26622662

2663-
if (!idr_pre_get(&minors, GFP_KERNEL))
2664-
goto out_no_minor_idr;
2665-
if (idr_get_new_above(&minors, mdev, minor, &minor_got))
2663+
minor_got = idr_alloc(&minors, mdev, minor, minor + 1, GFP_KERNEL);
2664+
if (minor_got < 0) {
2665+
if (minor_got == -ENOSPC) {
2666+
err = ERR_MINOR_EXISTS;
2667+
drbd_msg_put_info("requested minor exists already");
2668+
}
26662669
goto out_no_minor_idr;
2667-
if (minor_got != minor) {
2668-
err = ERR_MINOR_EXISTS;
2669-
drbd_msg_put_info("requested minor exists already");
2670-
goto out_idr_remove_minor;
26712670
}
26722671

2673-
if (!idr_pre_get(&tconn->volumes, GFP_KERNEL))
2674-
goto out_idr_remove_minor;
2675-
if (idr_get_new_above(&tconn->volumes, mdev, vnr, &vnr_got))
2672+
vnr_got = idr_alloc(&tconn->volumes, mdev, vnr, vnr + 1, GFP_KERNEL);
2673+
if (vnr_got < 0) {
2674+
if (vnr_got == -ENOSPC) {
2675+
err = ERR_INVALID_REQUEST;
2676+
drbd_msg_put_info("requested volume exists already");
2677+
}
26762678
goto out_idr_remove_minor;
2677-
if (vnr_got != vnr) {
2678-
err = ERR_INVALID_REQUEST;
2679-
drbd_msg_put_info("requested volume exists already");
2680-
goto out_idr_remove_vol;
26812679
}
2680+
26822681
add_disk(disk);
26832682
kref_init(&mdev->kref); /* one ref for both idrs and the the add_disk */
26842683

@@ -2689,8 +2688,6 @@ enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor,
26892688

26902689
return NO_ERROR;
26912690

2692-
out_idr_remove_vol:
2693-
idr_remove(&tconn->volumes, vnr_got);
26942691
out_idr_remove_minor:
26952692
idr_remove(&minors, minor_got);
26962693
synchronize_rcu();

0 commit comments

Comments
 (0)