target/iscsi: convert to idr_alloc()
authorTejun Heo <tj@kernel.org>
Thu, 28 Feb 2013 01:04:43 +0000 (17:04 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Feb 2013 03:10:18 +0000 (19:10 -0800)
Convert to the much saner new idr interface.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Nicholas A. Bellinger <nab@linux-iscsi.org>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/target/iscsi/iscsi_target.c
drivers/target/iscsi/iscsi_target_login.c

index 23a98e6583064ddbfeddb392f6c7c8f356900298..9435a3d369a7b8aa7f8e628ea2c32f0845b1f2a2 100644 (file)
@@ -144,23 +144,24 @@ struct iscsi_tiqn *iscsit_add_tiqn(unsigned char *buf)
        spin_lock_init(&tiqn->login_stats.lock);
        spin_lock_init(&tiqn->logout_stats.lock);
 
-       if (!idr_pre_get(&tiqn_idr, GFP_KERNEL)) {
-               pr_err("idr_pre_get() for tiqn_idr failed\n");
-               kfree(tiqn);
-               return ERR_PTR(-ENOMEM);
-       }
        tiqn->tiqn_state = TIQN_STATE_ACTIVE;
 
+       idr_preload(GFP_KERNEL);
        spin_lock(&tiqn_lock);
-       ret = idr_get_new(&tiqn_idr, NULL, &tiqn->tiqn_index);
+
+       ret = idr_alloc(&tiqn_idr, NULL, 0, 0, GFP_NOWAIT);
        if (ret < 0) {
-               pr_err("idr_get_new() failed for tiqn->tiqn_index\n");
+               pr_err("idr_alloc() failed for tiqn->tiqn_index\n");
                spin_unlock(&tiqn_lock);
+               idr_preload_end();
                kfree(tiqn);
                return ERR_PTR(ret);
        }
+       tiqn->tiqn_index = ret;
        list_add_tail(&tiqn->tiqn_list, &g_tiqn_list);
+
        spin_unlock(&tiqn_lock);
+       idr_preload_end();
 
        pr_debug("CORE[0] - Added iSCSI Target IQN: %s\n", tiqn->tiqn);
 
index fdb632f0ab851120851e34f8c89e5f2c91d84f81..2535d4d46c0efd119803e145f4bc9193487b386c 100644 (file)
@@ -247,19 +247,16 @@ static int iscsi_login_zero_tsih_s1(
        spin_lock_init(&sess->session_usage_lock);
        spin_lock_init(&sess->ttt_lock);
 
-       if (!idr_pre_get(&sess_idr, GFP_KERNEL)) {
-               pr_err("idr_pre_get() for sess_idr failed\n");
-               iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
-                               ISCSI_LOGIN_STATUS_NO_RESOURCES);
-               kfree(sess);
-               return -ENOMEM;
-       }
+       idr_preload(GFP_KERNEL);
        spin_lock_bh(&sess_idr_lock);
-       ret = idr_get_new(&sess_idr, NULL, &sess->session_index);
+       ret = idr_alloc(&sess_idr, NULL, 0, 0, GFP_NOWAIT);
+       if (ret >= 0)
+               sess->session_index = ret;
        spin_unlock_bh(&sess_idr_lock);
+       idr_preload_end();
 
        if (ret < 0) {
-               pr_err("idr_get_new() for sess_idr failed\n");
+               pr_err("idr_alloc() for sess_idr failed\n");
                iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
                                ISCSI_LOGIN_STATUS_NO_RESOURCES);
                kfree(sess);