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>
45 #include <sys/socket.h>
48 #include "hammer2_disk.h"
49 #include "hammer2_mount.h"
50 #include "hammer2_network.h"
52 struct hammer2_sync_info {
57 TAILQ_HEAD(hammer2_mntlist, hammer2_mount);
58 static struct hammer2_mntlist hammer2_mntlist;
59 static struct lock hammer2_mntlk;
62 int hammer2_cluster_enable = 1;
63 int hammer2_hardlink_enable = 1;
64 long hammer2_iod_file_read;
65 long hammer2_iod_meta_read;
66 long hammer2_iod_indr_read;
67 long hammer2_iod_file_write;
68 long hammer2_iod_meta_write;
69 long hammer2_iod_indr_write;
70 long hammer2_iod_volu_write;
71 long hammer2_ioa_file_read;
72 long hammer2_ioa_meta_read;
73 long hammer2_ioa_indr_read;
74 long hammer2_ioa_file_write;
75 long hammer2_ioa_meta_write;
76 long hammer2_ioa_indr_write;
77 long hammer2_ioa_volu_write;
79 SYSCTL_NODE(_vfs, OID_AUTO, hammer2, CTLFLAG_RW, 0, "HAMMER2 filesystem");
81 SYSCTL_INT(_vfs_hammer2, OID_AUTO, debug, CTLFLAG_RW,
82 &hammer2_debug, 0, "");
83 SYSCTL_INT(_vfs_hammer2, OID_AUTO, cluster_enable, CTLFLAG_RW,
84 &hammer2_cluster_enable, 0, "");
85 SYSCTL_INT(_vfs_hammer2, OID_AUTO, hardlink_enable, CTLFLAG_RW,
86 &hammer2_hardlink_enable, 0, "");
87 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_file_read, CTLFLAG_RW,
88 &hammer2_iod_file_read, 0, "");
89 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_meta_read, CTLFLAG_RW,
90 &hammer2_iod_meta_read, 0, "");
91 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_indr_read, CTLFLAG_RW,
92 &hammer2_iod_indr_read, 0, "");
93 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_file_write, CTLFLAG_RW,
94 &hammer2_iod_file_write, 0, "");
95 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_meta_write, CTLFLAG_RW,
96 &hammer2_iod_meta_write, 0, "");
97 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_indr_write, CTLFLAG_RW,
98 &hammer2_iod_indr_write, 0, "");
99 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, iod_volu_write, CTLFLAG_RW,
100 &hammer2_iod_volu_write, 0, "");
101 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_file_read, CTLFLAG_RW,
102 &hammer2_ioa_file_read, 0, "");
103 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_meta_read, CTLFLAG_RW,
104 &hammer2_ioa_meta_read, 0, "");
105 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_indr_read, CTLFLAG_RW,
106 &hammer2_ioa_indr_read, 0, "");
107 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_file_write, CTLFLAG_RW,
108 &hammer2_ioa_file_write, 0, "");
109 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_meta_write, CTLFLAG_RW,
110 &hammer2_ioa_meta_write, 0, "");
111 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_indr_write, CTLFLAG_RW,
112 &hammer2_ioa_indr_write, 0, "");
113 SYSCTL_LONG(_vfs_hammer2, OID_AUTO, ioa_volu_write, CTLFLAG_RW,
114 &hammer2_ioa_volu_write, 0, "");
116 static int hammer2_vfs_init(struct vfsconf *conf);
117 static int hammer2_vfs_mount(struct mount *mp, char *path, caddr_t data,
119 static int hammer2_remount(struct mount *, char *, struct vnode *,
121 static int hammer2_vfs_unmount(struct mount *mp, int mntflags);
122 static int hammer2_vfs_root(struct mount *mp, struct vnode **vpp);
123 static int hammer2_vfs_statfs(struct mount *mp, struct statfs *sbp,
125 static int hammer2_vfs_statvfs(struct mount *mp, struct statvfs *sbp,
127 static int hammer2_vfs_sync(struct mount *mp, int waitfor);
128 static int hammer2_vfs_vget(struct mount *mp, struct vnode *dvp,
129 ino_t ino, struct vnode **vpp);
130 static int hammer2_vfs_fhtovp(struct mount *mp, struct vnode *rootvp,
131 struct fid *fhp, struct vnode **vpp);
132 static int hammer2_vfs_vptofh(struct vnode *vp, struct fid *fhp);
133 static int hammer2_vfs_checkexp(struct mount *mp, struct sockaddr *nam,
134 int *exflagsp, struct ucred **credanonp);
136 static int hammer2_install_volume_header(hammer2_mount_t *hmp);
137 static int hammer2_sync_scan1(struct mount *mp, struct vnode *vp, void *data);
138 static int hammer2_sync_scan2(struct mount *mp, struct vnode *vp, void *data);
140 static void hammer2_cluster_thread_rd(void *arg);
141 static void hammer2_cluster_thread_wr(void *arg);
142 static int hammer2_msg_conn_reply(hammer2_state_t *state, hammer2_msg_t *msg);
143 static int hammer2_msg_span_reply(hammer2_state_t *state, hammer2_msg_t *msg);
144 static int hammer2_msg_lnk_rcvmsg(hammer2_msg_t *msg);
145 static void hammer2_drain_msgq(hammer2_pfsmount_t *pmp);
148 * HAMMER2 vfs operations.
150 static struct vfsops hammer2_vfsops = {
151 .vfs_init = hammer2_vfs_init,
152 .vfs_sync = hammer2_vfs_sync,
153 .vfs_mount = hammer2_vfs_mount,
154 .vfs_unmount = hammer2_vfs_unmount,
155 .vfs_root = hammer2_vfs_root,
156 .vfs_statfs = hammer2_vfs_statfs,
157 .vfs_statvfs = hammer2_vfs_statvfs,
158 .vfs_vget = hammer2_vfs_vget,
159 .vfs_vptofh = hammer2_vfs_vptofh,
160 .vfs_fhtovp = hammer2_vfs_fhtovp,
161 .vfs_checkexp = hammer2_vfs_checkexp
164 MALLOC_DEFINE(M_HAMMER2, "HAMMER2-mount", "");
166 VFS_SET(hammer2_vfsops, hammer2, 0);
167 MODULE_VERSION(hammer2, 1);
171 hammer2_vfs_init(struct vfsconf *conf)
177 if (HAMMER2_BLOCKREF_BYTES != sizeof(struct hammer2_blockref))
179 if (HAMMER2_INODE_BYTES != sizeof(struct hammer2_inode_data))
181 if (HAMMER2_ALLOCREF_BYTES != sizeof(struct hammer2_allocref))
183 if (HAMMER2_VOLUME_BYTES != sizeof(struct hammer2_volume_data))
187 kprintf("HAMMER2 structure size mismatch; cannot continue.\n");
189 lockinit(&hammer2_mntlk, "mntlk", 0, 0);
190 TAILQ_INIT(&hammer2_mntlist);
196 * Mount or remount HAMMER2 fileystem from physical media
199 * mp mount point structure
205 * mp mount point structure
206 * path path to mount point
207 * data pointer to argument structure in user space
208 * volume volume path (device@LABEL form)
209 * hflags user mount flags
210 * cred user credentials
217 hammer2_vfs_mount(struct mount *mp, char *path, caddr_t data,
220 struct hammer2_mount_info info;
221 hammer2_pfsmount_t *pmp;
222 hammer2_mount_t *hmp;
225 struct nlookupdata nd;
226 hammer2_chain_t *parent;
227 hammer2_chain_t *schain;
228 hammer2_chain_t *rchain;
229 char devstr[MNAMELEN];
244 kprintf("hammer2_mount\n");
250 bzero(&info, sizeof(info));
251 info.cluster_fd = -1;
255 * Non-root mount or updating a mount
257 error = copyin(data, &info, sizeof(info));
261 error = copyinstr(info.volume, devstr, MNAMELEN - 1, &done);
265 /* Extract device and label */
267 label = strchr(devstr, '@');
269 ((label + 1) - dev) > done) {
277 if (mp->mnt_flag & MNT_UPDATE) {
279 /* HAMMER2 implements NFS export via mountctl */
282 error = hammer2_remount(mp, path, devvp, cred);
290 * Lookup name and verify it refers to a block device.
292 error = nlookup_init(&nd, dev, UIO_SYSSPACE, NLC_FOLLOW);
294 error = nlookup(&nd);
296 error = cache_vref(&nd.nl_nch, nd.nl_cred, &devvp);
300 if (vn_isdisk(devvp, &error))
301 error = vfs_mountedon(devvp);
305 * Determine if the device has already been mounted. After this
306 * check hmp will be non-NULL if we are doing the second or more
307 * hammer2 mounts from the same device.
309 lockmgr(&hammer2_mntlk, LK_EXCLUSIVE);
310 TAILQ_FOREACH(hmp, &hammer2_mntlist, mntentry) {
311 if (hmp->devvp == devvp)
316 * Open the device if this isn't a secondary mount
322 if (error == 0 && vcount(devvp) > 0)
326 * Now open the device
329 ronly = ((mp->mnt_flag & MNT_RDONLY) != 0);
330 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
331 error = vinvalbuf(devvp, V_SAVE, 0, 0);
333 error = VOP_OPEN(devvp,
334 ronly ? FREAD : FREAD | FWRITE,
339 if (error && devvp) {
344 lockmgr(&hammer2_mntlk, LK_RELEASE);
350 * Block device opened successfully, finish initializing the
353 * From this point on we have to call hammer2_unmount() on failure.
355 pmp = kmalloc(sizeof(*pmp), M_HAMMER2, M_WAITOK | M_ZERO);
356 mp->mnt_data = (qaddr_t)pmp;
358 kmalloc_create(&pmp->mmsg, "HAMMER2-pfsmsg");
359 lockinit(&pmp->msglk, "h2msg", 0, 0);
360 TAILQ_INIT(&pmp->msgq);
361 RB_INIT(&pmp->staterd_tree);
362 RB_INIT(&pmp->statewr_tree);
365 hmp = kmalloc(sizeof(*hmp), M_HAMMER2, M_WAITOK | M_ZERO);
368 kmalloc_create(&hmp->minode, "HAMMER2-inodes");
369 kmalloc_create(&hmp->mchain, "HAMMER2-chains");
370 TAILQ_INSERT_TAIL(&hammer2_mntlist, hmp, mntentry);
372 ccms_domain_init(&pmp->ccms_dom);
374 pmp->router.pmp = pmp;
376 lockmgr(&hammer2_mntlk, LK_RELEASE);
377 kprintf("hammer2_mount hmp=%p pmpcnt=%d\n", hmp, hmp->pmp_count);
379 mp->mnt_flag = MNT_LOCAL;
380 mp->mnt_kern_flag |= MNTK_ALL_MPSAFE; /* all entry pts are SMP */
384 * vchain setup. vchain.data is special cased to NULL.
385 * vchain.refs is initialized and will never drop to 0.
387 hmp->vchain.refs = 1;
388 hmp->vchain.data = (void *)&hmp->voldata;
389 hmp->vchain.bref.type = HAMMER2_BREF_TYPE_VOLUME;
390 hmp->vchain.bref.data_off = 0 | HAMMER2_PBUFRADIX;
391 hmp->vchain.bref_flush = hmp->vchain.bref;
392 ccms_cst_init(&hmp->vchain.cst, NULL);
393 /* hmp->vchain.u.xxx is left NULL */
394 lockinit(&hmp->alloclk, "h2alloc", 0, 0);
395 lockinit(&hmp->voldatalk, "voldata", 0, LK_CANRECURSE);
398 * Install the volume header
400 error = hammer2_install_volume_header(hmp);
402 hammer2_vfs_unmount(mp, MNT_FORCE);
408 * required mount structure initializations
410 mp->mnt_stat.f_iosize = HAMMER2_PBUFSIZE;
411 mp->mnt_stat.f_bsize = HAMMER2_PBUFSIZE;
413 mp->mnt_vstat.f_frsize = HAMMER2_PBUFSIZE;
414 mp->mnt_vstat.f_bsize = HAMMER2_PBUFSIZE;
419 mp->mnt_iosize_max = MAXPHYS;
422 * First locate the super-root inode, which is key 0 relative to the
423 * volume header's blockset.
425 * Then locate the root inode by scanning the directory keyspace
426 * represented by the label.
429 parent = &hmp->vchain;
430 hammer2_chain_lock(hmp, parent, HAMMER2_RESOLVE_ALWAYS);
431 schain = hammer2_chain_lookup(hmp, &parent,
432 HAMMER2_SROOT_KEY, HAMMER2_SROOT_KEY, 0);
433 hammer2_chain_unlock(hmp, parent);
434 if (schain == NULL) {
435 kprintf("hammer2_mount: invalid super-root\n");
436 hammer2_vfs_unmount(mp, MNT_FORCE);
439 hammer2_chain_ref(hmp, schain); /* for hmp->schain */
440 hmp->schain = schain; /* left locked */
442 schain = hmp->schain;
443 hammer2_chain_lock(hmp, schain, HAMMER2_RESOLVE_ALWAYS);
447 lhc = hammer2_dirhash(label, strlen(label));
448 rchain = hammer2_chain_lookup(hmp, &parent,
449 lhc, lhc + HAMMER2_DIRHASH_LOMASK,
452 if (rchain->bref.type == HAMMER2_BREF_TYPE_INODE &&
454 strcmp(label, rchain->data->ipdata.filename) == 0) {
457 rchain = hammer2_chain_next(hmp, &parent, rchain,
458 lhc, lhc + HAMMER2_DIRHASH_LOMASK,
461 hammer2_chain_unlock(hmp, parent);
462 if (rchain == NULL) {
463 kprintf("hammer2_mount: PFS label not found\n");
464 hammer2_vfs_unmount(mp, MNT_FORCE);
467 if (rchain->flags & HAMMER2_CHAIN_MOUNTED) {
468 hammer2_chain_unlock(hmp, rchain);
469 kprintf("hammer2_mount: PFS label already mounted!\n");
470 hammer2_vfs_unmount(mp, MNT_FORCE);
473 atomic_set_int(&rchain->flags, HAMMER2_CHAIN_MOUNTED);
475 hammer2_chain_ref(hmp, rchain); /* for pmp->rchain */
476 hammer2_chain_unlock(hmp, rchain);
477 pmp->rchain = rchain; /* left held & unlocked */
478 pmp->iroot = rchain->u.ip; /* implied hold from rchain */
479 pmp->iroot->pmp = pmp;
481 kprintf("iroot %p\n", pmp->iroot);
484 * Ref the cluster management messaging descriptor. The mount
485 * program deals with the other end of the communications pipe.
487 pmp->msg_fp = holdfp(curproc->p_fd, info.cluster_fd, -1);
488 if (pmp->msg_fp == NULL) {
489 kprintf("hammer2_mount: bad cluster_fd!\n");
490 hammer2_vfs_unmount(mp, MNT_FORCE);
493 lwkt_create(hammer2_cluster_thread_rd, pmp, &pmp->msgrd_td,
494 NULL, 0, -1, "hammer2-msgrd");
495 lwkt_create(hammer2_cluster_thread_wr, pmp, &pmp->msgwr_td,
496 NULL, 0, -1, "hammer2-msgwr");
502 vfs_add_vnodeops(mp, &hammer2_vnode_vops, &mp->mnt_vn_norm_ops);
503 vfs_add_vnodeops(mp, &hammer2_spec_vops, &mp->mnt_vn_spec_ops);
504 vfs_add_vnodeops(mp, &hammer2_fifo_vops, &mp->mnt_vn_fifo_ops);
506 copyinstr(info.volume, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
507 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
508 bzero(mp->mnt_stat.f_mntonname, sizeof(mp->mnt_stat.f_mntonname));
509 copyinstr(path, mp->mnt_stat.f_mntonname,
510 sizeof(mp->mnt_stat.f_mntonname) - 1,
514 * Initial statfs to prime mnt_stat.
516 hammer2_vfs_statfs(mp, &mp->mnt_stat, cred);
523 hammer2_remount(struct mount *mp, char *path, struct vnode *devvp,
531 hammer2_vfs_unmount(struct mount *mp, int mntflags)
533 hammer2_pfsmount_t *pmp;
534 hammer2_mount_t *hmp;
537 int ronly = ((mp->mnt_flag & MNT_RDONLY) != 0);
544 if (mntflags & MNT_FORCE)
547 hammer2_mount_exlock(hmp);
550 * If mount initialization proceeded far enough we must flush
554 error = vflush(mp, 0, flags);
559 lockmgr(&hammer2_mntlk, LK_EXCLUSIVE);
561 kprintf("hammer2_unmount hmp=%p pmpcnt=%d\n", hmp, hmp->pmp_count);
564 * Flush any left over chains. The voldata lock is only used
565 * to synchronize against HAMMER2_CHAIN_MODIFIED_AUX.
567 hammer2_voldata_lock(hmp);
568 if (hmp->vchain.flags & (HAMMER2_CHAIN_MODIFIED |
569 HAMMER2_CHAIN_MODIFIED_AUX |
570 HAMMER2_CHAIN_SUBMODIFIED)) {
571 hammer2_voldata_unlock(hmp);
572 hammer2_vfs_sync(mp, MNT_WAIT);
574 hammer2_voldata_unlock(hmp);
576 if (hmp->pmp_count == 0) {
577 if (hmp->vchain.flags & (HAMMER2_CHAIN_MODIFIED |
578 HAMMER2_CHAIN_MODIFIED_AUX |
579 HAMMER2_CHAIN_SUBMODIFIED)) {
580 kprintf("hammer2_unmount: chains left over after "
582 if (hammer2_debug & 0x0010)
583 Debugger("entered debugger");
588 * Cleanup the root and super-root chain elements (which should be
593 atomic_clear_int(&pmp->rchain->flags, HAMMER2_CHAIN_MOUNTED);
594 KKASSERT(pmp->rchain->refs == 1);
595 hammer2_chain_drop(hmp, pmp->rchain);
598 ccms_domain_uninit(&pmp->ccms_dom);
601 * Ask the cluster controller to go away
603 atomic_set_int(&pmp->msg_ctl, HAMMER2_CLUSTERCTL_KILL);
604 while (pmp->msgrd_td || pmp->msgwr_td) {
605 wakeup(&pmp->msg_ctl);
606 tsleep(pmp, 0, "clstrkl", hz);
610 * Drop communications descriptor
618 * If no PFS's left drop the master hammer2_mount for the device.
620 if (hmp->pmp_count == 0) {
622 KKASSERT(hmp->schain->refs == 1);
623 hammer2_chain_drop(hmp, hmp->schain);
628 * Finish up with the device vnode
630 if ((devvp = hmp->devvp) != NULL) {
631 vinvalbuf(devvp, (ronly ? 0 : V_SAVE), 0, 0);
633 VOP_CLOSE(devvp, (ronly ? FREAD : FREAD|FWRITE));
638 hammer2_mount_unlock(hmp);
644 kmalloc_destroy(&pmp->mmsg);
646 kfree(pmp, M_HAMMER2);
647 if (hmp->pmp_count == 0) {
648 TAILQ_REMOVE(&hammer2_mntlist, hmp, mntentry);
649 kmalloc_destroy(&hmp->minode);
650 kmalloc_destroy(&hmp->mchain);
651 kfree(hmp, M_HAMMER2);
653 lockmgr(&hammer2_mntlk, LK_RELEASE);
659 hammer2_vfs_vget(struct mount *mp, struct vnode *dvp,
660 ino_t ino, struct vnode **vpp)
662 kprintf("hammer2_vget\n");
668 hammer2_vfs_root(struct mount *mp, struct vnode **vpp)
670 hammer2_pfsmount_t *pmp;
671 hammer2_mount_t *hmp;
677 hammer2_mount_exlock(hmp);
678 if (pmp->iroot == NULL) {
682 hammer2_chain_lock(hmp, &pmp->iroot->chain,
683 HAMMER2_RESOLVE_ALWAYS |
684 HAMMER2_RESOLVE_SHARED);
685 vp = hammer2_igetv(pmp->iroot, &error);
686 hammer2_chain_unlock(hmp, &pmp->iroot->chain);
689 kprintf("vnodefail\n");
691 hammer2_mount_unlock(hmp);
699 * XXX incorporate pmp->iroot->ip_data.inode_quota and data_quota
703 hammer2_vfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
705 hammer2_pfsmount_t *pmp;
706 hammer2_mount_t *hmp;
711 mp->mnt_stat.f_files = pmp->iroot->ip_data.inode_count +
712 pmp->iroot->delta_icount;
713 mp->mnt_stat.f_ffree = 0;
714 mp->mnt_stat.f_blocks = hmp->voldata.allocator_size / HAMMER2_PBUFSIZE;
715 mp->mnt_stat.f_bfree = (hmp->voldata.allocator_size -
716 hmp->voldata.allocator_beg) / HAMMER2_PBUFSIZE;
717 mp->mnt_stat.f_bavail = mp->mnt_stat.f_bfree;
725 hammer2_vfs_statvfs(struct mount *mp, struct statvfs *sbp, struct ucred *cred)
727 hammer2_pfsmount_t *pmp;
728 hammer2_mount_t *hmp;
733 mp->mnt_vstat.f_bsize = HAMMER2_PBUFSIZE;
734 mp->mnt_vstat.f_files = pmp->iroot->ip_data.inode_count +
735 pmp->iroot->delta_icount;
736 mp->mnt_vstat.f_ffree = 0;
737 mp->mnt_vstat.f_blocks = hmp->voldata.allocator_size / HAMMER2_PBUFSIZE;
738 mp->mnt_vstat.f_bfree = (hmp->voldata.allocator_size -
739 hmp->voldata.allocator_beg) / HAMMER2_PBUFSIZE;
740 mp->mnt_vstat.f_bavail = mp->mnt_vstat.f_bfree;
742 *sbp = mp->mnt_vstat;
747 * Sync the entire filesystem; this is called from the filesystem syncer
748 * process periodically and whenever a user calls sync(1) on the hammer
751 * Currently is actually called from the syncer! \o/
753 * This task will have to snapshot the state of the dirty inode chain.
754 * From that, it will have to make sure all of the inodes on the dirty
755 * chain have IO initiated. We make sure that io is initiated for the root
758 * If waitfor is set, we wait for media to acknowledge the new rootblock.
760 * THINKS: side A vs side B, to have sync not stall all I/O?
764 hammer2_vfs_sync(struct mount *mp, int waitfor)
766 struct hammer2_sync_info info;
767 hammer2_mount_t *hmp;
775 if (waitfor & MNT_LAZY)
776 flags |= VMSC_ONEPASS;
779 info.waitfor = MNT_NOWAIT;
780 vmntvnodescan(mp, flags | VMSC_NOWAIT,
782 hammer2_sync_scan2, &info);
783 if (info.error == 0 && (waitfor & MNT_WAIT)) {
784 info.waitfor = waitfor;
785 vmntvnodescan(mp, flags,
787 hammer2_sync_scan2, &info);
791 if (waitfor == MNT_WAIT) {
797 hammer2_chain_lock(hmp, &hmp->vchain, HAMMER2_RESOLVE_ALWAYS);
798 if (hmp->vchain.flags & (HAMMER2_CHAIN_MODIFIED |
799 HAMMER2_CHAIN_MODIFIED_AUX |
800 HAMMER2_CHAIN_SUBMODIFIED)) {
801 hammer2_chain_flush(hmp, &hmp->vchain, 0);
806 hammer2_chain_unlock(hmp, &hmp->vchain);
810 if ((waitfor & MNT_LAZY) == 0) {
811 waitfor = MNT_NOWAIT;
812 vn_lock(hmp->devvp, LK_EXCLUSIVE | LK_RETRY);
813 error = VOP_FSYNC(hmp->devvp, waitfor, 0);
814 vn_unlock(hmp->devvp);
817 if (error == 0 && haswork) {
821 * Synchronize the disk before flushing the volume
825 bp->b_bio1.bio_offset = 0;
828 bp->b_cmd = BUF_CMD_FLUSH;
829 bp->b_bio1.bio_done = biodone_sync;
830 bp->b_bio1.bio_flags |= BIO_SYNC;
831 vn_strategy(hmp->devvp, &bp->b_bio1);
832 biowait(&bp->b_bio1, "h2vol");
836 * Then we can safely flush the volume header. Volume
837 * data is locked separately to prevent ioctl functions
838 * from deadlocking due to a configuration issue.
840 bp = getblk(hmp->devvp, 0, HAMMER2_PBUFSIZE, 0, 0);
841 hammer2_voldata_lock(hmp);
842 bcopy(&hmp->voldata, bp->b_data, HAMMER2_PBUFSIZE);
843 hammer2_voldata_unlock(hmp);
852 * NOTE: We don't test SUBMODIFIED or MOVED here because the fsync code
853 * won't flush on those flags. The syncer code above will do a
854 * general meta-data flush globally that will catch these flags.
857 hammer2_sync_scan1(struct mount *mp, struct vnode *vp, void *data)
862 if (vp->v_type == VNON || ip == NULL ||
863 ((ip->chain.flags & (HAMMER2_CHAIN_MODIFIED |
864 HAMMER2_CHAIN_DIRTYEMBED)) == 0 &&
865 RB_EMPTY(&vp->v_rbdirty_tree))) {
872 hammer2_sync_scan2(struct mount *mp, struct vnode *vp, void *data)
874 struct hammer2_sync_info *info = data;
879 if (vp->v_type == VNON || vp->v_type == VBAD ||
880 ((ip->chain.flags & (HAMMER2_CHAIN_MODIFIED |
881 HAMMER2_CHAIN_DIRTYEMBED)) == 0 &&
882 RB_EMPTY(&vp->v_rbdirty_tree))) {
885 error = VOP_FSYNC(vp, MNT_NOWAIT, 0);
893 hammer2_vfs_vptofh(struct vnode *vp, struct fid *fhp)
900 hammer2_vfs_fhtovp(struct mount *mp, struct vnode *rootvp,
901 struct fid *fhp, struct vnode **vpp)
908 hammer2_vfs_checkexp(struct mount *mp, struct sockaddr *nam,
909 int *exflagsp, struct ucred **credanonp)
915 * Support code for hammer2_mount(). Read, verify, and install the volume
916 * header into the HMP
918 * XXX read four volhdrs and use the one with the highest TID whos CRC
923 * XXX For filesystems w/ less than 4 volhdrs, make sure to not write to
924 * nonexistant locations.
926 * XXX Record selected volhdr and ring updates to each of 4 volhdrs
930 hammer2_install_volume_header(hammer2_mount_t *hmp)
932 hammer2_volume_data_t *vd;
934 hammer2_crc32_t crc0, crc, bcrc0, bcrc;
946 * There are up to 4 copies of the volume header (syncs iterate
947 * between them so there is no single master). We don't trust the
948 * volu_size field so we don't know precisely how large the filesystem
949 * is, so depend on the OS to return an error if we go beyond the
950 * block device's EOF.
952 for (i = 0; i < HAMMER2_NUM_VOLHDRS; i++) {
953 error = bread(hmp->devvp, i * HAMMER2_ZONE_BYTES64,
954 HAMMER2_VOLUME_BYTES, &bp);
961 vd = (struct hammer2_volume_data *) bp->b_data;
962 if ((vd->magic != HAMMER2_VOLUME_ID_HBO) &&
963 (vd->magic != HAMMER2_VOLUME_ID_ABO)) {
969 if (vd->magic == HAMMER2_VOLUME_ID_ABO) {
970 /* XXX: Reversed-endianness filesystem */
971 kprintf("hammer2: reverse-endian filesystem detected");
977 crc = vd->icrc_sects[HAMMER2_VOL_ICRC_SECT0];
978 crc0 = hammer2_icrc32(bp->b_data + HAMMER2_VOLUME_ICRC0_OFF,
979 HAMMER2_VOLUME_ICRC0_SIZE);
980 bcrc = vd->icrc_sects[HAMMER2_VOL_ICRC_SECT1];
981 bcrc0 = hammer2_icrc32(bp->b_data + HAMMER2_VOLUME_ICRC1_OFF,
982 HAMMER2_VOLUME_ICRC1_SIZE);
983 if ((crc0 != crc) || (bcrc0 != bcrc)) {
984 kprintf("hammer2 volume header crc "
985 "mismatch copy #%d\t%08x %08x",
992 if (valid == 0 || hmp->voldata.mirror_tid < vd->mirror_tid) {
1002 kprintf("hammer2: a valid volume header was found\n");
1005 kprintf("hammer2: no valid volume headers found!\n");
1011 * Reconnect using the passed file pointer. The caller must ref the
1015 hammer2_cluster_reconnect(hammer2_pfsmount_t *pmp, struct file *fp)
1018 * Destroy the current connection
1020 atomic_set_int(&pmp->msg_ctl, HAMMER2_CLUSTERCTL_KILL);
1021 while (pmp->msgrd_td || pmp->msgwr_td) {
1022 wakeup(&pmp->msg_ctl);
1023 tsleep(pmp, 0, "clstrkl", hz);
1027 * Drop communications descriptor
1033 kprintf("RESTART CONNECTION\n");
1036 * Setup new communications descriptor
1041 lwkt_create(hammer2_cluster_thread_rd, pmp, &pmp->msgrd_td,
1042 NULL, 0, -1, "hammer2-msgrd");
1043 lwkt_create(hammer2_cluster_thread_wr, pmp, &pmp->msgwr_td,
1044 NULL, 0, -1, "hammer2-msgwr");
1048 * Cluster controller thread. Perform messaging functions. We have one
1049 * thread for the reader and one for the writer. The writer handles
1050 * shutdown requests (which should break the reader thread).
1054 hammer2_cluster_thread_rd(void *arg)
1056 hammer2_pfsmount_t *pmp = arg;
1057 hammer2_msg_hdr_t hdr;
1059 hammer2_state_t *state;
1063 while ((pmp->msg_ctl & HAMMER2_CLUSTERCTL_KILL) == 0) {
1065 * Retrieve the message from the pipe or socket.
1067 error = fp_read(pmp->msg_fp, &hdr, sizeof(hdr),
1068 NULL, 1, UIO_SYSSPACE);
1071 if (hdr.magic != HAMMER2_MSGHDR_MAGIC) {
1072 kprintf("hammer2: msgrd: bad magic: %04x\n",
1077 hbytes = (hdr.cmd & HAMMER2_MSGF_SIZE) * HAMMER2_MSG_ALIGN;
1078 if (hbytes < sizeof(hdr) || hbytes > HAMMER2_MSGAUX_MAX) {
1079 kprintf("hammer2: msgrd: bad header size %zd\n",
1084 /* XXX messy: mask cmd to avoid allocating state */
1085 msg = hammer2_msg_alloc(&pmp->router,
1086 hdr.cmd & HAMMER2_MSGF_BASECMDMASK,
1088 msg->any.head = hdr;
1089 msg->hdr_size = hbytes;
1090 if (hbytes > sizeof(hdr)) {
1091 error = fp_read(pmp->msg_fp, &msg->any.head + 1,
1092 hbytes - sizeof(hdr),
1093 NULL, 1, UIO_SYSSPACE);
1095 kprintf("hammer2: short msg received\n");
1100 msg->aux_size = hdr.aux_bytes * HAMMER2_MSG_ALIGN;
1101 if (msg->aux_size > HAMMER2_MSGAUX_MAX) {
1102 kprintf("hammer2: illegal msg payload size %zd\n",
1107 if (msg->aux_size) {
1108 msg->aux_data = kmalloc(msg->aux_size, pmp->mmsg,
1110 error = fp_read(pmp->msg_fp, msg->aux_data,
1112 NULL, 1, UIO_SYSSPACE);
1114 kprintf("hammer2: short msg "
1115 "payload received\n");
1121 * State machine tracking, state assignment for msg,
1122 * returns error and discard status. Errors are fatal
1123 * to the connection except for EALREADY which forces
1124 * a discard without execution.
1126 error = hammer2_state_msgrx(msg);
1129 * Raw protocol or connection error
1131 hammer2_msg_free(msg);
1132 if (error == EALREADY)
1134 } else if (msg->state && msg->state->func) {
1136 * Message related to state which already has a
1137 * handling function installed for it.
1139 error = msg->state->func(msg->state, msg);
1140 hammer2_state_cleanuprx(msg);
1141 } else if ((msg->any.head.cmd & HAMMER2_MSGF_PROTOS) ==
1142 HAMMER2_MSG_PROTO_LNK) {
1144 * Message related to the LNK protocol set
1146 error = hammer2_msg_lnk_rcvmsg(msg);
1147 hammer2_state_cleanuprx(msg);
1148 } else if ((msg->any.head.cmd & HAMMER2_MSGF_PROTOS) ==
1149 HAMMER2_MSG_PROTO_DBG) {
1151 * Message related to the DBG protocol set
1153 error = hammer2_msg_dbg_rcvmsg(msg);
1154 hammer2_state_cleanuprx(msg);
1157 * Other higher-level messages (e.g. vnops)
1159 error = hammer2_msg_adhoc_input(msg);
1160 hammer2_state_cleanuprx(msg);
1166 kprintf("hammer2: msg read failed error %d\n", error);
1168 lockmgr(&pmp->msglk, LK_EXCLUSIVE);
1170 if (msg->state && msg->state->msg == msg)
1171 msg->state->msg = NULL;
1172 hammer2_msg_free(msg);
1175 if ((state = pmp->freerd_state) != NULL) {
1176 pmp->freerd_state = NULL;
1177 hammer2_state_free(state);
1181 * Shutdown the socket before waiting for the transmit side.
1183 * If we are dying due to e.g. a socket disconnect verses being
1184 * killed explicity we have to set KILL in order to kick the tx
1185 * side when it might not have any other work to do. KILL might
1186 * already be set if we are in an unmount or reconnect.
1188 fp_shutdown(pmp->msg_fp, SHUT_RDWR);
1190 atomic_set_int(&pmp->msg_ctl, HAMMER2_CLUSTERCTL_KILL);
1191 wakeup(&pmp->msg_ctl);
1194 * Wait for the transmit side to drain remaining messages
1195 * before cleaning up the rx state. The transmit side will
1196 * set KILLTX and wait for the rx side to completely finish
1197 * (set msgrd_td to NULL) before cleaning up any remaining
1200 lockmgr(&pmp->msglk, LK_RELEASE);
1201 atomic_set_int(&pmp->msg_ctl, HAMMER2_CLUSTERCTL_KILLRX);
1202 wakeup(&pmp->msg_ctl);
1203 while ((pmp->msg_ctl & HAMMER2_CLUSTERCTL_KILLTX) == 0) {
1204 wakeup(&pmp->msg_ctl);
1205 tsleep(pmp, 0, "clstrkw", hz);
1208 pmp->msgrd_td = NULL;
1209 /* pmp can be ripped out from under us at this point */
1216 hammer2_cluster_thread_wr(void *arg)
1218 hammer2_pfsmount_t *pmp = arg;
1219 hammer2_msg_t *msg = NULL;
1220 hammer2_state_t *state;
1227 * Open a LNK_CONN transaction indicating that we want to take part
1228 * in the spanning tree algorithm. Filter explicitly on the PFS
1229 * info in the iroot.
1231 * We do not transmit our (only) LNK_SPAN until the other end has
1232 * acknowledged our link connection request.
1234 * The transaction remains fully open for the duration of the
1237 msg = hammer2_msg_alloc(&pmp->router, HAMMER2_LNK_CONN |
1238 HAMMER2_MSGF_CREATE,
1239 hammer2_msg_conn_reply, pmp);
1240 msg->any.lnk_conn.pfs_clid = pmp->iroot->ip_data.pfs_clid;
1241 msg->any.lnk_conn.pfs_fsid = pmp->iroot->ip_data.pfs_fsid;
1242 msg->any.lnk_conn.pfs_type = pmp->iroot->ip_data.pfs_type;
1243 msg->any.lnk_conn.proto_version = HAMMER2_SPAN_PROTO_1;
1244 name_len = pmp->iroot->ip_data.name_len;
1245 if (name_len >= sizeof(msg->any.lnk_conn.label))
1246 name_len = sizeof(msg->any.lnk_conn.label) - 1;
1247 bcopy(pmp->iroot->ip_data.filename, msg->any.lnk_conn.label, name_len);
1248 pmp->conn_state = msg->state;
1249 msg->any.lnk_conn.label[name_len] = 0;
1250 hammer2_msg_write(msg);
1256 lockmgr(&pmp->msglk, LK_EXCLUSIVE);
1258 while ((pmp->msg_ctl & HAMMER2_CLUSTERCTL_KILL) == 0 && error == 0) {
1260 * Sleep if no messages pending. Interlock with flag while
1263 if (TAILQ_EMPTY(&pmp->msgq)) {
1264 atomic_set_int(&pmp->msg_ctl,
1265 HAMMER2_CLUSTERCTL_SLEEPING);
1266 lksleep(&pmp->msg_ctl, &pmp->msglk, 0, "msgwr", hz);
1267 atomic_clear_int(&pmp->msg_ctl,
1268 HAMMER2_CLUSTERCTL_SLEEPING);
1271 while ((msg = TAILQ_FIRST(&pmp->msgq)) != NULL) {
1273 * Remove msg from the transmit queue and do
1274 * persist and half-closed state handling.
1276 TAILQ_REMOVE(&pmp->msgq, msg, qentry);
1277 lockmgr(&pmp->msglk, LK_RELEASE);
1279 error = hammer2_state_msgtx(msg);
1280 if (error == EALREADY) {
1282 hammer2_msg_free(msg);
1283 lockmgr(&pmp->msglk, LK_EXCLUSIVE);
1287 hammer2_msg_free(msg);
1288 lockmgr(&pmp->msglk, LK_EXCLUSIVE);
1293 * Dump the message to the pipe or socket.
1295 error = fp_write(pmp->msg_fp, &msg->any, msg->hdr_size,
1296 &res, UIO_SYSSPACE);
1297 if (error || res != msg->hdr_size) {
1300 lockmgr(&pmp->msglk, LK_EXCLUSIVE);
1303 if (msg->aux_size) {
1304 error = fp_write(pmp->msg_fp,
1305 msg->aux_data, msg->aux_size,
1306 &res, UIO_SYSSPACE);
1307 if (error || res != msg->aux_size) {
1310 lockmgr(&pmp->msglk, LK_EXCLUSIVE);
1314 hammer2_state_cleanuptx(msg);
1315 lockmgr(&pmp->msglk, LK_EXCLUSIVE);
1320 * Cleanup messages pending transmission and release msgq lock.
1323 kprintf("hammer2: msg write failed error %d\n", error);
1326 if (msg->state && msg->state->msg == msg)
1327 msg->state->msg = NULL;
1328 hammer2_msg_free(msg);
1332 * Shutdown the socket. This will cause the rx thread to get an
1333 * EOF and ensure that both threads get to a termination state.
1335 fp_shutdown(pmp->msg_fp, SHUT_RDWR);
1338 * Set KILLTX (which the rx side waits for), then wait for the RX
1339 * side to completely finish before we clean out any remaining
1342 lockmgr(&pmp->msglk, LK_RELEASE);
1343 atomic_set_int(&pmp->msg_ctl, HAMMER2_CLUSTERCTL_KILLTX);
1344 wakeup(&pmp->msg_ctl);
1345 while (pmp->msgrd_td) {
1346 wakeup(&pmp->msg_ctl);
1347 tsleep(pmp, 0, "clstrkw", hz);
1349 lockmgr(&pmp->msglk, LK_EXCLUSIVE);
1352 * Simulate received MSGF_DELETE's for any remaining states.
1355 RB_FOREACH(state, hammer2_state_tree, &pmp->staterd_tree) {
1357 (state->rxcmd & HAMMER2_MSGF_DELETE) == 0) {
1358 lockmgr(&pmp->msglk, LK_RELEASE);
1359 msg = hammer2_msg_alloc(&pmp->router,
1362 if ((state->rxcmd & HAMMER2_MSGF_CREATE) == 0)
1363 msg->any.head.cmd |= HAMMER2_MSGF_CREATE;
1364 msg->any.head.cmd |= HAMMER2_MSGF_DELETE;
1366 state->rxcmd = msg->any.head.cmd &
1367 ~HAMMER2_MSGF_DELETE;
1368 msg->state->func(state, msg);
1369 hammer2_state_cleanuprx(msg);
1370 lockmgr(&pmp->msglk, LK_EXCLUSIVE);
1373 if (state->func == NULL) {
1374 state->flags &= ~HAMMER2_STATE_INSERTED;
1375 RB_REMOVE(hammer2_state_tree,
1376 &pmp->staterd_tree, state);
1377 hammer2_state_free(state);
1383 * NOTE: We have to drain the msgq to handle situations
1384 * where received states have built up output
1385 * messages, to avoid creating messages with
1386 * duplicate CREATE/DELETE flags.
1389 hammer2_drain_msgq(pmp);
1390 RB_FOREACH(state, hammer2_state_tree, &pmp->statewr_tree) {
1392 (state->rxcmd & HAMMER2_MSGF_DELETE) == 0) {
1393 lockmgr(&pmp->msglk, LK_RELEASE);
1394 msg = hammer2_msg_alloc(&pmp->router,
1397 if ((state->rxcmd & HAMMER2_MSGF_CREATE) == 0)
1398 msg->any.head.cmd |= HAMMER2_MSGF_CREATE;
1399 msg->any.head.cmd |= HAMMER2_MSGF_DELETE |
1402 state->rxcmd = msg->any.head.cmd &
1403 ~HAMMER2_MSGF_DELETE;
1404 msg->state->func(state, msg);
1405 hammer2_state_cleanuprx(msg);
1406 lockmgr(&pmp->msglk, LK_EXCLUSIVE);
1409 if (state->func == NULL) {
1410 state->flags &= ~HAMMER2_STATE_INSERTED;
1411 RB_REMOVE(hammer2_state_tree,
1412 &pmp->statewr_tree, state);
1413 hammer2_state_free(state);
1418 hammer2_drain_msgq(pmp);
1420 panic("hammer2: comm thread shutdown couldn't drain");
1421 if (RB_ROOT(&pmp->statewr_tree))
1424 if ((state = pmp->freewr_state) != NULL) {
1425 pmp->freewr_state = NULL;
1426 hammer2_state_free(state);
1429 lockmgr(&pmp->msglk, LK_RELEASE);
1432 * The state trees had better be empty now
1434 KKASSERT(RB_EMPTY(&pmp->staterd_tree));
1435 KKASSERT(RB_EMPTY(&pmp->statewr_tree));
1436 KKASSERT(pmp->conn_state == NULL);
1439 * pmp can be ripped out from under us once msgwr_td is set to NULL.
1441 pmp->msgwr_td = NULL;
1447 * This cleans out the pending transmit message queue, adjusting any
1448 * persistent states properly in the process.
1450 * Caller must hold pmp->msglk
1454 hammer2_drain_msgq(hammer2_pfsmount_t *pmp)
1459 * Clean out our pending transmit queue, executing the
1460 * appropriate state adjustments. If this tries to open
1461 * any new outgoing transactions we have to loop up and
1464 while ((msg = TAILQ_FIRST(&pmp->msgq)) != NULL) {
1465 TAILQ_REMOVE(&pmp->msgq, msg, qentry);
1466 lockmgr(&pmp->msglk, LK_RELEASE);
1467 if (msg->state && msg->state->msg == msg)
1468 msg->state->msg = NULL;
1469 if (hammer2_state_msgtx(msg))
1470 hammer2_msg_free(msg);
1472 hammer2_state_cleanuptx(msg);
1473 lockmgr(&pmp->msglk, LK_EXCLUSIVE);
1478 * Called with msglk held after queueing a new message, wakes up the
1479 * transmit thread. We use an interlock thread to avoid unnecessary
1483 hammer2_clusterctl_wakeup(hammer2_pfsmount_t *pmp)
1485 if (pmp->msg_ctl & HAMMER2_CLUSTERCTL_SLEEPING) {
1486 atomic_clear_int(&pmp->msg_ctl, HAMMER2_CLUSTERCTL_SLEEPING);
1487 wakeup(&pmp->msg_ctl);
1492 hammer2_msg_lnk_rcvmsg(hammer2_msg_t *msg)
1494 switch(msg->any.head.cmd & HAMMER2_MSGF_TRANSMASK) {
1495 case HAMMER2_LNK_CONN | HAMMER2_MSGF_CREATE:
1497 * reply & leave trans open
1499 kprintf("CONN RECEIVE - (just ignore it)\n");
1500 hammer2_msg_result(msg, 0);
1502 case HAMMER2_LNK_SPAN | HAMMER2_MSGF_CREATE:
1503 kprintf("SPAN RECEIVE - ADDED FROM CLUSTER\n");
1505 case HAMMER2_LNK_SPAN | HAMMER2_MSGF_DELETE:
1506 kprintf("SPAN RECEIVE - DELETED FROM CLUSTER\n");
1515 * This function is called when the other end replies to our LNK_CONN
1518 * We transmit our (single) SPAN on the initial reply, leaving that
1519 * transaction open too.
1522 hammer2_msg_conn_reply(hammer2_state_t *state, hammer2_msg_t *msg)
1524 hammer2_pfsmount_t *pmp = state->any.pmp;
1525 hammer2_mount_t *hmp = pmp->hmp;
1526 hammer2_msg_t *rmsg;
1530 kprintf("LNK_CONN REPLY RECEIVED CMD %08x\n", msg->any.head.cmd);
1532 if (msg->any.head.cmd & HAMMER2_MSGF_CREATE) {
1533 kprintf("LNK_CONN transaction replied to, initiate SPAN\n");
1534 rmsg = hammer2_msg_alloc(&pmp->router, HAMMER2_LNK_SPAN |
1535 HAMMER2_MSGF_CREATE,
1536 hammer2_msg_span_reply, pmp);
1537 rmsg->any.lnk_span.pfs_clid = pmp->iroot->ip_data.pfs_clid;
1538 rmsg->any.lnk_span.pfs_fsid = pmp->iroot->ip_data.pfs_fsid;
1539 rmsg->any.lnk_span.pfs_type = pmp->iroot->ip_data.pfs_type;
1540 rmsg->any.lnk_span.proto_version = HAMMER2_SPAN_PROTO_1;
1541 name_len = pmp->iroot->ip_data.name_len;
1542 if (name_len >= sizeof(rmsg->any.lnk_span.label))
1543 name_len = sizeof(rmsg->any.lnk_span.label) - 1;
1544 bcopy(pmp->iroot->ip_data.filename,
1545 rmsg->any.lnk_span.label,
1547 rmsg->any.lnk_span.label[name_len] = 0;
1548 hammer2_msg_write(rmsg);
1551 * Dump the configuration stored in the volume header
1553 hammer2_voldata_lock(hmp);
1554 for (copyid = 0; copyid < HAMMER2_COPYID_COUNT; ++copyid) {
1555 if (hmp->voldata.copyinfo[copyid].copyid == 0)
1557 hammer2_volconf_update(pmp, copyid);
1559 hammer2_voldata_unlock(hmp);
1561 if ((state->txcmd & HAMMER2_MSGF_DELETE) == 0 &&
1562 (msg->any.head.cmd & HAMMER2_MSGF_DELETE)) {
1563 kprintf("LNK_CONN transaction terminated by remote\n");
1564 pmp->conn_state = NULL;
1565 hammer2_msg_reply(msg, 0);
1571 * Remote terminated our span transaction. We have to terminate our side.
1574 hammer2_msg_span_reply(hammer2_state_t *state, hammer2_msg_t *msg)
1576 hammer2_pfsmount_t *pmp = state->any.pmp;
1578 kprintf("SPAN REPLY - Our sent span was terminated by the remote %08x state %p\n", msg->any.head.cmd, state);
1579 if ((state->txcmd & HAMMER2_MSGF_DELETE) == 0 &&
1580 (msg->any.head.cmd & HAMMER2_MSGF_DELETE)) {
1581 hammer2_msg_reply(msg, 0);
1587 * Volume configuration updates are passed onto the userland service
1588 * daemon via the open LNK_CONN transaction.
1591 hammer2_volconf_update(hammer2_pfsmount_t *pmp, int index)
1593 hammer2_mount_t *hmp = pmp->hmp;
1596 /* XXX interlock against connection state termination */
1597 kprintf("volconf update %p\n", pmp->conn_state);
1598 if (pmp->conn_state) {
1599 kprintf("TRANSMIT VOLCONF VIA OPEN CONN TRANSACTION\n");
1600 msg = hammer2_msg_alloc(&pmp->router, HAMMER2_LNK_VOLCONF,
1602 msg->state = pmp->conn_state;
1603 msg->any.lnk_volconf.copy = hmp->voldata.copyinfo[index];
1604 msg->any.lnk_volconf.mediaid = hmp->voldata.fsid;
1605 msg->any.lnk_volconf.index = index;
1606 hammer2_msg_write(msg);