#if WITH_STORAGE_FS
struct _virNetfsDiscoverState {
const char *host;
- virStringList *list;
+ virStoragePoolSourceList list;
};
typedef struct _virNetfsDiscoverState virNetfsDiscoverState;
void *data)
{
virNetfsDiscoverState *state = data;
- virStringList *newItem;
const char *name, *path;
+ virStoragePoolSource *src;
path = groups[0];
return -1;
}
- /* Append new XML desc to list */
-
- if (VIR_ALLOC(newItem) != 0) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("new xml desc"));
+ if (VIR_REALLOC_N(state->list.sources, state->list.nsources+1) < 0) {
+ virStorageReportError(conn, VIR_ERR_NO_MEMORY, NULL);
return -1;
}
+ memset(state->list.sources + state->list.nsources, 0, sizeof(*state->list.sources));
- if (asprintf(&newItem->val,
- "<source><host name='%s'/><dir path='%s'/></source>",
- state->host, path) <= 0) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", _("asprintf failed"));
- VIR_FREE(newItem);
+ src = state->list.sources + state->list.nsources++;
+ if (!(src->host.name = strdup(state->host)) ||
+ !(src->dir = strdup(path)))
return -1;
- }
-
- newItem->len = strlen(newItem->val);
- newItem->next = state->list;
- state->list = newItem;
+ src->format = VIR_STORAGE_POOL_NETFS_NFS;
return 0;
}
};
xmlDocPtr doc = NULL;
xmlXPathContextPtr xpath_ctxt = NULL;
- virNetfsDiscoverState state = { .host = NULL, .list = NULL };
+ virNetfsDiscoverState state = {
+ .host = NULL,
+ .list = {
+ .type = VIR_STORAGE_POOL_NETFS,
+ .nsources = 0,
+ .sources = NULL
+ }
+ };
const char *prog[] = { SHOWMOUNT, "--no-headers", "--exports", NULL, NULL };
int exitstatus;
char *retval = NULL;
+ unsigned int i;
doc = xmlReadDoc((const xmlChar *)srcSpec, "srcSpec.xml", NULL,
XML_PARSE_NOENT | XML_PARSE_NONET |
&state, &exitstatus) < 0)
goto cleanup;
- retval = __virStringListJoin(state.list, SOURCES_START_TAG,
- SOURCES_END_TAG, "\n");
+ retval = virStoragePoolSourceListFormat(conn, &state.list);
if (retval == NULL) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("retval"));
goto cleanup;
}
cleanup:
+ for (i = 0; i < state.list.nsources; i++)
+ virStoragePoolSourceFree(&state.list.sources[i]);
+
+ VIR_FREE(state.list.sources);
+ VIR_FREE(state.host);
+
xmlFreeDoc(doc);
xmlXPathFreeContext(xpath_ctxt);
- VIR_FREE(state.host);
- __virStringListFree(state.list);
return retval;
}
return NULL;
}
+static int
+virStoragePoolSourceFormat(virConnectPtr conn,
+ virBufferPtr buf,
+ virStorageBackendPoolOptionsPtr options,
+ virStoragePoolSourcePtr src)
+{
+ int i, j;
+
+ virBufferAddLit(buf," <source>\n");
+ if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_HOST) &&
+ src->host.name)
+ virBufferVSprintf(buf," <host name='%s'/>\n", src->host.name);
+
+ if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE) &&
+ src->ndevice) {
+ for (i = 0 ; i < src->ndevice ; i++) {
+ if (src->devices[i].nfreeExtent) {
+ virBufferVSprintf(buf," <device path='%s'>\n",
+ src->devices[i].path);
+ for (j = 0 ; j < src->devices[i].nfreeExtent ; j++) {
+ virBufferVSprintf(buf, " <freeExtent start='%llu' end='%llu'/>\n",
+ src->devices[i].freeExtents[j].start,
+ src->devices[i].freeExtents[j].end);
+ }
+ virBufferAddLit(buf," </device>\n");
+ }
+ else
+ virBufferVSprintf(buf, " <device path='%s'/>\n",
+ src->devices[i].path);
+ }
+ }
+ if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DIR) &&
+ src->dir)
+ virBufferVSprintf(buf," <dir path='%s'/>\n", src->dir);
+ if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_ADAPTER) &&
+ src->adapter)
+ virBufferVSprintf(buf," <adapter name='%s'/>\n", src->adapter);
+ if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_NAME) &&
+ src->name)
+ virBufferVSprintf(buf," <name>%s</name>\n", src->name);
+
+ if (options->formatToString) {
+ const char *format = (options->formatToString)(src->format);
+ if (!format) {
+ virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ _("unknown pool format number %d"),
+ src->format);
+ return -1;
+ }
+ virBufferVSprintf(buf," <format type='%s'/>\n", format);
+ }
+
+
+ if (src->authType == VIR_STORAGE_POOL_AUTH_CHAP)
+ virBufferVSprintf(buf," <auth type='chap' login='%s' passwd='%s'>\n",
+ src->auth.chap.login,
+ src->auth.chap.passwd);
+ virBufferAddLit(buf," </source>\n");
+
+ return 0;
+}
+
char *
virStoragePoolDefFormat(virConnectPtr conn,
virBuffer buf = VIR_BUFFER_INITIALIZER;
const char *type;
char uuid[VIR_UUID_STRING_BUFLEN];
- int i, j;
options = virStorageBackendPoolOptionsForType(def->type);
if (options == NULL)
virBufferVSprintf(&buf," <available>%llu</available>\n",
def->available);
- virBufferAddLit(&buf," <source>\n");
- if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_HOST) &&
- def->source.host.name)
- virBufferVSprintf(&buf," <host name='%s'/>\n", def->source.host.name);
-
- if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE) &&
- def->source.ndevice) {
- for (i = 0 ; i < def->source.ndevice ; i++) {
- if (def->source.devices[i].nfreeExtent) {
- virBufferVSprintf(&buf," <device path='%s'>\n",
- def->source.devices[i].path);
- for (j = 0 ; j < def->source.devices[i].nfreeExtent ; j++) {
- virBufferVSprintf(&buf, " <freeExtent start='%llu' end='%llu'/>\n",
- def->source.devices[i].freeExtents[j].start,
- def->source.devices[i].freeExtents[j].end);
- }
- virBufferAddLit(&buf," </device>\n");
- }
- else
- virBufferVSprintf(&buf, " <device path='%s'/>\n",
- def->source.devices[i].path);
- }
- }
- if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DIR) &&
- def->source.dir)
- virBufferVSprintf(&buf," <dir path='%s'/>\n", def->source.dir);
- if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_ADAPTER) &&
- def->source.adapter)
- virBufferVSprintf(&buf," <adapter name='%s'/>\n", def->source.adapter);
- if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_NAME) &&
- def->source.name)
- virBufferVSprintf(&buf," <name>%s</name>\n", def->source.name);
-
- if (options->formatToString) {
- const char *format = (options->formatToString)(def->source.format);
- if (!format) {
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unknown pool format number %d"),
- def->source.format);
- goto cleanup;
- }
- virBufferVSprintf(&buf," <format type='%s'/>\n", format);
- }
-
-
- if (def->source.authType == VIR_STORAGE_POOL_AUTH_CHAP)
- virBufferVSprintf(&buf," <auth type='chap' login='%s' passwd='%s'>\n",
- def->source.auth.chap.login,
- def->source.auth.chap.passwd);
- virBufferAddLit(&buf," </source>\n");
+ if (virStoragePoolSourceFormat(conn, &buf, options, &def->source) < 0)
+ goto cleanup;
virBufferAddLit(&buf," <target>\n");
return 0;
}
-char *virStoragePoolSourceListFormat(virConnectPtr conn ATTRIBUTE_UNUSED,
+char *virStoragePoolSourceListFormat(virConnectPtr conn,
virStoragePoolSourceListPtr def)
{
- int i, j;
+ virStorageBackendPoolOptionsPtr options;
virBuffer buf = VIR_BUFFER_INITIALIZER;
+ const char *type;
+ int i;
- virBufferAddLit(&buf, "<sources>");
+ options = virStorageBackendPoolOptionsForType(def->type);
+ if (options == NULL)
+ return NULL;
+
+ type = virStorageBackendToString(def->type);
+ if (!type) {
+ virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ "%s", _("unexpected pool type"));
+ goto cleanup;
+ }
+
+ virBufferAddLit(&buf, "<sources>\n");
for (i = 0; i < def->nsources; i++) {
- virBufferVSprintf(&buf, "<source><name>%s</name>", def->sources[i].name);
- for (j = 0; j < def->sources[i].ndevice; j++)
- virBufferVSprintf(&buf, "<device path='%s'/>", def->sources[i].devices[j].path);
- virBufferAddLit(&buf, "</source>");
+ virStoragePoolSourceFormat(conn, &buf, options, &def->sources[i]);
}
- virBufferAddLit(&buf, "</sources>");
+ virBufferAddLit(&buf, "</sources>\n");
+
+ if (virBufferError(&buf))
+ goto no_memory;
return virBufferContentAndReset(&buf);
+
+ no_memory:
+ virStorageReportError(conn, VIR_ERR_NO_MEMORY, NULL);
+ cleanup:
+ free(virBufferContentAndReset(&buf));
+ return NULL;
}