Skip to content

Commit f128e20

Browse files
committed
[refactoring] move some fio_ function declaration from pg_probackup.h to utils/file.h
1 parent bf8b122 commit f128e20

File tree

4 files changed

+72
-74
lines changed

4 files changed

+72
-74
lines changed

src/pg_probackup.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,36 +1209,22 @@ extern int copy_pages(const char *to_fullpath, const char *from_fullpath,
12091209
BackupMode backup_mode);
12101210

12111211
/* FIO */
1212-
extern void setMyLocation(ProbackupSubcmd const subcmd);
12131212
extern int fio_send_pages(const char *to_fullpath, const char *from_fullpath, pgFile *file,
12141213
XLogRecPtr horizonLsn, int calg, int clevel, uint32 checksum_version,
12151214
bool use_pagemap, BlockNumber *err_blknum, char **errormsg,
12161215
BackupPageHeader2 **headers);
12171216
extern int fio_copy_pages(const char *to_fullpath, const char *from_fullpath, pgFile *file,
12181217
XLogRecPtr horizonLsn, int calg, int clevel, uint32 checksum_version,
12191218
bool use_pagemap, BlockNumber *err_blknum, char **errormsg);
1220-
/* return codes for fio_send_pages */
12211219
extern int fio_send_file_gz(const char *from_fullpath, const char *to_fullpath, FILE* out, char **errormsg);
12221220
extern int fio_send_file(const char *from_fullpath, const char *to_fullpath, FILE* out,
12231221
pgFile *file, char **errormsg);
12241222

1225-
extern void fio_list_dir(parray *files, const char *root, bool exclude, bool follow_symlink,
1226-
bool add_root, bool backup_logs, bool skip_hidden, int external_dir_num);
1227-
12281223
extern bool pgut_rmtree(const char *path, bool rmtopdir, bool strict);
12291224

12301225
extern void pgut_setenv(const char *key, const char *val);
12311226
extern void pgut_unsetenv(const char *key);
12321227

1233-
extern PageState *fio_get_checksum_map(const char *fullpath, uint32 checksum_version, int n_blocks,
1234-
XLogRecPtr dest_stop_lsn, BlockNumber segmentno, fio_location location);
1235-
1236-
extern datapagemap_t *fio_get_lsn_map(const char *fullpath, uint32 checksum_version,
1237-
int n_blocks, XLogRecPtr horizonLsn, BlockNumber segmentno,
1238-
fio_location location);
1239-
1240-
extern int32 fio_decompress(void* dst, void const* src, size_t size, int compress_alg, char **errormsg);
1241-
12421228
/* return codes for fio_send_pages() and fio_send_file() */
12431229
#define SEND_OK (0)
12441230
#define FILE_MISSING (-1)
@@ -1249,10 +1235,6 @@ extern int32 fio_decompress(void* dst, void const* src, size_t size, int compres
12491235
#define REMOTE_ERROR (-6)
12501236
#define PAGE_CORRUPTION (-8)
12511237

1252-
/* Check if specified location is local for current node */
1253-
extern bool fio_is_remote(fio_location location);
1254-
extern bool fio_is_remote_simple(fio_location location);
1255-
12561238
extern void get_header_errormsg(Page page, char **errormsg);
12571239
extern void get_checksum_errormsg(Page page, char **errormsg,
12581240
BlockNumber absolute_blkno);

src/restore.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,15 +1205,17 @@ restore_files(void *arg)
12051205
{
12061206
if (arguments->incremental_mode == INCR_LSN)
12071207
{
1208-
lsn_map = fio_get_lsn_map(to_fullpath, arguments->dest_backup->checksum_version,
1208+
lsn_map = fio_get_lsn_map(FIO_DB_HOST, to_fullpath,
1209+
arguments->dest_backup->checksum_version,
12091210
dest_file->n_blocks, arguments->shift_lsn,
1210-
dest_file->segno * RELSEG_SIZE, FIO_DB_HOST);
1211+
dest_file->segno * RELSEG_SIZE);
12111212
}
12121213
else if (arguments->incremental_mode == INCR_CHECKSUM)
12131214
{
1214-
checksum_map = fio_get_checksum_map(to_fullpath, arguments->dest_backup->checksum_version,
1215+
checksum_map = fio_get_checksum_map(FIO_DB_HOST, to_fullpath,
1216+
arguments->dest_backup->checksum_version,
12151217
dest_file->n_blocks, arguments->dest_backup->stop_lsn,
1216-
dest_file->segno * RELSEG_SIZE, FIO_DB_HOST);
1218+
dest_file->segno * RELSEG_SIZE);
12171219
}
12181220
}
12191221

src/utils/file.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ fio_write_async_impl(int fd, void const* buf, size_t size, int out)
909909
}
910910
}
911911

912-
int32
912+
static int32
913913
fio_decompress(void* dst, void const* src, size_t size, int compress_alg, char **errormsg)
914914
{
915915
const char *internal_errormsg = NULL;
@@ -3016,8 +3016,8 @@ fio_list_dir(parray *files, const char *root, bool exclude,
30163016
}
30173017

30183018
PageState *
3019-
fio_get_checksum_map(const char *fullpath, uint32 checksum_version, int n_blocks,
3020-
XLogRecPtr dest_stop_lsn, BlockNumber segmentno, fio_location location)
3019+
fio_get_checksum_map(fio_location location, const char *fullpath, uint32 checksum_version,
3020+
int n_blocks, XLogRecPtr dest_stop_lsn, BlockNumber segmentno)
30213021
{
30223022
if (fio_is_remote(location))
30233023
{
@@ -3059,7 +3059,7 @@ fio_get_checksum_map(const char *fullpath, uint32 checksum_version, int n_blocks
30593059
}
30603060

30613061
static void
3062-
fio_get_checksum_map_impl(int out, char *buf)
3062+
fio_get_checksum_map_impl(char *buf, int out)
30633063
{
30643064
fio_header hdr;
30653065
PageState *checksum_map = NULL;
@@ -3079,9 +3079,9 @@ fio_get_checksum_map_impl(int out, char *buf)
30793079
}
30803080

30813081
datapagemap_t *
3082-
fio_get_lsn_map(const char *fullpath, uint32 checksum_version,
3083-
int n_blocks, XLogRecPtr shift_lsn, BlockNumber segmentno,
3084-
fio_location location)
3082+
fio_get_lsn_map(fio_location location, const char *fullpath,
3083+
uint32 checksum_version, int n_blocks,
3084+
XLogRecPtr shift_lsn, BlockNumber segmentno)
30853085
{
30863086
datapagemap_t* lsn_map = NULL;
30873087

@@ -3127,7 +3127,7 @@ fio_get_lsn_map(const char *fullpath, uint32 checksum_version,
31273127
}
31283128

31293129
static void
3130-
fio_get_lsn_map_impl(int out, char *buf)
3130+
fio_get_lsn_map_impl(char *buf, int out)
31313131
{
31323132
fio_header hdr;
31333133
datapagemap_t *lsn_map = NULL;
@@ -3425,12 +3425,10 @@ fio_communicate(int in, int out)
34253425
IO_CHECK(fio_write_all(out, &crc, sizeof(crc)), sizeof(crc));
34263426
break;
34273427
case FIO_GET_CHECKSUM_MAP:
3428-
/* calculate crc32 for a file */
3429-
fio_get_checksum_map_impl(out, buf);
3428+
fio_get_checksum_map_impl(buf, out);
34303429
break;
34313430
case FIO_GET_LSN_MAP:
3432-
/* calculate crc32 for a file */
3433-
fio_get_lsn_map_impl(out, buf);
3431+
fio_get_lsn_map_impl(buf, out);
34343432
break;
34353433
case FIO_CHECK_POSTMASTER:
34363434
fio_check_postmaster_impl(buf, out);

src/utils/file.h

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

61-
typedef enum
62-
{
63-
FIO_LOCAL_HOST, /* data is locate at local host */
64-
FIO_DB_HOST, /* data is located at Postgres server host */
65-
FIO_BACKUP_HOST, /* data is located at backup host */
66-
FIO_REMOTE_HOST /* date is located at remote host */
67-
} fio_location;
68-
69-
#define FIO_FDMAX 64
70-
#define FIO_PIPE_MARKER 0x40000000
71-
72-
#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)
73-
#define IO_CHECK(cmd, size) do { int _rc = (cmd); if (_rc != (size)) fio_error(_rc, size, __FILE__, __LINE__); } while (0)
74-
7561
typedef struct
7662
{
7763
// fio_operations cop;
@@ -86,18 +72,51 @@ typedef struct
8672
unsigned arg;
8773
} fio_header;
8874

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

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

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

103+
#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)
104+
#define IO_CHECK(cmd, size) do { int _rc = (cmd); if (_rc != (size)) fio_error(_rc, size, __FILE__, __LINE__); } while (0)
105+
106+
107+
/* fd-style functions */
108+
extern int fio_open(fio_location location, const char* name, int mode);
109+
extern ssize_t fio_write(int fd, void const* buf, size_t size);
110+
extern ssize_t fio_write_async(int fd, void const* buf, size_t size);
111+
extern int fio_check_error_fd(int fd, char **errmsg);
112+
extern int fio_check_error_fd_gz(gzFile f, char **errmsg);
113+
extern ssize_t fio_read(int fd, void* buf, size_t size);
114+
extern int fio_flush(int fd);
115+
extern int fio_seek(int fd, off_t offs);
116+
extern int fio_fstat(int fd, struct stat* st);
117+
extern int fio_truncate(int fd, off_t size);
118+
extern int fio_close(int fd);
119+
101120
/* FILE-style functions */
102121
extern FILE* fio_fopen(fio_location location, const char* name, const char* mode);
103122
extern size_t fio_fwrite(FILE* f, void const* buf, size_t size);
@@ -116,18 +135,16 @@ extern int fio_ffstat(FILE* f, struct stat* st);
116135
extern FILE* fio_open_stream(fio_location location, const char* name);
117136
extern int fio_close_stream(FILE* f);
118137

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

132149
/* DIR-style functions */
133150
extern DIR* fio_opendir(fio_location location, const char* path);
@@ -149,15 +166,14 @@ extern bool fio_is_same_file(fio_location location, const char* filename1, co
149166
extern ssize_t fio_readlink(fio_location location, const char *path, char *value, size_t valsiz);
150167
extern pid_t fio_check_postmaster(fio_location location, const char *pgdata);
151168

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

163179
#endif

0 commit comments

Comments
 (0)