From nobody Fri May 3 17:25:40 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622727543; cv=none; d=zohomail.com; s=zohoarc; b=fGvRQN8yB1V4yrCpisVq0G6meMJlDjOxiGPx9XaXk+uMBBQc82efeMqhOCYdphgAHdqa85zwVSuk/yv1Pb8BoqMAs7vLlhUPW8JGRDgh/LmQuDvKoMYXOdShG1ULjnSVTK4m4RHK9XCJSxLSlUdpgSKhbNwFG78aAkE1BHGrm+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622727543; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ol7E5OOtSGud4DEQz+1bUjAViRDPBgiG2mSFKt001ck=; b=TUBCdacZP61TLyxXZbZKPWVMTz0OPj/Le2nT8i+IKaSaGn/yYHd2nStrKWdQjWWQxy+iWime8HMsvjaWllkqb5ankNGB7O1gzY4r70NVAciBEnCWnmvhNhJRrvRk+cPznAgy2u23kW+E8VblDKbvt6DJjmG5c6YM0UMyjJPUdN0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622727543965162.91559988724487; Thu, 3 Jun 2021 06:39:03 -0700 (PDT) Received: from localhost ([::1]:54032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lonYs-0005I6-QC for importer2@patchew.org; Thu, 03 Jun 2021 09:39:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lonXV-0002w2-1n; Thu, 03 Jun 2021 09:37:37 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:37711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lonXT-00005B-DD; Thu, 03 Jun 2021 09:37:36 -0400 Received: by mail-ej1-x62d.google.com with SMTP id ce15so9292370ejb.4; Thu, 03 Jun 2021 06:37:33 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id e24sm1555369ejb.52.2021.06.03.06.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 06:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ol7E5OOtSGud4DEQz+1bUjAViRDPBgiG2mSFKt001ck=; b=Gf25VDbzE1taoFRfi3VPPMtoGjW/wWKT+6/pdf2thxqHYKmNpTHDGSIU6cawiUJzCQ +/GkeE53cphJy0jXFbgfwzZMQ8iLde8UwDAF4kh5p2kW3oZIpSGm0L9WbWIjxP85CZot Bwgmq9UYAjEjV0r+87nURyzoJbuyGJ3TvC7qpFQ1hitiSU1n6gprOeWFfdAdV0xgJf9Q KXjVa33HKU90jVl5sCfn3JJI2sN9q/5Lbb1SnUrg8QcYIxww8gjoVRIloeJolUKwb+UA FpUQSwwLqF5u6A0iFB21xhNn9eAZNYccbE2snWTdI7czHmkSzCmLXhzX0C0xWFzhcreO oHiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ol7E5OOtSGud4DEQz+1bUjAViRDPBgiG2mSFKt001ck=; b=hIR5tEblDZkUChiJdr41ZtF3f1k/LSrUsl8cB1tZmj1d9Gog3h+ZP0Y0WOxzq1/g75 OTOapfFSNV+h63/ppOFc9VYoviBYL+6CLyHTTHdLOhDPUf2j06k4zqzvERKN8XjazkHU nvBAp40QZttEyFcFBIxPnojBC2sXRYUksoimQeyKWxmVrppuCHLFsxI/VwDHaOHCiQrP 4maboL5QiJUniPc+wrY76Xded7jCDC6AsWAAVn4BvbMRAZKa7JigsBDGRxgE8z8Yo09L hU+6RSRuOiglHhphHOs/OXfwZaKnfGGJL3tSEow9dXLUPfBqZjJggyPzSt3eJGtSrT1t gRMA== X-Gm-Message-State: AOAM533bXPcJ6ducuNk3ogafvN8yyQ/bedQXuVRHq5ou1OtLLzDduumJ T9EZPJ035KiMlbP8fIaZPsycnjletoPTGA== X-Google-Smtp-Source: ABdhPJx1by8TaukJ7G5L/DK4ADdY6m48LVDcidQytL1MA3cqf/YCsCd6XDwlm1P/FhhLt2Rwk8OKeg== X-Received: by 2002:a17:906:b0c9:: with SMTP id bk9mr39107009ejb.517.1622727452276; Thu, 03 Jun 2021 06:37:32 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v3 1/7] file-posix: fix max_iov for /dev/sg devices Date: Thu, 3 Jun 2021 15:37:16 +0200 Message-Id: <20210603133722.218465-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210603133722.218465-1-pbonzini@redhat.com> References: <20210603133722.218465-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Even though it was only called for devices that have bs->sg set (which must be character devices), sg_get_max_segments looked at /sys/dev/block which only works for block devices. On Linux the sg driver has its own way to provide the maximum number of iovecs in a scatter/gather list. Signed-off-by: Paolo Bonzini Reviewed-by: Max Reitz --- block/file-posix.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index f37dfc10b3..58db526cc2 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1180,6 +1180,17 @@ static int sg_get_max_segments(int fd) goto out; } =20 + if (S_ISCHR(st->st_mode)) { + if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) =3D=3D 0) { + return ret; + } + return -EIO; + } + + if (!S_ISBLK(st->st_mode)) { + return -ENOTSUP; + } + sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments= ", major(st.st_rdev), minor(st.st_rdev)); sysfd =3D open(sysfspath, O_RDONLY); --=20 2.31.1 From nobody Fri May 3 17:25:40 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622727545; cv=none; d=zohomail.com; s=zohoarc; b=bt0m9K6cBAh+VwNhQ0wAjucLPr27zRKG79RNB2Jy9GAHSnX21+dAbYEqCv9KSvj4Un6CHKU8uy/EbllLMX4qLYYCeTt2Qdz82AKwQlV+xn23EymnQfll/h1HklxzjLlKerR5RkYx/tcDMoVwe/iEbdRyh2qDhiDcjfbs6slB/0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622727545; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vbYfEBjMJnHzWkw4pPc6Wcc79dlc0TcTnsXCmhSPV+E=; b=J9lx6l8/WK3Q4cGGsGimMJOGo3CeHzyoL3iXt9GRweVIhB4spaSr997meQHgtiFs2EGioUdsCitpKX4piZwisk/WWD6dqnDREyFUlnFWFV+nVpqoQCq8dGHpRb1qJkQJcPt3jGJgURWBKZwXh9YfxPzg3vOfcmAXX7kjAENeCX4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16227275458510.7095642119166996; Thu, 3 Jun 2021 06:39:05 -0700 (PDT) Received: from localhost ([::1]:54186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lonYu-0005O6-Ow for importer2@patchew.org; Thu, 03 Jun 2021 09:39:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lonXV-0002x9-Jx; Thu, 03 Jun 2021 09:37:37 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]:39662) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lonXT-00006F-VI; Thu, 03 Jun 2021 09:37:37 -0400 Received: by mail-ed1-x534.google.com with SMTP id dj8so7164204edb.6; Thu, 03 Jun 2021 06:37:34 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id e24sm1555369ejb.52.2021.06.03.06.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 06:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vbYfEBjMJnHzWkw4pPc6Wcc79dlc0TcTnsXCmhSPV+E=; b=tdML921oBxDGd94yOU2xLmbz86p1Vv5d3Gtr9UMczuB+14vDpfgUl4J/fSrEe8RnrU y1XvRCFvuoxe+b8FgpOZrszh9JEcCd3nQ6f5SxdKJOdo7oO9yNDPxfmrQDuXergxqMF5 rMEH3nxPzHbBnztANQg++d9/qDTO5vL2Znb9e5uNIr+HsP2EVD8gJ2fuXbonNr8hFEDx LaveP0E5O5ebyVW3OCoxhqV6CwXnLSO7LQ/950IbJVVDWpbTT8Kxbz8tRFmGVkXjbo76 yPvqH1Djzg9PzCW7ndkL73r6OjiU+1QmU3/HqdHaToIacR08joRar6pcnxkN4dot72yl zLpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=vbYfEBjMJnHzWkw4pPc6Wcc79dlc0TcTnsXCmhSPV+E=; b=Q9agVd0HXuYs0qjjPVag3gMiapbyUAxSPFcn6JJqtPkRcfCi0qb1YTjlOMv/pX+csi 0GI6nIFSDiiJBhsEFvAbFItDLDd35GSllbYIwclkHhSlQAapzeyqDFioAgNfv+zAY6nj kGOOJS7arx/uT9xbPY6sJ8OIzMauV7AOsn6Mk7lkv/Cl65BhhDKUn4t5911oFY3neaqe z0F3TCQgRD7Y9VvL8KSKtWm2eZ7EO791lJCMMu9b9Q20k9JklaiFAZ2omXWY1S3OP+cp ft52q6bW4l65a7OSyIyUgqJ8KNDU2aza26czA16RyCBValIoIx2LohUTlYXPKfJE0ws4 DQbg== X-Gm-Message-State: AOAM531r9Rmi8Tw5i+8lUnw6rPRo/MVNk2cFeX3VLvvE2zpMmfy7niPw yyxtk3ypKD6UKMOMAtdFW9nAYe6HJTPsuw== X-Google-Smtp-Source: ABdhPJzZd0llU/EsJdvHjhmZwriRi1j+LMYOhE3494/MNauVLbTm7EFF7dclSzz9RaR3DLkZNIcsqw== X-Received: by 2002:a50:8e44:: with SMTP id 4mr44119663edx.244.1622727453209; Thu, 03 Jun 2021 06:37:33 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v3 2/7] scsi-generic: pass max_segments via max_iov field in BlockLimits Date: Thu, 3 Jun 2021 15:37:17 +0200 Message-Id: <20210603133722.218465-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210603133722.218465-1-pbonzini@redhat.com> References: <20210603133722.218465-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x534.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" I/O to a disk via read/write is not limited by the number of segments allow= ed by the host adapter; the kernel can split requests if needed, and the limit imposed by the host adapter can be very low (256k or so) to avoid that SG_IO returns EINVAL if memory is heavily fragmented. Since this value is only interesting for SG_IO-based I/O, do not include it in the max_transfer and only take it into account when patching the block limits VPD page in the scsi-generic device. Signed-off-by: Paolo Bonzini Reviewed-by: Max Reitz --- block/file-posix.c | 3 +-- hw/scsi/scsi-generic.c | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 58db526cc2..e3241a0dd3 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1239,8 +1239,7 @@ static void raw_refresh_limits(BlockDriverState *bs, = Error **errp) =20 ret =3D sg_get_max_segments(s->fd); if (ret > 0) { - bs->bl.max_transfer =3D MIN(bs->bl.max_transfer, - ret * qemu_real_host_page_size); + bs->bl.max_iov =3D ret; } } =20 diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 98c30c5d5c..82e1e2ee79 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -179,10 +179,12 @@ static void scsi_handle_inquiry_reply(SCSIGenericReq = *r, SCSIDevice *s) (r->req.cmd.buf[1] & 0x01)) { page =3D r->req.cmd.buf[2]; if (page =3D=3D 0xb0) { - uint32_t max_transfer =3D - blk_get_max_transfer(s->conf.blk) / s->blocksize; + uint32_t max_transfer =3D blk_get_max_transfer(s->conf.blk); + uint32_t max_iov =3D blk_get_max_iov(s->conf.blk); =20 assert(max_transfer); + max_transfer =3D MIN_NON_ZERO(max_transfer, max_iov * qemu_rea= l_host_page_size) + / s->blocksize; stl_be_p(&r->buf[8], max_transfer); /* Also take care of the opt xfer len. */ stl_be_p(&r->buf[12], --=20 2.31.1 From nobody Fri May 3 17:25:40 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622727659; cv=none; d=zohomail.com; s=zohoarc; b=ZjiaP2iDMjpoVyhIXoVAx4LqiNT5t9cg3iRrqxDzBOQhOr2gOfebH4Sgtr0cgWTqEOrHLpyzdyL/QQ0To4YMfT2KDnHqVUUmElC9uAeCVv3ZtW7CqkkhKUTgnZJUDgxxpVxxq3Wasm/ZUivAZ2xGlu2hcbdWXaVv5+9EXx6CdVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622727659; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TXk60Ue5UcMQghXgK7HFTeenuUtizKd8R3ZkiQqwPxM=; b=Cvy/7jXF/oP7qwff8qIOGJtA0IG7VogC5zIOy/PlvFZqAnLp31I3wOmgvJLGlCGGdg9dmURHGVbK8FlSulTcvbB9qL+/zZl0t4UbV9+omtvGmpJmwsnjouvufS4+f45FxZSYU6S9ezvNFQli5llRjkI73HvxNRDD3jpfxlOGuOU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622727659555394.76263437590364; Thu, 3 Jun 2021 06:40:59 -0700 (PDT) Received: from localhost ([::1]:32774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lonak-0001cp-Ir for importer2@patchew.org; Thu, 03 Jun 2021 09:40:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lonXW-0002yv-EV; Thu, 03 Jun 2021 09:37:38 -0400 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]:40713) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lonXU-00006U-Lb; Thu, 03 Jun 2021 09:37:38 -0400 Received: by mail-ed1-x536.google.com with SMTP id t3so7142751edc.7; Thu, 03 Jun 2021 06:37:35 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id e24sm1555369ejb.52.2021.06.03.06.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 06:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TXk60Ue5UcMQghXgK7HFTeenuUtizKd8R3ZkiQqwPxM=; b=a7LBLBLn7n55lvwYez12DWKDP15zijb0aCH7kFWnl+DqnaxV33Y/bPMpQZPNy3y1j7 beGBe8uzkSTorkqFhcze+0s85b7Sl+mk5/tiAShf1qEKGsoEP0Y9zsfPugVXO5hd/x9B L8A/auKHi36j+frChE2rMWF1i0ZFcN1tcKvHYdet6oGT3lNJE3XdHAO8CArhIHbGUovR OJx75WHorfwLrtLBJFWf2f/04NHZ68PNkeu0+DepDOQR6HY1r8pPL87pOFou7G5Qg7eG s7jBO5GC5zwnY1hFTdqxHvOzrAIeGtpp+MvMf7eBmexRKa8MyDYQMu1MrquveVPHBGrv uxqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=TXk60Ue5UcMQghXgK7HFTeenuUtizKd8R3ZkiQqwPxM=; b=IHGXwd0TZgJU6v0ONXZCIB1FfTkDCfC2crgK2tawzBn9f+sBuYNsZ8NvoMdH0S55tA GS2dKMor+id5dow3eGUqtaZDdqFzkodNKgE6UyRhnSNhqYKLOKm7WBuTUuVN+1ozDjjI LVmHoPxyW5jo412NeNXuGTUqNq8oLjkceZJ5n30sAxOiWCYRXf/d6NWHl10Q98NL7LtG tdXP30oDsT6CMsIubix3WaYjn+f4h5RCLoGkbsJL6LUbzJ68LbpE/fg31+wN4KlTcYb8 9L0A+CsWGTrl10TvwBkqhAk5jB198gnjXeKqkB12Z9J2sVSthSVrIwttEk3AucI8QpcV 8i0A== X-Gm-Message-State: AOAM530aIToi5OCsu6f8abZIwHsZkntthESUVkLKucBG8+YUr04ZyGQf IiZFBKOc1rW+brRQGY5t0r2aLeQ5/T77Qg== X-Google-Smtp-Source: ABdhPJyH3fniqfEat9ZF3VHP9GxiY53Uy8bvgo5n/w7gFFzLgPplVVMztsSHx0OFB9713lheDM+lWQ== X-Received: by 2002:a05:6402:152:: with SMTP id s18mr43169986edu.221.1622727454016; Thu, 03 Jun 2021 06:37:34 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v3 3/7] block: add max_hw_transfer to BlockLimits Date: Thu, 3 Jun 2021 15:37:18 +0200 Message-Id: <20210603133722.218465-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210603133722.218465-1-pbonzini@redhat.com> References: <20210603133722.218465-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x536.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For block host devices, I/O can happen through either the kernel file descriptor I/O system calls (preadv/pwritev, io_submit, io_uring) or the SCSI passthrough ioctl SG_IO. In the latter case, the size of each transfer can be limited by the HBA, while for file descriptor I/O the kernel is able to split and merge I/O in smaller pieces as needed. Applying the HBA limits to file descriptor I/O results in more system calls and suboptimal performance, so this patch splits the max_transfer limit in two: max_transfer remains valid and is used in general, while max_hw_transfer is limited to the maximum hardware size. max_hw_transfer can then be included by the scsi-generic driver in the block limits page, to ensure that the stricter hardware limit is used. Signed-off-by: Paolo Bonzini --- block/block-backend.c | 12 ++++++++++++ block/file-posix.c | 2 +- block/io.c | 1 + hw/scsi/scsi-generic.c | 2 +- include/block/block_int.h | 7 +++++++ include/sysemu/block-backend.h | 1 + 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 15f1ea4288..2ea1412a54 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1953,6 +1953,18 @@ uint32_t blk_get_request_alignment(BlockBackend *blk) return bs ? bs->bl.request_alignment : BDRV_SECTOR_SIZE; } =20 +/* Returns the maximum hardware transfer length, in bytes; guaranteed nonz= ero */ +uint64_t blk_get_max_hw_transfer(BlockBackend *blk) +{ + BlockDriverState *bs =3D blk_bs(blk); + uint64_t max =3D INT_MAX; + + if (bs) { + max =3D MIN_NON_ZERO(bs->bl.max_hw_transfer, bs->bl.max_transfer); + } + return max; +} + /* Returns the maximum transfer length, in bytes; guaranteed nonzero */ uint32_t blk_get_max_transfer(BlockBackend *blk) { diff --git a/block/file-posix.c b/block/file-posix.c index e3241a0dd3..f55f92d0f5 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1234,7 +1234,7 @@ static void raw_refresh_limits(BlockDriverState *bs, = Error **errp) int ret =3D sg_get_max_transfer_length(s->fd); =20 if (ret > 0 && ret <=3D BDRV_REQUEST_MAX_BYTES) { - bs->bl.max_transfer =3D pow2floor(ret); + bs->bl.max_hw_transfer =3D pow2floor(ret); } =20 ret =3D sg_get_max_segments(s->fd); diff --git a/block/io.c b/block/io.c index 323854d063..089b99bb0c 100644 --- a/block/io.c +++ b/block/io.c @@ -127,6 +127,7 @@ static void bdrv_merge_limits(BlockLimits *dst, const B= lockLimits *src) { dst->opt_transfer =3D MAX(dst->opt_transfer, src->opt_transfer); dst->max_transfer =3D MIN_NON_ZERO(dst->max_transfer, src->max_transfe= r); + dst->max_hw_transfer =3D MIN_NON_ZERO(dst->max_hw_transfer, src->max_h= w_transfer); dst->opt_mem_alignment =3D MAX(dst->opt_mem_alignment, src->opt_mem_alignment); dst->min_mem_alignment =3D MAX(dst->min_mem_alignment, diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 82e1e2ee79..3762dce749 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -179,7 +179,7 @@ static void scsi_handle_inquiry_reply(SCSIGenericReq *r= , SCSIDevice *s) (r->req.cmd.buf[1] & 0x01)) { page =3D r->req.cmd.buf[2]; if (page =3D=3D 0xb0) { - uint32_t max_transfer =3D blk_get_max_transfer(s->conf.blk); + uint64_t max_transfer =3D blk_get_max_hw_transfer(s->conf.blk); uint32_t max_iov =3D blk_get_max_iov(s->conf.blk); =20 assert(max_transfer); diff --git a/include/block/block_int.h b/include/block/block_int.h index 057d88b1fc..f1a54db0f8 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -695,6 +695,13 @@ typedef struct BlockLimits { * clamped down. */ uint32_t max_transfer; =20 + /* Maximal hardware transfer length in bytes. Applies whenever + * transfers to the device bypass the kernel I/O scheduler, for + * example with SG_IO. If larger than max_transfer or if zero, + * blk_get_max_hw_transfer will fall back to max_transfer. + */ + uint64_t max_hw_transfer; + /* memory alignment, in bytes so that no bounce buffer is needed */ size_t min_mem_alignment; =20 diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 5423e3d9c6..9ac5f7bbd3 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -208,6 +208,7 @@ void blk_eject(BlockBackend *blk, bool eject_flag); int blk_get_flags(BlockBackend *blk); uint32_t blk_get_request_alignment(BlockBackend *blk); uint32_t blk_get_max_transfer(BlockBackend *blk); +uint64_t blk_get_max_hw_transfer(BlockBackend *blk); int blk_get_max_iov(BlockBackend *blk); void blk_set_guest_block_size(BlockBackend *blk, int align); void *blk_try_blockalign(BlockBackend *blk, size_t size); --=20 2.31.1 From nobody Fri May 3 17:25:40 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622727643; cv=none; d=zohomail.com; s=zohoarc; b=cPPA5wuoynbC6cB7t3vQe724UjUvQ94KfheZEL/8VhTKEjjP0TrxMnIElw3UzU+XSSn2bXeP0DW0KD80bIEESBNSjfH7fRudQYHAobTcs6jjg5HHgym3GnfN0CPWhWXdBPGgxwN4tBJ4AksmVChN42t53VH0rEfBazZ3gx3AtQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622727643; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7UAZdz5dQs7FMRLCi+6byKh+otX+O5RQQ9i+ZxcAI5g=; b=IQ6CLR3Z1qVNKtUK5I/V2jfuTTlnmtxEXa4jVQqrBiKNqBnZFPXZe84mgTU/h9QqtR15eiZHZZUr0if2h80r4YUV0pIvBwn+2MTk51up75+goUTUE4Rwq5081dN2+tJIe1hqsD5Q17jXl+NfWQZKqPskrIKy+DAY/MKO2eC3xG8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622727643024162.63950717166063; Thu, 3 Jun 2021 06:40:43 -0700 (PDT) Received: from localhost ([::1]:60702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lonaU-0001P6-1n for importer2@patchew.org; Thu, 03 Jun 2021 09:40:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lonXW-0002yF-80; Thu, 03 Jun 2021 09:37:38 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:40702) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lonXU-00007m-LK; Thu, 03 Jun 2021 09:37:37 -0400 Received: by mail-ed1-x52a.google.com with SMTP id t3so7142808edc.7; Thu, 03 Jun 2021 06:37:35 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id e24sm1555369ejb.52.2021.06.03.06.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 06:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7UAZdz5dQs7FMRLCi+6byKh+otX+O5RQQ9i+ZxcAI5g=; b=lrvGRs/lggaUJjrVirwjaik3/uHYyeye0NG36RG41WzzH747K12ANbXBlFIL3YCmBc 6PbS1tWA7nw4XKasH7vqrdmq3HbEX7ChgcV2cWvxm73D7NEUikRRQ/bHJXjIujmnKM+3 0PGrWb2aFLfuc9J/R9dc5sGqCbgtmW9kntN46PvTqeLCttI0iwmeM4TYWafgjNUpjDs6 heEsiiNE3Qqvgg0SuBGj+2stnbEcHAHNKcDQCn6U+AjZ6EX5TTLPCIXpxbmWS1s3xLsh ojGaK1eWyHpcptJU+eTgICXc4XN3v2/AVr7WPmtUjLWWI3D3AkbfM/vwAlQC/+8cmuG6 XEMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=7UAZdz5dQs7FMRLCi+6byKh+otX+O5RQQ9i+ZxcAI5g=; b=syPIgWzwFS3oTu4XgFJ3lm+DuaTws3es7RdVHLb/6Vg60n6c3JMhFyacQk3cInPrtw yKee+/jbU6qf+c666++TqnhtzCJgzYReALExe+wcRS4qIwOhCm96GjfSFDe74xvvvfHj jMLd8NQnIzMkRNw9zXtrNJvlEA7+giNdl0Fc7t1g3wtp/SQosfLu/9deRZsjDCSka1QS gVVzR5qcrkBwPat5yiCpFAtUDnDVod7rQ0N1wWh/JBzbB2Gu4zyaV7Qp6JCka5ihNGeu +zPWP37whgK5yUgMSZnSRDXFFrSAVImh+tFNOFkBzl7q7ykS2M3nPuw+HKu/DooaAQy5 dIww== X-Gm-Message-State: AOAM530NFrgx8lOZ95WXegHp4zJ5SuEFcNxFARjxYU/pb/yIwLbiDfkM a2t+5jfkZ3kIw+umb40cpMQUayKDG/dM2Q== X-Google-Smtp-Source: ABdhPJxtdMlhkmLdTI4RHhf8hCkvuwwhmA75nzvXjAmRKSl1sig5gL9TR6sLpSPoo2sTRjARKXfB/A== X-Received: by 2002:a50:eb08:: with SMTP id y8mr44358794edp.89.1622727454781; Thu, 03 Jun 2021 06:37:34 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v3 4/7] file-posix: try BLKSECTGET on block devices too, do not round to power of 2 Date: Thu, 3 Jun 2021 15:37:19 +0200 Message-Id: <20210603133722.218465-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210603133722.218465-1-pbonzini@redhat.com> References: <20210603133722.218465-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52a.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" bs->sg is only true for character devices, but block devices can also be used with scsi-block and scsi-generic. Unfortunately BLKSECTGET returns bytes in an int for /dev/sgN devices, and sectors in a short for block devices, so account for that in the code. The maximum transfer also need not be a power of 2 (for example I have seen disks with 1280 KiB maximum transfer) so there's no need to pass the result through pow2floor. This patch reintroduces the logic that was removed in commit 867eccfed8 ("file-posix: Use max transfer length/segment count only for SCSI passthrough", 2019-07-12). The removal was motivated by the performance regression when using a block device's max_transfer with kernel I/O; the new, separate max_hw_transfer limit avoids reintroducing the same regression. Signed-off-by: Paolo Bonzini --- block/file-posix.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index f55f92d0f5..1439293f63 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1149,22 +1149,27 @@ static void raw_reopen_abort(BDRVReopenState *state) s->reopen_state =3D NULL; } =20 -static int sg_get_max_transfer_length(int fd) +static int hdev_get_max_hw_transfer(int fd, struct stat *st) { #ifdef BLKSECTGET - int max_bytes =3D 0; - - if (ioctl(fd, BLKSECTGET, &max_bytes) =3D=3D 0) { - return max_bytes; + if (S_ISBLK(st->st_mode)) { + unsigned short max_sectors =3D 0; + if (ioctl(fd, BLKSECTGET, &max_sectors) =3D=3D 0) { + return max_sectors * 512; + } } else { - return -errno; + int max_bytes =3D 0; + if (ioctl(fd, BLKSECTGET, &max_bytes) =3D=3D 0) { + return max_bytes; + } } + return -errno; #else return -ENOSYS; #endif } =20 -static int sg_get_max_segments(int fd) +static int hdev_get_max_segments(int fd, struct stat *st) { #ifdef CONFIG_LINUX char buf[32]; @@ -1173,12 +1178,6 @@ static int sg_get_max_segments(int fd) int ret; int sysfd =3D -1; long max_segments; - struct stat st; - - if (fstat(fd, &st)) { - ret =3D -errno; - goto out; - } =20 if (S_ISCHR(st->st_mode)) { if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) =3D=3D 0) { @@ -1192,7 +1191,7 @@ static int sg_get_max_segments(int fd) } =20 sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments= ", - major(st.st_rdev), minor(st.st_rdev)); + major(st->st_rdev), minor(st->st_rdev)); sysfd =3D open(sysfspath, O_RDONLY); if (sysfd =3D=3D -1) { ret =3D -errno; @@ -1229,15 +1228,20 @@ out: static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s =3D bs->opaque; + struct stat st; + + if (fstat(s->fd, &st)) { + return; + } =20 - if (bs->sg) { - int ret =3D sg_get_max_transfer_length(s->fd); + if (bs->sg || S_ISBLK(st.st_mode)) { + int ret =3D hdev_get_max_hw_transfer(s->fd, &st); =20 if (ret > 0 && ret <=3D BDRV_REQUEST_MAX_BYTES) { - bs->bl.max_hw_transfer =3D pow2floor(ret); + bs->bl.max_hw_transfer =3D ret; } =20 - ret =3D sg_get_max_segments(s->fd); + ret =3D hdev_get_max_segments(s->fd, &st); if (ret > 0) { bs->bl.max_iov =3D ret; } --=20 2.31.1 From nobody Fri May 3 17:25:40 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622727773; cv=none; d=zohomail.com; s=zohoarc; b=O4z1uGQ4ivwbDSzUcieRkCpiea88zbiWrq3lVewG1K4GbVIpKRJyZscLKZl0mgagOiFGLwbaEKReAG/vqsKR/P0HseJrQK3e0Lalaf2LRiwX8Xf/2zV6rkS0DNa1IzjFpworuh5h4Uhht1yDllu+y0P6xfTPkg3NmhLGol3TdVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622727773; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qIrFxkpuGXtIV+9EMRvjcnSutFmqrJXoTEv9Vpq96gE=; b=P9lN01Z5EX/wZqHHj56krBjYnpGFFBesQJ6u7gtDM1Fd1PQ9O0eKu3T3nsyYJoW11vVJQ4pmpjrLz7YJKqKsvnbWd7sSnZ7zyuhbvhs7+Xn+5+6oLXtqUmsbvSmPIRwbGL5rYAPlQJls1Vi6gRI55Zv/M4fAcFwE2rYwCe3Q7f8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622727773991708.2014582472445; Thu, 3 Jun 2021 06:42:53 -0700 (PDT) Received: from localhost ([::1]:39348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lonca-0006DX-Uz for importer2@patchew.org; Thu, 03 Jun 2021 09:42:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lonXX-00032e-Ox; Thu, 03 Jun 2021 09:37:39 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]:34462) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lonXV-00009K-Cj; Thu, 03 Jun 2021 09:37:39 -0400 Received: by mail-ed1-x531.google.com with SMTP id cb9so7184701edb.1; Thu, 03 Jun 2021 06:37:36 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id e24sm1555369ejb.52.2021.06.03.06.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 06:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qIrFxkpuGXtIV+9EMRvjcnSutFmqrJXoTEv9Vpq96gE=; b=oN6jqBue4ShFgKipmHCnoWAU3ag7udIjN0R5rQqJ+Ihf4azl6cgKpXTbrgA39m+3Fw 6Acd0PEqPmW2Mw+YA0Qppc6hHF0Tik7UIshNr+mEpvTIWMRLyA8ej/qzMMaCoLiVE3/n RMSkwfkS661ynOUPdwTJR6L0dtRuPQF0IcbqOQj1CVcmB0F6M9OlGNbMvLQh7SbhU7Lg 2wkt+l09V3zsI0J7N4ykSNpr4t4WDP1rQN+B60uClEql8IUZwEfpwtulUSV3AjcVO7yL dsPRd0ZotxtXOR3GXut3ClL/ECWdH5UtXb77pHwd5zZFtxjK2i7MCFGpc2oVx1EDynRD rNqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=qIrFxkpuGXtIV+9EMRvjcnSutFmqrJXoTEv9Vpq96gE=; b=E3YaLQvE2zfnRYQoxwh+kWtctSYQfdHk1hkwpJGMYTinjS8LH0vuUnkXuoiDjmrrLw cx4UI8gFO0MPoCZlHf99G2L/EjjB6sY/VpjTKRKhTBXxnHTjIaBQ0fKXojgtVKZZcQqp c2ZHbpddrvELkJhFW50PB+idagYGq0NSf0rpVOdt9vT0e+PLsLXwVdrkSzC3Gb/l6MoL dBJit8AqZ1vgz93vkdciz9gQQD9x2fegWMySqrlzgRQ0jxXCokLz1+MzAxRRDcuccYne zP6aGMwvaAZtG0D+t9TQNkAQ/77MUQfzzALtZGPCtxQs3DnwLE6++VI+JE/T+7C980iM bvIw== X-Gm-Message-State: AOAM530IFZtfbWQCZccrje0lvtCboHW8XdQJGsuEwB8XvEGM+YTtw2Qm m0H3mSzuy2yc1iUf8rdiOzXxloDl2CrsCg== X-Google-Smtp-Source: ABdhPJy1PfyxNep9Uo9hdj7n2CVxskOcvf3LJG10Otz1c+UuQQhhchMXz0r5c4yFnW72z2gl9xcprw== X-Received: by 2002:a05:6402:1bd1:: with SMTP id ch17mr1185125edb.357.1622727455705; Thu, 03 Jun 2021 06:37:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v3 5/7] block: feature detection for host block support Date: Thu, 3 Jun 2021 15:37:20 +0200 Message-Id: <20210603133722.218465-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210603133722.218465-1-pbonzini@redhat.com> References: <20210603133722.218465-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::531; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x531.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Joelle van Dyne , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Joelle van Dyne On Darwin (iOS), there are no system level APIs for directly accessing host block devices. We detect this at configure time. Signed-off-by: Joelle van Dyne Message-Id: <20210315180341.31638-2-j@getutm.app> Signed-off-by: Paolo Bonzini --- block/file-posix.c | 33 ++++++++++++++++++++++----------- meson.build | 6 +++++- qapi/block-core.json | 10 +++++++--- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 1439293f63..5821e1afed 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -42,6 +42,8 @@ #include "scsi/constants.h" =20 #if defined(__APPLE__) && (__MACH__) +#include +#if defined(HAVE_HOST_BLOCK_DEVICE) #include #include #include @@ -52,6 +54,7 @@ //#include #include #include +#endif /* defined(HAVE_HOST_BLOCK_DEVICE) */ #endif =20 #ifdef __sun__ @@ -180,7 +183,17 @@ typedef struct BDRVRawReopenState { bool check_cache_dropped; } BDRVRawReopenState; =20 -static int fd_open(BlockDriverState *bs); +static int fd_open(BlockDriverState *bs) +{ + BDRVRawState *s =3D bs->opaque; + + /* this is just to ensure s->fd is sane (its called by io ops) */ + if (s->fd >=3D 0) { + return 0; + } + return -EIO; +} + static int64_t raw_getlength(BlockDriverState *bs); =20 typedef struct RawPosixAIOData { @@ -3028,6 +3041,7 @@ static BlockStatsSpecific *raw_get_specific_stats(Blo= ckDriverState *bs) return stats; } =20 +#if defined(HAVE_HOST_BLOCK_DEVICE) static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs) { BlockStatsSpecific *stats =3D g_new(BlockStatsSpecific, 1); @@ -3037,6 +3051,7 @@ static BlockStatsSpecific *hdev_get_specific_stats(Bl= ockDriverState *bs) =20 return stats; } +#endif /* HAVE_HOST_BLOCK_DEVICE */ =20 static QemuOptsList raw_create_opts =3D { .name =3D "raw-create-opts", @@ -3252,6 +3267,8 @@ BlockDriver bdrv_file =3D { /***********************************************/ /* host device */ =20 +#if defined(HAVE_HOST_BLOCK_DEVICE) + #if defined(__APPLE__) && defined(__MACH__) static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath, CFIndex maxPathSize, int flags); @@ -3544,16 +3561,6 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long in= t req, void *buf) } #endif /* linux */ =20 -static int fd_open(BlockDriverState *bs) -{ - BDRVRawState *s =3D bs->opaque; - - /* this is just to ensure s->fd is sane (its called by io ops) */ - if (s->fd >=3D 0) - return 0; - return -EIO; -} - static coroutine_fn int hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { @@ -3877,6 +3884,8 @@ static BlockDriver bdrv_host_cdrom =3D { }; #endif /* __FreeBSD__ */ =20 +#endif /* HAVE_HOST_BLOCK_DEVICE */ + static void bdrv_file_init(void) { /* @@ -3884,6 +3893,7 @@ static void bdrv_file_init(void) * registered last will get probed first. */ bdrv_register(&bdrv_file); +#if defined(HAVE_HOST_BLOCK_DEVICE) bdrv_register(&bdrv_host_device); #ifdef __linux__ bdrv_register(&bdrv_host_cdrom); @@ -3891,6 +3901,7 @@ static void bdrv_file_init(void) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) bdrv_register(&bdrv_host_cdrom); #endif +#endif /* HAVE_HOST_BLOCK_DEVICE */ } =20 block_init(bdrv_file_init); diff --git a/meson.build b/meson.build index 913cf2a41a..9387fc5799 100644 --- a/meson.build +++ b/meson.build @@ -183,7 +183,7 @@ if targetos =3D=3D 'windows' include_directories: include_directo= ries('.')) elif targetos =3D=3D 'darwin' coref =3D dependency('appleframeworks', modules: 'CoreFoundation') - iokit =3D dependency('appleframeworks', modules: 'IOKit') + iokit =3D dependency('appleframeworks', modules: 'IOKit', required: fals= e) elif targetos =3D=3D 'sunos' socket =3D [cc.find_library('socket'), cc.find_library('nsl'), @@ -1072,6 +1072,9 @@ if get_option('cfi') add_global_link_arguments(cfi_flags, native: false, language: ['c', 'cpp= ', 'objc']) endif =20 +have_host_block_device =3D (targetos !=3D 'darwin' or + cc.has_header('IOKit/storage/IOMedia.h')) + ################# # config-host.h # ################# @@ -1165,6 +1168,7 @@ config_host_data.set('HAVE_PTY_H', cc.has_header('pty= .h')) config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h')) config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h')) config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', pre= fix: '#include ')) +config_host_data.set('HAVE_HOST_BLOCK_DEVICE', have_host_block_device) =20 config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#= include ')) =20 diff --git a/qapi/block-core.json b/qapi/block-core.json index 2ea294129e..2dd41be156 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -897,7 +897,8 @@ 'discriminator': 'driver', 'data': { 'file': 'BlockStatsSpecificFile', - 'host_device': 'BlockStatsSpecificFile', + 'host_device': { 'type': 'BlockStatsSpecificFile', + 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, 'nvme': 'BlockStatsSpecificNvme' } } =20 ## @@ -2814,7 +2815,9 @@ { 'enum': 'BlockdevDriver', 'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs', 'cloop', 'compress', 'copy-on-read', 'dmg', 'file', 'ftp', 'ft= ps', - 'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscs= i', + 'gluster', 'host_cdrom', + {'name': 'host_device', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)= ' }, + 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallel= s', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' }, @@ -3996,7 +3999,8 @@ 'ftps': 'BlockdevOptionsCurlFtps', 'gluster': 'BlockdevOptionsGluster', 'host_cdrom': 'BlockdevOptionsFile', - 'host_device':'BlockdevOptionsFile', + 'host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, 'http': 'BlockdevOptionsCurlHttp', 'https': 'BlockdevOptionsCurlHttps', 'iscsi': 'BlockdevOptionsIscsi', --=20 2.31.1 From nobody Fri May 3 17:25:40 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622727757; cv=none; d=zohomail.com; s=zohoarc; b=FUq0HrRLOW0IcGBR0I2RZOU3k9ukmDN/1FlV550kUd6bFEt4ZadJs3HwaSMQIELJ8YjX3roH4f0QbEJnvzbPCedhUJa3VJKj1DIPGqjdpvlOAArkSIhbu6C+dFYZDt8x53TRVrcOXSWDfV8JfFJ8BBMf6XT5YysGx5ix1z+GRco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622727757; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pHF46fO4kk0R6NoY+59bVj7PZ8zMQnZF40xB0YMAuds=; b=ndJpDiv7lbptfRVGHlFNZlf0/e5+MVE90hqlL/QDeLiQv+qw4apUxD3SafoJAJCJdCPVMWXwJHviacwPBRERvHL301ZMYGHXnXBxO6S3ur91i5rt/DgzmRpnDhOvRhoe1d6EMPd1OSRWwKvHEunrWmHzMRmWdqsKrItDaIT9OEI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622727757308985.4020579502413; Thu, 3 Jun 2021 06:42:37 -0700 (PDT) Received: from localhost ([::1]:38736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1loncK-0005nx-Ao for importer2@patchew.org; Thu, 03 Jun 2021 09:42:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lonXX-00032u-Rc; Thu, 03 Jun 2021 09:37:39 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:45664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lonXW-0000AP-8d; Thu, 03 Jun 2021 09:37:39 -0400 Received: by mail-ed1-x529.google.com with SMTP id dg27so7121211edb.12; Thu, 03 Jun 2021 06:37:37 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id e24sm1555369ejb.52.2021.06.03.06.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 06:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pHF46fO4kk0R6NoY+59bVj7PZ8zMQnZF40xB0YMAuds=; b=XWaOxtO39E6QdSutGjdwaVivrBBGEODURwd0NqB1hx77KBmXwcTP3+WiJL/tUbKJb9 eBFcB2GKdxT2v4U9CfvA+IMd/7+GnT0M7uKSSpHYqySBEOMIercEPpZYjlCRnfF2xldw evC9Yw3PUnXkYYa6EGmUURbIE2dwjfWsi11pgTepqlymf7UxvYRE/t00t910cXzynfa4 vQCFSTYzJ8wV5NnTHC+1BpPrZ+eIWT/8XE7gQYa20xRv/nOnlkGnHxwiAKBx+fng2IVq IvjgoZE1ZOdMjEv5LKvjCRFZG9zGJ5P0r/AFOgCVRRlnNPSLaq6SmplbZrhQN/52jyjI dKag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=pHF46fO4kk0R6NoY+59bVj7PZ8zMQnZF40xB0YMAuds=; b=PaN4mrpWuykxTJdNsESchKLMmYM0UMPhBTmOrMPr7U7fmf7eeyeHeKqY7AMqykH37V HlirkPYyJTiiJuYayToSJQZGCNBImAldsxTdgVYapi1BjGPMQ859ilCe/jwQNZl/+A0P /gERCmbrFwaaJDIL5q+UFrTRJ0/ORPy7fg5jao3PDBNzzZ4gz3WXgKoteIiclP+9tI+O 0lH3DPRtLdoEmwwZAZQ3/aNMulZ2+lqHojwq3lfzwss+QVZCdFsbOigCcEslG6/RtL+o c7obj5a5apaI1j6AYhXmd9Di52z28Wzo4eq3Wp5P0sImSoHmiuPB8V6LeK8DgkmdW3dG sMTQ== X-Gm-Message-State: AOAM531SwWPM5KJg7DdhQmFtTeBj38PdjCJY+gxxe61LznCuMczZB8gv rR4p3P03AEl2zzca+yq/KhW6V5e1IKO8gA== X-Google-Smtp-Source: ABdhPJyMHoBWw5I7t7lCdHr5P0WGGssAc6j5CM+NtNUODUh8nJWjCNQ6i5mpI/RiEmHkDSi2U7VQ7g== X-Received: by 2002:a05:6402:1601:: with SMTP id f1mr43685608edv.383.1622727456612; Thu, 03 Jun 2021 06:37:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v3 6/7] block: check for sys/disk.h Date: Thu, 3 Jun 2021 15:37:21 +0200 Message-Id: <20210603133722.218465-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210603133722.218465-1-pbonzini@redhat.com> References: <20210603133722.218465-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x529.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Joelle van Dyne , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Joelle van Dyne Some BSD platforms do not have this header. Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Joelle van Dyne Message-Id: <20210315180341.31638-3-j@getutm.app> Signed-off-by: Paolo Bonzini Reviewed-by: Max Reitz --- block.c | 2 +- meson.build | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 3f456892d0..1d37f133a8 100644 --- a/block.c +++ b/block.c @@ -54,7 +54,7 @@ #ifdef CONFIG_BSD #include #include -#ifndef __DragonFly__ +#if defined(HAVE_SYS_DISK_H) #include #endif #endif diff --git a/meson.build b/meson.build index 9387fc5799..8c44c37f9a 100644 --- a/meson.build +++ b/meson.build @@ -1169,6 +1169,7 @@ config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_head= er('sys/ioccom.h')) config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h')) config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', pre= fix: '#include ')) config_host_data.set('HAVE_HOST_BLOCK_DEVICE', have_host_block_device) +config_host_data.set('HAVE_SYS_DISK_H', cc.has_header('sys/disk.h')) =20 config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#= include ')) =20 --=20 2.31.1 From nobody Fri May 3 17:25:40 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622727688; cv=none; d=zohomail.com; s=zohoarc; b=XSy5W3Dps1AtjpWitdEEPalq5RNdSeNFRqJ7ZQCc+HpLU+TaSR0bRfK2fbFqHAgsQKZw3hCdSl/M7gcg4dYrykQK0134d3Unl9jbHSFvGMWqPez9thgAUFKucJLi/WM5tCdCsl5AzwFrIcmnJSDzljzo2rCV/VeODvD5YBgNR3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622727688; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zbEKtWwYtPu17XYhL91Y3v+VjithiK8Jl8+pLNVJebs=; b=ON3M59RXsXSfm8iIV56O/4c+kLUPdFLOQ0SThArKI5vhsrooSrpoDw9aDIlTj3nkF5DTCb9uOupmvWXV9BjqeeWeU83fgvBr4TZNos3O5wOnAFwe/FzlzfDi+egMBl1lJJKkWVHBHJUC9wsefQN2DZCILCiZszjf7MrjCn+gdKU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622727688112605.1756178463248; Thu, 3 Jun 2021 06:41:28 -0700 (PDT) Received: from localhost ([::1]:33906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lonbD-0002Ta-1N for importer2@patchew.org; Thu, 03 Jun 2021 09:41:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lonXZ-00037z-1J; Thu, 03 Jun 2021 09:37:41 -0400 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]:40711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lonXX-0000Ah-4U; Thu, 03 Jun 2021 09:37:40 -0400 Received: by mail-ed1-x533.google.com with SMTP id t3so7142998edc.7; Thu, 03 Jun 2021 06:37:38 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id e24sm1555369ejb.52.2021.06.03.06.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 06:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zbEKtWwYtPu17XYhL91Y3v+VjithiK8Jl8+pLNVJebs=; b=mhvapHKuR1ywaKvJavFkXZyniMR3SkGYpBU6Uns9o1ZmhTM+GwWsgUu39pQqCvF4R8 pxIAm/La2sUFscOGIn7vgheBBNuZcjeF1nw5YqEnggkYiPh5Paw5q8GYXlXVq5Pz1wyq oTRuzQgUqkVRjxdyCZyi7w2EqVEWyiDvn7DFf7E+q7KyVQOCh3k8dDzcPtwrA2MRGEoD DiYjeZ6Is0PCuYmbWe7PT402K587K40y1h/7OTNpGvu1fKNgVmRQkYZOBUZLEGZI7m2b EbvILEM3X1Q0HCe0DNaaaOTMgVp09lanjn3cZ7pPmIVvsCnA6zSRWKjr7kaTrHN/6fIQ eoUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=zbEKtWwYtPu17XYhL91Y3v+VjithiK8Jl8+pLNVJebs=; b=WMDOZXfK3ZK1kh+JWUShzhsq71pGw1FFP0Ukpa6Mi3GtsS0lyT4FFDYonODw4RK83X pC2J8ycvdOsaKyg7rp06LeE8fB1/kM8HMv07lYx731alTymEKN3LtwOW2KlertHwULFS F+b9b1cbOtnIhaB8tc3ffFKWZSMdznmOSInRGlt41Ov4gxQ7+ZBW2fvM4pDJqJ4nfwA3 QqMn1OFFIsAk61rrqzuzAcMGlRnFZUtJ4J+Xcz01i22sD0/I9wMQSss4Wif1w6wNaQcK J0o8k2OchSEbXW3qR+VFCQy7nf6wlFyBmT3evdYWZMDrbAvU+WH/mfvpGJwPvH4qzUe+ nCRw== X-Gm-Message-State: AOAM530sT+FVgrAA5ctbfM7pBmffUW1rRSy6RR3N8bLys/nqB2gX8HdS ZKmTMCZzETI7dwms05zEigjJYcAJTW5+/g== X-Google-Smtp-Source: ABdhPJzUPLjoEg1MNh1ia7sNM9vnPIzltpdI9w7CIxkxY1zHcxxPXfchpL+LZYNpe65eN9SEX3N8Gg== X-Received: by 2002:a05:6402:4310:: with SMTP id m16mr43878029edc.279.1622727457527; Thu, 03 Jun 2021 06:37:37 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v3 7/7] block: detect DKIOCGETBLOCKCOUNT/SIZE before use Date: Thu, 3 Jun 2021 15:37:22 +0200 Message-Id: <20210603133722.218465-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210603133722.218465-1-pbonzini@redhat.com> References: <20210603133722.218465-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::533; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x533.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Warner Losh , Joelle van Dyne , qemu-block@nongnu.org, Peter Maydell Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Joelle van Dyne iOS hosts do not have these defined so we fallback to the default behaviour. Co-authored-by: Warner Losh Reviewed-by: Peter Maydell Signed-off-by: Joelle van Dyne Message-Id: <20210315180341.31638-4-j@getutm.app> Signed-off-by: Paolo Bonzini --- block/file-posix.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 5821e1afed..4e2f7cf508 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2322,8 +2322,11 @@ static int64_t raw_getlength(BlockDriverState *bs) again: #endif if (!fstat(fd, &sb) && (S_IFCHR & sb.st_mode)) { + size =3D 0; #ifdef DIOCGMEDIASIZE - if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) + if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) { + size =3D 0; + } #elif defined(DIOCGPART) { struct partinfo pi; @@ -2332,9 +2335,7 @@ again: else size =3D 0; } - if (size =3D=3D 0) -#endif -#if defined(__APPLE__) && defined(__MACH__) +#elif defined(DKIOCGETBLOCKCOUNT) && defined(DKIOCGETBLOCKSIZE) { uint64_t sectors =3D 0; uint32_t sector_size =3D 0; @@ -2342,19 +2343,15 @@ again: if (ioctl(fd, DKIOCGETBLOCKCOUNT, §ors) =3D=3D 0 && ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) =3D=3D 0) { size =3D sectors * sector_size; - } else { - size =3D lseek(fd, 0LL, SEEK_END); - if (size < 0) { - return -errno; - } } } -#else - size =3D lseek(fd, 0LL, SEEK_END); +#endif + if (size =3D=3D 0) { + size =3D lseek(fd, 0LL, SEEK_END); + } if (size < 0) { return -errno; } -#endif #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) switch(s->type) { case FTYPE_CD: --=20 2.31.1