Skip to content

Commit 9fb9d32

Browse files
Joe EykholtJames Bottomley
authored andcommitted
[SCSI] libfc: make fc_rport_priv the primary rport interface.
The rport and discovery modules deal with remote ports before fc_remote_port_add() can be done, because the full set of rport identifiers is not known at early stages. In preparation for splitting the fc_rport/fc_rport_priv allocation, make fc_rport_priv the primary interface for the remote port and discovery engines. The FCP / SCSI layers still deal with fc_rport and fc_rport_libfc_priv, however. 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 922aa21 commit 9fb9d32

7 files changed

Lines changed: 245 additions & 279 deletions

File tree

‎drivers/scsi/libfc/fc_disc.c‎

Lines changed: 34 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ static void fc_disc_gpn_ft_req(struct fc_disc *);
4949
static void fc_disc_gpn_ft_resp(struct fc_seq *, struct fc_frame *, void *);
5050
static int fc_disc_new_target(struct fc_disc *, struct fc_rport *,
5151
struct fc_rport_identifiers *);
52-
static void fc_disc_del_target(struct fc_disc *, struct fc_rport *);
5352
static void fc_disc_done(struct fc_disc *);
5453
static void fc_disc_timeout(struct work_struct *);
5554
static void fc_disc_single(struct fc_disc *, struct fc_disc_port *);
@@ -60,27 +59,19 @@ static void fc_disc_restart(struct fc_disc *);
6059
* @lport: Fibre Channel host port instance
6160
* @port_id: remote port port_id to match
6261
*/
63-
struct fc_rport *fc_disc_lookup_rport(const struct fc_lport *lport,
64-
u32 port_id)
62+
struct fc_rport_priv *fc_disc_lookup_rport(const struct fc_lport *lport,
63+
u32 port_id)
6564
{
6665
const struct fc_disc *disc = &lport->disc;
67-
struct fc_rport *rport, *found = NULL;
66+
struct fc_rport *rport;
6867
struct fc_rport_priv *rdata;
69-
int disc_found = 0;
7068

7169
list_for_each_entry(rdata, &disc->rports, peers) {
7270
rport = PRIV_TO_RPORT(rdata);
73-
if (rport->port_id == port_id) {
74-
disc_found = 1;
75-
found = rport;
76-
break;
77-
}
71+
if (rport->port_id == port_id)
72+
return rdata;
7873
}
79-
80-
if (!disc_found)
81-
found = NULL;
82-
83-
return found;
74+
return NULL;
8475
}
8576

