From: Jan Kara <jack@suse.cz>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
linux-fsdevel@vger.kernel.org, Eric Paris <eparis@parisplace.org>,
Jan Kara <jack@suse.cz>
Subject: [PATCH 5/5] fanotify: Move unrelated handling from copy_event_to_user()
Date: Mon, 3 Mar 2014 12:12:23 +0100 [thread overview]
Message-ID: <1393845143-28007-6-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1393845143-28007-1-git-send-email-jack@suse.cz>
Move code moving event structure to access_list from
copy_event_to_user() to fanotify_read() where it is more logical (so
that we can immediately see in the main loop that we either move the
event to a different list or free it). Also move special error handling
for permission events from copy_event_to_user() to the main loop to have
it in one place with error handling for normal events. This makes
copy_event_to_user() really only copy the event to user without any side
effects.
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/notify/fanotify/fanotify_user.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 68a06a7b5659..4e565c814309 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -199,7 +199,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
ret = fill_event_metadata(group, &fanotify_event_metadata, event, &f);
if (ret < 0)
- goto out;
+ return ret;
fd = fanotify_event_metadata.fd;
ret = -EFAULT;
@@ -208,13 +208,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
goto out_close_fd;
#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
- if (event->mask & FAN_ALL_PERM_EVENTS) {
+ if (event->mask & FAN_ALL_PERM_EVENTS)
FANOTIFY_PE(event)->fd = fd;
- spin_lock(&group->fanotify_data.access_lock);
- list_add_tail(&event->fae.fse.list,
- &group->fanotify_data.access_list);
- spin_unlock(&group->fanotify_data.access_lock);
- }
#endif
if (fd != FAN_NOFD)
@@ -226,13 +221,6 @@ out_close_fd:
put_unused_fd(fd);
fput(f);
}
-out:
-#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
- if (event->mask & FAN_ALL_PERM_EVENTS) {
- FANOTIFY_PE(event)->response = FAN_DENY;
- wake_up(&group->fanotify_data.access_waitq);
- }
-#endif
return ret;
}
@@ -297,10 +285,23 @@ static ssize_t fanotify_read(struct file *file, char __user *buf,
* Permission events get queued to wait for response. Other
* events can be destroyed now.
*/
- if (!(kevent->mask & FAN_ALL_PERM_EVENTS))
+ if (!(kevent->mask & FAN_ALL_PERM_EVENTS)) {
fsnotify_destroy_event(group, kevent);
- if (ret < 0)
- break;
+ if (ret < 0)
+ break;
+ } else {
+#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
+ if (ret < 0) {
+ FANOTIFY_PE(kevent)->response = FAN_DENY;
+ wake_up(&group->fanotify_data.access_waitq);
+ break;
+ }
+ spin_lock(&group->fanotify_data.access_lock);
+ list_add_tail(&kevent->list,
+ &group->fanotify_data.access_list);
+ spin_unlock(&group->fanotify_data.access_lock);
+#endif
+ }
buf += ret;
count -= ret;
}
--
1.8.1.4
prev parent reply other threads:[~2014-03-03 11:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-03 11:12 [PATCH 0/5 v2] Fanotify cleanups Jan Kara
2014-03-03 11:12 ` [PATCH 1/5] fanotify: Remove useless bypass_perm check Jan Kara
2014-03-03 11:12 ` [PATCH 2/5] fanotify: Use fanotify event structure for permission response processing Jan Kara
2014-03-03 11:12 ` [PATCH 3/5] fanotify: Convert access_mutex to spinlock Jan Kara
2014-03-03 11:12 ` [PATCH 4/5] fanotify: Reorganize loop in fanotify_read() Jan Kara
2014-03-03 11:12 ` Jan Kara [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1393845143-28007-6-git-send-email-jack@suse.cz \
--to=jack@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=eparis@parisplace.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).