Bug 259090 - UFS: bad file descriptor: soft update journaling can not be enabled on some FreeBSD-provided disk images – failed to write updated cg
Summary: UFS: bad file descriptor: soft update journaling can not be enabled on some F...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 13.1-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-12 06:45 UTC by Graham Perrin
Modified: 2022-11-20 17:30 UTC (History)
5 users (show)

See Also:


Attachments
First boot from FreeBSD-13.0-RELEASE-amd64.vhd (82.11 KB, image/png)
2021-10-12 06:45 UTC, Graham Perrin
no flags Details
First boot from FreeBSD-13.0-STABLE-amd64.vhd (68.02 KB, image/png)
2021-10-13 00:15 UTC, Graham Perrin
no flags Details
free BLK count(s) wrong in SUPERBLK, salvaged (29.00 KB, image/png)
2021-10-13 00:19 UTC, Graham Perrin
no flags Details
Screenshot: FreeBSD-12.3-PRERELEASE-amd64.vhd OK (42.84 KB, image/png)
2021-11-03 00:52 UTC, Graham Perrin
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Graham Perrin freebsd_committer freebsd_triage 2021-10-12 06:45:22 UTC
Created attachment 228616 [details]
First boot from FreeBSD-13.0-RELEASE-amd64.vhd

<https://download.freebsd.org/ftp/releases/VM-IMAGES/13.0-RELEASE/amd64/Latest/>
▼
FreeBSD-13.0-RELEASE-amd64.vhd.xz

Bug first observed yesterday <https://forums.freebsd.org/posts/536326> with a FreeBSD 14.0-CURRENT host: 

> inode 11021 in cg 0

Reproduced this morning <https://i.imgur.com/0dsd45V.png> with a Windows 10 host: 

> inode 7 in cg 0

Reproducible with a third installation, at first boot of the guest. Screenshot attached: 

> inode 11021 in cg 0

----

Not reproducible with FreeBSD-12.2-RELEASE-amd64.vhd.xz
Comment 1 Graham Perrin freebsd_committer freebsd_triage 2021-10-13 00:15:08 UTC
Created attachment 228638 [details]
First boot from FreeBSD-13.0-STABLE-amd64.vhd

Reproducible with stable/13. 

FreeBSD-13.0-STABLE-amd64.vhd extracted from 
FreeBSD-13.0-STABLE-amd64.vhd.xz (2021-10-07 04:54)
Comment 2 Graham Perrin freebsd_committer freebsd_triage 2021-10-13 00:19:29 UTC
Created attachment 228640 [details]
free BLK count(s) wrong in SUPERBLK, salvaged

Incidentally, also at first boot: 

> FREE BLK COUNT(S) WRONG IN SUPERBLK

