LCOV - code coverage report
Current view: top level - pageserver/src/virtual_file - open_options.rs (source / functions) Coverage Total Hit
Test: fabb29a6339542ee130cd1d32b534fafdc0be240.info Lines: 73.3 % 90 66
Test Date: 2024-06-25 13:20:00 Functions: 76.9 % 13 10

            Line data    Source code
       1              : //! Enum-dispatch to the `OpenOptions` type of the respective [`super::IoEngineKind`];
       2              : 
       3              : use super::io_engine::IoEngine;
       4              : use std::{os::fd::OwnedFd, path::Path};
       5              : 
       6              : #[derive(Debug, Clone)]
       7              : pub enum OpenOptions {
       8              :     StdFs(std::fs::OpenOptions),
       9              :     #[cfg(target_os = "linux")]
      10              :     TokioEpollUring(tokio_epoll_uring::ops::open_at::OpenOptions),
      11              : }
      12              : 
      13              : impl Default for OpenOptions {
      14         5721 :     fn default() -> Self {
      15         5721 :         match super::io_engine::get() {
      16            0 :             IoEngine::NotSet => panic!("io engine not set"),
      17         2858 :             IoEngine::StdFs => Self::StdFs(std::fs::OpenOptions::new()),
      18              :             #[cfg(target_os = "linux")]
      19              :             IoEngine::TokioEpollUring => {
      20         2863 :                 Self::TokioEpollUring(tokio_epoll_uring::ops::open_at::OpenOptions::new())
      21              :             }
      22              :         }
      23         5721 :     }
      24              : }
      25              : 
      26              : impl OpenOptions {
      27         5721 :     pub fn new() -> OpenOptions {
      28         5721 :         Self::default()
      29         5721 :     }
      30              : 
      31         4125 :     pub fn read(&mut self, read: bool) -> &mut OpenOptions {
      32         4125 :         match self {
      33         2062 :             OpenOptions::StdFs(x) => {
      34         2062 :                 let _ = x.read(read);
      35         2062 :             }
      36              :             #[cfg(target_os = "linux")]
      37         2063 :             OpenOptions::TokioEpollUring(x) => {
      38         2063 :                 let _ = x.read(read);
      39         2063 :             }
      40              :         }
      41         4125 :         self
      42         4125 :     }
      43              : 
      44         2843 :     pub fn write(&mut self, write: bool) -> &mut OpenOptions {
      45         2843 :         match self {
      46         1419 :             OpenOptions::StdFs(x) => {
      47         1419 :                 let _ = x.write(write);
      48         1419 :             }
      49              :             #[cfg(target_os = "linux")]
      50         1424 :             OpenOptions::TokioEpollUring(x) => {
      51         1424 :                 let _ = x.write(write);
      52         1424 :             }
      53              :         }
      54         2843 :         self
      55         2843 :     }
      56              : 
      57         8119 :     pub fn create(&mut self, create: bool) -> &mut OpenOptions {
      58         8119 :         match self {
      59         4055 :             OpenOptions::StdFs(x) => {
      60         4055 :                 let _ = x.create(create);
      61         4055 :             }
      62              :             #[cfg(target_os = "linux")]
      63         4064 :             OpenOptions::TokioEpollUring(x) => {
      64         4064 :                 let _ = x.create(create);
      65         4064 :             }
      66              :         }
      67         8119 :         self
      68         8119 :     }
      69              : 
      70         5754 :     pub fn create_new(&mut self, create_new: bool) -> &mut OpenOptions {
      71         5754 :         match self {
      72         2874 :             OpenOptions::StdFs(x) => {
      73         2874 :                 let _ = x.create_new(create_new);
      74         2874 :             }
      75              :             #[cfg(target_os = "linux")]
      76         2880 :             OpenOptions::TokioEpollUring(x) => {
      77         2880 :                 let _ = x.create_new(create_new);
      78         2880 :             }
      79              :         }
      80         5754 :         self
      81         5754 :     }
      82              : 
      83         6876 :     pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions {
      84         6876 :         match self {
      85         3434 :             OpenOptions::StdFs(x) => {
      86         3434 :                 let _ = x.truncate(truncate);
      87         3434 :             }
      88              :             #[cfg(target_os = "linux")]
      89         3442 :             OpenOptions::TokioEpollUring(x) => {
      90         3442 :                 let _ = x.truncate(truncate);
      91         3442 :             }
      92              :         }
      93         6876 :         self
      94         6876 :     }
      95              : 
      96       189315 :     pub(in crate::virtual_file) async fn open(&self, path: &Path) -> std::io::Result<OwnedFd> {
      97       189315 :         match self {
      98        97497 :             OpenOptions::StdFs(x) => x.open(path).map(|file| file.into()),
      99              :             #[cfg(target_os = "linux")]
     100        91818 :             OpenOptions::TokioEpollUring(x) => {
     101        91818 :                 let system = super::io_engine::tokio_epoll_uring_ext::thread_local_system().await;
     102        91820 :                 system.open(path, x).await.map_err(|e| match e {
     103            0 :                     tokio_epoll_uring::Error::Op(e) => e,
     104            0 :                     tokio_epoll_uring::Error::System(system) => {
     105            0 :                         std::io::Error::new(std::io::ErrorKind::Other, system)
     106              :                     }
     107        91818 :                 })
     108              :             }
     109              :         }
     110       189315 :     }
     111              : }
     112              : 
     113              : impl std::os::unix::prelude::OpenOptionsExt for OpenOptions {
     114            0 :     fn mode(&mut self, mode: u32) -> &mut OpenOptions {
     115            0 :         match self {
     116            0 :             OpenOptions::StdFs(x) => {
     117            0 :                 let _ = x.mode(mode);
     118            0 :             }
     119              :             #[cfg(target_os = "linux")]
     120            0 :             OpenOptions::TokioEpollUring(x) => {
     121            0 :                 let _ = x.mode(mode);
     122            0 :             }
     123              :         }
     124            0 :         self
     125            0 :     }
     126              : 
     127            0 :     fn custom_flags(&mut self, flags: i32) -> &mut OpenOptions {
     128            0 :         match self {
     129            0 :             OpenOptions::StdFs(x) => {
     130            0 :                 let _ = x.custom_flags(flags);
     131            0 :             }
     132              :             #[cfg(target_os = "linux")]
     133            0 :             OpenOptions::TokioEpollUring(x) => {
     134            0 :                 let _ = x.custom_flags(flags);
     135            0 :             }
     136              :         }
     137            0 :         self
     138            0 :     }
     139              : }
        

Generated by: LCOV version 2.1-beta