[Midnightbsd-cvs] src [8827] trunk/sys/cddl/contrib/opensolaris: add the feature flags code for lz4 compression (we already had lz4 backported to zpool 28
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Sep 25 23:54:40 EDT 2016
Revision: 8827
http://svnweb.midnightbsd.org/src/?rev=8827
Author: laffer1
Date: 2016-09-25 23:54:40 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
add the feature flags code for lz4 compression (we already had lz4 backported to zpool 28
Modified Paths:
--------------
trunk/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c
trunk/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h
trunk/sys/cddl/contrib/opensolaris/uts/common/Makefile.files
trunk/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c
Modified: trunk/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c
===================================================================
--- trunk/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c 2016-09-26 03:53:19 UTC (rev 8826)
+++ trunk/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c 2016-09-26 03:54:40 UTC (rev 8827)
@@ -21,6 +21,7 @@
/*
* Copyright (c) 2012 by Delphix. All rights reserved.
+ * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
*/
#ifdef _KERNEL
@@ -155,4 +156,7 @@
zfeature_register(SPA_FEATURE_EMPTY_BPOBJ,
"com.delphix:empty_bpobj", "empty_bpobj",
"Snapshots use less space.", B_TRUE, B_FALSE, NULL);
+ zfeature_register(SPA_FEATURE_LZ4_COMPRESS,
+ "org.illumos:lz4_compress", "lz4_compress",
+ "LZ4 compression algorithm support.", B_FALSE, B_FALSE, NULL);
}
Modified: trunk/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h
===================================================================
--- trunk/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h 2016-09-26 03:53:19 UTC (rev 8826)
+++ trunk/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h 2016-09-26 03:54:40 UTC (rev 8827)
@@ -21,6 +21,7 @@
/*
* Copyright (c) 2012 by Delphix. All rights reserved.
+ * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
*/
#ifndef _ZFEATURE_COMMON_H
@@ -51,6 +52,7 @@
static enum spa_feature {
SPA_FEATURE_ASYNC_DESTROY,
SPA_FEATURE_EMPTY_BPOBJ,
+ SPA_FEATURE_LZ4_COMPRESS,
SPA_FEATURES
} spa_feature_t;
Modified: trunk/sys/cddl/contrib/opensolaris/uts/common/Makefile.files
===================================================================
--- trunk/sys/cddl/contrib/opensolaris/uts/common/Makefile.files 2016-09-26 03:53:19 UTC (rev 8826)
+++ trunk/sys/cddl/contrib/opensolaris/uts/common/Makefile.files 2016-09-26 03:54:40 UTC (rev 8827)
@@ -22,6 +22,7 @@
#
# Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
#
#
# This Makefile defines all file modules for the directory uts/common
Modified: trunk/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c
===================================================================
--- trunk/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c 2016-09-26 03:53:19 UTC (rev 8826)
+++ trunk/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c 2016-09-26 03:54:40 UTC (rev 8827)
@@ -27,6 +27,7 @@
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
+ * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
*/
#include <sys/types.h>
@@ -75,6 +76,7 @@
#include <sys/zvol.h>
#include <sys/dsl_scan.h>
#include <sys/dmu_objset.h>
+#include <sys/zfeature.h>
#include "zfs_namecheck.h"
#include "zfs_prop.h"
@@ -131,6 +133,12 @@
static void zfsdev_close(void *data);
+static int zfs_prop_activate_feature(dsl_pool_t *dp, zfeature_info_t *feature);
+static int zfs_prop_activate_feature_check(void *arg1, void *arg2,
+ dmu_tx_t *tx);
+static void zfs_prop_activate_feature_sync(void *arg1, void *arg2,
+ dmu_tx_t *tx);
+
/* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
void
__dprintf(const char *file, const char *func, int line, const char *fmt, ...)
@@ -2245,7 +2253,41 @@
}
break;
}
+ case ZFS_PROP_COMPRESSION:
+ {
+ if (intval == ZIO_COMPRESS_LZ4) {
+ zfeature_info_t *feature =
+ &spa_feature_table[SPA_FEATURE_LZ4_COMPRESS];
+ spa_t *spa;
+ dsl_pool_t *dp;
+ if ((err = spa_open(dsname, &spa, FTAG)) != 0)
+ return (err);
+
+ dp = spa->spa_dsl_pool;
+
+ /*
+ * Setting the LZ4 compression algorithm activates
+ * the feature.
+ */
+ if (!spa_feature_is_active(spa, feature)) {
+ if ((err = zfs_prop_activate_feature(dp,
+ feature)) != 0) {
+ spa_close(spa, FTAG);
+ return (err);
+ }
+ }
+
+ spa_close(spa, FTAG);
+ }
+ /*
+ * We still want the default set action to be performed in the
+ * caller, we only performed zfeature settings here.
+ */
+ err = -1;
+ break;
+ }
+
default:
err = -1;
}
@@ -3462,6 +3504,22 @@
SPA_VERSION_ZLE_COMPRESSION))
return (ENOTSUP);
+ if (intval == ZIO_COMPRESS_LZ4) {
+ zfeature_info_t *feature =
+ &spa_feature_table[
+ SPA_FEATURE_LZ4_COMPRESS];
+ spa_t *spa;
+
+ if ((err = spa_open(dsname, &spa, FTAG)) != 0)
+ return (err);
+
+ if (!spa_feature_is_enabled(spa, feature)) {
+ spa_close(spa, FTAG);
+ return (ENOTSUP);
+ }
+ spa_close(spa, FTAG);
+ }
+
/*
* If this is a bootable dataset then
* verify that the compression algorithm
@@ -3506,6 +3564,56 @@
}
/*
+ * Activates a feature on a pool in response to a property setting. This
+ * creates a new sync task which modifies the pool to reflect the feature
+ * as being active.
+ */
+static int
+zfs_prop_activate_feature(dsl_pool_t *dp, zfeature_info_t *feature)
+{
+ int err;
+
+ /* EBUSY here indicates that the feature is already active */
+ err = dsl_sync_task_do(dp, zfs_prop_activate_feature_check,
+ zfs_prop_activate_feature_sync, dp->dp_spa, feature, 2);
+
+ if (err != 0 && err != EBUSY)
+ return (err);
+ else
+ return (0);
+}
+
+/*
+ * Checks for a race condition to make sure we don't increment a feature flag
+ * multiple times.
+ */
+/*ARGSUSED*/
+static int
+zfs_prop_activate_feature_check(void *arg1, void *arg2, dmu_tx_t *tx)
+{
+ spa_t *spa = arg1;
+ zfeature_info_t *feature = arg2;
+
+ if (!spa_feature_is_active(spa, feature))
+ return (0);
+ else
+ return (EBUSY);
+}
+
+/*
+ * The callback invoked on feature activation in the sync task caused by
+ * zfs_prop_activate_feature.
+ */
+static void
+zfs_prop_activate_feature_sync(void *arg1, void *arg2, dmu_tx_t *tx)
+{
+ spa_t *spa = arg1;
+ zfeature_info_t *feature = arg2;
+
+ spa_feature_incr(spa, feature, tx);
+}
+
+/*
* Removes properties from the given props list that fail permission checks
* needed to clear them and to restore them in case of a receive error. For each
* property, make sure we have both set and inherit permissions.
More information about the Midnightbsd-cvs
mailing list