From patchwork Thu Jan 24 21:15:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10780149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CED691E for ; Thu, 24 Jan 2019 21:15:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BE0E2F805 for ; Thu, 24 Jan 2019 21:15:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FE262F83A; Thu, 24 Jan 2019 21:15:48 +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=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D58132F805 for ; Thu, 24 Jan 2019 21:15:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 989778E009C; Thu, 24 Jan 2019 16:15:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8EE2A8E0097; Thu, 24 Jan 2019 16:15:45 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 740F68E009C; Thu, 24 Jan 2019 16:15:45 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id 2FD338E0097 for ; Thu, 24 Jan 2019 16:15:45 -0500 (EST) Received: by mail-pf1-f200.google.com with SMTP id 82so5671922pfs.20 for ; Thu, 24 Jan 2019 13:15:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ucF1EwcLVxCtpPOBrQuqUFcO6ME+3ZXcCq84fU7zCQU=; b=nEFxo5qh/0yzk7UgyovvBb8WcX6p+6/Ze1MzJSlvSan/dP+drTgxgfB5RuCqTGrGBl yYUcs3lZe8Fjtjr6OG06eUm7+grru4mw3rNlbRYR0fVFxDiZiuN8pX7zIlpNKDjueKWP j34IoAmux0iwxWCGDpI+lG+OpKUYaGPiiCV+MlxzLeV+g7TTXnhdOwKiV6RrX9IPPgs/ Oaaa6w5e1pkH9oHvu33vQsYG7cSqcHGOiKdZpzu5hvysX/z1A6yHoEKP2NboLWo++V3Q +F/yNVs1ehQ9tU7echejBquiPZ5epyn51dL+Ku3bnIqWJRqdPoScNJz3lJp7ckMDRRuT x+Mw== X-Gm-Message-State: AJcUukec1vfPPtigPtiE1JlA/WUfFW1onv0SoY+bjcQf9JN04ifk3ZSW SQS1Osgg6Mv2ZZ/6y5WvLbZHFfjWGUegzxmn6P4cL3JcfZvd/5BOxSVJUc23gcAe+OLdIgZ/o5b fh+eAt6xrVoyAk7Z6oYr4mfLJJnMwtobkIonUcdGT0CT9un69PtRCOd1wHz16tcq3ci8re6gNig uEs1r/cMsGCbu0RilY4zEhM/i+Qzxn0/6gZic13NatOJXgXCZdTxFbPZ9l2PGod38Mz1vm3Uf8D j5GaIHyEKnO12vtGZUIaPSNAuKqLH5Kp53pDZ4Bw32Dv7i9d62DLMLmuF7FU+bMbANjVhU1pEz9 ha3O/xozLvXkd5vOZDnKkkvkuokUKkVALqKpHC8hdvpdkouB8n6HJaVY+C+pRncpk8n5TqcaZ8K F X-Received: by 2002:a17:902:1008:: with SMTP id b8mr7839416pla.252.1548364544758; Thu, 24 Jan 2019 13:15:44 -0800 (PST) X-Received: by 2002:a17:902:1008:: with SMTP id b8mr7839370pla.252.1548364543985; Thu, 24 Jan 2019 13:15:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548364543; cv=none; d=google.com; s=arc-20160816; b=oh23fQzZe3KuZqns9U/Z+TPHHC/O4jtWwnB/6yI4EGMYsArejDsANeVY972AkpflOx 0LBlORm1M2Sit2Z1YoaD2R/61BDeGCWdLejHTbNn5y5IJLX4hYfwZZ8MT0o43Mrs4JvI 66tcTB8oER1MQ0EIRlFBmmpO3oJ5KiOkFZM1cjmMHRP44lZRyZYh7tq8cGOMn75YE9VW krmOj8J/cBu7zcJeybt1B/1oNBf0w8VDVD17e+s28bBqN+WVjVzlriV4XzKx4Ir9gdRE pjkt1hGoAw7Aa9+yGZwuOOLe9mODsCXVfSY2+Ki2+ADK5QnBKruV5Huy97GolkkpqHce uHYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=ucF1EwcLVxCtpPOBrQuqUFcO6ME+3ZXcCq84fU7zCQU=; b=DTKrtWZxIJA4HKATP7Aua5syXutTqjgr7CxHv7B90MDOxSt04XyLENZfkWLjHwqKKV VwovmHSAtYebnBfol1ZcJHGAjRM2ZOIsTOAntWTgYSlddii0UUK8Q1MWei6aSfxP8K1M cVKgEkeQHmEYPBH/nO5RvUKb629lz0xCJlBNkv1eZv4nxALzrBTu+vsgBfClQNksO8D1 C5q2Z98hW0hnfqne7rGk+raMeaIEbTwkAABosxf3YORQCJSqcWukFgAWMunSSC3P7JEP RJ08N0xcalsNOVSlnFTi+tsgO55BZoDG9fSjfPK3CXDlaogcJu3lXWRJTFqaD9aNaDgf Cowg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gygzfM8D; spf=pass (google.com: domain of surenb@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n6sor35862537pgv.69.2019.01.24.13.15.43 for (Google Transport Security); Thu, 24 Jan 2019 13:15:43 -0800 (PST) Received-SPF: pass (google.com: domain of surenb@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gygzfM8D; spf=pass (google.com: domain of surenb@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ucF1EwcLVxCtpPOBrQuqUFcO6ME+3ZXcCq84fU7zCQU=; b=gygzfM8DMwdV2iIuQLyTUNZoqz3zBV3YtlUapmjclo6FC0Cojxkyvg4NivMng9lbsQ UWdyeeLEfhPEp8uDGJi7V+xJ1r8fLv7cSF3AgCBMzvurwt/n6qyU4ar7Cg9qTtZeIxbU J6YSkeKSSK0UPNMIulk/GIHII8GRmfVYhpB65NdU5mVAAkC5EC5Z9ITK8S75A88PP/rM YCmvpjQontE64hJ0camuKp/QHj5ID+XU4FRhNKvHB2zo3jpM7bZb6q/XuMvwwy6vaDwK BPTQ0nG+MGuEYAZ0eOa1zCAzJnqN3qOecuomYBNuInO5ONQIFkVFx7A78idtIZ3d2iHh EAXA== X-Google-Smtp-Source: ALg8bN7SzOSe/SY78Pfzr1GOzAhXFURTr4LVGcJJzkPSCrKgxlqMkTFLV98NujEgXfWObOrL6iJgLg== X-Received: by 2002:a63:31cc:: with SMTP id x195mr7538081pgx.52.1548364543402; Thu, 24 Jan 2019 13:15:43 -0800 (PST) Received: from surenb0.mtv.corp.google.com ([2620:0:1000:1612:3320:4357:47df:276b]) by smtp.googlemail.com with ESMTPSA id j197sm29626418pgc.76.2019.01.24.13.15.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Jan 2019 13:15:42 -0800 (PST) From: Suren Baghdasaryan To: gregkh@linuxfoundation.org Cc: tj@kernel.org, lizefan@huawei.com, hannes@cmpxchg.org, axboe@kernel.dk, dennis@kernel.org, dennisszhou@gmail.com, mingo@redhat.com, peterz@infradead.org, akpm@linux-foundation.org, corbet@lwn.net, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Suren Baghdasaryan Subject: [PATCH v3 1/5] fs: kernfs: add poll file operation Date: Thu, 24 Jan 2019 13:15:14 -0800 Message-Id: <20190124211518.244221-2-surenb@google.com> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190124211518.244221-1-surenb@google.com> References: <20190124211518.244221-1-surenb@google.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Weiner Kernfs has a standardized poll/notification mechanism for waking all pollers on all fds when a filesystem node changes. To allow polling for custom events, add a .poll callback that can override the default. This is in preparation for pollable cgroup pressure files which have per-fd trigger configurations. Signed-off-by: Johannes Weiner Signed-off-by: Suren Baghdasaryan --- fs/kernfs/file.c | 31 ++++++++++++++++++++----------- include/linux/kernfs.h | 6 ++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index f8d5021a652e..ae948aaa4c53 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c @@ -832,26 +832,35 @@ void kernfs_drain_open_files(struct kernfs_node *kn) * to see if it supports poll (Neither 'poll' nor 'select' return * an appropriate error code). When in doubt, set a suitable timeout value. */ +__poll_t kernfs_generic_poll(struct kernfs_open_file *of, poll_table *wait) +{ + struct kernfs_node *kn = kernfs_dentry_node(of->file->f_path.dentry); + struct kernfs_open_node *on = kn->attr.open; + + poll_wait(of->file, &on->poll, wait); + + if (of->event != atomic_read(&on->event)) + return DEFAULT_POLLMASK|EPOLLERR|EPOLLPRI; + + return DEFAULT_POLLMASK; +} + static __poll_t kernfs_fop_poll(struct file *filp, poll_table *wait) { struct kernfs_open_file *of = kernfs_of(filp); struct kernfs_node *kn = kernfs_dentry_node(filp->f_path.dentry); - struct kernfs_open_node *on = kn->attr.open; + __poll_t ret; if (!kernfs_get_active(kn)) - goto trigger; + return DEFAULT_POLLMASK|EPOLLERR|EPOLLPRI; - poll_wait(filp, &on->poll, wait); + if (kn->attr.ops->poll) + ret = kn->attr.ops->poll(of, wait); + else + ret = kernfs_generic_poll(of, wait); kernfs_put_active(kn); - - if (of->event != atomic_read(&on->event)) - goto trigger; - - return DEFAULT_POLLMASK; - - trigger: - return DEFAULT_POLLMASK|EPOLLERR|EPOLLPRI; + return ret; } static void kernfs_notify_workfn(struct work_struct *work) diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index 5b36b1287a5a..0cac1207bb00 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h @@ -25,6 +25,7 @@ struct seq_file; struct vm_area_struct; struct super_block; struct file_system_type; +struct poll_table_struct; struct kernfs_open_node; struct kernfs_iattrs; @@ -261,6 +262,9 @@ struct kernfs_ops { ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t bytes, loff_t off); + __poll_t (*poll)(struct kernfs_open_file *of, + struct poll_table_struct *pt); + int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma); #ifdef CONFIG_DEBUG_LOCK_ALLOC @@ -350,6 +354,8 @@ int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name, int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, const char *new_name, const void *new_ns); int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr); +__poll_t kernfs_generic_poll(struct kernfs_open_file *of, + struct poll_table_struct *pt); void kernfs_notify(struct kernfs_node *kn); const void *kernfs_super_ns(struct super_block *sb);