From patchwork Thu Jan 10 22:07: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: 10756991 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 1BDE617D2 for ; Thu, 10 Jan 2019 22:08:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0891D29EF0 for ; Thu, 10 Jan 2019 22:08:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEBEE29EFB; Thu, 10 Jan 2019 22:08: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=-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 E124E29EF0 for ; Thu, 10 Jan 2019 22:08:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAA198E0003; Thu, 10 Jan 2019 17:08:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D59728E0001; Thu, 10 Jan 2019 17:08:03 -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 C22C78E0003; Thu, 10 Jan 2019 17:08:03 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 831DB8E0001 for ; Thu, 10 Jan 2019 17:08:03 -0500 (EST) Received: by mail-pg1-f200.google.com with SMTP id 202so7156413pgb.6 for ; Thu, 10 Jan 2019 14:08:03 -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=6/O3eFualUs49i01Y9nCFMeVAmgaojLv/2MBw+YMFEw=; b=uheeIp1LATtuL3+Z02812fo+60lPolb8k//HRR7rEpceevZSMI2WP1TDiEkt13mBCR 2l26619+FRkaXpK2bIEPD1IiHf5mBYOWa9ZSStAiFtyeryRKJv+wdyEEv1M8cklXASlO FR7FmDmUgck4qUEX8sJ/KrAc5hqxhQK9Z0B5Plg2o0E78R8sAbeFxeudtRNqQWMbWeVf S1PxWzIUv1zh9gRn8oFsXU48n0M+XhOihNNHmh1f5VtsyEEzJOpDjdp6pCBrxFvzgYFX y6kGu1m39lvjm6GWQswfgscnPT9NVrtWjVarMMPNiqGbFJ5FJYtottdJ0vOt+W3s5zo5 B/nA== X-Gm-Message-State: AJcUukd+WGvkhoj9gPVMr60ZIYzNqsdBVITxqZPABTwzbiysdpVD7mum HUSHQJRCBju/9/AE+hyUpVClIdWyYyfj+mLDMsupJ4wDQTLrC7ZwW7bsMGNp2dE1/IhsPo6xYr4 itwKI1xEQnVeTpNzS8tw/IUCc46qRTN+s5/ccNSTYFmMzMMDsk/PgPziSiCqiOqVT86bs9lYssc ZYehCoPh3AL3WBLRdsLYuZD1g9p8IPpyPsI5NIJonj57RnrNLxaV9QR29fI5hm8rOtrT15BXUAj Jbk4xeJXqsTvEhC5Znls5UgOqazTBKvu6DKTzH/vWJYge0CqdqXEZql7U8FVrFe0JbpDdCVfW6D MrsviuNMKW0p1/7jtnLyHlH/rICK3glDu8HLMOgcEX4mNdBC7bf8fP2EwVHVPfxf3xeWFIVM8aP F X-Received: by 2002:a65:514c:: with SMTP id g12mr10914290pgq.169.1547158083168; Thu, 10 Jan 2019 14:08:03 -0800 (PST) X-Received: by 2002:a65:514c:: with SMTP id g12mr10914250pgq.169.1547158082417; Thu, 10 Jan 2019 14:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547158082; cv=none; d=google.com; s=arc-20160816; b=GaxjMjwoYfzgVCoqxlvwebn+cmTyf2SrC4FvND5Y7rXmfUc5bb4x7dB0TP+osOzacg GLOMP1OODkDWwL+m/xe+OMYLDvONE37EuNM4XFkEQm/G7h0CexajvS2tVKpCu6klQFys x7tLCB77U89y5UKaza7WHQeMnvZZtBsJjV/t3T5plndnRmXTr030CF+Nk8sqVSrcpUFG g4Lb6hrDD90kucJefle9XRP1k6hlaikL811lCiC3nLbypgF5NVdISf31+9SqsP5ZWSs4 4zvoIoAUv2pwW3qcjn0W6ukwOYH9o2JltBV9qso1l0hT6M/RE84yIA7cjoy6xkoFaGxc reOg== 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=6/O3eFualUs49i01Y9nCFMeVAmgaojLv/2MBw+YMFEw=; b=DyaUXigMafp2Kan4Jw3P83CNS7ToBWJ7PXcYYM5vQByjuzvHo22LNLrs3yEEIUlp00 Zvrp3Cg9E+V0CjHVnxu2JwAtH4Y6Evm9OCDtnabPyAGH6jmxkvSdOBIcDSCRbu6dRTDp uyJt3IH/anfMjRPOHMX1Rbsy5i3Akzlx5rEy0e/iypGBItZxIEZOvfb3uxzqncykPtwa vXWPJ5AnWLb6fxFHqk59zPdijj7uqmhbJ2sISXDszu+7WMLy2ujf8AM9Sbj14qneyVV0 CB3Nkm4NDVXnfGvA4QhH/XB0hQW2Ka3uEeqxhoeubB3UTz10ir8i2c5zvDU598mtI/jM GgOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZlV37vZt; 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 30sor547374pgz.10.2019.01.10.14.08.02 for (Google Transport Security); Thu, 10 Jan 2019 14:08:02 -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=ZlV37vZt; 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=6/O3eFualUs49i01Y9nCFMeVAmgaojLv/2MBw+YMFEw=; b=ZlV37vZth2xskaz25CzDUgkv2F5IWqrPsLkXq+5WGuLB2x/bp81M8lLF8ZPkjLtZW3 lq4hOdS+fLTm6uWk/RIkdTi3zA+1aFHHEfLWYUGirXTb9rXw6xxvs+LGaUumLrV2P4k7 pITQRvyOn+4dWlNuZ4A4QQcf2n6KmihrQklYYmeAcjKsOM9He4TenXOi36Bn82mU/Ald CTbGvrRA68GVELjzgQyqaSfj5x56VRoBO1LVTm8nyUiVwfH21VV2AV9+O8SDDYmNqkEz D4GgOBYB9F0wlUEkDQspNYjZOL9OuIk4OFAkNhkIxOnxdpi9c0OTdoI4AElmSojoCPxk /hSw== X-Google-Smtp-Source: ALg8bN4VK5/sM3LS/LoPFXFsneMHIR/ap0XXOfEPftIeUw/PbLjRJcIMdlUd4PLfeJM78GtOQw4fEw== X-Received: by 2002:a63:ee0e:: with SMTP id e14mr10793315pgi.8.1547158081876; Thu, 10 Jan 2019 14:08:01 -0800 (PST) Received: from surenb0.mtv.corp.google.com ([2620:0:1000:1612:3320:4357:47df:276b]) by smtp.googlemail.com with ESMTPSA id p7sm152958019pfj.72.2019.01.10.14.08.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Jan 2019 14:08:01 -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 v2 1/5] fs: kernfs: add poll file operation Date: Thu, 10 Jan 2019 14:07:14 -0800 Message-Id: <20190110220718.261134-2-surenb@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190110220718.261134-1-surenb@google.com> References: <20190110220718.261134-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 Reviewed-by: Greg Kroah-Hartman --- 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 dbf5bc250bfd..2d8b91f4475d 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);