xref: /minix3/lib/libpuffs/flush.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: flush.c,v 1.16 2008/08/12 19:44:39 pooka Exp $	*/
2*84d9c625SLionel Sambuc 
3*84d9c625SLionel Sambuc /*
4*84d9c625SLionel Sambuc  * Copyright (c) 2007  Antti Kantee.  All Rights Reserved.
5*84d9c625SLionel Sambuc  *
6*84d9c625SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
7*84d9c625SLionel Sambuc  * modification, are permitted provided that the following conditions
8*84d9c625SLionel Sambuc  * are met:
9*84d9c625SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
10*84d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
11*84d9c625SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
12*84d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
13*84d9c625SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
14*84d9c625SLionel Sambuc  *
15*84d9c625SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16*84d9c625SLionel Sambuc  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17*84d9c625SLionel Sambuc  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18*84d9c625SLionel Sambuc  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*84d9c625SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*84d9c625SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21*84d9c625SLionel Sambuc  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*84d9c625SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*84d9c625SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*84d9c625SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*84d9c625SLionel Sambuc  * SUCH DAMAGE.
26*84d9c625SLionel Sambuc  */
27*84d9c625SLionel Sambuc 
28*84d9c625SLionel Sambuc #include <sys/cdefs.h>
29*84d9c625SLionel Sambuc #if !defined(lint)
30*84d9c625SLionel Sambuc __RCSID("$NetBSD: flush.c,v 1.16 2008/08/12 19:44:39 pooka Exp $");
31*84d9c625SLionel Sambuc #endif /* !lint */
32*84d9c625SLionel Sambuc 
33*84d9c625SLionel Sambuc /*
34*84d9c625SLionel Sambuc  * Flushing / invalidation routines
35*84d9c625SLionel Sambuc  */
36*84d9c625SLionel Sambuc 
37*84d9c625SLionel Sambuc #include <sys/types.h>
38*84d9c625SLionel Sambuc 
39*84d9c625SLionel Sambuc #include <assert.h>
40*84d9c625SLionel Sambuc #include <err.h>
41*84d9c625SLionel Sambuc #include <errno.h>
42*84d9c625SLionel Sambuc #include <puffs.h>
43*84d9c625SLionel Sambuc #include <stdio.h>
44*84d9c625SLionel Sambuc #include <unistd.h>
45*84d9c625SLionel Sambuc 
46*84d9c625SLionel Sambuc #include "puffs_priv.h"
47*84d9c625SLionel Sambuc 
48*84d9c625SLionel Sambuc #if 0
49*84d9c625SLionel Sambuc int
50*84d9c625SLionel Sambuc puffs_inval_namecache_node(struct puffs_usermount *pu, puffs_cookie_t cookie,
51*84d9c625SLionel Sambuc 	const char *name)
52*84d9c625SLionel Sambuc {
53*84d9c625SLionel Sambuc 
54*84d9c625SLionel Sambuc 	return EOPNOTSUPP;
55*84d9c625SLionel Sambuc }
56*84d9c625SLionel Sambuc #endif
57*84d9c625SLionel Sambuc 
58*84d9c625SLionel Sambuc static int
doflush(struct puffs_usermount * pu,puffs_cookie_t cookie,int op,off_t start,off_t end)59*84d9c625SLionel Sambuc doflush(struct puffs_usermount *pu, puffs_cookie_t cookie, int op,
60*84d9c625SLionel Sambuc 	off_t start, off_t end)
61*84d9c625SLionel Sambuc {
62*84d9c625SLionel Sambuc 	struct puffs_framebuf *pb;
63*84d9c625SLionel Sambuc 	struct puffs_flush *pf;
64*84d9c625SLionel Sambuc 	size_t winlen;
65*84d9c625SLionel Sambuc 	int rv;
66*84d9c625SLionel Sambuc 
67*84d9c625SLionel Sambuc 	pb = puffs_framebuf_make();
68*84d9c625SLionel Sambuc 	if (pb == NULL)
69*84d9c625SLionel Sambuc 		return ENOMEM;
70*84d9c625SLionel Sambuc 
71*84d9c625SLionel Sambuc 	winlen = sizeof(struct puffs_flush);
72*84d9c625SLionel Sambuc 	if ((rv = puffs_framebuf_getwindow(pb, 0, (void *)&pf, &winlen)) == -1)
73*84d9c625SLionel Sambuc 		goto out;
74*84d9c625SLionel Sambuc 	assert(winlen == sizeof(struct puffs_flush));
75*84d9c625SLionel Sambuc 
76*84d9c625SLionel Sambuc 	pf->pf_req.preq_buflen = sizeof(struct puffs_flush);
77*84d9c625SLionel Sambuc 	pf->pf_req.preq_opclass = PUFFSOP_FLUSH;
78*84d9c625SLionel Sambuc 	pf->pf_req.preq_id = puffs__nextreq(pu);
79*84d9c625SLionel Sambuc 
80*84d9c625SLionel Sambuc 	pf->pf_op = op;
81*84d9c625SLionel Sambuc 	pf->pf_cookie = cookie;
82*84d9c625SLionel Sambuc 	pf->pf_start = start;
83*84d9c625SLionel Sambuc 	pf->pf_end = end;
84*84d9c625SLionel Sambuc 
85*84d9c625SLionel Sambuc 	rv = puffs_framev_enqueue_cc(puffs_cc_getcc(pu),
86*84d9c625SLionel Sambuc 	    puffs_getselectable(pu), pb, 0);
87*84d9c625SLionel Sambuc 
88*84d9c625SLionel Sambuc  out:
89*84d9c625SLionel Sambuc 	puffs_framebuf_destroy(pb);
90*84d9c625SLionel Sambuc 	return rv;
91*84d9c625SLionel Sambuc }
92*84d9c625SLionel Sambuc 
93*84d9c625SLionel Sambuc int
puffs_inval_namecache_dir(struct puffs_usermount * pu,puffs_cookie_t cookie)94*84d9c625SLionel Sambuc puffs_inval_namecache_dir(struct puffs_usermount *pu, puffs_cookie_t cookie)
95*84d9c625SLionel Sambuc {
96*84d9c625SLionel Sambuc 
97*84d9c625SLionel Sambuc 	return doflush(pu, cookie, PUFFS_INVAL_NAMECACHE_DIR, 0, 0);
98*84d9c625SLionel Sambuc }
99*84d9c625SLionel Sambuc 
100*84d9c625SLionel Sambuc int
puffs_inval_namecache_all(struct puffs_usermount * pu)101*84d9c625SLionel Sambuc puffs_inval_namecache_all(struct puffs_usermount *pu)
102*84d9c625SLionel Sambuc {
103*84d9c625SLionel Sambuc 
104*84d9c625SLionel Sambuc 	return doflush(pu, NULL, PUFFS_INVAL_NAMECACHE_ALL, 0, 0);
105*84d9c625SLionel Sambuc }
106*84d9c625SLionel Sambuc 
107*84d9c625SLionel Sambuc int
puffs_inval_pagecache_node(struct puffs_usermount * pu,puffs_cookie_t cookie)108*84d9c625SLionel Sambuc puffs_inval_pagecache_node(struct puffs_usermount *pu, puffs_cookie_t cookie)
109*84d9c625SLionel Sambuc {
110*84d9c625SLionel Sambuc 
111*84d9c625SLionel Sambuc 	return doflush(pu, cookie, PUFFS_INVAL_PAGECACHE_NODE_RANGE, 0, 0);
112*84d9c625SLionel Sambuc }
113*84d9c625SLionel Sambuc 
114*84d9c625SLionel Sambuc int
puffs_inval_pagecache_node_range(struct puffs_usermount * pu,puffs_cookie_t cookie,off_t start,off_t end)115*84d9c625SLionel Sambuc puffs_inval_pagecache_node_range(struct puffs_usermount *pu,
116*84d9c625SLionel Sambuc 	puffs_cookie_t cookie, off_t start, off_t end)
117*84d9c625SLionel Sambuc {
118*84d9c625SLionel Sambuc 
119*84d9c625SLionel Sambuc 	return doflush(pu, cookie, PUFFS_INVAL_PAGECACHE_NODE_RANGE, start,end);
120*84d9c625SLionel Sambuc }
121*84d9c625SLionel Sambuc 
122*84d9c625SLionel Sambuc int
puffs_flush_pagecache_node(struct puffs_usermount * pu,puffs_cookie_t cookie)123*84d9c625SLionel Sambuc puffs_flush_pagecache_node(struct puffs_usermount *pu, puffs_cookie_t cookie)
124*84d9c625SLionel Sambuc {
125*84d9c625SLionel Sambuc 
126*84d9c625SLionel Sambuc 	return doflush(pu, cookie, PUFFS_FLUSH_PAGECACHE_NODE_RANGE, 0, 0);
127*84d9c625SLionel Sambuc }
128*84d9c625SLionel Sambuc 
129*84d9c625SLionel Sambuc int
puffs_flush_pagecache_node_range(struct puffs_usermount * pu,puffs_cookie_t cookie,off_t start,off_t end)130*84d9c625SLionel Sambuc puffs_flush_pagecache_node_range(struct puffs_usermount *pu,
131*84d9c625SLionel Sambuc 	puffs_cookie_t cookie, off_t start, off_t end)
132*84d9c625SLionel Sambuc {
133*84d9c625SLionel Sambuc 
134*84d9c625SLionel Sambuc 	return doflush(pu, cookie, PUFFS_FLUSH_PAGECACHE_NODE_RANGE, start,end);
135*84d9c625SLionel Sambuc }
136