1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2021 Ant Group. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0

//! Online upgrade manager for Nydus daemons and filesystems.

use std::convert::{TryFrom, TryInto};
use std::path::PathBuf;

use crate::fs_service::{FsBackendMountCmd, FsBackendUmountCmd};
use crate::Result;

/// Error codes related to upgrade manager.
#[derive(thiserror::Error, Debug)]
pub enum UpgradeMgrError {}

/// FUSE fail-over policies.
#[derive(PartialEq, Eq)]
pub enum FailoverPolicy {
    /// Flush pending requests.
    Flush,
    /// Resend pending requests.
    Resend,
}

impl TryFrom<&str> for FailoverPolicy {
    type Error = std::io::Error;

    fn try_from(p: &str) -> std::result::Result<Self, Self::Error> {
        match p {
            "flush" => Ok(FailoverPolicy::Flush),
            "resend" => Ok(FailoverPolicy::Resend),
            x => Err(einval!(format!("invalid FUSE fail-over mode {}", x))),
        }
    }
}

impl TryFrom<&String> for FailoverPolicy {
    type Error = std::io::Error;

    fn try_from(p: &String) -> std::result::Result<Self, Self::Error> {
        p.as_str().try_into()
    }
}

/// Online upgrade manager.
pub struct UpgradeManager {}

impl UpgradeManager {
    /// Create a new instance of [UpgradeManager].
    pub fn new(_: PathBuf) -> Self {
        UpgradeManager {}
    }

    /// Add a filesystem instance into the upgrade manager.
    pub fn add_mounts_state(&mut self, _cmd: FsBackendMountCmd, _vfs_index: u8) -> Result<()> {
        Ok(())
    }

    /// Update a filesystem instance in the upgrade manager.
    pub fn update_mounts_state(&mut self, _cmd: FsBackendMountCmd) -> Result<()> {
        Ok(())
    }

    /// Remove a filesystem instance from the upgrade manager.
    pub fn remove_mounts_state(&mut self, _cmd: FsBackendUmountCmd) -> Result<()> {
        Ok(())
    }

    /// Disable online upgrade capability.
    pub fn disable_upgrade(&mut self) {}
}

/// Online upgrade utilities for FUSE daemon.
pub mod fusedev_upgrade {
    use super::*;
    use crate::fusedev::FusedevDaemon;

    /// Save state information for a FUSE daemon.
    pub fn save(_daemon: &FusedevDaemon) -> Result<()> {
        Ok(())
    }

    /// Restore state information for a FUSE daemon.
    pub fn restore(_daemon: &FusedevDaemon) -> Result<()> {
        Ok(())
    }
}