Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1405182 > unrolled thread

[RFC PATCH 2/2] lightnvm: Append device name to target name

Started byWenwei Tao <wwtao0320@163.com>
First post2016-05-23 11:20 +0200
Last post2016-05-23 11:20 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [RFC PATCH 2/2] lightnvm: Append device name to target name Wenwei Tao <wwtao0320@163.com> - 2016-05-23 11:20 +0200

#1405182 — [RFC PATCH 2/2] lightnvm: Append device name to target name

FromWenwei Tao <wwtao0320@163.com>
Date2016-05-23 11:20 +0200
Subject[RFC PATCH 2/2] lightnvm: Append device name to target name
Message-ID<rBUbM-3YT-17@gated-at.bofh.it>
From: Wenwei Tao <ww.tao0320@gmail.com>

We may create targets with same name on different
backend devices, this is not what we want, so append
the device name to target name to make the new target
name unique in the system.

Signed-off-by: Wenwei Tao <ww.tao0320@gmail.com>
---
 drivers/lightnvm/gennvm.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c
index 39ff0af..ecb09cb 100644
--- a/drivers/lightnvm/gennvm.c
+++ b/drivers/lightnvm/gennvm.c
@@ -43,9 +43,18 @@ static int gen_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
 	struct gendisk *tdisk;
 	struct nvm_tgt_type *tt;
 	struct nvm_target *t;
+	char tgtname[DISK_NAME_LEN];
 	void *targetdata;
 	int ret = -ENOMEM;
 
+	if (strlen(dev->name) + strlen(create->tgtname) + 1 > DISK_NAME_LEN) {
+		pr_err("nvm: target name too long. %s:%s\n",
+				dev->name, create->tgtname);
+		return -EINVAL;
+	}
+
+	sprintf(tgtname, "%s%s", dev->name, create->tgtname);
+
 	tt = nvm_find_target_type(create->tgttype, 1);
 	if (!tt) {
 		pr_err("nvm: target type %s not found\n", create->tgttype);
@@ -53,7 +62,7 @@ static int gen_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
 	}
 
 	mutex_lock(&gn->lock);
-	t = gen_find_target(gn, create->tgtname);
+	t = gen_find_target(gn, tgtname);
 	if (t) {
 		pr_err("nvm: target name already exists.\n");
 		ret = -EINVAL;
@@ -73,7 +82,7 @@ static int gen_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
 	if (!tdisk)
 		goto err_queue;
 
-	sprintf(tdisk->disk_name, "%s", create->tgtname);
+	sprintf(tdisk->disk_name, "%s", tgtname);
 	tdisk->flags = GENHD_FL_EXT_DEVT;
 	tdisk->major = 0;
 	tdisk->first_minor = 0;
-- 
1.8.3.1

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web