Skip to content

Commit 744bcd7

Browse files
committed
afs: Allow dumping of server cursor on operation failure
Provide an option to allow the file or volume location server cursor to be dumped if the rotation routine falls off the end without managing to contact a server. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 30062bd commit 744bcd7

5 files changed

Lines changed: 127 additions & 0 deletions

File tree

‎fs/afs/Kconfig‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,15 @@ config AFS_FSCACHE
2727
help
2828
Say Y here if you want AFS data to be cached locally on disk through
2929
the generic filesystem cache manager
30+
31+
config AFS_DEBUG_CURSOR
32+
bool "AFS server cursor debugging"
33+
depends on AFS_FS
34+
help
35+
Say Y here to cause the contents of a server cursor to be dumped to
36+
the dmesg log if the server rotation algorithm fails to successfully
37+
contact a server.
38+
39+
See <file:Documentation/filesystems/afs.txt> for more information.
40+
41+
If unsure, say N.

‎fs/afs/addr_list.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ bool afs_iterate_addresses(struct afs_addr_cursor *ac)
358358
if (!ac->alist)
359359
return false;
360360

361+
ac->nr_iterations++;
362+
361363
if (ac->begun) {
362364
ac->index++;
363365
if (ac->index == ac->alist->nr_addrs)

‎fs/afs/internal.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ struct afs_addr_cursor {
660660
short error;
661661
bool begun; /* T if we've begun iteration */
662662
bool responded; /* T if the current address responded */
663+
unsigned short nr_iterations; /* Number of address iterations */
663664
};
664665

665666
/*
@@ -677,6 +678,7 @@ struct afs_vl_cursor {
677678
#define AFS_VL_CURSOR_STOP 0x0001 /* Set to cease iteration */
678679
#define AFS_VL_CURSOR_RETRY 0x0002 /* Set to do a retry */
679680
#define AFS_VL_CURSOR_RETRIED 0x0004 /* Set if started a retry */
681+
unsigned short nr_iterations; /* Number of server iterations */
680682
};
681683

682684
/*
@@ -700,6 +702,7 @@ struct afs_fs_cursor {
700702
#define AFS_FS_CURSOR_VNOVOL 0x0008 /* Set if seen VNOVOL */
701703
#define AFS_FS_CURSOR_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
702704
#define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
705+
unsigned short nr_iterations; /* Number of server iterations */
703706
};
704707

705708
/*

‎fs/afs/rotate.c‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ bool afs_select_fileserver(struct afs_fs_cursor *fc)
156156
return false;
157157
}
158158

159+
fc->nr_iterations++;
160+
159161
/* Evaluate the result of the previous operation, if there was one. */
160162
switch (error) {
161163
case SHRT_MAX:
@@ -519,13 +521,68 @@ bool afs_select_current_fileserver(struct afs_fs_cursor *fc)
519521
return false;
520522
}
521523

524+
/*
525+
* Dump cursor state in the case of the error being EDESTADDRREQ.
526+
*/
527+
static void afs_dump_edestaddrreq(const struct afs_fs_cursor *fc)
528+
{
529+
static int count;
530+
int i;
531+
532+
if (!IS_ENABLED(CONFIG_AFS_DEBUG_CURSOR) || count > 3)
533+
return;
534+
count++;
535+
536+
rcu_read_lock();
537+
538+
pr_notice("EDESTADDR occurred\n");
539+
pr_notice("FC: cbb=%x cbb2=%x fl=%hx err=%hd\n",
540+
fc->cb_break, fc->cb_break_2, fc->flags, fc->error);
541+
pr_notice("FC: st=%u ix=%u ni=%u\n",
542+
fc->start, fc->index, fc->nr_iterations);
543+
544+
if (fc->server_list) {
545+
const struct afs_server_list *sl = fc->server_list;
546+
pr_notice("FC: SL nr=%u ix=%u vnov=%hx\n",
547+
sl->nr_servers, sl->index, sl->vnovol_mask);
548+
for (i = 0; i < sl->nr_servers; i++) {
549+
const struct afs_server *s = sl->servers[i].server;
550+
pr_notice("FC: server fl=%lx av=%u %pU\n",
551+
s->flags, s->addr_version, &s->uuid);
552+
if (s->addresses) {
553+
const struct afs_addr_list *a =
554+
rcu_dereference(s->addresses);
555+
pr_notice("FC: - av=%u nr=%u/%u/%u ax=%u\n",
556+
a->version,
557+
a->nr_ipv4, a->nr_addrs, a->max_addrs,
558+
a->index);
559+
pr_notice("FC: - pr=%lx yf=%lx\n",
560+
a->probed, a->yfs);
561+
if (a == fc->ac.alist)
562+
pr_notice("FC: - current\n");
563+
}
564+
}
565+
}
566+
567+
pr_notice("AC: as=%u ax=%u ac=%d er=%d b=%u r=%u ni=%u\n",
568+
fc->ac.start, fc->ac.index, fc->ac.abort_code, fc->ac.error,
569+
fc->ac.begun, fc->ac.responded, fc->ac.nr_iterations);
570+
571+
rcu_read_unlock();
572+
}
573+
522574
/*
523575
* Tidy up a filesystem cursor and unlock the vnode.
524576
*/
525577
int afs_end_vnode_operation(struct afs_fs_cursor *fc)
526578
{
527579
struct afs_net *net = afs_v2net(fc->vnode);
528580

581+
if (fc->error == -EDESTADDRREQ ||
582+
fc->error == -ENETUNREACH ||
583+
fc->error == -EHOSTUNREACH)
584+
afs_dump_edestaddrreq(fc);
585+
529586
mutex_unlock(&fc->vnode->io_lock);
530587

531588
afs_end_cursor(&fc->ac);

‎fs/afs/vl_rotate.c‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc)
8383
return false;
8484
}
8585

