Skip to content

Commit

Permalink
Merge tag 'fsnotify_for_v6.15-rc5' of git://git.kernel.org/pub/scm/li…
Browse files Browse the repository at this point in the history
…nux/kernel/git/jack/linux-fs

Pull fsnotify fix from Jan Kara:
 "A fix for the recently merged mount notification support"

* tag 'fsnotify_for_v6.15-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs:
  selftests/fs/mount-notify: test also remove/flush of mntns marks
  fanotify: fix flush of mntns marks
  • Loading branch information
Linus Torvalds committed Apr 29, 2025
2 parents 02d4004 + cd188e9 commit fba784c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
7 changes: 1 addition & 6 deletions fs/notify/fanotify/fanotify_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -1961,12 +1961,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
return -EINVAL;

if (mark_cmd == FAN_MARK_FLUSH) {
if (mark_type == FAN_MARK_MOUNT)
fsnotify_clear_vfsmount_marks_by_group(group);
else if (mark_type == FAN_MARK_FILESYSTEM)
fsnotify_clear_sb_marks_by_group(group);
else
fsnotify_clear_inode_marks_by_group(group);
fsnotify_clear_marks_by_group(group, obj_type);
return 0;
}

Expand Down
15 changes: 0 additions & 15 deletions include/linux/fsnotify_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -907,21 +907,6 @@ extern void fsnotify_wait_marks_destroyed(void);
/* Clear all of the marks of a group attached to a given object type */
extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
unsigned int obj_type);
/* run all the marks in a group, and clear all of the vfsmount marks */
static inline void fsnotify_clear_vfsmount_marks_by_group(struct fsnotify_group *group)
{
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_VFSMOUNT);
}
/* run all the marks in a group, and clear all of the inode marks */
static inline void fsnotify_clear_inode_marks_by_group(struct fsnotify_group *group)
{
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_INODE);
}
/* run all the marks in a group, and clear all of the sn marks */
static inline void fsnotify_clear_sb_marks_by_group(struct fsnotify_group *group)
{
fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_SB);
}
extern void fsnotify_get_mark(struct fsnotify_mark *mark);
extern void fsnotify_put_mark(struct fsnotify_mark *mark);
extern void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ static uint64_t get_mnt_id(struct __test_metadata *const _metadata,

static const char root_mntpoint_templ[] = "/tmp/mount-notify_test_root.XXXXXX";

static const int mark_cmds[] = {
FAN_MARK_ADD,
FAN_MARK_REMOVE,
FAN_MARK_FLUSH
};

#define NUM_FAN_FDS ARRAY_SIZE(mark_cmds)

FIXTURE(fanotify) {
int fan_fd;
int fan_fd[NUM_FAN_FDS];
char buf[256];
unsigned int rem;
void *next;
Expand All @@ -61,7 +69,7 @@ FIXTURE(fanotify) {

FIXTURE_SETUP(fanotify)
{
int ret;
int i, ret;

ASSERT_EQ(unshare(CLONE_NEWNS), 0);

Expand Down Expand Up @@ -89,20 +97,34 @@ FIXTURE_SETUP(fanotify)
self->root_id = get_mnt_id(_metadata, "/");
ASSERT_NE(self->root_id, 0);

self->fan_fd = fanotify_init(FAN_REPORT_MNT, 0);
ASSERT_GE(self->fan_fd, 0);

ret = fanotify_mark(self->fan_fd, FAN_MARK_ADD | FAN_MARK_MNTNS,
FAN_MNT_ATTACH | FAN_MNT_DETACH, self->ns_fd, NULL);
ASSERT_EQ(ret, 0);
for (i = 0; i < NUM_FAN_FDS; i++) {
self->fan_fd[i] = fanotify_init(FAN_REPORT_MNT | FAN_NONBLOCK,
0);
ASSERT_GE(self->fan_fd[i], 0);
ret = fanotify_mark(self->fan_fd[i], FAN_MARK_ADD |
FAN_MARK_MNTNS,
FAN_MNT_ATTACH | FAN_MNT_DETACH,
self->ns_fd, NULL);
ASSERT_EQ(ret, 0);
// On fd[0] we do an extra ADD that changes nothing.
// On fd[1]/fd[2] we REMOVE/FLUSH which removes the mark.
ret = fanotify_mark(self->fan_fd[i], mark_cmds[i] |
FAN_MARK_MNTNS,
FAN_MNT_ATTACH | FAN_MNT_DETACH,
self->ns_fd, NULL);
ASSERT_EQ(ret, 0);
}

self->rem = 0;
}

FIXTURE_TEARDOWN(fanotify)
{
int i;

ASSERT_EQ(self->rem, 0);
close(self->fan_fd);
for (i = 0; i < NUM_FAN_FDS; i++)
close(self->fan_fd[i]);

ASSERT_EQ(fchdir(self->orig_root), 0);

Expand All @@ -123,8 +145,21 @@ static uint64_t expect_notify(struct __test_metadata *const _metadata,
unsigned int thislen;

if (!self->rem) {
ssize_t len = read(self->fan_fd, self->buf, sizeof(self->buf));
ASSERT_GT(len, 0);
ssize_t len;
int i;

for (i = NUM_FAN_FDS - 1; i >= 0; i--) {
len = read(self->fan_fd[i], self->buf,
sizeof(self->buf));
if (i > 0) {
// Groups 1,2 should get EAGAIN
ASSERT_EQ(len, -1);
ASSERT_EQ(errno, EAGAIN);
} else {
// Group 0 should get events
ASSERT_GT(len, 0);
}
}

self->rem = len;
self->next = (void *) self->buf;
Expand Down

0 comments on commit fba784c

Please sign in to comment.