From patchwork Tue Mar 9 00:27:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joelle van Dyne X-Patchwork-Id: 12123623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97D34C433DB for ; Tue, 9 Mar 2021 00:29:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2AD9A6525B for ; Tue, 9 Mar 2021 00:29:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2AD9A6525B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=getutm.app Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJQFG-000233-5l for qemu-devel@archiver.kernel.org; Mon, 08 Mar 2021 19:29:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJQE2-0000Lp-2j; Mon, 08 Mar 2021 19:27:50 -0500 Received: from mail-pg1-f170.google.com ([209.85.215.170]:40820) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lJQE0-0006LB-Az; Mon, 08 Mar 2021 19:27:49 -0500 Received: by mail-pg1-f170.google.com with SMTP id n9so6603915pgi.7; Mon, 08 Mar 2021 16:27:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9WWcwh06/gRzc2Cz5zgitfkX4d70VqHv9apQwwyvZEk=; b=GvpByPuIs4ZoI1MnQV9ht1bVLeJaZIFK21Y6qSZiahvf3kGaOpdnV6mcYC83dREsD5 fkCOmp9R1LCVONPAk8AFfpluvugOtwz5bGPQamrtQ2L57HTKPrOPBJC7jdYHgurSI+3w rxSgL1KTVqKYPMPpcqbWjEvDcSnhhYmHVtTZnylFVncbnpeJz9XFtSnE1CwG2StI7DdU zhQ1Gje55Y4cbLTYcjlb/QbWNKmXShb6NXn5hQoTDFxxvz6bqffh7VaAihJ1Z7jrOXvu 5lflEcYHcbOa7gziKOK5kwXkp+OJUKpGMdvdcRQiPMAztkWOzzeoXrtQMXYoBTwcwzdk fQ/Q== X-Gm-Message-State: AOAM532q4wWovNUEe2rc1d8AGsBIhb5C0PjKsBhFq29OHDfyR5ShToL2 Q6haeY4N8HiGgILS949CgNoQ0TF/CbU= X-Google-Smtp-Source: ABdhPJzdjLBMl0NMxoiVy/DUfyAh6Hy/FgAMSE+7oOrb/H9yQzQEnODSEIHNea8jsENjUzLDE3KAuA== X-Received: by 2002:a63:fb18:: with SMTP id o24mr22149586pgh.55.1615249666326; Mon, 08 Mar 2021 16:27:46 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id d2sm466764pjx.42.2021.03.08.16.27.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Mar 2021 16:27:46 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v2 1/4] block: feature detection for host block support Date: Mon, 8 Mar 2021 16:27:38 -0800 Message-Id: <20210309002741.85057-2-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210309002741.85057-1-j@getutm.app> References: <20210309002741.85057-1-j@getutm.app> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.215.170; envelope-from=osy86github@gmail.com; helo=mail-pg1-f170.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Kevin Wolf , "open list:raw" , Markus Armbruster , Max Reitz , Joelle van Dyne Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- meson.build | 6 +++++- qapi/block-core.json | 10 +++++++--- block/file-posix.c | 33 ++++++++++++++++++++++----------- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/meson.build b/meson.build index 81d760d6e8..0e53876f69 100644 --- a/meson.build +++ b/meson.build @@ -181,7 +181,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'), @@ -1056,6 +1056,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 # ################# @@ -1149,6 +1152,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 9f555d5c1d..0c2cd9e689 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -959,7 +959,8 @@ 'discriminator': 'driver', 'data': { 'file': 'BlockStatsSpecificFile', - 'host_device': 'BlockStatsSpecificFile', + 'host_device': { 'type': 'BlockStatsSpecificFile', + 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' }, 'nvme': 'BlockStatsSpecificNvme' } } ## @@ -2863,7 +2864,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)' }, @@ -4066,7 +4069,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', diff --git a/block/file-posix.c b/block/file-posix.c index 05079b40ca..d1ab3180ff 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__ @@ -181,7 +184,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 { @@ -3032,6 +3045,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); @@ -3041,6 +3055,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", @@ -3265,6 +3280,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); @@ -3557,16 +3574,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) { @@ -3890,6 +3897,8 @@ static BlockDriver bdrv_host_cdrom = { }; #endif /* __FreeBSD__ */ +#endif /* HAVE_HOST_BLOCK_DEVICE */ + static void bdrv_file_init(void) { /* @@ -3897,6 +3906,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); @@ -3904,6 +3914,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); From patchwork Tue Mar 9 00:27:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Joelle van Dyne X-Patchwork-Id: 12123629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E67A6C433E0 for ; Tue, 9 Mar 2021 00:31:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 59F9C65275 for ; Tue, 9 Mar 2021 00:31:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 59F9C65275 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=getutm.app Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJQHc-0004T1-D3 for qemu-devel@archiver.kernel.org; Mon, 08 Mar 2021 19:31:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJQE3-0000N7-Bg; Mon, 08 Mar 2021 19:27:51 -0500 Received: from mail-pj1-f47.google.com ([209.85.216.47]:39557) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lJQE1-0006Lf-Uq; Mon, 08 Mar 2021 19:27:51 -0500 Received: by mail-pj1-f47.google.com with SMTP id lr10-20020a17090b4b8ab02900dd61b95c5eso1740018pjb.4; Mon, 08 Mar 2021 16:27:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QgU+W/R3FIydwYpBsWZV504V0tYBh/ETkHkfv0+pIB0=; b=kGVXfhQmIWpRSiH4FuK3m9tBlvit0qhK+Uwr0C7AgR4BPUIZJB7ZazOq3LviX+/RZC tYmYAaEDQOqe54BmLaQfmsOKNQDtiP7DyaQlAV1uUC1gSUaii9iwL3Q8EnwSZPB1C2Uh pVXYcC5zpPCj0GQ4hF2mB6HOg/Dn0M+AeGthuowGCz95oz+Njbyy3sqOskAiCuQbny4E NkEyAZ6x1aIVlSNRGORGash0PkxQXpG4VAT+Ipmjb0IRZBxhN3OxrpyZCz/hzuWZMvzy hKwkw9kUpLu6YnZELa1QdIzJo/3HbJIulsB1C2+BsQ+azO/XaXuUCTnW9jX9AbnyuGxg eG6g== X-Gm-Message-State: AOAM533qyZa8akkwDWhfCRKOdG23V2GvHcVGzmfBR7y12k3jj1bX/H7B Qg4lpQ4mdyrUAsyWuqXOOo9DcM43QzY= X-Google-Smtp-Source: ABdhPJxRns3ugxCglDlwtx6+/plmylnkbK9+G0q+hlVHxF8uwIL0RviqHkWmky7yqU5Cn3G4b4Z2TQ== X-Received: by 2002:a17:90a:f28e:: with SMTP id fs14mr1609100pjb.100.1615249668112; Mon, 08 Mar 2021 16:27:48 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id d2sm466764pjx.42.2021.03.08.16.27.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Mar 2021 16:27:47 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v2 2/4] block: check for sys/disk.h Date: Mon, 8 Mar 2021 16:27:39 -0800 Message-Id: <20210309002741.85057-3-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210309002741.85057-1-j@getutm.app> References: <20210309002741.85057-1-j@getutm.app> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.216.47; envelope-from=osy86github@gmail.com; helo=mail-pj1-f47.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Kevin Wolf , Joelle van Dyne , "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Some BSD platforms do not have this header. Signed-off-by: Joelle van Dyne Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- meson.build | 1 + block.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 0e53876f69..ba0db9fa1f 100644 --- a/meson.build +++ b/meson.build @@ -1153,6 +1153,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 ')) diff --git a/block.c b/block.c index a1f3cecd75..b2705ad225 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 From patchwork Tue Mar 9 00:27:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joelle van Dyne X-Patchwork-Id: 12123627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44188C433E6 for ; Tue, 9 Mar 2021 00:29:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B5B7565275 for ; Tue, 9 Mar 2021 00:29:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B5B7565275 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=getutm.app Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJQFM-0002KJ-Ps for qemu-devel@archiver.kernel.org; Mon, 08 Mar 2021 19:29:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJQE4-0000Qr-Ut; Mon, 08 Mar 2021 19:27:52 -0500 Received: from mail-pl1-f172.google.com ([209.85.214.172]:46884) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lJQE3-0006Mv-Hn; Mon, 08 Mar 2021 19:27:52 -0500 Received: by mail-pl1-f172.google.com with SMTP id u11so5665253plg.13; Mon, 08 Mar 2021 16:27:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RIP/r3nyG15GF413S6T6+JeyoT6XtJQWSwQR9etpPKM=; b=U9S4Ffi0ggyp/VFlMU+sviXtB9MiwSKoprQ7N2s6Q5mtUnfRgIua/1YU4MI4J2GpCv me2RUR6zVsuX3Gj08jK99Lkqw6XoFQ+Pv/3AK1X3NXokTETdYk/azLYvoTv1qggr3mYl 59cvRsyIVtL+FeITv0DPwTHVnC85JaxC8OZCZORi+Lu/1LT6+vLI/zqI04Bx2NNKIAEp CzxVThtRxUrTcWnypFATWa4azZFoZE1Pva6cSwHJfBJcAGEk8r+cfTj1BaMdsB7ZOTpL DzpdUq3j/qpLV58xc+jR4VfoS7dU93QcWfQoq4fKVGNs5STYBZWLSORvEAmL3iMODHSE ej5A== X-Gm-Message-State: AOAM5331kPrmgaDtJNeC08SJf8rhDd+T5dGP3dAUHDFHPLnaHoWXD73a sGfQehurb2vaxqBXN/AmYNpTyXpWImA= X-Google-Smtp-Source: ABdhPJy+evH0l2iPP2i20R8vNGvLwBVpuAjHw7BmCzqw+hydu+2PcyKVVorvHIsDJliRSHiDyGF/mA== X-Received: by 2002:a17:90a:b63:: with SMTP id 90mr1661927pjq.124.1615249669527; Mon, 08 Mar 2021 16:27:49 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id d2sm466764pjx.42.2021.03.08.16.27.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Mar 2021 16:27:49 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v2 3/4] block: detect DKIOCGETBLOCKCOUNT/SIZE before use Date: Mon, 8 Mar 2021 16:27:40 -0800 Message-Id: <20210309002741.85057-4-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210309002741.85057-1-j@getutm.app> References: <20210309002741.85057-1-j@getutm.app> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.172; envelope-from=osy86github@gmail.com; helo=mail-pl1-f172.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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: Kevin Wolf , "open list:raw" , Joelle van Dyne , Warner Losh , Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" iOS hosts do not have these defined so we fallback to the default behaviour. Co-authored-by: Warner Losh Signed-off-by: Joelle van Dyne Reviewed-by: Peter Maydell --- block/file-posix.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index d1ab3180ff..9b6d7ddda3 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2326,8 +2326,10 @@ 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)) + size = 0; #elif defined(DIOCGPART) { struct partinfo pi; @@ -2336,9 +2338,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; @@ -2346,19 +2346,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: From patchwork Tue Mar 9 00:27:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Joelle van Dyne X-Patchwork-Id: 12123625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A37ECC433E0 for ; Tue, 9 Mar 2021 00:29:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 29EFB65275 for ; Tue, 9 Mar 2021 00:29:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29EFB65275 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=getutm.app Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJQFM-0002J0-86 for qemu-devel@archiver.kernel.org; Mon, 08 Mar 2021 19:29:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJQE6-0000UQ-4A for qemu-devel@nongnu.org; Mon, 08 Mar 2021 19:27:54 -0500 Received: from mail-pl1-f177.google.com ([209.85.214.177]:41535) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lJQE4-0006N5-DX for qemu-devel@nongnu.org; Mon, 08 Mar 2021 19:27:53 -0500 Received: by mail-pl1-f177.google.com with SMTP id w7so2202812pll.8 for ; Mon, 08 Mar 2021 16:27:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uBSPYvlzXyM73rWWjH/hx6dBGEvtwRTUSDnjIjTgKQI=; b=sYBoOa75/Cz8HUMoev3nHywW446BblA23ZpHUps+UZO6wSh4p6AZ/JEdfRT6UPpL5M QJlgv2YPC0QmIZ2b+TYpPBVEvCell2+dGuqA6uzVoljKjmSTK1VXU20GDmdL+YD6ZCDR jhPow0aaEGpf9vQDJKcZ2CKSTqufeQ8xl0ua8AHkK6yQrYUY4UOONYQrb+WyzIn8YYKO 12M0ARPfxi6Bo1PsbzSUFcZL0kQ82mh20lYbNsGEWOovC1RSO5DtqGqd21PEc4AbCJCf 2F4wKBEAPeBkycIGhZJaXJmg8/ag5Mpcf0z7Ax0QyqcpNbQ3Rfdzca/vL5vS5KIUGjyk Pb8w== X-Gm-Message-State: AOAM532KpBqfXqUWzUtnwiaYMwufqR/9g+Y95/gIMe2ZcHu9k/taNNyd Xle4m70U1cohWZQISzu2QfD8RkEFtk8= X-Google-Smtp-Source: ABdhPJzrODbZXsOy1cFb73V8I3JsirEMi9zcAXqYNjO0cqLWV3XtB5KfvIhQR0Y/21RFwbBbr1U/xw== X-Received: by 2002:a17:90a:8a0f:: with SMTP id w15mr1587162pjn.200.1615249670752; Mon, 08 Mar 2021 16:27:50 -0800 (PST) Received: from localhost.localdomain ([73.93.154.215]) by smtp.gmail.com with ESMTPSA id d2sm466764pjx.42.2021.03.08.16.27.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Mar 2021 16:27:50 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v2 4/4] slirp: feature detection for smbd Date: Mon, 8 Mar 2021 16:27:41 -0800 Message-Id: <20210309002741.85057-5-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210309002741.85057-1-j@getutm.app> References: <20210309002741.85057-1-j@getutm.app> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.177; envelope-from=osy86github@gmail.com; helo=mail-pl1-f177.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Samuel Thibault , Jason Wang , Joelle van Dyne Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replace Windows specific macro with a more generic feature detection macro. Allows slirp smb feature to be disabled manually as well. Signed-off-by: Joelle van Dyne Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- configure | 26 +++++++++++++++++++++++--- meson.build | 2 +- net/slirp.c | 16 ++++++++-------- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/configure b/configure index 34fccaa2ba..8335a3e6a0 100755 --- a/configure +++ b/configure @@ -465,6 +465,7 @@ fuse_lseek="auto" multiprocess="auto" malloc_trim="auto" +slirp_smbd="auto" # parse CC options second for opt do @@ -834,8 +835,6 @@ do fi done -: ${smbd=${SMBD-/usr/sbin/smbd}} - # Default objcc to clang if available, otherwise use CC if has clang; then objcc=clang @@ -1560,6 +1559,10 @@ for opt do ;; --disable-multiprocess) multiprocess="disabled" ;; + --enable-slirp-smbd) slirp_smbd=yes + ;; + --disable-slirp-smbd) slirp_smbd=no + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1913,6 +1916,7 @@ disabled with --disable-FEATURE, default is enabled if available fuse FUSE block device export fuse-lseek SEEK_HOLE/SEEK_DATA support for FUSE exports multiprocess Out of process device emulation support + slirp-smbd use smbd (at path --smbd=*) in slirp networking NOTE: The object files are built at the place where configure is launched EOF @@ -5252,6 +5256,19 @@ case "$slirp" in ;; esac +# Check for slirp smbd dupport +: ${smbd=${SMBD-/usr/sbin/smbd}} +if test "$slirp_smbd" != "no" ; then + if test "$mingw32" = "yes" ; then + if test "$slirp_smbd" = "yes" ; then + error_exit "Host smbd not supported on this platform." + fi + slirp_smbd=no + else + slirp_smbd=yes + fi +fi + ########################################## # check for usable __NR_keyctl syscall @@ -5527,7 +5544,10 @@ fi if test "$guest_agent" = "yes" ; then echo "CONFIG_GUEST_AGENT=y" >> $config_host_mak fi -echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak +if test "$slirp_smbd" = "yes" ; then + echo "CONFIG_SLIRP_SMBD=y" >> $config_host_mak + echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak +fi if test "$vde" = "yes" ; then echo "CONFIG_VDE=y" >> $config_host_mak echo "VDE_LIBS=$vde_libs" >> $config_host_mak diff --git a/meson.build b/meson.build index ba0db9fa1f..cad70a8fc5 100644 --- a/meson.build +++ b/meson.build @@ -2424,7 +2424,7 @@ summary_info += {'genisoimage': config_host['GENISOIMAGE']} if targetos == 'windows' and config_host.has_key('CONFIG_GUEST_AGENT') summary_info += {'wixl': wixl.found() ? wixl.full_path() : false} endif -if slirp_opt != 'disabled' +if slirp_opt != 'disabled' and 'CONFIG_SLIRP_SMBD' in config_host summary_info += {'smbd': config_host['CONFIG_SMBD_COMMAND']} endif summary(summary_info, bool_yn: true, section: 'Host binaries') diff --git a/net/slirp.c b/net/slirp.c index be914c0be0..b3ded2aac1 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -27,7 +27,7 @@ #include "net/slirp.h" -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD) #include #include #endif @@ -90,7 +90,7 @@ typedef struct SlirpState { Slirp *slirp; Notifier poll_notifier; Notifier exit_notifier; -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD) gchar *smb_dir; #endif GSList *fwd; @@ -103,7 +103,7 @@ static QTAILQ_HEAD(, SlirpState) slirp_stacks = static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp); static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp); -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD) static int slirp_smb(SlirpState *s, const char *exported_dir, struct in_addr vserver_addr, Error **errp); static void slirp_smb_cleanup(SlirpState *s); @@ -367,7 +367,7 @@ static int net_slirp_init(NetClientState *peer, const char *model, struct in6_addr ip6_prefix; struct in6_addr ip6_host; struct in6_addr ip6_dns; -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD) struct in_addr smbsrv = { .s_addr = 0 }; #endif NetClientState *nc; @@ -477,7 +477,7 @@ static int net_slirp_init(NetClientState *peer, const char *model, return -1; } -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD) if (vsmbserver && !inet_aton(vsmbserver, &smbsrv)) { error_setg(errp, "Failed to parse SMB address"); return -1; @@ -592,7 +592,7 @@ static int net_slirp_init(NetClientState *peer, const char *model, } } } -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD) if (smb_export) { if (slirp_smb(s, smb_export, smbsrv, errp) < 0) { goto error; @@ -784,7 +784,7 @@ void hmp_hostfwd_add(Monitor *mon, const QDict *qdict) } -#ifndef _WIN32 +#if defined(CONFIG_SLIRP_SMBD) /* automatic user mode samba server configuration */ static void slirp_smb_cleanup(SlirpState *s) @@ -899,7 +899,7 @@ static int slirp_smb(SlirpState* s, const char *exported_dir, return 0; } -#endif /* !defined(_WIN32) */ +#endif /* defined(CONFIG_SLIRP_SMBD) */ static int guestfwd_can_read(void *opaque) {