Skip to content

Commit e1b0f14

Browse files
committed
New fio command FIO_GET_CRC32 added and local behavior changed in fio_pread()
1 parent 3962b02 commit e1b0f14

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/utils/file.c

+42-2
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,15 @@ int fio_pread(FILE* f, void* buf, off_t offs)
548548
return hdr.arg;
549549
}
550550
else
551-
return pread(fileno(f), buf, BLCKSZ, offs);
551+
{
552+
int rc;
553+
rc = fseek(f, offs, SEEK_SET);
554+
555+
if (rc < 0)
556+
return rc;
557+
558+
return fread(buf, 1, BLCKSZ, f);
559+
}
552560
}
553561

554562
/* Set position in stdio file */
@@ -898,6 +906,28 @@ int fio_sync(char const* path, fio_location location)
898906
}
899907
}
900908

909+
/* Get crc32 of file */
910+
pg_crc32 fio_get_crc32(const char *file_path, fio_location location)
911+
{
912+
if (fio_is_remote(location))
913+
{
914+
fio_header hdr;
915+
size_t path_len = strlen(file_path) + 1;
916+
pg_crc32 crc = 0;
917+
hdr.cop = FIO_GET_CRC32;
918+
hdr.handle = -1;
919+
hdr.size = path_len;
920+
921+
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
922+
IO_CHECK(fio_write_all(fio_stdout, file_path, path_len), path_len);
923+
IO_CHECK(fio_read_all(fio_stdin, &crc, sizeof(crc)), sizeof(crc));
924+
925+
return crc;
926+
}
927+
else
928+
return pgFileGetCRCnew(file_path, true, true);
929+
}
930+
901931
/* Remove file */
902932
int fio_unlink(char const* path, fio_location location)
903933
{
@@ -1403,7 +1433,11 @@ static void fio_send_pages_impl(int fd, int out, fio_send_request* req)
14031433
return;
14041434
}
14051435
}
1406-
/* horizonLsn is not 0 for delta backup. As far as unsigned number are always greater or equal than zero, there is no sense to add more checks */
1436+
/*
1437+
* horizonLsn is not 0 for delta backup.
1438+
* As far as unsigned number are always greater or equal than zero,
1439+
* there is no sense to add more checks.
1440+
*/
14071441
if (page_lsn >= req->horizonLsn || page_lsn == InvalidXLogRecPtr)
14081442
{
14091443
char write_buffer[BLCKSZ*2];
@@ -1450,6 +1484,7 @@ void fio_communicate(int in, int out)
14501484
struct stat st;
14511485
int rc;
14521486
int tmp_fd;
1487+
pg_crc32 crc;
14531488

14541489
#ifdef WIN32
14551490
SYS_CHECK(setmode(in, _O_BINARY));
@@ -1591,6 +1626,11 @@ void fio_communicate(int in, int out)
15911626

15921627
IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr));
15931628
break;
1629+
case FIO_GET_CRC32:
1630+
/* calculate crc32 for a file */
1631+
crc = pgFileGetCRCnew(buf, true, true);
1632+
IO_CHECK(fio_write_all(out, &crc, sizeof(crc)), sizeof(crc));
1633+
break;
15941634
default:
15951635
Assert(false);
15961636
}

src/utils/file.h

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef enum
3636
FIO_SEND_PAGES,
3737
FIO_PAGE,
3838
FIO_WRITE_COMPRESSED,
39+
FIO_GET_CRC32
3940
} fio_operations;
4041

4142
typedef enum
@@ -96,6 +97,7 @@ extern int fio_truncate(int fd, off_t size);
9697
extern int fio_close(int fd);
9798
extern void fio_disconnect(void);
9899
extern int fio_sync(char const* path, fio_location location);
100+
extern pg_crc32 fio_get_crc32(const char *file_path, fio_location location);
99101

100102
extern int fio_rename(char const* old_path, char const* new_path, fio_location location);
101103
extern int fio_symlink(char const* target, char const* link_path, fio_location location);

0 commit comments

Comments
 (0)