Skip to content

Commit 5baa17c

Browse files
Chris LeechJames Bottomley
authored andcommitted
[SCSI] libfc: Register Symbolic Node Name (RSNN_NN)
Register the fc_host symbolic name as the symbolic node name with the fabric name server. Signed-off-by: Chris Leech <christopher.leech@intel.com> Signed-off-by: Robert Love <robert.w.love@intel.com> Signed-off-by: James Bottomley <James.Bottomley@suse.de>
1 parent c9c7bd7 commit 5baa17c

5 files changed

Lines changed: 115 additions & 3 deletions

File tree

‎drivers/scsi/fcoe/fcoe.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,9 @@ static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost,
591591
if (!lp->vport)
592592
fc_host_max_npiv_vports(lp->host) = USHORT_MAX;
593593

594-
sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s",
595-
FCOE_NAME, FCOE_VERSION,
596-
fcoe_netdev(lp)->name);
594+
snprintf(fc_host_symbolic_name(lp->host), FC_SYMBOLIC_NAME_SIZE,
595+
"%s v%s over %s", FCOE_NAME, FCOE_VERSION,
596+
fcoe_netdev(lp)->name);
597597

598598
return 0;
599599
}

‎drivers/scsi/libfc/fc_lport.c‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ static void fc_lport_enter_reset(struct fc_lport *);
109109
static void fc_lport_enter_flogi(struct fc_lport *);
110110
static void fc_lport_enter_dns(struct fc_lport *);
111111
static void fc_lport_enter_rnn_id(struct fc_lport *);
112+
static void fc_lport_enter_rsnn_nn(struct fc_lport *);
112113
static void fc_lport_enter_rft_id(struct fc_lport *);
113114
static void fc_lport_enter_scr(struct fc_lport *);
114115
static void fc_lport_enter_ready(struct fc_lport *);
@@ -119,6 +120,7 @@ static const char *fc_lport_state_names[] = {
119120
[LPORT_ST_FLOGI] = "FLOGI",
120121
[LPORT_ST_DNS] = "dNS",
121122
[LPORT_ST_RNN_ID] = "RNN_ID",
123+
[LPORT_ST_RSNN_NN] = "RSNN_NN",
122124
[LPORT_ST_RFT_ID] = "RFT_ID",
123125
[LPORT_ST_SCR] = "SCR",
124126
[LPORT_ST_READY] = "Ready",
@@ -966,6 +968,7 @@ static void fc_lport_error(struct fc_lport *lport, struct fc_frame *fp)
966968
case LPORT_ST_READY:
967969
case LPORT_ST_RESET:
968970
case LPORT_ST_RNN_ID:
971+
case LPORT_ST_RSNN_NN:
969972
case LPORT_ST_RFT_ID:
970973
case LPORT_ST_SCR:
971974
case LPORT_ST_DNS:
@@ -1032,6 +1035,60 @@ static void fc_lport_rft_id_resp(struct fc_seq *sp, struct fc_frame *fp,
10321035
mutex_unlock(&lport->lp_mutex);
10331036
}
10341037

1038+
/**
1039+
* fc_lport_rsnn_nn_resp() - Handle response to Register Symbolic Node Name
1040+
* by Node Name (RSNN_NN) request
1041+
* @sp: current sequence in RSNN_NN exchange
1042+
* @fp: response frame
1043+
* @lp_arg: Fibre Channel host port instance
1044+
*
1045+
* Locking Note: This function will be called without the lport lock
1046+
* held, but it will lock, call an _enter_* function or fc_lport_error
1047+
* and then unlock the lport.
1048+
*/
1049+
static void fc_lport_rsnn_nn_resp(struct fc_seq *sp, struct fc_frame *fp,
1050+
void *lp_arg)
1051+
{
1052+
struct fc_lport *lport = lp_arg;
1053+
struct fc_frame_header *fh;
1054+
struct fc_ct_hdr *ct;
1055+
1056+
FC_LPORT_DBG(lport, "Received a RSNN_NN %s\n", fc_els_resp_type(fp));
1057+
1058+
if (fp == ERR_PTR(-FC_EX_CLOSED))
1059+
return;
1060+
1061+
mutex_lock(&lport->lp_mutex);
1062+
1063+
if (lport->state != LPORT_ST_RSNN_NN) {
1064+
FC_LPORT_DBG(lport, "Received a RSNN_NN response, but in state "
1065+
"%s\n", fc_lport_state(lport));
1066+
if (IS_ERR(fp))
1067+
goto err;
1068+
goto out;
1069+
}
1070+
1071+
if (IS_ERR(fp)) {
1072+
fc_lport_error(lport, fp);
1073+
goto err;
1074+
}
1075+
1076+
fh = fc_frame_header_get(fp);
1077+
ct = fc_frame_payload_get(fp, sizeof(*ct));
1078+
if (fh && ct && fh->fh_type == FC_TYPE_CT &&
1079+
ct->ct_fs_type == FC_FST_DIR &&
1080+
ct->ct_fs_subtype == FC_NS_SUBTYPE &&
1081+
ntohs(ct->ct_cmd) == FC_FS_ACC)
1082+
fc_lport_enter_rsnn_nn(lport);
1083+
else
1084+
fc_lport_error(lport, fp);
1085+
1086+
out:
1087+
fc_frame_free(fp);
1088+
err:
1089+
mutex_unlock(&lport->lp_mutex);
1090+
}
1091+
10351092
/**
10361093
* fc_lport_rnn_id_resp() - Handle response to Register Node
10371094
* Name by ID (RNN_ID) request
@@ -1203,6 +1260,37 @@ static void fc_lport_enter_rft_id(struct fc_lport *lport)
12031260
fc_lport_error(lport, fp);
12041261
}
12051262

1263+
/**
1264+
* fc_rport_enter_rsnn_nn() - Register symbolic node name with the name server
1265+
* @lport: Fibre Channel local port to register
1266+
*
1267+
* Locking Note: The lport lock is expected to be held before calling
1268+
* this routine.
1269+
*/
1270+
static void fc_lport_enter_rsnn_nn(struct fc_lport *lport)
1271+
{
1272+
struct fc_frame *fp;
1273+
size_t len;
1274+
1275+
FC_LPORT_DBG(lport, "Entered RSNN_NN state from %s state\n",
1276+
fc_lport_state(lport));
1277+
1278+
fc_lport_state_enter(lport, LPORT_ST_RSNN_NN);
1279+
1280+
len = strnlen(fc_host_symbolic_name(lport->host), 255);
1281+
fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) +
1282+
sizeof(struct fc_ns_rsnn) + len);
1283+
if (!fp) {
1284+
fc_lport_error(lport, fp);
1285+
return;
1286+
}
1287+
1288+
if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSNN_NN,
1289+
fc_lport_rsnn_nn_resp,
1290+
lport, lport->e_d_tov))
1291+
fc_lport_error(lport, fp);
1292+
}
1293+
12061294
/**
12071295
* fc_rport_enter_rnn_id() - Register node name with the name server
12081296
* @lport: Fibre Channel local port to register
@@ -1296,6 +1384,9 @@ static void fc_lport_timeout(struct work_struct *work)
12961384
case LPORT_ST_RNN_ID:
12971385
fc_lport_enter_rnn_id(lport);
12981386
break;
1387+
case LPORT_ST_RSNN_NN:
1388+
fc_lport_enter_rsnn_nn(lport);
1389+
break;
12991390
case LPORT_ST_RFT_ID:
13001391
fc_lport_enter_rft_id(lport);
13011392
break;

‎include/scsi/fc/fc_ns.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum fc_ns_req {
4747
FC_NS_RFT_ID = 0x0217, /* reg FC4 type for ID */
4848
FC_NS_RPN_ID = 0x0212, /* reg port name for ID */
4949
FC_NS_RNN_ID = 0x0213, /* reg node name for ID */
50+
FC_NS_RSNN_NN = 0x0239, /* reg symbolic node name */
5051
};
5152

