Commit 40e8b52f authored by David Howells's avatar David Howells
Browse files

afs: Use the per-peer app data provided by rxrpc



Make 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.

Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
cc: linux-fsdevel@vger.kernel.org
Link: https://lore.kernel.org/r/20250224234154.2014840-14-dhowells@redhat.com/ # v1
Link: https://lore.kernel.org/r/20250310094206.801057-10-dhowells@redhat.com/ # v4
parent f3a123b2
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
@@ -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);
}
+13 −69
Original line number Diff line number Diff line
@@ -138,49 +138,6 @@ bool afs_cm_incoming_call(struct afs_call *call)
	}
}

/*
 * Find the server record by peer address and record a probe to the cache
 * manager from a server.
 */
static int afs_find_cm_server_by_peer(struct afs_call *call)
{
	struct sockaddr_rxrpc srx;
	struct afs_server *server;
	struct rxrpc_peer *peer;

	peer = rxrpc_kernel_get_call_peer(call->net->socket, call->rxcall);

	server = afs_find_server(call->net, peer);
	if (!server) {
		trace_afs_cm_no_server(call, &srx);
		return 0;
	}

	call->server = server;
	return 0;
}

/*
 * Find the server record by server UUID and record a probe to the cache
 * manager from a server.
 */
static int afs_find_cm_server_by_uuid(struct afs_call *call,
				      struct afs_uuid *uuid)
{
	struct afs_server *server;

	rcu_read_lock();
	server = afs_find_server_by_uuid(call->net, call->request);
	rcu_read_unlock();
	if (!server) {
		trace_afs_cm_no_server_u(call, call->request);
		return 0;
	}

	call->server = server;
	return 0;
}

/*
 * Clean up a cache manager call.
 */
@@ -322,10 +279,7 @@ static int afs_deliver_cb_callback(struct afs_call *call)

	if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
		return afs_io_error(call, afs_io_error_cm_reply);

	/* we'll need the file server record as that tells us which set of
	 * vnodes to operate upon */
	return afs_find_cm_server_by_peer(call);
	return 0;
}

/*
@@ -349,18 +303,10 @@ static void SRXAFSCB_InitCallBackState(struct work_struct *work)
 */
static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
{
	int ret;

	_enter("");

	afs_extract_discard(call, 0);
	ret = afs_extract_data(call, false);
	if (ret < 0)
		return ret;

	/* we'll need the file server record as that tells us which set of
	 * vnodes to operate upon */
	return afs_find_cm_server_by_peer(call);
	return afs_extract_data(call, false);
}

/*
@@ -373,8 +319,6 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
	__be32 *b;
	int ret;

	_enter("");

	_enter("{%u}", call->unmarshall);

	switch (call->unmarshall) {
@@ -421,9 +365,13 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
	if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
		return afs_io_error(call, afs_io_error_cm_reply);

	/* we'll need the file server record as that tells us which set of
	 * vnodes to operate upon */
	return afs_find_cm_server_by_uuid(call, call->request);
	if (memcmp(call->request, &call->server->_uuid, sizeof(call->server->_uuid)) != 0) {
		pr_notice("Callback UUID does not match fileserver UUID\n");
		trace_afs_cm_no_server_u(call, call->request);
		return 0;
	}

	return 0;
}

/*
@@ -455,7 +403,7 @@ static int afs_deliver_cb_probe(struct afs_call *call)

	if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
		return afs_io_error(call, afs_io_error_cm_reply);
	return afs_find_cm_server_by_peer(call);
	return 0;
}

/*
@@ -533,7 +481,7 @@ static int afs_deliver_cb_probe_uuid(struct afs_call *call)

	if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
		return afs_io_error(call, afs_io_error_cm_reply);
	return afs_find_cm_server_by_peer(call);
	return 0;
}

/*
@@ -593,7 +541,7 @@ static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)

	if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
		return afs_io_error(call, afs_io_error_cm_reply);
	return afs_find_cm_server_by_peer(call);
	return 0;
}

/*
@@ -667,9 +615,5 @@ static int afs_deliver_yfs_cb_callback(struct afs_call *call)

	if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
		return afs_io_error(call, afs_io_error_cm_reply);

	/* We'll need the file server record as that tells us which set of
	 * vnodes to operate upon.
	 */
	return afs_find_cm_server_by_peer(call);
	return 0;
}
+22 −10
Original line number Diff line number Diff line
@@ -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,
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));
	if (old) {
		estate->responsive_set = old->responsive_set;
	estate->addresses = afs_get_addrlist(new_alist ?: old->addresses,
					     afs_alist_trace_get_estate);
		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;
}

/*
+6 −3
Original line number Diff line number Diff line
@@ -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);
+8 −2
Original line number Diff line number Diff line
@@ -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;
}

Loading