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