@@ -1083,6 +1083,7 @@ static int nvm_core_init(struct nvm_dev *dev)
INIT_LIST_HEAD(&dev->targets);
mutex_init(&dev->mlock);
spin_lock_init(&dev->lock);
+ dev->create_inflight = 0;
ret = nvm_register_map(dev);
if (ret)
@@ -1180,6 +1181,11 @@ void nvm_unregister(struct nvm_dev *dev)
struct nvm_target *t, *tmp;
mutex_lock(&dev->mlock);
+ while (dev->create_inflight > 0) {
+ mutex_unlock(&dev->mlock);
+ io_schedule();
+ mutex_lock(&dev->mlock);
+ }
list_for_each_entry_safe(t, tmp, &dev->targets, list) {
if (t->dev->parent != dev)
continue;
@@ -1213,6 +1219,7 @@ static void nvm_normalize_path(char *path)
static int __nvm_configure_create(struct nvm_ioctl_create *create)
{
struct nvm_dev *dev;
+ int ret;
down_write(&nvm_lock);
dev = nvm_find_nvm_dev(create->dev);
@@ -1223,7 +1230,17 @@ static int __nvm_configure_create(struct nvm_ioctl_create *create)
return -EINVAL;
}
- return nvm_create_tgt(dev, create);
+ mutex_lock(&dev->mlock);
+ dev->create_inflight++;
+ mutex_unlock(&dev->mlock);
+
+ ret = nvm_create_tgt(dev, create);
+
+ mutex_lock(&dev->mlock);
+ dev->create_inflight--;
+ mutex_unlock(&dev->mlock);
+
+ return ret;
}
static long nvm_ioctl_info(struct file *file, void __user *arg)
@@ -428,6 +428,8 @@ struct nvm_dev {
char name[DISK_NAME_LEN];
void *private_data;
+ int create_inflight;
+
void *rmap;
struct mutex mlock;
This patch adds a counter, which is responsible for tracking inflight target creations. When creation process is still in progress, target is not yet on targets list. This causes a chance for removing whole lightnvm subsystem by calling nvm_unregister() in the meantime and finally by causing kernel panic inside target init function. With this patch we are able to track such a scenarios and wait with completing nvm_unregister() and freeing memory until target creation will be completed. Signed-off-by: Igor Konopko <igor.j.konopko@intel.com> --- drivers/lightnvm/core.c | 19 ++++++++++++++++++- include/linux/lightnvm.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-)