Skip to content

Commit 3bf0fb6

Browse files
committed
afs: Probe multiple fileservers simultaneously
Send probes to all the unprobed fileservers in a fileserver list on all addresses simultaneously in an attempt to find out the fastest route whilst not getting stuck for 20s on any server or address that we don't get a reply from. This alleviates the problem whereby attempting to access a new server can take a long time because the rotation algorithm ends up rotating through all servers and addresses until it finds one that responds. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 18ac618 commit 3bf0fb6

17 files changed

Lines changed: 1050 additions & 350 deletions

File tree

‎fs/afs/Makefile‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ kafs-y := \
1717
file.o \
1818
flock.o \
1919
fsclient.o \
20+
fs_probe.o \
2021
inode.o \
2122
main.o \
2223
misc.o \
@@ -29,8 +30,9 @@ kafs-y := \
2930
super.o \
3031
netdevices.o \
3132
vlclient.o \
32-
vl_rotate.o \
3333
vl_list.o \
34+
vl_probe.o \
35+
vl_rotate.o \
3436
volume.o \
3537
write.o \
3638
xattr.o \

‎fs/afs/addr_list.c‎

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port)
303303
sizeof(alist->addrs[0]) * (alist->nr_addrs - i));
304304

305305
srx = &alist->addrs[i];
306+
srx->srx_family = AF_RXRPC;
307+
srx->transport_type = SOCK_DGRAM;
306308
srx->transport_len = sizeof(srx->transport.sin);
307309
srx->transport.sin.sin_family = AF_INET;
308310
srx->transport.sin.sin_port = htons(port);
@@ -341,6 +343,8 @@ void afs_merge_fs_addr6(struct afs_addr_list *alist, __be32 *xdr, u16 port)
341343
sizeof(alist->addrs[0]) * (alist->nr_addrs - i));
342344

343345
srx = &alist->addrs[i];
346+
srx->srx_family = AF_RXRPC;
347+
srx->transport_type = SOCK_DGRAM;
344348
srx->transport_len = sizeof(srx->transport.sin6);
345349
srx->transport.sin6.sin6_family = AF_INET6;
346350
srx->transport.sin6.sin6_port = htons(port);
@@ -353,23 +357,32 @@ void afs_merge_fs_addr6(struct afs_addr_list *alist, __be32 *xdr, u16 port)
353357
*/
354358
bool afs_iterate_addresses(struct afs_addr_cursor *ac)
355359
{
356-
_enter("%hu+%hd", ac->start, (short)ac->index);
360+
unsigned long set, failed;
361+
int index;
357362

358363
if (!ac->alist)
359364
return false;
360365

366+
set = ac->alist->responded;
367+
failed = ac->alist->failed;
368+
_enter("%lx-%lx-%lx,%d", set, failed, ac->tried, ac->index);
369+
361370
ac->nr_iterations++;
362371

363-
if (ac->begun) {
364-
ac->index++;
365-
if (ac->index == ac->alist->nr_addrs)
366-
ac->index = 0;
372+
set &= ~(failed | ac->tried);
367373

368-
if (ac->index == ac->start)
369-
return false;
370-
}
374+
if (!set)
375+
return false;
376+
377+
index = READ_ONCE(ac->alist->preferred);
378+
if (test_bit(index, &set))
379+
goto selected;
380+
381+
index = __ffs(set);
371382

372-
ac->begun = true;
383+
selected:
384+
ac->index = index;
385+
set_bit(index, &ac->tried);
373386
ac->responded = false;
374387
return true;
375388
}
@@ -383,12 +396,13 @@ int afs_end_cursor(struct afs_addr_cursor *ac)
383396

384397
alist = ac->alist;
385398
if (alist) {
386-
if (ac->responded && ac->index != ac->start)
387-
WRITE_ONCE(alist->index, ac->index);
399+
if (ac->responded &&
400+
ac->index != alist->preferred &&
401+
test_bit(ac->alist->preferred, &ac->tried))
402+
WRITE_ONCE(alist->preferred, ac->index);
388403
afs_put_addrlist(alist);
404+
ac->alist = NULL;
389405
}
390406

391-
ac->alist = NULL;
392-
ac->begun = false;
393407
return ac->error;
394408
}

‎fs/afs/cmservice.c‎

Lines changed: 94 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ bool afs_cm_incoming_call(struct afs_call *call)
122122
{
123123
_enter("{%u, CB.OP %u}", call->service_id, call->operation_ID);
124124

125+
call->epoch = rxrpc_kernel_get_epoch(call->net->socket, call->rxcall);
126+
125127
switch (call->operation_ID) {
126128
case CBCallBack:
127129
call->type = &afs_SRXCBCallBack;
@@ -151,6 +153,91 @@ bool afs_cm_incoming_call(struct afs_call *call)
151153
}
152154
}
153155

156+
/*
157+
* Record a probe to the cache manager from a server.
158+
*/
159+
static int afs_record_cm_probe(struct afs_call *call, struct afs_server *server)
160+
{
161+
_enter("");
162+
163+
if (test_bit(AFS_SERVER_FL_HAVE_EPOCH, &server->flags) &&
164+
!test_bit(AFS_SERVER_FL_PROBING, &server->flags)) {
165+
if (server->cm_epoch == call->epoch)
166+
return 0;
167+
168+
if (!server->probe.said_rebooted) {
169+
pr_notice("kAFS: FS rebooted %pU\n", &server->uuid);
170+
server->probe.said_rebooted = true;
171+
}
172+
}
173+
174+
spin_lock(&server->probe_lock);
175+
176+
if (!test_bit(AFS_SERVER_FL_HAVE_EPOCH, &server->flags)) {
177+
server->cm_epoch = call->epoch;
178+
server->probe.cm_epoch = call->epoch;
179+
goto out;
180+
}
181+
182+
if (server->probe.cm_probed &&
183+
call->epoch != server->probe.cm_epoch &&
184+
!server->probe.said_inconsistent) {
185+
pr_notice("kAFS: FS endpoints inconsistent %pU\n",
186+
&server->uuid);
187+
server->probe.said_inconsistent = true;
188+
}
189+
190+
if (!server->probe.cm_probed || call->epoch == server->cm_epoch)
191+
server->probe.cm_epoch = server->cm_epoch;
192+
193+
out:
194+
server->probe.cm_probed = true;
195+
spin_unlock(&server->probe_lock);
196+
return 0;
197+
}
198+
199+
/*
200+
* Find the server record by peer address and record a probe to the cache
201+
* manager from a server.
202+
*/
203+
static int afs_find_cm_server_by_peer(struct afs_call *call)
204+
{
205+
struct sockaddr_rxrpc srx;
206+
struct afs_server *server;
207+
208+
rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
209+
210+
server = afs_find_server(call->net, &srx);
211+
if (!server) {
212+
trace_afs_cm_no_server(call, &srx);
213+
return 0;
214+
}
215+
216+
call->cm_server = server;
217+
return afs_record_cm_probe(call, server);
218+
}
219+
220+
/*
221+
* Find the server record by server UUID and record a probe to the cache
222+
* manager from a server.
223+
*/
224+
static int afs_find_cm_server_by_uuid(struct afs_call *call,
225+
struct afs_uuid *uuid)
226+
{
227+
struct afs_server *server;
228+
229+
rcu_read_lock();
230+
server = afs_find_server_by_uuid(call->net, call->request);
231+
rcu_read_unlock();
232+
if (!server) {
233+
trace_afs_cm_no_server_u(call, call->request);
234+
return 0;
235+
}
236+
237+
call->cm_server = server;
238+
return afs_record_cm_probe(call, server);
239+
}
240+
154241
/*
155242
* Clean up a cache manager call.
156243
*/
@@ -187,7 +274,6 @@ static void SRXAFSCB_CallBack(struct work_struct *work)
187274
static int afs_deliver_cb_callback(struct afs_call *call)
188275
{
189276
struct afs_callback_break *cb;
190-
struct sockaddr_rxrpc srx;
191277
__be32 *bp;
192278
int ret, loop;
193279

@@ -276,12 +362,7 @@ static int afs_deliver_cb_callback(struct afs_call *call)
276362

277363
/* we'll need the file server record as that tells us which set of
278364
* vnodes to operate upon */
279-
rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
280-
call->cm_server = afs_find_server(call->net, &srx);
281-
if (!call->cm_server)
282-
trace_afs_cm_no_server(call, &srx);
283-
284-
return afs_queue_call_work(call);
365+
return afs_find_cm_server_by_peer(call);
285366
}
286367

