@@ -881,6 +881,7 @@ static int _xattr_get_virtual(struct dentry *d, char *buf, size_t buf_size, cons
881
881
ret = _xattr_get_vendorunique_xattr (& val , name , vol );
882
882
}
883
883
} else if (! strcmp (name , "ltfs.sync" )) {
884
+ ltfs_set_commit_message_reason (SYNC_EA , vol );
884
885
ret = ltfs_sync_index (SYNC_EA , false, vol );
885
886
}
886
887
}
@@ -915,9 +916,8 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va
915
916
{
916
917
int ret = 0 ;
917
918
918
- if (! strcmp (name , "ltfs.sync" ) && d == vol -> index -> root )
919
- ret = ltfs_sync_index (SYNC_EA , false, vol );
920
- else if (! strcmp (name , "ltfs.commitMessage" ) && d == vol -> index -> root ) {
919
+ if ((! strcmp (name , "ltfs.commitMessage" ) || ! strcmp (name , "ltfs.sync" ))
920
+ && d == vol -> index -> root ) {
921
921
char * value_null_terminated , * new_value ;
922
922
923
923
if (size > INDEX_MAX_COMMENT_LEN ) {
@@ -926,38 +926,49 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va
926
926
}
927
927
928
928
ltfs_mutex_lock (& vol -> index -> dirty_lock );
929
- if (! value || ! size ) {
930
- /* Clear the current comment field */
931
- if (vol -> index -> commit_message ) {
932
- free (vol -> index -> commit_message );
933
- vol -> index -> commit_message = NULL ;
934
- }
929
+ if (! vol -> index -> dirty ) {
930
+ /* Do nothing because index is clean */
931
+ ret = 0 ;
935
932
} else {
936
- value_null_terminated = malloc (size + 1 );
937
- if (! value_null_terminated ) {
938
- ltfsmsg (LTFS_ERR , 10001E , "_xattr_set_virtual: commit_message" );
939
- ltfs_mutex_unlock (& vol -> index -> dirty_lock );
940
- return - LTFS_NO_MEMORY ;
941
- }
942
- memcpy (value_null_terminated , value , size );
943
- value_null_terminated [size ] = '\0' ;
933
+ if (! value || ! size ) {
934
+ /* Clear the current comment field */
935
+ if (vol -> index -> commit_message ) {
936
+ free (vol -> index -> commit_message );
937
+ vol -> index -> commit_message = NULL ;
938
+ }
939
+ } else {
940
+ value_null_terminated = malloc (size + 1 );
941
+ if (! value_null_terminated ) {
942
+ ltfsmsg (LTFS_ERR , 10001E , "_xattr_set_virtual: commit_message" );
943
+ ltfs_mutex_unlock (& vol -> index -> dirty_lock );
944
+ return - LTFS_NO_MEMORY ;
945
+ }
946
+ memcpy (value_null_terminated , value , size );
947
+ value_null_terminated [size ] = '\0' ;
944
948
945
- ret = pathname_format (value_null_terminated , & new_value , false, true);
946
- free (value_null_terminated );
947
- if (ret < 0 ) {
948
- ltfs_mutex_unlock (& vol -> index -> dirty_lock );
949
- return ret ;
949
+ ret = pathname_format (value_null_terminated , & new_value , false, true);
950
+ free (value_null_terminated );
951
+ if (ret < 0 ) {
952
+ /* Try to sync index even if the value is not valid */
953
+ ltfs_set_commit_message_reason_unlocked (SYNC_EA , vol );
954
+ ltfs_mutex_unlock (& vol -> index -> dirty_lock );
955
+
956
+ ret = ltfs_sync_index (SYNC_EA , false, vol );
957
+ return ret ;
958
+ }
959
+ ret = 0 ;
960
+
961
+ /* Update THE commit message in the index */
962
+ if (vol -> index -> commit_message )
963
+ free (vol -> index -> commit_message );
964
+ vol -> index -> commit_message = new_value ;
950
965
}
951
- ret = 0 ;
952
966
953
- /* Update the commit message in the index */
954
- if (vol -> index -> commit_message )
955
- free (vol -> index -> commit_message );
956
- vol -> index -> commit_message = new_value ;
967
+ ltfs_set_index_dirty (false, false, vol -> index );
957
968
}
958
969
959
- ltfs_set_index_dirty (false, false, vol -> index );
960
970
ltfs_mutex_unlock (& vol -> index -> dirty_lock );
971
+ ret = ltfs_sync_index (SYNC_EA , false, vol );
961
972
962
973
} else if (! strcmp (name , "ltfs.volumeName" ) && d == vol -> index -> root ) {
963
974
char * value_null_terminated , * new_value ;
@@ -1228,6 +1239,8 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va
1228
1239
vol -> lock_status = new ;
1229
1240
1230
1241
ltfs_set_index_dirty (false, false, vol -> index );
1242
+ ltfs_set_commit_message_reason_unlocked (SYNC_ADV_LOCK , vol );
1243
+
1231
1244
ret = ltfs_sync_index (SYNC_ADV_LOCK , false, vol );
1232
1245
ret = tape_device_lock (vol -> device );
1233
1246
if (ret < 0 ) {
@@ -1486,9 +1499,10 @@ int xattr_set(struct dentry *d, const char *name, const char *value, size_t size
1486
1499
1487
1500
releasewrite_mrsw (& d -> meta_lock );
1488
1501
1489
- if (write_idx )
1502
+ if (write_idx ) {
1503
+ ltfs_set_commit_message_reason (SYNC_EA , vol );
1490
1504
ret = ltfs_sync_index (SYNC_EA , false, vol );
1491
- else
1505
+ } else
1492
1506
ret = 0 ;
1493
1507
1494
1508
out_unlock :
0 commit comments