– I assume that it's negligible, in the context of this bug.
Comment 3 Graham Perrin freebsd_committer freebsd_triage 2021-10-13 06:06:06 UTC
(In reply to Graham Perrin from comment #2)

To clarify: 

> FREE BLK COUNT(S) WRONG IN SUPERBLK

– this appears to result from the failed attempt to enable soft update journaling, i.e. (in single user mode): 


tunefs -j enable /
Comment 4 Kirk McKusick freebsd_committer freebsd_triage 2021-11-01 20:09:49 UTC
I have been able to reproduce the problem and will look into it.
Comment 5 Graham Perrin freebsd_committer freebsd_triage 2021-11-03 00:52:24 UTC
Created attachment 229232 [details]
Screenshot: FreeBSD-12.3-PRERELEASE-amd64.vhd OK

(In reply to Graham Perrin from comment #0)

> Not reproducible with FreeBSD-12.2-RELEASE-amd64.vhd.xz

Similarly, not reproducible with recent FreeBSD-12.3-PRERELEASE-amd64.vhd.xz – screenshot attached. 


(In reply to Kirk McKusick from comment #4)

Thanks.
Comment 6 Graham Perrin freebsd_committer freebsd_triage 2022-03-20 18:42:28 UTC
Reproducible with: 

FreeBSD-13.1-BETA2-amd64.vhd
Comment 7 Matthias Gamsjager 2022-05-17 10:11:52 UTC
Tried it on my RPI2 with FreeBSD generic 13.1-RELEASE FreeBSD 13.1-RELEASE releng/13.1-n250148-fc952ac2212 GENERIC arm

remounted R/O and ran:

root@generic:/home/freebsd # tunefs -j enable /
Using inode 4872 in cg 0 for 33554432 byte journal
tunefs: Failed to write updated cg: Bad file descriptor
tunefs: soft updates journaling cannot be enabled
tunefs: file system reloaded
Comment 8 BB Lister 2022-05-26 21:37:00 UTC
Tried also on FreeBSD 13.0-p11 (binary update from 12) to enable journaling on a secondary filesystem but I got 'using inode 6 in cg 0 for ..... byte journal' and 'failed to write updated cg: bad file descriptor'. The machine is on a virtio storage VPS (on a KVM cloud provider).

Thus I have to wait almost 30 minutes for an FSCK on this 400GB partition.
Comment 9 BB Lister 2022-08-20 14:09:31 UTC
I have used the FreeBSD 12.0 Live CD to boot this system, and enabled successfully the soft updates+journaling on the large filesystems. Definettly, there is something wrong in the FreeBSD 13.0 function to enable this functionality.
Comment 10 Kirk McKusick freebsd_committer freebsd_triage 2022-11-10 23:00:39 UTC
Please try this patch and see if it helps:

diff --git a/sbin/tunefs/tunefs.c b/sbin/tunefs/tunefs.c
index 11956f946ff5..bad31512daab 100644
--- a/sbin/tunefs/tunefs.c
+++ b/sbin/tunefs/tunefs.c
@@ -312,6 +312,8 @@ main(int argc, char *argv[])
        on = special = argv[0];
        if (ufs_disk_fillout(&disk, special) == -1)
                goto err;
+       if (ufs_disk_write(&disk) == -1)
+               goto err;
        /*
         * Check for unclean filesystem.
         */
Comment 11 commit-hook freebsd_committer freebsd_triage 2022-11-12 23:38:42 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5c7ba6bdf83fda82cce70f384e2ec8218f13002e

commit 5c7ba6bdf83fda82cce70f384e2ec8218f13002e
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2022-11-12 23:36:07 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2022-11-12 23:37:27 +0000

    Fix for tunefs(8) unable to add a UFS/FFS soft update journal.

    The reported bug is UFS: bad file descriptor: soft update journaling
    can not be enabled on some FreeBSD-provided disk images – failed
    to write updated cg.

    The UFS library (libufs(3)) failed to reopen its disk descriptor
    when first attempting to update a cylinder group. The error only
    occurred when trying to add journaling to a filesystem whose first
    cylinder group was too full to hold the journal.

    PR:           259090
    MFC after:    1 week
    Sponsored by: The FreeBSD Foundation

 lib/libufs/cgroup.c | 4 ++++
 1 file changed, 4 insertions(+)
Comment 12 commit-hook freebsd_committer freebsd_triage 2022-11-20 17:15:00 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=bca262f0f351e3881d478b7a9764c91ccb83c260

commit bca262f0f351e3881d478b7a9764c91ccb83c260
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2022-11-12 23:36:07 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2022-11-20 17:13:49 +0000

    Fix for tunefs(8) unable to add a UFS/FFS soft update journal.

    The reported bug is UFS: bad file descriptor: soft update journaling
    can not be enabled on some FreeBSD-provided disk images – failed
    to write updated cg.

    The UFS library (libufs(3)) failed to reopen its disk descriptor
    when first attempting to update a cylinder group. The error only
    occurred when trying to add journaling to a filesystem whose first
    cylinder group was too full to hold the journal.

    PR:           259090
    MFC after:    1 week
    Sponsored by: The FreeBSD Foundation

    (cherry picked from commit 5c7ba6bdf83fda82cce70f384e2ec8218f13002e)

 lib/libufs/cgroup.c | 4 ++++
 1 file changed, 4 insertions(+)
Comment 13 Kirk McKusick freebsd_committer freebsd_triage 2022-11-20 17:30:54 UTC
Has been MFC'ed to 13.

Not relevant to 12.