@@ -3376,30 +3376,24 @@ created_before(libzfs_handle_t *hdl, avl_tree_t *avl,
3376
3376
*/
3377
3377
static int
3378
3378
recv_fix_encryption_hierarchy (libzfs_handle_t * hdl , const char * top_zfs ,
3379
- nvlist_t * stream_nv )
3379
+ nvlist_t * stream_nv , avl_tree_t * stream_avl )
3380
3380
{
3381
3381
int err ;
3382
- nvpair_t * fselem = NULL ;
3383
- nvlist_t * stream_fss ;
3382
+ nvpair_t * fselem = NULL , * nextfselem ;
3383
+ nvlist_t * local_nv , * stream_fss ;
3384
+ avl_tree_t * local_avl ;
3385
+ boolean_t recursive ;
3386
+ char fsname [ZFS_MAX_DATASET_NAME_LEN ], * cp ;
3384
3387
3385
- stream_fss = fnvlist_lookup_nvlist (stream_nv , "fss" );
3388
+ recursive = (nvlist_lookup_boolean (stream_nv , "not_recursive" ) ==
3389
+ ENOENT );
3386
3390
3391
+ stream_fss = fnvlist_lookup_nvlist (stream_nv , "fss" );
3387
3392
while ((fselem = nvlist_next_nvpair (stream_fss , fselem )) != NULL ) {
3388
- zfs_handle_t * zhp = NULL ;
3389
- uint64_t crypt ;
3390
- nvlist_t * snaps , * props , * stream_nvfs = NULL ;
3393
+ nvlist_t * snaps , * stream_nvfs ;
3391
3394
nvpair_t * snapel = NULL ;
3392
- boolean_t is_encroot , is_clone , stream_encroot ;
3393
- char * cp ;
3394
- const char * stream_keylocation = NULL ;
3395
- char keylocation [MAXNAMELEN ];
3396
- char fsname [ZFS_MAX_DATASET_NAME_LEN ];
3397
-
3398
- keylocation [0 ] = '\0' ;
3399
3395
stream_nvfs = fnvpair_value_nvlist (fselem );
3400
3396
snaps = fnvlist_lookup_nvlist (stream_nvfs , "snaps" );
3401
- props = fnvlist_lookup_nvlist (stream_nvfs , "props" );
3402
- stream_encroot = nvlist_exists (stream_nvfs , "is_encroot" );
3403
3397
3404
3398
/* find a snapshot from the stream that exists locally */
3405
3399
err = ENOENT ;
@@ -3413,14 +3407,40 @@ recv_fix_encryption_hierarchy(libzfs_handle_t *hdl, const char *top_zfs,
3413
3407
break ;
3414
3408
}
3415
3409
3416
- if (err != 0 )
3417
- continue ;
3410
+ if (err == 0 )
3411
+ break ;
3412
+ }
3418
3413
3419
- cp = strchr (fsname , '@' );
3420
- if (cp != NULL )
3421
- * cp = '\0' ;
3414
+ if (err != 0 )
3415
+ return (0 );
3422
3416
3423
- zhp = zfs_open (hdl , fsname , ZFS_TYPE_DATASET );
3417
+ cp = strchr (fsname , '@' );
3418
+ if (cp != NULL )
3419
+ * cp = '\0' ;
3420
+
3421
+ if ((err = gather_nvlist (hdl , fsname , NULL , NULL ,
3422
+ recursive , B_TRUE , B_FALSE , recursive , B_FALSE , B_FALSE , B_FALSE ,
3423
+ B_FALSE , B_TRUE , & local_nv , & local_avl )) != 0 )
3424
+ return (err );
3425
+
3426
+ for (fselem = nvlist_next_nvpair (local_nv , NULL ); fselem ;
3427
+ fselem = nextfselem ) {
3428
+ zfs_handle_t * zhp = NULL ;
3429
+ uint64_t crypt ;
3430
+ nvlist_t * stream_props , * snaps , * stream_nvfs = NULL ,
3431
+ * nvfs = NULL ;
3432
+ boolean_t is_encroot , is_clone , stream_encroot ;
3433
+ const char * stream_keylocation = NULL , * fs ;
3434
+ char keylocation [MAXNAMELEN ];
3435
+ nvpair_t * snapelem ;
3436
+
3437
+ nextfselem = nvlist_next_nvpair (local_nv , fselem );
3438
+
3439
+ nvfs = fnvpair_value_nvlist (fselem );
3440
+ snaps = fnvlist_lookup_nvlist (nvfs , "snaps" );
3441
+ fs = fnvlist_lookup_string (nvfs , "name" );
3442
+ (void ) printf ("fs: %s\n" , fs );
3443
+ zhp = zfs_open (hdl , fs , ZFS_TYPE_DATASET );
3424
3444
if (zhp == NULL ) {
3425
3445
err = ENOENT ;
3426
3446
goto error ;
@@ -3436,6 +3456,28 @@ recv_fix_encryption_hierarchy(libzfs_handle_t *hdl, const char *top_zfs,
3436
3456
continue ;
3437
3457
}
3438
3458
3459
+ keylocation [0 ] = '\0' ;
3460
+
3461
+ /*
3462
+ * First find the stream's fs
3463
+ */
3464
+ for (snapelem = nvlist_next_nvpair (snaps , NULL );
3465
+ snapelem ; snapelem = nvlist_next_nvpair (snaps , snapelem )) {
3466
+ uint64_t thisguid ;
3467
+
3468
+ thisguid = fnvpair_value_uint64 (snapelem );
3469
+ stream_nvfs = fsavl_find (stream_avl , thisguid , NULL );
3470
+
3471
+ if (stream_nvfs != NULL )
3472
+ break ;
3473
+ }
3474
+
3475
+ if (stream_nvfs == NULL )
3476
+ continue ;
3477
+
3478
+ stream_props = fnvlist_lookup_nvlist (stream_nvfs , "props" );
3479
+ stream_encroot = nvlist_exists (stream_nvfs , "is_encroot" );
3480
+
3439
3481
/*
3440
3482
* If the dataset is flagged as an encryption root, was not
3441
3483
* received as a clone and is not currently an encryption root,
@@ -3451,7 +3493,7 @@ recv_fix_encryption_hierarchy(libzfs_handle_t *hdl, const char *top_zfs,
3451
3493
}
3452
3494
}
3453
3495
3454
- stream_keylocation = fnvlist_lookup_string (props ,
3496
+ stream_keylocation = fnvlist_lookup_string (stream_props ,
3455
3497
zfs_prop_to_name (ZFS_PROP_KEYLOCATION ));
3456
3498
3457
3499
/*
@@ -3518,14 +3560,14 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs,
3518
3560
boolean_t needagain , progress , recursive ;
3519
3561
const char * s1 , * s2 ;
3520
3562
3563
+ if (flags -> dryrun )
3564
+ return (0 );
3565
+
3521
3566
fromsnap = fnvlist_lookup_string (stream_nv , "fromsnap" );
3522
3567
3523
3568
recursive = (nvlist_lookup_boolean (stream_nv , "not_recursive" ) ==
3524
3569
ENOENT );
3525
3570
3526
- if (flags -> dryrun )
3527
- return (0 );
3528
-
3529
3571
again :
3530
3572
needagain = progress = B_FALSE ;
3531
3573
@@ -3999,9 +4041,9 @@ zfs_receive_package(libzfs_handle_t *hdl, int fd, const char *destname,
3999
4041
stream_nv , stream_avl , NULL );
4000
4042
}
4001
4043
4002
- if (raw && softerr == 0 && * top_zfs != NULL ) {
4044
+ if (raw && softerr == 0 && * top_zfs != NULL && ! flags -> dryrun ) {
4003
4045
softerr = recv_fix_encryption_hierarchy (hdl , * top_zfs ,
4004
- stream_nv );
4046
+ stream_nv , stream_avl );
4005
4047
}
4006
4048
4007
4049
out :
0 commit comments