Skip to content

Commit d51acc9

Browse files
committed
pivy-zfs: cope with PROP_KEYSTATUS id number changing on illumos
in r151050 the zfs crypto zprops were re-numbered, so this code needs to use function calls to get the right numbers out of the library instead if we want it to work on older builds as well
1 parent 9e25e40 commit d51acc9

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

pivy-zfs.c

+26-5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
#include <libzfs.h>
5757
#include <libzfs_core.h>
58+
#include <zfs_prop.h>
5859
#include <sys/spa_impl.h>
5960
#include <libnvpair.h>
6061
#include <sys/dmu.h>
@@ -85,6 +86,22 @@ const char *PROP_JOYENT = "com.joyent.kbm:ebox";
8586

8687
static void usage(void);
8788

89+
static int zprop_keystatus;
90+
static uint64_t keystatus_available;
91+
92+
static void
93+
load_keystatus(void)
94+
{
95+
int rc;
96+
zprop_keystatus = zprop_name_to_prop("keystatus", ZFS_TYPE_DATASET);
97+
rc = zprop_string_to_index(zprop_keystatus, "available",
98+
&keystatus_available, ZFS_TYPE_DATASET);
99+
#if defined(DMU_OT_ENCRYPTED)
100+
VERIFY(zprop_keystatus != ZPROP_INVAL);
101+
VERIFY(rc != -1);
102+
#endif
103+
}
104+
88105
static errf_t *
89106
unlock_or_recover(struct ebox *ebox, const char *descr, boolean_t *recovered)
90107
{
@@ -235,6 +252,8 @@ cmd_unlock(const char *fsname)
235252
uint64_t kstatus;
236253
#endif
237254

255+
load_keystatus();
256+
238257
ds = zfs_open(zfshdl, fsname, ZFS_TYPE_DATASET);
239258
if (ds == NULL)
240259
err(EXIT_ERROR, "failed to open dataset %s", fsname);
@@ -243,9 +262,9 @@ cmd_unlock(const char *fsname)
243262
VERIFY(props != NULL);
244263

245264
#if defined(DMU_OT_ENCRYPTED)
246-
kstatus = zfs_prop_get_int(ds, ZFS_PROP_KEYSTATUS);
265+
kstatus = zfs_prop_get_int(ds, zprop_keystatus);
247266

248-
if (kstatus == ZFS_KEYSTATUS_AVAILABLE) {
267+
if (kstatus == keystatus_available) {
249268
errx(EXIT_ALREADY_UNLOCKED, "key already loaded for %s",
250269
fsname);
251270
}
@@ -420,6 +439,8 @@ cmd_rekey(const char *fsname)
420439
nvlist_t *nprops;
421440
#endif
422441

442+
load_keystatus();
443+
423444
ds = zfs_open(zfshdl, fsname, ZFS_TYPE_DATASET);
424445
if (ds == NULL)
425446
err(EXIT_ERROR, "failed to open dataset %s", fsname);
@@ -468,9 +489,9 @@ cmd_rekey(const char *fsname)
468489
}
469490

470491
#if defined(DMU_OT_ENCRYPTED)
471-
kstatus = zfs_prop_get_int(ds, ZFS_PROP_KEYSTATUS);
492+
kstatus = zfs_prop_get_int(ds, zprop_keystatus);
472493

473-
if (kstatus != ZFS_KEYSTATUS_AVAILABLE) {
494+
if (kstatus != keystatus_available) {
474495
#endif
475496
(void) mlockall(MCL_CURRENT | MCL_FUTURE);
476497
if ((error = unlock_or_recover(ebox, description, &recovered)))
@@ -480,7 +501,7 @@ cmd_rekey(const char *fsname)
480501

481502
#if defined(DMU_OT_ENCRYPTED)
482503
rc = lzc_load_key(fsname, B_FALSE, (uint8_t *)key, keylen);
483-
if (rc != 0) {
504+
if (rc != 0 && rc != EEXIST) {
484505
errno = rc;
485506
err(EXIT_ERROR, "failed to load key material into "
486507
"ZFS for %s", fsname);

0 commit comments

Comments
 (0)