local_object.c (c25141062a82ae8bddced1b3ce2b57a1c0efabe0) local_object.c (09d2bf595db4b4075ea721acd61e180d6bb18f88)
1/* Local endpoint object management
2 *
3 * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version

--- 81 unchanged lines hidden (view full) ---

90 skb_queue_head_init(&local->event_queue);
91 local->client_conns = RB_ROOT;
92 spin_lock_init(&local->client_conns_lock);
93 spin_lock_init(&local->lock);
94 rwlock_init(&local->services_lock);
95 local->debug_id = atomic_inc_return(&rxrpc_debug_id);
96 memcpy(&local->srx, srx, sizeof(*srx));
97 local->srx.srx_service = 0;
1/* Local endpoint object management
2 *
3 * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version

--- 81 unchanged lines hidden (view full) ---

90 skb_queue_head_init(&local->event_queue);
91 local->client_conns = RB_ROOT;
92 spin_lock_init(&local->client_conns_lock);
93 spin_lock_init(&local->lock);
94 rwlock_init(&local->services_lock);
95 local->debug_id = atomic_inc_return(&rxrpc_debug_id);
96 memcpy(&local->srx, srx, sizeof(*srx));
97 local->srx.srx_service = 0;
98 trace_rxrpc_local(local, rxrpc_local_new, 1, NULL);
98 }
99
100 _leave(" = %p", local);
101 return local;
102}
103
104/*
105 * create the local socket

--- 146 unchanged lines hidden (view full) ---

252
253addr_in_use:
254 mutex_unlock(&rxnet->local_mutex);
255 _leave(" = -EADDRINUSE");
256 return ERR_PTR(-EADDRINUSE);
257}
258
259/*
99 }
100
101 _leave(" = %p", local);
102 return local;
103}
104
105/*
106 * create the local socket

--- 146 unchanged lines hidden (view full) ---

253
254addr_in_use:
255 mutex_unlock(&rxnet->local_mutex);
256 _leave(" = -EADDRINUSE");
257 return ERR_PTR(-EADDRINUSE);
258}
259
260/*
261 * Get a ref on a local endpoint.
262 */
263struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *local)
264{
265 const void *here = __builtin_return_address(0);
266 int n;
267
268 n = atomic_inc_return(&local->usage);
269 trace_rxrpc_local(local, rxrpc_local_got, n, here);
270 return local;
271}
272
273/*
274 * Get a ref on a local endpoint unless its usage has already reached 0.
275 */
276struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
277{
278 const void *here = __builtin_return_address(0);
279
280 if (local) {
281 int n = __atomic_add_unless(&local->usage, 1, 0);
282 if (n > 0)
283 trace_rxrpc_local(local, rxrpc_local_got, n + 1, here);
284 else
285 local = NULL;
286 }
287 return local;
288}
289
290/*
291 * Queue a local endpoint.
292 */
293void rxrpc_queue_local(struct rxrpc_local *local)
294{
295 const void *here = __builtin_return_address(0);
296
297 if (rxrpc_queue_work(&local->processor))
298 trace_rxrpc_local(local, rxrpc_local_queued,
299 atomic_read(&local->usage), here);
300}
301
302/*
260 * A local endpoint reached its end of life.
261 */
303 * A local endpoint reached its end of life.
304 */
262void __rxrpc_put_local(struct rxrpc_local *local)
305static void __rxrpc_put_local(struct rxrpc_local *local)
263{
264 _enter("%d", local->debug_id);
265 rxrpc_queue_work(&local->processor);
266}
267
268/*
306{
307 _enter("%d", local->debug_id);
308 rxrpc_queue_work(&local->processor);
309}
310
311/*
312 * Drop a ref on a local endpoint.
313 */
314void rxrpc_put_local(struct rxrpc_local *local)
315{
316 const void *here = __builtin_return_address(0);
317 int n;
318
319 if (local) {
320 n = atomic_dec_return(&local->usage);
321 trace_rxrpc_local(local, rxrpc_local_put, n, here);
322
323 if (n == 0)
324 __rxrpc_put_local(local);
325 }
326}
327
328/*
269 * Destroy a local endpoint's socket and then hand the record to RCU to dispose
270 * of.
271 *
272 * Closing the socket cannot be done from bottom half context or RCU callback
273 * context because it might sleep.
274 */
275static void rxrpc_local_destroyer(struct rxrpc_local *local)
276{

--- 40 unchanged lines hidden (view full) ---

317 * Process events on an endpoint
318 */
319static void rxrpc_local_processor(struct work_struct *work)
320{
321 struct rxrpc_local *local =
322 container_of(work, struct rxrpc_local, processor);
323 bool again;
324
329 * Destroy a local endpoint's socket and then hand the record to RCU to dispose
330 * of.
331 *
332 * Closing the socket cannot be done from bottom half context or RCU callback
333 * context because it might sleep.
334 */
335static void rxrpc_local_destroyer(struct rxrpc_local *local)
336{

--- 40 unchanged lines hidden (view full) ---

377 * Process events on an endpoint
378 */
379static void rxrpc_local_processor(struct work_struct *work)
380{
381 struct rxrpc_local *local =
382 container_of(work, struct rxrpc_local, processor);
383 bool again;
384
325 _enter("%d", local->debug_id);
385 trace_rxrpc_local(local, rxrpc_local_processing,
386 atomic_read(&local->usage), NULL);
326
327 do {
328 again = false;
329 if (atomic_read(&local->usage) == 0)
330 return rxrpc_local_destroyer(local);
331
332 if (!skb_queue_empty(&local->reject_queue)) {
333 rxrpc_reject_packets(local);

--- 47 unchanged lines hidden ---
387
388 do {
389 again = false;
390 if (atomic_read(&local->usage) == 0)
391 return rxrpc_local_destroyer(local);
392
393 if (!skb_queue_empty(&local->reject_queue)) {
394 rxrpc_reject_packets(local);

--- 47 unchanged lines hidden ---