[pbs-devel] [PATCH proxmox-backup 2/8] refactor: move socket helper to proxmox crate

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri May 14 15:44:51 CEST 2021


and constant to tools module.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---

Notes:
    requires proxmox patch #5 and proxmox version bump

 src/bin/proxmox-backup-proxy.rs |  6 ++----
 src/tools.rs                    |  4 +++-
 src/tools/http.rs               |  7 +++----
 src/tools/socket.rs             | 23 -----------------------
 4 files changed, 8 insertions(+), 32 deletions(-)
 delete mode 100644 src/tools/socket.rs

diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index 71517023..a53f554a 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -11,6 +11,7 @@ use serde_json::Value;
 
 use proxmox::try_block;
 use proxmox::api::RpcEnvironmentType;
+use proxmox::sys::linux::socket::set_tcp_keepalive;
 
 use proxmox_backup::{
     backup::DataStore,
@@ -38,6 +39,7 @@ use proxmox_backup::buildcfg;
 use proxmox_backup::server;
 use proxmox_backup::auth_helpers::*;
 use proxmox_backup::tools::{
+    PROXMOX_BACKUP_TCP_KEEPALIVE_TIME,
     daemon,
     disks::{
         DiskManage,
@@ -45,10 +47,6 @@ use proxmox_backup::tools::{
         get_pool_from_dataset,
     },
     logrotate::LogRotate,
-    socket::{
-        set_tcp_keepalive,
-        PROXMOX_BACKUP_TCP_KEEPALIVE_TIME,
-    },
 };
 
 use proxmox_backup::api2::pull::do_sync_job;
diff --git a/src/tools.rs b/src/tools.rs
index 8f2acded..8a1d0bc7 100644
--- a/src/tools.rs
+++ b/src/tools.rs
@@ -43,7 +43,6 @@ pub mod lru_cache;
 pub mod nom;
 pub mod runtime;
 pub mod serde_filter;
-pub mod socket;
 pub mod statistics;
 pub mod subscription;
 pub mod systemd;
@@ -483,6 +482,9 @@ impl<T: Any> AsAny for T {
     }
 }
 
+/// The default 2 hours are far too long for PBS
+pub const PROXMOX_BACKUP_TCP_KEEPALIVE_TIME: u32 = 120;
+
 /// This used to be: `SIMPLE_ENCODE_SET` plus space, `"`, `#`, `<`, `>`, backtick, `?`, `{`, `}`
 pub const DEFAULT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS // 0..1f and 7e
     // The SIMPLE_ENCODE_SET adds space and anything >= 0x7e (7e itself is already included above)
diff --git a/src/tools/http.rs b/src/tools/http.rs
index 0821992a..1d96c70f 100644
--- a/src/tools/http.rs
+++ b/src/tools/http.rs
@@ -18,12 +18,11 @@ use tokio::{
 };
 use tokio_openssl::SslStream;
 
+use proxmox::sys::linux::socket::set_tcp_keepalive;
+
 use crate::tools::{
+    PROXMOX_BACKUP_TCP_KEEPALIVE_TIME,
     async_io::MaybeTlsStream,
-    socket::{
-        set_tcp_keepalive,
-        PROXMOX_BACKUP_TCP_KEEPALIVE_TIME,
-    },
 };
 
 // Build a http::uri::Authority ("host:port"), use '[..]' around IPv6 addresses
diff --git a/src/tools/socket.rs b/src/tools/socket.rs
deleted file mode 100644
index 01e5edec..00000000
--- a/src/tools/socket.rs
+++ /dev/null
@@ -1,23 +0,0 @@
-use std::os::unix::io::RawFd;
-
-use nix::sys::socket::sockopt::{KeepAlive, TcpKeepIdle};
-use nix::sys::socket::setsockopt;
-
-pub const PROXMOX_BACKUP_TCP_KEEPALIVE_TIME: u32 = 120;
-
-/// Set TCP keepalive time on a socket
-///
-/// See "man 7 tcp" for details.
-///
-/// The default on Linux is 7200 (2 hours) which is far too long for
-/// our backup tools.
-pub fn set_tcp_keepalive(
-    socket_fd: RawFd,
-    tcp_keepalive_time: u32,
-) -> nix::Result<()> {
-
-    setsockopt(socket_fd, KeepAlive, &true)?;
-    setsockopt(socket_fd, TcpKeepIdle, &tcp_keepalive_time)?;
-
-    Ok(())
-}
-- 
2.20.1






More information about the pbs-devel mailing list