287368
/*
@@ -305,25 +386,18 @@ static void SRXAFSCB_InitCallBackState(struct work_struct *work)
305386
*/
306387
static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
307388
{
308-
struct sockaddr_rxrpc srx;
309389
int ret;
310390

311391
_enter("");
312392

313-
rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
314-
315393
afs_extract_discard(call, 0);
316394
ret = afs_extract_data(call, false);
317395
if (ret < 0)
318396
return ret;
319397

320398
/* we'll need the file server record as that tells us which set of
321399
* vnodes to operate upon */
322-
call->cm_server = afs_find_server(call->net, &srx);
323-
if (!call->cm_server)
324-
trace_afs_cm_no_server(call, &srx);
325-
326-
return afs_queue_call_work(call);
400+
return afs_find_cm_server_by_peer(call);
327401
}
328402

329403
/*
@@ -384,13 +458,7 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
384458

385459
/* we'll need the file server record as that tells us which set of
386460
* vnodes to operate upon */
387-
rcu_read_lock();
388-
call->cm_server = afs_find_server_by_uuid(call->net, call->request);
389-
rcu_read_unlock();
390-
if (!call->cm_server)
391-
trace_afs_cm_no_server_u(call, call->request);
392-
393-
return afs_queue_call_work(call);
461+
return afs_find_cm_server_by_uuid(call, call->request);
394462
}
395463

396464
/*
@@ -422,8 +490,7 @@ static int afs_deliver_cb_probe(struct afs_call *call)
422490

423491
if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
424492
return afs_io_error(call, afs_io_error_cm_reply);
425-
426-
return afs_queue_call_work(call);
493+
return afs_find_cm_server_by_peer(call);
427494
}
428495

429496
/*
@@ -503,8 +570,7 @@ static int afs_deliver_cb_probe_uuid(struct afs_call *call)
503570

504571
if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
505572
return afs_io_error(call, afs_io_error_cm_reply);
506-
507-
return afs_queue_call_work(call);
573+
return afs_find_cm_server_by_uuid(call, call->request);
508574
}
509575

510576
/*
@@ -586,8 +652,7 @@ static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
586652

587653
if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
588654
return afs_io_error(call, afs_io_error_cm_reply);
589-
590-
return afs_queue_call_work(call);
655+
return afs_find_cm_server_by_peer(call);
591656
}
592657

593658
/*
@@ -596,7 +661,6 @@ static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
596661
static int afs_deliver_yfs_cb_callback(struct afs_call *call)
597662
{
598663
struct afs_callback_break *cb;
599-
struct sockaddr_rxrpc srx;
600664
struct yfs_xdr_YFSFid *bp;
601665
size_t size;
602666
int ret, loop;
@@ -664,10 +728,5 @@ static int afs_deliver_yfs_cb_callback(struct afs_call *call)
664728
/* We'll need the file server record as that tells us which set of
665729
* vnodes to operate upon.
666730
*/
667-
rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
668-
call->cm_server = afs_find_server(call->net, &srx);
669-
if (!call->cm_server)
670-
trace_afs_cm_no_server(call, &srx);
671-
672-
return afs_queue_call_work(call);
731+
return afs_find_cm_server_by_peer(call);
673732
}

0 commit comments

Comments
 (0)