diff options
author | Paul Dagnelie <[email protected]> | 2019-06-19 09:48:13 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2019-06-19 09:48:12 -0700 |
commit | 30af21b02569ac192f52ce6e6511015f8a8d5729 (patch) | |
tree | e5f1091c2d3a6e511bbd2414782e490c18e0f59c /cmd | |
parent | c1b5801bb5af0055e5f3d263beaa07026103e212 (diff) |
Implement Redacted Send/Receive
Redacted send/receive allows users to send subsets of their data to
a target system. One possible use case for this feature is to not
transmit sensitive information to a data warehousing, test/dev, or
analytics environment. Another is to save space by not replicating
unimportant data within a given dataset, for example in backup tools
like zrepl.
Redacted send/receive is a three-stage process. First, a clone (or
clones) is made of the snapshot to be sent to the target. In this
clone (or clones), all unnecessary or unwanted data is removed or
modified. This clone is then snapshotted to create the "redaction
snapshot" (or snapshots). Second, the new zfs redact command is used
to create a redaction bookmark. The redaction bookmark stores the
list of blocks in a snapshot that were modified by the redaction
snapshot(s). Finally, the redaction bookmark is passed as a parameter
to zfs send. When sending to the snapshot that was redacted, the
redaction bookmark is used to filter out blocks that contain sensitive
or unwanted information, and those blocks are not included in the send
stream. When sending from the redaction bookmark, the blocks it
contains are considered as candidate blocks in addition to those
blocks in the destination snapshot that were modified since the
creation_txg of the redaction bookmark. This step is necessary to
allow the target to rehydrate data in the case where some blocks are
accidentally or unnecessarily modified in the redaction snapshot.
The changes to bookmarks to enable fast space estimation involve
adding deadlists to bookmarks. There is also logic to manage the
life cycles of these deadlists.
The new size estimation process operates in cases where previously
an accurate estimate could not be provided. In those cases, a send
is performed where no data blocks are read, reducing the runtime
significantly and providing a byte-accurate size estimate.
Reviewed-by: Dan Kimmel <[email protected]>
Reviewed-by: Matt Ahrens <[email protected]>
Reviewed-by: Prashanth Sreenivasa <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: George Wilson <[email protected]>
Reviewed-by: Chris Williamson <[email protected]>
Reviewed-by: Pavel Zhakarov <[email protected]>
Reviewed-by: Sebastien Roy <[email protected]>
Reviewed-by: Prakash Surya <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Paul Dagnelie <[email protected]>
Closes #7958
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/zdb/zdb.c | 282 | ||||
-rw-r--r-- | cmd/zfs/zfs_main.c | 194 | ||||
-rw-r--r-- | cmd/zstreamdump/zstreamdump.c | 16 |
3 files changed, 434 insertions, 58 deletions
diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 4b07cdb8e..3194fd082 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -50,11 +50,13 @@ #include <sys/dsl_dir.h> #include <sys/dsl_dataset.h> #include <sys/dsl_pool.h> +#include <sys/dsl_bookmark.h> #include <sys/dbuf.h> #include <sys/zil.h> #include <sys/zil_impl.h> #include <sys/stat.h> #include <sys/resource.h> +#include <sys/dmu_send.h> #include <sys/dmu_traverse.h> #include <sys/zio_checksum.h> #include <sys/zio_compress.h> @@ -143,6 +145,7 @@ usage(void) "\t\t[<poolname> [<object> ...]]\n" "\t%s [-AdiPv] [-e [-V] [-p <path> ...]] [-U <cache>] <dataset>\n" "\t\t[<object> ...]\n" + "\t%s [-v] <bookmark>\n" "\t%s -C [-A] [-U <cache>]\n" "\t%s -l [-Aqu] <device>\n" "\t%s -m [-AFLPX] [-e [-V] [-p <path> ...]] [-t <txg>] " @@ -154,7 +157,7 @@ usage(void) "\t%s -S [-AP] [-e [-V] [-p <path> ...]] [-U <cache>] " "<poolname>\n\n", cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, - cmdname, cmdname); + cmdname, cmdname, cmdname); (void) fprintf(stderr, " Dataset name must include at least one " "separator character '/' or '@'\n"); @@ -420,6 +423,43 @@ dump_uint8(objset_t *os, uint64_t object, void *data, size_t size) static void dump_uint64(objset_t *os, uint64_t object, void *data, size_t size) { + uint64_t *arr; + + if (dump_opt['d'] < 6) + return; + if (data == NULL) { + dmu_object_info_t doi; + + VERIFY0(dmu_object_info(os, object, &doi)); + size = doi.doi_max_offset; + arr = kmem_alloc(size, KM_SLEEP); + + int err = dmu_read(os, object, 0, size, arr, 0); + if (err != 0) { + (void) printf("got error %u from dmu_read\n", err); + kmem_free(arr, size); + return; + } + } else { + arr = data; + } + + if (size == 0) { + (void) printf("\t\t[]\n"); + return; + } + + (void) printf("\t\t[%0llx", (u_longlong_t)arr[0]); + for (size_t i = 1; i * sizeof (uint64_t) < size; i++) { + if (i % 4 != 0) + (void) printf(", %0llx", (u_longlong_t)arr[i]); + else + (void) printf(",\n\t\t%0llx", (u_longlong_t)arr[i]); + } + (void) printf("]\n"); + + if (data == NULL) + kmem_free(arr, size); } /*ARGSUSED*/ @@ -1498,6 +1538,7 @@ visit_indirect(spa_t *spa, const dnode_phys_t *dnp, int epb = BP_GET_LSIZE(bp) >> SPA_BLKPTRSHIFT; arc_buf_t *buf; uint64_t fill = 0; + ASSERT(!BP_IS_REDACTED(bp)); err = arc_read(NULL, spa, bp, arc_getbuf_func, &buf, ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, zb); @@ -1784,6 +1825,128 @@ dump_full_bpobj(bpobj_t *bpo, const char *name, int indent) } } +static int +dump_bookmark(dsl_pool_t *dp, char *name, boolean_t print_redact, + boolean_t print_list) +{ + int err = 0; + zfs_bookmark_phys_t prop; + objset_t *mos = dp->dp_spa->spa_meta_objset; + err = dsl_bookmark_lookup(dp, name, NULL, &prop); + + if (err != 0) { + return (err); + } + + (void) printf("\t#%s: ", strchr(name, '#') + 1); + (void) printf("{guid: %llx creation_txg: %llu creation_time: " + "%llu redaction_obj: %llu}\n", (u_longlong_t)prop.zbm_guid, + (u_longlong_t)prop.zbm_creation_txg, + (u_longlong_t)prop.zbm_creation_time, + (u_longlong_t)prop.zbm_redaction_obj); + + IMPLY(print_list, print_redact); + if (!print_redact || prop.zbm_redaction_obj == 0) + return (0); + + redaction_list_t *rl; + VERIFY0(dsl_redaction_list_hold_obj(dp, + prop.zbm_redaction_obj, FTAG, &rl)); + + redaction_list_phys_t *rlp = rl->rl_phys; + (void) printf("\tRedacted:\n\t\tProgress: "); + if (rlp->rlp_last_object != UINT64_MAX || + rlp->rlp_last_blkid != UINT64_MAX) { + (void) printf("%llu %llu (incomplete)\n", + (u_longlong_t)rlp->rlp_last_object, + (u_longlong_t)rlp->rlp_last_blkid); + } else { + (void) printf("complete\n"); + } + (void) printf("\t\tSnapshots: ["); + for (unsigned int i = 0; i < rlp->rlp_num_snaps; i++) { + if (i > 0) + (void) printf(", "); + (void) printf("%0llu", + (u_longlong_t)rlp->rlp_snaps[i]); + } + (void) printf("]\n\t\tLength: %llu\n", + (u_longlong_t)rlp->rlp_num_entries); + + if (!print_list) { + dsl_redaction_list_rele(rl, FTAG); + return (0); + } + + if (rlp->rlp_num_entries == 0) { + dsl_redaction_list_rele(rl, FTAG); + (void) printf("\t\tRedaction List: []\n\n"); + return (0); + } + + redact_block_phys_t *rbp_buf; + uint64_t size; + dmu_object_info_t doi; + + VERIFY0(dmu_object_info(mos, prop.zbm_redaction_obj, &doi)); + size = doi.doi_max_offset; + rbp_buf = kmem_alloc(size, KM_SLEEP); + + err = dmu_read(mos, prop.zbm_redaction_obj, 0, size, + rbp_buf, 0); + if (err != 0) { + dsl_redaction_list_rele(rl, FTAG); + kmem_free(rbp_buf, size); + return (err); + } + + (void) printf("\t\tRedaction List: [{object: %llx, offset: " + "%llx, blksz: %x, count: %llx}", + (u_longlong_t)rbp_buf[0].rbp_object, + (u_longlong_t)rbp_buf[0].rbp_blkid, + (uint_t)(redact_block_get_size(&rbp_buf[0])), + (u_longlong_t)redact_block_get_count(&rbp_buf[0])); + + for (size_t i = 1; i < rlp->rlp_num_entries; i++) { + (void) printf(",\n\t\t{object: %llx, offset: %llx, " + "blksz: %x, count: %llx}", + (u_longlong_t)rbp_buf[i].rbp_object, + (u_longlong_t)rbp_buf[i].rbp_blkid, + (uint_t)(redact_block_get_size(&rbp_buf[i])), + (u_longlong_t)redact_block_get_count(&rbp_buf[i])); + } + dsl_redaction_list_rele(rl, FTAG); + kmem_free(rbp_buf, size); + (void) printf("]\n\n"); + return (0); +} + +static void +dump_bookmarks(objset_t *os, int verbosity) +{ + zap_cursor_t zc; + zap_attribute_t attr; + dsl_dataset_t *ds = dmu_objset_ds(os); + dsl_pool_t *dp = spa_get_dsl(os->os_spa); + objset_t *mos = os->os_spa->spa_meta_objset; + if (verbosity < 4) + return; + dsl_pool_config_enter(dp, FTAG); + + for (zap_cursor_init(&zc, mos, ds->ds_bookmarks_obj); + zap_cursor_retrieve(&zc, &attr) == 0; + zap_cursor_advance(&zc)) { + char osname[ZFS_MAX_DATASET_NAME_LEN]; + char buf[ZFS_MAX_DATASET_NAME_LEN]; + dmu_objset_name(os, osname); + VERIFY0(snprintf(buf, sizeof (buf), "%s#%s", osname, + attr.za_name)); + (void) dump_bookmark(dp, buf, verbosity >= 5, verbosity >= 6); + } + zap_cursor_fini(&zc); + dsl_pool_config_exit(dp, FTAG); +} + static void bpobj_count_refd(bpobj_t *bpo) { @@ -1886,19 +2049,26 @@ static objset_t *sa_os = NULL; static sa_attr_type_t *sa_attr_table = NULL; static int -open_objset(const char *path, dmu_objset_type_t type, void *tag, objset_t **osp) +open_objset(const char *path, void *tag, objset_t **osp) { int err; uint64_t sa_attrs = 0; uint64_t version = 0; VERIFY3P(sa_os, ==, NULL); - err = dmu_objset_own(path, type, B_TRUE, B_FALSE, tag, osp); + /* + * We can't own an objset if it's redacted. Therefore, we do this + * dance: hold the objset, then acquire a long hold on its dataset, then + * release the pool (which is held as part of holding the objset). + */ + err = dmu_objset_hold(path, tag, osp); if (err != 0) { - (void) fprintf(stderr, "failed to own dataset '%s': %s\n", path, - strerror(err)); + (void) fprintf(stderr, "failed to hold dataset '%s': %s\n", + path, strerror(err)); return (err); } + dsl_dataset_long_hold(dmu_objset_ds(*osp), tag); + dsl_pool_rele(dmu_objset_pool(*osp), tag); if (dmu_objset_type(*osp) == DMU_OST_ZFS && !(*osp)->os_encrypted) { (void) zap_lookup(*osp, MASTER_NODE_OBJ, ZPL_VERSION_STR, @@ -1912,7 +2082,8 @@ open_objset(const char *path, dmu_objset_type_t type, void *tag, objset_t **osp) if (err != 0) { (void) fprintf(stderr, "sa_setup failed: %s\n", strerror(err)); - dmu_objset_disown(*osp, B_FALSE, tag); + dsl_dataset_long_rele(dmu_objset_ds(*osp), tag); + dsl_dataset_rele(dmu_objset_ds(*osp), tag); *osp = NULL; } } @@ -1927,7 +2098,8 @@ close_objset(objset_t *os, void *tag) VERIFY3P(os, ==, sa_os); if (os->os_sa != NULL) sa_tear_down(os); - dmu_objset_disown(os, B_FALSE, tag); + dsl_dataset_long_rele(dmu_objset_ds(os), tag); + dsl_dataset_rele(dmu_objset_ds(os), tag); sa_attr_table = NULL; sa_os = NULL; } @@ -2205,8 +2377,8 @@ static object_viewer_t *object_viewer[DMU_OT_NUMTYPES + 1] = { }; static void -dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header, - uint64_t *dnode_slots_used) +dump_object(objset_t *os, uint64_t object, int verbosity, + boolean_t *print_header, uint64_t *dnode_slots_used) { dmu_buf_t *db = NULL; dmu_object_info_t doi; @@ -2325,7 +2497,7 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header, (void) printf("\t\t(object encrypted)\n"); } - *print_header = 1; + *print_header = B_TRUE; } if (verbosity >= 5) @@ -2396,6 +2568,7 @@ count_ds_mos_objects(dsl_dataset_t *ds) mos_obj_refd(dsl_dataset_phys(ds)->ds_props_obj); mos_obj_refd(dsl_dataset_phys(ds)->ds_userrefs_obj); mos_obj_refd(dsl_dataset_phys(ds)->ds_snapnames_zapobj); + mos_obj_refd(ds->ds_bookmarks_obj); if (!dsl_dataset_is_snapshot(ds)) { count_dir_mos_objects(ds->ds_dir); @@ -2416,7 +2589,7 @@ dump_dir(objset_t *os) char osname[ZFS_MAX_DATASET_NAME_LEN]; const char *type = "UNKNOWN"; int verbosity = dump_opt['d']; - int print_header = 1; + boolean_t print_header; unsigned i; int error; uint64_t total_slots_used = 0; @@ -2430,6 +2603,8 @@ dump_dir(objset_t *os) dmu_objset_fast_stat(os, &dds); dsl_pool_config_exit(dmu_objset_pool(os), FTAG); + print_header = B_TRUE; + if (dds.dds_type < DMU_OST_NUMTYPES) type = objset_types[dds.dds_type]; @@ -2464,9 +2639,10 @@ dump_dir(objset_t *os) (dds.dds_inconsistent) ? " (inconsistent)" : ""); if (zopt_objects != 0) { - for (i = 0; i < zopt_objects; i++) + for (i = 0; i < zopt_objects; i++) { dump_object(os, zopt_object[i], verbosity, &print_header, NULL); + } (void) printf("\n"); return; } @@ -2485,6 +2661,9 @@ dump_dir(objset_t *os) count_ds_mos_objects(ds); } + if (dmu_objset_ds(os) != NULL) + dump_bookmarks(os, verbosity); + if (verbosity < 2) return; @@ -2962,7 +3141,7 @@ static int dump_path_impl(objset_t *os, uint64_t obj, char *name) { int err; - int header = 1; + boolean_t header = B_TRUE; uint64_t child_obj; char *s; dmu_buf_t *db; @@ -3033,7 +3212,7 @@ dump_path(char *ds, char *path) objset_t *os; uint64_t root_obj; - err = open_objset(ds, DMU_OST_ZFS, FTAG, &os); + err = open_objset(ds, FTAG, &os); if (err != 0) return (err); @@ -3041,7 +3220,7 @@ dump_path(char *ds, char *path) if (err != 0) { (void) fprintf(stderr, "can't lookup root znode: %s\n", strerror(err)); - dmu_objset_disown(os, B_FALSE, FTAG); + close_objset(os, FTAG); return (EINVAL); } @@ -3222,6 +3401,7 @@ dump_label(const char *dev) } static uint64_t dataset_feature_count[SPA_FEATURES]; +static uint64_t global_feature_count[SPA_FEATURES]; static uint64_t remap_deadlist_count = 0; /*ARGSUSED*/ @@ -3232,7 +3412,7 @@ dump_one_dir(const char *dsname, void *arg) objset_t *os; spa_feature_t f; - error = open_objset(dsname, DMU_OST_ANY, FTAG, &os); + error = open_objset(dsname, FTAG, &os); if (error != 0) return (0); @@ -3248,6 +3428,16 @@ dump_one_dir(const char *dsname, void *arg) remap_deadlist_count++; } + for (dsl_bookmark_node_t *dbn = + avl_first(&dmu_objset_ds(os)->ds_bookmarks); dbn != NULL; + dbn = AVL_NEXT(&dmu_objset_ds(os)->ds_bookmarks, dbn)) { + mos_obj_refd(dbn->dbn_phys.zbm_redaction_obj); + if (dbn->dbn_phys.zbm_redaction_obj != 0) + global_feature_count[SPA_FEATURE_REDACTION_BOOKMARKS]++; + if (dbn->dbn_phys.zbm_flags & ZBM_FLAG_HAS_FBN) + global_feature_count[SPA_FEATURE_BOOKMARK_WRITTEN]++; + } + dump_dir(os); close_objset(os, FTAG); fuid_table_destroy(); @@ -3484,7 +3674,7 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp, dmu_object_type_t type; boolean_t is_metadata; - if (bp == NULL) + if (zb->zb_level == ZB_DNODE_LEVEL) return (0); if (dump_opt['b'] >= 5 && bp->blk_birth > 0) { @@ -3499,7 +3689,7 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp, blkbuf); } - if (BP_IS_HOLE(bp)) + if (BP_IS_HOLE(bp) || BP_IS_REDACTED(bp)) return (0); type = BP_GET_TYPE(bp); @@ -4545,7 +4735,8 @@ zdb_ddt_add_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp, avl_index_t where; zdb_ddt_entry_t *zdde, zdde_search; - if (bp == NULL || BP_IS_HOLE(bp) || BP_IS_EMBEDDED(bp)) + if (zb->zb_level == ZB_DNODE_LEVEL || BP_IS_HOLE(bp) || + BP_IS_EMBEDDED(bp)) return (0); if (dump_opt['S'] > 1 && zb->zb_level == ZB_ROOT_LEVEL) { @@ -5381,6 +5572,12 @@ dump_zpool(spa_t *spa) } dump_dtl(spa->spa_root_vdev, 0); } + + for (spa_feature_t f = 0; f < SPA_FEATURES; f++) + global_feature_count[f] = UINT64_MAX; + global_feature_count[SPA_FEATURE_REDACTION_BOOKMARKS] = 0; + global_feature_count[SPA_FEATURE_BOOKMARK_WRITTEN] = 0; + (void) dmu_objset_find(spa_name(spa), dump_one_dir, NULL, DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN); @@ -5390,21 +5587,31 @@ dump_zpool(spa_t *spa) for (f = 0; f < SPA_FEATURES; f++) { uint64_t refcount; + uint64_t *arr; if (!(spa_feature_table[f].fi_flags & - ZFEATURE_FLAG_PER_DATASET) || - !spa_feature_is_enabled(spa, f)) { - ASSERT0(dataset_feature_count[f]); - continue; + ZFEATURE_FLAG_PER_DATASET)) { + if (global_feature_count[f] == UINT64_MAX) + continue; + if (!spa_feature_is_enabled(spa, f)) { + ASSERT0(global_feature_count[f]); + continue; + } + arr = global_feature_count; + } else { + if (!spa_feature_is_enabled(spa, f)) { + ASSERT0(dataset_feature_count[f]); + continue; + } + arr = dataset_feature_count; } if (feature_get_refcount(spa, &spa_feature_table[f], &refcount) == ENOTSUP) continue; - if (dataset_feature_count[f] != refcount) { + if (arr[f] != refcount) { (void) printf("%s feature refcount mismatch: " - "%lld datasets != %lld refcount\n", + "%lld consumers != %lld refcount\n", spa_feature_table[f].fi_uname, - (longlong_t)dataset_feature_count[f], - (longlong_t)refcount); + (longlong_t)arr[f], (longlong_t)refcount); rc = 2; } else { (void) printf("Verified %s feature refcount " @@ -6184,9 +6391,23 @@ main(int argc, char **argv) FTAG, policy, NULL); } } + } else if (strpbrk(target, "#") != NULL) { + dsl_pool_t *dp; + error = dsl_pool_hold(target, FTAG, &dp); + if (error != 0) { + fatal("can't dump '%s': %s", target, + strerror(error)); + } + error = dump_bookmark(dp, target, B_TRUE, verbose > 1); + dsl_pool_rele(dp, FTAG); + if (error != 0) { + fatal("can't dump '%s': %s", target, + strerror(error)); + } + return (error); } else { zdb_set_skip_mmp(target); - error = open_objset(target, DMU_OST_ANY, FTAG, &os); + error = open_objset(target, FTAG, &os); if (error == 0) spa = dmu_objset_spa(os); } @@ -6245,10 +6466,11 @@ main(int argc, char **argv) free(checkpoint_target); } - if (os != NULL) + if (os != NULL) { close_objset(os, FTAG); - else + } else { spa_close(spa, FTAG); + } fuid_table_destroy(); diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 214a437c5..9f34cc2f8 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -33,6 +33,7 @@ #include <assert.h> #include <ctype.h> +#include <sys/debug.h> #include <errno.h> #include <getopt.h> #include <libgen.h> @@ -119,6 +120,7 @@ static int zfs_do_unload_key(int argc, char **argv); static int zfs_do_change_key(int argc, char **argv); static int zfs_do_project(int argc, char **argv); static int zfs_do_version(int argc, char **argv); +static int zfs_do_redact(int argc, char **argv); /* * Enable a reasonable set of defaults for libumem debugging on DEBUG builds. @@ -173,7 +175,8 @@ typedef enum { HELP_LOAD_KEY, HELP_UNLOAD_KEY, HELP_CHANGE_KEY, - HELP_VERSION + HELP_VERSION, + HELP_REDACT, } zfs_help_t; typedef struct zfs_command { @@ -238,6 +241,7 @@ static zfs_command_t command_table[] = { { "load-key", zfs_do_load_key, HELP_LOAD_KEY }, { "unload-key", zfs_do_unload_key, HELP_UNLOAD_KEY }, { "change-key", zfs_do_change_key, HELP_CHANGE_KEY }, + { "redact", zfs_do_redact, HELP_REDACT }, }; #define NCOMMAND (sizeof (command_table) / sizeof (command_table[0])) @@ -279,7 +283,7 @@ get_usage(zfs_help_t idx) "[filesystem|volume|snapshot] ...\n")); case HELP_MOUNT: return (gettext("\tmount\n" - "\tmount [-lvO] [-o opts] <-a | filesystem>\n")); + "\tmount [-flvO] [-o opts] <-a | filesystem>\n")); case HELP_PROMOTE: return (gettext("\tpromote <clone-filesystem>\n")); case HELP_RECEIVE: @@ -302,6 +306,9 @@ get_usage(zfs_help_t idx) "<snapshot>\n" "\tsend [-nvPLecw] [-i snapshot|bookmark] " "<filesystem|volume|snapshot>\n" + "[-i bookmark] <snapshot> <bookmark_name>\n" + "\tsend [-DnPpvLecr] [-i bookmark|snapshot] " + "--redact <bookmark> <snapshot>\n" "\tsend [-nvPe] -t <receive_resume_token>\n")); case HELP_SET: return (gettext("\tset <property=value> ... " @@ -386,6 +393,9 @@ get_usage(zfs_help_t idx) "\tchange-key -i [-l] <filesystem|volume>\n")); case HELP_VERSION: return (gettext("\tversion\n")); + case HELP_REDACT: + return (gettext("\tredact <snapshot> <bookmark> " + "<redaction_snapshot> ...")); } abort(); @@ -543,6 +553,8 @@ usage(boolean_t requested) (void) fprintf(fp, "YES NO <size> | none\n"); (void) fprintf(fp, "\t%-15s ", "written@<snap>"); (void) fprintf(fp, " NO NO <size>\n"); + (void) fprintf(fp, "\t%-15s ", "written#<bookmark>"); + (void) fprintf(fp, " NO NO <size>\n"); (void) fprintf(fp, gettext("\nSizes are specified in bytes " "with standard units such as K, M, G, etc.\n")); @@ -1501,6 +1513,13 @@ zfs_do_destroy(int argc, char **argv) return (-1); } + /* + * Unfortunately, zfs_bookmark() doesn't honor the + * casesensitivity setting. However, we can't simply + * remove this check, because lzc_destroy_bookmarks() + * ignores non-existent bookmarks, so this is necessary + * to get a proper error message. + */ if (!zfs_bookmark_exists(argv[0])) { (void) fprintf(stderr, gettext("bookmark '%s' " "does not exist.\n"), argv[0]); @@ -3595,6 +3614,73 @@ zfs_do_promote(int argc, char **argv) return (ret); } +static int +zfs_do_redact(int argc, char **argv) +{ + char *snap = NULL; + char *bookname = NULL; + char **rsnaps = NULL; + int numrsnaps = 0; + argv++; + argc--; + if (argc < 3) { + (void) fprintf(stderr, gettext("too few arguments")); + usage(B_FALSE); + } + + snap = argv[0]; + bookname = argv[1]; + rsnaps = argv + 2; + numrsnaps = argc - 2; + + nvlist_t *rsnapnv = fnvlist_alloc(); + + for (int i = 0; i < numrsnaps; i++) { + fnvlist_add_boolean(rsnapnv, rsnaps[i]); + } + + int err = lzc_redact(snap, bookname, rsnapnv); + fnvlist_free(rsnapnv); + + switch (err) { + case 0: + break; + case ENOENT: + (void) fprintf(stderr, + gettext("provided snapshot %s does not exist"), snap); + break; + case EEXIST: + (void) fprintf(stderr, gettext("specified redaction bookmark " + "(%s) provided already exists"), bookname); + break; + case ENAMETOOLONG: + (void) fprintf(stderr, gettext("provided bookmark name cannot " + "be used, final name would be too long")); + break; + case E2BIG: + (void) fprintf(stderr, gettext("too many redaction snapshots " + "specified")); + break; + case EINVAL: + (void) fprintf(stderr, gettext("redaction snapshot must be " + "descendent of snapshot being redacted")); + break; + case EALREADY: + (void) fprintf(stderr, gettext("attempted to redact redacted " + "dataset or with respect to redacted dataset")); + break; + case ENOTSUP: + (void) fprintf(stderr, gettext("redaction bookmarks feature " + "not enabled")); + break; + default: + (void) fprintf(stderr, gettext("internal error: %s"), + strerror(errno)); + } + + return (err); +} + /* * zfs rollback [-rRf] <snapshot> * @@ -4006,6 +4092,7 @@ usage: return (-1); } + /* * Send a backup stream to stdout. */ @@ -4020,10 +4107,11 @@ zfs_do_send(int argc, char **argv) sendflags_t flags = { 0 }; int c, err; nvlist_t *dbgnv = NULL; - boolean_t extraverbose = B_FALSE; + char *redactbook = NULL; struct option long_options[] = { {"replicate", no_argument, NULL, 'R'}, + {"redact", required_argument, NULL, 'd'}, {"props", no_argument, NULL, 'p'}, {"parsable", no_argument, NULL, 'P'}, {"dedup", no_argument, NULL, 'D'}, @@ -4040,8 +4128,8 @@ zfs_do_send(int argc, char **argv) }; /* check options */ - while ((c = getopt_long(argc, argv, ":i:I:RDpvnPLeht:cwb", long_options, - NULL)) != -1) { + while ((c = getopt_long(argc, argv, ":i:I:RDpvnPLeht:cwbd:", + long_options, NULL)) != -1) { switch (c) { case 'i': if (fromname) @@ -4057,6 +4145,9 @@ zfs_do_send(int argc, char **argv) case 'R': flags.replicate = B_TRUE; break; + case 'd': + redactbook = optarg; + break; case 'p': flags.props = B_TRUE; break; @@ -4068,12 +4159,9 @@ zfs_do_send(int argc, char **argv) break; case 'P': flags.parsable = B_TRUE; - flags.verbose = B_TRUE; break; case 'v': - if (flags.verbose) - extraverbose = B_TRUE; - flags.verbose = B_TRUE; + flags.verbosity++; flags.progress = B_TRUE; break; case 'D': @@ -4141,19 +4229,22 @@ zfs_do_send(int argc, char **argv) } } + if (flags.parsable && flags.verbosity == 0) + flags.verbosity = 1; + argc -= optind; argv += optind; if (resume_token != NULL) { if (fromname != NULL || flags.replicate || flags.props || - flags.backup || flags.dedup) { + flags.backup || flags.dedup || flags.holds || + redactbook != NULL) { (void) fprintf(stderr, gettext("invalid flags combined with -t\n")); usage(B_FALSE); } - if (argc != 0) { - (void) fprintf(stderr, gettext("no additional " - "arguments are permitted with -t\n")); + if (argc > 0) { + (void) fprintf(stderr, gettext("too many arguments\n")); usage(B_FALSE); } } else { @@ -4168,6 +4259,12 @@ zfs_do_send(int argc, char **argv) } } + if (flags.raw && redactbook != NULL) { + (void) fprintf(stderr, + gettext("Error: raw sends may not be redacted.\n")); + return (1); + } + if (!flags.dryrun && isatty(STDOUT_FILENO)) { (void) fprintf(stderr, gettext("Error: Stream can not be written to a terminal.\n" @@ -4181,43 +4278,70 @@ zfs_do_send(int argc, char **argv) } /* - * Special case sending a filesystem, or from a bookmark. + * For everything except -R and -I, use the new, cleaner code path. */ - if (strchr(argv[0], '@') == NULL || - (fromname && strchr(fromname, '#') != NULL)) { + if (!(flags.replicate || flags.doall)) { char frombuf[ZFS_MAX_DATASET_NAME_LEN]; - if (flags.replicate || flags.doall || flags.props || - flags.backup || flags.dedup || flags.holds || - (strchr(argv[0], '@') == NULL && - (flags.dryrun || flags.verbose || flags.progress))) { - (void) fprintf(stderr, gettext("Error: " - "Unsupported flag with filesystem or bookmark.\n")); - return (1); + if (redactbook != NULL) { + if (strchr(argv[0], '@') == NULL) { + (void) fprintf(stderr, gettext("Error: Cannot " + "do a redacted send to a filesystem.\n")); + return (1); + } } zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_DATASET); if (zhp == NULL) return (1); + if (fromname != NULL && (strchr(fromname, '#') == NULL && + strchr(fromname, '@') == NULL)) { + /* + * Neither bookmark or snapshot was specified. Print a + * warning, and assume snapshot. + */ + (void) fprintf(stderr, "Warning: incremental source " + "didn't specify type, assuming snapshot. Use '@' " + "or '#' prefix to avoid ambiguity.\n"); + (void) snprintf(frombuf, sizeof (frombuf), "@%s", + fromname); + fromname = frombuf; + } if (fromname != NULL && (fromname[0] == '#' || fromname[0] == '@')) { /* * Incremental source name begins with # or @. * Default to same fs as target. */ + char tmpbuf[ZFS_MAX_DATASET_NAME_LEN]; + (void) strlcpy(tmpbuf, fromname, sizeof (tmpbuf)); (void) strlcpy(frombuf, argv[0], sizeof (frombuf)); cp = strchr(frombuf, '@'); if (cp != NULL) *cp = '\0'; - (void) strlcat(frombuf, fromname, sizeof (frombuf)); + (void) strlcat(frombuf, tmpbuf, sizeof (frombuf)); fromname = frombuf; } - err = zfs_send_one(zhp, fromname, STDOUT_FILENO, flags); + err = zfs_send_one(zhp, fromname, STDOUT_FILENO, &flags, + redactbook); zfs_close(zhp); return (err != 0); } + if (fromname != NULL && strchr(fromname, '#')) { + (void) fprintf(stderr, + gettext("Error: multiple snapshots cannot be " + "sent from a bookmark.\n")); + return (1); + } + + if (redactbook != NULL) { + (void) fprintf(stderr, gettext("Error: multiple snapshots " + "cannot be sent redacted.\n")); + return (1); + } + cp = strchr(argv[0], '@'); *cp = '\0'; toname = cp + 1; @@ -4261,9 +4385,9 @@ zfs_do_send(int argc, char **argv) flags.doall = B_TRUE; err = zfs_send(zhp, fromname, toname, &flags, STDOUT_FILENO, NULL, 0, - extraverbose ? &dbgnv : NULL); + flags.verbosity >= 3 ? &dbgnv : NULL); - if (extraverbose && dbgnv != NULL) { + if (flags.verbosity >= 3 && dbgnv != NULL) { /* * dump_nvlist prints to stdout, but that's been * redirected to a file. Make it print to stderr @@ -6379,6 +6503,17 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol, return (1); } + if (zfs_prop_get_int(zhp, ZFS_PROP_REDACTED) && !(flags & MS_FORCE)) { + if (!explicit) + return (0); + + (void) fprintf(stderr, gettext("cannot %s '%s': " + "Dataset is not complete, was created by receiving " + "a redacted zfs send stream.\n"), cmdname, + zfs_get_name(zhp)); + return (1); + } + /* * At this point, we have verified that the mountpoint and/or * shareopts are appropriate for auto management. If the @@ -6537,7 +6672,7 @@ share_mount(int op, int argc, char **argv) int flags = 0; /* check options */ - while ((c = getopt(argc, argv, op == OP_MOUNT ? ":alvo:O" : "al")) + while ((c = getopt(argc, argv, op == OP_MOUNT ? ":alvo:Of" : "al")) != -1) { switch (c) { case 'a': @@ -6565,6 +6700,9 @@ share_mount(int op, int argc, char **argv) case 'O': flags |= MS_OVERLAY; break; + case 'f': + flags |= MS_FORCE; + break; case ':': (void) fprintf(stderr, gettext("missing argument for " "'%c' option\n"), optopt); diff --git a/cmd/zstreamdump/zstreamdump.c b/cmd/zstreamdump/zstreamdump.c index a162eceda..ae8e5bf66 100644 --- a/cmd/zstreamdump/zstreamdump.c +++ b/cmd/zstreamdump/zstreamdump.c @@ -236,6 +236,7 @@ main(int argc, char *argv[]) struct drr_spill *drrs = &thedrr.drr_u.drr_spill; struct drr_write_embedded *drrwe = &thedrr.drr_u.drr_write_embedded; struct drr_object_range *drror = &thedrr.drr_u.drr_object_range; + struct drr_redact *drrr = &thedrr.drr_u.drr_redact; struct drr_checksum *drrc = &thedrr.drr_u.drr_checksum; int c; boolean_t verbose = B_FALSE; @@ -711,6 +712,21 @@ main(int argc, char *argv[]) mac); } break; + case DRR_REDACT: + if (do_byteswap) { + drrr->drr_object = BSWAP_64(drrr->drr_object); + drrr->drr_offset = BSWAP_64(drrr->drr_offset); + drrr->drr_length = BSWAP_64(drrr->drr_length); + drrr->drr_toguid = BSWAP_64(drrr->drr_toguid); + } + if (verbose) { + (void) printf("REDACT object = %llu offset = " + "%llu length = %llu\n", + (u_longlong_t)drrr->drr_object, + (u_longlong_t)drrr->drr_offset, + (u_longlong_t)drrr->drr_length); + } + break; case DRR_NUMTYPES: /* should never be reached */ exit(1); |