From patchwork Tue Jun 14 05:15:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 1643119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=AVc4O/qX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMcJl4Kxtz9sGD for ; Tue, 14 Jun 2022 15:22:47 +1000 (AEST) Received: from localhost ([::1]:39108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0z0n-0000em-Ll for incoming@patchwork.ozlabs.org; Tue, 14 Jun 2022 01:22:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0yvF-0000lx-Tu for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:01 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:38765) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o0yvE-0000zX-DP for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:01 -0400 Received: by mail-pf1-x42c.google.com with SMTP id e11so7622850pfj.5 for ; Mon, 13 Jun 2022 22:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bra4MXrkftG1CgYi5VJNtBbeWDP0NTrpYw+kRy2gXBY=; b=AVc4O/qX6GXxIN2/hewf9JY909hPO3jhYlwOjXk13mYY+Nxp1kLAgVjNd/SpsbTwT4 ps3tYPDePZ6NuOLIDBrCQcIabBcHHpBpQa/B5jeHteAos2MKZ0n0Nhr+O+OIptIFE4EQ LBQ/A7RdOgH4ZFOHJRB3zEH2IR2IN4SVHGlHhvxzqDl/XRYe7jGGHKM5tQayWu5GQVdf AYEeldbntlpRtQgkSnj5y6b7BsqJCwGKCyJge1AoGF9+Oz7lPQVs5iye/ECmiLY+A9b+ RW18uQMm1x4021xVFJh2Dj1imQ7A131xVBfE1AVLgXq91c1iywxrGlEhZEvDei+AXf1h RcKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bra4MXrkftG1CgYi5VJNtBbeWDP0NTrpYw+kRy2gXBY=; b=3QbgbjKse9eWTU72OmDoG5RCe4qwLi18bLha0klWTxqSMJIyAVYhDk47ouoHJt1EMQ pJMieUPS9erHf7JbRXpQdaC4K8N5A56zkvzGmo1Cz6ygumL9BLnsnPmyPYFIUNI+bRMz PKZROP6p5ZV30uwh7UOI//Q08guk8ahNpAj7Ks1LxJVsC/ZaeblBuYxa1lSrGmgV3i7U QBgWy425SEVA/7+BXQ98rs0LpV7anF0FfwAP3Lk9evRjGFyt5geBypPvjNm9/Q6Epz+j Wm+UVn7JiYkr+buxebN848l8p0PmEM1+Dta9sL+zre9TAdl1uX2RoTNEMzfajiakDK6J XkQg== X-Gm-Message-State: AOAM530urJCcbyUgR6t1w9bLrzf0iZZWD+imlPkR67+77Ia86tTfByz7 SYAjsMMK+A35Yhaw/6xeWgJX X-Google-Smtp-Source: ABdhPJw5o8ipotRVWPh8t5pRkUhxV9RSIprQmN/+k89ajNUKvaqsMVgVHB7cTxR683wv1A8G3IDXyw== X-Received: by 2002:a05:6a00:1350:b0:51c:26d2:9ce5 with SMTP id k16-20020a056a00135000b0051c26d29ce5mr2891428pfu.69.1655183819091; Mon, 13 Jun 2022 22:16:59 -0700 (PDT) Received: from localhost ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id o9-20020a62f909000000b0052089e1b88esm5389979pfh.192.2022.06.13.22.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 22:16:58 -0700 (PDT) From: Xie Yongji To: kwolf@redhat.com, stefanha@redhat.com Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 1/6] libvduse: Fix some compile errors with clang Date: Tue, 14 Jun 2022 13:15:27 +0800 Message-Id: <20220614051532.92-2-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220614051532.92-1-xieyongji@bytedance.com> References: <20220614051532.92-1-xieyongji@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=xieyongji@bytedance.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This fixes some compile errors with clang: ../subprojects/libvduse/libvduse.c:578:20: error: unused function 'vring_used_flags_set_bit' [-Werror,-Wunused-function] static inline void vring_used_flags_set_bit(VduseVirtq *vq, int mask) ^ ../subprojects/libvduse/libvduse.c:587:20: error: unused function 'vring_used_flags_unset_bit' [-Werror,-Wunused-function] static inline void vring_used_flags_unset_bit(VduseVirtq *vq, int mask) ../subprojects/libvduse/libvduse.c:325:20: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast] 325 | munmap((void *)dev->regions[i].mmap_addr, | ^ ../subprojects/libvduse/libvduse.c: In function 'vduse_dev_create': ../subprojects/libvduse/libvduse.c:1318:54: error: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'uint64_t' {aka 'long long unsigned int'} [-Werror=format=] 1318 | fprintf(stderr, "Failed to set api version %lu: %s\n", | ~~^ | | | long unsigned int | %llu 1319 | version, strerror(errno)); | ~~~~~~~ | | | uint64_t {aka long long unsigned int} Signed-off-by: Xie Yongji --- subprojects/libvduse/libvduse.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/subprojects/libvduse/libvduse.c b/subprojects/libvduse/libvduse.c index 78bb777402..dd1faffe66 100644 --- a/subprojects/libvduse/libvduse.c +++ b/subprojects/libvduse/libvduse.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -322,7 +323,7 @@ static void vduse_iova_remove_region(VduseDev *dev, uint64_t start, if (start <= dev->regions[i].iova && last >= (dev->regions[i].iova + dev->regions[i].size - 1)) { - munmap((void *)dev->regions[i].mmap_addr, + munmap((void *)(uintptr_t)dev->regions[i].mmap_addr, dev->regions[i].mmap_offset + dev->regions[i].size); dev->regions[i].mmap_addr = 0; dev->num_regions--; @@ -575,24 +576,6 @@ void vduse_queue_notify(VduseVirtq *vq) } } -static inline void vring_used_flags_set_bit(VduseVirtq *vq, int mask) -{ - uint16_t *flags; - - flags = (uint16_t *)((char*)vq->vring.used + - offsetof(struct vring_used, flags)); - *flags = htole16(le16toh(*flags) | mask); -} - -static inline void vring_used_flags_unset_bit(VduseVirtq *vq, int mask) -{ - uint16_t *flags; - - flags = (uint16_t *)((char*)vq->vring.used + - offsetof(struct vring_used, flags)); - *flags = htole16(le16toh(*flags) & ~mask); -} - static inline void vring_set_avail_event(VduseVirtq *vq, uint16_t val) { *((uint16_t *)&vq->vring.used->ring[vq->vring.num]) = htole16(val); @@ -1315,7 +1298,7 @@ VduseDev *vduse_dev_create(const char *name, uint32_t device_id, version = VDUSE_API_VERSION; if (ioctl(ctrl_fd, VDUSE_SET_API_VERSION, &version)) { - fprintf(stderr, "Failed to set api version %lu: %s\n", + fprintf(stderr, "Failed to set api version %" PRIu64 ": %s\n", version, strerror(errno)); goto err_dev; } From patchwork Tue Jun 14 05:15:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 1643115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=E032+evQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMcCM0rGCz9sGG for ; Tue, 14 Jun 2022 15:18:05 +1000 (AEST) Received: from localhost ([::1]:55920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0ywE-0001J3-9N for incoming@patchwork.ozlabs.org; Tue, 14 Jun 2022 01:18:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0yvJ-0000sG-H6 for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:06 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:42604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o0yvI-0000zx-3Z for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:05 -0400 Received: by mail-pj1-x1029.google.com with SMTP id o33-20020a17090a0a2400b001ea806e48c6so8048534pjo.1 for ; Mon, 13 Jun 2022 22:17:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YKRxELDYmUMfhugMV5DcbLSb/amLG/qPOQgkHQTfT7g=; b=E032+evQdRH2NuNgLiwG89CYUpUPj39VDFk33O/nudPj9/X10TSUXKJ337cTmbvlGJ RuObnfYSpq557vuPMVunbGdRRJXOigi0SUTaNijlbyYEjOkiLlQ4jTviDG9ne+ZnUQvi EI1GyiXWY4duJ/TioIG02Fott+tnJaMsAOkhkZyTUJ0U1eMaKVZVMQPTaMOCsUKpOZhc AxLJ4t45Cg/AGWUFYiSnk0X3/nYvR8IVstXFPgcMSJC5j5y7XEc4+wLjrW4jD+gMjrw0 hGT+mHK8+OzuVTTIBdO8iCn6U3wSCL1mw72T/x1+8+pPMU5aGCPLFrw/jg+i88XB0Joa iJvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YKRxELDYmUMfhugMV5DcbLSb/amLG/qPOQgkHQTfT7g=; b=BdDGmVwW52lUAjYlyciqxImslD+9EcrW13ytp3sPT1OAqI6taotoI6PgcqVB2zlI7u lD05I/piUVwfZbwVXAEHlxe/66ogOPmiDAppE98W/plVdqwPg9Tn11oCQAk7q/QC/0xm Mb4+xJp9QDT/N4lq4R1a5bbUZcdZ9dMnQ0Qx2H1NZiL8VC+g6jazU6TYCmeknF4VK36S YSp6jhbU9VaBrEtPNBXPxpX1e4RRvWo9PWVhe0t4DEjBguqrx/sYLB3F0tC01GmgNf6V rfLlAwW1J/suA3o0Xpysomt9c4tknCsXJsHhel2AzuC2ilnwwUdJw1sLX/6UPz/HjoXW W3IQ== X-Gm-Message-State: AJIora+4X6GnkfpqKwpIWegYyqlXM3dpVQ48TG3Bp8z9td/zj/EbXIoo HcY4BP4JnkWeT39lPuN0YyTR X-Google-Smtp-Source: AGRyM1uJhJEjat560HfZEGzTJUMGmik8LAiUn0GvK5DbccYRfN2b5SnSNf4dVsBYbkyYyXriRQ8+Ew== X-Received: by 2002:a17:90b:368b:b0:1e6:67a0:1c17 with SMTP id mj11-20020a17090b368b00b001e667a01c17mr2546599pjb.203.1655183822845; Mon, 13 Jun 2022 22:17:02 -0700 (PDT) Received: from localhost ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id l4-20020a170903120400b0016511314b94sm6103301plh.159.2022.06.13.22.17.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 22:17:02 -0700 (PDT) From: Xie Yongji To: kwolf@redhat.com, stefanha@redhat.com Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 2/6] libvduse: Fix resources leak in vduse_dev_destroy() Date: Tue, 14 Jun 2022 13:15:28 +0800 Message-Id: <20220614051532.92-3-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220614051532.92-1-xieyongji@bytedance.com> References: <20220614051532.92-1-xieyongji@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=xieyongji@bytedance.com; helo=mail-pj1-x1029.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This fixes resource leak when the fd is zero in vduse_dev_destroy(). Fixes: 8dbd281c1675 ("libvduse: Add VDUSE (vDPA Device in Userspace) library") Signed-off-by: Xie Yongji --- subprojects/libvduse/libvduse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subprojects/libvduse/libvduse.c b/subprojects/libvduse/libvduse.c index dd1faffe66..9a2bcec282 100644 --- a/subprojects/libvduse/libvduse.c +++ b/subprojects/libvduse/libvduse.c @@ -1357,11 +1357,11 @@ int vduse_dev_destroy(VduseDev *dev) free(dev->vqs[i].resubmit_list); } free(dev->vqs); - if (dev->fd > 0) { + if (dev->fd >= 0) { close(dev->fd); dev->fd = -1; } - if (dev->ctrl_fd > 0) { + if (dev->ctrl_fd >= 0) { if (ioctl(dev->ctrl_fd, VDUSE_DESTROY_DEV, dev->name)) { ret = -errno; } From patchwork Tue Jun 14 05:15:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 1643114 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=5xyPIZno; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMcCM0nGHz9sGD for ; Tue, 14 Jun 2022 15:18:05 +1000 (AEST) Received: from localhost ([::1]:56242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0ywF-0001Vz-3Z for incoming@patchwork.ozlabs.org; Tue, 14 Jun 2022 01:18:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0yvN-0000vd-AN for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:09 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:44851) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o0yvL-00010M-SZ for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:09 -0400 Received: by mail-pj1-x1036.google.com with SMTP id gc3-20020a17090b310300b001e33092c737so8031328pjb.3 for ; Mon, 13 Jun 2022 22:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0y2TFEqOSWX2sasE6c7pK+W7e00REmrQJniw6QVW8Dc=; b=5xyPIZno/EKK/KLDjARVWlVz/xJxtYxPR3pcI8orrAMrSnGuJQRDFvAAvYEpExUUJZ FkGpTfaovgvHeRps8LgeE0CIOykHmpBnuJ8xJLZ0wJeQFga1hFQH0SglBo8G4wx/l/1p VB+r6LW+aCTAID426Y+j5dSM9WY0FJQh+n7FKS0ItlqFsXIJu/mP24XX1XkBBHdla6bc 0XLh2erIcPhqeNEuQ1UH6stu1MPDaT2xOkV2Yj3XgFYCgLKF/cjlNdKmsln1VMjmtitH Xw868YveGEVj7sJigOHUceVd7NU8ZMg3i+qTDuD4Y+S0WflY1Mf2yNNC4dAeHmpZLr+d 4cJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0y2TFEqOSWX2sasE6c7pK+W7e00REmrQJniw6QVW8Dc=; b=TojEDWetPSiWXergNdsIrUNiEVBBfmrdT1fG0P4EKVRcu5f/HePYFWnAyRc0hUUR6o tfyiIOU2aG3Ws8WdS9aNTh5TNMvBxvk98TADizz12IDbktpeHOoJPUrZuG4S6YW9o3Kn QMbQ8RJO0BXluFFbEzCGutziGaor8n/h8ypKag1xi+2m5esxRzzCHZNr23dN0ba5FxeS +rwIAwdZ9eKbjtejS8skvEMQHgEjO6GCKt1O2tRMwLzqFV7wxFGCHRyopt3S8R0hDgyw KDorc6X2l4o+oolOctkk6gs88YJZlnzayXQMs3sxwyf7C/okLJ9jUPiIHAz1uvWUmAFc qAmg== X-Gm-Message-State: AJIora9w+TkpvTYX2+i+SNF/eQdwqB476MB3A1APudNtWfMcKrG/3tWJ l17Xu1dusHTTf15Rh7QHuTyU X-Google-Smtp-Source: AGRyM1tSShUXaCjYMciRctBom6qzhTde58+KBV9KsgwGK22WLbrPJyNFWOcTZUd1Bl0rAmAXFz+u5A== X-Received: by 2002:a17:90b:3a87:b0:1e8:8740:43e7 with SMTP id om7-20020a17090b3a8700b001e8874043e7mr2582604pjb.41.1655183826563; Mon, 13 Jun 2022 22:17:06 -0700 (PDT) Received: from localhost ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id ch6-20020a056a00288600b0051b32c2a5a7sm6362869pfb.138.2022.06.13.22.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 22:17:06 -0700 (PDT) From: Xie Yongji To: kwolf@redhat.com, stefanha@redhat.com Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 3/6] vduse-blk: Don't unlink the reconnect file if device exists Date: Tue, 14 Jun 2022 13:15:29 +0800 Message-Id: <20220614051532.92-4-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220614051532.92-1-xieyongji@bytedance.com> References: <20220614051532.92-1-xieyongji@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=xieyongji@bytedance.com; helo=mail-pj1-x1036.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We should not unlink the reconnect file if vduse_dev_destroy() fails with -EBUSY which means the VDUSE device has not been removed from the vDPA bus. Otherwise, we might fail on the reconnection later. Fixes: 730abef0e873 ("libvduse: Add support for reconnecting") Signed-off-by: Xie Yongji --- block/export/vduse-blk.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c index 3b10349173..c3a89894ae 100644 --- a/block/export/vduse-blk.c +++ b/block/export/vduse-blk.c @@ -316,12 +316,15 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, static void vduse_blk_exp_delete(BlockExport *exp) { VduseBlkExport *vblk_exp = container_of(exp, VduseBlkExport, export); + int ret; blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, vblk_exp); blk_set_dev_ops(exp->blk, NULL, NULL); - vduse_dev_destroy(vblk_exp->dev); - unlink(vblk_exp->recon_file); + ret = vduse_dev_destroy(vblk_exp->dev); + if (ret != -EBUSY) { + unlink(vblk_exp->recon_file); + } g_free(vblk_exp->recon_file); } From patchwork Tue Jun 14 05:15:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 1643118 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=ZlLwPVUV; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMcHr0Lj1z9sGD for ; Tue, 14 Jun 2022 15:22:00 +1000 (AEST) Received: from localhost ([::1]:36628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0z02-0007QC-4L for incoming@patchwork.ozlabs.org; Tue, 14 Jun 2022 01:21:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0yvR-0000zC-Lq for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:14 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:35677) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o0yvQ-00010l-5j for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:13 -0400 Received: by mail-pg1-x535.google.com with SMTP id 129so7545130pgc.2 for ; Mon, 13 Jun 2022 22:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tpwj4iCawFu7SFnzkW//trv7YNVTZc0mprYQAMb2zUk=; b=ZlLwPVUVQpjqTqGXsqkJho8Mxf2tcmCHSOsx2hwofRapJbbKIjGYv6k/jfoFG8xFQm Usr9+gTLPuewc5mGastk6rHxB7tWmI9mqJGRqLIPLdrgvHpYdIcRgU0VjmZe1GKdTMrz a2alJpILxjPeZAKnwCdRr3ydWoQRX6W2CuEhm3+JVgggQ0nmh/VEyXcd0ZODD4MzC9Rc 7A2BEDKO2Hfv5n6VBrWnUxuixxRN2ZEb5hsQUXzWoedBsqEk7L16PZNPijR0Qlts5Y1C eEb6+kyTXHiAs8F0Tk5cHdxcltG3ivRgJL7HAHfZxh+DG1Kw8QbI4gFgvwDrAyB/GC01 lCTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tpwj4iCawFu7SFnzkW//trv7YNVTZc0mprYQAMb2zUk=; b=yPhSKnWsQdh2j2iLG3HGQJ6cjjPxp/Ry0je8LuZI0jEAgm/+7p7W1yoLnQB/cHk4d5 5LbGu5uoWTPxt4G4Yw75tOUOKx3Iu3LLPCRE/HUXAxnahky+p+u5LXe7oNZQ8Ql+B238 hiGEf4vHjjX6LLehOgauZ91sx2vsWaiVhTUUf4mE3gSCTTAkehPSHRp5Err3+HX+SsJB fyegsVapfB/aOPcE/WwvAzI9kiYBMmpXzrGKD7dYLjlk+Om0vIBtIUaAWxIpRaoON+zc qN0r9L1amBlTp+PGsFjBD5ql5eReedpClPO2ek2QqKjiLlw98LXFb2G6Q+ZnLTvd1ZEU YrWA== X-Gm-Message-State: AOAM532EtQpiugXHrJ3C49aWsrQPlj8og9MyZTBaBy+NkG0XcmKpflfZ 2acGWpIjrV/Y6yNZKO0XX2CO X-Google-Smtp-Source: ABdhPJzq7Y6ZHXH/e5c72FwHfmq5QH72mJWroTJvj1KNg9WBWk03Rihp01VRM9ddHWIBs/7SqJQISg== X-Received: by 2002:a63:81c3:0:b0:3fc:c510:1a3 with SMTP id t186-20020a6381c3000000b003fcc51001a3mr2892423pgd.581.1655183830870; Mon, 13 Jun 2022 22:17:10 -0700 (PDT) Received: from localhost ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id e2-20020a170902b78200b00161fab018dfsm6071772pls.256.2022.06.13.22.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 22:17:10 -0700 (PDT) From: Xie Yongji To: kwolf@redhat.com, stefanha@redhat.com Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 4/6] vduse-blk: Don't delete the export until all inflight I/Os completed Date: Tue, 14 Jun 2022 13:15:30 +0800 Message-Id: <20220614051532.92-5-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220614051532.92-1-xieyongji@bytedance.com> References: <20220614051532.92-1-xieyongji@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=xieyongji@bytedance.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Don't delete the export until all inflight I/Os completed. Otherwise, it might lead to a use-after-free. Fixes: cc241b5505b2 ("vduse-blk: Implement vduse-blk export") Signed-off-by: Xie Yongji --- block/export/vduse-blk.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c index c3a89894ae..251d73c841 100644 --- a/block/export/vduse-blk.c +++ b/block/export/vduse-blk.c @@ -31,6 +31,7 @@ typedef struct VduseBlkExport { VduseDev *dev; uint16_t num_queues; char *recon_file; + unsigned int inflight; } VduseBlkExport; typedef struct VduseBlkReq { @@ -38,6 +39,18 @@ typedef struct VduseBlkReq { VduseVirtq *vq; } VduseBlkReq; +static void vduse_blk_inflight_inc(VduseBlkExport *vblk_exp) +{ + vblk_exp->inflight++; +} + +static void vduse_blk_inflight_dec(VduseBlkExport *vblk_exp) +{ + if (--vblk_exp->inflight == 0) { + aio_wait_kick(); + } +} + static void vduse_blk_req_complete(VduseBlkReq *req, size_t in_len) { vduse_queue_push(req->vq, &req->elem, in_len); @@ -68,10 +81,13 @@ static void coroutine_fn vduse_blk_virtio_process_req(void *opaque) } vduse_blk_req_complete(req, in_len); + vduse_blk_inflight_dec(vblk_exp); } static void vduse_blk_vq_handler(VduseDev *dev, VduseVirtq *vq) { + VduseBlkExport *vblk_exp = vduse_dev_get_priv(dev); + while (1) { VduseBlkReq *req; @@ -83,6 +99,8 @@ static void vduse_blk_vq_handler(VduseDev *dev, VduseVirtq *vq) Coroutine *co = qemu_coroutine_create(vduse_blk_virtio_process_req, req); + + vduse_blk_inflight_inc(vblk_exp); qemu_coroutine_enter(co); } } @@ -168,6 +186,8 @@ static void vduse_blk_detach_ctx(VduseBlkExport *vblk_exp) } aio_set_fd_handler(vblk_exp->export.ctx, vduse_dev_get_fd(vblk_exp->dev), true, NULL, NULL, NULL, NULL, NULL); + + AIO_WAIT_WHILE(vblk_exp->export.ctx, vblk_exp->inflight > 0); } @@ -332,7 +352,9 @@ static void vduse_blk_exp_request_shutdown(BlockExport *exp) { VduseBlkExport *vblk_exp = container_of(exp, VduseBlkExport, export); + aio_context_acquire(vblk_exp->export.ctx); vduse_blk_detach_ctx(vblk_exp); + aio_context_acquire(vblk_exp->export.ctx); } const BlockExportDriver blk_exp_vduse_blk = { From patchwork Tue Jun 14 05:15:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 1643117 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=y/faxTbR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMcH153Lvz9sGD for ; Tue, 14 Jun 2022 15:21:17 +1000 (AEST) Received: from localhost ([::1]:34656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0yzL-00065t-NS for incoming@patchwork.ozlabs.org; Tue, 14 Jun 2022 01:21:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0yvV-00013X-JA for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:19 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:35362) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o0yvT-000117-T0 for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:17 -0400 Received: by mail-pl1-x62f.google.com with SMTP id o6so6869097plg.2 for ; Mon, 13 Jun 2022 22:17:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CZ7G7Gujczw3DW8+iuBOrN7bUoP98YSa5d9uHEJ9yLY=; b=y/faxTbRg6aKgcIdU+to/ea5JVvVlFCkHefzgj/T+vp55Nt7yrKe+AMMuvBMKpHL4o DOk+3MfZX0874QNBl+jZU1xoueS9VmkXUm2KalbjWMYVg5NHBQ0Z9gDe8Mv5az7Hws00 20+PBtQj0ZsBJpQ6JZOOyXZ61OcOv/X4EFVpmAQsn9B/mSMMy7mHi1QAIIVnSY3gtX6q znc4iEs5NHFzw7kAgNoDEsBfrH1SI/Zp94v1/Sx4DvcfKP8LRYVbbgI5jrmW3yI6dr+c Jv3+PAnEImNpMAEoWk7NcSeKtq9qc9E87Dql+uV7YKPrYNedfX8Bwb2a7TH2OJPDndP/ oTLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CZ7G7Gujczw3DW8+iuBOrN7bUoP98YSa5d9uHEJ9yLY=; b=Bl0T9DqnKNbPdBCF2gstuqWuVdeczx3Nid0GSmVxl/IRMrlQBeV7nby7MV3+gXIFuf FI5rsufo7oG9XvhVSeYRuPD89RHHIjDhqDXJ7T5ay/cvt3zS9RRV5lDO1oR+IFn9EkHN /3/5f7F66e5J+JDcCoq0FJZhL3Mz47Q4f/OhPUwwuMcjBnG/JebpZf9Z+wBFdLceNk49 cCyoB3uGRQ9PhryVRWRSk0GhU7Ck2Fo7E577LFLyGYPevSdKz+OBci1HSkEZkK1NVihg 01OkeH5I28yedpfkce1dACX3DAD+rv9L1lstNNqjhAjCQ/XAYkwfvCzEDXj/3ia/knuI iqRQ== X-Gm-Message-State: AJIora/tteV1Cj9wEnqO/9rWK3shLirMjGN4jWOyEIHKt+CYn22SUh4Q D+4/afL8xTmzD9oqonUNmJk7 X-Google-Smtp-Source: AGRyM1vgEaUu1SPnEFG9R1sJOokQsD4DI0xYJjGt1tbvjGIQQrqSHXX7VvxlSm0XS59XGsdrXZHO5A== X-Received: by 2002:a17:902:d143:b0:168:d336:9de6 with SMTP id t3-20020a170902d14300b00168d3369de6mr2650124plt.124.1655183834531; Mon, 13 Jun 2022 22:17:14 -0700 (PDT) Received: from localhost ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id jj1-20020a170903048100b00163247b64bfsm6131399plb.115.2022.06.13.22.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 22:17:14 -0700 (PDT) From: Xie Yongji To: kwolf@redhat.com, stefanha@redhat.com Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 5/6] vduse-blk: Add serial option Date: Tue, 14 Jun 2022 13:15:31 +0800 Message-Id: <20220614051532.92-6-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220614051532.92-1-xieyongji@bytedance.com> References: <20220614051532.92-1-xieyongji@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=xieyongji@bytedance.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a 'serial' option to allow user to specify this value explicitly. And the default value is changed to an empty string as what we did in "hw/block/virtio-blk.c". Signed-off-by: Xie Yongji --- block/export/vduse-blk.c | 20 ++++++++++++++------ block/export/vhost-user-blk-server.c | 4 +++- block/export/virtio-blk-handler.h | 2 +- docs/tools/qemu-storage-daemon.rst | 2 +- qapi/block-export.json | 4 +++- storage-daemon/qemu-storage-daemon.c | 1 + 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c index 251d73c841..066e088b00 100644 --- a/block/export/vduse-blk.c +++ b/block/export/vduse-blk.c @@ -235,7 +235,7 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, Error *local_err = NULL; struct virtio_blk_config config = { 0 }; uint64_t features; - int i; + int i, ret; if (vblk_opts->has_num_queues) { num_queues = vblk_opts->num_queues; @@ -265,7 +265,8 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, } vblk_exp->num_queues = num_queues; vblk_exp->handler.blk = exp->blk; - vblk_exp->handler.serial = exp->id; + vblk_exp->handler.serial = g_strdup(vblk_opts->has_serial ? + vblk_opts->serial : ""); vblk_exp->handler.logical_block_size = logical_block_size; vblk_exp->handler.writable = opts->writable; @@ -306,16 +307,16 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, vblk_exp); if (!vblk_exp->dev) { error_setg(errp, "failed to create vduse device"); - return -ENOMEM; + ret = -ENOMEM; + goto err_dev; } vblk_exp->recon_file = g_strdup_printf("%s/vduse-blk-%s", g_get_tmp_dir(), exp->id); if (vduse_set_reconnect_log_file(vblk_exp->dev, vblk_exp->recon_file)) { error_setg(errp, "failed to set reconnect log file"); - vduse_dev_destroy(vblk_exp->dev); - g_free(vblk_exp->recon_file); - return -EINVAL; + ret = -EINVAL; + goto err; } for (i = 0; i < num_queues; i++) { @@ -331,6 +332,12 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, blk_set_dev_ops(exp->blk, &vduse_block_ops, exp); return 0; +err: + vduse_dev_destroy(vblk_exp->dev); + g_free(vblk_exp->recon_file); +err_dev: + g_free(vblk_exp->handler.serial); + return ret; } static void vduse_blk_exp_delete(BlockExport *exp) @@ -346,6 +353,7 @@ static void vduse_blk_exp_delete(BlockExport *exp) unlink(vblk_exp->recon_file); } g_free(vblk_exp->recon_file); + g_free(vblk_exp->handler.serial); } static void vduse_blk_exp_request_shutdown(BlockExport *exp) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c index c9c290cc4c..3409d9e02e 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -282,7 +282,7 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, return -EINVAL; } vexp->handler.blk = exp->blk; - vexp->handler.serial = "vhost_user_blk"; + vexp->handler.serial = g_strdup("vhost_user_blk"); vexp->handler.logical_block_size = logical_block_size; vexp->handler.writable = opts->writable; @@ -296,6 +296,7 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, num_queues, &vu_blk_iface, errp)) { blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, vexp); + g_free(vexp->handler.serial); return -EADDRNOTAVAIL; } @@ -308,6 +309,7 @@ static void vu_blk_exp_delete(BlockExport *exp) blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, vexp); + g_free(vexp->handler.serial); } const BlockExportDriver blk_exp_vhost_user_blk = { diff --git a/block/export/virtio-blk-handler.h b/block/export/virtio-blk-handler.h index 1c7a5e32ad..150d44cff2 100644 --- a/block/export/virtio-blk-handler.h +++ b/block/export/virtio-blk-handler.h @@ -23,7 +23,7 @@ typedef struct { BlockBackend *blk; - const char *serial; + char *serial; uint32_t logical_block_size; bool writable; } VirtioBlkHandler; diff --git a/docs/tools/qemu-storage-daemon.rst b/docs/tools/qemu-storage-daemon.rst index fbeaf76954..034f2809a6 100644 --- a/docs/tools/qemu-storage-daemon.rst +++ b/docs/tools/qemu-storage-daemon.rst @@ -77,7 +77,7 @@ Standard options: --export [type=]vhost-user-blk,id=,node-name=,addr.type=unix,addr.path=[,writable=on|off][,logical-block-size=][,num-queues=] --export [type=]vhost-user-blk,id=,node-name=,addr.type=fd,addr.str=[,writable=on|off][,logical-block-size=][,num-queues=] --export [type=]fuse,id=,node-name=,mountpoint=[,growable=on|off][,writable=on|off][,allow-other=on|off|auto] - --export [type=]vduse-blk,id=,node-name=[,writable=on|off][,num-queues=][,queue-size=][,logical-block-size=] + --export [type=]vduse-blk,id=,node-name=[,writable=on|off][,num-queues=][,queue-size=][,logical-block-size=][,serial=] is a block export definition. ``node-name`` is the block node that should be exported. ``writable`` determines whether or not the export allows write diff --git a/qapi/block-export.json b/qapi/block-export.json index e4bd4de363..d7aeb1fbf7 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -186,13 +186,15 @@ # @queue-size: the size of virtqueue. Defaults to 256. # @logical-block-size: Logical block size in bytes. Range [512, PAGE_SIZE] # and must be power of 2. Defaults to 512 bytes. +# @serial: the serial number of virtio block device. Defaults to empty string. # # Since: 7.1 ## { 'struct': 'BlockExportOptionsVduseBlk', 'data': { '*num-queues': 'uint16', '*queue-size': 'uint16', - '*logical-block-size': 'size'} } + '*logical-block-size': 'size', + '*serial': 'str' } } ## # @NbdServerAddOptions: diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c index 17fd3f2f5f..4e18d3fc85 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -126,6 +126,7 @@ static void help(void) " [,writable=on|off][,num-queues=]\n" " [,queue-size=]\n" " [,logical-block-size=]\n" +" [,serial=]\n" " export the specified block node as a vduse-blk\n" " device using the id as the VDUSE device name\n" "\n" From patchwork Tue Jun 14 05:15:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 1643120 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=dSIU/kZ/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMcL70ZV8z9sGD for ; Tue, 14 Jun 2022 15:23:57 +1000 (AEST) Received: from localhost ([::1]:42542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0z1u-0002vf-Lo for incoming@patchwork.ozlabs.org; Tue, 14 Jun 2022 01:23:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0yva-00019x-AA for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:22 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:37743) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o0yvY-00011a-Gy for qemu-devel@nongnu.org; Tue, 14 Jun 2022 01:17:22 -0400 Received: by mail-pg1-x52b.google.com with SMTP id h192so7538548pgc.4 for ; Mon, 13 Jun 2022 22:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Zitz3aw7vmqBdlw7whS7nBw2iJZB5B/SiBi5964udmY=; b=dSIU/kZ/1iHFaJIdReV8vjk47F8CkfdjUJTFYzNYUWrab42ORBObpd9f5DLMEtvpTh t/DqrTRWPBdeq98mP/R6Tn7+m7VLEGpSVxXDEqFgo6QYVn9QFii7g0GyKPxzBm5vguDU wKVtDu/8IfFl173fM7OT6HnVVprDVLxebtjHVomoxUUgsdZnr4HJu+JtzzZB2Df8GdX2 l80LOdGpEuyZcLy9Fh4Dn0xsPTuncNdQQ2iz1JiHJlNOU3c0aS28Jbi9ArSDhQKCXtgt StWRFmI8INKu3szbkPpM7LiW37fKguZChqjKzFliSxkqfsKfBen/wPX2m6MTFy20CoUJ 7KUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Zitz3aw7vmqBdlw7whS7nBw2iJZB5B/SiBi5964udmY=; b=b8GaXgCvYZnGAtWFWC9HXQYK5xSTJIq545vF3A3fB0o5xd1ipiCtAQrTJ/6nAPDJ1S ScHhYyHy7LvOAV8CyiWICSJnFYEFR14Kh/VfbQV4ZbdGtUcGsMpbihZVtu81gvP6OZcG nYbz3n2Pa99fPjJFDFYwyHyu114c85VJ47vNCmKGWOhJRl9TSDTljrkxLTiolYEY1JU8 +pssLIndngACc4lLHZDOc38IT4vD++hC2ysLMCY7GGeo2yDR6XzSbu5qS78YoaqHwhK1 jyH4gfl8kdFMp3a++fbLMrrrFV8EK7VopB/AMZ3NuW1GUycsLvKZtDdSsA4iUqiC+Sd0 FCTA== X-Gm-Message-State: AOAM533QpJpfLSDUiHzix5PhxVOrHfWEP3g6Gok+U7Q5wcGHUfOIHHjQ L/TSbCv9aIndzY9EssqCgckH X-Google-Smtp-Source: ABdhPJykDqPxH6wJ14EFtO/7KpPCuIXwdrT1L/YHHnL8S407efxup19vAoRteEs2dKnPrPssBXkzoQ== X-Received: by 2002:a05:6a00:1253:b0:51c:e1e:9990 with SMTP id u19-20020a056a00125300b0051c0e1e9990mr2945584pfi.5.1655183838276; Mon, 13 Jun 2022 22:17:18 -0700 (PDT) Received: from localhost ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id v17-20020a62c311000000b0050dc762816asm6366175pfg.68.2022.06.13.22.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 22:17:17 -0700 (PDT) From: Xie Yongji To: kwolf@redhat.com, stefanha@redhat.com Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 6/6] vduse-blk: Add name option Date: Tue, 14 Jun 2022 13:15:32 +0800 Message-Id: <20220614051532.92-7-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220614051532.92-1-xieyongji@bytedance.com> References: <20220614051532.92-1-xieyongji@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=xieyongji@bytedance.com; helo=mail-pg1-x52b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Currently we use 'id' option as the name of VDUSE device. It's a bit confusing since we use one value for two different purposes: the ID to identfy the export within QEMU (must be distinct from any other exports in the same QEMU process, but can overlap with names used by other processes), and the VDUSE name to uniquely identify it on the host (must be distinct from other VDUSE devices on the same host, but can overlap with other export types like NBD in the same process). To make it clear, this patch adds a separate 'name' option to specify the VDUSE name for the vduse-blk export instead. Signed-off-by: Xie Yongji --- block/export/vduse-blk.c | 4 ++-- docs/tools/qemu-storage-daemon.rst | 5 +++-- qapi/block-export.json | 7 ++++--- storage-daemon/qemu-storage-daemon.c | 8 ++++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c index 066e088b00..f101c24c3f 100644 --- a/block/export/vduse-blk.c +++ b/block/export/vduse-blk.c @@ -300,7 +300,7 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, features |= 1ULL << VIRTIO_BLK_F_RO; } - vblk_exp->dev = vduse_dev_create(exp->id, VIRTIO_ID_BLOCK, 0, + vblk_exp->dev = vduse_dev_create(vblk_opts->name, VIRTIO_ID_BLOCK, 0, features, num_queues, sizeof(struct virtio_blk_config), (char *)&config, &vduse_blk_ops, @@ -312,7 +312,7 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, } vblk_exp->recon_file = g_strdup_printf("%s/vduse-blk-%s", - g_get_tmp_dir(), exp->id); + g_get_tmp_dir(), vblk_opts->name); if (vduse_set_reconnect_log_file(vblk_exp->dev, vblk_exp->recon_file)) { error_setg(errp, "failed to set reconnect log file"); ret = -EINVAL; diff --git a/docs/tools/qemu-storage-daemon.rst b/docs/tools/qemu-storage-daemon.rst index 034f2809a6..ea00149a63 100644 --- a/docs/tools/qemu-storage-daemon.rst +++ b/docs/tools/qemu-storage-daemon.rst @@ -77,7 +77,7 @@ Standard options: --export [type=]vhost-user-blk,id=,node-name=,addr.type=unix,addr.path=[,writable=on|off][,logical-block-size=][,num-queues=] --export [type=]vhost-user-blk,id=,node-name=,addr.type=fd,addr.str=[,writable=on|off][,logical-block-size=][,num-queues=] --export [type=]fuse,id=,node-name=,mountpoint=[,growable=on|off][,writable=on|off][,allow-other=on|off|auto] - --export [type=]vduse-blk,id=,node-name=[,writable=on|off][,num-queues=][,queue-size=][,logical-block-size=][,serial=] + --export [type=]vduse-blk,id=,node-name=,name=[,writable=on|off][,num-queues=][,queue-size=][,logical-block-size=][,serial=] is a block export definition. ``node-name`` is the block node that should be exported. ``writable`` determines whether or not the export allows write @@ -111,7 +111,8 @@ Standard options: ``allow-other`` to auto (the default) will try enabling this option, and on error fall back to disabling it. - The ``vduse-blk`` export type uses the ``id`` as the VDUSE device name. + The ``vduse-blk`` export type takes a ``name`` (must be unique across the host) + to create the VDUSE device. ``num-queues`` sets the number of virtqueues (the default is 1). ``queue-size`` sets the virtqueue descriptor table size (the default is 256). diff --git a/qapi/block-export.json b/qapi/block-export.json index d7aeb1fbf7..81ef1e3dcd 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -182,6 +182,7 @@ # # A vduse-blk block export. # +# @name: the name of VDUSE device (must be unique across the host). # @num-queues: the number of virtqueues. Defaults to 1. # @queue-size: the size of virtqueue. Defaults to 256. # @logical-block-size: Logical block size in bytes. Range [512, PAGE_SIZE] @@ -191,7 +192,8 @@ # Since: 7.1 ## { 'struct': 'BlockExportOptionsVduseBlk', - 'data': { '*num-queues': 'uint16', + 'data': { 'name': 'str', + '*num-queues': 'uint16', '*queue-size': 'uint16', '*logical-block-size': 'size', '*serial': 'str' } } @@ -316,8 +318,7 @@ # Describes a block export, i.e. how single node should be exported on an # external interface. # -# @id: A unique identifier for the block export (across the host for vduse-blk -# export type or across all export types for other types) +# @id: A unique identifier for the block export (across all export types) # # @node-name: The node name of the block node to be exported (since: 5.2) # diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c index 4e18d3fc85..b8e910f220 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -123,12 +123,12 @@ static void help(void) #endif /* CONFIG_VHOST_USER_BLK_SERVER */ #ifdef CONFIG_VDUSE_BLK_EXPORT " --export [type=]vduse-blk,id=,node-name=\n" -" [,writable=on|off][,num-queues=]\n" -" [,queue-size=]\n" +" ,name=[,writable=on|off]\n" +" [,num-queues=][,queue-size=]\n" " [,logical-block-size=]\n" " [,serial=]\n" -" export the specified block node as a vduse-blk\n" -" device using the id as the VDUSE device name\n" +" export the specified block node as a\n" +" vduse-blk device\n" "\n" #endif /* CONFIG_VDUSE_BLK_EXPORT */ " --monitor [chardev=]name[,mode=control][,pretty[=on|off]]\n"