[DragonFlyBSD - Bug #3202] Cannot boot from HAMMER2

bugtracker-admin at leaf.dragonflybsd.org bugtracker-admin at leaf.dragonflybsd.org
Fri Dec 31 17:19:25 PST 2021

Issue #3202 has been updated by liweitianux.

I investigated this issue a bit and found that the extra 1 in @BOOT@ inode number was caused by
@hammer2_inode_create_pfs()@ on line 1016 (see below):

<pre><code class="c">
 995         /*
 996          * Locate an unused key in the collision space.
 997          */
 998         {
 999                 hammer2_xop_scanlhc_t *sxop;
1000                 hammer2_key_t lhcbase;
1002                 lhcbase = lhc;
1003                 sxop = hammer2_xop_alloc(pip, HAMMER2_XOP_MODIFYING);
1004                 sxop->lhc = lhc;
1005                 hammer2_xop_start(&sxop->head, &hammer2_scanlhc_desc);
1006                 while ((error = hammer2_xop_collect(&sxop->head, 0)) == 0) {
1007                         if (lhc != sxop->head.cluster.focus->bref.key)
1008                                 break;
1009                         ++lhc;
1010                 }
1011                 hammer2_xop_retire(&sxop->head, HAMMER2_XOPMASK_VOP);
1013                 if (error) {
1014                         if (error != HAMMER2_ERROR_ENOENT)
1015                                 goto done2;
1016                         ++lhc;  // <-- THIS
1017                         error = 0;
1018                 }
1019                 if ((lhcbase ^ lhc) & ~HAMMER2_DIRHASH_LOMASK) {
1020                         error = HAMMER2_ERROR_ENOSPC;
1021                         goto done2;
1022                 }
1023         }

It looks to me that the @++lhc@ is unnecessary, because the returned code is
@HAMMER2_ERROR_ENOENT@ which indicates the inode number could be used.
But I'm not sure why that @++lhc@ is needed.

So with @hammer2 pfs-create BOOT@, the created @BOOT@ PFS has inode number
@0xd9b36ce135528000 + 1@, due to the @++lhc@ above.

However with @newfs_hammer2 -L BOOT@, the inode number would be @0xd9b36ce135528000@,
the same as @hammer2 hash BOOT at .

Bug #3202: Cannot boot from HAMMER2

* Author: mneumann
* Status: New
* Priority: Normal
* Category: Kernel
* Target version: 6.2
* Start date: 2019-08-30
Booting from HAMMER2 "BOOT" PFS works when created via "newfs_hammer2 -L BOOT".

But when I use "hammer2 pfs-create BOOT", I got the message "hammer2: 'BOOT' PFS not found".
I might have created and deleted the "BOOT" PFS multiple times on that file system.

My BOOT PFS inode number is "0xd9b36ce135528001", but HAMMER2_BOOT_KEY is defined as "0xd9b36ce135528000".
With the following patch I can successfully boot from HAMMER2:

--- a/lib/libstand/hammer2.c
+++ b/lib/libstand/hammer2.c
@@ -692,7 +692,7 @@ h2init(struct hammer2_fs *hfs)
        h2lookup(hfs, NULL, 0, 0, NULL, NULL);
        r = h2lookup(hfs, &hfs->sroot,
-                    HAMMER2_BOOT_KEY, HAMMER2_BOOT_KEY,
+                    HAMMER2_BOOT_KEY, HAMMER2_BOOT_KEY | 0xFFFFU,
                     &hfs->sroot, &data);
        if (r <= 0) {
                printf("hammer2: 'BOOT' PFS not found\n");

I am not sure if this is 100% the right approach.
I would rather like to check for the name explicitly as there can be hash collisions.

To successfully boot from HAMMER2, I have to "set currdev="disk0s1d" and then 
"cd /kernel" and then follow normal boot procedure (loadall, boot).

To really be useful, one would have to allow other PFSes than "BOOT" to be booted from,
so that you can boot from a snapshot for instance.

You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account

More information about the Bugs mailing list