afs: Add a tracepoint for struct afs_addr_list

Add a tracepoint to track the lifetime of the afs_addr_list struct.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
This commit is contained in:
David Howells 2023-10-19 13:59:03 +01:00
parent aa453becce
commit 1e5d849325
10 changed files with 100 additions and 35 deletions

View File

@ -20,17 +20,39 @@ static void afs_free_addrlist(struct rcu_head *rcu)
for (i = 0; i < alist->nr_addrs; i++) for (i = 0; i < alist->nr_addrs; i++)
rxrpc_kernel_put_peer(alist->addrs[i].peer); rxrpc_kernel_put_peer(alist->addrs[i].peer);
trace_afs_alist(alist->debug_id, refcount_read(&alist->usage), afs_alist_trace_free);
kfree(alist);
} }
/* /*
* Release an address list. * Release an address list.
*/ */
void afs_put_addrlist(struct afs_addr_list *alist) void afs_put_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason)
{ {
if (alist && refcount_dec_and_test(&alist->usage)) unsigned int debug_id;
bool dead;
int r;
if (!alist)
return;
debug_id = alist->debug_id;
dead = __refcount_dec_and_test(&alist->usage, &r);
trace_afs_alist(debug_id, r - 1, reason);
if (dead)
call_rcu(&alist->rcu, afs_free_addrlist); call_rcu(&alist->rcu, afs_free_addrlist);
} }
struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason)
{
int r;
if (alist) {
__refcount_inc(&alist->usage, &r);
trace_afs_alist(alist->debug_id, r + 1, reason);
}
return alist;
}
/* /*
* Allocate an address list. * Allocate an address list.
*/ */
@ -38,6 +60,7 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 service_id)
{ {
struct afs_addr_list *alist; struct afs_addr_list *alist;
unsigned int i; unsigned int i;
static atomic_t debug_id;
_enter("%u,%u", nr, service_id); _enter("%u,%u", nr, service_id);
@ -50,9 +73,11 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 service_id)
refcount_set(&alist->usage, 1); refcount_set(&alist->usage, 1);
alist->max_addrs = nr; alist->max_addrs = nr;
alist->debug_id = atomic_inc_return(&debug_id);
for (i = 0; i < nr; i++) for (i = 0; i < nr; i++)
alist->addrs[i].service_id = service_id; alist->addrs[i].service_id = service_id;
trace_afs_alist(alist->debug_id, 1, afs_alist_trace_alloc);
return alist; return alist;
} }
@ -217,7 +242,7 @@ bad_address:
problem, p - text, (int)len, (int)len, text); problem, p - text, (int)len, (int)len, text);
ret = -EINVAL; ret = -EINVAL;
error: error:
afs_put_addrlist(alist); afs_put_addrlist(alist, afs_alist_trace_put_parse_error);
error_vl: error_vl:
afs_put_vlserverlist(net, vllist); afs_put_vlserverlist(net, vllist);
return ERR_PTR(ret); return ERR_PTR(ret);
@ -403,7 +428,7 @@ void afs_end_cursor(struct afs_addr_cursor *ac)
ac->index != alist->preferred && ac->index != alist->preferred &&
test_bit(ac->alist->preferred, &ac->tried)) test_bit(ac->alist->preferred, &ac->tried))
WRITE_ONCE(alist->preferred, ac->index); WRITE_ONCE(alist->preferred, ac->index);
afs_put_addrlist(alist); afs_put_addrlist(alist, afs_alist_trace_put_end_cursor);
ac->alist = NULL; ac->alist = NULL;
} }
} }

View File

