get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 2197752,
    "url": "http://patchwork.ozlabs.org/api/patches/2197752/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260218132633.29748-23-hreitz@redhat.com/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/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": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20260218132633.29748-23-hreitz@redhat.com>",
    "list_archive_url": null,
    "date": "2026-02-18T13:26:31",
    "name": "[v4,22/24] fuse: Implement multi-threading",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "3967fa5d9cc2ed1ed3cf48701df5150e2696eb49",
    "submitter": {
        "id": 82279,
        "url": "http://patchwork.ozlabs.org/api/people/82279/?format=api",
        "name": "Hanna Czenczek",
        "email": "hreitz@redhat.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260218132633.29748-23-hreitz@redhat.com/mbox/",
    "series": [
        {
            "id": 492547,
            "url": "http://patchwork.ozlabs.org/api/series/492547/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=492547",
            "date": "2026-02-18T13:26:09",
            "name": "export/fuse: Use coroutines and multi-threading",
            "version": 4,
            "mbox": "http://patchwork.ozlabs.org/series/492547/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2197752/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2197752/checks/",
    "tags": {},
    "related": [],
    "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 (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=JUDLrBPM;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=google header.b=tlZhqthQ;\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 (lists.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 4fGHZ21K5kz1xvq\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 19 Feb 2026 00:35:06 +1100 (AEDT)",
            "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 1vshgK-0004to-Ne; Wed, 18 Feb 2026 08:33:38 -0500",
            "from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <hreitz@redhat.com>) id 1vshft-0004U2-Ai\n for qemu-devel@nongnu.org; Wed, 18 Feb 2026 08:33:06 -0500",
            "from us-smtp-delivery-124.mimecast.com ([170.10.129.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <hreitz@redhat.com>) id 1vshfp-0006Gl-PS\n for qemu-devel@nongnu.org; Wed, 18 Feb 2026 08:33:05 -0500",
            "from mail-wm1-f70.google.com (mail-wm1-f70.google.com\n [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-263-HN-KJNKLOa64_eZtGyg8fw-1; Wed, 18 Feb 2026 08:27:40 -0500",
            "by mail-wm1-f70.google.com with SMTP id\n 5b1f17b1804b1-4837bfcfe0dso30014165e9.1\n for <qemu-devel@nongnu.org>; Wed, 18 Feb 2026 05:27:40 -0800 (PST)",
            "from localhost\n (p200300cfd737d029edef7b8da7441ac2.dip0.t-ipconnect.de.\n [2003:cf:d737:d029:edef:7b8d:a744:1ac2])\n by smtp.gmail.com with ESMTPSA id\n 5b1f17b1804b1-483801ff9b3sm303123835e9.13.2026.02.18.05.27.37\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 18 Feb 2026 05:27:37 -0800 (PST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1771421581;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:\n content-type:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=IxNqYftpopQBXsxGyECaF4EaTK+LIZo8y+vscZHFzIE=;\n b=JUDLrBPMT6GLHgxiqGG6TC/lURdmPkfx/19Jk8AjHPQqayEXVhJ4JptI6dkqylZ7u9dTbf\n YNj9ZmD0zNg9PdkGHEMEyw2YE220VBkdx1EHoz7BbAq3D1fYrjrZDd/0Qt7ekAtTTO19Ov\n /HvOyrQeYITYF0zV5sFDsNxVkbSWY7Q=",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=redhat.com; s=google; t=1771421259; x=1772026059; 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=IxNqYftpopQBXsxGyECaF4EaTK+LIZo8y+vscZHFzIE=;\n b=tlZhqthQYBiijLh535hMEm9HsrD+UBxHZ5qTRhgEjQgIJO1f1i9tX62g9vv3okS/AK\n q4cwt9aBleXQvG42M6OJtfCKFvVHouKs50bCSvZ7VzWj/Y94zO0guhB0awXyWAUN0wGR\n acvVfYFbPrONUy2MEzRWpOp15zt5IvpauaS02+MGrf9M0RaP1Se3mwnL7PFO30svckBl\n gjJvdJgF/mTolPAMU/jirxNhxROf7m0DEHVErz5z6dkUf3LDE0BNvl0dDiKbTDO6IvGF\n PZPIm0xilI0399NBv5+m1qZnMkqIsW7SedngC09owlJQZrGcFhpKoe1zktrc4GLF46lf\n T/gg=="
        ],
        "X-MC-Unique": "HN-KJNKLOa64_eZtGyg8fw-1",
        "X-Mimecast-MFC-AGG-ID": "HN-KJNKLOa64_eZtGyg8fw_1771421260",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1771421259; x=1772026059;\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=IxNqYftpopQBXsxGyECaF4EaTK+LIZo8y+vscZHFzIE=;\n b=r37SnunEqXraDHm5s3ZDs8ztJdfLXeuxsXL7hJghbXQkyTiFugNVd/XHgoCbPNLQ/L\n nOnn0S0bF5ZHA1P0Z1zCv4tKy3V09WFKgf79G3zBmnjLsU0xt3eWnbg4Io618xk+dRvE\n 25bYvUNrV3CCmdRN6h7f8ltypyK7TpwP9KAN86Jj0rPd+pOEA32MpTWWGm76COcVhtY9\n FPfnbrIaPzRVzgAwSoz/dZRyGAGIJVzbB67quzuDfFQ+UKNaiB1Bgihd9CAn3BIL8fGy\n dyDHeBSckvb6wI6LCXzrnFbuTouAR+E3fZD0nFKKmd3scNJK6EMaELYORog1Y/d6YMtA\n Woeg==",
        "X-Gm-Message-State": "AOJu0Yyl7IdFHwxd5gGcgdL8F7ZCYCtkTMliOE85svXyC1q0sWhCUin/\n 7SF1YbFn0GIMPiDHYINeGiNGsLC5P4gXWKLunhqCkB4owvWMHF/ax+ea3VZamU9FiP4XyfleHUe\n xGXvPwU7nWHxALgvruOcf0vHVbZqiox1XDGrINevgjbUeslZ7bzxx+CPu",
        "X-Gm-Gg": "AZuq6aK3y3cXrGxWYblmWNB1R5/2fb22vd2dF4IMsKAX8/eAtAJKIS4E+YMO0YkRIxZ\n 8kvHKUUY7KX51gGrJhERWc8CZAsIW+R1MVQYC49ucmhulsbcO5no84WiTk3GL/lK0BhQDfW22KW\n pAh6aF7HD8W2q1TvcU5ezB9xI3UuLyOWS6ZqA1F0Tw9xnsC8z4SY8BLn9ZDLYeqjw2O2m6YkFL1\n Ui8Sia4QbYwYKToExXeknSxKMJRWMKYcpfn8//WyixSjaGJ5v1VCKUqtQvgPIWB8FemfeNbEcS+\n NDi0OVXITvsZAgGTBBDd3vhuWoOjaXdZmKvvJm/KA/iXJFyUZwpaoMAyKz9YJ3+JZvdT6c8braA\n sbHbEDIXIProl1sDxkAPqblQCqswLNdR4ILErQbEgqnldCPoR92B1OfNfHwDuNqGCYav2eSlid2\n 08BtdT",
        "X-Received": [
            "by 2002:a05:600c:820d:b0:47d:403e:4eaf with SMTP id\n 5b1f17b1804b1-48379b9f278mr267766085e9.10.1771421259331;\n Wed, 18 Feb 2026 05:27:39 -0800 (PST)",
            "by 2002:a05:600c:820d:b0:47d:403e:4eaf with SMTP id\n 5b1f17b1804b1-48379b9f278mr267765525e9.10.1771421258675;\n Wed, 18 Feb 2026 05:27:38 -0800 (PST)"
        ],
        "From": "Hanna Czenczek <hreitz@redhat.com>",
        "To": "qemu-block@nongnu.org",
        "Cc": "qemu-devel@nongnu.org, Hanna Czenczek <hreitz@redhat.com>,\n Kevin Wolf <kwolf@redhat.com>, Brian Song <hibriansong@gmail.com>",
        "Subject": "[PATCH v4 22/24] fuse: Implement multi-threading",
        "Date": "Wed, 18 Feb 2026 14:26:31 +0100",
        "Message-ID": "<20260218132633.29748-23-hreitz@redhat.com>",
        "X-Mailer": "git-send-email 2.53.0",
        "In-Reply-To": "<20260218132633.29748-1-hreitz@redhat.com>",
        "References": "<20260218132633.29748-1-hreitz@redhat.com>",
        "MIME-Version": "1.0",
        "Content-Type": [
            "text/plain; charset=UTF-8",
            "text/plain; charset=UTF-8"
        ],
        "Content-Transfer-Encoding": "8bit",
        "Received-SPF": "pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com;\n helo=us-smtp-delivery-124.mimecast.com",
        "X-Spam_score_int": "-20",
        "X-Spam_score": "-2.1",
        "X-Spam_bar": "--",
        "X-Spam_report": "(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.043,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_PASS=-0.001,\n SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no",
        "X-Spam_action": "no action",
        "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": "FUSE allows creating multiple request queues by \"cloning\" /dev/fuse FDs\n(via open(\"/dev/fuse\") + ioctl(FUSE_DEV_IOC_CLONE)).\n\nWe can use this to implement multi-threading.\n\nFor configuration, we don't need any more information beyond the simple\narray provided by the core block export interface: The FUSE kernel\ndriver feeds these FDs in a round-robin fashion, so all of them are\nequivalent and we want to have exactly one per thread.\n\nThese are the benchmark results when using four threads (compared to a\nsingle thread); note that fio still only uses a single job, but\nperformance can still be improved because of said round-robin usage for\nthe queues.  (Not in the sync case, though, in which case I guess it\njust adds overhead.)\n\nfile:\n  read:\n    seq aio:   261.7k ±1.7k  (+168%)\n    rand aio:  129.2k ±14.3k (+35%)\n    seq sync:   36.6k ±0.6k  (+6%)\n    rand sync:  10.1k ±0.1k  (+2%)\n  write:\n    seq aio:   235.7k ±2.8k  (+243%)\n    rand aio:  232.0k ±6.7k  (+237%)\n    seq sync:   31.7k ±0.6k  (+4%)\n    rand sync:  31.8k ±0.5k  (+4%)\nnull:\n  read:\n    seq aio:   253.8k ±12.3k (+45%)\n    rand aio:  248.2k ±12.0k (+45%)\n    seq sync:   91.6k ±2.4k  (+12%)\n    rand sync:  91.3k ±2.1k  (+17%)\n  write:\n    seq aio:   208.2k ±9.8k  (+6%)\n    rand aio:  207.0k ±7.4k  (+8%)\n    seq sync:   91.2k ±1.9k  (+9%)\n    rand sync:  90.4k ±2.5k  (+14%)\n\nSo moderate improvements in most cases, but quite improved AIO\nperformance with an actual underlying file.\n\nHere's results for numjobs=4:\n\n\"Before\", i.e. without multithreading in QSD/FUSE (results compared to\nnumjobs=1):\n\nfile:\n  read:\n    seq aio:    85.5k ±0.4k (-13%)\n    rand aio:   92.5k ±0.5k (-3%)\n    seq sync:   54.5k ±9.1k (+58%)\n    rand sync:  38.0k ±0.2k (+283%)\n  write:\n    seq aio:    67.3k ±0.3k (-2%)\n    rand aio:   67.6k ±0.3k (-2%)\n    seq sync:   69.3k ±0.5k (+126%)\n    rand sync:  69.3k ±0.3k (+126%)\nnull:\n  read:\n    seq aio:   170.6k ±0.8k (-2%)\n    rand aio:  170.9k ±0.9k (±0%)\n    seq sync:  187.6k ±1.3k (+129%)\n    rand sync: 188.9k ±0.9k (+142%)\n  write:\n    seq aio:   191.5k ±1.2k (-2%)\n    rand aio:  193.8k ±1.4k (-1%)\n    seq sync:  206.1k ±1.3k (+147%)\n    rand sync: 206.1k ±1.2k (+159%)\n\nAs probably expected, little difference in the AIO case, but great\nimprovements in the sync cases because it kind of gives it an artificial\niodepth of 4.\n\n\"After\", i.e. with four threads in QSD/FUSE (now results compared to the\nabove):\n\nfile:\n  read:\n    seq aio:   198.7k ±2.7k (+132%)\n    rand aio:  317.3k ±0.6k (+243%)\n    seq sync:   55.9k ±8.9k (+3%)\n    rand sync:  39.1k ±0.0k (+3%)\n  write:\n    seq aio:   229.0k ±0.8k (+240%)\n    rand aio:  227.0k ±1.3k (+235%)\n    seq sync:  102.5k ±0.2k (+48%)\n    rand sync: 101.7k ±0.2k (+47%)\nnull:\n  read:\n    seq aio:   584.0k ±1.5k (+242%)\n    rand aio:  581.9k ±1.9k (+240%)\n    seq sync:  270.6k ±0.9k (+44%)\n    rand sync: 270.4k ±0.7k (+43%)\n  write:\n    seq aio:   598.4k ±2.0k (+212%)\n    rand aio:  605.2k ±2.0k (+212%)\n    seq sync:  274.0k ±0.8k (+33%)\n    rand sync: 275.0k ±0.7k (+33%)\n\nSo this helps mainly for the AIO cases, but also in the null sync cases,\nbecause null is always CPU-bound, so more threads help.\n\nOne unsolved mystery: When using a multithreaded export, running fio\nwith 1 job (benchmark at the top of this commit) yields better seqread\nperformance than doing so with 4 jobs.  Actually, with 4 jobs, it's\nsignificantly than randread, which is quite strange.\n\nSigned-off-by: Hanna Czenczek <hreitz@redhat.com>\n---\n block/export/fuse.c | 193 +++++++++++++++++++++++++++++++++++---------\n 1 file changed, 153 insertions(+), 40 deletions(-)",
    "diff": "diff --git a/block/export/fuse.c b/block/export/fuse.c\nindex 162cbdacfc..6777a7651b 100644\n--- a/block/export/fuse.c\n+++ b/block/export/fuse.c\n@@ -31,11 +31,13 @@\n #include \"qemu/error-report.h\"\n #include \"qemu/main-loop.h\"\n #include \"system/block-backend.h\"\n+#include \"system/iothread.h\"\n \n #include <fuse.h>\n #include <fuse_lowlevel.h>\n \n #include \"standard-headers/linux/fuse.h\"\n+#include <sys/ioctl.h>\n \n #if defined(CONFIG_FALLOCATE_ZERO_RANGE)\n #include <linux/falloc.h>\n@@ -119,12 +121,17 @@ QEMU_BUILD_BUG_ON(sizeof(((FuseRequestInHeaderBuf *)0)->head) +\n                   sizeof(((FuseRequestInHeaderBuf *)0)->tail) !=\n                   sizeof(FuseRequestInHeader));\n \n-typedef struct FuseExport {\n-    BlockExport common;\n+typedef struct FuseExport FuseExport;\n \n-    struct fuse_session *fuse_session;\n-    unsigned int in_flight; /* atomic */\n-    bool mounted, fd_handler_set_up;\n+/*\n+ * One FUSE \"queue\", representing one FUSE FD from which requests are fetched\n+ * and processed.  Each queue is tied to an AioContext.\n+ */\n+typedef struct FuseQueue {\n+    FuseExport *exp;\n+\n+    AioContext *ctx;\n+    int fuse_fd;\n \n     /*\n      * Cached buffer to receive the data of WRITE requests.  Cached because:\n@@ -141,6 +148,14 @@ typedef struct FuseExport {\n      * via blk_blockalign() and thus need to be freed via qemu_vfree().\n      */\n     void *req_write_data_cached;\n+} FuseQueue;\n+\n+struct FuseExport {\n+    BlockExport common;\n+\n+    struct fuse_session *fuse_session;\n+    unsigned int in_flight; /* atomic */\n+    bool mounted, fd_handler_set_up;\n \n     /*\n      * Set when there was an unrecoverable error and no requests should be read\n@@ -149,7 +164,15 @@ typedef struct FuseExport {\n      */\n     bool halted;\n \n-    int fuse_fd;\n+    int num_queues;\n+    FuseQueue *queues;\n+    /*\n+     * True if this export should follow the generic export's AioContext.\n+     * Will be false if the queues' AioContexts have been explicitly set by the\n+     * user, i.e. are expected to stay in those contexts.\n+     * (I.e. is always false if there is more than one queue.)\n+     */\n+    bool follow_aio_context;\n \n     char *mountpoint;\n     bool writable;\n@@ -161,7 +184,7 @@ typedef struct FuseExport {\n     mode_t st_mode;\n     uid_t st_uid;\n     gid_t st_gid;\n-} FuseExport;\n+};\n \n /*\n  * Verify that the size of FuseRequestInHeaderBuf.head plus the data\n@@ -180,12 +203,13 @@ static void fuse_export_halt(FuseExport *exp);\n static void init_exports_table(void);\n \n static int mount_fuse_export(FuseExport *exp, Error **errp);\n+static int clone_fuse_fd(int fd, Error **errp);\n \n static bool is_regular_file(const char *path, Error **errp);\n \n static void read_from_fuse_fd(void *opaque);\n static void coroutine_fn\n-fuse_co_process_request(FuseExport *exp, const FuseRequestInHeader *in_hdr,\n+fuse_co_process_request(FuseQueue *q, const FuseRequestInHeader *in_hdr,\n                         const void *data_buffer);\n static int fuse_write_err(int fd, const struct fuse_in_header *in_hdr, int err);\n \n@@ -217,8 +241,11 @@ static void fuse_attach_handlers(FuseExport *exp)\n         return;\n     }\n \n-    aio_set_fd_handler(exp->common.ctx, exp->fuse_fd,\n-                       read_from_fuse_fd, NULL, NULL, NULL, exp);\n+    for (int i = 0; i < exp->num_queues; i++) {\n+        aio_set_fd_handler(exp->queues[i].ctx, exp->queues[i].fuse_fd,\n+                           read_from_fuse_fd, NULL, NULL, NULL,\n+                           &exp->queues[i]);\n+    }\n     exp->fd_handler_set_up = true;\n }\n \n@@ -227,8 +254,10 @@ static void fuse_attach_handlers(FuseExport *exp)\n  */\n static void fuse_detach_handlers(FuseExport *exp)\n {\n-    aio_set_fd_handler(exp->common.ctx, exp->fuse_fd,\n-                       NULL, NULL, NULL, NULL, NULL);\n+    for (int i = 0; i < exp->num_queues; i++) {\n+        aio_set_fd_handler(exp->queues[i].ctx, exp->queues[i].fuse_fd,\n+                           NULL, NULL, NULL, NULL, NULL);\n+    }\n     exp->fd_handler_set_up = false;\n }\n \n@@ -243,6 +272,11 @@ static void fuse_export_drained_end(void *opaque)\n \n     /* Refresh AioContext in case it changed */\n     exp->common.ctx = blk_get_aio_context(exp->common.blk);\n+    if (exp->follow_aio_context) {\n+        assert(exp->num_queues == 1);\n+        exp->queues[0].ctx = exp->common.ctx;\n+    }\n+\n     fuse_attach_handlers(exp);\n }\n \n@@ -274,8 +308,32 @@ static int fuse_export_create(BlockExport *blk_exp,\n     assert(blk_exp_args->type == BLOCK_EXPORT_TYPE_FUSE);\n \n     if (multithread) {\n-        error_setg(errp, \"FUSE export does not support multi-threading\");\n-        return -EINVAL;\n+        /* Guaranteed by common export code */\n+        assert(mt_count >= 1);\n+\n+        exp->follow_aio_context = false;\n+        exp->num_queues = mt_count;\n+        exp->queues = g_new(FuseQueue, mt_count);\n+\n+        for (size_t i = 0; i < mt_count; i++) {\n+            exp->queues[i] = (FuseQueue) {\n+                .exp = exp,\n+                .ctx = multithread[i],\n+                .fuse_fd = -1,\n+            };\n+        }\n+    } else {\n+        /* Guaranteed by common export code */\n+        assert(mt_count == 0);\n+\n+        exp->follow_aio_context = true;\n+        exp->num_queues = 1;\n+        exp->queues = g_new(FuseQueue, 1);\n+        exp->queues[0] = (FuseQueue) {\n+            .exp = exp,\n+            .ctx = exp->common.ctx,\n+            .fuse_fd = -1,\n+        };\n     }\n \n     /* For growable and writable exports, take the RESIZE permission */\n@@ -287,7 +345,7 @@ static int fuse_export_create(BlockExport *blk_exp,\n         ret = blk_set_perm(exp->common.blk, blk_perm | BLK_PERM_RESIZE,\n                            blk_shared_perm, errp);\n         if (ret < 0) {\n-            return ret;\n+            goto fail;\n         }\n     }\n \n@@ -363,13 +421,23 @@ static int fuse_export_create(BlockExport *blk_exp,\n \n     g_hash_table_insert(exports, g_strdup(exp->mountpoint), NULL);\n \n-    exp->fuse_fd = fuse_session_fd(exp->fuse_session);\n-    ret = qemu_fcntl_addfl(exp->fuse_fd, O_NONBLOCK);\n+    assert(exp->num_queues >= 1);\n+    exp->queues[0].fuse_fd = fuse_session_fd(exp->fuse_session);\n+    ret = qemu_fcntl_addfl(exp->queues[0].fuse_fd, O_NONBLOCK);\n     if (ret < 0) {\n         error_setg_errno(errp, -ret, \"Failed to make FUSE FD non-blocking\");\n         goto fail;\n     }\n \n+    for (int i = 1; i < exp->num_queues; i++) {\n+        int fd = clone_fuse_fd(exp->queues[0].fuse_fd, errp);\n+        if (fd < 0) {\n+            ret = fd;\n+            goto fail;\n+        }\n+        exp->queues[i].fuse_fd = fd;\n+    }\n+\n     fuse_attach_handlers(exp);\n     return 0;\n \n@@ -462,28 +530,28 @@ fail:\n /**\n  * Allocate a buffer to receive WRITE data, or take the cached one.\n  */\n-static void *get_write_data_buffer(FuseExport *exp)\n+static void *get_write_data_buffer(FuseQueue *q)\n {\n-    if (exp->req_write_data_cached) {\n-        void *cached = exp->req_write_data_cached;\n-        exp->req_write_data_cached = NULL;\n+    if (q->req_write_data_cached) {\n+        void *cached = q->req_write_data_cached;\n+        q->req_write_data_cached = NULL;\n         return cached;\n     } else {\n-        return blk_blockalign(exp->common.blk, FUSE_MAX_WRITE_BYTES);\n+        return blk_blockalign(q->exp->common.blk, FUSE_MAX_WRITE_BYTES);\n     }\n }\n \n /**\n  * Release a WRITE data buffer, possibly reusing it for a subsequent request.\n  */\n-static void release_write_data_buffer(FuseExport *exp, void **buffer)\n+static void release_write_data_buffer(FuseQueue *q, void **buffer)\n {\n     if (!*buffer) {\n         return;\n     }\n \n-    if (!exp->req_write_data_cached) {\n-        exp->req_write_data_cached = *buffer;\n+    if (!q->req_write_data_cached) {\n+        q->req_write_data_cached = *buffer;\n     } else {\n         qemu_vfree(*buffer);\n     }\n@@ -529,9 +597,42 @@ static ssize_t req_op_hdr_len(const FuseRequestInHeader *in_hdr)\n     }\n }\n \n+/**\n+ * Clone the given /dev/fuse file descriptor, yielding a second FD from which\n+ * requests can be pulled for the associated filesystem.  Returns an FD on\n+ * success, and -errno on error.\n+ */\n+static int clone_fuse_fd(int fd, Error **errp)\n+{\n+    uint32_t src_fd = fd;\n+    int new_fd;\n+    int ret;\n+\n+    /*\n+     * The name \"/dev/fuse\" is fixed, see libfuse's lib/fuse_loop_mt.c\n+     * (fuse_clone_chan()).\n+     */\n+    new_fd = open(\"/dev/fuse\", O_RDWR | O_CLOEXEC | O_NONBLOCK);\n+    if (new_fd < 0) {\n+        ret = -errno;\n+        error_setg_errno(errp, errno, \"Failed to open /dev/fuse\");\n+        return ret;\n+    }\n+\n+    ret = ioctl(new_fd, FUSE_DEV_IOC_CLONE, &src_fd);\n+    if (ret < 0) {\n+        ret = -errno;\n+        error_setg_errno(errp, errno, \"Failed to clone FUSE FD\");\n+        close(new_fd);\n+        return ret;\n+    }\n+\n+    return new_fd;\n+}\n+\n /**\n  * Try to read a single request from the FUSE FD.\n- * Takes a FuseExport pointer in `opaque`.\n+ * Takes a FuseQueue pointer in `opaque`.\n  *\n  * Assumes the export's in-flight counter has already been incremented.\n  *\n@@ -539,8 +640,9 @@ static ssize_t req_op_hdr_len(const FuseRequestInHeader *in_hdr)\n  */\n static void coroutine_fn co_read_from_fuse_fd(void *opaque)\n {\n-    FuseExport *exp = opaque;\n-    int fuse_fd = exp->fuse_fd;\n+    FuseQueue *q = opaque;\n+    int fuse_fd = q->fuse_fd;\n+    FuseExport *exp = q->exp;\n     ssize_t ret;\n     FuseRequestInHeaderBuf in_hdr_buf;\n     const FuseRequestInHeader *in_hdr;\n@@ -552,7 +654,7 @@ static void coroutine_fn co_read_from_fuse_fd(void *opaque)\n         goto no_request;\n     }\n \n-    data_buffer = get_write_data_buffer(exp);\n+    data_buffer = get_write_data_buffer(q);\n \n     /* Construct the I/O vector to hold the FUSE request */\n     iov[0] = (struct iovec) { &in_hdr_buf.head, sizeof(in_hdr_buf.head) };\n@@ -613,29 +715,29 @@ static void coroutine_fn co_read_from_fuse_fd(void *opaque)\n             memcpy(in_hdr_buf.tail, data_buffer, len);\n         }\n \n-        release_write_data_buffer(exp, &data_buffer);\n+        release_write_data_buffer(q, &data_buffer);\n     }\n \n-    fuse_co_process_request(exp, in_hdr, data_buffer);\n+    fuse_co_process_request(q, in_hdr, data_buffer);\n \n no_request:\n-    release_write_data_buffer(exp, &data_buffer);\n+    release_write_data_buffer(q, &data_buffer);\n     fuse_dec_in_flight(exp);\n }\n \n /**\n  * Try to read and process a single request from the FUSE FD.\n  * (To be used as a handler for when the FUSE FD becomes readable.)\n- * Takes a FuseExport pointer in `opaque`.\n+ * Takes a FuseQueue pointer in `opaque`.\n  */\n static void read_from_fuse_fd(void *opaque)\n {\n-    FuseExport *exp = opaque;\n+    FuseQueue *q = opaque;\n     Coroutine *co;\n \n-    co = qemu_coroutine_create(co_read_from_fuse_fd, exp);\n+    co = qemu_coroutine_create(co_read_from_fuse_fd, q);\n     /* Decremented by co_read_from_fuse_fd() */\n-    fuse_inc_in_flight(exp);\n+    fuse_inc_in_flight(q->exp);\n     qemu_coroutine_enter(co);\n }\n \n@@ -660,6 +762,17 @@ static void fuse_export_delete(BlockExport *blk_exp)\n {\n     FuseExport *exp = container_of(blk_exp, FuseExport, common);\n \n+    for (int i = 0; i < exp->num_queues; i++) {\n+        FuseQueue *q = &exp->queues[i];\n+\n+        /* Queue 0's FD belongs to the FUSE session */\n+        if (i > 0 && q->fuse_fd >= 0) {\n+            close(q->fuse_fd);\n+        }\n+        qemu_vfree(q->req_write_data_cached);\n+    }\n+    g_free(exp->queues);\n+\n     if (exp->fuse_session) {\n         if (exp->mounted) {\n             fuse_session_unmount(exp->fuse_session);\n@@ -668,7 +781,6 @@ static void fuse_export_delete(BlockExport *blk_exp)\n         fuse_session_destroy(exp->fuse_session);\n     }\n \n-    qemu_vfree(exp->req_write_data_cached);\n     g_free(exp->mountpoint);\n }\n \n@@ -1373,10 +1485,11 @@ static int fuse_write_buf_response(int fd,\n  * Process a FUSE request, incl. writing the response.\n  */\n static void coroutine_fn\n-fuse_co_process_request(FuseExport *exp, const FuseRequestInHeader *in_hdr,\n+fuse_co_process_request(FuseQueue *q, const FuseRequestInHeader *in_hdr,\n                         const void *data_buffer)\n {\n     FuseRequestOutHeader out_hdr;\n+    FuseExport *exp = q->exp;\n     /* For read requests: Data to be returned */\n     void *out_data_buffer = NULL;\n     ssize_t ret;\n@@ -1498,10 +1611,10 @@ fuse_co_process_request(FuseExport *exp, const FuseRequestInHeader *in_hdr,\n     }\n \n     if (out_data_buffer) {\n-        fuse_write_buf_response(exp->fuse_fd, &out_hdr.common, out_data_buffer);\n+        fuse_write_buf_response(q->fuse_fd, &out_hdr.common, out_data_buffer);\n         qemu_vfree(out_data_buffer);\n     } else {\n-        fuse_write_response(exp->fuse_fd, &out_hdr);\n+        fuse_write_response(q->fuse_fd, &out_hdr);\n     }\n }\n \n",
    "prefixes": [
        "v4",
        "22/24"
    ]
}