Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cptofs: remount as read-only prior to exiting #534

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tools/lkl/cptofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,27 @@ int main(int argc, char **argv)
break;
}

/* FIXME: Remouting as readonly seems to be required to make sure the filessytem is cleanly umounted. Otherwise the journal will be still dirty... */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good as a workaround, but I would like to investigate the root cause. Do you have a way to reproduce this?

Copy link
Author

@Mic92 Mic92 Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ truncate -s 10G /tmp/foo.img
$ mkfs.ext4 /tmp/foo.img         
$ ./tools/lkl/cptofs -p -o 1000 -g 1000 -t ext4 -i /tmp/foo.img ./tools/lkl/tests  / 

Now if you try to mount the image read-only, you can see hat it fails because of the unclean journal

$ mount -o ro /tmp/foo.img /mnt

The error will show up in dmesg.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tavip did you managed to reproduce the issue? This would block us updating lkl in NixOS, where we use it for building disk images without the need for KVM.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I found the root cause but it is turning out more difficult to fix than I expected. Lets merge this for now. Thanks for the ping.

char dev_str[] = { "/dev/xxxxxxxx" };

snprintf(dev_str, sizeof(dev_str), "/dev/%08x", disk_id);
for (;;) {
ret = lkl_sys_mount(dev_str, mpoint, (char *)cla.fsimg_type, LKL_MS_RDONLY|LKL_MS_REMOUNT, NULL);
if (ret == 0)
break;
if (ret == -EBUSY) {
struct lkl_timespec ts = {
.tv_sec = 1,
.tv_nsec = 0,
};
lkl_sys_nanosleep((struct __lkl__kernel_timespec *)&ts, NULL);
continue;
} else if (ret < 0) {
fprintf(stderr, "cannot remount mount disk read-only: %s\n", lkl_strerror(ret));
break;
}
}

umount_ret = lkl_umount_dev(disk_id, cla.part, 0, 1000);
if (ret == 0)
ret = umount_ret;
Expand Down
Loading