Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd1106e5

Browse files
committed
[Issue#394] use durable_write in fio_write
1 parent8ae217b commitd1106e5

File tree

1 file changed

+39
-42
lines changed

1 file changed

+39
-42
lines changed

‎src/utils/file.c

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,34 @@ fio_fwrite(FILE* f, void const* buf, size_t size)
735735
returnfwrite(buf,1,size,f);
736736
}
737737

738+
/*
739+
* Write buffer to descriptor by calling write(),
740+
* If size of written data is less than buffer size,
741+
* then try to write what is left.
742+
* We do this to get honest errno if there are some problems
743+
* with filesystem, since writing less than buffer size
744+
* is not considered an error.
745+
*/
746+
staticssize_t
747+
durable_write(intfd,constchar*buf,size_tsize)
748+
{
749+
off_tcurrent_pos=0;
750+
size_tbytes_left=size;
751+
752+
while (bytes_left>0)
753+
{
754+
intrc=write(fd,buf+current_pos,bytes_left);
755+
756+
if (rc <=0)
757+
returnrc;
758+
759+
bytes_left-=rc;
760+
current_pos+=rc;
761+
}
762+
763+
returnsize;
764+
}
765+
738766
/* Write data to the file synchronously */
739767
ssize_t
740768
fio_write(intfd,voidconst*buf,size_tsize)
@@ -764,7 +792,7 @@ fio_write(int fd, void const* buf, size_t size)
764792
}
765793
else
766794
{
767-
returnwrite(fd,buf,size);
795+
returndurable_write(fd,buf,size);
768796
}
769797
}
770798

@@ -774,7 +802,7 @@ fio_write_impl(int fd, void const* buf, size_t size, int out)
774802
intrc;
775803
fio_headerhdr;
776804

777-
rc=write(fd,buf,size);
805+
rc=durable_write(fd,buf,size);
778806

779807
hdr.arg=0;
780808
hdr.size=0;
@@ -796,34 +824,6 @@ fio_fwrite_async(FILE* f, void const* buf, size_t size)
796824
:fwrite(buf,1,size,f);
797825
}
798826

799-
/*
800-
* Write buffer to descriptor by calling write(),
801-
* If size of written data is less than buffer size,
802-
* then try to write what is left.
803-
* We do this to get honest errno if there are some problems
804-
* with filesystem, since writing less than buffer size
805-
* is not considered an error.
806-
*/
807-
staticssize_t
808-
durable_write(intfd,constchar*buf,size_tsize)
809-
{
810-
off_tcurrent_pos=0;
811-
size_tbytes_left=size;
812-
813-
while (bytes_left>0)
814-
{
815-
intrc=write(fd,buf+current_pos,bytes_left);
816-
817-
if (rc <=0)
818-
returnrc;
819-
820-
bytes_left-=rc;
821-
current_pos+=rc;
822-
}
823-
824-
returnsize;
825-
}
826-
827827
/* Write data to the file */
828828
/* TODO: support async report error */
829829
ssize_t
@@ -908,23 +908,22 @@ fio_fwrite_async_compressed(FILE* f, void const* buf, size_t size, int compress_
908908
}
909909
else
910910
{
911-
charuncompressed_buf[BLCKSZ];
912911
char*errormsg=NULL;
913-
int32uncompressed_size=fio_decompress(uncompressed_buf,buf,size,compress_alg,&errormsg);
912+
chardecompressed_buf[BLCKSZ];
913+
int32decompressed_size=fio_decompress(decompressed_buf,buf,size,compress_alg,&errormsg);
914914

915-
if (uncompressed_size<0)
915+
if (decompressed_size<0)
916916
elog(ERROR,"%s",errormsg);
917917

918-
returnfwrite(uncompressed_buf,1,uncompressed_size,f);
918+
returnfwrite(decompressed_buf,1,decompressed_size,f);
919919
}
920920
}
921921

922922
staticvoid
923923
fio_write_compressed_impl(intfd,voidconst*buf,size_tsize,intcompress_alg)
924924
{
925-
intrc;
926-
int32uncompressed_size;
927-
charuncompressed_buf[BLCKSZ];
925+
int32decompressed_size;
926+
chardecompressed_buf[BLCKSZ];
928927

929928
/* If the previous command already have failed,
930929
* then there is no point in bashing a head against the wall
@@ -933,14 +932,12 @@ fio_write_compressed_impl(int fd, void const* buf, size_t size, int compress_alg
933932
return;
934933

935934
/* decompress chunk */
936-
uncompressed_size=fio_decompress(uncompressed_buf,buf,size,compress_alg,&async_errormsg);
935+
decompressed_size=fio_decompress(decompressed_buf,buf,size,compress_alg,&async_errormsg);
937936

938-
if (uncompressed_size<0)
937+
if (decompressed_size<0)
939938
return;
940939

941-
rc=write(fd,uncompressed_buf,uncompressed_size);
942-
943-
if (rc <=0)
940+
if (durable_write(fd,decompressed_buf,decompressed_size) <=0)
944941
{
945942
async_errormsg=pgut_malloc(ERRMSG_MAX_LEN);
946943
snprintf(async_errormsg,ERRMSG_MAX_LEN,"%s",strerror(errno));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp