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
This commit is contained in:
Daniel Veillard 2008-09-02 14:15:42 +00:00
parent 81cb09f9fe
commit 41ce15a586
8 changed files with 59 additions and 17 deletions

View File

@ -1,3 +1,12 @@
Tue Sep 2 16:12:20 CEST 2008 Daniel Veillard <veillard@redhat.com>
* 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 <meyering@redhat.com>
qemu_conf.c: use new function, virFileReadLimFD

View File

@ -210,7 +210,10 @@
or <code>device</code> element. Contains an attribute <code>name</code>
which is the hostname or IP address of the server. May optionally
contain a <code>port</code> attribute for the protocol specific
port number. <span class="since">Since 0.4.1</span></dd><dt><code>format</code></dt><dd>Provides information about the format of the pool. This
port number. <span class="since">Since 0.4.1</span></dd><dt><code>name</code></dt><dd>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.
<span class="since">Since 0.4.5</span></dd><dt><code>format</code></dt><dd>Provides information about the format of the pool. This
contains a single attribute <code>type</code> whose value is
backend specific. This is typically used to indicate filesystem
type, or network filesystem type, or partition table type, or

View File

@ -91,6 +91,11 @@
which is the hostname or IP address of the server. May optionally
contain a <code>port</code> attribute for the protocol specific
port number. <span class="since">Since 0.4.1</span></dd>
<dt><code>name</code></dt>
<dd>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.
<span class="since">Since 0.4.5</span></dd>
<dt><code>format</code></dt>
<dd>Provides information about the format of the pool. This
contains a single attribute <code>type</code> whose value is

View File

@ -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;

View File

@ -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,
},

View File

@ -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," <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)(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;
}

View File

@ -174,6 +174,9 @@ struct _virStoragePoolSource {
/* Or an adapter */
char *adapter;
/* Or a name */
char *name;
int authType; /* virStoragePoolAuthType */
union {
virStoragePoolAuthChap chap;

View File

@ -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, "<pool type='%s'>\n", type);
virBufferVSprintf(&buf, " <name>%s</name>\n", name);
if (srcHost || srcPath || srcDev) {
if (srcHost || srcPath || srcDev || srcName) {
virBufferAddLit(&buf, " <source>\n");
if (srcHost)
virBufferVSprintf(&buf, " <host>%s</host>\n", srcHost);
@ -3063,6 +3065,8 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
virBufferVSprintf(&buf, " <path>%s</path>\n", srcPath);
if (srcDev)
virBufferVSprintf(&buf, " <device>%s</device>\n", srcDev);
if (srcName)
virBufferVSprintf(&buf, " <name>%s</name>\n", srcName);
virBufferAddLit(&buf, " </source>\n");
}