From patchwork Tue Jun 8 13:16:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1489437 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Hf1JpuK1; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FzrQB3VpXz9sPf for ; Tue, 8 Jun 2021 23:17:54 +1000 (AEST) Received: from localhost ([::1]:48718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbc8-0008Tw-Dz for incoming@patchwork.ozlabs.org; Tue, 08 Jun 2021 09:17:52 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.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 --- 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; } + 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 Tue Jun 8 13:16:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1489441 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=o0W/0u5v; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FzrSy0cx5z9sPf for ; Tue, 8 Jun 2021 23:20:18 +1000 (AEST) Received: from localhost ([::1]:57336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbeR-0005nD-W4 for incoming@patchwork.ozlabs.org; Tue, 08 Jun 2021 09:20:16 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.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: 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) 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 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 = 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 Tue Jun 8 13:16:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1489442 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=gAcmYzrN; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FzrVj3clqz9sW6 for ; Tue, 8 Jun 2021 23:21:49 +1000 (AEST) Received: from localhost ([::1]:36438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbfv-0002I4-IM for incoming@patchwork.ozlabs.org; Tue, 08 Jun 2021 09:21:47 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.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: 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; } +/* 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(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 = 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..089b99bb0c 100644 --- a/block/io.c +++ b/block/io.c @@ -127,6 +127,7 @@ 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 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 = 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 Tue Jun 8 13:16:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1489438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=kJqFIWRj; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FzrQF1Ng9z9sPf for ; Tue, 8 Jun 2021 23:17:57 +1000 (AEST) Received: from localhost ([::1]:48938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbcB-0000E2-6r for incoming@patchwork.ozlabs.org; Tue, 08 Jun 2021 09:17:55 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.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: 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 = 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]; @@ -1173,26 +1178,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; @@ -1229,15 +1228,20 @@ out: static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s = bs->opaque; + struct stat st; + + if (fstat(s->fd, &st)) { + return; + } - if (bs->sg) { - int ret = sg_get_max_transfer_length(s->fd); + 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 = pow2floor(ret); + bs->bl.max_hw_transfer = ret; } - ret = sg_get_max_segments(s->fd); + ret = hdev_get_max_segments(s->fd, &st); if (ret > 0) { bs->bl.max_iov = ret; } From patchwork Tue Jun 8 13:16:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1489439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=U/6W5ka/; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FzrQR6zncz9sWF for ; Tue, 8 Jun 2021 23:18:07 +1000 (AEST) Received: from localhost ([::1]:49186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbcL-0000PA-OF for incoming@patchwork.ozlabs.org; Tue, 08 Jun 2021 09:18:05 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.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 --- 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" #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__ @@ -180,7 +183,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 { @@ -3028,6 +3041,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); @@ -3037,6 +3051,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", @@ -3252,6 +3267,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); @@ -3544,16 +3561,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) { @@ -3877,6 +3884,8 @@ static BlockDriver bdrv_host_cdrom = { }; #endif /* __FreeBSD__ */ +#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 */ } 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 == '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'), @@ -1089,6 +1089,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 # ################# @@ -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', 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..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' } } ## @@ -2814,7 +2815,9 @@ { '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', 'host_cdrom', + {'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)' }, @@ -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', From patchwork Tue Jun 8 13:16:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1489440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=UL4W7WZl; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FzrSr0QbWz9sWD for ; Tue, 8 Jun 2021 23:20:11 +1000 (AEST) Received: from localhost ([::1]:56666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbeL-0005Mi-Jd for incoming@patchwork.ozlabs.org; Tue, 08 Jun 2021 09:20:09 -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) 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) 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) 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 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_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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> 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_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 Tue Jun 8 13:16:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1489443 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=B34ocfF6; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FzrXh3sZZz9sWF for ; Tue, 8 Jun 2021 23:23:32 +1000 (AEST) Received: from localhost ([::1]:39096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqbha-00043L-Gm for incoming@patchwork.ozlabs.org; Tue, 08 Jun 2021 09:23:30 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.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 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 = 0; #ifdef DIOCGMEDIASIZE - if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) + if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) { + size = 0; + } #elif defined(DIOCGPART) { struct partinfo pi; @@ -2332,9 +2335,7 @@ again: else size = 0; } - if (size == 0) -#endif -#if defined(__APPLE__) && defined(__MACH__) +#elif defined(DKIOCGETBLOCKCOUNT) && defined(DKIOCGETBLOCKSIZE) { uint64_t sectors = 0; uint32_t sector_size = 0; @@ -2342,19 +2343,15 @@ again: 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: