Project

General

Profile

Actions

Bug #3202

closed

Cannot boot from HAMMER2

Added by mneumann about 5 years ago. Updated almost 3 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
Kernel
Target version:
Start date:
08/30/2019
Due date:
% Done:

100%

Estimated time:

Description

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)
return(1);
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.

Actions #1

Updated by liweitianux almost 3 years ago

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):

 995         /*
 996          * Locate an unused key in the collision space.
 997          */
 998         {
 999                 hammer2_xop_scanlhc_t *sxop;
1000                 hammer2_key_t lhcbase;
1001 
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);
1012 
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.

Actions #2

Updated by liweitianux almost 3 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

A modified patch pushed to master in commits d7e11471bd451b05672ba37334898eaa52f35415 and 2ad4d0e44d46f6fc8f0a772fce2898c8b8f896c8 by Matt.

Actions

Also available in: Atom PDF