From patchwork Fri Oct 28 15:56:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 12419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp909661wru; Fri, 28 Oct 2022 09:00:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7e1Z3qBOGd9p5iGkaj1jVcZsb/RvdBMVkLrm5qef9wE/7n9CBaZqqT5VboHs1mEWwD26pv X-Received: by 2002:a17:906:7621:b0:750:c4a3:8fcd with SMTP id c1-20020a170906762100b00750c4a38fcdmr53301ejn.180.1666972811240; Fri, 28 Oct 2022 09:00:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666972811; cv=none; d=google.com; s=arc-20160816; b=VG2ReuLWZpcRjuTbp1ECx8He2rWErfwz3TffgrUXZpJDIh2Eo2zD95dUQMG6sW6QIy w8kjQZPvFdbKPblwerhRniZn7V9WXTXgW24VNZsuVBhjYvI1SEuNvqwZ0r9Ujae5twfn jA6GCIxalEw7f3KMxsEOF2pxo2IIeXScbZaX9eBm+krz7NtjoUk6wvmlik9Vr79hDU/6 XKbuvHT6NeLwocWU7w1ThqE1iHIluDr7PHyxxBpnJ/3CUmWMBwDQwXQ6OUE0gQo6BG1E ut5XPXIW6GP3p7KhdEqdBnkuKdfaRfD81Re80YoCHm4HKfCy3YQQO7ODLX1tRMoC+/p5 oZPg== 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 :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=vcSnqlcRRyfKXl1TC1kFRibN44LvgmdEsy3sd9ep3aY=; b=wa8hYbv1h8EeyxvhScoDB2qQIHKsthMEhmcJ1IQJmm7jy5zmFa8md6g5Sh8l/q2MEY U3CsFPucvQBBGFhyto+gOPhV/tBTduBQqgnBQ4BhUy09+Lc+Fo+WuBgM1uypgeOUl6yD z+I+A+rg+uJW1hQDKxwHrk2TesFrZHqF8KyXckSKFGy9h82lRzm1WjchOfpW6Smsjt2r I1ZUJp5Wob5uxirAKRUXaIPSJ85lP2v3psElOc3rx6H7r78uLf4O378mNOCOT97unPib Pjgfm+rz7O4RIeWVFTfSE8f2Y6TXzx69vLkGYpf+R0UFMT1j5kPNP626ZbXi7T9HvppL u5dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="f/AIjJ62"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 9-20020a170906318900b00782e9b7305dsi4676670ejy.266.2022.10.28.08.59.47; Fri, 28 Oct 2022 09:00:11 -0700 (PDT) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="f/AIjJ62"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230295AbiJ1P6i (ORCPT + 99 others); Fri, 28 Oct 2022 11:58:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbiJ1P5e (ORCPT ); Fri, 28 Oct 2022 11:57:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCDF28C010 for ; Fri, 28 Oct 2022 08:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666972590; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vcSnqlcRRyfKXl1TC1kFRibN44LvgmdEsy3sd9ep3aY=; b=f/AIjJ62bPNJ6HwsAYQzAqhnRUIC3q4/rfFaMkSWxhRkBpvPpDiDrwn7Qkz9+5k6CMgaxV 3Fyu0U1xWfBS8r2miUxaR1oqsdF9gQedV01TlARasU6wfIdbHW2my4LieSIdI9uLeoXLUO KvOtb81B6mI4sZcgTf9OfnWlb1KKKoM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-447-4_ZbivfkPdSvo7GUgbezow-1; Fri, 28 Oct 2022 11:56:24 -0400 X-MC-Unique: 4_ZbivfkPdSvo7GUgbezow-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9664985A5B6; Fri, 28 Oct 2022 15:56:23 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13D7339DB3; Fri, 28 Oct 2022 15:56:21 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [RFC PATCH 5/9] cifs: Add some helper functions From: David Howells To: Steve French , Al Viro Cc: Steve French , Shyam Prasad N , Rohith Surabattula , linux-cifs@vger.kernel.org, dhowells@redhat.com, Shyam Prasad N , Rohith Surabattula , Tom Talpey , Christoph Hellwig , Matthew Wilcox , Jeff Layton , linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 28 Oct 2022 16:56:21 +0100 Message-ID: <166697258147.61150.9940790486999562110.stgit@warthog.procyon.org.uk> In-Reply-To: <166697254399.61150.1256557652599252121.stgit@warthog.procyon.org.uk> References: <166697254399.61150.1256557652599252121.stgit@warthog.procyon.org.uk> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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?1747947682048551968?= X-GMAIL-MSGID: =?utf-8?q?1747947682048551968?= Add some helper functions to manipulate the folio marks by iterating through a list of folios held in an xarray rather than using a page list. Signed-off-by: David Howells cc: Steve French cc: Shyam Prasad N cc: Rohith Surabattula cc: linux-cifs@vger.kernel.org --- fs/cifs/cifsfs.h | 3 ++ fs/cifs/file.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index 388b745a978e..e3ecf1406d1b 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h @@ -110,6 +110,9 @@ extern int cifs_file_strict_mmap(struct file * , struct vm_area_struct *); extern const struct file_operations cifs_dir_ops; extern int cifs_dir_open(struct inode *inode, struct file *file); extern int cifs_readdir(struct file *file, struct dir_context *ctx); +extern void cifs_pages_written_back(struct inode *inode, loff_t start, unsigned int len); +extern void cifs_pages_write_failed(struct inode *inode, loff_t start, unsigned int len); +extern void cifs_pages_write_redirty(struct inode *inode, loff_t start, unsigned int len); /* Functions related to dir entries */ extern const struct dentry_operations cifs_dentry_ops; diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 5b3b308e115c..0780d9bfb61d 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -36,6 +36,99 @@ #include "cifs_ioctl.h" #include "cached_dir.h" +/* + * Completion of write to server. + */ +void cifs_pages_written_back(struct inode *inode, loff_t start, unsigned int len) +{ + struct address_space *mapping = inode->i_mapping; + struct folio *folio; + pgoff_t end; + + XA_STATE(xas, &mapping->i_pages, start / PAGE_SIZE); + + if (!len) + return; + + rcu_read_lock(); + + end = (start + len - 1) / PAGE_SIZE; + xas_for_each(&xas, folio, end) { + if (!folio_test_writeback(folio)) { + WARN_ONCE(1, "bad %x @%llx page %lx %lx\n", + len, start, folio_index(folio), end); + continue; + } + + folio_detach_private(folio); + folio_end_writeback(folio); + } + + rcu_read_unlock(); +} + +/* + * Failure of write to server. + */ +void cifs_pages_write_failed(struct inode *inode, loff_t start, unsigned int len) +{ + struct address_space *mapping = inode->i_mapping; + struct folio *folio; + pgoff_t end; + + XA_STATE(xas, &mapping->i_pages, start / PAGE_SIZE); + + if (!len) + return; + + rcu_read_lock(); + + end = (start + len - 1) / PAGE_SIZE; + xas_for_each(&xas, folio, end) { + if (!folio_test_writeback(folio)) { + WARN_ONCE(1, "bad %x @%llx page %lx %lx\n", + len, start, folio_index(folio), end); + continue; + } + + folio_set_error(folio); + folio_end_writeback(folio); + } + + rcu_read_unlock(); +} + +/* + * Redirty pages after a temporary failure. + */ +void cifs_pages_write_redirty(struct inode *inode, loff_t start, unsigned int len) +{ + struct address_space *mapping = inode->i_mapping; + struct folio *folio; + pgoff_t end; + + XA_STATE(xas, &mapping->i_pages, start / PAGE_SIZE); + + if (!len) + return; + + rcu_read_lock(); + + end = (start + len - 1) / PAGE_SIZE; + xas_for_each(&xas, folio, end) { + if (!folio_test_writeback(folio)) { + WARN_ONCE(1, "bad %x @%llx page %lx %lx\n", + len, start, folio_index(folio), end); + continue; + } + + filemap_dirty_folio(folio->mapping, folio); + folio_end_writeback(folio); + } + + rcu_read_unlock(); +} + /* * Mark as invalid, all open files on tree connections since they * were closed when session to server was lost.