Commit a0575429 authored by David Howells's avatar David Howells Committed by David S. Miller
Browse files

rxrpc: Use refcount_t rather than atomic_t



Move to using refcount_t rather than atomic_t for refcounts in rxrpc.

Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 33912c26
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -583,7 +583,7 @@ TRACE_EVENT(rxrpc_client,
	    TP_fast_assign(
		    __entry->conn = conn ? conn->debug_id : 0;
		    __entry->channel = channel;
		    __entry->usage = conn ? atomic_read(&conn->usage) : -2;
		    __entry->usage = conn ? refcount_read(&conn->ref) : -2;
		    __entry->op = op;
		    __entry->cid = conn ? conn->proto.cid : 0;
			   ),
+1 −1
Original line number Diff line number Diff line
@@ -351,7 +351,7 @@ static void rxrpc_dummy_notify_rx(struct sock *sk, struct rxrpc_call *rxcall,
 */
void rxrpc_kernel_end_call(struct socket *sock, struct rxrpc_call *call)
{
	_enter("%d{%d}", call->debug_id, atomic_read(&call->usage));
	_enter("%d{%d}", call->debug_id, refcount_read(&call->ref));

	mutex_lock(&call->user_mutex);
	rxrpc_release_call(rxrpc_sk(sock->sk), call);
+5 −13
Original line number Diff line number Diff line
@@ -15,14 +15,6 @@
#include <keys/rxrpc-type.h>
#include "protocol.h"

#if 0
#define CHECK_SLAB_OKAY(X)				     \
	BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
	       (POISON_FREE << 8 | POISON_FREE))
#else
#define CHECK_SLAB_OKAY(X) do {} while (0)
#endif

#define FCRYPT_BSIZE 8
struct rxrpc_crypt {
	union {
@@ -279,7 +271,7 @@ struct rxrpc_security {
struct rxrpc_local {
	struct rcu_head		rcu;
	atomic_t		active_users;	/* Number of users of the local endpoint */
	atomic_t		usage;		/* Number of references to the structure */
	refcount_t		ref;		/* Number of references to the structure */
	struct rxrpc_net	*rxnet;		/* The network ns in which this resides */
	struct hlist_node	link;
	struct socket		*socket;	/* my UDP socket */
@@ -304,7 +296,7 @@ struct rxrpc_local {
 */
struct rxrpc_peer {
	struct rcu_head		rcu;		/* This must be first */
	atomic_t		usage;
	refcount_t		ref;
	unsigned long		hash_key;
	struct hlist_node	hash_link;
	struct rxrpc_local	*local;
@@ -406,7 +398,7 @@ enum rxrpc_conn_proto_state {
 */
struct rxrpc_bundle {
	struct rxrpc_conn_parameters params;
	atomic_t		usage;
	refcount_t		ref;
	unsigned int		debug_id;
	bool			try_upgrade;	/* True if the bundle is attempting upgrade */
	bool			alloc_conn;	/* True if someone's getting a conn */
@@ -427,7 +419,7 @@ struct rxrpc_connection {
	struct rxrpc_conn_proto	proto;
	struct rxrpc_conn_parameters params;

	atomic_t		usage;
	refcount_t		ref;
	struct rcu_head		rcu;
	struct list_head	cache_link;

@@ -609,7 +601,7 @@ struct rxrpc_call {
	int			error;		/* Local error incurred */
	enum rxrpc_call_state	state;		/* current state of call */
	enum rxrpc_call_completion completion;	/* Call completion condition */
	atomic_t		usage;
	refcount_t		ref;
	u16			service_id;	/* service ID */
	u8			security_ix;	/* Security type */
	enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */
+2 −2
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ static int rxrpc_service_prealloc_one(struct rxrpc_sock *rx,
				  (head + 1) & (size - 1));

		trace_rxrpc_conn(conn->debug_id, rxrpc_conn_new_service,
				 atomic_read(&conn->usage), here);
				 refcount_read(&conn->ref), here);
	}

	/* Now it gets complicated, because calls get registered with the
@@ -104,7 +104,7 @@ static int rxrpc_service_prealloc_one(struct rxrpc_sock *rx,
	call->state = RXRPC_CALL_SERVER_PREALLOC;

	trace_rxrpc_call(call->debug_id, rxrpc_call_new_service,
			 atomic_read(&call->usage),
			 refcount_read(&call->ref),
			 here, (const void *)user_call_ID);

	write_lock(&rx->call_lock);
+23 −21
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *rx,
found_extant_call:
	rxrpc_get_call(call, rxrpc_call_got);
	read_unlock(&rx->call_lock);
	_leave(" = %p [%d]", call, atomic_read(&call->usage));
	_leave(" = %p [%d]", call, refcount_read(&call->ref));
	return call;
}

@@ -160,7 +160,7 @@ struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *rx, gfp_t gfp,
	spin_lock_init(&call->notify_lock);
	spin_lock_init(&call->input_lock);
	rwlock_init(&call->state_lock);
	atomic_set(&call->usage, 1);
	refcount_set(&call->ref, 1);
	call->debug_id = debug_id;
	call->tx_total_len = -1;
	call->next_rx_timo = 20 * HZ;
@@ -299,7 +299,7 @@ struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx,
	call->interruptibility = p->interruptibility;
	call->tx_total_len = p->tx_total_len;
	trace_rxrpc_call(call->debug_id, rxrpc_call_new_client,
			 atomic_read(&call->usage),
			 refcount_read(&call->ref),
			 here, (const void *)p->user_call_ID);
	if (p->kernel)
		__set_bit(RXRPC_CALL_KERNEL, &call->flags);
@@ -352,7 +352,7 @@ struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx,
		goto error_attached_to_socket;

	trace_rxrpc_call(call->debug_id, rxrpc_call_connected,
			 atomic_read(&call->usage), here, NULL);
			 refcount_read(&call->ref), here, NULL);

	rxrpc_start_call_timer(call);

@@ -372,7 +372,7 @@ struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx,
	__rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR,
				    RX_CALL_DEAD, -EEXIST);
	trace_rxrpc_call(call->debug_id, rxrpc_call_error,
			 atomic_read(&call->usage), here, ERR_PTR(-EEXIST));
			 refcount_read(&call->ref), here, ERR_PTR(-EEXIST));
	rxrpc_release_call(rx, call);
	mutex_unlock(&call->user_mutex);
	rxrpc_put_call(call, rxrpc_call_put);
@@ -386,7 +386,7 @@ struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx,
	 */
error_attached_to_socket:
	trace_rxrpc_call(call->debug_id, rxrpc_call_error,
			 atomic_read(&call->usage), here, ERR_PTR(ret));
			 refcount_read(&call->ref), here, ERR_PTR(ret));
	set_bit(RXRPC_CALL_DISCONNECTED, &call->flags);
	__rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR,
				    RX_CALL_DEAD, ret);
@@ -442,8 +442,9 @@ void rxrpc_incoming_call(struct rxrpc_sock *rx,
bool rxrpc_queue_call(struct rxrpc_call *call)
{
	const void *here = __builtin_return_address(0);
	int n = atomic_fetch_add_unless(&call->usage, 1, 0);
	if (n == 0)
	int n;

	if (!__refcount_inc_not_zero(&call->ref, &n))
		return false;
	if (rxrpc_queue_work(&call->processor))
		trace_rxrpc_call(call->debug_id, rxrpc_call_queued, n + 1,
@@ -459,7 +460,7 @@ bool rxrpc_queue_call(struct rxrpc_call *call)
bool __rxrpc_queue_call(struct rxrpc_call *call)
{
	const void *here = __builtin_return_address(0);
	int n = atomic_read(&call->usage);
	int n = refcount_read(&call->ref);
	ASSERTCMP(n, >=, 1);
	if (rxrpc_queue_work(&call->processor))
		trace_rxrpc_call(call->debug_id, rxrpc_call_queued_ref, n,
@@ -476,7 +477,7 @@ void rxrpc_see_call(struct rxrpc_call *call)
{
	const void *here = __builtin_return_address(0);
	if (call) {
		int n = atomic_read(&call->usage);
		int n = refcount_read(&call->ref);

		trace_rxrpc_call(call->debug_id, rxrpc_call_seen, n,
				 here, NULL);
@@ -486,11 +487,11 @@ void rxrpc_see_call(struct rxrpc_call *call)
bool rxrpc_try_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op)
{
	const void *here = __builtin_return_address(0);
	int n = atomic_fetch_add_unless(&call->usage, 1, 0);
	int n;

	if (n == 0)
	if (!__refcount_inc_not_zero(&call->ref, &n))
		return false;
	trace_rxrpc_call(call->debug_id, op, n, here, NULL);
	trace_rxrpc_call(call->debug_id, op, n + 1, here, NULL);
	return true;
}

@@ -500,9 +501,10 @@ bool rxrpc_try_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op)
void rxrpc_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op)
{
	const void *here = __builtin_return_address(0);
	int n = atomic_inc_return(&call->usage);
	int n;

	trace_rxrpc_call(call->debug_id, op, n, here, NULL);
	__refcount_inc(&call->ref, &n);
	trace_rxrpc_call(call->debug_id, op, n + 1, here, NULL);
}

/*
@@ -527,10 +529,10 @@ void rxrpc_release_call(struct rxrpc_sock *rx, struct rxrpc_call *call)
	struct rxrpc_connection *conn = call->conn;
	bool put = false;

	_enter("{%d,%d}", call->debug_id, atomic_read(&call->usage));
	_enter("{%d,%d}", call->debug_id, refcount_read(&call->ref));

	trace_rxrpc_call(call->debug_id, rxrpc_call_release,
			 atomic_read(&call->usage),
			 refcount_read(&call->ref),
			 here, (const void *)call->flags);

	ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE);
@@ -619,14 +621,14 @@ void rxrpc_put_call(struct rxrpc_call *call, enum rxrpc_call_trace op)
	struct rxrpc_net *rxnet = call->rxnet;
	const void *here = __builtin_return_address(0);
	unsigned int debug_id = call->debug_id;
	bool dead;
	int n;

	ASSERT(call != NULL);

	n = atomic_dec_return(&call->usage);
	dead = __refcount_dec_and_test(&call->ref, &n);
	trace_rxrpc_call(debug_id, op, n, here, NULL);
	ASSERTCMP(n, >=, 0);
	if (n == 0) {
	if (dead) {
		_debug("call %d dead", call->debug_id);
		ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE);

@@ -716,7 +718,7 @@ void rxrpc_destroy_all_calls(struct rxrpc_net *rxnet)
			list_del_init(&call->link);

			pr_err("Call %p still in use (%d,%s,%lx,%lx)!\n",
			       call, atomic_read(&call->usage),
			       call, refcount_read(&call->ref),
			       rxrpc_call_states[call->state],
			       call->flags, call->events);

Loading