Skip to content

Commit 370c3bd

Browse files
Joe EykholtJames Bottomley
authored andcommitted
[SCSI] libfc: use ADISC to verify rport login state
When rport_login is called on an rport that is already thought to be logged in, use ADISC. If that fails, redo PLOGI. This is less disruptive after fabric changes that don't affect the state of the target. Implement the sending of ADISC via fc_els_fill. Add ADISC state to the rport state machine. This is entered from READY and returns to READY after successful completion. If it fails, the rport is either logged off and deleted or re-does PLOGI. Signed-off-by: Joe Eykholt <jeykholt@cisco.com> Signed-off-by: Robert Love <robert.w.love@intel.com> Signed-off-by: James Bottomley <James.Bottomley@suse.de>
1 parent 68a1750 commit 370c3bd

3 files changed

Lines changed: 139 additions & 5 deletions

File tree

‎drivers/scsi/libfc/fc_rport.c‎

Lines changed: 117 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static void fc_rport_enter_prli(struct fc_rport_priv *);
6262
static void fc_rport_enter_rtv(struct fc_rport_priv *);
6363
static void fc_rport_enter_ready(struct fc_rport_priv *);
6464
static void fc_rport_enter_logo(struct fc_rport_priv *);
65+
static void fc_rport_enter_adisc(struct fc_rport_priv *);
6566

6667
static void fc_rport_recv_plogi_req(struct fc_lport *,
6768
struct fc_seq *, struct fc_frame *);
@@ -83,6 +84,7 @@ static const char *fc_rport_state_names[] = {
8384
[RPORT_ST_RTV] = "RTV",
8485
[RPORT_ST_READY] = "Ready",
8586
[RPORT_ST_LOGO] = "LOGO",
87+
[RPORT_ST_ADISC] = "ADISC",
8688
[RPORT_ST_DELETE] = "Delete",
8789
};
8890

@@ -326,15 +328,25 @@ static void fc_rport_work(struct work_struct *work)
326328
* Locking Note: Called without the rport lock held. This
327329
* function will hold the rport lock, call an _enter_*
328330
* function and then unlock the rport.
331+
*
332+
* This indicates the intent to be logged into the remote port.
333+
* If it appears we are already logged in, ADISC is used to verify
334+
* the setup.
329335
*/
330336
int fc_rport_login(struct fc_rport_priv *rdata)
331337
{
332338
mutex_lock(&rdata->rp_mutex);
333339

334-
FC_RPORT_DBG(rdata, "Login to port\n");
335-
336-
fc_rport_enter_plogi(rdata);
337-
340+
switch (rdata->rp_state) {
341+
case RPORT_ST_READY:
342+
FC_RPORT_DBG(rdata, "ADISC port\n");
343+
fc_rport_enter_adisc(rdata);
344+
break;
345+
default:
346+
FC_RPORT_DBG(rdata, "Login to port\n");
347+
fc_rport_enter_plogi(rdata);
348+
break;
349+
}
338350
mutex_unlock(&rdata->rp_mutex);
339351

340352
return 0;
@@ -448,6 +460,9 @@ static void fc_rport_timeout(struct work_struct *work)
448460
case RPORT_ST_LOGO:
449461
fc_rport_enter_logo(rdata);
450462
break;
463+
case RPORT_ST_ADISC:
464+
fc_rport_enter_adisc(rdata);
465+
break;
451466
case RPORT_ST_READY:
452467
case RPORT_ST_INIT:
453468
case RPORT_ST_DELETE:
@@ -473,13 +488,16 @@ static void fc_rport_error(struct fc_rport_priv *rdata, struct fc_frame *fp)
473488

474489
switch (rdata->rp_state) {
475490
case RPORT_ST_PLOGI:
476-
case RPORT_ST_PRLI:
477491
case RPORT_ST_LOGO:
478492
fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
479493
break;
480494
case RPORT_ST_RTV:
481495
fc_rport_enter_ready(rdata);
482496
break;
497+
case RPORT_ST_PRLI:
498+
case RPORT_ST_ADISC:
499+
fc_rport_enter_logo(rdata);
500+
break;
483501
case RPORT_ST_DELETE:
484502
case RPORT_ST_READY:
485503
case RPORT_ST_INIT:
@@ -906,6 +924,93 @@ static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
906924
kref_get(&rdata->kref);
907925
}
908926

927+
/**
928+
* fc_rport_els_adisc_resp() - Address Discovery response handler
929+
* @sp: current sequence in the ADISC exchange
930+
* @fp: response frame
931+
* @rdata_arg: remote port private.
932+
*
933+
* Locking Note: This function will be called without the rport lock
934+
* held, but it will lock, call an _enter_* function or fc_rport_error
935+
* and then unlock the rport.
936+
*/
937+
static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
938+
void *rdata_arg)
939+
{
940+
struct fc_rport_priv *rdata = rdata_arg;
941+
struct fc_els_adisc *adisc;
942+
u8 op;
943+
944+
mutex_lock(&rdata->rp_mutex);
945+
946+
FC_RPORT_DBG(rdata, "Received a ADISC response\n");
947+
948+
if (rdata->rp_state != RPORT_ST_ADISC) {
949+
FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
950+
fc_rport_state(rdata));
951+
if (IS_ERR(fp))
952+
goto err;
953+
goto out;
954+
}
955+
956+
if (IS_ERR(fp)) {
957+
fc_rport_error(rdata, fp);
958+
goto err;
959+
}
960+
961+
/*
962+
* If address verification failed. Consider us logged out of the rport.
963+
* Since the rport is still in discovery, we want to be
964+
* logged in, so go to PLOGI state. Otherwise, go back to READY.
965+
*/
966+
op = fc_frame_payload_op(fp);
967+
adisc = fc_frame_payload_get(fp, sizeof(*adisc));
968+
if (op != ELS_LS_ACC || !adisc ||
969+
ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
970+
get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
971+
get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
972+
FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
973+
fc_rport_enter_plogi(rdata);
974+
} else {
975+
FC_RPORT_DBG(rdata, "ADISC OK\n");
976+
fc_rport_enter_ready(rdata);
977+
}
978+
out:
979+
fc_frame_free(fp);
980+
err:
981+
mutex_unlock(&rdata->rp_mutex);
982+
kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
983+
}
984+
985+
/**
986+
* fc_rport_enter_adisc() - Send Address Discover (ADISC) request to peer
987+
* @rdata: remote port private data
988+
*
989+
* Locking Note: The rport lock is expected to be held before calling
990+
* this routine.
991+
*/
992+
static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
993+
{
994+
struct fc_lport *lport = rdata->local_port;
995+
struct fc_frame *fp;
996+
997+
FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
998+
fc_rport_state(rdata));
999+
1000+
fc_rport_state_enter(rdata, RPORT_ST_ADISC);
1001+
1002+
fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
1003+
if (!fp) {
1004+
fc_rport_error_retry(rdata, fp);
1005+
return;
1006+
}
1007+
if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
1008+
fc_rport_adisc_resp, rdata, lport->e_d_tov))
1009+
fc_rport_error_retry(rdata, fp);
1010+
else
1011+
kref_get(&rdata->kref);
1012+
}
1013+
9091014
/**
9101015
* fc_rport_recv_els_req() - handle a validated ELS request.
9111016
* @lport: Fibre Channel local port
@@ -943,6 +1048,7 @@ static void fc_rport_recv_els_req(struct fc_lport *lport,
9431048
case RPORT_ST_PRLI:
9441049
case RPORT_ST_RTV:
9451050
case RPORT_ST_READY:
1051+
case RPORT_ST_ADISC:
9461052
break;
9471053
default:
9481054
mutex_unlock(&rdata->rp_mutex);
@@ -1095,6 +1201,10 @@ static void fc_rport_recv_plogi_req(struct fc_lport *lport,
10951201
break;
10961202
case RPORT_ST_PRLI:
10971203
case RPORT_ST_READY:
1204+
case RPORT_ST_ADISC:
1205+
FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
1206+
"- ignored for now\n", rdata->rp_state);
1207+
/* XXX TBD - should reset */
10981208
break;
10991209
case RPORT_ST_DELETE:
11001210
default:
@@ -1178,6 +1288,7 @@ static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
11781288
case RPORT_ST_PRLI:
11791289
case RPORT_ST_RTV:
11801290
case RPORT_ST_READY:
1291+
case RPORT_ST_ADISC:
11811292
reason = ELS_RJT_NONE;
11821293
break;
11831294
default:
@@ -1283,6 +1394,7 @@ static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
12831394
fc_rport_enter_ready(rdata);
12841395
break;
12851396
case RPORT_ST_READY:
1397+
case RPORT_ST_ADISC:
12861398
break;
12871399
default:
12881400
break;

