Skip to content

Commit 3ab66c5

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 339c829 commit 3ab66c5

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
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 <sys/fs/zfs.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 = zfs_name_to_prop("keystatus");
97+
rc = zfs_prop_string_to_index(zprop_keystatus, "available",
98+
&keystatus_available);
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);

slot-spec.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ slotspec_clear_all(struct slotspec *spec)
8484
}
8585

8686

87-
#line 88 "slot-spec.c"
87+
#line 83 "slot-spec.c"
8888
static const char _slotspec_actions[] = {
8989
0, 1, 3, 1, 6, 2, 0, 3,
9090
2, 2, 5, 2, 4, 5, 2, 6,
@@ -179,14 +179,14 @@ slotspec_parse_pe(struct slotspec *spec, const char *p, const char *pe)
179179
int cs;
180180

181181

182-
#line 183 "slot-spec.c"
182+
#line 174 "slot-spec.c"
183183
{
184184
cs = slotspec_start;
185185
}
186186

187187
#line 150 "slot-spec.rl"
188188

189-
#line 190 "slot-spec.c"
189+
#line 177 "slot-spec.c"
190190
{
191191
int _klen;
192192
unsigned int _trans;
@@ -325,7 +325,7 @@ slotspec_parse_pe(struct slotspec *spec, const char *p, const char *pe)
325325
"(expected '!' and then a slot)", p - 1));
326326
}
327327
break;
328-
#line 329 "slot-spec.c"
328+
#line 307 "slot-spec.c"
329329
}
330330
}
331331

@@ -398,7 +398,7 @@ slotspec_parse_pe(struct slotspec *spec, const char *p, const char *pe)
398398
"(expected '!' and then a slot)", p - 1));
399399
}
400400
break;
401-
#line 402 "slot-spec.c"
401+
#line 373 "slot-spec.c"
402402
}
403403
}
404404
}

0 commit comments

Comments
 (0)