Skip to content

Commit

Permalink
strip out some mac os specific stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewc12 committed Oct 22, 2023
1 parent 8e20e0f commit d6a5e49
Show file tree
Hide file tree
Showing 150 changed files with 9,564 additions and 242 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/macos-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build on macOS
on: push

jobs:
build:
runs-on: macos-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
#- name: csrutil disable
# run: |
# sudo csrutil disable
#- name: csrutil enable
# run: |
# sudo csrutil enable --without kext
#- name: spctl kext-consent disable
# run: |
# sudo spctl kext-consent disable
- name: install deps
run: |
brew install automake libtool gawk coreutils
- name: install deps
run: |
#brew install openssl@3
- name: autogen
run: |
./autogen.sh
- name: configure
run: |
#https://stackoverflow.com/a/62591864
./configure CPPFLAGS="-I/usr/local/opt/gettext/include -I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/gettext/lib/ -L/usr/local/opt/openssl/lib"
- name: build
run: |
make -j 2
#- name: install
# run: |
# sudo make install DESTDIR=///

#- name: load
# run: |
# sudo kextload -v /Library/Extensions/zfs.kext

#- name: ls
# run: |
# sudo ls -Rla
# ls -Rla
#- name: rsync
# run: |
# rsync -avx --exclude /out/ ${{github.workspace}}/ ${{github.workspace}}/out/ --no-links
#- name: Upload dev build
# uses: actions/[email protected]
# with:
# name: dev_build
# path: ${{github.workspace}}/out/*
9 changes: 8 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion cmd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ SHELLCHECKSCRIPTS += %D%/zvol_wait
include $(srcdir)/%D%/zed/Makefile.am
endif

if BUILD_MACOS
include $(srcdir)/%D%/zed/Makefile.am
include $(srcdir)/%D%/os/Makefile.am
endif

if USING_PYTHON
bin_SCRIPTS += arc_summary arcstat dbufstat zilstat
Expand All @@ -111,6 +115,5 @@ arc_summary: %D%/arc_summary
$(AM_V_at)cp $< $@
endif


PHONY += cmd
cmd: $(bin_SCRIPTS) $(bin_PROGRAMS) $(sbin_SCRIPTS) $(sbin_PROGRAMS) $(dist_bin_SCRIPTS) $(zfsexec_PROGRAMS) $(mounthelper_PROGRAMS)
16 changes: 16 additions & 0 deletions cmd/arcstat.in
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,23 @@ elif sys.platform.startswith('linux'):

name, unused, value = s.split()
kstat[name] = int(value)
elif sys.platform.startswith('darwin'):
import subprocess

def kstat_update():
global kstat

