From patchwork Mon Aug 27 15:29:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10577377 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 A3B8C14BD for ; Mon, 27 Aug 2018 15:33:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8606F29B5D for ; Mon, 27 Aug 2018 15:33:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79D0D29CEF; Mon, 27 Aug 2018 15:33:43 +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,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 119B029B5D for ; Mon, 27 Aug 2018 15:33:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726939AbeH0TUr (ORCPT ); Mon, 27 Aug 2018 15:20:47 -0400 Received: from mail-eopbgr50107.outbound.protection.outlook.com ([40.107.5.107]:43008 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727014AbeH0TUr (ORCPT ); Mon, 27 Aug 2018 15:20:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+aIRAKNytCXhXG8C8MhbyevhWC66MLtsAnZYfMuQYAY=; b=gAOS2AvgAvAXa5t+QopRDl78aS6Vl/U2Gp9TrTtDGtRW/09MfY832f5WLuNoWYaK7Cp2IFzatmMRC5PRHquDZfvAR+mWvzcQegmMqEQm/3LLtFYpB0/sFHmbrNX6lmGF3Or1JU/ps8VpllOFdc2JYIYQ+N7RzrMcvRZYXbzNhSE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (185.231.240.5) by VI1PR0801MB2032.eurprd08.prod.outlook.com (2603:10a6:800:8b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1080.17; Mon, 27 Aug 2018 15:29:41 +0000 Subject: [PATCH 4/6] fuse: Lock fc->lock during changing num_background and congestion_threshold From: Kirill Tkhai To: miklos@szeredi.hu, ktkhai@virtuozzo.com, linux-fsdevel@vger.kernel.org Date: Mon, 27 Aug 2018 18:29:37 +0300 Message-ID: <153538377784.18303.9880331591122960857.stgit@localhost.localdomain> In-Reply-To: <153538208536.18303.10732945923322972743.stgit@localhost.localdomain> References: <153538208536.18303.10732945923322972743.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: LO2P265CA0159.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::27) To VI1PR0801MB2032.eurprd08.prod.outlook.com (2603:10a6:800:8b::13) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c1c7f42a-9c18-4c82-0417-08d60c31e896 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:VI1PR0801MB2032; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB2032;3:P09fR8Yp0H2Rt57B+JcllfFdoL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fZdNwBTjLbYt2ZPDOxoovRoI3Ip5/m4pUumeJrRiUGnxvHKp+hQ/OKvqcQ9CopGMTcMLpc8oKjJvRAoSdiszoQmGEAe5AQr1MGdbKNY7VLtJBbeZv5hnRkRSszoUxTDt43tqPwXzsGRSLN/cmGwtowcG9gO4JnTnE3+dvJQEbEjNjr2JSOdFj7lzGCxL7tbOAx/iTDwU34EyP/oqu+C86rP49K0vliiPeaMN1FfiYLXRoR3B+mQuwK61jmLeOjwMww1tff14n/CIVgSaO5Fl2ewpCXfQrBjcyzSsfYidlH9StLjM3gMckhayoy5yRWmd8aC;4:YZMmZnvCZ7JEVnPf5wo3eURABeG7Mrmdzv6m235mr4+ji9bm/+I0+WRntGudVURVJoPFeO4ipZgzsnSLKHv92e4QKW9RONws984IyQuStJw2eYVYip8oJ6MLubcB9HQ52H2vFOqLq60mCFl10rzmoeufrmkPX4SVgWdxRvjmB1zgSKKNy96rTog4lYIxrIOx5Wa1dHPRFclC/xsbKg0SEBo1Y1xfLmn/i0ogi1l7KJlRMR05hWDLHgbBhQ8cuA17hlFdZVrbzNsBHI4XOCcojw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(3231311)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(201708071742011)(7699016);SRVR:VI1PR0801MB2032;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB2032; X-Forefront-PRVS: 07778E4001 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(396003)(346002)(136003)(39850400004)(366004)(376002)(189003)(199004)(8676002)(6506007)(81156014)(81166006)(316002)(8936002)(58126008)(478600001)(2906002)(86362001)(230700001)(305945005)(47776003)(7736002)(3846002)(6116002)(61506002)(103116003)(106356001)(66066001)(476003)(50466002)(11346002)(446003)(486006)(105586002)(33896004)(76176011)(68736007)(956004)(5660300001)(14444005)(6666003)(26005)(55016002)(186003)(25786009)(97736004)(386003)(9686003)(16526019)(53936002)(7696005)(2486003)(52116002)(23676004);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB2032;H:localhost.localdomain;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?q?1=3BVI1PR0801MB2032=3B23=3AYLKtX?= =?utf-8?q?JqPWswWXZrlYDWCBygo8Hc5k+BG+2e9it/XghnEfRZxlKwZfOZd68GpMmQc+0P1KW?= =?utf-8?q?iLecqbJAb9H6iK0LkRlYq6VtB4mO+X1TF5GIjv4QfL3NRThVCA/FMWQTxA5qQsij1?= =?utf-8?q?AWtVcMK8DYZRj3NvsCjGZelAeQ5G1o8Z7wk3pX/tyoF9LkG3IqHIBrTvkqb1v4oux?= =?utf-8?q?YmQQ+5M7gByY/E0aU92ygt1MYCuzcu0O0nLR27z+LqBXfTrnHzjvUUEu9cnXuP2BH?= =?utf-8?q?drVhrDQCqMkaL1hR877n1LDgLHj3162uXVvwyNqspVA5hiK075JN+y1MYeH1IRVhF?= =?utf-8?q?LMKEupQQNbKPLrpXGHl2OVgCZDnY6w5kPPhN2l8H7anPIR05zzYOlTlnA3I+bihxs?= =?utf-8?q?Ode6o2J2C0qjwdo0uLtCI/IMS10TuQTTUQGwBXGWTmBT0TlrrUs1/0LSlfkLTafYO?= =?utf-8?q?AGtAItOrKNgrz/op0NkBJTjFFajFepm8IecQY3xtk9ZWKxT3fI2kjAxOgky2LZoL5?= =?utf-8?q?3ayfcTSvDwf2bLFkpMB0V6Kk3xJwZRs2JGGxAwOIXA/gvENfhNgpR/s1T1aWcJgvp?= =?utf-8?q?xi1ibZtJ+LR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d6BEBtwMSgWq7Re55zM5iTMx7shyQL1B75Dc3E= X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB2032;6:57QlLf6oD5fz5gkYJuq+QjClEzjL05/aTF1xmZ30wMSUHPg6AGU6Hzr+Mt7WRx+TxT4w0Y549geoogQQXHAIZABynQo2+yhT+Vdar4lEe/VsL+bvIHQdn5CQCc5enXQ8Ox6AHKSnwIrnLktyDXFxt/yngWGNk2BW2wsC9xh5ZcFQliUYLcMLQnY/czYIbz72sKwAhAtrT+NBqsLHBwnMUuyJM4i/FnK9rIToPqghctao0E0Dq/wVzq30J/+leTq3XzyV+laqlKAyw+uupFEsTfyWMrOgGjeAVaXVqDt3TSw35QQSN7ivv7dteIuDb+1lfLCBGBZZyKRsJzjGaIGnga/NTB53VK/Ys6Lg51vWAvdCCnplqT+0tMR8sRgWvzz6Z/pOLcwAUvSMNNiEs0lmHOzLAXCb69xOvsa9LFIPC2MN347VVb1wmeqguEpBRT/1LVPP+HiSKf1kbJj40YkyVA==;5:UaLsYXmszctXzEqtLFe1YLjhJEKJV0kVfC+vJNjTEuWa41Kx1EuGa1QHyOS7YnzTyI5VjF+Kds9633c+hApkOwO0SY9OUgcOHAMaJOZhI2MoyZXjefbrVaNh4jt09759uI7i2v5nkxXDMnid2yDsXCq61+RmIYRT0oaRZ1ok8VY=;7:aiRK6Pwh4QXTQyIfGWp6CNdUO/6Ul3OzHDOgGTZpz7KEfU02ccBH6SZ/fdfNWi4N46vdLUVLJGTNX/o97T4x4wR/rPLDJp2bDwC7fHov8MweAV7+VouHBq0FhKDQi59sGIMEowEaQrO50ZH+mZ8CdrBrdCc92vz3TgPCCeHYX4f3olJJVN+csnXR2EuIYW5pMv7CYUmUU6qIsgLUfhz14ri5m3NNK5WJyu/eZ7eHaF+O6pKQyORrh39MdJudD/Uh SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB2032;20:NCyEHFyhEO1UIqvScnozNXvsVmU3SU3IviPsFDeCzJznLkU7UtzDvOM0wyGwR1fKA3oynU1/WGSrhWaLC3R0I0axmSPkQP71FL/q6djN/Q79msx5K7ZXD5czdK5g1usdmst/mkd21LbGLCVPGAHwornGn+Uc2NVMrZ/L8ow/fk0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2018 15:29:41.0466 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c1c7f42a-9c18-4c82-0417-08d60c31e896 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB2032 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 Functions sequences like request_end()->flush_bg_queue() require max_background and congestion_threshold are constant during their execution. Otherwise, checks like if (fc->num_background == fc->max_background) made in different time may behave not like expected. Signed-off-by: Kirill Tkhai --- fs/fuse/control.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/fs/fuse/control.c b/fs/fuse/control.c index c7290625e171..9206501bd94d 100644 --- a/fs/fuse/control.c +++ b/fs/fuse/control.c @@ -125,7 +125,12 @@ static ssize_t fuse_conn_max_background_write(struct file *file, if (ret > 0) { struct fuse_conn *fc = fuse_ctl_file_conn_get(file); if (fc) { + spin_lock(&fc->lock); fc->max_background = val; + fc->blocked = (fc->num_background >= fc->max_background); + if (!fc->blocked && waitqueue_active(&fc->blocked_waitq)) + wake_up(&fc->blocked_waitq); + spin_unlock(&fc->lock); fuse_conn_put(fc); } } @@ -155,18 +160,31 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file, size_t count, loff_t *ppos) { unsigned uninitialized_var(val); + struct fuse_conn *fc; ssize_t ret; ret = fuse_conn_limit_write(file, buf, count, ppos, &val, max_user_congthresh); - if (ret > 0) { - struct fuse_conn *fc = fuse_ctl_file_conn_get(file); - if (fc) { - fc->congestion_threshold = val; - fuse_conn_put(fc); + if (ret <= 0) + goto out; + fc = fuse_ctl_file_conn_get(file); + if (!fc) + goto out; + + spin_lock(&fc->lock); + fc->congestion_threshold = val; + if (fc->sb) { + if (fc->num_background < fc->congestion_threshold) { + clear_bdi_congested(fc->sb->s_bdi, BLK_RW_SYNC); + clear_bdi_congested(fc->sb->s_bdi, BLK_RW_ASYNC); + } else { + set_bdi_congested(fc->sb->s_bdi, BLK_RW_SYNC); + set_bdi_congested(fc->sb->s_bdi, BLK_RW_ASYNC); } } - + spin_unlock(&fc->lock); + fuse_conn_put(fc); +out: return ret; }