pub async fn nexus_create(
    name: &str,
    size: u64,
    uuid: Option<&str>,
    children: &[String],
) -> Result<(), Error> {
    // global variable defined in the nexus module
    let nexus_list = instances();
    if nexus_list.iter().any(|n| n.name == name) {
        // instead of error we return Ok without making sure that also the
        // children are the same, which seems wrong
        return Ok(());
    }

    let mut ni = Nexus::new(name, size, uuid, None);

    for child in children {
        if let Err(err) = ni.create_and_register(child).await {
            ni.destroy_children().await;
            return Err(err).context(CreateChild {
                name: ni.name.clone(),
            });
        }
    }

    match ni.open().await {
        // we still have code that waits for children to come online
        // this however only works for config files so we need to clean up
        // if we get the below error
        Err(Error::NexusIncomplete {
            ..
        }) => {
            info!("deleting nexus due to missing children");
            for child in children {
                if let Err(e) = bdev_destroy(child).await {
                    error!("failed to destroy child during cleanup {}", e);
                }
            }

            return Err(Error::NexusCreate {
                name: String::from(name),
            });
        }

        Err(e) => {
            error!("{:?}", e);
            return Err(e);
        }

        Ok(_) => nexus_list.push(ni),
    }
    Ok(())
}
/// If we fail to create one of the children we will fail the whole operation
/// destroy any created children and return the error. Once created, and we
/// bring the nexus online, there still might be a configuration mismatch that
/// would prevent the nexus to come online. We can only determine this
/// (currently) when online, so we check the errors twice for now.
If we fail to create one of the children we will fail the whole operation
destroy any created children and return the error. Once created, and we
bring the nexus online, there still might be a configuration mismatch that
would prevent the nexus to come online. We can only determine this
(currently) when online, so we check the errors twice for now.
If we fail to create one of the children we will fail the whole operation destroy any created children and return the error . Once created and we bring the nexus online there still might be a configuration mismatch that would prevent the nexus to come online . We can only determine this ( currently ) when online so we check the errors twice for now .
pub async fn nexus_create(
    name: &str,
    size: u64,
    uuid: Option<&str>,
    children: &[String],
) -> Result<(), Error> {
    // global variable defined in the nexus module
    let nexus_list = instances();
    if nexus_list.iter().any(|n| n.name == name) {
        // instead of error we return Ok without making sure that also the
        // children are the same, which seems wrong
        return Ok(());
    }
    let mut ni = Nexus::new(name, size, uuid, None);
    for child in children {
        if let Err(err) = ni.create_and_register(child).await {
            ni.destroy_children().await;
            return Err(err).context(CreateChild {
                name: ni.name.clone(),
            });
        }
    }
    match ni.open().await {
        // we still have code that waits for children to come online
        // this however only works for config files so we need to clean up
        // if we get the below error
        Err(Error::NexusIncomplete {
            ..
        }) => {
            info!("deleting nexus due to missing children");
            for child in children {
                if let Err(e) = bdev_destroy(child).await {
                    error!("failed to destroy child during cleanup {}", e);
                }
            }
            return Err(Error::NexusCreate {
                name: String::from(name),
            });
        }
        Err(e) => {
            error!("{:?}", e);
            return Err(e);
        }
        Ok(_) => nexus_list.push(ni),
    }
    Ok(())
}
pub async fn nexus_create ( name : & str , size : u64 , uuid : Option < & str > , children : & [ String ] , ) -> Result < ( ) , Error > { // global variable defined in the nexus module let nexus_list = instances ( ) ; if nexus_list . iter ( ) . any ( | n | n . name == name ) { // instead of error we return Ok without making sure that also the // children are the same, which seems wrong return Ok ( ( ) ) ; } let mut ni = Nexus :: new ( name , size , uuid , None ) ; for child in children { if let Err ( err ) = ni . create_and_register ( child ) . await { ni . destroy_children ( ) . await ; return Err ( err ) . context ( CreateChild { name : ni . name . clone ( ) , } ) ; } } match ni . open ( ) . await { // we still have code that waits for children to come online // this however only works for config files so we need to clean up // if we get the below error Err ( Error :: NexusIncomplete { .. } ) => { info ! ( " " ) ; for child in children { if let Err ( e ) = bdev_destroy ( child ) . await { error ! ( " " e ) ; } } return Err ( Error :: NexusCreate { name : String :: from ( name ) , } ) ; } Err ( e ) => { error ! ( " " e ) ; return Err ( e ) ; } Ok ( _ ) => nexus_list . push ( ni ) , } Ok ( ( ) ) }
If we fail to create one of the children we will fail the whole operation
destroy any created children and return the error.
If we fail to create one of the children we will fail the whole operation destroy any created children and return the error .
name
&str
size
u64
uuid
Option<&str>
children
&[String]
name
&str
size
u64
uuid
Option<&str>
children
&[String]