2 * Copyright (c) 2007-2008 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sys/vfs/hammer/hammer_vfsops.c,v 1.41 2008/06/09 04:19:10 dillon Exp $
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/vnode.h>
41 #include <sys/mount.h>
42 #include <sys/malloc.h>
43 #include <sys/nlookup.h>
44 #include <sys/fcntl.h>
45 #include <sys/sysctl.h>
51 int hammer_debug_general;
52 int hammer_debug_debug;
53 int hammer_debug_inode;
54 int hammer_debug_locks;
55 int hammer_debug_btree;
57 int hammer_debug_recover; /* -1 will disable, +1 will force */
58 int hammer_debug_recover_faults;
59 int hammer_count_inodes;
60 int hammer_count_reclaiming;
61 int hammer_count_records;
62 int hammer_count_record_datas;
63 int hammer_count_volumes;
64 int hammer_count_buffers;
65 int hammer_count_nodes;
66 int hammer_count_dirtybufs; /* global */
67 int hammer_count_reservations;
68 int hammer_stats_btree_iterations;
69 int hammer_stats_record_iterations;
70 int hammer_limit_dirtybufs; /* per-mount */
71 int hammer_limit_irecs; /* per-inode */
72 int hammer_limit_recs; /* as a whole XXX */
74 int64_t hammer_contention_count;
75 int64_t hammer_zone_limit;
77 SYSCTL_NODE(_vfs, OID_AUTO, hammer, CTLFLAG_RW, 0, "HAMMER filesystem");
78 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_general, CTLFLAG_RW,
79 &hammer_debug_general, 0, "");
80 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_io, CTLFLAG_RW,
81 &hammer_debug_io, 0, "");
82 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_debug, CTLFLAG_RW,
83 &hammer_debug_debug, 0, "");
84 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_inode, CTLFLAG_RW,
85 &hammer_debug_inode, 0, "");
86 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_locks, CTLFLAG_RW,
87 &hammer_debug_locks, 0, "");
88 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_btree, CTLFLAG_RW,
89 &hammer_debug_btree, 0, "");
90 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_tid, CTLFLAG_RW,
91 &hammer_debug_tid, 0, "");
92 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_recover, CTLFLAG_RW,
93 &hammer_debug_recover, 0, "");
94 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_recover_faults, CTLFLAG_RW,
95 &hammer_debug_recover_faults, 0, "");
97 SYSCTL_INT(_vfs_hammer, OID_AUTO, limit_dirtybufs, CTLFLAG_RW,
98 &hammer_limit_dirtybufs, 0, "");
99 SYSCTL_INT(_vfs_hammer, OID_AUTO, limit_irecs, CTLFLAG_RW,
100 &hammer_limit_irecs, 0, "");
101 SYSCTL_INT(_vfs_hammer, OID_AUTO, limit_recs, CTLFLAG_RW,
102 &hammer_limit_recs, 0, "");
104 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_inodes, CTLFLAG_RD,
105 &hammer_count_inodes, 0, "");
106 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_reclaiming, CTLFLAG_RD,
107 &hammer_count_reclaiming, 0, "");
108 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_records, CTLFLAG_RD,
109 &hammer_count_records, 0, "");
110 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_record_datas, CTLFLAG_RD,
111 &hammer_count_record_datas, 0, "");
112 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_volumes, CTLFLAG_RD,
113 &hammer_count_volumes, 0, "");
114 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_buffers, CTLFLAG_RD,
115 &hammer_count_buffers, 0, "");
116 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_nodes, CTLFLAG_RD,
117 &hammer_count_nodes, 0, "");
118 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_dirtybufs, CTLFLAG_RD,
119 &hammer_count_dirtybufs, 0, "");
120 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_reservations, CTLFLAG_RD,
121 &hammer_count_reservations, 0, "");
122 SYSCTL_QUAD(_vfs_hammer, OID_AUTO, zone_limit, CTLFLAG_RW,
123 &hammer_zone_limit, 0, "");
124 SYSCTL_QUAD(_vfs_hammer, OID_AUTO, contention_count, CTLFLAG_RW,
125 &hammer_contention_count, 0, "");
130 static void hammer_free_hmp(struct mount *mp);
132 static int hammer_vfs_mount(struct mount *mp, char *path, caddr_t data,
134 static int hammer_vfs_unmount(struct mount *mp, int mntflags);
135 static int hammer_vfs_root(struct mount *mp, struct vnode **vpp);
136 static int hammer_vfs_statfs(struct mount *mp, struct statfs *sbp,
138 static int hammer_vfs_statvfs(struct mount *mp, struct statvfs *sbp,
140 static int hammer_vfs_sync(struct mount *mp, int waitfor);
141 static int hammer_vfs_vget(struct mount *mp, ino_t ino,
143 static int hammer_vfs_init(struct vfsconf *conf);
144 static int hammer_vfs_fhtovp(struct mount *mp, struct fid *fhp,
146 static int hammer_vfs_vptofh(struct vnode *vp, struct fid *fhp);
147 static int hammer_vfs_checkexp(struct mount *mp, struct sockaddr *nam,
148 int *exflagsp, struct ucred **credanonp);
151 static struct vfsops hammer_vfsops = {
152 .vfs_mount = hammer_vfs_mount,
153 .vfs_unmount = hammer_vfs_unmount,
154 .vfs_root = hammer_vfs_root,
155 .vfs_statfs = hammer_vfs_statfs,
156 .vfs_statvfs = hammer_vfs_statvfs,
157 .vfs_sync = hammer_vfs_sync,
158 .vfs_vget = hammer_vfs_vget,
159 .vfs_init = hammer_vfs_init,
160 .vfs_vptofh = hammer_vfs_vptofh,
161 .vfs_fhtovp = hammer_vfs_fhtovp,
162 .vfs_checkexp = hammer_vfs_checkexp
165 MALLOC_DEFINE(M_HAMMER, "hammer-mount", "hammer mount");
167 VFS_SET(hammer_vfsops, hammer, 0);
168 MODULE_VERSION(hammer, 1);
171 hammer_vfs_init(struct vfsconf *conf)
173 if (hammer_limit_irecs == 0)
174 hammer_limit_irecs = nbuf;
175 if (hammer_limit_recs == 0) /* XXX TODO */
176 hammer_limit_recs = hammer_limit_irecs * 4;
177 if (hammer_limit_dirtybufs == 0) {
178 hammer_limit_dirtybufs = hidirtybuffers / 2;
179 if (hammer_limit_dirtybufs < 100)
180 hammer_limit_dirtybufs = 100;
186 hammer_vfs_mount(struct mount *mp, char *mntpt, caddr_t data,
189 struct hammer_mount_info info;
191 hammer_volume_t rootvol;
192 struct vnode *rootvp;
193 const char *upath; /* volume name in userspace */
194 char *path; /* volume name in system space */
198 if ((error = copyin(data, &info, sizeof(info))) != 0)
200 if ((mp->mnt_flag & MNT_UPDATE) == 0) {
201 if (info.nvolumes <= 0 || info.nvolumes >= 32768)
206 * Interal mount data structure
208 if (mp->mnt_flag & MNT_UPDATE) {
209 hmp = (void *)mp->mnt_data;
210 KKASSERT(hmp != NULL);
212 hmp = kmalloc(sizeof(*hmp), M_HAMMER, M_WAITOK | M_ZERO);
213 mp->mnt_data = (qaddr_t)hmp;
215 hmp->zbuf = kmalloc(HAMMER_BUFSIZE, M_HAMMER, M_WAITOK|M_ZERO);
216 hmp->namekey_iterator = mycpu->gd_time_seconds;
217 /*TAILQ_INIT(&hmp->recycle_list);*/
219 hmp->root_btree_beg.localization = HAMMER_MIN_LOCALIZATION;
220 hmp->root_btree_beg.obj_id = -0x8000000000000000LL;
221 hmp->root_btree_beg.key = -0x8000000000000000LL;
222 hmp->root_btree_beg.create_tid = 1;
223 hmp->root_btree_beg.delete_tid = 1;
224 hmp->root_btree_beg.rec_type = 0;
225 hmp->root_btree_beg.obj_type = 0;
227 hmp->root_btree_end.localization = HAMMER_MAX_LOCALIZATION;
228 hmp->root_btree_end.obj_id = 0x7FFFFFFFFFFFFFFFLL;
229 hmp->root_btree_end.key = 0x7FFFFFFFFFFFFFFFLL;
230 hmp->root_btree_end.create_tid = 0xFFFFFFFFFFFFFFFFULL;
231 hmp->root_btree_end.delete_tid = 0; /* special case */
232 hmp->root_btree_end.rec_type = 0xFFFFU;
233 hmp->root_btree_end.obj_type = 0;
234 lockinit(&hmp->blockmap_lock, "blkmap", 0, 0);
236 hmp->sync_lock.refs = 1;
237 hmp->free_lock.refs = 1;
239 TAILQ_INIT(&hmp->flush_list);
240 TAILQ_INIT(&hmp->objid_cache_list);
241 TAILQ_INIT(&hmp->undo_lru_list);
244 * Set default zone limits. This value can be reduced
245 * further by the zone limit specified in the root volume.
247 * The sysctl can force a small zone limit for debugging
250 for (i = 0; i < HAMMER_MAX_ZONES; ++i) {
251 hmp->zone_limits[i] =
252 HAMMER_ZONE_ENCODE(i, HAMMER_ZONE_LIMIT);
254 if (hammer_zone_limit) {
255 hmp->zone_limits[i] =
256 HAMMER_ZONE_ENCODE(i, hammer_zone_limit);
258 hammer_init_holes(hmp, &hmp->holes[i]);
261 hmp->hflags &= ~HMNT_USERFLAGS;
262 hmp->hflags |= info.hflags & HMNT_USERFLAGS;
265 mp->mnt_flag |= MNT_RDONLY;
266 hmp->asof = info.asof;
268 hmp->asof = HAMMER_MAX_TID;
272 * Re-open read-write if originally read-only, or vise-versa.
274 if (mp->mnt_flag & MNT_UPDATE) {
276 if (hmp->ronly && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
277 kprintf("HAMMER read-only -> read-write\n");
279 RB_SCAN(hammer_vol_rb_tree, &hmp->rb_vols_root, NULL,
280 hammer_adjust_volume_mode, NULL);
281 rootvol = hammer_get_root_volume(hmp, &error);
283 hammer_recover_flush_buffers(hmp, rootvol);
284 bcopy(rootvol->ondisk->vol0_blockmap,
286 sizeof(hmp->blockmap));
287 hammer_rel_volume(rootvol, 0);
289 RB_SCAN(hammer_ino_rb_tree, &hmp->rb_inos_root, NULL,
290 hammer_reload_inode, NULL);
291 /* kernel clears MNT_RDONLY */
292 } else if (hmp->ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
293 kprintf("HAMMER read-write -> read-only\n");
294 hmp->ronly = 1; /* messy */
295 RB_SCAN(hammer_ino_rb_tree, &hmp->rb_inos_root, NULL,
296 hammer_reload_inode, NULL);
298 hammer_flusher_sync(hmp);
299 hammer_flusher_sync(hmp);
300 hammer_flusher_sync(hmp);
302 RB_SCAN(hammer_vol_rb_tree, &hmp->rb_vols_root, NULL,
303 hammer_adjust_volume_mode, NULL);
308 RB_INIT(&hmp->rb_vols_root);
309 RB_INIT(&hmp->rb_inos_root);
310 RB_INIT(&hmp->rb_nods_root);
311 RB_INIT(&hmp->rb_undo_root);
312 RB_INIT(&hmp->rb_resv_root);
313 RB_INIT(&hmp->rb_bufs_root);
315 hmp->ronly = ((mp->mnt_flag & MNT_RDONLY) != 0);
317 TAILQ_INIT(&hmp->volu_list);
318 TAILQ_INIT(&hmp->undo_list);
319 TAILQ_INIT(&hmp->data_list);
320 TAILQ_INIT(&hmp->meta_list);
321 TAILQ_INIT(&hmp->lose_list);
326 path = objcache_get(namei_oc, M_WAITOK);
327 hmp->nvolumes = info.nvolumes;
328 for (i = 0; i < info.nvolumes; ++i) {
329 error = copyin(&info.volumes[i], &upath, sizeof(char *));
331 error = copyinstr(upath, path, MAXPATHLEN, NULL);
333 error = hammer_install_volume(hmp, path);
337 objcache_put(namei_oc, path);
340 * Make sure we found a root volume
342 if (error == 0 && hmp->rootvol == NULL) {
343 kprintf("hammer_mount: No root volume found!\n");
352 * No errors, setup enough of the mount point so we can lookup the
355 mp->mnt_iosize_max = MAXPHYS;
356 mp->mnt_kern_flag |= MNTK_FSMID;
359 * note: f_iosize is used by vnode_pager_haspage() when constructing
362 mp->mnt_stat.f_iosize = HAMMER_BUFSIZE;
363 mp->mnt_stat.f_bsize = HAMMER_BUFSIZE;
365 mp->mnt_vstat.f_frsize = HAMMER_BUFSIZE;
366 mp->mnt_vstat.f_bsize = HAMMER_BUFSIZE;
368 mp->mnt_maxsymlinklen = 255;
369 mp->mnt_flag |= MNT_LOCAL;
371 vfs_add_vnodeops(mp, &hammer_vnode_vops, &mp->mnt_vn_norm_ops);
372 vfs_add_vnodeops(mp, &hammer_spec_vops, &mp->mnt_vn_spec_ops);
373 vfs_add_vnodeops(mp, &hammer_fifo_vops, &mp->mnt_vn_fifo_ops);
376 * The root volume's ondisk pointer is only valid if we hold a
379 rootvol = hammer_get_root_volume(hmp, &error);
384 * Perform any necessary UNDO operations. The recovery code does
385 * call hammer_undo_lookup() so we have to pre-cache the blockmap,
386 * and then re-copy it again after recovery is complete.
388 * If this is a read-only mount the UNDO information is retained
389 * in memory in the form of dirty buffer cache buffers, and not
390 * written back to the media.
392 bcopy(rootvol->ondisk->vol0_blockmap, hmp->blockmap,
393 sizeof(hmp->blockmap));
395 error = hammer_recover(hmp, rootvol);
397 kprintf("Failed to recover HAMMER filesystem on mount\n");
402 * Finish setup now that we have a good root volume
404 ksnprintf(mp->mnt_stat.f_mntfromname,
405 sizeof(mp->mnt_stat.f_mntfromname), "%s",
406 rootvol->ondisk->vol_name);
407 mp->mnt_stat.f_fsid.val[0] =
408 crc32((char *)&rootvol->ondisk->vol_fsid + 0, 8);
409 mp->mnt_stat.f_fsid.val[1] =
410 crc32((char *)&rootvol->ondisk->vol_fsid + 8, 8);
412 mp->mnt_vstat.f_fsid_uuid = rootvol->ondisk->vol_fsid;
413 mp->mnt_vstat.f_fsid = crc32(&mp->mnt_vstat.f_fsid_uuid,
414 sizeof(mp->mnt_vstat.f_fsid_uuid));
417 * Certain often-modified fields in the root volume are cached in
418 * the hammer_mount structure so we do not have to generate lots
419 * of little UNDO structures for them.
421 * Recopy after recovery. This also has the side effect of
422 * setting our cached undo FIFO's first_offset, which serves to
423 * placemark the FIFO start for the NEXT flush cycle while the
424 * on-disk first_offset represents the LAST flush cycle.
426 hmp->next_tid = rootvol->ondisk->vol0_next_tid;
427 bcopy(rootvol->ondisk->vol0_blockmap, hmp->blockmap,
428 sizeof(hmp->blockmap));
429 hmp->copy_stat_freebigblocks = rootvol->ondisk->vol0_stat_freebigblocks;
432 * Use the zone limit set by newfs_hammer, or the zone limit set by
433 * sysctl (for debugging), whichever is smaller.
435 if (rootvol->ondisk->vol0_zone_limit) {
436 hammer_off_t vol0_zone_limit;
438 vol0_zone_limit = rootvol->ondisk->vol0_zone_limit;
439 for (i = 0; i < HAMMER_MAX_ZONES; ++i) {
440 if (hmp->zone_limits[i] > vol0_zone_limit)
441 hmp->zone_limits[i] = vol0_zone_limit;
445 hammer_flusher_create(hmp);
448 * Locate the root directory using the root cluster's B-Tree as a
449 * starting point. The root directory uses an obj_id of 1.
451 * FUTURE: Leave the root directory cached referenced but unlocked
452 * in hmp->rootvp (need to flush it on unmount).
454 error = hammer_vfs_vget(mp, 1, &rootvp);
458 /*vn_unlock(hmp->rootvp);*/
461 hammer_rel_volume(rootvol, 0);
464 * Cleanup and return.
472 hammer_vfs_unmount(struct mount *mp, int mntflags)
475 struct hammer_mount *hmp = (void *)mp->mnt_data;
481 * Clean out the vnodes
484 if (mntflags & MNT_FORCE)
486 if ((error = vflush(mp, 0, flags)) != 0)
490 * Clean up the internal mount structure and related entities. This
498 * Clean up the internal mount structure and disassociate it from the mount.
499 * This may issue I/O.
502 hammer_free_hmp(struct mount *mp)
504 struct hammer_mount *hmp = (void *)mp->mnt_data;
509 * Clean up the root vnode
516 hammer_flusher_sync(hmp);
517 hammer_flusher_sync(hmp);
518 hammer_flusher_destroy(hmp);
520 KKASSERT(RB_EMPTY(&hmp->rb_inos_root));
524 * Unload & flush inodes
526 * XXX illegal to call this from here, it can only be done from
529 RB_SCAN(hammer_ino_rb_tree, &hmp->rb_inos_root, NULL,
530 hammer_unload_inode, (void *)MNT_WAIT);
533 * Unload & flush volumes
537 * Unload buffers and then volumes
539 RB_SCAN(hammer_buf_rb_tree, &hmp->rb_bufs_root, NULL,
540 hammer_unload_buffer, NULL);
541 RB_SCAN(hammer_vol_rb_tree, &hmp->rb_vols_root, NULL,
542 hammer_unload_volume, NULL);
545 mp->mnt_flag &= ~MNT_LOCAL;
547 hammer_destroy_objid_cache(hmp);
548 kfree(hmp->zbuf, M_HAMMER);
549 lockuninit(&hmp->blockmap_lock);
551 for (i = 0; i < HAMMER_MAX_ZONES; ++i)
552 hammer_free_holes(hmp, &hmp->holes[i]);
554 kfree(hmp, M_HAMMER);
558 * Obtain a vnode for the specified inode number. An exclusively locked
562 hammer_vfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
564 struct hammer_transaction trans;
565 struct hammer_mount *hmp = (void *)mp->mnt_data;
566 struct hammer_inode *ip;
569 hammer_simple_transaction(&trans, hmp);
572 * Lookup the requested HAMMER inode. The structure must be
573 * left unlocked while we manipulate the related vnode to avoid
576 ip = hammer_get_inode(&trans, NULL, ino, hmp->asof, 0, &error);
581 error = hammer_get_vnode(ip, vpp);
582 hammer_rel_inode(ip, 0);
583 hammer_done_transaction(&trans);
588 * Return the root vnode for the filesystem.
590 * HAMMER stores the root vnode in the hammer_mount structure so
591 * getting it is easy.
594 hammer_vfs_root(struct mount *mp, struct vnode **vpp)
597 struct hammer_mount *hmp = (void *)mp->mnt_data;
601 error = hammer_vfs_vget(mp, 1, vpp);
606 hammer_vfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
608 struct hammer_mount *hmp = (void *)mp->mnt_data;
609 hammer_volume_t volume;
610 hammer_volume_ondisk_t ondisk;
614 volume = hammer_get_root_volume(hmp, &error);
617 ondisk = volume->ondisk;
622 mp->mnt_stat.f_files = ondisk->vol0_stat_inodes;
623 bfree = ondisk->vol0_stat_freebigblocks * HAMMER_LARGEBLOCK_SIZE;
624 hammer_rel_volume(volume, 0);
626 mp->mnt_stat.f_bfree = bfree / HAMMER_BUFSIZE;
627 mp->mnt_stat.f_bavail = mp->mnt_stat.f_bfree;
628 if (mp->mnt_stat.f_files < 0)
629 mp->mnt_stat.f_files = 0;
636 hammer_vfs_statvfs(struct mount *mp, struct statvfs *sbp, struct ucred *cred)
638 struct hammer_mount *hmp = (void *)mp->mnt_data;
639 hammer_volume_t volume;
640 hammer_volume_ondisk_t ondisk;
644 volume = hammer_get_root_volume(hmp, &error);
647 ondisk = volume->ondisk;
652 mp->mnt_vstat.f_files = ondisk->vol0_stat_inodes;
653 bfree = ondisk->vol0_stat_freebigblocks * HAMMER_LARGEBLOCK_SIZE;
654 hammer_rel_volume(volume, 0);
656 mp->mnt_vstat.f_bfree = bfree / HAMMER_BUFSIZE;
657 mp->mnt_vstat.f_bavail = mp->mnt_stat.f_bfree;
658 if (mp->mnt_vstat.f_files < 0)
659 mp->mnt_vstat.f_files = 0;
660 *sbp = mp->mnt_vstat;
665 * Sync the filesystem. Currently we have to run it twice, the second
666 * one will advance the undo start index to the end index, so if a crash
667 * occurs no undos will be run on mount.
669 * We do not sync the filesystem if we are called from a panic. If we did
670 * we might end up blowing up a sync that was already in progress.
673 hammer_vfs_sync(struct mount *mp, int waitfor)
675 struct hammer_mount *hmp = (void *)mp->mnt_data;
678 if (panicstr == NULL) {
679 error = hammer_sync_hmp(hmp, waitfor);
681 error = hammer_sync_hmp(hmp, waitfor);
689 * Convert a vnode to a file handle.
692 hammer_vfs_vptofh(struct vnode *vp, struct fid *fhp)
696 KKASSERT(MAXFIDSZ >= 16);
698 fhp->fid_len = offsetof(struct fid, fid_data[16]);
699 fhp->fid_reserved = 0;
700 bcopy(&ip->obj_id, fhp->fid_data + 0, sizeof(ip->obj_id));
701 bcopy(&ip->obj_asof, fhp->fid_data + 8, sizeof(ip->obj_asof));
707 * Convert a file handle back to a vnode.
710 hammer_vfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
712 struct hammer_transaction trans;
713 struct hammer_inode *ip;
714 struct hammer_inode_info info;
717 bcopy(fhp->fid_data + 0, &info.obj_id, sizeof(info.obj_id));
718 bcopy(fhp->fid_data + 8, &info.obj_asof, sizeof(info.obj_asof));
720 hammer_simple_transaction(&trans, (void *)mp->mnt_data);
723 * Get/allocate the hammer_inode structure. The structure must be
724 * unlocked while we manipulate the related vnode to avoid a
727 ip = hammer_get_inode(&trans, NULL, info.obj_id, info.obj_asof,
733 error = hammer_get_vnode(ip, vpp);
734 hammer_rel_inode(ip, 0);
735 hammer_done_transaction(&trans);
740 hammer_vfs_checkexp(struct mount *mp, struct sockaddr *nam,
741 int *exflagsp, struct ucred **credanonp)
743 hammer_mount_t hmp = (void *)mp->mnt_data;
747 np = vfs_export_lookup(mp, &hmp->export, nam);
749 *exflagsp = np->netc_exflags;
750 *credanonp = &np->netc_anon;
760 hammer_vfs_export(struct mount *mp, int op, const struct export_args *export)
762 hammer_mount_t hmp = (void *)mp->mnt_data;
766 case MOUNTCTL_SET_EXPORT:
767 error = vfs_export(mp, &hmp->export, export);