86+
vc->nr_iterations++;
87+
8688
/* Evaluate the result of the previous operation, if there was one. */
8789
switch (error) {
8890
case SHRT_MAX:
@@ -234,13 +236,64 @@ bool afs_select_vlserver(struct afs_vl_cursor *vc)
234236
return false;
235237
}
236238

239+
/*
240+
* Dump cursor state in the case of the error being EDESTADDRREQ.
241+
*/
242+
static void afs_vl_dump_edestaddrreq(const struct afs_vl_cursor *vc)
243+
{
244+
static int count;
245+
int i;
246+
247+
if (!IS_ENABLED(CONFIG_AFS_DEBUG_CURSOR) || count > 3)
248+
return;
249+
count++;
250+
251+
rcu_read_lock();
252+
pr_notice("EDESTADDR occurred\n");
253+
pr_notice("VC: st=%u ix=%u ni=%hu fl=%hx err=%hd\n",
254+
vc->start, vc->index, vc->nr_iterations, vc->flags, vc->error);
255+
256+
if (vc->server_list) {
257+
const struct afs_vlserver_list *sl = vc->server_list;
258+
pr_notice("VC: SL nr=%u ix=%u\n",
259+
sl->nr_servers, sl->index);
260+
for (i = 0; i < sl->nr_servers; i++) {
261+
const struct afs_vlserver *s = sl->servers[i].server;
262+
pr_notice("VC: server fl=%lx %s+%hu\n",
263+
s->flags, s->name, s->port);
264+
if (s->addresses) {
265+
const struct afs_addr_list *a =
266+
rcu_dereference(s->addresses);
267+
pr_notice("VC: - av=%u nr=%u/%u/%u ax=%u\n",
268+
a->version,
269+
a->nr_ipv4, a->nr_addrs, a->max_addrs,
270+
a->index);
271+
pr_notice("VC: - pr=%lx yf=%lx\n",
272+
a->probed, a->yfs);
273+
if (a == vc->ac.alist)
274+
pr_notice("VC: - current\n");
275+
}
276+
}
277+
}
278+
279+
pr_notice("AC: as=%u ax=%u ac=%d er=%d b=%u r=%u ni=%hu\n",
280+
vc->ac.start, vc->ac.index, vc->ac.abort_code, vc->ac.error,
281+
vc->ac.begun, vc->ac.responded, vc->ac.nr_iterations);
282+
rcu_read_unlock();
283+
}
284+
237285
/*
238286
* Tidy up a volume location server cursor and unlock the vnode.
239287
*/
240288
int afs_end_vlserver_operation(struct afs_vl_cursor *vc)
241289
{
242290
struct afs_net *net = vc->cell->net;
243291

292+
if (vc->error == -EDESTADDRREQ ||
293+
vc->error == -ENETUNREACH ||
294+
vc->error == -EHOSTUNREACH)
295+
afs_vl_dump_edestaddrreq(vc);
296+
244297
afs_end_cursor(&vc->ac);
245298
afs_put_vlserverlist(net, vc->server_list);
246299

0 commit comments

Comments
 (0)