xref: /freebsd/sys/rpc/replay.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1a9148abdSDoug Rabson /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3fe267a55SPedro F. Giffuni  *
4a9148abdSDoug Rabson  * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
5a9148abdSDoug Rabson  * Authors: Doug Rabson <dfr@rabson.org>
6a9148abdSDoug Rabson  * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
7a9148abdSDoug Rabson  *
8a9148abdSDoug Rabson  * Redistribution and use in source and binary forms, with or without
9a9148abdSDoug Rabson  * modification, are permitted provided that the following conditions
10a9148abdSDoug Rabson  * are met:
11a9148abdSDoug Rabson  * 1. Redistributions of source code must retain the above copyright
12a9148abdSDoug Rabson  *    notice, this list of conditions and the following disclaimer.
13a9148abdSDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
14a9148abdSDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
15a9148abdSDoug Rabson  *    documentation and/or other materials provided with the distribution.
16a9148abdSDoug Rabson  *
17a9148abdSDoug Rabson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18a9148abdSDoug Rabson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19a9148abdSDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20a9148abdSDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21a9148abdSDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22a9148abdSDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23a9148abdSDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24a9148abdSDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25a9148abdSDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26a9148abdSDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27a9148abdSDoug Rabson  * SUCH DAMAGE.
28a9148abdSDoug Rabson  */
29a9148abdSDoug Rabson 
30a9148abdSDoug Rabson #ifndef _RPC_REPLAY_H
31a9148abdSDoug Rabson #define _RPC_REPLAY_H
32a9148abdSDoug Rabson 
33a9148abdSDoug Rabson enum replay_state {
34a9148abdSDoug Rabson 	RS_NEW,			/* new request - caller should execute */
35a9148abdSDoug Rabson 	RS_DONE,		/* request was executed and reply sent */
36a9148abdSDoug Rabson 	RS_INPROGRESS,		/* request is being executed now */
37a9148abdSDoug Rabson 	RS_ERROR		/* allocation or other failure */
38a9148abdSDoug Rabson };
39a9148abdSDoug Rabson 
40a9148abdSDoug Rabson struct replay_cache;
41a9148abdSDoug Rabson 
42a9148abdSDoug Rabson /*
43a9148abdSDoug Rabson  * Create a new replay cache.
44a9148abdSDoug Rabson  */
45a9148abdSDoug Rabson struct replay_cache	*replay_newcache(size_t);
46a9148abdSDoug Rabson 
47a9148abdSDoug Rabson /*
48a9148abdSDoug Rabson  * Set the replay cache size.
49a9148abdSDoug Rabson  */
50a9148abdSDoug Rabson void			replay_setsize(struct replay_cache *, size_t);
51a9148abdSDoug Rabson 
52a9148abdSDoug Rabson /*
53a9148abdSDoug Rabson  * Free a replay cache. Caller must ensure that no cache entries are
54a9148abdSDoug Rabson  * in-progress.
55a9148abdSDoug Rabson  */
56a9148abdSDoug Rabson void			replay_freecache(struct replay_cache *rc);
57a9148abdSDoug Rabson 
58a9148abdSDoug Rabson /*
59a9148abdSDoug Rabson  * Check a replay cache for a message from a given address.
60a9148abdSDoug Rabson  *
61a9148abdSDoug Rabson  * If this is a new request, RS_NEW is returned. Caller should call
62a9148abdSDoug Rabson  * replay_setreply with the results of the request.
63a9148abdSDoug Rabson  *
64a9148abdSDoug Rabson  * If this is a request which is currently executing
65a9148abdSDoug Rabson  * (i.e. replay_setreply hasn't been called for it yet), RS_INPROGRESS
66a9148abdSDoug Rabson  * is returned. The caller should silently drop the request.
67a9148abdSDoug Rabson  *
68a9148abdSDoug Rabson  * If a reply to this message already exists, *repmsg and *mp are set
69a9148abdSDoug Rabson  * to point at the reply and, RS_DONE is returned. The caller should
70a9148abdSDoug Rabson  * re-send this reply.
71a9148abdSDoug Rabson  *
72a9148abdSDoug Rabson  * If the attempt to update the replay cache or copy a replay failed
73a9148abdSDoug Rabson  * for some reason (typically memory shortage), RS_ERROR is returned.
74a9148abdSDoug Rabson  */
75a9148abdSDoug Rabson enum replay_state	replay_find(struct replay_cache *rc,
76a9148abdSDoug Rabson     struct rpc_msg *msg, struct sockaddr *addr,
77a9148abdSDoug Rabson     struct rpc_msg *repmsg, struct mbuf **mp);
78a9148abdSDoug Rabson 
79a9148abdSDoug Rabson /*
80a9148abdSDoug Rabson  * Call this after executing a request to record the reply.
81a9148abdSDoug Rabson  */
82a9148abdSDoug Rabson void			replay_setreply(struct replay_cache *rc,
83a9148abdSDoug Rabson     struct rpc_msg *repmsg,  struct sockaddr *addr, struct mbuf *m);
84a9148abdSDoug Rabson 
85a9148abdSDoug Rabson #endif /* !_RPC_REPLAY_H */
86