/*
 * Disconnect from the target
 */
void iSCSILibWrapper::iSCSIDisconnect(void)
{
    // Remove us from the background thread
    iSCSIBackGround::GetInstance().RemoveConnection(*this);

    if (!mIscsi)
    {
        mErrorString.Format("%s: Disconnect from target %s not possible without a connection!",
                            __func__,
                            mTarget.c_str());
        mError = true;
        throw CException(mErrorString);
    }

    if (mClient.connected && iscsi_disconnect(mIscsi))
    {
        mErrorString.Format("%s: Failed to disconnect from target %s disconnect: %s",
                           __func__,
                           mAddress.c_str(),
                           iscsi_get_error(mIscsi));
        mError = true;
        throw CException(mErrorString);
    }

    mClient.finished = 0;

    iscsi_destroy_context(mIscsi);
    mIscsi = NULL;
    mClient.connected = 0; // We are no longer connected
    mClient.error = 0;     // There can be no error from here on in
}
示例#2
0
void discoverylogout_cb(struct iscsi_context *iscsi, int status, void *command_data, void *private_data)
{
	struct client_state *clnt = (struct client_state *)private_data;
	
	printf("discovery session logged out, Message from main() was:[%s]\n", clnt->message);

	printf("disconnect socket\n");
	if (iscsi_disconnect(iscsi) != 0) {
		printf("Failed to disconnect old socket\n");
		exit(10);
	}

	printf("reconnect with normal login to [%s]\n", clnt->target_address);
	printf("Use targetname [%s] when connecting\n", clnt->target_name);
	if (iscsi_set_targetname(iscsi, clnt->target_name)) {
		printf("Failed to set target name\n");
		exit(10);
	}
	if (iscsi_set_alias(iscsi, "ronnie") != 0) {
		printf("Failed to add alias\n");
		exit(10);
	}
	if (iscsi_set_session_type(iscsi, ISCSI_SESSION_NORMAL) != 0) {
		printf("Failed to set settion type to normal\n");
		exit(10);
	}

	if (iscsi_connect_async(iscsi, clnt->target_address, normalconnect_cb, clnt) != 0) {
		printf("iscsi_connect failed\n");
		exit(10);
	}
}
iSCSILibWrapper::~iSCSILibWrapper()
{
    // This ungracefully shuts down the session
    if (mClient.connected)
        iscsi_disconnect(mIscsi);
    if (mClient.error_message)
        free(mClient.error_message);
    if (mClient.target_name)
        free(mClient.target_name);
    if (mClient.target_address)
        free(mClient.target_address);
    if (mIscsi)
        iscsi_destroy_context(mIscsi);
}
示例#4
0
文件: init.c 项目: dooglus/ccan
int iscsi_destroy_context(struct iscsi_context *iscsi)
{
    struct iscsi_pdu *pdu;

    if (iscsi == NULL) {
        return 0;
    }
    if (iscsi->initiator_name != NULL) {
        free(discard_const(iscsi->initiator_name));
        iscsi->initiator_name = NULL;
    }
    if (iscsi->alias != NULL) {
        free(discard_const(iscsi->alias));
        iscsi->alias = NULL;
    }
    if (iscsi->is_loggedin != 0) {
        printf("deswtroying context while logged in\n");
    }
    if (iscsi->fd != -1) {
        iscsi_disconnect(iscsi);
    }

    if (iscsi->inbuf != NULL) {
        free(iscsi->inbuf);
        iscsi->inbuf = NULL;
        iscsi->insize = 0;
        iscsi->inpos = 0;
    }

    while ((pdu = iscsi->outqueue)) {
        DLIST_REMOVE(iscsi->outqueue, pdu);
        pdu->callback(iscsi, ISCSI_STATUS_CANCELLED, NULL, pdu->private_data);
        iscsi_free_pdu(iscsi, pdu);
    }
    while ((pdu = iscsi->waitpdu)) {
        DLIST_REMOVE(iscsi->waitpdu, pdu);
        pdu->callback(iscsi, ISCSI_STATUS_CANCELLED, NULL, pdu->private_data);
        iscsi_free_pdu(iscsi, pdu);
    }

    free(iscsi);

    return 0;
}