From patchwork Fri Mar 24 18:08:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9643585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 313DD60327 for ; Fri, 24 Mar 2017 18:10:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27BD9201BD for ; Fri, 24 Mar 2017 18:10:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CB62269DA; Fri, 24 Mar 2017 18:10:22 +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=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 91D60201BD for ; Fri, 24 Mar 2017 18:10:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932626AbdCXSKV (ORCPT ); Fri, 24 Mar 2017 14:10:21 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:32891 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934927AbdCXSI6 (ORCPT ); Fri, 24 Mar 2017 14:08:58 -0400 Received: by mail-qt0-f196.google.com with SMTP id r45so1428252qte.0 for ; Fri, 24 Mar 2017 11:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ECpbiSxZ/g2CvGs2dpLMRekRlFaFWdBc5lH3bpPpqMk=; b=A9v6wDbkMaP+heEt92HUU1h3019O0rlCb4w1IbmRrwBZhi/bhXuW3jSrsBRYRaQj2C trgWmzkSERNopnrJORu8/qQQufGEIgRP+6NJtvVbGVYVBThFE0WOyp0NzLdGlf8sfIio JUr4xhhrgaxW0OxuSPCv8RZzWVNyYx5wEfKQalrojeHwEebJZonfx2MIannvL8C3151m gnmWfkVKM2knzIpl5YDoXRRM2WM7vwJrBtM0GvDbntfxBpjsElTvT1gv4rYL/yIWjz7D YPDinRdM0/GIFzIdo0vi/hKYBnehgW43sMj39WMAFPzoD6Ri4t6kfvAjUmD9xQB9B7WU Wgbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ECpbiSxZ/g2CvGs2dpLMRekRlFaFWdBc5lH3bpPpqMk=; b=Z6+LxJKXm8qbYMZ0Hu35m0uGzBH2V7fPtZ5O4QktvRPvsLVIRZvuU0fbIMHxp22jpU nnaTEkeIDJALoiqJM5z5sVgVEwE476x0WKjItuzENgUKJxf56EDLhQGLpKNyzp2/dpcA aaqYJHvcj5+ywuOAKG+BzTgRtlZxcBYK50igwKDu6NjrCCTxfq6Ezy+JT0CLUziDWGxp FskyucgA9qpZ/A9lMEHhkhpYh7jPYrvTdHq9vGcs1UQqj2nkVhGn6J+uEnp+RIbqAmw3 Jq5PUs7R7iPrp1+T1RZ7Kro1HcXAcp1xZM3e4RA1st6BXLbaaY+/lGnKnUshbxp0P0GS reSQ== X-Gm-Message-State: AFeK/H3dJvB5FjiO78iAuCVGPEZOXHQEhD7/XYmhDbge/y4ZgXT3jKnsI33XO3KXcgMVAA== X-Received: by 10.200.51.199 with SMTP id d7mr9042204qtb.94.1490378922335; Fri, 24 Mar 2017 11:08:42 -0700 (PDT) Received: from localhost (cpe-2606-A000-4381-1201-225-22FF-FEB3-E51A.dyn6.twc.com. [2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id 1sm1983545qty.69.2017.03.24.11.08.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Mar 2017 11:08:41 -0700 (PDT) From: Josef Bacik To: axboe@kernel.dk, nbd-general@lists.sourceforge.net, linux-block@vger.kernel.org, kernel-team@fb.com Cc: Ratna Manoj Bolla Subject: [PATCH 4/4] nbd: replace kill_bdev() with __invalidate_device() Date: Fri, 24 Mar 2017 14:08:29 -0400 Message-Id: <1490378909-4056-5-git-send-email-josef@toxicpanda.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490378909-4056-1-git-send-email-josef@toxicpanda.com> References: <1490378909-4056-1-git-send-email-josef@toxicpanda.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ratna Manoj Bolla When a filesystem is mounted on a nbd device and on a disconnect, because of kill_bdev(), and resetting bdev size to zero, buffer_head mappings are getting destroyed under mounted filesystem. After a bdev size reset(i.e bdev->bd_inode->i_size = 0) on a disconnect, followed by a sys_umount(), generic_shutdown_super()->... ->__sync_blockdev()->... -blkdev_writepages()->... ->do_invalidatepage()->... -discard_buffer() is discarding superblock buffer_head assumed to be in mapped state by ext4_commit_super(). [mlin: ported to 4.11-rc2] Signed-off-by: Ratna Manoj Bolla --- drivers/block/nbd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index b0003da..d8a2356 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -126,7 +126,8 @@ static const char *nbdcmd_to_ascii(int cmd) static int nbd_size_clear(struct nbd_device *nbd, struct block_device *bdev) { - bd_set_size(bdev, 0); + if (bdev->bd_openers <= 1) + bd_set_size(bdev, 0); set_capacity(nbd->disk, 0); kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); @@ -665,6 +666,8 @@ static void nbd_reset(struct nbd_device *nbd) static void nbd_bdev_reset(struct block_device *bdev) { + if (bdev->bd_openers > 1) + return; set_device_ro(bdev, false); bdev->bd_inode->i_size = 0; if (max_part > 0) { @@ -728,7 +731,8 @@ static int nbd_clear_sock(struct nbd_device *nbd, struct block_device *bdev) { sock_shutdown(nbd); nbd_clear_que(nbd); - kill_bdev(bdev); + + __invalidate_device(bdev, true); nbd_bdev_reset(bdev); /* * We want to give the run thread a chance to wait for everybody