From patchwork Fri Oct 13 12:45:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 10004701 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 7006B60360 for ; Fri, 13 Oct 2017 13:05:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 623F129065 for ; Fri, 13 Oct 2017 13:05:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5738A29067; Fri, 13 Oct 2017 13:05:13 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable 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 D9DF029065 for ; Fri, 13 Oct 2017 13:05:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758130AbdJMNEQ (ORCPT ); Fri, 13 Oct 2017 09:04:16 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:57207 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753413AbdJMMrJ (ORCPT ); Fri, 13 Oct 2017 08:47:09 -0400 Received: by mail-wm0-f68.google.com with SMTP id l68so21508094wmd.5 for ; Fri, 13 Oct 2017 05:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NCReXiX77u3FLcLZahTiNnzcAAoIyzF1KsaGyFzJomk=; b=mPOiOb3qML6IdaYP8qR6mgsOFu/dcqaJ507hSz1I3vG/FyYln9zyXwp+FEcj0Z0I4N A79dqscRH+G+hSlgEUxyv8junGcA2MyrS3T66yN80fxbTQ0GV7D+Zt63GX3v8FykTsPl FhXcf/uM0U6SlIP7tCvKwleBzM0SYP66GJYqI= 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:mime-version:content-transfer-encoding; bh=NCReXiX77u3FLcLZahTiNnzcAAoIyzF1KsaGyFzJomk=; b=oW+GlIsuIyNqcP7ZQMIqvR4NoaWGZkJEx+f6mFXuDRIfCQeuQpVB88+xBG9ZMorQju ErLw0ZM/Dowc441IIN+Kc9hxU4jlC5m5+dKrdBbo1nEWb8VHBK1dtp0GF+zlY36FeSzv fAWgphE7+0ZAB6nLLpsq6KpMTpz3VN9TySooNaOp/5zB/2ThSe0ffkcNlc7zmRhhiYbH 7SmLj1E8OE+7UUMgsaRrySK4lyz7JLELBrEcW6lmKjbpfWkBTQrsjrX8r4OpGZAt4aNE T6uvhTBkqJWoAEgwo4a+d5ssdXn3qOUdnyLPZDvN+7NSIFNVsOcO9m6UQxA9NiBa911j sOHw== X-Gm-Message-State: AMCzsaWcNQBTis12aPv/vVU7j2KKaPol3eN5VfLdnwMEC9oT7jVCgdnm yiNgstICYfmKTUCR+WZg8bYeWw== X-Google-Smtp-Source: AOwi7QDd9J3EtxDMhFPNn2m9Z/PDXZvKabG+ITMNbTfXItduOUGkMkXlabuFDvtnxzEbUD6a2GL6DQ== X-Received: by 10.80.179.185 with SMTP id s54mr2048553edd.164.1507898828326; Fri, 13 Oct 2017 05:47:08 -0700 (PDT) Received: from skyninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id p91sm735012edp.69.2017.10.13.05.47.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Oct 2017 05:47:07 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Rakesh Pandit , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [GIT PULL 02/58] lightnvm: prevent bd removal if busy Date: Fri, 13 Oct 2017 14:45:51 +0200 Message-Id: <20171013124647.32668-3-m@bjorling.me> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20171013124647.32668-1-m@bjorling.me> References: <20171013124647.32668-1-m@bjorling.me> MIME-Version: 1.0 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: Rakesh Pandit When a virtual block device is formatted and mounted after creating with "nvme lnvm create... -t pblk", a removal from "nvm lnvm remove" would result in this: 446416.309757] bdi-block not registered [446416.309773] ------------[ cut here ]------------ [446416.309780] WARNING: CPU: 3 PID: 4319 at fs/fs-writeback.c:2159 __mark_inode_dirty+0x268/0x340 Ideally removal should return -EBUSY as block device is mounted after formatting. This patch tries to address this checking if whole device or any partition of it already mounted or not before removal. Whole device is checked using "bd_super" member of block device. This member is always set once block device has been mounted using a filesystem. Another member "bd_part_count" takes care of checking any if any partitions are under use. "bd_part_count" is only updated under locks when partitions are opened or closed (first open and last release). This at least does take care sending -EBUSY if removal is being attempted while whole block device or any partition is mounted. Signed-off-by: Rakesh Pandit Reviewed-by: Javier González Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 60e163b..c490711 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -373,6 +373,7 @@ static void __nvm_remove_target(struct nvm_target *t) static int nvm_remove_tgt(struct nvm_dev *dev, struct nvm_ioctl_remove *remove) { struct nvm_target *t; + struct block_device *bdev; mutex_lock(&dev->mlock); t = nvm_find_target(dev, remove->tgtname); @@ -380,6 +381,19 @@ static int nvm_remove_tgt(struct nvm_dev *dev, struct nvm_ioctl_remove *remove) mutex_unlock(&dev->mlock); return 1; } + bdev = bdget_disk(t->disk, 0); + if (!bdev) { + pr_err("nvm: removal failed, allocating bd failed\n"); + mutex_unlock(&dev->mlock); + return -ENOMEM; + } + if (bdev->bd_super || bdev->bd_part_count) { + pr_err("nvm: removal failed, block device busy\n"); + bdput(bdev); + mutex_unlock(&dev->mlock); + return -EBUSY; + } + bdput(bdev); __nvm_remove_target(t); mutex_unlock(&dev->mlock);