diff mbox series

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

Message ID 20210115121920.10386-1-minwoo.im.dev@gmail.com
State New
Headers show
Series hw/block/nvme: error if drive less than a zone size | expand

Commit Message

Minwoo Im Jan. 15, 2021, 12:19 p.m. UTC
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 mbox series

Patch

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",