@@ -552,43 +552,19 @@ static struct libos_encrypted_volume* get_volume(const char* mount_point_path) {
552
552
return NULL ;
553
553
}
554
554
555
- static struct libos_encrypted_volume * get_or_create_volume (const char * mount_point_path ,
556
- bool * out_created ) {
557
- assert (locked (& g_volumes_lock ));
558
-
559
- struct libos_encrypted_volume * volume = get_volume (mount_point_path );
560
- if (volume ) {
561
- * out_created = false;
562
- return volume ;
563
- }
555
+ int register_encrypted_volume (struct libos_encrypted_volume * volume ) {
556
+ assert (volume && volume -> mount_point_path );
564
557
565
- volume = calloc (1 , sizeof (* volume ));
566
- if (!volume )
567
- return NULL ;
568
- volume -> mount_point_path = strdup (mount_point_path );
569
- if (!volume -> mount_point_path ) {
570
- free (volume );
571
- return NULL ;
572
- }
573
- LISTP_ADD_TAIL (volume , & g_volumes , list );
574
- * out_created = true;
575
- return volume ;
576
- }
577
-
578
- int get_or_create_encrypted_volume (const char * mount_point_path ,
579
- struct libos_encrypted_volume * * out_volume , bool * out_created ) {
580
558
lock (& g_volumes_lock );
581
559
582
- int ret ;
560
+ int ret = 0 ;
583
561
584
- struct libos_encrypted_volume * volume = get_or_create_volume ( mount_point_path , out_created );
585
- if (! volume ) {
586
- ret = - ENOMEM ;
562
+ struct libos_encrypted_volume * existing_volume = get_volume ( volume -> mount_point_path );
563
+ if (existing_volume ) {
564
+ ret = - EEXIST ;
587
565
goto out ;
588
566
}
589
-
590
- * out_volume = volume ;
591
- ret = 0 ;
567
+ LISTP_ADD_TAIL (volume , & g_volumes , list );
592
568
out :
593
569
unlock (& g_volumes_lock );
594
570
return ret ;
@@ -983,7 +959,9 @@ BEGIN_RS_FUNC(encrypted_files_key) {
983
959
}
984
960
END_RS_FUNC (encrypted_files_key )
985
961
986
- /* Checkpoint the `g_volumes` list. */
962
+ /* Checkpoint the `g_volumes` list. Note we only call this to checkpoint all volumes. The list
963
+ * itself is not checkpointed (and hence also no corresponding restore function). The list is
964
+ * reconstructed in the restore function of the volumes itself. */
987
965
BEGIN_CP_FUNC (all_encrypted_volumes ) {
988
966
__UNUSED (size );
989
967
__UNUSED (obj );
@@ -1005,44 +983,55 @@ BEGIN_CP_FUNC(encrypted_volume) {
1005
983
struct libos_encrypted_volume * volume = obj ;
1006
984
struct libos_encrypted_volume * new_volume = NULL ;
1007
985
1008
- size_t off = ADD_CP_OFFSET (sizeof (struct libos_encrypted_volume ));
1009
-
1010
- new_volume = (struct libos_encrypted_volume * )(base + off );
1011
-
1012
- // TODO (MST): do something with remaining fields of struct
1013
- log_debug ("CP(encrypted_volume): protection_mode=%d file_state_mape=%p" ,
1014
- volume -> protection_mode , volume -> files_state_map ); // TODO (MST): DEBUG
1015
- // - protection_mode -> automatically copied
1016
- // - files_state_map
1017
- // - files_state_map_lock
1018
-
1019
- lock (& g_keys_lock );
1020
- DO_CP_MEMBER (encrypted_files_key , volume , new_volume , key );
1021
- unlock (& g_keys_lock );
1022
-
1023
- ADD_CP_FUNC_ENTRY (off );
986
+ size_t off = GET_FROM_CP_MAP (obj );
987
+ if (!off ) { /* We haven't already checkpointed this volume */
988
+ off = ADD_CP_OFFSET (sizeof (struct libos_encrypted_volume ));
989
+ ADD_TO_CP_MAP (obj , off );
990
+ new_volume = (struct libos_encrypted_volume * )(base + off );
991
+
992
+ log_debug ("CP(encrypted_volume): mount_point_path=%s protection_mode=%d file_state_mape=%p" ,
993
+ volume -> mount_point_path , volume -> protection_mode ,
994
+ volume -> files_state_map ); // TODO (MST): DEBUG
995
+ DO_CP_MEMBER (str , volume , new_volume , mount_point_path );
996
+ new_volume -> protection_mode = volume -> protection_mode ;
997
+ lock (& volume -> files_state_map_lock );
998
+ // - files_state_map -> TODO (MST): Serialize me
999
+ unlock (& volume -> files_state_map_lock );
1000
+ // files_state_map_lock has no check point, it will be recreated in restore
1001
+ lock (& g_keys_lock );
1002
+ DO_CP_MEMBER (encrypted_files_key , volume , new_volume , key );
1003
+ unlock (& g_keys_lock );
1004
+ INIT_LIST_HEAD (new_volume , list );
1024
1005
1006
+ ADD_CP_FUNC_ENTRY (off );
1007
+ } else {
1008
+ new_volume = (struct libos_encrypted_volume * )(base + off );
1009
+ }
1025
1010
if (objp )
1026
1011
* objp = (void * )new_volume ;
1027
1012
}
1028
1013
END_CP_FUNC (encrypted_volume )
1029
1014
1030
1015
// TODO (MST): revisit below, probably not correct?!
1031
1016
BEGIN_RS_FUNC (encrypted_volume ) {
1032
- struct libos_encrypted_volume * volume = (void * )(base + GET_CP_FUNC_ENTRY ());
1033
1017
__UNUSED (offset );
1018
+ struct libos_encrypted_volume * migrated_volume = (void * )(base + GET_CP_FUNC_ENTRY ());
1019
+
1020
+ CP_REBASE (migrated_volume -> mount_point_path );
1034
1021
1035
- // TODO (MST): do something with remaining fields of struct
1036
- log_debug ("RS(encrypted_volume): protection_mode=%d file_state_mape=%p" ,
1037
- volume -> protection_mode , volume -> files_state_map ); // TODO (MST): DEBUG
1038
- // - protection_mode -> automatically copied
1039
- // - files_state_map
1040
- // - files_state_map_lock
1041
- if (!create_lock (& volume -> files_state_map_lock )) {
1022
+ /* protection_mode needs no restore action */
1023
+ // files_state_map: TODO (MST): deserialize me
1024
+ if (!create_lock (& migrated_volume -> files_state_map_lock )) {
1042
1025
return - ENOMEM ;
1043
1026
}
1027
+ CP_REBASE (migrated_volume -> key );
1028
+ log_debug ("RS(encrypted_volume): mount_point_path=%s protection_mode=%d file_state_mape=%p" ,
1029
+ migrated_volume -> mount_point_path , migrated_volume -> protection_mode ,
1030
+ migrated_volume -> files_state_map ); // TODO (MST): DEBUG
1044
1031
1045
- CP_REBASE (volume -> key );
1032
+ int ret = register_encrypted_volume (migrated_volume );
1033
+ if (ret < 0 )
1034
+ return ret ;
1046
1035
}
1047
1036
END_RS_FUNC (encrypted_volume )
1048
1037
0 commit comments