Skip to content

Commit 439a110

Browse files
author
Jason King
committed
Support inheriting properties in channel programs
This adds support in channel programs to inherit properties analogous to `zfs inherit` by adding `zfs.sync.inherit` and `zfs.check.inherit` functions to the ZFS LUA API. Signed-off-by: Jason King <[email protected]>
1 parent 54c8366 commit 439a110

File tree

7 files changed

+163
-11
lines changed

7 files changed

+163
-11
lines changed

include/sys/dsl_prop.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
/*
2222
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2323
* Copyright (c) 2012 by Delphix. All rights reserved.
24+
* Copyright 2019 Joyent, Inc.
2425
*/
2526

2627
#ifndef _SYS_DSL_PROP_H
@@ -61,6 +62,12 @@ typedef struct dsl_props_arg {
6162
zprop_source_t pa_source;
6263
} dsl_props_arg_t;
6364

65+
typedef struct dsl_props_set_arg {
66+
const char *dpsa_dsname;
67+
zprop_source_t dpsa_source;
68+
nvlist_t *dpsa_props;
69+
} dsl_props_set_arg_t;
70+
6471
void dsl_prop_init(dsl_dir_t *dd);
6572
void dsl_prop_fini(dsl_dir_t *dd);
6673
int dsl_prop_register(struct dsl_dataset *ds, const char *propname,
@@ -85,6 +92,8 @@ int dsl_prop_get_dd(struct dsl_dir *dd, const char *propname,
8592
int intsz, int numints, void *buf, char *setpoint,
8693
boolean_t snapshot);
8794

95+
int dsl_props_set_check(void *arg, dmu_tx_t *tx);
96+
void dsl_props_set_sync(void *arg, dmu_tx_t *tx);
8897
void dsl_props_set_sync_impl(struct dsl_dataset *ds, zprop_source_t source,
8998
nvlist_t *props, dmu_tx_t *tx);
9099
void dsl_prop_set_sync_impl(struct dsl_dataset *ds, const char *propname,

man/man8/zfs-program.8

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
.\"
1010
.\"
1111
.\" Copyright (c) 2016, 2019 by Delphix. All Rights Reserved.
12+
.\" Copyright 2019 Joyent, Inc.
1213
.\"
13-
.Dd February 26, 2019
14+
.Dd December 5, 2019
1415
.Dt ZFS-PROGRAM 8
1516
.Os
1617
.Sh NAME
@@ -364,6 +365,23 @@ Valid only for destroying snapshots.
364365
If set to true, and the snapshot has holds or clones, allows the snapshot to be
365366
marked for deferred deletion rather than failing.
366367
.Ed
368+
.It Em zfs.sync.inherit(dataset, property)
369+
Clears the specified property in the given dataset.
370+
Returns 0 on success, or a nonzero error code if the property could not be
371+
cleared.
372+
.Pp
373+
dataset (string)
374+
.Bd -ragged -compact -offset "xxxx"
375+
Filesystem or snapshot to be destroyed.
376+
.Ed
377+
.Pp
378+
property (string)
379+
.Bd -ragged -compact -offset "xxxx"
380+
The property to clear.
381+
Allowed properties are the same as those for the
382+
.Nm zfs Cm inherit
383+
command.
384+
.Ed
367385
.It Em zfs.sync.promote(dataset)
368386
Promote the given clone to a filesystem.
369387
Returns 0 on successful promotion, or a nonzero error code otherwise.

module/zfs/dsl_prop.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2323
* Copyright (c) 2012, 2015 by Delphix. All rights reserved.
2424
* Copyright (c) 2013 Martin Matuska. All rights reserved.
25-
* Copyright 2015, Joyent, Inc.
25+
* Copyright 2019 Joyent, Inc.
2626
*/
2727

2828
#include <sys/zfs_context.h>
@@ -839,13 +839,7 @@ dsl_prop_inherit(const char *dsname, const char *propname,
839839
return (error);
840840
}
841841

842-
typedef struct dsl_props_set_arg {
843-
const char *dpsa_dsname;
844-
zprop_source_t dpsa_source;
845-
nvlist_t *dpsa_props;
846-
} dsl_props_set_arg_t;
847-
848-
static int
842+
int
849843
dsl_props_set_check(void *arg, dmu_tx_t *tx)
850844
{
851845
dsl_props_set_arg_t *dpsa = arg;
@@ -923,7 +917,7 @@ dsl_props_set_sync_impl(dsl_dataset_t *ds, zprop_source_t source,
923917
}
924918
}
925919

926-
static void
920+
void
927921
dsl_props_set_sync(void *arg, dmu_tx_t *tx)
928922
{
929923
dsl_props_set_arg_t *dpsa = arg;

module/zfs/zcp_synctask.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/*
1717
* Copyright (c) 2016, 2017 by Delphix. All rights reserved.
18+
* Copyright 2019 Joyent, Inc.
1819
*/
1920

2021
#include <sys/lua/lua.h>
@@ -35,6 +36,12 @@
3536

3637
#define DST_AVG_BLKSHIFT 14
3738

39+
typedef struct zcp_inherit_prop_arg {
40+
lua_State *zipa_state;
41+
const char *zipa_prop;
42+
dsl_props_set_arg_t zipa_dpsa;
43+
} zcp_inherit_prop_arg_t;
44+
3845
typedef int (zcp_synctask_func_t)(lua_State *, boolean_t, nvlist_t *);
3946
typedef struct zcp_synctask_info {
4047
const char *name;
@@ -275,6 +282,93 @@ zcp_synctask_snapshot(lua_State *state, boolean_t sync, nvlist_t *err_details)
275282
return (err);
276283
}
277284

285+
static int zcp_synctask_inherit_prop(lua_State *, boolean_t,
286+
nvlist_t *err_details);
287+
static zcp_synctask_info_t zcp_synctask_inherit_prop_info = {
288+
.name = "inherit",
289+
.func = zcp_synctask_inherit_prop,
290+
.space_check = ZFS_SPACE_CHECK_RESERVED,
291+
.blocks_modified = 2, /* 2 * numprops */
292+
.pargs = {
293+
{ .za_name = "dataset", .za_lua_type = LUA_TSTRING },
294+
{ .za_name = "property", .za_lua_type = LUA_TSTRING },
295+
{ NULL, 0 }
296+
},
297+
.kwargs = {
298+
{ NULL, 0 }
299+
},
300+
};
301+
302+
static int
303+
zcp_synctask_inherit_prop_check(void *arg, dmu_tx_t *tx)
304+
{
305+
zcp_inherit_prop_arg_t *args = arg;
306+
zfs_prop_t prop = zfs_name_to_prop(args->zipa_prop);
307+
int error = 0;
308+
309+
if (prop == ZPROP_INVAL) {
310+
if (zfs_prop_user(args->zipa_prop))
311+
return (0);
312+
313+
zfs_dbgmsg("Invalid property name");
314+
return (EINVAL);
315+
}
316+
317+
if (zfs_prop_readonly(prop)) {
318+
zfs_dbgmsg("Tried to set a read-only property");
319+
return (EINVAL);
320+
}
321+
322+
if (!zfs_prop_inheritable(prop)) {
323+
zfs_dbgmsg("Tried to set a non-inheritable property");
324+
return (EINVAL);
325+
}
326+
327+
if ((error = dsl_props_set_check(&args->zipa_dpsa, tx)) != 0)
328+
zfs_dbgmsg("Failed property check");
329+
330+
return (error);
331+
}
332+
333+
static void
334+
zcp_synctask_inherit_prop_sync(void *arg, dmu_tx_t *tx)
335+
{
336+
zcp_inherit_prop_arg_t *args = arg;
337+
dsl_props_set_arg_t *dpsa = &args->zipa_dpsa;
338+
339+
dsl_props_set_sync(dpsa, tx);
340+
}
341+
342+
static int
343+
zcp_synctask_inherit_prop(lua_State *state, boolean_t sync,
344+
nvlist_t *err_details)
345+
{
346+
int err;
347+
zcp_inherit_prop_arg_t zipa = { 0 };
348+
dsl_props_set_arg_t *dpsa = &zipa.zipa_dpsa;
349+
350+
const char *dsname = lua_tostring(state, 1);
351+
const char *prop = lua_tostring(state, 2);
352+
353+
zipa.zipa_state = state;
354+
zipa.zipa_prop = prop;
355+
dpsa->dpsa_dsname = dsname;
356+
dpsa->dpsa_source = ZPROP_SRC_INHERITED;
357+
dpsa->dpsa_props = fnvlist_alloc();
358+
fnvlist_add_boolean(dpsa->dpsa_props, prop);
359+
360+
zcp_cleanup_handler_t *zch = zcp_register_cleanup(state,
361+
(zcp_cleanup_t *)&fnvlist_free, dpsa->dpsa_props);
362+
363+
err = zcp_sync_task(state, zcp_synctask_inherit_prop_check,
364+
zcp_synctask_inherit_prop_sync, &zipa, sync, dsname);
365+
366+
zcp_deregister_cleanup(state, zch);
367+
fnvlist_free(dpsa->dpsa_props);
368+
369+
return (err);
370+
}
371+
278372
static int
279373
zcp_synctask_wrapper(lua_State *state)
280374
{
@@ -343,6 +437,7 @@ zcp_load_synctask_lib(lua_State *state, boolean_t sync)
343437
&zcp_synctask_promote_info,
344438
&zcp_synctask_rollback_info,
345439
&zcp_synctask_snapshot_info,
440+
&zcp_synctask_inherit_prop_info,
346441
NULL
347442
};
348443

tests/runfiles/common.run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ tags = ['functional', 'channel_program', 'lua_core']
7474
tests = ['tst.destroy_fs', 'tst.destroy_snap', 'tst.get_count_and_limit',
7575
'tst.get_index_props', 'tst.get_mountpoint', 'tst.get_neg',
7676
'tst.get_number_props', 'tst.get_string_props', 'tst.get_type',
77-
'tst.get_userquota', 'tst.get_written', 'tst.list_bookmarks',
77+
'tst.get_userquota', 'tst.get_written', 'tst.inherit', 'tst.list_bookmarks',
7878
'tst.list_children', 'tst.list_clones', 'tst.list_holds',
7979
'tst.list_snapshots', 'tst.list_system_props',
8080
'tst.list_user_props', 'tst.parse_args_neg','tst.promote_conflict',

tests/zfs-tests/tests/functional/channel_program/synctask_core/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dist_pkgdata_SCRIPTS = \
1313
tst.get_type.ksh \
1414
tst.get_userquota.ksh \
1515
tst.get_written.ksh \
16+
tst.inherit.ksh \
1617
tst.list_bookmarks.ksh \
1718
tst.list_children.ksh \
1819
tst.list_clones.ksh \
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/ksh -p
2+
#
3+
# This file and its contents are supplied under the terms of the
4+
# Common Development and Distribution License ("CDDL"), version 1.0.
5+
# You may only use this file in accordance with the terms of version
6+
# 1.0 of the CDDL.
7+
#
8+
# A full copy of the text of the CDDL should have accompanied this
9+
# source. A copy of the CDDL is also available via the Internet at
10+
# http://www.illumos.org/license/CDDL.
11+
#
12+
13+
#
14+
# Copyright 2019 Joyent, Inc.
15+
#
16+
17+
. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib
18+
19+
verify_runnable "global"
20+
21+
fs=$TESTPOOL/$TESTFS
22+
testprop="com.joyent:testprop"
23+
testval="testval"
24+
25+
log_must zfs set $testprop=$testval $fs
26+
log_must_program_sync $TESTPOOL - $fs $testprop <<-EOF
27+
arg = ...
28+
fs = arg["argv"][1]
29+
prop = arg["argv"][2]
30+
err = zfs.sync.inherit(fs, prop)
31+
msg = "resetting " .. prop .. " on " .. fs .. " err=" .. err
32+
return msg
33+
EOF
34+
35+
log_pass "Inherit/clear property with channel program works."

0 commit comments

Comments
 (0)