Skip to content

Commit 5b153d1

Browse files
behlendorfRageLtMan
authored andcommitted
Linux: Fix mount/unmount when dataset name has a space
The custom zpl_show_devname() helper should translate spaces in to the octal escape sequence \040. The getmntent(2) function is aware of this convention and properly translates the escape character back to a space when reading the fsname. Without this change the `zfs mount` and `zfs unmount` commands incorrectly detect when a dataset with a name containing spaces is mounted. Reviewed-by: Ryan Moeller <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes openzfs#11182 Closes openzfs#11187
1 parent 6b42c17 commit 5b153d1

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

module/os/linux/zfs/zpl_super.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,26 @@ zpl_remount_fs(struct super_block *sb, int *flags, char *data)
185185
static int
186186
__zpl_show_devname(struct seq_file *seq, zfsvfs_t *zfsvfs)
187187
{
188-
char *fsname;
189-
190188
ZFS_ENTER(zfsvfs);
191-
fsname = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP);
189+
190+
char *fsname = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP);
192191
dmu_objset_name(zfsvfs->z_os, fsname);
193-
seq_puts(seq, fsname);
192+
193+
for (int i = 0; fsname[i] != 0; i++) {
194+
/*
195+
* Spaces in the dataset name must be converted to their
196+
* octal escape sequence for getmntent(3) to correctly
197+
* parse then fsname portion of /proc/self/mounts.
198+
*/
199+
if (fsname[i] == ' ') {
200+
seq_puts(seq, "\\040");
201+
} else {
202+
seq_putc(seq, fsname[i]);
203+
}
204+
}
205+
194206
kmem_free(fsname, ZFS_MAX_DATASET_NAME_LEN);
207+
195208
ZFS_EXIT(zfsvfs);
196209

197210
return (0);

tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_001_pos.ksh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ function cleanup
5151
log_must zfs destroy -f ${datasets[$i]}
5252
((i = i + 1))
5353
done
54+
55+
zfs destroy -f "$TESTPOOL/with a space"
5456
}
5557

5658
log_onexit cleanup
@@ -68,4 +70,8 @@ while (( $i < ${#datasets[*]} )); do
6870
((i = i + 1))
6971
done
7072

73+
log_must zfs create "$TESTPOOL/with a space"
74+
log_must zfs unmount "$TESTPOOL/with a space"
75+
log_must zfs mount "$TESTPOOL/with a space"
76+
7177
log_pass "'zfs create <filesystem>' works as expected."

0 commit comments

Comments
 (0)