Skip to content

Commit 160cb95

Browse files
committed
afs: Better tracing of protocol errors
Include the site of detection of AFS protocol errors in trace lines to better be able to determine what went wrong. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 9ea9ce0 commit 160cb95

File tree

7 files changed

+146
-70
lines changed

7 files changed

+146
-70
lines changed

fs/afs/cmservice.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ static int afs_deliver_cb_callback(struct afs_call *call)
189189
call->count = ntohl(call->tmp);
190190
_debug("FID count: %u", call->count);
191191
if (call->count > AFSCBMAX)
192-
return afs_protocol_error(call, -EBADMSG);
192+
return afs_protocol_error(call, -EBADMSG,
193+
afs_eproto_cb_fid_count);
193194

194195
call->buffer = kmalloc(array3_size(call->count, 3, 4),
195196
GFP_KERNEL);
@@ -234,7 +235,8 @@ static int afs_deliver_cb_callback(struct afs_call *call)
234235
call->count2 = ntohl(call->tmp);
235236
_debug("CB count: %u", call->count2);
236237
if (call->count2 != call->count && call->count2 != 0)
237-
return afs_protocol_error(call, -EBADMSG);
238+
return afs_protocol_error(call, -EBADMSG,
239+
afs_eproto_cb_count);
238240
call->offset = 0;
239241
call->unmarshall++;
240242

fs/afs/fsclient.c

Lines changed: 71 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static int xdr_decode_AFSFetchStatus(struct afs_call *call,
233233

234234
bad:
235235
xdr_dump_bad(*_bp);
236-
return afs_protocol_error(call, -EBADMSG);
236+
return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
237237
}
238238

239239
/*
@@ -399,9 +399,10 @@ static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
399399

400400
/* unmarshall the reply once we've received all of it */
401401
bp = call->buffer;
402-
if (afs_decode_status(call, &bp, &vnode->status, vnode,
403-
&call->expected_version, NULL) < 0)
404-
return afs_protocol_error(call, -EBADMSG);
402+
ret = afs_decode_status(call, &bp, &vnode->status, vnode,
403+
&call->expected_version, NULL);
404+
if (ret < 0)
405+
return ret;
405406
xdr_decode_AFSCallBack(call, vnode, &bp);
406407
if (call->reply[1])
407408
xdr_decode_AFSVolSync(&bp, call->reply[1]);
@@ -580,9 +581,10 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call)
580581
return ret;
581582

582583
bp = call->buffer;
583-
if (afs_decode_status(call, &bp, &vnode->status, vnode,
584-
&vnode->status.data_version, req) < 0)
585-
return afs_protocol_error(call, -EBADMSG);
584+
ret = afs_decode_status(call, &bp, &vnode->status, vnode,
585+
&vnode->status.data_version, req);
586+
if (ret < 0)
587+
return ret;
586588
xdr_decode_AFSCallBack(call, vnode, &bp);
587589
if (call->reply[1])
588590
xdr_decode_AFSVolSync(&bp, call->reply[1]);
@@ -733,10 +735,13 @@ static int afs_deliver_fs_create_vnode(struct afs_call *call)
733735
/* unmarshall the reply once we've received all of it */
734736
bp = call->buffer;
735737
xdr_decode_AFSFid(&bp, call->reply[1]);
736-
if (afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL) < 0 ||
737-
afs_decode_status(call, &bp, &vnode->status, vnode,
738-
&call->expected_version, NULL) < 0)
739-
return afs_protocol_error(call, -EBADMSG);
738+
ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
739+
if (ret < 0)
740+
return ret;
741+
ret = afs_decode_status(call, &bp, &vnode->status, vnode,
742+
&call->expected_version, NULL);
743+
if (ret < 0)
744+
return ret;
740745
xdr_decode_AFSCallBack_raw(&bp, call->reply[3]);
741746
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
742747

@@ -839,9 +844,10 @@ static int afs_deliver_fs_remove(struct afs_call *call)
839844

840845
/* unmarshall the reply once we've received all of it */
841846
bp = call->buffer;
842-
if (afs_decode_status(call, &bp, &vnode->status, vnode,
843-
&call->expected_version, NULL) < 0)
844-
return afs_protocol_error(call, -EBADMSG);
847+
ret = afs_decode_status(call, &bp, &vnode->status, vnode,
848+
&call->expected_version, NULL);
849+
if (ret < 0)
850+
return ret;
845851
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
846852

