afs, rxrpc: Clean up refcounting on afs_cell and afs_server records
Subsystems (5)
David Howells
maintainercover afs, rxrpc: Clean up refcounting on afs_cell and afs_server records
Here are some patches that fix an occasional hang that's only really encountered when rmmod'ing the kafs module. Arguably, this could also go through the vfs tree, but I have a bunch more primarily crypto and rxrpc patches that need to go through net-next on top of this[1].
Now, at the beginning of this set, I've included five fix patches that are already committed to the net/main branch but that need to be applied first, but haven't made their way into net-next/main or upstream as yet:
rxrpc: rxperf: Fix missing decoding of terminal magic cookie
rxrpc: peer->mtu_lock is redundant
rxrpc: Fix locking issues with the peer record hash
afs: Fix the server_list to unuse a displaced server rather than putting it
afs: Give an afs_server object a ref on the afs_cell object it points to
On top of those, I have:
(1) Remove the "-o autocell" mount option. This is obsolete with the dynamic root and removing it makes the next patch slightly easier.
(2) Change how the dynamic root mount is constructed. Currently, the root directory is (de)populated when it is (un)mounted if there are cells already configured and, further, pairs of automount points have to be created/removed each time a cell is added/deleted.
This is changed so that readdir on the root dir lists all the known cell automount pairs plus the @cell symlinks and the inodes and dentries are constructed by lookup on demand. This simplifies the cell management code.
(3) A few improvements to the afs_volume tracepoint.
(4) A few improvements to the afs_server tracepoint.
(5) Pass trace info into the afs_lookup_cell() function to allow the trace log to indicate the purpose of the lookup.
(6) Remove the 'net' parameter from afs_unuse_cell() as it's superfluous.
(7) In rxrpc, allow a kernel app (such as kafs) to store a word of information on rxrpc_peer records.
(8) Use the information stored on the rxrpc_peer record to point to the afs_server record. This allows the server address lookup to be done away with.
(9) Simplify the afs_server ref/activity accounting to make each one self-contained and not garbage collected from the cell management work item.
(10) Simplify the afs_cell ref/activity accounting to make each one of these also self-contained and not driven by a central management work item.
The current code was intended to make it such that a single timer for the namespace and one work item per cell could do all the work required to maintain these records. This, however, made for some sequencing problems when cleaning up these records. Further, the attempt to pass refs along with timers and work items made getting it right rather tricky when the timer or work item already had a ref attached and now a ref had to be got rid of.
David
The patches can be found on this branch also:
http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=rxrpc-next
David Howells (15):
rxrpc: rxperf: Fix missing decoding of terminal magic cookie
rxrpc: peer->mtu_lock is redundant
rxrpc: Fix locking issues with the peer record hash
afs: Fix the server_list to unuse a displaced server rather than
putting it
afs: Give an afs_server object a ref on the afs_cell object it points
to
afs: Remove the "autocell" mount option
afs: Change dynroot to create contents on demand
afs: Improve afs_volume tracing to display a debug ID
afs: Improve server refcount/active count tracing
afs: Make afs_lookup_cell() take a trace note
afs: Drop the net parameter from afs_unuse_cell()
rxrpc: Allow the app to store private data on peer structs
afs: Use the per-peer app data provided by rxrpc
afs: Fix afs_server ref accounting
afs: Simplify cell record handling
fs/afs/addr_list.c | 50 +++ fs/afs/cell.c | 436 +++++++++++---------------- fs/afs/cmservice.c | 82 +---- fs/afs/dir.c | 5 +- fs/afs/dynroot.c | 484 ++++++++++++----------------- fs/afs/fs_probe.c | 32 +- fs/afs/fsclient.c | 4 +- fs/afs/internal.h | 98 +++--- fs/afs/main.c | 16 +- fs/afs/mntpt.c | 5 +- fs/afs/proc.c | 15 +- fs/afs/rxrpc.c | 8 +- fs/afs/server.c | 602 ++++++++++++++++--------------------- fs/afs/server_list.c | 6 +- fs/afs/super.c | 25 +- fs/afs/vl_alias.c | 7 +- fs/afs/vl_rotate.c | 2 +- fs/afs/volume.c | 15 +- include/net/af_rxrpc.h | 2 + include/trace/events/afs.h | 85 +++--- net/rxrpc/ar-internal.h | 2 +- net/rxrpc/input.c | 2 - net/rxrpc/peer_event.c | 9 +- net/rxrpc/peer_object.c | 35 ++- net/rxrpc/rxperf.c | 12 + 25 files changed, 922 insertions(+), 1117 deletions(-)
David Howells
maintainerPATCH 1/15 rxrpc: rxperf: Fix missing decoding of terminal magic cookie
The rxperf RPCs seem to have a magic cookie at the end of the request that was failing to be taken account of by the unmarshalling of the request. Fix the rxperf code to expect this.
--- net/rxrpc/rxperf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/rxrpc/rxperf.c +12 -0
@@ -478,6 +478,18 @@ static int rxperf_deliver_request(struct rxperf_call *call) call->unmarshal++; fallthrough;case 2 : + ret =rxperf_extract_data (call, true); +if (ret <0 ) +return ret; + +/* Deal with the terminal magic cookie. */ + call->iov_len =4 ; + call->kvec[0 ].iov_len = call->iov_len; + call->kvec[0 ].iov_base = call->tmp; +iov_iter_kvec (&call->iter,READ , call->kvec,1 , call->iov_len); + call->unmarshal++; + fallthrough; +case 3 : ret =rxperf_extract_data (call, false);if (ret <0 )return ret;
David Howells
maintainerPATCH 2/15 rxrpc: peer->mtu_lock is redundant
In reply to David HowellsThe peer->mtu_lock is only used to lock around writes to peer->max_data - and nothing else; further, all such writes take place in the I/O thread and the lock is only ever write-locked and never read-locked.
In a couple of places, the write_seqcount_begin() is wrapped in preempt_disable/enable(), but not in all places. This can cause lockdep to throw a complaint:
WARNING: CPU: 0 PID: 1549 at include/linux/seqlock.h:221 rxrpc_input_ack_trailer+0x305/0x430 ... RIP: 0010:rxrpc_input_ack_trailer+0x305/0x430
Fix this by just getting rid of the lock.
--- net/rxrpc/ar-internal.h | 1 - net/rxrpc/input.c | 2 -- net/rxrpc/peer_event.c | 9 +-------- net/rxrpc/peer_object.c | 1 - 4 files changed, 1 insertion(+), 12 deletions(-)
net/rxrpc/ar-internal.h +0 -1
@@ -360,7 +360,6 @@ struct rxrpc_peer {u8 pmtud_jumbo;/* Max jumbo packets for the MTU */ bool ackr_adv_pmtud;/* T if the peer advertises path-MTU */ unsigned int ackr_max_data;/* Maximum data advertised by peer */ -seqcount_t mtu_lock;/* Lockless MTU access management */ unsigned int if_mtu;/* Local interface MTU (- hdrsize) for this peer */ unsigned int max_data;/* Maximum packet data capacity for this peer */ unsigned short hdrsize;/* header size (IP + UDP + RxRPC) */
net/rxrpc/input.c +0 -2
@@ -810,9 +810,7 @@ static void rxrpc_input_ack_trailer(struct rxrpc_call *call, struct sk_buff *skbif (max_mtu < peer->max_data) {trace_rxrpc_pmtud_reduce (peer, sp->hdr.serial, max_mtu, rxrpc_pmtud_reduce_ack); -write_seqcount_begin (&peer->mtu_lock); peer->max_data = max_mtu; -write_seqcount_end (&peer->mtu_lock); } max_data =umin (max_mtu, peer->max_data);
net/rxrpc/peer_event.c +1 -8
@@ -130,9 +130,7 @@ static void rxrpc_adjust_mtu(struct rxrpc_peer *peer, unsigned int mtu) peer->pmtud_bad = max_data +1 ;trace_rxrpc_pmtud_reduce (peer,0 , max_data, rxrpc_pmtud_reduce_icmp); -write_seqcount_begin (&peer->mtu_lock); peer->max_data = max_data; -write_seqcount_end (&peer->mtu_lock); } }
@@ -408,13 +406,8 @@ void rxrpc_input_probe_for_pmtud(struct rxrpc_connection *conn, rxrpc_serial_t a } max_data =umin (max_data, peer->ackr_max_data); -if (max_data != peer->max_data) { -preempt_disable (); -write_seqcount_begin (&peer->mtu_lock); +if (max_data != peer->max_data) peer->max_data = max_data; -write_seqcount_end (&peer->mtu_lock); -preempt_enable (); - } jumbo = max_data +sizeof (struct rxrpc_jumbo_header ); jumbo /=RXRPC_JUMBO_SUBPKTLEN ;
net/rxrpc/peer_object.c +0 -1
@@ -235,7 +235,6 @@ struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *local, gfp_t gfp, peer->service_conns =RB_ROOT ;seqlock_init (&peer->service_conn_lock);spin_lock_init (&peer->lock); -seqcount_init (&peer->mtu_lock); peer->debug_id =atomic_inc_return (&rxrpc_debug_id); peer->recent_srtt_us =UINT_MAX ; peer->cong_ssthresh =RXRPC_TX_MAX_WINDOW ;
David Howells
maintainerPATCH 3/15 rxrpc: Fix locking issues with the peer record hash
In reply to David Howellsrxrpc_new_incoming_peer() can't use spin_lock_bh() whilst its caller has interrupts disabled.
WARNING: CPU: 0 PID: 1550 at kernel/softirq.c:369 __local_bh_enable_ip+0x46/0xd0
...
Call Trace:
rxrpc_alloc_incoming_call+0x1b0/0x400
rxrpc_new_incoming_call+0x1dd/0x5e0
rxrpc_input_packet+0x84a/0x920
rxrpc_io_thread+0x40d/0xb40
kthread+0x2ec/0x300
ret_from_fork+0x24/0x40
ret_from_fork_asm+0x1a/0x30
</TASK>
irq event stamp: 1811
hardirqs last enabled at (1809): _raw_spin_unlock_irq+0x24/0x50
hardirqs last disabled at (1810): _raw_read_lock_irq+0x17/0x70
softirqs last enabled at (1182): handle_softirqs+0x3ee/0x430
softirqs last disabled at (1811): rxrpc_new_incoming_peer+0x56/0x120Fix this by using a plain spin_lock() instead. IRQs are held, so softirqs can't happen.
--- net/rxrpc/peer_object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/rxrpc/peer_object.c +2 -2
@@ -324,10 +324,10 @@ void rxrpc_new_incoming_peer(struct rxrpc_local *local, struct rxrpc_peer *peer) hash_key =rxrpc_peer_hash_key (local, &peer->srx);rxrpc_init_peer (local, peer, hash_key); -spin_lock_bh (&rxnet->peer_hash_lock); +spin_lock (&rxnet->peer_hash_lock);hash_add_rcu (rxnet->peer_hash, &peer->hash_link, hash_key);list_add_tail (&peer->keepalive_link, &rxnet->peer_keepalive_new); -spin_unlock_bh (&rxnet->peer_hash_lock); +spin_unlock (&rxnet->peer_hash_lock); }/*
David Howells
maintainerPATCH 4/15 afs: Fix the server_list to unuse a displaced server rather than putting it
In reply to David HowellsWhen allocating and building an afs_server_list struct object from a VLDB record, we look up each server address to get the server record for it - but a server may have more than one entry in the record and we discard the duplicate pointers. Currently, however, when we discard, we only put a server record, not unuse it - but the lookup got as an active-user count.
The active-user count on an afs_server_list object determines its lifetime whereas the refcount keeps the memory backing it around. Failing to reduce the active-user counter prevents the record from being cleaned up and can lead to multiple copied being seen - and pointing to deleted afs_cell objects and other such things.
Fix this by switching the incorrect 'put' to an 'unuse' instead.
Without this, occasionally, a dead server record can be seen in /proc/net/afs/servers and list corruption may be observed:
list_del corruption. prev->next should be ffff888102423e40, but was 0000000000000000. (prev=ffff88810140cd38)
--- fs/afs/server_list.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/afs/server_list.c +2 -2
@@ -97,8 +97,8 @@ struct afs_server_list *afs_alloc_server_list(struct afs_volume *volume,break ;if (j < slist->nr_servers) {if (slist->servers[j].server == server) { -afs_put_server (volume->cell->net, server, - afs_server_trace_put_slist_isort); +afs_unuse_server (volume->cell->net, server, + afs_server_trace_put_slist_isort);continue ; }
David Howells
maintainerPATCH 5/15 afs: Give an afs_server object a ref on the afs_cell object it points to
In reply to David HowellsGive an afs_server object a ref on the afs_cell object it points to so that the cell doesn't get deleted before the server record.
Whilst this is circular (cell -> vol -> server_list -> server -> cell), the ref only pins the memory, not the lifetime as that's controlled by the activity counter. When the volume's activity counter reaches 0, it detaches from the cell and discards its server list; when a cell's activity counter reaches 0, it discards its root volume. At that point, the circularity is broken.
--- fs/afs/server.c | 3 +++ include/trace/events/afs.h | 2 ++ 2 files changed, 5 insertions(+)
fs/afs/server.c +3 -0
@@ -163,6 +163,8 @@ static struct afs_server *afs_install_server(struct afs_cell *cell,rb_insert_color (&server->uuid_rb, &net->fs_servers);hlist_add_head_rcu (&server->proc_link, &net->fs_proc); +afs_get_cell (cell, afs_cell_trace_get_server); + added_dup:write_seqlock (&net->fs_addr_lock); estate = rcu_dereference_protected(server->endpoint_state,
@@ -442,6 +444,7 @@ static void afs_server_rcu(struct rcu_head *rcu) atomic_read(&server->active), afs_server_trace_free);afs_put_endpoint_state (rcu_access_pointer (server->endpoint_state), afs_estate_trace_put_server); +afs_put_cell (server->cell, afs_cell_trace_put_server);kfree (server); }
include/trace/events/afs.h +2 -0
@@ -174,6 +174,7 @@ enum yfs_cm_operation { EM(afs_cell_trace_get_queue_dns, "GET q-dns ") \ EM(afs_cell_trace_get_queue_manage, "GET q-mng ") \ EM(afs_cell_trace_get_queue_new, "GET q-new ") \ + EM(afs_cell_trace_get_server, "GET server") \ EM(afs_cell_trace_get_vol, "GET vol ") \ EM(afs_cell_trace_insert, "INSERT ") \EM (afs_cell_trace_manage,"MANAGE " ) \
@@ -182,6 +183,7 @@ enum yfs_cm_operation { EM(afs_cell_trace_put_destroy, "PUT destry") \ EM(afs_cell_trace_put_queue_work, "PUT q-work") \ EM(afs_cell_trace_put_queue_fail, "PUT q-fail") \ + EM(afs_cell_trace_put_server, "PUT server") \ EM(afs_cell_trace_put_vol, "PUT vol ") \ EM(afs_cell_trace_see_source, "SEE source") \EM (afs_cell_trace_see_ws,"SEE ws " ) \
David Howells
maintainerPATCH 6/15 afs: Remove the "autocell" mount option
In reply to David HowellsRemove the "autocell" mount option. It was an attempt to do automounting of arbitrary cells based on what the user looked up but within the root directory of a mounted volume. This isn't really the right thing to do, and using the "dyn" mount option to get the dynamic root is the right way to do it. The kafs-client package uses "-o dyn" when mounting /afs, so it should be safe to drop "-o autocell".
--- fs/afs/dir.c | 5 ++--- fs/afs/dynroot.c | 5 +---- fs/afs/internal.h | 2 -- fs/afs/super.c | 5 ----- 4 files changed, 3 insertions(+), 14 deletions(-)
fs/afs/dir.c +2 -3
@@ -1004,9 +1004,8 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,afs_stat_v (dvnode, n_lookup); inode =afs_do_lookup (dir, dentry);if (inode ==ERR_PTR (-ENOENT )) - inode =afs_try_auto_mntpt (dentry, dir); - -if (!IS_ERR_OR_NULL (inode)) + inode =NULL ; +else if (!IS_ERR_OR_NULL (inode)) fid =AFS_FS_I (inode)->fid;_debug ("splice %p" , dentry->d_inode);
fs/afs/dynroot.c +1 -4
@@ -155,7 +155,7 @@ static int afs_probe_cell_name(struct dentry *dentry)* Try to auto mount the mountpoint with pseudo directory, if the autocell * operation is setted. */ -struct inode *afs_try_auto_mntpt (struct dentry *dentry,struct inode *dir) +static struct inode *afs_try_auto_mntpt (struct dentry *dentry,struct inode *dir) {struct afs_vnode *vnode =AFS_FS_I (dir);struct inode *inode;
@@ -164,9 +164,6 @@ struct inode *afs_try_auto_mntpt(struct dentry *dentry, struct inode *dir)_enter ("%p{%pd}, {%llx:%llu}" , dentry, dentry, vnode->fid.vid, vnode->fid.vnode); -if (!test_bit (AFS_VNODE_AUTOCELL , &vnode->flags)) - goto out; - ret =afs_probe_cell_name (dentry);if (ret <0 ) goto out;
fs/afs/internal.h +0 -2
@@ -700,7 +700,6 @@ struct afs_vnode {#define AFS_VNODE_ZAP_DATA 3/* set if vnode's data should be invalidated */ #define AFS_VNODE_DELETED 4/* set if vnode deleted on server */ #define AFS_VNODE_MOUNTPOINT 5/* set if vnode is a mountpoint symlink */ -#define AFS_VNODE_AUTOCELL 6/* set if Vnode is an auto mount point */ #define AFS_VNODE_PSEUDODIR 7/* set if Vnode is a pseudo directory */ #define AFS_VNODE_NEW_CONTENT 8/* Set if file has new content (create/trunc-0) */ #define AFS_VNODE_SILLY_DELETED 9/* Set if file has been silly-deleted */
@@ -1111,7 +1110,6 @@ extern int afs_silly_iput(struct dentry *, struct inode *);extern const struct inode_operations afs_dynroot_inode_operations;extern const struct dentry_operations afs_dynroot_dentry_operations; -extern struct inode *afs_try_auto_mntpt (struct dentry *,struct inode *);extern int afs_dynroot_mkdir (struct afs_net *,struct afs_cell *);extern void afs_dynroot_rmdir (struct afs_net *,struct afs_cell *);extern int afs_dynroot_populate (struct super_block *);
fs/afs/super.c +0 -5
@@ -194,8 +194,6 @@ static int afs_show_options(struct seq_file *m, struct dentry *root)if (as->dyn_root)seq_puts (m,",dyn" ); -if (test_bit (AFS_VNODE_AUTOCELL , &AFS_FS_I (d_inode (root))->flags)) -seq_puts (m,",autocell" );switch (as->flock_mode) {case afs_flock_mode_unset:break ;case afs_flock_mode_local: p ="local" ;break ;
@@ -478,9 +476,6 @@ static int afs_fill_super(struct super_block *sb, struct afs_fs_context *ctx)if (IS_ERR (inode))return PTR_ERR (inode); -if (ctx->autocell || as->dyn_root) -set_bit (AFS_VNODE_AUTOCELL , &AFS_FS_I (inode)->flags); - ret = -ENOMEM ; sb->s_root =d_make_root (inode);if (!sb->s_root)
David Howells
maintainerPATCH 7/15 afs: Change dynroot to create contents on demand
In reply to David HowellsChange the AFS dynamic root to do things differently:
(1) Rather than having the creation of cell records create inodes and dentries for cell mountpoints, create them on demand during lookup.
This simplifies cell management and locking as we no longer have to create these objects in advance *and* on speculative lookup by the user for a cell that isn't precreated.
(2) Rather than using the libfs dentry-based readdir (the dentries now no longer exist until accessed from (1)), have readdir generate the contents by reading the list of cells. The @cell symlinks get pushed in positions 2 and 3 if rootcell has been configured.
(3) Make the @cell symlink dentries persist for the life of the superblock or until reclaimed, but make cell mountpoints disappear immediately if unused.
It's not perfect as someone doing an "ls -l /afs" may create a whole bunch of dentries which will be garbage collected immediately. But any dentry that gets automounted will be pinned by the mount, so it shouldn't be too bad.
(4) Allocate the inode numbers for the cell mountpoints from an IDR to prevent duplicates appearing in the event it cycles round. The number allocated from the IDR is doubled to provide two inode numbers - one for the normal cell name (RO) and one for the dotted cell name (RW).
--- fs/afs/cell.c | 8 +- fs/afs/dynroot.c | 480 +++++++++++++++---------------------- fs/afs/internal.h | 8 +- fs/afs/main.c | 3 + fs/afs/super.c | 8 +- include/trace/events/afs.h | 2 + 6 files changed, 210 insertions(+), 299 deletions(-)
fs/afs/cell.c +6 -2
@@ -203,7 +203,12 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, cell->dns_status = vllist->status;smp_store_release (&cell->dns_lookup_count,1 );/* vs source/status */ atomic_inc (&net->cells_outstanding); + cell->dynroot_ino =idr_alloc_cyclic (&net->cells_dyn_ino, cell, +2 ,INT_MAX /2 ,GFP_KERNEL ); +if (cell->dynroot_ino <0 ) + goto error; cell->debug_id =atomic_inc_return (&cell_debug_id); +trace_afs_cell (cell->debug_id,1 ,0 , afs_cell_trace_alloc);_leave (" = %p" , cell);
@@ -512,6 +517,7 @@ static void afs_cell_destroy(struct rcu_head *rcu)afs_put_vlserverlist (net,rcu_access_pointer (cell->vl_servers));afs_unuse_cell (net, cell->alias_of, afs_cell_trace_unuse_alias);key_put (cell->anonymous_key); +idr_remove (&net->cells_dyn_ino, cell->dynroot_ino);kfree (cell->name -1 );kfree (cell);
@@ -705,7 +711,6 @@ static int afs_activate_cell(struct afs_net *net, struct afs_cell *cell)if (cell->proc_link.next) cell->proc_link.next->pprev = &cell->proc_link.next; -afs_dynroot_mkdir (net, cell);mutex_unlock (&net->proc_cells_lock);return 0 ; }
@@ -722,7 +727,6 @@ static void afs_deactivate_cell(struct afs_net *net, struct afs_cell *cell)mutex_lock (&net->proc_cells_lock);if (!hlist_unhashed (&cell->proc_link))hlist_del_rcu (&cell->proc_link); -afs_dynroot_rmdir (net, cell);mutex_unlock (&net->proc_cells_lock);_leave ("" );
fs/afs/dynroot.c +195 -285
606 lines not on this page · raw message
fs/afs/internal.h +3 -5
@@ -287,6 +287,7 @@ struct afs_net {/* Cell database */ struct rb_root cells; +struct idr cells_dyn_ino;/* cell->dynroot_ino mapping */ struct afs_cell *ws_cell;struct work_struct cells_manager;struct timer_list cells_timer;
@@ -398,6 +399,7 @@ struct afs_cell { enum dns_lookup_status dns_status:8; /* Latest status of data from lookup */unsigned int dns_lookup_count;/* Counter of DNS lookups */ unsigned int debug_id; +unsigned int dynroot_ino;/* Inode numbers for dynroot (a pair) */ /* The volumes belonging to this cell */ struct rw_semaphore vs_lock;/* Lock for server->volumes */
@@ -1110,10 +1112,7 @@ extern int afs_silly_iput(struct dentry *, struct inode *);extern const struct inode_operations afs_dynroot_inode_operations;extern const struct dentry_operations afs_dynroot_dentry_operations; -extern int afs_dynroot_mkdir (struct afs_net *,struct afs_cell *); -extern void afs_dynroot_rmdir (struct afs_net *,struct afs_cell *); -extern int afs_dynroot_populate (struct super_block *); -extern void afs_dynroot_depopulate (struct super_block *); +struct inode *afs_dynroot_iget_root (struct super_block *sb);/* * file.c
@@ -1226,7 +1225,6 @@ int afs_readlink(struct dentry *dentry, char __user *buffer, int buflen);extern void afs_vnode_commit_status (struct afs_operation *,struct afs_vnode_param *);extern int afs_fetch_status (struct afs_vnode *,struct key *,bool ,afs_access_t *);extern int afs_ilookup5_test_by_fid (struct inode *,void *); -extern struct inode *afs_iget_pseudo_dir (struct super_block *,bool );extern struct inode *afs_iget (struct afs_operation *,struct afs_vnode_param *);extern struct inode *afs_root_iget (struct super_block *,struct key *); extern int afs_getattr(struct mnt_idmap *idmap, const struct path *,
fs/afs/main.c +3 -0
@@ -76,6 +76,7 @@ static int __net_init afs_net_init(struct net *net_ns)mutex_init (&net->socket_mutex); net->cells =RB_ROOT ; +idr_init (&net->cells_dyn_ino);init_rwsem (&net->cells_lock);INIT_WORK (&net->cells_manager, afs_manage_cells);timer_setup (&net->cells_timer, afs_cells_timer,0 );
@@ -137,6 +138,7 @@ static int __net_init afs_net_init(struct net *net_ns) error_proc:afs_put_sysnames (net->sysnames); error_sysnames: +idr_destroy (&net->cells_dyn_ino); net->live = false;return ret; }
@@ -155,6 +157,7 @@ static void __net_exit afs_net_exit(struct net *net_ns)afs_close_socket (net);afs_proc_cleanup (net);afs_put_sysnames (net->sysnames); +idr_destroy (&net->cells_dyn_ino);kfree_rcu (rcu_access_pointer (net->address_prefs), rcu); }
fs/afs/super.c +1 -7
@@ -466,7 +466,7 @@ static int afs_fill_super(struct super_block *sb, struct afs_fs_context *ctx)/* allocate the root inode and dentry */ if (as->dyn_root) { - inode =afs_iget_pseudo_dir (sb, true); + inode =afs_dynroot_iget_root (sb); }else {sprintf (sb->s_id,"%llu" , as->volume->vid);afs_activate_volume (as->volume);
@@ -483,9 +483,6 @@ static int afs_fill_super(struct super_block *sb, struct afs_fs_context *ctx)if (as->dyn_root) { sb->s_d_op = &afs_dynroot_dentry_operations; - ret =afs_dynroot_populate (sb); -if (ret <0 ) - goto error; }else { sb->s_d_op = &afs_fs_dentry_operations;rcu_assign_pointer (as->volume->sb, sb);
@@ -534,9 +531,6 @@ static void afs_kill_super(struct super_block *sb) {struct afs_super_info *as =AFS_FS_S (sb); -if (as->dyn_root) -afs_dynroot_depopulate (sb); -/* Clear the callback interests (which will do ilookup5) before * deactivating the superblock. */
include/trace/events/afs.h +2 -0
@@ -190,8 +190,10 @@ enum yfs_cm_operation { EM(afs_cell_trace_unuse_alias, "UNU alias ") \ EM(afs_cell_trace_unuse_check_alias, "UNU chk-al") \ EM(afs_cell_trace_unuse_delete, "UNU delete") \ + EM(afs_cell_trace_unuse_dynroot_mntpt, "UNU dyn-mp") \ EM(afs_cell_trace_unuse_fc, "UNU fc ") \ EM(afs_cell_trace_unuse_lookup, "UNU lookup") \ + EM(afs_cell_trace_unuse_lookup_dynroot, "UNU lu-dyn") \ EM(afs_cell_trace_unuse_mntpt, "UNU mntpt ") \ EM(afs_cell_trace_unuse_no_pin, "UNU no-pin") \EM (afs_cell_trace_unuse_parse,"UNU parse " ) \
David Howells
maintainerPATCH 8/15 afs: Improve afs_volume tracing to display a debug ID
In reply to David HowellsImprove the tracing of afs_volume objects to include displaying a debug ID so that different instances of volumes with the same "vid" can be distinguished.
Also be consistent about displaying the volume's refcount (and not the cell's).
--- fs/afs/internal.h | 1 + fs/afs/volume.c | 15 +++++++++------ include/trace/events/afs.h | 18 +++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-)
fs/afs/internal.h +1 -0
@@ -623,6 +623,7 @@ struct afs_volume {afs_volid_t vid;/* The volume ID of this volume */ afs_volid_t vids[AFS_MAXTYPES ];/* All associated volume IDs */ refcount_t ref; +unsigned int debug_id;/* Debugging ID for traces */ time64_t update_at;/* Time at which to next update */ struct afs_cell *cell;/* Cell to which belongs (pins ref) */ struct rb_node cell_node;/* Link in cell->volumes */
fs/afs/volume.c +9 -6
@@ -10,6 +10,7 @@#include "internal.h" static unsigned __read_mostly afs_volume_record_life =60 *60 ; +static atomic_t afs_volume_debug_id;static void afs_destroy_volume (struct work_struct *work);
@@ -59,7 +60,7 @@ static void afs_remove_volume_from_cell(struct afs_volume *volume)struct afs_cell *cell = volume->cell;if (!hlist_unhashed (&volume->proc_link)) { -trace_afs_volume (volume->vid,refcount_read (&cell->ref), +trace_afs_volume (volume->debug_id, volume->vid,refcount_read (&volume->ref), afs_volume_trace_remove);write_seqlock (&cell->volume_lock);hlist_del_rcu (&volume->proc_link);
@@ -84,6 +85,7 @@ static struct afs_volume *afs_alloc_volume(struct afs_fs_context *params,if (!volume) goto error_0; + volume->debug_id =atomic_inc_return (&afs_volume_debug_id); volume->vid = vldb->vid[params->type]; volume->update_at =ktime_get_real_seconds () + afs_volume_record_life; volume->cell =afs_get_cell (params->cell, afs_cell_trace_get_vol);
@@ -115,7 +117,7 @@ static struct afs_volume *afs_alloc_volume(struct afs_fs_context *params, *_slist = slist;rcu_assign_pointer (volume->servers, slist); -trace_afs_volume (volume->vid,1 , afs_volume_trace_alloc); +trace_afs_volume (volume->debug_id, volume->vid,1 , afs_volume_trace_alloc);return volume; error_1:
@@ -247,7 +249,7 @@ static void afs_destroy_volume(struct work_struct *work)afs_remove_volume_from_cell (volume);afs_put_serverlist (volume->cell->net, slist);afs_put_cell (volume->cell, afs_cell_trace_put_vol); -trace_afs_volume (volume->vid,refcount_read (&volume->ref), +trace_afs_volume (volume->debug_id, volume->vid,refcount_read (&volume->ref), afs_volume_trace_free);kfree_rcu (volume, rcu);
@@ -262,7 +264,7 @@ bool afs_try_get_volume(struct afs_volume *volume, enum afs_volume_trace reason)int r;if (__refcount_inc_not_zero (&volume->ref, &r)) { -trace_afs_volume (volume->vid, r +1 , reason); +trace_afs_volume (volume->debug_id, volume->vid, r +1 , reason);return true; }return false;
@@ -278,7 +280,7 @@ struct afs_volume *afs_get_volume(struct afs_volume *volume,int r;__refcount_inc (&volume->ref, &r); -trace_afs_volume (volume->vid, r +1 , reason); +trace_afs_volume (volume->debug_id, volume->vid, r +1 , reason); }return volume; }
@@ -290,12 +292,13 @@ struct afs_volume *afs_get_volume(struct afs_volume *volume,void afs_put_volume (struct afs_volume *volume,enum afs_volume_trace reason) {if (volume) { +unsigned int debug_id = volume->debug_id;afs_volid_t vid = volume->vid;bool zero;int r; zero =__refcount_dec_and_test (&volume->ref, &r); -trace_afs_volume (vid, r -1 , reason); +trace_afs_volume (debug_id, vid, r -1 , reason);if (zero)schedule_work (&volume->destructor); }
include/trace/events/afs.h +11 -7
@@ -1539,25 +1539,29 @@ TRACE_EVENT(afs_server, );TRACE_EVENT (afs_volume, - TP_PROTO(afs_volid_t vid, int ref, enum afs_volume_trace reason), + TP_PROTO(unsigned int debug_id, afs_volid_t vid, int ref, + enum afs_volume_trace reason), -TP_ARGS (vid, ref, reason), +TP_ARGS (debug_id, vid, ref, reason),TP_STRUCT__entry ( + __field(unsigned int, debug_id) __field(afs_volid_t, vid) __field(int, ref) __field(enum afs_volume_trace, reason) ),TP_fast_assign ( - __entry->vid = vid; - __entry->ref = ref; - __entry->reason = reason; + __entry->debug_id = debug_id; + __entry->vid = vid; + __entry->ref = ref; + __entry->reason = reason; ), -TP_printk ("V=%llx %s ur=%d" , - __entry->vid, +TP_printk ("V=%08x %s vid=%llx r=%d" , + __entry->debug_id,__print_symbolic (__entry->reason, afs_volume_traces), + __entry->vid, __entry->ref) );
David Howells
maintainerPATCH 9/15 afs: Improve server refcount/active count tracing
In reply to David HowellsImprove server refcount/active count tracing to distinguish between simply getting/putting a ref and using/unusing the server record (which changes the activity count as well as the refcount). This makes it a bit easier to work out what's going on.
--- fs/afs/fsclient.c | 4 ++-- fs/afs/rxrpc.c | 2 +- fs/afs/server.c | 11 ++++++----- fs/afs/server_list.c | 4 ++-- include/trace/events/afs.h | 27 +++++++++++++++------------ 5 files changed, 26 insertions(+), 22 deletions(-)
fs/afs/fsclient.c +2 -2
@@ -1653,7 +1653,7 @@ int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *server, bp = call->request; *bp++ =htonl (FSGIVEUPALLCALLBACKS ); - call->server =afs_use_server (server, afs_server_trace_give_up_cb); + call->server =afs_use_server (server, afs_server_trace_use_give_up_cb);afs_make_call (call,GFP_NOFS );afs_wait_for_call_to_complete (call); ret = call->error;
@@ -1760,7 +1760,7 @@ bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,return false; call->key = key; - call->server =afs_use_server (server, afs_server_trace_get_caps); + call->server =afs_use_server (server, afs_server_trace_use_get_caps); call->peer =rxrpc_kernel_get_peer (estate->addresses->addrs[addr_index].peer); call->probe =afs_get_endpoint_state (estate, afs_estate_trace_get_getcaps); call->probe_index = addr_index;
fs/afs/rxrpc.c +1 -1
@@ -179,7 +179,7 @@ static void afs_free_call(struct afs_call *call)if (call->type->destructor) 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_unuse_call);kfree (call->request); o =atomic_read (&net->nr_outstanding_calls);
fs/afs/server.c +6 -5
@@ -33,7 +33,7 @@ struct afs_server *afs_find_server(struct afs_net *net, const struct rxrpc_peer do { if (server) - afs_unuse_server_notime(net, server, afs_server_trace_put_find_rsq); + afs_unuse_server_notime(net, server, afs_server_trace_unuse_find_rsq); server = NULL; seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&net->fs_addr_lock, &seq);
@@ -49,7 +49,7 @@ struct afs_server *afs_find_server(struct afs_net *net, const struct rxrpc_peer server =NULL ;continue ; found: - server =afs_maybe_use_server (server, afs_server_trace_get_by_addr); + server =afs_maybe_use_server (server, afs_server_trace_use_by_addr); }while (need_seqretry (&net->fs_addr_lock, seq));
@@ -76,7 +76,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_net *net, const uuid_t *uu* changes. */ if (server) -afs_unuse_server (net, server, afs_server_trace_put_uuid_rsq); +afs_unuse_server (net, server, afs_server_trace_unuse_uuid_rsq); server =NULL ; seq++;/* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock (&net->fs_lock, &seq);
@@ -91,7 +91,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_net *net, const uuid_t *uu }else if (diff >0 ) { p = p->rb_right; }else { -afs_use_server (server, afs_server_trace_get_by_uuid); +afs_use_server (server, afs_server_trace_use_by_uuid);break ; }
@@ -273,7 +273,8 @@ static struct afs_addr_list *afs_vl_lookup_addrs(struct afs_cell *cell, }/* -* Get or create a fileserver record. +* Get or create a fileserver record and return it with an active-use count on +* it. */ struct afs_server *afs_lookup_server (struct afs_cell *cell,struct key *key,const uuid_t *uuid,u32 addr_version)
fs/afs/server_list.c +2 -2
@@ -16,7 +16,7 @@ void afs_put_serverlist(struct afs_net *net, struct afs_server_list *slist)if (slist &&refcount_dec_and_test (&slist->usage)) {for (i =0 ; i < slist->nr_servers; i++)afs_unuse_server (net, slist->servers[i].server, - afs_server_trace_put_slist); + afs_server_trace_unuse_slist);kfree_rcu (slist, rcu); } }
@@ -98,7 +98,7 @@ struct afs_server_list *afs_alloc_server_list(struct afs_volume *volume,if (j < slist->nr_servers) {if (slist->servers[j].server == server) {afs_unuse_server (volume->cell->net, server, - afs_server_trace_put_slist_isort); + afs_server_trace_unuse_slist_isort);continue ; }
include/trace/events/afs.h +15 -12
@@ -132,22 +132,25 @@ enum yfs_cm_operation { EM(afs_server_trace_destroy, "DESTROY ") \ EM(afs_server_trace_free, "FREE ") \ EM(afs_server_trace_gc, "GC ") \ - EM(afs_server_trace_get_by_addr, "GET addr ") \ - EM(afs_server_trace_get_by_uuid, "GET uuid ") \ - EM(afs_server_trace_get_caps, "GET caps ") \ EM(afs_server_trace_get_install, "GET inst ") \ - EM(afs_server_trace_get_new_cbi, "GET cbi ") \ EM(afs_server_trace_get_probe, "GET probe") \ - EM(afs_server_trace_give_up_cb, "giveup-cb") \ EM(afs_server_trace_purging, "PURGE ") \ - EM(afs_server_trace_put_call, "PUT call ") \ EM(afs_server_trace_put_cbi, "PUT cbi ") \ - EM(afs_server_trace_put_find_rsq, "PUT f-rsq") \ EM(afs_server_trace_put_probe, "PUT probe") \ - EM(afs_server_trace_put_slist, "PUT slist") \ - EM(afs_server_trace_put_slist_isort, "PUT isort") \ - EM(afs_server_trace_put_uuid_rsq, "PUT u-req") \ - E_(afs_server_trace_update, "UPDATE") + EM(afs_server_trace_see_expired, "SEE expd ") \ + EM(afs_server_trace_unuse_call, "UNU call ") \ + EM(afs_server_trace_unuse_create_fail, "UNU cfail") \ + EM(afs_server_trace_unuse_find_rsq, "UNU f-rsq") \ + EM(afs_server_trace_unuse_slist, "UNU slist") \ + EM(afs_server_trace_unuse_slist_isort, "UNU isort") \ + EM(afs_server_trace_unuse_uuid_rsq, "PUT u-req") \ + EM(afs_server_trace_update, "UPDATE ") \ + EM(afs_server_trace_use_by_addr, "USE addr ") \ + EM(afs_server_trace_use_by_uuid, "USE uuid ") \ + EM(afs_server_trace_use_cm_call, "USE cm-cl") \ + EM(afs_server_trace_use_get_caps, "USE gcaps") \ + EM(afs_server_trace_use_give_up_cb, "USE gvupc") \ + E_(afs_server_trace_wait_create, "WAIT crt ")#define afs_volume_traces \ EM(afs_volume_trace_alloc, "ALLOC ") \
@@ -1531,7 +1534,7 @@ TRACE_EVENT(afs_server, __entry->reason = reason; ), - TP_printk("s=%08x %s u=%d a=%d", + TP_printk("s=%08x %s r=%d a=%d", __entry->server, __print_symbolic(__entry->reason, afs_server_traces), __entry->ref,
David Howells
maintainerPATCH 10/15 afs: Make afs_lookup_cell() take a trace note
In reply to David HowellsPass a note to be added to the afs_cell tracepoint to afs_lookup_cell() so that different callers can be distinguished.
--- fs/afs/cell.c | 13 ++++++++----- fs/afs/dynroot.c | 3 ++- fs/afs/internal.h | 6 ++++-- fs/afs/mntpt.c | 3 ++- fs/afs/proc.c | 3 ++- fs/afs/super.c | 3 ++- fs/afs/vl_alias.c | 3 ++- include/trace/events/afs.h | 7 ++++++- 8 files changed, 28 insertions(+), 13 deletions(-)
fs/afs/cell.c +8 -5
@@ -231,6 +231,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,* @namesz: The strlen of the cell name. * @vllist: A colon/comma separated list of numeric IP addresses or NULL. * @excl: T if an error should be given if the cell name already exists. +* @trace: The reason to be logged if the lookup is successful. * * Look up a cell record by name and query the DNS for VL server addresses if * needed. Note that that actual DNS query is punted off to the manager thread
@@ -239,7 +240,8 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,*/ struct afs_cell *afs_lookup_cell (struct afs_net *net,const char *name,unsigned int namesz, -const char *vllist,bool excl) +const char *vllist,bool excl, +enum afs_cell_trace trace) {struct afs_cell *cell, *candidate, *cursor;struct rb_node *parent, **pp;
@@ -249,7 +251,7 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net,_enter ("%s,%s" , name, vllist);if (!excl) { - cell =afs_find_cell (net, name, namesz, afs_cell_trace_use_lookup); + cell =afs_find_cell (net, name, namesz, trace);if (!IS_ERR (cell)) goto wait_for_cell; }
@@ -325,7 +327,7 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net,if (excl) { ret = -EEXIST ; }else { -afs_use_cell (cursor, afs_cell_trace_use_lookup); +afs_use_cell (cursor, trace); ret =0 ; }up_write (&net->cells_lock);
@@ -380,8 +382,9 @@ int afs_cell_init(struct afs_net *net, const char *rootcell)if (cp && cp < rootcell + len)return -EINVAL ; -/* allocate a cell record for the root cell */ - new_root =afs_lookup_cell (net, rootcell, len, vllist, false); +/* allocate a cell record for the root/workstation cell */ + new_root =afs_lookup_cell (net, rootcell, len, vllist, false, + afs_cell_trace_use_lookup_ws);if (IS_ERR (new_root)) {_leave (" = %ld" ,PTR_ERR (new_root));return PTR_ERR (new_root);
fs/afs/dynroot.c +2 -1
@@ -108,7 +108,8 @@ static struct dentry *afs_dynroot_lookup_cell(struct inode *dir, struct dentry * dotted = true; } - cell =afs_lookup_cell (net, name, len,NULL , false); + cell =afs_lookup_cell (net, name, len,NULL , false, + afs_cell_trace_use_lookup_dynroot);if (IS_ERR (cell)) { ret =PTR_ERR (cell); goto out_no_cell;
fs/afs/internal.h +4 -2
@@ -1046,8 +1046,10 @@ static inline bool afs_cb_is_broken(unsigned int cb_break,extern int afs_cell_init (struct afs_net *,const char *);extern struct afs_cell *afs_find_cell (struct afs_net *,const char *,unsigned ,enum afs_cell_trace ); -extern struct afs_cell *afs_lookup_cell (struct afs_net *,const char *,unsigned , -const char *,bool ); +struct afs_cell *afs_lookup_cell (struct afs_net *net, +const char *name,unsigned int namesz, +const char *vllist,bool excl, +enum afs_cell_trace trace);extern struct afs_cell *afs_use_cell (struct afs_cell *,enum afs_cell_trace );extern void afs_unuse_cell (struct afs_net *,struct afs_cell *,enum afs_cell_trace );extern struct afs_cell *afs_get_cell (struct afs_cell *,enum afs_cell_trace );
fs/afs/mntpt.c +2 -1
@@ -107,7 +107,8 @@ static int afs_mntpt_set_params(struct fs_context *fc, struct dentry *mntpt)if (size >AFS_MAXCELLNAME )return -ENAMETOOLONG ; - cell =afs_lookup_cell (ctx->net, p, size,NULL , false); + cell =afs_lookup_cell (ctx->net, p, size,NULL , false, + afs_cell_trace_use_lookup_mntpt);if (IS_ERR (cell)) {pr_err ("kAFS: unable to lookup cell '%pd'\n" , mntpt);return PTR_ERR (cell);
fs/afs/proc.c +2 -1
@@ -122,7 +122,8 @@ static int afs_proc_cells_write(struct file *file, char *buf, size_t size)if (strcmp (buf,"add" ) ==0 ) {struct afs_cell *cell; - cell =afs_lookup_cell (net, name,strlen (name), args, true); + cell =afs_lookup_cell (net, name,strlen (name), args, true, + afs_cell_trace_use_lookup_add);if (IS_ERR (cell)) { ret =PTR_ERR (cell); goto done;
fs/afs/super.c +2 -1
@@ -290,7 +290,8 @@ static int afs_parse_source(struct fs_context *fc, struct fs_parameter *param)/* lookup the cell record */ if (cellname) { cell =afs_lookup_cell (ctx->net, cellname, cellnamesz, -NULL , false); +NULL , false, + afs_cell_trace_use_lookup_mount);if (IS_ERR (cell)) {pr_err ("kAFS: unable to lookup cell '%*.*s'\n" , cellnamesz, cellnamesz, cellname ?:"" );
fs/afs/vl_alias.c +2 -1
@@ -269,7 +269,8 @@ static int yfs_check_canonical_cell_name(struct afs_cell *cell, struct key *key)if (!name_len || name_len >AFS_MAXCELLNAME ) master =ERR_PTR (-EOPNOTSUPP );else - master =afs_lookup_cell (cell->net, cell_name, name_len,NULL , false); + master =afs_lookup_cell (cell->net, cell_name, name_len,NULL , false, + afs_cell_trace_use_lookup_canonical);kfree (cell_name);if (IS_ERR (master))return PTR_ERR (master);
include/trace/events/afs.h +6 -1
@@ -208,7 +208,12 @@ enum yfs_cm_operation { EM(afs_cell_trace_use_check_alias, "USE chk-al") \ EM(afs_cell_trace_use_fc, "USE fc ") \ EM(afs_cell_trace_use_fc_alias, "USE fc-al ") \ - EM(afs_cell_trace_use_lookup, "USE lookup") \ + EM(afs_cell_trace_use_lookup_add, "USE lu-add") \ + EM(afs_cell_trace_use_lookup_canonical, "USE lu-can") \ + EM(afs_cell_trace_use_lookup_dynroot, "USE lu-dyn") \ + EM(afs_cell_trace_use_lookup_mntpt, "USE lu-mpt") \ + EM(afs_cell_trace_use_lookup_mount, "USE lu-mnt") \ + EM(afs_cell_trace_use_lookup_ws, "USE lu-ws ") \ EM(afs_cell_trace_use_mntpt, "USE mntpt ") \ EM(afs_cell_trace_use_pin, "USE pin ") \EM (afs_cell_trace_use_probe,"USE probe " ) \
David Howells
maintainerPATCH 11/15 afs: Drop the net parameter from afs_unuse_cell()
In reply to David HowellsRemove the redundant net parameter to afs_unuse_cell() as cell->net can be used instead.
--- fs/afs/cell.c | 12 ++++++------ fs/afs/dynroot.c | 4 ++-- fs/afs/internal.h | 2 +- fs/afs/mntpt.c | 2 +- fs/afs/proc.c | 2 +- fs/afs/super.c | 9 ++++----- fs/afs/vl_alias.c | 4 ++-- include/trace/events/afs.h | 1 + 8 files changed, 18 insertions(+), 18 deletions(-)
fs/afs/cell.c +6 -6
@@ -337,7 +337,7 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net, goto wait_for_cell; goto error_noput; error: -afs_unuse_cell (net, cell, afs_cell_trace_unuse_lookup); +afs_unuse_cell (cell, afs_cell_trace_unuse_lookup_error); error_noput:_leave (" = %d [error]" , ret);return ERR_PTR (ret);
@@ -400,7 +400,7 @@ int afs_cell_init(struct afs_net *net, const char *rootcell) net->ws_cell = new_root;up_write (&net->cells_lock); -afs_unuse_cell (net, old_root, afs_cell_trace_unuse_ws); +afs_unuse_cell (old_root, afs_cell_trace_unuse_ws);_leave (" = 0" );return 0 ; }
@@ -518,7 +518,7 @@ static void afs_cell_destroy(struct rcu_head *rcu)trace_afs_cell (cell->debug_id, r,atomic_read (&cell->active), afs_cell_trace_free);afs_put_vlserverlist (net,rcu_access_pointer (cell->vl_servers)); -afs_unuse_cell (net, cell->alias_of, afs_cell_trace_unuse_alias); +afs_unuse_cell (cell->alias_of, afs_cell_trace_unuse_alias);key_put (cell->anonymous_key);idr_remove (&net->cells_dyn_ino, cell->dynroot_ino);kfree (cell->name -1 );
@@ -606,7 +606,7 @@ struct afs_cell *afs_use_cell(struct afs_cell *cell, enum afs_cell_trace reason)* Record a cell becoming less active. When the active counter reaches 1, it * is scheduled for destruction, but may get reactivated. */ -void afs_unuse_cell (struct afs_net *net,struct afs_cell *cell,enum afs_cell_trace reason) +void afs_unuse_cell (struct afs_cell *cell,enum afs_cell_trace reason) {unsigned int debug_id;time64_t now, expire_delay;
@@ -630,7 +630,7 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_trWARN_ON (a ==0 );if (a ==1 )/* 'cell' may now be garbage collected. */ -afs_set_cell_timer (net, expire_delay); +afs_set_cell_timer (cell->net, expire_delay); }/*
@@ -955,7 +955,7 @@ void afs_cell_purge(struct afs_net *net) ws = net->ws_cell; net->ws_cell =NULL ;up_write (&net->cells_lock); -afs_unuse_cell (net, ws, afs_cell_trace_unuse_ws); +afs_unuse_cell (ws, afs_cell_trace_unuse_ws);_debug ("del timer" );if (del_timer_sync (&net->cells_timer))
fs/afs/dynroot.c +2 -2
@@ -125,7 +125,7 @@ static struct dentry *afs_dynroot_lookup_cell(struct inode *dir, struct dentry *return d_splice_alias (inode, dentry); out: -afs_unuse_cell (cell->net, cell, afs_cell_trace_unuse_lookup_dynroot); +afs_unuse_cell (cell, afs_cell_trace_unuse_lookup_dynroot); out_no_cell:if (!inode)return d_splice_alias (inode, dentry);
@@ -167,7 +167,7 @@ static void afs_dynroot_d_release(struct dentry *dentry) {struct afs_cell *cell = dentry->d_fsdata; -afs_unuse_cell (cell->net, cell, afs_cell_trace_unuse_dynroot_mntpt); +afs_unuse_cell (cell, afs_cell_trace_unuse_dynroot_mntpt); }/*
fs/afs/internal.h +1 -1
@@ -1051,7 +1051,7 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net, const char *vllist, bool excl, enum afs_cell_trace trace);extern struct afs_cell *afs_use_cell (struct afs_cell *,enum afs_cell_trace ); -extern void afs_unuse_cell (struct afs_net *,struct afs_cell *,enum afs_cell_trace ); +void afs_unuse_cell (struct afs_cell *cell,enum afs_cell_trace reason);extern struct afs_cell *afs_get_cell (struct afs_cell *,enum afs_cell_trace );extern void afs_see_cell (struct afs_cell *,enum afs_cell_trace );extern void afs_put_cell (struct afs_cell *,enum afs_cell_trace );
fs/afs/mntpt.c +1 -1
@@ -87,7 +87,7 @@ static int afs_mntpt_set_params(struct fs_context *fc, struct dentry *mntpt) ctx->force = true; }if (ctx->cell) { -afs_unuse_cell (ctx->net, ctx->cell, afs_cell_trace_unuse_mntpt); +afs_unuse_cell (ctx->cell, afs_cell_trace_unuse_mntpt); ctx->cell =NULL ; }if (test_bit (AFS_VNODE_PSEUDODIR , &vnode->flags)) {
fs/afs/proc.c +1 -1
@@ -130,7 +130,7 @@ static int afs_proc_cells_write(struct file *file, char *buf, size_t size) }if (test_and_set_bit (AFS_CELL_FL_NO_GC , &cell->flags)) -afs_unuse_cell (net, cell, afs_cell_trace_unuse_no_pin); +afs_unuse_cell (cell, afs_cell_trace_unuse_no_pin); }else { goto inval; }
fs/afs/super.c +4 -5
@@ -297,7 +297,7 @@ static int afs_parse_source(struct fs_context *fc, struct fs_parameter *param) cellnamesz, cellnamesz, cellname ?: "");return PTR_ERR (cell); } -afs_unuse_cell (ctx->net, ctx->cell, afs_cell_trace_unuse_parse); +afs_unuse_cell (ctx->cell, afs_cell_trace_unuse_parse);afs_see_cell (cell, afs_cell_trace_see_source); ctx->cell = cell; }
@@ -394,7 +394,7 @@ static int afs_validate_fc(struct fs_context *fc) ctx->key =NULL ; cell =afs_use_cell (ctx->cell->alias_of, afs_cell_trace_use_fc_alias); -afs_unuse_cell (ctx->net, ctx->cell, afs_cell_trace_unuse_fc); +afs_unuse_cell (ctx->cell, afs_cell_trace_unuse_fc); ctx->cell = cell; goto reget_key; }
@@ -520,9 +520,8 @@ static struct afs_super_info *afs_alloc_sbi(struct fs_context *fc)static void afs_destroy_sbi (struct afs_super_info *as) {if (as) { -struct afs_net *net =afs_net (as->net_ns);afs_put_volume (as->volume, afs_volume_trace_put_destroy_sbi); -afs_unuse_cell (net, as->cell, afs_cell_trace_unuse_sbi); +afs_unuse_cell (as->cell, afs_cell_trace_unuse_sbi);put_net (as->net_ns);kfree (as); }
@@ -605,7 +604,7 @@ static void afs_free_fc(struct fs_context *fc)afs_destroy_sbi (fc->s_fs_info);afs_put_volume (ctx->volume, afs_volume_trace_put_free_fc); -afs_unuse_cell (ctx->net, ctx->cell, afs_cell_trace_unuse_fc); +afs_unuse_cell (ctx->cell, afs_cell_trace_unuse_fc);key_put (ctx->key);kfree (ctx); }
fs/afs/vl_alias.c +2 -2
@@ -205,11 +205,11 @@ static int afs_query_for_alias(struct afs_cell *cell, struct key *key) goto is_alias;if (mutex_lock_interruptible (&cell->net->proc_cells_lock) <0 ) { -afs_unuse_cell (cell->net, p, afs_cell_trace_unuse_check_alias); +afs_unuse_cell (p, afs_cell_trace_unuse_check_alias);return -ERESTARTSYS ; } -afs_unuse_cell (cell->net, p, afs_cell_trace_unuse_check_alias); +afs_unuse_cell (p, afs_cell_trace_unuse_check_alias); }mutex_unlock (&cell->net->proc_cells_lock);
include/trace/events/afs.h +1 -0
@@ -197,6 +197,7 @@ enum yfs_cm_operation { EM(afs_cell_trace_unuse_fc, "UNU fc ") \ EM(afs_cell_trace_unuse_lookup, "UNU lookup") \ EM(afs_cell_trace_unuse_lookup_dynroot, "UNU lu-dyn") \ + EM(afs_cell_trace_unuse_lookup_error, "UNU lu-err") \ EM(afs_cell_trace_unuse_mntpt, "UNU mntpt ") \ EM(afs_cell_trace_unuse_no_pin, "UNU no-pin") \EM (afs_cell_trace_unuse_parse,"UNU parse " ) \
David Howells
maintainerPATCH 12/15 rxrpc: Allow the app to store private data on peer structs
In reply to David HowellsProvide a way for the application (e.g. the afs filesystem) to store private data on the rxrpc_peer structs for later retrieval via the call object.
This will allow afs to store a pointer to the afs_server object on the rxrpc_peer struct, thereby obviating the need for afs to keep lookup tables by which it can associate an incoming call with server that transmitted it.
--- include/net/af_rxrpc.h | 2 ++ net/rxrpc/ar-internal.h | 1 + net/rxrpc/peer_object.c | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+)
include/net/af_rxrpc.h +2 -0
@@ -69,6 +69,8 @@ struct rxrpc_peer *rxrpc_kernel_get_peer(struct rxrpc_peer *peer);struct rxrpc_peer *rxrpc_kernel_get_call_peer (struct socket *sock,struct rxrpc_call *call);const struct sockaddr_rxrpc *rxrpc_kernel_remote_srx (const struct rxrpc_peer *peer);const struct sockaddr *rxrpc_kernel_remote_addr (const struct rxrpc_peer *peer); +unsigned long rxrpc_kernel_set_peer_data (struct rxrpc_peer *peer,unsigned long app_data); +unsigned long rxrpc_kernel_get_peer_data (const struct rxrpc_peer *peer);unsigned int rxrpc_kernel_get_srtt (const struct rxrpc_peer *); int rxrpc_kernel_charge_accept(struct socket *, rxrpc_notify_rx_t, rxrpc_user_attach_call_t, unsigned long, gfp_t,
net/rxrpc/ar-internal.h +1 -0
@@ -344,6 +344,7 @@ struct rxrpc_peer {struct hlist_head error_targets;/* targets for net error distribution */ struct rb_root service_conns;/* Service connections */ struct list_head keepalive_link;/* Link in net->peer_keepalive[] */ +unsigned long app_data;/* Application data (e.g. afs_server) */ time64_t last_tx_at;/* Last time packet sent here */ seqlock_t service_conn_lock;spinlock_t lock;/* access lock */
net/rxrpc/peer_object.c +26 -0
@@ -520,3 +520,29 @@ const struct sockaddr *rxrpc_kernel_remote_addr(const struct rxrpc_peer *peer) (peer ? &peer->srx.transport : &rxrpc_null_addr.transport); }EXPORT_SYMBOL (rxrpc_kernel_remote_addr); + +/** +* rxrpc_kernel_set_peer_data - Set app-specific data on a peer. +* @peer: The peer to alter +* @app_data: The data to set +* +* Set the app-specific data on a peer. AF_RXRPC makes no effort to retain +* anything the data might refer to. The previous app_data is returned. +*/ +unsigned long rxrpc_kernel_set_peer_data (struct rxrpc_peer *peer,unsigned long app_data) +{ +return xchg (&peer->app_data, app_data); +} +EXPORT_SYMBOL (rxrpc_kernel_set_peer_data); + +/** +* rxrpc_kernel_get_peer_data - Get app-specific data from a peer. +* @peer: The peer to query +* +* Retrieve the app-specific data from a peer. +*/ +unsigned long rxrpc_kernel_get_peer_data (const struct rxrpc_peer *peer) +{ +return peer->app_data; +} +EXPORT_SYMBOL (rxrpc_kernel_get_peer_data);
David Howells
maintainerPATCH 13/15 afs: Use the per-peer app data provided by rxrpc
In reply to David HowellsMake use of the per-peer application data that rxrpc now allows the application to store on the rxrpc_peer struct to hold a back pointer to the afs_server record that peer represents an endpoint for.
Then, when a call comes in to the AFS cache manager, this can be used to map it to the correct server record rather than having to use a UUID-to-server mapping table and having to do an additional lookup.
--- fs/afs/addr_list.c | 50 +++++++++++++++++++++++ fs/afs/cmservice.c | 82 ++++++-------------------------------- fs/afs/fs_probe.c | 32 ++++++++++----- fs/afs/internal.h | 9 +++-- fs/afs/proc.c | 10 ++++- fs/afs/rxrpc.c | 6 +++ fs/afs/server.c | 46 ++++++--------------- include/trace/events/afs.h | 4 +- net/rxrpc/peer_object.c | 4 +- 9 files changed, 120 insertions(+), 123 deletions(-)
fs/afs/addr_list.c +50 -0
@@ -362,3 +362,53 @@ int afs_merge_fs_addr6(struct afs_net *net, struct afs_addr_list *alist, alist->nr_addrs++;return 0 ; } + +/* +* Set the app data on the rxrpc peers an address list points to +*/ +void afs_set_peer_appdata (struct afs_server *server, +struct afs_addr_list *old_alist, +struct afs_addr_list *new_alist) +{ +unsigned long data = (unsigned long )server; +int n =0 , o =0 ; + +if (!old_alist) { +/* New server. Just set all. */ +for (; n < new_alist->nr_addrs; n++) +rxrpc_kernel_set_peer_data (new_alist->addrs[n].peer, data); +return ; + } +if (!new_alist) { +/* Dead server. Just remove all. */ +for (; o < old_alist->nr_addrs; o++) +rxrpc_kernel_set_peer_data (old_alist->addrs[o].peer,0 ); +return ; + } + +/* Walk through the two lists simultaneously, setting new peers and +* clearing old ones. The two lists are ordered by pointer to peer +* record. +*/ +while (n < new_alist->nr_addrs && o < old_alist->nr_addrs) { +struct rxrpc_peer *pn = new_alist->addrs[n].peer; +struct rxrpc_peer *po = old_alist->addrs[o].peer; + +if (pn == po) +continue ; +if (pn < po) { +rxrpc_kernel_set_peer_data (pn, data); + n++; + }else { +rxrpc_kernel_set_peer_data (po,0 ); + o++; + } + } + +if (n < new_alist->nr_addrs) +for (; n < new_alist->nr_addrs; n++) +rxrpc_kernel_set_peer_data (new_alist->addrs[n].peer, data); +if (o < old_alist->nr_addrs) +for (; o < old_alist->nr_addrs; o++) +rxrpc_kernel_set_peer_data (old_alist->addrs[o].peer,0 ); +}
fs/afs/cmservice.c +13 -69
137 lines not on this page · raw message
fs/afs/fs_probe.c +22 -10
@@ -235,20 +235,20 @@ void afs_fileserver_probe_result(struct afs_call *call)* Probe all of a fileserver's addresses to find out the best route and to * query its capabilities. */ -void afs_fs_probe_fileserver (struct afs_net *net,struct afs_server *server, -struct afs_addr_list *new_alist,struct key *key) +int afs_fs_probe_fileserver (struct afs_net *net,struct afs_server *server, +struct afs_addr_list *new_alist,struct key *key) {struct afs_endpoint_state *estate, *old; -struct afs_addr_list *alist; +struct afs_addr_list *old_alist =NULL , *alist;unsigned long unprobed;_enter ("%pU" , &server->uuid); estate =kzalloc (sizeof (*estate),GFP_KERNEL );if (!estate) -return ; +return -ENOMEM ; -refcount_set (&estate->ref,1 ); +refcount_set (&estate->ref,2 ); estate->server_id = server->debug_id; estate->rtt =UINT_MAX ;
@@ -256,21 +256,31 @@ void afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *server, old =rcu_dereference_protected (server->endpoint_state,lockdep_is_held (&server->fs_lock)); - estate->responsive_set = old->responsive_set; - estate->addresses =afs_get_addrlist (new_alist ?: old->addresses, - afs_alist_trace_get_estate); +if (old) { + estate->responsive_set = old->responsive_set; +if (!new_alist) + new_alist = old->addresses; + } + +if (old_alist != new_alist) +afs_set_peer_appdata (server, old_alist, new_alist); + + estate->addresses =afs_get_addrlist (new_alist, afs_alist_trace_get_estate); alist = estate->addresses; estate->probe_seq = ++server->probe_counter;atomic_set (&estate->nr_probing, alist->nr_addrs); +if (new_alist) + server->addr_version = new_alist->version;rcu_assign_pointer (server->endpoint_state, estate); -set_bit (AFS_ESTATE_SUPERSEDED , &old->flags);write_unlock (&server->fs_lock); +if (old) +set_bit (AFS_ESTATE_SUPERSEDED , &old->flags);trace_afs_estate (estate->server_id, estate->probe_seq,refcount_read (&estate->ref), afs_estate_trace_alloc_probe); -afs_get_address_preferences (net, alist); +afs_get_address_preferences (net, new_alist); server->probed_at = jiffies; unprobed = (1UL << alist->nr_addrs) -1 ;
@@ -293,6 +303,8 @@ void afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *server, }afs_put_endpoint_state (old, afs_estate_trace_put_probe); +afs_put_endpoint_state (estate, afs_estate_trace_put_probe); +return 0 ; }/*
fs/afs/internal.h +6 -3
@@ -1010,6 +1010,9 @@ extern int afs_merge_fs_addr4(struct afs_net *net, struct afs_addr_list *addr, __be32 xdr, u16 port);extern int afs_merge_fs_addr6 (struct afs_net *net,struct afs_addr_list *addr,__be32 *xdr,u16 port); +void afs_set_peer_appdata (struct afs_server *server, +struct afs_addr_list *old_alist, +struct afs_addr_list *new_alist);/* * addr_prefs.c
@@ -1207,8 +1210,8 @@ struct afs_endpoint_state *afs_get_endpoint_state(struct afs_endpoint_state *est enum afs_estate_trace where);void afs_put_endpoint_state (struct afs_endpoint_state *estate,enum afs_estate_trace where);extern void afs_fileserver_probe_result (struct afs_call *); -void afs_fs_probe_fileserver (struct afs_net *net,struct afs_server *server, -struct afs_addr_list *new_addrs,struct key *key); +int afs_fs_probe_fileserver (struct afs_net *net,struct afs_server *server, +struct afs_addr_list *new_alist,struct key *key);int afs_wait_for_fs_probes (struct afs_operation *op,struct afs_server_state *states,bool intr);extern void afs_probe_fileserver (struct afs_net *,struct afs_server *);extern void afs_fs_probe_dispatcher (struct work_struct *);
@@ -1509,7 +1512,7 @@ extern void __exit afs_clean_up_permit_cache(void);*/ extern spinlock_t afs_server_peer_lock; -extern struct afs_server *afs_find_server (struct afs_net *,const struct rxrpc_peer *); +struct afs_server *afs_find_server (const struct rxrpc_peer *peer);extern struct afs_server *afs_find_server_by_uuid (struct afs_net *,const uuid_t *);extern struct afs_server *afs_lookup_server (struct afs_cell *,struct key *,const uuid_t *,u32 );extern struct afs_server *afs_get_server (struct afs_server *,enum afs_server_trace );
fs/afs/proc.c +8 -2
@@ -444,8 +444,6 @@ static int afs_proc_servers_show(struct seq_file *m, void *v) } server = list_entry(v, struct afs_server, proc_link); - estate =rcu_dereference (server->endpoint_state); - alist = estate->addresses; seq_printf(m, "%pU %3d %3d %s\n", &server->uuid, refcount_read(&server->ref),
@@ -455,10 +453,16 @@ static int afs_proc_servers_show(struct seq_file *m, void *v) server->flags, server->rtt);seq_printf (m," - probe: last=%d\n" , (int )(jiffies - server->probed_at) /HZ ); + + estate =rcu_dereference (server->endpoint_state); +if (!estate) + goto out; failed = estate->failed_set;seq_printf (m," - ESTATE pq=%x np=%u rsp=%lx f=%lx\n" , estate->probe_seq,atomic_read (&estate->nr_probing), estate->responsive_set, estate->failed_set); + + alist = estate->addresses;seq_printf (m," - ALIST v=%u ap=%u\n" , alist->version, alist->addr_pref_version);for (i =0 ; i < alist->nr_addrs; i++) {
@@ -471,6 +475,8 @@ static int afs_proc_servers_show(struct seq_file *m, void *v)rxrpc_kernel_get_srtt (addr->peer), addr->last_error, addr->prio); } + +out:return 0 ; }
fs/afs/rxrpc.c +6 -0
@@ -766,8 +766,14 @@ static void afs_rx_discard_new_call(struct rxrpc_call *rxcall,static void afs_rx_new_call (struct sock *sk,struct rxrpc_call *rxcall,unsigned long user_call_ID) { +struct afs_call *call = (struct afs_call *)user_call_ID;struct afs_net *net =afs_sock2net (sk); + call->peer =rxrpc_kernel_get_call_peer (sk->sk_socket, call->rxcall); + call->server =afs_find_server (call->peer); +if (!call->server) +trace_afs_cm_no_server (call,rxrpc_kernel_remote_srx (call->peer)); +queue_work (afs_wq, &net->charge_preallocation_work); }
fs/afs/server.c +12 -34
63 lines not on this page · raw message
include/trace/events/afs.h +1 -3
@@ -140,12 +140,10 @@ enum yfs_cm_operation { EM(afs_server_trace_see_expired, "SEE expd ") \ EM(afs_server_trace_unuse_call, "UNU call ") \ EM(afs_server_trace_unuse_create_fail, "UNU cfail") \ - EM(afs_server_trace_unuse_find_rsq, "UNU f-rsq") \ EM(afs_server_trace_unuse_slist, "UNU slist") \ EM(afs_server_trace_unuse_slist_isort, "UNU isort") \ EM(afs_server_trace_unuse_uuid_rsq, "PUT u-req") \ EM(afs_server_trace_update, "UPDATE ") \ - EM(afs_server_trace_use_by_addr, "USE addr ") \ EM(afs_server_trace_use_by_uuid, "USE uuid ") \ EM(afs_server_trace_use_cm_call, "USE cm-cl") \EM (afs_server_trace_use_get_caps,"USE gcaps" ) \
@@ -1281,7 +1279,7 @@ TRACE_EVENT(afs_bulkstat_error, ); TRACE_EVENT(afs_cm_no_server, - TP_PROTO(struct afs_call *call, struct sockaddr_rxrpc *srx), + TP_PROTO(struct afs_call *call, const struct sockaddr_rxrpc *srx), TP_ARGS(call, srx),
net/rxrpc/peer_object.c +2 -2
@@ -461,7 +461,7 @@ void rxrpc_destroy_all_peers(struct rxrpc_net *rxnet)continue ;hlist_for_each_entry (peer, &rxnet->peer_hash[i], hash_link) { -pr_err ("Leaked peer %u {%u} %pISp\n" , +pr_err ("Leaked peer %x {%u} %pISp\n" , peer->debug_id,refcount_read (&peer->ref), &peer->srx.transport);
@@ -478,7 +478,7 @@ void rxrpc_destroy_all_peers(struct rxrpc_net *rxnet)*/ struct rxrpc_peer *rxrpc_kernel_get_call_peer (struct socket *sock,struct rxrpc_call *call) { -return call->peer; +return rxrpc_get_peer (call->peer, rxrpc_peer_get_application); }EXPORT_SYMBOL (rxrpc_kernel_get_call_peer);
David Howells
maintainerPATCH 14/15 afs: Fix afs_server ref accounting
In reply to David HowellsThe current way that afs_server refs are accounted and cleaned up sometimes cause rmmod to hang when it is waiting for cell records to be removed. The problem is that the cell cleanup might occasionally happen before the server cleanup and then there's nothing that causes the cell to garbage-collect the remaining servers as they become inactive.
Partially fix this by:
(1) Give each afs_server record its own management timer that rather than relying on the cell manager's central timer to drive each individual cell's maintenance work item to garbage collect servers.
This timer is set when afs_unuse_server() reduces a server's activity count to zero and will schedule the server's destroyer work item upon firing.
(2) Give each afs_server record its own destroyer work item that removes the record from the cell's database, shuts down the timer, cancels any pending work for itself, sends an RPC to the server to cancel outstanding callbacks.
This change, in combination with the timer, obviates the need to try and coordinate so closely between the cell record and a bunch of other server records to try and tear everything down in a coordinated fashion. With this, the cell record is pinned until the server RCU is complete and namespace/module removal will wait until all the cell records are removed.
(3) Now that incoming calls are mapped to servers (and thus cells) using data attached to an rxrpc_peer, the UUID-to-server mapping tree is moved from the namespace to the cell (cell->fs_servers). This means there can no longer be duplicates therein - and that allows the mapping tree to be simpler as there doesn't need to be a chain of same-UUID servers that are in different cells.
(4) The lock protecting the UUID mapping tree is switched to an rw_semaphore on the cell rather than a seqlock on the namespace as it's now only used during mounting in contexts in which we're allowed to sleep.
(5) When it comes time for a cell that is being removed to purge its set of servers, it just needs to iterate over them and wake them up. Once a server becomes inactive, its destroyer work item will observe the state of the cell and immediately remove that record.
(6) When a server record is removed, it is marked AFS_SERVER_FL_EXPIRED to prevent reattempts at removal. The record will be dispatched to RCU for destruction once its refcount reaches 0.
(7) The AFS_SERVER_FL_UNCREATED/CREATING flags are used to synchronise simultaneous creation attempts. If one attempt fails, it will abandon the attempt and allow another to try again.
Note that the record can't just be abandoned when dead as it's bound into a server list attached to a volume and only subject to replacement if the server list obtained for the volume from the VLDB changes.
--- fs/afs/cell.c | 3 +- fs/afs/fsclient.c | 4 +- fs/afs/internal.h | 54 ++-- fs/afs/main.c | 10 +- fs/afs/server.c | 564 ++++++++++++++++--------------------- fs/afs/server_list.c | 4 +- include/trace/events/afs.h | 7 +- 7 files changed, 289 insertions(+), 357 deletions(-)
fs/afs/cell.c +2 -1
@@ -168,7 +168,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,INIT_HLIST_HEAD (&cell->proc_volumes);seqlock_init (&cell->volume_lock); cell->fs_servers =RB_ROOT ; -seqlock_init (&cell->fs_lock); +init_rwsem (&cell->fs_lock);rwlock_init (&cell->vl_servers_lock); cell->flags = (1 <<AFS_CELL_FL_CHECK_ALIAS );
@@ -836,6 +836,7 @@ static void afs_manage_cell(struct afs_cell *cell)/* The root volume is pinning the cell */ afs_put_volume (cell->root_volume, afs_volume_trace_put_cell_root); cell->root_volume =NULL ; +afs_purge_servers (cell);afs_put_cell (cell, afs_cell_trace_put_destroy); }
fs/afs/fsclient.c +2 -2
@@ -1653,7 +1653,7 @@ int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *server, bp = call->request; *bp++ =htonl (FSGIVEUPALLCALLBACKS ); - call->server =afs_use_server (server, afs_server_trace_use_give_up_cb); + call->server =afs_use_server (server, false, afs_server_trace_use_give_up_cb);afs_make_call (call,GFP_NOFS );afs_wait_for_call_to_complete (call); ret = call->error;
@@ -1760,7 +1760,7 @@ bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,return false; call->key = key; - call->server =afs_use_server (server, afs_server_trace_use_get_caps); + call->server =afs_use_server (server, false, afs_server_trace_use_get_caps); call->peer =rxrpc_kernel_get_peer (estate->addresses->addrs[addr_index].peer); call->probe =afs_get_endpoint_state (estate, afs_estate_trace_get_getcaps); call->probe_index = addr_index;
fs/afs/internal.h +29 -25
101 lines not on this page · raw message
fs/afs/main.c +2 -8
@@ -86,16 +86,10 @@ static int __net_init afs_net_init(struct net *net_ns)INIT_HLIST_HEAD (&net->proc_cells);seqlock_init (&net->fs_lock); - net->fs_servers =RB_ROOT ;INIT_LIST_HEAD (&net->fs_probe_fast);INIT_LIST_HEAD (&net->fs_probe_slow);INIT_HLIST_HEAD (&net->fs_proc); -INIT_HLIST_HEAD (&net->fs_addresses); -seqlock_init (&net->fs_addr_lock); - -INIT_WORK (&net->fs_manager, afs_manage_servers); -timer_setup (&net->fs_timer, afs_servers_timer,0 );INIT_WORK (&net->fs_prober, afs_fs_probe_dispatcher);timer_setup (&net->fs_probe_timer, afs_fs_probe_timer,0 );atomic_set (&net->servers_outstanding,1 );
@@ -131,7 +125,7 @@ static int __net_init afs_net_init(struct net *net_ns) net->live = false;afs_fs_probe_cleanup (net);afs_cell_purge (net); -afs_purge_servers (net); +afs_wait_for_servers (net); error_cell_init: net->live = false;afs_proc_cleanup (net);
@@ -153,7 +147,7 @@ static void __net_exit afs_net_exit(struct net *net_ns) net->live = false;afs_fs_probe_cleanup (net);afs_cell_purge (net); -afs_purge_servers (net); +afs_wait_for_servers (net);afs_close_socket (net);afs_proc_cleanup (net);afs_put_sysnames (net->sysnames);
fs/afs/server.c +248 -316
765 lines not on this page · raw message
fs/afs/server_list.c +2 -2
@@ -97,8 +97,8 @@ struct afs_server_list *afs_alloc_server_list(struct afs_volume *volume,break ;if (j < slist->nr_servers) {if (slist->servers[j].server == server) { -afs_unuse_server (volume->cell->net, server, - afs_server_trace_unuse_slist_isort); +afs_unuse_server_notime (volume->cell->net, server, + afs_server_trace_unuse_slist_isort);continue ; }
include/trace/events/afs.h +4 -3
@@ -127,7 +127,6 @@ enum yfs_cm_operation { E_(afs_call_trace_work, "QUEUE")#define afs_server_traces \ - EM(afs_server_trace_alloc, "ALLOC ") \ EM(afs_server_trace_callback, "CALLBACK ") \ EM(afs_server_trace_destroy, "DESTROY ") \ EM(afs_server_trace_free, "FREE ") \
@@ -137,12 +136,14 @@ enum yfs_cm_operation { EM(afs_server_trace_purging, "PURGE ") \ EM(afs_server_trace_put_cbi, "PUT cbi ") \ EM(afs_server_trace_put_probe, "PUT probe") \ + EM(afs_server_trace_see_destroyer, "SEE destr") \ EM(afs_server_trace_see_expired, "SEE expd ") \ + EM(afs_server_trace_see_purge, "SEE purge") \ + EM(afs_server_trace_see_timer, "SEE timer") \ EM(afs_server_trace_unuse_call, "UNU call ") \ EM(afs_server_trace_unuse_create_fail, "UNU cfail") \ EM(afs_server_trace_unuse_slist, "UNU slist") \ EM(afs_server_trace_unuse_slist_isort, "UNU isort") \ - EM(afs_server_trace_unuse_uuid_rsq, "PUT u-req") \ EM(afs_server_trace_update, "UPDATE ") \ EM(afs_server_trace_use_by_uuid, "USE uuid ") \EM (afs_server_trace_use_cm_call,"USE cm-cl" ) \
@@ -229,7 +230,7 @@ enum yfs_cm_operation { 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_server_dup, "PUT sv-dup") \ + EM(afs_alist_trace_put_server_create, "PUT sv-crt") \ 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_vlgetcaps,"PUT vgtcap" ) \
David Howells
maintainerPATCH 15/15 afs: Simplify cell record handling
In reply to David HowellsSimplify afs_cell record handling to avoid very occasional races that cause module removal to hang (it waits for all cell records to be removed).
There are two things that particularly contribute to the difficulty:
firstly, the code tries to pass a ref on the cell to the cell's maintenance work item (which gets awkward if the work item is already queued); and, secondly, there's an overall cell manager that tries to use just one timer for the entire cell collection (to avoid having loads of timers). However, both of these are probably unnecessarily restrictive.
To simplify this, the following changes are made:
(1) The cell record collection manager is removed. Each cell record manages itself individually.
(2) Each afs_cell is given a second work item (cell->destroyer) that is queued when its refcount reaches zero. This is not done in the context of the putting thread as it might be in an inconvenient place to sleep.
(3) Each afs_cell is given its own timer. The timer is used to expire the cell record after a period of unuse if not otherwise pinned and can also be used for other maintenance tasks if necessary (of which there are currently none as DNS refresh is triggered by filesystem operations).
(4) The afs_cell manager work item (cell->manager) is no longer given a ref on the cell when queued; rather, the manager must be deleted. This does away with the need to deal with the consequences of losing a race to queue cell->manager. Clean up of extra queuing is deferred to the destroyer.
(5) The cell destroyer work item makes sure the cell timer is removed and that the normal cell work is cancelled before farming the actual destruction off to RCU.
(6) When a network namespace is destroyed or the kafs module is unloaded, it's now a simple matter of marking the namespace as dead then just waking up all the cell work items. They will then remove and destroy themselves once all remaining activity counts and/or a ref counts are dropped. This makes sure that all server records are dropped first.
(7) The cell record state set is reduced to just four states: SETTING_UP, ACTIVE, REMOVING and DEAD. The record persists in the active state even when it's not being used until the time comes to remove it rather than downgrading it to an inactive state from whence it can be restored.
This means that the cell still appears in /proc and /afs when not in use until it switches to the REMOVING state - at which point it is removed.
Note that the REMOVING state is included so that someone wanting to resurrect the cell record is forced to wait whilst the cell is torn down in that state. Once it's in the DEAD state, it has been removed from net->cells tree and is no longer findable and can be replaced.
--- fs/afs/cell.c | 404 +++++++++++++++---------------------- fs/afs/dynroot.c | 4 +- fs/afs/internal.h | 16 +- fs/afs/main.c | 3 - fs/afs/server.c | 8 +- fs/afs/vl_rotate.c | 2 +- include/trace/events/afs.h | 23 +-- 7 files changed, 187 insertions(+), 273 deletions(-)
fs/afs/cell.c +163 -241
@@ -20,8 +20,9 @@ static unsigned __read_mostly afs_cell_min_ttl = 10 * 60;static unsigned __read_mostly afs_cell_max_ttl =24 *60 *60 ;static atomic_t cell_debug_id; -static void afs_queue_cell_manager (struct afs_net *); -static void afs_manage_cell_work (struct work_struct *); +static void afs_cell_timer (struct timer_list *timer); +static void afs_destroy_cell_work (struct work_struct *work); +static void afs_manage_cell_work (struct work_struct *work);static void afs_dec_cells_outstanding (struct afs_net *net) {
@@ -29,19 +30,11 @@ static void afs_dec_cells_outstanding(struct afs_net *net)wake_up_var (&net->cells_outstanding); } -/* -* Set the cell timer to fire after a given delay, assuming it's not already -* set for an earlier time. -*/ -static void afs_set_cell_timer (struct afs_net *net,time64_t delay) +static void afs_set_cell_state (struct afs_cell *cell,enum afs_cell_state state) { -if (net->live) { -atomic_inc (&net->cells_outstanding); -if (timer_reduce (&net->cells_timer, jiffies + delay *HZ )) -afs_dec_cells_outstanding (net); - }else { -afs_queue_cell_manager (net); - } +smp_store_release (&cell->state, state);/* Commit cell changes before state */ +smp_wmb ();/* Set cell state before task state */ +wake_up_var (&cell->state); }/*
@@ -115,7 +108,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, const char *name, unsigned int namelen, const char *addresses) { - struct afs_vlserver_list *vllist; + struct afs_vlserver_list *vllist = NULL;struct afs_cell *cell;int i, ret;
@@ -162,7 +155,9 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net, cell->net = net;refcount_set (&cell->ref,1 );atomic_set (&cell->active,0 ); +INIT_WORK (&cell->destroyer, afs_destroy_cell_work);INIT_WORK (&cell->manager, afs_manage_cell_work); +timer_setup (&cell->management_timer, afs_cell_timer,0 );init_rwsem (&cell->vs_lock); cell->volumes =RB_ROOT ;INIT_HLIST_HEAD (&cell->proc_volumes);
@@ -218,6 +213,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,if (ret == -EINVAL )printk (KERN_ERR "kAFS: bad VL server IP address\n" ); error: +afs_put_vlserverlist (cell->net, vllist);kfree (cell->name -1 );kfree (cell);_leave (" = %d" , ret);
@@ -294,26 +290,28 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net, cell = candidate; candidate =NULL ; -atomic_set (&cell->active,2 ); -trace_afs_cell (cell->debug_id,refcount_read (&cell->ref),2 , afs_cell_trace_insert); +afs_use_cell (cell, trace);rb_link_node_rcu (&cell->net_node, parent, pp);rb_insert_color (&cell->net_node, &net->cells);up_write (&net->cells_lock); -afs_queue_cell (cell, afs_cell_trace_get_queue_new); +afs_queue_cell (cell, afs_cell_trace_queue_new); wait_for_cell: -trace_afs_cell (cell->debug_id,refcount_read (&cell->ref),atomic_read (&cell->active), - afs_cell_trace_wait);_debug ("wait_for_cell" ); -wait_var_event (&cell->state, - ({ - state =smp_load_acquire (&cell->state);/* vs error */ - state ==AFS_CELL_ACTIVE || state ==AFS_CELL_REMOVED ; - })); + state =smp_load_acquire (&cell->state);/* vs error */ +if (state !=AFS_CELL_ACTIVE && + state !=AFS_CELL_DEAD ) { +afs_see_cell (cell, afs_cell_trace_wait); +wait_var_event (&cell->state, + ({ + state =smp_load_acquire (&cell->state);/* vs error */ + state ==AFS_CELL_ACTIVE || state ==AFS_CELL_DEAD ; + })); + }/* Check the state obtained from the wait check. */ -if (state ==AFS_CELL_REMOVED ) { +if (state ==AFS_CELL_DEAD ) { ret = cell->error; goto error; }
@@ -395,7 +393,6 @@ int afs_cell_init(struct afs_net *net, const char *rootcell)/* install the new cell */ down_write (&net->cells_lock); -afs_see_cell (new_root, afs_cell_trace_see_ws); old_root = net->ws_cell; net->ws_cell = new_root;up_write (&net->cells_lock);
@@ -528,30 +525,14 @@ static void afs_cell_destroy(struct rcu_head *rcu)_leave (" [destroyed]" ); } -/* -* Queue the cell manager. -*/ -static void afs_queue_cell_manager (struct afs_net *net) -{ -int outstanding =atomic_inc_return (&net->cells_outstanding); - -_enter ("%d" , outstanding); - -if (!queue_work (afs_wq, &net->cells_manager)) -afs_dec_cells_outstanding (net); -} - -/* -* Cell management timer. We have an increment on cells_outstanding that we -* need to pass along to the work item. -*/ -void afs_cells_timer (struct timer_list *timer) +static void afs_destroy_cell_work (struct work_struct *work) { - struct afs_net *net = container_of(timer, struct afs_net, cells_timer); + struct afs_cell *cell = container_of(work, struct afs_cell, destroyer); -_enter ("" ); -if (!queue_work (afs_wq, &net->cells_manager)) -afs_dec_cells_outstanding (net); +afs_see_cell (cell, afs_cell_trace_destroy); +timer_delete_sync (&cell->management_timer); +cancel_work_sync (&cell->manager); +call_rcu (&cell->rcu, afs_cell_destroy); }/*
@@ -583,7 +564,7 @@ void afs_put_cell(struct afs_cell *cell, enum afs_cell_trace reason)if (zero) { a =atomic_read (&cell->active);WARN (a !=0 ,"Cell active count %u > 0\n" , a); -call_rcu (&cell->rcu, afs_cell_destroy); +WARN_ON (!queue_work (afs_wq, &cell->destroyer)); } } }
@@ -595,10 +576,9 @@ struct afs_cell *afs_use_cell(struct afs_cell *cell, enum afs_cell_trace reason) {int r, a; - r =refcount_read (&cell->ref); -WARN_ON (r ==0 ); +__refcount_inc (&cell->ref, &r); a =atomic_inc_return (&cell->active); -trace_afs_cell (cell->debug_id, r, a, reason); +trace_afs_cell (cell->debug_id, r +1 , a, reason);return cell; }
@@ -610,6 +590,7 @@ void afs_unuse_cell(struct afs_cell *cell, enum afs_cell_trace reason) {unsigned int debug_id;time64_t now, expire_delay; +bool zero;int r, a;if (!cell)
@@ -624,13 +605,15 @@ void afs_unuse_cell(struct afs_cell *cell, enum afs_cell_trace reason) expire_delay = afs_cell_gc_delay; debug_id = cell->debug_id; - r =refcount_read (&cell->ref); a =atomic_dec_return (&cell->active); -trace_afs_cell (debug_id, r, a, reason); -WARN_ON (a ==0 ); -if (a ==1 ) +if (!a)/* 'cell' may now be garbage collected. */ -afs_set_cell_timer (cell->net, expire_delay); +afs_set_cell_timer (cell, expire_delay); + + zero =__refcount_dec_and_test (&cell->ref, &r); +trace_afs_cell (debug_id, r -1 , a, reason); +if (zero) +WARN_ON (!queue_work (afs_wq, &cell->destroyer)); }/*
@@ -650,9 +633,27 @@ void afs_see_cell(struct afs_cell *cell, enum afs_cell_trace reason)*/ void afs_queue_cell (struct afs_cell *cell,enum afs_cell_trace reason) { -afs_get_cell (cell, reason); -if (!queue_work (afs_wq, &cell->manager)) -afs_put_cell (cell, afs_cell_trace_put_queue_fail); +queue_work (afs_wq, &cell->manager); +} + +/* +* Cell-specific management timer. +*/ +static void afs_cell_timer (struct timer_list *timer) +{ + struct afs_cell *cell = container_of(timer, struct afs_cell, management_timer); + +afs_see_cell (cell, afs_cell_trace_see_mgmt_timer); +if (refcount_read (&cell->ref) >0 && cell->net->live) +queue_work (afs_wq, &cell->manager); +} + +/* +* Set/reduce the cell timer. +*/ +void afs_set_cell_timer (struct afs_cell *cell,unsigned int delay_secs) +{ +timer_reduce (&cell->management_timer, jiffies + delay_secs *HZ ); }/*
@@ -735,212 +736,125 @@ static void afs_deactivate_cell(struct afs_net *net, struct afs_cell *cell)_leave ("" ); } +static bool afs_has_cell_expired (struct afs_cell *cell,time64_t *_next_manage) +{ +const struct afs_vlserver_list *vllist; +time64_t expire_at = cell->last_inactive; +time64_t now =ktime_get_real_seconds (); + +if (atomic_read (&cell->active)) +return false; +if (!cell->net->live) +return true; + + vllist =rcu_dereference_protected (cell->vl_servers, true); +if (vllist && vllist->nr_servers >0 ) + expire_at += afs_cell_gc_delay; + +if (expire_at <= now) +return true; +if (expire_at < *_next_manage) + *_next_manage = expire_at; +return false; +} +/* * Manage a cell record, initialising and destroying it, maintaining its DNS * records. */ -static void afs_manage_cell (struct afs_cell *cell) +static bool afs_manage_cell (struct afs_cell *cell) {struct afs_net *net = cell->net; -int ret, active; +time64_t next_manage =TIME64_MAX ; +int ret;_enter ("%s" , cell->name); -again:_debug ("state %u" , cell->state);switch (cell->state) { -case AFS_CELL_INACTIVE : -case AFS_CELL_FAILED : -down_write (&net->cells_lock); - active =1 ; -if (atomic_try_cmpxchg_relaxed (&cell->active, &active,0 )) { -rb_erase (&cell->net_node, &net->cells); -trace_afs_cell (cell->debug_id,refcount_read (&cell->ref),0 , - afs_cell_trace_unuse_delete); -smp_store_release (&cell->state,AFS_CELL_REMOVED ); - } -up_write (&net->cells_lock); -if (cell->state ==AFS_CELL_REMOVED ) { -wake_up_var (&cell->state); - goto final_destruction; - } -if (cell->state ==AFS_CELL_FAILED ) - goto done; -smp_store_release (&cell->state,AFS_CELL_UNSET ); -wake_up_var (&cell->state); - goto again; - -case AFS_CELL_UNSET : -smp_store_release (&cell->state,AFS_CELL_ACTIVATING ); -wake_up_var (&cell->state); - goto again; - -case AFS_CELL_ACTIVATING : - ret =afs_activate_cell (net, cell); -if (ret <0 ) - goto activation_failed; +case AFS_CELL_SETTING_UP : + goto set_up_cell; +case AFS_CELL_ACTIVE : + goto cell_is_active; +case AFS_CELL_REMOVING : +WARN_ON_ONCE (1 ); +return false; +case AFS_CELL_DEAD : +return false; +default : +_debug ("bad state %u" , cell->state); +WARN_ON_ONCE (1 );/* Unhandled state */ +return false; + } -smp_store_release (&cell->state,AFS_CELL_ACTIVE ); -wake_up_var (&cell->state); - goto again; +set_up_cell: + ret =afs_activate_cell (net, cell); +if (ret <0 ) { + cell->error = ret; + goto remove_cell; + } -case AFS_CELL_ACTIVE : -if (atomic_read (&cell->active) >1 ) { -if (test_and_clear_bit (AFS_CELL_FL_DO_LOOKUP , &cell->flags)) { - ret =afs_update_cell (cell); -if (ret <0 ) - cell->error = ret; - } - goto done; - } -smp_store_release (&cell->state,AFS_CELL_DEACTIVATING ); -wake_up_var (&cell->state); - goto again; +afs_set_cell_state (cell,AFS_CELL_ACTIVE ); -case AFS_CELL_DEACTIVATING : -if (atomic_read (&cell->active) >1 ) - goto reverse_deactivation; -afs_deactivate_cell (net, cell); -smp_store_release (&cell->state,AFS_CELL_INACTIVE ); -wake_up_var (&cell->state); - goto again; +cell_is_active: +if (afs_has_cell_expired (cell, &next_manage)) + goto remove_cell; -case AFS_CELL_REMOVED : - goto done; +if (test_and_clear_bit (AFS_CELL_FL_DO_LOOKUP , &cell->flags)) { + ret =afs_update_cell (cell); +if (ret <0 ) + cell->error = ret; + } -default : -break ; +if (next_manage <TIME64_MAX && cell->net->live) { +time64_t now =ktime_get_real_seconds (); + +if (next_manage - now <=0 ) +afs_queue_cell (cell, afs_cell_trace_queue_again); +else +afs_set_cell_timer (cell, next_manage - now); } -_debug ("bad state %u" , cell->state); -BUG ();/* Unhandled state */ +_leave (" [done %u]" , cell->state); +return false; -activation_failed: - cell->error = ret; -afs_deactivate_cell (net, cell); +remove_cell: +down_write (&net->cells_lock); -smp_store_release (&cell->state,AFS_CELL_FAILED );/* vs error */ -wake_up_var (&cell->state); - goto again; +if (atomic_read (&cell->active)) { +up_write (&net->cells_lock); + goto cell_is_active; + } -reverse_deactivation: -smp_store_release (&cell->state,AFS_CELL_ACTIVE ); -wake_up_var (&cell->state); -_leave (" [deact->act]" ); -return ; +/* Make sure that the expiring server records are going to see the fact +* that the cell is caput. +*/ +afs_set_cell_state (cell,AFS_CELL_REMOVING ); -done: -_leave (" [done %u]" , cell->state); -return ; +afs_deactivate_cell (net, cell); +afs_purge_servers (cell); + +rb_erase (&cell->net_node, &net->cells); +afs_see_cell (cell, afs_cell_trace_unuse_delete); +up_write (&net->cells_lock); -final_destruction:/* The root volume is pinning the cell */ afs_put_volume (cell->root_volume, afs_volume_trace_put_cell_root); cell->root_volume =NULL ; -afs_purge_servers (cell); -afs_put_cell (cell, afs_cell_trace_put_destroy); + +afs_set_cell_state (cell,AFS_CELL_DEAD ); +return true; }static void afs_manage_cell_work (struct work_struct *work) { struct afs_cell *cell = container_of(work, struct afs_cell, manager); +bool final_put; -afs_manage_cell (cell); -afs_put_cell (cell, afs_cell_trace_put_queue_work); -} - -/* -* Manage the records of cells known to a network namespace. This includes -* updating the DNS records and garbage collecting unused cells that were -* automatically added. -* -* Note that constructed cell records may only be removed from net->cells by -* this work item, so it is safe for this work item to stash a cursor pointing -* into the tree and then return to caller (provided it skips cells that are -* still under construction). -* -* Note also that we were given an increment on net->cells_outstanding by -* whoever queued us that we need to deal with before returning. -*/ -void afs_manage_cells (struct work_struct *work) -{ - struct afs_net *net = container_of(work, struct afs_net, cells_manager); -struct rb_node *cursor; -time64_t now =ktime_get_real_seconds (), next_manage =TIME64_MAX ; -bool purging = !net->live; - -_enter ("" ); - -/* Trawl the cell database looking for cells that have expired from -* lack of use and cells whose DNS results have expired and dispatch -* their managers. -*/ -down_read (&net->cells_lock); - -for (cursor =rb_first (&net->cells); cursor; cursor =rb_next (cursor)) { -struct afs_cell *cell = - rb_entry(cursor, struct afs_cell, net_node); -unsigned active; -bool sched_cell = false; - - active =atomic_read (&cell->active); -trace_afs_cell (cell->debug_id,refcount_read (&cell->ref), - active, afs_cell_trace_manage); - - ASSERTCMP(active, >=, 1); - -if (purging) { -if (test_and_clear_bit (AFS_CELL_FL_NO_GC , &cell->flags)) { - active =atomic_dec_return (&cell->active); -trace_afs_cell (cell->debug_id,refcount_read (&cell->ref), - active, afs_cell_trace_unuse_pin); - } - } - -if (active ==1 ) { -struct afs_vlserver_list *vllist; -time64_t expire_at = cell->last_inactive; - -read_lock (&cell->vl_servers_lock); - vllist =rcu_dereference_protected ( - cell->vl_servers, -lockdep_is_held (&cell->vl_servers_lock)); -if (vllist->nr_servers >0 ) - expire_at += afs_cell_gc_delay; -read_unlock (&cell->vl_servers_lock); -if (purging || expire_at <= now) - sched_cell = true; -else if (expire_at < next_manage) - next_manage = expire_at; - } - -if (!purging) { -if (test_bit (AFS_CELL_FL_DO_LOOKUP , &cell->flags)) - sched_cell = true; - } - -if (sched_cell) -afs_queue_cell (cell, afs_cell_trace_get_queue_manage); - } - -up_read (&net->cells_lock); - -/* Update the timer on the way out. We have to pass an increment on -* cells_outstanding in the namespace that we are in to the timer or -* the work scheduler. -*/ -if (!purging && next_manage <TIME64_MAX ) { - now =ktime_get_real_seconds (); - -if (next_manage - now <=0 ) { -if (queue_work (afs_wq, &net->cells_manager)) -atomic_inc (&net->cells_outstanding); - }else { -afs_set_cell_timer (net, next_manage - now); - } - } - -afs_dec_cells_outstanding (net); -_leave (" [%d]" ,atomic_read (&net->cells_outstanding)); +afs_see_cell (cell, afs_cell_trace_manage); + final_put =afs_manage_cell (cell); +afs_see_cell (cell, afs_cell_trace_managed); +if (final_put) +afs_put_cell (cell, afs_cell_trace_put_final); }/*
@@ -949,6 +863,7 @@ void afs_manage_cells(struct work_struct *work)void afs_cell_purge (struct afs_net *net) {struct afs_cell *ws; +struct rb_node *cursor;_enter ("" );
@@ -958,12 +873,19 @@ void afs_cell_purge(struct afs_net *net)up_write (&net->cells_lock);afs_unuse_cell (ws, afs_cell_trace_unuse_ws); -_debug ("del timer" ); -if (del_timer_sync (&net->cells_timer)) -atomic_dec (&net->cells_outstanding); +_debug ("kick cells" ); +down_read (&net->cells_lock); +for (cursor =rb_first (&net->cells); cursor; cursor =rb_next (cursor)) { + struct afs_cell *cell = rb_entry(cursor, struct afs_cell, net_node); + +afs_see_cell (cell, afs_cell_trace_purge); -_debug ("kick mgr" ); -afs_queue_cell_manager (net); +if (test_and_clear_bit (AFS_CELL_FL_NO_GC , &cell->flags)) +afs_unuse_cell (cell, afs_cell_trace_unuse_pin); + +afs_queue_cell (cell, afs_cell_trace_queue_purge); + } +up_read (&net->cells_lock);_debug ("wait" ); wait_var_event(&net->cells_outstanding,
fs/afs/dynroot.c +2 -2
@@ -282,8 +282,8 @@ static int afs_dynroot_readdir_cells(struct afs_net *net, struct dir_context *ct cell =idr_get_next (&net->cells_dyn_ino, &ix);if (!cell)return 0 ; -if (READ_ONCE (cell->state) ==AFS_CELL_FAILED || -READ_ONCE (cell->state) ==AFS_CELL_REMOVED ) { +if (READ_ONCE (cell->state) ==AFS_CELL_REMOVING || +READ_ONCE (cell->state) ==AFS_CELL_DEAD ) { ctx->pos +=2 ; ctx->pos &= ~1 ;continue ;
fs/afs/internal.h +6 -10
@@ -289,8 +289,6 @@ struct afs_net {struct rb_root cells;struct idr cells_dyn_ino;/* cell->dynroot_ino mapping */ struct afs_cell *ws_cell; -struct work_struct cells_manager; -struct timer_list cells_timer;atomic_t cells_outstanding;struct rw_semaphore cells_lock;struct mutex cells_alias_lock;
@@ -339,13 +337,10 @@ struct afs_net {extern const char afs_init_sysname[];enum afs_cell_state { -AFS_CELL_UNSET , -AFS_CELL_ACTIVATING , +AFS_CELL_SETTING_UP ,AFS_CELL_ACTIVE , -AFS_CELL_DEACTIVATING , -AFS_CELL_INACTIVE , -AFS_CELL_FAILED , -AFS_CELL_REMOVED , +AFS_CELL_REMOVING , +AFS_CELL_DEAD , };/*
@@ -376,7 +371,9 @@ struct afs_cell {struct afs_cell *alias_of;/* The cell this is an alias of */ struct afs_volume *root_volume;/* The root.cell volume if there is one */ struct key *anonymous_key;/* anonymous user key for this cell */ +struct work_struct destroyer;/* Destroyer for cell */ struct work_struct manager;/* Manager for init/deinit/dns */ +struct timer_list management_timer;/* General management timer */ struct hlist_node proc_link;/* /proc cell list link */ time64_t dns_expiry;/* Time AFSDB/SRV record expires */ time64_t last_inactive;/* Time of last drop of usage count */
@@ -1053,8 +1050,7 @@ extern struct afs_cell *afs_get_cell(struct afs_cell *, enum afs_cell_trace);extern void afs_see_cell (struct afs_cell *,enum afs_cell_trace );extern void afs_put_cell (struct afs_cell *,enum afs_cell_trace );extern void afs_queue_cell (struct afs_cell *,enum afs_cell_trace ); -extern void afs_manage_cells (struct work_struct *); -extern void afs_cells_timer (struct timer_list *); +void afs_set_cell_timer (struct afs_cell *cell,unsigned int delay_secs); extern void __net_exit afs_cell_purge(struct afs_net *);/*
fs/afs/main.c +0 -3
@@ -78,9 +78,6 @@ static int __net_init afs_net_init(struct net *net_ns) net->cells =RB_ROOT ;idr_init (&net->cells_dyn_ino);init_rwsem (&net->cells_lock); -INIT_WORK (&net->cells_manager, afs_manage_cells); -timer_setup (&net->cells_timer, afs_cells_timer,0 ); -mutex_init (&net->cells_alias_lock);mutex_init (&net->proc_cells_lock);INIT_HLIST_HEAD (&net->proc_cells);
fs/afs/server.c +4 -4
@@ -103,7 +103,7 @@ static struct afs_server *afs_install_server(struct afs_cell *cell,afs_get_cell (cell, afs_cell_trace_get_server); exists: -afs_use_server (server, true, afs_server_trace_get_install); +afs_use_server (server, true, afs_server_trace_use_install);return server; }
@@ -356,7 +356,7 @@ void afs_unuse_server_notime(struct afs_net *net, struct afs_server *server,if (atomic_dec_and_test (&server->active)) {if (test_bit (AFS_SERVER_FL_EXPIRED , &server->flags) || -READ_ONCE (server->cell->state) >=AFS_CELL_FAILED ) +READ_ONCE (server->cell->state) >=AFS_CELL_REMOVING )schedule_work (&server->destroyer); }
@@ -374,7 +374,7 @@ void afs_unuse_server(struct afs_net *net, struct afs_server *server,if (atomic_dec_and_test (&server->active)) {if (!test_bit (AFS_SERVER_FL_EXPIRED , &server->flags) && -READ_ONCE (server->cell->state) <AFS_CELL_FAILED ) { +READ_ONCE (server->cell->state) <AFS_CELL_REMOVING ) {time64_t unuse_time =ktime_get_real_seconds (); server->unuse_time = unuse_time;
@@ -424,7 +424,7 @@ static bool afs_has_server_expired(const struct afs_server *server)return false;if (server->cell->net->live || - server->cell->state >=AFS_CELL_FAILED ) { + server->cell->state >=AFS_CELL_REMOVING ) {trace_afs_server (server->debug_id,refcount_read (&server->ref),0 , afs_server_trace_purging);return true;
fs/afs/vl_rotate.c +1 -1
@@ -48,7 +48,7 @@ static bool afs_start_vl_iteration(struct afs_vl_cursor *vc) cell->dns_expiry <= ktime_get_real_seconds()) { dns_lookup_count =smp_load_acquire (&cell->dns_lookup_count);set_bit (AFS_CELL_FL_DO_LOOKUP , &cell->flags); -afs_queue_cell (cell, afs_cell_trace_get_queue_dns); +afs_queue_cell (cell, afs_cell_trace_queue_dns);if (cell->dns_source ==DNS_RECORD_UNAVAILABLE ) { if (wait_var_event_interruptible(
include/trace/events/afs.h +11 -12
@@ -131,7 +131,6 @@ enum yfs_cm_operation { EM(afs_server_trace_destroy, "DESTROY ") \ EM(afs_server_trace_free, "FREE ") \ EM(afs_server_trace_gc, "GC ") \ - EM(afs_server_trace_get_install, "GET inst ") \ EM(afs_server_trace_get_probe, "GET probe") \ EM(afs_server_trace_purging, "PURGE ") \EM (afs_server_trace_put_cbi,"PUT cbi " ) \
@@ -149,6 +148,7 @@ enum yfs_cm_operation { EM(afs_server_trace_use_cm_call, "USE cm-cl") \ EM(afs_server_trace_use_get_caps, "USE gcaps") \ EM(afs_server_trace_use_give_up_cb, "USE gvupc") \ + EM(afs_server_trace_use_install, "USE inst ") \ E_(afs_server_trace_wait_create, "WAIT crt ")#define afs_volume_traces \
@@ -171,37 +171,36 @@ enum yfs_cm_operation {#define afs_cell_traces \ EM(afs_cell_trace_alloc, "ALLOC ") \ + EM(afs_cell_trace_destroy, "DESTROY ") \ EM(afs_cell_trace_free, "FREE ") \ EM(afs_cell_trace_get_atcell, "GET atcell") \ - EM(afs_cell_trace_get_queue_dns, "GET q-dns ") \ - EM(afs_cell_trace_get_queue_manage, "GET q-mng ") \ - EM(afs_cell_trace_get_queue_new, "GET q-new ") \ EM(afs_cell_trace_get_server, "GET server") \ EM(afs_cell_trace_get_vol, "GET vol ") \ - EM(afs_cell_trace_insert, "INSERT ") \ - EM(afs_cell_trace_manage, "MANAGE ") \ + EM(afs_cell_trace_purge, "PURGE ") \ EM(afs_cell_trace_put_atcell, "PUT atcell") \ EM(afs_cell_trace_put_candidate, "PUT candid") \ - EM(afs_cell_trace_put_destroy, "PUT destry") \ - EM(afs_cell_trace_put_queue_work, "PUT q-work") \ - EM(afs_cell_trace_put_queue_fail, "PUT q-fail") \ + EM(afs_cell_trace_put_final, "PUT final ") \ EM(afs_cell_trace_put_server, "PUT server") \ EM(afs_cell_trace_put_vol, "PUT vol ") \ + EM(afs_cell_trace_queue_again, "QUE again ") \ + EM(afs_cell_trace_queue_dns, "QUE dns ") \ + EM(afs_cell_trace_queue_new, "QUE new ") \ + EM(afs_cell_trace_queue_purge, "QUE purge ") \ + EM(afs_cell_trace_manage, "MANAGE ") \ + EM(afs_cell_trace_managed, "MANAGED ") \ EM(afs_cell_trace_see_source, "SEE source") \ - EM(afs_cell_trace_see_ws, "SEE ws ") \ + EM(afs_cell_trace_see_mgmt_timer, "SEE mtimer") \ EM(afs_cell_trace_unuse_alias, "UNU alias ") \ EM(afs_cell_trace_unuse_check_alias, "UNU chk-al") \ EM(afs_cell_trace_unuse_delete, "UNU delete") \ EM(afs_cell_trace_unuse_dynroot_mntpt, "UNU dyn-mp") \ EM(afs_cell_trace_unuse_fc, "UNU fc ") \ - EM(afs_cell_trace_unuse_lookup, "UNU lookup") \ EM(afs_cell_trace_unuse_lookup_dynroot, "UNU lu-dyn") \ EM(afs_cell_trace_unuse_lookup_error, "UNU lu-err") \ EM(afs_cell_trace_unuse_mntpt, "UNU mntpt ") \ EM(afs_cell_trace_unuse_no_pin, "UNU no-pin") \ EM(afs_cell_trace_unuse_parse, "UNU parse ") \ EM(afs_cell_trace_unuse_pin, "UNU pin ") \ - EM(afs_cell_trace_unuse_probe, "UNU probe ") \ EM(afs_cell_trace_unuse_sbi, "UNU sbi ") \ EM(afs_cell_trace_unuse_ws, "UNU ws ") \ EM(afs_cell_trace_use_alias, "USE alias ") \
Paolo Abeni
maintainerQuoted 9 lines · David Howells
Here are some patches that fix an occasional hang that's only really encountered when rmmod'ing the kafs module. Arguably, this could also go through the vfs tree, but I have a bunch more primarily crypto and rxrpc patches that need to go through net-next on top of this[1].
Now, at the beginning of this set, I've included five fix patches that are already committed to the net/main branch but that need to be applied first, but haven't made their way into net-next/main or upstream as yet:
Quoted 5 lines
rxrpc: rxperf: Fix missing decoding of terminal magic cookie
rxrpc:peer->mtu_lockis redundant
rxrpc: Fix locking issues with the peer record hash
afs: Fix theserver_listto unuse a displaced server rather than putting it
afs: Give anafs_serverobject a ref on theafs_cellobject it points to
You don't need to re-post such patches, just wait a couple of days, when net will be merged back into net-next. So that we will not have "duplicate changes" inside the tree.
The remaining patches in this series touch only AFS, I'm unsure if net-next if the best target here??? The rxrpc follow-up could just wait the upcoming net -> net-next merge. AFAICS crypto patches go trough their own tree.
Thanks!
Paolo
David Howells
maintainerQuoted 2 lines · Paolo Abeni
The remaining patches in this series touch only AFS, I'm unsure if net-next if the best target here???
Yeah. It's tricky as the complete set of patches I would like to post spans three subsystems.
Quoted 2 lines
The rxrpc follow-up could just wait the upcoming net -> net-next merge. AFAICS crypto patches go trough their own tree.
Ah, no. That doesn't work. The rxrpc follow-up needs the crypto patches to even compile and so needs to go through the same tree.
Further, the afs patches in this patchset are also something of a pre-requisite for the afs part of the rxrpc follow-up. The problem is that we have to be able to map back from the address in a challenge packet back to the managing socket and the server record in order that we can send find the info to put in the response packet and the key required in order to encrypt it.
This is something that this patchset deals with, as part of fixing some a couple of very low-probability bugs (hence why I proposed it for net-next rather than pushing it Linuswards).
If you prefer, I can see about sending all the patches through the vfs tree or the crypto tree rather than net-next. Or I can see if I can push this set as a bug fix through the VFS tree.
David
Paolo Abeni
maintainerQuoted 6 lines · David Howells
Quoted 2 lines · Paolo Abeni
The remaining patches in this series touch only AFS, I'm unsure if net-next if the best target here???
Yeah. It's tricky as the complete set of patches I would like to post spans three subsystems.
Possibly sharing a stable tree somewhere, and let the relevant subsystem pull the tree specific deps/bits could help?
/P
David Howells
maintainerWhich tree to push afs + crypto + rxrpc spanning patches through?
Quoted 8 lines · Paolo Abeni
Quoted 5 lines
Quoted 2 lines
The remaining patches in this series touch only AFS, I'm unsure if net-next if the best target here???
Yeah. It's tricky as the complete set of patches I would like to post spans three subsystems.
Possibly sharing a stable tree somewhere, and let the relevant subsystem pull the tree specific deps/bits could help?
The networking tree would still have to take the afs and crypto bits in order to take the rxrpc bits so that the code compiles. Unfortunately, the rxrpc bits depend on the other two.
If you're okay with the rxrpc bits not going through the networking tree and if Herbert is okay with the krb5 library not going through the crypto tree, I can try pushing the whole lot through the filesystem tree.
David
Re: Which tree to push afs + crypto + rxrpc spanning patches through?
Quoted 4 lines · David Howells
If you're okay with the rxrpc bits not going through the networking tree and if Herbert is okay with the krb5 library not going through the crypto tree, I can try pushing the whole lot through the filesystem tree.
Sure I have no objections.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Mon, 24 Feb 2025 23:41:37 +0000 you wrote:
Here are some patches that fix an occasional hang that's only really encountered when rmmod'ing the kafs module. Arguably, this could also go through the vfs tree, but I have a bunch more primarily crypto and rxrpc patches that need to go through net-next on top of this[1].
Now, at the beginning of this set, I've included five fix patches that are already committed to the net/main branch but that need to be applied first, but haven't made their way into net-next/main or upstream as yet:
[...]
Here is the summary with links:
- [net-next,01/15] rxrpc: rxperf: Fix missing decoding of terminal magic cookie
https://git.kernel.org/netdev/net-next/c/c34d999ca314 - [net-next,02/15] rxrpc: peer->mtu_lock is redundant https://git.kernel.org/netdev/net-next/c/833fefa07444 - [net-next,03/15] rxrpc: Fix locking issues with the peer record hash https://git.kernel.org/netdev/net-next/c/71f5409176f4 - [net-next,04/15] afs: Fix the server_list to unuse a displaced server rather than putting it https://git.kernel.org/netdev/net-next/c/add117e48df4 - [net-next,05/15] afs: Give an afs_server object a ref on the afs_cell object it points to https://git.kernel.org/netdev/net-next/c/1f0fc3374f33
- [net-next,06/15] afs: Remove the "autocell" mount option
(no matching commit)
- [net-next,07/15] afs: Change dynroot to create contents on demand (no matching commit)
- [net-next,08/15] afs: Improve afs_volume tracing to display a debug ID (no matching commit)
- [net-next,09/15] afs: Improve server refcount/active count tracing (no matching commit)
- [net-next,10/15] afs: Make afs_lookup_cell() take a trace note (no matching commit)
- [net-next,11/15] afs: Drop the net parameter from afs_unuse_cell() (no matching commit)
- [net-next,12/15] rxrpc: Allow the app to store private data on peer structs (no matching commit)
- [net-next,13/15] afs: Use the per-peer app data provided by rxrpc (no matching commit)
- [net-next,14/15] afs: Fix afs_server ref accounting
(no matching commit)
- [net-next,15/15] afs: Simplify cell record handling
(no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Jakub Kicinski
maintainerQuoted 11 lines · On Thu, 27 Feb 2025 19:20:57 +0000 [email protected] wrote:
Here is the summary with links:
- [net-next,01/15] rxrpc: rxperf: Fix missing decoding of terminal magic cookiehttps://git.kernel.org/netdev/net-next/c/c34d999ca314 - [net-next,02/15] rxrpc: peer->mtu_lock is redundant https://git.kernel.org/netdev/net-next/c/833fefa07444 - [net-next,03/15] rxrpc: Fix locking issues with the peer record hash https://git.kernel.org/netdev/net-next/c/71f5409176f4 - [net-next,04/15] afs: Fix the server_list to unuse a displaced server rather than putting it https://git.kernel.org/netdev/net-next/c/add117e48df4 - [net-next,05/15] afs: Give an afs_server object a ref on the afs_cell object it points to https://git.kernel.org/netdev/net-next/c/1f0fc3374f33
Nice job pw-bot! Turns out the first 5 patches were already in the net tree with fixes, and now they made their way to Linus. So let's discard those from v2. And even less of a reason for this to go via networking :(
David Howells
maintainerQuoted 3 lines · Jakub Kicinski
Nice job pw-bot! Turns out the first 5 patches were already in the net tree with fixes, and now they made their way to Linus. So let's discard those from v2.
Yes. I mentioned them specifically in the cover note.
Quoted 1 line
And even less of a reason for this to go via networking :(
The point wasn't those five patches, but the following rxrpc patches that I haven't posted yet that depend on these... but never mind.
David