From patchwork Wed May 25 02:48:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 12860687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95081C433F5 for ; Wed, 25 May 2022 02:48:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242438AbiEYCsk (ORCPT ); Tue, 24 May 2022 22:48:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234123AbiEYCsi (ORCPT ); Tue, 24 May 2022 22:48:38 -0400 Received: from mail-vs1-xe33.google.com (mail-vs1-xe33.google.com [IPv6:2607:f8b0:4864:20::e33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30B2E703C7 for ; Tue, 24 May 2022 19:48:36 -0700 (PDT) Received: by mail-vs1-xe33.google.com with SMTP id z6so19965837vsp.0 for ; Tue, 24 May 2022 19:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to:cc; bh=RRJ46JB/nYv8adFmsAtkD7ohsfbSmPHvi/tw0fAjKGQ=; b=WmUdQG7RE6hMImLSMVvYi0rtsNtn4db/pZWVcmT7rQTFtSbznc5Gaw0s5Yo2Jj+x6T LU8LQmj6lt8Vjo/ZtbDe/JwDYxHU5BsJbEn02fYNvrX4U8T0a33Jmq4W0VMy1eVO53dX R4UXCHsqfA8wnxAUDh6mge3jbZKwFoK5iYkxEYZZ9JD0Eq44QZ6TNiM4KsdGgQVX24Ny zQh0txsVw+TFGc+MEV6gYyCW71RLED57paCHuvXj4/NNlIzhxo/iBn6/30OFqLk6Mccp OtxbCpoOs5lWGanudX0R6nJL0h3AlC6AVORtnjHv0X8hzd+9A12uJVoxlr3x2cg6iaTc Ws6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=RRJ46JB/nYv8adFmsAtkD7ohsfbSmPHvi/tw0fAjKGQ=; b=jS1FeIUxnCjkigKswJswAvSzGwF2LOzq8tEFsW3eKTo8b7XkMvB0uswS745WWFMMLi LHvV5at+6VCJCAGg0dOtKeVLgJsA8lawYX1mFSb+scOFLC0f4YjYDWbKcSPdzcQqNh1V wZGsRQwfwAjGlSz+L+gJ9m5ziJCAifpT30IGZT0nwLexozuLeaLObwx12TrxCvhtLjbi roFMI7XVOg4c0wCNWvnC7GVR1WU3h/3XItF6ERHa5zlR7qOq8ExJOoPyHRMypyGtiLq6 L9geQFmqp3st9pi2RjSlyn3862zBbDeFc+3OvJB2CQGXR9ArF4iVg+/Eu/2O5d+NffoI yPXw== X-Gm-Message-State: AOAM533hhRTOUwp3MopE3htTYtKcqLvqrDiJqHny/gvvRPRCahox+FlD E1P4sbVbfycb2WKAdV7DBofmbt+ju/QcuPKD+1BWNGfVAuE= X-Google-Smtp-Source: ABdhPJyqsJDkgQHgyjrp6G0heNpF8BvBY45auyaxem49WPFv7PxXIae7VhUiTI4uWz/cw2QTdHstJYx+amHiarZOilo= X-Received: by 2002:a67:b607:0:b0:337:b5b7:adc9 with SMTP id d7-20020a67b607000000b00337b5b7adc9mr5396254vsm.17.1653446914833; Tue, 24 May 2022 19:48:34 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Tue, 24 May 2022 21:48:23 -0500 Message-ID: Subject: Should BUG() be removed or changed to WARN_ON in iov_iter changeset To: David Howells Cc: CIFS Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org ------------------------------------------------------------------------- /home/smfrench/dhowell/linux-fs/0003-cifs-Add-some-helper-functions.patch ------------------------------------------------------------------------- WARNING: Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON() #67: FILE: fs/cifs/cifssmb.c:1950: + BUG(); WARNING: Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON() #95: FILE: fs/cifs/cifssmb.c:1978: + BUG(); WARNING: Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON() #123: FILE: fs/cifs/cifssmb.c:2006: + BUG(); total: 0 errors, 3 warnings, 106 lines checked From 99b3366e40c61642efbd953022aec76cf791eca9 Mon Sep 17 00:00:00 2001 From: David Howells Date: Wed, 6 Apr 2022 19:41:28 +0100 Subject: [PATCH 3/7] cifs: Add some helper functions 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/cifssmb.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index c0542bdcd06b..34ad965cde21 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/cifssmb.c b/fs/cifs/cifssmb.c index 47e927c4ff8d..88e2de74f74f 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -27,6 +27,7 @@ #include "cifsglob.h" #include "cifsacl.h" #include "cifsproto.h" +#include "cifsfs.h" #include "cifs_unicode.h" #include "cifs_debug.h" #include "smb2proto.h" @@ -1928,6 +1929,90 @@ cifs_writedata_release(struct kref *refcount) kfree(wdata); } +/* + * 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); + + rcu_read_lock(); + + end = (start + len - 1) / PAGE_SIZE; + xas_for_each(&xas, folio, end) { + if (!folio_test_writeback(folio)) { + pr_err("bad %x @%llx page %lx %lx\n", + len, start, folio_index(folio), end); + BUG(); + } + + 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); + + rcu_read_lock(); + + end = (start + len - 1) / PAGE_SIZE; + xas_for_each(&xas, folio, end) { + if (!folio_test_writeback(folio)) { + pr_err("bad %x @%llx page %lx %lx\n", + len, start, folio_index(folio), end); + BUG(); + } + + 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); + + rcu_read_lock(); + + end = (start + len - 1) / PAGE_SIZE; + xas_for_each(&xas, folio, end) { + if (!folio_test_writeback(folio)) { + pr_err("bad %x @%llx page %lx %lx\n", + len, start, folio_index(folio), end); + BUG(); + } + + filemap_dirty_folio(folio->mapping, folio); + folio_end_writeback(folio); + } + + rcu_read_unlock(); +} + /* * Write failed with a retryable error. Resend the write request. It's also * possible that the page was redirtied so re-clean the page. -- 2.34.1