Skip to content

Commit

Permalink
non macos changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewc12 committed Nov 14, 2023
1 parent d70949e commit 55cc02c
Show file tree
Hide file tree
Showing 80 changed files with 999 additions and 64 deletions.
8 changes: 4 additions & 4 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2189,16 +2189,16 @@ dump_history(spa_t *spa)
if (ievent >= ZFS_NUM_LEGACY_HISTORY_EVENTS)
goto next;

(void) printf(" %s [internal %s txg:%ju] %s\n",
(void) printf(" %s [internal %s txg:%llu] %s\n",
tbuf,
zfs_history_event_names[ievent],
fnvlist_lookup_uint64(events[i],
(u_longlong_t)fnvlist_lookup_uint64(events[i],
ZPOOL_HIST_TXG),
fnvlist_lookup_string(events[i],
ZPOOL_HIST_INT_STR));
} else if (nvlist_exists(events[i], ZPOOL_HIST_INT_NAME)) {
(void) printf("%s [txg:%ju] %s", tbuf,
fnvlist_lookup_uint64(events[i],
(void) printf("%s [txg:%llu] %s", tbuf,
(u_longlong_t)fnvlist_lookup_uint64(events[i],
ZPOOL_HIST_TXG),
fnvlist_lookup_string(events[i],
ZPOOL_HIST_INT_NAME));
Expand Down
2 changes: 1 addition & 1 deletion cmd/zed/agents/fmd_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ typedef struct fmd_stat {
uint_t fmds_type; /* statistic type (see above) */
char fmds_desc[64]; /* statistic description */
union {
int bool; /* FMD_TYPE_BOOL */
int fmds_bool; /* FMD_TYPE_BOOL */
int32_t i32; /* FMD_TYPE_INT32 */
uint32_t ui32; /* FMD_TYPE_UINT32 */
int64_t i64; /* FMD_TYPE_INT64 */
Expand Down
58 changes: 57 additions & 1 deletion cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ zfs_mount_and_share(libzfs_handle_t *hdl, const char *dataset, zfs_type_t type)
} else if (zfs_share(zhp, NULL) != 0) {
(void) fprintf(stderr, gettext("filesystem "
"successfully created, but not shared\n"));
ret = 1;
ret = 0;
}
zfs_commit_shares(NULL);
}
Expand Down Expand Up @@ -1459,6 +1459,9 @@ destroy_callback(zfs_handle_t *zhp, void *data)
if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) {
cb->cb_snap_count++;
fnvlist_add_boolean(cb->cb_batchedsnaps, name);
#ifdef __APPLE__
zfs_snapshot_unmount(zhp, cb->cb_force ? MS_FORCE : 0);
#endif
if (cb->cb_snap_count % 10 == 0 && cb->cb_defer_destroy) {
error = destroy_batched(cb);
if (error != 0) {
Expand Down Expand Up @@ -4187,6 +4190,11 @@ zfs_do_rollback(int argc, char **argv)
*/
ret = zfs_rollback(zhp, snap, force);

#ifdef __APPLE__
if (ret == 0)
zfs_rollback_os(zhp);
#endif

out:
zfs_close(snap);
zfs_close(zhp);
Expand Down Expand Up @@ -7285,6 +7293,39 @@ share_mount(int op, int argc, char **argv)

(void) fclose(mnttab);
} else {
#if defined(__APPLE__)
/*
* OsX can not mount from kernel, users are expected to mount
* by hand using "zfs mount dataset@snapshot".
*/
zfs_handle_t *zhp;

if (argc > 1) {
(void) fprintf(stderr,
gettext("too many arguments\n"));
usage(B_FALSE);
}

if ((zhp = zfs_open(g_zfs, argv[0],
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT)) == NULL) {
ret = 1;
} else {

if (zfs_get_type(zhp)&ZFS_TYPE_SNAPSHOT) {

ret = zfs_snapshot_mount(zhp, options, flags);

} else {

ret = share_mount_one(zhp, op, flags,
SA_NO_PROTOCOL, B_TRUE, options);
}

zfs_close(zhp);
}

#else // APPLE

zfs_handle_t *zhp;

if (argc > 1) {
Expand All @@ -7302,6 +7343,7 @@ share_mount(int op, int argc, char **argv)
zfs_commit_shares(NULL);
zfs_close(zhp);
}
#endif // !APPLE
}

free(options);
Expand Down Expand Up @@ -7673,9 +7715,23 @@ unshare_unmount(int op, int argc, char **argv)
return (unshare_unmount_path(op, argv[0],
flags, B_FALSE));

#if defined(__APPLE__)
/* Temporarily, allow mounting snapshots on OS X */

if ((zhp = zfs_open(g_zfs, argv[0],
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT)) == NULL)
return (1);

if (zfs_get_type(zhp) & ZFS_TYPE_SNAPSHOT) {
ret = zfs_snapshot_unmount(zhp, flags);
zfs_close(zhp);
return (ret);
}
#else
if ((zhp = zfs_open(g_zfs, argv[0],
ZFS_TYPE_FILESYSTEM)) == NULL)
return (1);
#endif

verify(zfs_prop_get(zhp, op == OP_SHARE ?
ZFS_PROP_SHARENFS : ZFS_PROP_MOUNTPOINT,
Expand Down
29 changes: 27 additions & 2 deletions cmd/zpool/zpool_vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <libintl.h>
#include <libnvpair.h>
#include <libzutil.h>
Expand Down Expand Up @@ -272,6 +273,9 @@ static nvlist_t *
make_leaf_vdev(nvlist_t *props, const char *arg, boolean_t is_primary)
{
char path[MAXPATHLEN];
char *d, *b;
char *dpath;
const char *bname;
struct stat64 statbuf;
nvlist_t *vdev = NULL;
const char *type = NULL;
Expand Down Expand Up @@ -307,8 +311,29 @@ make_leaf_vdev(nvlist_t *props, const char *arg, boolean_t is_primary)
return (NULL);
}

/* After whole disk check restore original passed path */
strlcpy(path, arg, sizeof (path));
/*
* After whole disk check restore original passed path and use
* the realpath of the directory.
*/
d = strdup(arg);
b = strdup(arg);
int idx = zfs_dirnamelen(d);
if (idx != -1)
d[idx] = 0;
dpath = d;
bname = zfs_basename(b);
if (realpath(dpath, path) == NULL) {
(void) fprintf(stderr,
gettext("cannot resolve path '%s'\n"), dpath);
free(d);
free(b);
return (NULL);
}

strlcat(path, "/", sizeof (path));
strlcat(path, bname, sizeof (path));
free(d);
free(b);
} else if (zpool_is_draid_spare(arg)) {
if (!is_primary) {
(void) fprintf(stderr,
Expand Down
17 changes: 17 additions & 0 deletions include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,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
Expand Down Expand Up @@ -1040,9 +1041,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
Expand Down
4 changes: 4 additions & 0 deletions include/libzutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions include/os/freebsd/spl/sys/simd_aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
10 changes: 10 additions & 0 deletions include/os/linux/kernel/linux/simd_aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 4 additions & 0 deletions include/os/linux/zfs/sys/zfs_context_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@
#undef longjmp
#endif

#ifndef MODULE_PARAM_MAX
#define MODULE_PARAM_MAX 1024
#endif

#endif
9 changes: 8 additions & 1 deletion include/sys/abd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 *);
Expand Down Expand Up @@ -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
*/
Expand Down
3 changes: 3 additions & 0 deletions include/sys/abd_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions include/sys/asm_linkage.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

#include <sys/ia32/asm_linkage.h> /* XX64 x86/sys/asm_linkage.h */

#elif defined(__aarch64__)

#include <sys/aarch64/asm_linkage.h>

#endif

#if defined(_KERNEL) && defined(HAVE_KERNEL_OBJTOOL)
Expand Down
3 changes: 3 additions & 0 deletions include/sys/crypto/icp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
7 changes: 7 additions & 0 deletions include/sys/mntent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions include/sys/spa.h
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,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);
Expand Down
3 changes: 3 additions & 0 deletions include/sys/spa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,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
Expand Down
2 changes: 1 addition & 1 deletion include/sys/sysevent/dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions include/sys/vdev_raidz.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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_expand {
uint64_t vre_vdev_id;
Expand Down
Loading

0 comments on commit 55cc02c

Please sign in to comment.