Skip to content

Commit 42e9041

Browse files
Joe EykholtJames Bottomley
authored andcommitted
[SCSI] libfc: convert rport lookup to be RCU safe
To allow LLD to do lookups on rports without grabbing a mutex, make them RCU-safe. The caller of lport->tt.rport_lookup will have the choice of holding disc_mutex or the rcu_read_lock(). 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 519e513 commit 42e9041

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎drivers/scsi/libfc/fc_disc.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ static void fc_disc_restart(struct fc_disc *);
6363
void fc_disc_stop_rports(struct fc_disc *disc)
6464
{
6565
struct fc_lport *lport;
66-
struct fc_rport_priv *rdata, *next;
66+
struct fc_rport_priv *rdata;
6767

6868
lport = disc->lport;
6969

7070
mutex_lock(&disc->disc_mutex);
71-
list_for_each_entry_safe(rdata, next, &disc->rports, peers)
71+
list_for_each_entry_rcu(rdata, &disc->rports, peers)
7272
lport->tt.rport_logoff(rdata);
7373
mutex_unlock(&disc->disc_mutex);
7474
}
@@ -292,7 +292,7 @@ static void fc_disc_done(struct fc_disc *disc, enum fc_disc_event event)
292292
* Skip ports which were never discovered. These are the dNS port
293293
* and ports which were created by PLOGI.
294294
*/
295-
list_for_each_entry(rdata, &disc->rports, peers) {
295+
list_for_each_entry_rcu(rdata, &disc->rports, peers) {
296296
if (!rdata->disc_id)
297297
continue;
298298
if (rdata->disc_id == disc->disc_id)

‎drivers/scsi/libfc/fc_rport.c‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ static const char *fc_rport_state_names[] = {
9595
* fc_rport_lookup() - Lookup a remote port by port_id
9696
* @lport: The local port to lookup the remote port on
9797
* @port_id: The remote port ID to look up
98+
*
99+
* The caller must hold either disc_mutex or rcu_read_lock().
98100
*/
99101
static struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
100102
u32 port_id)
101103
{
102104
struct fc_rport_priv *rdata;
103105

104-
list_for_each_entry(rdata, &lport->disc.rports, peers)
106+
list_for_each_entry_rcu(rdata, &lport->disc.rports, peers)
105107
if (rdata->ids.port_id == port_id)
106108
return rdata;
107109
return NULL;
@@ -146,10 +148,22 @@ static struct fc_rport_priv *fc_rport_create(struct fc_lport *lport,
146148
INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
147149
INIT_WORK(&rdata->event_work, fc_rport_work);
148150
if (port_id != FC_FID_DIR_SERV)
149-
list_add(&rdata->peers, &lport->disc.rports);
151+
list_add_rcu(&rdata->peers, &lport->disc.rports);
150152
return rdata;
151153
}
152154

155+
/**
156+
* fc_rport_free_rcu() - Free a remote port
157+
* @rcu: The rcu_head structure inside the remote port
158+
*/
159+
static void fc_rport_free_rcu(struct rcu_head *rcu)
160+
{
161+
struct fc_rport_priv *rdata;
162+
163+
rdata = container_of(rcu, struct fc_rport_priv, rcu);
164+
kfree(rdata);
165+
}
166+
153167
/**
154168
* fc_rport_destroy() - Free a remote port after last reference is released
155169
* @kref: The remote port's kref
@@ -159,7 +173,7 @@ static void fc_rport_destroy(struct kref *kref)
159173
struct fc_rport_priv *rdata;
160174

161175
rdata = container_of(kref, struct fc_rport_priv, kref);
162-
kfree(rdata);
176+
call_rcu(&rdata->rcu, fc_rport_free_rcu);
163177
}
164178

165179
/**
@@ -334,7 +348,7 @@ static void fc_rport_work(struct work_struct *work)
334348
mutex_unlock(&rdata->rp_mutex);
335349
} else {
336350
FC_RPORT_DBG(rdata, "work delete\n");
337-
list_del(&rdata->peers);
351+
list_del_rcu(&rdata->peers);
338352
mutex_unlock(&rdata->rp_mutex);
339353
kref_put(&rdata->kref, lport->tt.rport_destroy);
340354
}

‎include/scsi/libfc.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ struct fc_rport_libfc_priv {
195195
* @rp_mutex: The mutex that protects the remote port
196196
* @retry_work: Handle for retries
197197
* @event_callback: Callback when READY, FAILED or LOGO states complete
198+
* @rcu: Structure used for freeing in an RCU-safe manner
198199
*/
199200
struct fc_rport_priv {
200201
struct fc_lport *local_port;
@@ -217,6 +218,7 @@ struct fc_rport_priv {
217218
struct list_head peers;
218219
struct work_struct event_work;
219220
u32 supported_classes;
221+
struct rcu_head rcu;
220222
};
221223

222224
/**

0 commit comments

Comments
 (0)