コード例 #1
0
ファイル: tfc_sess.c プロジェクト: 33d/linux-2.6.21-hh20
/*
 * Allocate session and enter it in the hash for the local port.
 * Caller holds ft_lport_lock.
 */
static struct ft_sess *ft_sess_create(struct ft_tport *tport, u32 port_id,
				      struct ft_node_acl *acl)
{
	struct ft_sess *sess;
	struct hlist_head *head;
	struct hlist_node *pos;

	head = &tport->hash[ft_sess_hash(port_id)];
	hlist_for_each_entry_rcu(sess, pos, head, hash)
		if (sess->port_id == port_id)
			return sess;

	sess = kzalloc(sizeof(*sess), GFP_KERNEL);
	if (!sess)
		return NULL;

	sess->se_sess = transport_init_session();
	if (IS_ERR(sess->se_sess)) {
		kfree(sess);
		return NULL;
	}
	sess->se_sess->se_node_acl = &acl->se_node_acl;
	sess->tport = tport;
	sess->port_id = port_id;
	kref_init(&sess->kref);	/* ref for table entry */
	hlist_add_head_rcu(&sess->hash, head);
	tport->sess_count++;

	pr_debug("port_id %x sess %p\n", port_id, sess);

	transport_register_session(&tport->tpg->se_tpg, &acl->se_node_acl,
				   sess->se_sess, sess);
	return sess;
}
コード例 #2
0
int target_xcopy_setup_pt(void)
{
	int ret;

	xcopy_wq = alloc_workqueue("xcopy_wq", WQ_MEM_RECLAIM, 0);
	if (!xcopy_wq) {
		pr_err("Unable to allocate xcopy_wq\n");
		return -ENOMEM;
	}

	memset(&xcopy_pt_tpg, 0, sizeof(struct se_portal_group));
	INIT_LIST_HEAD(&xcopy_pt_tpg.se_tpg_node);
	INIT_LIST_HEAD(&xcopy_pt_tpg.acl_node_list);
	INIT_LIST_HEAD(&xcopy_pt_tpg.tpg_sess_list);

	xcopy_pt_tpg.se_tpg_tfo = &xcopy_pt_tfo;

	memset(&xcopy_pt_nacl, 0, sizeof(struct se_node_acl));
	INIT_LIST_HEAD(&xcopy_pt_nacl.acl_list);
	INIT_LIST_HEAD(&xcopy_pt_nacl.acl_sess_list);
	memset(&xcopy_pt_sess, 0, sizeof(struct se_session));
	ret = transport_init_session(&xcopy_pt_sess);
	if (ret < 0)
		return ret;

	xcopy_pt_nacl.se_tpg = &xcopy_pt_tpg;
	xcopy_pt_nacl.nacl_sess = &xcopy_pt_sess;

	xcopy_pt_sess.se_tpg = &xcopy_pt_tpg;
	xcopy_pt_sess.se_node_acl = &xcopy_pt_nacl;

	return 0;
}
コード例 #3
0
ファイル: tcm_loop.c プロジェクト: JackWangCUMT/linux
static int tcm_loop_make_nexus(
    struct tcm_loop_tpg *tl_tpg,
    const char *name)
{
    struct se_portal_group *se_tpg;
    struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
    struct tcm_loop_nexus *tl_nexus;
    int ret = -ENOMEM;

    if (tl_tpg->tl_hba->tl_nexus) {
        pr_debug("tl_tpg->tl_hba->tl_nexus already exists\n");
        return -EEXIST;
    }
    se_tpg = &tl_tpg->tl_se_tpg;

    tl_nexus = kzalloc(sizeof(struct tcm_loop_nexus), GFP_KERNEL);
    if (!tl_nexus) {
        pr_err("Unable to allocate struct tcm_loop_nexus\n");
        return -ENOMEM;
    }
    /*
     * Initialize the struct se_session pointer
     */
    tl_nexus->se_sess = transport_init_session();
    if (IS_ERR(tl_nexus->se_sess)) {
        ret = PTR_ERR(tl_nexus->se_sess);
        goto out;
    }
    /*
     * Since we are running in 'demo mode' this call with generate a
     * struct se_node_acl for the tcm_loop struct se_portal_group with the SCSI
     * Initiator port name of the passed configfs group 'name'.
     */
    tl_nexus->se_sess->se_node_acl = core_tpg_check_initiator_node_acl(
                                         se_tpg, (unsigned char *)name);
    if (!tl_nexus->se_sess->se_node_acl) {
        transport_free_session(tl_nexus->se_sess);
        goto out;
    }
    /*
     * Now, register the SAS I_T Nexus as active with the call to
     * transport_register_session()
     */
    __transport_register_session(se_tpg, tl_nexus->se_sess->se_node_acl,
                                 tl_nexus->se_sess, tl_nexus);
    tl_tpg->tl_hba->tl_nexus = tl_nexus;
    pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated"
             " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba),
             name);
    return 0;

out:
    kfree(tl_nexus);
    return ret;
}