Skip to content

Commit 2ab7e1e

Browse files
Joe EykholtJames Bottomley
authored andcommitted
[SCSI] libfc: send GPN_ID in reaction to single-port RSCNs.
When an RSCN indicates changes to individual remote ports, don't blindly log them out and then back in. Instead, determine whether they're still in the directory, by doing GPN_ID. If that is successful, call login, which will send ADISC and reverify, otherwise, call logoff. Perhaps we should just delete the rport, not send LOGO, but it seems safer. Also, fix a possible issue where if a mix of records in the RSCN cause us to queue disc_ports for disc_single and then we decide to do full rediscovery, we leak memory for those disc_ports queued. So, go through the list of disc_ports even if doing full discovery. Free the disc_ports in any case. If any of the disc_single() calls return error, do a full discovery. The ability to fill in GPN_ID requests was added to fc_ct_fill(). For this, it needs the FC_ID to be passed in as an arg. The did parameter for fc_elsct_send() is used for that, since the actual D_DID will always be 0xfffffc for all CT requests so far. 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 8abbe3a commit 2ab7e1e

3 files changed

Lines changed: 128 additions & 27 deletions

File tree

‎drivers/scsi/libfc/fc_disc.c‎

Lines changed: 113 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void fc_disc_gpn_ft_req(struct fc_disc *);
4747
static void fc_disc_gpn_ft_resp(struct fc_seq *, struct fc_frame *, void *);
4848
static void fc_disc_done(struct fc_disc *, enum fc_disc_event);
4949
static void fc_disc_timeout(struct work_struct *);
50-
static void fc_disc_single(struct fc_disc *, struct fc_disc_port *);
50+
static int fc_disc_single(struct fc_lport *, struct fc_disc_port *);
5151
static void fc_disc_restart(struct fc_disc *);
5252

5353
/**
@@ -83,7 +83,6 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
8383
struct fc_disc *disc)
8484
{
8585
struct fc_lport *lport;
86-
struct fc_rport_priv *rdata;
8786
struct fc_els_rscn *rp;
8887
struct fc_els_rscn_page *pp;
8988
struct fc_seq_els_data rjt_data;
@@ -150,21 +149,26 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
150149
}
151150
}
152151
lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL);
152+
153+
/*
154+
* If not doing a complete rediscovery, do GPN_ID on
155+
* the individual ports mentioned in the list.
156+
* If any of these get an error, do a full rediscovery.
157+
* In any case, go through the list and free the entries.
158+
*/
159+
list_for_each_entry_safe(dp, next, &disc_ports, peers) {
160+
list_del(&dp->peers);
161+
if (!redisc)
162+
redisc = fc_disc_single(lport, dp);
163+
kfree(dp);
164+
}
153165
if (redisc) {
154166
FC_DISC_DBG(disc, "RSCN received: rediscovering\n");
155167
fc_disc_restart(disc);
156168
} else {
157169
FC_DISC_DBG(disc, "RSCN received: not rediscovering. "
158170
"redisc %d state %d in_prog %d\n",
159171
redisc, lport->state, disc->pending);
160-
list_for_each_entry_safe(dp, next, &disc_ports, peers) {
161-
list_del(&dp->peers);
162-
rdata = lport->tt.rport_lookup(lport, dp->port_id);
163-
if (rdata) {
164-
lport->tt.rport_logoff(rdata);
165-
}
166-
fc_disc_single(disc, dp);
167-
}
168172
}
169173
fc_frame_free(fp);
170174
return;
@@ -562,32 +566,117 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp,
562566
}
563567

