1 From: Chris Leech <christopher.leech@intel.com>
2 Subject: [FcOE] make fc_disc inline with the fc_lport structure
3 References: bnc #459142
5 The extra memory allocation we're not being checked for failure. Rather than
6 further complicating things, just make the discovery code required fields be
7 part of the lport structure.
9 Signed-off-by: Chris Leech <christopher.leech@intel.com>
10 Acked-by: Bernhard Walle <bwalle@suse.de>
13 drivers/scsi/libfc/fc_disc.c | 80 +++++++-----------------------------------
14 drivers/scsi/libfc/fc_lport.c | 2 -
15 include/scsi/libfc.h | 22 ++++++++++-
16 3 files changed, 35 insertions(+), 69 deletions(-)
19 --- a/drivers/scsi/libfc/fc_disc.c
20 +++ b/drivers/scsi/libfc/fc_disc.c
21 @@ -45,26 +45,6 @@ static int fc_disc_debug;
26 - unsigned char retry_count;
27 - unsigned char delay;
28 - unsigned char pending;
29 - unsigned char requested;
30 - unsigned short seq_count;
31 - unsigned char buf_len;
32 - enum fc_disc_event event;
34 - void (*disc_callback)(struct fc_lport *,
35 - enum fc_disc_event);
37 - struct list_head rports;
38 - struct fc_lport *lport;
39 - struct mutex disc_mutex;
40 - struct fc_gpn_ft_resp partial_buf; /* partial name buffer */
41 - struct delayed_work disc_work;
45 static void fc_disc_gpn_ft_req(struct fc_disc *);
46 static void fc_disc_gpn_ft_resp(struct fc_seq *, struct fc_frame *, void *);
47 static int fc_disc_new_target(struct fc_disc *, struct fc_rport *,
48 @@ -83,14 +63,11 @@ static void fc_disc_restart(struct fc_di
49 struct fc_rport *fc_disc_lookup_rport(const struct fc_lport *lport,
52 - struct fc_disc *disc = lport->disc;
53 + const struct fc_disc *disc = &lport->disc;
54 struct fc_rport *rport, *found = NULL;
55 struct fc_rport_libfc_priv *rdata;
61 list_for_each_entry(rdata, &disc->rports, peers) {
62 rport = PRIV_TO_RPORT(rdata);
63 if (rport->port_id == port_id) {
64 @@ -108,27 +85,6 @@ struct fc_rport *fc_disc_lookup_rport(co
68 - * fc_disc_alloc - Allocate a discovery work object
69 - * @lport: The FC lport associated with the discovery job
71 -static inline struct fc_disc *fc_disc_alloc(struct fc_lport *lport)
73 - struct fc_disc *disc;
75 - disc = kzalloc(sizeof(struct fc_disc), GFP_KERNEL);
76 - INIT_DELAYED_WORK(&disc->disc_work, fc_disc_timeout);
77 - mutex_init(&disc->disc_mutex);
78 - INIT_LIST_HEAD(&disc->rports);
80 - disc->lport = lport;
82 - disc->delay = FC_DISC_DELAY;
83 - disc->event = DISC_EV_NONE;
89 * fc_disc_stop_rports - delete all the remote ports associated with the lport
90 * @disc: The discovery job to stop rports on
92 @@ -167,7 +123,7 @@ static void fc_disc_rport_callback(struc
93 enum fc_rport_event event)
95 struct fc_rport_libfc_priv *rdata = rport->dd_data;
96 - struct fc_disc *disc = lport->disc;
97 + struct fc_disc *disc = &lport->disc;
100 FC_DEBUG_DISC("Received a %d event for port (%6x)\n", event,
101 @@ -304,13 +260,7 @@ static void fc_disc_recv_req(struct fc_s
102 struct fc_lport *lport)
105 - struct fc_disc *disc = lport->disc;
108 - FC_DBG("Received a request for an lport not managed "
109 - "by the discovery engine\n");
112 + struct fc_disc *disc = &lport->disc;
114 op = fc_frame_payload_op(fp);
116 @@ -365,17 +315,7 @@ static void fc_disc_start(void (*disc_ca
118 struct fc_rport *rport;
119 struct fc_rport_identifiers ids;
120 - struct fc_disc *disc = lport->disc;
123 - FC_DEBUG_DISC("No existing discovery job, "
124 - "creating one for lport (%6x)\n",
125 - fc_host_port_id(lport->host));
126 - disc = fc_disc_alloc(lport);
128 - FC_DEBUG_DISC("Found an existing discovery job "
129 - "for lport (%6x)\n",
130 - fc_host_port_id(lport->host));
131 + struct fc_disc *disc = &lport->disc;
134 * At this point we may have a new disc job or an existing
135 @@ -831,7 +771,7 @@ out:
137 void fc_disc_stop(struct fc_lport *lport)
139 - struct fc_disc *disc = lport->disc;
140 + struct fc_disc *disc = &lport->disc;
143 cancel_delayed_work_sync(&disc->disc_work);
144 @@ -858,6 +798,7 @@ void fc_disc_stop_final(struct fc_lport
146 int fc_disc_init(struct fc_lport *lport)
148 + struct fc_disc *disc;
150 if (!lport->tt.disc_start)
151 lport->tt.disc_start = fc_disc_start;
152 @@ -874,6 +815,15 @@ int fc_disc_init(struct fc_lport *lport)
153 if (!lport->tt.rport_lookup)
154 lport->tt.rport_lookup = fc_disc_lookup_rport;
156 + disc = &lport->disc;
157 + INIT_DELAYED_WORK(&disc->disc_work, fc_disc_timeout);
158 + mutex_init(&disc->disc_mutex);
159 + INIT_LIST_HEAD(&disc->rports);
161 + disc->lport = lport;
162 + disc->delay = FC_DISC_DELAY;
163 + disc->event = DISC_EV_NONE;
167 EXPORT_SYMBOL(fc_disc_init);
168 --- a/drivers/scsi/libfc/fc_lport.c
169 +++ b/drivers/scsi/libfc/fc_lport.c
170 @@ -627,8 +627,6 @@ int fc_fabric_logoff(struct fc_lport *lp
172 lport->tt.disc_stop_final(lport);
173 mutex_lock(&lport->lp_mutex);
174 - kfree(lport->disc);
175 - lport->disc = NULL;
176 fc_lport_enter_logo(lport);
177 mutex_unlock(&lport->lp_mutex);
179 --- a/include/scsi/libfc.h
180 +++ b/include/scsi/libfc.h
181 @@ -572,7 +572,25 @@ struct libfc_function_template {
182 void (*disc_stop_final) (struct fc_lport *);
186 +/* information used by the discovery layer */
188 + unsigned char retry_count;
189 + unsigned char delay;
190 + unsigned char pending;
191 + unsigned char requested;
192 + unsigned short seq_count;
193 + unsigned char buf_len;
194 + enum fc_disc_event event;
196 + void (*disc_callback)(struct fc_lport *,
197 + enum fc_disc_event);
199 + struct list_head rports;
200 + struct fc_lport *lport;
201 + struct mutex disc_mutex;
202 + struct fc_gpn_ft_resp partial_buf; /* partial name buffer */
203 + struct delayed_work disc_work;
207 struct list_head list;
208 @@ -582,8 +600,8 @@ struct fc_lport {
209 struct fc_exch_mgr *emp;
210 struct fc_rport *dns_rp;
211 struct fc_rport *ptp_rp;
212 - struct fc_disc *disc;
214 + struct fc_disc disc;
216 /* Operational Information */
217 struct libfc_function_template tt;