From patchwork Mon Oct 10 19:13:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9369879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F65560487 for ; Mon, 10 Oct 2016 19:28:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49A1929A17 for ; Mon, 10 Oct 2016 19:28:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E65629A19; Mon, 10 Oct 2016 19:28:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C296429A17 for ; Mon, 10 Oct 2016 19:28:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751503AbcJJT2k (ORCPT ); Mon, 10 Oct 2016 15:28:40 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:34928 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751375AbcJJT2i (ORCPT ); Mon, 10 Oct 2016 15:28:38 -0400 Received: by mail-lf0-f67.google.com with SMTP id x79so8301825lff.2 for ; Mon, 10 Oct 2016 12:28:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bJfmrK55vRe9BioOeh4wK6MgHtqVruR5/pJyACAkM70=; b=yDr3KcKB7z8gx5zC2Ovev3f50lkj1oW+qWBJZwjaQsuLUTu54k5KfiqoYYIo9s+4Ta pUiXxsrkNnubuxWYdcSHLggD0fTApSkGaNV1aYzQjQiYrzHivmnwmVdfPKYOWNDKjJj9 EVh9zDM/1qZEgDqt1gIXSogca8IuYrb3jOxAEB6X7mCRa49s7L9loTmtJb0mz9OiEMcS RDKPd16ABJMqiqIhhpdL30ItXc7d993pX2E4/IgOYsu7kvSMABsHkNNAegGEldWjMWax nqI4Vbdj5eIZD54yG49wNqGHiYbHD4hEt3DaaJ+hMKxot4mRMBw+jipnSFs54JHbxhGi qeGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bJfmrK55vRe9BioOeh4wK6MgHtqVruR5/pJyACAkM70=; b=WEfaKvUtUETdDVRmArKs3QRQFMCIxQB38OyswCGHELV5+rmjw4IaadHxH3FoaS1MMv kCpxtiFoIgNAL8I15vObvB6LEvgOHTT4D2OO2AJFw0dVUoVKb8ZrFooW/d92pMz3sxBT uWFvNOhX0HheAegtYBgZMse8UIkq+juQmx/i9qBlujT/tH1IqIJon834aNNk6HtjpwS9 s/oqtUOOZ1AdTQIyYyUEtO5a2uutrCqW/L9AdFW8NhB4rHdaQ9hWM1ZB1VDiwd37WhuS ZE15i3/GV3NFeQQmhOy+h0KAefxBeuwjAcYWMlgfTXXPAJtg9s+NskinvscRmjU0qdBu AGjQ== X-Gm-Message-State: AA6/9RmGOHlqA9C0N/aRaxeZ5Xi7sxOON3D/K+7HjNXHtLc6EAx2YdB+JH2ONoi8zG3d8Q== X-Received: by 10.194.155.35 with SMTP id vt3mr17731952wjb.223.1476126827344; Mon, 10 Oct 2016 12:13:47 -0700 (PDT) Received: from amir-VirtualBox.Home (bzq-79-180-3-185.red.bezeqint.net. [79.180.3.185]) by smtp.gmail.com with ESMTPSA id hb5sm83688wjc.5.2016.10.10.12.13.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Oct 2016 12:13:46 -0700 (PDT) From: Amir Goldstein To: linux-fsdevel@vger.kernel.org Cc: Jan Kara , Lino Sanfilippo , Eric Paris , Al Viro Subject: [RFC][PATCH 5/7] fanotify: support events with data type FSNOTIFY_EVENT_DENTRY Date: Mon, 10 Oct 2016 22:13:02 +0300 Message-Id: <1476126784-12520-6-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476126784-12520-1-git-send-email-amir73il@gmail.com> References: <1476126784-12520-1-git-send-email-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When event data type is FSNOTIFY_EVENT_DENTRY, store the provided dentry in the event queue along with the mount point that was used to setup the watch. This will enable the watcher to read the path of the passed dentry from /proc/self/fd/X, for example on FAN_ATTRIB events. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 39 +++++++++++++++++++++++++++++++------- fs/notify/fanotify/fanotify_user.c | 9 +++++++-- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index d2f97ec..fb2b852 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -105,18 +105,28 @@ static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark, { __u32 marks_mask, marks_ignored_mask; struct path *path = data; + struct dentry *dentry; pr_debug("%s: inode_mark=%p vfsmnt_mark=%p mask=%x data=%p" " data_type=%d\n", __func__, inode_mark, vfsmnt_mark, event_mask, data, data_type); /* if we don't have enough info to send an event to userspace say no */ - if (data_type != FSNOTIFY_EVENT_PATH) + if (data_type != FSNOTIFY_EVENT_PATH && + data_type != FSNOTIFY_EVENT_DENTRY) return false; - /* sorry, fanotify only gives a damn about files and dirs */ - if (!d_is_reg(path->dentry) && - !d_can_lookup(path->dentry)) + dentry = path->dentry; + pr_debug("%s: dentry=%p d_flags=%x inode=%p\n", __func__, + dentry, dentry->d_flags, dentry->d_inode); + + if (d_is_negative(dentry) || d_really_is_negative(dentry)) + return false; + + /* sorry, fanotify only gives a damn about files and dirs + * FIXME: can this be removed? */ + if (data_type == FSNOTIFY_EVENT_PATH && + !d_is_reg(dentry) && !d_can_lookup(dentry)) return false; if (inode_mark && vfsmnt_mark) { @@ -139,7 +149,7 @@ static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark, BUG(); } - if (d_is_dir(path->dentry) && + if (d_is_dir(dentry) && !(marks_mask & FS_ISDIR & ~marks_ignored_mask)) return false; @@ -177,6 +187,10 @@ init: __maybe_unused if (path) { event->path = *path; path_get(&event->path); + pr_debug("%s: mnt=%p, dentry=%p parent=%p d_flags=%x\n", + __func__, event->path.mnt, event->path.dentry, + event->path.dentry->d_parent, + event->path.dentry->d_flags); } else { event->path.mnt = NULL; event->path.dentry = NULL; @@ -194,6 +208,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, int ret = 0; struct fanotify_event_info *event; struct fsnotify_event *fsn_event; + struct path path; BUILD_BUG_ON(FAN_ACCESS != FS_ACCESS); BUILD_BUG_ON(FAN_MODIFY != FS_MODIFY); @@ -206,14 +221,24 @@ static int fanotify_handle_event(struct fsnotify_group *group, BUILD_BUG_ON(FAN_ACCESS_PERM != FS_ACCESS_PERM); BUILD_BUG_ON(FAN_ONDIR != FS_ISDIR); - if (!fanotify_should_send_event(inode_mark, fanotify_mark, mask, data, + if (data_type == FSNOTIFY_EVENT_PATH) { + path = *(struct path *)data; + } else if (data_type == FSNOTIFY_EVENT_DENTRY) { + path.dentry = (struct dentry *)data; + path.mnt = (inode_mark ? inode_mark->mnt : fanotify_mark->mnt); + } else { + path.mnt = NULL; + path.dentry = NULL; + } + + if (!fanotify_should_send_event(inode_mark, fanotify_mark, mask, &path, data_type)) return 0; pr_debug("%s: group=%p inode=%p mask=%x\n", __func__, group, inode, mask); - event = fanotify_alloc_event(inode, mask, data); + event = fanotify_alloc_event(inode, mask, &path); if (unlikely(!event)) return -ENOMEM; diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 0696d46..789962c 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -88,12 +88,17 @@ static int create_fd(struct fsnotify_group *group, */ /* it's possible this event was an overflow event. in that case dentry and mnt * are NULL; That's fine, just don't call dentry open */ - if (event->path.dentry && event->path.mnt) + if (event->path.dentry && event->path.mnt) { + pr_debug("%s: mnt=%p, dentry=%p parent=%p d_flags=%x\n", + __func__, event->path.mnt, event->path.dentry, + event->path.dentry->d_parent, + event->path.dentry->d_flags); new_file = dentry_open(&event->path, group->fanotify_data.f_flags | FMODE_NONOTIFY, current_cred()); - else + } else { new_file = ERR_PTR(-EOVERFLOW); + } if (IS_ERR(new_file)) { /* * we still send an event even if we can't open the file. this