847853
_leave(" = 0 [done]");
@@ -929,10 +935,13 @@ static int afs_deliver_fs_link(struct afs_call *call)
929935

930936
/* unmarshall the reply once we've received all of it */
931937
bp = call->buffer;
932-
if (afs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL) < 0 ||
933-
afs_decode_status(call, &bp, &dvnode->status, dvnode,
934-
&call->expected_version, NULL) < 0)
935-
return afs_protocol_error(call, -EBADMSG);
938+
ret = afs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
939+
if (ret < 0)
940+
return ret;
941+
ret = afs_decode_status(call, &bp, &dvnode->status, dvnode,
942+
&call->expected_version, NULL);
943+
if (ret < 0)
944+
return ret;
936945
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
937946

938947
_leave(" = 0 [done]");
@@ -1016,10 +1025,13 @@ static int afs_deliver_fs_symlink(struct afs_call *call)
10161025
/* unmarshall the reply once we've received all of it */
10171026
bp = call->buffer;
10181027
xdr_decode_AFSFid(&bp, call->reply[1]);
1019-
if (afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL) ||
1020-
afs_decode_status(call, &bp, &vnode->status, vnode,
1021-
&call->expected_version, NULL) < 0)
1022-
return afs_protocol_error(call, -EBADMSG);
1028+
ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
1029+
if (ret < 0)
1030+
return ret;
1031+
ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1032+
&call->expected_version, NULL);
1033+
if (ret < 0)
1034+
return ret;
10231035
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
10241036

10251037
_leave(" = 0 [done]");
@@ -1122,13 +1134,16 @@ static int afs_deliver_fs_rename(struct afs_call *call)
11221134

11231135
/* unmarshall the reply once we've received all of it */
11241136
bp = call->buffer;
1125-
if (afs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1126-
&call->expected_version, NULL) < 0)
1127-
return afs_protocol_error(call, -EBADMSG);
1128-
if (new_dvnode != orig_dvnode &&
1129-
afs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1130-
&call->expected_version_2, NULL) < 0)
1131-
return afs_protocol_error(call, -EBADMSG);
1137+
ret = afs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
1138+
&call->expected_version, NULL);
1139+
if (ret < 0)
1140+
return ret;
1141+
if (new_dvnode != orig_dvnode) {
1142+
ret = afs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
1143+
&call->expected_version_2, NULL);
1144+
if (ret < 0)
1145+
return ret;
1146+
}
11321147
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
11331148

11341149
_leave(" = 0 [done]");
@@ -1231,9 +1246,10 @@ static int afs_deliver_fs_store_data(struct afs_call *call)
12311246

12321247
/* unmarshall the reply once we've received all of it */
12331248
bp = call->buffer;
1234-
if (afs_decode_status(call, &bp, &vnode->status, vnode,
1235-
&call->expected_version, NULL) < 0)
1236-
return afs_protocol_error(call, -EBADMSG);
1249+
ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1250+
&call->expected_version, NULL);
1251+
if (ret < 0)
1252+
return ret;
12371253
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
12381254

12391255
afs_pages_written_back(vnode, call);
@@ -1407,9 +1423,10 @@ static int afs_deliver_fs_store_status(struct afs_call *call)
14071423

