qemu-block
[Top][All Lists]
Advanced

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

[PATCH] hw/block/nvme: error if drive less than a zone size


From: Minwoo Im
Subject: [PATCH] hw/block/nvme: error if drive less than a zone size
Date: Fri, 15 Jan 2021 21:19:20 +0900

If a user gives backing device file less than a single zone size, the
namespace capacity will be reported to 0 and the kerenl will fail to
allocate namespace silently.

This patch errors in case that num_zones are 0 which is backing device
is less than a single zone size.

Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
---
 hw/block/nvme-ns.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c
index 274eaf61b721..98690d030379 100644
--- a/hw/block/nvme-ns.c
+++ b/hw/block/nvme-ns.c
@@ -137,6 +137,13 @@ static int nvme_ns_zoned_check_calc_geometry(NvmeNamespace 
*ns, Error **errp)
     ns->num_zones = ns->size / lbasz / ns->zone_size;
 
     /* Do a few more sanity checks of ZNS properties */
+    if (!ns->num_zones) {
+        error_setg(errp,
+                   "num_zone is 0, drive must be larger than a zone %luB",
+                   zone_size);
+        return -1;
+    }
+
     if (ns->params.max_open_zones > ns->num_zones) {
         error_setg(errp,
                    "max_open_zones value %u exceeds the number of zones %u",
-- 
2.17.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]