Skip to contentSkip to conversation

hw/nvme: support online resize

PATCH Applied Alexander Mikhalitsyn 2 participants 7 messages Aug 3 – Sep 7

lore
Share & tools
lore
#0 lore raw

v3 cover hw/nvme: support online resize

From: Alexander Mikhalitsyn <[email protected]>

Dear friends,

This patchset is aimed to support online resize for NVMe emulated device. My approach is simple - I just implement (BlockDevOps *)->resize_cb() callback and ensure that AER notification is fired to all controllers using a namespace that is being resized.

Testing.

I manually validated this with Debian 13 VM (a resized disk was a root disk) and Windows Server 2022 (a resized disk was a secondary one).

Git tree:
https://gitlab.com/mihalicyn/qemu/-/commits/nvme-resize

Changelog for version 3:
- rebased

Changelog for version 2:
- checkpatch fixes
- rebased
- CI is green (https://gitlab.com/mihalicyn/qemu/-/pipelines/2602102750)

Kind regards,
Alex

Alexander Mikhalitsyn (2):
hw/nvme: initialize ns->subsys for n->namespace
hw/nvme: support online resize

 hw/nvme/ctrl.c | 10 ++++++++
 hw/nvme/ns.c   | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/nvme/nvme.h |  2 ++
 3 files changed, 79 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH v3 1/2 hw/nvme: initialize ns->subsys for n->namespace

From: Alexander Mikhalitsyn <[email protected]>

We must properly initialize n->namespace.subsys too.

Will be important in the following patches.

---
 hw/nvme/ctrl.c | 1 +
 1 file changed, 1 insertion(+)
hw/nvme/ctrl.c +1 -0
index bd6ad64b200..710c3e0d77d 100644
@@ -9648,6 +9648,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
         ns = &n->namespace;
         ns->params.nsid = 1;
         ns->ctrl = n;
+        ns->subsys = n->subsys;
 
         if (nvme_ns_setup(ns, errp)) {
             return;
Signature · 1 line
2.47.3
#2 lore raw

PATCH v3 2/2 hw/nvme: support online resize

In reply to Alexander Mikhalitsyn

From: Alexander Mikhalitsyn <[email protected]>

Implement (BlockDevOps *)->resize_cb() for NVMe namespace to enable online resize support.

We must handle cases when multiple namespaces are attached to a single controller, or namespace is shared across a few different controllers by iterating over controllers attached to a NvmeSubsystem and properly notify every controller about a size change.

---
v3:
- rebased
v2:
- check-patch fixes

---
 hw/nvme/ctrl.c |  9 +++++++
 hw/nvme/ns.c   | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/nvme/nvme.h |  2 ++
 3 files changed, 78 insertions(+), 1 deletion(-)
hw/nvme/ctrl.c +9 -0
index 710c3e0d77d..d60b3e105a1 100644
@@ -7009,6 +7009,15 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
     return NVME_SUCCESS;
 }
 
+void nvme_ctrl_notify_ns_resize(NvmeCtrl *ctrl, NvmeNamespace *ns)
+{
+    if (!test_and_set_bit(ns->params.nsid, ctrl->changed_nsids)) {
+        nvme_enqueue_event(ctrl, NVME_AER_TYPE_NOTICE,
+                           NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED,
+                           NVME_LOG_CHANGED_NSLIST);
+    }
+}
+
 typedef struct NvmeFormatAIOCB {
     BlockAIOCB common;
     BlockAIOCB *aiocb;
hw/nvme/ns.c +67 -1

83 lines not on this page · raw message

hw/nvme/nvme.h +2 -0
index 43e3c916f73..a4b2c01a2cc 100644
@@ -764,6 +764,8 @@ void nvme_atomic_configure_max_write_size(bool dn, uint16_t awun,
 void nvme_ns_atomic_configure_boundary(bool dn, uint16_t nabsn,
                                        uint16_t nabspf, NvmeAtomic *atomic);
 
+void nvme_ctrl_notify_ns_resize(NvmeCtrl *ctrl, NvmeNamespace *ns);
+
 extern const VMStateDescription nvme_vmstate_atomic;
 extern const VMStateDescription nvme_vmstate_ns;
 
Signature · 1 line
2.47.3
Reviewed-by on the v3 series
#3 lore raw
In reply to Alexander Mikhalitsyn
Quoted 28 lines · Alexander Mikhalitsyn

From: Alexander Mikhalitsyn <[email protected]>

Dear friends,

This patchset is aimed to support online resize for NVMe emulated device. My approach is simple - I just implement (BlockDevOps *)->resize_cb() callback and ensure that AER notification is fired to all controllers using a namespace that is being resized.

Testing.

I manually validated this with Debian 13 VM (a resized disk was a root disk) and Windows Server 2022 (a resized disk was a secondary one).

Git tree:
https://gitlab.com/mihalicyn/qemu/-/commits/nvme-resize

Changelog for version 3:
- rebased

Changelog for version 2:
- checkpatch fixes
- rebased
- CI is green (https://gitlab.com/mihalicyn/qemu/-/pipelines/2602102750)

Kind regards,
Alex

Quoted 13 lines

Alexander Mikhalitsyn (2):
hw/nvme: initialize ns->subsys for n->namespace
hw/nvme: support online resize

 hw/nvme/ctrl.c | 10 ++++++++
 hw/nvme/ns.c   | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/nvme/nvme.h |  2 ++
 3 files changed, 79 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.3

LGTM.

#4 lore raw

Am Mo., 3. Aug. 2026 um 15:42 Uhr schrieb Klaus Jensen <[email protected]>:

Quoted 39 lines · Alexander Mikhalitsyn
Quoted 37 lines

From: Alexander Mikhalitsyn <[email protected]>

Dear friends,

This patchset is aimed to support online resize for NVMe emulated device. My approach is simple - I just implement (BlockDevOps *)->resize_cb() callback and ensure that AER notification is fired to all controllers using a namespace that is being resized.

Testing.

I manually validated this with Debian 13 VM (a resized disk was a root disk) and Windows Server 2022 (a resized disk was a secondary one).

Git tree:
https://gitlab.com/mihalicyn/qemu/-/commits/nvme-resize

Changelog for version 3:
- rebased

Changelog for version 2:
- checkpatch fixes
- rebased
- CI is green (https://gitlab.com/mihalicyn/qemu/-/pipelines/2602102750)

Kind regards,
Alex

Alexander Mikhalitsyn (2):
hw/nvme: initialize ns->subsys for n->namespace
hw/nvme: support online resize

 hw/nvme/ctrl.c | 10 ++++++++
 hw/nvme/ns.c   | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/nvme/nvme.h |  2 ++
 3 files changed, 79 insertions(+), 1 deletion(-)
Quoted 4 lines
Quoted 4 lines

--
2.47.3

Hi Klaus,

Quoted 4 lines

LGTM.

Thank you, I wonder if you have a plan to take this into nvme.next soon?

Kind regards,
Alex

Applied
#5 lore raw
Quoted 48 lines · Alexander Mikhalitsyn

Am Mo., 3. Aug. 2026 um 15:42 Uhr schrieb Klaus Jensen <[email protected]>:

Quoted 39 lines · Alexander Mikhalitsyn
Quoted 37 lines

From: Alexander Mikhalitsyn <[email protected]>

Dear friends,

This patchset is aimed to support online resize for NVMe emulated device. My approach is simple - I just implement (BlockDevOps *)->resize_cb() callback and ensure that AER notification is fired to all controllers using a namespace that is being resized.

Testing.

I manually validated this with Debian 13 VM (a resized disk was a root disk) and Windows Server 2022 (a resized disk was a secondary one).

Git tree:
https://gitlab.com/mihalicyn/qemu/-/commits/nvme-resize

Changelog for version 3:
- rebased

Changelog for version 2:
- checkpatch fixes
- rebased
- CI is green (https://gitlab.com/mihalicyn/qemu/-/pipelines/2602102750)

Kind regards,
Alex

Alexander Mikhalitsyn (2):
hw/nvme: initialize ns->subsys for n->namespace
hw/nvme: support online resize

 hw/nvme/ctrl.c | 10 ++++++++
 hw/nvme/ns.c   | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/nvme/nvme.h |  2 ++
 3 files changed, 79 insertions(+), 1 deletion(-)
Quoted 4 lines
Quoted 4 lines

--
2.47.3

Hi Klaus,

Quoted 1 line
Quoted 9 lines
Quoted 3 lines

LGTM.

Thank you, I wonder if you have a plan to take this into nvme.next soon?

Kind regards,
Alex

Hi Alex,

Applied to nvme.next. Thanks!

I dropped the assert on ctrls (always true).

Thanks,
Klaus

#6 lore raw

Am Mo., 7. Sept. 2026 um 09:39 Uhr schrieb Klaus Jensen <[email protected]>:

Quoted 54 lines · Alexander Mikhalitsyn
Quoted 52 lines

Am Mo., 3. Aug. 2026 um 15:42 Uhr schrieb Klaus Jensen <[email protected]>:

Quoted 39 lines · Alexander Mikhalitsyn
Quoted 37 lines

From: Alexander Mikhalitsyn <[email protected]>

Dear friends,

This patchset is aimed to support online resize for NVMe emulated device. My approach is simple - I just implement (BlockDevOps *)->resize_cb() callback and ensure that AER notification is fired to all controllers using a namespace that is being resized.

Testing.

I manually validated this with Debian 13 VM (a resized disk was a root disk) and Windows Server 2022 (a resized disk was a secondary one).

Git tree:
https://gitlab.com/mihalicyn/qemu/-/commits/nvme-resize

Changelog for version 3:
- rebased

Changelog for version 2:
- checkpatch fixes
- rebased
- CI is green (https://gitlab.com/mihalicyn/qemu/-/pipelines/2602102750)

Kind regards,
Alex

Alexander Mikhalitsyn (2):
hw/nvme: initialize ns->subsys for n->namespace
hw/nvme: support online resize

 hw/nvme/ctrl.c | 10 ++++++++
 hw/nvme/ns.c   | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/nvme/nvme.h |  2 ++
 3 files changed, 79 insertions(+), 1 deletion(-)
Quoted 4 lines
Quoted 4 lines

--
2.47.3

Hi Klaus,

Quoted 4 lines

LGTM.

Quoted 7 lines
Quoted 5 lines

Thank you, I wonder if you have a plan to take this into nvme.next soon?

Kind regards,
Alex

Hi Alex,

Hi Klaus,

Quoted 4 lines

Applied to nvme.next. Thanks!

I dropped the assert on ctrls (always true).

Thank you ;-)

Kind regards,
Alex

Quoted 4 lines

Thanks,
Klaus