Skip to content

Commit

Permalink
Native data and metadata encryption for zfs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Caputi authored and lundman committed Apr 25, 2017
1 parent 2c9df17 commit 762989c
Show file tree
Hide file tree
Showing 135 changed files with 13,710 additions and 976 deletions.
3 changes: 2 additions & 1 deletion usr/src/cmd/mdb/intel/amd64/libzpool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ MODSRCS_DIR = ../../../common/modules/zfs
GENUNIX_DIR = ../../../common/modules/genunix

CPPFLAGS += -I../../../../../lib/libzpool/common \
-I../../../../../uts/common/fs/zfs
-I../../../../../uts/common/fs/zfs \
-I../../../../../common/zfs

C99MODE= -xc99=%all
C99LMODE= -Xc99=%all
Expand Down
3 changes: 2 additions & 1 deletion usr/src/cmd/mdb/intel/amd64/zfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ include ../../Makefile.amd64
include ../../../Makefile.module
include ../../../common/modules/zfs/Makefile.zfs

CPPFLAGS += -I../../../../../uts/common/fs/zfs
CPPFLAGS += -I../../../../../uts/common/fs/zfs \
-I../../../../../common/zfs

C99MODE= -xc99=%all
C99LMODE= -Xc99=%all
Expand Down
3 changes: 2 additions & 1 deletion usr/src/cmd/mdb/intel/ia32/libzpool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ MODSRCS_DIR = ../../../common/modules/zfs
GENUNIX_DIR = ../../../common/modules/genunix

CPPFLAGS += -I../../../../../lib/libzpool/common \
-I../../../../../uts/common/fs/zfs
-I../../../../../uts/common/fs/zfs \
-I../../../../../common/zfs

C99MODE= -xc99=%all
C99LMODE= -Xc99=%all
Expand Down
3 changes: 2 additions & 1 deletion usr/src/cmd/mdb/intel/ia32/zfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ include ../../Makefile.ia32
include ../../../Makefile.module
include ../../../common/modules/zfs/Makefile.zfs

CPPFLAGS += -I../../../../../uts/common/fs/zfs
CPPFLAGS += -I../../../../../uts/common/fs/zfs \
-I../../../../../common/zfs

C99MODE= -xc99=%all
C99LMODE= -Xc99=%all
Expand Down
3 changes: 2 additions & 1 deletion usr/src/cmd/mdb/sparc/v7/libzpool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ MODSRCS_DIR = ../../../common/modules/zfs
GENUNIX_DIR = ../../../common/modules/genunix

CPPFLAGS += -I../../../../../lib/libzpool/common \
-I../../../../../uts/common/fs/zfs
-I../../../../../uts/common/fs/zfs \
-I../../../../../common/zfs

C99MODE= -xc99=%all
C99LMODE= -Xc99=%all
Expand Down
3 changes: 2 additions & 1 deletion usr/src/cmd/mdb/sparc/v9/libzpool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ MODSRCS_DIR = ../../../common/modules/zfs
GENUNIX_DIR = ../../../common/modules/genunix

CPPFLAGS += -I../../../../../lib/libzpool/common \
-I../../../../../uts/common/fs/zfs
-I../../../../../uts/common/fs/zfs \
-I../../../../../common/zfs

C99MODE= -xc99=%all
C99LMODE= -Xc99=%all
Expand Down
3 changes: 3 additions & 0 deletions usr/src/cmd/zdb/Makefile.com
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ LINTFLAGS64 += -xerroff=E_NAME_DEF_NOT_USED2
LINTFLAGS += -erroff=E_STATIC_UNUSED
LINTFLAGS64 += -erroff=E_STATIC_UNUSED

LINTFLAGS += -erroff=E_BAD_PTR_CAST_ALIGN
LINTFLAGS64 += -erroff=E_BAD_PTR_CAST_ALIGN

.KEEP_STATE:

all: $(PROG)
Expand Down
77 changes: 57 additions & 20 deletions usr/src/cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include <sys/ddt.h>
#include <sys/zfeature.h>
#include <sys/abd.h>
#include <sys/dsl_crypt.h>
#include <zfs_comutil.h>
#undef verify
#include <libzfs.h>
Expand Down Expand Up @@ -1598,7 +1599,7 @@ open_objset(const char *path, dmu_objset_type_t type, void *tag, objset_t **osp)
uint64_t version = 0;

VERIFY3P(sa_os, ==, NULL);
err = dmu_objset_own(path, type, B_TRUE, tag, osp);
err = dmu_objset_own(path, type, B_TRUE, B_FALSE, tag, osp);
if (err != 0) {
(void) fprintf(stderr, "failed to own dataset '%s': %s\n", path,
strerror(err));
Expand All @@ -1617,7 +1618,7 @@ 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, tag);
dmu_objset_disown(*osp, B_FALSE, tag);
*osp = NULL;
}
}
Expand All @@ -1632,7 +1633,7 @@ close_objset(objset_t *os, void *tag)
VERIFY3P(os, ==, sa_os);
if (os->os_sa != NULL)
sa_tear_down(os);
dmu_objset_disown(os, tag);
dmu_objset_disown(os, B_FALSE, tag);
sa_attr_table = NULL;
sa_os = NULL;
}
Expand Down Expand Up @@ -1785,6 +1786,7 @@ dump_dmu_objset(objset_t *os, uint64_t object, void *data, size_t size)
{
}


static object_viewer_t *object_viewer[DMU_OT_NUMTYPES + 1] = {
dump_none, /* unallocated */
dump_zap, /* object directory */
Expand Down Expand Up @@ -1849,6 +1851,7 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header)
dmu_buf_t *db = NULL;
dmu_object_info_t doi;
dnode_t *dn;
boolean_t dnode_held = B_FALSE;
void *bonus = NULL;
size_t bsize = 0;
char iblk[32], dblk[32], lsize[32], asize[32], fill[32];
Expand All @@ -1865,16 +1868,33 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header)

if (object == 0) {
dn = DMU_META_DNODE(os);
dmu_object_info_from_dnode(dn, &doi);
} else {
error = dmu_bonus_hold(os, object, FTAG, &db);
/*
* Encrypted datasets will have sensitive bonus buffers
* encrypted. Therefore we cannot hold the bonus buffer and
* must hold the dnode itself instead.
*/
error = dmu_object_info(os, object, &doi);
if (error)
fatal("dmu_bonus_hold(%llu) failed, errno %u",
object, error);
bonus = db->db_data;
bsize = db->db_size;
dn = DB_DNODE((dmu_buf_impl_t *)db);
fatal("dmu_object_info() failed, errno %u", error);

if (os->os_encrypted &&
DMU_OT_IS_ENCRYPTED(doi.doi_bonus_type)) {
error = dnode_hold(os, object, FTAG, &dn);
if (error)
fatal("dnode_hold() failed, errno %u", error);
dnode_held = B_TRUE;
} else {
error = dmu_bonus_hold(os, object, FTAG, &db);
if (error)
fatal("dmu_bonus_hold(%llu) failed, errno %u",
object, error);
bonus = db->db_data;
bsize = db->db_size;
dn = DB_DNODE((dmu_buf_impl_t *)db);
}
}
dmu_object_info_from_dnode(dn, &doi);

zdb_nicenum(doi.doi_metadata_block_size, iblk);
zdb_nicenum(doi.doi_data_block_size, dblk);
Expand Down Expand Up @@ -1918,9 +1938,20 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header)
(void) printf("\tdnode maxblkid: %llu\n",
(longlong_t)dn->dn_phys->dn_maxblkid);

object_viewer[ZDB_OT_TYPE(doi.doi_bonus_type)](os, object,
bonus, bsize);
object_viewer[ZDB_OT_TYPE(doi.doi_type)](os, object, NULL, 0);
if (!dnode_held) {
object_viewer[ZDB_OT_TYPE(doi.doi_bonus_type)](os,
object, bonus, bsize);
} else {
(void) printf("\t\t(bonus encrypted)\n");
}

if (!os->os_encrypted || !DMU_OT_IS_ENCRYPTED(doi.doi_type)) {
object_viewer[ZDB_OT_TYPE(doi.doi_type)](os, object,
NULL, 0);
} else {
(void) printf("\t\t(object encrypted)\n");
}

*print_header = 1;
}

Expand Down Expand Up @@ -1962,6 +1993,8 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header)

if (db != NULL)
dmu_buf_rele(db, FTAG);
if (dnode_held)
dnode_rele(dn, FTAG);
}

static char *objset_types[DMU_OST_NUMTYPES] = {
Expand Down Expand Up @@ -2265,7 +2298,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, FTAG);
dmu_objset_disown(os, B_FALSE, FTAG);
return (EINVAL);
}

Expand Down Expand Up @@ -2376,9 +2409,11 @@ dump_one_dir(const char *dsname, void *arg)
int error;
objset_t *os;

error = open_objset(dsname, DMU_OST_ANY, FTAG, &os);
if (error != 0)
error = dmu_objset_own(dsname, DMU_OST_ANY, B_TRUE, B_FALSE, FTAG, &os);
if (error != 0) {
(void) printf("Could not open %s, error %d\n", dsname, error);
return (0);
}

for (spa_feature_t f = 0; f < SPA_FEATURES; f++) {
if (!dmu_objset_ds(os)->ds_feature_inuse[f])
Expand Down Expand Up @@ -2833,7 +2868,8 @@ dump_block_stats(spa_t *spa)
zdb_cb_t zcb = { 0 };
zdb_blkstats_t *zb, *tzb;
uint64_t norm_alloc, norm_space, total_alloc, total_found;
int flags = TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA | TRAVERSE_HARD;
int flags = TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA |
TRAVERSE_NO_DECRYPT | TRAVERSE_HARD;
boolean_t leaks = B_FALSE;

(void) printf("\nTraversing all blocks %s%s%s%s%s...\n\n",
Expand Down Expand Up @@ -3132,8 +3168,8 @@ dump_simulated_ddt(spa_t *spa)

spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER);

(void) traverse_pool(spa, 0, TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA,
zdb_ddt_add_cb, &t);
(void) traverse_pool(spa, 0, TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA |
TRAVERSE_NO_DECRYPT, zdb_ddt_add_cb, &t);

spa_config_exit(spa, SCL_CONFIG, FTAG);

Expand Down Expand Up @@ -3960,7 +3996,8 @@ main(int argc, char **argv)
}
}
} else {
error = open_objset(target, DMU_OST_ANY, FTAG, &os);
error = dmu_objset_own(target, DMU_OST_ANY,
B_TRUE, B_FALSE, FTAG, &os);
}
}
nvlist_free(policy);
Expand Down
11 changes: 8 additions & 3 deletions usr/src/cmd/zdb/zdb_il.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,13 @@ print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
(u_longlong_t)lr->lrc_txg,
(u_longlong_t)lr->lrc_seq);

if (txtype && verbose >= 3)
zil_rec_info[txtype].zri_print(zilog, txtype, lr);
if (txtype && verbose >= 3) {
if (!zilog->zl_os->os_encrypted) {
zil_rec_info[txtype].zri_print(zilog, txtype, lr);
} else {
(void) printf("%s(encrypted)\n", prefix);
}
}

zil_rec_info[txtype].zri_count++;
zil_rec_info[0].zri_count++;
Expand Down Expand Up @@ -394,7 +399,7 @@ dump_intent_log(zilog_t *zilog)
if (verbose >= 2) {
(void) printf("\n");
(void) zil_parse(zilog, print_log_block, print_log_record, NULL,
zh->zh_claim_txg);
zh->zh_claim_txg, B_FALSE);
print_log_stats(verbose);
}
}
Loading

0 comments on commit 762989c

Please sign in to comment.