@@ -814,6 +814,34 @@ fio_fwrite_async(FILE* f, void const* buf, size_t size)
814814 : fwrite (buf , 1 , size , f );
815815}
816816
817+ /*
818+ * Write buffer to descriptor by calling write(),
819+ * If size of written data is less than buffer size,
820+ * then try to write what is left.
821+ * We do this to get honest errno if there are some problems
822+ * with filesystem, since writing less than buffer size
823+ * is not considered an error.
824+ */
825+ static ssize_t
826+ durable_write (int fd , const char * buf , size_t size )
827+ {
828+ off_t current_pos = 0 ;
829+ size_t bytes_left = size ;
830+
831+ while (bytes_left > 0 )
832+ {
833+ int rc = write (fd , buf + current_pos , bytes_left );
834+
835+ if (rc <= 0 )
836+ return rc ;
837+
838+ bytes_left -= rc ;
839+ current_pos += rc ;
840+ }
841+
842+ return size ;
843+ }
844+
817845/* Write data to the file */
818846/* TODO: support async report error */
819847ssize_t
@@ -832,27 +860,21 @@ fio_write_async(int fd, void const* buf, size_t size)
832860
833861 IO_CHECK (fio_write_all (fio_stdout , & hdr , sizeof (hdr )), sizeof (hdr ));
834862 IO_CHECK (fio_write_all (fio_stdout , buf , size ), size );
835-
836- return size ;
837863 }
838864 else
839- {
840- return write ( fd , buf , size );
841- }
865+ return durable_write ( fd , buf , size );
866+
867+ return size ;
842868}
843869
844870static void
845871fio_write_async_impl (int fd , void const * buf , size_t size , int out )
846872{
847- int rc ;
848-
849873 /* Quick exit if agent is tainted */
850874 if (async_errormsg )
851875 return ;
852876
853- rc = write (fd , buf , size );
854-
855- if (rc <= 0 )
877+ if (durable_write (fd , buf , size ) <= 0 )
856878 {
857879 async_errormsg = pgut_malloc (ERRMSG_MAX_LEN );
858880 snprintf (async_errormsg , ERRMSG_MAX_LEN , "%s" , strerror (errno ));
0 commit comments