From 75ebc391c3b8b8b42e9a2ad01ac5cecf40dfd7ee Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Tue, 16 Jan 2024 14:33:46 +0100 Subject: [PATCH] fix macOS build using conditional compilation (#6355) Depends on https://github.com/neondatabase/tokio-epoll-uring/pull/32 --- Cargo.lock | 4 ++-- pageserver/src/virtual_file/io_engine.rs | 2 ++ pageserver/src/virtual_file/open_options.rs | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc8c652031f93..e4fc2df80de35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5483,7 +5483,7 @@ dependencies = [ [[package]] name = "tokio-epoll-uring" version = "0.1.0" -source = "git+https://github.com/neondatabase/tokio-epoll-uring.git?branch=main#9c5ea716add1357dc8c180167e43a2ae596eba68" +source = "git+https://github.com/neondatabase/tokio-epoll-uring.git?branch=main#0dd3a2f8bf3239d34a19719ef1a74146c093126f" dependencies = [ "futures", "once_cell", @@ -6049,7 +6049,7 @@ dependencies = [ [[package]] name = "uring-common" version = "0.1.0" -source = "git+https://github.com/neondatabase/tokio-epoll-uring.git?branch=main#9c5ea716add1357dc8c180167e43a2ae596eba68" +source = "git+https://github.com/neondatabase/tokio-epoll-uring.git?branch=main#0dd3a2f8bf3239d34a19719ef1a74146c093126f" dependencies = [ "io-uring", "libc", diff --git a/pageserver/src/virtual_file/io_engine.rs b/pageserver/src/virtual_file/io_engine.rs index 8619cbf661e46..f9e9aa963004d 100644 --- a/pageserver/src/virtual_file/io_engine.rs +++ b/pageserver/src/virtual_file/io_engine.rs @@ -22,6 +22,7 @@ #[strum(serialize_all = "kebab-case")] pub enum IoEngineKind { StdFs, + #[cfg(target_os = "linux")] TokioEpollUring, } @@ -91,6 +92,7 @@ impl IoEngineKind { drop(dst); ((file_guard, buf), res) } + #[cfg(target_os = "linux")] IoEngineKind::TokioEpollUring => { let system = tokio_epoll_uring::thread_local_system().await; let (resources, res) = system.read(file_guard, offset, buf).await; diff --git a/pageserver/src/virtual_file/open_options.rs b/pageserver/src/virtual_file/open_options.rs index eb925327b1e23..1e5ffe15ccfcc 100644 --- a/pageserver/src/virtual_file/open_options.rs +++ b/pageserver/src/virtual_file/open_options.rs @@ -6,6 +6,7 @@ use std::{os::fd::OwnedFd, path::Path}; #[derive(Debug, Clone)] pub enum OpenOptions { StdFs(std::fs::OpenOptions), + #[cfg(target_os = "linux")] TokioEpollUring(tokio_epoll_uring::ops::open_at::OpenOptions), } @@ -13,6 +14,7 @@ impl Default for OpenOptions { fn default() -> Self { match super::io_engine::get() { IoEngineKind::StdFs => Self::StdFs(std::fs::OpenOptions::new()), + #[cfg(target_os = "linux")] IoEngineKind::TokioEpollUring => { Self::TokioEpollUring(tokio_epoll_uring::ops::open_at::OpenOptions::new()) } @@ -30,6 +32,7 @@ impl OpenOptions { OpenOptions::StdFs(x) => { let _ = x.read(read); } + #[cfg(target_os = "linux")] OpenOptions::TokioEpollUring(x) => { let _ = x.read(read); } @@ -42,6 +45,7 @@ impl OpenOptions { OpenOptions::StdFs(x) => { let _ = x.write(write); } + #[cfg(target_os = "linux")] OpenOptions::TokioEpollUring(x) => { let _ = x.write(write); } @@ -54,6 +58,7 @@ impl OpenOptions { OpenOptions::StdFs(x) => { let _ = x.create(create); } + #[cfg(target_os = "linux")] OpenOptions::TokioEpollUring(x) => { let _ = x.create(create); } @@ -66,6 +71,7 @@ impl OpenOptions { OpenOptions::StdFs(x) => { let _ = x.create_new(create_new); } + #[cfg(target_os = "linux")] OpenOptions::TokioEpollUring(x) => { let _ = x.create_new(create_new); } @@ -78,6 +84,7 @@ impl OpenOptions { OpenOptions::StdFs(x) => { let _ = x.truncate(truncate); } + #[cfg(target_os = "linux")] OpenOptions::TokioEpollUring(x) => { let _ = x.truncate(truncate); } @@ -88,6 +95,7 @@ impl OpenOptions { pub(in crate::virtual_file) async fn open(&self, path: &Path) -> std::io::Result { match self { OpenOptions::StdFs(x) => x.open(path).map(|file| file.into()), + #[cfg(target_os = "linux")] OpenOptions::TokioEpollUring(x) => { let system = tokio_epoll_uring::thread_local_system().await; system.open(path, x).await.map_err(|e| match e { @@ -107,6 +115,7 @@ impl std::os::unix::prelude::OpenOptionsExt for OpenOptions { OpenOptions::StdFs(x) => { let _ = x.mode(mode); } + #[cfg(target_os = "linux")] OpenOptions::TokioEpollUring(x) => { let _ = x.mode(mode); } @@ -119,6 +128,7 @@ impl std::os::unix::prelude::OpenOptionsExt for OpenOptions { OpenOptions::StdFs(x) => { let _ = x.custom_flags(flags); } + #[cfg(target_os = "linux")] OpenOptions::TokioEpollUring(x) => { let _ = x.custom_flags(flags); }