/// 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.
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.
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 .
pub(crate) fn open(
        &mut self,
        parent_size: u64,
    ) -> Result<String, ChildError> {
        trace!("{}: Opening child device {}", self.parent, self.name);
        if self.status() == ChildStatus::Faulted {
            return Err(ChildError::ChildFaulted {});
        }
        if self.state != ChildState::Closed && self.state != ChildState::Init {
            return Err(ChildError::ChildNotClosed {});
        }
        if self.bdev.is_none() {
            return Err(ChildError::OpenWithoutBdev {});
        }
        let bdev = self.bdev.as_ref().unwrap();
        let child_size = bdev.size_in_bytes();
        if parent_size > child_size {
            error!(
                "{}: child to small parent size: {} child size: {}",
                self.name, parent_size, child_size
            );
            self.state = ChildState::ConfigInvalid;
            return Err(ChildError::ChildTooSmall {
                parent_size,
                child_size,
            });
        }
        self.desc = Some(Arc::new(
            Bdev::open_by_name(&bdev.name(), true).context(OpenChild {})?,
        ));
        self.bdev_handle = Some(
            BdevHandle::try_from(self.desc.as_ref().unwrap().clone()).unwrap(),
        );
        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.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 ) ; if self . status ( ) == ChildStatus :: Faulted { return Err ( ChildError :: ChildFaulted { } ) ; } if self . state != ChildState :: Closed && self . state != ChildState :: Init { return Err ( ChildError :: ChildNotClosed { } ) ; } if self . bdev . is_none ( ) { return Err ( ChildError :: OpenWithoutBdev { } ) ; } let bdev = self . bdev . as_ref ( ) . unwrap ( ) ; let child_size = bdev . size_in_bytes ( ) ; if parent_size > child_size { error ! ( " " self name parent_size child_size ) ; self . state = ChildState :: ConfigInvalid ; return Err ( ChildError :: ChildTooSmall { parent_size , child_size , } ) ; } self . desc = Some ( Arc :: new ( Bdev :: open_by_name ( & bdev . name ( ) , true ) . context ( OpenChild { } ) ? , ) ) ; self . bdev_handle = Some ( BdevHandle :: try_from ( self . desc . as_ref ( ) . unwrap ( ) . clone ( ) ) . unwrap ( ) , ) ; 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 . 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