01cffbcc9d68c0089dbd063ab81e52f00cd4eeaa
[dragonfly.git] / sys / vfs / hammer2 / hammer2_vnops.c
1 /*
2  * Copyright (c) 2011-2012 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@dragonflybsd.org>
6  * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  * 3. Neither the name of The DragonFly Project nor the names of its
19  *    contributors may be used to endorse or promote products derived
20  *    from this software without specific, prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
26  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/fcntl.h>
39 #include <sys/buf.h>
40 #include <sys/proc.h>
41 #include <sys/namei.h>
42 #include <sys/mount.h>
43 #include <sys/vnode.h>
44 #include <sys/mountctl.h>
45
46 #include "hammer2.h"
47
48 /*
49  * Last reference to a vnode is going away but it is still cached.
50  */
51 static
52 int
53 hammer2_vop_inactive(struct vop_inactive_args *ap)
54 {
55         struct vnode *vp;
56         struct hammer2_inode *ip;
57 #if 0
58         struct hammer2_mount *hmp;
59 #endif
60
61         kprintf("hammer2_inactive\n");
62
63         vp = ap->a_vp;
64         ip = VTOI(vp);
65
66         return (0);
67 }
68
69 /*
70  * Reclaim a vnode so that it can be reused; after the inode is
71  * disassociated, the filesystem must manage it alone.
72  */
73 static
74 int
75 hammer2_vop_reclaim(struct vop_reclaim_args *ap)
76 {
77         struct vnode *vp;
78         struct hammer2_inode *ip;
79         struct hammer2_mount *hmp;
80
81         vp = ap->a_vp;
82         ip = VTOI(vp);
83         hmp = ip->hmp;
84
85         hammer2_inode_lock_ex(ip);
86         vp->v_data = NULL;
87         ip->vp = NULL;
88         hammer2_inode_unlock_ex(ip);
89
90         /*
91          * XXX handle background sync when ip dirty, kernel will no longer
92          * notify us regarding this inode because there is no longer a
93          * vnode attached to it.
94          */
95
96         return (0);
97 }
98
99 static
100 int
101 hammer2_vop_fsync(struct vop_fsync_args *ap)
102 {
103         kprintf("hammer2_fsync\n");
104         return (EOPNOTSUPP);
105 }
106
107 static
108 int
109 hammer2_vop_access(struct vop_access_args *ap)
110 {
111         kprintf("hammer2_access\n");
112         return (0);
113 }
114
115 static
116 int
117 hammer2_vop_getattr(struct vop_getattr_args *ap)
118 {
119         struct vnode *vp;
120         struct vattr *vap;
121         struct hammer2_inode *ip;
122
123         vp = ap->a_vp;
124         vap = ap->a_vap;
125
126         kprintf("hammer2_getattr\n");
127
128         ip = VTOI(vp);
129         hammer2_inode_lock_sh(ip);
130
131         vap->va_type = vp->v_type;
132         vap->va_mode = 0777;
133         vap->va_nlink = 1;
134         vap->va_uid = 0;
135         vap->va_gid = 0;
136         vap->va_size = 0;
137         vap->va_blocksize = PAGE_SIZE;
138         vap->va_flags = 0;
139
140         hammer2_inode_unlock_sh(ip);
141
142         return (0);
143 }
144
145 static
146 int
147 hammer2_vop_readdir(struct vop_readdir_args *ap)
148 {
149         kprintf("hammer2_readdir\n");
150         return (EOPNOTSUPP);
151 }
152
153 static
154 int
155 hammer2_vop_read(struct vop_read_args *ap)
156 {
157         return (EOPNOTSUPP);
158 }
159
160 static
161 int
162 hammer2_vop_write(struct vop_write_args *ap)
163 {
164         return (EOPNOTSUPP);
165 }
166
167 static
168 int
169 hammer2_vop_nresolve(struct vop_nresolve_args *ap)
170 {
171         kprintf("hammer2_nresolve\n");
172         return (EOPNOTSUPP);
173 }
174
175 static
176 int
177 hammer2_vop_bmap(struct vop_bmap_args *ap)
178 {
179         kprintf("hammer2_bmap\n");
180         return (EOPNOTSUPP);
181 }
182
183 static
184 int
185 hammer2_vop_open(struct vop_open_args *ap)
186 {
187         kprintf("hammer2_open\n");
188         return vop_stdopen(ap);
189 }
190
191 static
192 int
193 hammer2_vop_strategy(struct vop_strategy_args *ap)
194 {
195         struct vnode *vp;
196         struct bio *biop;
197         struct buf *bp;
198         struct hammer2_inode *ip;
199         int error;
200
201         vp = ap->a_vp;
202         biop = ap->a_bio;
203         bp = biop->bio_buf;
204         ip = VTOI(vp);
205
206         switch(bp->b_cmd) {
207         case (BUF_CMD_READ):
208         case (BUF_CMD_WRITE):
209         default:
210                 bp->b_error = error = EINVAL;
211                 bp->b_flags |= B_ERROR;
212                 biodone(biop);
213                 break;
214         }
215
216         return (error);
217 }
218
219 static
220 int 
221 hammer2_vop_mountctl(struct vop_mountctl_args *ap)
222 {
223         struct mount *mp;
224         struct hammer2_mount *hmp;
225         int rc;
226
227         switch (ap->a_op) {
228         case (MOUNTCTL_SET_EXPORT):
229                 mp = ap->a_head.a_ops->head.vv_mount;
230                 hmp = MPTOH2(mp);
231
232                 if (ap->a_ctllen != sizeof(struct export_args))
233                         rc = (EINVAL);
234                 else
235                         rc = vfs_export(mp, &hmp->hm_export,
236                                 (const struct export_args *) ap->a_ctl);
237                 break;
238         default:
239                 rc = vop_stdmountctl(ap);
240                 break;
241         }
242         return (rc);
243 }
244
245 struct vop_ops hammer2_vnode_vops = {
246         .vop_default    = vop_defaultop,
247         .vop_fsync      = hammer2_vop_fsync,
248         .vop_getpages   = vop_stdgetpages,
249         .vop_putpages   = vop_stdputpages,
250         .vop_access     = hammer2_vop_access,
251         .vop_getattr    = hammer2_vop_getattr,
252         .vop_readdir    = hammer2_vop_readdir,
253         .vop_read       = hammer2_vop_read,
254         .vop_write      = hammer2_vop_write,
255         .vop_open       = hammer2_vop_open,
256         .vop_inactive   = hammer2_vop_inactive,
257         .vop_reclaim    = hammer2_vop_reclaim,
258         .vop_nresolve   = hammer2_vop_nresolve,
259         .vop_mountctl   = hammer2_vop_mountctl,
260         .vop_bmap       = hammer2_vop_bmap,
261         .vop_strategy   = hammer2_vop_strategy,
262 };
263
264 struct vop_ops hammer2_spec_vops = {
265
266 };
267
268 struct vop_ops hammer2_fifo_vops = {
269
270 };