Skip to content

Commit 95d0d30

Browse files
Olga KornievskaiaTrond Myklebust
authored andcommitted
SUNRPC create an iterator to list only OFFLINE xprts
Create a new iterator helper that will go thru the all the transports in the switch and return transports that are marked OFFLINE. Signed-off-by: Olga Kornievskaia <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent 88363d3 commit 95d0d30

File tree

3 files changed

+101
-12
lines changed

3 files changed

+101
-12
lines changed

include/linux/sunrpc/xprtmultipath.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ extern void xprt_iter_init(struct rpc_xprt_iter *xpi,
6363
extern void xprt_iter_init_listall(struct rpc_xprt_iter *xpi,
6464
struct rpc_xprt_switch *xps);
6565

66+
extern void xprt_iter_init_listoffline(struct rpc_xprt_iter *xpi,
67+
struct rpc_xprt_switch *xps);
68+
6669
extern void xprt_iter_destroy(struct rpc_xprt_iter *xpi);
6770

6871
extern struct rpc_xprt_switch *xprt_iter_xchg_switch(

net/sunrpc/clnt.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ int rpc_switch_client_transport(struct rpc_clnt *clnt,
786786
EXPORT_SYMBOL_GPL(rpc_switch_client_transport);
787787

788788
static
789-
int rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi)
789+
int _rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi,
790+
void func(struct rpc_xprt_iter *xpi, struct rpc_xprt_switch *xps))
790791
{
791792
struct rpc_xprt_switch *xps;
792793

@@ -795,11 +796,17 @@ int rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi)
795796
rcu_read_unlock();
796797
if (xps == NULL)
797798
return -EAGAIN;
798-
xprt_iter_init_listall(xpi, xps);
799+
func(xpi, xps);
799800
xprt_switch_put(xps);
800801
return 0;
801802
}
802803

