* [PATCH v3 0/2] hw/nvme: support online resize
@ 2026-08-03 8:30 Alexander Mikhalitsyn
2026-08-03 8:30 ` [PATCH v3 1/2] hw/nvme: initialize ns->subsys for n->namespace Alexander Mikhalitsyn
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Alexander Mikhalitsyn @ 2026-08-03 8:30 UTC (permalink / raw)
To: qemu-devel
Cc: Stéphane Graber, Alexander Mikhalitsyn, Keith Busch,
Klaus Jensen, qemu-block, Jesper Devantier, Alexander Mikhalitsyn
From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
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(-)
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v3 1/2] hw/nvme: initialize ns->subsys for n->namespace 2026-08-03 8:30 [PATCH v3 0/2] hw/nvme: support online resize Alexander Mikhalitsyn @ 2026-08-03 8:30 ` Alexander Mikhalitsyn 2026-08-03 8:30 ` [PATCH v3 2/2] hw/nvme: support online resize Alexander Mikhalitsyn 2026-08-03 13:42 ` [PATCH v3 0/2] " Klaus Jensen 2 siblings, 0 replies; 7+ messages in thread From: Alexander Mikhalitsyn @ 2026-08-03 8:30 UTC (permalink / raw) To: qemu-devel Cc: Stéphane Graber, Alexander Mikhalitsyn, Keith Busch, Klaus Jensen, qemu-block, Jesper Devantier, Alexander Mikhalitsyn From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io> We must properly initialize n->namespace.subsys too. Will be important in the following patches. Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io> --- hw/nvme/ctrl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index bd6ad64b200..710c3e0d77d 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -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; -- 2.47.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/2] hw/nvme: support online resize 2026-08-03 8:30 [PATCH v3 0/2] hw/nvme: support online resize Alexander Mikhalitsyn 2026-08-03 8:30 ` [PATCH v3 1/2] hw/nvme: initialize ns->subsys for n->namespace Alexander Mikhalitsyn @ 2026-08-03 8:30 ` Alexander Mikhalitsyn 2026-08-03 13:42 ` [PATCH v3 0/2] " Klaus Jensen 2 siblings, 0 replies; 7+ messages in thread From: Alexander Mikhalitsyn @ 2026-08-03 8:30 UTC (permalink / raw) To: qemu-devel Cc: Stéphane Graber, Alexander Mikhalitsyn, Keith Busch, Klaus Jensen, qemu-block, Jesper Devantier, Alexander Mikhalitsyn From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io> 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. Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io> --- 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(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 710c3e0d77d..d60b3e105a1 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -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; diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c index 7f0f9ac7662..e2954fd91b3 100644 --- a/hw/nvme/ns.c +++ b/hw/nvme/ns.c @@ -163,6 +163,70 @@ lbaf_found: return 0; } +static void nvme_ns_resize_cb(void *opaque) +{ + NvmeNamespace *ns = opaque; + int64_t size; + int cntlid, notified_ctrls; + + size = blk_getlength(ns->blkconf.blk); + if (size < 0) { + error_report("can't get size of block device %s: %s", + blk_name(ns->blkconf.blk), strerror(-size)); + return; + } + + ns->size = size; + nvme_ns_init_format(ns); + + if (!ns->attached) { + return; + } + + /* + * Okay, the namespace is attached so we need to notify all controllers + * about size change. + * + * Let's just take ns->subsys, iterate over all controllers and find + * to which of them our namespace is attached. + */ + + assert(ns->subsys); + assert(ns->subsys->ctrls); + + notified_ctrls = 0; + for (cntlid = 0; cntlid < ARRAY_SIZE(ns->subsys->ctrls); cntlid++) { + NvmeCtrl *ctrl; + + /* notified everyone? */ + if (notified_ctrls == ns->attached) { + break; + } + + ctrl = nvme_subsys_ctrl(ns->subsys, cntlid); + if (!ctrl) { + continue; + } + + for (uint32_t nsid = 1; nsid <= NVME_MAX_NAMESPACES; nsid++) { + NvmeNamespace *ns_iter = ctrl->namespaces[nsid]; + + if (!ns_iter || ns_iter != ns) { + continue; + } + + nvme_ctrl_notify_ns_resize(ctrl, ns); + + notified_ctrls++; + break; + } + } +} + +static const BlockDevOps nvme_ns_block_ops = { + .resize_cb = nvme_ns_resize_cb, +}; + static int nvme_ns_init_blk(NvmeNamespace *ns, Error **errp) { bool read_only; @@ -172,10 +236,12 @@ static int nvme_ns_init_blk(NvmeNamespace *ns, Error **errp) } read_only = !blk_supports_write_perm(ns->blkconf.blk); - if (!blkconf_apply_backend_options(&ns->blkconf, read_only, false, errp)) { + if (!blkconf_apply_backend_options(&ns->blkconf, read_only, true, errp)) { return -1; } + blk_set_dev_ops(ns->blkconf.blk, &nvme_ns_block_ops, ns); + if (ns->blkconf.discard_granularity == -1) { ns->blkconf.discard_granularity = MAX(ns->blkconf.logical_block_size, MIN_DISCARD_GRANULARITY); diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index 43e3c916f73..a4b2c01a2cc 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -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; -- 2.47.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 0/2] hw/nvme: support online resize 2026-08-03 8:30 [PATCH v3 0/2] hw/nvme: support online resize Alexander Mikhalitsyn 2026-08-03 8:30 ` [PATCH v3 1/2] hw/nvme: initialize ns->subsys for n->namespace Alexander Mikhalitsyn 2026-08-03 8:30 ` [PATCH v3 2/2] hw/nvme: support online resize Alexander Mikhalitsyn @ 2026-08-03 13:42 ` Klaus Jensen 2026-08-31 7:04 ` Alexander Mikhalitsyn 2 siblings, 1 reply; 7+ messages in thread From: Klaus Jensen @ 2026-08-03 13:42 UTC (permalink / raw) To: Alexander Mikhalitsyn Cc: qemu-devel, Stéphane Graber, Keith Busch, qemu-block, Jesper Devantier, Alexander Mikhalitsyn [-- Attachment #1: Type: text/plain, Size: 1272 bytes --] On Aug 3 10:30, Alexander Mikhalitsyn wrote: > From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io> > > 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(-) > > -- > 2.47.3 > > LGTM. Reviewed-by: Klaus Jensen <k.jensen@samsung.com> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 0/2] hw/nvme: support online resize 2026-08-03 13:42 ` [PATCH v3 0/2] " Klaus Jensen @ 2026-08-31 7:04 ` Alexander Mikhalitsyn 2026-09-07 7:39 ` Klaus Jensen 0 siblings, 1 reply; 7+ messages in thread From: Alexander Mikhalitsyn @ 2026-08-31 7:04 UTC (permalink / raw) To: Klaus Jensen Cc: qemu-devel, Stéphane Graber, Keith Busch, qemu-block, Jesper Devantier, Alexander Mikhalitsyn Am Mo., 3. Aug. 2026 um 15:42 Uhr schrieb Klaus Jensen <its@irrelevant.dk>: > > On Aug 3 10:30, Alexander Mikhalitsyn wrote: > > From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io> > > > > 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(-) > > > > -- > > 2.47.3 > > > > Hi Klaus, > > LGTM. > > Reviewed-by: Klaus Jensen <k.jensen@samsung.com> Thank you, I wonder if you have a plan to take this into nvme.next soon? Kind regards, Alex ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 0/2] hw/nvme: support online resize 2026-08-31 7:04 ` Alexander Mikhalitsyn @ 2026-09-07 7:39 ` Klaus Jensen 2026-09-07 8:24 ` Alexander Mikhalitsyn 0 siblings, 1 reply; 7+ messages in thread From: Klaus Jensen @ 2026-09-07 7:39 UTC (permalink / raw) To: Alexander Mikhalitsyn Cc: qemu-devel, Stéphane Graber, Keith Busch, qemu-block, Jesper Devantier, Alexander Mikhalitsyn [-- Attachment #1: Type: text/plain, Size: 1818 bytes --] On Aug 31 09:04, Alexander Mikhalitsyn wrote: > Am Mo., 3. Aug. 2026 um 15:42 Uhr schrieb Klaus Jensen <its@irrelevant.dk>: > > > > On Aug 3 10:30, Alexander Mikhalitsyn wrote: > > > From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io> > > > > > > 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(-) > > > > > > -- > > > 2.47.3 > > > > > > > > Hi Klaus, > > > > > LGTM. > > > > Reviewed-by: Klaus Jensen <k.jensen@samsung.com> > > 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 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 0/2] hw/nvme: support online resize 2026-09-07 7:39 ` Klaus Jensen @ 2026-09-07 8:24 ` Alexander Mikhalitsyn 0 siblings, 0 replies; 7+ messages in thread From: Alexander Mikhalitsyn @ 2026-09-07 8:24 UTC (permalink / raw) To: Klaus Jensen Cc: qemu-devel, Stéphane Graber, Keith Busch, qemu-block, Jesper Devantier, Alexander Mikhalitsyn Am Mo., 7. Sept. 2026 um 09:39 Uhr schrieb Klaus Jensen <its@irrelevant.dk>: > > On Aug 31 09:04, Alexander Mikhalitsyn wrote: > > Am Mo., 3. Aug. 2026 um 15:42 Uhr schrieb Klaus Jensen <its@irrelevant.dk>: > > > > > > On Aug 3 10:30, Alexander Mikhalitsyn wrote: > > > > From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io> > > > > > > > > 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(-) > > > > > > > > -- > > > > 2.47.3 > > > > > > > > > > > > Hi Klaus, > > > > > > > > LGTM. > > > > > > Reviewed-by: Klaus Jensen <k.jensen@samsung.com> > > > > Thank you, I wonder if you have a plan to take this into nvme.next soon? > > > > Kind regards, > > Alex > > > > Hi Alex, Hi Klaus, > > Applied to nvme.next. Thanks! > > I dropped the assert on ctrls (always true). Thank you ;-) Kind regards, Alex > > > Thanks, > Klaus ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-09-07 8:25 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-08-03 8:30 [PATCH v3 0/2] hw/nvme: support online resize Alexander Mikhalitsyn 2026-08-03 8:30 ` [PATCH v3 1/2] hw/nvme: initialize ns->subsys for n->namespace Alexander Mikhalitsyn 2026-08-03 8:30 ` [PATCH v3 2/2] hw/nvme: support online resize Alexander Mikhalitsyn 2026-08-03 13:42 ` [PATCH v3 0/2] " Klaus Jensen 2026-08-31 7:04 ` Alexander Mikhalitsyn 2026-09-07 7:39 ` Klaus Jensen 2026-09-07 8:24 ` Alexander Mikhalitsyn
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.