Commit 81a5d60e authored by Philipp Reisner's avatar Philipp Reisner

drbd: Replaced the minor_table array by an idr

Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent 774b3055
...@@ -168,8 +168,8 @@ drbd_insert_fault(struct drbd_conf *mdev, unsigned int type) { ...@@ -168,8 +168,8 @@ drbd_insert_fault(struct drbd_conf *mdev, unsigned int type) {
/* 4th incarnation of the disk layout. */ /* 4th incarnation of the disk layout. */
#define DRBD_MD_MAGIC (DRBD_MAGIC+4) #define DRBD_MD_MAGIC (DRBD_MAGIC+4)
extern struct drbd_conf **minor_table;
extern struct ratelimit_state drbd_ratelimit_state; extern struct ratelimit_state drbd_ratelimit_state;
extern struct idr minors;
extern struct list_head drbd_tconns; extern struct list_head drbd_tconns;
/* on the wire */ /* on the wire */
...@@ -1109,11 +1109,7 @@ struct drbd_conf { ...@@ -1109,11 +1109,7 @@ struct drbd_conf {
static inline struct drbd_conf *minor_to_mdev(unsigned int minor) static inline struct drbd_conf *minor_to_mdev(unsigned int minor)
{ {
struct drbd_conf *mdev; return (struct drbd_conf *)idr_find(&minors, minor);
mdev = minor < minor_count ? minor_table[minor] : NULL;
return mdev;
} }
static inline unsigned int mdev_to_minor(struct drbd_conf *mdev) static inline unsigned int mdev_to_minor(struct drbd_conf *mdev)
......
...@@ -74,7 +74,7 @@ MODULE_AUTHOR("Philipp Reisner <phil@linbit.com>, " ...@@ -74,7 +74,7 @@ MODULE_AUTHOR("Philipp Reisner <phil@linbit.com>, "
MODULE_DESCRIPTION("drbd - Distributed Replicated Block Device v" REL_VERSION); MODULE_DESCRIPTION("drbd - Distributed Replicated Block Device v" REL_VERSION);
MODULE_VERSION(REL_VERSION); MODULE_VERSION(REL_VERSION);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_PARM_DESC(minor_count, "Maximum number of drbd devices (" MODULE_PARM_DESC(minor_count, "Approximate number of drbd devices ("
__stringify(DRBD_MINOR_COUNT_MIN) "-" __stringify(DRBD_MINOR_COUNT_MAX) ")"); __stringify(DRBD_MINOR_COUNT_MIN) "-" __stringify(DRBD_MINOR_COUNT_MAX) ")");
MODULE_ALIAS_BLOCKDEV_MAJOR(DRBD_MAJOR); MODULE_ALIAS_BLOCKDEV_MAJOR(DRBD_MAJOR);
...@@ -120,7 +120,7 @@ module_param_string(usermode_helper, usermode_helper, sizeof(usermode_helper), 0 ...@@ -120,7 +120,7 @@ module_param_string(usermode_helper, usermode_helper, sizeof(usermode_helper), 0
/* in 2.6.x, our device mapping and config info contains our virtual gendisks /* in 2.6.x, our device mapping and config info contains our virtual gendisks
* as member "struct gendisk *vdisk;" * as member "struct gendisk *vdisk;"
*/ */
struct drbd_conf **minor_table; struct idr minors;
struct list_head drbd_tconns; /* list of struct drbd_tconn */ struct list_head drbd_tconns; /* list of struct drbd_tconn */
struct kmem_cache *drbd_request_cache; struct kmem_cache *drbd_request_cache;
...@@ -2118,11 +2118,13 @@ void drbd_delete_device(unsigned int minor) ...@@ -2118,11 +2118,13 @@ void drbd_delete_device(unsigned int minor)
* allocated from drbd_new_device * allocated from drbd_new_device
* and actually free the mdev itself */ * and actually free the mdev itself */
drbd_free_mdev(mdev); drbd_free_mdev(mdev);
idr_remove(&minors, minor);
} }
static void drbd_cleanup(void) static void drbd_cleanup(void)
{ {
unsigned int i; unsigned int i;
struct drbd_conf *mdev;
unregister_reboot_notifier(&drbd_notifier); unregister_reboot_notifier(&drbd_notifier);
...@@ -2139,17 +2141,13 @@ static void drbd_cleanup(void) ...@@ -2139,17 +2141,13 @@ static void drbd_cleanup(void)
drbd_nl_cleanup(); drbd_nl_cleanup();
if (minor_table) { idr_for_each_entry(&minors, mdev, i)
i = minor_count; drbd_delete_device(i);
while (i--) drbd_destroy_mempools();
drbd_delete_device(i);
drbd_destroy_mempools();
}
kfree(minor_table);
unregister_blkdev(DRBD_MAJOR, "drbd"); unregister_blkdev(DRBD_MAJOR, "drbd");
idr_destroy(&minors);
printk(KERN_INFO "drbd: module cleanup done.\n"); printk(KERN_INFO "drbd: module cleanup done.\n");
} }
...@@ -2286,6 +2284,7 @@ enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor, ...@@ -2286,6 +2284,7 @@ enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor,
struct gendisk *disk; struct gendisk *disk;
struct request_queue *q; struct request_queue *q;
int vnr_got = vnr; int vnr_got = vnr;
int minor_got = minor;
mdev = minor_to_mdev(minor); mdev = minor_to_mdev(minor);
if (mdev) if (mdev)
...@@ -2361,13 +2360,20 @@ enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor, ...@@ -2361,13 +2360,20 @@ enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor,
INIT_LIST_HEAD(&mdev->current_epoch->list); INIT_LIST_HEAD(&mdev->current_epoch->list);
mdev->epochs = 1; mdev->epochs = 1;
minor_table[minor] = mdev; if (!idr_pre_get(&minors, GFP_KERNEL))
goto out_no_minor_idr;
if (idr_get_new(&minors, mdev, &minor_got))
goto out_no_minor_idr;
if (minor_got != minor) {
idr_remove(&minors, minor_got);
goto out_no_minor_idr;
}
add_disk(disk); add_disk(disk);
return NO_ERROR; return NO_ERROR;
/* out_whatever_else: out_no_minor_idr:
kfree(mdev->current_epoch); */ kfree(mdev->current_epoch);
out_no_epoch: out_no_epoch:
drbd_bm_cleanup(mdev); drbd_bm_cleanup(mdev);
out_no_bitmap: out_no_bitmap:
...@@ -2406,7 +2412,7 @@ int __init drbd_init(void) ...@@ -2406,7 +2412,7 @@ int __init drbd_init(void)
if (minor_count < DRBD_MINOR_COUNT_MIN || minor_count > DRBD_MINOR_COUNT_MAX) { if (minor_count < DRBD_MINOR_COUNT_MIN || minor_count > DRBD_MINOR_COUNT_MAX) {
printk(KERN_ERR printk(KERN_ERR
"drbd: invalid minor_count (%d)\n", minor_count); "drbd: invalid minor_count (%d)\n", minor_count);
#ifdef MODULE #ifdef MODULE
return -EINVAL; return -EINVAL;
#else #else
...@@ -2436,10 +2442,7 @@ int __init drbd_init(void) ...@@ -2436,10 +2442,7 @@ int __init drbd_init(void)
init_waitqueue_head(&drbd_pp_wait); init_waitqueue_head(&drbd_pp_wait);
drbd_proc = NULL; /* play safe for drbd_cleanup */ drbd_proc = NULL; /* play safe for drbd_cleanup */
minor_table = kzalloc(sizeof(struct drbd_conf *)*minor_count, idr_init(&minors);
GFP_KERNEL);
if (!minor_table)
goto Enomem;
err = drbd_create_mempools(); err = drbd_create_mempools();
if (err) if (err)
...@@ -2460,7 +2463,6 @@ int __init drbd_init(void) ...@@ -2460,7 +2463,6 @@ int __init drbd_init(void)
printk(KERN_INFO "drbd: %s\n", drbd_buildtag()); printk(KERN_INFO "drbd: %s\n", drbd_buildtag());
printk(KERN_INFO "drbd: registered as block device major %d\n", printk(KERN_INFO "drbd: registered as block device major %d\n",
DRBD_MAJOR); DRBD_MAJOR);
printk(KERN_INFO "drbd: minor_table @ 0x%p\n", minor_table);
return 0; /* Success! */ return 0; /* Success! */
......
...@@ -194,7 +194,7 @@ static void resync_dump_detail(struct seq_file *seq, struct lc_element *e) ...@@ -194,7 +194,7 @@ static void resync_dump_detail(struct seq_file *seq, struct lc_element *e)
static int drbd_seq_show(struct seq_file *seq, void *v) static int drbd_seq_show(struct seq_file *seq, void *v)
{ {
int i, hole = 0; int i, prev_i = -1;
const char *sn; const char *sn;
struct drbd_conf *mdev; struct drbd_conf *mdev;
...@@ -227,16 +227,10 @@ static int drbd_seq_show(struct seq_file *seq, void *v) ...@@ -227,16 +227,10 @@ static int drbd_seq_show(struct seq_file *seq, void *v)
oos .. known out-of-sync kB oos .. known out-of-sync kB
*/ */
for (i = 0; i < minor_count; i++) { idr_for_each_entry(&minors, mdev, i) {
mdev = minor_to_mdev(i); if (prev_i != i - 1)
if (!mdev) {
hole = 1;
continue;
}
if (hole) {
hole = 0;
seq_printf(seq, "\n"); seq_printf(seq, "\n");
} prev_i = i;
sn = drbd_conn_str(mdev->state.conn); sn = drbd_conn_str(mdev->state.conn);
......
...@@ -284,7 +284,7 @@ static void drbd_pp_free(struct drbd_conf *mdev, struct page *page, int is_net) ...@@ -284,7 +284,7 @@ static void drbd_pp_free(struct drbd_conf *mdev, struct page *page, int is_net)
atomic_t *a = is_net ? &mdev->pp_in_use_by_net : &mdev->pp_in_use; atomic_t *a = is_net ? &mdev->pp_in_use_by_net : &mdev->pp_in_use;
int i; int i;
if (drbd_pp_vacant > (DRBD_MAX_BIO_SIZE/PAGE_SIZE)*minor_count) if (drbd_pp_vacant > (DRBD_MAX_BIO_SIZE/PAGE_SIZE) * minor_count)
i = page_chain_free(page); i = page_chain_free(page);
else { else {
struct page *tmp; struct page *tmp;
......
...@@ -1349,10 +1349,7 @@ static int _drbd_pause_after(struct drbd_conf *mdev) ...@@ -1349,10 +1349,7 @@ static int _drbd_pause_after(struct drbd_conf *mdev)
struct drbd_conf *odev; struct drbd_conf *odev;
int i, rv = 0; int i, rv = 0;
for (i = 0; i < minor_count; i++) { idr_for_each_entry(&minors, odev, i) {
odev = minor_to_mdev(i);
if (!odev)
continue;
if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS) if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS)
continue; continue;
if (!_drbd_may_sync_now(odev)) if (!_drbd_may_sync_now(odev))
...@@ -1374,10 +1371,7 @@ static int _drbd_resume_next(struct drbd_conf *mdev) ...@@ -1374,10 +1371,7 @@ static int _drbd_resume_next(struct drbd_conf *mdev)
struct drbd_conf *odev; struct drbd_conf *odev;
int i, rv = 0; int i, rv = 0;
for (i = 0; i < minor_count; i++) { idr_for_each_entry(&minors, odev, i) {
odev = minor_to_mdev(i);
if (!odev)
continue;
if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS) if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS)
continue; continue;
if (odev->state.aftr_isp) { if (odev->state.aftr_isp) {
......
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