‎include/scsi/fc_encode.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl,
5656
fh->fh_parm_offset = htonl(parm_offset);
5757
}
5858

59+
/**
60+
* fc_adisc_fill() - Fill in adisc request frame
61+
* @lport: local port.
62+
* @fp: fc frame where payload will be placed.
63+
*/
64+
static inline void fc_adisc_fill(struct fc_lport *lport, struct fc_frame *fp)
65+
{
66+
struct fc_els_adisc *adisc;
67+
68+
adisc = fc_frame_payload_get(fp, sizeof(*adisc));
69+
memset(adisc, 0, sizeof(*adisc));
70+
adisc->adisc_cmd = ELS_ADISC;
71+
put_unaligned_be64(lport->wwpn, &adisc->adisc_wwpn);
72+
put_unaligned_be64(lport->wwnn, &adisc->adisc_wwnn);
73+
hton24(adisc->adisc_port_id, fc_host_port_id(lport->host));
74+
}
75+
5976
/**
6077
* fc_ct_hdr_fill- fills ct header and reset ct payload
6178
* returns pointer to ct request.
@@ -255,6 +272,10 @@ static inline int fc_els_fill(struct fc_lport *lport,
255272
enum fc_rctl *r_ctl, enum fc_fh_type *fh_type)
256273
{
257274
switch (op) {
275+
case ELS_ADISC:
276+
fc_adisc_fill(lport, fp);
277+
break;
278+
258279
case ELS_PLOGI:
259280
fc_plogi_fill(lport, fp, ELS_PLOGI);
260281
break;

‎include/scsi/libfc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ enum fc_rport_state {
143143
RPORT_ST_RTV, /* waiting for RTV completion */
144144
RPORT_ST_READY, /* ready for use */
145145
RPORT_ST_LOGO, /* port logout sent */
146+
RPORT_ST_ADISC, /* Discover Address sent */
146147
RPORT_ST_DELETE, /* port being deleted */
147148
};
148149

0 commit comments

Comments
 (0)