@@ -881,6 +881,7 @@ static int _xattr_get_virtual(struct dentry *d, char *buf, size_t buf_size, cons
881881 ret = _xattr_get_vendorunique_xattr (& val , name , vol );
882882 }
883883 } else if (! strcmp (name , "ltfs.sync" )) {
884+ ltfs_set_commit_message_reason (SYNC_EA , vol );
884885 ret = ltfs_sync_index (SYNC_EA , false, vol );
885886 }
886887 }
@@ -915,9 +916,8 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va
915916{
916917 int ret = 0 ;
917918
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 ) {
921921 char * value_null_terminated , * new_value ;
922922
923923 if (size > INDEX_MAX_COMMENT_LEN ) {
@@ -926,38 +926,49 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va
926926 }
927927
928928 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 ;
935932 } 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' ;
944948
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 ;
950965 }
951- ret = 0 ;
952966
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 );
957968 }
958969
959- ltfs_set_index_dirty (false, false, vol -> index );
960970 ltfs_mutex_unlock (& vol -> index -> dirty_lock );
971+ ret = ltfs_sync_index (SYNC_EA , false, vol );
961972
962973 } else if (! strcmp (name , "ltfs.volumeName" ) && d == vol -> index -> root ) {
963974 char * value_null_terminated , * new_value ;
@@ -1228,6 +1239,8 @@ static int _xattr_set_virtual(struct dentry *d, const char *name, const char *va
12281239 vol -> lock_status = new ;
12291240
12301241 ltfs_set_index_dirty (false, false, vol -> index );
1242+ ltfs_set_commit_message_reason_unlocked (SYNC_ADV_LOCK , vol );
1243+
12311244 ret = ltfs_sync_index (SYNC_ADV_LOCK , false, vol );
12321245 ret = tape_device_lock (vol -> device );
12331246 if (ret < 0 ) {
@@ -1486,9 +1499,10 @@ int xattr_set(struct dentry *d, const char *name, const char *value, size_t size
14861499
14871500 releasewrite_mrsw (& d -> meta_lock );
14881501
1489- if (write_idx )
1502+ if (write_idx ) {
1503+ ltfs_set_commit_message_reason (SYNC_EA , vol );
14901504 ret = ltfs_sync_index (SYNC_EA , false, vol );
1491- else
1505+ } else
14921506 ret = 0 ;
14931507
14941508out_unlock :
0 commit comments