Skip to content

Commit b5cae08

Browse files
amir73iljankara
authored andcommitted
fanotify: merge two checks regarding add of ignore mark
There are two similar checks for adding an ignore mark without FAN_MARK_IGNORED_SURV_MODIFY, one for the old FAN_MARK_IGNORED flag and one for the new FAN_MARK_IGNORE flag. Merge the two checks into a single location. Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]> Message-Id: <[email protected]>
1 parent 230d97d commit b5cae08

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

fs/notify/fanotify/fanotify_user.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,18 +1412,6 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
14121412
struct inode *inode, __u32 mask,
14131413
unsigned int flags, struct fan_fsid *fsid)
14141414
{
1415-
pr_debug("%s: group=%p inode=%p\n", __func__, group, inode);
1416-
1417-
/*
1418-
* If some other task has this inode open for write we should not add
1419-
* an ignore mask, unless that ignore mask is supposed to survive
1420-
* modification changes anyway.
1421-
*/
1422-
if ((flags & FANOTIFY_MARK_IGNORE_BITS) &&
1423-
!(flags & FAN_MARK_IGNORED_SURV_MODIFY) &&
1424-
inode_is_open_for_write(inode))
1425-
return 0;
1426-
14271415
return fanotify_add_mark(group, &inode->i_fsnotify_marks,
14281416
FSNOTIFY_OBJ_TYPE_INODE, mask, flags, fsid);
14291417
}
@@ -1913,12 +1901,23 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
19131901
else
19141902
mnt = path.mnt;
19151903

1916-
ret = mnt ? -EINVAL : -EISDIR;
1917-
/* FAN_MARK_IGNORE requires SURV_MODIFY for sb/mount/dir marks */
1918-
if (mark_cmd == FAN_MARK_ADD && ignore == FAN_MARK_IGNORE &&
1919-
(mnt || S_ISDIR(inode->i_mode)) &&
1920-
!(flags & FAN_MARK_IGNORED_SURV_MODIFY))
1921-
goto path_put_and_out;
1904+
/*
1905+
* If some other task has this inode open for write we should not add
1906+
* an ignore mask, unless that ignore mask is supposed to survive
1907+
* modification changes anyway.
1908+
*/
1909+
if (mark_cmd == FAN_MARK_ADD && (flags & FANOTIFY_MARK_IGNORE_BITS) &&
1910+
!(flags & FAN_MARK_IGNORED_SURV_MODIFY)) {
1911+
ret = mnt ? -EINVAL : -EISDIR;
1912+
/* FAN_MARK_IGNORE requires SURV_MODIFY for sb/mount/dir marks */
1913+
if (ignore == FAN_MARK_IGNORE &&
1914+
(mnt || S_ISDIR(inode->i_mode)))
1915+
goto path_put_and_out;
1916+
1917+
ret = 0;
1918+
if (inode && inode_is_open_for_write(inode))
1919+
goto path_put_and_out;
1920+
}
19221921

19231922
/* Mask out FAN_EVENT_ON_CHILD flag for sb/mount/non-dir marks */
19241923
if (mnt || !S_ISDIR(inode->i_mode)) {

0 commit comments

Comments
 (0)