From patchwork Thu Jun 24 18:04:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12342713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC939C49EA5 for ; Thu, 24 Jun 2021 18:07:22 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 90C27613EE for ; Thu, 24 Jun 2021 18:07:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 90C27613EE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwTl3-0003zL-NZ for qemu-devel@archiver.kernel.org; Thu, 24 Jun 2021 14:07:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwTiI-0007yu-9J; Thu, 24 Jun 2021 14:04:30 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]:43735) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwTiG-0001Pc-2U; Thu, 24 Jun 2021 14:04:29 -0400 Received: by mail-ej1-x630.google.com with SMTP id nb6so10866467ejc.10; Thu, 24 Jun 2021 11:04:27 -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=GjCZXEAAw7qiNbzDIiyL4DTYii0HnblTscfX7SsNJa4=; b=CLo44oXfCpxjTO9eQY21X4tlCjvR1v4CWVGgvxHeobLD39YoqtGm1hU3fh1SSyn1EP 1J6Rm5UC+k8dHqCzglZMkMp7Kr+e9uuhlxbxI1kGJx73uUHS1QHdt8ukUiOddrRvFzYQ 4RQ2KFm/ERXOPxiJ5rZ4I25QstlXDTuaM1qn4vcGkOdViK2VVkDFsByLnATM1AvdtrfE 4+8vy1UAK1EPqwvWRqQGHuu728pHuM4OHHpjKEDV1+erS5C7u41LDdsczqg3gw98fw3U q3ayjvQW0lBh61LGj9AJjCm8u6vIcXiWcQOzWp+J/61RKwHxgZbKR5uR0tKiZ4XNstBy j/lA== 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=GjCZXEAAw7qiNbzDIiyL4DTYii0HnblTscfX7SsNJa4=; b=PrhHq6uRkcrqC3gVc81105Pe3JRDR+d5ADiif3tpwH4A7dPrByDL/dK9LakxR0XVSc nPF3Hx6JO3wBhWbD0s5q/wra0hVpT1v22AbLTxflQbSyZb3EvbXg9YmQdR1S9dW54rQR 4F6ov9iN6K1Um1SEI+QeqJo22dtB02t1cfPKcCvRTxcredo46e0A4ODavxuOXlOTdng5 lsvKDWcVp8jVrpp8XjgP2ztED0zkXS2s1kqoKMweGYEtUl5Qv8d2D56qh3lf4Byu2/3d 4v9w8qfPYLQ0dKm0M2Ig+UNdL5bQ7MHGOUA6FpUN9Ts3OQ0twFrheStc24Qt3+1l754L dF6g== X-Gm-Message-State: AOAM531ehV20tfBo6dMwRX9BJ2axzXkUCfoYOM7fYAOu8xdJ+UN5ZnbE EY//GoSHP2G+AvnKj9ZW5aXwdyVQI4U= X-Google-Smtp-Source: ABdhPJwY+3/JUcFK4Fg4N7CKc5XVn9W28GrIFMd0qwwiwk6YL4CIXNj7GN3GrjSA1MlGgStEB/0pPg== X-Received: by 2002:a17:907:7662:: with SMTP id kk2mr6448352ejc.218.1624557866300; Thu, 24 Jun 2021 11:04:26 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id a1sm2436466edt.16.2021.06.24.11.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 11:04:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 01/11] file-posix: fix max_iov for /dev/sg devices Date: Thu, 24 Jun 2021 20:04:13 +0200 Message-Id: <20210624180423.1322165-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624180423.1322165-1-pbonzini@redhat.com> References: <20210624180423.1322165-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::630; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x630.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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: mreitz@redhat.com, qemu-block@nongnu.org, mlevitsk@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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, so add support for it. The block device path is kept because it will be reinstated in the next patches. 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 b3fbb9bd63..b8dc19ce1a 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1178,6 +1178,17 @@ static int sg_get_max_segments(int fd) goto out; } + if (S_ISCHR(st.st_mode)) { + if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) == 0) { + return ret; + } + return -ENOTSUP; + } + + if (!S_ISBLK(st.st_mode)) { + return -ENOTSUP; + } + sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments", major(st.st_rdev), minor(st.st_rdev)); sysfd = open(sysfspath, O_RDONLY); From patchwork Thu Jun 24 18:04:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12342709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 925ACC49EA6 for ; Thu, 24 Jun 2021 18:06:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 54E87613C2 for ; Thu, 24 Jun 2021 18:06:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 54E87613C2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwTkU-0002V4-Gd for qemu-devel@archiver.kernel.org; Thu, 24 Jun 2021 14:06:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwTiJ-0007zz-N6; Thu, 24 Jun 2021 14:04:35 -0400 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]:45626) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwTiH-0001R4-Dj; Thu, 24 Jun 2021 14:04:31 -0400 Received: by mail-ej1-x631.google.com with SMTP id hc16so10755187ejc.12; Thu, 24 Jun 2021 11:04:28 -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=oBy2rWBfxuFWeS2NQNlXhg91jwIz3LB5M14uVRp5Bzc=; b=XVL+ww5we5OR0G2n7Hl9nF+LFURkAG5B2y0c18jZX7Zba3oCRBpKaUU/REm98RJiwD s+kzhQO2Ru2AQ68Wf4GS62LdQ4MLS8FICJGb6FI1YLv6g+cWCTgt1Ik4476DX4nWIpiw LxJ15RtdGVN9RGaaM9xs5s1yi8mfqNHrXWCjjlBTKladJAmfcrv+SbzOUeaOxNUlpNSY B200pnIUVvS/Mm6ebekeFQ+ULUWReXKipV5jL7Cq9r8SOAtEUWmW8vOQRARmGz4tg/ax mLHCC2Blx2exOPjaQ4wtAHwTpGypq7hXRIciN84FxfLtxVtBlNlRL24BeTi8NGxjDzpL OQ3w== 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=oBy2rWBfxuFWeS2NQNlXhg91jwIz3LB5M14uVRp5Bzc=; b=NpKwgKfzYwnQJc035QNlvD0/YTPic2nBWbN3Iuv1CUm+sinIkMsIeW/i3Az4LAr5z8 LJL+QWfkQ4bNTHSmvwMXWxTkHnH4PU7ouOVM94cKdUOLON5huFaDXLnTcq7zYOt8AlDN 3gJYJjy0iv9TfOGhQqPBpOWdGDNxHZzQu8d2kSTflq1ws20P4jGMyb/g0qB+RwOqqpYl KeA0k/4bJw+KO7rQ98XKpDEw1antqCcPILcp7HCT68yVNDF7fRXqRfsfwi88FL13x20Y 48BuwnlrVmq6s85MVnQI+GP8VxQGg8KrC/4r2zd0HQ8LfqGaXxPqPrjMxBJlIvrCIg7d MkpQ== X-Gm-Message-State: AOAM5325+ndehg6C7OS1KN/ohL9ybm5aooFsfpLBqtU0x6EmeialH2YZ 2U0Vj+umOmzhk++EF/A2f/WDvizYrXw= X-Google-Smtp-Source: ABdhPJzzol6boMxNi2LQMCMJMfu+2foufVQ870eLjJsQljBcFck19rUk0fs0punIHyGg8X11JbrDOA== X-Received: by 2002:a17:907:3f06:: with SMTP id hq6mr6195166ejc.130.1624557867074; Thu, 24 Jun 2021 11:04:27 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id a1sm2436466edt.16.2021.06.24.11.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 11:04:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 02/11] scsi-generic: pass max_segments via max_iov field in BlockLimits Date: Thu, 24 Jun 2021 20:04:14 +0200 Message-Id: <20210624180423.1322165-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624180423.1322165-1-pbonzini@redhat.com> References: <20210624180423.1322165-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x631.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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: mreitz@redhat.com, qemu-block@nongnu.org, mlevitsk@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" I/O to a disk via read/write is not limited by the number of segments allowed 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 b8dc19ce1a..6db690baf2 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1237,8 +1237,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) ret = sg_get_max_segments(s->fd); if (ret > 0) { - bs->bl.max_transfer = MIN(bs->bl.max_transfer, - ret * qemu_real_host_page_size); + bs->bl.max_iov = ret; } } diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 40e039864f..b6c4143dc7 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -179,10 +179,12 @@ static int scsi_handle_inquiry_reply(SCSIGenericReq *r, SCSIDevice *s, int len) (r->req.cmd.buf[1] & 0x01)) { page = r->req.cmd.buf[2]; if (page == 0xb0) { - uint32_t max_transfer = - blk_get_max_transfer(s->conf.blk) / s->blocksize; + uint32_t max_transfer = blk_get_max_transfer(s->conf.blk); + uint32_t max_iov = blk_get_max_iov(s->conf.blk); assert(max_transfer); + max_transfer = MIN_NON_ZERO(max_transfer, max_iov * qemu_real_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], From patchwork Thu Jun 24 18:04:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12342711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B55CC49EA5 for ; Thu, 24 Jun 2021 18:07:16 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0820E613EE for ; Thu, 24 Jun 2021 18:07:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0820E613EE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwTkx-0003W2-1D for qemu-devel@archiver.kernel.org; Thu, 24 Jun 2021 14:07:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwTiJ-0007zy-Ma; Thu, 24 Jun 2021 14:04:32 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]:43741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwTiH-0001Rs-JW; Thu, 24 Jun 2021 14:04:31 -0400 Received: by mail-ej1-x636.google.com with SMTP id nb6so10866569ejc.10; Thu, 24 Jun 2021 11:04:28 -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=GNN3PKGCrmEv1egmkbcKJ78YTkUsB3DLKlu9c2s2Q9Y=; b=rQr1/65fvgMg3N7umnZVx4q6lGayemE4gwQJixH/v3azO3wW79ORgDpxePEkjnRVyC 8IW6kBURiSPL+RCd7Ti/0+9Eu9+m3/780GF7EdtwIZZe4cJtZZ4hHS6sktrvH5wPttbN 7bPUgR8hPPh62OCj0+d9BGT6ykhFngG2iVYuGabeLco+QNGc3GL2TEZtsh7eVFlK9xSK EtxcaB/Ub9H5HmTGWjb4hSF2J8E9ZGXEixONZbHjGlNBjZ7gjHPZZkVaFIenMMY4hMBM AJkXJiCBK+yrF/0XJcz0yODMZQZJN7oG8MtBvIXubgSfskat+K17dIPWlP+crA/vkfC+ +8LQ== 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=GNN3PKGCrmEv1egmkbcKJ78YTkUsB3DLKlu9c2s2Q9Y=; b=kOrFq5kg1bQhypFFf0EzhcqhUzONdSlbU2bPKkcX1XHSaY7+Y7S6ulB2CSNeJnwC5R 6Tqk4tYoFLWhHxX3rWWnHf7Yjkkthhz4sBQGI3/5JU4CBmTnL2T98uIS29ZNBO+njfch 4bb09vyL0t92dC9LySZ4jsJFoJl/O0Jyj/Vf0lg5lt+WmnajmkudyJTXbwsWWmNJd+em Kwk9UY/uEXXppmG//LiLhXMTC+0KFH5BsAKSiCjbg1sQHzth211RFVHA4XdXC94D5RhG LHJAybzr0GE5A9tYHo7SRIc1p52SgJtbT41vMqiWCWSvnrhL2E6EmDdB7ACNj08h6ISx RpFw== X-Gm-Message-State: AOAM530S3lrfXew22T4jhWW+FFvEJblTmhnjCIBk0mH2tIYj6hz3lMmJ pPe6DyOOr0dQ4itEtvWPtd6KgTSLLX4= X-Google-Smtp-Source: ABdhPJy5UK5J8q2DdB0e4+36XSq7XWVY4Rlenvxm8oZP3azkS39emm1H+kNHYFyPg+UIx1nm57gP5g== X-Received: by 2002:a17:906:c241:: with SMTP id bl1mr6453850ejb.536.1624557867971; Thu, 24 Jun 2021 11:04:27 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id a1sm2436466edt.16.2021.06.24.11.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 11:04:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 03/11] osdep: provide ROUND_DOWN macro Date: Thu, 24 Jun 2021 20:04:15 +0200 Message-Id: <20210624180423.1322165-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624180423.1322165-1-pbonzini@redhat.com> References: <20210624180423.1322165-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x636.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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: mreitz@redhat.com, qemu-block@nongnu.org, mlevitsk@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" osdep.h provides a ROUND_UP macro to hide bitwise operations for the purpose of rounding a number up to a power of two; add a ROUND_DOWN macro that does the same with truncation towards zero. While at it, change the formatting of some comments. Signed-off-by: Paolo Bonzini Reviewed-by: Max Reitz Reviewed-by: Philippe Mathieu-Daudé --- include/qemu/osdep.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 0a54bf7be8..c3656b755a 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -319,11 +319,16 @@ extern "C" { }) #endif -/* Round number down to multiple */ +/* + * Round number down to multiple. Safe when m is not a power of 2 (see + * ROUND_DOWN for a faster version when a power of 2 is guaranteed). + */ #define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m)) -/* Round number up to multiple. Safe when m is not a power of 2 (see - * ROUND_UP for a faster version when a power of 2 is guaranteed) */ +/* + * Round number up to multiple. Safe when m is not a power of 2 (see + * ROUND_UP for a faster version when a power of 2 is guaranteed). + */ #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m)) /* Check if n is a multiple of m */ @@ -340,11 +345,22 @@ extern "C" { /* Check if pointer p is n-bytes aligned */ #define QEMU_PTR_IS_ALIGNED(p, n) QEMU_IS_ALIGNED((uintptr_t)(p), (n)) -/* Round number up to multiple. Requires that d be a power of 2 (see +/* + * Round number down to multiple. Requires that d be a power of 2 (see * QEMU_ALIGN_UP for a safer but slower version on arbitrary - * numbers); works even if d is a smaller type than n. */ + * numbers); works even if d is a smaller type than n. + */ +#ifndef ROUND_DOWN +#define ROUND_DOWN(n, d) ((n) & -(0 ? (n) : (d))) +#endif + +/* + * Round number up to multiple. Requires that d be a power of 2 (see + * QEMU_ALIGN_UP for a safer but slower version on arbitrary + * numbers); works even if d is a smaller type than n. + */ #ifndef ROUND_UP -#define ROUND_UP(n, d) (((n) + (d) - 1) & -(0 ? (n) : (d))) +#define ROUND_UP(n, d) ROUND_DOWN((n) + (d) - 1, (d)) #endif #ifndef DIV_ROUND_UP From patchwork Thu Jun 24 18:04:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12342721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89CFBC49EA5 for ; Thu, 24 Jun 2021 18:10:30 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1ADE960FD8 for ; Thu, 24 Jun 2021 18:10:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1ADE960FD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:56472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwTo5-0000oR-96 for qemu-devel@archiver.kernel.org; Thu, 24 Jun 2021 14:10:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwTiN-00080C-So; Thu, 24 Jun 2021 14:04:37 -0400 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]:37513) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwTiI-0001S1-Ay; Thu, 24 Jun 2021 14:04:32 -0400 Received: by mail-ed1-x52e.google.com with SMTP id i24so9796980edx.4; Thu, 24 Jun 2021 11:04:29 -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=qpjBRyyTP4cjVVNX0Br2C9CiFX8IHvmV4kWlXQxiCsA=; b=pQ4qf/DY1cJzzI1s96GU6X9CEinrrHU358IvMC16bjfmqnnmlSO6MZZnr8s0kAsyqC eRx5DQHygU6O+SGPDPpwkK4L3qT9JJgmZAHYbPlr1ksnUZhc8JDx6cMGlArNhh+6peQz TB3+EA+2I6mibxBG8rWzvdMaLo1PvWUARHKr7I5GDugE8ygZfrpojsuPkVezIyyd8X3K 0wJnhJRg6hrFxQ8UDsegiT4+mOnBV1tqNMJQCD3cTv+zlLAy5DqKIhsLaq7PX7V8r+ix 0WjDWITsLfBNkZrwAzeGkai1BazM93LxDGs8l8jFTqTNz25/TlCE85fLV3ymSFxJ+dv/ qwaA== 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=qpjBRyyTP4cjVVNX0Br2C9CiFX8IHvmV4kWlXQxiCsA=; b=o4aT8XkIwrVNmq8ZD+WJyMBBYIK8OMFLlr/6bJ07NsUSfcZLj+HSSbm/wN/96trj7s VhTQ3zcpHkblPlMIlkztGA7g0fcztXhA4f8xQCo5N13SZylsMhQCPrjaOTvyG0VFoPqU xba7xWHMXrA2GDRnH5DOGGrj/QFc0NGAgnC3CW22G2MkfSNdZjeUbVWQ5iTm1Xn0xKj2 kUVeN9WmFqyTbVrHOpLGlw9rLKeK5qbMN4H4Lwp0njfgUA7QtGk57bUky60CpgeyLO6D POEmFiy/tQFrvEIjX5wZdDgRN6atGz1a0tdmg+NioOciR1ByR9txnZYGfInBbEMLtB8q 1Wkg== X-Gm-Message-State: AOAM531IXAeFuYcQ4vfufzebPtyWNh+FxubBGaFp/kW+HjIWWQ4nt7Jf 1olY9CviRVd5rrr8YTpOW7axscU7bzw= X-Google-Smtp-Source: ABdhPJyKLKiKr7OFiWakk56fW2Bh85KXN/+sVUniC/UWA4c1ytDZe7A1jCAdr390boX9rsBWHphPdQ== X-Received: by 2002:aa7:d413:: with SMTP id z19mr9119497edq.37.1624557868745; Thu, 24 Jun 2021 11:04:28 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id a1sm2436466edt.16.2021.06.24.11.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 11:04:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 04/11] block-backend: align max_transfer to request alignment Date: Thu, 24 Jun 2021 20:04:16 +0200 Message-Id: <20210624180423.1322165-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624180423.1322165-1-pbonzini@redhat.com> References: <20210624180423.1322165-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52e; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52e.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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: mreitz@redhat.com, qemu-block@nongnu.org, mlevitsk@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Block device requests must be aligned to bs->bl.request_alignment. It makes sense for drivers to align bs->bl.max_transfer the same way; however when there is no specified limit, blk_get_max_transfer just returns INT_MAX. Since the contract of the function does not specify that INT_MAX means "no maximum", just align the outcome of the function (whether INT_MAX or bs->bl.max_transfer) before returning it. Signed-off-by: Paolo Bonzini Reviewed-by: Max Reitz --- block/block-backend.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 15f1ea4288..6e37582740 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1957,12 +1957,12 @@ uint32_t blk_get_request_alignment(BlockBackend *blk) uint32_t blk_get_max_transfer(BlockBackend *blk) { BlockDriverState *bs = blk_bs(blk); - uint32_t max = 0; + uint32_t max = INT_MAX; if (bs) { - max = bs->bl.max_transfer; + max = MIN_NON_ZERO(max, bs->bl.max_transfer); } - return MIN_NON_ZERO(max, INT_MAX); + return ROUND_DOWN(max, blk_get_request_alignment(blk)); } int blk_get_max_iov(BlockBackend *blk) From patchwork Thu Jun 24 18:04:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12342725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D831C49EA6 for ; Thu, 24 Jun 2021 18:12:16 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 825C460FD8 for ; Thu, 24 Jun 2021 18:12:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 825C460FD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwTpk-0003of-KD for qemu-devel@archiver.kernel.org; Thu, 24 Jun 2021 14:12:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwTiQ-00081B-8D; Thu, 24 Jun 2021 14:04:39 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]:35808) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwTiJ-0001SJ-Rs; Thu, 24 Jun 2021 14:04:37 -0400 Received: by mail-ej1-x629.google.com with SMTP id gn32so10930876ejc.2; Thu, 24 Jun 2021 11:04:30 -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=XzrbbkEGL9DUDKoP6G9+FXKiRtPajUq/O5vyZRD1tS4=; b=awr+BAkN5scwFViKHAvpUqN8lx1NSYBZguAnrGrHj/s7Sgqvy7Ee2AHhFCQHQDP80E EuUrIf9pP9Tv8QFWBPTMZXaPGTxjrdSCpirJCdz6mOh+PfJiFVDK3nV9ccoZlS5uiu0a lTmpjEwzAnqgK4W6AEK6sJecYa9zxrmct54QjwVNQxdVBDbyC1+fh9JYzU5wTeJSARvt fHaNljZwOKRrDRamzBgeyN935i6IAwgQOS/CWUcx6ThCxG34FiaoBikDuPmkWwQxz5+c haTRcXGS4vg1iTcyQP/HUbYNIeDuLpDPd0TN3And693SlzHQoUHE7x1DDIZLVCxDhrNE jJxg== 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=XzrbbkEGL9DUDKoP6G9+FXKiRtPajUq/O5vyZRD1tS4=; b=WRLnyoSIlbxeXi/eZQxP14i4C6pgZck8fq4vwvlT9n4sjrQH0wFppFw2IAHzM92r1a zq4EIymAb8ln3ywdFxluy2d5YFhrT6IIXfvn0JKrmEVDu1qyo2phsV+rDtKqPn2FGvQ0 HfpF8YjmKcTTjfpuWNOLpSZRAib/CpQAtm8V6X6Pla5dUS+zN5S+3nn7hkVUnVSKA54q KXkB2YFjWhiE6vP9IL+vNNbweYUv/Hz/zvX9/iwTBvWuCS5nuyvcFTqi5ImpFc+UvFQe BQOP+i13NAUzMY7fyojze1rgfk7vIOEkXYYwGQoYG3e+OvVowUnlllwCHcQjP3Uwz0uG gDrQ== X-Gm-Message-State: AOAM531EdWneWpffvwd2ulp23ZlvlcuPKULbkVDMfhbhHIlCZrdajEOW 8+pGKupkTm0FOW7VzFW3nCRWImQKPqA= X-Google-Smtp-Source: ABdhPJwZUIdViLfA/75syoYpnk2qvGt6zidPycs/wJ/swekmSGCMw0AmdMsjPNsB8rZa4oHiB7ft9w== X-Received: by 2002:a17:906:fc6:: with SMTP id c6mr6436973ejk.65.1624557869633; Thu, 24 Jun 2021 11:04:29 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id a1sm2436466edt.16.2021.06.24.11.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 11:04:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 05/11] block: add max_hw_transfer to BlockLimits Date: Thu, 24 Jun 2021 20:04:17 +0200 Message-Id: <20210624180423.1322165-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624180423.1322165-1-pbonzini@redhat.com> References: <20210624180423.1322165-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x629.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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: mreitz@redhat.com, qemu-block@nongnu.org, mlevitsk@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Max Reitz --- block/block-backend.c | 13 +++++++++++++ block/file-posix.c | 2 +- block/io.c | 2 ++ hw/scsi/scsi-generic.c | 2 +- include/block/block_int.h | 7 +++++++ include/sysemu/block-backend.h | 1 + 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 6e37582740..deb55c272e 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1953,6 +1953,19 @@ uint32_t blk_get_request_alignment(BlockBackend *blk) return bs ? bs->bl.request_alignment : BDRV_SECTOR_SIZE; } +/* Returns the maximum hardware transfer length, in bytes; guaranteed nonzero */ +uint64_t blk_get_max_hw_transfer(BlockBackend *blk) +{ + BlockDriverState *bs = blk_bs(blk); + uint64_t max = INT_MAX; + + if (bs) { + max = MIN_NON_ZERO(max, bs->bl.max_hw_transfer); + max = MIN_NON_ZERO(max, bs->bl.max_transfer); + } + return ROUND_DOWN(max, blk_get_request_alignment(blk)); +} + /* 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 6db690baf2..88e58d2863 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1232,7 +1232,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) int ret = sg_get_max_transfer_length(s->fd); if (ret > 0 && ret <= BDRV_REQUEST_MAX_BYTES) { - bs->bl.max_transfer = pow2floor(ret); + bs->bl.max_hw_transfer = pow2floor(ret); } ret = sg_get_max_segments(s->fd); diff --git a/block/io.c b/block/io.c index 323854d063..dd93364258 100644 --- a/block/io.c +++ b/block/io.c @@ -127,6 +127,8 @@ static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src) { dst->opt_transfer = MAX(dst->opt_transfer, src->opt_transfer); dst->max_transfer = MIN_NON_ZERO(dst->max_transfer, src->max_transfer); + dst->max_hw_transfer = MIN_NON_ZERO(dst->max_hw_transfer, + src->max_hw_transfer); dst->opt_mem_alignment = MAX(dst->opt_mem_alignment, src->opt_mem_alignment); dst->min_mem_alignment = MAX(dst->min_mem_alignment, diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index b6c4143dc7..665baf900e 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -179,7 +179,7 @@ static int scsi_handle_inquiry_reply(SCSIGenericReq *r, SCSIDevice *s, int len) (r->req.cmd.buf[1] & 0x01)) { page = r->req.cmd.buf[2]; if (page == 0xb0) { - uint32_t max_transfer = blk_get_max_transfer(s->conf.blk); + uint64_t max_transfer = blk_get_max_hw_transfer(s->conf.blk); uint32_t max_iov = blk_get_max_iov(s->conf.blk); 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; + /* 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; 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); From patchwork Thu Jun 24 18:04:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12342719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFD85C49EA5 for ; Thu, 24 Jun 2021 18:09:50 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 2FF536008E for ; Thu, 24 Jun 2021 18:09:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2FF536008E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwTnR-0008HM-Al for qemu-devel@archiver.kernel.org; Thu, 24 Jun 2021 14:09:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwTiQ-00080y-7L; Thu, 24 Jun 2021 14:04:39 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]:37411) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwTiN-0001TH-TR; Thu, 24 Jun 2021 14:04:37 -0400 Received: by mail-ej1-x62c.google.com with SMTP id mj3so3459984ejb.4; Thu, 24 Jun 2021 11:04: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=d05PnkwnuDECdWXUS+gfsGR0SVTVhh2B+agXt5vsNfs=; b=U52vS18D/Yczva5a8WuV9TcxEouRHZc9gZLGy/XyKMTdLFERNL52+pHcQq/Omi1NZf UXtNbfKK15zgAnS/9s1zhl0WUA9QfHmSdQqBRt4nUbc60QAabGyuD5D+Wnrs987QkEpJ yPsaHCA92yr1jL1y3Lh8YmgrRJH3pKcPtzEdFjhYfEyo9WryTAAQyZ//0iLAppIi1zVr ZnrhD41aGebKwD1q/B67u7Vd2+pt0F1Gaja3H0ltVyq24X+NrLt+2iw9EobmfucOesRK +J/gwfb+mVp8hqLACUsfMvJ9aY3uNsZk8slIJvliQDj/qy2BJGJaOFD7MBKAQhxp6YQV fJUg== 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=d05PnkwnuDECdWXUS+gfsGR0SVTVhh2B+agXt5vsNfs=; b=ZdX6xfTNSfNPT1ZF1sbE3Xms++/TmwkCIixl9rumdlvVcKZ4cvgPUT9NPVKQZnKj1V E/o5mP0aiuAlyZslyeA6ijstaY19/nEbmkwEbneRMHfqX1Soc2vm4kP1NOXjfo6jHfKS JHT8HOjNuUD0djotD+kGgAqFlLUa+kZZb3+Ab/qKzI92cM/4Y0EZbv14de8X+VGPeySs Qxur8s+CPWY3VCQrfkq/mIAWRVsuWJZpFihwDwae4O/unciVGe3tcmAADkr6EiK+zK3K sWV6kpYzuGf3sbs01enygttMBGeUzz8iSuwjYK1mymq8Qgi4fqpa6NysM3lh2gtTJrkB FU6w== X-Gm-Message-State: AOAM530MTMz5klRgPbSCnsL0CDTFgxyVqdgrmoyo7nR86nac4B2/LEcV ahzdI0Pq8cadm4ELOOKAKaLmc1PKCdA= X-Google-Smtp-Source: ABdhPJyUXCe1+p6YZk6AqewbyQg2aIwRK3qVIGyFOH46qnPoTQHCWoyAfylJ2UnE+rdrZ3GhHqmbFQ== X-Received: by 2002:a17:906:eda9:: with SMTP id sa9mr6582427ejb.501.1624557870630; Thu, 24 Jun 2021 11:04:30 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id a1sm2436466edt.16.2021.06.24.11.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 11:04:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 06/11] file-posix: try BLKSECTGET on block devices too, do not round to power of 2 Date: Thu, 24 Jun 2021 20:04:18 +0200 Message-Id: <20210624180423.1322165-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624180423.1322165-1-pbonzini@redhat.com> References: <20210624180423.1322165-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62c.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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: mreitz@redhat.com, qemu-block@nongnu.org, mlevitsk@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Paolo Bonzini Reviewed-by: Max Reitz --- block/file-posix.c | 67 ++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 88e58d2863..ea102483b0 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1147,22 +1147,27 @@ static void raw_reopen_abort(BDRVReopenState *state) s->reopen_state = NULL; } -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 = 0; - - if (ioctl(fd, BLKSECTGET, &max_bytes) == 0) { - return max_bytes; + if (S_ISBLK(st->st_mode)) { + unsigned short max_sectors = 0; + if (ioctl(fd, BLKSECTGET, &max_sectors) == 0) { + return max_sectors * 512; + } } else { - return -errno; + int max_bytes = 0; + if (ioctl(fd, BLKSECTGET, &max_bytes) == 0) { + return max_bytes; + } } + return -errno; #else return -ENOSYS; #endif } -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]; @@ -1171,26 +1176,20 @@ static int sg_get_max_segments(int fd) int ret; int sysfd = -1; long max_segments; - struct stat st; - if (fstat(fd, &st)) { - ret = -errno; - goto out; - } - - if (S_ISCHR(st.st_mode)) { + if (S_ISCHR(st->st_mode)) { if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) == 0) { return ret; } return -ENOTSUP; } - if (!S_ISBLK(st.st_mode)) { + if (!S_ISBLK(st->st_mode)) { return -ENOTSUP; } sysfspath = 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 = open(sysfspath, O_RDONLY); if (sysfd == -1) { ret = -errno; @@ -1227,23 +1226,33 @@ out: static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s = bs->opaque; - - if (bs->sg) { - int ret = sg_get_max_transfer_length(s->fd); - - if (ret > 0 && ret <= BDRV_REQUEST_MAX_BYTES) { - bs->bl.max_hw_transfer = pow2floor(ret); - } - - ret = sg_get_max_segments(s->fd); - if (ret > 0) { - bs->bl.max_iov = ret; - } - } + struct stat st; raw_probe_alignment(bs, s->fd, errp); bs->bl.min_mem_alignment = s->buf_align; bs->bl.opt_mem_alignment = MAX(s->buf_align, qemu_real_host_page_size); + + /* + * Maximum transfers are best effort, so it is okay to ignore any + * errors. That said, based on the man page errors in fstat would be + * very much unexpected; the only possible case seems to be ENOMEM. + */ + if (fstat(s->fd, &st)) { + return; + } + + if (bs->sg || S_ISBLK(st.st_mode)) { + int ret = hdev_get_max_hw_transfer(s->fd, &st); + + if (ret > 0 && ret <= BDRV_REQUEST_MAX_BYTES) { + bs->bl.max_hw_transfer = ret; + } + + ret = hdev_get_max_segments(s->fd, &st); + if (ret > 0) { + bs->bl.max_iov = ret; + } + } } static int check_for_dasd(int fd) From patchwork Thu Jun 24 18:04:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12342781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1819AC49EA5 for ; Thu, 24 Jun 2021 18:15:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id AC90B60231 for ; Thu, 24 Jun 2021 18:15:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC90B60231 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:43404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwTtB-0002nf-QY for qemu-devel@archiver.kernel.org; Thu, 24 Jun 2021 14:15:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwTiS-00081a-6y; Thu, 24 Jun 2021 14:04:41 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]:41877) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwTiO-0001Ty-Ar; Thu, 24 Jun 2021 14:04:39 -0400 Received: by mail-ej1-x62c.google.com with SMTP id ot9so9885087ejb.8; Thu, 24 Jun 2021 11:04: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=g8puEhoQXzcNaDNMf2eB0lkryCgLVyBvEnsLiu0loco=; b=ZuGu/QvK3z0rliEL2OZ/ZfwFQqhrk8zniYU5b9VcWMqyUOlPgyiU2tr6vHEpz7HKcm RNGzLyf3/lU+SWVzkBl7wtyTEmtgrKSnbYDKexWi/NAjYgW1QUGgxe0qLQij3RClMg0Q MuoxxkXX9h4ZxNSHkIE4sx5d/sdymR5lFVZAC3zTra0MVYOkWZkneIhxGmH2TenVzQ7w BdQdEGnQcVi+QvS4k3ksg8HVIzcSsBkYqW9JNVPWZjdO252hDPBU3k4XtOheDiXTzFTk Rk8eWeHLy65RPNZ5MaGSpEl/TiceC+BOHA7yjW8nS8y1h4j+oKd9KMaHCsfQX8Jtbvgd 3H2Q== 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=g8puEhoQXzcNaDNMf2eB0lkryCgLVyBvEnsLiu0loco=; b=KPfGptTwttLLWnHFG/t6N4l5DzgvjqdaPAF/P1peaIRzPcbAXsd8Vxx1ShlbPf1K1k UaFiiB2arYCC2saV5yFDdwI6Sa4UAca2IA+bJVbV6KH/FsPjX1mwkcBw1gflfp29tG5h H7dimOWt4oOJ/W+ud17WQWrzijhtftOjKINNwmKYr747HI60/JYfD5MYVPR1BFS4YhVy CHLyGERftNVa5Yjh3S+zo1pfNm0jZAXcSRON3+YSQHw/JEhWXkuGEE+7/RKA8f0fA89g 2+kQ6lUxrefUmrhrhDjvl6GBbxhKKh7Hi6CDlE37U2dlwLBmnoxj5GaOdjgRAGJTrb8p OHug== X-Gm-Message-State: AOAM532CxpkSsv7cHXLWMteZaGJS2/yRGKxSIZuApWVSHtcTP+b9llxp YojG+1mN8M6ydW3oWO9MQNnsdFmXqlo= X-Google-Smtp-Source: ABdhPJzohgoZg55oM4ccrTMQMznXu78jsn4VOWJZgDhdatbbDGZ7sz4GEAv+cg9mgkSg280nXpJhzw== X-Received: by 2002:a17:906:4fc6:: with SMTP id i6mr6401697ejw.472.1624557871571; Thu, 24 Jun 2021 11:04:31 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id a1sm2436466edt.16.2021.06.24.11.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 11:04:31 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 07/11] block: feature detection for host block support Date: Thu, 24 Jun 2021 20:04:19 +0200 Message-Id: <20210624180423.1322165-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624180423.1322165-1-pbonzini@redhat.com> References: <20210624180423.1322165-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62c.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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: mreitz@redhat.com, Joelle van Dyne , qemu-block@nongnu.org, mlevitsk@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Max Reitz --- block/file-posix.c | 33 ++++++++++++++++++++++----------- meson.build | 6 +++++- qapi/block-core.json | 14 ++++++++++---- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index ea102483b0..e56bb491a1 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -42,6 +42,8 @@ #include "scsi/constants.h" #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 #ifdef __sun__ @@ -178,7 +181,17 @@ typedef struct BDRVRawReopenState { bool check_cache_dropped; } BDRVRawReopenState; -static int fd_open(BlockDriverState *bs); +static int fd_open(BlockDriverState *bs) +{ + BDRVRawState *s = bs->opaque; + + /* this is just to ensure s->fd is sane (its called by io ops) */ + if (s->fd >= 0) { + return 0; + } + return -EIO; +} + static int64_t raw_getlength(BlockDriverState *bs); typedef struct RawPosixAIOData { @@ -3033,6 +3046,7 @@ static BlockStatsSpecific *raw_get_specific_stats(BlockDriverState *bs) return stats; } +#if defined(HAVE_HOST_BLOCK_DEVICE) static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs) { BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1); @@ -3042,6 +3056,7 @@ static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs) return stats; } +#endif /* HAVE_HOST_BLOCK_DEVICE */ static QemuOptsList raw_create_opts = { .name = "raw-create-opts", @@ -3257,6 +3272,8 @@ BlockDriver bdrv_file = { /***********************************************/ /* host device */ +#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); @@ -3549,16 +3566,6 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) } #endif /* linux */ -static int fd_open(BlockDriverState *bs) -{ - BDRVRawState *s = bs->opaque; - - /* this is just to ensure s->fd is sane (its called by io ops) */ - if (s->fd >= 0) - return 0; - return -EIO; -} - static coroutine_fn int hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { @@ -3882,6 +3889,8 @@ static BlockDriver bdrv_host_cdrom = { }; #endif /* __FreeBSD__ */ +#endif /* HAVE_HOST_BLOCK_DEVICE */ + static void bdrv_file_init(void) { /* @@ -3889,6 +3898,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); @@ -3896,6 +3906,7 @@ static void bdrv_file_init(void) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) bdrv_register(&bdrv_host_cdrom); #endif +#endif /* HAVE_HOST_BLOCK_DEVICE */ } block_init(bdrv_file_init); diff --git a/meson.build b/meson.build index 62de7ac106..bb3a5be796 100644 --- a/meson.build +++ b/meson.build @@ -183,7 +183,7 @@ if targetos == 'windows' include_directories: include_directories('.')) elif targetos == 'darwin' coref = dependency('appleframeworks', modules: 'CoreFoundation') - iokit = dependency('appleframeworks', modules: 'IOKit') + iokit = dependency('appleframeworks', modules: 'IOKit', required: false) elif targetos == 'sunos' socket = [cc.find_library('socket'), cc.find_library('nsl'), @@ -1147,6 +1147,9 @@ if get_option('cfi') add_global_link_arguments(cfi_flags, native: false, language: ['c', 'cpp', 'objc']) endif +have_host_block_device = (targetos != 'darwin' or + cc.has_header('IOKit/storage/IOMedia.h')) + ################# # config-host.h # ################# @@ -1246,6 +1249,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', prefix: '#include ')) +config_host_data.set('HAVE_HOST_BLOCK_DEVICE', have_host_block_device) config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#include ')) diff --git a/qapi/block-core.json b/qapi/block-core.json index 2ea294129e..a54f37dbef 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' } } ## @@ -2814,7 +2815,10 @@ { 'enum': 'BlockdevDriver', 'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs', 'cloop', 'compress', 'copy-on-read', 'dmg', 'file', 'ftp', 'ftps', - 'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscsi', + 'gluster', + {'name': 'host_cdrom', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, + {'name': 'host_device', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, + 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' }, @@ -3995,8 +3999,10 @@ 'ftp': 'BlockdevOptionsCurlFtp', 'ftps': 'BlockdevOptionsCurlFtps', 'gluster': 'BlockdevOptionsGluster', - 'host_cdrom': 'BlockdevOptionsFile', - 'host_device':'BlockdevOptionsFile', + 'host_cdrom': { 'type': 'BlockdevOptionsFile', + 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, + 'host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, 'http': 'BlockdevOptionsCurlHttp', 'https': 'BlockdevOptionsCurlHttps', 'iscsi': 'BlockdevOptionsIscsi', From patchwork Thu Jun 24 18:04:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12342779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27197C49EAB for ; Thu, 24 Jun 2021 18:14:24 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E74C261249 for ; Thu, 24 Jun 2021 18:14:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E74C261249 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwTrr-00012h-3w for qemu-devel@archiver.kernel.org; Thu, 24 Jun 2021 14:14:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwTiS-00081Y-65; Thu, 24 Jun 2021 14:04:41 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:42580) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwTiN-0001US-Vl; Thu, 24 Jun 2021 14:04:38 -0400 Received: by mail-ej1-x62b.google.com with SMTP id bg14so10853600ejb.9; Thu, 24 Jun 2021 11:04: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=WRN9g/NoEZLbkWiwwJHbOcIt/+zi5y6rwgfm406D0pw=; b=ZoSazrxxj5EGv6bI5oEcIla9sFSg5UaqLCIGhdW8F9JH8FksklOFOSKBhFPf1pGXpb gLVpWHi6P97aXY5t0o8LbYDpnQppMmik4KSbM/bdySHEZhX+09boI3zgZ1SoUnucIp3/ pnbXfM0JJ1vaMCixOYklKqURXR0tSi00dAL/YQVB/nAapgmGmymG77d7eVJ0ZKVitVVs mKcoTwghuYT/2HNuwufRAcyjf1weCO1hHfxLZQLlMIXWS3J+FAGhuP/BL9kj8dU/dggh kB6E8ysSBnYkTgjhPt8olVHJkCAf4wjd5oZJM4/Sef0jEgEPzwlCuMsYvZ94oMs+5HcJ Jrtw== 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=WRN9g/NoEZLbkWiwwJHbOcIt/+zi5y6rwgfm406D0pw=; b=sOTp8Hz0L+MFeCwpw1tdy2fi8ZO4+xfnULRSYUKSoaXtXtMhdTle8PV5Et28ArCgFK rp+eBgo3HDWBvfnqLT2hk7D1rHQUfwiHvNq0/YAN2y+M9PGg1lcTjwvka5J5VyoihJSc EAWiQ4EaUsTt4NA2TibdkfQW6Hh59eQatfyKRA5CaQXlD5MQF1Azwn47EONganXTqh2m bcjJ5TM+e9V9tKd85tOZRiT+ugGgLCRxCJ+GSqrWNyKGcWyQi1JYAq1oa34CC415DZn0 8vy/pIMp+3APCgxXPnz6vMEq75FWHJWx+4H+wEFBrrHyEEI+rAbkSIXkyIkS83l2C8gM ITyA== X-Gm-Message-State: AOAM531OvFcfV3Zi9ENjQMxMY8UVndq8NVd52yjXrHkLgmB9QG9y+v7I x1ii0Me090WPpwAajajxD1j5mhVRjSM= X-Google-Smtp-Source: ABdhPJzWfX7zImDFRRqxt95f0+mrHH3+BmRJe14OqTQkKPrjq/BmXlNlutkmpxCUDB85GI7kufO82w== X-Received: by 2002:a17:906:edc7:: with SMTP id sb7mr6565991ejb.29.1624557872561; Thu, 24 Jun 2021 11:04:32 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id a1sm2436466edt.16.2021.06.24.11.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 11:04:32 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 08/11] block: check for sys/disk.h Date: Thu, 24 Jun 2021 20:04:20 +0200 Message-Id: <20210624180423.1322165-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624180423.1322165-1-pbonzini@redhat.com> References: <20210624180423.1322165-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62b.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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: Peter Maydell , qemu-block@nongnu.org, mreitz@redhat.com, Joelle van Dyne , mlevitsk@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Joelle van Dyne Some BSD platforms do not have this header. Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Joelle van Dyne Message-Id: <20210315180341.31638-3-j@getutm.app> Reviewed-by: Max Reitz Signed-off-by: Paolo Bonzini --- 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 bb3a5be796..a95a9fbcbf 100644 --- a/meson.build +++ b/meson.build @@ -1250,6 +1250,7 @@ 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', prefix: '#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')) config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#include ')) From patchwork Thu Jun 24 18:04:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12342775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C070C49EA6 for ; Thu, 24 Jun 2021 18:12:49 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C344D60FEB for ; Thu, 24 Jun 2021 18:12:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C344D60FEB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwTqH-0005iZ-TB for qemu-devel@archiver.kernel.org; Thu, 24 Jun 2021 14:12:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwTiS-00081W-6K; Thu, 24 Jun 2021 14:04:41 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]:44947) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwTiN-0001UY-UQ; Thu, 24 Jun 2021 14:04:38 -0400 Received: by mail-ej1-x630.google.com with SMTP id gt18so10842155ejc.11; Thu, 24 Jun 2021 11:04: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=1inmLhcVq0aSD320zpWtlTjRRoDETw4S+Ab6hL0QjO8=; b=rr1/z9Kciyox4j/5FbBQ5+ZUvjci1mOQW/njMSxKTTBG06eFCYvbQQ5qmXcDG4lfkb VnZFp+RA2/2T8qyxZH3Jhyc991HnIikvxzlUF07iE7k+W0FbWWeOzHZagGA7BQ3dhPzX ag3wSQf14oKkf8+fhxV8Of6SQYue43DYWs5P5uSzHym73PWbJWrMu9k6lCN4gBbnJGRp CNYR06REciWanIprdFfO882c/fjwNiqpM1Yfl3ckCACMJhVEIg4SkWe9cZWUUHcqOPtV dbXeA1oUK+xxrb0An64qUa3Gi/3qUJpSLJoW0fzPq/E57oHguPCzM7sVu8i4++IKotQm svWQ== 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=1inmLhcVq0aSD320zpWtlTjRRoDETw4S+Ab6hL0QjO8=; b=a9QlmQUOxGzJPUv1ciB/xTF/AqQ7idhi5nWGujekJP9TmX7jFgp2LUiDnCLZijcSpq wrCE0ZHQcH2WL6wep43tER7VCQlhWf+nXD6JR2gxb49TNN1wxJK+09BaVzqqJQdharNh c1jSudLSaIU3EsStJfBZM6/5LRLhuPqmIu5XwwnThFR9oQp+x6WrAsyuRSGaOE8sTJgu S/5q/qkCv/0jdpXL/ZSTCJu6ZRAoOTVEMhdbzKaCubYY+UM5lacIE+pkj69nU2B2ej7J WGhfCkcLFy+ad56k1X0nvfmAQ7Uo9B0+bePf3LPzku/bSguVCN83dkevffZ2wJcFNPcy dm5g== X-Gm-Message-State: AOAM5304i7G3fTUC9b4T+Id128ox1YRcvBcZASYa8MFmhoKUkRjMT39Z PSR9fLFP8QGi8zKF12qZE8H9LyKBFJ0= X-Google-Smtp-Source: ABdhPJxA75QDU80ZgQg5xkQzSx1nm3kyxW+z0A9XC5ZbUhXy7iq9Ks784whwm3IjgVn63saNlqyw8A== X-Received: by 2002:a17:906:9a4f:: with SMTP id aj15mr6354005ejc.197.1624557873392; Thu, 24 Jun 2021 11:04:33 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id a1sm2436466edt.16.2021.06.24.11.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 11:04:32 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 09/11] block: try BSD disk size ioctls one after another Date: Thu, 24 Jun 2021 20:04:21 +0200 Message-Id: <20210624180423.1322165-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624180423.1322165-1-pbonzini@redhat.com> References: <20210624180423.1322165-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::630; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x630.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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: mreitz@redhat.com, qemu-block@nongnu.org, mlevitsk@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Try all the possible ioctls for disk size as long as they are supported, to keep the #if ladder simple. Extracted and cleaned up from a patch by Joelle van Dyne and Warner Losh. Signed-off-by: Paolo Bonzini Reviewed-by: Max Reitz --- block/file-posix.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index e56bb491a1..f16d987c07 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2327,39 +2327,37 @@ static int64_t raw_getlength(BlockDriverState *bs) again: #endif if (!fstat(fd, &sb) && (S_IFCHR & sb.st_mode)) { + size = 0; #ifdef DIOCGMEDIASIZE - if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) -#elif defined(DIOCGPART) - { - struct partinfo pi; - if (ioctl(fd, DIOCGPART, &pi) == 0) - size = pi.media_size; - else - size = 0; + if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) { + size = 0; + } +#endif +#ifdef DIOCGPART + if (size == 0) { + struct partinfo pi; + if (ioctl(fd, DIOCGPART, &pi) == 0) { + size = pi.media_size; + } } - if (size == 0) #endif #if defined(__APPLE__) && defined(__MACH__) - { + if (size == 0) { uint64_t sectors = 0; uint32_t sector_size = 0; if (ioctl(fd, DKIOCGETBLOCKCOUNT, §ors) == 0 && ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) == 0) { size = sectors * sector_size; - } else { - size = lseek(fd, 0LL, SEEK_END); - if (size < 0) { - return -errno; - } } } -#else - size = lseek(fd, 0LL, SEEK_END); +#endif + if (size == 0) { + size = lseek(fd, 0LL, SEEK_END); + } if (size < 0) { return -errno; } -#endif #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) switch(s->type) { case FTYPE_CD: From patchwork Thu Jun 24 18:04:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12342723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AE70C49EA6 for ; Thu, 24 Jun 2021 18:11:46 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 13AB560FD8 for ; Thu, 24 Jun 2021 18:11:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 13AB560FD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwTpJ-0003Fw-6w for qemu-devel@archiver.kernel.org; Thu, 24 Jun 2021 14:11:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwTiS-00081X-6B; Thu, 24 Jun 2021 14:04:41 -0400 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]:35514) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwTiO-0001Uf-9N; Thu, 24 Jun 2021 14:04:39 -0400 Received: by mail-ed1-x52e.google.com with SMTP id df12so9829498edb.2; Thu, 24 Jun 2021 11:04: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=BevMjojoz4Zbbmnx7q+o91aCSPbNgcWVWrT6Beq1/n0=; b=P/aa0oaMfot02Hc47c+81ANMFB5yE+bJ1WpScVwsE44Cc1w5kAQm4WpixNPLVZk5Th JHDDu7Psuliiz4JANSXzJpfZyoJd43UNi0aIDR3JG6tJls1Yc8GZbObohZl8JYJgy3CB bZ2AHeodzMy4zPnNzmBtyteW/JWaetApSi81wk5nMDmDSuyjm88WXXnZ32O6GncJK4ZH C2k1iDBtM4lBJbz1jkS0rDP53ylfKxNe09Mf8TPWqS000mXdbITC8ZSHOMU+xMJ1rXdW RfkOvwkQ9ktce2o/KAs0KpdNPB2q2SqysgH1dcYAi6UXcovApfdW/AC6otgMxK7AhSQn 7OvQ== 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=BevMjojoz4Zbbmnx7q+o91aCSPbNgcWVWrT6Beq1/n0=; b=t0tS4RY4FtPySKgh+xb1TomhHK2V82YO5bo4FqUbAwMQCRGQUn2IOgNcfDQo0HCjiv e0nhZgZgqJg02nSpE732DXo4DlPOAo0QtfVyxgPrNOqo3jb70BN0OUoAuFbglvB9OAMM Ptfa9zrEJ2hlKNXoVQv4PbFm+Ea9USwtjY6+U12RlTRw+skAkDlfeZEkMmUbiErtXC0Q NUmxAaHMdG7hzx8X72EgtIw/f3YEZLGsnh10F7xzANDmioBA087DHnUxw8G4Lr7yWKBx rfZEkpHdJ0Qdqu/jI4U6gEQJAqntpDm7v7KtUWr41qqyrZg4EWIvxGk8JTKTHzsax1S6 gNtw== X-Gm-Message-State: AOAM532rhqBbu+Qs64A/BiIntNlTthUBvL7xEjIbptElO7bYdIAtJDjx ECpCCSvwXiw8gBhM/tAmBUwbas+k+Qw= X-Google-Smtp-Source: ABdhPJw4Sy+1cAYVeLyYEo35IcTLsO8Z0TRmTPIbGuow/4sG76pFeAkOmDtKXBhd09UI+rXBvX+btA== X-Received: by 2002:a05:6402:1e89:: with SMTP id f9mr8934095edf.117.1624557874316; Thu, 24 Jun 2021 11:04:34 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id a1sm2436466edt.16.2021.06.24.11.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 11:04:33 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 10/11] block: detect DKIOCGETBLOCKCOUNT/SIZE before use Date: Thu, 24 Jun 2021 20:04:22 +0200 Message-Id: <20210624180423.1322165-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624180423.1322165-1-pbonzini@redhat.com> References: <20210624180423.1322165-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52e; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52e.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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: Warner Losh , mreitz@redhat.com, Joelle van Dyne , qemu-block@nongnu.org, mlevitsk@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Joelle van Dyne iOS hosts do not have these defined so we fallback to the default behaviour. Co-authored-by: Warner Losh Signed-off-by: Joelle van Dyne Signed-off-by: Paolo Bonzini Reviewed-by: Max Reitz --- block/file-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index f16d987c07..74b8216077 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2341,7 +2341,7 @@ again: } } #endif -#if defined(__APPLE__) && defined(__MACH__) +#if defined(DKIOCGETBLOCKCOUNT) && defined(DKIOCGETBLOCKSIZE) if (size == 0) { uint64_t sectors = 0; uint32_t sector_size = 0; From patchwork Thu Jun 24 18:04:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12342777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 504AEC49EA5 for ; Thu, 24 Jun 2021 18:13:05 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 064CD60FEB for ; Thu, 24 Jun 2021 18:13:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 064CD60FEB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:36494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwTqa-0006W8-2C for qemu-devel@archiver.kernel.org; Thu, 24 Jun 2021 14:13:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwTiT-00081b-Df; Thu, 24 Jun 2021 14:04:41 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:34420) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwTiQ-0001Uj-Bh; Thu, 24 Jun 2021 14:04:41 -0400 Received: by mail-ed1-x529.google.com with SMTP id i5so9849710eds.1; Thu, 24 Jun 2021 11:04: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=wJvWsUqGOQTva1vOWOjj4YQ10DwGdZUCbC7uWnekL7s=; b=VDexv85f/KxfmkV+D3FzBX/Q6qs0DzStLWOMaKTpnI/Y+trWcyeHZeS2NxkwL9xvmb Xl6qcLa4AgPIgTb2CWHQNfTNbu8tM1wbGSWQe26LkP/dU17SzZHqTvSkt7laorndZc/u RbVZIuCnQm7dtsJMJJYb+Mf5Rbxslc0hCSqP13qFN0hdtCXJd//lcfSX6q3N4hAK/R/r Qqwfp45jDPiFfLmtHwM0EbmtyIPmAhc/UpvYphzJjYJlo8pZRkD7Mhio38uIA6QlHvix B8TNACQZJRsUsqB+oK30rn0TdldeAOYyl3ZOC/fiCrBKiF4alkjE3F1v01NMxmpxnX4c rrEA== 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=wJvWsUqGOQTva1vOWOjj4YQ10DwGdZUCbC7uWnekL7s=; b=hRbXI6AB52ba8mTsOcgFcm7O5gT5Mr8/gcLiDWFmuXXPfMp1tIx+ktvEyJiCHCblIk vuSeiPnYknw2JZNd2QXVFIQt8XCi7gRXsP/XCene4jtbgj5KCmWW+RI3+1qezDwdIGTG qaBeOy9fufOUwRcACbeifJPzOmpZgB4qPKGbU1PAqj1aHpREBQzwjwGbbM9ovqQ+DovC 7XA09ylHlltTHXyRt2a2q01Tqki4wGoq283iVFAXWd+s1d9yK763W7u3m0PIeoviQuPl E8BXWXNS1RYPjmtOTIijFILcpXVY4TJXqJOK04BkUMkv12m97Lo35V4uwlhcEBzFWa+o mxIw== X-Gm-Message-State: AOAM531rMck0XAk8iOwDB7BiBywyyUEMW58vzqssxIEWjm4iobSpqnJb uEvnucW+uPf37vyMKtvB5/hs8ysBg98= X-Google-Smtp-Source: ABdhPJxNAoJkHoFI/N6ikIg6xr4dOQ5I2hqDxbsumuw8zSgdC4cyCXTDzkEMgDPIJqWgE/Z82QlCYg== X-Received: by 2002:aa7:c3d6:: with SMTP id l22mr9003804edr.245.1624557875158; Thu, 24 Jun 2021 11:04:35 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id a1sm2436466edt.16.2021.06.24.11.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 11:04:34 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 11/11] file-posix: handle EINTR during ioctl Date: Thu, 24 Jun 2021 20:04:23 +0200 Message-Id: <20210624180423.1322165-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624180423.1322165-1-pbonzini@redhat.com> References: <20210624180423.1322165-1-pbonzini@redhat.com> MIME-Version: 1.0 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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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: mreitz@redhat.com, Gordon Watson , qemu-block@nongnu.org, mlevitsk@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Similar to other handle_aiocb_* functions, handle_aiocb_ioctl needs to cater for the possibility that ioctl is interrupted by a signal. Otherwise, the I/O is incorrectly reported as a failure to the guest. Reported-by: Gordon Watson Signed-off-by: Paolo Bonzini Reviewed-by: Max Reitz --- block/file-posix.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index 74b8216077..a26eab0ac3 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1347,7 +1347,9 @@ static int handle_aiocb_ioctl(void *opaque) RawPosixAIOData *aiocb = opaque; int ret; - ret = ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf); + do { + ret = ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf); + } while (ret == -1 && errno == EINTR); if (ret == -1) { return -errno; }