3 #include <sys/kernel.h>
5 #include <sys/malloc.h>
10 #include <geom/geom.h>
11 #include <geom/geom_vfs.h>
14 #include "xfs_macros.h"
15 #include "xfs_types.h"
18 #include "xfs_trans.h"
23 #include "xfs_dmapi.h"
24 #include "xfs_mount.h"
25 #include "xfs_alloc_btree.h"
26 #include "xfs_bmap_btree.h"
27 #include "xfs_ialloc_btree.h"
28 #include "xfs_btree.h"
29 #include "xfs_ialloc.h"
30 #include "xfs_attr_sf.h"
31 #include "xfs_dir_sf.h"
32 #include "xfs_dir2_sf.h"
33 #include "xfs_dinode.h"
34 #include "xfs_inode.h"
35 #include "xfs_alloc.h"
36 #include "xfs_rtalloc.h"
38 #include "xfs_error.h"
41 #include "xfs_quota.h"
42 #include "xfs_fsops.h"
45 #include <xfs_mountops.h>
47 MALLOC_DEFINE(M_XFSNODE, "XFS node", "XFS vnode private part");
49 static vfs_mount_t _xfs_mount;
50 static vfs_unmount_t _xfs_unmount;
51 static vfs_root_t _xfs_root;
52 static vfs_quotactl_t _xfs_quotactl;
53 static vfs_statfs_t _xfs_statfs;
54 static vfs_sync_t _xfs_sync;
55 static vfs_vget_t _xfs_vget;
56 static vfs_fhtovp_t _xfs_fhtovp;
57 static vfs_checkexp_t _xfs_checkexp;
58 static vfs_vptofh_t _xfs_vptofh;
59 static vfs_init_t _xfs_init;
60 static vfs_uninit_t _xfs_uninit;
61 static vfs_extattrctl_t _xfs_extattrctl;
63 static b_strategy_t xfs_geom_strategy;
65 static const char *xfs_opts[] =
66 { "from", "flags", "logbufs", "logbufsize",
67 "rtname", "logname", "iosizelog", "sunit",
72 parse_int(struct mount *mp, const char *opt, int *val, int *error)
76 tmp = vfs_getopts(mp->mnt_optnew, opt, error);
81 *val = (int)strtol(tmp, &ep, 10);
90 _xfs_param_copyin(struct mount *mp, struct thread *td)
92 struct xfsmount *xmp = MNTTOXFS(mp);
93 struct xfs_mount_args *args = &xmp->m_args;
100 path = vfs_getopts(mp->mnt_optnew, "fspath", &error);
104 bzero(args, sizeof(struct xfs_mount_args));
106 args->logbufsize = -1;
108 parse_int(mp, "flags", &args->flags, &error);
112 args->flags |= XFSMNT_32BITINODES;
114 parse_int(mp, "sunit", &args->sunit, &error);
118 parse_int(mp, "swidth", &args->swidth, &error);
122 parse_int(mp, "logbufs", &args->logbufs, &error);
126 parse_int(mp, "logbufsize", &args->logbufsize, &error);
130 fsname = vfs_getopts(mp->mnt_optnew, "from", &error);
131 if (error == 0 && fsname != NULL) {
132 strncpy(args->fsname, fsname, sizeof(args->fsname) - 1);
135 logname = vfs_getopts(mp->mnt_optnew, "logname", &error);
136 if (error == 0 && logname != NULL) {
137 strncpy(args->logname, logname, sizeof(args->logname) - 1);
140 rtname = vfs_getopts(mp->mnt_optnew, "rtname", &error);
141 if (error == 0 && rtname != NULL) {
142 strncpy(args->rtname, rtname, sizeof(args->rtname) - 1);
145 strncpy(args->mtpt, path, sizeof(args->mtpt));
147 printf("fsname '%s' logname '%s' rtname '%s'\n"
148 "flags 0x%x sunit %d swidth %d logbufs %d logbufsize %d\n",
149 args->fsname, args->logname, args->rtname, args->flags,
150 args->sunit, args->swidth, args->logbufs, args->logbufsize);
152 vfs_mountedfrom(mp, args->fsname);
158 _xfs_mount(struct mount *mp,
161 struct xfsmount *xmp;
162 struct xfs_vnode *rootvp;
163 struct ucred *curcred;
168 if (vfs_filteropt(mp->mnt_optnew, xfs_opts))
171 xmp = xfsmount_allocate(mp);
175 if((error = _xfs_param_copyin(mp, td)) != 0)
178 /* Force read-only mounts in this branch. */
179 XFSTOVFS(xmp)->vfs_flag |= VFS_RDONLY;
180 mp->mnt_flag |= MNT_RDONLY;
182 /* XXX: Do not support MNT_UPDATE yet */
183 if (mp->mnt_flag & MNT_UPDATE)
186 curcred = td->td_ucred;
187 XVFS_MOUNT(XFSTOVFS(xmp), &xmp->m_args, curcred, error);
191 XVFS_ROOT(XFSTOVFS(xmp), &rootvp, error);
195 ddev = XFS_VFSTOM(XFSTOVFS(xmp))->m_dev;
196 if (ddev->si_iosize_max != 0)
197 mp->mnt_iosize_max = ddev->si_iosize_max;
198 if (mp->mnt_iosize_max > MAXPHYS)
199 mp->mnt_iosize_max = MAXPHYS;
201 mp->mnt_flag |= MNT_LOCAL | MNT_RDONLY;
202 mp->mnt_stat.f_fsid.val[0] = dev2udev(ddev);
203 mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
205 VFS_STATFS(mp, &mp->mnt_stat, td);
209 rvp = rootvp->v_vnode;
210 rvp->v_vflag |= VV_ROOT;
216 XVFS_UNMOUNT(XFSTOVFS(xmp), 0, curcred, error);
220 xfsmount_deallocate(xmp);
226 * Free reference to null layer
229 _xfs_unmount(mp, mntflags, td)
236 XVFS_UNMOUNT(MNTTOVFS(mp), 0, td->td_ucred, error);
241 _xfs_root(mp, flags, vpp, td)
250 XVFS_ROOT(MNTTOVFS(mp), &vp, error);
253 VOP_LOCK(*vpp, flags, curthread);
259 _xfs_quotactl(mp, cmd, uid, arg, td)
266 printf("xfs_quotactl\n");
271 _xfs_statfs(mp, sbp, td)
278 XVFS_STATVFS(MNTTOVFS(mp), sbp, NULL, error);
282 /* Fix up the values XFS statvfs calls does not know about. */
283 sbp->f_iosize = sbp->f_bsize;
289 _xfs_sync(mp, waitfor, td)
295 int flags = SYNC_FSDATA|SYNC_ATTR|SYNC_REFCACHE;
297 if (waitfor == MNT_WAIT)
299 else if (waitfor == MNT_LAZY)
300 flags |= SYNC_BDFLUSH;
301 XVFS_SYNC(MNTTOVFS(mp), flags, td->td_ucred, error);
306 _xfs_vget(mp, ino, flags, vpp)
315 printf("XVFS_GET_VNODE(MNTTOVFS(mp), &vp, ino, error);\n");
323 _xfs_fhtovp(mp, fidp, vpp)
328 printf("xfs_fhtovp\n");
333 _xfs_checkexp(mp, nam, extflagsp, credanonp)
335 struct sockaddr *nam;
337 struct ucred **credanonp;
339 printf("xfs_checkexp\n");
348 printf("xfs_vptofh");
353 _xfs_extattrctl(struct mount *mp, int cm,
354 struct vnode *filename_v,
355 int attrnamespace, const char *attrname,
358 printf("xfs_extattrctl\n");
364 struct vfsconf *vfsp;
368 error = init_xfs_fs();
375 struct vfsconf *vfsp;
381 static struct vfsops xfs_fsops = {
382 .vfs_mount = _xfs_mount,
383 .vfs_unmount = _xfs_unmount,
384 .vfs_root = _xfs_root,
385 .vfs_quotactl = _xfs_quotactl,
386 .vfs_statfs = _xfs_statfs,
387 .vfs_sync = _xfs_sync,
388 .vfs_vget = _xfs_vget,
389 .vfs_fhtovp = _xfs_fhtovp,
390 .vfs_checkexp = _xfs_checkexp,
391 .vfs_vptofh = _xfs_vptofh,
392 .vfs_init = _xfs_init,
393 .vfs_uninit = _xfs_uninit,
394 .vfs_extattrctl = _xfs_extattrctl,
397 /* XXX: Read-only for now */
398 VFS_SET(xfs_fsops, xfs, VFCF_READONLY);
401 * Copy GEOM VFS functions here to provide a conveniet place to
402 * track all XFS-related IO without being distracted by other
403 * filesystems which happen to be mounted on the machine at the
408 xfs_geom_biodone(struct bio *bip)
412 if (bip->bio_error) {
413 printf("g_vfs_done():");
415 printf("error = %d\n", bip->bio_error);
417 bp = bip->bio_caller2;
418 bp->b_error = bip->bio_error;
419 bp->b_ioflags = bip->bio_flags;
421 bp->b_ioflags |= BIO_ERROR;
422 bp->b_resid = bp->b_bcount - bip->bio_completed;
430 xfs_geom_strategy(struct bufobj *bo, struct buf *bp)
432 struct g_consumer *cp;
436 G_VALID_CONSUMER(cp);
439 bip->bio_cmd = bp->b_iocmd;
440 bip->bio_offset = bp->b_iooffset;
441 bip->bio_data = bp->b_data;
442 bip->bio_done = xfs_geom_biodone;
443 bip->bio_caller2 = bp;
444 bip->bio_length = bp->b_bcount;
445 g_io_request(bip, cp);
449 xfs_geom_bufwrite(struct buf *bp)
454 struct buf_ops xfs_ops = {
456 .bop_write = xfs_geom_bufwrite,
457 .bop_strategy = xfs_geom_strategy,