Skip to content

Commit 52f4d59

Browse files
kulaginmGrigory Smolkin
authored andcommitted
[refactoring] move some fio_ function declaration from pg_probackup.h to utils/file.h
1 parent 25be85d commit 52f4d59

File tree

4 files changed

+70
-69
lines changed

4 files changed

+70
-69
lines changed

src/pg_probackup.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,6 @@ extern int copy_pages(const char *to_fullpath, const char *from_fullpath,
12341234
BackupMode backup_mode);
12351235

12361236
/* FIO */
1237-
extern void setMyLocation(ProbackupSubcmd const subcmd);
12381237
extern int fio_send_pages(const char *to_fullpath, const char *from_fullpath, pgFile *file,
12391238
XLogRecPtr horizonLsn, int calg, int clevel, uint32 checksum_version,
12401239
bool use_pagemap, BlockNumber *err_blknum, char **errormsg,
@@ -1249,19 +1248,8 @@ extern int fio_send_file(const char *from_fullpath, FILE* out, bool cut_zero_tai
12491248
extern int fio_send_file_local(const char *from_fullpath, FILE* out, bool cut_zero_tail,
12501249
pgFile *file, char **errormsg);
12511250

1252-
extern void fio_list_dir(parray *files, const char *root, bool exclude, bool follow_symlink,
1253-
bool add_root, bool backup_logs, bool skip_hidden, int external_dir_num);
1254-
12551251
extern bool pgut_rmtree(const char *path, bool rmtopdir, bool strict);
12561252

1257-
extern PageState *fio_get_checksum_map(fio_location location, const char *fullpath, uint32 checksum_version, int n_blocks,
1258-
XLogRecPtr dest_stop_lsn, BlockNumber segmentno);
1259-
1260-
extern datapagemap_t *fio_get_lsn_map(fio_location location, const char *fullpath, uint32 checksum_version,
1261-
int n_blocks, XLogRecPtr horizonLsn, BlockNumber segmentno);
1262-
1263-
extern int32 fio_decompress(void* dst, void const* src, size_t size, int compress_alg, char **errormsg);
1264-
12651253
/* return codes for fio_send_pages() and fio_send_file() */
12661254
#define SEND_OK (0)
12671255
#define FILE_MISSING (-1)
@@ -1272,10 +1260,6 @@ extern int32 fio_decompress(void* dst, void const* src, size_t size, int compres
12721260
#define REMOTE_ERROR (-6)
12731261
#define PAGE_CORRUPTION (-8)
12741262

1275-
/* Check if specified location is local for current node */
1276-
extern bool fio_is_remote(fio_location location);
1277-
extern bool fio_is_remote_simple(fio_location location);
1278-
12791263
extern void get_header_errormsg(Page page, char **errormsg);
12801264
extern void get_checksum_errormsg(Page page, char **errormsg,
12811265
BlockNumber absolute_blkno);

src/restore.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,13 +1199,15 @@ restore_files(void *arg)
11991199
{
12001200
if (arguments->incremental_mode == INCR_LSN)
12011201
{
1202-
lsn_map = fio_get_lsn_map(FIO_DB_HOST, to_fullpath, arguments->dest_backup->checksum_version,
1202+
lsn_map = fio_get_lsn_map(FIO_DB_HOST, to_fullpath,
1203+
arguments->dest_backup->checksum_version,
12031204
dest_file->n_blocks, arguments->shift_lsn,
12041205
dest_file->segno * RELSEG_SIZE);
12051206
}
12061207
else if (arguments->incremental_mode == INCR_CHECKSUM)
12071208
{
1208-
checksum_map = fio_get_checksum_map(FIO_DB_HOST, to_fullpath, arguments->dest_backup->checksum_version,
1209+
checksum_map = fio_get_checksum_map(FIO_DB_HOST, to_fullpath,
1210+
arguments->dest_backup->checksum_version,
12091211
dest_file->n_blocks, arguments->dest_backup->stop_lsn,
12101212
dest_file->segno * RELSEG_SIZE);
12111213
}

src/utils/file.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ fio_write_async_impl(int fd, void const* buf, size_t size, int out)
839839
}
840840
}
841841

842-
int32
842+
static int32
843843
fio_decompress(void* dst, void const* src, size_t size, int compress_alg, char **errormsg)
844844
{
845845
const char *internal_errormsg = NULL;
@@ -3465,8 +3465,8 @@ fio_list_dir(parray *files, const char *root, bool exclude,
34653465
}
34663466

34673467
PageState *
3468-
fio_get_checksum_map(fio_location location, const char *fullpath, uint32 checksum_version, int n_blocks,
3469-
XLogRecPtr dest_stop_lsn, BlockNumber segmentno)
3468+
fio_get_checksum_map(fio_location location, const char *fullpath, uint32 checksum_version,
3469+
int n_blocks, XLogRecPtr dest_stop_lsn, BlockNumber segmentno)
34703470
{
34713471
if (fio_is_remote(location))
34723472
{
@@ -3508,7 +3508,7 @@ fio_get_checksum_map(fio_location location, const char *fullpath, uint32 checksu
35083508
}
35093509

35103510
static void
3511-
fio_get_checksum_map_impl(int out, char *buf)
3511+
fio_get_checksum_map_impl(char *buf, int out)
35123512
{
35133513
fio_header hdr;
35143514
PageState *checksum_map = NULL;
@@ -3528,8 +3528,9 @@ fio_get_checksum_map_impl(int out, char *buf)
35283528
}
35293529

35303530
datapagemap_t *
3531-
fio_get_lsn_map(fio_location location, const char *fullpath, uint32 checksum_version,
3532-
int n_blocks, XLogRecPtr shift_lsn, BlockNumber segmentno)
3531+
fio_get_lsn_map(fio_location location, const char *fullpath,
3532+
uint32 checksum_version, int n_blocks,
3533+
XLogRecPtr shift_lsn, BlockNumber segmentno)
35333534
{
35343535
datapagemap_t* lsn_map = NULL;
35353536

@@ -3575,7 +3576,7 @@ fio_get_lsn_map(fio_location location, const char *fullpath, uint32 checksum_ver
35753576
}
35763577

35773578
static void
3578-
fio_get_lsn_map_impl(int out, char *buf)
3579+
fio_get_lsn_map_impl(char *buf, int out)
35793580
{
35803581
fio_header hdr;
35813582
datapagemap_t *lsn_map = NULL;
@@ -3879,12 +3880,10 @@ fio_communicate(int in, int out)
38793880
IO_CHECK(fio_write_all(out, &crc, sizeof(crc)), sizeof(crc));
38803881
break;
38813882
case FIO_GET_CHECKSUM_MAP:
3882-
/* calculate crc32 for a file */
3883-
fio_get_checksum_map_impl(out, buf);
3883+
fio_get_checksum_map_impl(buf, out);
38843884
break;
38853885
case FIO_GET_LSN_MAP:
3886-
/* calculate crc32 for a file */
3887-
fio_get_lsn_map_impl(out, buf);
3886+
fio_get_lsn_map_impl(buf, out);
38883887
break;
38893888
case FIO_CHECK_POSTMASTER:
38903889
fio_check_postmaster_impl(buf, out);

src/utils/file.h

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,6 @@ typedef enum
5959
FIO_PAGE_ZERO
6060
} fio_operations;
6161

62-
typedef enum
63-
{
64-
FIO_LOCAL_HOST, /* data is locate at local host */
65-
FIO_DB_HOST, /* data is located at Postgres server host */
66-
FIO_BACKUP_HOST, /* data is located at backup host */
67-
FIO_REMOTE_HOST /* date is located at remote host */
68-
} fio_location;
69-
70-
#define FIO_FDMAX 64
71-
#define FIO_PIPE_MARKER 0x40000000
72-
73-
#define SYS_CHECK(cmd) do if ((cmd) < 0) { fprintf(stderr, "%s:%d: (%s) %s\n", __FILE__, __LINE__, #cmd, strerror(errno)); exit(EXIT_FAILURE); } while (0)
74-
#define IO_CHECK(cmd, size) do { int _rc = (cmd); if (_rc != (size)) fio_error(_rc, size, __FILE__, __LINE__); } while (0)
75-
7662
typedef struct
7763
{
7864
// fio_operations cop;
@@ -87,18 +73,51 @@ typedef struct
8773
unsigned arg;
8874
} fio_header;
8975

76+
typedef enum
77+
{
78+
FIO_LOCAL_HOST, /* data is locate at local host */
79+
FIO_DB_HOST, /* data is located at Postgres server host */
80+
FIO_BACKUP_HOST, /* data is located at backup host */
81+
FIO_REMOTE_HOST /* date is located at remote host */
82+
} fio_location;
83+
9084
extern fio_location MyLocation;
9185

92-
/* Check if FILE handle is local or remote (created by FIO) */
93-
#define fio_is_remote_file(file) ((size_t)(file) <= FIO_FDMAX)
86+
extern void setMyLocation(ProbackupSubcmd const subcmd);
87+
/* Check if specified location is local for current node */
88+
extern bool fio_is_remote(fio_location location);
89+
extern bool fio_is_remote_simple(fio_location location);
9490

95-
extern void fio_redirect(int in, int out, int err);
9691
extern void fio_communicate(int in, int out);
9792
extern void fio_disconnect(void);
98-
9993
extern void fio_get_agent_version(int* protocol, char* payload_buf, size_t payload_buf_size);
94+
95+
#define FIO_FDMAX 64
96+
#define FIO_PIPE_MARKER 0x40000000
97+
98+
/* Check if FILE handle is local or remote (created by FIO) */
99+
#define fio_is_remote_file(file) ((size_t)(file) <= FIO_FDMAX)
100+
101+
extern void fio_redirect(int in, int out, int err);
100102
extern void fio_error(int rc, int size, const char* file, int line);
101103

104+
#define SYS_CHECK(cmd) do if ((cmd) < 0) { fprintf(stderr, "%s:%d: (%s) %s\n", __FILE__, __LINE__, #cmd, strerror(errno)); exit(EXIT_FAILURE); } while (0)
105+
#define IO_CHECK(cmd, size) do { int _rc = (cmd); if (_rc != (size)) fio_error(_rc, size, __FILE__, __LINE__); } while (0)
106+
107+
108+
/* fd-style functions */
109+
extern int fio_open(fio_location location, const char* name, int mode);
110+
extern ssize_t fio_write(int fd, void const* buf, size_t size);
111+
extern ssize_t fio_write_async(int fd, void const* buf, size_t size);
112+
extern int fio_check_error_fd(int fd, char **errmsg);
113+
extern int fio_check_error_fd_gz(gzFile f, char **errmsg);
114+
extern ssize_t fio_read(int fd, void* buf, size_t size);
115+
extern int fio_flush(int fd);
116+
extern int fio_seek(int fd, off_t offs);
117+
extern int fio_fstat(int fd, struct stat* st);
118+
extern int fio_truncate(int fd, off_t size);
119+
extern int fio_close(int fd);
120+
102121
/* FILE-style functions */
103122
extern FILE* fio_fopen(fio_location location, const char* name, const char* mode);
104123
extern size_t fio_fwrite(FILE* f, void const* buf, size_t size);
@@ -117,18 +136,16 @@ extern int fio_ffstat(FILE* f, struct stat* st);
117136
extern FILE* fio_open_stream(fio_location location, const char* name);
118137
extern int fio_close_stream(FILE* f);
119138

120-
/* fd-style functions */
121-
extern int fio_open(fio_location location, const char* name, int mode);
122-
extern ssize_t fio_write(int fd, void const* buf, size_t size);
123-
extern ssize_t fio_write_async(int fd, void const* buf, size_t size);
124-
extern int fio_check_error_fd(int fd, char **errmsg);
125-
extern int fio_check_error_fd_gz(gzFile f, char **errmsg);
126-
extern ssize_t fio_read(int fd, void* buf, size_t size);
127-
extern int fio_flush(int fd);
128-
extern int fio_seek(int fd, off_t offs);
129-
extern int fio_fstat(int fd, struct stat* st);
130-
extern int fio_truncate(int fd, off_t size);
131-
extern int fio_close(int fd);
139+
/* gzFile-style functions */
140+
#ifdef HAVE_LIBZ
141+
extern gzFile fio_gzopen(fio_location location, const char* path, const char* mode, int level);
142+
extern int fio_gzclose(gzFile file);
143+
extern int fio_gzread(gzFile f, void *buf, unsigned size);
144+
extern int fio_gzwrite(gzFile f, void const* buf, unsigned size);
145+
extern int fio_gzeof(gzFile f);
146+
extern z_off_t fio_gzseek(gzFile f, z_off_t offset, int whence);
147+
extern const char* fio_gzerror(gzFile file, int *errnum);
148+
#endif
132149

133150
/* DIR-style functions */
134151
extern DIR* fio_opendir(fio_location location, const char* path);
@@ -153,15 +170,14 @@ extern bool fio_is_same_file(fio_location location, const char* filename1, co
153170
extern ssize_t fio_readlink(fio_location location, const char *path, char *value, size_t valsiz);
154171
extern pid_t fio_check_postmaster(fio_location location, const char *pgdata);
155172

156-
/* gzFile-style functions */
157-
#ifdef HAVE_LIBZ
158-
extern gzFile fio_gzopen(fio_location location, const char* path, const char* mode, int level);
159-
extern int fio_gzclose(gzFile file);
160-
extern int fio_gzread(gzFile f, void *buf, unsigned size);
161-
extern int fio_gzwrite(gzFile f, void const* buf, unsigned size);
162-
extern int fio_gzeof(gzFile f);
163-
extern z_off_t fio_gzseek(gzFile f, z_off_t offset, int whence);
164-
extern const char* fio_gzerror(gzFile file, int *errnum);
165-
#endif
173+
extern void fio_list_dir(parray *files, const char *root, bool exclude, bool follow_symlink,
174+
bool add_root, bool backup_logs, bool skip_hidden, int external_dir_num);
175+
176+
struct PageState; /* defined in pg_probackup.h */
177+
extern struct PageState *fio_get_checksum_map(fio_location location, const char *fullpath, uint32 checksum_version,
178+
int n_blocks, XLogRecPtr dest_stop_lsn, BlockNumber segmentno);
179+
struct datapagemap; /* defined in datapagemap.h */
180+
extern struct datapagemap *fio_get_lsn_map(fio_location location, const char *fullpath, uint32 checksum_version,
181+
int n_blocks, XLogRecPtr horizonLsn, BlockNumber segmentno);
166182

167183
#endif

0 commit comments

Comments
 (0)