mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-02-03 14:01:57 +02:00
Some minor fixes (#397)
* Reformat fio_*() definitions for easier grep'ping * typo * move check_postmaster() into src/utils/file.c (from src/util.c), rename it to local_check_postmaster() and make it static/private to src/utils/file.c
This commit is contained in:
parent
47c39932b0
commit
477e5bcb4f
@ -1516,7 +1516,7 @@ validate_one_page(Page page, BlockNumber absolute_blkno,
|
||||
}
|
||||
|
||||
/*
|
||||
* Valiate pages of datafile in PGDATA one by one.
|
||||
* Validate pages of datafile in PGDATA one by one.
|
||||
*
|
||||
* returns true if the file is valid
|
||||
* also returns true if the file was not found
|
||||
|
@ -1071,8 +1071,6 @@ extern PageState *get_checksum_map(const char *fullpath, uint32 checksum_version
|
||||
int n_blocks, XLogRecPtr dest_stop_lsn, BlockNumber segmentno);
|
||||
extern datapagemap_t *get_lsn_map(const char *fullpath, uint32 checksum_version,
|
||||
int n_blocks, XLogRecPtr shift_lsn, BlockNumber segmentno);
|
||||
extern pid_t check_postmaster(const char *pgdata);
|
||||
|
||||
extern bool validate_file_pages(pgFile *file, const char *fullpath, XLogRecPtr stop_lsn,
|
||||
uint32 checksum_version, uint32 backup_version, HeaderMap *hdr_map);
|
||||
|
||||
|
48
src/util.c
48
src/util.c
@ -556,51 +556,3 @@ datapagemap_print_debug(datapagemap_t *map)
|
||||
|
||||
pg_free(iter);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return pid of postmaster process running in given pgdata.
|
||||
* Return 0 if there is none.
|
||||
* Return 1 if postmaster.pid is mangled.
|
||||
*/
|
||||
pid_t
|
||||
check_postmaster(const char *pgdata)
|
||||
{
|
||||
FILE *fp;
|
||||
pid_t pid;
|
||||
char pid_file[MAXPGPATH];
|
||||
|
||||
join_path_components(pid_file, pgdata, "postmaster.pid");
|
||||
|
||||
fp = fopen(pid_file, "r");
|
||||
if (fp == NULL)
|
||||
{
|
||||
/* No pid file, acceptable*/
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
else
|
||||
elog(ERROR, "Cannot open file \"%s\": %s",
|
||||
pid_file, strerror(errno));
|
||||
}
|
||||
|
||||
if (fscanf(fp, "%i", &pid) != 1)
|
||||
{
|
||||
/* something is wrong with the file content */
|
||||
pid = 1;
|
||||
}
|
||||
|
||||
if (pid > 1)
|
||||
{
|
||||
if (kill(pid, 0) != 0)
|
||||
{
|
||||
/* process no longer exists */
|
||||
if (errno == ESRCH)
|
||||
pid = 0;
|
||||
else
|
||||
elog(ERROR, "Failed to send signal 0 to a process %d: %s",
|
||||
pid, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return pid;
|
||||
}
|
||||
|
238
src/utils/file.c
238
src/utils/file.c
@ -30,7 +30,6 @@ typedef struct
|
||||
int path_len;
|
||||
} fio_send_request;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char path[MAXPGPATH];
|
||||
@ -85,14 +84,16 @@ typedef struct
|
||||
#endif
|
||||
|
||||
/* Use specified file descriptors as stdin/stdout for FIO functions */
|
||||
void fio_redirect(int in, int out, int err)
|
||||
void
|
||||
fio_redirect(int in, int out, int err)
|
||||
{
|
||||
fio_stdin = in;
|
||||
fio_stdout = out;
|
||||
fio_stderr = err;
|
||||
}
|
||||
|
||||
void fio_error(int rc, int size, char const* file, int line)
|
||||
void
|
||||
fio_error(int rc, int size, char const* file, int line)
|
||||
{
|
||||
if (remote_agent)
|
||||
{
|
||||
@ -115,7 +116,8 @@ void fio_error(int rc, int size, char const* file, int line)
|
||||
}
|
||||
|
||||
/* Check if file descriptor is local or remote (created by FIO) */
|
||||
static bool fio_is_remote_fd(int fd)
|
||||
static bool
|
||||
fio_is_remote_fd(int fd)
|
||||
{
|
||||
return (fd & FIO_PIPE_MARKER) != 0;
|
||||
}
|
||||
@ -157,14 +159,17 @@ fio_safestat(const char *path, struct stat *buf)
|
||||
#define stat(x, y) fio_safestat(x, y)
|
||||
|
||||
/* TODO: use real pread on Linux */
|
||||
static ssize_t pread(int fd, void* buf, size_t size, off_t off)
|
||||
static ssize_t
|
||||
pread(int fd, void* buf, size_t size, off_t off)
|
||||
{
|
||||
off_t rc = lseek(fd, off, SEEK_SET);
|
||||
if (rc != off)
|
||||
return -1;
|
||||
return read(fd, buf, size);
|
||||
}
|
||||
static int remove_file_or_dir(char const* path)
|
||||
|
||||
static int
|
||||
remove_file_or_dir(char const* path)
|
||||
{
|
||||
int rc = remove(path);
|
||||
#ifdef WIN32
|
||||
@ -178,7 +183,8 @@ static int remove_file_or_dir(char const* path)
|
||||
#endif
|
||||
|
||||
/* Check if specified location is local for current node */
|
||||
bool fio_is_remote(fio_location location)
|
||||
bool
|
||||
fio_is_remote(fio_location location)
|
||||
{
|
||||
bool is_remote = MyLocation != FIO_LOCAL_HOST
|
||||
&& location != FIO_LOCAL_HOST
|
||||
@ -189,7 +195,8 @@ bool fio_is_remote(fio_location location)
|
||||
}
|
||||
|
||||
/* Check if specified location is local for current node */
|
||||
bool fio_is_remote_simple(fio_location location)
|
||||
bool
|
||||
fio_is_remote_simple(fio_location location)
|
||||
{
|
||||
bool is_remote = MyLocation != FIO_LOCAL_HOST
|
||||
&& location != FIO_LOCAL_HOST
|
||||
@ -198,7 +205,8 @@ bool fio_is_remote_simple(fio_location location)
|
||||
}
|
||||
|
||||
/* Try to read specified amount of bytes unless error or EOF are encountered */
|
||||
static ssize_t fio_read_all(int fd, void* buf, size_t size)
|
||||
static ssize_t
|
||||
fio_read_all(int fd, void* buf, size_t size)
|
||||
{
|
||||
size_t offs = 0;
|
||||
while (offs < size)
|
||||
@ -220,7 +228,8 @@ static ssize_t fio_read_all(int fd, void* buf, size_t size)
|
||||
}
|
||||
|
||||
/* Try to write specified amount of bytes unless error is encountered */
|
||||
static ssize_t fio_write_all(int fd, void const* buf, size_t size)
|
||||
static ssize_t
|
||||
fio_write_all(int fd, void const* buf, size_t size)
|
||||
{
|
||||
size_t offs = 0;
|
||||
while (offs < size)
|
||||
@ -241,7 +250,8 @@ static ssize_t fio_write_all(int fd, void const* buf, size_t size)
|
||||
}
|
||||
|
||||
/* Get version of remote agent */
|
||||
int fio_get_agent_version(void)
|
||||
int
|
||||
fio_get_agent_version(void)
|
||||
{
|
||||
fio_header hdr;
|
||||
hdr.cop = FIO_AGENT_VERSION;
|
||||
@ -254,7 +264,8 @@ int fio_get_agent_version(void)
|
||||
}
|
||||
|
||||
/* Open input stream. Remote file is fetched to the in-memory buffer and then accessed through Linux fmemopen */
|
||||
FILE* fio_open_stream(char const* path, fio_location location)
|
||||
FILE*
|
||||
fio_open_stream(char const* path, fio_location location)
|
||||
{
|
||||
FILE* f;
|
||||
if (fio_is_remote(location))
|
||||
@ -294,7 +305,8 @@ FILE* fio_open_stream(char const* path, fio_location location)
|
||||
}
|
||||
|
||||
/* Close input stream */
|
||||
int fio_close_stream(FILE* f)
|
||||
int
|
||||
fio_close_stream(FILE* f)
|
||||
{
|
||||
if (fio_stdin_buffer)
|
||||
{
|
||||
@ -305,7 +317,8 @@ int fio_close_stream(FILE* f)
|
||||
}
|
||||
|
||||
/* Open directory */
|
||||
DIR* fio_opendir(char const* path, fio_location location)
|
||||
DIR*
|
||||
fio_opendir(char const* path, fio_location location)
|
||||
{
|
||||
DIR* dir;
|
||||
if (fio_is_remote(location))
|
||||
@ -346,7 +359,8 @@ DIR* fio_opendir(char const* path, fio_location location)
|
||||
}
|
||||
|
||||
/* Get next directory entry */
|
||||
struct dirent* fio_readdir(DIR *dir)
|
||||
struct dirent*
|
||||
fio_readdir(DIR *dir)
|
||||
{
|
||||
if (fio_is_remote_file((FILE*)dir))
|
||||
{
|
||||
@ -374,7 +388,8 @@ struct dirent* fio_readdir(DIR *dir)
|
||||
}
|
||||
|
||||
/* Close directory */
|
||||
int fio_closedir(DIR *dir)
|
||||
int
|
||||
fio_closedir(DIR *dir)
|
||||
{
|
||||
if (fio_is_remote_file((FILE*)dir))
|
||||
{
|
||||
@ -394,7 +409,8 @@ int fio_closedir(DIR *dir)
|
||||
}
|
||||
|
||||
/* Open file */
|
||||
int fio_open(char const* path, int mode, fio_location location)
|
||||
int
|
||||
fio_open(char const* path, int mode, fio_location location)
|
||||
{
|
||||
int fd;
|
||||
if (fio_is_remote(location))
|
||||
@ -461,7 +477,8 @@ fio_disconnect(void)
|
||||
}
|
||||
|
||||
/* Open stdio file */
|
||||
FILE* fio_fopen(char const* path, char const* mode, fio_location location)
|
||||
FILE*
|
||||
fio_fopen(char const* path, char const* mode, fio_location location)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
|
||||
@ -506,7 +523,8 @@ FILE* fio_fopen(char const* path, char const* mode, fio_location location)
|
||||
}
|
||||
|
||||
/* Format output to file stream */
|
||||
int fio_fprintf(FILE* f, char const* format, ...)
|
||||
int
|
||||
fio_fprintf(FILE* f, char const* format, ...)
|
||||
{
|
||||
int rc;
|
||||
va_list args;
|
||||
@ -532,7 +550,8 @@ int fio_fprintf(FILE* f, char const* format, ...)
|
||||
}
|
||||
|
||||
/* Flush stream data (does nothing for remote file) */
|
||||
int fio_fflush(FILE* f)
|
||||
int
|
||||
fio_fflush(FILE* f)
|
||||
{
|
||||
int rc = 0;
|
||||
if (!fio_is_remote_file(f))
|
||||
@ -541,13 +560,15 @@ int fio_fflush(FILE* f)
|
||||
}
|
||||
|
||||
/* Sync file to the disk (does nothing for remote file) */
|
||||
int fio_flush(int fd)
|
||||
int
|
||||
fio_flush(int fd)
|
||||
{
|
||||
return fio_is_remote_fd(fd) ? 0 : fsync(fd);
|
||||
}
|
||||
|
||||
/* Close output stream */
|
||||
int fio_fclose(FILE* f)
|
||||
int
|
||||
fio_fclose(FILE* f)
|
||||
{
|
||||
return fio_is_remote_file(f)
|
||||
? fio_close(fio_fileno(f))
|
||||
@ -555,7 +576,8 @@ int fio_fclose(FILE* f)
|
||||
}
|
||||
|
||||
/* Close file */
|
||||
int fio_close(int fd)
|
||||
int
|
||||
fio_close(int fd)
|
||||
{
|
||||
if (fio_is_remote_fd(fd))
|
||||
{
|
||||
@ -578,7 +600,8 @@ int fio_close(int fd)
|
||||
}
|
||||
|
||||
/* Truncate stdio file */
|
||||
int fio_ftruncate(FILE* f, off_t size)
|
||||
int
|
||||
fio_ftruncate(FILE* f, off_t size)
|
||||
{
|
||||
return fio_is_remote_file(f)
|
||||
? fio_truncate(fio_fileno(f), size)
|
||||
@ -588,7 +611,8 @@ int fio_ftruncate(FILE* f, off_t size)
|
||||
/* Truncate file
|
||||
* TODO: make it synchronous
|
||||
*/
|
||||
int fio_truncate(int fd, off_t size)
|
||||
int
|
||||
fio_truncate(int fd, off_t size)
|
||||
{
|
||||
if (fio_is_remote_fd(fd))
|
||||
{
|
||||
@ -613,7 +637,8 @@ int fio_truncate(int fd, off_t size)
|
||||
/*
|
||||
* Read file from specified location.
|
||||
*/
|
||||
int fio_pread(FILE* f, void* buf, off_t offs)
|
||||
int
|
||||
fio_pread(FILE* f, void* buf, off_t offs)
|
||||
{
|
||||
if (fio_is_remote_file(f))
|
||||
{
|
||||
@ -649,7 +674,8 @@ int fio_pread(FILE* f, void* buf, off_t offs)
|
||||
}
|
||||
|
||||
/* Set position in stdio file */
|
||||
int fio_fseek(FILE* f, off_t offs)
|
||||
int
|
||||
fio_fseek(FILE* f, off_t offs)
|
||||
{
|
||||
return fio_is_remote_file(f)
|
||||
? fio_seek(fio_fileno(f), offs)
|
||||
@ -658,7 +684,8 @@ int fio_fseek(FILE* f, off_t offs)
|
||||
|
||||
/* Set position in file */
|
||||
/* TODO: make it synchronous or check async error */
|
||||
int fio_seek(int fd, off_t offs)
|
||||
int
|
||||
fio_seek(int fd, off_t offs)
|
||||
{
|
||||
if (fio_is_remote_fd(fd))
|
||||
{
|
||||
@ -699,7 +726,8 @@ fio_seek_impl(int fd, off_t offs)
|
||||
}
|
||||
|
||||
/* Write data to stdio file */
|
||||
size_t fio_fwrite(FILE* f, void const* buf, size_t size)
|
||||
size_t
|
||||
fio_fwrite(FILE* f, void const* buf, size_t size)
|
||||
{
|
||||
if (fio_is_remote_file(f))
|
||||
return fio_write(fio_fileno(f), buf, size);
|
||||
@ -708,7 +736,8 @@ size_t fio_fwrite(FILE* f, void const* buf, size_t size)
|
||||
}
|
||||
|
||||
/* Write data to the file synchronously */
|
||||
ssize_t fio_write(int fd, void const* buf, size_t size)
|
||||
ssize_t
|
||||
fio_write(int fd, void const* buf, size_t size)
|
||||
{
|
||||
if (fio_is_remote_fd(fd))
|
||||
{
|
||||
@ -759,7 +788,8 @@ fio_write_impl(int fd, void const* buf, size_t size, int out)
|
||||
return;
|
||||
}
|
||||
|
||||
size_t fio_fwrite_async(FILE* f, void const* buf, size_t size)
|
||||
size_t
|
||||
fio_fwrite_async(FILE* f, void const* buf, size_t size)
|
||||
{
|
||||
return fio_is_remote_file(f)
|
||||
? fio_write_async(fio_fileno(f), buf, size)
|
||||
@ -768,7 +798,8 @@ size_t fio_fwrite_async(FILE* f, void const* buf, size_t size)
|
||||
|
||||
/* Write data to the file */
|
||||
/* TODO: support async report error */
|
||||
ssize_t fio_write_async(int fd, void const* buf, size_t size)
|
||||
ssize_t
|
||||
fio_write_async(int fd, void const* buf, size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
@ -836,7 +867,8 @@ fio_decompress(void* dst, void const* src, size_t size, int compress_alg, char *
|
||||
}
|
||||
|
||||
/* Write data to the file */
|
||||
ssize_t fio_fwrite_async_compressed(FILE* f, void const* buf, size_t size, int compress_alg)
|
||||
ssize_t
|
||||
fio_fwrite_async_compressed(FILE* f, void const* buf, size_t size, int compress_alg)
|
||||
{
|
||||
if (fio_is_remote_file(f))
|
||||
{
|
||||
@ -976,7 +1008,8 @@ fio_get_async_error_impl(int out)
|
||||
}
|
||||
|
||||
/* Read data from stdio file */
|
||||
ssize_t fio_fread(FILE* f, void* buf, size_t size)
|
||||
ssize_t
|
||||
fio_fread(FILE* f, void* buf, size_t size)
|
||||
{
|
||||
size_t rc;
|
||||
if (fio_is_remote_file(f))
|
||||
@ -986,7 +1019,8 @@ ssize_t fio_fread(FILE* f, void* buf, size_t size)
|
||||
}
|
||||
|
||||
/* Read data from file */
|
||||
ssize_t fio_read(int fd, void* buf, size_t size)
|
||||
ssize_t
|
||||
fio_read(int fd, void* buf, size_t size)
|
||||
{
|
||||
if (fio_is_remote_fd(fd))
|
||||
{
|
||||
@ -1012,7 +1046,8 @@ ssize_t fio_read(int fd, void* buf, size_t size)
|
||||
}
|
||||
|
||||
/* Get information about file */
|
||||
int fio_stat(char const* path, struct stat* st, bool follow_symlink, fio_location location)
|
||||
int
|
||||
fio_stat(char const* path, struct stat* st, bool follow_symlink, fio_location location)
|
||||
{
|
||||
if (fio_is_remote(location))
|
||||
{
|
||||
@ -1045,7 +1080,8 @@ int fio_stat(char const* path, struct stat* st, bool follow_symlink, fio_locatio
|
||||
}
|
||||
|
||||
/* Check presence of the file */
|
||||
int fio_access(char const* path, int mode, fio_location location)
|
||||
int
|
||||
fio_access(char const* path, int mode, fio_location location)
|
||||
{
|
||||
if (fio_is_remote(location))
|
||||
{
|
||||
@ -1076,7 +1112,8 @@ int fio_access(char const* path, int mode, fio_location location)
|
||||
}
|
||||
|
||||
/* Create symbolic link */
|
||||
int fio_symlink(char const* target, char const* link_path, bool overwrite, fio_location location)
|
||||
int
|
||||
fio_symlink(char const* target, char const* link_path, bool overwrite, fio_location location)
|
||||
{
|
||||
if (fio_is_remote(location))
|
||||
{
|
||||
@ -1103,7 +1140,8 @@ int fio_symlink(char const* target, char const* link_path, bool overwrite, fio_l
|
||||
}
|
||||
}
|
||||
|
||||
static void fio_symlink_impl(int out, char *buf, bool overwrite)
|
||||
static void
|
||||
fio_symlink_impl(int out, char *buf, bool overwrite)
|
||||
{
|
||||
char *linked_path = buf;
|
||||
char *link_path = buf + strlen(buf) + 1;
|
||||
@ -1117,7 +1155,8 @@ static void fio_symlink_impl(int out, char *buf, bool overwrite)
|
||||
}
|
||||
|
||||
/* Rename file */
|
||||
int fio_rename(char const* old_path, char const* new_path, fio_location location)
|
||||
int
|
||||
fio_rename(char const* old_path, char const* new_path, fio_location location)
|
||||
{
|
||||
if (fio_is_remote(location))
|
||||
{
|
||||
@ -1143,7 +1182,8 @@ int fio_rename(char const* old_path, char const* new_path, fio_location location
|
||||
}
|
||||
|
||||
/* Sync file to disk */
|
||||
int fio_sync(char const* path, fio_location location)
|
||||
int
|
||||
fio_sync(char const* path, fio_location location)
|
||||
{
|
||||
if (fio_is_remote(location))
|
||||
{
|
||||
@ -1185,7 +1225,8 @@ int fio_sync(char const* path, fio_location location)
|
||||
}
|
||||
|
||||
/* Get crc32 of file */
|
||||
pg_crc32 fio_get_crc32(const char *file_path, fio_location location, bool decompress)
|
||||
pg_crc32
|
||||
fio_get_crc32(const char *file_path, fio_location location, bool decompress)
|
||||
{
|
||||
if (fio_is_remote(location))
|
||||
{
|
||||
@ -1216,7 +1257,8 @@ pg_crc32 fio_get_crc32(const char *file_path, fio_location location, bool decomp
|
||||
}
|
||||
|
||||
/* Remove file */
|
||||
int fio_unlink(char const* path, fio_location location)
|
||||
int
|
||||
fio_unlink(char const* path, fio_location location)
|
||||
{
|
||||
if (fio_is_remote(location))
|
||||
{
|
||||
@ -1241,7 +1283,8 @@ int fio_unlink(char const* path, fio_location location)
|
||||
/* Create directory
|
||||
* TODO: add strict flag
|
||||
*/
|
||||
int fio_mkdir(char const* path, int mode, fio_location location)
|
||||
int
|
||||
fio_mkdir(char const* path, int mode, fio_location location)
|
||||
{
|
||||
if (fio_is_remote(location))
|
||||
{
|
||||
@ -1267,7 +1310,8 @@ int fio_mkdir(char const* path, int mode, fio_location location)
|
||||
}
|
||||
|
||||
/* Change file mode */
|
||||
int fio_chmod(char const* path, int mode, fio_location location)
|
||||
int
|
||||
fio_chmod(char const* path, int mode, fio_location location)
|
||||
{
|
||||
if (fio_is_remote(location))
|
||||
{
|
||||
@ -1562,7 +1606,8 @@ fio_gzclose(gzFile f)
|
||||
}
|
||||
}
|
||||
|
||||
int fio_gzeof(gzFile f)
|
||||
int
|
||||
fio_gzeof(gzFile f)
|
||||
{
|
||||
if ((size_t)f & FIO_GZ_REMOTE_MARKER)
|
||||
{
|
||||
@ -1575,7 +1620,8 @@ int fio_gzeof(gzFile f)
|
||||
}
|
||||
}
|
||||
|
||||
const char* fio_gzerror(gzFile f, int *errnum)
|
||||
const char*
|
||||
fio_gzerror(gzFile f, int *errnum)
|
||||
{
|
||||
if ((size_t)f & FIO_GZ_REMOTE_MARKER)
|
||||
{
|
||||
@ -1590,7 +1636,8 @@ const char* fio_gzerror(gzFile f, int *errnum)
|
||||
}
|
||||
}
|
||||
|
||||
z_off_t fio_gzseek(gzFile f, z_off_t offset, int whence)
|
||||
z_off_t
|
||||
fio_gzseek(gzFile f, z_off_t offset, int whence)
|
||||
{
|
||||
Assert(!((size_t)f & FIO_GZ_REMOTE_MARKER));
|
||||
return gzseek(f, offset, whence);
|
||||
@ -1602,7 +1649,8 @@ z_off_t fio_gzseek(gzFile f, z_off_t offset, int whence)
|
||||
/* Send file content
|
||||
* Note: it should not be used for large files.
|
||||
*/
|
||||
static void fio_load_file(int out, char const* path)
|
||||
static void
|
||||
fio_load_file(int out, char const* path)
|
||||
{
|
||||
int fd = open(path, O_RDONLY);
|
||||
fio_header hdr;
|
||||
@ -1644,7 +1692,8 @@ static void fio_load_file(int out, char const* path)
|
||||
* In case of DELTA mode horizonLsn must be a valid lsn,
|
||||
* otherwise it should be set to InvalidXLogRecPtr.
|
||||
*/
|
||||
int fio_send_pages(const char *to_fullpath, const char *from_fullpath, pgFile *file,
|
||||
int
|
||||
fio_send_pages(const char *to_fullpath, const char *from_fullpath, pgFile *file,
|
||||
XLogRecPtr horizonLsn, int calg, int clevel, uint32 checksum_version,
|
||||
bool use_pagemap, BlockNumber* err_blknum, char **errormsg,
|
||||
BackupPageHeader2 **headers)
|
||||
@ -1804,7 +1853,8 @@ int fio_send_pages(const char *to_fullpath, const char *from_fullpath, pgFile *f
|
||||
* FIO_SEND_FILE_CORRUPTION
|
||||
* FIO_SEND_FILE_EOF
|
||||
*/
|
||||
static void fio_send_pages_impl(int out, char* buf)
|
||||
static void
|
||||
fio_send_pages_impl(int out, char* buf)
|
||||
{
|
||||
FILE *in = NULL;
|
||||
BlockNumber blknum = 0;
|
||||
@ -2074,7 +2124,8 @@ cleanup:
|
||||
* ZLIB_ERROR (-5)
|
||||
* REMOTE_ERROR (-6)
|
||||
*/
|
||||
int fio_send_file_gz(const char *from_fullpath, const char *to_fullpath, FILE* out, char **errormsg)
|
||||
int
|
||||
fio_send_file_gz(const char *from_fullpath, const char *to_fullpath, FILE* out, char **errormsg)
|
||||
{
|
||||
fio_header hdr;
|
||||
int exit_code = SEND_OK;
|
||||
@ -2234,7 +2285,8 @@ cleanup:
|
||||
* OPEN_FAILED and READ_FAIL should also set errormsg.
|
||||
* If pgFile is not NULL then we must calculate crc and read_size for it.
|
||||
*/
|
||||
int fio_send_file(const char *from_fullpath, const char *to_fullpath, FILE* out,
|
||||
int
|
||||
fio_send_file(const char *from_fullpath, const char *to_fullpath, FILE* out,
|
||||
pgFile *file, char **errormsg)
|
||||
{
|
||||
fio_header hdr;
|
||||
@ -2315,7 +2367,8 @@ int fio_send_file(const char *from_fullpath, const char *to_fullpath, FILE* out,
|
||||
* FIO_SEND_FILE_EOF
|
||||
*
|
||||
*/
|
||||
static void fio_send_file_impl(int out, char const* path)
|
||||
static void
|
||||
fio_send_file_impl(int out, char const* path)
|
||||
{
|
||||
FILE *fp;
|
||||
fio_header hdr;
|
||||
@ -2406,7 +2459,8 @@ cleanup:
|
||||
}
|
||||
|
||||
/* Compile the array of files located on remote machine in directory root */
|
||||
static void fio_list_dir_internal(parray *files, const char *root, bool exclude,
|
||||
static void
|
||||
fio_list_dir_internal(parray *files, const char *root, bool exclude,
|
||||
bool follow_symlink, bool add_root, bool backup_logs,
|
||||
bool skip_hidden, int external_dir_num)
|
||||
{
|
||||
@ -2499,7 +2553,8 @@ static void fio_list_dir_internal(parray *files, const char *root, bool exclude,
|
||||
*
|
||||
* TODO: replace FIO_SEND_FILE and FIO_SEND_FILE_EOF with dedicated messages
|
||||
*/
|
||||
static void fio_list_dir_impl(int out, char* buf)
|
||||
static void
|
||||
fio_list_dir_impl(int out, char* buf)
|
||||
{
|
||||
int i;
|
||||
fio_header hdr;
|
||||
@ -2565,7 +2620,8 @@ static void fio_list_dir_impl(int out, char* buf)
|
||||
}
|
||||
|
||||
/* Wrapper for directory listing */
|
||||
void fio_list_dir(parray *files, const char *root, bool exclude,
|
||||
void
|
||||
fio_list_dir(parray *files, const char *root, bool exclude,
|
||||
bool follow_symlink, bool add_root, bool backup_logs,
|
||||
bool skip_hidden, int external_dir_num)
|
||||
{
|
||||
@ -2620,7 +2676,8 @@ fio_get_checksum_map(const char *fullpath, uint32 checksum_version, int n_blocks
|
||||
}
|
||||
}
|
||||
|
||||
static void fio_get_checksum_map_impl(int out, char *buf)
|
||||
static void
|
||||
fio_get_checksum_map_impl(int out, char *buf)
|
||||
{
|
||||
fio_header hdr;
|
||||
PageState *checksum_map = NULL;
|
||||
@ -2687,7 +2744,8 @@ fio_get_lsn_map(const char *fullpath, uint32 checksum_version,
|
||||
return lsn_map;
|
||||
}
|
||||
|
||||
static void fio_get_lsn_map_impl(int out, char *buf)
|
||||
static void
|
||||
fio_get_lsn_map_impl(int out, char *buf)
|
||||
{
|
||||
fio_header hdr;
|
||||
datapagemap_t *lsn_map = NULL;
|
||||
@ -2713,11 +2771,60 @@ static void fio_get_lsn_map_impl(int out, char *buf)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return pid of postmaster process running in given pgdata on local machine.
|
||||
* Return 0 if there is none.
|
||||
* Return 1 if postmaster.pid is mangled.
|
||||
*/
|
||||
static pid_t
|
||||
local_check_postmaster(const char *pgdata)
|
||||
{
|
||||
FILE *fp;
|
||||
pid_t pid;
|
||||
char pid_file[MAXPGPATH];
|
||||
|
||||
join_path_components(pid_file, pgdata, "postmaster.pid");
|
||||
|
||||
fp = fopen(pid_file, "r");
|
||||
if (fp == NULL)
|
||||
{
|
||||
/* No pid file, acceptable*/
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
else
|
||||
elog(ERROR, "Cannot open file \"%s\": %s",
|
||||
pid_file, strerror(errno));
|
||||
}
|
||||
|
||||
if (fscanf(fp, "%i", &pid) != 1)
|
||||
{
|
||||
/* something is wrong with the file content */
|
||||
pid = 1;
|
||||
}
|
||||
|
||||
if (pid > 1)
|
||||
{
|
||||
if (kill(pid, 0) != 0)
|
||||
{
|
||||
/* process no longer exists */
|
||||
if (errno == ESRCH)
|
||||
pid = 0;
|
||||
else
|
||||
elog(ERROR, "Failed to send signal 0 to a process %d: %s",
|
||||
pid, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return pid;
|
||||
}
|
||||
|
||||
/*
|
||||
* Go to the remote host and get postmaster pid from file postmaster.pid
|
||||
* and check that process is running, if process is running, return its pid number.
|
||||
*/
|
||||
pid_t fio_check_postmaster(const char *pgdata, fio_location location)
|
||||
pid_t
|
||||
fio_check_postmaster(const char *pgdata, fio_location location)
|
||||
{
|
||||
if (fio_is_remote(location))
|
||||
{
|
||||
@ -2734,16 +2841,17 @@ pid_t fio_check_postmaster(const char *pgdata, fio_location location)
|
||||
return hdr.arg;
|
||||
}
|
||||
else
|
||||
return check_postmaster(pgdata);
|
||||
return local_check_postmaster(pgdata);
|
||||
}
|
||||
|
||||
static void fio_check_postmaster_impl(int out, char *buf)
|
||||
static void
|
||||
fio_check_postmaster_impl(int out, char *buf)
|
||||
{
|
||||
fio_header hdr;
|
||||
pid_t postmaster_pid;
|
||||
char *pgdata = (char*) buf;
|
||||
|
||||
postmaster_pid = check_postmaster(pgdata);
|
||||
postmaster_pid = local_check_postmaster(pgdata);
|
||||
|
||||
/* send arrays of checksums to main process */
|
||||
hdr.arg = postmaster_pid;
|
||||
@ -2782,7 +2890,8 @@ fio_delete_impl(mode_t mode, char *buf)
|
||||
}
|
||||
|
||||
/* Execute commands at remote host */
|
||||
void fio_communicate(int in, int out)
|
||||
void
|
||||
fio_communicate(int in, int out)
|
||||
{
|
||||
/*
|
||||
* Map of file and directory descriptors.
|
||||
@ -2990,4 +3099,3 @@ void fio_communicate(int in, int out)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,4 +145,3 @@ extern const char* fio_gzerror(gzFile file, int *errnum);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user