From patchwork Tue Nov 7 18:26:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10047121 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 92B286032D for ; Tue, 7 Nov 2017 18:27:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 832212A291 for ; Tue, 7 Nov 2017 18:27:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 762382A22C; Tue, 7 Nov 2017 18:27:01 +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 F168F2A22C for ; Tue, 7 Nov 2017 18:27:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755784AbdKGS1A (ORCPT ); Tue, 7 Nov 2017 13:27:00 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:52411 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755645AbdKGS07 (ORCPT ); Tue, 7 Nov 2017 13:26:59 -0500 Received: by mail-qt0-f195.google.com with SMTP id 31so182077qtz.9 for ; Tue, 07 Nov 2017 10:26:58 -0800 (PST) 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; bh=rdPepT0HtOseI721Ur7f/duNBd5Jp2fk8V88LmzZ+wM=; b=GdzWEhqKKwh6fer9NHqNlUnetBWIEXhgkbJZLRsSylJdlBeEqgOjI91UcFlcQfBAw2 0pBME2tNmNpGjwS6Fe3cB8EOm0frQ0TanOtNi6f5veb6RKCLhUbjqrt0HMOEjTObQxPp W9LOgNZu1PS9hy1WEJ8b8YbCXIo+49niJBYXgak3iGkMBgefCwtG7DovGDsCh1Ifh31S JAwZdwI4Ig2P8HXLwyMmiyuG2elqzmJw7X3XNSKXnaaA98yGfcz6j2J/1IY0+KV/d+1H jWxmwlxPnSotkYNjv8zfO4g4+TprlsNPRojXww3I1vKgbM04efKKWak1c5JOCFzqUjTu MfPQ== 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; bh=rdPepT0HtOseI721Ur7f/duNBd5Jp2fk8V88LmzZ+wM=; b=tbCJzDPE+EKT8/1QUgp+Dnm8qD8gCemhAgg1uq4Hs3SfcqlWT9QgLV5npG7eMcswDA B8NW/wdn25qH3yo960rA44SFM4y5V8njmlVFO4EYQNcG41DMToJR+vhntyes//kv6IUR crJsqIV7VQ8eMmuPzvaLKG9MAtT2XEZFxfXsxpmZmvcTaub7cOpKPGTUeA5BIoGTLon9 Jdq+zx+z1I71pcCyfgBwPq9n8VJ2ouw+S+gpIhIOv97s0OJkTsvDkGVb1+aP+JDnw3T4 j3j1eJdVAZnK1GQWw/n7umoHvdvulI74MzA+PhePde94rDJTGpCdK+PeBmSfBtVjfX4C 4lVw== X-Gm-Message-State: AMCzsaXi1i9mqjaPoR+PbGDAeBZA2s5lillFQPeB6Yl/dbUNpgDJZl09 /6NxpCg5uA+s86TfSUIMkWtDFA== X-Google-Smtp-Source: ABhQp+TIU7hHCu8MLhNVnEN7zSgAexqJDQ0RRc/bGXGvoEWQrd40PUo54MtOTCxIYjIysq5kEBjW8Q== X-Received: by 10.200.8.149 with SMTP id v21mr29504065qth.123.1510079218419; Tue, 07 Nov 2017 10:26:58 -0800 (PST) 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 h187sm1317360qkc.40.2017.11.07.10.26.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2017 10:26:57 -0800 (PST) From: Josef Bacik To: axboe@kernel.dk, nbd@other.debian.org, linux-block@vger.kernel.org, kernel-team@fb.com Cc: Josef Bacik Subject: [PATCH] nbd: fix bdev invalidation Date: Tue, 7 Nov 2017 13:26:56 -0500 Message-Id: <1510079216-4580-1-git-send-email-josef@toxicpanda.com> X-Mailer: git-send-email 2.7.5 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: Josef Bacik We do the bdev invalidation sort of haphazardly throughout nbd which has resulted in weirdness like partitions not showing up when doing netlink connects, or they not disappearing properly in the ioctl case. Fix this by making the invalidation of the device more forceful when we drop our config, and make sure we invalidate the bdev every time we make a new connection so the partition table is picked up. Signed-off-by: Josef Bacik --- drivers/block/nbd.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 5f2a4240a204..ef7398ccb387 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -220,14 +220,6 @@ static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock, nsock->sent = 0; } -static void nbd_size_clear(struct nbd_device *nbd) -{ - if (nbd->config->bytesize) { - set_capacity(nbd->disk, 0); - kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); - } -} - static void nbd_size_update(struct nbd_device *nbd) { struct nbd_config *config = nbd->config; @@ -945,14 +937,20 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg) return -ENOSPC; } -static void nbd_bdev_reset(struct block_device *bdev) +static void nbd_invalidate_disk(struct nbd_device *nbd) { - if (bdev->bd_openers > 1) + struct block_device *bdev; + + if (!nbd->config->bytesize) return; - bd_set_size(bdev, 0); - if (max_part > 0) { - blkdev_reread_part(bdev); + + bdev = bdget_disk(nbd->disk, 0); + if (bdev) { + set_capacity(nbd->disk, 0); + __invalidate_device(bdev, true); bdev->bd_invalidated = 1; + bdput(bdev); + kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); } } @@ -1022,7 +1020,7 @@ static void nbd_config_put(struct nbd_device *nbd) &nbd->config_lock)) { struct nbd_config *config = nbd->config; nbd_dev_dbg_close(nbd); - nbd_size_clear(nbd); + nbd_invalidate_disk(nbd); if (test_and_clear_bit(NBD_HAS_PID_FILE, &config->runtime_flags)) device_remove_file(disk_to_dev(nbd->disk), &pid_attr); @@ -1110,15 +1108,13 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *b return ret; bd_set_size(bdev, config->bytesize); - if (max_part) - bdev->bd_invalidated = 1; + bdev->bd_invalidated = 1; mutex_unlock(&nbd->config_lock); ret = wait_event_interruptible(config->recv_wq, atomic_read(&config->recv_threads) == 0); if (ret) sock_shutdown(nbd); mutex_lock(&nbd->config_lock); - bd_set_size(bdev, 0); /* user requested, ignore socket errors */ if (test_bit(NBD_DISCONNECT_REQUESTED, &config->runtime_flags)) ret = 0; @@ -1131,8 +1127,6 @@ static void nbd_clear_sock_ioctl(struct nbd_device *nbd, struct block_device *bdev) { sock_shutdown(nbd); - kill_bdev(bdev); - nbd_bdev_reset(bdev); if (test_and_clear_bit(NBD_HAS_CONFIG_REF, &nbd->config->runtime_flags)) nbd_config_put(nbd); @@ -1708,6 +1702,11 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info) } } ret = nbd_start_device(nbd); + if (!ret) { + struct block_device *bdev = bdget_disk(nbd->disk, 0); + bdev->bd_invalidated = 1; + bdput(bdev); + } out: mutex_unlock(&nbd->config_lock); if (!ret) {