Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3: cmd/* and tests/* #15442

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 +14,16 @@ 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%/statechange-slot_off.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 @@ -34,11 +38,15 @@ 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 \
statechange-slot_off.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
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 @@ -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
10 changes: 10 additions & 0 deletions cmd/zpool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ zpool_SOURCES += \
%D%/os/linux/zpool_vdev_os.c
endif

if BUILD_MACOS
zpool_SOURCES += %D%/os/macos/zpool_vdev_os.c
endif

zpool_LDADD = \
libzfs.la \
libzfs_core.la \
Expand All @@ -36,6 +40,12 @@ zpool_LDADD += $(LTLIBINTL)
if BUILD_FREEBSD
zpool_LDADD += -lgeom
endif

if BUILD_MACOS
zpool_LDFLAGS = -sectcreate __TEXT __info_plist %D%/os/macos/Info-zpool.plist
zpool_LDFLAGS += -sectcreate __TEXT __entitlements %D%/os/macos/zpool-entitlements.plist
endif

zpool_LDADD += -lm $(LIBBLKID_LIBS) $(LIBUUID_LIBS)

dist_noinst_DATA += %D%/zpool.d/README
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
Empty file added tests/runfiles/darwin.run
Empty file.
Loading