564568
/**
565-
* fc_disc_single() - Discover the directory information for a single target
566-
* @lport: FC local port
567-
* @dp: The port to rediscover
569+
* fc_disc_gpn_id_resp() - Handle a response frame from Get Port Names (GPN_ID)
570+
* @sp: exchange sequence
571+
* @fp: response frame
572+
* @rdata_arg: remote port private data
568573
*
569-
* Locking Note: This function expects that the disc_mutex is locked
570-
* before it is called.
574+
* Locking Note: This function is called without disc mutex held.
571575
*/
572-
static void fc_disc_single(struct fc_disc *disc, struct fc_disc_port *dp)
576+
static void fc_disc_gpn_id_resp(struct fc_seq *sp, struct fc_frame *fp,
577+
void *rdata_arg)
573578
{
579+
struct fc_rport_priv *rdata = rdata_arg;
580+
struct fc_rport_priv *new_rdata;
574581
struct fc_lport *lport;
575-
struct fc_rport_priv *rdata;
582+
struct fc_disc *disc;
583+
struct fc_ct_hdr *cp;
584+
struct fc_ns_gid_pn *pn;
585+
u64 port_name;
576586

577-
lport = disc->lport;
587+
lport = rdata->local_port;
588+
disc = &lport->disc;
578589

579-
if (dp->port_id == fc_host_port_id(lport->host))
590+
mutex_lock(&disc->disc_mutex);
591+
if (PTR_ERR(fp) == -FC_EX_CLOSED)
580592
goto out;
593+
if (IS_ERR(fp))
594+
goto redisc;
595+
596+
cp = fc_frame_payload_get(fp, sizeof(*cp));
597+
if (!cp)
598+
goto redisc;
599+
if (ntohs(cp->ct_cmd) == FC_FS_ACC) {
600+
if (fr_len(fp) < sizeof(struct fc_frame_header) +
601+
sizeof(*cp) + sizeof(*pn))
602+
goto redisc;
603+
pn = (struct fc_ns_gid_pn *)(cp + 1);
604+
port_name = get_unaligned_be64(&pn->fn_wwpn);
605+
if (rdata->ids.port_name == -1)
606+
rdata->ids.port_name = port_name;
607+
else if (rdata->ids.port_name != port_name) {
608+
FC_DISC_DBG(disc, "GPN_ID accepted. WWPN changed. "
609+
"Port-id %x wwpn %llx\n",
610+
rdata->ids.port_id, port_name);
611+
lport->tt.rport_logoff(rdata);
581612

582-
rdata = lport->tt.rport_create(lport, dp->port_id);
583-
if (rdata) {
613+
new_rdata = lport->tt.rport_create(lport,
614+
rdata->ids.port_id);
615+
if (new_rdata) {
616+
new_rdata->disc_id = disc->disc_id;
617+
lport->tt.rport_login(new_rdata);
618+
}
619+
goto out;
620+
}
584621
rdata->disc_id = disc->disc_id;
585-
kfree(dp);
586622
lport->tt.rport_login(rdata);
623+
} else if (ntohs(cp->ct_cmd) == FC_FS_RJT) {
624+
FC_DISC_DBG(disc, "GPN_ID rejected reason %x exp %x\n",
625+
cp->ct_reason, cp->ct_explan);
626+
lport->tt.rport_logoff(rdata);
627+
} else {
628+
FC_DISC_DBG(disc, "GPN_ID unexpected response code %x\n",
629+
ntohs(cp->ct_cmd));
630+
redisc:
631+
fc_disc_restart(disc);
587632
}
588-
return;
589633
out:
590-
kfree(dp);
634+
mutex_unlock(&disc->disc_mutex);
635+
kref_put(&rdata->kref, lport->tt.rport_destroy);
636+
}
637+
638+
/**
639+
* fc_disc_gpn_id_req() - Send Get Port Names by ID (GPN_ID) request
640+
* @lport: local port
641+
* @rdata: remote port private data
642+
*
643+
* Locking Note: This function expects that the disc_mutex is locked
644+
* before it is called.
645+
* On failure, an error code is returned.
646+
*/
647+
static int fc_disc_gpn_id_req(struct fc_lport *lport,
648+
struct fc_rport_priv *rdata)
649+
{
650+
struct fc_frame *fp;
651+
652+
fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) +
653+
sizeof(struct fc_ns_fid));
654+
if (!fp)
655+
return -ENOMEM;
656+
if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, FC_NS_GPN_ID,
657+
fc_disc_gpn_id_resp, rdata, lport->e_d_tov))
658+
return -ENOMEM;
659+
kref_get(&rdata->kref);
660+
return 0;
661+
}
662+
663+
/**
664+
* fc_disc_single() - Discover the directory information for a single target
665+
* @lport: local port
666+
* @dp: The port to rediscover
667+
*
668+
* Locking Note: This function expects that the disc_mutex is locked
669+
* before it is called.
670+
*/
671+
static int fc_disc_single(struct fc_lport *lport, struct fc_disc_port *dp)
672+
{
673+
struct fc_rport_priv *rdata;
674+
675+
rdata = lport->tt.rport_create(lport, dp->port_id);
676+
if (!rdata)
677+
return -ENOMEM;
678+
rdata->disc_id = 0;
679+
return fc_disc_gpn_id_req(lport, rdata);
591680
}
592681

593682
/**

‎drivers/scsi/libfc/fc_elsct.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static struct fc_seq *fc_elsct_send(struct fc_lport *lport,
4949
rc = fc_els_fill(lport, did, fp, op, &r_ctl, &fh_type);
5050
else {
5151
/* CT requests */
52-
rc = fc_ct_fill(lport, fp, op, &r_ctl, &fh_type);
52+
rc = fc_ct_fill(lport, did, fp, op, &r_ctl, &fh_type);
5353
did = FC_FID_DIR_SERV;
5454
}
5555

‎include/scsi/fc_encode.h‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct fc_ct_req {
3232
struct fc_ns_gid_ft gid;
3333
struct fc_ns_rn_id rn;
3434
struct fc_ns_rft rft;
35+
struct fc_ns_fid fid;
3536
} payload;
3637
};
3738

@@ -94,10 +95,16 @@ static inline struct fc_ct_req *fc_ct_hdr_fill(const struct fc_frame *fp,
9495
}
9596

9697
/**
97-
* fc_ct_fill - Fill in a name service request frame
98+
* fc_ct_fill() - Fill in a name service request frame
99+
* @lport: local port.
100+
* @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries.
101+
* @fp: frame to contain payload.
102+
* @op: CT opcode.
103+
* @r_ctl: pointer to FC header R_CTL.
104+
* @fh_type: pointer to FC-4 type.
98105
*/
99106
static inline int fc_ct_fill(struct fc_lport *lport,
100-
struct fc_frame *fp,
107+
u32 fc_id, struct fc_frame *fp,
101108
unsigned int op, enum fc_rctl *r_ctl,
102109
enum fc_fh_type *fh_type)
103110
{
@@ -109,6 +116,11 @@ static inline int fc_ct_fill(struct fc_lport *lport,
109116
ct->payload.gid.fn_fc4_type = FC_TYPE_FCP;
110117
break;
111118

119+
case FC_NS_GPN_ID:
120+
ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_fid));
121+
hton24(ct->payload.fid.fp_fid, fc_id);
122+
break;
123+
112124
case FC_NS_RFT_ID:
113125
ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rft));
114126
hton24(ct->payload.rft.fid.fp_fid,

0 commit comments

Comments
 (0)