-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Comments
This is related to #9381 and seems to be related to #9461 which affects me. 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? |
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. |
System information
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:
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
The text was updated successfully, but these errors were encountered: