From patchwork Tue Feb 21 10:33:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 59855 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1791606wrn; Tue, 21 Feb 2023 02:42:33 -0800 (PST) X-Google-Smtp-Source: AK7set9NsCB6SgM9g62xmfGRDMKPGRCpTqUPClnCAXa+9hmlWxsZb3CMJ9C5LvruMMMdkb0J58wx X-Received: by 2002:a05:6402:412:b0:4ac:b838:a8fb with SMTP id q18-20020a056402041200b004acb838a8fbmr3265840edv.36.1676976153098; Tue, 21 Feb 2023 02:42:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676976153; cv=none; d=google.com; s=arc-20160816; b=Flr+PFbHprosVXiZNrH2zRboQzgLvltPXdTFs7JN9WUDlbZCdBRpsHvGfLGSuib+kI q1Mj8Qrdt7cAHkRd0DrNnIw7yE/Yodwly7908BoiZSttPJ8I1hendyoV4riH7iH90r5K Nu8av8buwV+kl4Udn+PZOq2sQQZ98siHJg9vuSLwLXpmDcHPlBK3Po7rD4A5ny+Eens5 NMt0iOAcOZbOl1HZHZA3CZliTHBswVtnUa/3+rwi8Uz6XBuHcla/mB9KzhLYG5ggkNgw CzXl9pG1i8T7BMPe7ot3S8yRRT4e8gYeytDfhBwBZvwwAg2zhBNPWIV2pTy7cVesrCQF 5VHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xmWMmRLO4RCPXUE5aAy0wfapwcwudmep/VuEFFP6HEo=; b=LJ02uTF31cE/1tTF8Pd8bIytk/amlBO+kS4G/7TuJk7zfQ+5bRairzRtAEw9GbrKux 6mQnZ5Y+pmr1kSZaLJ+AoDXKgi5kSDCpym2IUzBlXEta6ARYiJIxvmVLq1ZRe+1RSDxb IM8YmiJd416anIxvewAXBI/JRFyU2+HFXZtskSiFDTA6sDb3zIQb15Nun6SlhbUqS8UN GlqS8SNzvT72S04q8p7chusBrQzKYA3kE1GFSBspnhXs9m/r1QTjrCMsEWrlQwJ8C8Ql OL6qNwccnJz5F/Nw0jS3Mr7TKnsYZm2seEMBCOBQVVk2nfmbbJL26HCk/pXaWvHRP5Od cTXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j23-20020a50ed17000000b0049b935e07e4si2805149eds.207.2023.02.21.02.42.10; Tue, 21 Feb 2023 02:42:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233731AbjBUKdV (ORCPT + 99 others); Tue, 21 Feb 2023 05:33:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232115AbjBUKdU (ORCPT ); Tue, 21 Feb 2023 05:33:20 -0500 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8455F7ED9 for ; Tue, 21 Feb 2023 02:33:17 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R321e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0VcC1Vwm_1676975594; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VcC1Vwm_1676975594) by smtp.aliyun-inc.com; Tue, 21 Feb 2023 18:33:15 +0800 From: Jingbo Xu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/2] cachefiles: don't align the write IO in ondemand mode Date: Tue, 21 Feb 2023 18:33:12 +0800 Message-Id: <20230221103313.120834-2-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230221103313.120834-1-jefflexu@linux.alibaba.com> References: <20230221103313.120834-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758436946614398157?= X-GMAIL-MSGID: =?utf-8?q?1758436946614398157?= If the write IO requested by the user daemon is not aligned with the block size of the backing filesystem, it's expected to fail directly rather than submit the aligned write IO (with expanded file range unmatching with the given iov_iter). Signed-off-by: Jingbo Xu --- fs/cachefiles/ondemand.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 0254ed39f68c..c017aca2a8a2 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -52,7 +52,8 @@ static ssize_t cachefiles_ondemand_fd_write_iter(struct kiocb *kiocb, return -ENOBUFS; cachefiles_begin_secure(cache, &saved_cred); - ret = __cachefiles_prepare_write(object, file, &pos, &len, true); + ret = cachefiles_has_space(cache, 0, len >> cache->bshift, + cachefiles_has_space_for_write); cachefiles_end_secure(cache, saved_cred); if (ret < 0) return ret; From patchwork Tue Feb 21 10:33:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 59853 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1789894wrn; Tue, 21 Feb 2023 02:37:31 -0800 (PST) X-Google-Smtp-Source: AK7set+MN8hueChUW/jx8DBzxCcRVo/V2u2rGs589Ungw/ks9NMpTnn0RKboy6ygbfghiLP+zmRB X-Received: by 2002:a17:907:9c04:b0:88d:ba89:183a with SMTP id ld4-20020a1709079c0400b0088dba89183amr8343956ejc.11.1676975851400; Tue, 21 Feb 2023 02:37:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676975851; cv=none; d=google.com; s=arc-20160816; b=wrwSshcc9Ri4FTLNmW319ovckU8/QSwbSseqDoQ03QAQ8amuEdKPNUHHMlQFnseqt2 ltWbWBy2MZ50AsgY4fNYC3OCypMzRQJF4ijZADtFVMyVQalk+4K7UYmAMnLJ1iw6BcIA E8Ct/nwBbI2UxN53QU1AM3pJ1pPisL2GWtBFIUJWJWx2+0f2U8lYGKMg5PYuikxGUtuv VEYLq/YP82+YX0meUFo4sTXVnY7XzDzcrWv7YdNyo6vHyA+GOHQPd7yGu8NuWn24KujX 3XilbbiQDnP6oOCzsBZumPeRl2qcwOY8a741cTWm3I9EeW10+oU1mxAgRRV5TzOJicKK Ticg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=YGhcs2sEl/YMkH99cZfz6SaabLfc4k6BOWBztxyRLd0=; b=sr7CrDE4bDgVeKVGfSm2DY7cvvTgCt70hbOZyRu+7c6vLelk1L5tv6TrJRilb6WUig OGzCjQgmAEpYn8rH9cOSrTKW3fuSzEYoXPGGdOW6QpDLV7fKNHwbDSnI1Oz4nCpudFHS 5BvRQK4CYjEN5cSWnrG1WeGcLLxMZbReX+OCIVEG53RsZIUidFGISMPuYY5hYbAMck9N RfymmmG/OEu4Nz9ykI2BPXfjOM+wczTqMeWR/Fvz7+keiFByRcQjktyhR9M68Whtmv3H gjl9oKLDVxoxpyIWU/9EXfr5XmmqS3H4Py1Qj/h8aD2HYi/19vstARq0riQtNyiFRPx1 FLfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n14-20020a17090673ce00b0087783864543si21658803ejl.591.2023.02.21.02.37.07; Tue, 21 Feb 2023 02:37:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233767AbjBUKd0 (ORCPT + 99 others); Tue, 21 Feb 2023 05:33:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233364AbjBUKdV (ORCPT ); Tue, 21 Feb 2023 05:33:21 -0500 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7EA383C4 for ; Tue, 21 Feb 2023 02:33:18 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0VcC7r-U_1676975595; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VcC7r-U_1676975595) by smtp.aliyun-inc.com; Tue, 21 Feb 2023 18:33:15 +0800 From: Jingbo Xu To: dhowells@redhat.com, linux-cachefs@redhat.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/2] fscache: introduce fscache_begin_wait_operation() helper Date: Tue, 21 Feb 2023 18:33:13 +0800 Message-Id: <20230221103313.120834-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230221103313.120834-1-jefflexu@linux.alibaba.com> References: <20230221103313.120834-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758436630404297099?= X-GMAIL-MSGID: =?utf-8?q?1758436630404297099?= This is a variant of fscache_wait_for_operation() except that it's exported for users of FsCache, and thus cookie->lock is held when checking cookie's state. Exporting fscache_begin_operation() directly is not acceptable as it would introduce dependency of for users of FsCache. Signed-off-by: Jingbo Xu --- fs/fscache/io.c | 9 +++++++++ include/linux/fscache.h | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/fs/fscache/io.c b/fs/fscache/io.c index 0d2b8dec8f82..6ccc5aadf151 100644 --- a/fs/fscache/io.c +++ b/fs/fscache/io.c @@ -158,6 +158,15 @@ int __fscache_begin_write_operation(struct netfs_cache_resources *cres, } EXPORT_SYMBOL(__fscache_begin_write_operation); +int __fscache_begin_wait_operation(struct netfs_cache_resources *cres, + struct fscache_cookie *cookie, + enum fscache_want_state want_state) +{ + return fscache_begin_operation(cres, cookie, want_state, + fscache_access_io_wait); +} +EXPORT_SYMBOL(__fscache_begin_wait_operation); + /** * fscache_dirty_folio - Mark folio dirty and pin a cache object for writeback * @mapping: The mapping the folio belongs to. diff --git a/include/linux/fscache.h b/include/linux/fscache.h index 8e312c8323a8..708cf8db7f46 100644 --- a/include/linux/fscache.h +++ b/include/linux/fscache.h @@ -171,6 +171,8 @@ extern void __fscache_resize_cookie(struct fscache_cookie *, loff_t); extern void __fscache_invalidate(struct fscache_cookie *, const void *, loff_t, unsigned int); extern int __fscache_begin_read_operation(struct netfs_cache_resources *, struct fscache_cookie *); extern int __fscache_begin_write_operation(struct netfs_cache_resources *, struct fscache_cookie *); +extern int __fscache_begin_wait_operation(struct netfs_cache_resources *, struct fscache_cookie *, + enum fscache_want_state want_state); extern void __fscache_write_to_cache(struct fscache_cookie *, struct address_space *, loff_t, size_t, loff_t, netfs_io_terminated_t, void *, @@ -543,6 +545,26 @@ int fscache_begin_write_operation(struct netfs_cache_resources *cres, return -ENOBUFS; } +/** + * fscache_begin_wait_operation - Wait for an object become accessible + * @cres: The cache resources for the operation being performed + * @cookie: The cookie representing the cache object + * + * Returns: + * * 0 - Success + * * -ENOBUFS - No caching available + * * Other error code from the cache, such as -ENOMEM. + */ +static inline +int fscache_begin_wait_operation(struct netfs_cache_resources *cres, + struct fscache_cookie *cookie, + enum fscache_want_state want_state) +{ + if (fscache_cookie_enabled(cookie)) + return __fscache_begin_wait_operation(cres, cookie, want_state); + return -ENOBUFS; +} + /** * fscache_write - Start a write to the cache. * @cres: The cache resources to use