From: Rakesh Pandit <rakesh@tuxera.com>
To: <linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: "Matias Bjørling" <mb@lightnvm.io>, "Javier González" <jg@lightnvm.io>
Subject: [PATCH] lightnvm: prevent bd removal if busy
Date: Thu, 7 Sep 2017 16:58:27 +0300 [thread overview]
Message-ID: <20170907135825.GA44302@dhcp-216.srv.tuxera.com> (raw)
Removal of virtual block device by "nvm lnvm remove..." undergoing IO
and created by "nvme lnvm create... -t pblk" results in following and
is annoying.
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
.....
This patch solves this by checking bd_openers for each partition
before removal can continue. Note that this isn't full proof as
device can become busy as soon as it's bd_mutex is unlocked but it
needn't be full proof either. It does work for general case where
device is mounted and removal can be prevented.
Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
---
drivers/lightnvm/core.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index bbea2c8..cff91c7 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -369,6 +369,10 @@ 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 gendisk *tdisk;
+ struct disk_part_iter piter;
+ struct hd_struct *part;
+ int err;
mutex_lock(&dev->mlock);
t = nvm_find_target(dev, remove->tgtname);
@@ -376,10 +380,48 @@ static int nvm_remove_tgt(struct nvm_dev *dev, struct nvm_ioctl_remove *remove)
mutex_unlock(&dev->mlock);
return 1;
}
+
+ /*
+ * Lets make sure device is not in use. Note that this isn't full proof
+ * in anyway (as devices can become busy after unlock) but it is useful
+ * for preventing removal of devices which are open and undergoing IO.
+ */
+ tdisk = t->disk;
+ disk_part_iter_init(&piter, tdisk,
+ DISK_PITER_INCL_EMPTY | DISK_PITER_INCL_PART0 |
+ DISK_PITER_INCL_EMPTY_PART0);
+ while ((part = disk_part_iter_next(&piter))) {
+ struct block_device *bdev;
+
+ bdev = bdget(part_devt(part));
+ if (!bdev) {
+ err = -ENOMEM;
+ pr_err("nvm: removal failed, allocating bd failed\n");
+ goto err_out;
+ }
+ mutex_lock(&bdev->bd_mutex);
+ if (bdev->bd_openers) {
+ mutex_unlock(&bdev->bd_mutex);
+ bdput(bdev);
+ err = -EBUSY;
+ pr_err("nvm: removal failed, block device busy\n");
+ goto err_out;
+ }
+ mutex_unlock(&bdev->bd_mutex);
+ bdput(bdev);
+ }
+ disk_part_iter_exit(&piter);
+
__nvm_remove_target(t);
mutex_unlock(&dev->mlock);
return 0;
+err_out:
+ disk_part_iter_exit(&piter);
+ disk_put_part(part);
+ mutex_unlock(&dev->mlock);
+
+ return err;
}
static int nvm_register_map(struct nvm_dev *dev)
--
2.7.4
next reply other threads:[~2017-09-07 14:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-07 13:58 Rakesh Pandit [this message]
2017-09-08 10:42 ` Matias Bjørling
2017-09-10 19:14 ` Rakesh Pandit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170907135825.GA44302@dhcp-216.srv.tuxera.com \
--to=rakesh@tuxera.com \
--cc=jg@lightnvm.io \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mb@lightnvm.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®