From: Amir Goldstein <amir73il@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: Matthew Bobrowski <mbobrowski@mbobrowski.org>,
linux-fsdevel@vger.kernel.org
Subject: [PATCH v3 06/13] fanotify: encode file identifier for FAN_REPORT_FID
Date: Sun, 25 Nov 2018 15:43:45 +0200 [thread overview]
Message-ID: <20181125134352.21499-7-amir73il@gmail.com> (raw)
In-Reply-To: <20181125134352.21499-1-amir73il@gmail.com>
Allocate and encode event->info.fid for a group with FAN_REPORT_FID.
Treat failure to allocate fid buffer as failure to allocate event.
Treat failure to encode fid by printing a warning but queueing
the event without the fid information.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/notify/fanotify/fanotify.c | 59 +++++++++++++++++++++++++++++++++--
1 file changed, 57 insertions(+), 2 deletions(-)
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index 8192d4b1db21..844b748f0b74 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -13,6 +13,8 @@
#include <linux/wait.h>
#include <linux/audit.h>
#include <linux/sched/mm.h>
+#include <linux/statfs.h>
+#include <linux/exportfs.h>
#include "fanotify.h"
@@ -146,11 +148,55 @@ static u32 fanotify_group_event_mask(struct fsnotify_iter_info *iter_info,
~marks_ignored_mask;
}
+static struct fanotify_event_fid *fanotify_alloc_fid(const struct path *path,
+ gfp_t gfp)
+{
+ struct fanotify_event_fid *fid = NULL;
+ int dwords, bytes = 0;
+ struct kstatfs stat;
+ int err, type;
+
+ dwords = 0;
+ err = -ENOENT;
+ type = exportfs_encode_fh(path->dentry, NULL, &dwords, 0);
+ if (!dwords)
+ goto out_err;
+
+ err = vfs_statfs(path, &stat);
+ if (err)
+ goto out_err;
+
+ /* Treat failure to allocate fid as failure to allocate event */
+ bytes = dwords << 2;
+ fid = kmalloc(FANOTIFY_FID_LEN(bytes), gfp);
+ if (!fid)
+ return NULL;
+
+ type = exportfs_encode_fh(path->dentry, (struct fid *)fid->f_handle,
+ &dwords, 0);
+ err = -EINVAL;
+ if (type == FILEID_INVALID || bytes != dwords << 2)
+ goto out_err;
+
+ fid->handle_bytes = bytes;
+ fid->handle_type = type;
+ fid->fsid = stat.f_fsid;
+
+ return fid;
+
+out_err:
+ pr_warn_ratelimited("fanotify: failed to encode fid of %pd2 (bytes=%d, err=%i)\n",
+ path->dentry, bytes, err);
+ kfree(fid);
+ return ERR_PTR(err);
+}
+
struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
struct inode *inode, u32 mask,
const struct path *path)
{
struct fanotify_event *event = NULL;
+ struct fanotify_event_fid *fid = NULL;
gfp_t gfp = GFP_KERNEL_ACCOUNT;
/*
@@ -164,6 +210,16 @@ struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
/* Whoever is interested in the event, pays for the allocation. */
memalloc_use_memcg(group->memcg);
+ if (path && FAN_GROUP_FLAG(group, FAN_REPORT_FID)) {
+ fid = fanotify_alloc_fid(path, gfp);
+ /* Treat failure to allocate fid as failure to allocate event */
+ if (!fid)
+ goto out;
+ /* Report the event without a file identifier on encode error */
+ if (IS_ERR(fid))
+ fid = NULL;
+ }
+
if (fanotify_is_perm_event(mask)) {
struct fanotify_perm_event *pevent;
@@ -184,8 +240,7 @@ init: __maybe_unused
else
event->pid = get_pid(task_tgid(current));
if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) {
- /* TODO: allocate buffer and encode file handle */
- fanotify_set_fid(event, NULL);
+ fanotify_set_fid(event, fid);
} else if (path) {
event->path = *path;
path_get(&event->path);
--
2.17.1
next prev parent reply other threads:[~2018-11-26 0:35 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-25 13:43 [PATCH v3 00/13] fanotify: add support for more event types Amir Goldstein
2018-11-25 13:43 ` [PATCH v3 01/13] fsnotify: annotate directory entry modification events Amir Goldstein
2018-11-28 12:59 ` Jan Kara
2018-11-28 14:39 ` Amir Goldstein
2018-11-28 14:43 ` Jan Kara
2018-11-28 15:01 ` Amir Goldstein
2018-11-25 13:43 ` [PATCH v3 02/13] fsnotify: send all event types to super block marks Amir Goldstein
2018-11-28 14:26 ` Jan Kara
2018-11-25 13:43 ` [PATCH v3 03/13] fanotify: rename struct fanotify_{,perm_}event_info Amir Goldstein
2018-11-28 14:29 ` Jan Kara
2018-11-25 13:43 ` [PATCH v3 04/13] fanotify: define the structures to report a unique file identifier Amir Goldstein
2018-11-28 15:27 ` Jan Kara
2018-11-28 16:24 ` Amir Goldstein
2018-11-28 17:43 ` Jan Kara
2018-11-28 18:34 ` Amir Goldstein
2018-11-29 7:51 ` Jan Kara
2018-11-29 8:16 ` Amir Goldstein
2018-11-29 10:16 ` Jan Kara
2018-11-29 11:10 ` Amir Goldstein
2018-11-30 15:32 ` Amir Goldstein
2018-12-01 16:43 ` Amir Goldstein
2018-11-25 13:43 ` [PATCH v3 05/13] fanotify: classify events that hold a " Amir Goldstein
2018-11-28 15:33 ` Jan Kara
2018-11-28 15:44 ` Jan Kara
2018-11-28 15:52 ` Amir Goldstein
2018-11-25 13:43 ` Amir Goldstein [this message]
2018-11-25 13:43 ` [PATCH v3 07/13] fanotify: copy event fid info to user Amir Goldstein
2018-11-29 9:00 ` Jan Kara
[not found] ` <CAOQ4uxjcb=UqQiw0XcpDfetK28bM4tOYdvgxPwhkjgE2mxpt=g@mail.gmail.com>
2018-11-29 9:49 ` Jan Kara
2018-11-25 13:43 ` [PATCH v3 08/13] fanotify: enable FAN_REPORT_FID init flag Amir Goldstein
2018-11-29 9:46 ` Jan Kara
2018-11-29 10:52 ` Jan Kara
2018-11-29 11:03 ` Amir Goldstein
2018-11-29 13:08 ` Jan Kara
2018-11-25 13:43 ` [PATCH v3 09/13] fanotify: cache fsid in fsnotify_mark_connector Amir Goldstein
2018-11-29 10:48 ` Jan Kara
2018-11-29 11:42 ` Amir Goldstein
2018-11-29 13:11 ` Jan Kara
2018-11-25 13:43 ` [PATCH v3 10/13] fanotify: check FS_ISDIR flag instead of d_is_dir() Amir Goldstein
2018-11-25 13:43 ` [PATCH v3 11/13] fanotify: support events with data type FSNOTIFY_EVENT_INODE Amir Goldstein
2018-11-25 13:43 ` [PATCH v3 12/13] fanotify: add support for create/attrib/move/delete events Amir Goldstein
2018-11-25 13:43 ` [PATCH v3 13/13] fanotify: report FAN_ONDIR to listener with FAN_REPORT_FID Amir Goldstein
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=20181125134352.21499-7-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=mbobrowski@mbobrowski.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).