@ -205,7 +205,7 @@ void afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *server,
read_lock(&server->fs_lock); read_lock(&server->fs_lock);
ac.alist = rcu_dereference_protected(server->addresses, ac.alist = rcu_dereference_protected(server->addresses,
lockdep_is_held(&server->fs_lock)); lockdep_is_held(&server->fs_lock));
afs_get_addrlist(ac.alist); afs_get_addrlist(ac.alist, afs_alist_trace_get_probe);
read_unlock(&server->fs_lock); read_unlock(&server->fs_lock);
server->probed_at = jiffies; server->probed_at = jiffies;
@ -226,7 +226,7 @@ void afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *server,
afs_fs_probe_not_done(net, server, &ac); afs_fs_probe_not_done(net, server, &ac);
} }
afs_put_addrlist(ac.alist); afs_put_addrlist(ac.alist, afs_alist_trace_put_probe);
} }
/* /*

View File

@ -85,6 +85,7 @@ struct afs_addr_list {
struct rcu_head rcu; struct rcu_head rcu;
refcount_t usage; refcount_t usage;
u32 version; /* Version */ u32 version; /* Version */
unsigned int debug_id;
unsigned char max_addrs; unsigned char max_addrs;
unsigned char nr_addrs; unsigned char nr_addrs;
unsigned char preferred; /* Preferred address */ unsigned char preferred; /* Preferred address */
@ -969,14 +970,9 @@ static inline bool afs_is_folio_dirty_mmapped(unsigned long priv)
/* /*
* addr_list.c * addr_list.c
*/ */
static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist) struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason);
{
if (alist)
refcount_inc(&alist->usage);
return alist;
}
extern struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 service_id); extern struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, u16 service_id);
extern void afs_put_addrlist(struct afs_addr_list *); extern void afs_put_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason);
extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *, extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
const char *, size_t, char, const char *, size_t, char,
unsigned short, unsigned short); unsigned short, unsigned short);

View File

@ -484,7 +484,7 @@ selected_server:
read_lock(&server->fs_lock); read_lock(&server->fs_lock);
alist = rcu_dereference_protected(server->addresses, alist = rcu_dereference_protected(server->addresses,
lockdep_is_held(&server->fs_lock)); lockdep_is_held(&server->fs_lock));
afs_get_addrlist(alist); afs_get_addrlist(alist, afs_alist_trace_get_fsrotate_set);
read_unlock(&server->fs_lock); read_unlock(&server->fs_lock);
retry_server: retry_server:
@ -493,7 +493,7 @@ retry_server:
if (!op->ac.alist) if (!op->ac.alist)
op->ac.alist = alist; op->ac.alist = alist;
else else
afs_put_addrlist(alist); afs_put_addrlist(alist, afs_alist_trace_put_retry_server);
op->ac.index = -1; op->ac.index = -1;

View File

