1427e5fc6SMatthew Dillon /* 2b84de5afSMatthew Dillon * Copyright (c) 2007-2008 The DragonFly Project. All rights reserved. 3427e5fc6SMatthew Dillon * 4427e5fc6SMatthew Dillon * This code is derived from software contributed to The DragonFly Project 5427e5fc6SMatthew Dillon * by Matthew Dillon <dillon@backplane.com> 6427e5fc6SMatthew Dillon * 7427e5fc6SMatthew Dillon * Redistribution and use in source and binary forms, with or without 8427e5fc6SMatthew Dillon * modification, are permitted provided that the following conditions 9427e5fc6SMatthew Dillon * are met: 10427e5fc6SMatthew Dillon * 11427e5fc6SMatthew Dillon * 1. Redistributions of source code must retain the above copyright 12427e5fc6SMatthew Dillon * notice, this list of conditions and the following disclaimer. 13427e5fc6SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright 14427e5fc6SMatthew Dillon * notice, this list of conditions and the following disclaimer in 15427e5fc6SMatthew Dillon * the documentation and/or other materials provided with the 16427e5fc6SMatthew Dillon * distribution. 17427e5fc6SMatthew Dillon * 3. Neither the name of The DragonFly Project nor the names of its 18427e5fc6SMatthew Dillon * contributors may be used to endorse or promote products derived 19427e5fc6SMatthew Dillon * from this software without specific, prior written permission. 20427e5fc6SMatthew Dillon * 21427e5fc6SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22427e5fc6SMatthew Dillon * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23427e5fc6SMatthew Dillon * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24427e5fc6SMatthew Dillon * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25427e5fc6SMatthew Dillon * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26427e5fc6SMatthew Dillon * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27427e5fc6SMatthew Dillon * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28427e5fc6SMatthew Dillon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29427e5fc6SMatthew Dillon * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30427e5fc6SMatthew Dillon * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31427e5fc6SMatthew Dillon * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32427e5fc6SMatthew Dillon * SUCH DAMAGE. 33427e5fc6SMatthew Dillon * 34*67863d04SMatthew Dillon * $DragonFly: src/sys/vfs/hammer/hammer_vfsops.c,v 1.71 2008/09/17 21:44:20 dillon Exp $ 35427e5fc6SMatthew Dillon */ 36427e5fc6SMatthew Dillon 37427e5fc6SMatthew Dillon #include <sys/param.h> 38427e5fc6SMatthew Dillon #include <sys/systm.h> 39427e5fc6SMatthew Dillon #include <sys/kernel.h> 40427e5fc6SMatthew Dillon #include <sys/vnode.h> 41427e5fc6SMatthew Dillon #include <sys/mount.h> 42427e5fc6SMatthew Dillon #include <sys/malloc.h> 43427e5fc6SMatthew Dillon #include <sys/nlookup.h> 44427e5fc6SMatthew Dillon #include <sys/fcntl.h> 45b3deaf57SMatthew Dillon #include <sys/sysctl.h> 46427e5fc6SMatthew Dillon #include <sys/buf.h> 47427e5fc6SMatthew Dillon #include <sys/buf2.h> 48427e5fc6SMatthew Dillon #include "hammer.h" 49427e5fc6SMatthew Dillon 502f85fa4dSMatthew Dillon int hammer_debug_io; 51d5ef456eSMatthew Dillon int hammer_debug_general; 521b0ab2c3SMatthew Dillon int hammer_debug_debug = 1; /* medium-error panics */ 53e8599db1SMatthew Dillon int hammer_debug_inode; 547d683b0fSMatthew Dillon int hammer_debug_locks; 55b3deaf57SMatthew Dillon int hammer_debug_btree; 56d113fda1SMatthew Dillon int hammer_debug_tid; 5746fe7ae1SMatthew Dillon int hammer_debug_recover; /* -1 will disable, +1 will force */ 5846fe7ae1SMatthew Dillon int hammer_debug_recover_faults; 591b0ab2c3SMatthew Dillon int hammer_cluster_enable = 1; /* enable read clustering by default */ 607a61b85dSMatthew Dillon int hammer_count_fsyncs; 61b3deaf57SMatthew Dillon int hammer_count_inodes; 62af209b0fSMatthew Dillon int hammer_count_iqueued; 639f5097dcSMatthew Dillon int hammer_count_reclaiming; 64b3deaf57SMatthew Dillon int hammer_count_records; 65b3deaf57SMatthew Dillon int hammer_count_record_datas; 66b3deaf57SMatthew Dillon int hammer_count_volumes; 67b3deaf57SMatthew Dillon int hammer_count_buffers; 68b3deaf57SMatthew Dillon int hammer_count_nodes; 69a7e9bef1SMatthew Dillon int64_t hammer_count_extra_space_used; 70cb51be26SMatthew Dillon int64_t hammer_stats_btree_lookups; 71cb51be26SMatthew Dillon int64_t hammer_stats_btree_searches; 72cb51be26SMatthew Dillon int64_t hammer_stats_btree_inserts; 73cb51be26SMatthew Dillon int64_t hammer_stats_btree_deletes; 74cb51be26SMatthew Dillon int64_t hammer_stats_btree_elements; 75cb51be26SMatthew Dillon int64_t hammer_stats_btree_splits; 76cb51be26SMatthew Dillon int64_t hammer_stats_btree_iterations; 77cb51be26SMatthew Dillon int64_t hammer_stats_record_iterations; 78ce0138a6SMatthew Dillon 79ce0138a6SMatthew Dillon int64_t hammer_stats_file_read; 80ce0138a6SMatthew Dillon int64_t hammer_stats_file_write; 81ce0138a6SMatthew Dillon int64_t hammer_stats_file_iopsr; 82ce0138a6SMatthew Dillon int64_t hammer_stats_file_iopsw; 83ce0138a6SMatthew Dillon int64_t hammer_stats_disk_read; 84ce0138a6SMatthew Dillon int64_t hammer_stats_disk_write; 85ce0138a6SMatthew Dillon int64_t hammer_stats_inode_flushes; 86ce0138a6SMatthew Dillon int64_t hammer_stats_commits; 87ce0138a6SMatthew Dillon 88f5a07a7aSMatthew Dillon int hammer_count_dirtybufspace; /* global */ 89a99b9ea2SMatthew Dillon int hammer_count_refedbufs; /* global */ 900832c9bbSMatthew Dillon int hammer_count_reservations; 91a99b9ea2SMatthew Dillon int hammer_count_io_running_read; 92a99b9ea2SMatthew Dillon int hammer_count_io_running_write; 93a99b9ea2SMatthew Dillon int hammer_count_io_locked; 94f5a07a7aSMatthew Dillon int hammer_limit_dirtybufspace; /* per-mount */ 950832c9bbSMatthew Dillon int hammer_limit_recs; /* as a whole XXX */ 96af209b0fSMatthew Dillon int hammer_limit_iqueued; /* per-mount */ 971f07f686SMatthew Dillon int hammer_bio_count; 98cb51be26SMatthew Dillon int hammer_verify_zone; 991b0ab2c3SMatthew Dillon int hammer_verify_data = 1; 100cb51be26SMatthew Dillon int hammer_write_mode; 1017d683b0fSMatthew Dillon int64_t hammer_contention_count; 102f03c9cf4SMatthew Dillon int64_t hammer_zone_limit; 103b3deaf57SMatthew Dillon 104b3deaf57SMatthew Dillon SYSCTL_NODE(_vfs, OID_AUTO, hammer, CTLFLAG_RW, 0, "HAMMER filesystem"); 105d5ef456eSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_general, CTLFLAG_RW, 106d5ef456eSMatthew Dillon &hammer_debug_general, 0, ""); 1072f85fa4dSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_io, CTLFLAG_RW, 1082f85fa4dSMatthew Dillon &hammer_debug_io, 0, ""); 10977062c8aSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_debug, CTLFLAG_RW, 11077062c8aSMatthew Dillon &hammer_debug_debug, 0, ""); 111e8599db1SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_inode, CTLFLAG_RW, 112e8599db1SMatthew Dillon &hammer_debug_inode, 0, ""); 1137d683b0fSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_locks, CTLFLAG_RW, 1147d683b0fSMatthew Dillon &hammer_debug_locks, 0, ""); 115b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_btree, CTLFLAG_RW, 116b3deaf57SMatthew Dillon &hammer_debug_btree, 0, ""); 117d113fda1SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_tid, CTLFLAG_RW, 118d113fda1SMatthew Dillon &hammer_debug_tid, 0, ""); 119b33e2cc0SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_recover, CTLFLAG_RW, 120b33e2cc0SMatthew Dillon &hammer_debug_recover, 0, ""); 12146fe7ae1SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_recover_faults, CTLFLAG_RW, 12246fe7ae1SMatthew Dillon &hammer_debug_recover_faults, 0, ""); 1231b0ab2c3SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, cluster_enable, CTLFLAG_RW, 1241b0ab2c3SMatthew Dillon &hammer_cluster_enable, 0, ""); 1259480ff55SMatthew Dillon 126f5a07a7aSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, limit_dirtybufspace, CTLFLAG_RW, 127f5a07a7aSMatthew Dillon &hammer_limit_dirtybufspace, 0, ""); 12847637bffSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, limit_recs, CTLFLAG_RW, 12947637bffSMatthew Dillon &hammer_limit_recs, 0, ""); 130af209b0fSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, limit_iqueued, CTLFLAG_RW, 131af209b0fSMatthew Dillon &hammer_limit_iqueued, 0, ""); 1329480ff55SMatthew Dillon 1337a61b85dSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_fsyncs, CTLFLAG_RD, 1347a61b85dSMatthew Dillon &hammer_count_fsyncs, 0, ""); 135b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_inodes, CTLFLAG_RD, 136b3deaf57SMatthew Dillon &hammer_count_inodes, 0, ""); 137af209b0fSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_iqueued, CTLFLAG_RD, 138af209b0fSMatthew Dillon &hammer_count_iqueued, 0, ""); 1399f5097dcSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_reclaiming, CTLFLAG_RD, 1409f5097dcSMatthew Dillon &hammer_count_reclaiming, 0, ""); 141b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_records, CTLFLAG_RD, 142b3deaf57SMatthew Dillon &hammer_count_records, 0, ""); 143b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_record_datas, CTLFLAG_RD, 144b3deaf57SMatthew Dillon &hammer_count_record_datas, 0, ""); 145b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_volumes, CTLFLAG_RD, 146b3deaf57SMatthew Dillon &hammer_count_volumes, 0, ""); 147b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_buffers, CTLFLAG_RD, 148b3deaf57SMatthew Dillon &hammer_count_buffers, 0, ""); 149b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_nodes, CTLFLAG_RD, 150b3deaf57SMatthew Dillon &hammer_count_nodes, 0, ""); 151a7e9bef1SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, count_extra_space_used, CTLFLAG_RD, 152a7e9bef1SMatthew Dillon &hammer_count_extra_space_used, 0, ""); 153ce0138a6SMatthew Dillon 154cb51be26SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_btree_searches, CTLFLAG_RD, 155cb51be26SMatthew Dillon &hammer_stats_btree_searches, 0, ""); 156cb51be26SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_btree_lookups, CTLFLAG_RD, 157cb51be26SMatthew Dillon &hammer_stats_btree_lookups, 0, ""); 158cb51be26SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_btree_inserts, CTLFLAG_RD, 159cb51be26SMatthew Dillon &hammer_stats_btree_inserts, 0, ""); 160cb51be26SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_btree_deletes, CTLFLAG_RD, 161cb51be26SMatthew Dillon &hammer_stats_btree_deletes, 0, ""); 162cb51be26SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_btree_elements, CTLFLAG_RD, 163cb51be26SMatthew Dillon &hammer_stats_btree_elements, 0, ""); 164cb51be26SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_btree_splits, CTLFLAG_RD, 165cb51be26SMatthew Dillon &hammer_stats_btree_splits, 0, ""); 166cb51be26SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_btree_iterations, CTLFLAG_RD, 167cb51be26SMatthew Dillon &hammer_stats_btree_iterations, 0, ""); 168cb51be26SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_record_iterations, CTLFLAG_RD, 169cb51be26SMatthew Dillon &hammer_stats_record_iterations, 0, ""); 170ce0138a6SMatthew Dillon 171ce0138a6SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_file_read, CTLFLAG_RD, 172ce0138a6SMatthew Dillon &hammer_stats_file_read, 0, ""); 173ce0138a6SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_file_write, CTLFLAG_RD, 174ce0138a6SMatthew Dillon &hammer_stats_file_write, 0, ""); 175ce0138a6SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_file_iopsr, CTLFLAG_RD, 176ce0138a6SMatthew Dillon &hammer_stats_file_iopsr, 0, ""); 177ce0138a6SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_file_iopsw, CTLFLAG_RD, 178ce0138a6SMatthew Dillon &hammer_stats_file_iopsw, 0, ""); 179ce0138a6SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_disk_read, CTLFLAG_RD, 180ce0138a6SMatthew Dillon &hammer_stats_disk_read, 0, ""); 181ce0138a6SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_disk_write, CTLFLAG_RD, 182ce0138a6SMatthew Dillon &hammer_stats_disk_write, 0, ""); 183ce0138a6SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_inode_flushes, CTLFLAG_RD, 184ce0138a6SMatthew Dillon &hammer_stats_inode_flushes, 0, ""); 185ce0138a6SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, stats_commits, CTLFLAG_RD, 186ce0138a6SMatthew Dillon &hammer_stats_commits, 0, ""); 187ce0138a6SMatthew Dillon 188f5a07a7aSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_dirtybufspace, CTLFLAG_RD, 189f5a07a7aSMatthew Dillon &hammer_count_dirtybufspace, 0, ""); 190a99b9ea2SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_refedbufs, CTLFLAG_RD, 191a99b9ea2SMatthew Dillon &hammer_count_refedbufs, 0, ""); 1920832c9bbSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_reservations, CTLFLAG_RD, 1930832c9bbSMatthew Dillon &hammer_count_reservations, 0, ""); 194a99b9ea2SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_io_running_read, CTLFLAG_RD, 195a99b9ea2SMatthew Dillon &hammer_count_io_running_read, 0, ""); 196a99b9ea2SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_io_locked, CTLFLAG_RD, 197a99b9ea2SMatthew Dillon &hammer_count_io_locked, 0, ""); 198a99b9ea2SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_io_running_write, CTLFLAG_RD, 199a99b9ea2SMatthew Dillon &hammer_count_io_running_write, 0, ""); 200f03c9cf4SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, zone_limit, CTLFLAG_RW, 201f03c9cf4SMatthew Dillon &hammer_zone_limit, 0, ""); 2027d683b0fSMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, contention_count, CTLFLAG_RW, 2037d683b0fSMatthew Dillon &hammer_contention_count, 0, ""); 204cb51be26SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, verify_zone, CTLFLAG_RW, 205cb51be26SMatthew Dillon &hammer_verify_zone, 0, ""); 2061b0ab2c3SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, verify_data, CTLFLAG_RW, 2071b0ab2c3SMatthew Dillon &hammer_verify_data, 0, ""); 208cb51be26SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, write_mode, CTLFLAG_RW, 209cb51be26SMatthew Dillon &hammer_write_mode, 0, ""); 210b3deaf57SMatthew Dillon 211bcac4bbbSMatthew Dillon KTR_INFO_MASTER(hammer); 212bcac4bbbSMatthew Dillon 213427e5fc6SMatthew Dillon /* 214427e5fc6SMatthew Dillon * VFS ABI 215427e5fc6SMatthew Dillon */ 216427e5fc6SMatthew Dillon static void hammer_free_hmp(struct mount *mp); 217427e5fc6SMatthew Dillon 218427e5fc6SMatthew Dillon static int hammer_vfs_mount(struct mount *mp, char *path, caddr_t data, 219427e5fc6SMatthew Dillon struct ucred *cred); 220427e5fc6SMatthew Dillon static int hammer_vfs_unmount(struct mount *mp, int mntflags); 221427e5fc6SMatthew Dillon static int hammer_vfs_root(struct mount *mp, struct vnode **vpp); 222427e5fc6SMatthew Dillon static int hammer_vfs_statfs(struct mount *mp, struct statfs *sbp, 223427e5fc6SMatthew Dillon struct ucred *cred); 2246f97fce3SMatthew Dillon static int hammer_vfs_statvfs(struct mount *mp, struct statvfs *sbp, 2256f97fce3SMatthew Dillon struct ucred *cred); 226427e5fc6SMatthew Dillon static int hammer_vfs_sync(struct mount *mp, int waitfor); 227513ca7d7SMatthew Dillon static int hammer_vfs_vget(struct mount *mp, ino_t ino, 228513ca7d7SMatthew Dillon struct vnode **vpp); 229427e5fc6SMatthew Dillon static int hammer_vfs_init(struct vfsconf *conf); 230*67863d04SMatthew Dillon static int hammer_vfs_fhtovp(struct mount *mp, struct vnode *rootvp, 231*67863d04SMatthew Dillon struct fid *fhp, struct vnode **vpp); 232513ca7d7SMatthew Dillon static int hammer_vfs_vptofh(struct vnode *vp, struct fid *fhp); 233513ca7d7SMatthew Dillon static int hammer_vfs_checkexp(struct mount *mp, struct sockaddr *nam, 234513ca7d7SMatthew Dillon int *exflagsp, struct ucred **credanonp); 235513ca7d7SMatthew Dillon 236427e5fc6SMatthew Dillon 237427e5fc6SMatthew Dillon static struct vfsops hammer_vfsops = { 238427e5fc6SMatthew Dillon .vfs_mount = hammer_vfs_mount, 239427e5fc6SMatthew Dillon .vfs_unmount = hammer_vfs_unmount, 240427e5fc6SMatthew Dillon .vfs_root = hammer_vfs_root, 241427e5fc6SMatthew Dillon .vfs_statfs = hammer_vfs_statfs, 2426f97fce3SMatthew Dillon .vfs_statvfs = hammer_vfs_statvfs, 243427e5fc6SMatthew Dillon .vfs_sync = hammer_vfs_sync, 244427e5fc6SMatthew Dillon .vfs_vget = hammer_vfs_vget, 245513ca7d7SMatthew Dillon .vfs_init = hammer_vfs_init, 246513ca7d7SMatthew Dillon .vfs_vptofh = hammer_vfs_vptofh, 247513ca7d7SMatthew Dillon .vfs_fhtovp = hammer_vfs_fhtovp, 248513ca7d7SMatthew Dillon .vfs_checkexp = hammer_vfs_checkexp 249427e5fc6SMatthew Dillon }; 250427e5fc6SMatthew Dillon 2519b45155dSMatthew Dillon MALLOC_DEFINE(M_HAMMER, "hammer-general", "hammer general"); 2529b45155dSMatthew Dillon MALLOC_DEFINE(M_HAMMER_INO, "hammer-inodes", "hammer inodes"); 253427e5fc6SMatthew Dillon 254427e5fc6SMatthew Dillon VFS_SET(hammer_vfsops, hammer, 0); 255427e5fc6SMatthew Dillon MODULE_VERSION(hammer, 1); 256427e5fc6SMatthew Dillon 257427e5fc6SMatthew Dillon static int 258427e5fc6SMatthew Dillon hammer_vfs_init(struct vfsconf *conf) 259427e5fc6SMatthew Dillon { 2603098dc2fSMatthew Dillon int n; 2613098dc2fSMatthew Dillon 2623098dc2fSMatthew Dillon if (hammer_limit_recs == 0) { 263a99b9ea2SMatthew Dillon hammer_limit_recs = nbuf * 25; 2643098dc2fSMatthew Dillon n = kmalloc_limit(M_HAMMER) / 512; 2653098dc2fSMatthew Dillon if (hammer_limit_recs > n) 2663098dc2fSMatthew Dillon hammer_limit_recs = n; 2673098dc2fSMatthew Dillon } 268f5a07a7aSMatthew Dillon if (hammer_limit_dirtybufspace == 0) { 269f5a07a7aSMatthew Dillon hammer_limit_dirtybufspace = hidirtybufspace / 2; 270f5a07a7aSMatthew Dillon if (hammer_limit_dirtybufspace < 100) 271f5a07a7aSMatthew Dillon hammer_limit_dirtybufspace = 100; 2729f5097dcSMatthew Dillon } 273af209b0fSMatthew Dillon if (hammer_limit_iqueued == 0) 274af209b0fSMatthew Dillon hammer_limit_iqueued = desiredvnodes / 5; 275427e5fc6SMatthew Dillon return(0); 276427e5fc6SMatthew Dillon } 277427e5fc6SMatthew Dillon 278427e5fc6SMatthew Dillon static int 279427e5fc6SMatthew Dillon hammer_vfs_mount(struct mount *mp, char *mntpt, caddr_t data, 280427e5fc6SMatthew Dillon struct ucred *cred) 281427e5fc6SMatthew Dillon { 282427e5fc6SMatthew Dillon struct hammer_mount_info info; 283a89aec1bSMatthew Dillon hammer_mount_t hmp; 284a89aec1bSMatthew Dillon hammer_volume_t rootvol; 28527ea2398SMatthew Dillon struct vnode *rootvp; 2867c19b529SMichael Neumann struct vnode *devvp = NULL; 287427e5fc6SMatthew Dillon const char *upath; /* volume name in userspace */ 288427e5fc6SMatthew Dillon char *path; /* volume name in system space */ 289427e5fc6SMatthew Dillon int error; 290427e5fc6SMatthew Dillon int i; 291732a1697SMatthew Dillon int master_id; 2927c19b529SMichael Neumann if (mntpt == NULL) { 2937c19b529SMichael Neumann /* 2947c19b529SMichael Neumann * Root mount 2957c19b529SMichael Neumann */ 2967c19b529SMichael Neumann if ((error = bdevvp(rootdev, &devvp))) { 2977c19b529SMichael Neumann kprintf("hammer_mountroot: can't find devvp\n"); 2987c19b529SMichael Neumann return (error); 2997c19b529SMichael Neumann } 3007c19b529SMichael Neumann mp->mnt_flag &= ~MNT_RDONLY; /* mount R/W */ 3017c19b529SMichael Neumann bzero(&info, sizeof(info)); 3027c19b529SMichael Neumann info.asof = 0; 3037c19b529SMichael Neumann info.hflags = 0; 3047c19b529SMichael Neumann info.nvolumes = 1; 3057c19b529SMichael Neumann } else { 306427e5fc6SMatthew Dillon if ((error = copyin(data, &info, sizeof(info))) != 0) 307427e5fc6SMatthew Dillon return (error); 3087c19b529SMichael Neumann } 309427e5fc6SMatthew Dillon 310427e5fc6SMatthew Dillon /* 311732a1697SMatthew Dillon * updating or new mount 312427e5fc6SMatthew Dillon */ 313195c19a1SMatthew Dillon if (mp->mnt_flag & MNT_UPDATE) { 314195c19a1SMatthew Dillon hmp = (void *)mp->mnt_data; 315195c19a1SMatthew Dillon KKASSERT(hmp != NULL); 316195c19a1SMatthew Dillon } else { 317732a1697SMatthew Dillon if (info.nvolumes <= 0 || info.nvolumes >= 32768) 318732a1697SMatthew Dillon return (EINVAL); 319732a1697SMatthew Dillon hmp = NULL; 320732a1697SMatthew Dillon } 321732a1697SMatthew Dillon 322732a1697SMatthew Dillon /* 323732a1697SMatthew Dillon * master-id validation. The master id may not be changed by a 324732a1697SMatthew Dillon * mount update. 325732a1697SMatthew Dillon */ 326732a1697SMatthew Dillon if (info.hflags & HMNT_MASTERID) { 327732a1697SMatthew Dillon if (hmp && hmp->master_id != info.master_id) { 328732a1697SMatthew Dillon kprintf("hammer: cannot change master id " 329732a1697SMatthew Dillon "with mount update\n"); 330732a1697SMatthew Dillon return(EINVAL); 331732a1697SMatthew Dillon } 332732a1697SMatthew Dillon master_id = info.master_id; 333732a1697SMatthew Dillon if (master_id < -1 || master_id >= HAMMER_MAX_MASTERS) 334732a1697SMatthew Dillon return (EINVAL); 335732a1697SMatthew Dillon } else { 336732a1697SMatthew Dillon if (hmp) 337732a1697SMatthew Dillon master_id = hmp->master_id; 338732a1697SMatthew Dillon else 339732a1697SMatthew Dillon master_id = 0; 340732a1697SMatthew Dillon } 341732a1697SMatthew Dillon 342732a1697SMatthew Dillon /* 343732a1697SMatthew Dillon * Interal mount data structure 344732a1697SMatthew Dillon */ 345732a1697SMatthew Dillon if (hmp == NULL) { 346427e5fc6SMatthew Dillon hmp = kmalloc(sizeof(*hmp), M_HAMMER, M_WAITOK | M_ZERO); 347427e5fc6SMatthew Dillon mp->mnt_data = (qaddr_t)hmp; 348427e5fc6SMatthew Dillon hmp->mp = mp; 349195c19a1SMatthew Dillon hmp->namekey_iterator = mycpu->gd_time_seconds; 35046fe7ae1SMatthew Dillon /*TAILQ_INIT(&hmp->recycle_list);*/ 35147197d71SMatthew Dillon 352dd94f1b1SMatthew Dillon hmp->root_btree_beg.localization = 0x00000000U; 35347197d71SMatthew Dillon hmp->root_btree_beg.obj_id = -0x8000000000000000LL; 35447197d71SMatthew Dillon hmp->root_btree_beg.key = -0x8000000000000000LL; 35547197d71SMatthew Dillon hmp->root_btree_beg.create_tid = 1; 35647197d71SMatthew Dillon hmp->root_btree_beg.delete_tid = 1; 35747197d71SMatthew Dillon hmp->root_btree_beg.rec_type = 0; 35847197d71SMatthew Dillon hmp->root_btree_beg.obj_type = 0; 35947197d71SMatthew Dillon 360dd94f1b1SMatthew Dillon hmp->root_btree_end.localization = 0xFFFFFFFFU; 36147197d71SMatthew Dillon hmp->root_btree_end.obj_id = 0x7FFFFFFFFFFFFFFFLL; 36247197d71SMatthew Dillon hmp->root_btree_end.key = 0x7FFFFFFFFFFFFFFFLL; 36347197d71SMatthew Dillon hmp->root_btree_end.create_tid = 0xFFFFFFFFFFFFFFFFULL; 36447197d71SMatthew Dillon hmp->root_btree_end.delete_tid = 0; /* special case */ 36547197d71SMatthew Dillon hmp->root_btree_end.rec_type = 0xFFFFU; 36647197d71SMatthew Dillon hmp->root_btree_end.obj_type = 0; 367f03c9cf4SMatthew Dillon 368cdb6e4e6SMatthew Dillon hmp->krate.freq = 1; /* maximum reporting rate (hz) */ 369cdb6e4e6SMatthew Dillon hmp->krate.count = -16; /* initial burst */ 370cdb6e4e6SMatthew Dillon 3719480ff55SMatthew Dillon hmp->sync_lock.refs = 1; 372c9b9e29dSMatthew Dillon hmp->free_lock.refs = 1; 373d99d6bf5SMatthew Dillon hmp->undo_lock.refs = 1; 374d99d6bf5SMatthew Dillon hmp->blkmap_lock.refs = 1; 3759480ff55SMatthew Dillon 376cebe9493SMatthew Dillon TAILQ_INIT(&hmp->delay_list); 3777a61b85dSMatthew Dillon TAILQ_INIT(&hmp->flush_group_list); 3780729c8c8SMatthew Dillon TAILQ_INIT(&hmp->objid_cache_list); 379e8599db1SMatthew Dillon TAILQ_INIT(&hmp->undo_lru_list); 3807bc5b8c2SMatthew Dillon TAILQ_INIT(&hmp->reclaim_list); 381195c19a1SMatthew Dillon } 38251c35492SMatthew Dillon hmp->hflags &= ~HMNT_USERFLAGS; 38351c35492SMatthew Dillon hmp->hflags |= info.hflags & HMNT_USERFLAGS; 384732a1697SMatthew Dillon 385732a1697SMatthew Dillon hmp->master_id = master_id; 386732a1697SMatthew Dillon 3877f7c1f84SMatthew Dillon if (info.asof) { 3887f7c1f84SMatthew Dillon mp->mnt_flag |= MNT_RDONLY; 3897f7c1f84SMatthew Dillon hmp->asof = info.asof; 3907f7c1f84SMatthew Dillon } else { 3917f7c1f84SMatthew Dillon hmp->asof = HAMMER_MAX_TID; 3927f7c1f84SMatthew Dillon } 393195c19a1SMatthew Dillon 394195c19a1SMatthew Dillon /* 39551c35492SMatthew Dillon * Re-open read-write if originally read-only, or vise-versa. 396195c19a1SMatthew Dillon */ 397195c19a1SMatthew Dillon if (mp->mnt_flag & MNT_UPDATE) { 39851c35492SMatthew Dillon error = 0; 39951c35492SMatthew Dillon if (hmp->ronly && (mp->mnt_kern_flag & MNTK_WANTRDWR)) { 40051c35492SMatthew Dillon kprintf("HAMMER read-only -> read-write\n"); 401195c19a1SMatthew Dillon hmp->ronly = 0; 40251c35492SMatthew Dillon RB_SCAN(hammer_vol_rb_tree, &hmp->rb_vols_root, NULL, 40351c35492SMatthew Dillon hammer_adjust_volume_mode, NULL); 40451c35492SMatthew Dillon rootvol = hammer_get_root_volume(hmp, &error); 40551c35492SMatthew Dillon if (rootvol) { 40606ad81ffSMatthew Dillon hammer_recover_flush_buffers(hmp, rootvol, 1); 4079f5097dcSMatthew Dillon bcopy(rootvol->ondisk->vol0_blockmap, 4089f5097dcSMatthew Dillon hmp->blockmap, 4099f5097dcSMatthew Dillon sizeof(hmp->blockmap)); 41051c35492SMatthew Dillon hammer_rel_volume(rootvol, 0); 411195c19a1SMatthew Dillon } 41251c35492SMatthew Dillon RB_SCAN(hammer_ino_rb_tree, &hmp->rb_inos_root, NULL, 41351c35492SMatthew Dillon hammer_reload_inode, NULL); 41451c35492SMatthew Dillon /* kernel clears MNT_RDONLY */ 41551c35492SMatthew Dillon } else if (hmp->ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) { 41651c35492SMatthew Dillon kprintf("HAMMER read-write -> read-only\n"); 41751c35492SMatthew Dillon hmp->ronly = 1; /* messy */ 41851c35492SMatthew Dillon RB_SCAN(hammer_ino_rb_tree, &hmp->rb_inos_root, NULL, 41951c35492SMatthew Dillon hammer_reload_inode, NULL); 42051c35492SMatthew Dillon hmp->ronly = 0; 42151c35492SMatthew Dillon hammer_flusher_sync(hmp); 42251c35492SMatthew Dillon hammer_flusher_sync(hmp); 42351c35492SMatthew Dillon hammer_flusher_sync(hmp); 42451c35492SMatthew Dillon hmp->ronly = 1; 42551c35492SMatthew Dillon RB_SCAN(hammer_vol_rb_tree, &hmp->rb_vols_root, NULL, 42651c35492SMatthew Dillon hammer_adjust_volume_mode, NULL); 42751c35492SMatthew Dillon } 42851c35492SMatthew Dillon return(error); 429195c19a1SMatthew Dillon } 430195c19a1SMatthew Dillon 431427e5fc6SMatthew Dillon RB_INIT(&hmp->rb_vols_root); 432427e5fc6SMatthew Dillon RB_INIT(&hmp->rb_inos_root); 43340043e7fSMatthew Dillon RB_INIT(&hmp->rb_nods_root); 434e8599db1SMatthew Dillon RB_INIT(&hmp->rb_undo_root); 4350832c9bbSMatthew Dillon RB_INIT(&hmp->rb_resv_root); 4360832c9bbSMatthew Dillon RB_INIT(&hmp->rb_bufs_root); 4375fa5c92fSMatthew Dillon RB_INIT(&hmp->rb_pfsm_root); 4380832c9bbSMatthew Dillon 439195c19a1SMatthew Dillon hmp->ronly = ((mp->mnt_flag & MNT_RDONLY) != 0); 440427e5fc6SMatthew Dillon 44110a5d1baSMatthew Dillon TAILQ_INIT(&hmp->volu_list); 44210a5d1baSMatthew Dillon TAILQ_INIT(&hmp->undo_list); 44310a5d1baSMatthew Dillon TAILQ_INIT(&hmp->data_list); 44410a5d1baSMatthew Dillon TAILQ_INIT(&hmp->meta_list); 44510a5d1baSMatthew Dillon TAILQ_INIT(&hmp->lose_list); 44610a5d1baSMatthew Dillon 447427e5fc6SMatthew Dillon /* 448427e5fc6SMatthew Dillon * Load volumes 449427e5fc6SMatthew Dillon */ 450427e5fc6SMatthew Dillon path = objcache_get(namei_oc, M_WAITOK); 4511b0ab2c3SMatthew Dillon hmp->nvolumes = -1; 452427e5fc6SMatthew Dillon for (i = 0; i < info.nvolumes; ++i) { 4537c19b529SMichael Neumann if (mntpt == NULL) { 4547c19b529SMichael Neumann /* 4557c19b529SMichael Neumann * Root mount. 4567c19b529SMichael Neumann * Only one volume; and no need for copyin. 4577c19b529SMichael Neumann */ 4587c19b529SMichael Neumann KKASSERT(info.nvolumes == 1); 4597c19b529SMichael Neumann ksnprintf(path, MAXPATHLEN, "/dev/%s", 4607c19b529SMichael Neumann mp->mnt_stat.f_mntfromname); 4617c19b529SMichael Neumann error = 0; 4627c19b529SMichael Neumann } else { 4637c19b529SMichael Neumann error = copyin(&info.volumes[i], &upath, 4647c19b529SMichael Neumann sizeof(char *)); 465427e5fc6SMatthew Dillon if (error == 0) 4667c19b529SMichael Neumann error = copyinstr(upath, path, 4677c19b529SMichael Neumann MAXPATHLEN, NULL); 4687c19b529SMichael Neumann } 469427e5fc6SMatthew Dillon if (error == 0) 4707c19b529SMichael Neumann error = hammer_install_volume(hmp, path, devvp); 471427e5fc6SMatthew Dillon if (error) 472427e5fc6SMatthew Dillon break; 473427e5fc6SMatthew Dillon } 474427e5fc6SMatthew Dillon objcache_put(namei_oc, path); 475427e5fc6SMatthew Dillon 476427e5fc6SMatthew Dillon /* 477427e5fc6SMatthew Dillon * Make sure we found a root volume 478427e5fc6SMatthew Dillon */ 479427e5fc6SMatthew Dillon if (error == 0 && hmp->rootvol == NULL) { 480427e5fc6SMatthew Dillon kprintf("hammer_mount: No root volume found!\n"); 481427e5fc6SMatthew Dillon error = EINVAL; 482427e5fc6SMatthew Dillon } 4831b0ab2c3SMatthew Dillon 4841b0ab2c3SMatthew Dillon /* 4851b0ab2c3SMatthew Dillon * Check that all required volumes are available 4861b0ab2c3SMatthew Dillon */ 4871b0ab2c3SMatthew Dillon if (error == 0 && hammer_mountcheck_volumes(hmp)) { 4881b0ab2c3SMatthew Dillon kprintf("hammer_mount: Missing volumes, cannot mount!\n"); 4891b0ab2c3SMatthew Dillon error = EINVAL; 4901b0ab2c3SMatthew Dillon } 4911b0ab2c3SMatthew Dillon 492427e5fc6SMatthew Dillon if (error) { 493427e5fc6SMatthew Dillon hammer_free_hmp(mp); 494427e5fc6SMatthew Dillon return (error); 495427e5fc6SMatthew Dillon } 496427e5fc6SMatthew Dillon 497427e5fc6SMatthew Dillon /* 49827ea2398SMatthew Dillon * No errors, setup enough of the mount point so we can lookup the 49927ea2398SMatthew Dillon * root vnode. 500427e5fc6SMatthew Dillon */ 501427e5fc6SMatthew Dillon mp->mnt_iosize_max = MAXPHYS; 502427e5fc6SMatthew Dillon mp->mnt_kern_flag |= MNTK_FSMID; 503c0ade690SMatthew Dillon 504c0ade690SMatthew Dillon /* 505c0ade690SMatthew Dillon * note: f_iosize is used by vnode_pager_haspage() when constructing 506c0ade690SMatthew Dillon * its VOP_BMAP call. 507c0ade690SMatthew Dillon */ 508c0ade690SMatthew Dillon mp->mnt_stat.f_iosize = HAMMER_BUFSIZE; 509fbc6e32aSMatthew Dillon mp->mnt_stat.f_bsize = HAMMER_BUFSIZE; 5106f97fce3SMatthew Dillon 5116f97fce3SMatthew Dillon mp->mnt_vstat.f_frsize = HAMMER_BUFSIZE; 5126f97fce3SMatthew Dillon mp->mnt_vstat.f_bsize = HAMMER_BUFSIZE; 5136f97fce3SMatthew Dillon 514427e5fc6SMatthew Dillon mp->mnt_maxsymlinklen = 255; 515427e5fc6SMatthew Dillon mp->mnt_flag |= MNT_LOCAL; 516427e5fc6SMatthew Dillon 517427e5fc6SMatthew Dillon vfs_add_vnodeops(mp, &hammer_vnode_vops, &mp->mnt_vn_norm_ops); 5187a04d74fSMatthew Dillon vfs_add_vnodeops(mp, &hammer_spec_vops, &mp->mnt_vn_spec_ops); 5197a04d74fSMatthew Dillon vfs_add_vnodeops(mp, &hammer_fifo_vops, &mp->mnt_vn_fifo_ops); 52027ea2398SMatthew Dillon 52127ea2398SMatthew Dillon /* 522a89aec1bSMatthew Dillon * The root volume's ondisk pointer is only valid if we hold a 523a89aec1bSMatthew Dillon * reference to it. 524a89aec1bSMatthew Dillon */ 525a89aec1bSMatthew Dillon rootvol = hammer_get_root_volume(hmp, &error); 526a89aec1bSMatthew Dillon if (error) 527f90dde4cSMatthew Dillon goto failed; 528f90dde4cSMatthew Dillon 529f90dde4cSMatthew Dillon /* 5309f5097dcSMatthew Dillon * Perform any necessary UNDO operations. The recovery code does 5310729c8c8SMatthew Dillon * call hammer_undo_lookup() so we have to pre-cache the blockmap, 5320729c8c8SMatthew Dillon * and then re-copy it again after recovery is complete. 533c9b9e29dSMatthew Dillon * 53451c35492SMatthew Dillon * If this is a read-only mount the UNDO information is retained 53551c35492SMatthew Dillon * in memory in the form of dirty buffer cache buffers, and not 53651c35492SMatthew Dillon * written back to the media. 537f90dde4cSMatthew Dillon */ 5380729c8c8SMatthew Dillon bcopy(rootvol->ondisk->vol0_blockmap, hmp->blockmap, 5390729c8c8SMatthew Dillon sizeof(hmp->blockmap)); 540c9b9e29dSMatthew Dillon 5417a61b85dSMatthew Dillon /* 5427a61b85dSMatthew Dillon * The undo_rec_limit limits the size of flush groups to avoid 5437a61b85dSMatthew Dillon * blowing out the UNDO FIFO. This calculation is typically in 5447a61b85dSMatthew Dillon * the tens of thousands and is designed primarily when small 5457a61b85dSMatthew Dillon * HAMMER filesystems are created. 5467a61b85dSMatthew Dillon */ 5477a61b85dSMatthew Dillon hmp->undo_rec_limit = hammer_undo_max(hmp) / 8192 + 100; 5487a61b85dSMatthew Dillon if (hammer_debug_general & 0x0001) 5497a61b85dSMatthew Dillon kprintf("HAMMER: undo_rec_limit %d\n", hmp->undo_rec_limit); 5507a61b85dSMatthew Dillon 551f90dde4cSMatthew Dillon error = hammer_recover(hmp, rootvol); 552f90dde4cSMatthew Dillon if (error) { 553f90dde4cSMatthew Dillon kprintf("Failed to recover HAMMER filesystem on mount\n"); 554a89aec1bSMatthew Dillon goto done; 555f90dde4cSMatthew Dillon } 556f90dde4cSMatthew Dillon 557f90dde4cSMatthew Dillon /* 558adf01747SMatthew Dillon * Finish setup now that we have a good root volume. 559adf01747SMatthew Dillon * 560adf01747SMatthew Dillon * The top 16 bits of fsid.val[1] is a pfs id. 561f90dde4cSMatthew Dillon */ 562a89aec1bSMatthew Dillon ksnprintf(mp->mnt_stat.f_mntfromname, 563a89aec1bSMatthew Dillon sizeof(mp->mnt_stat.f_mntfromname), "%s", 564a89aec1bSMatthew Dillon rootvol->ondisk->vol_name); 565513ca7d7SMatthew Dillon mp->mnt_stat.f_fsid.val[0] = 566513ca7d7SMatthew Dillon crc32((char *)&rootvol->ondisk->vol_fsid + 0, 8); 567513ca7d7SMatthew Dillon mp->mnt_stat.f_fsid.val[1] = 568513ca7d7SMatthew Dillon crc32((char *)&rootvol->ondisk->vol_fsid + 8, 8); 569adf01747SMatthew Dillon mp->mnt_stat.f_fsid.val[1] &= 0x0000FFFF; 570b84de5afSMatthew Dillon 5716f97fce3SMatthew Dillon mp->mnt_vstat.f_fsid_uuid = rootvol->ondisk->vol_fsid; 5726f97fce3SMatthew Dillon mp->mnt_vstat.f_fsid = crc32(&mp->mnt_vstat.f_fsid_uuid, 5736f97fce3SMatthew Dillon sizeof(mp->mnt_vstat.f_fsid_uuid)); 5746f97fce3SMatthew Dillon 5750729c8c8SMatthew Dillon /* 5760729c8c8SMatthew Dillon * Certain often-modified fields in the root volume are cached in 5770729c8c8SMatthew Dillon * the hammer_mount structure so we do not have to generate lots 5780729c8c8SMatthew Dillon * of little UNDO structures for them. 579c9b9e29dSMatthew Dillon * 5809f5097dcSMatthew Dillon * Recopy after recovery. This also has the side effect of 5819f5097dcSMatthew Dillon * setting our cached undo FIFO's first_offset, which serves to 5829f5097dcSMatthew Dillon * placemark the FIFO start for the NEXT flush cycle while the 5839f5097dcSMatthew Dillon * on-disk first_offset represents the LAST flush cycle. 5840729c8c8SMatthew Dillon */ 585b84de5afSMatthew Dillon hmp->next_tid = rootvol->ondisk->vol0_next_tid; 5864889cbd4SMatthew Dillon hmp->flush_tid1 = hmp->next_tid; 5874889cbd4SMatthew Dillon hmp->flush_tid2 = hmp->next_tid; 5880729c8c8SMatthew Dillon bcopy(rootvol->ondisk->vol0_blockmap, hmp->blockmap, 5890729c8c8SMatthew Dillon sizeof(hmp->blockmap)); 590e63644f0SMatthew Dillon hmp->copy_stat_freebigblocks = rootvol->ondisk->vol0_stat_freebigblocks; 5910729c8c8SMatthew Dillon 592059819e3SMatthew Dillon hammer_flusher_create(hmp); 593059819e3SMatthew Dillon 594a89aec1bSMatthew Dillon /* 59527ea2398SMatthew Dillon * Locate the root directory using the root cluster's B-Tree as a 59627ea2398SMatthew Dillon * starting point. The root directory uses an obj_id of 1. 59727ea2398SMatthew Dillon * 59827ea2398SMatthew Dillon * FUTURE: Leave the root directory cached referenced but unlocked 59927ea2398SMatthew Dillon * in hmp->rootvp (need to flush it on unmount). 60027ea2398SMatthew Dillon */ 60127ea2398SMatthew Dillon error = hammer_vfs_vget(mp, 1, &rootvp); 602a89aec1bSMatthew Dillon if (error) 603a89aec1bSMatthew Dillon goto done; 60427ea2398SMatthew Dillon vput(rootvp); 60527ea2398SMatthew Dillon /*vn_unlock(hmp->rootvp);*/ 60627ea2398SMatthew Dillon 607a89aec1bSMatthew Dillon done: 608f90dde4cSMatthew Dillon hammer_rel_volume(rootvol, 0); 609f90dde4cSMatthew Dillon failed: 61027ea2398SMatthew Dillon /* 61127ea2398SMatthew Dillon * Cleanup and return. 61227ea2398SMatthew Dillon */ 61327ea2398SMatthew Dillon if (error) 61427ea2398SMatthew Dillon hammer_free_hmp(mp); 615427e5fc6SMatthew Dillon return (error); 616427e5fc6SMatthew Dillon } 617427e5fc6SMatthew Dillon 618427e5fc6SMatthew Dillon static int 619427e5fc6SMatthew Dillon hammer_vfs_unmount(struct mount *mp, int mntflags) 620427e5fc6SMatthew Dillon { 621427e5fc6SMatthew Dillon #if 0 622427e5fc6SMatthew Dillon struct hammer_mount *hmp = (void *)mp->mnt_data; 623427e5fc6SMatthew Dillon #endif 624427e5fc6SMatthew Dillon int flags; 62566325755SMatthew Dillon int error; 62627ea2398SMatthew Dillon 62727ea2398SMatthew Dillon /* 628427e5fc6SMatthew Dillon * Clean out the vnodes 629427e5fc6SMatthew Dillon */ 63066325755SMatthew Dillon flags = 0; 63166325755SMatthew Dillon if (mntflags & MNT_FORCE) 63266325755SMatthew Dillon flags |= FORCECLOSE; 63366325755SMatthew Dillon if ((error = vflush(mp, 0, flags)) != 0) 63466325755SMatthew Dillon return (error); 635427e5fc6SMatthew Dillon 636427e5fc6SMatthew Dillon /* 637427e5fc6SMatthew Dillon * Clean up the internal mount structure and related entities. This 638427e5fc6SMatthew Dillon * may issue I/O. 639427e5fc6SMatthew Dillon */ 640427e5fc6SMatthew Dillon hammer_free_hmp(mp); 641427e5fc6SMatthew Dillon return(0); 642427e5fc6SMatthew Dillon } 643427e5fc6SMatthew Dillon 644427e5fc6SMatthew Dillon /* 645427e5fc6SMatthew Dillon * Clean up the internal mount structure and disassociate it from the mount. 646427e5fc6SMatthew Dillon * This may issue I/O. 647427e5fc6SMatthew Dillon */ 648427e5fc6SMatthew Dillon static void 649427e5fc6SMatthew Dillon hammer_free_hmp(struct mount *mp) 650427e5fc6SMatthew Dillon { 651427e5fc6SMatthew Dillon struct hammer_mount *hmp = (void *)mp->mnt_data; 652cdb6e4e6SMatthew Dillon hammer_flush_group_t flg; 6531b0ab2c3SMatthew Dillon int count; 654427e5fc6SMatthew Dillon 655427e5fc6SMatthew Dillon /* 656cdb6e4e6SMatthew Dillon * Flush anything dirty. This won't even run if the 657cdb6e4e6SMatthew Dillon * filesystem errored-out. 658427e5fc6SMatthew Dillon */ 6591b0ab2c3SMatthew Dillon count = 0; 6601b0ab2c3SMatthew Dillon while (hammer_flusher_haswork(hmp)) { 661059819e3SMatthew Dillon hammer_flusher_sync(hmp); 6621b0ab2c3SMatthew Dillon ++count; 6631b0ab2c3SMatthew Dillon if (count >= 5) { 6641b0ab2c3SMatthew Dillon if (count == 5) 6651b0ab2c3SMatthew Dillon kprintf("HAMMER: umount flushing."); 6661b0ab2c3SMatthew Dillon else 6671b0ab2c3SMatthew Dillon kprintf("."); 6681b0ab2c3SMatthew Dillon tsleep(hmp, 0, "hmrufl", hz); 6691b0ab2c3SMatthew Dillon } 6701b0ab2c3SMatthew Dillon if (count == 30) { 6711b0ab2c3SMatthew Dillon kprintf("giving up\n"); 6721b0ab2c3SMatthew Dillon break; 6731b0ab2c3SMatthew Dillon } 6741b0ab2c3SMatthew Dillon } 6751b0ab2c3SMatthew Dillon if (count >= 5 && count < 30) 6761b0ab2c3SMatthew Dillon kprintf("\n"); 677cdb6e4e6SMatthew Dillon 678cdb6e4e6SMatthew Dillon /* 679cdb6e4e6SMatthew Dillon * If the mount had a critical error we have to destroy any 680cdb6e4e6SMatthew Dillon * remaining inodes before we can finish cleaning up the flusher. 681cdb6e4e6SMatthew Dillon */ 682cdb6e4e6SMatthew Dillon if (hmp->flags & HAMMER_MOUNT_CRITICAL_ERROR) { 683cdb6e4e6SMatthew Dillon RB_SCAN(hammer_ino_rb_tree, &hmp->rb_inos_root, NULL, 684cdb6e4e6SMatthew Dillon hammer_destroy_inode_callback, NULL); 685cdb6e4e6SMatthew Dillon } 686cdb6e4e6SMatthew Dillon 687cdb6e4e6SMatthew Dillon /* 688cdb6e4e6SMatthew Dillon * There shouldn't be any inodes left now and any left over 689cdb6e4e6SMatthew Dillon * flush groups should now be empty. 690cdb6e4e6SMatthew Dillon */ 691cdb6e4e6SMatthew Dillon KKASSERT(RB_EMPTY(&hmp->rb_inos_root)); 692cdb6e4e6SMatthew Dillon while ((flg = TAILQ_FIRST(&hmp->flush_group_list)) != NULL) { 693cdb6e4e6SMatthew Dillon TAILQ_REMOVE(&hmp->flush_group_list, flg, flush_entry); 694cdb6e4e6SMatthew Dillon KKASSERT(TAILQ_EMPTY(&flg->flush_list)); 695cdb6e4e6SMatthew Dillon if (flg->refs) { 696cdb6e4e6SMatthew Dillon kprintf("HAMMER: Warning, flush_group %p was " 697cdb6e4e6SMatthew Dillon "not empty on umount!\n", flg); 698cdb6e4e6SMatthew Dillon } 699cdb6e4e6SMatthew Dillon kfree(flg, M_HAMMER); 700cdb6e4e6SMatthew Dillon } 701cdb6e4e6SMatthew Dillon 702cdb6e4e6SMatthew Dillon /* 703cdb6e4e6SMatthew Dillon * We can finally destroy the flusher 704cdb6e4e6SMatthew Dillon */ 705059819e3SMatthew Dillon hammer_flusher_destroy(hmp); 706427e5fc6SMatthew Dillon 707b84de5afSMatthew Dillon /* 70800f16fadSMatthew Dillon * We may have held recovered buffers due to a read-only mount. 70900f16fadSMatthew Dillon * These must be discarded. 71000f16fadSMatthew Dillon */ 71100f16fadSMatthew Dillon if (hmp->ronly) 71200f16fadSMatthew Dillon hammer_recover_flush_buffers(hmp, NULL, -1); 71300f16fadSMatthew Dillon 71400f16fadSMatthew Dillon /* 7150832c9bbSMatthew Dillon * Unload buffers and then volumes 716b84de5afSMatthew Dillon */ 7170832c9bbSMatthew Dillon RB_SCAN(hammer_buf_rb_tree, &hmp->rb_bufs_root, NULL, 7180832c9bbSMatthew Dillon hammer_unload_buffer, NULL); 719427e5fc6SMatthew Dillon RB_SCAN(hammer_vol_rb_tree, &hmp->rb_vols_root, NULL, 720427e5fc6SMatthew Dillon hammer_unload_volume, NULL); 721427e5fc6SMatthew Dillon 722427e5fc6SMatthew Dillon mp->mnt_data = NULL; 72366325755SMatthew Dillon mp->mnt_flag &= ~MNT_LOCAL; 724427e5fc6SMatthew Dillon hmp->mp = NULL; 7250729c8c8SMatthew Dillon hammer_destroy_objid_cache(hmp); 726427e5fc6SMatthew Dillon kfree(hmp, M_HAMMER); 727427e5fc6SMatthew Dillon } 728427e5fc6SMatthew Dillon 729427e5fc6SMatthew Dillon /* 730cdb6e4e6SMatthew Dillon * Report critical errors. ip may be NULL. 731cdb6e4e6SMatthew Dillon */ 732cdb6e4e6SMatthew Dillon void 733cdb6e4e6SMatthew Dillon hammer_critical_error(hammer_mount_t hmp, hammer_inode_t ip, 734cdb6e4e6SMatthew Dillon int error, const char *msg) 735cdb6e4e6SMatthew Dillon { 736cdb6e4e6SMatthew Dillon hmp->flags |= HAMMER_MOUNT_CRITICAL_ERROR; 737cdb6e4e6SMatthew Dillon krateprintf(&hmp->krate, 738cdb6e4e6SMatthew Dillon "HAMMER(%s): Critical error inode=%lld %s\n", 739cdb6e4e6SMatthew Dillon hmp->mp->mnt_stat.f_mntfromname, 740cdb6e4e6SMatthew Dillon (ip ? ip->obj_id : -1), msg); 741cdb6e4e6SMatthew Dillon if (hmp->ronly == 0) { 742cdb6e4e6SMatthew Dillon hmp->ronly = 2; /* special errored read-only mode */ 743cdb6e4e6SMatthew Dillon hmp->mp->mnt_flag |= MNT_RDONLY; 744cdb6e4e6SMatthew Dillon kprintf("HAMMER(%s): Forcing read-only mode\n", 745cdb6e4e6SMatthew Dillon hmp->mp->mnt_stat.f_mntfromname); 746cdb6e4e6SMatthew Dillon } 747cdb6e4e6SMatthew Dillon hmp->error = error; 748cdb6e4e6SMatthew Dillon } 749cdb6e4e6SMatthew Dillon 750cdb6e4e6SMatthew Dillon 751cdb6e4e6SMatthew Dillon /* 752513ca7d7SMatthew Dillon * Obtain a vnode for the specified inode number. An exclusively locked 753513ca7d7SMatthew Dillon * vnode is returned. 754513ca7d7SMatthew Dillon */ 755513ca7d7SMatthew Dillon int 756513ca7d7SMatthew Dillon hammer_vfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp) 757513ca7d7SMatthew Dillon { 75836f82b23SMatthew Dillon struct hammer_transaction trans; 759513ca7d7SMatthew Dillon struct hammer_mount *hmp = (void *)mp->mnt_data; 760513ca7d7SMatthew Dillon struct hammer_inode *ip; 761513ca7d7SMatthew Dillon int error; 762513ca7d7SMatthew Dillon 76336f82b23SMatthew Dillon hammer_simple_transaction(&trans, hmp); 76436f82b23SMatthew Dillon 765513ca7d7SMatthew Dillon /* 76636f82b23SMatthew Dillon * Lookup the requested HAMMER inode. The structure must be 76736f82b23SMatthew Dillon * left unlocked while we manipulate the related vnode to avoid 76836f82b23SMatthew Dillon * a deadlock. 769513ca7d7SMatthew Dillon */ 770ddfdf542SMatthew Dillon ip = hammer_get_inode(&trans, NULL, ino, 771ddfdf542SMatthew Dillon hmp->asof, HAMMER_DEF_LOCALIZATION, 772ddfdf542SMatthew Dillon 0, &error); 773513ca7d7SMatthew Dillon if (ip == NULL) { 774513ca7d7SMatthew Dillon *vpp = NULL; 77500f16fadSMatthew Dillon hammer_done_transaction(&trans); 776513ca7d7SMatthew Dillon return(error); 777513ca7d7SMatthew Dillon } 778e8599db1SMatthew Dillon error = hammer_get_vnode(ip, vpp); 779513ca7d7SMatthew Dillon hammer_rel_inode(ip, 0); 780b84de5afSMatthew Dillon hammer_done_transaction(&trans); 781513ca7d7SMatthew Dillon return (error); 782513ca7d7SMatthew Dillon } 783513ca7d7SMatthew Dillon 784513ca7d7SMatthew Dillon /* 785427e5fc6SMatthew Dillon * Return the root vnode for the filesystem. 786427e5fc6SMatthew Dillon * 787427e5fc6SMatthew Dillon * HAMMER stores the root vnode in the hammer_mount structure so 788427e5fc6SMatthew Dillon * getting it is easy. 789427e5fc6SMatthew Dillon */ 790427e5fc6SMatthew Dillon static int 791427e5fc6SMatthew Dillon hammer_vfs_root(struct mount *mp, struct vnode **vpp) 792427e5fc6SMatthew Dillon { 79347197d71SMatthew Dillon #if 0 794427e5fc6SMatthew Dillon struct hammer_mount *hmp = (void *)mp->mnt_data; 79547197d71SMatthew Dillon #endif 79627ea2398SMatthew Dillon int error; 797427e5fc6SMatthew Dillon 79827ea2398SMatthew Dillon error = hammer_vfs_vget(mp, 1, vpp); 79927ea2398SMatthew Dillon return (error); 800427e5fc6SMatthew Dillon } 801427e5fc6SMatthew Dillon 802427e5fc6SMatthew Dillon static int 803427e5fc6SMatthew Dillon hammer_vfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred) 804427e5fc6SMatthew Dillon { 805fbc6e32aSMatthew Dillon struct hammer_mount *hmp = (void *)mp->mnt_data; 806fbc6e32aSMatthew Dillon hammer_volume_t volume; 807fbc6e32aSMatthew Dillon hammer_volume_ondisk_t ondisk; 808fbc6e32aSMatthew Dillon int error; 80947197d71SMatthew Dillon int64_t bfree; 810fbc6e32aSMatthew Dillon 811fbc6e32aSMatthew Dillon volume = hammer_get_root_volume(hmp, &error); 812fbc6e32aSMatthew Dillon if (error) 813fbc6e32aSMatthew Dillon return(error); 814fbc6e32aSMatthew Dillon ondisk = volume->ondisk; 815fbc6e32aSMatthew Dillon 81647197d71SMatthew Dillon /* 81747197d71SMatthew Dillon * Basic stats 81847197d71SMatthew Dillon */ 819fbc6e32aSMatthew Dillon mp->mnt_stat.f_files = ondisk->vol0_stat_inodes; 820c3be93f2SMatthew Dillon bfree = ondisk->vol0_stat_freebigblocks * HAMMER_LARGEBLOCK_SIZE; 82140043e7fSMatthew Dillon hammer_rel_volume(volume, 0); 82247197d71SMatthew Dillon 82347197d71SMatthew Dillon mp->mnt_stat.f_bfree = bfree / HAMMER_BUFSIZE; 82447197d71SMatthew Dillon mp->mnt_stat.f_bavail = mp->mnt_stat.f_bfree; 825fbc6e32aSMatthew Dillon if (mp->mnt_stat.f_files < 0) 826fbc6e32aSMatthew Dillon mp->mnt_stat.f_files = 0; 827fbc6e32aSMatthew Dillon 82827ea2398SMatthew Dillon *sbp = mp->mnt_stat; 82927ea2398SMatthew Dillon return(0); 830427e5fc6SMatthew Dillon } 831427e5fc6SMatthew Dillon 8326f97fce3SMatthew Dillon static int 8336f97fce3SMatthew Dillon hammer_vfs_statvfs(struct mount *mp, struct statvfs *sbp, struct ucred *cred) 8346f97fce3SMatthew Dillon { 8356f97fce3SMatthew Dillon struct hammer_mount *hmp = (void *)mp->mnt_data; 8366f97fce3SMatthew Dillon hammer_volume_t volume; 8376f97fce3SMatthew Dillon hammer_volume_ondisk_t ondisk; 8386f97fce3SMatthew Dillon int error; 8396f97fce3SMatthew Dillon int64_t bfree; 8406f97fce3SMatthew Dillon 8416f97fce3SMatthew Dillon volume = hammer_get_root_volume(hmp, &error); 8426f97fce3SMatthew Dillon if (error) 8436f97fce3SMatthew Dillon return(error); 8446f97fce3SMatthew Dillon ondisk = volume->ondisk; 8456f97fce3SMatthew Dillon 8466f97fce3SMatthew Dillon /* 8476f97fce3SMatthew Dillon * Basic stats 8486f97fce3SMatthew Dillon */ 8496f97fce3SMatthew Dillon mp->mnt_vstat.f_files = ondisk->vol0_stat_inodes; 8506f97fce3SMatthew Dillon bfree = ondisk->vol0_stat_freebigblocks * HAMMER_LARGEBLOCK_SIZE; 8516f97fce3SMatthew Dillon hammer_rel_volume(volume, 0); 8526f97fce3SMatthew Dillon 8536f97fce3SMatthew Dillon mp->mnt_vstat.f_bfree = bfree / HAMMER_BUFSIZE; 8546f97fce3SMatthew Dillon mp->mnt_vstat.f_bavail = mp->mnt_stat.f_bfree; 8556f97fce3SMatthew Dillon if (mp->mnt_vstat.f_files < 0) 8566f97fce3SMatthew Dillon mp->mnt_vstat.f_files = 0; 8576f97fce3SMatthew Dillon *sbp = mp->mnt_vstat; 8586f97fce3SMatthew Dillon return(0); 8596f97fce3SMatthew Dillon } 8606f97fce3SMatthew Dillon 8610729c8c8SMatthew Dillon /* 8620729c8c8SMatthew Dillon * Sync the filesystem. Currently we have to run it twice, the second 8630729c8c8SMatthew Dillon * one will advance the undo start index to the end index, so if a crash 8640729c8c8SMatthew Dillon * occurs no undos will be run on mount. 86577062c8aSMatthew Dillon * 86677062c8aSMatthew Dillon * We do not sync the filesystem if we are called from a panic. If we did 86777062c8aSMatthew Dillon * we might end up blowing up a sync that was already in progress. 8680729c8c8SMatthew Dillon */ 869427e5fc6SMatthew Dillon static int 870427e5fc6SMatthew Dillon hammer_vfs_sync(struct mount *mp, int waitfor) 871427e5fc6SMatthew Dillon { 872fbc6e32aSMatthew Dillon struct hammer_mount *hmp = (void *)mp->mnt_data; 8730729c8c8SMatthew Dillon int error; 8740729c8c8SMatthew Dillon 87577062c8aSMatthew Dillon if (panicstr == NULL) { 8760729c8c8SMatthew Dillon error = hammer_sync_hmp(hmp, waitfor); 87777062c8aSMatthew Dillon } else { 87877062c8aSMatthew Dillon error = EIO; 87977062c8aSMatthew Dillon } 8800729c8c8SMatthew Dillon return (error); 881427e5fc6SMatthew Dillon } 882427e5fc6SMatthew Dillon 883513ca7d7SMatthew Dillon /* 884513ca7d7SMatthew Dillon * Convert a vnode to a file handle. 885513ca7d7SMatthew Dillon */ 886513ca7d7SMatthew Dillon static int 887513ca7d7SMatthew Dillon hammer_vfs_vptofh(struct vnode *vp, struct fid *fhp) 888513ca7d7SMatthew Dillon { 889513ca7d7SMatthew Dillon hammer_inode_t ip; 890513ca7d7SMatthew Dillon 891513ca7d7SMatthew Dillon KKASSERT(MAXFIDSZ >= 16); 892513ca7d7SMatthew Dillon ip = VTOI(vp); 893513ca7d7SMatthew Dillon fhp->fid_len = offsetof(struct fid, fid_data[16]); 894adf01747SMatthew Dillon fhp->fid_ext = ip->obj_localization >> 16; 895513ca7d7SMatthew Dillon bcopy(&ip->obj_id, fhp->fid_data + 0, sizeof(ip->obj_id)); 896513ca7d7SMatthew Dillon bcopy(&ip->obj_asof, fhp->fid_data + 8, sizeof(ip->obj_asof)); 897513ca7d7SMatthew Dillon return(0); 898513ca7d7SMatthew Dillon } 899513ca7d7SMatthew Dillon 900513ca7d7SMatthew Dillon 901513ca7d7SMatthew Dillon /* 902513ca7d7SMatthew Dillon * Convert a file handle back to a vnode. 903*67863d04SMatthew Dillon * 904*67863d04SMatthew Dillon * Use rootvp to enforce PFS isolation when a PFS is exported via a 905*67863d04SMatthew Dillon * null mount. 906513ca7d7SMatthew Dillon */ 907513ca7d7SMatthew Dillon static int 908*67863d04SMatthew Dillon hammer_vfs_fhtovp(struct mount *mp, struct vnode *rootvp, 909*67863d04SMatthew Dillon struct fid *fhp, struct vnode **vpp) 910513ca7d7SMatthew Dillon { 91136f82b23SMatthew Dillon struct hammer_transaction trans; 912513ca7d7SMatthew Dillon struct hammer_inode *ip; 913513ca7d7SMatthew Dillon struct hammer_inode_info info; 914513ca7d7SMatthew Dillon int error; 915adf01747SMatthew Dillon u_int32_t localization; 916513ca7d7SMatthew Dillon 917513ca7d7SMatthew Dillon bcopy(fhp->fid_data + 0, &info.obj_id, sizeof(info.obj_id)); 918513ca7d7SMatthew Dillon bcopy(fhp->fid_data + 8, &info.obj_asof, sizeof(info.obj_asof)); 919*67863d04SMatthew Dillon if (rootvp) 920*67863d04SMatthew Dillon localization = VTOI(rootvp)->obj_localization; 921*67863d04SMatthew Dillon else 922adf01747SMatthew Dillon localization = (u_int32_t)fhp->fid_ext << 16; 923513ca7d7SMatthew Dillon 92436f82b23SMatthew Dillon hammer_simple_transaction(&trans, (void *)mp->mnt_data); 92536f82b23SMatthew Dillon 926513ca7d7SMatthew Dillon /* 927513ca7d7SMatthew Dillon * Get/allocate the hammer_inode structure. The structure must be 928513ca7d7SMatthew Dillon * unlocked while we manipulate the related vnode to avoid a 929513ca7d7SMatthew Dillon * deadlock. 930513ca7d7SMatthew Dillon */ 931ddfdf542SMatthew Dillon ip = hammer_get_inode(&trans, NULL, info.obj_id, 932adf01747SMatthew Dillon info.obj_asof, localization, 0, &error); 933513ca7d7SMatthew Dillon if (ip == NULL) { 934513ca7d7SMatthew Dillon *vpp = NULL; 935513ca7d7SMatthew Dillon return(error); 936513ca7d7SMatthew Dillon } 937e8599db1SMatthew Dillon error = hammer_get_vnode(ip, vpp); 938513ca7d7SMatthew Dillon hammer_rel_inode(ip, 0); 939b84de5afSMatthew Dillon hammer_done_transaction(&trans); 940513ca7d7SMatthew Dillon return (error); 941513ca7d7SMatthew Dillon } 942513ca7d7SMatthew Dillon 943513ca7d7SMatthew Dillon static int 944513ca7d7SMatthew Dillon hammer_vfs_checkexp(struct mount *mp, struct sockaddr *nam, 945513ca7d7SMatthew Dillon int *exflagsp, struct ucred **credanonp) 946513ca7d7SMatthew Dillon { 947513ca7d7SMatthew Dillon hammer_mount_t hmp = (void *)mp->mnt_data; 948513ca7d7SMatthew Dillon struct netcred *np; 949513ca7d7SMatthew Dillon int error; 950513ca7d7SMatthew Dillon 951513ca7d7SMatthew Dillon np = vfs_export_lookup(mp, &hmp->export, nam); 952513ca7d7SMatthew Dillon if (np) { 953513ca7d7SMatthew Dillon *exflagsp = np->netc_exflags; 954513ca7d7SMatthew Dillon *credanonp = &np->netc_anon; 955513ca7d7SMatthew Dillon error = 0; 956513ca7d7SMatthew Dillon } else { 957513ca7d7SMatthew Dillon error = EACCES; 958513ca7d7SMatthew Dillon } 959513ca7d7SMatthew Dillon return (error); 960513ca7d7SMatthew Dillon 961513ca7d7SMatthew Dillon } 962513ca7d7SMatthew Dillon 963513ca7d7SMatthew Dillon int 964513ca7d7SMatthew Dillon hammer_vfs_export(struct mount *mp, int op, const struct export_args *export) 965513ca7d7SMatthew Dillon { 966513ca7d7SMatthew Dillon hammer_mount_t hmp = (void *)mp->mnt_data; 967513ca7d7SMatthew Dillon int error; 968513ca7d7SMatthew Dillon 969513ca7d7SMatthew Dillon switch(op) { 970513ca7d7SMatthew Dillon case MOUNTCTL_SET_EXPORT: 971513ca7d7SMatthew Dillon error = vfs_export(mp, &hmp->export, export); 972513ca7d7SMatthew Dillon break; 973513ca7d7SMatthew Dillon default: 974513ca7d7SMatthew Dillon error = EOPNOTSUPP; 975513ca7d7SMatthew Dillon break; 976513ca7d7SMatthew Dillon } 977513ca7d7SMatthew Dillon return(error); 978513ca7d7SMatthew Dillon } 979513ca7d7SMatthew Dillon 980