2 * Copyright (c) 2007-2008 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sys/vfs/hammer/hammer_inode.c,v 1.114 2008/09/24 00:53:51 dillon Exp $
38 #include <vm/vm_extern.h>
40 static int hammer_unload_inode(struct hammer_inode *ip);
41 static void hammer_free_inode(hammer_inode_t ip);
42 static void hammer_flush_inode_core(hammer_inode_t ip,
43 hammer_flush_group_t flg, int flags);
44 static int hammer_setup_child_callback(hammer_record_t rec, void *data);
46 static int hammer_syncgrp_child_callback(hammer_record_t rec, void *data);
48 static int hammer_setup_parent_inodes(hammer_inode_t ip, int depth,
49 hammer_flush_group_t flg);
50 static int hammer_setup_parent_inodes_helper(hammer_record_t record,
51 int depth, hammer_flush_group_t flg);
52 static void hammer_inode_wakereclaims(hammer_inode_t ip);
55 extern struct hammer_inode *HammerTruncIp;
59 * RB-Tree support for inode structures
62 hammer_ino_rb_compare(hammer_inode_t ip1, hammer_inode_t ip2)
64 if (ip1->obj_localization < ip2->obj_localization)
66 if (ip1->obj_localization > ip2->obj_localization)
68 if (ip1->obj_id < ip2->obj_id)
70 if (ip1->obj_id > ip2->obj_id)
72 if (ip1->obj_asof < ip2->obj_asof)
74 if (ip1->obj_asof > ip2->obj_asof)
80 hammer_redo_rb_compare(hammer_inode_t ip1, hammer_inode_t ip2)
82 if (ip1->redo_fifo_start < ip2->redo_fifo_start)
84 if (ip1->redo_fifo_start > ip2->redo_fifo_start)
90 * RB-Tree support for inode structures / special LOOKUP_INFO
93 hammer_inode_info_cmp(hammer_inode_info_t info, hammer_inode_t ip)
95 if (info->obj_localization < ip->obj_localization)
97 if (info->obj_localization > ip->obj_localization)
99 if (info->obj_id < ip->obj_id)
101 if (info->obj_id > ip->obj_id)
103 if (info->obj_asof < ip->obj_asof)
105 if (info->obj_asof > ip->obj_asof)
111 * Used by hammer_scan_inode_snapshots() to locate all of an object's
112 * snapshots. Note that the asof field is not tested, which we can get
113 * away with because it is the lowest-priority field.
116 hammer_inode_info_cmp_all_history(hammer_inode_t ip, void *data)
118 hammer_inode_info_t info = data;
120 if (ip->obj_localization > info->obj_localization)
122 if (ip->obj_localization < info->obj_localization)
124 if (ip->obj_id > info->obj_id)
126 if (ip->obj_id < info->obj_id)
132 * Used by hammer_unload_pseudofs() to locate all inodes associated with
136 hammer_inode_pfs_cmp(hammer_inode_t ip, void *data)
138 u_int32_t localization = *(u_int32_t *)data;
139 if (ip->obj_localization > localization)
141 if (ip->obj_localization < localization)
147 * RB-Tree support for pseudofs structures
150 hammer_pfs_rb_compare(hammer_pseudofs_inmem_t p1, hammer_pseudofs_inmem_t p2)
152 if (p1->localization < p2->localization)
154 if (p1->localization > p2->localization)
160 RB_GENERATE(hammer_ino_rb_tree, hammer_inode, rb_node, hammer_ino_rb_compare);
161 RB_GENERATE_XLOOKUP(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
162 hammer_inode_info_cmp, hammer_inode_info_t);
163 RB_GENERATE2(hammer_pfs_rb_tree, hammer_pseudofs_inmem, rb_node,
164 hammer_pfs_rb_compare, u_int32_t, localization);
167 * The kernel is not actively referencing this vnode but is still holding
170 * This is called from the frontend.
175 hammer_vop_inactive(struct vop_inactive_args *ap)
177 struct hammer_inode *ip = VTOI(ap->a_vp);
188 * If the inode no longer has visibility in the filesystem try to
189 * recycle it immediately, even if the inode is dirty. Recycling
190 * it quickly allows the system to reclaim buffer cache and VM
191 * resources which can matter a lot in a heavily loaded system.
193 * This can deadlock in vfsync() if we aren't careful.
195 * Do not queue the inode to the flusher if we still have visibility,
196 * otherwise namespace calls such as chmod will unnecessarily generate
197 * multiple inode updates.
199 if (ip->ino_data.nlinks == 0) {
201 hammer_inode_unloadable_check(ip, 0);
202 if (ip->flags & HAMMER_INODE_MODMASK)
203 hammer_flush_inode(ip, 0);
211 * Release the vnode association. This is typically (but not always)
212 * the last reference on the inode.
214 * Once the association is lost we are on our own with regards to
215 * flushing the inode.
217 * We must interlock ip->vp so hammer_get_vnode() can avoid races.
220 hammer_vop_reclaim(struct vop_reclaim_args *ap)
222 struct hammer_inode *ip;
228 if ((ip = vp->v_data) != NULL) {
230 hammer_lock_ex(&ip->lock);
234 if ((ip->flags & HAMMER_INODE_RECLAIM) == 0) {
235 ++hammer_count_reclaiming;
236 ++hmp->inode_reclaims;
237 ip->flags |= HAMMER_INODE_RECLAIM;
239 hammer_unlock(&ip->lock);
240 hammer_rel_inode(ip, 1);
246 * Return a locked vnode for the specified inode. The inode must be
247 * referenced but NOT LOCKED on entry and will remain referenced on
250 * Called from the frontend.
253 hammer_get_vnode(struct hammer_inode *ip, struct vnode **vpp)
263 if ((vp = ip->vp) == NULL) {
264 error = getnewvnode(VT_HAMMER, hmp->mp, vpp, 0, 0);
267 hammer_lock_ex(&ip->lock);
268 if (ip->vp != NULL) {
269 hammer_unlock(&ip->lock);
275 hammer_ref(&ip->lock);
279 obj_type = ip->ino_data.obj_type;
280 vp->v_type = hammer_get_vnode_type(obj_type);
282 hammer_inode_wakereclaims(ip);
284 switch(ip->ino_data.obj_type) {
285 case HAMMER_OBJTYPE_CDEV:
286 case HAMMER_OBJTYPE_BDEV:
287 vp->v_ops = &hmp->mp->mnt_vn_spec_ops;
288 addaliasu(vp, ip->ino_data.rmajor,
289 ip->ino_data.rminor);
291 case HAMMER_OBJTYPE_FIFO:
292 vp->v_ops = &hmp->mp->mnt_vn_fifo_ops;
294 case HAMMER_OBJTYPE_REGFILE:
301 * Only mark as the root vnode if the ip is not
302 * historical, otherwise the VFS cache will get
303 * confused. The other half of the special handling
304 * is in hammer_vop_nlookupdotdot().
306 * Pseudo-filesystem roots can be accessed via
307 * non-root filesystem paths and setting VROOT may
308 * confuse the namecache. Set VPFSROOT instead.
310 if (ip->obj_id == HAMMER_OBJID_ROOT &&
311 ip->obj_asof == hmp->asof) {
312 if (ip->obj_localization == 0)
313 vsetflags(vp, VROOT);
315 vsetflags(vp, VPFSROOT);
318 vp->v_data = (void *)ip;
319 /* vnode locked by getnewvnode() */
320 /* make related vnode dirty if inode dirty? */
321 hammer_unlock(&ip->lock);
322 if (vp->v_type == VREG)
323 vinitvmio(vp, ip->ino_data.size);
328 * Interlock vnode clearing. This does not prevent the
329 * vnode from going into a reclaimed state but it does
330 * prevent it from being destroyed or reused so the vget()
331 * will properly fail.
333 hammer_lock_ex(&ip->lock);
334 if ((vp = ip->vp) == NULL) {
335 hammer_unlock(&ip->lock);
338 vhold_interlocked(vp);
339 hammer_unlock(&ip->lock);
342 * loop if the vget fails (aka races), or if the vp
343 * no longer matches ip->vp.
345 if (vget(vp, LK_EXCLUSIVE) == 0) {
359 * Locate all copies of the inode for obj_id compatible with the specified
360 * asof, reference, and issue the related call-back. This routine is used
361 * for direct-io invalidation and does not create any new inodes.
364 hammer_scan_inode_snapshots(hammer_mount_t hmp, hammer_inode_info_t iinfo,
365 int (*callback)(hammer_inode_t ip, void *data),
368 hammer_ino_rb_tree_RB_SCAN(&hmp->rb_inos_root,
369 hammer_inode_info_cmp_all_history,
374 * Acquire a HAMMER inode. The returned inode is not locked. These functions
375 * do not attach or detach the related vnode (use hammer_get_vnode() for
378 * The flags argument is only applied for newly created inodes, and only
379 * certain flags are inherited.
381 * Called from the frontend.
383 struct hammer_inode *
384 hammer_get_inode(hammer_transaction_t trans, hammer_inode_t dip,
385 int64_t obj_id, hammer_tid_t asof, u_int32_t localization,
386 int flags, int *errorp)
388 hammer_mount_t hmp = trans->hmp;
389 struct hammer_node_cache *cachep;
390 struct hammer_inode_info iinfo;
391 struct hammer_cursor cursor;
392 struct hammer_inode *ip;
396 * Determine if we already have an inode cached. If we do then
399 * If we find an inode with no vnode we have to mark the
400 * transaction such that hammer_inode_waitreclaims() is
401 * called later on to avoid building up an infinite number
402 * of inodes. Otherwise we can continue to * add new inodes
403 * faster then they can be disposed of, even with the tsleep
406 * If we find a dummy inode we return a failure so dounlink
407 * (which does another lookup) doesn't try to mess with the
408 * link count. hammer_vop_nresolve() uses hammer_get_dummy_inode()
409 * to ref dummy inodes.
411 iinfo.obj_id = obj_id;
412 iinfo.obj_asof = asof;
413 iinfo.obj_localization = localization;
415 ip = hammer_ino_rb_tree_RB_LOOKUP_INFO(&hmp->rb_inos_root, &iinfo);
417 if (ip->flags & HAMMER_INODE_DUMMY) {
421 hammer_ref(&ip->lock);
427 * Allocate a new inode structure and deal with races later.
429 ip = kmalloc(sizeof(*ip), hmp->m_inodes, M_WAITOK|M_ZERO);
430 ++hammer_count_inodes;
433 ip->obj_asof = iinfo.obj_asof;
434 ip->obj_localization = localization;
436 ip->flags = flags & HAMMER_INODE_RO;
437 ip->cache[0].ip = ip;
438 ip->cache[1].ip = ip;
439 ip->cache[2].ip = ip;
440 ip->cache[3].ip = ip;
442 ip->flags |= HAMMER_INODE_RO;
443 ip->sync_trunc_off = ip->trunc_off = ip->save_trunc_off =
444 0x7FFFFFFFFFFFFFFFLL;
445 RB_INIT(&ip->rec_tree);
446 TAILQ_INIT(&ip->target_list);
447 hammer_ref(&ip->lock);
450 * Locate the on-disk inode. If this is a PFS root we always
451 * access the current version of the root inode and (if it is not
452 * a master) always access information under it with a snapshot
455 * We cache recent inode lookups in this directory in dip->cache[2].
456 * If we can't find it we assume the inode we are looking for is
457 * close to the directory inode.
462 if (dip->cache[2].node)
463 cachep = &dip->cache[2];
465 cachep = &dip->cache[0];
467 hammer_init_cursor(trans, &cursor, cachep, NULL);
468 cursor.key_beg.localization = localization + HAMMER_LOCALIZE_INODE;
469 cursor.key_beg.obj_id = ip->obj_id;
470 cursor.key_beg.key = 0;
471 cursor.key_beg.create_tid = 0;
472 cursor.key_beg.delete_tid = 0;
473 cursor.key_beg.rec_type = HAMMER_RECTYPE_INODE;
474 cursor.key_beg.obj_type = 0;
476 cursor.asof = iinfo.obj_asof;
477 cursor.flags = HAMMER_CURSOR_GET_LEAF | HAMMER_CURSOR_GET_DATA |
480 *errorp = hammer_btree_lookup(&cursor);
481 if (*errorp == EDEADLK) {
482 hammer_done_cursor(&cursor);
487 * On success the B-Tree lookup will hold the appropriate
488 * buffer cache buffers and provide a pointer to the requested
489 * information. Copy the information to the in-memory inode
490 * and cache the B-Tree node to improve future operations.
493 ip->ino_leaf = cursor.node->ondisk->elms[cursor.index].leaf;
494 ip->ino_data = cursor.data->inode;
497 * cache[0] tries to cache the location of the object inode.
498 * The assumption is that it is near the directory inode.
500 * cache[1] tries to cache the location of the object data.
501 * We might have something in the governing directory from
502 * scan optimizations (see the strategy code in
505 * We update dip->cache[2], if possible, with the location
506 * of the object inode for future directory shortcuts.
508 hammer_cache_node(&ip->cache[0], cursor.node);
510 if (dip->cache[3].node) {
511 hammer_cache_node(&ip->cache[1],
514 hammer_cache_node(&dip->cache[2], cursor.node);
518 * The file should not contain any data past the file size
519 * stored in the inode. Setting save_trunc_off to the
520 * file size instead of max reduces B-Tree lookup overheads
521 * on append by allowing the flusher to avoid checking for
524 ip->save_trunc_off = ip->ino_data.size;
527 * Locate and assign the pseudofs management structure to
530 if (dip && dip->obj_localization == ip->obj_localization) {
531 ip->pfsm = dip->pfsm;
532 hammer_ref(&ip->pfsm->lock);
534 ip->pfsm = hammer_load_pseudofs(trans,
535 ip->obj_localization,
537 *errorp = 0; /* ignore ENOENT */
542 * The inode is placed on the red-black tree and will be synced to
543 * the media when flushed or by the filesystem sync. If this races
544 * another instantiation/lookup the insertion will fail.
547 if (RB_INSERT(hammer_ino_rb_tree, &hmp->rb_inos_root, ip)) {
548 hammer_free_inode(ip);
549 hammer_done_cursor(&cursor);
552 ip->flags |= HAMMER_INODE_ONDISK;
554 if (ip->flags & HAMMER_INODE_RSV_INODES) {
555 ip->flags &= ~HAMMER_INODE_RSV_INODES; /* sanity */
559 hammer_free_inode(ip);
562 hammer_done_cursor(&cursor);
563 trans->flags |= HAMMER_TRANSF_NEWINODE;
568 * Get a dummy inode to placemark a broken directory entry.
570 struct hammer_inode *
571 hammer_get_dummy_inode(hammer_transaction_t trans, hammer_inode_t dip,
572 int64_t obj_id, hammer_tid_t asof, u_int32_t localization,
573 int flags, int *errorp)
575 hammer_mount_t hmp = trans->hmp;
576 struct hammer_inode_info iinfo;
577 struct hammer_inode *ip;
580 * Determine if we already have an inode cached. If we do then
583 * If we find an inode with no vnode we have to mark the
584 * transaction such that hammer_inode_waitreclaims() is
585 * called later on to avoid building up an infinite number
586 * of inodes. Otherwise we can continue to * add new inodes
587 * faster then they can be disposed of, even with the tsleep
590 * If we find a non-fake inode we return an error. Only fake
591 * inodes can be returned by this routine.
593 iinfo.obj_id = obj_id;
594 iinfo.obj_asof = asof;
595 iinfo.obj_localization = localization;
598 ip = hammer_ino_rb_tree_RB_LOOKUP_INFO(&hmp->rb_inos_root, &iinfo);
600 if ((ip->flags & HAMMER_INODE_DUMMY) == 0) {
604 hammer_ref(&ip->lock);
609 * Allocate a new inode structure and deal with races later.
611 ip = kmalloc(sizeof(*ip), hmp->m_inodes, M_WAITOK|M_ZERO);
612 ++hammer_count_inodes;
615 ip->obj_asof = iinfo.obj_asof;
616 ip->obj_localization = localization;
618 ip->flags = flags | HAMMER_INODE_RO | HAMMER_INODE_DUMMY;
619 ip->cache[0].ip = ip;
620 ip->cache[1].ip = ip;
621 ip->cache[2].ip = ip;
622 ip->cache[3].ip = ip;
623 ip->sync_trunc_off = ip->trunc_off = ip->save_trunc_off =
624 0x7FFFFFFFFFFFFFFFLL;
625 RB_INIT(&ip->rec_tree);
626 TAILQ_INIT(&ip->target_list);
627 hammer_ref(&ip->lock);
630 * Populate the dummy inode. Leave everything zero'd out.
632 * (ip->ino_leaf and ip->ino_data)
634 * Make the dummy inode a FIFO object which most copy programs
635 * will properly ignore.
637 ip->save_trunc_off = ip->ino_data.size;
638 ip->ino_data.obj_type = HAMMER_OBJTYPE_FIFO;
641 * Locate and assign the pseudofs management structure to
644 if (dip && dip->obj_localization == ip->obj_localization) {
645 ip->pfsm = dip->pfsm;
646 hammer_ref(&ip->pfsm->lock);
648 ip->pfsm = hammer_load_pseudofs(trans, ip->obj_localization,
650 *errorp = 0; /* ignore ENOENT */
654 * The inode is placed on the red-black tree and will be synced to
655 * the media when flushed or by the filesystem sync. If this races
656 * another instantiation/lookup the insertion will fail.
658 * NOTE: Do not set HAMMER_INODE_ONDISK. The inode is a fake.
661 if (RB_INSERT(hammer_ino_rb_tree, &hmp->rb_inos_root, ip)) {
662 hammer_free_inode(ip);
666 if (ip->flags & HAMMER_INODE_RSV_INODES) {
667 ip->flags &= ~HAMMER_INODE_RSV_INODES; /* sanity */
670 hammer_free_inode(ip);
673 trans->flags |= HAMMER_TRANSF_NEWINODE;
678 * Return a referenced inode only if it is in our inode cache.
680 * Dummy inodes do not count.
682 struct hammer_inode *
683 hammer_find_inode(hammer_transaction_t trans, int64_t obj_id,
684 hammer_tid_t asof, u_int32_t localization)
686 hammer_mount_t hmp = trans->hmp;
687 struct hammer_inode_info iinfo;
688 struct hammer_inode *ip;
690 iinfo.obj_id = obj_id;
691 iinfo.obj_asof = asof;
692 iinfo.obj_localization = localization;
694 ip = hammer_ino_rb_tree_RB_LOOKUP_INFO(&hmp->rb_inos_root, &iinfo);
696 if (ip->flags & HAMMER_INODE_DUMMY)
699 hammer_ref(&ip->lock);
705 * Create a new filesystem object, returning the inode in *ipp. The
706 * returned inode will be referenced. The inode is created in-memory.
708 * If pfsm is non-NULL the caller wishes to create the root inode for
712 hammer_create_inode(hammer_transaction_t trans, struct vattr *vap,
714 hammer_inode_t dip, const char *name, int namelen,
715 hammer_pseudofs_inmem_t pfsm, struct hammer_inode **ipp)
726 ip = kmalloc(sizeof(*ip), hmp->m_inodes, M_WAITOK|M_ZERO);
727 ++hammer_count_inodes;
729 trans->flags |= HAMMER_TRANSF_NEWINODE;
732 KKASSERT(pfsm->localization != 0);
733 ip->obj_id = HAMMER_OBJID_ROOT;
734 ip->obj_localization = pfsm->localization;
736 KKASSERT(dip != NULL);
737 namekey = hammer_directory_namekey(dip, name, namelen, &dummy);
738 ip->obj_id = hammer_alloc_objid(hmp, dip, namekey);
739 ip->obj_localization = dip->obj_localization;
742 KKASSERT(ip->obj_id != 0);
743 ip->obj_asof = hmp->asof;
745 ip->flush_state = HAMMER_FST_IDLE;
746 ip->flags = HAMMER_INODE_DDIRTY |
747 HAMMER_INODE_ATIME | HAMMER_INODE_MTIME;
748 ip->cache[0].ip = ip;
749 ip->cache[1].ip = ip;
750 ip->cache[2].ip = ip;
751 ip->cache[3].ip = ip;
753 ip->trunc_off = 0x7FFFFFFFFFFFFFFFLL;
754 /* ip->save_trunc_off = 0; (already zero) */
755 RB_INIT(&ip->rec_tree);
756 TAILQ_INIT(&ip->target_list);
758 ip->ino_data.atime = trans->time;
759 ip->ino_data.mtime = trans->time;
760 ip->ino_data.size = 0;
761 ip->ino_data.nlinks = 0;
764 * A nohistory designator on the parent directory is inherited by
765 * the child. We will do this even for pseudo-fs creation... the
766 * sysad can turn it off.
769 ip->ino_data.uflags = dip->ino_data.uflags &
770 (SF_NOHISTORY|UF_NOHISTORY|UF_NODUMP);
773 ip->ino_leaf.base.btype = HAMMER_BTREE_TYPE_RECORD;
774 ip->ino_leaf.base.localization = ip->obj_localization +
775 HAMMER_LOCALIZE_INODE;
776 ip->ino_leaf.base.obj_id = ip->obj_id;
777 ip->ino_leaf.base.key = 0;
778 ip->ino_leaf.base.create_tid = 0;
779 ip->ino_leaf.base.delete_tid = 0;
780 ip->ino_leaf.base.rec_type = HAMMER_RECTYPE_INODE;
781 ip->ino_leaf.base.obj_type = hammer_get_obj_type(vap->va_type);
783 ip->ino_data.obj_type = ip->ino_leaf.base.obj_type;
784 ip->ino_data.version = HAMMER_INODE_DATA_VERSION;
785 ip->ino_data.mode = vap->va_mode;
786 ip->ino_data.ctime = trans->time;
789 * If we are running version 2 or greater directory entries are
790 * inode-localized instead of data-localized.
792 if (trans->hmp->version >= HAMMER_VOL_VERSION_TWO) {
793 if (ip->ino_leaf.base.obj_type == HAMMER_OBJTYPE_DIRECTORY) {
794 ip->ino_data.cap_flags |=
795 HAMMER_INODE_CAP_DIR_LOCAL_INO;
800 * Setup the ".." pointer. This only needs to be done for directories
801 * but we do it for all objects as a recovery aid.
804 ip->ino_data.parent_obj_id = dip->ino_leaf.base.obj_id;
807 * The parent_obj_localization field only applies to pseudo-fs roots.
808 * XXX this is no longer applicable, PFSs are no longer directly
809 * tied into the parent's directory structure.
811 if (ip->ino_data.obj_type == HAMMER_OBJTYPE_DIRECTORY &&
812 ip->obj_id == HAMMER_OBJID_ROOT) {
813 ip->ino_data.ext.obj.parent_obj_localization =
814 dip->obj_localization;
818 switch(ip->ino_leaf.base.obj_type) {
819 case HAMMER_OBJTYPE_CDEV:
820 case HAMMER_OBJTYPE_BDEV:
821 ip->ino_data.rmajor = vap->va_rmajor;
822 ip->ino_data.rminor = vap->va_rminor;
829 * Calculate default uid/gid and overwrite with information from
833 xuid = hammer_to_unix_xid(&dip->ino_data.uid);
834 xuid = vop_helper_create_uid(hmp->mp, dip->ino_data.mode,
835 xuid, cred, &vap->va_mode);
839 ip->ino_data.mode = vap->va_mode;
841 if (vap->va_vaflags & VA_UID_UUID_VALID)
842 ip->ino_data.uid = vap->va_uid_uuid;
843 else if (vap->va_uid != (uid_t)VNOVAL)
844 hammer_guid_to_uuid(&ip->ino_data.uid, vap->va_uid);
846 hammer_guid_to_uuid(&ip->ino_data.uid, xuid);
848 if (vap->va_vaflags & VA_GID_UUID_VALID)
849 ip->ino_data.gid = vap->va_gid_uuid;
850 else if (vap->va_gid != (gid_t)VNOVAL)
851 hammer_guid_to_uuid(&ip->ino_data.gid, vap->va_gid);
853 ip->ino_data.gid = dip->ino_data.gid;
855 hammer_ref(&ip->lock);
859 hammer_ref(&pfsm->lock);
861 } else if (dip->obj_localization == ip->obj_localization) {
862 ip->pfsm = dip->pfsm;
863 hammer_ref(&ip->pfsm->lock);
866 ip->pfsm = hammer_load_pseudofs(trans,
867 ip->obj_localization,
869 error = 0; /* ignore ENOENT */
873 hammer_free_inode(ip);
875 } else if (RB_INSERT(hammer_ino_rb_tree, &hmp->rb_inos_root, ip)) {
876 panic("hammer_create_inode: duplicate obj_id %llx",
877 (long long)ip->obj_id);
879 hammer_free_inode(ip);
886 * Final cleanup / freeing of an inode structure
889 hammer_free_inode(hammer_inode_t ip)
891 struct hammer_mount *hmp;
894 KKASSERT(ip->lock.refs == 1);
895 hammer_uncache_node(&ip->cache[0]);
896 hammer_uncache_node(&ip->cache[1]);
897 hammer_uncache_node(&ip->cache[2]);
898 hammer_uncache_node(&ip->cache[3]);
899 hammer_inode_wakereclaims(ip);
901 hammer_clear_objid(ip);
902 --hammer_count_inodes;
905 hammer_rel_pseudofs(hmp, ip->pfsm);
908 kfree(ip, hmp->m_inodes);
913 * Retrieve pseudo-fs data. NULL will never be returned.
915 * If an error occurs *errorp will be set and a default template is returned,
916 * otherwise *errorp is set to 0. Typically when an error occurs it will
919 hammer_pseudofs_inmem_t
920 hammer_load_pseudofs(hammer_transaction_t trans,
921 u_int32_t localization, int *errorp)
923 hammer_mount_t hmp = trans->hmp;
925 hammer_pseudofs_inmem_t pfsm;
926 struct hammer_cursor cursor;
930 pfsm = RB_LOOKUP(hammer_pfs_rb_tree, &hmp->rb_pfsm_root, localization);
932 hammer_ref(&pfsm->lock);
938 * PFS records are stored in the root inode (not the PFS root inode,
939 * but the real root). Avoid an infinite recursion if loading
940 * the PFS for the real root.
943 ip = hammer_get_inode(trans, NULL, HAMMER_OBJID_ROOT,
945 HAMMER_DEF_LOCALIZATION, 0, errorp);
950 pfsm = kmalloc(sizeof(*pfsm), hmp->m_misc, M_WAITOK | M_ZERO);
951 pfsm->localization = localization;
952 pfsm->pfsd.unique_uuid = trans->rootvol->ondisk->vol_fsid;
953 pfsm->pfsd.shared_uuid = pfsm->pfsd.unique_uuid;
955 hammer_init_cursor(trans, &cursor, (ip ? &ip->cache[1] : NULL), ip);
956 cursor.key_beg.localization = HAMMER_DEF_LOCALIZATION +
957 HAMMER_LOCALIZE_MISC;
958 cursor.key_beg.obj_id = HAMMER_OBJID_ROOT;
959 cursor.key_beg.create_tid = 0;
960 cursor.key_beg.delete_tid = 0;
961 cursor.key_beg.rec_type = HAMMER_RECTYPE_PFS;
962 cursor.key_beg.obj_type = 0;
963 cursor.key_beg.key = localization;
964 cursor.asof = HAMMER_MAX_TID;
965 cursor.flags |= HAMMER_CURSOR_ASOF;
968 *errorp = hammer_ip_lookup(&cursor);
970 *errorp = hammer_btree_lookup(&cursor);
972 *errorp = hammer_ip_resolve_data(&cursor);
974 if (cursor.data->pfsd.mirror_flags &
975 HAMMER_PFSD_DELETED) {
978 bytes = cursor.leaf->data_len;
979 if (bytes > sizeof(pfsm->pfsd))
980 bytes = sizeof(pfsm->pfsd);
981 bcopy(cursor.data, &pfsm->pfsd, bytes);
985 hammer_done_cursor(&cursor);
987 pfsm->fsid_udev = hammer_fsid_to_udev(&pfsm->pfsd.shared_uuid);
988 hammer_ref(&pfsm->lock);
990 hammer_rel_inode(ip, 0);
991 if (RB_INSERT(hammer_pfs_rb_tree, &hmp->rb_pfsm_root, pfsm)) {
992 kfree(pfsm, hmp->m_misc);
999 * Store pseudo-fs data. The backend will automatically delete any prior
1000 * on-disk pseudo-fs data but we have to delete in-memory versions.
1003 hammer_save_pseudofs(hammer_transaction_t trans, hammer_pseudofs_inmem_t pfsm)
1005 struct hammer_cursor cursor;
1006 hammer_record_t record;
1010 ip = hammer_get_inode(trans, NULL, HAMMER_OBJID_ROOT, HAMMER_MAX_TID,
1011 HAMMER_DEF_LOCALIZATION, 0, &error);
1013 pfsm->fsid_udev = hammer_fsid_to_udev(&pfsm->pfsd.shared_uuid);
1014 hammer_init_cursor(trans, &cursor, &ip->cache[1], ip);
1015 cursor.key_beg.localization = ip->obj_localization +
1016 HAMMER_LOCALIZE_MISC;
1017 cursor.key_beg.obj_id = HAMMER_OBJID_ROOT;
1018 cursor.key_beg.create_tid = 0;
1019 cursor.key_beg.delete_tid = 0;
1020 cursor.key_beg.rec_type = HAMMER_RECTYPE_PFS;
1021 cursor.key_beg.obj_type = 0;
1022 cursor.key_beg.key = pfsm->localization;
1023 cursor.asof = HAMMER_MAX_TID;
1024 cursor.flags |= HAMMER_CURSOR_ASOF;
1027 * Replace any in-memory version of the record.
1029 error = hammer_ip_lookup(&cursor);
1030 if (error == 0 && hammer_cursor_inmem(&cursor)) {
1031 record = cursor.iprec;
1032 if (record->flags & HAMMER_RECF_INTERLOCK_BE) {
1033 KKASSERT(cursor.deadlk_rec == NULL);
1034 hammer_ref(&record->lock);
1035 cursor.deadlk_rec = record;
1038 record->flags |= HAMMER_RECF_DELETED_FE;
1044 * Allocate replacement general record. The backend flush will
1045 * delete any on-disk version of the record.
1047 if (error == 0 || error == ENOENT) {
1048 record = hammer_alloc_mem_record(ip, sizeof(pfsm->pfsd));
1049 record->type = HAMMER_MEM_RECORD_GENERAL;
1051 record->leaf.base.localization = ip->obj_localization +
1052 HAMMER_LOCALIZE_MISC;
1053 record->leaf.base.rec_type = HAMMER_RECTYPE_PFS;
1054 record->leaf.base.key = pfsm->localization;
1055 record->leaf.data_len = sizeof(pfsm->pfsd);
1056 bcopy(&pfsm->pfsd, record->data, sizeof(pfsm->pfsd));
1057 error = hammer_ip_add_record(trans, record);
1059 hammer_done_cursor(&cursor);
1060 if (error == EDEADLK)
1062 hammer_rel_inode(ip, 0);
1067 * Create a root directory for a PFS if one does not alredy exist.
1069 * The PFS root stands alone so we must also bump the nlinks count
1070 * to prevent it from being destroyed on release.
1073 hammer_mkroot_pseudofs(hammer_transaction_t trans, struct ucred *cred,
1074 hammer_pseudofs_inmem_t pfsm)
1080 ip = hammer_get_inode(trans, NULL, HAMMER_OBJID_ROOT, HAMMER_MAX_TID,
1081 pfsm->localization, 0, &error);
1086 error = hammer_create_inode(trans, &vap, cred,
1090 ++ip->ino_data.nlinks;
1091 hammer_modify_inode(ip, HAMMER_INODE_DDIRTY);
1095 hammer_rel_inode(ip, 0);
1100 * Unload any vnodes & inodes associated with a PFS, return ENOTEMPTY
1101 * if we are unable to disassociate all the inodes.
1105 hammer_unload_pseudofs_callback(hammer_inode_t ip, void *data)
1109 hammer_ref(&ip->lock);
1110 if (ip->lock.refs == 2 && ip->vp)
1111 vclean_unlocked(ip->vp);
1112 if (ip->lock.refs == 1 && ip->vp == NULL)
1115 res = -1; /* stop, someone is using the inode */
1116 hammer_rel_inode(ip, 0);
1121 hammer_unload_pseudofs(hammer_transaction_t trans, u_int32_t localization)
1126 for (try = res = 0; try < 4; ++try) {
1127 res = hammer_ino_rb_tree_RB_SCAN(&trans->hmp->rb_inos_root,
1128 hammer_inode_pfs_cmp,
1129 hammer_unload_pseudofs_callback,
1131 if (res == 0 && try > 1)
1133 hammer_flusher_sync(trans->hmp);
1142 * Release a reference on a PFS
1145 hammer_rel_pseudofs(hammer_mount_t hmp, hammer_pseudofs_inmem_t pfsm)
1147 hammer_unref(&pfsm->lock);
1148 if (pfsm->lock.refs == 0) {
1149 RB_REMOVE(hammer_pfs_rb_tree, &hmp->rb_pfsm_root, pfsm);
1150 kfree(pfsm, hmp->m_misc);
1155 * Called by hammer_sync_inode().
1158 hammer_update_inode(hammer_cursor_t cursor, hammer_inode_t ip)
1160 hammer_transaction_t trans = cursor->trans;
1161 hammer_record_t record;
1169 * If the inode has a presence on-disk then locate it and mark
1170 * it deleted, setting DELONDISK.
1172 * The record may or may not be physically deleted, depending on
1173 * the retention policy.
1175 if ((ip->flags & (HAMMER_INODE_ONDISK|HAMMER_INODE_DELONDISK)) ==
1176 HAMMER_INODE_ONDISK) {
1177 hammer_normalize_cursor(cursor);
1178 cursor->key_beg.localization = ip->obj_localization +
1179 HAMMER_LOCALIZE_INODE;
1180 cursor->key_beg.obj_id = ip->obj_id;
1181 cursor->key_beg.key = 0;
1182 cursor->key_beg.create_tid = 0;
1183 cursor->key_beg.delete_tid = 0;
1184 cursor->key_beg.rec_type = HAMMER_RECTYPE_INODE;
1185 cursor->key_beg.obj_type = 0;
1186 cursor->asof = ip->obj_asof;
1187 cursor->flags &= ~HAMMER_CURSOR_INITMASK;
1188 cursor->flags |= HAMMER_CURSOR_GET_LEAF | HAMMER_CURSOR_ASOF;
1189 cursor->flags |= HAMMER_CURSOR_BACKEND;
1191 error = hammer_btree_lookup(cursor);
1192 if (hammer_debug_inode)
1193 kprintf("IPDEL %p %08x %d", ip, ip->flags, error);
1196 error = hammer_ip_delete_record(cursor, ip, trans->tid);
1197 if (hammer_debug_inode)
1198 kprintf(" error %d\n", error);
1200 ip->flags |= HAMMER_INODE_DELONDISK;
1203 hammer_cache_node(&ip->cache[0], cursor->node);
1205 if (error == EDEADLK) {
1206 hammer_done_cursor(cursor);
1207 error = hammer_init_cursor(trans, cursor,
1209 if (hammer_debug_inode)
1210 kprintf("IPDED %p %d\n", ip, error);
1217 * Ok, write out the initial record or a new record (after deleting
1218 * the old one), unless the DELETED flag is set. This routine will
1219 * clear DELONDISK if it writes out a record.
1221 * Update our inode statistics if this is the first application of
1222 * the inode on-disk.
1224 if (error == 0 && (ip->flags & HAMMER_INODE_DELETED) == 0) {
1226 * Generate a record and write it to the media. We clean-up
1227 * the state before releasing so we do not have to set-up
1230 record = hammer_alloc_mem_record(ip, 0);
1231 record->type = HAMMER_MEM_RECORD_INODE;
1232 record->flush_state = HAMMER_FST_FLUSH;
1233 record->leaf = ip->sync_ino_leaf;
1234 record->leaf.base.create_tid = trans->tid;
1235 record->leaf.data_len = sizeof(ip->sync_ino_data);
1236 record->leaf.create_ts = trans->time32;
1237 record->data = (void *)&ip->sync_ino_data;
1238 record->flags |= HAMMER_RECF_INTERLOCK_BE;
1241 * If this flag is set we cannot sync the new file size
1242 * because we haven't finished related truncations. The
1243 * inode will be flushed in another flush group to finish
1246 if ((ip->flags & HAMMER_INODE_WOULDBLOCK) &&
1247 ip->sync_ino_data.size != ip->ino_data.size) {
1249 ip->sync_ino_data.size = ip->ino_data.size;
1255 error = hammer_ip_sync_record_cursor(cursor, record);
1256 if (hammer_debug_inode)
1257 kprintf("GENREC %p rec %08x %d\n",
1258 ip, record->flags, error);
1259 if (error != EDEADLK)
1261 hammer_done_cursor(cursor);
1262 error = hammer_init_cursor(trans, cursor,
1264 if (hammer_debug_inode)
1265 kprintf("GENREC reinit %d\n", error);
1271 * Note: The record was never on the inode's record tree
1272 * so just wave our hands importantly and destroy it.
1274 record->flags |= HAMMER_RECF_COMMITTED;
1275 record->flags &= ~HAMMER_RECF_INTERLOCK_BE;
1276 record->flush_state = HAMMER_FST_IDLE;
1277 ++ip->rec_generation;
1278 hammer_rel_mem_record(record);
1284 if (hammer_debug_inode)
1285 kprintf("CLEANDELOND %p %08x\n", ip, ip->flags);
1286 ip->sync_flags &= ~(HAMMER_INODE_DDIRTY |
1287 HAMMER_INODE_SDIRTY |
1288 HAMMER_INODE_ATIME |
1289 HAMMER_INODE_MTIME);
1290 ip->flags &= ~HAMMER_INODE_DELONDISK;
1292 ip->sync_flags |= HAMMER_INODE_DDIRTY;
1295 * Root volume count of inodes
1297 hammer_sync_lock_sh(trans);
1298 if ((ip->flags & HAMMER_INODE_ONDISK) == 0) {
1299 hammer_modify_volume_field(trans,
1302 ++ip->hmp->rootvol->ondisk->vol0_stat_inodes;
1303 hammer_modify_volume_done(trans->rootvol);
1304 ip->flags |= HAMMER_INODE_ONDISK;
1305 if (hammer_debug_inode)
1306 kprintf("NOWONDISK %p\n", ip);
1308 hammer_sync_unlock(trans);
1313 * If the inode has been destroyed, clean out any left-over flags
1314 * that may have been set by the frontend.
1316 if (error == 0 && (ip->flags & HAMMER_INODE_DELETED)) {
1317 ip->sync_flags &= ~(HAMMER_INODE_DDIRTY |
1318 HAMMER_INODE_SDIRTY |
1319 HAMMER_INODE_ATIME |
1320 HAMMER_INODE_MTIME);
1326 * Update only the itimes fields.
1328 * ATIME can be updated without generating any UNDO. MTIME is updated
1329 * with UNDO so it is guaranteed to be synchronized properly in case of
1332 * Neither field is included in the B-Tree leaf element's CRC, which is how
1333 * we can get away with updating ATIME the way we do.
1336 hammer_update_itimes(hammer_cursor_t cursor, hammer_inode_t ip)
1338 hammer_transaction_t trans = cursor->trans;
1342 if ((ip->flags & (HAMMER_INODE_ONDISK|HAMMER_INODE_DELONDISK)) !=
1343 HAMMER_INODE_ONDISK) {
1347 hammer_normalize_cursor(cursor);
1348 cursor->key_beg.localization = ip->obj_localization +
1349 HAMMER_LOCALIZE_INODE;
1350 cursor->key_beg.obj_id = ip->obj_id;
1351 cursor->key_beg.key = 0;
1352 cursor->key_beg.create_tid = 0;
1353 cursor->key_beg.delete_tid = 0;
1354 cursor->key_beg.rec_type = HAMMER_RECTYPE_INODE;
1355 cursor->key_beg.obj_type = 0;
1356 cursor->asof = ip->obj_asof;
1357 cursor->flags &= ~HAMMER_CURSOR_INITMASK;
1358 cursor->flags |= HAMMER_CURSOR_ASOF;
1359 cursor->flags |= HAMMER_CURSOR_GET_LEAF;
1360 cursor->flags |= HAMMER_CURSOR_GET_DATA;
1361 cursor->flags |= HAMMER_CURSOR_BACKEND;
1363 error = hammer_btree_lookup(cursor);
1365 hammer_cache_node(&ip->cache[0], cursor->node);
1366 if (ip->sync_flags & HAMMER_INODE_MTIME) {
1368 * Updating MTIME requires an UNDO. Just cover
1369 * both atime and mtime.
1371 hammer_sync_lock_sh(trans);
1372 hammer_modify_buffer(trans, cursor->data_buffer,
1373 HAMMER_ITIMES_BASE(&cursor->data->inode),
1374 HAMMER_ITIMES_BYTES);
1375 cursor->data->inode.atime = ip->sync_ino_data.atime;
1376 cursor->data->inode.mtime = ip->sync_ino_data.mtime;
1377 hammer_modify_buffer_done(cursor->data_buffer);
1378 hammer_sync_unlock(trans);
1379 } else if (ip->sync_flags & HAMMER_INODE_ATIME) {
1381 * Updating atime only can be done in-place with
1384 hammer_sync_lock_sh(trans);
1385 hammer_modify_buffer(trans, cursor->data_buffer,
1387 cursor->data->inode.atime = ip->sync_ino_data.atime;
1388 hammer_modify_buffer_done(cursor->data_buffer);
1389 hammer_sync_unlock(trans);
1391 ip->sync_flags &= ~(HAMMER_INODE_ATIME | HAMMER_INODE_MTIME);
1393 if (error == EDEADLK) {
1394 hammer_done_cursor(cursor);
1395 error = hammer_init_cursor(trans, cursor,
1404 * Release a reference on an inode, flush as requested.
1406 * On the last reference we queue the inode to the flusher for its final
1410 hammer_rel_inode(struct hammer_inode *ip, int flush)
1412 /*hammer_mount_t hmp = ip->hmp;*/
1415 * Handle disposition when dropping the last ref.
1418 if (ip->lock.refs == 1) {
1420 * Determine whether on-disk action is needed for
1421 * the inode's final disposition.
1423 KKASSERT(ip->vp == NULL);
1424 hammer_inode_unloadable_check(ip, 0);
1425 if (ip->flags & HAMMER_INODE_MODMASK) {
1426 hammer_flush_inode(ip, 0);
1427 } else if (ip->lock.refs == 1) {
1428 hammer_unload_inode(ip);
1433 hammer_flush_inode(ip, 0);
1436 * The inode still has multiple refs, try to drop
1439 KKASSERT(ip->lock.refs >= 1);
1440 if (ip->lock.refs > 1) {
1441 hammer_unref(&ip->lock);
1449 * Unload and destroy the specified inode. Must be called with one remaining
1450 * reference. The reference is disposed of.
1452 * The inode must be completely clean.
1455 hammer_unload_inode(struct hammer_inode *ip)
1457 hammer_mount_t hmp = ip->hmp;
1459 KASSERT(ip->lock.refs == 1,
1460 ("hammer_unload_inode: %d refs\n", ip->lock.refs));
1461 KKASSERT(ip->vp == NULL);
1462 KKASSERT(ip->flush_state == HAMMER_FST_IDLE);
1463 KKASSERT(ip->cursor_ip_refs == 0);
1464 KKASSERT(hammer_notlocked(&ip->lock));
1465 KKASSERT((ip->flags & HAMMER_INODE_MODMASK) == 0);
1467 KKASSERT(RB_EMPTY(&ip->rec_tree));
1468 KKASSERT(TAILQ_EMPTY(&ip->target_list));
1470 if (ip->flags & HAMMER_INODE_RDIRTY) {
1471 RB_REMOVE(hammer_redo_rb_tree, &hmp->rb_redo_root, ip);
1472 ip->flags &= ~HAMMER_INODE_RDIRTY;
1474 RB_REMOVE(hammer_ino_rb_tree, &hmp->rb_inos_root, ip);
1476 hammer_free_inode(ip);
1481 * Called during unmounting if a critical error occured. The in-memory
1482 * inode and all related structures are destroyed.
1484 * If a critical error did not occur the unmount code calls the standard
1485 * release and asserts that the inode is gone.
1488 hammer_destroy_inode_callback(struct hammer_inode *ip, void *data __unused)
1490 hammer_record_t rec;
1493 * Get rid of the inodes in-memory records, regardless of their
1494 * state, and clear the mod-mask.
1496 while ((rec = TAILQ_FIRST(&ip->target_list)) != NULL) {
1497 TAILQ_REMOVE(&ip->target_list, rec, target_entry);
1498 rec->target_ip = NULL;
1499 if (rec->flush_state == HAMMER_FST_SETUP)
1500 rec->flush_state = HAMMER_FST_IDLE;
1502 while ((rec = RB_ROOT(&ip->rec_tree)) != NULL) {
1503 if (rec->flush_state == HAMMER_FST_FLUSH)
1504 --rec->flush_group->refs;
1506 hammer_ref(&rec->lock);
1507 KKASSERT(rec->lock.refs == 1);
1508 rec->flush_state = HAMMER_FST_IDLE;
1509 rec->flush_group = NULL;
1510 rec->flags |= HAMMER_RECF_DELETED_FE; /* wave hands */
1511 rec->flags |= HAMMER_RECF_DELETED_BE; /* wave hands */
1512 ++ip->rec_generation;
1513 hammer_rel_mem_record(rec);
1515 ip->flags &= ~HAMMER_INODE_MODMASK;
1516 ip->sync_flags &= ~HAMMER_INODE_MODMASK;
1517 KKASSERT(ip->vp == NULL);
1520 * Remove the inode from any flush group, force it idle. FLUSH
1521 * and SETUP states have an inode ref.
1523 switch(ip->flush_state) {
1524 case HAMMER_FST_FLUSH:
1525 RB_REMOVE(hammer_fls_rb_tree, &ip->flush_group->flush_tree, ip);
1526 --ip->flush_group->refs;
1527 ip->flush_group = NULL;
1529 case HAMMER_FST_SETUP:
1530 hammer_unref(&ip->lock);
1531 ip->flush_state = HAMMER_FST_IDLE;
1533 case HAMMER_FST_IDLE:
1538 * There shouldn't be any associated vnode. The unload needs at
1539 * least one ref, if we do have a vp steal its ip ref.
1542 kprintf("hammer_destroy_inode_callback: Unexpected "
1543 "vnode association ip %p vp %p\n", ip, ip->vp);
1544 ip->vp->v_data = NULL;
1547 hammer_ref(&ip->lock);
1549 hammer_unload_inode(ip);
1554 * Called on mount -u when switching from RW to RO or vise-versa. Adjust
1555 * the read-only flag for cached inodes.
1557 * This routine is called from a RB_SCAN().
1560 hammer_reload_inode(hammer_inode_t ip, void *arg __unused)
1562 hammer_mount_t hmp = ip->hmp;
1564 if (hmp->ronly || hmp->asof != HAMMER_MAX_TID)
1565 ip->flags |= HAMMER_INODE_RO;
1567 ip->flags &= ~HAMMER_INODE_RO;
1572 * A transaction has modified an inode, requiring updates as specified by
1575 * HAMMER_INODE_DDIRTY: Inode data has been updated, not incl mtime/atime,
1576 * and not including size changes due to write-append
1577 * (but other size changes are included).
1578 * HAMMER_INODE_SDIRTY: Inode data has been updated, size changes due to
1580 * HAMMER_INODE_XDIRTY: Dirty in-memory records
1581 * HAMMER_INODE_BUFS: Dirty buffer cache buffers
1582 * HAMMER_INODE_DELETED: Inode record/data must be deleted
1583 * HAMMER_INODE_ATIME/MTIME: mtime/atime has been updated
1586 hammer_modify_inode(hammer_inode_t ip, int flags)
1589 * ronly of 0 or 2 does not trigger assertion.
1590 * 2 is a special error state
1592 KKASSERT(ip->hmp->ronly != 1 ||
1593 (flags & (HAMMER_INODE_DDIRTY | HAMMER_INODE_XDIRTY |
1594 HAMMER_INODE_SDIRTY |
1595 HAMMER_INODE_BUFS | HAMMER_INODE_DELETED |
1596 HAMMER_INODE_ATIME | HAMMER_INODE_MTIME)) == 0);
1597 if ((ip->flags & HAMMER_INODE_RSV_INODES) == 0) {
1598 ip->flags |= HAMMER_INODE_RSV_INODES;
1599 ++ip->hmp->rsv_inodes;
1606 * Request that an inode be flushed. This whole mess cannot block and may
1607 * recurse (if not synchronous). Once requested HAMMER will attempt to
1608 * actively flush the inode until the flush can be done.
1610 * The inode may already be flushing, or may be in a setup state. We can
1611 * place the inode in a flushing state if it is currently idle and flag it
1612 * to reflush if it is currently flushing.
1614 * Upon return if the inode could not be flushed due to a setup
1615 * dependancy, then it will be automatically flushed when the dependancy
1619 hammer_flush_inode(hammer_inode_t ip, int flags)
1622 hammer_flush_group_t flg;
1626 * next_flush_group is the first flush group we can place the inode
1627 * in. It may be NULL. If it becomes full we append a new flush
1628 * group and make that the next_flush_group.
1631 while ((flg = hmp->next_flush_group) != NULL) {
1632 KKASSERT(flg->running == 0);
1633 if (flg->total_count + flg->refs <= ip->hmp->undo_rec_limit)
1635 hmp->next_flush_group = TAILQ_NEXT(flg, flush_entry);
1636 hammer_flusher_async(ip->hmp, flg);
1639 flg = kmalloc(sizeof(*flg), hmp->m_misc, M_WAITOK|M_ZERO);
1640 hmp->next_flush_group = flg;
1641 RB_INIT(&flg->flush_tree);
1642 TAILQ_INSERT_TAIL(&hmp->flush_group_list, flg, flush_entry);
1646 * Trivial 'nothing to flush' case. If the inode is in a SETUP
1647 * state we have to put it back into an IDLE state so we can
1648 * drop the extra ref.
1650 * If we have a parent dependancy we must still fall through
1653 if ((ip->flags & HAMMER_INODE_MODMASK) == 0) {
1654 if (ip->flush_state == HAMMER_FST_SETUP &&
1655 TAILQ_EMPTY(&ip->target_list)) {
1656 ip->flush_state = HAMMER_FST_IDLE;
1657 hammer_rel_inode(ip, 0);
1659 if (ip->flush_state == HAMMER_FST_IDLE)
1664 * Our flush action will depend on the current state.
1666 switch(ip->flush_state) {
1667 case HAMMER_FST_IDLE:
1669 * We have no dependancies and can flush immediately. Some
1670 * our children may not be flushable so we have to re-test
1671 * with that additional knowledge.
1673 hammer_flush_inode_core(ip, flg, flags);
1675 case HAMMER_FST_SETUP:
1677 * Recurse upwards through dependancies via target_list
1678 * and start their flusher actions going if possible.
1680 * 'good' is our connectivity. -1 means we have none and
1681 * can't flush, 0 means there weren't any dependancies, and
1682 * 1 means we have good connectivity.
1684 good = hammer_setup_parent_inodes(ip, 0, flg);
1688 * We can continue if good >= 0. Determine how
1689 * many records under our inode can be flushed (and
1692 hammer_flush_inode_core(ip, flg, flags);
1695 * Parent has no connectivity, tell it to flush
1696 * us as soon as it does.
1698 * The REFLUSH flag is also needed to trigger
1699 * dependancy wakeups.
1701 ip->flags |= HAMMER_INODE_CONN_DOWN |
1702 HAMMER_INODE_REFLUSH;
1703 if (flags & HAMMER_FLUSH_SIGNAL) {
1704 ip->flags |= HAMMER_INODE_RESIGNAL;
1705 hammer_flusher_async(ip->hmp, flg);
1709 case HAMMER_FST_FLUSH:
1711 * We are already flushing, flag the inode to reflush
1712 * if needed after it completes its current flush.
1714 * The REFLUSH flag is also needed to trigger
1715 * dependancy wakeups.
1717 if ((ip->flags & HAMMER_INODE_REFLUSH) == 0)
1718 ip->flags |= HAMMER_INODE_REFLUSH;
1719 if (flags & HAMMER_FLUSH_SIGNAL) {
1720 ip->flags |= HAMMER_INODE_RESIGNAL;
1721 hammer_flusher_async(ip->hmp, flg);
1728 * Scan ip->target_list, which is a list of records owned by PARENTS to our
1729 * ip which reference our ip.
1731 * XXX This is a huge mess of recursive code, but not one bit of it blocks
1732 * so for now do not ref/deref the structures. Note that if we use the
1733 * ref/rel code later, the rel CAN block.
1736 hammer_setup_parent_inodes(hammer_inode_t ip, int depth,
1737 hammer_flush_group_t flg)
1739 hammer_record_t depend;
1744 * If we hit our recursion limit and we have parent dependencies
1745 * We cannot continue. Returning < 0 will cause us to be flagged
1746 * for reflush. Returning -2 cuts off additional dependency checks
1747 * because they are likely to also hit the depth limit.
1749 * We cannot return < 0 if there are no dependencies or there might
1750 * not be anything to wakeup (ip).
1752 if (depth == 20 && TAILQ_FIRST(&ip->target_list)) {
1753 kprintf("HAMMER Warning: depth limit reached on "
1754 "setup recursion, inode %p %016llx\n",
1755 ip, (long long)ip->obj_id);
1763 TAILQ_FOREACH(depend, &ip->target_list, target_entry) {
1764 r = hammer_setup_parent_inodes_helper(depend, depth, flg);
1765 KKASSERT(depend->target_ip == ip);
1766 if (r < 0 && good == 0)
1772 * If we failed due to the recursion depth limit then stop
1782 * This helper function takes a record representing the dependancy between
1783 * the parent inode and child inode.
1785 * record->ip = parent inode
1786 * record->target_ip = child inode
1788 * We are asked to recurse upwards and convert the record from SETUP
1789 * to FLUSH if possible.
1791 * Return 1 if the record gives us connectivity
1793 * Return 0 if the record is not relevant
1795 * Return -1 if we can't resolve the dependancy and there is no connectivity.
1798 hammer_setup_parent_inodes_helper(hammer_record_t record, int depth,
1799 hammer_flush_group_t flg)
1805 KKASSERT(record->flush_state != HAMMER_FST_IDLE);
1810 * If the record is already flushing, is it in our flush group?
1812 * If it is in our flush group but it is a general record or a
1813 * delete-on-disk, it does not improve our connectivity (return 0),
1814 * and if the target inode is not trying to destroy itself we can't
1815 * allow the operation yet anyway (the second return -1).
1817 if (record->flush_state == HAMMER_FST_FLUSH) {
1819 * If not in our flush group ask the parent to reflush
1820 * us as soon as possible.
1822 if (record->flush_group != flg) {
1823 pip->flags |= HAMMER_INODE_REFLUSH;
1824 record->target_ip->flags |= HAMMER_INODE_CONN_DOWN;
1829 * If in our flush group everything is already set up,
1830 * just return whether the record will improve our
1831 * visibility or not.
1833 if (record->type == HAMMER_MEM_RECORD_ADD)
1839 * It must be a setup record. Try to resolve the setup dependancies
1840 * by recursing upwards so we can place ip on the flush list.
1842 * Limit ourselves to 20 levels of recursion to avoid blowing out
1843 * the kernel stack. If we hit the recursion limit we can't flush
1844 * until the parent flushes. The parent will flush independantly
1845 * on its own and ultimately a deep recursion will be resolved.
1847 KKASSERT(record->flush_state == HAMMER_FST_SETUP);
1849 good = hammer_setup_parent_inodes(pip, depth + 1, flg);
1852 * If good < 0 the parent has no connectivity and we cannot safely
1853 * flush the directory entry, which also means we can't flush our
1854 * ip. Flag us for downward recursion once the parent's
1855 * connectivity is resolved. Flag the parent for [re]flush or it
1856 * may not check for downward recursions.
1859 pip->flags |= HAMMER_INODE_REFLUSH;
1860 record->target_ip->flags |= HAMMER_INODE_CONN_DOWN;
1865 * We are go, place the parent inode in a flushing state so we can
1866 * place its record in a flushing state. Note that the parent
1867 * may already be flushing. The record must be in the same flush
1868 * group as the parent.
1870 if (pip->flush_state != HAMMER_FST_FLUSH)
1871 hammer_flush_inode_core(pip, flg, HAMMER_FLUSH_RECURSION);
1872 KKASSERT(pip->flush_state == HAMMER_FST_FLUSH);
1873 KKASSERT(record->flush_state == HAMMER_FST_SETUP);
1876 if (record->type == HAMMER_MEM_RECORD_DEL &&
1877 (record->target_ip->flags & (HAMMER_INODE_DELETED|HAMMER_INODE_DELONDISK)) == 0) {
1879 * Regardless of flushing state we cannot sync this path if the
1880 * record represents a delete-on-disk but the target inode
1881 * is not ready to sync its own deletion.
1883 * XXX need to count effective nlinks to determine whether
1884 * the flush is ok, otherwise removing a hardlink will
1885 * just leave the DEL record to rot.
1887 record->target_ip->flags |= HAMMER_INODE_REFLUSH;
1891 if (pip->flush_group == flg) {
1893 * Because we have not calculated nlinks yet we can just
1894 * set records to the flush state if the parent is in
1895 * the same flush group as we are.
1897 record->flush_state = HAMMER_FST_FLUSH;
1898 record->flush_group = flg;
1899 ++record->flush_group->refs;
1900 hammer_ref(&record->lock);
1903 * A general directory-add contributes to our visibility.
1905 * Otherwise it is probably a directory-delete or
1906 * delete-on-disk record and does not contribute to our
1907 * visbility (but we can still flush it).
1909 if (record->type == HAMMER_MEM_RECORD_ADD)
1914 * If the parent is not in our flush group we cannot
1915 * flush this record yet, there is no visibility.
1916 * We tell the parent to reflush and mark ourselves
1917 * so the parent knows it should flush us too.
1919 pip->flags |= HAMMER_INODE_REFLUSH;
1920 record->target_ip->flags |= HAMMER_INODE_CONN_DOWN;
1926 * This is the core routine placing an inode into the FST_FLUSH state.
1929 hammer_flush_inode_core(hammer_inode_t ip, hammer_flush_group_t flg, int flags)
1934 * Set flush state and prevent the flusher from cycling into
1935 * the next flush group. Do not place the ip on the list yet.
1936 * Inodes not in the idle state get an extra reference.
1938 KKASSERT(ip->flush_state != HAMMER_FST_FLUSH);
1939 if (ip->flush_state == HAMMER_FST_IDLE)
1940 hammer_ref(&ip->lock);
1941 ip->flush_state = HAMMER_FST_FLUSH;
1942 ip->flush_group = flg;
1943 ++ip->hmp->flusher.group_lock;
1944 ++ip->hmp->count_iqueued;
1945 ++hammer_count_iqueued;
1947 hammer_redo_fifo_start_flush(ip);
1950 * If the flush group reaches the autoflush limit we want to signal
1951 * the flusher. This is particularly important for remove()s.
1953 if (flg->total_count == hammer_autoflush)
1954 flags |= HAMMER_FLUSH_SIGNAL;
1958 * We need to be able to vfsync/truncate from the backend.
1960 * XXX Any truncation from the backend will acquire the vnode
1963 KKASSERT((ip->flags & HAMMER_INODE_VHELD) == 0);
1964 if (ip->vp && (ip->vp->v_flag & VINACTIVE) == 0) {
1965 ip->flags |= HAMMER_INODE_VHELD;
1971 * Figure out how many in-memory records we can actually flush
1972 * (not including inode meta-data, buffers, etc).
1974 KKASSERT((ip->flags & HAMMER_INODE_WOULDBLOCK) == 0);
1975 if (flags & HAMMER_FLUSH_RECURSION) {
1977 * If this is a upwards recursion we do not want to
1978 * recurse down again!
1982 } else if (ip->flags & HAMMER_INODE_WOULDBLOCK) {
1984 * No new records are added if we must complete a flush
1985 * from a previous cycle, but we do have to move the records
1986 * from the previous cycle to the current one.
1989 go_count = RB_SCAN(hammer_rec_rb_tree, &ip->rec_tree, NULL,
1990 hammer_syncgrp_child_callback, NULL);
1996 * Normal flush, scan records and bring them into the flush.
1997 * Directory adds and deletes are usually skipped (they are
1998 * grouped with the related inode rather then with the
2001 * go_count can be negative, which means the scan aborted
2002 * due to the flush group being over-full and we should
2003 * flush what we have.
2005 go_count = RB_SCAN(hammer_rec_rb_tree, &ip->rec_tree, NULL,
2006 hammer_setup_child_callback, NULL);
2010 * This is a more involved test that includes go_count. If we
2011 * can't flush, flag the inode and return. If go_count is 0 we
2012 * were are unable to flush any records in our rec_tree and
2013 * must ignore the XDIRTY flag.
2015 if (go_count == 0) {
2016 if ((ip->flags & HAMMER_INODE_MODMASK_NOXDIRTY) == 0) {
2017 --ip->hmp->count_iqueued;
2018 --hammer_count_iqueued;
2021 ip->flush_state = HAMMER_FST_SETUP;
2022 ip->flush_group = NULL;
2024 if (ip->flags & HAMMER_INODE_VHELD) {
2025 ip->flags &= ~HAMMER_INODE_VHELD;
2031 * REFLUSH is needed to trigger dependancy wakeups
2032 * when an inode is in SETUP.
2034 ip->flags |= HAMMER_INODE_REFLUSH;
2035 if (flags & HAMMER_FLUSH_SIGNAL) {
2036 ip->flags |= HAMMER_INODE_RESIGNAL;
2037 hammer_flusher_async(ip->hmp, flg);
2039 if (--ip->hmp->flusher.group_lock == 0)
2040 wakeup(&ip->hmp->flusher.group_lock);
2046 * Snapshot the state of the inode for the backend flusher.
2048 * We continue to retain save_trunc_off even when all truncations
2049 * have been resolved as an optimization to determine if we can
2050 * skip the B-Tree lookup for overwrite deletions.
2052 * NOTE: The DELETING flag is a mod flag, but it is also sticky,
2053 * and stays in ip->flags. Once set, it stays set until the
2054 * inode is destroyed.
2056 if (ip->flags & HAMMER_INODE_TRUNCATED) {
2057 KKASSERT((ip->sync_flags & HAMMER_INODE_TRUNCATED) == 0);
2058 ip->sync_trunc_off = ip->trunc_off;
2059 ip->trunc_off = 0x7FFFFFFFFFFFFFFFLL;
2060 ip->flags &= ~HAMMER_INODE_TRUNCATED;
2061 ip->sync_flags |= HAMMER_INODE_TRUNCATED;
2064 * The save_trunc_off used to cache whether the B-Tree
2065 * holds any records past that point is not used until
2066 * after the truncation has succeeded, so we can safely
2069 if (ip->save_trunc_off > ip->sync_trunc_off)
2070 ip->save_trunc_off = ip->sync_trunc_off;
2072 ip->sync_flags |= (ip->flags & HAMMER_INODE_MODMASK &
2073 ~HAMMER_INODE_TRUNCATED);
2074 ip->sync_ino_leaf = ip->ino_leaf;
2075 ip->sync_ino_data = ip->ino_data;
2076 ip->flags &= ~HAMMER_INODE_MODMASK | HAMMER_INODE_TRUNCATED;
2077 #ifdef DEBUG_TRUNCATE
2078 if ((ip->sync_flags & HAMMER_INODE_TRUNCATED) && ip == HammerTruncIp)
2079 kprintf("truncateS %016llx\n", ip->sync_trunc_off);
2083 * The flusher list inherits our inode and reference.
2085 KKASSERT(flg->running == 0);
2086 RB_INSERT(hammer_fls_rb_tree, &flg->flush_tree, ip);
2087 if (--ip->hmp->flusher.group_lock == 0)
2088 wakeup(&ip->hmp->flusher.group_lock);
2090 if (flags & HAMMER_FLUSH_SIGNAL) {
2091 hammer_flusher_async(ip->hmp, flg);
2096 * Callback for scan of ip->rec_tree. Try to include each record in our
2097 * flush. ip->flush_group has been set but the inode has not yet been
2098 * moved into a flushing state.
2100 * If we get stuck on a record we have to set HAMMER_INODE_REFLUSH on
2103 * We return 1 for any record placed or found in FST_FLUSH, which prevents
2104 * the caller from shortcutting the flush.
2107 hammer_setup_child_callback(hammer_record_t rec, void *data)
2109 hammer_flush_group_t flg;
2110 hammer_inode_t target_ip;
2115 * Records deleted or committed by the backend are ignored.
2116 * Note that the flush detects deleted frontend records at
2117 * multiple points to deal with races. This is just the first
2118 * line of defense. The only time HAMMER_RECF_DELETED_FE cannot
2119 * be set is when HAMMER_RECF_INTERLOCK_BE is set, because it
2120 * messes up link-count calculations.
2122 * NOTE: Don't get confused between record deletion and, say,
2123 * directory entry deletion. The deletion of a directory entry
2124 * which is on-media has nothing to do with the record deletion
2127 if (rec->flags & (HAMMER_RECF_DELETED_FE | HAMMER_RECF_DELETED_BE |
2128 HAMMER_RECF_COMMITTED)) {
2129 if (rec->flush_state == HAMMER_FST_FLUSH) {
2130 KKASSERT(rec->flush_group == rec->ip->flush_group);
2139 * If the record is in an idle state it has no dependancies and
2143 flg = ip->flush_group;
2146 switch(rec->flush_state) {
2147 case HAMMER_FST_IDLE:
2149 * The record has no setup dependancy, we can flush it.
2151 KKASSERT(rec->target_ip == NULL);
2152 rec->flush_state = HAMMER_FST_FLUSH;
2153 rec->flush_group = flg;
2155 hammer_ref(&rec->lock);
2158 case HAMMER_FST_SETUP:
2160 * The record has a setup dependancy. These are typically
2161 * directory entry adds and deletes. Such entries will be
2162 * flushed when their inodes are flushed so we do not
2163 * usually have to add them to the flush here. However,
2164 * if the target_ip has set HAMMER_INODE_CONN_DOWN then
2165 * it is asking us to flush this record (and it).
2167 target_ip = rec->target_ip;
2168 KKASSERT(target_ip != NULL);
2169 KKASSERT(target_ip->flush_state != HAMMER_FST_IDLE);
2172 * If the target IP is already flushing in our group
2173 * we could associate the record, but target_ip has
2174 * already synced ino_data to sync_ino_data and we
2175 * would also have to adjust nlinks. Plus there are
2176 * ordering issues for adds and deletes.
2178 * Reflush downward if this is an ADD, and upward if
2181 if (target_ip->flush_state == HAMMER_FST_FLUSH) {
2182 if (rec->flush_state == HAMMER_MEM_RECORD_ADD)
2183 ip->flags |= HAMMER_INODE_REFLUSH;
2185 target_ip->flags |= HAMMER_INODE_REFLUSH;
2190 * Target IP is not yet flushing. This can get complex
2191 * because we have to be careful about the recursion.
2193 * Directories create an issue for us in that if a flush
2194 * of a directory is requested the expectation is to flush
2195 * any pending directory entries, but this will cause the
2196 * related inodes to recursively flush as well. We can't
2197 * really defer the operation so just get as many as we
2201 if ((target_ip->flags & HAMMER_INODE_RECLAIM) == 0 &&
2202 (target_ip->flags & HAMMER_INODE_CONN_DOWN) == 0) {
2204 * We aren't reclaiming and the target ip was not
2205 * previously prevented from flushing due to this
2206 * record dependancy. Do not flush this record.
2211 if (flg->total_count + flg->refs >
2212 ip->hmp->undo_rec_limit) {
2214 * Our flush group is over-full and we risk blowing
2215 * out the UNDO FIFO. Stop the scan, flush what we
2216 * have, then reflush the directory.
2218 * The directory may be forced through multiple
2219 * flush groups before it can be completely
2222 ip->flags |= HAMMER_INODE_RESIGNAL |
2223 HAMMER_INODE_REFLUSH;
2225 } else if (rec->type == HAMMER_MEM_RECORD_ADD) {
2227 * If the target IP is not flushing we can force
2228 * it to flush, even if it is unable to write out
2229 * any of its own records we have at least one in
2230 * hand that we CAN deal with.
2232 rec->flush_state = HAMMER_FST_FLUSH;
2233 rec->flush_group = flg;
2235 hammer_ref(&rec->lock);
2236 hammer_flush_inode_core(target_ip, flg,
2237 HAMMER_FLUSH_RECURSION);
2241 * General or delete-on-disk record.
2243 * XXX this needs help. If a delete-on-disk we could
2244 * disconnect the target. If the target has its own
2245 * dependancies they really need to be flushed.
2249 rec->flush_state = HAMMER_FST_FLUSH;
2250 rec->flush_group = flg;
2252 hammer_ref(&rec->lock);
2253 hammer_flush_inode_core(target_ip, flg,
2254 HAMMER_FLUSH_RECURSION);
2258 case HAMMER_FST_FLUSH:
2260 * The flush_group should already match.
2262 KKASSERT(rec->flush_group == flg);
2271 * This version just moves records already in a flush state to the new
2272 * flush group and that is it.
2275 hammer_syncgrp_child_callback(hammer_record_t rec, void *data)
2277 hammer_inode_t ip = rec->ip;
2279 switch(rec->flush_state) {
2280 case HAMMER_FST_FLUSH:
2281 KKASSERT(rec->flush_group == ip->flush_group);
2291 * Wait for a previously queued flush to complete.
2293 * If a critical error occured we don't try to wait.
2296 hammer_wait_inode(hammer_inode_t ip)
2298 hammer_flush_group_t flg;
2301 if ((ip->hmp->flags & HAMMER_MOUNT_CRITICAL_ERROR) == 0) {
2302 while (ip->flush_state != HAMMER_FST_IDLE &&
2303 (ip->hmp->flags & HAMMER_MOUNT_CRITICAL_ERROR) == 0) {
2304 if (ip->flush_state == HAMMER_FST_SETUP)
2305 hammer_flush_inode(ip, HAMMER_FLUSH_SIGNAL);
2306 if (ip->flush_state != HAMMER_FST_IDLE) {
2307 ip->flags |= HAMMER_INODE_FLUSHW;
2308 tsleep(&ip->flags, 0, "hmrwin", 0);
2315 * Called by the backend code when a flush has been completed.
2316 * The inode has already been removed from the flush list.
2318 * A pipelined flush can occur, in which case we must re-enter the
2319 * inode on the list and re-copy its fields.
2322 hammer_flush_inode_done(hammer_inode_t ip, int error)
2327 KKASSERT(ip->flush_state == HAMMER_FST_FLUSH);
2332 * Auto-reflush if the backend could not completely flush
2333 * the inode. This fixes a case where a deferred buffer flush
2334 * could cause fsync to return early.
2336 if (ip->sync_flags & HAMMER_INODE_MODMASK)
2337 ip->flags |= HAMMER_INODE_REFLUSH;
2340 * Merge left-over flags back into the frontend and fix the state.
2341 * Incomplete truncations are retained by the backend.
2344 ip->flags |= ip->sync_flags & ~HAMMER_INODE_TRUNCATED;
2345 ip->sync_flags &= HAMMER_INODE_TRUNCATED;
2348 * The backend may have adjusted nlinks, so if the adjusted nlinks
2349 * does not match the fronttend set the frontend's DDIRTY flag again.
2351 if (ip->ino_data.nlinks != ip->sync_ino_data.nlinks)
2352 ip->flags |= HAMMER_INODE_DDIRTY;
2355 * Fix up the dirty buffer status.
2357 if (ip->vp && RB_ROOT(&ip->vp->v_rbdirty_tree)) {
2358 ip->flags |= HAMMER_INODE_BUFS;
2360 hammer_redo_fifo_end_flush(ip);
2363 * Re-set the XDIRTY flag if some of the inode's in-memory records
2364 * could not be flushed.
2366 KKASSERT((RB_EMPTY(&ip->rec_tree) &&
2367 (ip->flags & HAMMER_INODE_XDIRTY) == 0) ||
2368 (!RB_EMPTY(&ip->rec_tree) &&
2369 (ip->flags & HAMMER_INODE_XDIRTY) != 0));
2372 * Do not lose track of inodes which no longer have vnode
2373 * assocations, otherwise they may never get flushed again.
2375 * The reflush flag can be set superfluously, causing extra pain
2376 * for no reason. If the inode is no longer modified it no longer
2377 * needs to be flushed.
2379 if (ip->flags & HAMMER_INODE_MODMASK) {
2381 ip->flags |= HAMMER_INODE_REFLUSH;
2383 ip->flags &= ~HAMMER_INODE_REFLUSH;
2387 * Adjust the flush state.
2389 if (ip->flags & HAMMER_INODE_WOULDBLOCK) {
2391 * We were unable to flush out all our records, leave the
2392 * inode in a flush state and in the current flush group.
2393 * The flush group will be re-run.
2395 * This occurs if the UNDO block gets too full or there is
2396 * too much dirty meta-data and allows the flusher to
2397 * finalize the UNDO block and then re-flush.
2399 ip->flags &= ~HAMMER_INODE_WOULDBLOCK;
2403 * Remove from the flush_group
2405 RB_REMOVE(hammer_fls_rb_tree, &ip->flush_group->flush_tree, ip);
2406 ip->flush_group = NULL;
2410 * Clean up the vnode ref and tracking counts.
2412 if (ip->flags & HAMMER_INODE_VHELD) {
2413 ip->flags &= ~HAMMER_INODE_VHELD;
2417 --hmp->count_iqueued;
2418 --hammer_count_iqueued;
2421 * And adjust the state.
2423 if (TAILQ_EMPTY(&ip->target_list) && RB_EMPTY(&ip->rec_tree)) {
2424 ip->flush_state = HAMMER_FST_IDLE;
2427 ip->flush_state = HAMMER_FST_SETUP;
2432 * If the frontend is waiting for a flush to complete,
2435 if (ip->flags & HAMMER_INODE_FLUSHW) {
2436 ip->flags &= ~HAMMER_INODE_FLUSHW;
2441 * If the frontend made more changes and requested another
2442 * flush, then try to get it running.
2444 * Reflushes are aborted when the inode is errored out.
2446 if (ip->flags & HAMMER_INODE_REFLUSH) {
2447 ip->flags &= ~HAMMER_INODE_REFLUSH;
2448 if (ip->flags & HAMMER_INODE_RESIGNAL) {
2449 ip->flags &= ~HAMMER_INODE_RESIGNAL;
2450 hammer_flush_inode(ip, HAMMER_FLUSH_SIGNAL);
2452 hammer_flush_inode(ip, 0);
2458 * If we have no parent dependancies we can clear CONN_DOWN
2460 if (TAILQ_EMPTY(&ip->target_list))
2461 ip->flags &= ~HAMMER_INODE_CONN_DOWN;
2464 * If the inode is now clean drop the space reservation.
2466 if ((ip->flags & HAMMER_INODE_MODMASK) == 0 &&
2467 (ip->flags & HAMMER_INODE_RSV_INODES)) {
2468 ip->flags &= ~HAMMER_INODE_RSV_INODES;
2473 hammer_rel_inode(ip, 0);
2477 * Called from hammer_sync_inode() to synchronize in-memory records
2481 hammer_sync_record_callback(hammer_record_t record, void *data)
2483 hammer_cursor_t cursor = data;
2484 hammer_transaction_t trans = cursor->trans;
2485 hammer_mount_t hmp = trans->hmp;
2489 * Skip records that do not belong to the current flush.
2491 ++hammer_stats_record_iterations;
2492 if (record->flush_state != HAMMER_FST_FLUSH)
2496 if (record->flush_group != record->ip->flush_group) {
2497 kprintf("sync_record %p ip %p bad flush group %p %p\n", record, record->ip, record->flush_group ,record->ip->flush_group);
2498 if (hammer_debug_critical)
2503 KKASSERT(record->flush_group == record->ip->flush_group);
2506 * Interlock the record using the BE flag. Once BE is set the
2507 * frontend cannot change the state of FE.
2509 * NOTE: If FE is set prior to us setting BE we still sync the
2510 * record out, but the flush completion code converts it to
2511 * a delete-on-disk record instead of destroying it.
2513 KKASSERT((record->flags & HAMMER_RECF_INTERLOCK_BE) == 0);
2514 record->flags |= HAMMER_RECF_INTERLOCK_BE;
2517 * The backend has already disposed of the record.
2519 if (record->flags & (HAMMER_RECF_DELETED_BE | HAMMER_RECF_COMMITTED)) {
2525 * If the whole inode is being deleting all on-disk records will
2526 * be deleted very soon, we can't sync any new records to disk
2527 * because they will be deleted in the same transaction they were
2528 * created in (delete_tid == create_tid), which will assert.
2530 * XXX There may be a case with RECORD_ADD with DELETED_FE set
2531 * that we currently panic on.
2533 if (record->ip->sync_flags & HAMMER_INODE_DELETING) {
2534 switch(record->type) {
2535 case HAMMER_MEM_RECORD_DATA:
2537 * We don't have to do anything, if the record was
2538 * committed the space will have been accounted for
2542 case HAMMER_MEM_RECORD_GENERAL:
2544 * Set deleted-by-backend flag. Do not set the
2545 * backend committed flag, because we are throwing
2548 record->flags |= HAMMER_RECF_DELETED_BE;
2549 ++record->ip->rec_generation;
2552 case HAMMER_MEM_RECORD_ADD:
2553 panic("hammer_sync_record_callback: illegal add "
2554 "during inode deletion record %p", record);
2555 break; /* NOT REACHED */
2556 case HAMMER_MEM_RECORD_INODE:
2557 panic("hammer_sync_record_callback: attempt to "
2558 "sync inode record %p?", record);
2559 break; /* NOT REACHED */
2560 case HAMMER_MEM_RECORD_DEL:
2562 * Follow through and issue the on-disk deletion
2569 * If DELETED_FE is set special handling is needed for directory
2570 * entries. Dependant pieces related to the directory entry may
2571 * have already been synced to disk. If this occurs we have to
2572 * sync the directory entry and then change the in-memory record
2573 * from an ADD to a DELETE to cover the fact that it's been
2574 * deleted by the frontend.
2576 * A directory delete covering record (MEM_RECORD_DEL) can never
2577 * be deleted by the frontend.
2579 * Any other record type (aka DATA) can be deleted by the frontend.
2580 * XXX At the moment the flusher must skip it because there may
2581 * be another data record in the flush group for the same block,
2582 * meaning that some frontend data changes can leak into the backend's
2583 * synchronization point.
2585 if (record->flags & HAMMER_RECF_DELETED_FE) {
2586 if (record->type == HAMMER_MEM_RECORD_ADD) {
2588 * Convert a front-end deleted directory-add to
2589 * a directory-delete entry later.
2591 record->flags |= HAMMER_RECF_CONVERT_DELETE;
2594 * Dispose of the record (race case). Mark as
2595 * deleted by backend (and not committed).
2597 KKASSERT(record->type != HAMMER_MEM_RECORD_DEL);
2598 record->flags |= HAMMER_RECF_DELETED_BE;
2599 ++record->ip->rec_generation;
2606 * Assign the create_tid for new records. Deletions already
2607 * have the record's entire key properly set up.
2609 if (record->type != HAMMER_MEM_RECORD_DEL) {
2610 record->leaf.base.create_tid = trans->tid;
2611 record->leaf.create_ts = trans->time32;
2615 * This actually moves the record to the on-media B-Tree. We
2616 * must also generate REDO_TERM entries in the UNDO/REDO FIFO
2617 * indicating that the related REDO_WRITE(s) have been committed.
2619 * During recovery any REDO_TERM's within the nominal recovery span
2620 * are ignored since the related meta-data is being undone, causing
2621 * any matching REDO_WRITEs to execute. The REDO_TERMs outside
2622 * the nominal recovery span will match against REDO_WRITEs and
2623 * prevent them from being executed (because the meta-data has
2624 * already been synchronized).
2626 if (record->flags & HAMMER_RECF_REDO) {
2627 KKASSERT(record->type == HAMMER_MEM_RECORD_DATA);
2628 hammer_generate_redo(trans, record->ip,
2629 record->leaf.base.key -
2630 record->leaf.data_len,
2631 HAMMER_REDO_TERM_WRITE,
2633 record->leaf.data_len);
2636 error = hammer_ip_sync_record_cursor(cursor, record);
2637 if (error != EDEADLK)
2639 hammer_done_cursor(cursor);
2640 error = hammer_init_cursor(trans, cursor, &record->ip->cache[0],
2645 record->flags &= ~HAMMER_RECF_CONVERT_DELETE;
2650 hammer_flush_record_done(record, error);
2653 * Do partial finalization if we have built up too many dirty
2654 * buffers. Otherwise a buffer cache deadlock can occur when
2655 * doing things like creating tens of thousands of tiny files.
2657 * We must release our cursor lock to avoid a 3-way deadlock
2658 * due to the exclusive sync lock the finalizer must get.
2660 * WARNING: See warnings in hammer_unlock_cursor() function.
2662 if (hammer_flusher_meta_limit(hmp)) {
2663 hammer_unlock_cursor(cursor);
2664 hammer_flusher_finalize(trans, 0);
2665 hammer_lock_cursor(cursor);
2672 * Backend function called by the flusher to sync an inode to media.
2675 hammer_sync_inode(hammer_transaction_t trans, hammer_inode_t ip)
2677 struct hammer_cursor cursor;
2678 hammer_node_t tmp_node;
2679 hammer_record_t depend;
2680 hammer_record_t next;
2681 int error, tmp_error;
2684 if ((ip->sync_flags & HAMMER_INODE_MODMASK) == 0)
2687 error = hammer_init_cursor(trans, &cursor, &ip->cache[1], ip);
2692 * Any directory records referencing this inode which are not in
2693 * our current flush group must adjust our nlink count for the
2694 * purposes of synchronizating to disk.
2696 * Records which are in our flush group can be unlinked from our
2697 * inode now, potentially allowing the inode to be physically
2700 * This cannot block.
2702 nlinks = ip->ino_data.nlinks;
2703 next = TAILQ_FIRST(&ip->target_list);
2704 while ((depend = next) != NULL) {
2705 next = TAILQ_NEXT(depend, target_entry);
2706 if (depend->flush_state == HAMMER_FST_FLUSH &&
2707 depend->flush_group == ip->flush_group) {
2709 * If this is an ADD that was deleted by the frontend
2710 * the frontend nlinks count will have already been
2711 * decremented, but the backend is going to sync its
2712 * directory entry and must account for it. The
2713 * record will be converted to a delete-on-disk when
2716 * If the ADD was not deleted by the frontend we
2717 * can remove the dependancy from our target_list.
2719 if (depend->flags & HAMMER_RECF_DELETED_FE) {
2722 TAILQ_REMOVE(&ip->target_list, depend,
2724 depend->target_ip = NULL;
2726 } else if ((depend->flags & HAMMER_RECF_DELETED_FE) == 0) {
2728 * Not part of our flush group and not deleted by
2729 * the front-end, adjust the link count synced to
2730 * the media (undo what the frontend did when it
2731 * queued the record).
2733 KKASSERT((depend->flags & HAMMER_RECF_DELETED_BE) == 0);
2734 switch(depend->type) {
2735 case HAMMER_MEM_RECORD_ADD:
2738 case HAMMER_MEM_RECORD_DEL:
2748 * Set dirty if we had to modify the link count.
2750 if (ip->sync_ino_data.nlinks != nlinks) {
2751 KKASSERT((int64_t)nlinks >= 0);
2752 ip->sync_ino_data.nlinks = nlinks;
2753 ip->sync_flags |= HAMMER_INODE_DDIRTY;
2757 * If there is a trunction queued destroy any data past the (aligned)
2758 * truncation point. Userland will have dealt with the buffer
2759 * containing the truncation point for us.
2761 * We don't flush pending frontend data buffers until after we've
2762 * dealt with the truncation.
2764 if (ip->sync_flags & HAMMER_INODE_TRUNCATED) {
2766 * Interlock trunc_off. The VOP front-end may continue to
2767 * make adjustments to it while we are blocked.
2770 off_t aligned_trunc_off;
2773 trunc_off = ip->sync_trunc_off;
2774 blkmask = hammer_blocksize(trunc_off) - 1;
2775 aligned_trunc_off = (trunc_off + blkmask) & ~(int64_t)blkmask;
2778 * Delete any whole blocks on-media. The front-end has
2779 * already cleaned out any partial block and made it
2780 * pending. The front-end may have updated trunc_off
2781 * while we were blocked so we only use sync_trunc_off.
2783 * This operation can blow out the buffer cache, EWOULDBLOCK
2784 * means we were unable to complete the deletion. The
2785 * deletion will update sync_trunc_off in that case.
2787 error = hammer_ip_delete_range(&cursor, ip,
2789 0x7FFFFFFFFFFFFFFFLL, 2);
2790 if (error == EWOULDBLOCK) {
2791 ip->flags |= HAMMER_INODE_WOULDBLOCK;
2793 goto defer_buffer_flush;
2800 * Generate a REDO_TERM_TRUNC entry in the UNDO/REDO FIFO.
2802 * XXX we do this even if we did not previously generate
2803 * a REDO_TRUNC record. This operation may enclosed the
2804 * range for multiple prior truncation entries in the REDO
2807 if (trans->hmp->version >= HAMMER_VOL_VERSION_FOUR &&
2808 (ip->flags & HAMMER_INODE_RDIRTY)) {
2809 hammer_generate_redo(trans, ip, aligned_trunc_off,
2810 HAMMER_REDO_TERM_TRUNC,
2815 * Clear the truncation flag on the backend after we have
2816 * completed the deletions. Backend data is now good again
2817 * (including new records we are about to sync, below).
2819 * Leave sync_trunc_off intact. As we write additional
2820 * records the backend will update sync_trunc_off. This
2821 * tells the backend whether it can skip the overwrite
2822 * test. This should work properly even when the backend
2823 * writes full blocks where the truncation point straddles
2824 * the block because the comparison is against the base
2825 * offset of the record.
2827 ip->sync_flags &= ~HAMMER_INODE_TRUNCATED;
2828 /* ip->sync_trunc_off = 0x7FFFFFFFFFFFFFFFLL; */
2834 * Now sync related records. These will typically be directory
2835 * entries, records tracking direct-writes, or delete-on-disk records.
2838 tmp_error = RB_SCAN(hammer_rec_rb_tree, &ip->rec_tree, NULL,
2839 hammer_sync_record_callback, &cursor);
2845 hammer_cache_node(&ip->cache[1], cursor.node);
2848 * Re-seek for inode update, assuming our cache hasn't been ripped
2849 * out from under us.
2852 tmp_node = hammer_ref_node_safe(trans, &ip->cache[0], &error);
2854 hammer_cursor_downgrade(&cursor);
2855 hammer_lock_sh(&tmp_node->lock);
2856 if ((tmp_node->flags & HAMMER_NODE_DELETED) == 0)
2857 hammer_cursor_seek(&cursor, tmp_node, 0);
2858 hammer_unlock(&tmp_node->lock);
2859 hammer_rel_node(tmp_node);
2865 * If we are deleting the inode the frontend had better not have
2866 * any active references on elements making up the inode.
2868 * The call to hammer_ip_delete_clean() cleans up auxillary records
2869 * but not DB or DATA records. Those must have already been deleted
2870 * by the normal truncation mechanic.
2872 if (error == 0 && ip->sync_ino_data.nlinks == 0 &&
2873 RB_EMPTY(&ip->rec_tree) &&
2874 (ip->sync_flags & HAMMER_INODE_DELETING) &&
2875 (ip->flags & HAMMER_INODE_DELETED) == 0) {
2878 error = hammer_ip_delete_clean(&cursor, ip, &count1);
2880 ip->flags |= HAMMER_INODE_DELETED;
2881 ip->sync_flags &= ~HAMMER_INODE_DELETING;
2882 ip->sync_flags &= ~HAMMER_INODE_TRUNCATED;
2883 KKASSERT(RB_EMPTY(&ip->rec_tree));
2886 * Set delete_tid in both the frontend and backend
2887 * copy of the inode record. The DELETED flag handles
2888 * this, do not set DDIRTY.
2890 ip->ino_leaf.base.delete_tid = trans->tid;
2891 ip->sync_ino_leaf.base.delete_tid = trans->tid;
2892 ip->ino_leaf.delete_ts = trans->time32;
2893 ip->sync_ino_leaf.delete_ts = trans->time32;
2897 * Adjust the inode count in the volume header
2899 hammer_sync_lock_sh(trans);
2900 if (ip->flags & HAMMER_INODE_ONDISK) {
2901 hammer_modify_volume_field(trans,
2904 --ip->hmp->rootvol->ondisk->vol0_stat_inodes;
2905 hammer_modify_volume_done(trans->rootvol);
2907 hammer_sync_unlock(trans);
2913 ip->sync_flags &= ~HAMMER_INODE_BUFS;
2917 * Now update the inode's on-disk inode-data and/or on-disk record.
2918 * DELETED and ONDISK are managed only in ip->flags.
2920 * In the case of a defered buffer flush we still update the on-disk
2921 * inode to satisfy visibility requirements if there happen to be
2922 * directory dependancies.
2924 switch(ip->flags & (HAMMER_INODE_DELETED | HAMMER_INODE_ONDISK)) {
2925 case HAMMER_INODE_DELETED|HAMMER_INODE_ONDISK:
2927 * If deleted and on-disk, don't set any additional flags.
2928 * the delete flag takes care of things.
2930 * Clear flags which may have been set by the frontend.
2932 ip->sync_flags &= ~(HAMMER_INODE_DDIRTY | HAMMER_INODE_XDIRTY |
2933 HAMMER_INODE_SDIRTY |
2934 HAMMER_INODE_ATIME | HAMMER_INODE_MTIME |
2935 HAMMER_INODE_DELETING);
2937 case HAMMER_INODE_DELETED:
2939 * Take care of the case where a deleted inode was never
2940 * flushed to the disk in the first place.
2942 * Clear flags which may have been set by the frontend.
2944 ip->sync_flags &= ~(HAMMER_INODE_DDIRTY | HAMMER_INODE_XDIRTY |
2945 HAMMER_INODE_SDIRTY |
2946 HAMMER_INODE_ATIME | HAMMER_INODE_MTIME |
2947 HAMMER_INODE_DELETING);
2948 while (RB_ROOT(&ip->rec_tree)) {
2949 hammer_record_t record = RB_ROOT(&ip->rec_tree);
2950 hammer_ref(&record->lock);
2951 KKASSERT(record->lock.refs == 1);
2952 record->flags |= HAMMER_RECF_DELETED_BE;
2953 ++record->ip->rec_generation;
2954 hammer_rel_mem_record(record);
2957 case HAMMER_INODE_ONDISK:
2959 * If already on-disk, do not set any additional flags.
2964 * If not on-disk and not deleted, set DDIRTY to force
2965 * an initial record to be written.
2967 * Also set the create_tid in both the frontend and backend
2968 * copy of the inode record.
2970 ip->ino_leaf.base.create_tid = trans->tid;
2971 ip->ino_leaf.create_ts = trans->time32;
2972 ip->sync_ino_leaf.base.create_tid = trans->tid;
2973 ip->sync_ino_leaf.create_ts = trans->time32;
2974 ip->sync_flags |= HAMMER_INODE_DDIRTY;
2979 * If DDIRTY or SDIRTY is set, write out a new record.
2980 * If the inode is already on-disk the old record is marked as
2983 * If DELETED is set hammer_update_inode() will delete the existing
2984 * record without writing out a new one.
2986 * If *ONLY* the ITIMES flag is set we can update the record in-place.
2988 if (ip->flags & HAMMER_INODE_DELETED) {
2989 error = hammer_update_inode(&cursor, ip);
2991 if (!(ip->sync_flags & (HAMMER_INODE_DDIRTY | HAMMER_INODE_SDIRTY)) &&
2992 (ip->sync_flags & (HAMMER_INODE_ATIME | HAMMER_INODE_MTIME))) {
2993 error = hammer_update_itimes(&cursor, ip);
2995 if (ip->sync_flags & (HAMMER_INODE_DDIRTY | HAMMER_INODE_SDIRTY |
2996 HAMMER_INODE_ATIME | HAMMER_INODE_MTIME)) {
2997 error = hammer_update_inode(&cursor, ip);
3001 hammer_critical_error(ip->hmp, ip, error,
3002 "while syncing inode");
3004 hammer_done_cursor(&cursor);
3009 * This routine is called when the OS is no longer actively referencing
3010 * the inode (but might still be keeping it cached), or when releasing
3011 * the last reference to an inode.
3013 * At this point if the inode's nlinks count is zero we want to destroy
3014 * it, which may mean destroying it on-media too.
3017 hammer_inode_unloadable_check(hammer_inode_t ip, int getvp)
3022 * Set the DELETING flag when the link count drops to 0 and the
3023 * OS no longer has any opens on the inode.
3025 * The backend will clear DELETING (a mod flag) and set DELETED
3026 * (a state flag) when it is actually able to perform the
3029 * Don't reflag the deletion if the flusher is currently syncing
3030 * one that was already flagged. A previously set DELETING flag
3031 * may bounce around flags and sync_flags until the operation is
3034 if (ip->ino_data.nlinks == 0 &&
3035 ((ip->flags | ip->sync_flags) & (HAMMER_INODE_DELETING|HAMMER_INODE_DELETED)) == 0) {
3036 ip->flags |= HAMMER_INODE_DELETING;
3037 ip->flags |= HAMMER_INODE_TRUNCATED;
3041 if (hammer_get_vnode(ip, &vp) != 0)
3049 vtruncbuf(ip->vp, 0, HAMMER_BUFSIZE);
3050 vnode_pager_setsize(ip->vp, 0);
3059 * After potentially resolving a dependancy the inode is tested
3060 * to determine whether it needs to be reflushed.
3063 hammer_test_inode(hammer_inode_t ip)
3065 if (ip->flags & HAMMER_INODE_REFLUSH) {
3066 ip->flags &= ~HAMMER_INODE_REFLUSH;
3067 hammer_ref(&ip->lock);
3068 if (ip->flags & HAMMER_INODE_RESIGNAL) {
3069 ip->flags &= ~HAMMER_INODE_RESIGNAL;
3070 hammer_flush_inode(ip, HAMMER_FLUSH_SIGNAL);
3072 hammer_flush_inode(ip, 0);
3074 hammer_rel_inode(ip, 0);
3079 * Clear the RECLAIM flag on an inode. This occurs when the inode is
3080 * reassociated with a vp or just before it gets freed.
3082 * Pipeline wakeups to threads blocked due to an excessive number of
3083 * detached inodes. This typically occurs when atime updates accumulate
3084 * while scanning a directory tree.
3087 hammer_inode_wakereclaims(hammer_inode_t ip)
3089 struct hammer_reclaim *reclaim;
3090 hammer_mount_t hmp = ip->hmp;
3092 if ((ip->flags & HAMMER_INODE_RECLAIM) == 0)
3095 --hammer_count_reclaiming;
3096 --hmp->inode_reclaims;
3097 ip->flags &= ~HAMMER_INODE_RECLAIM;
3099 while ((reclaim = TAILQ_FIRST(&hmp->reclaim_list)) != NULL) {
3100 if (reclaim->count > 0 && --reclaim->count == 0) {
3101 TAILQ_REMOVE(&hmp->reclaim_list, reclaim, entry);
3104 if (hmp->inode_reclaims > hammer_limit_reclaim / 2)
3110 * Setup our reclaim pipeline. We only let so many detached (and dirty)
3111 * inodes build up before we start blocking. This routine is called
3112 * if a new inode is created or an inode is loaded from media.
3114 * When we block we don't care *which* inode has finished reclaiming,
3115 * as lone as one does.
3118 hammer_inode_waitreclaims(hammer_mount_t hmp)
3120 struct hammer_reclaim reclaim;
3122 if (hmp->inode_reclaims < hammer_limit_reclaim)
3125 TAILQ_INSERT_TAIL(&hmp->reclaim_list, &reclaim, entry);
3126 tsleep(&reclaim, 0, "hmrrcm", hz);
3127 if (reclaim.count > 0)
3128 TAILQ_REMOVE(&hmp->reclaim_list, &reclaim, entry);
3134 * XXX not used, doesn't work very well due to the large batching nature
3137 * A larger then normal backlog of inodes is sitting in the flusher,
3138 * enforce a general slowdown to let it catch up. This routine is only
3139 * called on completion of a non-flusher-related transaction which
3140 * performed B-Tree node I/O.
3142 * It is possible for the flusher to stall in a continuous load.
3143 * blogbench -i1000 -o seems to do a good job generating this sort of load.
3144 * If the flusher is unable to catch up the inode count can bloat until
3145 * we run out of kvm.
3147 * This is a bit of a hack.
3150 hammer_inode_waithard(hammer_mount_t hmp)
3155 if (hmp->flags & HAMMER_MOUNT_FLUSH_RECOVERY) {
3156 if (hmp->inode_reclaims < hammer_limit_reclaim / 2 &&
3157 hmp->count_iqueued < hmp->count_inodes / 20) {
3158 hmp->flags &= ~HAMMER_MOUNT_FLUSH_RECOVERY;
3162 if (hmp->inode_reclaims < hammer_limit_reclaim ||
3163 hmp->count_iqueued < hmp->count_inodes / 10) {
3166 hmp->flags |= HAMMER_MOUNT_FLUSH_RECOVERY;
3170 * Block for one flush cycle.
3172 hammer_flusher_wait_next(hmp);