diff options
Diffstat (limited to 'drivers/target')
-rw-r--r-- | drivers/target/iscsi/iscsi_target.c | 86 | ||||
-rw-r--r-- | drivers/target/iscsi/iscsi_target_auth.c | 98 | ||||
-rw-r--r-- | drivers/target/iscsi/iscsi_target_configfs.c | 75 | ||||
-rw-r--r-- | drivers/target/iscsi/iscsi_target_login.c | 45 | ||||
-rw-r--r-- | drivers/target/target_core_configfs.c | 203 | ||||
-rw-r--r-- | drivers/target/target_core_fabric_configfs.c | 194 | ||||
-rw-r--r-- | drivers/target/target_core_internal.h | 1 | ||||
-rw-r--r-- | drivers/target/target_core_stat.c | 41 | ||||
-rw-r--r-- | drivers/target/target_core_tmr.c | 1 |
9 files changed, 242 insertions, 502 deletions
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 576a7a4..961202f 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -16,9 +16,9 @@ * GNU General Public License for more details. ******************************************************************************/ +#include <crypto/hash.h> #include <linux/string.h> #include <linux/kthread.h> -#include <linux/crypto.h> #include <linux/completion.h> #include <linux/module.h> #include <linux/vmalloc.h> @@ -1190,7 +1190,7 @@ iscsit_handle_scsi_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, } static u32 iscsit_do_crypto_hash_sg( - struct hash_desc *hash, + struct ahash_request *hash, struct iscsi_cmd *cmd, u32 data_offset, u32 data_length, @@ -1201,7 +1201,7 @@ static u32 iscsit_do_crypto_hash_sg( struct scatterlist *sg; unsigned int page_off; - crypto_hash_init(hash); + crypto_ahash_init(hash); sg = cmd->first_data_sg; page_off = cmd->first_data_sg_off; @@ -1209,7 +1209,8 @@ static u32 iscsit_do_crypto_hash_sg( while (data_length) { u32 cur_len = min_t(u32, data_length, (sg->length - page_off)); - crypto_hash_update(hash, sg, cur_len); + ahash_request_set_crypt(hash, sg, NULL, cur_len); + crypto_ahash_update(hash); data_length -= cur_len; page_off = 0; @@ -1221,33 +1222,34 @@ static u32 iscsit_do_crypto_hash_sg( struct scatterlist pad_sg; sg_init_one(&pad_sg, pad_bytes, padding); - crypto_hash_update(hash, &pad_sg, padding); + ahash_request_set_crypt(hash, &pad_sg, (u8 *)&data_crc, + padding); + crypto_ahash_finup(hash); + } else { + ahash_request_set_crypt(hash, NULL, (u8 *)&data_crc, 0); + crypto_ahash_final(hash); } - crypto_hash_final(hash, (u8 *) &data_crc); return data_crc; } static void iscsit_do_crypto_hash_buf( - struct hash_desc *hash, + struct ahash_request *hash, const void *buf, u32 payload_length, u32 padding, u8 *pad_bytes, u8 *data_crc) { - struct scatterlist sg; + struct scatterlist sg[2]; - crypto_hash_init(hash); + sg_init_table(sg, ARRAY_SIZE(sg)); + sg_set_buf(sg, buf, payload_length); + sg_set_buf(sg + 1, pad_bytes, padding); - sg_init_one(&sg, buf, payload_length); - crypto_hash_update(hash, &sg, payload_length); + ahash_request_set_crypt(hash, sg, data_crc, payload_length + padding); - if (padding) { - sg_init_one(&sg, pad_bytes, padding); - crypto_hash_update(hash, &sg, padding); - } - crypto_hash_final(hash, data_crc); + crypto_ahash_digest(hash); } int @@ -1422,7 +1424,7 @@ iscsit_get_dataout(struct iscsi_conn *conn, struct iscsi_cmd *cmd, if (conn->conn_ops->DataDigest) { u32 data_crc; - data_crc = iscsit_do_crypto_hash_sg(&conn->conn_rx_hash, cmd, + data_crc = iscsit_do_crypto_hash_sg(conn->conn_rx_hash, cmd, be32_to_cpu(hdr->offset), payload_length, padding, cmd->pad_bytes); @@ -1682,7 +1684,7 @@ static int iscsit_handle_nop_out(struct iscsi_conn *conn, struct iscsi_cmd *cmd, } if (conn->conn_ops->DataDigest) { - iscsit_do_crypto_hash_buf(&conn->conn_rx_hash, + iscsit_do_crypto_hash_buf(conn->conn_rx_hash, ping_data, payload_length, padding, cmd->pad_bytes, (u8 *)&data_crc); @@ -2101,7 +2103,7 @@ iscsit_handle_text_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, goto reject; if (conn->conn_ops->DataDigest) { - iscsit_do_crypto_hash_buf(&conn->conn_rx_hash, + iscsit_do_crypto_hash_buf(conn->conn_rx_hash, text_in, payload_length, padding, (u8 *)&pad_bytes, (u8 *)&data_crc); @@ -2440,7 +2442,7 @@ static int iscsit_handle_immediate_data( if (conn->conn_ops->DataDigest) { u32 data_crc; - data_crc = iscsit_do_crypto_hash_sg(&conn->conn_rx_hash, cmd, + data_crc = iscsit_do_crypto_hash_sg(conn->conn_rx_hash, cmd, cmd->write_data_done, length, padding, cmd->pad_bytes); @@ -2553,7 +2555,7 @@ static int iscsit_send_conn_drop_async_message( if (conn->conn_ops->HeaderDigest) { u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, hdr, ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest); cmd->tx_size += ISCSI_CRC_LEN; @@ -2683,7 +2685,7 @@ static int iscsit_send_datain(struct iscsi_cmd *cmd, struct iscsi_conn *conn) if (conn->conn_ops->HeaderDigest) { u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, cmd->pdu, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, cmd->pdu, ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest); iov[0].iov_len += ISCSI_CRC_LEN; @@ -2711,7 +2713,7 @@ static int iscsit_send_datain(struct iscsi_cmd *cmd, struct iscsi_conn *conn) cmd->padding); } if (conn->conn_ops->DataDigest) { - cmd->data_crc = iscsit_do_crypto_hash_sg(&conn->conn_tx_hash, cmd, + cmd->data_crc = iscsit_do_crypto_hash_sg(conn->conn_tx_hash, cmd, datain.offset, datain.length, cmd->padding, cmd->pad_bytes); iov[iov_count].iov_base = &cmd->data_crc; @@ -2857,7 +2859,7 @@ iscsit_send_logout(struct iscsi_cmd *cmd, struct iscsi_conn *conn) if (conn->conn_ops->HeaderDigest) { u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, &cmd->pdu[0], + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, &cmd->pdu[0], ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest); iov[0].iov_len += ISCSI_CRC_LEN; @@ -2915,7 +2917,7 @@ static int iscsit_send_unsolicited_nopin( if (conn->conn_ops->HeaderDigest) { u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, hdr, ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest); tx_size += ISCSI_CRC_LEN; @@ -2963,7 +2965,7 @@ iscsit_send_nopin(struct iscsi_cmd *cmd, struct iscsi_conn *conn) if (conn->conn_ops->HeaderDigest) { u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, hdr, ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest); iov[0].iov_len += ISCSI_CRC_LEN; @@ -2993,7 +2995,7 @@ iscsit_send_nopin(struct iscsi_cmd *cmd, struct iscsi_conn *conn) " padding bytes.\n", padding); } if (conn->conn_ops->DataDigest) { - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, cmd->buf_ptr, cmd->buf_ptr_size, padding, (u8 *)&cmd->pad_bytes, (u8 *)&cmd->data_crc); @@ -3049,7 +3051,7 @@ static int iscsit_send_r2t( if (conn->conn_ops->HeaderDigest) { u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, hdr, ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest); cmd->iov_misc[0].iov_len += ISCSI_CRC_LEN; @@ -3239,7 +3241,7 @@ static int iscsit_send_response(struct iscsi_cmd *cmd, struct iscsi_conn *conn) } if (conn->conn_ops->DataDigest) { - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, cmd->sense_buffer, (cmd->se_cmd.scsi_sense_length + padding), 0, NULL, (u8 *)&cmd->data_crc); @@ -3262,7 +3264,7 @@ static int iscsit_send_response(struct iscsi_cmd *cmd, struct iscsi_conn *conn) if (conn->conn_ops->HeaderDigest) { u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, cmd->pdu, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, cmd->pdu, ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest); iov[0].iov_len += ISCSI_CRC_LEN; @@ -3332,7 +3334,7 @@ iscsit_send_task_mgt_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn) if (conn->conn_ops->HeaderDigest) { u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, hdr, ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest); cmd->iov_misc[0].iov_len += ISCSI_CRC_LEN; @@ -3601,7 +3603,7 @@ static int iscsit_send_text_rsp( if (conn->conn_ops->HeaderDigest) { u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, hdr, ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest); iov[0].iov_len += ISCSI_CRC_LEN; @@ -3611,7 +3613,7 @@ static int iscsit_send_text_rsp( } if (conn->conn_ops->DataDigest) { - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, cmd->buf_ptr, text_length, 0, NULL, (u8 *)&cmd->data_crc); @@ -3668,7 +3670,7 @@ static int iscsit_send_reject( if (conn->conn_ops->HeaderDigest) { u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, hdr, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, hdr, ISCSI_HDR_LEN, 0, NULL, (u8 *)header_digest); iov[0].iov_len += ISCSI_CRC_LEN; @@ -3678,7 +3680,7 @@ static int iscsit_send_reject( } if (conn->conn_ops->DataDigest) { - iscsit_do_crypto_hash_buf(&conn->conn_tx_hash, cmd->buf_ptr, + iscsit_do_crypto_hash_buf(conn->conn_tx_hash, cmd->buf_ptr, ISCSI_HDR_LEN, 0, NULL, (u8 *)&cmd->data_crc); iov[iov_count].iov_base = &cmd->data_crc; @@ -4145,7 +4147,7 @@ int iscsi_target_rx_thread(void *arg) goto transport_err; } - iscsit_do_crypto_hash_buf(&conn->conn_rx_hash, + iscsit_do_crypto_hash_buf(conn->conn_rx_hash, buffer, ISCSI_HDR_LEN, 0, NULL, (u8 *)&checksum); @@ -4359,10 +4361,14 @@ int iscsit_close_connection( */ iscsit_check_conn_usage_count(conn); - if (conn->conn_rx_hash.tfm) - crypto_free_hash(conn->conn_rx_hash.tfm); - if (conn->conn_tx_hash.tfm) - crypto_free_hash(conn->conn_tx_hash.tfm); + ahash_request_free(conn->conn_tx_hash); + if (conn->conn_rx_hash) { + struct crypto_ahash *tfm; + + tfm = crypto_ahash_reqtfm(conn->conn_rx_hash); + ahash_request_free(conn->conn_rx_hash); + crypto_free_ahash(tfm); + } free_cpumask_var(conn->conn_cpumask); diff --git a/drivers/target/iscsi/iscsi_target_auth.c b/drivers/target/iscsi/iscsi_target_auth.c index 47e249d..667406f 100644 --- a/drivers/target/iscsi/iscsi_target_auth.c +++ b/drivers/target/iscsi/iscsi_target_auth.c @@ -16,9 +16,9 @@ * GNU General Public License for more details. ******************************************************************************/ +#include <crypto/hash.h> #include <linux/kernel.h> #include <linux/string.h> -#include <linux/crypto.h> #include <linux/err.h> #include <linux/scatterlist.h> @@ -185,9 +185,8 @@ static int chap_server_compute_md5( unsigned char chap_n[MAX_CHAP_N_SIZE], chap_r[MAX_RESPONSE_LENGTH]; size_t compare_len; struct iscsi_chap *chap = conn->auth_protocol; - struct crypto_hash *tfm; - struct hash_desc desc; - struct scatterlist sg; + struct crypto_shash *tfm = NULL; + struct shash_desc *desc = NULL; int auth_ret = -1, ret, challenge_len; memset(identifier, 0, 10); @@ -245,52 +244,47 @@ static int chap_server_compute_md5( pr_debug("[server] Got CHAP_R=%s\n", chap_r); chap_string_to_hex(client_digest, chap_r, strlen(chap_r)); - tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC); + tfm = crypto_alloc_shash("md5", 0, 0); if (IS_ERR(tfm)) { - pr_err("Unable to allocate struct crypto_hash\n"); + tfm = NULL; + pr_err("Unable to allocate struct crypto_shash\n"); goto out; } - desc.tfm = tfm; - desc.flags = 0; - ret = crypto_hash_init(&desc); - if (ret < 0) { - pr_err("crypto_hash_init() failed\n"); - crypto_free_hash(tfm); + desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(tfm), GFP_KERNEL); + if (!desc) { + pr_err("Unable to allocate struct shash_desc\n"); goto out; } - sg_init_one(&sg, &chap->id, 1); - ret = crypto_hash_update(&desc, &sg, 1); + desc->tfm = tfm; + desc->flags = 0; + + ret = crypto_shash_init(desc); if (ret < 0) { - pr_err("crypto_hash_update() failed for id\n"); - crypto_free_hash(tfm); + pr_err("crypto_shash_init() failed\n"); goto out; } - sg_init_one(&sg, &auth->password, strlen(auth->password)); - ret = crypto_hash_update(&desc, &sg, strlen(auth->password)); + ret = crypto_shash_update(desc, &chap->id, 1); if (ret < 0) { - pr_err("crypto_hash_update() failed for password\n"); - crypto_free_hash(tfm); + pr_err("crypto_shash_update() failed for id\n"); goto out; } - sg_init_one(&sg, chap->challenge, CHAP_CHALLENGE_LENGTH); - ret = crypto_hash_update(&desc, &sg, CHAP_CHALLENGE_LENGTH); + ret = crypto_shash_update(desc, (char *)&auth->password, + strlen(auth->password)); if (ret < 0) { - pr_err("crypto_hash_update() failed for challenge\n"); - crypto_free_hash(tfm); + pr_err("crypto_shash_update() failed for password\n"); goto out; } - ret = crypto_hash_final(&desc, server_digest); + ret = crypto_shash_finup(desc, chap->challenge, + CHAP_CHALLENGE_LENGTH, server_digest); if (ret < 0) { - pr_err("crypto_hash_final() failed for server digest\n"); - crypto_free_hash(tfm); + pr_err("crypto_shash_finup() failed for challenge\n"); goto out; } - crypto_free_hash(tfm); chap_binaryhex_to_asciihex(response, server_digest, MD5_SIGNATURE_SIZE); pr_debug("[server] MD5 Server Digest: %s\n", response); @@ -306,9 +300,8 @@ static int chap_server_compute_md5( * authentication is not enabled. */ if (!auth->authenticate_target) { - kfree(challenge); - kfree(challenge_binhex); - return 0; + auth_ret = 0; + goto out; } /* * Get CHAP_I. @@ -372,58 +365,37 @@ static int chap_server_compute_md5( /* * Generate CHAP_N and CHAP_R for mutual authentication. */ - tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC); - if (IS_ERR(tfm)) { - pr_err("Unable to allocate struct crypto_hash\n"); - goto out; - } - desc.tfm = tfm; - desc.flags = 0; - - ret = crypto_hash_init(&desc); + ret = crypto_shash_init(desc); if (ret < 0) { - pr_err("crypto_hash_init() failed\n"); - crypto_free_hash(tfm); + pr_err("crypto_shash_init() failed\n"); goto out; } /* To handle both endiannesses */ id_as_uchar = id; - sg_init_one(&sg, &id_as_uchar, 1); - ret = crypto_hash_update(&desc, &sg, 1); + ret = crypto_shash_update(desc, &id_as_uchar, 1); if (ret < 0) { - pr_err("crypto_hash_update() failed for id\n"); - crypto_free_hash(tfm); + pr_err("crypto_shash_update() failed for id\n"); goto out; } - sg_init_one(&sg, auth->password_mutual, - strlen(auth->password_mutual)); - ret = crypto_hash_update(&desc, &sg, strlen(auth->password_mutual)); + ret = crypto_shash_update(desc, auth->password_mutual, + strlen(auth->password_mutual)); if (ret < 0) { - pr_err("crypto_hash_update() failed for" + pr_err("crypto_shash_update() failed for" " password_mutual\n"); - crypto_free_hash(tfm); goto out; } /* * Convert received challenge to binary hex. */ - sg_init_one(&sg, challenge_binhex, challenge_len); - ret = crypto_hash_update(&desc, &sg, challenge_len); + ret = crypto_shash_finup(desc, challenge_binhex, challenge_len, + digest); if (ret < 0) { - pr_err("crypto_hash_update() failed for ma challenge\n"); - crypto_free_hash(tfm); + pr_err("crypto_shash_finup() failed for ma challenge\n"); goto out; } - ret = crypto_hash_final(&desc, digest); - if (ret < 0) { - pr_err("crypto_hash_final() failed for ma digest\n"); - crypto_free_hash(tfm); - goto out; - } - crypto_free_hash(tfm); /* * Generate CHAP_N and CHAP_R. */ @@ -440,6 +412,8 @@ static int chap_server_compute_md5( pr_debug("[server] Sending CHAP_R=0x%s\n", response); auth_ret = 0; out: + kzfree(desc); + crypto_free_shash(tfm); kfree(challenge); kfree(challenge_binhex); return auth_ret; diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c index 2f821de..a24443b 100644 --- a/drivers/target/iscsi/iscsi_target_configfs.c +++ b/drivers/target/iscsi/iscsi_target_configfs.c @@ -771,21 +771,11 @@ static int lio_target_init_nodeacl(struct se_node_acl *se_nacl, { struct iscsi_node_acl *acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl); - struct config_group *stats_cg = &se_nacl->acl_fabric_stat_group; - - stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, - GFP_KERNEL); - if (!stats_cg->default_groups) { - pr_err("Unable to allocate memory for" - " stats_cg->default_groups\n"); - return -ENOMEM; - } - stats_cg->default_groups[0] = &acl->node_stat_grps.iscsi_sess_stats_group; - stats_cg->default_groups[1] = NULL; config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group, "iscsi_sess_stats", &iscsi_stat_sess_cit); - + configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group, + &se_nacl->acl_fabric_stat_group); return 0; } @@ -793,17 +783,8 @@ static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl) { struct iscsi_node_acl *acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl); - struct config_item *df_item; - struct config_group *stats_cg; - int i; - - stats_cg = &acl->se_node_acl.acl_fabric_stat_group; - for (i = 0; stats_cg->default_groups[i]; i++) { - df_item = &stats_cg->default_groups[i]->cg_item; - stats_cg->default_groups[i] = NULL; - config_item_put(df_item); - } - kfree(stats_cg->default_groups); + + configfs_remove_default_groups(&acl->se_node_acl.acl_fabric_stat_group); } /* End items for lio_target_acl_cit */ @@ -1260,42 +1241,37 @@ static struct se_wwn *lio_target_call_coreaddtiqn( struct config_group *group, const char *name) { - struct config_group *stats_cg; struct iscsi_tiqn *tiqn; tiqn = iscsit_add_tiqn((unsigned char *)name); if (IS_ERR(tiqn)) return ERR_CAST(tiqn); - /* - * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group. - */ - stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; - - stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6, - GFP_KERNEL); - if (!stats_cg->default_groups) { - pr_err("Unable to allocate memory for" - " stats_cg->default_groups\n"); - iscsit_del_tiqn(tiqn); - return ERR_PTR(-ENOMEM); - } - stats_cg->default_groups[0] = &tiqn->tiqn_stat_grps.iscsi_instance_group; - stats_cg->default_groups[1] = &tiqn->tiqn_stat_grps.iscsi_sess_err_group; - stats_cg->default_groups[2] = &tiqn->tiqn_stat_grps.iscsi_tgt_attr_group; - stats_cg->default_groups[3] = &tiqn->tiqn_stat_grps.iscsi_login_stats_group; - stats_cg->default_groups[4] = &tiqn->tiqn_stat_grps.iscsi_logout_stats_group; - stats_cg->default_groups[5] = NULL; config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group, "iscsi_instance", &iscsi_stat_instance_cit); + configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group, + &tiqn->tiqn_wwn.fabric_stat_group); + config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group, "iscsi_sess_err", &iscsi_stat_sess_err_cit); + configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group, + &tiqn->tiqn_wwn.fabric_stat_group); + config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group, "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit); + configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group, + &tiqn->tiqn_wwn.fabric_stat_group); + config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group, "iscsi_login_stats", &iscsi_stat_login_cit); + configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group, + &tiqn->tiqn_wwn.fabric_stat_group); + config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group, "iscsi_logout_stats", &iscsi_stat_logout_cit); + configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group, + &tiqn->tiqn_wwn.fabric_stat_group); + pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:" @@ -1307,17 +1283,8 @@ static void lio_target_call_coredeltiqn( struct se_wwn *wwn) { struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); - struct config_item *df_item; - struct config_group *stats_cg; - int i; - - stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; - for (i = 0; stats_cg->default_groups[i]; i++) { - df_item = &stats_cg->default_groups[i]->cg_item; - stats_cg->default_groups[i] = NULL; - config_item_put(df_item); - } - kfree(stats_cg->default_groups); + + configfs_remove_default_groups(&tiqn->tiqn_wwn.fabric_stat_group); pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n", tiqn->tiqn); diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c index 96e78c8..8436d56 100644 --- a/drivers/target/iscsi/iscsi_target_login.c +++ b/drivers/target/iscsi/iscsi_target_login.c @@ -16,9 +16,9 @@ * GNU General Public License for more details. ******************************************************************************/ +#include <crypto/hash.h> #include <linux/string.h> #include <linux/kthread.h> -#include <linux/crypto.h> #include <linux/idr.h> #include <scsi/iscsi_proto.h> #include <target/target_core_base.h> @@ -115,27 +115,36 @@ out_login: */ int iscsi_login_setup_crypto(struct iscsi_conn *conn) { + struct crypto_ahash *tfm; + /* * Setup slicing by CRC32C algorithm for RX and TX libcrypto contexts * which will default to crc32c_intel.ko for cpu_has_xmm4_2, or fallback * to software 1x8 byte slicing from crc32c.ko */ - conn->conn_rx_hash.flags = 0; - conn->conn_rx_hash.tfm = crypto_alloc_hash("crc32c", 0, - CRYPTO_ALG_ASYNC); - if (IS_ERR(conn->conn_rx_hash.tfm)) { - pr_err("crypto_alloc_hash() failed for conn_rx_tfm\n"); + tfm = crypto_alloc_ahash("crc32c", 0, CRYPTO_ALG_ASYNC); + if (IS_ERR(tfm)) { + pr_err("crypto_alloc_ahash() failed\n"); return -ENOMEM; } - conn->conn_tx_hash.flags = 0; - conn->conn_tx_hash.tfm = crypto_alloc_hash("crc32c", 0, - CRYPTO_ALG_ASYNC); - if (IS_ERR(conn->conn_tx_hash.tfm)) { - pr_err("crypto_alloc_hash() failed for conn_tx_tfm\n"); - crypto_free_hash(conn->conn_rx_hash.tfm); + conn->conn_rx_hash = ahash_request_alloc(tfm, GFP_KERNEL); + if (!conn->conn_rx_hash) { + pr_err("ahash_request_alloc() failed for conn_rx_hash\n"); + crypto_free_ahash(tfm); + return -ENOMEM; + } + ahash_request_set_callback(conn->conn_rx_hash, 0, NULL, NULL); + + conn->conn_tx_hash = ahash_request_alloc(tfm, GFP_KERNEL); + if (!conn->conn_tx_hash) { + pr_err("ahash_request_alloc() failed for conn_tx_hash\n"); + ahash_request_free(conn->conn_rx_hash); + conn->conn_rx_hash = NULL; + crypto_free_ahash(tfm); return -ENOMEM; } + ahash_request_set_callback(conn->conn_tx_hash, 0, NULL, NULL); return 0; } @@ -1174,10 +1183,14 @@ old_sess_out: iscsit_dec_session_usage_count(conn->sess); } - if (!IS_ERR(conn->conn_rx_hash.tfm)) - crypto_free_hash(conn->conn_rx_hash.tfm); - if (!IS_ERR(conn->conn_tx_hash.tfm)) - crypto_free_hash(conn->conn_tx_hash.tfm); + ahash_request_free(conn->conn_tx_hash); + if (conn->conn_rx_hash) { + struct crypto_ahash *tfm; + + tfm = crypto_ahash_reqtfm(conn->conn_rx_hash); + ahash_request_free(conn->conn_rx_hash); + crypto_free_ahash(tfm); + } free_cpumask_var(conn->conn_cpumask); diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 713c63d9..d498533 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -194,13 +194,11 @@ static struct config_group *target_core_register_fabric( pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n", &tf->tf_wwn_cit); - tf->tf_group.default_groups = tf->tf_default_groups; - tf->tf_group.default_groups[0] = &tf->tf_disc_group; - tf->tf_group.default_groups[1] = NULL; - config_group_init_type_name(&tf->tf_group, name, &tf->tf_wwn_cit); + config_group_init_type_name(&tf->tf_disc_group, "discovery_auth", &tf->tf_discovery_cit); + configfs_add_default_group(&tf->tf_disc_group, &tf->tf_group); pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:" " %s\n", tf->tf_group.cg_item.ci_name); @@ -216,9 +214,6 @@ static void target_core_deregister_fabric( { struct target_fabric_configfs *tf = container_of( to_config_group(item), struct target_fabric_configfs, tf_group); - struct config_group *tf_group; - struct config_item *df_item; - int i; pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in" " tf list\n", config_item_name(item)); @@ -230,12 +225,7 @@ static void target_core_deregister_fabric( pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci" " %s\n", config_item_name(item)); - tf_group = &tf->tf_group; - for (i = 0; tf_group->default_groups[i]; i++) { - df_item = &tf_group->default_groups[i]->cg_item; - tf_group->default_groups[i] = NULL; - config_item_put(df_item); - } + configfs_remove_default_groups(&tf->tf_group); config_item_put(item); } @@ -2151,7 +2141,6 @@ static void target_core_dev_release(struct config_item *item) struct se_device *dev = container_of(dev_cg, struct se_device, dev_group); - kfree(dev_cg->default_groups); target_free_device(dev); } @@ -2819,8 +2808,6 @@ static struct config_group *target_core_make_subdev( struct se_hba *hba = item_to_hba(hba_ci); struct target_backend *tb = hba->backend; struct se_device *dev; - struct config_group *dev_cg = NULL, *tg_pt_gp_cg = NULL; - struct config_group *dev_stat_grp = NULL; int errno = -ENOMEM, ret; ret = mutex_lock_interruptible(&hba->hba_access_mutex); @@ -2831,73 +2818,52 @@ static struct config_group *target_core_make_subdev( if (!dev) goto out_unlock; - dev_cg = &dev->dev_group; - - dev_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6, - GFP_KERNEL); - if (!dev_cg->default_groups) - goto out_free_device; + config_group_init_type_name(&dev->dev_group, name, &tb->tb_dev_cit); - config_group_init_type_name(dev_cg, name, &tb->tb_dev_cit); config_group_init_type_name(&dev->dev_attrib.da_group, "attrib", &tb->tb_dev_attrib_cit); + configfs_add_default_group(&dev->dev_attrib.da_group, &dev->dev_group); + config_group_init_type_name(&dev->dev_pr_group, "pr", &tb->tb_dev_pr_cit); + configfs_add_default_group(&dev->dev_pr_group, &dev->dev_group); + config_group_init_type_name(&dev->t10_wwn.t10_wwn_group, "wwn", &tb->tb_dev_wwn_cit); + configfs_add_default_group(&dev->t10_wwn.t10_wwn_group, + &dev->dev_group); + config_group_init_type_name(&dev->t10_alua.alua_tg_pt_gps_group, "alua", &tb->tb_dev_alua_tg_pt_gps_cit); + configfs_add_default_group(&dev->t10_alua.alua_tg_pt_gps_group, + &dev->dev_group); + config_group_init_type_name(&dev->dev_stat_grps.stat_group, "statistics", &tb->tb_dev_stat_cit); + configfs_add_default_group(&dev->dev_stat_grps.stat_group, + &dev->dev_group); - dev_cg->default_groups[0] = &dev->dev_attrib.da_group; - dev_cg->default_groups[1] = &dev->dev_pr_group; - dev_cg->default_groups[2] = &dev->t10_wwn.t10_wwn_group; - dev_cg->default_groups[3] = &dev->t10_alua.alua_tg_pt_gps_group; - dev_cg->default_groups[4] = &dev->dev_stat_grps.stat_group; - dev_cg->default_groups[5] = NULL; /* * Add core/$HBA/$DEV/alua/default_tg_pt_gp */ tg_pt_gp = core_alua_allocate_tg_pt_gp(dev, "default_tg_pt_gp", 1); if (!tg_pt_gp) - goto out_free_dev_cg_default_groups; + goto out_free_device; dev->t10_alua.default_tg_pt_gp = tg_pt_gp; - tg_pt_gp_cg = &dev->t10_alua.alua_tg_pt_gps_group; - tg_pt_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, - GFP_KERNEL); - if (!tg_pt_gp_cg->default_groups) { - pr_err("Unable to allocate tg_pt_gp_cg->" - "default_groups\n"); - goto out_free_tg_pt_gp; - } - config_group_init_type_name(&tg_pt_gp->tg_pt_gp_group, "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit); - tg_pt_gp_cg->default_groups[0] = &tg_pt_gp->tg_pt_gp_group; - tg_pt_gp_cg->default_groups[1] = NULL; + configfs_add_default_group(&tg_pt_gp->tg_pt_gp_group, + &dev->t10_alua.alua_tg_pt_gps_group); + /* * Add core/$HBA/$DEV/statistics/ default groups */ - dev_stat_grp = &dev->dev_stat_grps.stat_group; - dev_stat_grp->default_groups = kmalloc(sizeof(struct config_group *) * 4, - GFP_KERNEL); - if (!dev_stat_grp->default_groups) { - pr_err("Unable to allocate dev_stat_grp->default_groups\n"); - goto out_free_tg_pt_gp_cg_default_groups; - } target_stat_setup_dev_default_groups(dev); mutex_unlock(&hba->hba_access_mutex); - return dev_cg; + return &dev->dev_group; -out_free_tg_pt_gp_cg_default_groups: - kfree(tg_pt_gp_cg->default_groups); -out_free_tg_pt_gp: - core_alua_free_tg_pt_gp(tg_pt_gp); -out_free_dev_cg_default_groups: - kfree(dev_cg->default_groups); out_free_device: target_free_device(dev); out_unlock: @@ -2913,40 +2879,22 @@ static void target_core_drop_subdev( struct se_device *dev = container_of(dev_cg, struct se_device, dev_group); struct se_hba *hba; - struct config_item *df_item; - struct config_group *tg_pt_gp_cg, *dev_stat_grp; - int i; hba = item_to_hba(&dev->se_hba->hba_group.cg_item); mutex_lock(&hba->hba_access_mutex); - dev_stat_grp = &dev->dev_stat_grps.stat_group; - for (i = 0; dev_stat_grp->default_groups[i]; i++) { - df_item = &dev_stat_grp->default_groups[i]->cg_item; - dev_stat_grp->default_groups[i] = NULL; - config_item_put(df_item); - } - kfree(dev_stat_grp->default_groups); + configfs_remove_default_groups(&dev->dev_stat_grps.stat_group); + configfs_remove_default_groups(&dev->t10_alua.alua_tg_pt_gps_group); - tg_pt_gp_cg = &dev->t10_alua.alua_tg_pt_gps_group; - for (i = 0; tg_pt_gp_cg->default_groups[i]; i++) { - df_item = &tg_pt_gp_cg->default_groups[i]->cg_item; - tg_pt_gp_cg->default_groups[i] = NULL; - config_item_put(df_item); - } - kfree(tg_pt_gp_cg->default_groups); /* * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp * directly from target_core_alua_tg_pt_gp_release(). */ dev->t10_alua.default_tg_pt_gp = NULL; - for (i = 0; dev_cg->default_groups[i]; i++) { - df_item = &dev_cg->default_groups[i]->cg_item; - dev_cg->default_groups[i] = NULL; - config_item_put(df_item); - } + configfs_remove_default_groups(dev_cg); + /* * se_dev is released from target_core_dev_item_ops->release() */ @@ -3141,8 +3089,6 @@ void target_setup_backend_cits(struct target_backend *tb) static int __init target_core_init_configfs(void) { - struct config_group *target_cg, *hba_cg = NULL, *alua_cg = NULL; - struct config_group *lu_gp_cg = NULL; struct configfs_subsystem *subsys = &target_core_fabrics; struct t10_alua_lu_gp *lu_gp; int ret; @@ -3161,51 +3107,24 @@ static int __init target_core_init_configfs(void) * Create $CONFIGFS/target/core default group for HBA <-> Storage Object * and ALUA Logical Unit Group and Target Port Group infrastructure. */ - target_cg = &subsys->su_group; - target_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, - GFP_KERNEL); - if (!target_cg->default_groups) { - pr_err("Unable to allocate target_cg->default_groups\n"); - ret = -ENOMEM; - goto out_global; - } + config_group_init_type_name(&target_core_hbagroup, "core", + &target_core_cit); + configfs_add_default_group(&target_core_hbagroup, &subsys->su_group); - config_group_init_type_name(&target_core_hbagroup, - "core", &target_core_cit); - target_cg->default_groups[0] = &target_core_hbagroup; - target_cg->default_groups[1] = NULL; /* * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/ */ - hba_cg = &target_core_hbagroup; - hba_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, - GFP_KERNEL); - if (!hba_cg->default_groups) { - pr_err("Unable to allocate hba_cg->default_groups\n"); - ret = -ENOMEM; - goto out_global; - } - config_group_init_type_name(&alua_group, - "alua", &target_core_alua_cit); - hba_cg->default_groups[0] = &alua_group; - hba_cg->default_groups[1] = NULL; + config_group_init_type_name(&alua_group, "alua", &target_core_alua_cit); + configfs_add_default_group(&alua_group, &target_core_hbagroup); + /* * Add ALUA Logical Unit Group and Target Port Group ConfigFS * groups under /sys/kernel/config/target/core/alua/ */ - alua_cg = &alua_group; - alua_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, - GFP_KERNEL); - if (!alua_cg->default_groups) { - pr_err("Unable to allocate alua_cg->default_groups\n"); - ret = -ENOMEM; - goto out_global; - } + config_group_init_type_name(&alua_lu_gps_group, "lu_gps", + &target_core_alua_lu_gps_cit); + configfs_add_default_group(&alua_lu_gps_group, &alua_group); - config_group_init_type_name(&alua_lu_gps_group, - "lu_gps", &target_core_alua_lu_gps_cit); - alua_cg->default_groups[0] = &alua_lu_gps_group; - alua_cg->default_groups[1] = NULL; /* * Add core/alua/lu_gps/default_lu_gp */ @@ -3215,20 +3134,12 @@ static int __init target_core_init_configfs(void) goto out_global; } - lu_gp_cg = &alua_lu_gps_group; - lu_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, - GFP_KERNEL); - if (!lu_gp_cg->default_groups) { - pr_err("Unable to allocate lu_gp_cg->default_groups\n"); - ret = -ENOMEM; - goto out_global; - } - config_group_init_type_name(&lu_gp->lu_gp_group, "default_lu_gp", &target_core_alua_lu_gp_cit); - lu_gp_cg->default_groups[0] = &lu_gp->lu_gp_group; - lu_gp_cg->default_groups[1] = NULL; + configfs_add_default_group(&lu_gp->lu_gp_group, &alua_lu_gps_group); + default_lu_gp = lu_gp; + /* * Register the target_core_mod subsystem with configfs. */ @@ -3267,55 +3178,21 @@ out_global: core_alua_free_lu_gp(default_lu_gp); default_lu_gp = NULL; } - if (lu_gp_cg) - kfree(lu_gp_cg->default_groups); - if (alua_cg) - kfree(alua_cg->default_groups); - if (hba_cg) - kfree(hba_cg->default_groups); - kfree(target_cg->default_groups); release_se_kmem_caches(); return ret; } static void __exit target_core_exit_configfs(void) { - struct config_group *hba_cg, *alua_cg, *lu_gp_cg; - struct config_item *item; - int i; + configfs_remove_default_groups(&alua_lu_gps_group); + configfs_remove_default_groups(&alua_group); + configfs_remove_default_groups(&target_core_hbagroup); - lu_gp_cg = &alua_lu_gps_group; - for (i = 0; lu_gp_cg->default_groups[i]; i++) { - item = &lu_gp_cg->default_groups[i]->cg_item; - lu_gp_cg->default_groups[i] = NULL; - config_item_put(item); - } - kfree(lu_gp_cg->default_groups); - lu_gp_cg->default_groups = NULL; - - alua_cg = &alua_group; - for (i = 0; alua_cg->default_groups[i]; i++) { - item = &alua_cg->default_groups[i]->cg_item; - alua_cg->default_groups[i] = NULL; - config_item_put(item); - } - kfree(alua_cg->default_groups); - alua_cg->default_groups = NULL; - - hba_cg = &target_core_hbagroup; - for (i = 0; hba_cg->default_groups[i]; i++) { - item = &hba_cg->default_groups[i]->cg_item; - hba_cg->default_groups[i] = NULL; - config_item_put(item); - } - kfree(hba_cg->default_groups); - hba_cg->default_groups = NULL; /* * We expect subsys->su_group.default_groups to be released * by configfs subsystem provider logic.. */ configfs_unregister_subsystem(&target_core_fabrics); - kfree(target_core_fabrics.su_group.default_groups); core_alua_free_lu_gp(default_lu_gp); default_lu_gp = NULL; diff --git a/drivers/target/target_core_fabric_configfs.c b/drivers/target/target_core_fabric_configfs.c index f916d18..8caef31 100644 --- a/drivers/target/target_core_fabric_configfs.c +++ b/drivers/target/target_core_fabric_configfs.c @@ -273,18 +273,10 @@ static struct config_group *target_fabric_make_mappedlun( struct se_portal_group *se_tpg = se_nacl->se_tpg; struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; struct se_lun_acl *lacl = NULL; - struct config_item *acl_ci; - struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL; char *buf; unsigned long long mapped_lun; int ret = 0; - acl_ci = &group->cg_item; - if (!acl_ci) { - pr_err("Unable to locatel acl_ci\n"); - return NULL; - } - buf = kzalloc(strlen(name) + 1, GFP_KERNEL); if (!buf) { pr_err("Unable to allocate memory for name buf\n"); @@ -315,37 +307,19 @@ static struct config_group *target_fabric_make_mappedlun( goto out; } - lacl_cg = &lacl->se_lun_group; - lacl_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, - GFP_KERNEL); - if (!lacl_cg->default_groups) { - pr_err("Unable to allocate lacl_cg->default_groups\n"); - ret = -ENOMEM; - goto out; - } - config_group_init_type_name(&lacl->se_lun_group, name, &tf->tf_tpg_mappedlun_cit); + config_group_init_type_name(&lacl->ml_stat_grps.stat_group, "statistics", &tf->tf_tpg_mappedlun_stat_cit); - lacl_cg->default_groups[0] = &lacl->ml_stat_grps.stat_group; - lacl_cg->default_groups[1] = NULL; - - ml_stat_grp = &lacl->ml_stat_grps.stat_group; - ml_stat_grp->default_groups = kmalloc(sizeof(struct config_group *) * 3, - GFP_KERNEL); - if (!ml_stat_grp->default_groups) { - pr_err("Unable to allocate ml_stat_grp->default_groups\n"); - ret = -ENOMEM; - goto out; - } + configfs_add_default_group(&lacl->ml_stat_grps.stat_group, + &lacl->se_lun_group); + target_stat_setup_mappedlun_default_groups(lacl); kfree(buf); return &lacl->se_lun_group; out: - if (lacl_cg) - kfree(lacl_cg->default_groups); kfree(lacl); kfree(buf); return ERR_PTR(ret); @@ -357,25 +331,9 @@ static void target_fabric_drop_mappedlun( { struct se_lun_acl *lacl = container_of(to_config_group(item), struct se_lun_acl, se_lun_group); - struct config_item *df_item; - struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL; - int i; - - ml_stat_grp = &lacl->ml_stat_grps.stat_group; - for (i = 0; ml_stat_grp->default_groups[i]; i++) { - df_item = &ml_stat_grp->default_groups[i]->cg_item; - ml_stat_grp->default_groups[i] = NULL; - config_item_put(df_item); - } - kfree(ml_stat_grp->default_groups); - lacl_cg = &lacl->se_lun_group; - for (i = 0; lacl_cg->default_groups[i]; i++) { - df_item = &lacl_cg->default_groups[i]->cg_item; - lacl_cg->default_groups[i] = NULL; - config_item_put(df_item); - } - kfree(lacl_cg->default_groups); + configfs_remove_default_groups(&lacl->ml_stat_grps.stat_group); + configfs_remove_default_groups(&lacl->se_lun_group); config_item_put(item); } @@ -424,7 +382,6 @@ static struct config_group *target_fabric_make_nodeacl( struct se_portal_group, tpg_acl_group); struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; struct se_node_acl *se_nacl; - struct config_group *nacl_cg; se_nacl = core_tpg_add_initiator_node_acl(se_tpg, name); if (IS_ERR(se_nacl)) @@ -438,24 +395,28 @@ static struct config_group *target_fabric_make_nodeacl( } } - nacl_cg = &se_nacl->acl_group; - nacl_cg->default_groups = se_nacl->acl_default_groups; - nacl_cg->default_groups[0] = &se_nacl->acl_attrib_group; - nacl_cg->default_groups[1] = &se_nacl->acl_auth_group; - nacl_cg->default_groups[2] = &se_nacl->acl_param_group; - nacl_cg->default_groups[3] = &se_nacl->acl_fabric_stat_group; - nacl_cg->default_groups[4] = NULL; - config_group_init_type_name(&se_nacl->acl_group, name, &tf->tf_tpg_nacl_base_cit); + config_group_init_type_name(&se_nacl->acl_attrib_group, "attrib", &tf->tf_tpg_nacl_attrib_cit); + configfs_add_default_group(&se_nacl->acl_attrib_group, + &se_nacl->acl_group); + config_group_init_type_name(&se_nacl->acl_auth_group, "auth", &tf->tf_tpg_nacl_auth_cit); + configfs_add_default_group(&se_nacl->acl_auth_group, + &se_nacl->acl_group); + config_group_init_type_name(&se_nacl->acl_param_group, "param", &tf->tf_tpg_nacl_param_cit); + configfs_add_default_group(&se_nacl->acl_param_group, + &se_nacl->acl_group); + config_group_init_type_name(&se_nacl->acl_fabric_stat_group, "fabric_statistics", &tf->tf_tpg_nacl_stat_cit); + configfs_add_default_group(&se_nacl->acl_fabric_stat_group, + &se_nacl->acl_group); return &se_nacl->acl_group; } @@ -466,16 +427,9 @@ static void target_fabric_drop_nodeacl( { struct se_node_acl *se_nacl = container_of(to_config_group(item), struct se_node_acl, acl_group); - struct config_item *df_item; - struct config_group *nacl_cg; - int i; - - nacl_cg = &se_nacl->acl_group; - for (i = 0; nacl_cg->default_groups[i]; i++) { - df_item = &nacl_cg->default_groups[i]->cg_item; - nacl_cg->default_groups[i] = NULL; - config_item_put(df_item); - } + + configfs_remove_default_groups(&se_nacl->acl_group); + /* * struct se_node_acl free is done in target_fabric_nacl_base_release() */ @@ -795,7 +749,6 @@ static struct config_group *target_fabric_make_lun( struct se_portal_group *se_tpg = container_of(group, struct se_portal_group, tpg_lun_group); struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; - struct config_group *lun_cg = NULL, *port_stat_grp = NULL; unsigned long long unpacked_lun; int errno; @@ -812,31 +765,14 @@ static struct config_group *target_fabric_make_lun( if (IS_ERR(lun)) return ERR_CAST(lun); - lun_cg = &lun->lun_group; - lun_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, - GFP_KERNEL); - if (!lun_cg->default_groups) { - pr_err("Unable to allocate lun_cg->default_groups\n"); - kfree(lun); - return ERR_PTR(-ENOMEM); - } - config_group_init_type_name(&lun->lun_group, name, &tf->tf_tpg_port_cit); + config_group_init_type_name(&lun->port_stat_grps.stat_group, "statistics", &tf->tf_tpg_port_stat_cit); - lun_cg->default_groups[0] = &lun->port_stat_grps.stat_group; - lun_cg->default_groups[1] = NULL; - - port_stat_grp = &lun->port_stat_grps.stat_group; - port_stat_grp->default_groups = kzalloc(sizeof(struct config_group *) * 4, - GFP_KERNEL); - if (!port_stat_grp->default_groups) { - pr_err("Unable to allocate port_stat_grp->default_groups\n"); - kfree(lun_cg->default_groups); - kfree(lun); - return ERR_PTR(-ENOMEM); - } + configfs_add_default_group(&lun->port_stat_grps.stat_group, + &lun->lun_group); + target_stat_setup_port_default_groups(lun); return &lun->lun_group; @@ -848,25 +784,9 @@ static void target_fabric_drop_lun( { struct se_lun *lun = container_of(to_config_group(item), struct se_lun, lun_group); - struct config_item *df_item; - struct config_group *lun_cg, *port_stat_grp; - int i; - - port_stat_grp = &lun->port_stat_grps.stat_group; - for (i = 0; port_stat_grp->default_groups[i]; i++) { - df_item = &port_stat_grp->default_groups[i]->cg_item; - port_stat_grp->default_groups[i] = NULL; - config_item_put(df_item); - } - kfree(port_stat_grp->default_groups); - lun_cg = &lun->lun_group; - for (i = 0; lun_cg->default_groups[i]; i++) { - df_item = &lun_cg->default_groups[i]->cg_item; - lun_cg->default_groups[i] = NULL; - config_item_put(df_item); - } - kfree(lun_cg->default_groups); + configfs_remove_default_groups(&lun->port_stat_grps.stat_group); + configfs_remove_default_groups(&lun->lun_group); config_item_put(item); } @@ -922,32 +842,39 @@ static struct config_group *target_fabric_make_tpg( se_tpg = tf->tf_ops->fabric_make_tpg(wwn, group, name); if (!se_tpg || IS_ERR(se_tpg)) return ERR_PTR(-EINVAL); - /* - * Setup default groups from pre-allocated se_tpg->tpg_default_groups - */ - se_tpg->tpg_group.default_groups = se_tpg->tpg_default_groups; - se_tpg->tpg_group.default_groups[0] = &se_tpg->tpg_lun_group; - se_tpg->tpg_group.default_groups[1] = &se_tpg->tpg_np_group; - se_tpg->tpg_group.default_groups[2] = &se_tpg->tpg_acl_group; - se_tpg->tpg_group.default_groups[3] = &se_tpg->tpg_attrib_group; - se_tpg->tpg_group.default_groups[4] = &se_tpg->tpg_auth_group; - se_tpg->tpg_group.default_groups[5] = &se_tpg->tpg_param_group; - se_tpg->tpg_group.default_groups[6] = NULL; config_group_init_type_name(&se_tpg->tpg_group, name, &tf->tf_tpg_base_cit); + config_group_init_type_name(&se_tpg->tpg_lun_group, "lun", &tf->tf_tpg_lun_cit); + configfs_add_default_group(&se_tpg->tpg_lun_group, + &se_tpg->tpg_group); + config_group_init_type_name(&se_tpg->tpg_np_group, "np", &tf->tf_tpg_np_cit); + configfs_add_default_group(&se_tpg->tpg_np_group, + &se_tpg->tpg_group); + config_group_init_type_name(&se_tpg->tpg_acl_group, "acls", &tf->tf_tpg_nacl_cit); + configfs_add_default_group(&se_tpg->tpg_acl_group, + &se_tpg->tpg_group); + config_group_init_type_name(&se_tpg->tpg_attrib_group, "attrib", &tf->tf_tpg_attrib_cit); + configfs_add_default_group(&se_tpg->tpg_attrib_group, + &se_tpg->tpg_group); + config_group_init_type_name(&se_tpg->tpg_auth_group, "auth", &tf->tf_tpg_auth_cit); + configfs_add_default_group(&se_tpg->tpg_auth_group, + &se_tpg->tpg_group); + config_group_init_type_name(&se_tpg->tpg_param_group, "param", &tf->tf_tpg_param_cit); + configfs_add_default_group(&se_tpg->tpg_param_group, + &se_tpg->tpg_group); return &se_tpg->tpg_group; } @@ -958,19 +885,8 @@ static void target_fabric_drop_tpg( { struct se_portal_group *se_tpg = container_of(to_config_group(item), struct se_portal_group, tpg_group); - struct config_group *tpg_cg = &se_tpg->tpg_group; - struct config_item *df_item; - int i; - /* - * Release default groups, but do not release tpg_cg->default_groups - * memory as it is statically allocated at se_tpg->tpg_default_groups. - */ - for (i = 0; tpg_cg->default_groups[i]; i++) { - df_item = &tpg_cg->default_groups[i]->cg_item; - tpg_cg->default_groups[i] = NULL; - config_item_put(df_item); - } + configfs_remove_default_groups(&se_tpg->tpg_group); config_item_put(item); } @@ -1026,16 +942,12 @@ static struct config_group *target_fabric_make_wwn( return ERR_PTR(-EINVAL); wwn->wwn_tf = tf; - /* - * Setup default groups from pre-allocated wwn->wwn_default_groups - */ - wwn->wwn_group.default_groups = wwn->wwn_default_groups; - wwn->wwn_group.default_groups[0] = &wwn->fabric_stat_group; - wwn->wwn_group.default_groups[1] = NULL; config_group_init_type_name(&wwn->wwn_group, name, &tf->tf_tpg_cit); + config_group_init_type_name(&wwn->fabric_stat_group, "fabric_statistics", &tf->tf_wwn_fabric_stats_cit); + configfs_add_default_group(&wwn->fabric_stat_group, &wwn->wwn_group); return &wwn->wwn_group; } @@ -1046,16 +958,8 @@ static void target_fabric_drop_wwn( { struct se_wwn *wwn = container_of(to_config_group(item), struct se_wwn, wwn_group); - struct config_item *df_item; - struct config_group *cg = &wwn->wwn_group; - int i; - - for (i = 0; cg->default_groups[i]; i++) { - df_item = &cg->default_groups[i]->cg_item; - cg->default_groups[i] = NULL; - config_item_put(df_item); - } + configfs_remove_default_groups(&wwn->wwn_group); config_item_put(item); } diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index db4412f..4a7cf49 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h @@ -22,7 +22,6 @@ struct target_fabric_configfs { struct list_head tf_list; struct config_group tf_group; struct config_group tf_disc_group; - struct config_group *tf_default_groups[2]; const struct target_core_fabric_ops *tf_ops; struct config_item_type tf_discovery_cit; diff --git a/drivers/target/target_core_stat.c b/drivers/target/target_core_stat.c index 81a6b3e..1a39033 100644 --- a/drivers/target/target_core_stat.c +++ b/drivers/target/target_core_stat.c @@ -407,19 +407,20 @@ static struct config_item_type target_stat_scsi_lu_cit = { */ void target_stat_setup_dev_default_groups(struct se_device *dev) { - struct config_group *dev_stat_grp = &dev->dev_stat_grps.stat_group; - config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group, "scsi_dev", &target_stat_scsi_dev_cit); + configfs_add_default_group(&dev->dev_stat_grps.scsi_dev_group, + &dev->dev_stat_grps.stat_group); + config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group, "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit); + configfs_add_default_group(&dev->dev_stat_grps.scsi_tgt_dev_group, + &dev->dev_stat_grps.stat_group); + config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group, "scsi_lu", &target_stat_scsi_lu_cit); - - dev_stat_grp->default_groups[0] = &dev->dev_stat_grps.scsi_dev_group; - dev_stat_grp->default_groups[1] = &dev->dev_stat_grps.scsi_tgt_dev_group; - dev_stat_grp->default_groups[2] = &dev->dev_stat_grps.scsi_lu_group; - dev_stat_grp->default_groups[3] = NULL; + configfs_add_default_group(&dev->dev_stat_grps.scsi_lu_group, + &dev->dev_stat_grps.stat_group); } /* @@ -818,19 +819,20 @@ static struct config_item_type target_stat_scsi_transport_cit = { */ void target_stat_setup_port_default_groups(struct se_lun *lun) { - struct config_group *port_stat_grp = &lun->port_stat_grps.stat_group; - config_group_init_type_name(&lun->port_stat_grps.scsi_port_group, "scsi_port", &target_stat_scsi_port_cit); + configfs_add_default_group(&lun->port_stat_grps.scsi_port_group, + &lun->port_stat_grps.stat_group); + config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group, "scsi_tgt_port", &target_stat_scsi_tgt_port_cit); + configfs_add_default_group(&lun->port_stat_grps.scsi_tgt_port_group, + &lun->port_stat_grps.stat_group); + config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group, "scsi_transport", &target_stat_scsi_transport_cit); - - port_stat_grp->default_groups[0] = &lun->port_stat_grps.scsi_port_group; - port_stat_grp->default_groups[1] = &lun->port_stat_grps.scsi_tgt_port_group; - port_stat_grp->default_groups[2] = &lun->port_stat_grps.scsi_transport_group; - port_stat_grp->default_groups[3] = NULL; + configfs_add_default_group(&lun->port_stat_grps.scsi_transport_group, + &lun->port_stat_grps.stat_group); } /* @@ -1351,14 +1353,13 @@ static struct config_item_type target_stat_scsi_att_intr_port_cit = { */ void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl) { - struct config_group *ml_stat_grp = &lacl->ml_stat_grps.stat_group; - config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group, "scsi_auth_intr", &target_stat_scsi_auth_intr_cit); + configfs_add_default_group(&lacl->ml_stat_grps.scsi_auth_intr_group, + &lacl->ml_stat_grps.stat_group); + config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group, "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit); - - ml_stat_grp->default_groups[0] = &lacl->ml_stat_grps.scsi_auth_intr_group; - ml_stat_grp->default_groups[1] = &lacl->ml_stat_grps.scsi_att_intr_port_group; - ml_stat_grp->default_groups[2] = NULL; + configfs_add_default_group(&lacl->ml_stat_grps.scsi_att_intr_port_group, + &lacl->ml_stat_grps.stat_group); } diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 82a663b..4f229e7 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -177,7 +177,6 @@ void core_tmr_abort_task( if (!__target_check_io_state(se_cmd, se_sess, 0)) { spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); - target_put_sess_cmd(se_cmd); goto out; } list_del_init(&se_cmd->se_cmd_list); |