]> 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 r162503,
[FreeBSD/FreeBSD.git] / sys / gnu / fs / xfs / FreeBSD / xfs_super.c
1 /*
2  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 #include "xfs.h"
19 #include "xfs_bit.h"
20 #include "xfs_log.h"
21 #include "xfs_clnt.h"
22 #include "xfs_inum.h"
23 #include "xfs_trans.h"
24 #include "xfs_sb.h"
25 #include "xfs_ag.h"
26 #include "xfs_dir.h"
27 #include "xfs_dir2.h"
28 #include "xfs_alloc.h"
29 #include "xfs_dmapi.h"
30 #include "xfs_quota.h"
31 #include "xfs_mount.h"
32 #include "xfs_bmap_btree.h"
33 #include "xfs_alloc_btree.h"
34 #include "xfs_ialloc_btree.h"
35 #include "xfs_dir_sf.h"
36 #include "xfs_dir2_sf.h"
37 #include "xfs_attr_sf.h"
38 #include "xfs_dinode.h"
39 #include "xfs_inode.h"
40 #include "xfs_btree.h"
41 #include "xfs_ialloc.h"
42 #include "xfs_bmap.h"
43 #include "xfs_rtalloc.h"
44 #include "xfs_error.h"
45 #include "xfs_itable.h"
46 #include "xfs_rw.h"
47 #include "xfs_acl.h"
48 #include "xfs_cap.h"
49 #include "xfs_mac.h"
50 #include "xfs_attr.h"
51 #include "xfs_buf_item.h"
52 #include "xfs_utils.h"
53 #include "xfs_version.h"
54 #include "xfs_buf.h"
55
56 #include <geom/geom.h>
57 #include <geom/geom_vfs.h>
58
59 extern struct vop_vector xfs_fifoops;
60 extern struct xfs_vnodeops xfs_vnodeops;
61
62 __uint64_t
63 xfs_max_file_offset(
64         unsigned int            blockshift)
65 {
66
67         return (OFF_MAX);
68 }
69
70 void
71 xfs_initialize_vnode(
72         bhv_desc_t              *bdp,
73         xfs_vnode_t             *xvp,
74         bhv_desc_t              *inode_bhv,
75         int                     unlock)
76 {
77         xfs_inode_t             *ip = XFS_BHVTOI(inode_bhv);
78
79         if (!inode_bhv->bd_vobj) {
80                 xvp->v_vfsp = bhvtovfs(bdp);
81                 bhv_desc_init(inode_bhv, ip, xvp, &xfs_vnodeops);
82                 bhv_insert(VN_BHV_HEAD(xvp), inode_bhv);
83         }
84
85         /*
86          * XXX: Use VNON as an indication of freshly allocated vnode
87          * which need to be initialized and unlocked.
88          * This is _not_ like the same place in Linux version of
89          * routine.
90          */
91
92         if (xvp->v_vnode->v_type != VNON)
93           return;
94
95         xvp->v_vnode->v_type =  IFTOVT(ip->i_d.di_mode);
96
97         if (xvp->v_vnode->v_type == VFIFO)
98                 xvp->v_vnode->v_op = &xfs_fifoops;
99
100         ASSERT_VOP_LOCKED(xvp->v_vnode, "xfs_initialize_vnode");
101
102         /* For new inodes we need to set the ops vectors,
103          * and unlock the inode.
104          */
105         if (ip->i_d.di_mode != 0 && unlock)
106                 VOP_UNLOCK(xvp->v_vnode, 0, curthread);
107 }
108
109 #if 0
110 struct vnode *
111 xfs_get_inode(
112         bhv_desc_t      *bdp,
113         xfs_ino_t       ino,
114         int             flags)
115 {
116         return NULL;
117 }
118 #endif
119
120 /*ARGSUSED*/
121 int
122 xfs_blkdev_get(
123         xfs_mount_t             *mp,
124         const char              *name,
125         struct vnode            **bdevp)
126 {
127         struct nameidata        nd;
128         struct nameidata        *ndp = &nd;
129         int                     error, ronly;
130         struct thread           *td;
131         struct vnode            *devvp;
132         struct g_consumer       *cp;
133         struct g_provider       *pp;
134         mode_t                  accessmode;
135
136         td = curthread;
137
138         NDINIT(ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, name, td);
139         if ((error = namei(ndp)) != 0)
140                 return (error);
141         NDFREE(ndp, NDF_ONLY_PNBUF);
142         devvp = ndp->ni_vp;
143
144         if (!vn_isdisk(devvp, &error)) {
145                 vrele(devvp);
146                 return (error);
147         }
148
149         vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
150
151         ronly = ((XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY) != 0);
152         if (suser(td)) {
153                 accessmode = VREAD;
154                 if (!ronly)
155                         accessmode |= VWRITE;
156                 if ((error = VOP_ACCESS(devvp, accessmode, td->td_ucred, td))!= 0){
157                         vput(devvp);
158                         return (error);
159                 }
160         }
161
162         DROP_GIANT();
163         g_topology_lock();
164
165         /*
166          * XXX: Do not allow more than one consumer to open a device
167          *      associated with a particular GEOM provider.
168          *      This disables multiple read-only mounts of a device,
169          *      but it gets rid of panics in bmemfree() when you try to
170          *      mount the same device more than once.
171          *      During mounting, XFS does a bread() of the superblock, but does
172          *      not brelse() it.  A subsequent mount of the same device
173          *      will try to bread() the superblock, resulting in a panic in 
174          *      bremfree(), "buffer not on queue".
175          */
176         pp = g_dev_getprovider(devvp->v_rdev);
177         if ((pp != NULL) && ((pp->acr | pp->acw | pp->ace ) != 0)) 
178                 error = EPERM;
179         else 
180                 error = g_vfs_open(devvp, &cp, "xfs", ronly ? 0 : 1);
181
182         g_topology_unlock();
183         PICKUP_GIANT();
184
185         if (error) {
186                 vput(devvp);
187                 return (error);
188         }
189         VOP_UNLOCK(devvp, 0, td);
190
191         devvp->v_bufobj.bo_private = cp;
192         devvp->v_bufobj.bo_ops = &xfs_bo_ops;
193
194         *bdevp = devvp;
195         return (0);
196 }
197
198 void
199 xfs_blkdev_put(
200         struct vnode    *devvp)
201 {
202         struct g_consumer       *cp;
203
204         if (devvp == NULL)
205                 return;
206
207         vinvalbuf(devvp, V_SAVE, curthread, 0, 0);
208
209         cp = devvp->v_bufobj.bo_private;
210         DROP_GIANT();
211         g_topology_lock();
212         g_wither_geom_close(cp->geom, ENXIO);
213         g_topology_unlock();
214         PICKUP_GIANT();
215
216         vrele(devvp);
217 }
218
219 void
220 xfs_mountfs_check_barriers(xfs_mount_t *mp)
221 {
222         printf("xfs_mountfs_check_barriers NI\n");
223 }
224
225 void
226 xfs_flush_inode(
227                 xfs_inode_t     *ip)
228 {
229         printf("xfs_flush_inode NI\n");
230 }
231
232 void
233 xfs_flush_device(
234                  xfs_inode_t    *ip)
235 {
236         printf("xfs_flush_device NI\n");
237         xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
238 }
239
240
241 void
242 xfs_blkdev_issue_flush(
243         xfs_buftarg_t           *buftarg)
244 {
245         printf("xfs_blkdev_issue_flush NI\n");
246 }
247
248 int
249 init_xfs_fs( void )
250 {
251         static char             message[] =
252                 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
253
254         printf(message);
255
256         vn_init();
257         xfs_init();
258         uuid_init();
259 #ifdef RMC
260         vfs_initdmapi();
261 #endif
262         vfs_initquota();
263
264         return 0;
265 }
266
267 void
268 exit_xfs_fs(void)
269 {
270         xfs_cleanup();
271         vfs_exitquota();
272 #ifdef RMC
273         vfs_exitdmapi();
274 #endif
275 }
276