From d68ad3bbe7122d8d4fdd8572fd830ab5328175bd Mon Sep 17 00:00:00 2001 From: Jorgen Lundman Date: Mon, 23 Oct 2023 09:07:40 +0900 Subject: [PATCH] 5: include/* lib/* and top build Bonus part5, the non-macos changes to include lib and the top level Makefiles Signed-off-by: Jorgen Lundman --- Makefile.am | 9 ++- configure.ac | 5 +- etc/Makefile.am | 6 ++ include/libzfs.h | 17 ++++++ include/libzutil.h | 4 ++ include/os/freebsd/spl/sys/simd_aarch64.h | 9 +++ include/os/linux/kernel/linux/simd_aarch64.h | 10 ++++ include/os/linux/zfs/sys/zfs_context_os.h | 4 ++ include/sys/abd.h | 9 ++- include/sys/abd_impl.h | 3 + include/sys/asm_linkage.h | 4 ++ include/sys/crypto/icp.h | 3 + include/sys/fs/zfs.h | 21 ++++++- include/sys/mntent.h | 7 +++ include/sys/spa.h | 2 + include/sys/spa_impl.h | 3 + include/sys/sysevent/dev.h | 2 +- include/sys/vdev_raidz.h | 1 + include/sys/xvattr.h | 12 +++- include/sys/zfs_bootenv.h | 1 + include/sys/zfs_debug.h | 21 ++++++- include/sys/zfs_file.h | 2 + include/sys/zfs_ioctl_impl.h | 3 + include/sys/zfs_sa.h | 10 ++++ include/sys/zfs_znode.h | 3 + include/sys/zio.h | 4 ++ include/sys/zio_crypt.h | 5 ++ include/zfs_fletcher.h | 1 + lib/Makefile.am | 14 +++-- lib/libefi/Makefile.am | 13 +++- lib/libicp/Makefile.am | 3 +- lib/libnvpair/Makefile.am | 23 ++++++++ lib/libshare/Makefile.am | 6 ++ lib/libspl/Makefile.am | 7 +++ lib/libspl/atomic.c | 8 +-- lib/libspl/include/Makefile.am | 41 +++++++++++++ lib/libspl/include/sys/asm_linkage.h | 5 +- lib/libspl/include/sys/dkio.h | 2 + lib/libspl/include/sys/isa_defs.h | 3 + lib/libspl/include/sys/simd.h | 32 ++++++++++ lib/libspl/include/sys/uio.h | 6 +- lib/libuutil/Makefile.am | 2 + lib/libzfs/Makefile.am | 17 ++++++ lib/libzfs/libzfs.abi | 7 ++- lib/libzfs/libzfs_crypto.c | 2 + lib/libzfs/libzfs_dataset.c | 62 ++++++++++++++++++++ lib/libzfs/libzfs_diff.c | 5 ++ lib/libzfs/libzfs_iter.c | 16 ++--- lib/libzfs/libzfs_sendrecv.c | 27 +++++++++ lib/libzfs_core/Makefile.am | 9 +++ lib/libzfs_core/libzfs_core.c | 3 + lib/libzfsbootenv/Makefile.am | 2 + lib/libzpool/Makefile.am | 2 + lib/libzutil/Makefile.am | 11 ++++ lib/libzutil/zutil_device_path.c | 40 ++++++++++++- lib/libzutil/zutil_import.c | 17 ++++++ lib/libzutil/zutil_pool.c | 1 + 57 files changed, 532 insertions(+), 35 deletions(-) diff --git a/Makefile.am b/Makefile.am index 11e45dae8255..5c6f339d8464 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,6 +18,12 @@ if BUILD_LINUX include $(srcdir)/%D%/rpm/Makefile.am endif +if BUILD_MACOS +bin_PROGRAMS= +noinst_PROGRAMS= +include $(srcdir)/%D%/module/os/macos/Makefile.am +endif + if CONFIG_USER include $(srcdir)/%D%/cmd/Makefile.am include $(srcdir)/%D%/contrib/Makefile.am @@ -194,11 +200,12 @@ cscopelist: PHONY += tags tags: ctags etags -PHONY += pkg pkg-dkms pkg-kmod pkg-utils +PHONY += pkg pkg-dkms pkg-kmod pkg-utils pkg-macos pkg: @DEFAULT_PACKAGE@ pkg-dkms: @DEFAULT_PACKAGE@-dkms pkg-kmod: @DEFAULT_PACKAGE@-kmod pkg-utils: @DEFAULT_PACKAGE@-utils +pkg-macos: @DEFAULT_PACKAGE@-macos include config/rpm.am include config/deb.am diff --git a/configure.ac b/configure.ac index 4c75616e4299..403c2762a675 100644 --- a/configure.ac +++ b/configure.ac @@ -44,7 +44,7 @@ AM_INIT_AUTOMAKE([subdir-objects foreign]) # Remove default macros from config.h: # PACKAGE, PACKAGE_{BUGREPORT,NAME,STRING,TARNAME,VERSION}, STDC_HEADERS, VERSION AC_CONFIG_HEADERS([zfs_config.h], [ - sed -nri~ -e '/^$/be' -e 'N;N;/#define (PACKAGE|VERSION|STDC_HEADERS)/d' -e ':e' -e 'p' zfs_config.h && rm zfs_config.h~ || exit]) + $SED -nri~ -e '/^$/be' -e 'N;N;/#define (PACKAGE|VERSION|STDC_HEADERS)/d' -e ':e' -e 'p' zfs_config.h && rm zfs_config.h~ || exit]) LT_INIT AC_PROG_INSTALL @@ -55,6 +55,9 @@ AM_PROG_AS AM_PROG_CC_C_O AX_CODE_COVERAGE _AM_PROG_TAR(pax) +AC_PROG_CXX(clang++) +AC_PROG_OBJC(clang) +AC_PROG_OBJCXX(clang++) ZFS_AC_LICENSE ZFS_AC_CONFIG diff --git a/etc/Makefile.am b/etc/Makefile.am index 7187762d3802..3121ebf2680b 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -97,3 +97,9 @@ dist_modulesload_DATA = \ %D%/modules-load.d/zfs.conf endif endif + +if BUILD_MACOS +include $(srcdir)/%D%/launchd/Makefile.am +include $(srcdir)/%D%/paths.d/Makefile.am +include $(srcdir)/%D%/launchd.d/Makefile.am +endif diff --git a/include/libzfs.h b/include/libzfs.h index 4adfa38e87be..ca74841029eb 100644 --- a/include/libzfs.h +++ b/include/libzfs.h @@ -1003,6 +1003,7 @@ _LIBZFS_H int zpool_enable_datasets(zpool_handle_t *, const char *, int); _LIBZFS_H int zpool_disable_datasets(zpool_handle_t *, boolean_t); _LIBZFS_H void zpool_disable_datasets_os(zpool_handle_t *, boolean_t); _LIBZFS_H void zpool_disable_volume_os(const char *); +_LIBZFS_H void zfs_rollback_os(struct zfs_handle *); /* * Parse a features file for -o compatibility @@ -1039,9 +1040,25 @@ _LIBZFS_H int zpool_nextboot(libzfs_handle_t *, uint64_t, uint64_t, * Add or delete the given filesystem to/from the given user namespace. */ _LIBZFS_H int zfs_userns(zfs_handle_t *zhp, const char *nspath, int attach); +#endif +#ifdef __APPLE__ +_LIBZFS_H int zfs_snapshot_mount(zfs_handle_t *, const char *, int); +_LIBZFS_H int zfs_snapshot_unmount(zfs_handle_t *, int); +/* We moved these from libspl to libzfs to be able to do more */ +_LIBZFS_H int getmntent(FILE *, struct mnttab *); +_LIBZFS_H char *hasmntopt(struct mnttab *, const char *); +_LIBZFS_H int getextmntent(const char *, struct extmnttab *, + struct stat64 *); +_LIBZFS_H int do_mount(zfs_handle_t *, const char *, const char *, int); #endif +/* + * Manual mounting of snapshots. + */ +extern int zfs_snapshot_mount(zfs_handle_t *, const char *, int); +extern int zfs_snapshot_unmount(zfs_handle_t *, int); + #ifdef __cplusplus } #endif diff --git a/include/libzutil.h b/include/libzutil.h index 237ff976ba62..4bd597daf668 100644 --- a/include/libzutil.h +++ b/include/libzutil.h @@ -109,7 +109,11 @@ _LIBZUTIL_H void update_vdev_config_dev_strs(nvlist_t *); * Default device paths */ #define DISK_ROOT "/dev" +#ifdef __APPLE__ +#define UDISK_ROOT "/private/var/run/disk" +#else #define UDISK_ROOT "/dev/disk" +#endif #define ZVOL_ROOT "/dev/zvol" _LIBZUTIL_H int zfs_append_partition(char *path, size_t max_len); diff --git a/include/os/freebsd/spl/sys/simd_aarch64.h b/include/os/freebsd/spl/sys/simd_aarch64.h index 234f401db791..2af01a939afb 100644 --- a/include/os/freebsd/spl/sys/simd_aarch64.h +++ b/include/os/freebsd/spl/sys/simd_aarch64.h @@ -91,4 +91,13 @@ zfs_sha512_available(void) return (elf_hwcap & HWCAP_SHA512); } +/* + * Check if AESV8 is available + */ +static inline boolean_t +zfs_aesv8_available(void) +{ + return (elf_hwcap & HWCAP_AES); +} + #endif /* _FREEBSD_SIMD_AARCH64_H */ diff --git a/include/os/linux/kernel/linux/simd_aarch64.h b/include/os/linux/kernel/linux/simd_aarch64.h index 16276b08c759..e48c9b3be932 100644 --- a/include/os/linux/kernel/linux/simd_aarch64.h +++ b/include/os/linux/kernel/linux/simd_aarch64.h @@ -113,4 +113,14 @@ zfs_sha512_available(void) return (ftr & 0x2); } +/* + * Check if AESV8 is available + */ +static inline boolean_t +zfs_aesv8_available(void) +{ + unsigned long ftr = ((get_ftr(ID_AA64ISAR0_EL1)) >> 4) & 0x3; + return (ftr); +} + #endif /* _LINUX_SIMD_AARCH64_H */ diff --git a/include/os/linux/zfs/sys/zfs_context_os.h b/include/os/linux/zfs/sys/zfs_context_os.h index 04a5f0c0d239..ca424785b975 100644 --- a/include/os/linux/zfs/sys/zfs_context_os.h +++ b/include/os/linux/zfs/sys/zfs_context_os.h @@ -37,4 +37,8 @@ #undef longjmp #endif +#ifndef MODULE_PARAM_MAX +#define MODULE_PARAM_MAX 1024 +#endif + #endif diff --git a/include/sys/abd.h b/include/sys/abd.h index 750f9986c1da..08c1c9ce5760 100644 --- a/include/sys/abd.h +++ b/include/sys/abd.h @@ -60,7 +60,8 @@ typedef struct abd { union { struct abd_scatter { uint_t abd_offset; -#if defined(__FreeBSD__) && defined(_KERNEL) +#if defined(_KERNEL) && (defined(__FreeBSD__) || defined(__APPLE__)) + uint_t abd_chunk_size; void *abd_chunks[1]; /* actually variable-length */ #else uint_t abd_nents; @@ -129,6 +130,7 @@ void abd_copy_off(abd_t *, abd_t *, size_t, size_t, size_t); void abd_copy_from_buf_off(abd_t *, const void *, size_t, size_t); void abd_copy_to_buf_off(void *, abd_t *, size_t, size_t); int abd_cmp(abd_t *, abd_t *); +int abd_cmp_size(abd_t *, abd_t *, size_t); int abd_cmp_buf_off(abd_t *, const void *, size_t, size_t); void abd_zero_off(abd_t *, size_t, size_t); void abd_verify(abd_t *); @@ -176,6 +178,11 @@ abd_zero(abd_t *abd, size_t size) abd_zero_off(abd, 0, size); } +#ifdef __APPLE__ +void abd_return_buf_off(abd_t *, void *, size_t, size_t, size_t); +void abd_return_buf_copy_off(abd_t *, void *, size_t, size_t, size_t); +#endif + /* * ABD type check functions */ diff --git a/include/sys/abd_impl.h b/include/sys/abd_impl.h index 40546d4af137..6d7b4ccc3a59 100644 --- a/include/sys/abd_impl.h +++ b/include/sys/abd_impl.h @@ -95,6 +95,9 @@ void abd_iter_unmap(struct abd_iter *); #if defined(__FreeBSD__) #define abd_enter_critical(flags) critical_enter() #define abd_exit_critical(flags) critical_exit() +#elif defined(__APPLE__) +#define abd_enter_critical(flags) (flags) = ml_set_interrupts_enabled(FALSE) +#define abd_exit_critical(flags) ml_set_interrupts_enabled((flags)) #else #define abd_enter_critical(flags) local_irq_save(flags) #define abd_exit_critical(flags) local_irq_restore(flags) diff --git a/include/sys/asm_linkage.h b/include/sys/asm_linkage.h index 749157d4c3db..95958ad918ae 100644 --- a/include/sys/asm_linkage.h +++ b/include/sys/asm_linkage.h @@ -33,6 +33,10 @@ #include /* XX64 x86/sys/asm_linkage.h */ +#elif defined(__aarch64__) + +#include + #endif #if defined(_KERNEL) && defined(HAVE_KERNEL_OBJTOOL) diff --git a/include/sys/crypto/icp.h b/include/sys/crypto/icp.h index 8c3f19886fd8..fca3f8194546 100644 --- a/include/sys/crypto/icp.h +++ b/include/sys/crypto/icp.h @@ -39,6 +39,9 @@ int icp_init(void); void icp_fini(void); int aes_impl_set(const char *); +int aes_impl_get(char *, size_t); int gcm_impl_set(const char *); +int gcm_impl_get(char *, size_t); + #endif /* _SYS_CRYPTO_ALGS_H */ diff --git a/include/sys/fs/zfs.h b/include/sys/fs/zfs.h index bc940e8a7929..216f0af96a9b 100644 --- a/include/sys/fs/zfs.h +++ b/include/sys/fs/zfs.h @@ -191,6 +191,11 @@ typedef enum { ZFS_PROP_REDACTED, ZFS_PROP_REDACT_SNAPS, ZFS_PROP_SNAPSHOTS_CHANGED, + ZFS_PROP_BROWSE, /* macOS: nobrowse/browse */ + ZFS_PROP_IGNOREOWNER, /* macOS: ignoreowner mount */ + ZFS_PROP_LASTUNMOUNT, /* macOS: Spotlight required */ + ZFS_PROP_MIMIC, /* macOS: mimic=hfs|apfs */ + ZFS_PROP_DEVDISK, /* macOS: create IOkit virtual disk */ ZFS_NUM_PROPS } zfs_prop_t; @@ -543,6 +548,18 @@ typedef enum zfs_key_location { ZFS_KEYLOCATION_LOCATIONS } zfs_keylocation_t; +typedef enum zfs_mimic { + ZFS_MIMIC_OFF = 0, + ZFS_MIMIC_HFS, + ZFS_MIMIC_APFS +} zfs_mimic_t; + +typedef enum zfs_devdisk { + ZFS_DEVDISK_POOLONLY = 0, + ZFS_DEVDISK_OFF, + ZFS_DEVDISK_ON +} zfs_devdisk_t; + #define DEFAULT_PBKDF2_ITERATIONS 350000 #define MIN_PBKDF2_ITERATIONS 100000 @@ -1379,7 +1396,7 @@ typedef enum zfs_ioc { /* * Core features - 88/128 numbers reserved. */ -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__APPLE__) ZFS_IOC_FIRST = 0, #else ZFS_IOC_FIRST = ('Z' << 8), @@ -1488,6 +1505,8 @@ typedef enum zfs_ioc { ZFS_IOC_USERNS_DETACH = ZFS_IOC_UNJAIL, /* 0x86 (Linux) */ ZFS_IOC_SET_BOOTENV, /* 0x87 */ ZFS_IOC_GET_BOOTENV, /* 0x88 */ + ZFS_IOC_PROXY_DATASET, /* 0x89 (macOS) */ + ZFS_IOC_PROXY_REMOVE, /* 0x8a (macOS) */ ZFS_IOC_LAST } zfs_ioc_t; diff --git a/include/sys/mntent.h b/include/sys/mntent.h index 5bb7e080cda8..4449ea1206a8 100644 --- a/include/sys/mntent.h +++ b/include/sys/mntent.h @@ -79,6 +79,13 @@ #elif defined(__FreeBSD__) #define MNTOPT_SETUID "setuid" /* Set uid allowed */ #define MNTOPT_NOSETUID "nosetuid" /* Set uid not allowed */ +#elif defined(__APPLE__) +#define MNTOPT_SETUID "setuid" /* Set uid allowed */ +#define MNTOPT_NOSETUID "nosetuid" /* Set uid not allowed */ +#define MNTOPT_BROWSE "browse" /* browsable autofs mount */ +#define MNTOPT_NOBROWSE "nobrowse" /* non-browsable autofs mount */ +#define MNTOPT_OWNERS "owners" /* use ownership */ +#define MNTOPT_NOOWNERS "noowners" /* ignore ownership */ #else #error "unknown OS" #endif diff --git a/include/sys/spa.h b/include/sys/spa.h index 18062d3f2a95..688639098ef3 100644 --- a/include/sys/spa.h +++ b/include/sys/spa.h @@ -1144,6 +1144,8 @@ extern boolean_t zfs_ereport_is_valid(const char *clazz, spa_t *spa, vdev_t *vd, zio_t *zio); extern void zfs_ereport_taskq_fini(void); extern void zfs_ereport_clear(spa_t *spa, vdev_t *vd); +extern void zfs_ereport_zvol_post(const char *subclass, const char *name, + const char *bsd, const char *rbsd); extern nvlist_t *zfs_event_create(spa_t *spa, vdev_t *vd, const char *type, const char *name, nvlist_t *aux); extern void zfs_post_remove(spa_t *spa, vdev_t *vd); diff --git a/include/sys/spa_impl.h b/include/sys/spa_impl.h index 094258d47a48..194a2e0743a3 100644 --- a/include/sys/spa_impl.h +++ b/include/sys/spa_impl.h @@ -441,6 +441,9 @@ struct spa { boolean_t spa_waiters_cancel; /* waiters should return */ char *spa_compatibility; /* compatibility file(s) */ +#ifdef __APPLE__ + spa_iokit_t *spa_iokit_proxy; /* IOKit pool proxy */ +#endif /* * spa_refcount & spa_config_lock must be the last elements diff --git a/include/sys/sysevent/dev.h b/include/sys/sysevent/dev.h index 0783d0073162..d0eb96eb6b17 100644 --- a/include/sys/sysevent/dev.h +++ b/include/sys/sysevent/dev.h @@ -239,7 +239,7 @@ extern "C" { #define DEV_INSTANCE "instance" #define DEV_PROP_PREFIX "prop-" -#ifdef __linux__ +#if defined(__linux__) || defined(__APPLE__) #define DEV_IDENTIFIER "devid" #define DEV_PATH "path" #define DEV_IS_PART "is_slice" diff --git a/include/sys/vdev_raidz.h b/include/sys/vdev_raidz.h index e34b6e4b158e..f8fc4bacbdc0 100644 --- a/include/sys/vdev_raidz.h +++ b/include/sys/vdev_raidz.h @@ -64,6 +64,7 @@ int vdev_raidz_math_generate(struct raidz_map *, struct raidz_row *); int vdev_raidz_math_reconstruct(struct raidz_map *, struct raidz_row *, const int *, const int *, const int); int vdev_raidz_impl_set(const char *); +int vdev_raidz_impl_get(char *buffer, size_t max); typedef struct vdev_raidz { int vd_logical_width; diff --git a/include/sys/xvattr.h b/include/sys/xvattr.h index a7994db894b9..53d02d3b584d 100644 --- a/include/sys/xvattr.h +++ b/include/sys/xvattr.h @@ -67,6 +67,9 @@ typedef struct xoptattr { uint8_t xoa_sparse; uint8_t xoa_projinherit; uint64_t xoa_projid; + uint8_t xoa_tracked; /* macOS */; + uint8_t xoa_sappendonly; /* macOS */; + uint8_t xoa_simmutable; /* macOS */; } xoptattr_t; /* @@ -174,12 +177,16 @@ typedef struct xvattr { #define XAT0_SPARSE 0x00010000 /* sparse */ #define XAT0_PROJINHERIT 0x00020000 /* Create with parent projid */ #define XAT0_PROJID 0x00040000 /* Project ID */ +#define XAT0_TRACKED 0x00080000 /* macOS UF_TRACKED */ +#define XAT0_SAPPENDONLY 0x00100000 /* macOS SF_APPENDONLY */ +#define XAT0_SIMMUTABLE 0x00200000 /* macOS SF_IMMUTABLE */ #define XAT0_ALL_ATTRS (XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \ XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \ XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| XAT0_AV_MODIFIED| \ XAT0_AV_SCANSTAMP|XAT0_REPARSE|XATO_GEN|XAT0_OFFLINE|XAT0_SPARSE| \ - XAT0_PROJINHERIT | XAT0_PROJID) + XAT0_PROJINHERIT | XAT0_PROJID|XAT0_TRACKED|XAT0_SAPPENDONLY| \ + XAT0_SIMMUTABLE) /* Support for XAT_* optional attributes */ #define XVA_MASK 0xffffffff /* Used to mask off 32 bits */ @@ -218,6 +225,9 @@ typedef struct xvattr { #define XAT_SPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_SPARSE) #define XAT_PROJINHERIT ((XAT0_INDEX << XVA_SHFT) | XAT0_PROJINHERIT) #define XAT_PROJID ((XAT0_INDEX << XVA_SHFT) | XAT0_PROJID) +#define XAT_TRACKED ((XAT0_INDEX << XVA_SHFT) | XAT0_TRACKED) +#define XAT_SAPPENDONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_SAPPENDONLY) +#define XAT_SIMMUTABLE ((XAT0_INDEX << XVA_SHFT) | XAT0_SIMMUTABLE) /* * The returned attribute map array (xva_rtnattrmap[]) is located past the diff --git a/include/sys/zfs_bootenv.h b/include/sys/zfs_bootenv.h index 7af0a57dd008..5823da980b48 100644 --- a/include/sys/zfs_bootenv.h +++ b/include/sys/zfs_bootenv.h @@ -30,6 +30,7 @@ extern "C" { #define BE_FREEBSD_VENDOR "freebsd" #define BE_GRUB_VENDOR "grub" #define BE_LINUX_VENDOR "linux" +#define BE_MACOS_VENDOR "macos" #include diff --git a/include/sys/zfs_debug.h b/include/sys/zfs_debug.h index a1dfef1d89ff..b4fad7ffa6e2 100644 --- a/include/sys/zfs_debug.h +++ b/include/sys/zfs_debug.h @@ -83,12 +83,27 @@ extern void __dprintf(boolean_t dprint, const char *file, const char *func, if (zfs_dbgmsg_enable) \ __dprintf(B_FALSE, __FILE__, __func__, __LINE__, __VA_ARGS__) -#ifdef ZFS_DEBUG +#ifdef __APPLE__ /* * To enable this: * - * $ echo 1 >/sys/module/zfs/parameters/zfs_flags + * $ sysctl kstat.zfs.darwin.tunable.zfs_flags=1 */ +#ifdef _KERNEL +#undef dprintf +#define dprintf(...) \ + if (zfs_flags & ZFS_DEBUG_DPRINTF) \ + __dprintf(B_TRUE, __FILE__, __func__, __LINE__, __VA_ARGS__) +#endif + +#else /* !APPLE */ + +#ifdef ZFS_DEBUG + /* + * To enable this: + * + * $ echo 1 >/sys/module/zfs/parameters/zfs_flags + */ #define dprintf(...) \ if (zfs_flags & ZFS_DEBUG_DPRINTF) \ __dprintf(B_TRUE, __FILE__, __func__, __LINE__, __VA_ARGS__) @@ -96,6 +111,8 @@ extern void __dprintf(boolean_t dprint, const char *file, const char *func, #define dprintf(...) ((void)0) #endif /* ZFS_DEBUG */ +#endif /* !APPLE */ + extern void zfs_panic_recover(const char *fmt, ...); extern void zfs_dbgmsg_init(void); diff --git a/include/sys/zfs_file.h b/include/sys/zfs_file.h index e944165adc40..c11ba376ded4 100644 --- a/include/sys/zfs_file.h +++ b/include/sys/zfs_file.h @@ -31,6 +31,8 @@ typedef struct zfs_file { } zfs_file_t; #elif defined(__linux__) || defined(__FreeBSD__) typedef struct file zfs_file_t; +#elif defined(__APPLE__) +typedef struct spl_fileproc zfs_file_t; #else #error "unknown OS" #endif diff --git a/include/sys/zfs_ioctl_impl.h b/include/sys/zfs_ioctl_impl.h index cb852c5577fd..df5fe41bae43 100644 --- a/include/sys/zfs_ioctl_impl.h +++ b/include/sys/zfs_ioctl_impl.h @@ -75,6 +75,9 @@ int zfs_secpolicy_config(zfs_cmd_t *, nvlist_t *, cred_t *); void zfs_ioctl_register_dataset_nolog(zfs_ioc_t, zfs_ioc_legacy_func_t *, zfs_secpolicy_func_t *, zfs_ioc_poolcheck_t); +void zfs_ioctl_register_pool(zfs_ioc_t, zfs_ioc_legacy_func_t *, + zfs_secpolicy_func_t *, boolean_t, zfs_ioc_poolcheck_t); + void zfs_ioctl_register(const char *, zfs_ioc_t, zfs_ioc_func_t *, zfs_secpolicy_func_t *, zfs_ioc_namecheck_t, zfs_ioc_poolcheck_t, diff --git a/include/sys/zfs_sa.h b/include/sys/zfs_sa.h index 1b4b8abf0244..502d3e8f35a2 100644 --- a/include/sys/zfs_sa.h +++ b/include/sys/zfs_sa.h @@ -75,6 +75,16 @@ typedef enum zpl_attr { ZPL_DACL_ACES, ZPL_DXATTR, ZPL_PROJID, + + /* + * Apple defines a ADDEDTIME, which is the time the entry was placed + * in the containing directory. Ie, CRTIME and updated when moved + * into a different directory. This can be retrieved with getxattr + * "FinderInfo" or the getattrlist() syscall. + */ + ZPL_ADDTIME, + ZPL_DOCUMENTID, + ZPL_END } zpl_attr_t; diff --git a/include/sys/zfs_znode.h b/include/sys/zfs_znode.h index 2f266f53247e..4798e4cdd459 100644 --- a/include/sys/zfs_znode.h +++ b/include/sys/zfs_znode.h @@ -112,6 +112,9 @@ extern "C" { #define SA_ZPL_PAD(z) z->z_attr_table[ZPL_PAD] #define SA_ZPL_PROJID(z) z->z_attr_table[ZPL_PROJID] +#define SA_ZPL_ADDTIME(z) z->z_attr_table[ZPL_ADDTIME] +#define SA_ZPL_DOCUMENTID(z) z->z_attr_table[ZPL_DOCUMENTID] + /* * Is ID ephemeral? */ diff --git a/include/sys/zio.h b/include/sys/zio.h index e1f4d5c04499..a4c93697a981 100644 --- a/include/sys/zio.h +++ b/include/sys/zio.h @@ -520,6 +520,10 @@ struct zio { kcondvar_t io_cv; int io_allocator; +#ifdef ZIO_OS_FIELDS + ZIO_OS_FIELDS +#endif + /* FMA state */ zio_cksum_report_t *io_cksum_report; uint64_t io_ena; diff --git a/include/sys/zio_crypt.h b/include/sys/zio_crypt.h index 6a3efabb0405..75b2dd962160 100644 --- a/include/sys/zio_crypt.h +++ b/include/sys/zio_crypt.h @@ -148,6 +148,11 @@ int zio_crypt_do_hmac(zio_crypt_key_t *key, uint8_t *data, uint_t datalen, uint8_t *digestbuf, uint_t digestlen); int zio_crypt_do_objset_hmacs(zio_crypt_key_t *key, void *data, uint_t datalen, boolean_t byteswap, uint8_t *portable_mac, uint8_t *local_mac); +#ifdef __APPLE__ +int zio_crypt_do_objset_hmacs_errata1(zio_crypt_key_t *key, void *data, + uint_t datalen, boolean_t should_bswap, uint8_t *portable_mac, + uint8_t *local_mac); +#endif int zio_do_crypt_data(boolean_t encrypt, zio_crypt_key_t *key, dmu_object_type_t ot, boolean_t byteswap, uint8_t *salt, uint8_t *iv, uint8_t *mac, uint_t datalen, uint8_t *plainbuf, uint8_t *cipherbuf, diff --git a/include/zfs_fletcher.h b/include/zfs_fletcher.h index ca1a092928d6..b61f428ef335 100644 --- a/include/zfs_fletcher.h +++ b/include/zfs_fletcher.h @@ -132,6 +132,7 @@ typedef struct fletcher_4_func { _ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_superscalar_ops; _ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_superscalar4_ops; +_ZFS_FLETCHER_H int fletcher_4_get(char *, size_t); #if defined(HAVE_SSE2) _ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_sse2_ops; diff --git a/lib/Makefile.am b/lib/Makefile.am index 499ebdaeba9b..91ebc4b440d9 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -54,6 +54,16 @@ noinst_LTLIBRARIES = lib_LTLIBRARIES = pkgconfig_DATA = + +if BUILD_MACOS +include $(srcdir)/%D%/os/macos/libdiskmgt/Makefile.am +include $(srcdir)/%D%/libefi/Makefile.am +endif + +if BUILD_LINUX +include $(srcdir)/%D%/libefi/Makefile.am +endif + include $(srcdir)/%D%/libavl/Makefile.am include $(srcdir)/%D%/libicp/Makefile.am include $(srcdir)/%D%/libnvpair/Makefile.am @@ -68,10 +78,6 @@ include $(srcdir)/%D%/libzfsbootenv/Makefile.am include $(srcdir)/%D%/libzpool/Makefile.am include $(srcdir)/%D%/libzstd/Makefile.am include $(srcdir)/%D%/libzutil/Makefile.am -if BUILD_LINUX -include $(srcdir)/%D%/libefi/Makefile.am -endif - PHONY += lib lib: $(noinst_LTLIBRARIES) $(lib_LTLIBRARIES) diff --git a/lib/libefi/Makefile.am b/lib/libefi/Makefile.am index 5c3e57346c86..f8abc88701be 100644 --- a/lib/libefi/Makefile.am +++ b/lib/libefi/Makefile.am @@ -5,7 +5,18 @@ libefi_la_CFLAGS += -fvisibility=hidden noinst_LTLIBRARIES += libefi.la CPPCHECKTARGETS += libefi.la -libefi_la_SOURCES = \ +libefi_la_SOURCES = +libefi_la_LDFLAGS = + +if BUILD_MACOS +libefi_la_SOURCES += \ + %D%/rdwr_efi_macos.c +libefi_la_LDFLAGS += -framework DiskArbitration -framework CoreServices +endif + +if BUILD_LINUX +libefi_la_SOURCES += \ %D%/rdwr_efi.c +endif libefi_la_LIBADD = $(LIBUUID_LIBS) $(ZLIB_LIBS) diff --git a/lib/libicp/Makefile.am b/lib/libicp/Makefile.am index 4ba55b2158bc..257f71e3fbcd 100644 --- a/lib/libicp/Makefile.am +++ b/lib/libicp/Makefile.am @@ -9,6 +9,7 @@ nodist_libicp_la_SOURCES = \ module/icp/api/kcf_cipher.c \ module/icp/api/kcf_mac.c \ module/icp/algs/aes/aes_impl_aesni.c \ + module/icp/algs/aes/aes_impl_aesv8.c \ module/icp/algs/aes/aes_impl_generic.c \ module/icp/algs/aes/aes_impl_x86-64.c \ module/icp/algs/aes/aes_impl.c \ @@ -44,6 +45,7 @@ nodist_libicp_la_SOURCES = \ if TARGET_CPU_AARCH64 nodist_libicp_la_SOURCES += \ + module/icp/asm-aarch64/aes/aesv8-armx.S \ module/icp/asm-aarch64/blake3/b3_aarch64_sse2.S \ module/icp/asm-aarch64/blake3/b3_aarch64_sse41.S \ module/icp/asm-aarch64/sha2/sha256-armv8.S \ @@ -81,4 +83,3 @@ nodist_libicp_la_SOURCES += \ module/icp/asm-x86_64/blake3/blake3_sse2.S \ module/icp/asm-x86_64/blake3/blake3_sse41.S endif - diff --git a/lib/libnvpair/Makefile.am b/lib/libnvpair/Makefile.am index 87b8d32aa175..1c6ea889f18d 100644 --- a/lib/libnvpair/Makefile.am +++ b/lib/libnvpair/Makefile.am @@ -6,6 +6,27 @@ libnvpair_la_CFLAGS += -fvisibility=hidden %D%/libnvpair_la-libnvpair_json.$(OBJEXT) : CFLAGS += -Wno-type-limits %D%/libnvpair_la-libnvpair_json.l$(OBJEXT): CFLAGS += -Wno-type-limits + +if BUILD_MACOS +# See comment in macOS rpc/xdr.h, starting at: +# "A xdrproc_t exists for each data type which is to be encoded or decoded." +module/nvpair/nvpair.$(OBJEXT): CFLAGS += -Wno-incompatible-pointer-types +../../module/nvpair/nvpair.$(OBJEXT): CFLAGS += -Wwgat -Wno-incompatible-pointer-types +%D%/libnvpair_la-nvpair.$(OBJEXT) : CFLAGS += -Wno-type-limits +nvpair.$(OBJEXT) : CFLAGS += -Wno-type-limits2 +libnvpair_la-nvpair.$(OBJEXT) : CFLAGS += -Wno-type-limits3 +%D%/../../module/nvpair/libnvpair_la-nvpair.$(OBJEXT) : CFLAGS += -Wno-type-limits4 +endif +nvpair.lo : CFLAGS += -Wno-type-limits2 +libnvpair_la-nvpair.lo : CFLAGS += -Wno-type-limits2 +%D%/libnvpair_la-nvpair.lo : CFLAGS += -Wno-type-limits2 +../../module/nvpair/nvpair.lo : CFLAGS += -Wno-type-limits2 +module/nvpair/nvpair.lo : CFLAGS += -Wno-type-limits2 +module/nvpair/libnvpair_la-nvpair.lo : CFLAGS += -Wno-type-limits2 + + + + lib_LTLIBRARIES += libnvpair.la CPPCHECKTARGETS += libnvpair.la @@ -26,9 +47,11 @@ libnvpair_la_LIBADD += $(LIBTIRPC_LIBS) $(LTLIBINTL) libnvpair_la_LDFLAGS = +if !BUILD_MACOS if !ASAN_ENABLED libnvpair_la_LDFLAGS += -Wl,-z,defs endif +endif libnvpair_la_LDFLAGS += -version-info 3:0:0 diff --git a/lib/libshare/Makefile.am b/lib/libshare/Makefile.am index 48d8cb832428..c61b6a44e6b2 100644 --- a/lib/libshare/Makefile.am +++ b/lib/libshare/Makefile.am @@ -25,3 +25,9 @@ libshare_la_SOURCES += \ %D%/os/freebsd/nfs.c \ %D%/os/freebsd/smb.c endif + +if BUILD_MACOS +libshare_la_SOURCES += \ + %D%/os/macos/nfs.c \ + %D%/os/macos/smb.c +endif diff --git a/lib/libspl/Makefile.am b/lib/libspl/Makefile.am index 822bef7e7a8d..9ab692418e2c 100644 --- a/lib/libspl/Makefile.am +++ b/lib/libspl/Makefile.am @@ -39,6 +39,13 @@ libspl_la_SOURCES += \ %D%/os/freebsd/zone.c endif +if BUILD_MACOS +libspl_la_SOURCES += \ + %D%/os/macos/getexecname.c \ + %D%/os/macos/gethostid.c \ + %D%/os/macos/zone.c +endif + libspl_la_LIBADD = \ libspl_assert.la diff --git a/lib/libspl/atomic.c b/lib/libspl/atomic.c index 8cc350710ba0..103949ecdffa 100644 --- a/lib/libspl/atomic.c +++ b/lib/libspl/atomic.c @@ -343,13 +343,13 @@ atomic_swap_ptr(volatile void *target, void *bits) uint64_t atomic_load_64(volatile uint64_t *target) { - return (__atomic_load_n(target, __ATOMIC_RELAXED)); + return (__atomic_load_n(target, __ATOMIC_ACQUIRE)); } void atomic_store_64(volatile uint64_t *target, uint64_t bits) { - return (__atomic_store_n(target, bits, __ATOMIC_RELAXED)); + return (__atomic_store_n(target, bits, __ATOMIC_RELEASE)); } #endif @@ -390,11 +390,11 @@ membar_sync(void) void membar_producer(void) { - __atomic_thread_fence(__ATOMIC_RELEASE); + __atomic_thread_fence(__ATOMIC_SEQ_CST); } void membar_consumer(void) { - __atomic_thread_fence(__ATOMIC_ACQUIRE); + __atomic_thread_fence(__ATOMIC_SEQ_CST); } diff --git a/lib/libspl/include/Makefile.am b/lib/libspl/include/Makefile.am index 2c1d21edf19d..872b105328ce 100644 --- a/lib/libspl/include/Makefile.am +++ b/lib/libspl/include/Makefile.am @@ -101,3 +101,44 @@ libspl_sys_dktpdir = $(libspl_sysdir)/dktp libspl_sys_dktp_HEADERS = \ %D%/sys/dktp/fdisk.h +if BUILD_MACOS + +# macOS does not promote header location (legacy) +libsplmacosdir = $(includedir)/libspl/os/macos +libsplmacos_HEADERS = \ + %D%/os/macos/dirent.h \ + %D%/os/macos/libdiskmgt.h \ + %D%/os/macos/mntent.h \ + %D%/os/macos/poll.h \ + %D%/os/macos/pthread.h \ + %D%/os/macos/stdio.h \ + %D%/os/macos/stdlib.h \ + %D%/os/macos/string.h \ + %D%/os/macos/synch.h \ + %D%/os/macos/time.h \ + %D%/os/macos/unistd.h + +libsplmacos_machdir = $(libsplmacosdir)/mach +libsplmacos_mach_HEADERS = \ + %D%/os/macos/mach/boolean.h \ + %D%/os/macos/mach/task.h + +libsplmacos_sysdir = $(libsplmacosdir)/sys +libsplmacos_sys_HEADERS = \ + %D%/os/macos/sys/byteorder.h \ + %D%/os/macos/sys/errno.h \ + %D%/os/macos/sys/fcntl.h \ + %D%/os/macos/sys/file.h \ + %D%/os/macos/sys/kernel_types.h \ + %D%/os/macos/sys/misc.h \ + %D%/os/macos/sys/mnttab.h \ + %D%/os/macos/sys/mount.h \ + %D%/os/macos/sys/param.h \ + %D%/os/macos/sys/stat.h \ + %D%/os/macos/sys/sysmacros.h \ + %D%/os/macos/sys/time.h \ + %D%/os/macos/sys/uio.h \ + %D%/os/macos/sys/vfs.h \ + %D%/os/macos/sys/xattr.h \ + %D%/os/macos/sys/zfs_context_os.h +endif diff --git a/lib/libspl/include/sys/asm_linkage.h b/lib/libspl/include/sys/asm_linkage.h index 84aa0854a9ff..ba08164c954a 100644 --- a/lib/libspl/include/sys/asm_linkage.h +++ b/lib/libspl/include/sys/asm_linkage.h @@ -29,8 +29,11 @@ #if defined(__i386) || defined(__amd64) +#if defined(__APPLE__) +#include /* XX64 x86/sys/asm_linkage.h */ +#else #include /* XX64 x86/sys/asm_linkage.h */ - +#endif #endif #if defined(_KERNEL) && defined(HAVE_KERNEL_OBJTOOL) diff --git a/lib/libspl/include/sys/dkio.h b/lib/libspl/include/sys/dkio.h index 9517b580bdf5..72e9eeeb71f8 100644 --- a/lib/libspl/include/sys/dkio.h +++ b/lib/libspl/include/sys/dkio.h @@ -161,7 +161,9 @@ struct dk_geom { */ #define DKIOCGGEOM (DKIOC|1) /* Get geometry */ #define DKIOCINFO (DKIOC|3) /* Get info */ +#ifndef DKIOCEJECT #define DKIOCEJECT (DKIOC|6) /* Generic 'eject' */ +#endif #define DKIOCGVTOC (DKIOC|11) /* Get VTOC */ #define DKIOCSVTOC (DKIOC|12) /* Set VTOC & Write to Disk */ diff --git a/lib/libspl/include/sys/isa_defs.h b/lib/libspl/include/sys/isa_defs.h index 302f31e989cb..4b3fbe56318e 100644 --- a/lib/libspl/include/sys/isa_defs.h +++ b/lib/libspl/include/sys/isa_defs.h @@ -128,13 +128,16 @@ extern "C" { /* arm arch specific defines */ #elif defined(__arm) || defined(__arm__) +/* We can NOT define __arm / __arm__ on macOS, it is only for 32bit */ #if !defined(__arm) #define __arm #endif +#ifndef __APPLE__ #if !defined(__arm__) #define __arm__ #endif +#endif #if !defined(_ILP32) #define _ILP32 diff --git a/lib/libspl/include/sys/simd.h b/lib/libspl/include/sys/simd.h index 41f9df506468..3b14d554c9c4 100644 --- a/lib/libspl/include/sys/simd.h +++ b/lib/libspl/include/sys/simd.h @@ -49,6 +49,27 @@ static inline unsigned long getauxval(unsigned long key) #define AT_HWCAP 16 #define AT_HWCAP2 26 extern unsigned long getauxval(unsigned long type); +#elif defined(__APPLE__) +#include +#define AT_HWCAP 0 +static inline unsigned long getauxval(unsigned long key) +{ + (void) key; + /* HWCAP_ are all defined halfway down this file */ + unsigned long val = 1 /* HWCAP_FP */; + int intval; + size_t intvallen = sizeof (intval); + int err; + err = sysctlbyname("hw.optional.arm.FEAT_SHA256", + &intval, &intvallen, NULL, 0); + if (err == 0 && intval != 0) + val |= 0x00000040; /* SHA256 */ + err = sysctlbyname("hw.optional.arm.FEAT_SHA512", + &intval, &intvallen, NULL, 0); + if (err == 0 && intval != 0) + val |= 0x00200000; /* SHA512 */ + return (val); +} #endif /* __linux__ */ #endif /* arm || aarch64 || powerpc */ @@ -516,6 +537,7 @@ zfs_sha256_available(void) #define kfpu_end() do {} while (0) #define HWCAP_FP 0x00000001 +#define HWCAP_AES 0x00000008 #define HWCAP_SHA2 0x00000040 #define HWCAP_SHA512 0x00200000 @@ -549,6 +571,16 @@ zfs_sha512_available(void) return (hwcap & HWCAP_SHA512); } +/* + * Check if AESV8 is available + */ +static inline boolean_t +zfs_aesv8_available(void) +{ + unsigned long hwcap = getauxval(AT_HWCAP); + return (hwcap & HWCAP_AES); +} + #elif defined(__powerpc__) #define kfpu_allowed() 0 diff --git a/lib/libspl/include/sys/uio.h b/lib/libspl/include/sys/uio.h index e9e21819d4f8..94088a5cf4fb 100644 --- a/lib/libspl/include/sys/uio.h +++ b/lib/libspl/include/sys/uio.h @@ -43,14 +43,10 @@ #include #include_next -#ifdef __APPLE__ -#include -#endif - #include typedef struct iovec iovec_t; -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) typedef enum zfs_uio_rw { UIO_READ = 0, UIO_WRITE = 1, diff --git a/lib/libuutil/Makefile.am b/lib/libuutil/Makefile.am index b973ce3cca4c..18ecc74144c1 100644 --- a/lib/libuutil/Makefile.am +++ b/lib/libuutil/Makefile.am @@ -19,9 +19,11 @@ libuutil_la_LIBADD += $(LTLIBINTL) libuutil_la_LDFLAGS = -pthread +if !BUILD_MACOS if !ASAN_ENABLED libuutil_la_LDFLAGS += -Wl,-z,defs endif +endif libuutil_la_LDFLAGS += -version-info 3:0:0 diff --git a/lib/libzfs/Makefile.am b/lib/libzfs/Makefile.am index 5e74d908de3d..697da3a30c87 100644 --- a/lib/libzfs/Makefile.am +++ b/lib/libzfs/Makefile.am @@ -33,6 +33,15 @@ dist_libzfs_la_SOURCES += \ %D%/os/linux/libzfs_util_os.c endif +if BUILD_MACOS +dist_libzfs_la_SOURCES += \ + %D%/os/macos/libzfs_dataset_os.c \ + %D%/os/macos/libzfs_getmntany.c \ + %D%/os/macos/libzfs_mount_os.c \ + %D%/os/macos/libzfs_pool_os.c \ + %D%/os/macos/libzfs_util_os.c +endif + nodist_libzfs_la_SOURCES = \ module/zcommon/cityhash.c \ module/zcommon/zfeature_common.c \ @@ -61,14 +70,22 @@ libzfs_la_LIBADD += -lrt -lm $(LIBCRYPTO_LIBS) $(ZLIB_LIBS) $(LIBFETCH_LIBS) $(L libzfs_la_LDFLAGS = -pthread +if !BUILD_MACOS if !ASAN_ENABLED libzfs_la_LDFLAGS += -Wl,-z,defs endif +endif if BUILD_FREEBSD libzfs_la_LIBADD += -lutil -lgeom endif +if BUILD_MACOS +libzfs_la_LIBADD += \ + libdiskmgt.la +libzfs_la_LDFLAGS += -lobjc -framework IOKit -framework Foundation -lssl +endif + libzfs_la_LDFLAGS += -version-info 5:0:1 pkgconfig_DATA += %D%/libzfs.pc diff --git a/lib/libzfs/libzfs.abi b/lib/libzfs/libzfs.abi index c1ce3d0f67d8..c819b0a8be23 100644 --- a/lib/libzfs/libzfs.abi +++ b/lib/libzfs/libzfs.abi @@ -1867,7 +1867,12 @@ - + + + + + + diff --git a/lib/libzfs/libzfs_crypto.c b/lib/libzfs/libzfs_crypto.c index 8f2a50d55e87..8dd842dd6c27 100644 --- a/lib/libzfs/libzfs_crypto.c +++ b/lib/libzfs/libzfs_crypto.c @@ -611,7 +611,9 @@ get_key_material_https(libzfs_handle_t *hdl, const char *uri, (void) unlink(path); free(path); +#ifdef O_TMPFILE kfdok: +#endif if ((key = fdopen(kfd, "r+")) == NULL) { ret = errno; (void) close(kfd); diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index 727efc5a91ad..9a00bf9ec2f7 100644 --- a/lib/libzfs/libzfs_dataset.c +++ b/lib/libzfs/libzfs_dataset.c @@ -33,6 +33,7 @@ * Copyright (c) 2019 Datto Inc. * Copyright (c) 2019, loli10K * Copyright (c) 2021 Matt Fiddaman + * Copyright (c) 2020, Jorgen Lundman */ #include @@ -2219,6 +2220,18 @@ get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src, mntopt_off = MNTOPT_NONBMAND; break; +#ifdef __APPLE__ /* So they don't need to have MNTOPT_BROWSE */ + case ZFS_PROP_BROWSE: + mntopt_on = MNTOPT_BROWSE; + mntopt_off = MNTOPT_NOBROWSE; + break; + + case ZFS_PROP_IGNOREOWNER: + mntopt_on = MNTOPT_NOOWNERS; + mntopt_off = MNTOPT_OWNERS; + break; +#endif + default: break; } @@ -2255,6 +2268,10 @@ get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src, case ZFS_PROP_SETUID: #ifndef __FreeBSD__ case ZFS_PROP_XATTR: +#endif +#ifdef __APPLE__ + case ZFS_PROP_BROWSE: + case ZFS_PROP_IGNOREOWNER: #endif case ZFS_PROP_NBMAND: *val = getprop_uint64(zhp, prop, source); @@ -2765,6 +2782,33 @@ zfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen, relpath[0] != '\0')) str++; +#ifdef __APPLE__ + /* + * On OSX by default we mount pools under /Volumes + * unless the dataset property mountpoint specifies + * otherwise. + * In addition to this, there is an undocumented + * environment variable __ZFS_MAIN_MOUNTPOINT_DIR, + * used mainly by the testing environment, as it + * expects "/" by default. + */ + const char *default_mountpoint; + default_mountpoint = + getenv("__ZFS_MAIN_MOUNTPOINT_DIR"); + if (!default_mountpoint) + default_mountpoint = "/Volumes/"; + + if (relpath[0] == '\0') + (void) snprintf(propbuf, proplen, "%s%s", + root, str); + else + (void) snprintf(propbuf, proplen, "%s%s%s%s", + root, str, source == NULL || + source[0] == '\0' ? default_mountpoint : + "/", relpath); + +#else + if (relpath[0] == '\0') (void) snprintf(propbuf, proplen, "%s%s", root, str); @@ -2772,6 +2816,8 @@ zfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen, (void) snprintf(propbuf, proplen, "%s%s%s%s", root, str, relpath[0] == '@' ? "" : "/", relpath); +#endif /* APPLE */ + } else { /* 'legacy' or 'none' */ (void) strlcpy(propbuf, str, proplen); @@ -3911,7 +3957,23 @@ zfs_destroy(zfs_handle_t *zhp, boolean_t defer) error = lzc_destroy_snaps(nv, defer, NULL); fnvlist_free(nv); } else { + +#ifdef __APPLE__ + /* DiskArbitrationd gets in the way a lot */ + int retry = 0; + do { + if ((retry++) != 1) { + sleep(1); + } +#endif + error = lzc_destroy(zhp->zfs_name); + +#ifdef __APPLE__ + } while ((error == EBUSY) && (retry <= 5)); +#endif + + } if (error != 0 && error != ENOENT) { diff --git a/lib/libzfs/libzfs_diff.c b/lib/libzfs/libzfs_diff.c index da2b26ef99ce..4b743bc593aa 100644 --- a/lib/libzfs/libzfs_diff.c +++ b/lib/libzfs/libzfs_diff.c @@ -761,7 +761,12 @@ zfs_show_diffs(zfs_handle_t *zhp, int outfd, const char *fromsnap, return (-1); } +#if defined(__APPLE__) + /* Can't do IO on pipes, open fds mkfifo */ + if (libzfs_macos_pipefd(&pipefd[0], &pipefd[1])) { +#else if (pipe2(pipefd, O_CLOEXEC)) { +#endif zfs_error_aux(zhp->zfs_hdl, "%s", strerror(errno)); teardown_differ_info(&di); return (zfs_error(zhp->zfs_hdl, EZFS_PIPEFAILED, errbuf)); diff --git a/lib/libzfs/libzfs_iter.c b/lib/libzfs/libzfs_iter.c index 452d8fd6ab71..e1404475a3c1 100644 --- a/lib/libzfs/libzfs_iter.c +++ b/lib/libzfs/libzfs_iter.c @@ -634,17 +634,19 @@ zfs_iter_mounted(zfs_handle_t *zhp, zfs_iter_f func, void *data) continue; if ((mtab_zhp = zfs_open(zhp->zfs_hdl, entry.mnt_special, - ZFS_TYPE_FILESYSTEM)) == NULL) + ZFS_TYPE_FILESYSTEM|ZFS_TYPE_SNAPSHOT)) == NULL) continue; /* Ignore legacy mounts as they are user managed */ - verify(zfs_prop_get(mtab_zhp, ZFS_PROP_MOUNTPOINT, mnt_prop, - sizeof (mnt_prop), NULL, NULL, 0, B_FALSE) == 0); - if (strcmp(mnt_prop, "legacy") == 0) { - zfs_close(mtab_zhp); - continue; + if (mtab_zhp->zfs_type != ZFS_TYPE_SNAPSHOT) { + verify(zfs_prop_get(mtab_zhp, ZFS_PROP_MOUNTPOINT, + mnt_prop, sizeof (mnt_prop), NULL, NULL, 0, + B_FALSE) == 0); + if (strcmp(mnt_prop, "legacy") == 0) { + zfs_close(mtab_zhp); + continue; + } } - err = func(mtab_zhp, data); } diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index e9bc78aa8d39..ba2becec0186 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -1252,6 +1252,12 @@ dump_snapshot(zfs_handle_t *zhp, void *arg) } if (!sdd->dryrun) { + +#if defined(__APPLE__) + /* Can't do IO on pipes, possibly wrap fd in domain socket */ + libzfs_macos_wrapfd(&sdd->outfd, B_TRUE); +#endif + /* * If progress reporting is requested, spawn a new thread to * poll ZFS_IOC_SEND_PROGRESS at a regular interval. @@ -1961,6 +1967,11 @@ zfs_send_resume_impl_cb_impl(libzfs_handle_t *hdl, sendflags_t *flags, SEND_PROGRESS_THREAD_PARENT_BLOCK(&oldmask); } +#if defined(__APPLE__) + /* Can't do IO on pipes, possibly wrap fd in domain socket */ + libzfs_macos_wrapfd(&outfd, B_TRUE); +#endif + error = lzc_send_resume_redacted(zhp->zfs_name, fromname, outfd, lzc_flags, resumeobj, resumeoff, redact_book); if (redact_book != NULL) @@ -2747,6 +2758,11 @@ zfs_send_one_cb_impl(zfs_handle_t *zhp, const char *from, int fd, if (flags->dryrun) return (0); +#if defined(__APPLE__) + /* Can't do IO on pipes, possibly wrap fd in domain socket */ + libzfs_macos_wrapfd(&fd, B_TRUE); +#endif + /* * If progress reporting is requested, spawn a new thread to poll * ZFS_IOC_SEND_PROGRESS at a regular interval. @@ -2830,6 +2846,7 @@ zfs_send_one_cb_impl(zfs_handle_t *zhp, const char *from, int fd, return (zfs_standard_error(hdl, errno, errbuf)); } } + return (err != 0); } @@ -5019,6 +5036,11 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, goto out; } +#if defined(__APPLE__) + /* Can't do IO on pipes, possibly wrap fd in domain socket */ + libzfs_macos_wrapfd(&infd, B_FALSE); +#endif + if (flags->heal) { err = ioctl_err = lzc_receive_with_heal(destsnap, rcvprops, oxprops, wkeydata, wkeylen, origin, flags->force, @@ -5448,6 +5470,11 @@ zfs_receive_impl(libzfs_handle_t *hdl, const char *tosnap, return (zfs_error(hdl, EZFS_NOENT, errbuf)); } +#if defined(__APPLE__) + /* Can't do IO on pipes, possibly wrap fd in domain socket */ + libzfs_macos_wrapfd(&infd, B_FALSE); +#endif + /* read in the BEGIN record */ if (0 != (err = recv_read(hdl, infd, &drr, sizeof (drr), B_FALSE, &zcksum))) diff --git a/lib/libzfs_core/Makefile.am b/lib/libzfs_core/Makefile.am index d1c6fb86d186..e392e34f767d 100644 --- a/lib/libzfs_core/Makefile.am +++ b/lib/libzfs_core/Makefile.am @@ -23,6 +23,13 @@ nodist_libzfs_core_la_SOURCES = \ module/os/freebsd/zfs/zfs_ioctl_compat.c endif +if BUILD_MACOS +libzfs_core_la_CPPFLAGS += -I$(top_srcdir)/include/os/macos/zfs + +libzfs_core_la_SOURCES += \ + %D%/os/macos/libzfs_core_ioctl.c +endif + libzfs_core_la_LIBADD = \ libnvpair.la \ libspl.la @@ -31,9 +38,11 @@ libzfs_core_la_LIBADD += $(LTLIBINTL) libzfs_core_la_LDFLAGS = -pthread +if !BUILD_MACOS if !ASAN_ENABLED libzfs_core_la_LDFLAGS += -Wl,-z,defs endif +endif if BUILD_FREEBSD libzfs_core_la_LIBADD += -lutil -lgeom diff --git a/lib/libzfs_core/libzfs_core.c b/lib/libzfs_core/libzfs_core.c index 01d803e21db0..1c4f3898a043 100644 --- a/lib/libzfs_core/libzfs_core.c +++ b/lib/libzfs_core/libzfs_core.c @@ -94,6 +94,9 @@ #if __FreeBSD__ #define BIG_PIPE_SIZE (64 * 1024) /* From sys/pipe.h */ #endif +#if __APPLE__ +#define BIG_PIPE_SIZE (64 * 1024) +#endif static int g_fd = -1; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; diff --git a/lib/libzfsbootenv/Makefile.am b/lib/libzfsbootenv/Makefile.am index 118f154821fc..8913f07983aa 100644 --- a/lib/libzfsbootenv/Makefile.am +++ b/lib/libzfsbootenv/Makefile.am @@ -18,9 +18,11 @@ libzfsbootenv_la_LIBADD = \ libzfsbootenv_la_LDFLAGS = +if !BUILD_MACOS if !ASAN_ENABLED libzfsbootenv_la_LDFLAGS += -Wl,-z,defs endif +endif libzfsbootenv_la_LDFLAGS += -version-info 1:0:0 diff --git a/lib/libzpool/Makefile.am b/lib/libzpool/Makefile.am index 58d7f07527aa..4ef6d4b87bbb 100644 --- a/lib/libzpool/Makefile.am +++ b/lib/libzpool/Makefile.am @@ -197,9 +197,11 @@ libzpool_la_LIBADD += $(LIBCLOCK_GETTIME) $(ZLIB_LIBS) -ldl -lm libzpool_la_LDFLAGS = -pthread +if !BUILD_MACOS if !ASAN_ENABLED libzpool_la_LDFLAGS += -Wl,-z,defs endif +endif if BUILD_FREEBSD libzpool_la_LIBADD += -lgeom diff --git a/lib/libzutil/Makefile.am b/lib/libzutil/Makefile.am index 519906235f7f..cbd0363279a7 100644 --- a/lib/libzutil/Makefile.am +++ b/lib/libzutil/Makefile.am @@ -28,6 +28,12 @@ libzutil_la_SOURCES += \ %D%/os/freebsd/zutil_import_os.c endif +if BUILD_MACOS +libzutil_la_SOURCES += \ + %D%/os/macos/zutil_device_path_os.c \ + %D%/os/macos/zutil_import_os.c +endif + libzutil_la_LIBADD = \ libavl.la \ libtpool.la \ @@ -40,4 +46,9 @@ libzutil_la_LIBADD += \ -lrt endif +if BUILD_MACOS +libzutil_la_LIBADD += \ + libefi.la +endif + libzutil_la_LIBADD += -lm $(LIBBLKID_LIBS) $(LIBUDEV_LIBS) diff --git a/lib/libzutil/zutil_device_path.c b/lib/libzutil/zutil_device_path.c index 0425018e1022..4447f4af86c7 100644 --- a/lib/libzutil/zutil_device_path.c +++ b/lib/libzutil/zutil_device_path.c @@ -24,6 +24,7 @@ */ #include +#include #include #include #include @@ -158,6 +159,8 @@ zfs_strcmp_pathname(const char *name, const char *cmp, int wholedisk) char path_name[MAXPATHLEN]; char cmp_name[MAXPATHLEN]; char *dir, *tmp = NULL; + char *d, *b; + const char *dpath, *bname; /* Strip redundant slashes if they exist due to ZPOOL_IMPORT_PATH */ cmp_name[0] = '\0'; @@ -182,8 +185,39 @@ zfs_strcmp_pathname(const char *name, const char *cmp, int wholedisk) return (ENOMEM); } - if ((path_len != cmp_len) || strcmp(path_name, cmp_name)) - return (ENOENT); + if ((path_len == cmp_len) && strcmp(path_name, cmp_name) == 0) + return (0); + else { + int idx; + d = strdup(path_name); + b = strdup(path_name); + idx = zfs_dirnamelen(d); + if (idx != -1) + d[idx] = 0; + dpath = d; + bname = zfs_basename(b); + if (realpath(dpath, path_name) == NULL) { + (void) fprintf(stderr, "cannot resolve path '%s'\n", + dpath); + free(d); + free(b); + return (ENOENT); + } + + if (strcmp(dpath, path_name) == 0) { + free(d); + free(b); + return (ENOENT); // We already tried this path + } + + strlcat(path_name, "/", sizeof (path_name)); + path_len = strlcat(path_name, bname, sizeof (path_name)); + free(d); + free(b); + + if ((path_len == cmp_len) && strcmp(path_name, cmp_name) == 0) + return (0); + } - return (0); + return (ENOENT); } diff --git a/lib/libzutil/zutil_import.c b/lib/libzutil/zutil_import.c index 19d8a4742813..15a1c9a4c178 100644 --- a/lib/libzutil/zutil_import.c +++ b/lib/libzutil/zutil_import.c @@ -910,6 +910,12 @@ get_configs(libpc_handle_t *hdl, pool_list_t *pl, boolean_t active_ok, return (NULL); } +#ifdef __APPLE__ + +/* We have our own zpool_read_label() / label_offset() */ + +#else + /* * Return the offset of the given label. */ @@ -921,6 +927,9 @@ label_offset(uint64_t size, int l) 0 : size - VDEV_LABELS * sizeof (vdev_label_t))); } +#ifdef __APPLE__ +/* We have our own */ +#else /* * The same description applies as to zpool_read_label below, * except here we do it without aio, presumably because an aio call @@ -997,6 +1006,7 @@ zpool_read_label_slow(int fd, nvlist_t **config, int *num_labels) return (0); } +#endif /* APPLE */ /* * Given a file descriptor, read the label information and return an nvlist @@ -1133,6 +1143,7 @@ zpool_read_label(int fd, nvlist_t **config, int *num_labels) return (0); #endif } +#endif /* APPLE */ /* * Sorted by full path and then vdev guid to allow for multiple entries with @@ -1239,6 +1250,12 @@ zpool_find_import_scan_add_slice(libpc_handle_t *hdl, pthread_mutex_t *lock, slice->rn_lock = lock; slice->rn_avl = cache; slice->rn_hdl = hdl; +#ifdef __APPLE__ + /* Prefer diskX over rdiskX: involve os/ somehow? */ + if (name[0] == 'r') + slice->rn_order = order + IMPORT_ORDER_DEFAULT; + else +#endif slice->rn_order = order + IMPORT_ORDER_SCAN_OFFSET; slice->rn_labelpaths = B_FALSE; diff --git a/lib/libzutil/zutil_pool.c b/lib/libzutil/zutil_pool.c index 288a0033cd13..c3383442961c 100644 --- a/lib/libzutil/zutil_pool.c +++ b/lib/libzutil/zutil_pool.c @@ -28,6 +28,7 @@ #include #include #include +#include #include