804+
static
805+
int rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi)
806+
{
807+
return _rpc_clnt_xprt_iter_init(clnt, xpi, xprt_iter_init_listall);
808+
}
809+
803810
/**
804811
* rpc_clnt_iterate_for_each_xprt - Apply a function to all transports
805812
* @clnt: pointer to client

net/sunrpc/xprtmultipath.c

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef struct rpc_xprt *(*xprt_switch_find_xprt_t)(struct rpc_xprt_switch *xps,
2727
static const struct rpc_xprt_iter_ops rpc_xprt_iter_singular;
2828
static const struct rpc_xprt_iter_ops rpc_xprt_iter_roundrobin;
2929
static const struct rpc_xprt_iter_ops rpc_xprt_iter_listall;
30+
static const struct rpc_xprt_iter_ops rpc_xprt_iter_listoffline;
3031

3132
static void xprt_switch_add_xprt_locked(struct rpc_xprt_switch *xps,
3233
struct rpc_xprt *xprt)
@@ -248,6 +249,18 @@ struct rpc_xprt *xprt_switch_find_first_entry(struct list_head *head)
248249
return NULL;
249250
}
250251

252+
static
253+
struct rpc_xprt *xprt_switch_find_first_entry_offline(struct list_head *head)
254+
{
255+
struct rpc_xprt *pos;
256+
257+
list_for_each_entry_rcu(pos, head, xprt_switch) {
258+
if (!xprt_is_active(pos))
259+
return pos;
260+
}
261+
return NULL;
262+
}
263+
251264
static
252265
struct rpc_xprt *xprt_iter_first_entry(struct rpc_xprt_iter *xpi)
253266
{
@@ -259,23 +272,35 @@ struct rpc_xprt *xprt_iter_first_entry(struct rpc_xprt_iter *xpi)
259272
}
260273

261274
static
262-
struct rpc_xprt *xprt_switch_find_current_entry(struct list_head *head,
263-
const struct rpc_xprt *cur)
275+
struct rpc_xprt *_xprt_switch_find_current_entry(struct list_head *head,
276+
const struct rpc_xprt *cur,
277+
bool find_active)
264278
{
265279
struct rpc_xprt *pos;
266280
bool found = false;
267281

268282
list_for_each_entry_rcu(pos, head, xprt_switch) {
269283
if (cur == pos)
270284
found = true;
271-
if (found && xprt_is_active(pos))
285+
if (found && ((find_active && xprt_is_active(pos)) ||
286+
(!find_active && xprt_is_active(pos))))
272287
return pos;
273288
}
274289
return NULL;
275290
}
276291

277292
static
278-
struct rpc_xprt *xprt_iter_current_entry(struct rpc_xprt_iter *xpi)
293+
struct rpc_xprt *xprt_switch_find_current_entry(struct list_head *head,
294+
const struct rpc_xprt *cur)
295+
{
296+
return _xprt_switch_find_current_entry(head, cur, true);
297+
}
298+
299+
static
300+
struct rpc_xprt * _xprt_iter_current_entry(struct rpc_xprt_iter *xpi,
301+
struct rpc_xprt *first_entry(struct list_head *head),
302+
struct rpc_xprt *current_entry(struct list_head *head,
303+
const struct rpc_xprt *cur))
279304
{
280305
struct rpc_xprt_switch *xps = rcu_dereference(xpi->xpi_xpswitch);
281306
struct list_head *head;
@@ -284,8 +309,30 @@ struct rpc_xprt *xprt_iter_current_entry(struct rpc_xprt_iter *xpi)
284309
return NULL;
285310
head = &xps->xps_xprt_list;
286311
if (xpi->xpi_cursor == NULL || xps->xps_nxprts < 2)
287-
return xprt_switch_find_first_entry(head);
288-
return xprt_switch_find_current_entry(head, xpi->xpi_cursor);
312+
return first_entry(head);
313+
return current_entry(head, xpi->xpi_cursor);
314+
}
315+
316+
static
317+
struct rpc_xprt *xprt_iter_current_entry(struct rpc_xprt_iter *xpi)
318+
{
319+
return _xprt_iter_current_entry(xpi, xprt_switch_find_first_entry,
320+
xprt_switch_find_current_entry);
321+
}
322+
323+
static
324+
struct rpc_xprt *xprt_switch_find_current_entry_offline(struct list_head *head,
325+
const struct rpc_xprt *cur)
326+
{
327+
return _xprt_switch_find_current_entry(head, cur, false);
328+
}
329+
330+
static
331+
struct rpc_xprt *xprt_iter_current_entry_offline(struct rpc_xprt_iter *xpi)
332+
{
333+
return _xprt_iter_current_entry(xpi,
334+
xprt_switch_find_first_entry_offline,
335+
xprt_switch_find_current_entry_offline);
289336
}
290337

291338
bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
@@ -310,15 +357,20 @@ bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
310357

311358
static
312359
struct rpc_xprt *xprt_switch_find_next_entry(struct list_head *head,
313-
const struct rpc_xprt *cur)
360+
const struct rpc_xprt *cur, bool check_active)
314361
{
315362
struct rpc_xprt *pos, *prev = NULL;
316363
bool found = false;
317364

318365
list_for_each_entry_rcu(pos, head, xprt_switch) {
319366
if (cur == prev)
320367
found = true;
321-
if (found && xprt_is_active(pos))
368+
/* for request to return active transports return only
369+
* active, for request to return offline transports
370+
* return only offline
371+
*/
372+
if (found && ((check_active && xprt_is_active(pos)) ||
373+
(!check_active && !xprt_is_active(pos))))
322374
return pos;
323375
prev = pos;
324376
}
@@ -355,7 +407,7 @@ struct rpc_xprt *__xprt_switch_find_next_entry_roundrobin(struct list_head *head
355407
{
356408
struct rpc_xprt *ret;
357409

358-
ret = xprt_switch_find_next_entry(head, cur);
410+
ret = xprt_switch_find_next_entry(head, cur, true);
359411
if (ret != NULL)
360412
return ret;
361413
return xprt_switch_find_first_entry(head);
@@ -397,7 +449,14 @@ static
397449
struct rpc_xprt *xprt_switch_find_next_entry_all(struct rpc_xprt_switch *xps,
398450
const struct rpc_xprt *cur)
399451
{
400-
return xprt_switch_find_next_entry(&xps->xps_xprt_list, cur);
452+
return xprt_switch_find_next_entry(&xps->xps_xprt_list, cur, true);
453+
}
454+
455+
static
456+
struct rpc_xprt *xprt_switch_find_next_entry_offline(struct rpc_xprt_switch *xps,
457+
const struct rpc_xprt *cur)
458+
{
459+
return xprt_switch_find_next_entry(&xps->xps_xprt_list, cur, false);
401460
}
402461

403462
static
@@ -407,6 +466,13 @@ struct rpc_xprt *xprt_iter_next_entry_all(struct rpc_xprt_iter *xpi)
407466
xprt_switch_find_next_entry_all);
408467
}
409468

469+
static
470+
struct rpc_xprt *xprt_iter_next_entry_offline(struct rpc_xprt_iter *xpi)
471+
{
472+
return xprt_iter_next_entry_multiple(xpi,
473+
xprt_switch_find_next_entry_offline);
474+
}
475+
410476
/*
411477
* xprt_iter_rewind - Resets the xprt iterator
412478
* @xpi: pointer to rpc_xprt_iter
@@ -460,6 +526,12 @@ void xprt_iter_init_listall(struct rpc_xprt_iter *xpi,
460526
__xprt_iter_init(xpi, xps, &rpc_xprt_iter_listall);
461527
}
462528

529+
void xprt_iter_init_listoffline(struct rpc_xprt_iter *xpi,
530+
struct rpc_xprt_switch *xps)
531+
{
532+
__xprt_iter_init(xpi, xps, &rpc_xprt_iter_listoffline);
533+
}
534+
463535
/**
464536
* xprt_iter_xchg_switch - Atomically swap out the rpc_xprt_switch
465537
* @xpi: pointer to rpc_xprt_iter
@@ -574,3 +646,10 @@ const struct rpc_xprt_iter_ops rpc_xprt_iter_listall = {
574646
.xpi_xprt = xprt_iter_current_entry,
575647
.xpi_next = xprt_iter_next_entry_all,
576648
};
649+
650+
static
651+
const struct rpc_xprt_iter_ops rpc_xprt_iter_listoffline = {
652+
.xpi_rewind = xprt_iter_default_rewind,
653+
.xpi_xprt = xprt_iter_current_entry_offline,
654+
.xpi_next = xprt_iter_next_entry_offline,
655+
};

0 commit comments

Comments
 (0)