@@ -686,7 +686,9 @@ static gchar* fs_mount (const gchar *device, gchar *fstype, gboolean read_only,
686686 ret = bd_fs_mount (device , mountpoint , fstype , read_only ? "nosuid,nodev,ro" : "nosuid,nodev" , NULL , & l_error );
687687 if (!ret ) {
688688 g_propagate_prefixed_error (error , l_error , "Failed to mount '%s': " , device );
689- g_rmdir (mountpoint );
689+ if (g_rmdir (mountpoint ) != 0 )
690+ bd_utils_log_format (BD_UTILS_LOG_INFO , "Failed to remove temporary mountpoint '%s'" ,
691+ mountpoint );
690692 g_free (mountpoint );
691693 return NULL ;
692694 } else
@@ -703,6 +705,26 @@ static gchar* fs_mount (const gchar *device, gchar *fstype, gboolean read_only,
703705 return mountpoint ;
704706}
705707
708+ static gboolean fs_unmount (const gchar * device , const gchar * mountpoint , const gchar * operation , GError * * error ) {
709+ gboolean ret = FALSE;
710+ GError * local_error = NULL ;
711+
712+ ret = bd_fs_unmount (mountpoint , FALSE, FALSE, NULL , & local_error );
713+ if (!ret ) {
714+ g_set_error (error , BD_FS_ERROR , BD_FS_ERROR_UNMOUNT_FAIL ,
715+ "Failed to unmount '%s' after %s it: %s" ,
716+ device , operation , local_error -> message );
717+ g_clear_error (& local_error );
718+ return FALSE;
719+ } else {
720+ if (g_rmdir (mountpoint ) != 0 )
721+ bd_utils_log_format (BD_UTILS_LOG_INFO , "Failed to remove temporary mountpoint '%s'" ,
722+ mountpoint );
723+ }
724+ return TRUE;
725+ }
726+
727+
706728/**
707729 * xfs_resize_device:
708730 * @device: the device the file system of which to resize
@@ -739,22 +761,18 @@ static gboolean xfs_resize_device (const gchar *device, guint64 new_size, const
739761 success = bd_fs_xfs_resize (mountpoint , new_size , extra , error );
740762
741763 if (unmount ) {
742- ret = bd_fs_unmount ( mountpoint , FALSE, FALSE, NULL , & local_error );
764+ ret = fs_unmount ( device , mountpoint , "resizing" , & local_error );
743765 if (!ret ) {
744766 if (success ) {
745767 /* resize was successful but unmount failed */
746- g_set_error (error , BD_FS_ERROR , BD_FS_ERROR_UNMOUNT_FAIL ,
747- "Failed to unmount '%s' after resizing it: %s" ,
748- device , local_error -> message );
749- g_clear_error (& local_error );
768+ g_propagate_error (error , local_error );
750769 return FALSE;
751770 } else
752771 /* both resize and unmount were unsuccessful but the error
753772 from the resize is more important so just ignore the
754773 unmount error */
755774 g_clear_error (& local_error );
756- } else
757- g_rmdir (mountpoint );
775+ }
758776 }
759777
760778 return success ;
@@ -794,22 +812,18 @@ static gboolean nilfs2_resize_device (const gchar *device, guint64 new_size, GEr
794812 success = bd_fs_nilfs2_resize (device , new_size , error );
795813
796814 if (unmount ) {
797- ret = bd_fs_unmount ( mountpoint , FALSE, FALSE, NULL , & local_error );
815+ ret = fs_unmount ( device , mountpoint , "resizing" , & local_error );
798816 if (!ret ) {
799817 if (success ) {
800818 /* resize was successful but unmount failed */
801- g_set_error (error , BD_FS_ERROR , BD_FS_ERROR_UNMOUNT_FAIL ,
802- "Failed to unmount '%s' after resizing it: %s" ,
803- device , local_error -> message );
804- g_clear_error (& local_error );
819+ g_propagate_error (error , local_error );
805820 return FALSE;
806821 } else
807822 /* both resize and unmount were unsuccessful but the error
808823 from the resize is more important so just ignore the
809824 unmount error */
810825 g_clear_error (& local_error );
811- } else
812- g_rmdir (mountpoint );
826+ }
813827 }
814828
815829 return success ;
@@ -829,23 +843,19 @@ static BDFSBtrfsInfo* btrfs_get_info (const gchar *device, GError **error) {
829843 btrfs_info = bd_fs_btrfs_get_info (mountpoint , error );
830844
831845 if (unmount ) {
832- ret = bd_fs_unmount ( mountpoint , FALSE, FALSE, NULL , & local_error );
846+ ret = fs_unmount ( device , mountpoint , "getting info" , & local_error );
833847 if (!ret ) {
834848 if (btrfs_info ) {
835849 /* info was successful but unmount failed */
836- g_set_error (error , BD_FS_ERROR , BD_FS_ERROR_UNMOUNT_FAIL ,
837- "Failed to unmount '%s' after getting info: %s" ,
838- device , local_error -> message );
839- g_clear_error (& local_error );
850+ g_propagate_error (error , local_error );
840851 bd_fs_btrfs_info_free (btrfs_info );
841852 return NULL ;
842853 } else
843854 /* both info and unmount were unsuccessful but the error
844855 from the info is more important so just ignore the
845856 unmount error */
846857 g_clear_error (& local_error );
847- } else
848- g_rmdir (mountpoint );
858+ }
849859 }
850860
851861 return btrfs_info ;
@@ -865,22 +875,18 @@ static gboolean btrfs_resize_device (const gchar *device, guint64 new_size, GErr
865875 success = bd_fs_btrfs_resize (mountpoint , new_size , NULL , error );
866876
867877 if (unmount ) {
868- ret = bd_fs_unmount ( mountpoint , FALSE, FALSE, NULL , & local_error );
878+ ret = fs_unmount ( device , mountpoint , "resizing" , & local_error );
869879 if (!ret ) {
870880 if (success ) {
871881 /* resize was successful but unmount failed */
872- g_set_error (error , BD_FS_ERROR , BD_FS_ERROR_UNMOUNT_FAIL ,
873- "Failed to unmount '%s' after resizing it: %s" ,
874- device , local_error -> message );
875- g_clear_error (& local_error );
882+ g_propagate_error (error , local_error );
876883 return FALSE;
877884 } else
878885 /* both resize and unmount were unsuccessful but the error
879886 from the resize is more important so just ignore the
880887 unmount error */
881888 g_clear_error (& local_error );
882- } else
883- g_rmdir (mountpoint );
889+ }
884890 }
885891
886892 return success ;
@@ -900,22 +906,18 @@ static gboolean btrfs_set_label (const gchar *device, const gchar *label, GError
900906 success = bd_fs_btrfs_set_label (mountpoint , label , error );
901907
902908 if (unmount ) {
903- ret = bd_fs_unmount ( mountpoint , FALSE, FALSE, NULL , & local_error );
909+ ret = fs_unmount ( device , mountpoint , "setting label" , & local_error );
904910 if (!ret ) {
905911 if (success ) {
906- /* resize was successful but unmount failed */
907- g_set_error (error , BD_FS_ERROR , BD_FS_ERROR_UNMOUNT_FAIL ,
908- "Failed to unmount '%s' after setting label: %s" ,
909- device , local_error -> message );
910- g_clear_error (& local_error );
912+ /* label was successful but unmount failed */
913+ g_propagate_error (error , local_error );
911914 return FALSE;
912915 } else
913- /* both set label and unmount were unsuccessful but the error
914- from the set label is more important so just ignore the
916+ /* both label and unmount were unsuccessful but the error
917+ from the label is more important so just ignore the
915918 unmount error */
916919 g_clear_error (& local_error );
917- } else
918- g_rmdir (mountpoint );
920+ }
919921 }
920922
921923 return success ;
0 commit comments