block: feature detection for host block support
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 <j@getutm.app> Message-Id: <20210315180341.31638-2-j@getutm.app> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
18473467d5
commit
14176c8d05
|
@ -42,6 +42,8 @@
|
||||||
#include "scsi/constants.h"
|
#include "scsi/constants.h"
|
||||||
|
|
||||||
#if defined(__APPLE__) && (__MACH__)
|
#if defined(__APPLE__) && (__MACH__)
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#if defined(HAVE_HOST_BLOCK_DEVICE)
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <IOKit/IOKitLib.h>
|
#include <IOKit/IOKitLib.h>
|
||||||
|
@ -52,6 +54,7 @@
|
||||||
//#include <IOKit/storage/IOCDTypes.h>
|
//#include <IOKit/storage/IOCDTypes.h>
|
||||||
#include <IOKit/storage/IODVDMedia.h>
|
#include <IOKit/storage/IODVDMedia.h>
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
#endif /* defined(HAVE_HOST_BLOCK_DEVICE) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __sun__
|
#ifdef __sun__
|
||||||
|
@ -178,7 +181,17 @@ typedef struct BDRVRawReopenState {
|
||||||
bool check_cache_dropped;
|
bool check_cache_dropped;
|
||||||
} BDRVRawReopenState;
|
} 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);
|
static int64_t raw_getlength(BlockDriverState *bs);
|
||||||
|
|
||||||
typedef struct RawPosixAIOData {
|
typedef struct RawPosixAIOData {
|
||||||
|
@ -3033,6 +3046,7 @@ static BlockStatsSpecific *raw_get_specific_stats(BlockDriverState *bs)
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_HOST_BLOCK_DEVICE)
|
||||||
static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)
|
static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1);
|
BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1);
|
||||||
|
@ -3042,6 +3056,7 @@ static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs)
|
||||||
|
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
#endif /* HAVE_HOST_BLOCK_DEVICE */
|
||||||
|
|
||||||
static QemuOptsList raw_create_opts = {
|
static QemuOptsList raw_create_opts = {
|
||||||
.name = "raw-create-opts",
|
.name = "raw-create-opts",
|
||||||
|
@ -3257,6 +3272,8 @@ BlockDriver bdrv_file = {
|
||||||
/***********************************************/
|
/***********************************************/
|
||||||
/* host device */
|
/* host device */
|
||||||
|
|
||||||
|
#if defined(HAVE_HOST_BLOCK_DEVICE)
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath,
|
static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath,
|
||||||
CFIndex maxPathSize, int flags);
|
CFIndex maxPathSize, int flags);
|
||||||
|
@ -3549,16 +3566,6 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
|
||||||
}
|
}
|
||||||
#endif /* linux */
|
#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
|
static coroutine_fn int
|
||||||
hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
|
hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
|
||||||
{
|
{
|
||||||
|
@ -3882,6 +3889,8 @@ static BlockDriver bdrv_host_cdrom = {
|
||||||
};
|
};
|
||||||
#endif /* __FreeBSD__ */
|
#endif /* __FreeBSD__ */
|
||||||
|
|
||||||
|
#endif /* HAVE_HOST_BLOCK_DEVICE */
|
||||||
|
|
||||||
static void bdrv_file_init(void)
|
static void bdrv_file_init(void)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -3889,6 +3898,7 @@ static void bdrv_file_init(void)
|
||||||
* registered last will get probed first.
|
* registered last will get probed first.
|
||||||
*/
|
*/
|
||||||
bdrv_register(&bdrv_file);
|
bdrv_register(&bdrv_file);
|
||||||
|
#if defined(HAVE_HOST_BLOCK_DEVICE)
|
||||||
bdrv_register(&bdrv_host_device);
|
bdrv_register(&bdrv_host_device);
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
bdrv_register(&bdrv_host_cdrom);
|
bdrv_register(&bdrv_host_cdrom);
|
||||||
|
@ -3896,6 +3906,7 @@ static void bdrv_file_init(void)
|
||||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
bdrv_register(&bdrv_host_cdrom);
|
bdrv_register(&bdrv_host_cdrom);
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* HAVE_HOST_BLOCK_DEVICE */
|
||||||
}
|
}
|
||||||
|
|
||||||
block_init(bdrv_file_init);
|
block_init(bdrv_file_init);
|
||||||
|
|
|
@ -183,7 +183,7 @@ if targetos == 'windows'
|
||||||
include_directories: include_directories('.'))
|
include_directories: include_directories('.'))
|
||||||
elif targetos == 'darwin'
|
elif targetos == 'darwin'
|
||||||
coref = dependency('appleframeworks', modules: 'CoreFoundation')
|
coref = dependency('appleframeworks', modules: 'CoreFoundation')
|
||||||
iokit = dependency('appleframeworks', modules: 'IOKit')
|
iokit = dependency('appleframeworks', modules: 'IOKit', required: false)
|
||||||
elif targetos == 'sunos'
|
elif targetos == 'sunos'
|
||||||
socket = [cc.find_library('socket'),
|
socket = [cc.find_library('socket'),
|
||||||
cc.find_library('nsl'),
|
cc.find_library('nsl'),
|
||||||
|
@ -1148,6 +1148,9 @@ if get_option('cfi')
|
||||||
add_global_link_arguments(cfi_flags, native: false, language: ['c', 'cpp', 'objc'])
|
add_global_link_arguments(cfi_flags, native: false, language: ['c', 'cpp', 'objc'])
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
have_host_block_device = (targetos != 'darwin' or
|
||||||
|
cc.has_header('IOKit/storage/IOMedia.h'))
|
||||||
|
|
||||||
#################
|
#################
|
||||||
# config-host.h #
|
# config-host.h #
|
||||||
#################
|
#################
|
||||||
|
@ -1247,6 +1250,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_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_SYS_KCOV_H', cc.has_header('sys/kcov.h'))
|
||||||
config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include <stdlib.h>'))
|
config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include <stdlib.h>'))
|
||||||
|
config_host_data.set('HAVE_HOST_BLOCK_DEVICE', have_host_block_device)
|
||||||
|
|
||||||
config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#include <sys/uio.h>'))
|
config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#include <sys/uio.h>'))
|
||||||
|
|
||||||
|
|
|
@ -897,7 +897,8 @@
|
||||||
'discriminator': 'driver',
|
'discriminator': 'driver',
|
||||||
'data': {
|
'data': {
|
||||||
'file': 'BlockStatsSpecificFile',
|
'file': 'BlockStatsSpecificFile',
|
||||||
'host_device': 'BlockStatsSpecificFile',
|
'host_device': { 'type': 'BlockStatsSpecificFile',
|
||||||
|
'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
|
||||||
'nvme': 'BlockStatsSpecificNvme' } }
|
'nvme': 'BlockStatsSpecificNvme' } }
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -2814,7 +2815,10 @@
|
||||||
{ 'enum': 'BlockdevDriver',
|
{ 'enum': 'BlockdevDriver',
|
||||||
'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs',
|
'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs',
|
||||||
'cloop', 'compress', 'copy-on-read', 'dmg', 'file', 'ftp', 'ftps',
|
'cloop', 'compress', 'copy-on-read', 'dmg', 'file', 'ftp', 'ftps',
|
||||||
'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscsi',
|
'gluster',
|
||||||
|
{'name': 'host_cdrom', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
|
||||||
|
{'name': 'host_device', 'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
|
||||||
|
'http', 'https', 'iscsi',
|
||||||
'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels',
|
'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels',
|
||||||
'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd',
|
'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd',
|
||||||
{ 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
|
{ 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
|
||||||
|
@ -3995,8 +3999,10 @@
|
||||||
'ftp': 'BlockdevOptionsCurlFtp',
|
'ftp': 'BlockdevOptionsCurlFtp',
|
||||||
'ftps': 'BlockdevOptionsCurlFtps',
|
'ftps': 'BlockdevOptionsCurlFtps',
|
||||||
'gluster': 'BlockdevOptionsGluster',
|
'gluster': 'BlockdevOptionsGluster',
|
||||||
'host_cdrom': 'BlockdevOptionsFile',
|
'host_cdrom': { 'type': 'BlockdevOptionsFile',
|
||||||
'host_device':'BlockdevOptionsFile',
|
'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
|
||||||
|
'host_device': { 'type': 'BlockdevOptionsFile',
|
||||||
|
'if': 'defined(HAVE_HOST_BLOCK_DEVICE)' },
|
||||||
'http': 'BlockdevOptionsCurlHttp',
|
'http': 'BlockdevOptionsCurlHttp',
|
||||||
'https': 'BlockdevOptionsCurlHttps',
|
'https': 'BlockdevOptionsCurlHttps',
|
||||||
'iscsi': 'BlockdevOptionsIscsi',
|
'iscsi': 'BlockdevOptionsIscsi',
|
||||||
|
|
Loading…
Reference in New Issue