* [PATCH] nvme: free pre-allocated queue if create ioq goes wrong
@ 2018-01-14 7:15 Minwoo Im
2018-01-14 9:18 ` Sagi Grimberg
0 siblings, 1 reply; 4+ messages in thread
From: Minwoo Im @ 2018-01-14 7:15 UTC (permalink / raw)
If either create-sq or create-cq is failed with an NVMe status,
nvme_init_queue() is invoked which was not expected to be called in
nvme_create_queue().
To prevent this inconsistency of queue_count, free queue(s) already
allocated in nvme_create_io_queues() when it goes wrong in
nvme_create_queue().
Signed-off-by: Minwoo Im <minwoo.im.dev at gmail.com>
---
drivers/nvme/host/pci.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index d53550e..a58282d 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1456,11 +1456,11 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
nvmeq->cq_vector = qid - 1;
result = adapter_alloc_cq(dev, qid, nvmeq);
- if (result < 0)
- return result;
+ if (result)
+ goto free_queue;
result = adapter_alloc_sq(dev, qid, nvmeq);
- if (result < 0)
+ if (result)
goto release_cq;
nvme_init_queue(nvmeq, qid);
@@ -1474,9 +1474,10 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
adapter_delete_sq(dev, qid);
release_cq:
adapter_delete_cq(dev, qid);
+ free_queue:
+ nvme_free_queues(dev, dev->online_queues);
return result;
}
-
static const struct blk_mq_ops nvme_mq_admin_ops = {
.queue_rq = nvme_queue_rq,
.complete = nvme_pci_complete_rq,
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH] nvme: free pre-allocated queue if create ioq goes wrong
2018-01-14 7:15 [PATCH] nvme: free pre-allocated queue if create ioq goes wrong Minwoo Im
@ 2018-01-14 9:18 ` Sagi Grimberg
2018-01-14 9:41 ` Minwoo Im
0 siblings, 1 reply; 4+ messages in thread
From: Sagi Grimberg @ 2018-01-14 9:18 UTC (permalink / raw)
Minwoo,
> If either create-sq or create-cq is failed with an NVMe status,
> nvme_init_queue() is invoked which was not expected to be called in
> nvme_create_queue().
> To prevent this inconsistency of queue_count, free queue(s) already
> allocated in nvme_create_io_queues() when it goes wrong in
> nvme_create_queue().
The fix looks good, but I think it would be better to cleanup the queue
in the call site where nvme_alloc_queue is called, having it here is a
bit awkward IMO.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] nvme: free pre-allocated queue if create ioq goes wrong
2018-01-14 9:18 ` Sagi Grimberg
@ 2018-01-14 9:41 ` Minwoo Im
2018-01-14 16:24 ` Sagi Grimberg
0 siblings, 1 reply; 4+ messages in thread
From: Minwoo Im @ 2018-01-14 9:41 UTC (permalink / raw)
Sagi,
On Sun, Jan 14, 2018@6:18 PM, Sagi Grimberg <sagi@grimberg.me> wrote:
> Minwoo,
>
>> If either create-sq or create-cq is failed with an NVMe status,
>> nvme_init_queue() is invoked which was not expected to be called in
>> nvme_create_queue().
>> To prevent this inconsistency of queue_count, free queue(s) already
>> allocated in nvme_create_io_queues() when it goes wrong in
>> nvme_create_queue().
>
>
> The fix looks good, but I think it would be better to cleanup the queue
> in the call site where nvme_alloc_queue is called, having it here is a
> bit awkward IMO.
Thanks for your kind review.
I agree with that allocation and freeing should be in the same place
because it looks much more consistent in code.
What about below code?
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index d53550e..ecef45a 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1456,11 +1456,11 @@ static int nvme_create_queue(struct nvme_queue
*nvmeq, int qid)
nvmeq->cq_vector = qid - 1;
result = adapter_alloc_cq(dev, qid, nvmeq);
- if (result < 0)
+ if (result)
return result;
result = adapter_alloc_sq(dev, qid, nvmeq);
- if (result < 0)
+ if (result)
goto release_cq;
nvme_init_queue(nvmeq, qid);
@@ -1476,7 +1476,6 @@ static int nvme_create_queue(struct nvme_queue
*nvmeq, int qid)
adapter_delete_cq(dev, qid);
return result;
}
-
static const struct blk_mq_ops nvme_mq_admin_ops = {
.queue_rq = nvme_queue_rq,
.complete = nvme_pci_complete_rq,
@@ -1637,8 +1636,10 @@ static int nvme_create_io_queues(struct nvme_dev *dev)
max = min(dev->max_qid, dev->ctrl.queue_count - 1);
for (i = dev->online_queues; i <= max; i++) {
ret = nvme_create_queue(dev->queues[i], i);
- if (ret)
+ if (ret) {
+ nvme_free_queues(dev, dev->online_queues);
break;
+ }
}
/*
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH] nvme: free pre-allocated queue if create ioq goes wrong
2018-01-14 9:41 ` Minwoo Im
@ 2018-01-14 16:24 ` Sagi Grimberg
0 siblings, 0 replies; 4+ messages in thread
From: Sagi Grimberg @ 2018-01-14 16:24 UTC (permalink / raw)
On 01/14/2018 11:41 AM, Minwoo Im wrote:
> Sagi,
>
> On Sun, Jan 14, 2018@6:18 PM, Sagi Grimberg <sagi@grimberg.me> wrote:
>> Minwoo,
>>
>>> If either create-sq or create-cq is failed with an NVMe status,
>>> nvme_init_queue() is invoked which was not expected to be called in
>>> nvme_create_queue().
>>> To prevent this inconsistency of queue_count, free queue(s) already
>>> allocated in nvme_create_io_queues() when it goes wrong in
>>> nvme_create_queue().
>>
>>
>> The fix looks good, but I think it would be better to cleanup the queue
>> in the call site where nvme_alloc_queue is called, having it here is a
>> bit awkward IMO.
>
> Thanks for your kind review.
>
> I agree with that allocation and freeing should be in the same place
> because it looks much more consistent in code.
>
> What about below code?
Looks better, please send a proper patch, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-01-14 16:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-14 7:15 [PATCH] nvme: free pre-allocated queue if create ioq goes wrong Minwoo Im
2018-01-14 9:18 ` Sagi Grimberg
2018-01-14 9:41 ` Minwoo Im
2018-01-14 16:24 ` Sagi Grimberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox