FreeBSD/sys/geom/mirror/g_mirror.c
/*
 * Initialize disk. This means allocate memory, create consumer, attach it
 * to the provider and open access (r1w1e1) to it.
 */
Initialize disk. This means allocate memory, create consumer, attach it
to the provider and open access (r1w1e1) to it.
Initialize disk . This means allocate memory create consumer attach it to the provider and open access ( r1w1e1 ) to it .
static struct g_mirror_disk *
g_mirror_init_disk(struct g_mirror_softc *sc, struct g_provider *pp,
    struct g_mirror_metadata *md, int *errorp)
{
	struct g_mirror_disk *disk;
	int i, error;
	disk = malloc(sizeof(*disk), M_MIRROR, M_NOWAIT | M_ZERO);
	if (disk == NULL) {
		error = ENOMEM;
		goto fail;
	}
	disk->d_softc = sc;
	error = g_mirror_connect_disk(disk, pp);
	if (error != 0)
		goto fail;
	disk->d_id = md->md_did;
	disk->d_state = G_MIRROR_DISK_STATE_NONE;
	disk->d_priority = md->md_priority;
	disk->d_flags = md->md_dflags;
	error = g_getattr("GEOM::candelete", disk->d_consumer, &i);
	if (error == 0 && i != 0)
		disk->d_flags |= G_MIRROR_DISK_FLAG_CANDELETE;
	if (md->md_provider[0] != '\0')
		disk->d_flags |= G_MIRROR_DISK_FLAG_HARDCODED;
	disk->d_sync.ds_consumer = NULL;
	disk->d_sync.ds_offset = md->md_sync_offset;
	disk->d_sync.ds_offset_done = md->md_sync_offset;
	disk->d_genid = md->md_genid;
	disk->d_sync.ds_syncid = md->md_syncid;
	if (errorp != NULL)
		*errorp = 0;
	return (disk);
fail:
	if (errorp != NULL)
		*errorp = error;
	if (disk != NULL)
		free(disk, M_MIRROR);
	return (NULL);
}
static struct g_mirror_disk * g_mirror_init_disk ( struct g_mirror_softc * sc , struct g_provider * pp , struct g_mirror_metadata * md , int * errorp ) { struct g_mirror_disk * disk ; int i , error ; disk = malloc ( sizeof ( * disk ) , M_MIRROR , M_NOWAIT | M_ZERO ) ; if ( disk == NULL ) { error = ENOMEM ; goto fail ; } disk -> d_softc = sc ; error = g_mirror_connect_disk ( disk , pp ) ; if ( error != 0 ) goto fail ; disk -> d_id = md -> md_did ; disk -> d_state = G_MIRROR_DISK_STATE_NONE ; disk -> d_priority = md -> md_priority ; disk -> d_flags = md -> md_dflags ; error = g_getattr ( " " , disk -> d_consumer , & i ) ; if ( error == 0 && i != 0 ) disk -> d_flags |= G_MIRROR_DISK_FLAG_CANDELETE ; if ( md -> md_provider [ 0 ] != ' \0 ' ) disk -> d_flags |= G_MIRROR_DISK_FLAG_HARDCODED ; disk -> d_sync . ds_consumer = NULL ; disk -> d_sync . ds_offset = md -> md_sync_offset ; disk -> d_sync . ds_offset_done = md -> md_sync_offset ; disk -> d_genid = md -> md_genid ; disk -> d_sync . ds_syncid = md -> md_syncid ; if ( errorp != NULL ) * errorp = 0 ; return ( disk ) ; fail : if ( errorp != NULL ) * errorp = error ; if ( disk != NULL ) free ( disk , M_MIRROR ) ; return ( NULL ) ; }
Initialize disk.
Initialize disk .