FreeBSD/sys/geom/virstor/g_virstor.c
/*
 * Generate XML dump of current state
 */
Generate XML dump of current state
Generate XML dump of current state
static void
g_virstor_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
    struct g_consumer *cp, struct g_provider *pp)
{
	struct g_virstor_softc *sc;
	g_topology_assert();
	sc = gp->softc;
	if (sc == NULL || pp != NULL)
		return;
	if (cp != NULL) {
		struct g_virstor_component *comp;
		comp = cp->private;
		if (comp == NULL)
			return;
		sbuf_printf(sb, "%s<ComponentIndex>%u</ComponentIndex>\n",
		    indent, comp->index);
		sbuf_printf(sb, "%s<ChunkCount>%u</ChunkCount>\n",
		    indent, comp->chunk_count);
		sbuf_printf(sb, "%s<ChunksUsed>%u</ChunksUsed>\n",
		    indent, comp->chunk_next);
		sbuf_printf(sb, "%s<ChunksReserved>%u</ChunksReserved>\n",
		    indent, comp->chunk_reserved);
		sbuf_printf(sb, "%s<StorageFree>%u%%</StorageFree>\n",
		    indent,
		    comp->chunk_next > 0 ? 100 -
		    ((comp->chunk_next + comp->chunk_reserved) * 100) /
		    comp->chunk_count : 100);
	} else {
		u_int count, used, i;
		off_t size;
		count = used = size = 0;
		for (i = 0; i < sc->n_components; i++) {
			if (sc->components[i].gcons != NULL) {
				count += sc->components[i].chunk_count;
				used += sc->components[i].chunk_next +
				    sc->components[i].chunk_reserved;
				size += sc->components[i].gcons->
				    provider->mediasize;
			}
		}
		sbuf_printf(sb, "%s<Status>"
		    "Components=%u, Online=%u</Status>\n", indent,
		    sc->n_components, virstor_valid_components(sc));
		sbuf_printf(sb, "%s<State>%u%% physical free</State>\n",
		    indent, 100-(used * 100) / count);
		sbuf_printf(sb, "%s<ChunkSize>%zu</ChunkSize>\n", indent,
		    sc->chunk_size);
		sbuf_printf(sb, "%s<PhysicalFree>%u%%</PhysicalFree>\n",
		    indent, used > 0 ? 100 - (used * 100) / count : 100);
		sbuf_printf(sb, "%s<ChunkPhysicalCount>%u</ChunkPhysicalCount>\n",
		    indent, count);
		sbuf_printf(sb, "%s<ChunkVirtualCount>%zu</ChunkVirtualCount>\n",
		    indent, sc->chunk_count);
		sbuf_printf(sb, "%s<PhysicalBacking>%zu%%</PhysicalBacking>\n",
		    indent,
		    (count * 100) / sc->chunk_count);
		sbuf_printf(sb, "%s<PhysicalBackingSize>%jd</PhysicalBackingSize>\n",
		    indent, size);
		sbuf_printf(sb, "%s<VirtualSize>%jd</VirtualSize>\n", indent,
		    sc->virsize);
	}
}
static void g_virstor_dumpconf ( struct sbuf * sb , const char * indent , struct g_geom * gp , struct g_consumer * cp , struct g_provider * pp ) { struct g_virstor_softc * sc ; g_topology_assert ( ) ; sc = gp -> softc ; if ( sc == NULL || pp != NULL ) return ; if ( cp != NULL ) { struct g_virstor_component * comp ; comp = cp -> private ; if ( comp == NULL ) return ; sbuf_printf ( sb , " \n " , indent , comp -> index ) ; sbuf_printf ( sb , " \n " , indent , comp -> chunk_count ) ; sbuf_printf ( sb , " \n " , indent , comp -> chunk_next ) ; sbuf_printf ( sb , " \n " , indent , comp -> chunk_reserved ) ; sbuf_printf ( sb , " \n " , indent , comp -> chunk_next > 0 ? 100 - ( ( comp -> chunk_next + comp -> chunk_reserved ) * 100 ) / comp -> chunk_count : 100 ) ; } else { u_int count , used , i ; off_t size ; count = used = size = 0 ; for ( i = 0 ; i < sc -> n_components ; i ++ ) { if ( sc -> components [ i ] . gcons != NULL ) { count += sc -> components [ i ] . chunk_count ; used += sc -> components [ i ] . chunk_next + sc -> components [ i ] . chunk_reserved ; size += sc -> components [ i ] . gcons -> provider -> mediasize ; } } sbuf_printf ( sb , " " " \n " , indent , sc -> n_components , virstor_valid_components ( sc ) ) ; sbuf_printf ( sb , " \n " , indent , 100 - ( used * 100 ) / count ) ; sbuf_printf ( sb , " \n " , indent , sc -> chunk_size ) ; sbuf_printf ( sb , " \n " , indent , used > 0 ? 100 - ( used * 100 ) / count : 100 ) ; sbuf_printf ( sb , " \n " , indent , count ) ; sbuf_printf ( sb , " \n " , indent , sc -> chunk_count ) ; sbuf_printf ( sb , " \n " , indent , ( count * 100 ) / sc -> chunk_count ) ; sbuf_printf ( sb , " \n " , indent , size ) ; sbuf_printf ( sb , " \n " , indent , sc -> virsize ) ; } }
Generate XML dump of current state
Generate XML dump of current state
/* For each component */ /* For the whole thing */