process = subprocess.Popen(['sysctl', 'kstat.zfs.misc.arcstats'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
kstats = process.communicate()[0].decode('ascii').splitlines()

kstat = {}
for l in kstats:
items = l.split(':')
name = items[0]
value = items[1].strip()
kstat[name[24:]] = int(value)

def detailed_usage():
sys.stderr.write("%s\n" % cmd)
Expand Down
2 changes: 2 additions & 0 deletions cmd/os/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

include $(srcdir)/%D%/macos/Makefile.am
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
3 changes: 3 additions & 0 deletions cmd/zed/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ zed_LDADD = \
libnvpair.la \
libuutil.la

if !BUILD_MACOS
zed_LDADD += -lrt $(LIBATOMIC_LIBS) $(LIBUDEV_LIBS) $(LIBUUID_LIBS)
endif

zed_LDFLAGS = -pthread

dist_noinst_DATA += %D%/agents/README.md
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
12 changes: 10 additions & 2 deletions cmd/zed/zed.d/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ dist_zedexec_SCRIPTS = \
%D%/resilver_finish-notify.sh \
%D%/resilver_finish-start-scrub.sh \
%D%/scrub_finish-notify.sh \
%D%/snapshot_mount.sh \
%D%/snapshot_unmount.sh \
%D%/statechange-led.sh \
%D%/statechange-notify.sh \
%D%/trim_finish-notify.sh \
%D%/vdev_attach-led.sh \
%D%/vdev_clear-led.sh
%D%/vdev_clear-led.sh \
%D%/zvol_create.sh \
%D%/zvol_remove.sh

nodist_zedexec_SCRIPTS = \
%D%/history_event-zfs-list-cacher.sh
Expand All @@ -33,10 +37,14 @@ zedconfdefaults = \
resilver_finish-notify.sh \
resilver_finish-start-scrub.sh \
scrub_finish-notify.sh \
snapshot_mount.sh \
snapshot_unmount.sh \
statechange-led.sh \
statechange-notify.sh \
vdev_attach-led.sh \
vdev_clear-led.sh
vdev_clear-led.sh \
zvol_create.sh \
zvol_remove.sh

dist_noinst_DATA += %D%/README

Expand Down
30 changes: 30 additions & 0 deletions cmd/zed/zed.d/snapshot_mount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
# shellcheck disable=SC2154
#
# Helper to mount and unmount snapshots when asked to by kernel.
#
# Mostly used in macOS.
#
set -ef

[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
. "${ZED_ZEDLET_DIR}/zed-functions.sh"

[ -n "${ZEVENT_SNAPSHOT_NAME}" ] || exit 1
[ -n "${ZEVENT_SUBCLASS}" ] || exit 2

if [ "${ZEVENT_SUBCLASS}" = "snapshot_mount" ]; then
action="mount"
elif [ "${ZEVENT_SUBCLASS}" = "snapshot_unmount" ]; then
action="unmount"
else
zed_log_err "unsupported event class \"${ZEVENT_SUBCLASS}\""
exit 3
fi

zed_exit_if_ignoring_this_event
zed_check_cmd "${ZFS}" || exit 4

"${ZFS}" "${action}" "${ZEVENT_SNAPSHOT_NAME}"

finished
1 change: 1 addition & 0 deletions cmd/zed/zed.d/snapshot_unmount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
snapshot_mount.sh
28 changes: 28 additions & 0 deletions cmd/zed/zed.d/zvol_create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
# shellcheck disable=SC2154
#
# Log the zevent via syslog.
#

# Given POOL and DATASET name for ZVOL
# DEVICE_NAME for /dev/disk*
# RAW_DEVICE_NAME for /dev/rdisk*
# Create symlink in
# /var/run/zfs/zvol/dsk/POOL/DATASET -> /dev/disk*
# /var/run/zfs/zvol/rdsk/POOL/DATASET -> /dev/rdisk*

ZVOL_ROOT="/var/run/zfs/zvol"

mkdir -p "$(dirname "${ZVOL_ROOT}/rdsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}")" "$(dirname "${ZVOL_ROOT}/dsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}")"

# Remove them if they already exist. (ln -f is not portable)
rm -f "${ZVOL_ROOT}/rdsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}" "${ZVOL_ROOT}/dsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}"

ln -s "/dev/${ZEVENT_DEVICE_NAME}" "${ZVOL_ROOT}/dsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}"
ln -s "/dev/${ZEVENT_RAW_NAME}" "${ZVOL_ROOT}/rdsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}"

logger -t "${ZED_SYSLOG_TAG:=zed}" -p "${ZED_SYSLOG_PRIORITY:=daemon.notice}" \
eid="${ZEVENT_EID}" class="${ZEVENT_SUBCLASS}" \
"${ZEVENT_POOL:+pool=$ZEVENT_POOL}/${ZEVENT_VOLUME} symlinked ${ZEVENT_DEVICE_NAME}"

echo 0
23 changes: 23 additions & 0 deletions cmd/zed/zed.d/zvol_remove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
# shellcheck disable=SC2154
#
# Log the zevent via syslog.
#

# Given POOL and DATASET name for ZVOL
# DEVICE_NAME for /dev/disk*
# RAW_DEVICE_NAME for /dev/rdisk*
# Create symlink in
# /var/run/zfs/zvol/dsk/POOL/DATASET -> /dev/disk*
# /var/run/zfs/zvol/rdsk/POOL/DATASET -> /dev/rdisk*

ZVOL_ROOT="/var/run/zfs/zvol"

rm -f "${ZVOL_ROOT}/rdsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}" "${ZVOL_ROOT}/dsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}"
rmdir "$(dirname "${ZVOL_ROOT}/rdsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}")" "$(dirname "${ZVOL_ROOT}/dsk/${ZEVENT_POOL}/${ZEVENT_VOLUME}")"

logger -t "${ZED_SYSLOG_TAG:=zed}" -p "${ZED_SYSLOG_PRIORITY:=daemon.notice}" \
eid="${ZEVENT_EID}" class="${ZEVENT_SUBCLASS}" \
"${ZEVENT_POOL:+pool=$ZEVENT_POOL}/${ZEVENT_VOLUME} removed symlink"

echo 0
4 changes: 4 additions & 0 deletions cmd/zfs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ zfs_LDADD += $(LTLIBINTL)
if BUILD_FREEBSD
zfs_LDADD += -lgeom -ljail
endif

if BUILD_MACOS
zfs_LDFLAGS = -sectcreate __TEXT __info_plist %D%/../zpool/os/macos/Info-zfs.plist
endif
58 changes: 57 additions & 1 deletion cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,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 @@ -1454,6 +1454,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 @@ -4178,6 +4181,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 @@ -7266,6 +7274,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 @@ -7283,6 +7324,7 @@ share_mount(int op, int argc, char **argv)
zfs_commit_shares(NULL);
zfs_close(zhp);
}
#endif // !APPLE
}

free(options);
Expand Down Expand Up @@ -7654,9 +7696,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
Loading

0 comments on commit d6a5e49

Please sign in to comment.