/// Mount Rafs per as to provided mount-info.
Mount Rafs per as to provided mount-info.
Mount Rafs per as to provided mount - info .
pub fn rafs_mount(
    info: MountInfo,
    default_rafs_conf: &RafsConfig,
    vfs: &Arc<Vfs>,
) -> std::io::Result<()> {
    match info.ops.as_str() {
        "mount" => {
            let mut rafs;
            if let Some(source) = info.source.as_ref() {
                let mut file = Box::new(File::open(source).map_err(|e| eother!(e))?)
                    as Box<dyn rafs::RafsIoRead>;
                rafs = match info.config.as_ref() {
                    Some(config) => {
                        let content = std::fs::read_to_string(config).map_err(|e| einval!(e))?;
                        let rafs_conf: RafsConfig =
                            serde_json::from_str(&content).map_err(|e| einval!(e))?;
                        Rafs::new(rafs_conf, &info.mountpoint, &mut file)?
                    }
                    None => Rafs::new(default_rafs_conf.clone(), &info.mountpoint, &mut file)?,
                };
                rafs.import(&mut file, None)?;
                match vfs.mount(Box::new(rafs), &info.mountpoint) {
                    Ok(()) => {
                        info!("rafs mounted");
                        Ok(())
                    }
                    Err(e) => Err(eother!(e)),
                }
            } else {
                Err(eother!("No source was provided!"))
            }
        }
        "umount" => match vfs.umount(&info.mountpoint) {
            Ok(()) => Ok(()),
            Err(e) => Err(e),
        },
        "update" => {
            info!("switch backend");
            let rafs_conf = match info.config.as_ref() {
                Some(config) => {
                    let content = std::fs::read_to_string(config).map_err(|e| einval!(e))?;
                    let rafs_conf: RafsConfig =
                        serde_json::from_str(&content).map_err(|e| einval!(e))?;
                    rafs_conf
                }
                None => {
                    return Err(enoent!("No rafs configuration was provided!"));
                }
            };
            let rootfs = vfs.get_rootfs(&info.mountpoint).map_err(|e| enoent!(e))?;
            let any_fs = rootfs.deref().as_any();
            if let Some(fs_swap) = any_fs.downcast_ref::<Rafs>() {
                if let Some(source) = info.source.as_ref() {
                    let mut file = Box::new(File::open(source).map_err(|e| last_error!(e))?)
                        as Box<dyn rafs::RafsIoRead>;
                    fs_swap
                        .update(&mut file, rafs_conf)
                        .map_err(|e| eother!(e))?;
                    Ok(())
                } else {
                    error!("no info.source is found, invalid mount info {:?}", info);
                    Err(enoent!("No source file was provided!"))
                }
            } else {
                Err(eother!("Can't swap fs"))
            }
        }
        _ => Err(einval!("Invalid op")),
    }
}
pub fn rafs_mount ( info : MountInfo , default_rafs_conf : & RafsConfig , vfs : & Arc < Vfs > , ) -> std :: io :: Result < ( ) > { match info . ops . as_str ( ) { " " => { let mut rafs ; if let Some ( source ) = info . source . as_ref ( ) { let mut file = Box :: new ( File :: open ( source ) . map_err ( | e | eother ! ( e ) ) ? ) as Box < dyn rafs :: RafsIoRead > ; rafs = match info . config . as_ref ( ) { Some ( config ) => { let content = std :: fs :: read_to_string ( config ) . map_err ( | e | einval ! ( e ) ) ? ; let rafs_conf : RafsConfig = serde_json :: from_str ( & content ) . map_err ( | e | einval ! ( e ) ) ? ; Rafs :: new ( rafs_conf , & info . mountpoint , & mut file ) ? } None => Rafs :: new ( default_rafs_conf . clone ( ) , & info . mountpoint , & mut file ) ? , } ; rafs . import ( & mut file , None ) ? ; match vfs . mount ( Box :: new ( rafs ) , & info . mountpoint ) { Ok ( ( ) ) => { info ! ( " " ) ; Ok ( ( ) ) } Err ( e ) => Err ( eother ! ( e ) ) , } } else { Err ( eother ! ( " " ) ) } } " " => match vfs . umount ( & info . mountpoint ) { Ok ( ( ) ) => Ok ( ( ) ) , Err ( e ) => Err ( e ) , } , " " => { info ! ( " " ) ; let rafs_conf = match info . config . as_ref ( ) { Some ( config ) => { let content = std :: fs :: read_to_string ( config ) . map_err ( | e | einval ! ( e ) ) ? ; let rafs_conf : RafsConfig = serde_json :: from_str ( & content ) . map_err ( | e | einval ! ( e ) ) ? ; rafs_conf } None => { return Err ( enoent ! ( " " ) ) ; } } ; let rootfs = vfs . get_rootfs ( & info . mountpoint ) . map_err ( | e | enoent ! ( e ) ) ? ; let any_fs = rootfs . deref ( ) . as_any ( ) ; if let Some ( fs_swap ) = any_fs . downcast_ref :: < Rafs > ( ) { if let Some ( source ) = info . source . as_ref ( ) { let mut file = Box :: new ( File :: open ( source ) . map_err ( | e | last_error ! ( e ) ) ? ) as Box < dyn rafs :: RafsIoRead > ; fs_swap . update ( & mut file , rafs_conf ) . map_err ( | e | eother ! ( e ) ) ? ; Ok ( ( ) ) } else { error ! ( " " info ) ; Err ( enoent ! ( " " ) ) } } else { Err ( eother ! ( " " ) ) } } _ => Err ( einval ! ( " " ) ) , } }
Mount Rafs per as to provided mount-info.
Mount Rafs per as to provided mount - info .
info
MountInfo
default_rafs_conf
&RafsConfig
vfs
&Arc<Vfs>