55
55
56
56
#include <libzfs.h>
57
57
#include <libzfs_core.h>
58
+ #include <sys/fs/zfs.h>
58
59
#include <sys/spa_impl.h>
59
60
#include <libnvpair.h>
60
61
#include <sys/dmu.h>
@@ -85,6 +86,22 @@ const char *PROP_JOYENT = "com.joyent.kbm:ebox";
85
86
86
87
static void usage (void );
87
88
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
+
88
105
static errf_t *
89
106
unlock_or_recover (struct ebox * ebox , const char * descr , boolean_t * recovered )
90
107
{
@@ -235,6 +252,8 @@ cmd_unlock(const char *fsname)
235
252
uint64_t kstatus ;
236
253
#endif
237
254
255
+ load_keystatus ();
256
+
238
257
ds = zfs_open (zfshdl , fsname , ZFS_TYPE_DATASET );
239
258
if (ds == NULL )
240
259
err (EXIT_ERROR , "failed to open dataset %s" , fsname );
@@ -243,9 +262,9 @@ cmd_unlock(const char *fsname)
243
262
VERIFY (props != NULL );
244
263
245
264
#if defined(DMU_OT_ENCRYPTED )
246
- kstatus = zfs_prop_get_int (ds , ZFS_PROP_KEYSTATUS );
265
+ kstatus = zfs_prop_get_int (ds , zprop_keystatus );
247
266
248
- if (kstatus == ZFS_KEYSTATUS_AVAILABLE ) {
267
+ if (kstatus == keystatus_available ) {
249
268
errx (EXIT_ALREADY_UNLOCKED , "key already loaded for %s" ,
250
269
fsname );
251
270
}
@@ -420,6 +439,8 @@ cmd_rekey(const char *fsname)
420
439
nvlist_t * nprops ;
421
440
#endif
422
441
442
+ load_keystatus ();
443
+
423
444
ds = zfs_open (zfshdl , fsname , ZFS_TYPE_DATASET );
424
445
if (ds == NULL )
425
446
err (EXIT_ERROR , "failed to open dataset %s" , fsname );
@@ -468,9 +489,9 @@ cmd_rekey(const char *fsname)
468
489
}
469
490
470
491
#if defined(DMU_OT_ENCRYPTED )
471
- kstatus = zfs_prop_get_int (ds , ZFS_PROP_KEYSTATUS );
492
+ kstatus = zfs_prop_get_int (ds , zprop_keystatus );
472
493
473
- if (kstatus != ZFS_KEYSTATUS_AVAILABLE ) {
494
+ if (kstatus != keystatus_available ) {
474
495
#endif
475
496
(void ) mlockall (MCL_CURRENT | MCL_FUTURE );
476
497
if ((error = unlock_or_recover (ebox , description , & recovered )))
@@ -480,7 +501,7 @@ cmd_rekey(const char *fsname)
480
501
481
502
#if defined(DMU_OT_ENCRYPTED )
482
503
rc = lzc_load_key (fsname , B_FALSE , (uint8_t * )key , keylen );
483
- if (rc != 0 ) {
504
+ if (rc != 0 && rc != EEXIST ) {
484
505
errno = rc ;
485
506
err (EXIT_ERROR , "failed to load key material into "
486
507
"ZFS for %s" , fsname );
0 commit comments