Re: [PATCH v7 1/5] lightnvm: Support for Open-Channel SSDs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 09/04/2015 04:05 PM, Matias Bjørling wrote:

So here is a suggestion, register_bm again
if we found nvm_dev->bm == NULL in create_target(). And if it is still
NULL after that. return an error "nvm: no compatible bm was found"
and stop target creating. Otherwise, there would be a NULL Pointer
reference problem.

That's a real problem I met in my testing and I did this change
in my local using. I hope that's useful to you.

Hi Yang,
ac
Similar to this?

Okey, I attached two changes in my local using. I hope that
useful to you.

Yang

diff --git i/drivers/lightnvm/core.c w/drivers/lightnvm/core.c
index 5e4c2b8..0d2e5e3 100644
--- i/drivers/lightnvm/core.c
+++ w/drivers/lightnvm/core.c
@@ -262,8 +262,9 @@ int nvm_init(struct nvm_dev *dev)
         }

         if (!ret) {
-               pr_info("nvm: no compatible bm was found.\n");
-               return 0;
+               pr_info("nvm: %s was not initialized due to no
compatible bm.\n",
+                                                               dev->name);
+               return -EINVAL;
         }

         pr_info("nvm: registered %s with luns: %u blocks: %lu sector
size: %d\n",



.


>From 2060232d379328679b22753587d16249f01fa219 Mon Sep 17 00:00:00 2001
From: Dongsheng Yang <yangds.fnst@xxxxxxxxxxxxxx>
Date: Fri, 4 Sep 2015 08:10:13 +0900
Subject: [PATCH 2/2] lightNVM: register bm in nvm_create_target if dev->bm is
 NULL

When we create target, we need to make sure dev->bm is not NULL.
If it's NULL try to register bm again. If we still fail to find
a proper bm for this dev, return error rather than continue to
provide a NULL pointer dereference problem later.

Signed-off-by: Dongsheng Yang <yangds.fnst@xxxxxxxxxxxxxx>
---
 drivers/lightnvm/core.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 5e4c2b8..9c75ea4 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -293,10 +293,30 @@ static int nvm_create_target(struct nvm_dev *dev, char *ttname, char *tname,
 						int lun_begin, int lun_end)
 {
 	struct request_queue *tqueue;
+	struct nvm_bm_type *bt;
 	struct gendisk *tdisk;
 	struct nvm_tgt_type *tt;
 	struct nvm_target *t;
 	void *targetdata;
+	int ret = 0;
+
+	if (!dev->bm) {
+		/* register with device with a supported BM */
+		list_for_each_entry(bt, &nvm_bms, list) {
+			ret = bt->register_bm(dev);
+			if (ret < 0)
+				return ret; /* initialization failed */
+			if (ret > 0) {
+				dev->bm = bt;
+				break; /* successfully initialized */
+			}
+		}
+
+		if (!ret) {
+			pr_info("nvm: no compatible bm was found.\n");
+			return -ENODEV;
+		}
+	}
 
 	tt = nvm_find_target_type(ttname);
 	if (!tt) {
-- 
1.8.4.2

>From 699d279ee0dbf3db5a4e7a78d52fb93e954294a1 Mon Sep 17 00:00:00 2001
From: Dongsheng Yang <yangds.fnst@xxxxxxxxxxxxxx>
Date: Mon, 31 Aug 2015 17:22:23 -0400
Subject: [PATCH 1/2] lightNVM: fix a compatibility problem in compiling.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In some old gcc version, such as [gcc version 4.4.7 20120313 (Red Hat 4.4.7-4)]
there is a compiling error with this kind of code:

struct test {
	union {
		int data;
	};
};

int main()
{
        struct test ins = {
                .data = 1,
        };
        return 0;
}

 # gcc test.c
 # test.c: In function â??mainâ??:
 # test.c:12: error: unknown field â??dataâ?? specified in initializer

This patch fix this problem to initialize it in a compatible way.

Signed-off-by: Dongsheng Yang <yangds.fnst@xxxxxxxxxxxxxx>
---
 drivers/block/nvme-lightnvm.c | 58 +++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 32 deletions(-)

diff --git a/drivers/block/nvme-lightnvm.c b/drivers/block/nvme-lightnvm.c
index 8ad84c9..d1dbc67 100644
--- a/drivers/block/nvme-lightnvm.c
+++ b/drivers/block/nvme-lightnvm.c
@@ -184,13 +184,13 @@ static int init_chnls(struct request_queue *q, struct nvm_id *nvm_id,
 	struct nvme_nvm_id_chnl *src = nvme_nvm_id->chnls;
 	struct nvm_id_chnl *dst = nvm_id->chnls;
 	struct nvme_ns *ns = q->queuedata;
-	struct nvme_nvm_command c = {
-		.nvm_identify.opcode = nvme_nvm_admin_identify,
-		.nvm_identify.nsid = cpu_to_le32(ns->ns_id),
-	};
+	struct nvme_nvm_command c = {};
 	unsigned int len = nvm_id->nchannels;
 	int i, end, ret, off = 0;
 
+	c.nvm_identify.opcode = nvme_nvm_admin_identify;
+	c.nvm_identify.nsid = cpu_to_le32(ns->ns_id);
+
 	while (len) {
 		end = min_t(u32, NVME_NVM_CHNLS_PR_REQ, len);
 
@@ -230,13 +230,12 @@ static int nvme_nvm_identify(struct request_queue *q, struct nvm_id *nvm_id)
 {
 	struct nvme_ns *ns = q->queuedata;
 	struct nvme_nvm_id *nvme_nvm_id;
-	struct nvme_nvm_command c = {
-		.nvm_identify.opcode = nvme_nvm_admin_identify,
-		.nvm_identify.nsid = cpu_to_le32(ns->ns_id),
-		.nvm_identify.chnl_off = 0,
-	};
+	struct nvme_nvm_command c = {};
 	int ret;
 
+	c.nvm_identify.opcode = nvme_nvm_admin_identify;
+	c.nvm_identify.nsid = cpu_to_le32(ns->ns_id);
+	c.nvm_identify.chnl_off = 0;
 	nvme_nvm_id = kmalloc(4096, GFP_KERNEL);
 	if (!nvme_nvm_id)
 		return -ENOMEM;
@@ -270,14 +269,13 @@ static int nvme_nvm_get_features(struct request_queue *q,
 						struct nvm_get_features *gf)
 {
 	struct nvme_ns *ns = q->queuedata;
-	struct nvme_nvm_command c = {
-		.common.opcode = nvme_nvm_admin_get_features,
-		.common.nsid = ns->ns_id,
-	};
+	struct nvme_nvm_command c = {};
 	int sz = sizeof(struct nvm_get_features);
 	int ret;
 	u64 *resp;
 
+	c.common.opcode = nvme_nvm_admin_get_features;
+	c.common.nsid = ns->ns_id;
 	resp = kmalloc(sz, GFP_KERNEL);
 	if (!resp)
 		return -ENOMEM;
@@ -297,12 +295,11 @@ done:
 static int nvme_nvm_set_resp(struct request_queue *q, u64 resp)
 {
 	struct nvme_ns *ns = q->queuedata;
-	struct nvme_nvm_command c = {
-		.nvm_resp.opcode = nvme_nvm_admin_set_resp,
-		.nvm_resp.nsid = cpu_to_le32(ns->ns_id),
-		.nvm_resp.resp = cpu_to_le64(resp),
-	};
+	struct nvme_nvm_command c = {};
 
+	c.nvm_resp.opcode = nvme_nvm_admin_set_resp;
+	c.nvm_resp.nsid = cpu_to_le32(ns->ns_id);
+	c.nvm_resp.resp = cpu_to_le64(resp);
 	return nvme_submit_sync_cmd(q, (struct nvme_command *)&c, NULL, 0);
 }
 
@@ -311,16 +308,15 @@ static int nvme_nvm_get_l2p_tbl(struct request_queue *q, u64 slba, u64 nlb,
 {
 	struct nvme_ns *ns = q->queuedata;
 	struct nvme_dev *dev = ns->dev;
-	struct nvme_nvm_command c = {
-		.nvm_l2p.opcode = nvme_nvm_admin_get_l2p_tbl,
-		.nvm_l2p.nsid = cpu_to_le32(ns->ns_id),
-	};
+	struct nvme_nvm_command c = {};
 	u32 len = queue_max_hw_sectors(q) << 9;
 	u64 nlb_pr_rq = len / sizeof(u64);
 	u64 cmd_slba = slba;
 	void *entries;
 	int ret = 0;
 
+	c.nvm_l2p.opcode = nvme_nvm_admin_get_l2p_tbl;
+	c.nvm_l2p.nsid = cpu_to_le32(ns->ns_id);
 	entries = kmalloc(len, GFP_KERNEL);
 	if (!entries)
 		return -ENOMEM;
@@ -365,15 +361,14 @@ static int nvme_nvm_get_bb_tbl(struct request_queue *q, int lunid,
 {
 	struct nvme_ns *ns = q->queuedata;
 	struct nvme_dev *dev = ns->dev;
-	struct nvme_nvm_command c = {
-		.nvm_get_bb.opcode = nvme_nvm_admin_get_bb_tbl,
-		.nvm_get_bb.nsid = cpu_to_le32(ns->ns_id),
-		.nvm_get_bb.lbb = cpu_to_le32(lunid),
-	};
+	struct nvme_nvm_command c = {};
 	void *bb_bitmap;
 	u16 bb_bitmap_size;
 	int ret = 0;
 
+	c.nvm_get_bb.opcode = nvme_nvm_admin_get_bb_tbl;
+	c.nvm_get_bb.nsid = cpu_to_le32(ns->ns_id);
+	c.nvm_get_bb.lbb = cpu_to_le32(lunid);
 	bb_bitmap_size = ((nr_blocks >> 15) + 1) * PAGE_SIZE;
 	bb_bitmap = kmalloc(bb_bitmap_size, GFP_KERNEL);
 	if (!bb_bitmap)
@@ -471,12 +466,11 @@ static int nvme_nvm_submit_io(struct request_queue *q, struct nvm_rq *rqd)
 static int nvme_nvm_erase_block(struct request_queue *q, sector_t block_id)
 {
 	struct nvme_ns *ns = q->queuedata;
-	struct nvme_nvm_command c = {
-		.nvm_erase.opcode = nvme_nvm_cmd_erase,
-		.nvm_erase.nsid = cpu_to_le32(ns->ns_id),
-		.nvm_erase.blk_addr = cpu_to_le64(block_id),
-	};
+	struct nvme_nvm_command c = {};
 
+	c.nvm_erase.opcode = nvme_nvm_cmd_erase;
+	c.nvm_erase.nsid = cpu_to_le32(ns->ns_id);
+	c.nvm_erase.blk_addr = cpu_to_le64(block_id);
 	return nvme_submit_sync_cmd(q, (struct nvme_command *)&c, NULL, 0);
 }
 
-- 
1.8.4.2


[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux