FreeBSD/sys/geom/virstor/g_virstor.c
/**
 * Utility function: encode & write metadata. Assumes topology lock is
 * held.
 *
 * There is no useful way of recovering from errors in this function,
 * not involving panicking the kernel. If the metadata cannot be written
 * the most we can do is notify the operator and hope he spots it and
 * replaces the broken drive.
 */
Utility function: encode & write metadata. Assumes topology lock is
held.

There is no useful way of recovering from errors in this function,
not involving panicking the kernel. If the metadata cannot be written
the most we can do is notify the operator and hope he spots it and
replaces the broken drive.
Utility function : encode & write metadata . Assumes topology lock is held . There is no useful way of recovering from errors in this function not involving panicking the kernel . If the metadata cannot be written the most we can do is notify the operator and hope he spots it and replaces the broken drive .
static void
write_metadata(struct g_consumer *cp, struct g_virstor_metadata *md)
{
	struct g_provider *pp;
	char *buf;
	int error;
	KASSERT(cp != NULL && md != NULL && cp->provider != NULL,
	    ("Something's fishy in %s", __func__));
	LOG_MSG(LVL_DEBUG, "Writing metadata on %s", cp->provider->name);
	g_topology_assert();
	error = g_access(cp, 0, 1, 0);
	if (error != 0) {
		LOG_MSG(LVL_ERROR, "g_access(0,1,0) failed for %s: %d",
		    cp->provider->name, error);
		return;
	}
	pp = cp->provider;
	buf = malloc(pp->sectorsize, M_GVIRSTOR, M_WAITOK);
	virstor_metadata_encode(md, buf);
	g_topology_unlock();
	error = g_write_data(cp, pp->mediasize - pp->sectorsize, buf,
	    pp->sectorsize);
	g_topology_lock();
	g_access(cp, 0, -1, 0);
	free(buf, M_GVIRSTOR);
	if (error != 0)
		LOG_MSG(LVL_ERROR, "Error %d writing metadata to %s",
		    error, cp->provider->name);
}
static void write_metadata ( struct g_consumer * cp , struct g_virstor_metadata * md ) { struct g_provider * pp ; char * buf ; int error ; KASSERT ( cp != NULL && md != NULL && cp -> provider != NULL , ( " " , __func__ ) ) ; LOG_MSG ( LVL_DEBUG , " " , cp -> provider -> name ) ; g_topology_assert ( ) ; error = g_access ( cp , 0 , 1 , 0 ) ; if ( error != 0 ) { LOG_MSG ( LVL_ERROR , " " , cp -> provider -> name , error ) ; return ; } pp = cp -> provider ; buf = malloc ( pp -> sectorsize , M_GVIRSTOR , M_WAITOK ) ; virstor_metadata_encode ( md , buf ) ; g_topology_unlock ( ) ; error = g_write_data ( cp , pp -> mediasize - pp -> sectorsize , buf , pp -> sectorsize ) ; g_topology_lock ( ) ; g_access ( cp , 0 , -1 , 0 ) ; free ( buf , M_GVIRSTOR ) ; if ( error != 0 ) LOG_MSG ( LVL_ERROR , " " , error , cp -> provider -> name ) ; }
Utility function: encode & write metadata.
Utility function : encode & write metadata .