HAMMER 40F/Many: UNDO cleanup & stabilization.
[dragonfly.git] / sys / vfs / hammer / hammer_vfsops.c
1 /*
2  * Copyright (c) 2007-2008 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
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
16  *    distribution.
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.
20  * 
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
32  * SUCH DAMAGE.
33  * 
34  * $DragonFly: src/sys/vfs/hammer/hammer_vfsops.c,v 1.33 2008/05/04 09:06:45 dillon Exp $
35  */
36
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>
46 #include <sys/buf.h>
47 #include <sys/buf2.h>
48 #include "hammer.h"
49
50 int hammer_debug_general;
51 int hammer_debug_inode;
52 int hammer_debug_locks;
53 int hammer_debug_btree;
54 int hammer_debug_tid;
55 int hammer_debug_recover;       /* -1 will disable, +1 will force */
56 int hammer_debug_recover_faults;
57 int hammer_count_inodes;
58 int hammer_count_records;
59 int hammer_count_record_datas;
60 int hammer_count_volumes;
61 int hammer_count_buffers;
62 int hammer_count_nodes;
63 int hammer_count_dirtybufs;             /* global */
64 int hammer_limit_dirtybufs = 100;       /* per-mount */
65 int hammer_bio_count;
66 int64_t hammer_contention_count;
67 int64_t hammer_zone_limit;
68
69 SYSCTL_NODE(_vfs, OID_AUTO, hammer, CTLFLAG_RW, 0, "HAMMER filesystem");
70 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_general, CTLFLAG_RW,
71            &hammer_debug_general, 0, "");
72 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_inode, CTLFLAG_RW,
73            &hammer_debug_inode, 0, "");
74 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_locks, CTLFLAG_RW,
75            &hammer_debug_locks, 0, "");
76 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_btree, CTLFLAG_RW,
77            &hammer_debug_btree, 0, "");
78 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_tid, CTLFLAG_RW,
79            &hammer_debug_tid, 0, "");
80 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_recover, CTLFLAG_RW,
81            &hammer_debug_recover, 0, "");
82 SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_recover_faults, CTLFLAG_RW,
83            &hammer_debug_recover_faults, 0, "");
84
85 SYSCTL_INT(_vfs_hammer, OID_AUTO, limit_dirtybufs, CTLFLAG_RW,
86            &hammer_limit_dirtybufs, 0, "");
87
88 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_inodes, CTLFLAG_RD,
89            &hammer_count_inodes, 0, "");
90 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_records, CTLFLAG_RD,
91            &hammer_count_records, 0, "");
92 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_record_datas, CTLFLAG_RD,
93            &hammer_count_record_datas, 0, "");
94 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_volumes, CTLFLAG_RD,
95            &hammer_count_volumes, 0, "");
96 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_buffers, CTLFLAG_RD,
97            &hammer_count_buffers, 0, "");
98 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_nodes, CTLFLAG_RD,
99            &hammer_count_nodes, 0, "");
100 SYSCTL_INT(_vfs_hammer, OID_AUTO, count_dirtybufs, CTLFLAG_RD,
101            &hammer_count_dirtybufs, 0, "");
102 SYSCTL_QUAD(_vfs_hammer, OID_AUTO, zone_limit, CTLFLAG_RW,
103            &hammer_zone_limit, 0, "");
104 SYSCTL_QUAD(_vfs_hammer, OID_AUTO, contention_count, CTLFLAG_RW,
105            &hammer_contention_count, 0, "");
106
107 /*
108  * VFS ABI
109  */
110 static void     hammer_free_hmp(struct mount *mp);
111
112 static int      hammer_vfs_mount(struct mount *mp, char *path, caddr_t data,
113                                 struct ucred *cred);
114 static int      hammer_vfs_unmount(struct mount *mp, int mntflags);
115 static int      hammer_vfs_root(struct mount *mp, struct vnode **vpp);
116 static int      hammer_vfs_statfs(struct mount *mp, struct statfs *sbp,
117                                 struct ucred *cred);
118 static int      hammer_vfs_sync(struct mount *mp, int waitfor);
119 static int      hammer_vfs_vget(struct mount *mp, ino_t ino,
120                                 struct vnode **vpp);
121 static int      hammer_vfs_init(struct vfsconf *conf);
122 static int      hammer_vfs_fhtovp(struct mount *mp, struct fid *fhp,
123                                 struct vnode **vpp);
124 static int      hammer_vfs_vptofh(struct vnode *vp, struct fid *fhp);
125 static int      hammer_vfs_checkexp(struct mount *mp, struct sockaddr *nam,
126                                 int *exflagsp, struct ucred **credanonp);
127
128
129 static struct vfsops hammer_vfsops = {
130         .vfs_mount      = hammer_vfs_mount,
131         .vfs_unmount    = hammer_vfs_unmount,
132         .vfs_root       = hammer_vfs_root,
133         .vfs_statfs     = hammer_vfs_statfs,
134         .vfs_sync       = hammer_vfs_sync,
135         .vfs_vget       = hammer_vfs_vget,
136         .vfs_init       = hammer_vfs_init,
137         .vfs_vptofh     = hammer_vfs_vptofh,
138         .vfs_fhtovp     = hammer_vfs_fhtovp,
139         .vfs_checkexp   = hammer_vfs_checkexp
140 };
141
142 MALLOC_DEFINE(M_HAMMER, "hammer-mount", "hammer mount");
143
144 VFS_SET(hammer_vfsops, hammer, 0);
145 MODULE_VERSION(hammer, 1);
146
147 static int
148 hammer_vfs_init(struct vfsconf *conf)
149 {
150         /*hammer_init_alist_config();*/
151         return(0);
152 }
153
154 static int
155 hammer_vfs_mount(struct mount *mp, char *mntpt, caddr_t data,
156                  struct ucred *cred)
157 {
158         struct hammer_mount_info info;
159         hammer_mount_t hmp;
160         hammer_volume_t rootvol;
161         struct vnode *rootvp;
162         const char *upath;      /* volume name in userspace */
163         char *path;             /* volume name in system space */
164         int error;
165         int i;
166
167         if ((error = copyin(data, &info, sizeof(info))) != 0)
168                 return (error);
169         if (info.nvolumes <= 0 || info.nvolumes >= 32768)
170                 return (EINVAL);
171
172         /*
173          * Interal mount data structure
174          */
175         if (mp->mnt_flag & MNT_UPDATE) {
176                 hmp = (void *)mp->mnt_data;
177                 KKASSERT(hmp != NULL);
178         } else {
179                 hmp = kmalloc(sizeof(*hmp), M_HAMMER, M_WAITOK | M_ZERO);
180                 mp->mnt_data = (qaddr_t)hmp;
181                 hmp->mp = mp;
182                 hmp->zbuf = kmalloc(HAMMER_BUFSIZE, M_HAMMER, M_WAITOK|M_ZERO);
183                 hmp->namekey_iterator = mycpu->gd_time_seconds;
184                 /*TAILQ_INIT(&hmp->recycle_list);*/
185
186                 hmp->root_btree_beg.obj_id = -0x8000000000000000LL;
187                 hmp->root_btree_beg.key = -0x8000000000000000LL;
188                 hmp->root_btree_beg.create_tid = 1;
189                 hmp->root_btree_beg.delete_tid = 1;
190                 hmp->root_btree_beg.rec_type = 0;
191                 hmp->root_btree_beg.obj_type = 0;
192
193                 hmp->root_btree_end.obj_id = 0x7FFFFFFFFFFFFFFFLL;
194                 hmp->root_btree_end.key = 0x7FFFFFFFFFFFFFFFLL;
195                 hmp->root_btree_end.create_tid = 0xFFFFFFFFFFFFFFFFULL;
196                 hmp->root_btree_end.delete_tid = 0;   /* special case */
197                 hmp->root_btree_end.rec_type = 0xFFFFU;
198                 hmp->root_btree_end.obj_type = 0;
199                 lockinit(&hmp->blockmap_lock, "blkmap", 0, 0);
200
201                 hmp->sync_lock.refs = 1;
202                 hmp->free_lock.refs = 1;
203
204                 TAILQ_INIT(&hmp->flush_list);
205                 TAILQ_INIT(&hmp->objid_cache_list);
206                 TAILQ_INIT(&hmp->undo_lru_list);
207
208                 /*
209                  * Set default zone limits.  This value can be reduced
210                  * further by the zone limit specified in the root volume.
211                  *
212                  * The sysctl can force a small zone limit for debugging
213                  * purposes.
214                  */
215                 for (i = 0; i < HAMMER_MAX_ZONES; ++i) {
216                         hmp->zone_limits[i] =
217                                 HAMMER_ZONE_ENCODE(i, HAMMER_ZONE_LIMIT);
218
219                         if (hammer_zone_limit) {
220                                 hmp->zone_limits[i] =
221                                     HAMMER_ZONE_ENCODE(i, hammer_zone_limit);
222                         }
223                         hammer_init_holes(hmp, &hmp->holes[i]);
224                 }
225         }
226         hmp->hflags = info.hflags;
227         if (info.asof) {
228                 mp->mnt_flag |= MNT_RDONLY;
229                 hmp->asof = info.asof;
230         } else {
231                 hmp->asof = HAMMER_MAX_TID;
232         }
233
234         /*
235          * Re-open read-write if originally read-only, or vise-versa XXX
236          */
237         if (mp->mnt_flag & MNT_UPDATE) {
238                 if (hmp->ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
239                         kprintf("HAMMER read-write -> read-only XXX\n");
240                         hmp->ronly = 1;
241                 } else if (hmp->ronly && (mp->mnt_flag & MNT_RDONLY) == 0) {
242                         kprintf("HAMMER read-only -> read-write XXX\n");
243                         hmp->ronly = 0;
244                 }
245                 return(0);
246         }
247
248         RB_INIT(&hmp->rb_vols_root);
249         RB_INIT(&hmp->rb_inos_root);
250         RB_INIT(&hmp->rb_nods_root);
251         RB_INIT(&hmp->rb_undo_root);
252         hmp->ronly = ((mp->mnt_flag & MNT_RDONLY) != 0);
253
254         TAILQ_INIT(&hmp->volu_list);
255         TAILQ_INIT(&hmp->undo_list);
256         TAILQ_INIT(&hmp->data_list);
257         TAILQ_INIT(&hmp->meta_list);
258         TAILQ_INIT(&hmp->lose_list);
259
260         /*
261          * Load volumes
262          */
263         path = objcache_get(namei_oc, M_WAITOK);
264         hmp->nvolumes = info.nvolumes;
265         for (i = 0; i < info.nvolumes; ++i) {
266                 error = copyin(&info.volumes[i], &upath, sizeof(char *));
267                 if (error == 0)
268                         error = copyinstr(upath, path, MAXPATHLEN, NULL);
269                 if (error == 0)
270                         error = hammer_install_volume(hmp, path);
271                 if (error)
272                         break;
273         }
274         objcache_put(namei_oc, path);
275
276         /*
277          * Make sure we found a root volume
278          */
279         if (error == 0 && hmp->rootvol == NULL) {
280                 kprintf("hammer_mount: No root volume found!\n");
281                 error = EINVAL;
282         }
283         if (error) {
284                 hammer_free_hmp(mp);
285                 return (error);
286         }
287
288         /*
289          * No errors, setup enough of the mount point so we can lookup the
290          * root vnode.
291          */
292         mp->mnt_iosize_max = MAXPHYS;
293         mp->mnt_kern_flag |= MNTK_FSMID;
294
295         /* 
296          * note: f_iosize is used by vnode_pager_haspage() when constructing
297          * its VOP_BMAP call.
298          */
299         mp->mnt_stat.f_iosize = HAMMER_BUFSIZE;
300         mp->mnt_stat.f_bsize = HAMMER_BUFSIZE;
301         mp->mnt_maxsymlinklen = 255;
302         mp->mnt_flag |= MNT_LOCAL;
303
304         vfs_add_vnodeops(mp, &hammer_vnode_vops, &mp->mnt_vn_norm_ops);
305         vfs_add_vnodeops(mp, &hammer_spec_vops, &mp->mnt_vn_spec_ops);
306         vfs_add_vnodeops(mp, &hammer_fifo_vops, &mp->mnt_vn_fifo_ops);
307
308         /*
309          * The root volume's ondisk pointer is only valid if we hold a
310          * reference to it.
311          */
312         rootvol = hammer_get_root_volume(hmp, &error);
313         if (error)
314                 goto failed;
315
316         /*
317          * Perform any necessary UNDO operations.  The recover code does
318          * call hammer_undo_lookup() so we have to pre-cache the blockmap,
319          * and then re-copy it again after recovery is complete.
320          *
321          * The recover code will load hmp->flusher_undo_start.
322          */
323         bcopy(rootvol->ondisk->vol0_blockmap, hmp->blockmap,
324               sizeof(hmp->blockmap));
325
326         error = hammer_recover(hmp, rootvol);
327         if (error) {
328                 kprintf("Failed to recover HAMMER filesystem on mount\n");
329                 goto done;
330         }
331
332         /*
333          * Finish setup now that we have a good root volume
334          */
335         ksnprintf(mp->mnt_stat.f_mntfromname,
336                   sizeof(mp->mnt_stat.f_mntfromname), "%s",
337                   rootvol->ondisk->vol_name);
338         mp->mnt_stat.f_fsid.val[0] =
339                 crc32((char *)&rootvol->ondisk->vol_fsid + 0, 8);
340         mp->mnt_stat.f_fsid.val[1] =
341                 crc32((char *)&rootvol->ondisk->vol_fsid + 8, 8);
342
343         /*
344          * Certain often-modified fields in the root volume are cached in
345          * the hammer_mount structure so we do not have to generate lots
346          * of little UNDO structures for them.
347          *
348          * Recopy after recovery.
349          */
350         hmp->next_tid = rootvol->ondisk->vol0_next_tid;
351         bcopy(rootvol->ondisk->vol0_blockmap, hmp->blockmap,
352               sizeof(hmp->blockmap));
353
354         /*
355          * Use the zone limit set by newfs_hammer, or the zone limit set by
356          * sysctl (for debugging), whichever is smaller.
357          */
358         if (rootvol->ondisk->vol0_zone_limit) {
359                 hammer_off_t vol0_zone_limit;
360
361                 vol0_zone_limit = rootvol->ondisk->vol0_zone_limit;
362                 for (i = 0; i < HAMMER_MAX_ZONES; ++i) {
363                         if (hmp->zone_limits[i] > vol0_zone_limit)
364                                 hmp->zone_limits[i] = vol0_zone_limit;
365                 }
366         }
367
368         hammer_flusher_create(hmp);
369
370         /*
371          * Locate the root directory using the root cluster's B-Tree as a
372          * starting point.  The root directory uses an obj_id of 1.
373          *
374          * FUTURE: Leave the root directory cached referenced but unlocked
375          * in hmp->rootvp (need to flush it on unmount).
376          */
377         error = hammer_vfs_vget(mp, 1, &rootvp);
378         if (error)
379                 goto done;
380         vput(rootvp);
381         /*vn_unlock(hmp->rootvp);*/
382
383 done:
384         hammer_rel_volume(rootvol, 0);
385 failed:
386         /*
387          * Cleanup and return.
388          */
389         if (error)
390                 hammer_free_hmp(mp);
391         return (error);
392 }
393
394 static int
395 hammer_vfs_unmount(struct mount *mp, int mntflags)
396 {
397 #if 0
398         struct hammer_mount *hmp = (void *)mp->mnt_data;
399 #endif
400         int flags;
401         int error;
402
403         /*
404          * Clean out the vnodes
405          */
406         flags = 0;
407         if (mntflags & MNT_FORCE)
408                 flags |= FORCECLOSE;
409         if ((error = vflush(mp, 0, flags)) != 0)
410                 return (error);
411
412         /*
413          * Clean up the internal mount structure and related entities.  This
414          * may issue I/O.
415          */
416         hammer_free_hmp(mp);
417         return(0);
418 }
419
420 /*
421  * Clean up the internal mount structure and disassociate it from the mount.
422  * This may issue I/O.
423  */
424 static void
425 hammer_free_hmp(struct mount *mp)
426 {
427         struct hammer_mount *hmp = (void *)mp->mnt_data;
428         int i;
429
430 #if 0
431         /*
432          * Clean up the root vnode
433          */
434         if (hmp->rootvp) {
435                 vrele(hmp->rootvp);
436                 hmp->rootvp = NULL;
437         }
438 #endif
439         hammer_flusher_sync(hmp);
440         hammer_flusher_sync(hmp);
441         hammer_flusher_destroy(hmp);
442
443         KKASSERT(RB_EMPTY(&hmp->rb_inos_root));
444
445 #if 0
446         /*
447          * Unload & flush inodes
448          *
449          * XXX illegal to call this from here, it can only be done from
450          * the flusher.
451          */
452         RB_SCAN(hammer_ino_rb_tree, &hmp->rb_inos_root, NULL,
453                 hammer_unload_inode, (void *)MNT_WAIT);
454
455         /*
456          * Unload & flush volumes
457          */
458 #endif
459         /*
460          * Unload the volumes
461          */
462         RB_SCAN(hammer_vol_rb_tree, &hmp->rb_vols_root, NULL,
463                 hammer_unload_volume, NULL);
464
465         mp->mnt_data = NULL;
466         mp->mnt_flag &= ~MNT_LOCAL;
467         hmp->mp = NULL;
468         hammer_destroy_objid_cache(hmp);
469         kfree(hmp->zbuf, M_HAMMER);
470         lockuninit(&hmp->blockmap_lock);
471
472         for (i = 0; i < HAMMER_MAX_ZONES; ++i)
473                 hammer_free_holes(hmp, &hmp->holes[i]);
474
475         kfree(hmp, M_HAMMER);
476 }
477
478 /*
479  * Obtain a vnode for the specified inode number.  An exclusively locked
480  * vnode is returned.
481  */
482 int
483 hammer_vfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
484 {
485         struct hammer_transaction trans;
486         struct hammer_mount *hmp = (void *)mp->mnt_data;
487         struct hammer_inode *ip;
488         int error;
489
490         hammer_simple_transaction(&trans, hmp);
491
492         /*
493          * Lookup the requested HAMMER inode.  The structure must be
494          * left unlocked while we manipulate the related vnode to avoid
495          * a deadlock.
496          */
497         ip = hammer_get_inode(&trans, NULL, ino, hmp->asof, 0, &error);
498         if (ip == NULL) {
499                 *vpp = NULL;
500                 return(error);
501         }
502         error = hammer_get_vnode(ip, vpp);
503         hammer_rel_inode(ip, 0);
504         hammer_done_transaction(&trans);
505         return (error);
506 }
507
508 /*
509  * Return the root vnode for the filesystem.
510  *
511  * HAMMER stores the root vnode in the hammer_mount structure so
512  * getting it is easy.
513  */
514 static int
515 hammer_vfs_root(struct mount *mp, struct vnode **vpp)
516 {
517 #if 0
518         struct hammer_mount *hmp = (void *)mp->mnt_data;
519 #endif
520         int error;
521
522         error = hammer_vfs_vget(mp, 1, vpp);
523         return (error);
524 }
525
526 static int
527 hammer_vfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
528 {
529         struct hammer_mount *hmp = (void *)mp->mnt_data;
530         hammer_volume_t volume;
531         hammer_volume_ondisk_t ondisk;
532         int error;
533         int64_t bfree;
534
535         volume = hammer_get_root_volume(hmp, &error);
536         if (error)
537                 return(error);
538         ondisk = volume->ondisk;
539
540         /*
541          * Basic stats
542          */
543         mp->mnt_stat.f_files = ondisk->vol0_stat_inodes;
544         bfree = ondisk->vol0_stat_freebigblocks * HAMMER_LARGEBLOCK_SIZE;
545         hammer_rel_volume(volume, 0);
546
547         mp->mnt_stat.f_bfree = bfree / HAMMER_BUFSIZE;
548         mp->mnt_stat.f_bavail = mp->mnt_stat.f_bfree;
549         if (mp->mnt_stat.f_files < 0)
550                 mp->mnt_stat.f_files = 0;
551
552         *sbp = mp->mnt_stat;
553         return(0);
554 }
555
556 /*
557  * Sync the filesystem.  Currently we have to run it twice, the second
558  * one will advance the undo start index to the end index, so if a crash
559  * occurs no undos will be run on mount.
560  */
561 static int
562 hammer_vfs_sync(struct mount *mp, int waitfor)
563 {
564         struct hammer_mount *hmp = (void *)mp->mnt_data;
565         int error;
566
567         error = hammer_sync_hmp(hmp, waitfor);
568         if (error == 0)
569                 error = hammer_sync_hmp(hmp, waitfor);
570         return (error);
571 }
572
573 /*
574  * Convert a vnode to a file handle.
575  */
576 static int
577 hammer_vfs_vptofh(struct vnode *vp, struct fid *fhp)
578 {
579         hammer_inode_t ip;
580
581         KKASSERT(MAXFIDSZ >= 16);
582         ip = VTOI(vp);
583         fhp->fid_len = offsetof(struct fid, fid_data[16]);
584         fhp->fid_reserved = 0;
585         bcopy(&ip->obj_id, fhp->fid_data + 0, sizeof(ip->obj_id));
586         bcopy(&ip->obj_asof, fhp->fid_data + 8, sizeof(ip->obj_asof));
587         return(0);
588 }
589
590
591 /*
592  * Convert a file handle back to a vnode.
593  */
594 static int
595 hammer_vfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
596 {
597         struct hammer_transaction trans;
598         struct hammer_inode *ip;
599         struct hammer_inode_info info;
600         int error;
601
602         bcopy(fhp->fid_data + 0, &info.obj_id, sizeof(info.obj_id));
603         bcopy(fhp->fid_data + 8, &info.obj_asof, sizeof(info.obj_asof));
604
605         hammer_simple_transaction(&trans, (void *)mp->mnt_data);
606
607         /*
608          * Get/allocate the hammer_inode structure.  The structure must be
609          * unlocked while we manipulate the related vnode to avoid a
610          * deadlock.
611          */
612         ip = hammer_get_inode(&trans, NULL, info.obj_id, info.obj_asof,
613                               0, &error);
614         if (ip == NULL) {
615                 *vpp = NULL;
616                 return(error);
617         }
618         error = hammer_get_vnode(ip, vpp);
619         hammer_rel_inode(ip, 0);
620         hammer_done_transaction(&trans);
621         return (error);
622 }
623
624 static int
625 hammer_vfs_checkexp(struct mount *mp, struct sockaddr *nam,
626                     int *exflagsp, struct ucred **credanonp)
627 {
628         hammer_mount_t hmp = (void *)mp->mnt_data;
629         struct netcred *np;
630         int error;
631
632         np = vfs_export_lookup(mp, &hmp->export, nam);
633         if (np) {
634                 *exflagsp = np->netc_exflags;
635                 *credanonp = &np->netc_anon;
636                 error = 0;
637         } else {
638                 error = EACCES;
639         }
640         return (error);
641
642 }
643
644 int
645 hammer_vfs_export(struct mount *mp, int op, const struct export_args *export)
646 {
647         hammer_mount_t hmp = (void *)mp->mnt_data;
648         int error;
649
650         switch(op) {
651         case MOUNTCTL_SET_EXPORT:
652                 error = vfs_export(mp, &hmp->export, export);
653                 break;
654         default:
655                 error = EOPNOTSUPP;
656                 break;
657         }
658         return(error);
659 }
660