From 41ce15a5867851d56e762f860bb9cac54d1e4859 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 2 Sep 2008 14:15:42 +0000 Subject: [PATCH] Adds storage source element for pools * src/storage_backend.h src/storage_backend_logical.c src/storage_conf.c src/storage_conf.h src/virsh.c: Applied patches from David Lively to add storage source elements needed for storage pool * docs/formatstorage.html docs/formatstorage.html.in: associated documentation Daniel --- ChangeLog | 9 +++++++++ docs/formatstorage.html | 5 ++++- docs/formatstorage.html.in | 5 +++++ src/storage_backend.h | 1 + src/storage_backend_logical.c | 11 ++++++----- src/storage_conf.c | 34 +++++++++++++++++++++++++--------- src/storage_conf.h | 3 +++ src/virsh.c | 8 ++++++-- 8 files changed, 59 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 87c3c684bc..3ef2c64ab2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue Sep 2 16:12:20 CEST 2008 Daniel Veillard + + * src/storage_backend.h src/storage_backend_logical.c + src/storage_conf.c src/storage_conf.h src/virsh.c: + Applied patches from David Lively to add storage source + elements needed for storage pool + * docs/formatstorage.html docs/formatstorage.html.in: associated + documentation + Tue Sep 2 12:28:54 CEST 2008 Jim Meyering qemu_conf.c: use new function, virFileReadLimFD diff --git a/docs/formatstorage.html b/docs/formatstorage.html index 4f0027bcd2..9d92b4cfef 100644 --- a/docs/formatstorage.html +++ b/docs/formatstorage.html @@ -210,7 +210,10 @@ or device element. Contains an attribute name which is the hostname or IP address of the server. May optionally contain a port attribute for the protocol specific - port number. Since 0.4.1
format
Provides information about the format of the pool. This + port number. Since 0.4.1
name
Provides the source for pools backed by storage from a + named element (e.g., a logical volume group name). + remote server. Contains a string identifier. + Since 0.4.5
format
Provides information about the format of the pool. This contains a single attribute type whose value is backend specific. This is typically used to indicate filesystem type, or network filesystem type, or partition table type, or diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in index 7ee7bb8669..7cd4731da9 100644 --- a/docs/formatstorage.html.in +++ b/docs/formatstorage.html.in @@ -91,6 +91,11 @@ which is the hostname or IP address of the server. May optionally contain a port attribute for the protocol specific port number. Since 0.4.1
+
name
+
Provides the source for pools backed by storage from a + named element (e.g., a logical volume group name). + remote server. Contains a string identifier. + Since 0.4.5
format
Provides information about the format of the pool. This contains a single attribute type whose value is diff --git a/src/storage_backend.h b/src/storage_backend.h index a06746b396..5ca5d27b53 100644 --- a/src/storage_backend.h +++ b/src/storage_backend.h @@ -53,6 +53,7 @@ enum { VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE = (1<<1), VIR_STORAGE_BACKEND_POOL_SOURCE_DIR = (1<<2), VIR_STORAGE_BACKEND_POOL_SOURCE_ADAPTER = (1<<3), + VIR_STORAGE_BACKEND_POOL_SOURCE_NAME = (1<<4), }; typedef struct _virStorageBackendPoolOptions virStorageBackendPoolOptions; diff --git a/src/storage_backend_logical.c b/src/storage_backend_logical.c index c30323acbf..d182b5e36d 100644 --- a/src/storage_backend_logical.c +++ b/src/storage_backend_logical.c @@ -80,7 +80,7 @@ virStorageBackendLogicalSetActive(virConnectPtr conn, cmdargv[0] = VGCHANGE; cmdargv[1] = on ? "-ay" : "-an"; - cmdargv[2] = pool->def->name; + cmdargv[2] = pool->def->source.name; cmdargv[3] = NULL; if (virRun(conn, cmdargv, NULL) < 0) @@ -213,7 +213,7 @@ virStorageBackendLogicalFindLVs(virConnectPtr conn, LVS, "--separator", ":", "--noheadings", "--units", "b", "--unbuffered", "--nosuffix", "--options", "lv_name,uuid,devices,seg_size,vg_extent_size", - pool->def->name, NULL + pool->def->source.name, NULL }; int exitstatus; @@ -357,7 +357,7 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn, } vgargv[n++] = VGCREATE; - vgargv[n++] = pool->def->name; + vgargv[n++] = pool->def->source.name; pvargv[0] = PVCREATE; pvargv[2] = NULL; @@ -434,7 +434,7 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn, const char *prog[] = { VGS, "--separator", ":", "--noheadings", "--units", "b", "--unbuffered", "--nosuffix", "--options", "vg_size,vg_free", - pool->def->name, NULL + pool->def->source.name, NULL }; int exitstatus; @@ -488,7 +488,7 @@ virStorageBackendLogicalDeletePool(virConnectPtr conn, unsigned int flags ATTRIBUTE_UNUSED) { const char *cmdargv[] = { - VGREMOVE, "-f", pool->def->name, NULL + VGREMOVE, "-f", pool->def->source.name, NULL }; if (virRun(conn, cmdargv, NULL) < 0) @@ -618,6 +618,7 @@ virStorageBackend virStorageBackendLogical = { .deleteVol = virStorageBackendLogicalDeleteVol, .poolOptions = { + .flags = VIR_STORAGE_BACKEND_POOL_SOURCE_NAME, .formatFromString = virStorageBackendLogicalPoolFormatFromString, .formatToString = virStorageBackendLogicalPoolFormatToString, }, diff --git a/src/storage_conf.c b/src/storage_conf.c index 05b68af15b..2f6093beb6 100644 --- a/src/storage_conf.c +++ b/src/storage_conf.c @@ -96,6 +96,7 @@ virStoragePoolDefFree(virStoragePoolDefPtr def) { } VIR_FREE(def->source.devices); VIR_FREE(def->source.dir); + VIR_FREE(def->source.name); if (def->source.authType == VIR_STORAGE_POOL_AUTH_CHAP) { VIR_FREE(def->source.auth.chap.login); @@ -234,7 +235,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn, if (STRNEQ((const char *)root->name, "pool")) { virStorageReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("unknown root element")); + "%s", _("unknown root elementi for storage pool")); goto cleanup; } @@ -248,9 +249,13 @@ virStoragePoolDefParseDoc(virConnectPtr conn, goto cleanup; } - if ((ret->name = virXPathString(conn, "string(/pool/name)", ctxt)) == NULL) { + ret->name = virXPathString(conn, "string(/pool/name)", ctxt); + if (ret->name == NULL && + options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_NAME) + ret->name = virXPathString(conn, "string(/pool/source/name)", ctxt); + if (ret->name == NULL) { virStorageReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("missing name element")); + "%s", _("missing pool source name element")); goto cleanup; } @@ -282,7 +287,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn, if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_HOST) { if ((ret->source.host.name = virXPathString(conn, "string(/pool/source/host/@name)", ctxt)) == NULL) { virStorageReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("missing source host name")); + "%s", _("missing storage pool source host name")); goto cleanup; } } @@ -292,7 +297,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn, if ((nsource = virXPathNodeSet(conn, "/pool/source/device", ctxt, &nodeset)) <= 0) { virStorageReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("cannot extract source devices")); + "%s", _("cannot extract storage pool source devices")); goto cleanup; } if (VIR_ALLOC_N(ret->source.devices, nsource) < 0) { @@ -305,7 +310,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn, if (path == NULL) { VIR_FREE(nodeset); virStorageReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("missing source device path")); + "%s", _("missing storage pool source device path")); goto cleanup; } ret->source.devices[i].path = (char *)path; @@ -316,10 +321,18 @@ virStoragePoolDefParseDoc(virConnectPtr conn, if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DIR) { if ((ret->source.dir = virXPathString(conn, "string(/pool/source/dir/@path)", ctxt)) == NULL) { virStorageReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("missing source path")); + "%s", _("missing storage pool source path")); goto cleanup; } } + if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_NAME) { + ret->source.name = virXPathString(conn, "string(/pool/source/name)", + ctxt); + if (ret->source.name == NULL) { + /* source name defaults to pool name */ + ret->source.name = strdup(ret->name); + } + } authType = virXPathString(conn, "string(/pool/source/auth/@type)", ctxt); @@ -345,7 +358,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn, if ((ret->target.path = virXPathString(conn, "string(/pool/target/path)", ctxt)) == NULL) { virStorageReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("missing target path")); + "%s", _("missing storage pool target path")); goto cleanup; } @@ -499,6 +512,9 @@ virStoragePoolDefFormat(virConnectPtr conn, if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_ADAPTER) && def->source.adapter) virBufferVSprintf(&buf," \n", def->source.adapter); + if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_NAME) && + def->source.name) + virBufferVSprintf(&buf," %s\n", def->source.name); if (options->formatToString) { const char *format = (options->formatToString)(conn, def->source.format); @@ -698,7 +714,7 @@ virStorageVolDefParseDoc(virConnectPtr conn, ret->name = virXPathString(conn, "string(/volume/name)", ctxt); if (ret->name == NULL) { virStorageReportError(conn, VIR_ERR_XML_ERROR, - "%s", _("missing name element")); + "%s", _("missing volume name element")); goto cleanup; } diff --git a/src/storage_conf.h b/src/storage_conf.h index e3577b59ca..3500039dff 100644 --- a/src/storage_conf.h +++ b/src/storage_conf.h @@ -174,6 +174,9 @@ struct _virStoragePoolSource { /* Or an adapter */ char *adapter; + /* Or a name */ + char *name; + int authType; /* virStoragePoolAuthType */ union { virStoragePoolAuthChap chap; diff --git a/src/virsh.c b/src/virsh.c index eb5c659323..1fb07ad8a2 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -3024,6 +3024,7 @@ static const vshCmdOptDef opts_pool_define_as[] = { {"source-host", VSH_OT_DATA, 0, gettext_noop("source-host for underlying storage")}, {"source-path", VSH_OT_DATA, 0, gettext_noop("source path for underlying storage")}, {"source-dev", VSH_OT_DATA, 0, gettext_noop("source device for underlying storage")}, + {"source-name", VSH_OT_DATA, 0, gettext_noop("source name for underlying storage")}, {"target", VSH_OT_DATA, 0, gettext_noop("target for underlying storage")}, {NULL, 0, 0, NULL} }; @@ -3035,7 +3036,7 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr pool; int found; char *xml; - char *name, *type, *srcHost, *srcPath, *srcDev, *target; + char *name, *type, *srcHost, *srcPath, *srcDev, *srcName, *target; virBuffer buf = VIR_BUFFER_INITIALIZER; if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) @@ -3051,11 +3052,12 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd) srcHost = vshCommandOptString(cmd, "source-host", &found); srcPath = vshCommandOptString(cmd, "source-path", &found); srcDev = vshCommandOptString(cmd, "source-dev", &found); + srcName = vshCommandOptString(cmd, "source-name", &found); target = vshCommandOptString(cmd, "target", &found); virBufferVSprintf(&buf, "\n", type); virBufferVSprintf(&buf, " %s\n", name); - if (srcHost || srcPath || srcDev) { + if (srcHost || srcPath || srcDev || srcName) { virBufferAddLit(&buf, " \n"); if (srcHost) virBufferVSprintf(&buf, " %s\n", srcHost); @@ -3063,6 +3065,8 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd) virBufferVSprintf(&buf, " %s\n", srcPath); if (srcDev) virBufferVSprintf(&buf, " %s\n", srcDev); + if (srcName) + virBufferVSprintf(&buf, " %s\n", srcName); virBufferAddLit(&buf, " \n"); } -- 2.47.2