From nobody Sat May 18 07:48:38 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623158331; cv=none; d=zohomail.com; s=zohoarc; b=HW9fYEu+g7i1RGRWm7jzYlpQoFH+LrMR2rPk7JFL3jBTDtrBGLnvMaLADgwNdw6zE1TkyYvKhI+HO0RGi0BxaAsJzio/yHGjcwaMOagIxN4w3Dl000GIfsKOmcktJ7QRVgzSQBBuPbfyBm7o5TVd3/ZxcV17m1UgDhEN/AghT8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623158331; 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=/T+WzI/t8Mf28zcKRtnur9X7J1V8blJ53LC+b/8bDvE=; b=ZDqACJVhRtL59R0Pli9XpUgw1pSbwKIo1xAK+br9BUFJnLF1zdvwSCqRJS7/W6ienPKbPzWkeE5lpSZpEWH3bOyYyBxWec/xDID3MFgWfmx2xHQ/6juqmIc3aH/k99pIv4ePnSal1Tj1g7H5CWS1MgtCIrhDKDEkaQOjTLlyMP8= 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+importer=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 1623158331165518.8227915615107; Tue, 8 Jun 2021 06:18:51 -0700 (PDT) Received: from localhost ([::1]:52776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbd4-0002nV-8k for importer@patchew.org; Tue, 08 Jun 2021 09:18:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqbay-000834-9G; Tue, 08 Jun 2021 09:16:40 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:37416) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqbaw-0001v3-Kj; Tue, 08 Jun 2021 09:16:40 -0400 Received: by mail-wm1-x330.google.com with SMTP id f16-20020a05600c1550b02901b00c1be4abso1936491wmg.2; Tue, 08 Jun 2021 06:16:37 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id i9sm15855686wrn.54.2021.06.08.06.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 06:16: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=/T+WzI/t8Mf28zcKRtnur9X7J1V8blJ53LC+b/8bDvE=; b=Hf1JpuK1kJ0tHbj8JHe6Bn/jOS4zXjqFBzMbA7djWDYDJwIVuYWNDONUoL7QrnqBkM 7zsKOeo/B255UfSefv7hEQ1FbO3vxHj1V35B8yOLEtJGcms/1Etgp7oX0JI64XwF4vxR JO5LH4osEs2bzEx2sR6Hd99+SyGzkUi5k+OpAY/IkKFm1EjuxrCThd82KTKEoJ0hi/2l o0aE5rb8TvHM15I18uJR3qGV0Wzi7r1Jlat6F0CfBuw1UhsVQ8VlJmVPQVqAq8RaEy6R yg4StLYcYPE1crSQlteLSwx9kZFPyyI5Bh2dj7to4F34SkXM3drRsR7N6aZ+uzAHP+nN mPIw== 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=/T+WzI/t8Mf28zcKRtnur9X7J1V8blJ53LC+b/8bDvE=; b=mubOOGfkjKbxLYtm+5l4132zN6pZbaMRLgzbcxHAa6OUkYpBpEE1smloyCMqODfpDQ OBJYtjX3RraddSjyjr8T9WNZzocnDgUMXYdcYKV9ZhFuqSHLpzmp2mExDSmMCjSiOMW+ 0msc7jU2BO6A0B3kwP24A3irwdpAjx5hvmd+kF9h4QpIH8ZLcAReZg6CL7K7V2fw1QBk h6m0prg5tl2GRQh42iq6RaD1XjLkswr1zdrfK46Rujcl1Ofvz9aJL+L4wKOagObBoWDA eQw5r8tUVteQghx2FBm0cnl0NX7yJJSzXKeYfU49EUijQUyjN+F7QeL0EQdd6ZKfmEXp WE2w== X-Gm-Message-State: AOAM531KIZtyY6PHMzYiNDWFqaOgOeGjUtfN5WhYn/b+n5vBKzwvRpL9 vJf90fx8P39/BdkjZWBsS75zH2SrlizpIA== X-Google-Smtp-Source: ABdhPJw3H8ZZnw8C4vlHle6I0OPh2Wu1dy0j4PodjhgVjGF1LQ9ophu/FJF0ScIeAj7xnPrNWhwPRQ== X-Received: by 2002:a05:600c:1c1b:: with SMTP id j27mr22509351wms.133.1623158196984; Tue, 08 Jun 2021 06:16:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v4 1/7] file-posix: fix max_iov for /dev/sg devices Date: Tue, 8 Jun 2021 15:16:28 +0200 Message-Id: <20210608131634.423904-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608131634.423904-1-pbonzini@redhat.com> References: <20210608131634.423904-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x330.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.248, 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, vsementsov@virtuozzo.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=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, 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 --- block/file-posix.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index f37dfc10b3..536998a1d6 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 -ENOTSUP; + } + + 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 Sat May 18 07:48:38 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623158453; cv=none; d=zohomail.com; s=zohoarc; b=jnr5uWtqpw+QAQe2adLrK5bQdKN9do8Zo7IKwSdtR48y8e3u1HI/hiWfqur67dCDraqOtcaSrSAq0WUPRpa7XPYVQ1nUjxmd9cuaY9WKp/7agB9kqa0nE2N6GAX7mZZ80MTyhMCrC8CwZm0RY6IcB9LbJhgWCecdvVSrMTftr/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623158453; 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=w5BYwz9CkzKMn1Gz4JxvpKD5vqS4sgLfzaKKcpIrvYQ=; b=E5tDi6cgLOvAZ9fLLEY1R8x27DTYyGmn9HZXaBE8p35QggRO/fdds0ZO3OBvUgcEzNJ0Lzu1R2jnRb86NvQJidl/WxTmzfPbMBs4Z+GLV7Q+xk10GpbEjOuK38kzARkg+JjwnjZlABLXPUIeG4D6T/fdAB0/zlnp4Ak3beX2WZo= 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+importer=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 1623158453647673.5753708336246; Tue, 8 Jun 2021 06:20:53 -0700 (PDT) Received: from localhost ([::1]:60682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbf2-00084r-HE for importer@patchew.org; Tue, 08 Jun 2021 09:20:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqbaz-00084V-JF; Tue, 08 Jun 2021 09:16:41 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:53232) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqbax-0001vI-Ls; Tue, 08 Jun 2021 09:16:41 -0400 Received: by mail-wm1-x32c.google.com with SMTP id f17so1825730wmf.2; Tue, 08 Jun 2021 06:16:38 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id i9sm15855686wrn.54.2021.06.08.06.16.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 06:16: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=w5BYwz9CkzKMn1Gz4JxvpKD5vqS4sgLfzaKKcpIrvYQ=; b=o0W/0u5v+AKNCd0FurLQgWlJMr4JFZI1SCp2nwuMp7/Kh27sxSaXqIitIlOPG8a+H7 f6rImiq3v78oY47EWHWDazjVI+0d1HN9NkgY0fDDJXqn/w06eht7/rO7NRmXLf9LDb9W 5Leps4vvz3FCya5AQLi4Spia/LtstqnbMbg4XWxHvQuDFnlrMyhZRI0tdAVZYasl/977 0n1S8dtZorgfN+dmfvX3lzuENn2w152IJmR4PW56GeDx2cjZb+ppH6c0HaKdQ51YAGNb DLskqeEjaiEUC1+8pFNiO8V6ctay9So1kdY580eWfovbjYVsQBnpdXYYVsH0XBJcRh1A 7vHg== 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=w5BYwz9CkzKMn1Gz4JxvpKD5vqS4sgLfzaKKcpIrvYQ=; b=pA5Jm3IWgy6ZgtXiML4Au3jrVxRahIn/WRtAJ2Xl0SxKaAjtHv7Y5gvRq4i2pOLgm4 jvF0a88hAE1LLiDFl9RoxR9mgygyCK/F3Uc5xHHhyyY/0+uuxTYKT66Y2N5s80K2yiEE +LHqIKpw/CNPwWoGoaAxal/veyMac7p/blQ5u056xxYxYtnYVWsyZZv24itfFLibYZgx dq0//gw93tR1l79aNahl0sSTmoeZiGISS0CLCrwJ1asyVehcw9N0dip7HsiNh312p9QT DNPAsaP2Jg6rBmHMH7Uof28WfwEnThmbWrmD34BUgRQgLPGacGxc5uC5YL0gnv62NTQG NSNg== X-Gm-Message-State: AOAM533GFYEw2Ne7EuNFSYFyAoT1UnELjNCLm56Ah/HRYRT9FwgpATlC 8/bne3fk8ehHk8RmuUkygJZ8WOgPON95vg== X-Google-Smtp-Source: ABdhPJwVpue1B5NM5p04uk/2R19WyMFiyRQm3NhRxUtgIwfuIQeUJ3wzgZV2hSdrruFf5PU21kVdnw== X-Received: by 2002:a7b:cc09:: with SMTP id f9mr21786708wmh.104.1623158197708; Tue, 08 Jun 2021 06:16:37 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v4 2/7] scsi-generic: pass max_segments via max_iov field in BlockLimits Date: Tue, 8 Jun 2021 15:16:29 +0200 Message-Id: <20210608131634.423904-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608131634.423904-1-pbonzini@redhat.com> References: <20210608131634.423904-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32c.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.248, 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, vsementsov@virtuozzo.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=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: Eric Blake --- 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 536998a1d6..670c577bfe 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 Sat May 18 07:48:38 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623158544; cv=none; d=zohomail.com; s=zohoarc; b=nAP8cEVK/MmYIDj54EgfsuQ35BE/gHYIn7ukdGtov+mfAqDffJvvqD18TssbdiqKtYFqmhBsbHBgfiO6XhCUQu7PbdX9GZ9Go5pbbTll6ZuShRdvLqCUr83CiLTmXBUPvFmXDQHI0FO5O7tk3XcWiHJuzKxJok3aH+m3uB6ZYOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623158544; 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=dF7owOl+svnhvnWs3WgYxu4nGCHypf8DifXjCW0AXrU=; b=G3t9A88uboAlvGxClnHjNioTzi0tkCsJoCcT6pL+EFK25/MjVOZE/FYCvCRpWmSDIxnPsyaoBqDqRmJy0z3vjVHWPitocP5fZ2GmOy/+KxANyG7PiHnx5TR73u5IOQX0zIsWaNRZVvUpHsb6VDRCKf9elC6ai/qXvE1QtonXu1s= 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+importer=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 1623158544981199.5987501083638; Tue, 8 Jun 2021 06:22:24 -0700 (PDT) Received: from localhost ([::1]:37766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbgV-0003Bh-Rg for importer@patchew.org; Tue, 08 Jun 2021 09:22:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40928) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqbb1-00087R-4D; Tue, 08 Jun 2021 09:16:43 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:39704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqbay-0001wI-Bv; Tue, 08 Jun 2021 09:16:42 -0400 Received: by mail-wr1-x432.google.com with SMTP id l2so21575655wrw.6; Tue, 08 Jun 2021 06:16:39 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id i9sm15855686wrn.54.2021.06.08.06.16.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 06:16:38 -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=dF7owOl+svnhvnWs3WgYxu4nGCHypf8DifXjCW0AXrU=; b=gAcmYzrNXaBPye7k7uvaY5wgZkdQMrTwBS+gtIEg3ZUCdXZW/gs7pYIhMR+Q5T9VgL vnVW0/SMyFvaXsr3o2Wy3T8HLhohqotkpmqdIGHmTXJKHNLzf14vOVJp7VyHjrrLiIUn sdSvigXhOgIuUuk4xGumJfw6oCYWKTl5ka0rZr31RUvxuAI2oks/EiRpZN2kikNOyVOE BNFa+n5e2zOZ8RezMJk0MCIfucMhQgnIBi2dTCilLr/1YXVIvTNngmdFkmdvfBTXwCMM NQFrEyFF6vSCLOxwWlcJncsrc4z0nXoJp1JNu9gdBJj5HSYv7QudtRqh9JNgRske59BA ICBA== 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=dF7owOl+svnhvnWs3WgYxu4nGCHypf8DifXjCW0AXrU=; b=ZlR75T3t2Ah0FNe4dHMRuMSueaq+0uGodrthtZWOsyeuZ4hJ0QegHGjMqWtJvcxSa0 ld2/GykCQHftWhHvVjHwsFosmXPBjHgWoAj7rtiuuDxhsFlAILUIEXsALeQJrAvSssRa G+jI18ujYCbSkJK4RetEzGjZov4MaGRMEfeWTwLTIWJ29sdygrkSPZyVoFXlLlCAJdE7 qok3Je4ts47WqWf3F+gmsJqaSoWUUwX2UcVLIE57k6UaMZOh76oXMiT3DR3WLtfVt5Cm mRp4US0Rfi9WMf0/bMFP3AIc7T8niXfhMMuGSnAsOF/okXjFd1FBW79y8B+Xd3LERqix nltg== X-Gm-Message-State: AOAM532C039JPj1PiHgm+L8F7SFZOm9m0WQPCaZ/IW5YZUgUSZ0US+jH +33YU1XofXIsY2j5feulTrijY5IywMf0tw== X-Google-Smtp-Source: ABdhPJylo3c8FC5lf0LbgokxGWpCB2IBgx2O1kkNHzs3f5BtsOxA6g0LF+YNvUblk0h5lF3LV0Ji0A== X-Received: by 2002:adf:de03:: with SMTP id b3mr22720768wrm.15.1623158198466; Tue, 08 Jun 2021 06:16:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v4 3/7] block: add max_hw_transfer to BlockLimits Date: Tue, 8 Jun 2021 15:16:30 +0200 Message-Id: <20210608131634.423904-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608131634.423904-1-pbonzini@redhat.com> References: <20210608131634.423904-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x432.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.248, 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, vsementsov@virtuozzo.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=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 Reviewed-by: Eric Blake Reviewed-by: Maxim Levitsky --- 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 670c577bfe..c9746d3eb6 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 Sat May 18 07:48:38 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623158333; cv=none; d=zohomail.com; s=zohoarc; b=Nwnpg2A32kR/NSvPe8QU6ll4mB+bbyvnFezhprNjI/swxO8qFIUXT0n5MdO0I9E3n9xDShul7yFEB9chYULjKjVnu7rYKnwMeQQfKBAeGyRJnm1HZDRTL5mr0fKXt229Wf8pI8WA4hAKXKf1r2ttZ26sM8BE1GGXvQzT7PDu3os= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623158333; 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=ikfSr+R6k78Hz4eiit0nQyTHY92c+5jpIVNQZpw7fc0=; b=Dv4Xr+zJlD/45BMtH0wxVaUDSVes6GHxjtRwe5r693NWivSOIJnXq1pHGVlKownS7j9ma1QSEi3SSXu7eBmJYIX7qkTbp8MW7XcVR+pKdoA7H7vLqs8eOS/+L9AnSSkAVtvJUOQ6r7fP9uTR+DeeUwwuve9vQ9PMPWTUndPgrNE= 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+importer=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 1623158333524628.9401727422601; Tue, 8 Jun 2021 06:18:53 -0700 (PDT) Received: from localhost ([::1]:52964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbd6-0002v5-NW for importer@patchew.org; Tue, 08 Jun 2021 09:18:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqbb1-00087L-2X; Tue, 08 Jun 2021 09:16:43 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:36393) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqbay-0001xm-Vd; Tue, 08 Jun 2021 09:16:42 -0400 Received: by mail-wm1-x335.google.com with SMTP id h11-20020a05600c350bb02901b59c28e8b4so1442068wmq.1; Tue, 08 Jun 2021 06:16:40 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id i9sm15855686wrn.54.2021.06.08.06.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 06:16:38 -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=ikfSr+R6k78Hz4eiit0nQyTHY92c+5jpIVNQZpw7fc0=; b=kJqFIWRjxld/d0eIZwtvpHkKnv7dA3UjThqsW6YZ4/2CZsu2NJYig8wLUZGPsXgOd3 aqTjPoQfEQWFGV/oB7GJOgoRAqPq6P9YZLGLQuLneo+1q7XcZKSeXNoVNaQbCu36AqnC fiKBkrEkKi02UHmKqm7uttOxwKDjZDtqOBGQ8wJasCpEVcXTgZwHlJLUFN7wHjibx296 0a/PG2q3s+ZzdB0qx1tPVJpcsv5ZA+4pdlPeAH1g3FPbGieSMFCAGE7fySKf0PeBa1QZ n+11h/07rltoHxGAJY/3lhV788udQZFeoCJjdj6mRG1K97lK1rxFBflU7QF10/tdUCIF i3OA== 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=ikfSr+R6k78Hz4eiit0nQyTHY92c+5jpIVNQZpw7fc0=; b=mTOlpFPMRwMQPpMXbFodGSO6S376uacJ0J1xDo5BdU6dr4wmpnP3c1CNpVJXN70jLv E/TIDZxybEBM4tumE1LEqWJkZ0KVzu+m+PK9jUCCqeMIkf+E2Zbazj62wDJOcKcFUD3V DYJcgBs1x9RuswnJodqDkmYqiJo5/PmR/0+JWnl8y+4p30XEODVyHw41yhW1E7UFgOJ8 Pa64DoX6DpbdxGyXDx1LZcCDJrq4YdcF1nCbrAfY1/f3ozfbKA1Br4PnBg95gfa8tYSD 2q4ghyDGyY8JmAuCbT8Ew8gqpFUJ0F/0E5WCkDlcscwD8HfRl4Ibh6jVMNyrCgUmXvMe 1TFg== X-Gm-Message-State: AOAM5324p7Y32vJ5Q4NgMVJRpq0K6DSNiZi8IgZIKypHQFrjScgMYHym a7MxcC1UHoUcdFfWD/RZ7VgsgxvMTcpXhg== X-Google-Smtp-Source: ABdhPJyHZCbgb2MasP0d3LP947Ph+4IeNKQ+IHq8KM0IZQooA078r8+YdOZ8N3YrY7aXTZKyllBVBw== X-Received: by 2002:a1c:7313:: with SMTP id d19mr21866863wmb.14.1623158199097; Tue, 08 Jun 2021 06:16:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v4 4/7] file-posix: try BLKSECTGET on block devices too, do not round to power of 2 Date: Tue, 8 Jun 2021 15:16:31 +0200 Message-Id: <20210608131634.423904-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608131634.423904-1-pbonzini@redhat.com> References: <20210608131634.423904-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x335.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.248, 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, vsementsov@virtuozzo.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=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. Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake --- block/file-posix.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index c9746d3eb6..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,26 +1178,20 @@ static int sg_get_max_segments(int fd) int ret; int sysfd =3D -1; long max_segments; - struct stat st; =20 - if (fstat(fd, &st)) { - ret =3D -errno; - goto out; - } - - if (S_ISCHR(st.st_mode)) { + if (S_ISCHR(st->st_mode)) { if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) =3D=3D 0) { return ret; } return -ENOTSUP; } =20 - if (!S_ISBLK(st.st_mode)) { + if (!S_ISBLK(st->st_mode)) { return -ENOTSUP; } =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 Sat May 18 07:48:38 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623158335; cv=none; d=zohomail.com; s=zohoarc; b=eLmUER6SlzdsFaptSbo5Jchf2HvwrKqn/p749TU5r6C1r92vV1Gz6nEB9O8fsrb1LSnCqa6cJvoXEoIPrW0NWy/YyWcO1CadGZm6EdzdzC5tnO2R6IyqkJ11sHqcxEOubCWS9Z1ysnpeYEAMaftlovuhc+ecJsUoK67t5Nlygos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623158335; 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=YWGng/AgwvqijHTZHExWPRs5g9nBRTrMUPBsYX6VZJ8=; b=kgsig7g5IW7q89F8OLhOUjEXJQ6GCTNKIKkNEbKmwt2te2a28xRd3HcNW+NJV6Zcxl/8o8aoCVX3l5aleobtJDkm5htHVb5fnFP6+lc9gzxM+RPzG9UkTWgdUjLJ2TVOoL6107wH1bxAdWNIqCewFVwy+kWy3iAzXSC0hirWzEg= 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+importer=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 1623158335981515.6334316600944; Tue, 8 Jun 2021 06:18:55 -0700 (PDT) Received: from localhost ([::1]:53166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbd9-00033j-58 for importer@patchew.org; Tue, 08 Jun 2021 09:18:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40942) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqbb1-00089w-Oi; Tue, 08 Jun 2021 09:16:43 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:54156) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqbaz-0001yT-GD; Tue, 08 Jun 2021 09:16:43 -0400 Received: by mail-wm1-x32c.google.com with SMTP id h3so1809129wmq.3; Tue, 08 Jun 2021 06:16:40 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id i9sm15855686wrn.54.2021.06.08.06.16.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 06:16:39 -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=YWGng/AgwvqijHTZHExWPRs5g9nBRTrMUPBsYX6VZJ8=; b=U/6W5ka/QW/xxR2PDeTaBDl0hmnIE7bT8H3JIxCDcFFVJpir0nBwYc+0yHAeGsbckb Is7vFRibwAVDYcORUNIw1HgvUcvCwiIWbj+T4bwYtsH/OkxAYWhob58ApBARqNIriu51 GidW9hDN6mTXcv15AFY+vjsqed5e8YwYrsD6UT/H2y/Og8E+HeTs9n6sFA1gwm3Ol9EH vNdZr2idFrvK5aJbACRkqVtRZAJPHMmc/yotSLuug6o9amvxTMZBtVo7RDjjCGkEcCyR /NHfespABPTdlg3uRCmnFpWg8tER7kirmBe6erM1u+nbzw08Vc10A5QC2Fnbd6nVkWyD MP/Q== 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=YWGng/AgwvqijHTZHExWPRs5g9nBRTrMUPBsYX6VZJ8=; b=sFGRPwFB0DCRXZo3naabETCtM0IxPJ6cxHPsfSbtbIj+k+If3FzDkEggNHrFgD7Wjo 9VVq9Wh7Xg5LRhB2Ht8ylpJdDYrObaJOjOaHI1arbX5xxhzS5Dn/kYD7Pt3AeY26L9vG 71xlbOtrilkIXQyAgTy+dH/HeIw5bYhIr6k2heE6uRUry2pgV1ZNnrMAPWpmq1oySg0D Z+q1tw6qOWDOCHV0CUO+ZTduIAl4IU1rnSgRTCwdVDBWY0dQU1LicBnkR3+6Ou07d0s6 Jp4Wf920fr28wy8mWkZKn6R2gKwRxDlXmDKqNpyChkKgr6vrTZgwY4YGNhBk2yMuiomH r+9g== X-Gm-Message-State: AOAM530RRjA1jPHDp7gjri6HjiHr613z38cN6tGJhL5KsjEf7HylHh9s e71npVw/PTPn2oGwq3qOmBee4H0g4axmxw== X-Google-Smtp-Source: ABdhPJydqg5lXp6CiFhMM3sjNybhf95l37/9x4hr6nXA7GvGLjK40Iu8pXSgydzDdCw61YtKWv36RA== X-Received: by 2002:a1c:f70d:: with SMTP id v13mr21390652wmh.183.1623158199813; Tue, 08 Jun 2021 06:16:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v4 5/7] block: feature detection for host block support Date: Tue, 8 Jun 2021 15:16:32 +0200 Message-Id: <20210608131634.423904-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608131634.423904-1-pbonzini@redhat.com> References: <20210608131634.423904-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32c.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.248, 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, vsementsov@virtuozzo.com, Joelle van Dyne , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=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 626cf932c1..53150866ac 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'), @@ -1089,6 +1089,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 # ################# @@ -1183,6 +1186,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 Sat May 18 07:48:38 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623158446; cv=none; d=zohomail.com; s=zohoarc; b=PDq4XUuisYdwJzAqb/PvyUm12F8jaMPOFwEVEZTSxoSveAsAfLj/266LOmDpgDWq/Y3i3DHHotCOl7EMAbExpkytNimWv08zWNMWTw0Gdy+T2YVazts2CjpXYNmUD2e8u6NFkDW3uAutYy7vcL35++XcchRkytnZ3jzA79a4krw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623158446; 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=z5JxGJSakRyFgaDMwSNCyo2E3Qm6rZqr75V7oP8N/jQ=; b=FR3drF/T0m8WoTSWu1ssJ3i5scprcUZBgZ11fflaJEOW7Hh510YfTt8kyidpJ66aUfksonVEHIdyV752niaRJCKG71dYFkRcRE28oT1Y4IfN+3hlSpslsKH+X+zscfAuoOVzHI+gjnwlEZcTHPAHP5yS2cGQJm6sW4CpjnkQDc4= 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+importer=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 1623158446314654.4292918265434; Tue, 8 Jun 2021 06:20:46 -0700 (PDT) Received: from localhost ([::1]:60102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbeu-0007fk-OH for importer@patchew.org; Tue, 08 Jun 2021 09:20:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqbb2-0008CR-Aa; Tue, 08 Jun 2021 09:16:44 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:44931) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqbb0-0001z7-C4; Tue, 08 Jun 2021 09:16:44 -0400 Received: by mail-wm1-x32d.google.com with SMTP id p13-20020a05600c358db029019f44afc845so1836427wmq.3; Tue, 08 Jun 2021 06:16:41 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id i9sm15855686wrn.54.2021.06.08.06.16.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 06:16:40 -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=z5JxGJSakRyFgaDMwSNCyo2E3Qm6rZqr75V7oP8N/jQ=; b=UL4W7WZlcT7T+cIOXMx3NvRNDqop0YtbSHjI80jt09VdrgyRg0fzECXQvt3IY+b/Mr Odqncv3051hmWSTc6dN+ZOzPXnJ0Shh/ttXt4OpN9fOp9nry1DUzJ4BUfgG6iLtJUfCg R9VkZQGv1xVTFOJJijEj/n5enSDK8aEDm6FK+7F5AGh7C+QDmnAJlKzqqqfwm6RaxXqM ffIkdaNwG11lRqhVBS7tCkWpd9+1oz+0c0DdwDV9wMVIZNhod03Bf4D1hBN2vxq5we1Q H6h4baMFzBv7i49adeZ06X6fca3Ak3FqqN4xuRO8lnHvJH7Q8A6NbhJoj31kHWFQzWKw vULA== 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=z5JxGJSakRyFgaDMwSNCyo2E3Qm6rZqr75V7oP8N/jQ=; b=IGflSqQgXVESq+ue54COKfhKpD6Dz6JQCG6U3+fLKRGiks4KiPCMOq0JCdl48QPnKm /H8MvGWch5otogbULR3iGJHPieiuLO5OCeQ+ZgvKunpX1kipicia23n8AYI5NPlUbTRr WnnVC00eM9+VpfgasXwFE7U+QpC+b2Nj8CxPGhkEcfyf15ZxIJPlcwyieg1MBin2q6M7 9kuO8bNcK4f5fu41ms+EUViEVs1seRN/YerXBNZwQfRIMIU2xiPZ1pyC7FtnO0eK4zUf bj6PoFhckh0ABKqx59CP6U+QAVa4xgIjPBZQ15wPfU0j280yfTQVa0avi4/ZL2T6bV6o CmXA== X-Gm-Message-State: AOAM533rUDdpiDRXuPoTBYbqsKaNss2FO59x6+OorUDmyarcMIXflLRE H8b2WVlzcfILIfW6I3HfNiskC2FpCy3OVg== X-Google-Smtp-Source: ABdhPJymI5jJE1X7rmJXBWVM3zAsHagJRqMGSWPCaAa3J6Peg7GERkCGjy99CtvlOKOntFlrXX4WqQ== X-Received: by 2002:a7b:c394:: with SMTP id s20mr17482703wmj.33.1623158200616; Tue, 08 Jun 2021 06:16:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v4 6/7] block: check for sys/disk.h Date: Tue, 8 Jun 2021 15:16:33 +0200 Message-Id: <20210608131634.423904-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608131634.423904-1-pbonzini@redhat.com> References: <20210608131634.423904-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32d.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.248, 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 , vsementsov@virtuozzo.com, qemu-block@nongnu.org, Joelle van Dyne , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=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 --- 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 53150866ac..7e3902b5c8 100644 --- a/meson.build +++ b/meson.build @@ -1187,6 +1187,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 Sat May 18 07:48:38 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623158713; cv=none; d=zohomail.com; s=zohoarc; b=JfZGg09llmYyUecW//csoakf2FR7mOsO1YcKab0S+fowiSeLcTUwrem4yWkAjyowI/ota3iO1/Zdg6cAvoslTLi65ri/dKrogOXMS8ig9bRpRW1kgp0n9DNFK4MoJ4zDTkvFN84s2zHWaDlhqr9ylOFswD4/eh/9V1/UK30Mdwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623158713; 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=jfRvNaMHBwF4U4h//ac+Ucv8Gy+INRf/GGfB3ST6KJbYbzbVw5m7qQ1/PwEiXYPqsn7pUsMAt4GynjI2NgiEGfTr89efAJFjjdTG3ABuHuXB54lre3FtJMq2cHl4ryadKuJtakh7/ljNb1zCps1IORhN2Z15u2/CAlmHtN7Nyuo= 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+importer=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 1623158713197276.8910894065399; Tue, 8 Jun 2021 06:25:13 -0700 (PDT) Received: from localhost ([::1]:40316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbiN-0004rp-RC for importer@patchew.org; Tue, 08 Jun 2021 09:24:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqbb2-0008Dp-N4; Tue, 08 Jun 2021 09:16:48 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:36386) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqbb1-0001zx-04; Tue, 08 Jun 2021 09:16:44 -0400 Received: by mail-wm1-x32d.google.com with SMTP id h11-20020a05600c350bb02901b59c28e8b4so1442170wmq.1; Tue, 08 Jun 2021 06:16:42 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id i9sm15855686wrn.54.2021.06.08.06.16.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 06:16:41 -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=B34ocfF6yZbf7UUiTswjm+rFTaQEeiK39tg8gADUCqYBW35ZybKnjALh90kg8VQaf1 7P8RTUng90WiayY4DljsW4Rf3W7pJOAQuzdPt6mdLxE7NBZegf+ER7GL+iG+yOtAnbdi d+sksBl7NedyM9bY21Z9NvuKqmGbQbNeQRR6F54wQ2jvDFi+RBg/yJ9gMD1YKph0Bgga wxnqXVUGsh6TMD+fYIK1aqsLt1Gf/YZZphrxveuuIAFOB4d1cruRzB69yScyP1X+RFiP 2WZyfjykyankPPfjmrrIC5UG5LoJHarWvPLYZAm4CmPfum0MAfdzmPp3jp+LikpbHVxo 04Yw== 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=YGHbnUx+Swy/LMEDivDU0W+5Rz5ELsxqYI2nZ4gm69bgLzi68mvXHuAG9+RFwyHLEq RQa6qystiELBQaT260PTdDWntbOcaSZYIyDdWb7qEJn6XMY/rMyL7RBTCPSinlUHvBzI 4mF6W+ZKjIulWU5kGoHyE1hwpkNpWqvvWHbka99cArbNkGyELbWFc691XJfbepNirEoS tUUjRzxbx3s+OiFusM0rRvaz8trCBiUbelhLt8/kekYDzyS5zT3kyTJXjqNIc0jNfSoB 8QTaDRe1yWvxil1VePeGNdFg5UBrFAOOMCR4MQng+V1nK+Icxjm4Fq8Fssmks4SD9qSe cEKw== X-Gm-Message-State: AOAM532C3Zg2vgYGVpeROZxgkyKn5Hgw+WtOaQNWhMPBrbuzVXrbZV0C LnvS/h4viVRN5bgxKMDm8CByCyk8coMo4g== X-Google-Smtp-Source: ABdhPJx/d9RM/dC6+AvC2Z0RLKaSXob4cmqfu0FUO/1rvctbRhsNl2weDqss7Csbi7SYQCAu4wDCXA== X-Received: by 2002:a05:600c:1c0b:: with SMTP id j11mr22314007wms.139.1623158201398; Tue, 08 Jun 2021 06:16:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v4 7/7] block: detect DKIOCGETBLOCKCOUNT/SIZE before use Date: Tue, 8 Jun 2021 15:16:34 +0200 Message-Id: <20210608131634.423904-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608131634.423904-1-pbonzini@redhat.com> References: <20210608131634.423904-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32d.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.248, 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 , vsementsov@virtuozzo.com, qemu-block@nongnu.org, Joelle van Dyne , Warner Losh Errors-To: qemu-devel-bounces+importer=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