get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.1/patches/2221989/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2221989,
    "url": "http://patchwork.ozlabs.org/api/1.1/patches/2221989/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260410143000.86708-1-matthieu@min.io/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/1.1/projects/14/?format=api",
        "name": "QEMU Development",
        "link_name": "qemu-devel",
        "list_id": "qemu-devel.nongnu.org",
        "list_email": "qemu-devel@nongnu.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20260410143000.86708-1-matthieu@min.io>",
    "date": "2026-04-10T14:30:00",
    "name": "[v3] hw/nvme: add namespace hotplug support",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "2ef8e0bd9b105cd56663a7eeed5f577895a79cb7",
    "submitter": {
        "id": 93098,
        "url": "http://patchwork.ozlabs.org/api/1.1/people/93098/?format=api",
        "name": "Matthieu Rolla",
        "email": "matthieu@minio.io"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260410143000.86708-1-matthieu@min.io/mbox/",
    "series": [
        {
            "id": 499475,
            "url": "http://patchwork.ozlabs.org/api/1.1/series/499475/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=499475",
            "date": "2026-04-10T14:30:00",
            "name": "[v3] hw/nvme: add namespace hotplug support",
            "version": 3,
            "mbox": "http://patchwork.ozlabs.org/series/499475/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2221989/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2221989/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=minio.io header.i=@minio.io header.a=rsa-sha256\n header.s=minio header.b=M+ZuNuub;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"
        ],
        "Received": [
            "from lists.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fsg5M1T56z20HT\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 11 Apr 2026 01:02:29 +1000 (AEST)",
            "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wBDMs-00041K-9q; Fri, 10 Apr 2026 11:01:58 -0400",
            "from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <matthieu@minio.io>) id 1wBCrt-0002Wi-FY\n for qemu-devel@nongnu.org; Fri, 10 Apr 2026 10:29:57 -0400",
            "from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <matthieu@minio.io>) id 1wBCrr-0008Gq-F2\n for qemu-devel@nongnu.org; Fri, 10 Apr 2026 10:29:57 -0400",
            "by mail-wr1-x42c.google.com with SMTP id\n ffacd0b85a97d-43d02a71526so1301823f8f.3\n for <qemu-devel@nongnu.org>; Fri, 10 Apr 2026 07:29:54 -0700 (PDT)",
            "from localhost\n (2a01cb001411480071f5d8bdb591a8f9.ipv6.abo.wanadoo.fr.\n [2a01:cb00:1411:4800:71f5:d8bd:b591:a8f9])\n by smtp.gmail.com with UTF8SMTPSA id\n ffacd0b85a97d-43d63de2a74sm8382197f8f.3.2026.04.10.07.29.52\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Fri, 10 Apr 2026 07:29:52 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=minio.io; s=minio; t=1775831393; x=1776436193; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=ruMXow8DpCxyiShGLxBR3aEG16JIAkSYkotS72n+iGc=;\n b=M+ZuNuub6nBdX/KPhJz8dHy+xpMFZ9Iz2Iq4LjPTIUaAqdBYYEjVDf3SeqmKt+O2kk\n xTYabPIE2THct3wEKJ2BZZLCp6z6TaJuZHn0I5kgHinXCTdPLUir+nuxZLxzmCRGfzce\n 3l8LzgwKesve1lHiaBpNp9RzKMFqGgl+hPyI4k/fm9i+lzb6oxzsKXGynnAjPd/i+Sev\n 5fOcgJ9wVLylh7WBjtBTIiAcc3a3SMX0IVmiA0gWuWOkONunRT6piA8RcSClBY7mbv7v\n C6O4R3ejOr03P9fahBmy6H4vyQ4M7n+0qvc5N4PsXV9oytyoLRJ0+Q1tGzev4eJaPG13\n dKSQ==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775831393; x=1776436193;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=ruMXow8DpCxyiShGLxBR3aEG16JIAkSYkotS72n+iGc=;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Ts06y35AAwFeg2u7c5B5quIPS\n c+F5Yk0ShdsZzfBwHAwqxM7b9a50RxnHIpJTeH6NJ4IK7oLRmbizbQpyvYguIasqgRzQ4ldMjb2\n Wp+2PqB4O6S8dQUDoXipE7VEcPbFPV5EQok6wVJBW76IHM+MRP243/fSwk60MJF+DIRoeRJ",
        "X-Received": "by 2002:a05:6000:2082:b0:439:c799:dbfa with SMTP id\n ffacd0b85a97d-43d6423cff9mr5186798f8f.9.1775831392747;\n Fri, 10 Apr 2026 07:29:52 -0700 (PDT)",
        "From": "mr-083 <matthieu@minio.io>",
        "X-Google-Original-From": "mr-083 <matthieu@min.io>",
        "To": "qemu-devel@nongnu.org,\n\tqemu-block@nongnu.org",
        "Cc": "its@irrelevant.dk, kbusch@kernel.org, stefanha@redhat.com,\n mr-083 <matthieu@min.io>",
        "Subject": "[PATCH v3] hw/nvme: add namespace hotplug support",
        "Date": "Fri, 10 Apr 2026 16:30:00 +0200",
        "Message-ID": "<20260410143000.86708-1-matthieu@min.io>",
        "X-Mailer": "git-send-email 2.53.0",
        "In-Reply-To": "<20260409060155.94704-1-matthieu@min.io>",
        "References": "<20260409060155.94704-1-matthieu@min.io>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Received-SPF": "pass client-ip=2a00:1450:4864:20::42c;\n envelope-from=matthieu@minio.io; helo=mail-wr1-x42c.google.com",
        "X-Spam_score_int": "-10",
        "X-Spam_score": "-1.1",
        "X-Spam_bar": "-",
        "X-Spam_report": "(-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n HK_NAME_MR_MRS=0.998,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=no autolearn_force=no",
        "X-Spam_action": "no action",
        "X-Mailman-Approved-At": "Fri, 10 Apr 2026 11:01:56 -0400",
        "X-BeenThere": "qemu-devel@nongnu.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "qemu development <qemu-devel.nongnu.org>",
        "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>",
        "List-Post": "<mailto:qemu-devel@nongnu.org>",
        "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>",
        "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>",
        "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org",
        "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"
    },
    "content": "Add hotplug support for nvme-ns devices on the NvmeBus. This enables\nNVMe namespace-level hot-add and hot-remove via device_add and\ndevice_del with proper Asynchronous Event Notification (AEN), so the\nguest kernel can react to namespace topology changes.\n\nMark nvme-ns devices as hotpluggable and register the NvmeBus as a\nhotplug handler with proper plug and unplug callbacks:\n\n- plug: attach namespace to all started controllers and send an\n  Asynchronous Event Notification (AEN) with NS_ATTR_CHANGED so\n  the guest kernel rescans namespaces and adds the block device\n- unplug: drain in-flight I/O, detach from all controllers, send\n  AEN, then unrealize the device. The guest kernel rescans and\n  removes the block device.\n\nThe plug handler skips controllers that haven't started yet\n(qs_created == false) to avoid interfering with boot-time namespace\nattachment in nvme_start_ctrl().\n\nThe unplug handler drains in-flight I/O via nvme_ns_drain() before\ndetaching the namespace from controllers, so pending requests can\ncomplete normally without touching freed state.\n\nFor symmetry with nvme_ns_realize() which sets subsys->namespaces[nsid],\nnvme_ns_unrealize() now clears that slot too — making the namespace\nlifecycle complete.\n\nBoth the controller bus and subsystem bus are configured as hotplug\nhandlers via qbus_set_bus_hotplug_handler() since nvme-ns devices\nmay reparent to the subsystem bus during realize.\n\nExample hot-swap sequence using the NVMe subsystem model:\n\n  # Boot with: -device nvme-subsys,id=subsys0\n  #            -device nvme,id=ctrl0,subsys=subsys0\n  #            -device nvme-ns,id=ns0,drive=drv0,bus=ctrl0,nsid=1\n\n  device_del ns0             # guest receives AEN, removes /dev/nvme0n1\n  drive_del drv0\n  drive_add 0 file=disk.qcow2,format=qcow2,id=drv0,if=none\n  device_add nvme-ns,id=ns0,drive=drv0,bus=ctrl0,nsid=1\n                              # guest receives AEN, adds /dev/nvme0n1\n\nTested with Linux 6.1 guest (NVMe driver processes AEN and rescans\nnamespace list automatically).\n\nSigned-off-by: Matthieu <matthieu@min.io>\n---\n hw/nvme/ctrl.c   | 88 ++++++++++++++++++++++++++++++++++++++++++++++++\n hw/nvme/ns.c     |  8 +++++\n hw/nvme/subsys.c |  2 ++\n 3 files changed, 98 insertions(+)",
    "diff": "diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c\nindex be6c7028cb..2024b0ff75 100644\n--- a/hw/nvme/ctrl.c\n+++ b/hw/nvme/ctrl.c\n@@ -206,6 +206,7 @@\n #include \"system/hostmem.h\"\n #include \"hw/pci/msix.h\"\n #include \"hw/pci/pcie_sriov.h\"\n+#include \"hw/core/qdev.h\"\n #include \"system/spdm-socket.h\"\n #include \"migration/vmstate.h\"\n \n@@ -9293,6 +9294,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)\n     }\n \n     qbus_init(&n->bus, sizeof(NvmeBus), TYPE_NVME_BUS, dev, dev->id);\n+    qbus_set_bus_hotplug_handler(BUS(&n->bus));\n \n     if (nvme_init_subsys(n, errp)) {\n         return;\n@@ -9553,10 +9555,96 @@ static const TypeInfo nvme_info = {\n     },\n };\n \n+static void nvme_ns_hot_plug(HotplugHandler *hotplug_dev, DeviceState *dev,\n+                              Error **errp)\n+{\n+    NvmeNamespace *ns = NVME_NS(dev);\n+    NvmeSubsystem *subsys = ns->subsys;\n+    uint32_t nsid = ns->params.nsid;\n+    int i;\n+\n+    /*\n+     * Attach to all started controllers and notify via AEN.\n+     * Skip controllers that haven't started yet (boot-time realize) —\n+     * nvme_start_ctrl() will attach namespaces during controller init.\n+     */\n+    for (i = 0; i < NVME_MAX_CONTROLLERS; i++) {\n+        NvmeCtrl *ctrl = nvme_subsys_ctrl(subsys, i);\n+        if (!ctrl || !ctrl->qs_created) {\n+            continue;\n+        }\n+\n+        if (nvme_csi_supported(ctrl, ns->csi) && !ns->params.detached) {\n+            nvme_attach_ns(ctrl, ns);\n+            nvme_update_dsm_limits(ctrl, ns);\n+\n+            if (!test_and_set_bit(nsid, ctrl->changed_nsids)) {\n+                nvme_enqueue_event(ctrl, NVME_AER_TYPE_NOTICE,\n+                                   NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED,\n+                                   NVME_LOG_CHANGED_NSLIST);\n+            }\n+        }\n+    }\n+}\n+\n+static void nvme_ns_hot_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,\n+                               Error **errp)\n+{\n+    NvmeNamespace *ns = NVME_NS(dev);\n+    NvmeSubsystem *subsys = ns->subsys;\n+    uint32_t nsid = ns->params.nsid;\n+    int i;\n+\n+    /*\n+     * Drain in-flight I/O before tearing down the namespace.\n+     * This must happen while the namespace is still attached to the\n+     * controllers so any pending requests can complete normally.\n+     */\n+    nvme_ns_drain(ns);\n+\n+    /*\n+     * Detach from all controllers and notify the guest via AEN.\n+     * The guest kernel will rescan namespaces and remove the block device.\n+     */\n+    for (i = 0; i < NVME_MAX_CONTROLLERS; i++) {\n+        NvmeCtrl *ctrl = nvme_subsys_ctrl(subsys, i);\n+        if (!ctrl || !nvme_ns(ctrl, nsid)) {\n+            continue;\n+        }\n+\n+        nvme_detach_ns(ctrl, ns);\n+        nvme_update_dsm_limits(ctrl, NULL);\n+\n+        if (!test_and_set_bit(nsid, ctrl->changed_nsids)) {\n+            nvme_enqueue_event(ctrl, NVME_AER_TYPE_NOTICE,\n+                               NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED,\n+                               NVME_LOG_CHANGED_NSLIST);\n+        }\n+    }\n+\n+    /*\n+     * Unrealize: removes from subsystem (in nvme_ns_unrealize), flushes,\n+     * cleans up structures, and removes from QOM.\n+     */\n+    qdev_unrealize(dev);\n+}\n+\n+static void nvme_bus_class_init(ObjectClass *klass, const void *data)\n+{\n+    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);\n+    hc->plug = nvme_ns_hot_plug;\n+    hc->unplug = nvme_ns_hot_unplug;\n+}\n+\n static const TypeInfo nvme_bus_info = {\n     .name = TYPE_NVME_BUS,\n     .parent = TYPE_BUS,\n     .instance_size = sizeof(NvmeBus),\n+    .class_init = nvme_bus_class_init,\n+    .interfaces = (const InterfaceInfo[]) {\n+        { TYPE_HOTPLUG_HANDLER },\n+        { }\n+    },\n };\n \n static void nvme_register_types(void)\ndiff --git a/hw/nvme/ns.c b/hw/nvme/ns.c\nindex b0106eaa5c..f4f755c6fc 100644\n--- a/hw/nvme/ns.c\n+++ b/hw/nvme/ns.c\n@@ -719,10 +719,17 @@ void nvme_ns_cleanup(NvmeNamespace *ns)\n static void nvme_ns_unrealize(DeviceState *dev)\n {\n     NvmeNamespace *ns = NVME_NS(dev);\n+    NvmeSubsystem *subsys = ns->subsys;\n+    uint32_t nsid = ns->params.nsid;\n \n     nvme_ns_drain(ns);\n     nvme_ns_shutdown(ns);\n     nvme_ns_cleanup(ns);\n+\n+    /* Symmetric with nvme_ns_realize() which sets subsys->namespaces[nsid]. */\n+    if (subsys && nsid && subsys->namespaces[nsid] == ns) {\n+        subsys->namespaces[nsid] = NULL;\n+    }\n }\n \n void nvme_ns_atomic_configure_boundary(bool dn, uint16_t nabsn,\n@@ -937,6 +944,7 @@ static void nvme_ns_class_init(ObjectClass *oc, const void *data)\n     dc->bus_type = TYPE_NVME_BUS;\n     dc->realize = nvme_ns_realize;\n     dc->unrealize = nvme_ns_unrealize;\n+    dc->hotpluggable = true;\n     device_class_set_props(dc, nvme_ns_props);\n     dc->desc = \"Virtual NVMe namespace\";\n }\ndiff --git a/hw/nvme/subsys.c b/hw/nvme/subsys.c\nindex 777e1c620f..fa35055d3c 100644\n--- a/hw/nvme/subsys.c\n+++ b/hw/nvme/subsys.c\n@@ -9,6 +9,7 @@\n #include \"qemu/osdep.h\"\n #include \"qemu/units.h\"\n #include \"qapi/error.h\"\n+#include \"hw/core/qdev.h\"\n \n #include \"nvme.h\"\n \n@@ -205,6 +206,7 @@ static void nvme_subsys_realize(DeviceState *dev, Error **errp)\n     NvmeSubsystem *subsys = NVME_SUBSYS(dev);\n \n     qbus_init(&subsys->bus, sizeof(NvmeBus), TYPE_NVME_BUS, dev, dev->id);\n+    qbus_set_bus_hotplug_handler(BUS(&subsys->bus));\n \n     nvme_subsys_setup(subsys, errp);\n }\n",
    "prefixes": [
        "v3"
    ]
}