5253
/*
@@ -156,4 +157,13 @@ struct fc_ns_rn_id {
156157
__be64 fr_wwn; /* node name or port name */
157158
} __attribute__((__packed__));
158159

160+
/*
161+
* RSNN_NN request - register symbolic node name
162+
*/
163+
struct fc_ns_rsnn {
164+
__be64 fr_wwn; /* node name */
165+
__u8 fr_name_len;
166+
char fr_name[];
167+
} __attribute__((__packed__));
168+
159169
#endif /* _FC_NS_H_ */

‎include/scsi/fc_encode.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct fc_ct_req {
3333
struct fc_ns_rn_id rn;
3434
struct fc_ns_rft rft;
3535
struct fc_ns_fid fid;
36+
struct fc_ns_rsnn snn;
3637
} payload;
3738
};
3839

@@ -136,6 +137,15 @@ static inline int fc_ct_fill(struct fc_lport *lport,
136137
put_unaligned_be64(lport->wwnn, &ct->payload.rn.fr_wwn);
137138
break;
138139

140+
case FC_NS_RSNN_NN:
141+
ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rsnn));
142+
put_unaligned_be64(lport->wwnn, &ct->payload.snn.fr_wwn);
143+
strncpy(ct->payload.snn.fr_name,
144+
fc_host_symbolic_name(lport->host), 255);
145+
ct->payload.snn.fr_name_len =
146+
strnlen(ct->payload.snn.fr_name, 255);
147+
break;
148+
139149
default:
140150
return -EINVAL;
141151
}

‎include/scsi/libfc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ enum fc_lport_state {
6262
LPORT_ST_FLOGI,
6363
LPORT_ST_DNS,
6464
LPORT_ST_RNN_ID,
65+
LPORT_ST_RSNN_NN,
6566
LPORT_ST_RFT_ID,
6667
LPORT_ST_SCR,
6768
LPORT_ST_READY,

0 commit comments

Comments
 (0)