2 * Copyright (c) 2011, 2012 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 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/nlookup.h>
38 #include <sys/vnode.h>
39 #include <sys/mount.h>
40 #include <sys/fcntl.h>
43 #include <sys/vfsops.h>
44 #include <sys/sysctl.h>
47 #include "hammer2_disk.h"
48 #include "hammer2_mount.h"
50 struct hammer2_sync_info {
56 int hammer2_cluster_enable = 1;
57 long hammer2_iod_file_read;
58 long hammer2_iod_meta_read;
59 long hammer2_iod_indr_read;
60 long hammer2_iod_file_write;
61 long hammer2_iod_meta_write;
62 long hammer2_iod_indr_write;
63 long hammer2_iod_volu_write;
64 long hammer2_ioa_file_read;
65 long hammer2_ioa_meta_read;
66 long hammer2_ioa_indr_read;
67 long hammer2_ioa_file_write;
68 long hammer2_ioa_meta_write;
69 long hammer2_ioa_indr_write;
70 long hammer2_ioa_volu_write;
72 SYSCTL_NODE(_vfs, OID_AUTO, hammer2, CTLFLAG_RW, 0, "HAMMER2 filesystem");
74 SYSCTL_INT(_vfs_hammer2, OID_AUTO, debug, CTLFLAG_RW,
75 &hammer2_debug, 0, "");
76 SYSCTL_INT(_vfs_hammer2, OID_AUTO, cluster_enable, CTLFLAG_RW,
77 &hammer2_cluster_enable, 0, "");
78 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_file_read, CTLFLAG_RW,
79 &hammer2_iod_file_read, 0, "");
80 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_meta_read, CTLFLAG_RW,
81 &hammer2_iod_meta_read, 0, "");
82 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_indr_read, CTLFLAG_RW,
83 &hammer2_iod_indr_read, 0, "");
84 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_file_write, CTLFLAG_RW,
85 &hammer2_iod_file_write, 0, "");
86 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_meta_write, CTLFLAG_RW,
87 &hammer2_iod_meta_write, 0, "");
88 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_indr_write, CTLFLAG_RW,
89 &hammer2_iod_indr_write, 0, "");
90 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_volu_write, CTLFLAG_RW,
91 &hammer2_iod_volu_write, 0, "");
92 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_file_read, CTLFLAG_RW,
93 &hammer2_ioa_file_read, 0, "");
94 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_meta_read, CTLFLAG_RW,
95 &hammer2_ioa_meta_read, 0, "");
96 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_indr_read, CTLFLAG_RW,
97 &hammer2_ioa_indr_read, 0, "");
98 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_file_write, CTLFLAG_RW,
99 &hammer2_ioa_file_write, 0, "");
100 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_meta_write, CTLFLAG_RW,
101 &hammer2_ioa_meta_write, 0, "");
102 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_indr_write, CTLFLAG_RW,
103 &hammer2_ioa_indr_write, 0, "");
104 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_volu_write, CTLFLAG_RW,
105 &hammer2_ioa_volu_write, 0, "");
107 static int hammer2_vfs_init(struct vfsconf *conf);
108 static int hammer2_vfs_mount(struct mount *mp, char *path, caddr_t data,
110 static int hammer2_remount(struct mount *, char *, struct vnode *,
112 static int hammer2_vfs_unmount(struct mount *mp, int mntflags);
113 static int hammer2_vfs_root(struct mount *mp, struct vnode **vpp);
114 static int hammer2_vfs_statfs(struct mount *mp, struct statfs *sbp,
116 static int hammer2_vfs_statvfs(struct mount *mp, struct statvfs *sbp,
118 static int hammer2_vfs_sync(struct mount *mp, int waitfor);
119 static int hammer2_vfs_vget(struct mount *mp, struct vnode *dvp,
120 ino_t ino, struct vnode **vpp);
121 static int hammer2_vfs_fhtovp(struct mount *mp, struct vnode *rootvp,
122 struct fid *fhp, struct vnode **vpp);
123 static int hammer2_vfs_vptofh(struct vnode *vp, struct fid *fhp);
124 static int hammer2_vfs_checkexp(struct mount *mp, struct sockaddr *nam,
125 int *exflagsp, struct ucred **credanonp);
127 static int hammer2_install_volume_header(hammer2_mount_t *hmp);
128 static int hammer2_sync_scan1(struct mount *mp, struct vnode *vp, void *data);
129 static int hammer2_sync_scan2(struct mount *mp, struct vnode *vp, void *data);
132 * HAMMER2 vfs operations.
134 static struct vfsops hammer2_vfsops = {
135 .vfs_init = hammer2_vfs_init,
136 .vfs_sync = hammer2_vfs_sync,
137 .vfs_mount = hammer2_vfs_mount,
138 .vfs_unmount = hammer2_vfs_unmount,
139 .vfs_root = hammer2_vfs_root,
140 .vfs_statfs = hammer2_vfs_statfs,
141 .vfs_statvfs = hammer2_vfs_statvfs,
142 .vfs_vget = hammer2_vfs_vget,
143 .vfs_vptofh = hammer2_vfs_vptofh,
144 .vfs_fhtovp = hammer2_vfs_fhtovp,
145 .vfs_checkexp = hammer2_vfs_checkexp
148 MALLOC_DEFINE(M_HAMMER2, "HAMMER2-mount", "");
150 VFS_SET(hammer2_vfsops, hammer2, 0);
151 MODULE_VERSION(hammer2, 1);
155 hammer2_vfs_init(struct vfsconf *conf)
161 if (HAMMER2_BLOCKREF_BYTES != sizeof(struct hammer2_blockref))
163 if (HAMMER2_INODE_BYTES != sizeof(struct hammer2_inode_data))
165 if (HAMMER2_ALLOCREF_BYTES != sizeof(struct hammer2_allocref))
167 if (HAMMER2_VOLUME_BYTES != sizeof(struct hammer2_volume_data))
171 kprintf("HAMMER2 structure size mismatch; cannot continue.\n");
177 * Mount or remount HAMMER2 fileystem from physical media
180 * mp mount point structure
186 * mp mount point structure
187 * path path to mount point
188 * data pointer to argument structure in user space
189 * volume volume path (device@LABEL form)
190 * hflags user mount flags
191 * cred user credentials
198 hammer2_vfs_mount(struct mount *mp, char *path, caddr_t data,
201 struct hammer2_mount_info info;
202 hammer2_mount_t *hmp;
205 struct nlookupdata nd;
206 hammer2_chain_t *parent;
207 hammer2_chain_t *schain;
208 hammer2_chain_t *rchain;
209 char devstr[MNAMELEN];
222 kprintf("hammer2_mount\n");
231 * Non-root mount or updating a mount
233 error = copyin(data, &info, sizeof(info));
237 error = copyinstr(info.volume, devstr, MNAMELEN - 1, &done);
241 /* Extract device and label */
243 label = strchr(devstr, '@');
245 ((label + 1) - dev) > done) {
253 if (mp->mnt_flag & MNT_UPDATE) {
255 /* HAMMER2 implements NFS export via mountctl */
258 error = hammer2_remount(mp, path, devvp, cred);
266 /* Lookup name and verify it refers to a block device */
267 error = nlookup_init(&nd, dev, UIO_SYSSPACE, NLC_FOLLOW);
269 error = nlookup(&nd);
271 error = cache_vref(&nd.nl_nch, nd.nl_cred, &devvp);
275 if (vn_isdisk(devvp, &error))
276 error = vfs_mountedon(devvp);
278 if (error == 0 && vcount(devvp) > 0)
282 * Now open the device
285 ronly = ((mp->mnt_flag & MNT_RDONLY) != 0);
286 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
287 error = vinvalbuf(devvp, V_SAVE, 0, 0);
289 error = VOP_OPEN(devvp, ronly ? FREAD : FREAD | FWRITE,
294 if (error && devvp) {
302 * Block device opened successfully, finish initializing the
305 * From this point on we have to call hammer2_unmount() on failure.
307 hmp = kmalloc(sizeof(*hmp), M_HAMMER2, M_WAITOK | M_ZERO);
308 mp->mnt_data = (qaddr_t)hmp;
312 kmalloc_create(&hmp->minode, "HAMMER2-inodes");
313 kmalloc_create(&hmp->mchain, "HAMMER2-chains");
315 mp->mnt_flag = MNT_LOCAL;
316 mp->mnt_kern_flag |= MNTK_ALL_MPSAFE; /* all entry pts are SMP */
319 * vchain setup. vchain.data is special cased to NULL. vchain.refs
320 * is initialized and will never drop to 0.
322 hmp->vchain.bref.type = HAMMER2_BREF_TYPE_VOLUME;
323 hmp->vchain.refs = 1;
324 hmp->vchain.data = (void *)&hmp->voldata;
325 hmp->vchain.bref.data_off = 0 | HAMMER2_PBUFRADIX;
326 /* hmp->vchain.u.xxx is left NULL */
327 lockinit(&hmp->vchain.lk, "volume", 0, LK_CANRECURSE);
328 lockinit(&hmp->alloclk, "h2alloc", 0, 0);
329 lockinit(&hmp->voldatalk, "voldata", 0, LK_CANRECURSE);
332 * Install the volume header
334 error = hammer2_install_volume_header(hmp);
336 hammer2_vfs_unmount(mp, MNT_FORCE);
341 * required mount structure initializations
343 mp->mnt_stat.f_iosize = HAMMER2_PBUFSIZE;
344 mp->mnt_stat.f_bsize = HAMMER2_PBUFSIZE;
346 mp->mnt_vstat.f_frsize = HAMMER2_PBUFSIZE;
347 mp->mnt_vstat.f_bsize = HAMMER2_PBUFSIZE;
352 mp->mnt_iosize_max = MAXPHYS;
355 * First locate the super-root inode, which is key 0 relative to the
356 * volume header's blockset.
358 * Then locate the root inode by scanning the directory keyspace
359 * represented by the label.
361 lhc = hammer2_dirhash(label, strlen(label));
362 parent = &hmp->vchain;
363 hammer2_chain_lock(hmp, parent, HAMMER2_RESOLVE_ALWAYS);
364 schain = hammer2_chain_lookup(hmp, &parent,
365 HAMMER2_SROOT_KEY, HAMMER2_SROOT_KEY, 0);
366 hammer2_chain_unlock(hmp, parent);
367 if (schain == NULL) {
368 kprintf("hammer2_mount: invalid super-root\n");
369 hammer2_vfs_unmount(mp, MNT_FORCE);
373 hammer2_chain_ref(hmp, schain); /* for hmp->schain */
375 rchain = hammer2_chain_lookup(hmp, &parent,
376 lhc, lhc + HAMMER2_DIRHASH_LOMASK,
379 if (rchain->bref.type == HAMMER2_BREF_TYPE_INODE &&
381 strcmp(label, rchain->data->ipdata.filename) == 0) {
384 rchain = hammer2_chain_next(hmp, &parent, rchain,
385 lhc, lhc + HAMMER2_DIRHASH_LOMASK,
388 hammer2_chain_unlock(hmp, parent);
389 if (rchain == NULL) {
390 kprintf("hammer2_mount: root label not found\n");
391 hammer2_chain_drop(hmp, schain);
392 hammer2_vfs_unmount(mp, MNT_FORCE);
395 hammer2_chain_ref(hmp, rchain); /* for hmp->rchain */
396 hammer2_chain_unlock(hmp, rchain);
398 hmp->schain = schain; /* left held & unlocked */
399 hmp->rchain = rchain; /* left held & unlocked */
400 hmp->iroot = rchain->u.ip; /* implied hold from rchain */
401 kprintf("iroot %p\n", rchain->u.ip);
404 vfs_add_vnodeops(mp, &hammer2_vnode_vops, &mp->mnt_vn_norm_ops);
405 vfs_add_vnodeops(mp, &hammer2_spec_vops, &mp->mnt_vn_spec_ops);
406 vfs_add_vnodeops(mp, &hammer2_fifo_vops, &mp->mnt_vn_fifo_ops);
408 copyinstr(info.volume, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
409 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
410 bzero(mp->mnt_stat.f_mntonname, sizeof(mp->mnt_stat.f_mntonname));
411 copyinstr(path, mp->mnt_stat.f_mntonname,
412 sizeof(mp->mnt_stat.f_mntonname) - 1,
415 hammer2_vfs_statfs(mp, &mp->mnt_stat, cred);
422 hammer2_remount(struct mount *mp, char *path, struct vnode *devvp,
430 hammer2_vfs_unmount(struct mount *mp, int mntflags)
432 hammer2_mount_t *hmp;
435 int ronly = ((mp->mnt_flag & MNT_RDONLY) != 0);
438 kprintf("hammer2_unmount\n");
443 if (mntflags & MNT_FORCE)
446 hammer2_mount_exlock(hmp);
449 * If mount initialization proceeded far enough we must flush
453 error = vflush(mp, 0, flags);
459 * Flush any left over chains. The voldata lock is only used
460 * to synchronize against HAMMER2_CHAIN_MODIFIED_AUX.
462 hammer2_voldata_lock(hmp);
463 if (hmp->vchain.flags & (HAMMER2_CHAIN_MODIFIED |
464 HAMMER2_CHAIN_MODIFIED_AUX |
465 HAMMER2_CHAIN_SUBMODIFIED)) {
466 hammer2_voldata_unlock(hmp);
467 hammer2_vfs_sync(mp, MNT_WAIT);
469 hammer2_voldata_unlock(hmp);
471 if (hmp->vchain.flags & (HAMMER2_CHAIN_MODIFIED |
472 HAMMER2_CHAIN_MODIFIED_AUX |
473 HAMMER2_CHAIN_SUBMODIFIED)) {
474 kprintf("hammer2_unmount: chains left over after final sync\n");
475 if (hammer2_debug & 0x0010)
476 Debugger("entered debugger");
480 * Cleanup the root and super-root chain elements (which should be
485 KKASSERT(hmp->rchain->refs == 1);
486 hammer2_chain_drop(hmp, hmp->rchain);
490 KKASSERT(hmp->schain->refs == 1);
491 hammer2_chain_drop(hmp, hmp->schain);
496 * Finish up with the device vnode
498 if ((devvp = hmp->devvp) != NULL) {
499 vinvalbuf(devvp, (ronly ? 0 : V_SAVE), 0, 0);
501 VOP_CLOSE(devvp, (ronly ? FREAD : FREAD|FWRITE));
506 kmalloc_destroy(&hmp->minode);
507 kmalloc_destroy(&hmp->mchain);
509 hammer2_mount_unlock(hmp);
513 kfree(hmp, M_HAMMER2);
520 hammer2_vfs_vget(struct mount *mp, struct vnode *dvp,
521 ino_t ino, struct vnode **vpp)
523 kprintf("hammer2_vget\n");
529 hammer2_vfs_root(struct mount *mp, struct vnode **vpp)
531 hammer2_mount_t *hmp;
536 hammer2_mount_exlock(hmp);
537 if (hmp->iroot == NULL) {
541 vp = hammer2_igetv(hmp->iroot, &error);
544 kprintf("vnodefail\n");
546 hammer2_mount_unlock(hmp);
553 hammer2_vfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
555 hammer2_mount_t *hmp;
559 mp->mnt_stat.f_files = 10;
560 mp->mnt_stat.f_bfree = 10;
561 mp->mnt_stat.f_bavail = mp->mnt_stat.f_bfree;
569 hammer2_vfs_statvfs(struct mount *mp, struct statvfs *sbp, struct ucred *cred)
571 hammer2_mount_t *hmp;
575 mp->mnt_vstat.f_bsize = HAMMER2_PBUFSIZE;
576 mp->mnt_vstat.f_files = 0;
577 mp->mnt_vstat.f_bavail = mp->mnt_stat.f_bfree;
579 *sbp = mp->mnt_vstat;
584 * Sync the entire filesystem; this is called from the filesystem syncer
585 * process periodically and whenever a user calls sync(1) on the hammer
588 * Currently is actually called from the syncer! \o/
590 * This task will have to snapshot the state of the dirty inode chain.
591 * From that, it will have to make sure all of the inodes on the dirty
592 * chain have IO initiated. We make sure that io is initiated for the root
595 * If waitfor is set, we wait for media to acknowledge the new rootblock.
597 * THINKS: side A vs side B, to have sync not stall all I/O?
601 hammer2_vfs_sync(struct mount *mp, int waitfor)
603 struct hammer2_sync_info info;
604 hammer2_mount_t *hmp;
612 if (waitfor & MNT_LAZY)
613 flags |= VMSC_ONEPASS;
616 info.waitfor = MNT_NOWAIT;
617 vmntvnodescan(mp, flags | VMSC_NOWAIT,
619 hammer2_sync_scan2, &info);
620 if (info.error == 0 && (waitfor & MNT_WAIT)) {
621 info.waitfor = waitfor;
622 vmntvnodescan(mp, flags,
624 hammer2_sync_scan2, &info);
628 if (waitfor == MNT_WAIT) {
634 hammer2_chain_lock(hmp, &hmp->vchain, HAMMER2_RESOLVE_ALWAYS);
635 if (hmp->vchain.flags & (HAMMER2_CHAIN_MODIFIED |
636 HAMMER2_CHAIN_MODIFIED_AUX |
637 HAMMER2_CHAIN_SUBMODIFIED)) {
638 hammer2_chain_flush(hmp, &hmp->vchain);
643 hammer2_chain_unlock(hmp, &hmp->vchain);
647 if ((waitfor & MNT_LAZY) == 0) {
648 waitfor = MNT_NOWAIT;
649 vn_lock(hmp->devvp, LK_EXCLUSIVE | LK_RETRY);
650 error = VOP_FSYNC(hmp->devvp, waitfor, 0);
651 vn_unlock(hmp->devvp);
654 if (error == 0 && haswork) {
658 * Synchronize the disk before flushing the volume
662 bp->b_bio1.bio_offset = 0;
665 bp->b_cmd = BUF_CMD_FLUSH;
666 bp->b_bio1.bio_done = biodone_sync;
667 bp->b_bio1.bio_flags |= BIO_SYNC;
668 vn_strategy(hmp->devvp, &bp->b_bio1);
669 biowait(&bp->b_bio1, "h2vol");
673 * Then we can safely flush the volume header. Volume
674 * data is locked separately to prevent ioctl functions
675 * from deadlocking due to a configuration issue.
677 bp = getblk(hmp->devvp, 0, HAMMER2_PBUFSIZE, 0, 0);
678 hammer2_voldata_lock(hmp);
679 bcopy(&hmp->voldata, bp->b_data, HAMMER2_PBUFSIZE);
680 hammer2_voldata_unlock(hmp);
689 * NOTE: We don't test SUBMODIFIED or MOVED here because the fsync code
690 * won't flush on those flags. The syncer code above will do a
691 * general meta-data flush globally that will catch these flags.
694 hammer2_sync_scan1(struct mount *mp, struct vnode *vp, void *data)
699 if (vp->v_type == VNON || ip == NULL ||
700 ((ip->chain.flags & (HAMMER2_CHAIN_MODIFIED |
701 HAMMER2_CHAIN_DIRTYEMBED)) == 0 &&
702 RB_EMPTY(&vp->v_rbdirty_tree))) {
709 hammer2_sync_scan2(struct mount *mp, struct vnode *vp, void *data)
711 struct hammer2_sync_info *info = data;
716 if (vp->v_type == VNON || vp->v_type == VBAD ||
717 ((ip->chain.flags & (HAMMER2_CHAIN_MODIFIED |
718 HAMMER2_CHAIN_DIRTYEMBED)) == 0 &&
719 RB_EMPTY(&vp->v_rbdirty_tree))) {
722 error = VOP_FSYNC(vp, MNT_NOWAIT, 0);
730 hammer2_vfs_vptofh(struct vnode *vp, struct fid *fhp)
737 hammer2_vfs_fhtovp(struct mount *mp, struct vnode *rootvp,
738 struct fid *fhp, struct vnode **vpp)
745 hammer2_vfs_checkexp(struct mount *mp, struct sockaddr *nam,
746 int *exflagsp, struct ucred **credanonp)
752 * Support code for hammer2_mount(). Read, verify, and install the volume
753 * header into the HMP
755 * XXX read four volhdrs and use the one with the highest TID whos CRC
760 * XXX For filesystems w/ less than 4 volhdrs, make sure to not write to
761 * nonexistant locations.
763 * XXX Record selected volhdr and ring updates to each of 4 volhdrs
767 hammer2_install_volume_header(hammer2_mount_t *hmp)
769 hammer2_volume_data_t *vd;
771 hammer2_crc32_t crc0, crc, bcrc0, bcrc;
783 * There are up to 4 copies of the volume header (syncs iterate
784 * between them so there is no single master). We don't trust the
785 * volu_size field so we don't know precisely how large the filesystem
786 * is, so depend on the OS to return an error if we go beyond the
787 * block device's EOF.
789 for (i = 0; i < HAMMER2_NUM_VOLHDRS; i++) {
790 error = bread(hmp->devvp, i * HAMMER2_RESERVE_BYTES64,
791 HAMMER2_VOLUME_BYTES, &bp);
798 vd = (struct hammer2_volume_data *) bp->b_data;
799 if ((vd->magic != HAMMER2_VOLUME_ID_HBO) &&
800 (vd->magic != HAMMER2_VOLUME_ID_ABO)) {
806 if (vd->magic == HAMMER2_VOLUME_ID_ABO) {
807 /* XXX: Reversed-endianness filesystem */
808 kprintf("hammer2: reverse-endian filesystem detected");
814 crc = vd->icrc_sects[HAMMER2_VOL_ICRC_SECT0];
815 crc0 = hammer2_icrc32(bp->b_data + HAMMER2_VOLUME_ICRC0_OFF,
816 HAMMER2_VOLUME_ICRC0_SIZE);
817 bcrc = vd->icrc_sects[HAMMER2_VOL_ICRC_SECT1];
818 bcrc0 = hammer2_icrc32(bp->b_data + HAMMER2_VOLUME_ICRC1_OFF,
819 HAMMER2_VOLUME_ICRC1_SIZE);
820 if ((crc0 != crc) || (bcrc0 != bcrc)) {
821 kprintf("hammer2 volume header crc "
822 "mismatch copy #%d\t%08x %08x",
829 if (valid == 0 || hmp->voldata.last_tid < vd->last_tid) {
839 kprintf("hammer2: a valid volume header was found\n");
842 kprintf("hammer2: no valid volume headers found!\n");