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

0.8.3: snapshot does not automount in initramfs #10128

Closed
JKDingwall opened this issue Mar 13, 2020 · 2 comments
Closed

0.8.3: snapshot does not automount in initramfs #10128

JKDingwall opened this issue Mar 13, 2020 · 2 comments
Labels
Status: Stale No recent activity for issue

Comments

@JKDingwall
Copy link
Contributor

System information

Type Version/Name
Distribution Name Ubuntu
Distribution Version 18.04
Linux Kernel 5.3.0-41
Architecture x86_64 / amd64
ZFS Version 0.8.3
SPL Version 0.8.3

Describe the problem you're observing

We have some custom initramfs scripts which load a squashfs root image from a zfs snapshot. I substituted /usr/bin/env to be a wrapper to catch the command line:

mount -t zfs -n zpool/filesystems/root@snap1234 /.zfs/snapshot/snap1234

i.e. the leading zfs path is absent from the mountpoint. Reverting 5a1bf9e and 093bb64 has resolved the issue. It was possible to manually correct the mount command to get access to the snapshot content.

Describe how to reproduce the problem

Break in the initramfs, import zpool, try to cd to a snapshot directory.

Include any warning/errors/backtraces from the system logs

@ccorn
Copy link

ccorn commented Mar 21, 2020

This is related to #9381 and seems to be related to #9461 which affects me.
And thanks to @JKDingwall having identified the cause I decided to checkout some recent code (d3fe62c as of 2020-03-13). The issue remained.
Then I did git revert -n 5a1bf9e 093bb64 and the issue indeed disappeared.
For reference, this is the diff resulting from the reverts:

diff --git a/module/os/linux/zfs/zfs_ctldir.c b/module/os/linux/zfs/zfs_ctldir.c
index c2748ce45..c04654394 100644
--- a/module/os/linux/zfs/zfs_ctldir.c
+++ b/module/os/linux/zfs/zfs_ctldir.c
@@ -704,6 +704,37 @@ zfsctl_snapshot_name(zfsvfs_t *zfsvfs, const char *snap_name, int len,
 	return (0);
 }
 
+/*
+ * Returns full path in full_path: "/pool/dataset/.zfs/snapshot/snap_name/"
+ */
+static int
+zfsctl_snapshot_path(struct path *path, int len, char *full_path)
+{
+	char *path_buffer, *path_ptr;
+	int path_len, error = 0;
+
+	path_buffer = kmem_alloc(len, KM_SLEEP);
+
+	path_ptr = d_path(path, path_buffer, len);
+	if (IS_ERR(path_ptr)) {
+		error = -PTR_ERR(path_ptr);
+		goto out;
+	}
+
+	path_len = path_buffer + len - 1 - path_ptr;
+	if (path_len > len) {
+		error = SET_ERROR(EFAULT);
+		goto out;
+	}
+
+	memcpy(full_path, path_ptr, path_len);
+	full_path[path_len] = '\0';
+out:
+	kmem_free(path_buffer, len);
+
+	return (error);
+}
+
 /*
  * Returns full path in full_path: "/pool/dataset/.zfs/snapshot/snap_name/"
  */
@@ -1047,14 +1078,9 @@ zfsctl_snapshot_mount(struct path *path, int flags)
 	if (error)
 		goto error;
 
-	/*
-	 * Construct a mount point path from sb of the ctldir inode and dirent
-	 * name, instead of from d_path(), so that chroot'd process doesn't fail
-	 * on mount.zfs(8).
-	 */
-	snprintf(full_path, MAXPATHLEN, "%s/.zfs/snapshot/%s",
-	    zfsvfs->z_vfs->vfs_mntpoint ? zfsvfs->z_vfs->vfs_mntpoint : "",
-	    dname(dentry));
+	error = zfsctl_snapshot_path(path, MAXPATHLEN, full_path);
+	if (error)
+		goto error;
 
 	/*
 	 * Multiple concurrent automounts of a snapshot are never allowed.

So 5a1bf9e 093bb64 have broken automounts in initramfs. How to address this?

@stale
Copy link

stale bot commented Mar 21, 2021

This issue has been automatically marked as "stale" because it has not had any activity for a while. It will be closed in 90 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale No recent activity for issue label Mar 21, 2021
@stale stale bot closed this as completed Jun 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale No recent activity for issue
Projects
None yet
Development

No branches or pull requests

2 participants