14081424
/* unmarshall the reply once we've received all of it */
14091425
bp = call->buffer;
1410-
if (afs_decode_status(call, &bp, &vnode->status, vnode,
1411-
&call->expected_version, NULL) < 0)
1412-
return afs_protocol_error(call, -EBADMSG);
1426+
ret = afs_decode_status(call, &bp, &vnode->status, vnode,
1427+
&call->expected_version, NULL);
1428+
if (ret < 0)
1429+
return ret;
14131430
/* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
14141431

14151432
_leave(" = 0 [done]");
@@ -1612,7 +1629,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call)
16121629
call->count = ntohl(call->tmp);
16131630
_debug("volname length: %u", call->count);
16141631
if (call->count >= AFSNAMEMAX)
1615-
return afs_protocol_error(call, -EBADMSG);
1632+
return afs_protocol_error(call, -EBADMSG,
1633+
afs_eproto_volname_len);
16161634
call->offset = 0;
16171635
call->unmarshall++;
16181636

@@ -1659,7 +1677,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call)
16591677
call->count = ntohl(call->tmp);
16601678
_debug("offline msg length: %u", call->count);
16611679
if (call->count >= AFSNAMEMAX)
1662-
return afs_protocol_error(call, -EBADMSG);
1680+
return afs_protocol_error(call, -EBADMSG,
1681+
afs_eproto_offline_msg_len);
16631682
call->offset = 0;
16641683
call->unmarshall++;
16651684

@@ -1706,7 +1725,8 @@ static int afs_deliver_fs_get_volume_status(struct afs_call *call)
17061725
call->count = ntohl(call->tmp);
17071726
_debug("motd length: %u", call->count);
17081727
if (call->count >= AFSNAMEMAX)
1709-
return afs_protocol_error(call, -EBADMSG);
1728+
return afs_protocol_error(call, -EBADMSG,
1729+
afs_eproto_motd_len);
17101730
call->offset = 0;
17111731
call->unmarshall++;
17121732

@@ -2109,8 +2129,10 @@ static int afs_deliver_fs_fetch_status(struct afs_call *call)
21092129

21102130
/* unmarshall the reply once we've received all of it */
21112131
bp = call->buffer;
2112-
afs_decode_status(call, &bp, status, vnode,
2113-
&call->expected_version, NULL);
2132+
ret = afs_decode_status(call, &bp, status, vnode,
2133+
&call->expected_version, NULL);
2134+
if (ret < 0)
2135+
return ret;
21142136
callback[call->count].version = ntohl(bp[0]);
21152137
callback[call->count].expiry = ntohl(bp[1]);
21162138
callback[call->count].type = ntohl(bp[2]);
@@ -2206,7 +2228,8 @@ static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
22062228
tmp = ntohl(call->tmp);
22072229
_debug("status count: %u/%u", tmp, call->count2);
22082230
if (tmp != call->count2)
2209-
return afs_protocol_error(call, -EBADMSG);
2231+
return afs_protocol_error(call, -EBADMSG,
2232+
afs_eproto_ibulkst_count);
22102233

22112234
call->count = 0;
22122235
call->unmarshall++;
@@ -2221,10 +2244,11 @@ static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
22212244

22222245
bp = call->buffer;
22232246
statuses = call->reply[1];
2224-
if (afs_decode_status(call, &bp, &statuses[call->count],
2225-
call->count == 0 ? vnode : NULL,
2226-
NULL, NULL) < 0)
2227-
return afs_protocol_error(call, -EBADMSG);
2247+
ret = afs_decode_status(call, &bp, &statuses[call->count],
2248+
call->count == 0 ? vnode : NULL,
2249+
NULL, NULL);
2250+
if (ret < 0)
2251+
return ret;
22282252

22292253
call->count++;
22302254
if (call->count < call->count2)
@@ -2244,7 +2268,8 @@ static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
22442268
tmp = ntohl(call->tmp);
22452269
_debug("CB count: %u", tmp);
22462270
if (tmp != call->count2)
2247-
return afs_protocol_error(call, -EBADMSG);
2271+
return afs_protocol_error(call, -EBADMSG,
2272+
afs_eproto_ibulkst_cb_count);
22482273
call->count = 0;
22492274
call->unmarshall++;
22502275
more_cbs:

fs/afs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int afs_inode_init_from_status(struct afs_vnode *vnode, struct key *key)
8282
default:
8383
printk("kAFS: AFS vnode with undefined type\n");
8484
read_sequnlock_excl(&vnode->cb_lock);
85-
return afs_protocol_error(NULL, -EBADMSG);
85+
return afs_protocol_error(NULL, -EBADMSG, afs_eproto_file_type);
8686
}
8787

8888
inode->i_blocks = 0;

fs/afs/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ extern void afs_flat_call_destructor(struct afs_call *);
931931
extern void afs_send_empty_reply(struct afs_call *);
932932
extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
933933
extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
934-
extern int afs_protocol_error(struct afs_call *, int);
934+
extern int afs_protocol_error(struct afs_call *, int, enum afs_eproto_cause);
935935

