]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/gnu/fs/xfs/FreeBSD/xfs_super.c
This commit was generated by cvs2svn to compensate for changes in r155518,
[FreeBSD/FreeBSD.git] / sys / gnu / fs / xfs / FreeBSD / xfs_super.c
1 /*
2  * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  *
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  *
26  * http://www.sgi.com
27  *
28  * For further information regarding this notice, see:
29  *
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32
33 #include "xfs.h"
34
35 #include "xfs_inum.h"
36 #include "xfs_log.h"
37 #include "xfs_clnt.h"
38 #include "xfs_trans.h"
39 #include "xfs_sb.h"
40 #include "xfs_dir.h"
41 #include "xfs_dir2.h"
42 #include "xfs_alloc.h"
43 #include "xfs_dmapi.h"
44 #include "xfs_quota.h"
45 #include "xfs_mount.h"
46 #include "xfs_alloc_btree.h"
47 #include "xfs_bmap_btree.h"
48 #include "xfs_ialloc_btree.h"
49 #include "xfs_btree.h"
50 #include "xfs_ialloc.h"
51 #include "xfs_attr_sf.h"
52 #include "xfs_dir_sf.h"
53 #include "xfs_dir2_sf.h"
54 #include "xfs_dinode.h"
55 #include "xfs_inode.h"
56 #include "xfs_bmap.h"
57 #include "xfs_bit.h"
58 #include "xfs_rtalloc.h"
59 #include "xfs_error.h"
60 #include "xfs_itable.h"
61 #include "xfs_rw.h"
62 #include "xfs_acl.h"
63 #include "xfs_cap.h"
64 #include "xfs_mac.h"
65 #include "xfs_attr.h"
66 #include "xfs_buf_item.h"
67 #include "xfs_utils.h"
68 #include "xfs_version.h"
69
70 #include <geom/geom.h>
71 #include <geom/geom_vfs.h>
72
73 extern struct vop_vector xfs_fifoops;
74 extern struct buf_ops xfs_ops;
75
76 __uint64_t
77 xfs_max_file_offset(
78         unsigned int            blockshift)
79 {
80
81         return (OFF_MAX);
82 }
83
84 void
85 xfs_initialize_vnode(
86         bhv_desc_t              *bdp,
87         xfs_vnode_t             *vp,
88         bhv_desc_t              *inode_bhv,
89         int                     unlock)
90 {
91         xfs_inode_t             *ip = XFS_BHVTOI(inode_bhv);
92
93         if (!inode_bhv->bd_vobj) {
94                 vp->v_vfsp = bhvtovfs(bdp);
95                 bhv_desc_init(inode_bhv, ip, vp, &xfs_vnodeops);
96                 bhv_insert(VN_BHV_HEAD(vp), inode_bhv);
97         }
98
99         /*
100          * XXX: Use VNON as an indication of freshly allocated vnode
101          * which need to be initialized and unlocked.
102          * This is _not_ like the same place in Linux version of
103          * routine.
104          */
105         if (vp->v_type != VNON)
106                 return;
107
108         vp->v_type = IFTOVT(ip->i_d.di_mode);
109         vp->v_vnode->v_type = vp->v_type;
110
111         if (vp->v_type == VFIFO)
112                 vp->v_vnode->v_op = &xfs_fifoops;
113
114         ASSERT_VOP_LOCKED(vp->v_vnode, "xfs_initialize_vnode");
115
116         /* For new inodes we need to set the ops vectors,
117          * and unlock the inode.
118          */
119         if (unlock)
120                 VOP_UNLOCK(vp->v_vnode, 0, curthread);
121 }
122
123 struct vnode *
124 xfs_get_inode(
125         bhv_desc_t      *bdp,
126         xfs_ino_t       ino,
127         int             flags)
128 {
129         return NULL;
130 }
131
132 void
133 xfs_flush_inode(
134         xfs_inode_t     *ip)
135 {
136         printf("xfs_flush_inode NI\n");
137 }
138
139 void
140 xfs_flush_device(
141         xfs_inode_t     *ip)
142 {
143         printf("xfs_flush_device NI\n");
144         xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
145 }
146
147 /*ARGSUSED*/
148 int
149 xfs_blkdev_get(
150         xfs_mount_t             *mp,
151         const char              *name,
152         struct vnode            **bdevp)
153 {
154         struct nameidata        nd;
155         struct nameidata        *ndp = &nd;
156         int                     error, ronly;
157         struct thread           *td;
158         struct vnode            *devvp;
159         struct g_consumer       *cp;
160         struct g_provider       *pp;
161         mode_t                  accessmode;
162
163         td = curthread;
164
165         NDINIT(ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, name, td);
166         if ((error = namei(ndp)) != 0)
167                 return (error);
168         NDFREE(ndp, NDF_ONLY_PNBUF);
169         devvp = ndp->ni_vp;
170
171         if (!vn_isdisk(devvp, &error)) {
172                 vrele(devvp);
173                 return (error);
174         }
175
176         vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
177
178         ronly = ((XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY) != 0);
179         if (suser(td)) {
180                 accessmode = VREAD;
181                 if (!ronly)
182                         accessmode |= VWRITE;
183                 if ((error = VOP_ACCESS(devvp, accessmode, td->td_ucred, td))!= 0){
184                         vput(devvp);
185                         return (error);
186                 }
187         }
188
189         DROP_GIANT();
190         g_topology_lock();
191
192         /*
193          * XXX: Do not allow more than one consumer to open a device
194          *      associated with a particular GEOM provider.
195          *      This disables multiple read-only mounts of a device,
196          *      but it gets rid of panics in bmemfree() when you try to
197          *      mount the same device more than once.
198          *      During mounting, XFS does a bread() of the superblock, but does
199          *      not brelse() it.  A subsequent mount of the same device
200          *      will try to bread() the superblock, resulting in a panic in 
201          *      bremfree(), "buffer not on queue".
202          */
203         pp = g_dev_getprovider(devvp->v_rdev);
204         if ((pp != NULL) && ((pp->acr | pp->acw | pp->ace ) != 0)) 
205                 error = EPERM;
206         else 
207                 error = g_vfs_open(devvp, &cp, "xfs", ronly ? 0 : 1);
208
209         g_topology_unlock();
210         PICKUP_GIANT();
211
212         VOP_UNLOCK(devvp, 0, td);
213         if (error) {
214                 vput(devvp);
215                 return (error);
216         }
217
218         devvp->v_bufobj.bo_private = cp;
219         devvp->v_bufobj.bo_ops = &xfs_ops;
220
221         *bdevp = devvp;
222         return (0);
223 }
224
225 void
226 xfs_blkdev_put(
227         struct vnode    *devvp)
228 {
229         struct g_consumer       *cp;
230
231         if (devvp == NULL)
232                 return;
233
234         vinvalbuf(devvp, V_SAVE, curthread, 0, 0);
235
236         cp = devvp->v_bufobj.bo_private;
237         DROP_GIANT();
238         g_topology_lock();
239         g_wither_geom_close(cp->geom, ENXIO);
240         g_topology_unlock();
241         PICKUP_GIANT();
242
243         vrele(devvp);
244 }
245
246 void
247 xfs_flush_buftarg(
248         xfs_buftarg_t           *btp)
249 {
250         printf("xfs_flush_buftarg NI %p\n",btp);
251 }
252
253 void
254 xfs_free_buftarg(
255         xfs_buftarg_t           *btp)
256 {
257         xfs_flush_buftarg(btp);
258         kmem_free(btp, sizeof(*btp));
259 }
260
261 int
262 xfs_readonly_buftarg(
263         xfs_buftarg_t           *btp)
264 {
265         struct g_consumer *cp;
266
267         KASSERT(btp->specvp->v_bufobj.bo_ops == &xfs_ops,
268            ("Bogus xfs_buftarg_t pointer"));
269         cp = btp->specvp->v_bufobj.bo_private;
270         
271         return (cp->acw == 0);
272 }
273
274 void
275 xfs_relse_buftarg(
276         xfs_buftarg_t           *btp)
277 {
278         printf("xfs_readonly_buftarg NI %p\n",btp);
279 }
280
281 unsigned int
282 xfs_getsize_buftarg(
283         xfs_buftarg_t           *btp)
284 {
285         struct g_consumer       *cp;
286         cp = btp->specvp->v_bufobj.bo_private;
287         return (cp->provider->sectorsize);
288 }
289
290 void
291 xfs_setsize_buftarg(
292         xfs_buftarg_t           *btp,
293         unsigned int            blocksize,
294         unsigned int            sectorsize)
295 {
296         printf("xfs_setsize_buftarg NI %p\n",btp);
297 }
298
299 xfs_buftarg_t *
300 xfs_alloc_buftarg(
301         struct vnode    *bdev)
302 {
303         xfs_buftarg_t           *btp;
304
305         btp = kmem_zalloc(sizeof(*btp), KM_SLEEP);
306
307         btp->dev    = bdev->v_rdev;
308         btp->specvp = bdev;
309
310         return btp;
311 }
312
313 int
314 init_xfs_fs( void )
315 {
316         static char             message[] =
317                 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
318
319         printf(message);
320
321         vn_init();
322         xfs_init();
323         uuid_init();
324         vfs_initdmapi();
325         vfs_initquota();
326
327         return 0;
328 }
329
330 void
331 exit_xfs_fs(void)
332 {
333         xfs_cleanup();
334         vfs_exitquota();
335         vfs_exitdmapi();
336         uuid_cleanup();
337 }
338