@ -187,7 +187,7 @@ void afs_put_call(struct afs_call *call)
call->type->destructor(call); call->type->destructor(call);
afs_unuse_server_notime(call->net, call->server, afs_server_trace_put_call); afs_unuse_server_notime(call->net, call->server, afs_server_trace_put_call);
afs_put_addrlist(call->alist); afs_put_addrlist(call->alist, afs_alist_trace_put_call);
kfree(call->request); kfree(call->request);
trace_afs_call(call->debug_id, afs_call_trace_free, 0, o, trace_afs_call(call->debug_id, afs_call_trace_free, 0, o,
@ -315,7 +315,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
atomic_read(&call->net->nr_outstanding_calls)); atomic_read(&call->net->nr_outstanding_calls));
call->addr_ix = ac->index; call->addr_ix = ac->index;
call->alist = afs_get_addrlist(ac->alist); call->alist = afs_get_addrlist(ac->alist, afs_alist_trace_get_make_call);
/* Work out the length we're going to transmit. This is awkward for /* Work out the length we're going to transmit. This is awkward for
* calls such as FS.StoreData where there's an extra injection of data * calls such as FS.StoreData where there's an extra injection of data

View File

@ -275,13 +275,13 @@ struct afs_server *afs_lookup_server(struct afs_cell *cell, struct key *key,
candidate = afs_alloc_server(cell, uuid, alist); candidate = afs_alloc_server(cell, uuid, alist);
if (!candidate) { if (!candidate) {
afs_put_addrlist(alist); afs_put_addrlist(alist, afs_alist_trace_put_server_oom);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
server = afs_install_server(cell, candidate); server = afs_install_server(cell, candidate);
if (server != candidate) { if (server != candidate) {
afs_put_addrlist(alist); afs_put_addrlist(alist, afs_alist_trace_put_server_dup);
kfree(candidate); kfree(candidate);
} else { } else {
/* Immediately dispatch an asynchronous probe to each interface /* Immediately dispatch an asynchronous probe to each interface
@ -421,7 +421,8 @@ static void afs_server_rcu(struct rcu_head *rcu)
trace_afs_server(server->debug_id, refcount_read(&server->ref), trace_afs_server(server->debug_id, refcount_read(&server->ref),
atomic_read(&server->active), afs_server_trace_free); atomic_read(&server->active), afs_server_trace_free);
afs_put_addrlist(rcu_access_pointer(server->addresses)); afs_put_addrlist(rcu_access_pointer(server->addresses),
afs_alist_trace_put_server);
kfree(server); kfree(server);
} }
@ -643,7 +644,7 @@ static noinline bool afs_update_server_record(struct afs_operation *op,
write_unlock(&server->fs_lock); write_unlock(&server->fs_lock);
} }
afs_put_addrlist(discard); afs_put_addrlist(discard, afs_alist_trace_put_server_update);
_leave(" = t"); _leave(" = t");
return true; return true;
} }

View File

@ -33,7 +33,8 @@ static void afs_vlserver_rcu(struct rcu_head *rcu)
{ {
struct afs_vlserver *vlserver = container_of(rcu, struct afs_vlserver, rcu); struct afs_vlserver *vlserver = container_of(rcu, struct afs_vlserver, rcu);
afs_put_addrlist(rcu_access_pointer(vlserver->addresses)); afs_put_addrlist(rcu_access_pointer(vlserver->addresses),
afs_alist_trace_put_vlserver);
kfree_rcu(vlserver, rcu); kfree_rcu(vlserver, rcu);
} }
@ -145,7 +146,7 @@ static struct afs_addr_list *afs_extract_vl_addrs(struct afs_net *net,
error: error:
*_b = b; *_b = b;
afs_put_addrlist(alist); afs_put_addrlist(alist, afs_alist_trace_put_parse_error);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
@ -260,7 +261,7 @@ struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *cell,
if (vllist->nr_servers >= nr_servers) { if (vllist->nr_servers >= nr_servers) {
_debug("skip %u >= %u", vllist->nr_servers, nr_servers); _debug("skip %u >= %u", vllist->nr_servers, nr_servers);
afs_put_addrlist(addrs); afs_put_addrlist(addrs, afs_alist_trace_put_parse_empty);
afs_put_vlserver(cell->net, server); afs_put_vlserver(cell->net, server);
continue; continue;
} }
@ -269,7 +270,7 @@ struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *cell,
addrs->status = bs.status; addrs->status = bs.status;
if (addrs->nr_addrs == 0) { if (addrs->nr_addrs == 0) {
afs_put_addrlist(addrs); afs_put_addrlist(addrs, afs_alist_trace_put_parse_empty);
if (!rcu_access_pointer(server->addresses)) { if (!rcu_access_pointer(server->addresses)) {
afs_put_vlserver(cell->net, server); afs_put_vlserver(cell->net, server);
continue; continue;
@ -281,7 +282,7 @@ struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *cell,
old = rcu_replace_pointer(server->addresses, old, old = rcu_replace_pointer(server->addresses, old,
lockdep_is_held(&server->lock)); lockdep_is_held(&server->lock));
write_unlock(&server->lock); write_unlock(&server->lock);
afs_put_addrlist(old); afs_put_addrlist(old, afs_alist_trace_put_vlserver_old);
} }

View File

@ -231,16 +231,11 @@ selected_server:
read_lock(&vlserver->lock); read_lock(&vlserver->lock);
alist = rcu_dereference_protected(vlserver->addresses, alist = rcu_dereference_protected(vlserver->addresses,
lockdep_is_held(&vlserver->lock)); lockdep_is_held(&vlserver->lock));
afs_get_addrlist(alist); afs_get_addrlist(alist, afs_alist_trace_get_vlrotate_set);
read_unlock(&vlserver->lock); read_unlock(&vlserver->lock);
memset(&vc->ac, 0, sizeof(vc->ac)); memset(&vc->ac, 0, sizeof(vc->ac));
vc->ac.alist = alist;
if (!vc->ac.alist)
vc->ac.alist = alist;
else
afs_put_addrlist(alist);
vc->ac.index = -1; vc->ac.index = -1;
iterate_address: iterate_address:

View File

@ -314,7 +314,7 @@ struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *vc,
alist = call->ret_alist; alist = call->ret_alist;
afs_put_call(call); afs_put_call(call);
if (vc->call_error) { if (vc->call_error) {
afs_put_addrlist(alist); afs_put_addrlist(alist, afs_alist_trace_put_getaddru);
return ERR_PTR(vc->call_error); return ERR_PTR(vc->call_error);
} }
return alist; return alist;
@ -668,7 +668,7 @@ struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *vc,
alist = call->ret_alist; alist = call->ret_alist;
afs_put_call(call); afs_put_call(call);
if (vc->call_error) { if (vc->call_error) {
afs_put_addrlist(alist); afs_put_addrlist(alist, afs_alist_trace_put_getaddru);
return ERR_PTR(vc->call_error); return ERR_PTR(vc->call_error);
} }
return alist; return alist;

View File

@ -202,6 +202,27 @@ enum yfs_cm_operation {
EM(afs_cell_trace_use_sbi, "USE sbi ") \ EM(afs_cell_trace_use_sbi, "USE sbi ") \
E_(afs_cell_trace_wait, "WAIT ") E_(afs_cell_trace_wait, "WAIT ")
#define afs_alist_traces \
EM(afs_alist_trace_alloc, "ALLOC ") \
EM(afs_alist_trace_get_fsrotate_set, "GET fs-rot") \
EM(afs_alist_trace_get_make_call, "GET mkcall") \
EM(afs_alist_trace_get_probe, "GET probe ") \
EM(afs_alist_trace_get_vlrotate_set, "GET vl-rot") \
EM(afs_alist_trace_put_call, "PUT call ") \
EM(afs_alist_trace_put_end_cursor, "PUT endcur") \
EM(afs_alist_trace_put_getaddru, "PUT GtAdrU") \
EM(afs_alist_trace_put_parse_empty, "PUT p-empt") \
EM(afs_alist_trace_put_parse_error, "PUT p-err ") \
EM(afs_alist_trace_put_probe, "PUT probe ") \
EM(afs_alist_trace_put_retry_server, "PUT retry ") \
EM(afs_alist_trace_put_server, "PUT server") \
EM(afs_alist_trace_put_server_dup, "PUT sv-dup") \
EM(afs_alist_trace_put_server_oom, "PUT sv-oom") \
EM(afs_alist_trace_put_server_update, "PUT sv-upd") \
EM(afs_alist_trace_put_vlserver, "PUT vlsrvr") \
EM(afs_alist_trace_put_vlserver_old, "PUT vs-old") \
E_(afs_alist_trace_free, "FREE ")
#define afs_fs_operations \ #define afs_fs_operations \
EM(afs_FS_FetchData, "FS.FetchData") \ EM(afs_FS_FetchData, "FS.FetchData") \
EM(afs_FS_FetchStatus, "FS.FetchStatus") \ EM(afs_FS_FetchStatus, "FS.FetchStatus") \
@ -420,6 +441,7 @@ enum yfs_cm_operation {
#define EM(a, b) a, #define EM(a, b) a,
#define E_(a, b) a #define E_(a, b) a
enum afs_alist_trace { afs_alist_traces } __mode(byte);
enum afs_call_trace { afs_call_traces } __mode(byte); enum afs_call_trace { afs_call_traces } __mode(byte);
enum afs_cb_break_reason { afs_cb_break_reasons } __mode(byte); enum afs_cb_break_reason { afs_cb_break_reasons } __mode(byte);
enum afs_cell_trace { afs_cell_traces } __mode(byte); enum afs_cell_trace { afs_cell_traces } __mode(byte);
@ -443,6 +465,7 @@ enum afs_volume_trace { afs_volume_traces } __mode(byte);
#define EM(a, b) TRACE_DEFINE_ENUM(a); #define EM(a, b) TRACE_DEFINE_ENUM(a);
#define E_(a, b) TRACE_DEFINE_ENUM(a); #define E_(a, b) TRACE_DEFINE_ENUM(a);
afs_alist_traces;
afs_call_traces; afs_call_traces;
afs_server_traces; afs_server_traces;
afs_cell_traces; afs_cell_traces;
@ -1330,6 +1353,30 @@ TRACE_EVENT(afs_cell,
__entry->active) __entry->active)
); );
TRACE_EVENT(afs_alist,
TP_PROTO(unsigned int alist_debug_id, int ref, enum afs_alist_trace reason),
TP_ARGS(alist_debug_id, ref, reason),
TP_STRUCT__entry(
__field(unsigned int, alist)
__field(int, ref)
__field(int, active)
__field(int, reason)
),
TP_fast_assign(
__entry->alist = alist_debug_id;
__entry->ref = ref;
__entry->reason = reason;
),
TP_printk("AL=%08x %s r=%d",
__entry->alist,
__print_symbolic(__entry->reason, afs_alist_traces),
__entry->ref)
);
#endif /* _TRACE_AFS_H */ #endif /* _TRACE_AFS_H */
/* This part must be outside protection */ /* This part must be outside protection */