pub(crate) fn open(
        &mut self,
        parent_size: u64,
    ) -> Result<String, ChildError> {
        trace!("{}: Opening child device {}", self.parent, self.name);

        // verify the state of the child before we open it
        match self.state() {
            ChildState::Faulted(reason) => {
                error!(
                    "{}: can not open child {} reason {}",
                    self.parent, self.name, reason
                );
                return Err(ChildError::ChildFaulted {});
            }
            ChildState::Open => {
                // the child (should) already be open
                assert_eq!(self.bdev.is_some(), true);
                assert_eq!(self.desc.is_some(), true);
                info!("called open on an already opened child");
                return Ok(self.name.clone());
            }
            _ => {}
        }

        let bdev = self.bdev.as_ref().unwrap();

        let child_size = bdev.size_in_bytes();
        if parent_size > child_size {
            error!(
                "{}: child {} too small, parent size: {} child size: {}",
                self.parent, self.name, parent_size, child_size
            );

            self.set_state(ChildState::ConfigInvalid);
            return Err(ChildError::ChildTooSmall {
                parent_size,
                child_size,
            });
        }

        let desc = Arc::new(Bdev::open_by_name(&bdev.name(), true).map_err(
            |source| {
                self.set_state(Faulted(Reason::CantOpen));
                ChildError::OpenChild {
                    source,
                }
            },
        )?);

        self.desc = Some(desc);

        let cfg = Config::get();
        if cfg.err_store_opts.enable_err_store {
            self.err_store =
                Some(NexusErrStore::new(cfg.err_store_opts.err_store_size));
        };

        self.set_state(ChildState::Open);

        debug!("{}: child {} opened successfully", self.parent, self.name);
        Ok(self.name.clone())
    }
/// Open the child in RW mode and claim the device to be ours. If the child
/// is already opened by someone else (i.e one of the targets) it will
/// error out.
///
/// only devices in the closed or Init state can be opened.
///
/// A child can only be opened if:
///  - it's not faulted
///  - it's not already opened
Open the child in RW mode and claim the device to be ours. If the child
is already opened by someone else  it will
error out.

only devices in the closed or Init state can be opened.

A child can only be opened if:
it's not faulted
it's not already opened
Open the child in RW mode and claim the device to be ours . If the child is already opened by someone else it will error out . only devices in the closed or Init state can be opened . A child can only be opened if : it ' s not faulted it ' s not already opened
pub(crate) fn open(
        &mut self,
        parent_size: u64,
    ) -> Result<String, ChildError> {
        trace!("{}: Opening child device {}", self.parent, self.name);
        // verify the state of the child before we open it
        match self.state() {
            ChildState::Faulted(reason) => {
                error!(
                    "{}: can not open child {} reason {}",
                    self.parent, self.name, reason
                );
                return Err(ChildError::ChildFaulted {});
            }
            ChildState::Open => {
                // the child (should) already be open
                assert_eq!(self.bdev.is_some(), true);
                assert_eq!(self.desc.is_some(), true);
                info!("called open on an already opened child");
                return Ok(self.name.clone());
            }
            _ => {}
        }
        let bdev = self.bdev.as_ref().unwrap();
        let child_size = bdev.size_in_bytes();
        if parent_size > child_size {
            error!(
                "{}: child {} too small, parent size: {} child size: {}",
                self.parent, self.name, parent_size, child_size
            );
            self.set_state(ChildState::ConfigInvalid);
            return Err(ChildError::ChildTooSmall {
                parent_size,
                child_size,
            });
        }
        let desc = Arc::new(Bdev::open_by_name(&bdev.name(), true).map_err(
            |source| {
                self.set_state(Faulted(Reason::CantOpen));
                ChildError::OpenChild {
                    source,
                }
            },
        )?);
        self.desc = Some(desc);
        let cfg = Config::get();
        if cfg.err_store_opts.enable_err_store {
            self.err_store =
                Some(NexusErrStore::new(cfg.err_store_opts.err_store_size));
        };
        self.set_state(ChildState::Open);
        debug!("{}: child {} opened successfully", self.parent, self.name);
        Ok(self.name.clone())
    }
pub ( crate ) fn open ( & mut self , parent_size : u64 , ) -> Result < String , ChildError > { trace ! ( " " self parent self name ) ; // verify the state of the child before we open it match self . state ( ) { ChildState :: Faulted ( reason ) => { error ! ( " " self parent self name reason ) ; return Err ( ChildError :: ChildFaulted { } ) ; } ChildState :: Open => { // the child (should) already be open assert_eq ! ( self bdev is_some ( ) true ) ; assert_eq ! ( self desc is_some ( ) true ) ; info ! ( " " ) ; return Ok ( self . name . clone ( ) ) ; } _ => { } } let bdev = self . bdev . as_ref ( ) . unwrap ( ) ; let child_size = bdev . size_in_bytes ( ) ; if parent_size > child_size { error ! ( " " self parent self name parent_size child_size ) ; self . set_state ( ChildState :: ConfigInvalid ) ; return Err ( ChildError :: ChildTooSmall { parent_size , child_size , } ) ; } let desc = Arc :: new ( Bdev :: open_by_name ( & bdev . name ( ) , true ) . map_err ( | source | { self . set_state ( Faulted ( Reason :: CantOpen ) ) ; ChildError :: OpenChild { source , } } , ) ? ) ; self . desc = Some ( desc ) ; let cfg = Config :: get ( ) ; if cfg . err_store_opts . enable_err_store { self . err_store = Some ( NexusErrStore :: new ( cfg . err_store_opts . err_store_size ) ) ; } ; self . set_state ( ChildState :: Open ) ; debug ! ( " " self parent self name ) ; Ok ( self . name . clone ( ) ) }
Open the child in RW mode and claim the device to be ours.
Open the child in RW mode and claim the device to be ours .
&mut self
parent_size
u64