20 */
21 /*
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 */
25
26 #include <sys/cpuvar.h>
27 #include <sys/types.h>
28 #include <sys/conf.h>
29 #include <sys/file.h>
30 #include <sys/ddi.h>
31 #include <sys/sunddi.h>
32 #include <sys/modctl.h>
33 #include <sys/sysmacros.h>
34 #include <sys/scsi/generic/persist.h>
35
36 #include <sys/socket.h>
37 #include <sys/strsubr.h>
38 #include <sys/note.h>
39 #include <sys/sdt.h>
40
41 #include <sys/stmf.h>
42 #include <sys/stmf_ioctl.h>
43 #include <sys/portif.h>
44 #include <sys/idm/idm.h>
45
46 #define ISCSIT_SESS_SM_STRINGS
47 #include "iscsit.h"
48
49 typedef struct {
50 list_node_t se_ctx_node;
51 iscsit_session_event_t se_ctx_event;
52 iscsit_conn_t *se_event_data;
53 } sess_event_ctx_t;
54
55 static void
56 sess_sm_event_locked(iscsit_sess_t *ist, iscsit_session_event_t event,
57 iscsit_conn_t *ict);
58
59 static void
194 *error_class = ISCSI_STATUS_CLASS_SUCCESS;
195 } else {
196 mutex_exit(&iscsit_global.global_state_mutex);
197 *error_class = ISCSI_STATUS_CLASS_TARGET_ERR;
198 *error_detail = ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE;
199 }
200 }
201
202 /*
203 * As noted above we must return a session pointer even if something
204 * failed. The resources will get freed later.
205 */
206 return (result);
207 }
208
209 static void
210 iscsit_sess_unref(void *ist_void)
211 {
212 iscsit_sess_t *ist = ist_void;
213 stmf_scsi_session_t *iss;
214
215 /*
216 * State machine has run to completion, destroy session
217 *
218 * If we have an associated STMF session we should clean it
219 * up now.
220 *
221 * This session is no longer associated with a target at this
222 * point so don't touch the target.
223 */
224 mutex_enter(&ist->ist_mutex);
225 ASSERT(ist->ist_conn_count == 0);
226 iss = ist->ist_stmf_sess;
227 if (iss != NULL) {
228 stmf_deregister_scsi_session(ist->ist_lport, iss);
229 kmem_free(iss->ss_rport_id, sizeof (scsi_devid_desc_t) +
230 strlen(ist->ist_initiator_name) + 1);
231 stmf_remote_port_free(iss->ss_rport);
232 if (iss->ss_rport_alias)
233 strfree(iss->ss_rport_alias);
234 stmf_free(iss);
235 }
236 mutex_exit(&ist->ist_mutex);
237
238 iscsit_sess_destroy(ist);
239 iscsit_global_rele();
240 }
241
242 void
243 iscsit_sess_destroy(iscsit_sess_t *ist)
244 {
245 idm_refcnt_destroy(&ist->ist_refcnt);
246 if (ist->ist_initiator_name)
247 kmem_free(ist->ist_initiator_name,
|
20 */
21 /*
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 */
25
26 #include <sys/cpuvar.h>
27 #include <sys/types.h>
28 #include <sys/conf.h>
29 #include <sys/file.h>
30 #include <sys/ddi.h>
31 #include <sys/sunddi.h>
32 #include <sys/modctl.h>
33 #include <sys/sysmacros.h>
34 #include <sys/scsi/generic/persist.h>
35
36 #include <sys/socket.h>
37 #include <sys/strsubr.h>
38 #include <sys/note.h>
39 #include <sys/sdt.h>
40 #include <sys/kstat.h>
41
42 #include <sys/stmf.h>
43 #include <sys/stmf_ioctl.h>
44 #include <sys/portif.h>
45 #include <sys/idm/idm.h>
46
47 #define ISCSIT_SESS_SM_STRINGS
48 #include "iscsit.h"
49
50 typedef struct {
51 list_node_t se_ctx_node;
52 iscsit_session_event_t se_ctx_event;
53 iscsit_conn_t *se_event_data;
54 } sess_event_ctx_t;
55
56 static void
57 sess_sm_event_locked(iscsit_sess_t *ist, iscsit_session_event_t event,
58 iscsit_conn_t *ict);
59
60 static void
195 *error_class = ISCSI_STATUS_CLASS_SUCCESS;
196 } else {
197 mutex_exit(&iscsit_global.global_state_mutex);
198 *error_class = ISCSI_STATUS_CLASS_TARGET_ERR;
199 *error_detail = ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE;
200 }
201 }
202
203 /*
204 * As noted above we must return a session pointer even if something
205 * failed. The resources will get freed later.
206 */
207 return (result);
208 }
209
210 static void
211 iscsit_sess_unref(void *ist_void)
212 {
213 iscsit_sess_t *ist = ist_void;
214 stmf_scsi_session_t *iss;
215 char prop_buf[KSTAT_STRLEN + 1];
216
217 /*
218 * State machine has run to completion, destroy session
219 *
220 * If we have an associated STMF session we should clean it
221 * up now.
222 *
223 * This session is no longer associated with a target at this
224 * point so don't touch the target.
225 */
226 mutex_enter(&ist->ist_mutex);
227 ASSERT(ist->ist_conn_count == 0);
228 iss = ist->ist_stmf_sess;
229 if (iss != NULL) {
230 (void) snprintf(prop_buf, sizeof (prop_buf),
231 "peername_%"PRIxPTR"", (uintptr_t)ist);
232 stmf_remove_rport_info(iss, prop_buf);
233 stmf_deregister_scsi_session(ist->ist_lport, iss);
234 kmem_free(iss->ss_rport_id, sizeof (scsi_devid_desc_t) +
235 strlen(ist->ist_initiator_name) + 1);
236 stmf_remote_port_free(iss->ss_rport);
237 if (iss->ss_rport_alias)
238 strfree(iss->ss_rport_alias);
239 stmf_free(iss);
240 }
241 mutex_exit(&ist->ist_mutex);
242
243 iscsit_sess_destroy(ist);
244 iscsit_global_rele();
245 }
246
247 void
248 iscsit_sess_destroy(iscsit_sess_t *ist)
249 {
250 idm_refcnt_destroy(&ist->ist_refcnt);
251 if (ist->ist_initiator_name)
252 kmem_free(ist->ist_initiator_name,
|