diff --git a/src/data.c b/src/data.c index e4b2ecb3..47e96d56 100644 --- a/src/data.c +++ b/src/data.c @@ -266,14 +266,22 @@ read_page_from_file(pgFile *file, BlockNumber blknum, } /* Verify checksum */ - if (current.checksum_version && read_len == BLCKSZ) + if (current.checksum_version) { + BlockNumber blkno = file->segno * RELSEG_SIZE + blknum; + uint16 page_crc = read_len == BLCKSZ + ? pg_checksum_page(page, blkno) + /* + * Recompute Cpage checksum calculated by agent with blkno=0 + * pg_checksum_page is calculating it in this way: + * (((checksum ^ blkno) % 65535) + 1) + */ + : (uint16)(((*(uint16*)((PageHeader)page)->pd_linp - 1) ^ blkno) + 1); /* * If checksum is wrong, sleep a bit and then try again * several times. If it didn't help, throw error */ - if (pg_checksum_page(page, file->segno * RELSEG_SIZE + blknum) - != ((PageHeader) page)->pd_checksum) + if (page_crc != ((PageHeader) page)->pd_checksum) { elog(WARNING, "File: %s blknum %u have wrong checksum, try again", file->path, blknum); diff --git a/src/pg_probackup.c b/src/pg_probackup.c index dcf8278f..a271adf7 100644 --- a/src/pg_probackup.c +++ b/src/pg_probackup.c @@ -338,8 +338,13 @@ main(int argc, char *argv[]) } canonicalize_path(backup_path); + MyLocation = IsSshProtocol() + ? backup_subcmd == ARCHIVE_PUSH_CMD + ? FIO_DB_HOST : FIO_BACKUP_HOST + : FIO_LOCAL_HOST; + /* Ensure that backup_path is a path to a directory */ - rc = stat(backup_path, &stat_buf); + rc = fio_stat(backup_path, &stat_buf, true, FIO_BACKUP_HOST); if (rc != -1 && !S_ISDIR(stat_buf.st_mode)) elog(ERROR, "-B, --backup-path must be a path to directory"); @@ -356,11 +361,6 @@ main(int argc, char *argv[]) elog(ERROR, "required parameter not specified: --instance"); } - MyLocation = IsSshProtocol() - ? backup_subcmd == ARCHIVE_PUSH_CMD - ? FIO_DB_HOST : FIO_BACKUP_HOST - : FIO_LOCAL_HOST; - /* * If --instance option was passed, construct paths for backup data and * xlog files of this backup instance. @@ -378,7 +378,7 @@ main(int argc, char *argv[]) */ if (backup_subcmd != INIT_CMD && backup_subcmd != ADD_INSTANCE_CMD) { - if (access(backup_instance_path, F_OK) != 0) + if (fio_access(backup_instance_path, F_OK, FIO_BACKUP_HOST) != 0) elog(ERROR, "Instance '%s' does not exist in this backup catalog", instance_name); } diff --git a/src/utils/file.c b/src/utils/file.c index b8336883..7b391e7d 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -4,6 +4,7 @@ #include #include "pg_probackup.h" +#include "storage/checksum.h" #include "file.h" #define PRINTF_BUF_SIZE 1024 @@ -884,9 +885,12 @@ void fio_communicate(int in, int out) ? PageXLogRecPtrGet(((PageHeader)buf)->pd_lsn) < horizon_lsn /* For non-delta backup horizon_lsn == 0, so this condition is always false */ ? sizeof(PageHeaderData) : BLCKSZ : 0; - IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr)); + if (hdr.size == sizeof(PageHeaderData)) + /* calculate checksum without XOR-ing with block number to compare it with page CRC at master */ + *(int16*)((PageHeader)buf)->pd_linp = pg_checksum_page(buf, 0); + IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr)); if (hdr.size != 0) - IO_CHECK(fio_write_all(out, buf, hdr.size), hdr.size); + IO_CHECK(fio_write_all(out, buf, hdr.size), hdr.size); break; case FIO_FSTAT: /* Get information about opened file */ hdr.size = sizeof(st); diff --git a/src/utils/remote.c b/src/utils/remote.c index 3b6fc8e2..eced5f87 100644 --- a/src/utils/remote.c +++ b/src/utils/remote.c @@ -52,12 +52,12 @@ static int split_options(int argc, char* argv[], int max_options, char* options) } static int child_pid; - +#if 0 static void kill_child(void) { kill(child_pid, SIGTERM); } - +#endif bool launch_agent(void) {