Skip to content

Commit 7f25f04

Browse files
committed
Merge tag 'fs.mount_setattr.v5.17-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux
Pull mount_setattr test/doc fixes from Christian Brauner: "This contains a fix for one of the selftests for the mount_setattr syscall to create idmapped mounts, an entry for idmapped mounts for maintainers, and missing kernel documentation for the helper we split out some time ago to get and yield write access to a mount when changing mount properties" * tag 'fs.mount_setattr.v5.17-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux: fs: add kernel doc for mnt_{hold,unhold}_writers() MAINTAINERS: add entry for idmapped mounts tests: fix idmapped mount_setattr test
2 parents c1034d2 + 538f4f0 commit 7f25f04

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

MAINTAINERS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9263,6 +9263,15 @@ S: Maintained
92639263
W: https://github.com/o2genum/ideapad-slidebar
92649264
F: drivers/input/misc/ideapad_slidebar.c
92659265

9266+
IDMAPPED MOUNTS
9267+
M: Christian Brauner <brauner@kernel.org>
9268+
L: linux-fsdevel@vger.kernel.org
9269+
S: Maintained
9270+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git
9271+
F: Documentation/filesystems/idmappings.rst
9272+
F: tools/testing/selftests/mount_setattr/
9273+
F: include/linux/mnt_idmapping.h
9274+
92669275
IDT VersaClock 5 CLOCK DRIVER
92679276
M: Luca Ceresoli <luca@lucaceresoli.net>
92689277
S: Maintained

fs/namespace.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,24 @@ void mnt_drop_write_file(struct file *file)
469469
}
470470
EXPORT_SYMBOL(mnt_drop_write_file);
471471

472+
/**
473+
* mnt_hold_writers - prevent write access to the given mount
474+
* @mnt: mnt to prevent write access to
475+
*
476+
* Prevents write access to @mnt if there are no active writers for @mnt.
477+
* This function needs to be called and return successfully before changing
478+
* properties of @mnt that need to remain stable for callers with write access
479+
* to @mnt.
480+
*
481+
* After this functions has been called successfully callers must pair it with
482+
* a call to mnt_unhold_writers() in order to stop preventing write access to
483+
* @mnt.
484+
*
485+
* Context: This function expects lock_mount_hash() to be held serializing
486+
* setting MNT_WRITE_HOLD.
487+
* Return: On success 0 is returned.
488+
* On error, -EBUSY is returned.
489+
*/
472490
static inline int mnt_hold_writers(struct mount *mnt)
473491
{
474492
mnt->mnt.mnt_flags |= MNT_WRITE_HOLD;
@@ -500,6 +518,18 @@ static inline int mnt_hold_writers(struct mount *mnt)
500518
return 0;
501519
}
502520

521+
/**
522+
* mnt_unhold_writers - stop preventing write access to the given mount
523+
* @mnt: mnt to stop preventing write access to
524+
*
525+
* Stop preventing write access to @mnt allowing callers to gain write access
526+
* to @mnt again.
527+
*
528+
* This function can only be called after a successful call to
529+
* mnt_hold_writers().
530+
*
531+
* Context: This function expects lock_mount_hash() to be held.
532+
*/
503533
static inline void mnt_unhold_writers(struct mount *mnt)
504534
{
505535
/*

tools/testing/selftests/mount_setattr/mount_setattr_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ static int get_userns_fd(unsigned long nsid, unsigned long hostid, unsigned long
12361236
}
12371237

12381238
/**
1239-
* Validate that an attached mount in our mount namespace can be idmapped.
1239+
* Validate that an attached mount in our mount namespace cannot be idmapped.
12401240
* (The kernel enforces that the mount's mount namespace and the caller's mount
12411241
* namespace match.)
12421242
*/
@@ -1259,7 +1259,7 @@ TEST_F(mount_setattr_idmapped, attached_mount_inside_current_mount_namespace)
12591259

12601260
attr.userns_fd = get_userns_fd(0, 10000, 10000);
12611261
ASSERT_GE(attr.userns_fd, 0);
1262-
ASSERT_EQ(sys_mount_setattr(open_tree_fd, "", AT_EMPTY_PATH, &attr, sizeof(attr)), 0);
1262+
ASSERT_NE(sys_mount_setattr(open_tree_fd, "", AT_EMPTY_PATH, &attr, sizeof(attr)), 0);
12631263
ASSERT_EQ(close(attr.userns_fd), 0);
12641264
ASSERT_EQ(close(open_tree_fd), 0);
12651265
}

0 commit comments

Comments
 (0)