@@ -776,6 +776,34 @@ fio_fwrite(FILE* f, void const* buf, size_t size)
776776return fwrite (buf ,1 ,size ,f );
777777}
778778
779+ /*
780+ * Write buffer to descriptor by calling write(),
781+ * If size of written data is less than buffer size,
782+ * then try to write what is left.
783+ * We do this to get honest errno if there are some problems
784+ * with filesystem, since writing less than buffer size
785+ * is not considered an error.
786+ */
787+ static ssize_t
788+ durable_write (int fd ,const char * buf ,size_t size )
789+ {
790+ off_t current_pos = 0 ;
791+ size_t bytes_left = size ;
792+
793+ while (bytes_left > 0 )
794+ {
795+ int rc = write (fd ,buf + current_pos ,bytes_left );
796+
797+ if (rc <=0 )
798+ return rc ;
799+
800+ bytes_left -= rc ;
801+ current_pos += rc ;
802+ }
803+
804+ return size ;
805+ }
806+
779807/* Write data to the file synchronously */
780808ssize_t
781809fio_write (int fd ,void const * buf ,size_t size )
@@ -805,7 +833,7 @@ fio_write(int fd, void const* buf, size_t size)
805833}
806834else
807835{
808- return write (fd ,buf ,size );
836+ return durable_write (fd ,buf ,size );
809837}
810838}
811839
@@ -815,7 +843,7 @@ fio_write_impl(int fd, void const* buf, size_t size, int out)
815843int rc ;
816844fio_header hdr ;
817845
818- rc = write (fd ,buf ,size );
846+ rc = durable_write (fd ,buf ,size );
819847
820848hdr .arg = 0 ;
821849hdr .size = 0 ;
@@ -837,34 +865,6 @@ fio_fwrite_async(FILE* f, void const* buf, size_t size)
837865:fwrite (buf ,1 ,size ,f );
838866}
839867
840- /*
841- * Write buffer to descriptor by calling write(),
842- * If size of written data is less than buffer size,
843- * then try to write what is left.
844- * We do this to get honest errno if there are some problems
845- * with filesystem, since writing less than buffer size
846- * is not considered an error.
847- */
848- static ssize_t
849- durable_write (int fd ,const char * buf ,size_t size )
850- {
851- off_t current_pos = 0 ;
852- size_t bytes_left = size ;
853-
854- while (bytes_left > 0 )
855- {
856- int rc = write (fd ,buf + current_pos ,bytes_left );
857-
858- if (rc <=0 )
859- return rc ;
860-
861- bytes_left -= rc ;
862- current_pos += rc ;
863- }
864-
865- return size ;
866- }
867-
868868/* Write data to the file */
869869/* TODO: support async report error */
870870ssize_t
@@ -949,23 +949,22 @@ fio_fwrite_async_compressed(FILE* f, void const* buf, size_t size, int compress_
949949}
950950else
951951{
952- char uncompressed_buf [BLCKSZ ];
953952char * errormsg = NULL ;
954- int32 uncompressed_size = fio_decompress (uncompressed_buf ,buf ,size ,compress_alg ,& errormsg );
953+ char decompressed_buf [BLCKSZ ];
954+ int32 decompressed_size = fio_decompress (decompressed_buf ,buf ,size ,compress_alg ,& errormsg );
955955
956- if (uncompressed_size < 0 )
956+ if (decompressed_size < 0 )
957957elog (ERROR ,"%s" ,errormsg );
958958
959- return fwrite (uncompressed_buf ,1 ,uncompressed_size ,f );
959+ return fwrite (decompressed_buf ,1 ,decompressed_size ,f );
960960}
961961}
962962
963963static void
964964fio_write_compressed_impl (int fd ,void const * buf ,size_t size ,int compress_alg )
965965{
966- int rc ;
967- int32 uncompressed_size ;
968- char uncompressed_buf [BLCKSZ ];
966+ int32 decompressed_size ;
967+ char decompressed_buf [BLCKSZ ];
969968
970969/* If the previous command already have failed,
971970 * then there is no point in bashing a head against the wall
@@ -974,14 +973,12 @@ fio_write_compressed_impl(int fd, void const* buf, size_t size, int compress_alg
974973return ;
975974
976975/* decompress chunk */
977- uncompressed_size = fio_decompress (uncompressed_buf ,buf ,size ,compress_alg ,& async_errormsg );
976+ decompressed_size = fio_decompress (decompressed_buf ,buf ,size ,compress_alg ,& async_errormsg );
978977
979- if (uncompressed_size < 0 )
978+ if (decompressed_size < 0 )
980979return ;
981980
982- rc = write (fd ,uncompressed_buf ,uncompressed_size );
983-
984- if (rc <=0 )
981+ if (durable_write (fd ,decompressed_buf ,decompressed_size ) <=0 )
985982{
986983async_errormsg = pgut_malloc (ERRMSG_MAX_LEN );
987984snprintf (async_errormsg ,ERRMSG_MAX_LEN ,"%s" ,strerror (errno ));