936936
static inline int afs_transfer_reply(struct afs_call *call)
937937
{

fs/afs/rxrpc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,9 @@ int afs_extract_data(struct afs_call *call, void *buf, size_t count,
939939
/*
940940
* Log protocol error production.
941941
*/
942-
noinline int afs_protocol_error(struct afs_call *call, int error)
942+
noinline int afs_protocol_error(struct afs_call *call, int error,
943+
enum afs_eproto_cause cause)
943944
{
944-
trace_afs_protocol_error(call, error, __builtin_return_address(0));
945+
trace_afs_protocol_error(call, error, cause);
945946
return error;
946947
}

fs/afs/vlclient.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
451451
call->count2 = ntohl(*bp); /* Type or next count */
452452

453453
if (call->count > YFS_MAXENDPOINTS)
454-
return afs_protocol_error(call, -EBADMSG);
454+
return afs_protocol_error(call, -EBADMSG,
455+
afs_eproto_yvl_fsendpt_num);
455456

456457
alist = afs_alloc_addrlist(call->count, FS_SERVICE, AFS_FS_PORT);
457458
if (!alist)
@@ -475,7 +476,8 @@ static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
475476
size = sizeof(__be32) * (1 + 4 + 1);
476477
break;
477478
default:
478-
return afs_protocol_error(call, -EBADMSG);
479+
return afs_protocol_error(call, -EBADMSG,
480+
afs_eproto_yvl_fsendpt_type);
479481
}
480482

481483
size += sizeof(__be32);
@@ -488,18 +490,21 @@ static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
488490
switch (call->count2) {
489491
case YFS_ENDPOINT_IPV4:
490492
if (ntohl(bp[0]) != sizeof(__be32) * 2)
491-
return afs_protocol_error(call, -EBADMSG);
493+
return afs_protocol_error(call, -EBADMSG,
494+
afs_eproto_yvl_fsendpt4_len);
492495
afs_merge_fs_addr4(alist, bp[1], ntohl(bp[2]));
493496
bp += 3;
494497
break;
495498
case YFS_ENDPOINT_IPV6:
496499
if (ntohl(bp[0]) != sizeof(__be32) * 5)
497-
return afs_protocol_error(call, -EBADMSG);
500+
return afs_protocol_error(call, -EBADMSG,
501+
afs_eproto_yvl_fsendpt6_len);
498502
afs_merge_fs_addr6(alist, bp + 1, ntohl(bp[5]));
499503
bp += 6;
500504
break;
501505
default:
502-
return afs_protocol_error(call, -EBADMSG);
506+
return afs_protocol_error(call, -EBADMSG,
507+
afs_eproto_yvl_fsendpt_type);
503508
}
504509

505510
/* Got either the type of the next entry or the count of
@@ -518,7 +523,8 @@ static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
518523
if (!call->count)
519524
goto end;
520525
if (call->count > YFS_MAXENDPOINTS)
521-
return afs_protocol_error(call, -EBADMSG);
526+
return afs_protocol_error(call, -EBADMSG,
527+
afs_eproto_yvl_vlendpt_type);
522528

523529
call->unmarshall = 3;
524530

@@ -546,7 +552,8 @@ static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
546552
size = sizeof(__be32) * (1 + 4 + 1);
547553
break;
548554
default:
549-
return afs_protocol_error(call, -EBADMSG);
555+
return afs_protocol_error(call, -EBADMSG,
556+
afs_eproto_yvl_vlendpt_type);
550557
}
551558

552559
if (call->count > 1)
@@ -559,16 +566,19 @@ static int afs_deliver_yfsvl_get_endpoints(struct afs_call *call)
559566
switch (call->count2) {
560567
case YFS_ENDPOINT_IPV4:
561568
if (ntohl(bp[0]) != sizeof(__be32) * 2)
562-
return afs_protocol_error(call, -EBADMSG);
569+
return afs_protocol_error(call, -EBADMSG,
570+
afs_eproto_yvl_vlendpt4_len);
563571
bp += 3;
564572
break;
565573
case YFS_ENDPOINT_IPV6:
566574
if (ntohl(bp[0]) != sizeof(__be32) * 5)
567-
return afs_protocol_error(call, -EBADMSG);
575+
return afs_protocol_error(call, -EBADMSG,
576+
afs_eproto_yvl_vlendpt6_len);
568577
bp += 6;
569578
break;
570579
default:
571-
return afs_protocol_error(call, -EBADMSG);
580+
return afs_protocol_error(call, -EBADMSG,
581+
afs_eproto_yvl_vlendpt_type);
572582
}
573583

574584
/* Got either the type of the next entry or the count of

0 commit comments

Comments
 (0)