From 7142460ec83241fd46d78e13e2969d58700babd9 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 3 Mar 2024 13:50:35 +0300 Subject: [PATCH] Support --logfile in nfs-proxy --- src/epoll_manager.cpp | 2 +- src/nbd_proxy.cpp | 4 ++-- src/nfs_proxy.cpp | 7 +++++-- src/nfs_proxy.h | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/epoll_manager.cpp b/src/epoll_manager.cpp index 379820ee..7dc127ae 100644 --- a/src/epoll_manager.cpp +++ b/src/epoll_manager.cpp @@ -101,7 +101,7 @@ void epoll_manager_t::handle_uring_event() my_uring_prep_poll_add(sqe, epoll_fd, POLLIN); data->callback = [this](ring_data_t *data) { - if (data->res < 0) + if (data->res < 0 && data->res != -ECANCELED) { throw std::runtime_error(std::string("epoll failed: ") + strerror(-data->res)); } diff --git a/src/nbd_proxy.cpp b/src/nbd_proxy.cpp index 1b4017e7..6a1934f5 100644 --- a/src/nbd_proxy.cpp +++ b/src/nbd_proxy.cpp @@ -146,7 +146,7 @@ public: " Note that nbd_timeout, nbd_max_devices and nbd_max_part options may also be specified\n" " in /etc/vitastor/vitastor.conf or in other configuration file specified with --config_file.\n" " --logfile /path/to/log/file.txt\n" - " Wite log messages to the specified file instead of dropping them (in background mode)\n" + " Write log messages to the specified file instead of dropping them (in background mode)\n" " or printing them to the standard output (in foreground mode).\n" " --dev_num N\n" " Use the specified device /dev/nbdN instead of automatic selection.\n" @@ -298,7 +298,7 @@ public: } } } - if (cfg["logfile"].is_string()) + if (cfg["logfile"].string_value() != "") { logfile = cfg["logfile"].string_value(); } diff --git a/src/nfs_proxy.cpp b/src/nfs_proxy.cpp index 682667eb..c98549eb 100644 --- a/src/nfs_proxy.cpp +++ b/src/nfs_proxy.cpp @@ -69,6 +69,7 @@ json11::Json::object nfs_proxy_t::parse_args(int narg, const char *args[]) " --nfspath set NFS export path to (default is /)\n" " --port use port for NFS services (default is 2049)\n" " --pool use as default pool for new files (images)\n" + " --logfile log to the specified file\n" " --foreground 1 stay in foreground, do not daemonize\n" "\n" "NFS proxy is stateless if you use immediate_commit=all in your cluster and if\n" @@ -98,6 +99,8 @@ void nfs_proxy_t::run(json11::Json cfg) srand48(tv.tv_sec*1000000000 + tv.tv_nsec); server_id = (uint64_t)lrand48() | ((uint64_t)lrand48() << 31) | ((uint64_t)lrand48() << 62); // Parse options + if (cfg["logfile"].string_value() != "") + logfile = cfg["logfile"].string_value(); trace = cfg["log_level"].uint64_value() > 5 || cfg["trace"].uint64_value() > 0; bind_address = cfg["bind"].string_value(); if (bind_address == "") @@ -999,8 +1002,8 @@ void nfs_proxy_t::daemonize() close(1); close(2); open("/dev/null", O_RDONLY); - open("/dev/null", O_WRONLY); - open("/dev/null", O_WRONLY); + open(logfile.c_str(), O_WRONLY|O_APPEND|O_CREAT, 0666); + open(logfile.c_str(), O_WRONLY|O_APPEND|O_CREAT, 0666); } int main(int narg, const char *args[]) diff --git a/src/nfs_proxy.h b/src/nfs_proxy.h index c5bb63f3..872ddb55 100644 --- a/src/nfs_proxy.h +++ b/src/nfs_proxy.h @@ -33,6 +33,7 @@ public: uint64_t fs_inode_count = 0; int readdir_getattr_parallel = 8, id_alloc_batch_size = 200; int trace = 0; + std::string logfile = "/dev/null"; pool_id_t default_pool_id; uint64_t pool_block_size = 0;