From nobody Mon Feb 9 08:55:14 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1611346485; cv=none; d=zohomail.com; s=zohoarc; b=TePgsgYCXp1nJrHg/5Zjifd81ep6ycugYS0KCu+kZtxQf06jqP/BCu5keUnOP+UdTrt0tzD6zL8AscdQIcKo1xIwk+dPb2M/DZv/puPJ19eFVnOfqYCTBXzQtVq4TpNu8ZWcRIM5D8vER/c80ZQBqczkaBWcbsny0IEdi67lj2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611346485; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qVqRMnh8npYh0Rc9gcDpg3IYcVv+P2nL9eIHhLcj2Fs=; b=j0euKdJdAqlx3m19h77RzB4sL4Ob3jeXBdgRMPpzL0VncJ7s/5clf9YN9nS1uyH32ucK3U0RbZOlB7ghw3OLz/MmiT35mTVsT6rAa9XC3UBRpf5W96tYA+AqgNPNq5ypqf7oxyvR3ucmN9jI5VLebwBLv6OK+UFZ9ogLoW2I8J0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1611346485506107.62323558695061; Fri, 22 Jan 2021 12:14:45 -0800 (PST) Received: from localhost ([::1]:54150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l32pQ-0000x9-7s for importer@patchew.org; Fri, 22 Jan 2021 15:14:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l32m9-0004nm-6z; Fri, 22 Jan 2021 15:11:21 -0500 Received: from mail-pj1-f54.google.com ([209.85.216.54]:38677) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l32m7-0004ZI-AG; Fri, 22 Jan 2021 15:11:20 -0500 Received: by mail-pj1-f54.google.com with SMTP id x20so4597113pjh.3; Fri, 22 Jan 2021 12:11:18 -0800 (PST) Received: from localhost.localdomain ([73.93.152.129]) by smtp.gmail.com with ESMTPSA id u12sm8741839pgi.91.2021.01.22.12.11.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jan 2021 12:11:16 -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=qVqRMnh8npYh0Rc9gcDpg3IYcVv+P2nL9eIHhLcj2Fs=; b=QQRUtw+RPKtbsHH4FF3GQHtYtXRyDCDN/KKI64VjOJhQQvwWhjHmHV+0hUWK0V9+P2 uXRt1ZTfCYyOYAjY5vhl2of7RV3gj4QAOQkjE98/aCaJ9k58+gPLjuB+L3tWnLFpeNzO OMEQTU1L8qjBOX4a4IrqDq5mVxV4yGgPi1ACJWAxhvf7zs0LHann1xmLrRukge5aPufM mjNH9wgLn0SoQBFa7nALNdMcDA3C7HnVj58z+WYy5KJPH+8CaCNhhGGPIsZn3HP9Fl3W L56eqv1OSMWzYgSQ4fm3nXXN/8YwTfC2I1Ns4tcX5H4fOPfNmWr1iFJmesk+opoL/bEm t1OA== X-Gm-Message-State: AOAM533PcU3tFt/wWALbTlzQhYHBKOsByZUprpykMtdFzCUL23M/7anX 1+RVl7M/xUX4F9vIgtQglHqtiyKnUik= X-Google-Smtp-Source: ABdhPJzyz4jwOLz51/IlbaZvOQJ5oWXVpzcT7/gao6MZN9we0rYDoDYBNIXkUTL1twdv/zX92VCWTQ== X-Received: by 2002:a17:90a:c787:: with SMTP id gn7mr351239pjb.222.1611346277183; Fri, 22 Jan 2021 12:11:17 -0800 (PST) From: Joelle van Dyne To: qemu-devel@nongnu.org Subject: [PATCH v7 01/11] block: feature detection for host block support Date: Fri, 22 Jan 2021 12:11:03 -0800 Message-Id: <20210122201113.63788-2-j@getutm.app> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210122201113.63788-1-j@getutm.app> References: <20210122201113.63788-1-j@getutm.app> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=209.85.216.54; envelope-from=osy86github@gmail.com; helo=mail-pj1-f54.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.249, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 --- configure | 13 +++++++++++++ meson.build | 2 +- qapi/block-core.json | 10 +++++++--- block/file-posix.c | 33 ++++++++++++++++++++++----------- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 6f6a319c2f..acf7f7414a 100755 --- a/configure +++ b/configure @@ -5283,6 +5283,16 @@ but not implemented on your system" fi fi =20 +########################################## +# check for host block device +# assume always true for non-Darwin hosts + +if ! test "$darwin" =3D=3D "yes" || check_include "IOKit/storage/IOMedia.h= " ; then + have_host_block_device=3Dyes +else + have_host_block_device=3Dno +fi + ########################################## # End of CC checks # After here, no more $cc or $ld runs @@ -5513,6 +5523,9 @@ echo "GIT_UPDATE=3D$git_update" >> $config_host_mak =20 echo "ARCH=3D$ARCH" >> $config_host_mak =20 +if test "$have_host_block_device" =3D "yes" ; then + echo "HAVE_HOST_BLOCK_DEVICE=3Dy" >> $config_host_mak +fi if test "$debug_tcg" =3D "yes" ; then echo "CONFIG_DEBUG_TCG=3Dy" >> $config_host_mak fi diff --git a/meson.build b/meson.build index af2bc89741..6c3ee7f8ca 100644 --- a/meson.build +++ b/meson.build @@ -180,7 +180,7 @@ if targetos =3D=3D 'windows' include_directories: include_directo= ries('.')) elif targetos =3D=3D 'darwin' coref =3D dependency('appleframeworks', modules: 'CoreFoundation') - iokit =3D dependency('appleframeworks', modules: 'IOKit') + iokit =3D dependency('appleframeworks', modules: 'IOKit', required: 'HAV= E_HOST_BLOCK_DEVICE' in config_host) elif targetos =3D=3D 'sunos' socket =3D [cc.find_library('socket'), cc.find_library('nsl'), diff --git a/qapi/block-core.json b/qapi/block-core.json index 3484986d1c..1a9576de8d 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' } } =20 ## @@ -2827,7 +2828,9 @@ { 'enum': 'BlockdevDriver', 'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs', 'cloop', 'compress', 'copy-on-read', 'dmg', 'file', 'ftp', 'ft= ps', - 'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscs= i', + 'gluster', 'host_cdrom', + {'name': 'host_device', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)= ' }, + 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallel= s', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' }, @@ -4012,7 +4015,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 00cdaaa2d4..11d2021346 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -42,6 +42,8 @@ #include "scsi/constants.h" =20 #if defined(__APPLE__) && (__MACH__) +#include +#if defined(HAVE_HOST_BLOCK_DEVICE) #include #include #include @@ -52,6 +54,7 @@ //#include #include #include +#endif /* defined(HAVE_HOST_BLOCK_DEVICE) */ #endif =20 #ifdef __sun__ @@ -181,7 +184,17 @@ typedef struct BDRVRawReopenState { bool check_cache_dropped; } BDRVRawReopenState; =20 -static int fd_open(BlockDriverState *bs); +static int fd_open(BlockDriverState *bs) +{ + BDRVRawState *s =3D bs->opaque; + + /* this is just to ensure s->fd is sane (its called by io ops) */ + if (s->fd >=3D 0) { + return 0; + } + return -EIO; +} + static int64_t raw_getlength(BlockDriverState *bs); =20 typedef struct RawPosixAIOData { @@ -3014,6 +3027,7 @@ static BlockStatsSpecific *raw_get_specific_stats(Blo= ckDriverState *bs) return stats; } =20 +#if defined(HAVE_HOST_BLOCK_DEVICE) static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs) { BlockStatsSpecific *stats =3D g_new(BlockStatsSpecific, 1); @@ -3023,6 +3037,7 @@ static BlockStatsSpecific *hdev_get_specific_stats(Bl= ockDriverState *bs) =20 return stats; } +#endif /* HAVE_HOST_BLOCK_DEVICE */ =20 static QemuOptsList raw_create_opts =3D { .name =3D "raw-create-opts", @@ -3247,6 +3262,8 @@ BlockDriver bdrv_file =3D { /***********************************************/ /* host device */ =20 +#if defined(HAVE_HOST_BLOCK_DEVICE) + #if defined(__APPLE__) && defined(__MACH__) static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath, CFIndex maxPathSize, int flags); @@ -3539,16 +3556,6 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long in= t req, void *buf) } #endif /* linux */ =20 -static int fd_open(BlockDriverState *bs) -{ - BDRVRawState *s =3D bs->opaque; - - /* this is just to ensure s->fd is sane (its called by io ops) */ - if (s->fd >=3D 0) - return 0; - return -EIO; -} - static coroutine_fn int hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { @@ -3872,6 +3879,8 @@ static BlockDriver bdrv_host_cdrom =3D { }; #endif /* __FreeBSD__ */ =20 +#endif /* HAVE_HOST_BLOCK_DEVICE */ + static void bdrv_file_init(void) { /* @@ -3879,6 +3888,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); @@ -3886,6 +3896,7 @@ static void bdrv_file_init(void) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) bdrv_register(&bdrv_host_cdrom); #endif +#endif /* HAVE_HOST_BLOCK_DEVICE */ } =20 block_init(bdrv_file_init); --=20 2.28.0