Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up some clippy allows in logrotate_fs #1071

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions lading/src/generator/file_gen/logrotate_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@
#![allow(clippy::cast_sign_loss)] // TODO remove these clippy allows
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::cast_possible_wrap)]
#![allow(missing_docs)]
#![allow(clippy::missing_panics_doc)]
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::needless_pass_by_value)]

use crate::generator;
use fuser::{
spawn_mount2, BackgroundSession, FileAttr, Filesystem, MountOption, ReplyAttr, ReplyData,
ReplyDirectory, ReplyEntry, Request,
};
use lading_payload::block;
use rand::{rngs::SmallRng, SeedableRng};
use tokio::task;
use tracing::{error, info};
// use lading_payload::block;
use crate::generator;
use nix::libc::{self, ENOENT};
use rand::{rngs::SmallRng, SeedableRng};
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
Expand All @@ -28,6 +21,8 @@ use std::{
sync::{Arc, Mutex, MutexGuard},
time::Duration,
};
use tokio::task::{self, JoinError};
use tracing::{error, info};

mod model;

Expand Down Expand Up @@ -74,6 +69,9 @@ pub enum Error {
/// Failed to convert, value is 0
#[error("Value provided must not be zero")]
Zero,
/// Could not join on task
#[error("Could not join on task: {0}")]
Join(#[from] JoinError),
}

#[derive(Debug)]
Expand All @@ -84,22 +82,25 @@ pub enum Error {
/// to the target _but_ keeps track of how many bytes are written and read
/// during operation.
pub struct Server {
// handles: Vec<JoinHandle<Result<(), Error>>>,
shutdown: lading_signal::Watcher,
background_session: BackgroundSession,
}

impl Server {
/// Create a new instances of `Server`
///
/// # Errors
///
/// Function will error if block cache cannot be built.
///
/// # Panics
///
/// Function will panic if the filesystem cannot be started.
pub fn new(
_: generator::General,
config: Config,
shutdown: lading_signal::Watcher,
) -> Result<Self, Error> {
// TODO spawn a filesystem thread here and not in spin but bubble up any
// errors and make it so that spin waits for the FS thread and also for
// the shutdown signal. We have a synchronous try_recv on the Watcher
// but the way that fuser runs it just blocks the thread and there's no
// place to poll.
let mut rng = SmallRng::from_seed(config.seed);

let total_bytes =
Expand Down Expand Up @@ -148,11 +149,16 @@ impl Server {

#[allow(clippy::cast_precision_loss)]
#[allow(clippy::cast_possible_truncation)]
/// Run the `Server` to completion
///
/// # Errors
///
/// Function will error if it cannot join on filesystem thread.
pub async fn spin(self) -> Result<(), Error> {
self.shutdown.recv().await;

let handle = task::spawn_blocking(|| self.background_session.join());
let _ = handle.await;
let () = handle.await?;

Ok(())
}
Expand Down
Loading