Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3027186rwr; Fri, 28 Apr 2023 22:26:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7OONvkYsFKslXiHBrQZX/x3kIDSNmQKYzvi2Sv4ZUdC/hKVHU2U5qRXJOAFCK7eNg5oYni X-Received: by 2002:a05:6a20:2451:b0:f6:28de:89e1 with SMTP id t17-20020a056a20245100b000f628de89e1mr9756446pzc.33.1682745985084; Fri, 28 Apr 2023 22:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682745985; cv=none; d=google.com; s=arc-20160816; b=k+7JR4zp8VkaiH2o/U/jlujnY/LYxMkzEOeznH8zEmebDKZAiXW0aa0nIJdjYAFzMi /pqmTF1KzsN1vCfKYoHuRuBg5T0oBBdx+wdP9brGOP7LtPW4SvTG4EEbHfw9AuME6v6f jf+DGDvRLCO6chFo2P/53cfe+ctAoUSA9A7JG3pMbp3AsisNst9fwzlNKA6q2j8DlcVQ 0ML6n5Jh/MFYhwg0RWJRRNhElvrKXBE19MlBzYVLOupxJdO5QB3rh77XhxSBQ2PXHq9z RaM5GlDvc/zU2NCHCrRT2nb4DZXEUaUJDqvgnq0W//fmGyDCZEonTsCaJv8mLDfo2ejG +OFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MxVIng8Evj++Z1u5M0nsXwrWqthOdSqW0ypNnEpPCFw=; b=LE2JOcXeAGK/xHtawZpTSi5S+PdQ/dZR8QbayRf2hNNYSU6DSTDzkBrSztZLY9TGYl TfWvdHHTtk+r9Ll2gBz7kcc/BF/Y1T48TIp6FaQ9bILnjjDv19Hasi00ibc52MFvZpr0 7KnoJDd/iOwybU2MrQS47m5ff6lhyt0/o7+xBtWF6v8gR5hPC3JGKb4PVeBE0FGw6ane mTJ0ypaSi2Tm4rllsuBBDgtUufAieRyoi+PDx6keqE3bqfTbVYPNzI6OPV29kguRIE/O W3kSlWXWb27ChNG/sMjl75oMbpUE9Etf5kx649VtbkiI19bF5cunvuewRx8O4Q1ok3D7 3u+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=HKk5nO+q; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a6540cb000000b0051b25fd77absi21430038pgp.887.2023.04.28.22.26.10; Fri, 28 Apr 2023 22:26:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=fail header.i=@mit.edu header.s=outgoing header.b=HKk5nO+q; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230347AbjD2E46 (ORCPT + 99 others); Sat, 29 Apr 2023 00:56:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbjD2E45 (ORCPT ); Sat, 29 Apr 2023 00:56:57 -0400 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 052D72D7F for ; Fri, 28 Apr 2023 21:56:55 -0700 (PDT) Received: from letrec.thunk.org ([76.150.80.181]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 33T4u4S9019981 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 29 Apr 2023 00:56:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1682744169; bh=MxVIng8Evj++Z1u5M0nsXwrWqthOdSqW0ypNnEpPCFw=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=HKk5nO+qnFlDZChkGokPzHeb6mvY0qy3p1ZzgVpxcrxibP21L3LwhzN0L4jDw90kI rI2LnVSA2rc3SkGUKXHZ6OzPX6WV1VJS0OZg3JnOFp5IeCr0s025WZVc3r5bjKXis6 fbaz12JodlwTmZUq4iSXHcD57Z2JCIE9BsY7PENAuTwFrBUIHtO9NwOHAyhCrhpntL nMZ8yuB5zX0TXXgUNOObAmZkfmIOxsb4sZGE0z6ceafd4F3pgog1qX0LFSKzHmxHYz SEg5X9BmJM4q+abjxF8q/WSE6mfkZRqwheEM41Q2by7xwJRV10PKJDXCxcNgu0psiz zz2t9GLTgjh1Q== Received: by letrec.thunk.org (Postfix, from userid 15806) id EF0678C01B4; Sat, 29 Apr 2023 00:56:03 -0400 (EDT) Date: Sat, 29 Apr 2023 00:56:03 -0400 From: "Theodore Ts'o" To: Ming Lei Cc: Baokun Li , Matthew Wilcox , linux-ext4@vger.kernel.org, Andreas Dilger , linux-block@vger.kernel.org, Andrew Morton , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Dave Chinner , Eric Sandeen , Christoph Hellwig , Zhang Yi , yangerkun Subject: Re: [ext4 io hang] buffered write io hang in balance_dirty_pages Message-ID: References: <663b10eb-4b61-c445-c07c-90c99f629c74@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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-ext4@vger.kernel.org On Sat, Apr 29, 2023 at 11:16:14AM +0800, Ming Lei wrote: > > bdi_unregister() is called in del_gendisk(), since bdi_register() has > to be called in add_disk() where major/minor is figured out. > > > problem is that the block device shouldn't just *vanish*, with the > > That looks not realistic, removable disk can be gone any time, and device > driver error handler often deletes disk as the last straw, and it shouldn't > be hard to observe such error. It's not realistic to think that the file system can write back any dirty pages, sure. At this point, the user has already yanked out the thumb drive, and the physical device is gone. However, various fields like bdi->dev shouldn't get deinitialized until after the s_ops->shutdown() function has returned. We need to give the file system a chance to shutdown any pending writebacks; otherwise, we could be racing with writeback happening in some other kernel thread, and while the I/O is certainly not going to suceed, it would be nice if attempts to write to the block device return an error, intead potentially causing the kernel to crash. The shutdown function might need to sleep while it waits for workqueues or kernel threads to exit, or while it iterates over all inodes and clears all of the dirty bits and/or drop all of the pages associated with the file system on the disconnected block device. So while this happens, I/O should just fail, and not result in a kernel BUG or oops. Once the s_ops->shutdown() has returned, then del_gendisk can shutdown and/or deallocate anything it wants, and if the file system tries to use the bdi after s_ops->shutdown() has returned, well, it deserves anything it gets. (Well, it would be nice if things didn't bug/oops in fs/buffer.c if there is no s_ops->shutdown() function, since there are a lot of legacy file systems that use the buffer cache and until we can add some kind of generic shutdown function to fs/libfs.c and make sure that all of the legacy file systems that are likely to be used on a USB thumb drive are fixed, it would be nice if they were protected. At the very least, we should make that things are no worse than they currently are.) - Ted P.S. Note that the semantics I've described here for s_ops->shutdown() are slightly different than what the FS_IOC_SHUTDOWN ioctl currently does. For example, after FS_IOC_SHUTDOWN, writes to files will fail, but read to already open files will succeed. I know this because the original ext4 shutdown implementation did actually prevent reads from going through, but we got objections from those that wanted ext4's FS_IOC_SHUTDOWN to work the same way as xfs's. So we have an out of tree patch for ext4's FS_IOC_SHUTDOWN implementation in our kernels at $WORK, because we were using it when we knew that the back-end server providing the iSCSI or remote block had died, and we wanted to make sure our borg (think Kubernetes) jobs would fast fail when they tried reading from the dead file system, as opposed to failing only after some timeout had elapsed. To avoid confusion, we should probably either use a different name than s_ops->shutdown(), or add a new mode to FS_IOC_SHUTDOWN which corresponds to "the block device is gone, shut *everything* down: reads, writes, everything." My preference would be the latter, since it would mean we could stop carrying that out-of-tree patch in our data center kernels...