8677
/**
@@ -93,21 +84,18 @@ struct fc_rport *fc_disc_lookup_rport(const struct fc_lport *lport,
9384
void fc_disc_stop_rports(struct fc_disc *disc)
9485
{
9586
struct fc_lport *lport;
96-
struct fc_rport *rport;
9787
struct fc_rport_priv *rdata, *next;
9888

9989
lport = disc->lport;
10090

10191
mutex_lock(&disc->disc_mutex);
10292
list_for_each_entry_safe(rdata, next, &disc->rports, peers) {
103-
rport = PRIV_TO_RPORT(rdata);
10493
list_del(&rdata->peers);
105-
lport->tt.rport_logoff(rport);
94+
lport->tt.rport_logoff(rdata);
10695
}
10796

10897
list_for_each_entry_safe(rdata, next, &disc->rogue_rports, peers) {
109-
rport = PRIV_TO_RPORT(rdata);
110-
lport->tt.rport_logoff(rport);
98+
lport->tt.rport_logoff(rdata);
11199
}
112100

113101
mutex_unlock(&disc->disc_mutex);
@@ -116,18 +104,18 @@ void fc_disc_stop_rports(struct fc_disc *disc)
116104
/**
117105
* fc_disc_rport_callback() - Event handler for rport events
118106
* @lport: The lport which is receiving the event
119-
* @rport: The rport which the event has occured on
107+
* @rdata: private remote port data
120108
* @event: The event that occured
121109
*
122110
* Locking Note: The rport lock should not be held when calling
123111
* this function.
124112
*/
125113
static void fc_disc_rport_callback(struct fc_lport *lport,
126-
struct fc_rport *rport,
114+
struct fc_rport_priv *rdata,
127115
enum fc_rport_event event)
128116
{
129-
struct fc_rport_priv *rdata = rport->dd_data;
130117
struct fc_disc *disc = &lport->disc;
118+
struct fc_rport *rport = PRIV_TO_RPORT(rdata);
131119

132120
FC_DISC_DBG(disc, "Received a %d event for port (%6x)\n", event,
133121
rport->port_id);
@@ -169,7 +157,6 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
169157
struct fc_disc *disc)
170158
{
171159
struct fc_lport *lport;
172-
struct fc_rport *rport;
173160
struct fc_rport_priv *rdata;
174161
struct fc_els_rscn *rp;
175162
struct fc_els_rscn_page *pp;
@@ -249,11 +236,10 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
249236
redisc, lport->state, disc->pending);
250237
list_for_each_entry_safe(dp, next, &disc_ports, peers) {
251238
list_del(&dp->peers);
252-
rport = lport->tt.rport_lookup(lport, dp->ids.port_id);
253-
if (rport) {
254-
rdata = rport->dd_data;
239+
rdata = lport->tt.rport_lookup(lport, dp->ids.port_id);
240+
if (rdata) {
255241
list_del(&rdata->peers);
256-
lport->tt.rport_logoff(rport);
242+
lport->tt.rport_logoff(rdata);
257243
}
258244
fc_disc_single(disc, dp);
259245
}
@@ -308,16 +294,14 @@ static void fc_disc_recv_req(struct fc_seq *sp, struct fc_frame *fp,
308294
*/
309295
static void fc_disc_restart(struct fc_disc *disc)
310296
{
311-
struct fc_rport *rport;
312297
struct fc_rport_priv *rdata, *next;
313298
struct fc_lport *lport = disc->lport;
314299

315300
FC_DISC_DBG(disc, "Restarting discovery\n");
316301

317302
list_for_each_entry_safe(rdata, next, &disc->rports, peers) {
318-
rport = PRIV_TO_RPORT(rdata);
319303
list_del(&rdata->peers);
320-
lport->tt.rport_logoff(rport);
304+
lport->tt.rport_logoff(rdata);
321305
}
322306

323307
disc->requested = 1;
@@ -335,6 +319,7 @@ static void fc_disc_start(void (*disc_callback)(struct fc_lport *,
335319
enum fc_disc_event),
336320
struct fc_lport *lport)
337321
{
322+
struct fc_rport_priv *rdata;
338323
struct fc_rport *rport;
339324
struct fc_rport_identifiers ids;
340325
struct fc_disc *disc = &lport->disc;
@@ -362,8 +347,9 @@ static void fc_disc_start(void (*disc_callback)(struct fc_lport *,
362347
* Handle point-to-point mode as a simple discovery
363348
* of the remote port. Yucky, yucky, yuck, yuck!
364349
*/
365-
rport = disc->lport->ptp_rp;
366-
if (rport) {
350+
rdata = disc->lport->ptp_rp;
351+
if (rdata) {
352+
rport = PRIV_TO_RPORT(rdata);
367353
ids.port_id = rport->port_id;
368354
ids.port_name = rport->port_name;
369355
ids.node_name = rport->node_name;
@@ -418,45 +404,36 @@ static int fc_disc_new_target(struct fc_disc *disc,
418404
* assigned the same FCID. This should be rare.
419405
* Delete the old one and fall thru to re-create.
420406
*/
421-
fc_disc_del_target(disc, rport);
407+
rdata = rport->dd_data;
408+
list_del(&rdata->peers);
409+
lport->tt.rport_logoff(rdata);
422410
rport = NULL;
423411
}
424412
}
425413
if (((ids->port_name != -1) || (ids->port_id != -1)) &&
426414
ids->port_id != fc_host_port_id(lport->host) &&
427415
ids->port_name != lport->wwpn) {
428416
if (!rport) {
429-
rport = lport->tt.rport_lookup(lport, ids->port_id);
417+
rdata = lport->tt.rport_lookup(lport, ids->port_id);
430418
if (!rport) {
431-
rport = lport->tt.rport_create(lport, ids);
419+
rdata = lport->tt.rport_create(lport, ids);
432420
}
433-
if (!rport)
421+
if (!rdata)
434422
error = -ENOMEM;
423+
else
424+
rport = PRIV_TO_RPORT(rdata);
435425
}
436426
if (rport) {
437427
rdata = rport->dd_data;
438428
rdata->ops = &fc_disc_rport_ops;
439429
rdata->rp_state = RPORT_ST_INIT;
440430
list_add_tail(&rdata->peers, &disc->rogue_rports);
441-
lport->tt.rport_login(rport);
431+
lport->tt.rport_login(rdata);
442432
}
443433
}
444434
return error;
445435
}
446436

447-
/**
448-
* fc_disc_del_target() - Delete a target
449-
* @disc: FC discovery context
450-
* @rport: The remote port to be removed
451-
*/
452-
static void fc_disc_del_target(struct fc_disc *disc, struct fc_rport *rport)
453-
{
454-
struct fc_lport *lport = disc->lport;
455-
struct fc_rport_priv *rdata = rport->dd_data;
456-
list_del(&rdata->peers);
457-
lport->tt.rport_logoff(rport);
458-
}
459-
460437
/**
461438
* fc_disc_done() - Discovery has been completed
462439
* @disc: FC discovery context
@@ -573,7 +550,6 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len)
573550
size_t tlen;
574551
int error = 0;
575552
struct fc_rport_identifiers ids;
576-
struct fc_rport *rport;
577553
struct fc_rport_priv *rdata;
578554

579555
lport = disc->lport;
@@ -622,14 +598,13 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len)
622598

623599
if (ids.port_id != fc_host_port_id(lport->host) &&
624600
ids.port_name != lport->wwpn) {
625-
rport = lport->tt.rport_create(lport, &ids);
626-
if (rport) {
627-
rdata = rport->dd_data;
601+
rdata = lport->tt.rport_create(lport, &ids);
602+
if (rdata) {
628603
rdata->ops = &fc_disc_rport_ops;
629604
rdata->local_port = lport;
630605
list_add_tail(&rdata->peers,
631606
&disc->rogue_rports);
632-
lport->tt.rport_login(rport);
607+
lport->tt.rport_login(rdata);
633608
} else
634609
printk(KERN_WARNING "libfc: Failed to allocate "
635610
"memory for the newly discovered port "
@@ -766,21 +741,19 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp,
766741
static void fc_disc_single(struct fc_disc *disc, struct fc_disc_port *dp)
767742
{
768743
struct fc_lport *lport;
769-
struct fc_rport *new_rport;
770744
struct fc_rport_priv *rdata;
771745

772746
lport = disc->lport;
773747

774748
if (dp->ids.port_id == fc_host_port_id(lport->host))
775749
goto out;
776750

777-
new_rport = lport->tt.rport_create(lport, &dp->ids);
778-
if (new_rport) {
779-
rdata = new_rport->dd_data;
751+
rdata = lport->tt.rport_create(lport, &dp->ids);
752+
if (rdata) {
780753
rdata->ops = &fc_disc_rport_ops;
781754
kfree(dp);
782755
list_add_tail(&rdata->peers, &disc->rogue_rports);
783-
lport->tt.rport_login(new_rport);
756+
lport->tt.rport_login(rdata);
784757
}
785758
return;
786759
out:

‎drivers/scsi/libfc/fc_elsct.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* fc_elsct_send - sends ELS/CT frame
3333
*/
3434
static struct fc_seq *fc_elsct_send(struct fc_lport *lport,
35-
struct fc_rport *rport,
35+
struct fc_rport_priv *rdata,
3636
struct fc_frame *fp,
3737
unsigned int op,
3838
void (*resp)(struct fc_seq *,
@@ -47,7 +47,7 @@ static struct fc_seq *fc_elsct_send(struct fc_lport *lport,
4747

4848
/* ELS requests */
4949
if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS))
50-
rc = fc_els_fill(lport, rport, fp, op, &r_ctl, &did, &fh_type);
50+
rc = fc_els_fill(lport, rdata, fp, op, &r_ctl, &did, &fh_type);
5151
else
5252
/* CT requests */
5353
rc = fc_ct_fill(lport, fp, op, &r_ctl, &did, &fh_type);

‎drivers/scsi/libfc/fc_fcp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ static void fc_fcp_rec(struct fc_fcp_pkt *fsp)
13081308
fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rport->port_id,
13091309
fc_host_port_id(rp->local_port->host), FC_TYPE_ELS,
13101310
FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
1311-
if (lp->tt.elsct_send(lp, rport, fp, ELS_REC, fc_fcp_rec_resp,
1311+
if (lp->tt.elsct_send(lp, rport->dd_data, fp, ELS_REC, fc_fcp_rec_resp,
13121312
fsp, jiffies_to_msecs(FC_SCSI_REC_TOV))) {
13131313
fc_fcp_pkt_hold(fsp); /* hold while REC outstanding */
13141314
return;

‎drivers/scsi/libfc/fc_lport.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,18 @@ static int fc_frame_drop(struct fc_lport *lport, struct fc_frame *fp)
133133
/**
134134
* fc_lport_rport_callback() - Event handler for rport events
135135
* @lport: The lport which is receiving the event
136-
* @rport: The rport which the event has occured on
136+
* @rdata: private remote port data
137137
* @event: The event that occured
138138
*
139139
* Locking Note: The rport lock should not be held when calling
140140
* this function.
141141
*/
142142
static void fc_lport_rport_callback(struct fc_lport *lport,
143-
struct fc_rport *rport,
143+
struct fc_rport_priv *rdata,
144144
enum fc_rport_event event)
145145
{
146+
struct fc_rport *rport = PRIV_TO_RPORT(rdata);
147+
146148
FC_LPORT_DBG(lport, "Received a %d event for port (%6x)\n", event,
147149
rport->port_id);
148150

@@ -151,7 +153,7 @@ static void fc_lport_rport_callback(struct fc_lport *lport,
151153
if (rport->port_id == FC_FID_DIR_SERV) {
152154
mutex_lock(&lport->lp_mutex);
153155
if (lport->state == LPORT_ST_DNS) {
154-
lport->dns_rp = rport;
156+
lport->dns_rp = rdata;
155157
fc_lport_enter_rpn_id(lport);
156158
} else {
157159
FC_LPORT_DBG(lport, "Received an CREATED event "
@@ -160,7 +162,7 @@ static void fc_lport_rport_callback(struct fc_lport *lport,
160162
"in the DNS state, it's in the "
161163
"%d state", rport->port_id,
162164
lport->state);
163-
lport->tt.rport_logoff(rport);
165+
lport->tt.rport_logoff(rdata);
164166
}
165167
mutex_unlock(&lport->lp_mutex);
166168
} else
@@ -832,7 +834,7 @@ static void fc_lport_recv_req(struct fc_lport *lport, struct fc_seq *sp,
832834
{
833835
struct fc_frame_header *fh = fc_frame_header_get(fp);
834836
void (*recv) (struct fc_seq *, struct fc_frame *, struct fc_lport *);
835-
struct fc_rport *rport;
837+
struct fc_rport_priv *rdata;
836838
u32 s_id;
837839
u32 d_id;
838840
struct fc_seq_els_data rjt_data;
@@ -888,9 +890,9 @@ static void fc_lport_recv_req(struct fc_lport *lport, struct fc_seq *sp,
888890
s_id = ntoh24(fh->fh_s_id);
889891
d_id = ntoh24(fh->fh_d_id);
890892

891-
rport = lport->tt.rport_lookup(lport, s_id);
892-
if (rport)
893-
lport->tt.rport_recv_req(sp, fp, rport);
893+
rdata = lport->tt.rport_lookup(lport, s_id);
894+
if (rdata)
895+
lport->tt.rport_recv_req(sp, fp, rdata);
894896
else {
895897
rjt_data.fp = NULL;
896898
rjt_data.reason = ELS_RJT_UNAB;
@@ -1304,7 +1306,6 @@ static struct fc_rport_operations fc_lport_rport_ops = {
13041306
*/
13051307
static void fc_lport_enter_dns(struct fc_lport *lport)
13061308
{
1307-
struct fc_rport *rport;
13081309
struct fc_rport_priv *rdata;
13091310
struct fc_rport_identifiers ids;
13101311

@@ -1318,13 +1319,12 @@ static void fc_lport_enter_dns(struct fc_lport *lport)
13181319

13191320
fc_lport_state_enter(lport, LPORT_ST_DNS);
13201321

1321-
rport = lport->tt.rport_create(lport, &ids);
1322-
if (!rport)
1322+
rdata = lport->tt.rport_create(lport, &ids);
1323+
if (!rdata)
13231324
goto err;
13241325

1325-
rdata = rport->dd_data;
13261326
rdata->ops = &fc_lport_rport_ops;
1327-
lport->tt.rport_login(rport);
1327+
lport->tt.rport_login(rdata);
13281328
return;
13291329

13301330
err:

0 commit comments

Comments
 (0)