peer.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* peer.h: Rx RPC per-transport peer record
  2. *
  3. * Copyright (C) 2002 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 License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #ifndef _LINUX_RXRPC_PEER_H
  12. #define _LINUX_RXRPC_PEER_H
  13. #include <linux/wait.h>
  14. #include <rxrpc/types.h>
  15. #include <rxrpc/krxtimod.h>
  16. struct rxrpc_peer_ops
  17. {
  18. /* peer record being added */
  19. int (*adding)(struct rxrpc_peer *peer);
  20. /* peer record being discarded from graveyard */
  21. void (*discarding)(struct rxrpc_peer *peer);
  22. /* change of epoch detected on connection */
  23. void (*change_of_epoch)(struct rxrpc_connection *conn);
  24. };
  25. /*****************************************************************************/
  26. /*
  27. * Rx RPC per-transport peer record
  28. * - peers only retain a refcount on the transport when they are active
  29. * - peers with refcount==0 are inactive and reside in the transport's graveyard
  30. */
  31. struct rxrpc_peer
  32. {
  33. atomic_t usage;
  34. struct rxrpc_peer_ops *ops; /* operations on this peer */
  35. struct rxrpc_transport *trans; /* owner transport */
  36. struct rxrpc_timer timeout; /* timeout for grave destruction */
  37. struct list_head link; /* link in transport's peer list */
  38. struct list_head proc_link; /* link in /proc list */
  39. rwlock_t conn_idlock; /* lock for connection IDs */
  40. struct list_head conn_idlist; /* list of connections granted IDs */
  41. uint32_t conn_idcounter; /* connection ID counter */
  42. rwlock_t conn_lock; /* lock for active/dead connections */
  43. struct list_head conn_active; /* active connections to/from this peer */
  44. struct list_head conn_graveyard; /* graveyard for inactive connections */
  45. spinlock_t conn_gylock; /* lock for conn_graveyard */
  46. wait_queue_head_t conn_gy_waitq; /* wait queue hit when graveyard is empty */
  47. atomic_t conn_count; /* number of attached connections */
  48. struct in_addr addr; /* remote address */
  49. size_t if_mtu; /* interface MTU for this peer */
  50. spinlock_t lock; /* access lock */
  51. void *user; /* application layer data */
  52. /* calculated RTT cache */
  53. #define RXRPC_RTT_CACHE_SIZE 32
  54. suseconds_t rtt; /* current RTT estimate (in uS) */
  55. unsigned rtt_point; /* next entry at which to insert */
  56. unsigned rtt_usage; /* amount of cache actually used */
  57. suseconds_t rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
  58. };
  59. extern int rxrpc_peer_lookup(struct rxrpc_transport *trans,
  60. __be32 addr,
  61. struct rxrpc_peer **_peer);
  62. static inline void rxrpc_get_peer(struct rxrpc_peer *peer)
  63. {
  64. BUG_ON(atomic_read(&peer->usage)<0);
  65. atomic_inc(&peer->usage);
  66. //printk("rxrpc_get_peer(%p{u=%d})\n",peer,atomic_read(&peer->usage));
  67. }
  68. extern void rxrpc_put_peer(struct rxrpc_peer *peer);
  69. #endif /* _LINUX_RXRPC_PEER_H */