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