From patchwork Tue May 18 08:38:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1480085 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=eu/37W0T; 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 4FkqKL11ypz9sRN for ; Tue, 18 May 2021 18:43:34 +1000 (AEST) Received: from localhost ([::1]:55388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1livK8-0001KT-44 for incoming@patchwork.ozlabs.org; Tue, 18 May 2021 04:43:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1livFq-0003Xg-8z; Tue, 18 May 2021 04:39:06 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:41951) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1livFo-00047E-J9; Tue, 18 May 2021 04:39:06 -0400 Received: by mail-wm1-x32f.google.com with SMTP id o6-20020a05600c4fc6b029015ec06d5269so1012469wmq.0; Tue, 18 May 2021 01:39:03 -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=bXssOFtwQI3r6hP5tP3UWXJ1+o0S9QmsQBbP86KdnTE=; b=eu/37W0Ty7k/UltkaPHmEK1FySh0HcBao0VQnbOJ0aKzxT+7qSb+Hn4HzjXmOz8if/ dXH1F9TGYDSH3EMMtHMMjDgbe8X9IipzCv8KApWbZ5fgyWvDSVQEaqK/S62mkMNKt0+7 ylDtYvDmTTzye0JEJk5drKEp33D3FfTJ+yhcx/h+GjfmuG7Z16u4WjCuIZvlCqdOvx2F kDEnJrZB112YRHIyTO4wv3688+jGqrtxfV2B38sBXwFvwvKZnT/Rm5VvZLW+FWHHyG70 tBNFyHfY+DQjmEmVVZUQ8X8DFehTJzmdmiTSc9IQ2hZA0igAllq26EwVAeAdKUtEV0eu znHg== 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=bXssOFtwQI3r6hP5tP3UWXJ1+o0S9QmsQBbP86KdnTE=; b=H8+D0DARrPMwoOjBAi2gzo4yG8+FCQi4v2SabcTBDNsw2CldPq1Wov6AdrUZXGWIpA KsqOHMsR/LFUH6RKN421IfFXlGyBjrwGVlMw9R6K2yBSV8bg4GghCH0paK/dq3QAvY5h x6b+/ndBGy3RreNONVi3PsvDBiPGNsh8JAoG6GrbRQWntqZ7UUqy25j27yqxYV2ZZqQ5 Q4BKkpyiJalSHInDOzBjoNGgbp/6t6t7fdyQc6ZK8Wtqx4XhK0HEGJ/d5u1/X2mL35YU rgM95fVqeVvy2Fvyi5RZZlJO0eWKMJqhzDxFbhdR05xjcD04puJZqIuwMepBoZCIBcUY Qafw== X-Gm-Message-State: AOAM531QT2Yp1fjUz+Ai5zKVSjNFsupiVAdtSHGgVyHwOJ/DfVBxu/ZE 2Pml+TITh4JvvX+kiQYwDeTLZwOO92o6Lg== X-Google-Smtp-Source: ABdhPJyMAM1gO9uxzZzS/D4a9voN4KteMSRWS+dzJEc2Sync72J34cU/h7YU1rbYPbxfYancfymkyQ== X-Received: by 2002:a1c:b4c6:: with SMTP id d189mr4068783wmf.39.1621327142787; Tue, 18 May 2021 01:39:02 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id y6sm70959wmy.23.2021.05.18.01.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 01:39:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 1/5] file-posix: try BLKSECTGET on block devices too, do not round to power of 2 Date: Tue, 18 May 2021 10:38:57 +0200 Message-Id: <20210518083901.97369-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518083901.97369-1-pbonzini@redhat.com> References: <20210518083901.97369-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 --- block/file-posix.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 59c889d5a7..e5ef006aee 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 sg_get_max_transfer_length(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 sg_get_max_segments(int fd, struct stat *st) { #ifdef CONFIG_LINUX char buf[32]; @@ -1173,15 +1178,9 @@ 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; - } 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; @@ -1218,15 +1217,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 = sg_get_max_transfer_length(s->fd, &st); if (ret > 0 && ret <= BDRV_REQUEST_MAX_BYTES) { - bs->bl.max_transfer = pow2floor(ret); + bs->bl.max_transfer = ret; } - ret = sg_get_max_segments(s->fd); + ret = sg_get_max_segments(s->fd, &st); if (ret > 0) { bs->bl.max_iov = ret; } From patchwork Tue May 18 08:38:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1480086 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=kqnw26a5; 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 4FkqKN6V6Bz9sWW for ; Tue, 18 May 2021 18:43:36 +1000 (AEST) Received: from localhost ([::1]:55632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1livKA-0001VE-VF for incoming@patchwork.ozlabs.org; Tue, 18 May 2021 04:43:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49104) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1livFv-0003YA-2P; Tue, 18 May 2021 04:39:11 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:33465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1livFp-00047e-3r; Tue, 18 May 2021 04:39:07 -0400 Received: by mail-wr1-x432.google.com with SMTP id n2so9306887wrm.0; Tue, 18 May 2021 01:39:04 -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=K5qPvgjroW4HFZ0QOxtJbrxU7fNNc6UbjjlweCupMYc=; b=kqnw26a5iqDSb7hT+L7wOoBaXhKxzsGqK8GVNRWOjZLD4IZCXzCfMbc7T4RVZq+iWs wcAX7FM1i2jHao4iANkfuoVhfaVLoQpXoQVQFkeKZ16FatPRXcyISR2ujqmQk5JrvOEs be5kyw8MYtUn5hOn/7buJsV71Pq2Wu4IIPfdz3lYoRZNaFMPBcY3vjFHSwa5HmKGmHL7 G8kptMLwYJUCnJCldI0H+2UfiUlHn1SlNDI+WMgihSjdIIJuF8/IV2OL5zByY74y4vTd sYmQWba1MRPzIaKcQgRI3Jpfi0+QwsxPLS485u1k/YLMBFgtw9uaoAoW1zOjEGA83r3J eXqw== 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=K5qPvgjroW4HFZ0QOxtJbrxU7fNNc6UbjjlweCupMYc=; b=dVYHS1yiRNRC5fhix6E0tZ5QTWiynPKuEhVkT4bmAH7PANlSpimOq9Ps/sB1eF1Jya Hy4gt1QZ2/AUwk+mCR11CpwinNlhMU/5SV7fBKQajgPr/1Hjoi4VamyqGVMyKbM+1Ghf d3g4FNK195HzLCt/jCi2Msw86JN3G6fNNYvF5JKzCAsIUNxelvFteR0q0ZLl63D+mjer BPDfFKG73xfjGGQeSGrpIVGQBxphY5Sylw/6cEKx6acAE+GYJ36pj6swGuWdzGRK+EUx DIdakgHXZ4yaW3Qu0Dn5POZJ8o2NclGNy9hNCsU7okT3bsF2VntL57LzVEzlcECtiAys Qp1Q== X-Gm-Message-State: AOAM532V2ZK/9oE3ujz3l+mkHioSJ2A1/VeVop9uAYU+xs1KLqiXC3W3 w3epEVwO9tp8Z5Uj3s5g2+gbK4VhfeoHXg== X-Google-Smtp-Source: ABdhPJyTBDuXFmijGtKl6oX052ClG1jXC81Z+o/sT2+flVgZedN6Bxkj5vfFILB6xdPAwFPf+Qe0IQ== X-Received: by 2002:a5d:4805:: with SMTP id l5mr5350095wrq.142.1621327143462; Tue, 18 May 2021 01:39:03 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id y6sm70959wmy.23.2021.05.18.01.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 01:39:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 2/5] file-posix: fix max_iov for /dev/sg devices Date: Tue, 18 May 2021 10:38:58 +0200 Message-Id: <20210518083901.97369-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518083901.97369-1-pbonzini@redhat.com> References: <20210518083901.97369-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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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. 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 e5ef006aee..77a45083a6 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1179,6 +1179,17 @@ static int sg_get_max_segments(int fd, struct stat *st) int sysfd = -1; long max_segments; + if (S_ISCHR(st->st_mode)) { + if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) == 0) { + return ret; + } + return -EIO; + } + + 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 May 18 08:38:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1480083 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=cEAwVdPV; 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 4FkqGC0JqXz9sW5 for ; Tue, 18 May 2021 18:40:51 +1000 (AEST) Received: from localhost ([::1]:46768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1livHU-0003av-W7 for incoming@patchwork.ozlabs.org; Tue, 18 May 2021 04:40:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1livFv-0003YC-2D; Tue, 18 May 2021 04:39:11 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:34451) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1livFp-00048a-LL; Tue, 18 May 2021 04:39:07 -0400 Received: by mail-wr1-x433.google.com with SMTP id r12so9250831wrp.1; Tue, 18 May 2021 01:39:04 -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=3IOoGiTeTATnDAZQ2tgPicty7sASRWe0f4T7r6PyMl0=; b=cEAwVdPVxi8bY2UwmP/oVScHchYcA/rI1Gvhcqkj4e1PdAMcls4JtYCoDcO+zygKc/ SywQMnN1UbI0/4At292lCbOdisjtlaYAyw4qiKqhMnHj8RX8qM6DKv2YSGjnd3XX8di5 esoDoZ8UA+8IoaPDzZhGYcLpSOkL512N00eQi2ANY+zy7LvMsBr6eYMO7f+MWBh9ehwf GM3Rtoluqdq7W9daPWnCHpVO7rtFA8Ks289RtIiqjn4Fw/pEWK1unPX9ZdT2HtK7qlaX wAma+6c3k/CpEfIFMq2ckXqBKz7dnEwSWvPXuLj9bTA/pNmOBpfSVetogkoosDt/kpbJ c/Yw== 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=3IOoGiTeTATnDAZQ2tgPicty7sASRWe0f4T7r6PyMl0=; b=CeFK0SMOG7tpDjI5imn5KJvrd9HNxcmy9uMNuUfxoyEdsaGr42EILXoGobCmXU5TnO BcgjnASLrCsoQoyJY7T26sFLdMF3TlA62IdccVnlEAuxCooum4ZRCQ/0IMvr/DnElvyE p1NmC3IibJ8SwX8fzZ7zpjOmCarlmUwU9wWQdWSM190qlxlWagkWXKmyss0kSi5/aNJr RcmTNrfgekEZiyJS1vEFu0JUx2GvM/vZ2HQikj0E6oF1/jKYXTK3lf3ZnPValDB15eSY CSHHj+sKg/GWRvpUM5SPPDNCCBZKZbxsNoB6GtFfZrY0l6UJiar/ySEi0uQKyajlDeys IB/w== X-Gm-Message-State: AOAM5326xXme9I1BGklk5uQu+XvIiWOtOcB6HTR8nqmxl6ZuR0FaRkpF gYwcciDRSVLwOasdmyHSULXOCAJrhtDAtQ== X-Google-Smtp-Source: ABdhPJxTElG2TYrsVgz5ESw2ihQqeqxxTRfjm9vUKKl2HEoGHW/645yR8iKvj1Rnlt794KjPZ23MAQ== X-Received: by 2002:adf:f7c9:: with SMTP id a9mr5371955wrq.395.1621327144076; Tue, 18 May 2021 01:39:04 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id y6sm70959wmy.23.2021.05.18.01.39.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 01:39:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 3/5] block: feature detection for host block support Date: Tue, 18 May 2021 10:38:59 +0200 Message-Id: <20210518083901.97369-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518083901.97369-1-pbonzini@redhat.com> References: <20210518083901.97369-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x433.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 77a45083a6..e83f34a960 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 { @@ -3017,6 +3030,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); @@ -3026,6 +3040,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", @@ -3241,6 +3256,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); @@ -3533,16 +3550,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) { @@ -3866,6 +3873,8 @@ static BlockDriver bdrv_host_cdrom = { }; #endif /* __FreeBSD__ */ +#endif /* HAVE_HOST_BLOCK_DEVICE */ + static void bdrv_file_init(void) { /* @@ -3873,6 +3882,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); @@ -3880,6 +3890,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 5cf0dce695..b3cc45c41d 100644 --- a/meson.build +++ b/meson.build @@ -182,7 +182,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'), @@ -1067,6 +1067,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 # ################# @@ -1160,6 +1163,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 May 18 08:39:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1480088 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=I4pJcjvu; 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 4FkqML4MC4z9sRN for ; Tue, 18 May 2021 18:45:18 +1000 (AEST) Received: from localhost ([::1]:34014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1livLo-0005uZ-KL for incoming@patchwork.ozlabs.org; Tue, 18 May 2021 04:45:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1livFv-0003YB-2h; Tue, 18 May 2021 04:39:11 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:37870) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1livFq-00048j-DJ; Tue, 18 May 2021 04:39:07 -0400 Received: by mail-wm1-x329.google.com with SMTP id f19-20020a05600c1553b02901794fafcfefso375799wmg.2; Tue, 18 May 2021 01:39:05 -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=gy7bya1GfaCYAsMvtBUOrz63lYwfM7lAidIzQ0mKnCw=; b=I4pJcjvuT/OV7hdK2oFOQMztXSirzdWENCJXFeBxCr02lVULwO1RBcxJeiKlAN92vD yaj++b5LaW3h9j7Oul781IATP+f0nCiPP9N2nroSi9DC6DPgJMa4rBGXzjRC2A0/S2s8 1YYGD1zGI1alVMAT5XnYH2i8aNM9n5sA/sXkmBXln7U1XZm9J010q0ESnWgSabgr4JYW nKmYMkiof/GKbkEA5PyopcwDSZ+OKsFiIBecbxZUrrkJD6sDkK9UBoWKo6Tgp73XPpf1 UX0bgevpyS82aGiXP2mZGqpMbmc20XN4nMe/6fiY8OQC7lW96fbdl0wvZoXEu1nN6Qie u9eQ== 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=gy7bya1GfaCYAsMvtBUOrz63lYwfM7lAidIzQ0mKnCw=; b=pWAZVN5ROOWurlC0SQ5wKqeZZPBXsRhNsdifDI1QRfCfEQOln+rzU65XAnDw9Zk//W maXJwU34x5Fwo3aP/Od9zLBA8IyreFHxxbVibP56SeMTBO0+FPCsGRi6Q9gTl4xa7RFu EhB3r8xXFrzAiyDamdH7HLdxY6UaZLJ/tdXBvH0F5llFc8owCUTJG/hZLccVFHUexf7c YHjSP8fCezr/vt43MazLz4y5th1+yS4KE/xom0mPNb20ox3KErKmx+z9wIxps764XvIF sn28PTTGaGyzHnz3Jc41rpJ19NnjGlrvc5zuNBFuV3gcCDE/Uirf0xG3rqiEHLchQjnD sS/g== X-Gm-Message-State: AOAM530AnBJ46hxXVuvwNXyGB9uaAREIisfvsLw0Y3Ck58ityL/rtGsS T+Gl+wtwlF/82zlD59jN3p4Quths4q4Caw== X-Google-Smtp-Source: ABdhPJw5/dmzzwjhEx5xuddZFpoApB7o+dkfDrlPrmVApOLSjdLEWKCv7P5SIsr8c+/4FZBIRTJdrA== X-Received: by 2002:a7b:c93a:: with SMTP id h26mr3616304wml.141.1621327144729; Tue, 18 May 2021 01:39:04 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id y6sm70959wmy.23.2021.05.18.01.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 01:39:04 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 4/5] block: check for sys/disk.h Date: Tue, 18 May 2021 10:39:00 +0200 Message-Id: <20210518083901.97369-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518083901.97369-1-pbonzini@redhat.com> References: <20210518083901.97369-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , 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 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 9ad725d205..86a8c638c6 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 b3cc45c41d..5f0d4a1bc3 100644 --- a/meson.build +++ b/meson.build @@ -1164,6 +1164,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 May 18 08:39:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1480084 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=emMpfbmK; 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 4FkqGb3vSSz9sRN for ; Tue, 18 May 2021 18:41:11 +1000 (AEST) Received: from localhost ([::1]:47420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1livHn-00046j-V4 for incoming@patchwork.ozlabs.org; Tue, 18 May 2021 04:41:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1livFw-0003ax-Bs; Tue, 18 May 2021 04:39:12 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:41563) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1livFu-00049Q-RW; Tue, 18 May 2021 04:39:12 -0400 Received: by mail-wr1-x433.google.com with SMTP id d11so9216259wrw.8; Tue, 18 May 2021 01:39:06 -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=J4uFbK1t87t3yE0My/WwkVODQQO6taRX0FVG5vrflTQ=; b=emMpfbmK+hiPZt1z/b571kZP6uiN6NrQFpGfjPfiljSvfko51AV1TD+UbnCBbrkbm3 YBp399AaUrOXkC6SRWPm7tH4R0IAGJecZ7BIOMxRwZhXgC+EVnlwqoBmtsAGcVxCir8Z bOgWoqt6jQHR0h7iAJRa7aQSTRzwxZX0DPx99iMEhB18et+HDqlWkwjGUYdqgO1UHfSE i0rO2kSle7sSYU6sYcwF5FoaYqEHYOKLCtp79uq78DC9a7VsZpWPAyZOpZJvFikNXJ45 Al9Y85FCTfuGD5CCtFZzI8g7KI34kFTU3fborFwQRw8zGDYqaa3G1cjnRtk0IkKC8h1t JXiw== 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=J4uFbK1t87t3yE0My/WwkVODQQO6taRX0FVG5vrflTQ=; b=PVdi0N72C7OJGo1sp/LweolwWXxs7IFGQdX16rYqYxic7wp5hA70aEd7MbdTljKg82 /f5rh6rSGrSUocJ8v2E1ikuj0WGwgZFvHyte1FwAHlTT63tFYAwhYWSNCFu8/htyKEXJ 84VHbqWhwSCFciKXL+gB7an7n6FwCPCpGbsOQReyU7ZQvsuurF+Ukp/2g4cE4zKBeAmh FbPwP+hFpOunwS2UdB1mnKNhH9O8AkjPvWJaWJu3IBRfXgvVbYv5QVIfYU85/kSzCsUQ cNPJuwZqwf9zSA0DHN6avm+onj+aR6yFQ7g6f0aYKDak4/1XBrwqgySsoDCEj2JSGVF3 4Hqg== X-Gm-Message-State: AOAM531eVJZYueC98FdowNf4QYuYmBO2IKDAPWdvKY4kQ48/CtFYTxNV CL4tdRFSkiFYCOsw08J7Rn3AcDxA0JiQlw== X-Google-Smtp-Source: ABdhPJwDeUZf/RaJ3zcH0f+f+VAJscf9UqyhZ03BmbSaB0NA6PMgL6eGYF5cLzzoevuV9YK/KVnL/g== X-Received: by 2002:a05:6000:1863:: with SMTP id d3mr5343072wri.126.1621327145427; Tue, 18 May 2021 01:39:05 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id y6sm70959wmy.23.2021.05.18.01.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 01:39:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 5/5] block: detect DKIOCGETBLOCKCOUNT/SIZE before use Date: Tue, 18 May 2021 10:39:01 +0200 Message-Id: <20210518083901.97369-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518083901.97369-1-pbonzini@redhat.com> References: <20210518083901.97369-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x433.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Warner Losh , Joelle van Dyne , qemu-block@nongnu.org, Peter Maydell 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 e83f34a960..34bd413553 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2311,8 +2311,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; @@ -2321,9 +2324,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; @@ -2331,19 +2332,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: