From: Adam Kupczyk Date: Mon, 30 Jul 2018 10:02:55 +0000 (+0200) Subject: iolog: allow to read_iolog from unix socket X-Git-Tag: fio-3.9~50^2 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=2f8f4821ef614ce3e0b221701c36a6d2d2044bb2 iolog: allow to read_iolog from unix socket Checks is file provided via --read_iolog parameter is a unix socket. In such case connect to it and fetch data from there. Signed-off-by: Adam Kupczyk --- diff --git a/iolog.c b/iolog.c index 5be3e84b..3b04195e 100644 --- a/iolog.c +++ b/iolog.c @@ -20,6 +20,13 @@ #include "blktrace.h" #include "pshared.h" +#include +#include +#include +#include +#include +#include + static int iolog_flush(struct io_log *log); static const char iolog_ver2[] = "fio version 2 iolog"; @@ -485,16 +492,46 @@ static bool read_iolog2(struct thread_data *td, FILE *f) return true; } +static bool is_socket(const char *path) +{ + struct stat buf; + int r = stat(path, &buf); + if (r == -1) + return false; + + return S_ISSOCK(buf.st_mode); +} + +static int open_socket(const char *path) +{ + int fd = socket(AF_UNIX, SOCK_STREAM, 0); + struct sockaddr_un addr; + if (fd < 0) + return fd; + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, path, sizeof(addr.sun_path)); + if (connect(fd, (const struct sockaddr *)&addr, strlen(path) + sizeof(addr.sun_family)) == 0) + return fd; + else + close(fd); + return -1; +} + /* * open iolog, check version, and call appropriate parser */ static bool init_iolog_read(struct thread_data *td) { char buffer[256], *p; - FILE *f; + FILE *f = NULL; bool ret; - - f = fopen(td->o.read_iolog_file, "r"); + if (is_socket(td->o.read_iolog_file)) { + int fd = open_socket(td->o.read_iolog_file); + if (fd >= 0) { + f = fdopen(fd, "r"); + } + } else + f = fopen(td->o.read_iolog_file, "r"); if (!f) { perror("fopen read iolog"); return false;