From patchwork Fri Apr 20 23:11:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10353845 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 B155060540 for ; Fri, 20 Apr 2018 23:10:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2F42288CD for ; Fri, 20 Apr 2018 23:10:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97C7E288D4; Fri, 20 Apr 2018 23:10:06 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 20B3B288D9 for ; Fri, 20 Apr 2018 23:10:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752489AbeDTXKE (ORCPT ); Fri, 20 Apr 2018 19:10:04 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:39938 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752628AbeDTXJz (ORCPT ); Fri, 20 Apr 2018 19:09:55 -0400 Received: by mail-pg0-f66.google.com with SMTP id e9so4600561pgr.7 for ; Fri, 20 Apr 2018 16:09:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QdP6V5pT/LWROjaRzFhsIPTyXCtNmTT529SDh6p2Liw=; b=ePJAJ4JKKSbBpgmIwl98L47ihme7N+Ct4Ugbc/0JmurDIaFQUroS0YelV32dxN/237 uHnlwfmmTpMsEAdatK0RqP68yqBC9dSBeRMGP2PTz0JUGj2IhYaPRhvx5SJkMrdh1cDS WvZSRtxSEI+gXM066VBEjZJ6OyELA4kcKQF/PHmRIWafJcfs5PNsVCgmFIjNpx1nZQe2 nh0JDole6xs7v5pqNnMRj3S+Xc4ymnXgt1w5iaW4Ox9RUPanMPoG/pul4oSb4Noqstut q7rhctX6p0BPMNBfhQ0fJLho5wS35whMI1fVp20up8wIgThGaEXjJ/oJ7/pWYkr1oHww oUlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QdP6V5pT/LWROjaRzFhsIPTyXCtNmTT529SDh6p2Liw=; b=hVQTIqAv336HA7GUP9rAqX821AYrNF1hI68PLU78W01sOxbitKEtm01nw2JqXekNNb jIGfSPLO+4TmfEznXbXHg7LRvKvH/HR6tPIBT+N+Ut4LLTEiOEOu+djDAi2F6r0IEH1C HdHmHvmZ1aumdGHPQn9SRoVCwsu6RloTgw5B/b5oOCiZfAcdgUWu3BmcRL8wcv+aocN5 mCdzZ/sq/YtzBzaWnIIX1Bnfzqpo5bloXqqSGo7R/jcKCRU6ipuhluycPuZLiIyBrc6n isUWyyZJtUmujfYZSKxFu1T3ylb4q2o1tnFDbnGn7KPGNbnk95/0WX4wqbpEhNGRpMXW iU2A== X-Gm-Message-State: ALQs6tA4Bflh4M4/D/e5SeQCItL0GFt9tENVlSIeBJScaAhkwFHU4Q8G CFbpP2CIE7c3kzGqmp6wX9AyBQ== X-Google-Smtp-Source: AIpwx48u66MCNOheRj7UYklvbJd/biHlXok60tUgSjYQZByzdjSa0Z4TFS6A1nje4nj5tCQjrOoQKg== X-Received: by 10.98.211.143 with SMTP id z15mr11292925pfk.100.1524265794601; Fri, 20 Apr 2018 16:09:54 -0700 (PDT) Received: from amir-VirtualBox.localdomain (c-24-5-85-70.hsd1.ca.comcast.net. [24.5.85.70]) by smtp.gmail.com with ESMTPSA id c12sm10541220pfn.13.2018.04.20.16.09.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 20 Apr 2018 16:09:54 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 12/13] fsnotify: let connector point to abstract fsnotify_obj Date: Fri, 20 Apr 2018 16:11:00 -0700 Message-Id: <1524265861-6316-13-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524265861-6316-1-git-send-email-amir73il@gmail.com> References: <1524265861-6316-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 Make the code to attach/detach a connector to object more generic by letting the fsnotify connector point to the abstract fsnotify_obj. Code that needs to dereference an inode or mount object now uses the macros fsnotify_obj_{inode,mount}. Signed-off-by: Amir Goldstein --- fs/notify/fdinfo.c | 2 +- fs/notify/mark.c | 35 ++++++++++++++--------------------- include/linux/fsnotify_backend.h | 8 ++++---- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c index b3cf03e347a8..725c92bf2dc3 100644 --- a/fs/notify/fdinfo.c +++ b/fs/notify/fdinfo.c @@ -127,7 +127,7 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) seq_putc(m, '\n'); iput(inode); } else if (mark->connector->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { - struct mount *mnt = real_mount(mark->connector->mnt); + struct mount *mnt = fsnotify_obj_mount(mark->connector->obj); seq_printf(m, "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x\n", mnt->mnt_id, mflags, mark->mask, mark->ignored_mask); diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 7103a0a442e7..9642d6c14bfc 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -119,15 +119,12 @@ static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) if (mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED) new_mask |= mark->mask; } - if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) - conn->inode->i_fsnotify.mask = new_mask; - else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) - real_mount(conn->mnt)->mnt_fsnotify.mask = new_mask; + conn->obj->mask = new_mask; } /* * Calculate mask of events for a list of marks. The caller must make sure - * connector and connector->inode cannot disappear under us. Callers achieve + * connector and connector->obj cannot disappear under us. Callers achieve * this by holding a mark->lock or mark->group->mark_mutex for a mark on this * list. */ @@ -167,19 +164,16 @@ static struct inode *fsnotify_detach_connector_from_object( { struct inode *inode = NULL; - if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) { - inode = conn->inode; - rcu_assign_pointer(inode->i_fsnotify.marks, NULL); - inode->i_fsnotify.mask = 0; - conn->inode = NULL; - conn->type = FSNOTIFY_OBJ_TYPE_DETACHED; - } else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { - rcu_assign_pointer(real_mount(conn->mnt)->mnt_fsnotify.marks, - NULL); - real_mount(conn->mnt)->mnt_fsnotify.mask = 0; - conn->mnt = NULL; - conn->type = FSNOTIFY_OBJ_TYPE_DETACHED; - } + if (conn->type == FSNOTIFY_OBJ_TYPE_DETACHED) + return NULL; + + if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) + inode = fsnotify_obj_inode(conn->obj); + + rcu_assign_pointer(conn->obj->marks, NULL); + conn->obj->mask = 0; + conn->obj = NULL; + conn->type = FSNOTIFY_OBJ_TYPE_DETACHED; return inode; } @@ -449,10 +443,9 @@ static int fsnotify_attach_connector_to_object(struct fsnotify_obj *obj, spin_lock_init(&conn->lock); INIT_HLIST_HEAD(&conn->list); conn->type = type; + conn->obj = obj; if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) - inode = conn->inode = igrab(fsnotify_obj_inode(obj)); - else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) - conn->mnt = &fsnotify_obj_mount(obj)->mnt; + inode = igrab(fsnotify_obj_inode(obj)); /* * cmpxchg() provides the barrier so that readers of obj->marks can see * only initialized structure diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 6e9397c16124..b7ba56b9feb8 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -265,9 +265,9 @@ FSNOTIFY_ITER_FUNCS(vfsmount, VFSMOUNT) struct fsnotify_mark_connector { spinlock_t lock; unsigned int type; /* Type of object [lock] */ - union { /* Object pointer [lock] */ - struct inode *inode; - struct vfsmount *mnt; + union { + /* Object pointer [lock] */ + struct fsnotify_obj *obj; /* Used listing heads to free after srcu period expires */ struct fsnotify_mark_connector *destroy_next; }; @@ -282,7 +282,7 @@ static inline struct inode *fsnotify_obj_inode(struct fsnotify_obj *obj) static inline struct inode *fsnotify_connector_inode( struct fsnotify_mark_connector *conn) { - return conn->inode; + return fsnotify_obj_inode(conn->obj); } /*