Re: [libvirt] [PATCH v8 1/5] virstoragefile: Add helper to get storage source backingStore

2016-01-04 Thread Matthias Gatto
On Wed, Dec 16, 2015 at 12:14 AM, John Ferlan <jfer...@redhat.com> wrote:
> From: Matthias Gatto <matthias.ga...@outscale.com>
>
> Add a new helper - virStorageSourceGetBackingStore - to fetch the storage
> source backingStore pointer in order to make it easier to change the
> future format of the data.
>
> A future patch will adjust the backingStore pointer to become a table or
> array of backingStorePtr's accessible by the argument 'pos'.
>
> For now, if 'pos' > 0, the code will return NULL as if the backingStore
> pointer didn't exist. All callers in subsequent patches will start by
> passing a 0 as the parameter.
>
> Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
> Signed-off-by: John Ferlan <jfer...@redhat.com>
> ---
>  src/libvirt_private.syms  |  1 +
>  src/util/virstoragefile.c | 23 +++
>  src/util/virstoragefile.h |  3 +++
>  3 files changed, 27 insertions(+)
>
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 55822ae..1c55370 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -2196,6 +2196,7 @@ virStorageSourceClear;
>  virStorageSourceCopy;
>  virStorageSourceFree;
>  virStorageSourceGetActualType;
> +virStorageSourceGetBackingStore;
>  virStorageSourceGetSecurityLabelDef;
>  virStorageSourceInitChainElement;
>  virStorageSourceIsEmpty;
> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
> index 2aa1d90..2771c95 100644
> --- a/src/util/virstoragefile.c
> +++ b/src/util/virstoragefile.c
> @@ -1810,6 +1810,29 @@ virStorageSourcePoolDefCopy(const 
> virStorageSourcePoolDef *src)
>
>
>  /**
> + * virStorageSourceGetBackingStore:
> + * @src: virStorageSourcePtr containing the backing stores
> + * @pos: presently unused
> + *
> + * Return the @src backingStore pointer at @pos. For now, @pos is
> + * expected to be 0. A future patch will use @pos index into an array
> + * of storage backingStore pointers
> + *
> + * Returns:
> + * A pointer to the storage source backingStore @pos or
> + * NULL if the backingStore pointer cannot be found
> + */
> +virStorageSourcePtr
> +virStorageSourceGetBackingStore(const virStorageSource *src,
> +size_t pos)
> +{
> +if (!src || pos > 0)
> +return NULL;
> +return src->backingStore;
> +}
> +
> +
> +/**
>   * virStorageSourcePtr:
>   *
>   * Deep-copies a virStorageSource structure. If @backing chain is true
> diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
> index b98fe25..8cd4854 100644
> --- a/src/util/virstoragefile.h
> +++ b/src/util/virstoragefile.h
> @@ -289,6 +289,9 @@ struct _virStorageSource {
>  #  define DEV_BSIZE 512
>  # endif
>
> +virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
> *src,
> +size_t pos);
> +
>  int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
>  int virStorageFileProbeFormatFromBuf(const char *path,
>   char *buf,
> --
> 2.5.0
>

ping

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v7 01/13] virstoragefile: Add virStorageSourceGetBackingStore

2015-12-16 Thread Matthias Gatto
On Mon, Dec 14, 2015 at 10:57 PM, John Ferlan <jfer...@redhat.com> wrote:
>
>
> On 12/03/2015 09:35 AM, Matthias Gatto wrote:
>> Create virStorageSourceGetBackingStore function in
>> preparation for quorum:
>> Actually, if we want to get a backing store inside a virStorageSource
>> we have to do it manually(src->backingStore = backingStore).
>> The problem is that with a quorum, a virStorageSource
>> can contain multiple backing stores, and src->backingStore can
>> be treated as a virStorageSourcePtr or a virStorageSourcePtrPtr.
>>
>> Due to these reason, we need to simplify the manipulation of
>> virStorageSource, and create a function to get the asked
>> backingStore in a virStorageSource
>>
>> For now, this function only return the backingStore field
>
> More simply said -
>
> Create helper virStorageSourceGetBackingStore in order to make it easier
> to access the storage backingStore pointer. Future patches will adjust
> the backingStore pointer to become a table or list of backingStorePtr's
>
>
> [Sure you're doing it because of the quorum changes, but it's
> essentially creating an accessor function]
>>
>> Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
>> ---
>>  src/libvirt_private.syms  |  1 +
>>  src/util/virstoragefile.c | 10 ++
>>  src/util/virstoragefile.h |  3 +++
>>  3 files changed, 14 insertions(+)
>>
>> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
>> index dd085c3..5354a4a 100644
>> --- a/src/libvirt_private.syms
>> +++ b/src/libvirt_private.syms
>> @@ -2190,6 +2190,7 @@ virStorageSourceClear;
>>  virStorageSourceCopy;
>>  virStorageSourceFree;
>>  virStorageSourceGetActualType;
>> +virStorageSourceGetBackingStore;
>>  virStorageSourceGetSecurityLabelDef;
>>  virStorageSourceInitChainElement;
>>  virStorageSourceIsEmpty;
>> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
>> index 2aa1d90..016beaa 100644
>> --- a/src/util/virstoragefile.c
>> +++ b/src/util/virstoragefile.c
>> @@ -1809,6 +1809,16 @@ virStorageSourcePoolDefCopy(const 
>> virStorageSourcePoolDef *src)
>>  }
>>
>>
>> +virStorageSourcePtr
>> +virStorageSourceGetBackingStore(const virStorageSource *src,
>> +size_t pos ATTRIBUTE_UNUSED)
>> +{
>> +if (!src)
>
> I think perhaps Peter's point from his review is
>
> if (!src || pos > 0)
>
> IOW: range checking for pos
>
> Eventually patch 5 will make a real check...
>
> In order to make some progress on this series - at least the first 5 or
> 6 patches - I can make the change if that is what Peter had in mind...
>
> John
>> +return NULL;
>> +return src->backingStore;
>> +}
>> +
>> +
>>  /**
>>   * virStorageSourcePtr:
>>   *
>> diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
>> index b98fe25..8cd4854 100644
>> --- a/src/util/virstoragefile.h
>> +++ b/src/util/virstoragefile.h
>> @@ -289,6 +289,9 @@ struct _virStorageSource {
>>  #  define DEV_BSIZE 512
>>  # endif
>>
>> +virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
>> *src,
>> +size_t pos);
>> +
>>  int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
>>  int virStorageFileProbeFormatFromBuf(const char *path,
>>   char *buf,
>>

Thank you for the review, and your changes on v8.
Sorry for the check, I was thinking it unnecessary because we do it on patch 5.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v7 00/13] qemu: Add quorum support to libvirt

2015-12-14 Thread Matthias Gatto
ping

On Thu, Dec 3, 2015 at 3:35 PM, Matthias Gatto
<matthias.ga...@outscale.com> wrote:
> The purpose of these patches is to introduce quorum for libvirt
> I've try to follow this proposal:
> http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html
>
> This feature ask for 5 task:
>
> 1) Allow a _virStorageSource to contain more than one backing store.
>
> Because all the actual libvirt code use the backingStore field
> as a pointer and we needs want to change that, I've decide to encapsulate
> the backingStore field to simplifie the array manipulation.
>
> 2) Add the missing field a quorum need in _virStorageSource and
> the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
> their respectives enums.
>
> 3) Parse and format the xml
> Because a quorum allows to have more than one backing store at the same level
> we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
> to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
> in a loop.
> virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
> call themself recursively in a loop because a quorum can contain another
> quorum
>
> 4) Build qemu string
> As for the xml, we have to call the function which create quorum recursively.
> But this task have the problem explained here:
> http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
> The _virStorageSource missing some informations that can be passed to
> a child, and therefore this version of quorum is incomplet.
>
> 5) Allow to hotplug/change a disk in a quorum
> This part is not present in these patches because for this task
> we have to use blockdev-add, and currently libvirt use
> device_add for hotpluging that doesn't allow to hotplug quorum childs.
>
>
> V2:
> -Rebase on master
> -Add Documentation
>
> V3:
> -Transforme the backingStore field in virStorageSource into
>  an array of pointer instead of a pointer
> -Modify virStorageSourceSetBackingStore to allow it to expand
>  the backingStore size.
>
> V4:
> -Rebase on master
>
> V5:
> -Rebase on master
> -patch 1-4/9: use patchs from John Ferlan
> -patch 4/9: check return of virStorageSourceSetBackingStore
> -patch 5/9: report type of error on virStorageSourceSetBackingStore
>
> v6:
> -Rebase on master
> -Remove node-name patch
> -patch 06/13: Add virStorageSourceIsRAID
> -patch 10/13: Add virDomainDefHasRAID
> -patch 11-13/13: Block all unsupported operations
>
> v7:
> -Rebase on master.
> -Parse unconditionally backing store.
> -fold qemuBuildRAIDFileSourceStr into qemuBuildRAIDStr.
> -use 0/-1 return values when failing instead of bool.
> -virStorageSourceSetBackingStore now free backing store when they are
> already set.
>
> Matthias Gatto (13):
>   virstoragefile: Add virStorageSourceGetBackingStore
>   virstoragefile: Always use virStorageSourceGetBackingStore to get
> backing store
>   virstoragefile: Add virStorageSourceSetBackingStore
>   virstoragefile: Always use virStorageSourceSetBackingStore to set
> backing store
>   virstoragefile: change backingStore to backingStores.
>   virstoragefile: Add virStorageSourceIsRAID
>   virstoragefile: Add quorum in virstoragefile
>   domain_conf: Read and Write quorum config
>   qemu: Add quorum support in qemuBuildDriveDevStr
>   domain: Add virDomainDefHasRAID
>   qemu: Forbid blocks operations with quorum
>   qemu: qemuDomainGetBlockInfo quorum support
>   qemu: qemuDiskPathToAlias quorum support
>
>  docs/formatdomain.html.in |  23 -
>  docs/schemas/domaincommon.rng |  21 +++-
>  docs/schemas/storagecommon.rng|   1 +
>  docs/schemas/storagevol.rng   |   1 +
>  src/conf/domain_conf.c| 174 
> --
>  src/conf/domain_conf.h|   1 +
>  src/conf/storage_conf.c   |  23 +++--
>  src/libvirt_private.syms  |   4 +
>  src/qemu/qemu_cgroup.c|   4 +-
>  src/qemu/qemu_command.c   |  78 +++
>  src/qemu/qemu_domain.c|   2 +-
>  src/qemu/qemu_driver.c|  72 ++
>  src/qemu/qemu_migration.c |   1 +
>  src/qemu/qemu_monitor_json.c  |   4 +-
>  src/security/security_dac.c   |   2 +-
>  src/security/security_selinux.c   |   4 +-
>  src/security/virt-aa-helper.c |   2 +-
>  src/storage/storage_backend.c |  24 +++--
>  src/storage/storage_backend_fs.c  |  45 +
>

[libvirt] [PATCH v7 13/13] qemu: qemuDiskPathToAlias quorum support

2015-12-03 Thread Matthias Gatto
By adding quorum support to qemuDiskPathToAlias, we're adding support to
qemuDomainGetBlkioParameters, which was returning an error when the domain
was active.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/qemu/qemu_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 44ce90f..69dfed6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16126,7 +16126,7 @@ qemuDiskPathToAlias(virDomainObjPtr vm, const char 
*path, int *idxret)
 if (idxret)
 *idxret = idx;
 
-if (virDomainDiskGetSource(disk)) {
+if (virDomainDiskGetSource(disk) || virStorageSourceIsRAID(disk->src)) {
 if (virAsprintf(, "drive-%s", disk->info.alias) < 0)
 return NULL;
 }
-- 
2.6.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v7 02/13] virstoragefile: Always use virStorageSourceGetBackingStore to get backing store

2015-12-03 Thread Matthias Gatto
Uniformize backing store usage by calling virStorageSourceGetBackingStore
instead of setting backing store manually.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/conf/domain_conf.c|  7 ---
 src/conf/storage_conf.c   |  6 +++---
 src/qemu/qemu_cgroup.c|  4 ++--
 src/qemu/qemu_domain.c|  2 +-
 src/qemu/qemu_driver.c| 18 +
 src/qemu/qemu_monitor_json.c  |  4 +++-
 src/security/security_dac.c   |  2 +-
 src/security/security_selinux.c   |  4 ++--
 src/security/virt-aa-helper.c |  2 +-
 src/storage/storage_backend.c | 22 
 src/storage/storage_backend_fs.c  | 38 ---
 src/storage/storage_backend_gluster.c |  8 +---
 src/storage/storage_backend_logical.c | 12 +++
 src/util/virstoragefile.c | 20 +-
 tests/virstoragetest.c| 14 ++---
 15 files changed, 93 insertions(+), 70 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e6102a0..5b413b5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18625,7 +18625,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
 /* We currently don't output seclabels for backing chain element */
 if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true) < 0 ||
 virDomainDiskBackingStoreFormat(buf,
-backingStore->backingStore,
+
virStorageSourceGetBackingStore(backingStore, 0),
 backingStore->backingStoreRaw,
 idx + 1) < 0)
 return -1;
@@ -18746,7 +18746,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
 /* Don't format backingStore to inactive XMLs until the code for
  * persistent storage of backing chains is ready. */
 if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) &&
-virDomainDiskBackingStoreFormat(buf, def->src->backingStore,
+virDomainDiskBackingStoreFormat(buf,
+
virStorageSourceGetBackingStore(def->src, 0),
 def->src->backingStoreRaw, 1) < 0)
 return -1;
 
@@ -22714,7 +22715,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
 }
 }
 
-for (tmp = disk->src; tmp; tmp = tmp->backingStore) {
+for (tmp = disk->src; tmp; tmp = virStorageSourceGetBackingStore(tmp, 0)) {
 int actualType = virStorageSourceGetActualType(tmp);
 /* execute the callback only for local storage */
 if (actualType != VIR_STORAGE_TYPE_NETWORK &&
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 9b8abea..d048e39 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1330,7 +1330,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 if (virStorageSize(unit, capacity, >target.capacity) < 0)
 goto error;
 } else if (!(flags & VIR_VOL_XML_PARSE_NO_CAPACITY) &&
-   !((flags & VIR_VOL_XML_PARSE_OPT_CAPACITY) && 
ret->target.backingStore)) {
+   !((flags & VIR_VOL_XML_PARSE_OPT_CAPACITY) && 
virStorageSourceGetBackingStore(>target, 0))) {
 virReportError(VIR_ERR_XML_ERROR, "%s", _("missing capacity element"));
 goto error;
 }
@@ -1644,9 +1644,9 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
  >target, "target") < 0)
 goto cleanup;
 
-if (def->target.backingStore &&
+if (virStorageSourceGetBackingStore(>target, 0) &&
 virStorageVolTargetDefFormat(options, ,
- def->target.backingStore,
+ 
virStorageSourceGetBackingStore(>target, 0),
  "backingStore") < 0)
 goto cleanup;
 
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index b52ce3a..6405944 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -121,7 +121,7 @@ qemuSetupDiskCgroup(virDomainObjPtr vm,
 virStorageSourcePtr next;
 bool forceReadonly = false;
 
-for (next = disk->src; next; next = next->backingStore) {
+for (next = disk->src; next; next = virStorageSourceGetBackingStore(next, 
0)) {
 if (qemuSetImageCgroupInternal(vm, next, false, forceReadonly) < 0)
 return -1;
 
@@ -139,7 +139,7 @@ qemuTeardownDiskCgroup(virDomainObjPtr vm,
 {
 virStorageSourcePtr next;
 
-for (next = disk->src; next; next = next->backingStore) {
+for (next = disk->src; next; next = virStorageSourceG

[libvirt] [PATCH v7 04/13] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store

2015-12-03 Thread Matthias Gatto
Replace the parts of the code where a backing store is set manually
with virStorageSourceSetBackingStore

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/conf/domain_conf.c|  3 ++-
 src/conf/storage_conf.c   | 17 ++---
 src/qemu/qemu_driver.c| 17 +++--
 src/storage/storage_backend_fs.c  |  7 +--
 src/storage/storage_backend_gluster.c |  5 +++--
 src/storage/storage_backend_logical.c |  5 +++--
 src/storage/storage_driver.c  |  3 ++-
 src/util/virstoragefile.c |  8 +---
 tests/virstoragetest.c|  4 ++--
 9 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5b413b5..d146811 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6359,7 +6359,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 virDomainDiskBackingStoreParse(ctxt, backingStore) < 0)
 goto cleanup;
 
-src->backingStore = backingStore;
+if (virStorageSourceSetBackingStore(src, backingStore, 0) < 0)
+goto cleanup;
 ret = 0;
 
  cleanup:
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index d048e39..b9db5eb 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1259,6 +1259,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 char *capacity = NULL;
 char *unit = NULL;
 char *backingStore = NULL;
+virStorageSourcePtr backingStorePtr;
 xmlNodePtr node;
 xmlNodePtr *nodes = NULL;
 size_t i;
@@ -1295,20 +1296,22 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 }
 
 if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
-if (VIR_ALLOC(ret->target.backingStore) < 0)
+if (VIR_ALLOC(backingStorePtr) < 0)
 goto error;
 
-ret->target.backingStore->path = backingStore;
+if (virStorageSourceSetBackingStore(>target, backingStorePtr, 0) 
< 0)
+goto error;
+backingStorePtr->path = backingStore;
 backingStore = NULL;
 
 if (options->formatFromString) {
 char *format = 
virXPathString("string(./backingStore/format/@type)", ctxt);
 if (format == NULL)
-ret->target.backingStore->format = options->defaultFormat;
+backingStorePtr->format = options->defaultFormat;
 else
-ret->target.backingStore->format = 
(options->formatFromString)(format);
+backingStorePtr->format = (options->formatFromString)(format);
 
-if (ret->target.backingStore->format < 0) {
+if (backingStorePtr->format < 0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown volume format type %s"), format);
 VIR_FREE(format);
@@ -1317,9 +1320,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 VIR_FREE(format);
 }
 
-if (VIR_ALLOC(ret->target.backingStore->perms) < 0)
+if (VIR_ALLOC(backingStorePtr->perms) < 0)
 goto error;
-if (virStorageDefParsePerms(ctxt, ret->target.backingStore->perms,
+if (virStorageDefParsePerms(ctxt, backingStorePtr->perms,
 "./backingStore/permissions") < 0)
 goto error;
 }
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8ba7566..edfd8e6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14261,13 +14261,18 @@ 
qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes.  */
 need_unlink = false;
 
-newDiskSrc->backingStore = disk->src;
-disk->src = newDiskSrc;
+if (virStorageSourceSetBackingStore(newDiskSrc, disk->src, 0) < 0) {
+ret = -1;
+goto cleanup;
+}
 newDiskSrc = NULL;
 
 if (persistDisk) {
-persistDiskSrc->backingStore = persistDisk->src;
-persistDisk->src = persistDiskSrc;
+if (virStorageSourceSetBackingStore(persistDiskSrc,
+persistDisk->src, 0) < 0) {
+ret = -1;
+goto cleanup;
+}
 persistDiskSrc = NULL;
 }
 
@@ -14310,13 +14315,13 @@ 
qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes. */
 tmp = disk->src;
 disk->src = virStorageSourceGetBackingStore(tmp, 0);
-tmp->backingStore = NULL;
+ignore_value(virStorageSourceSetBackingStore(tmp, NULL, 0));
 virStorageSourceFree(tmp);
 
 if (persistDisk) {
 tmp = persistDisk->src;
 persistDisk->src = vir

[libvirt] [PATCH v7 11/13] qemu: Forbid blocks operations with quorum

2015-12-03 Thread Matthias Gatto
For now we block all blocks operations with RAID disks.

Quorum doesn't support BlockRebase neither, but
qemuDomainBlockRebase call qemuDomainBlockPullCommon or
qemuDomainBlockCopyCommon which are alerady blocked.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/qemu/qemu_driver.c | 28 
 1 file changed, 28 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4a56ebd..d0f7866 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14682,6 +14682,12 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
 if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
 goto cleanup;
 
+if (virDomainDefHasRAID(vm->def)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Snapshot does not support domain with RAID(like 
quorum) yet"));
+goto cleanup;
+}
+
 if (qemuProcessAutoDestroyActive(driver, vm)) {
 virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is marked for auto destroy"));
@@ -16300,6 +16306,13 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver,
 goto endjob;
 disk = vm->def->disks[idx];
 
+if (virStorageSourceIsRAID(disk->src)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("block pull is not yet supported with disk of format 
'%s'"),
+   virStorageFileFormatTypeToString(disk->src->format));
+goto endjob;
+}
+
 if (qemuDomainDiskBlockJobIsActive(disk))
 goto endjob;
 
@@ -16411,6 +16424,13 @@ qemuDomainBlockJobAbort(virDomainPtr dom,
 goto endjob;
 disk = vm->def->disks[idx];
 
+if (virStorageSourceIsRAID(disk->src)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("block job is not yes supported with disk of format 
'%s'"),
+   virStorageFileFormatTypeToString(disk->src->format));
+goto endjob;
+}
+
 if (disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_NONE &&
 disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_READY) {
 virReportError(VIR_ERR_OPERATION_INVALID,
@@ -16702,6 +16722,14 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
_("block copy is not supported with this QEMU binary"));
 goto endjob;
 }
+
+if (virStorageSourceIsRAID(disk->src)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("block copy is not yet supported with disk of format 
'%s'"),
+   virStorageFileFormatTypeToString(disk->src->format));
+goto endjob;
+}
+
 if (vm->persistent) {
 /* XXX if qemu ever lets us start a new domain with mirroring
  * already active, we can relax this; but for now, the risk of
-- 
2.6.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v7 05/13] virstoragefile: change backingStore to backingStores.

2015-12-03 Thread Matthias Gatto
The backingStore field was a virStorageSourcePtr.
Because a quorum can contain more that one backingStore at the same level,
it's now an array of 'virStorageSourcePtr'.

This patch rename  src->backingStore to src->backingStores,
Made the necessary changes to virStorageSourceSetBackingStore
and virStorageSourceGetBackingStore.
virStorageSourceSetBackingStore can now expand the size of src->backingStores.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/storage/storage_backend.c|  2 +-
 src/storage/storage_backend_fs.c |  2 +-
 src/util/virstoragefile.c| 66 +++-
 src/util/virstoragefile.h|  3 +-
 4 files changed, 56 insertions(+), 17 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 08ed1dd..d71bb1a 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -498,7 +498,7 @@ virStorageBackendCreateRaw(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 goto cleanup;
 }
 
-if (vol->target.backingStore) {
+if (vol->target.backingStores) {
 virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("backing storage not supported for raw volumes"));
 goto cleanup;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index b216e91..68419e3 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1100,7 +1100,7 @@ static int createFileDir(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 return -1;
 }
 
-if (vol->target.backingStore) {
+if (vol->target.backingStores) {
 virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("backing storage not supported for directories 
volumes"));
 return -1;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 1299f98..8c05786 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1809,22 +1809,50 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+/**
+ * virStorageSourceGetBackingStore:
+ * @src: virStorageSourcePtr containing the backing stores
+ * @pos: position of the backing store to get
+ *
+ * return the backingStore at the position of @pos
+ */
 virStorageSourcePtr
-virStorageSourceGetBackingStore(const virStorageSource *src,
-size_t pos ATTRIBUTE_UNUSED)
+virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos)
 {
-if (!src)
+if (!src || !src->backingStores || pos >= src->nBackingStores)
 return NULL;
-return src->backingStore;
+return src->backingStores[pos];
 }
 
 
+/**
+ * virStorageSourceSetBackingStore:
+ * @src: virStorageSourcePtr to hold @backingStore
+ * @backingStore: backingStore to store
+ * @pos: position of the backing store to store
+ *
+ * Set @backingStore at @pos in src->backingStores.
+ * If src->backingStores don't have the space to contain
+ * @backingStore, we expand src->backingStores.
+ * If src->backingStores[pos] is alerady set, free it.
+ */
 int
 virStorageSourceSetBackingStore(virStorageSourcePtr src,
 virStorageSourcePtr backingStore,
-size_t pos ATTRIBUTE_UNUSED)
+size_t pos)
 {
-src->backingStore = backingStore;
+if (!src)
+return -1;
+
+if (pos >= src->nBackingStores) {
+int nbr = pos - src->nBackingStores + 1;
+if (VIR_EXPAND_N(src->backingStores, src->nBackingStores, nbr) < 0)
+return -1;
+}
+
+if (src->backingStores[pos])
+virStorageSourceFree(src->backingStores[pos]);
+src->backingStores[pos] = backingStore;
 return 0;
 }
 
@@ -1843,6 +1871,7 @@ virStorageSourceCopy(const virStorageSource *src,
  bool backingChain)
 {
 virStorageSourcePtr ret = NULL;
+size_t i;
 
 if (VIR_ALLOC(ret) < 0)
 return NULL;
@@ -1855,6 +1884,8 @@ virStorageSourceCopy(const virStorageSource *src,
 ret->physical = src->physical;
 ret->readonly = src->readonly;
 ret->shared = src->shared;
+ret->nBackingStores = src->nBackingStores;
+ret->threshold = src->threshold;
 
 /* storage driver metadata are not copied */
 ret->drv = NULL;
@@ -1903,12 +1934,14 @@ virStorageSourceCopy(const virStorageSource *src,
 !(ret->auth = virStorageAuthDefCopy(src->auth)))
 goto error;
 
-if (backingChain && virStorageSourceGetBackingStore(src, 0)) {
-if (virStorageSourceSetBackingStore(ret,
-
virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0),
- true),
- 0) < 0)
-goto err

[libvirt] [PATCH v7 03/13] virstoragefile: Add virStorageSourceSetBackingStore

2015-12-03 Thread Matthias Gatto
As explained for virStorageSourceGetBackingStore, quorum allows
multiple backing store, this make the operation to set bs complex
because we have to check if the backingStore is used as an array
or a pointer, and set it differently in both case.

In order to help the manipulation of backing store, I've added a
function virStorageSourceSetBackingStore.

For now virStorageSourceSetBackingStore don't handle the case where
we have more than one backing store in virStorageSource.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 10 ++
 src/util/virstoragefile.h |  4 
 3 files changed, 15 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5354a4a..d3baee8 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2200,6 +2200,7 @@ virStorageSourceParseRBDColonString;
 virStorageSourcePoolDefFree;
 virStorageSourcePoolModeTypeFromString;
 virStorageSourcePoolModeTypeToString;
+virStorageSourceSetBackingStore;
 virStorageSourceUpdateBlockPhysicalSize;
 virStorageTypeFromString;
 virStorageTypeToString;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index af17d82..a8a2134 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1819,6 +1819,16 @@ virStorageSourceGetBackingStore(const virStorageSource 
*src,
 }
 
 
+int
+virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr backingStore,
+size_t pos ATTRIBUTE_UNUSED)
+{
+src->backingStore = backingStore;
+return 0;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 8cd4854..ce1cb5d 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,10 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+int virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr backingStore,
+size_t pos);
+
 virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
 size_t pos);
 
-- 
2.6.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v7 12/13] qemu: qemuDomainGetBlockInfo quorum support

2015-12-03 Thread Matthias Gatto
Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/qemu/qemu_driver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d0f7866..44ce90f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11834,7 +11834,8 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
 goto endjob;
 }
 
-if (virStorageSourceIsEmpty(disk->src)) {
+if (!virStorageSourceIsRAID(disk->src) &&
+virStorageSourceIsEmpty(disk->src)) {
 virReportError(VIR_ERR_INVALID_ARG,
_("disk '%s' does not currently have a source 
assigned"),
path);
-- 
2.6.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v7 01/13] virstoragefile: Add virStorageSourceGetBackingStore

2015-12-03 Thread Matthias Gatto
Create virStorageSourceGetBackingStore function in
preparation for quorum:
Actually, if we want to get a backing store inside a virStorageSource
we have to do it manually(src->backingStore = backingStore).
The problem is that with a quorum, a virStorageSource
can contain multiple backing stores, and src->backingStore can
be treated as a virStorageSourcePtr or a virStorageSourcePtrPtr.

Due to these reason, we need to simplify the manipulation of
virStorageSource, and create a function to get the asked
backingStore in a virStorageSource

For now, this function only return the backingStore field

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 10 ++
 src/util/virstoragefile.h |  3 +++
 3 files changed, 14 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index dd085c3..5354a4a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2190,6 +2190,7 @@ virStorageSourceClear;
 virStorageSourceCopy;
 virStorageSourceFree;
 virStorageSourceGetActualType;
+virStorageSourceGetBackingStore;
 virStorageSourceGetSecurityLabelDef;
 virStorageSourceInitChainElement;
 virStorageSourceIsEmpty;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 2aa1d90..016beaa 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1809,6 +1809,16 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+virStorageSourcePtr
+virStorageSourceGetBackingStore(const virStorageSource *src,
+size_t pos ATTRIBUTE_UNUSED)
+{
+if (!src)
+return NULL;
+return src->backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index b98fe25..8cd4854 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
+size_t pos);
+
 int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
 int virStorageFileProbeFormatFromBuf(const char *path,
  char *buf,
-- 
2.6.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v7 10/13] domain: Add virDomainDefHasRAID

2015-12-03 Thread Matthias Gatto
This function check if a domain has a RAID as a disk.
This function is useful to block snapshot operations on domain
which contain quorum.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/conf/domain_conf.c   | 13 +
 src/conf/domain_conf.h   |  1 +
 src/libvirt_private.syms |  1 +
 3 files changed, 15 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5178e57..69d916d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2573,6 +2573,19 @@ virDomainDefNewFull(const char *name,
 }
 
 
+bool
+virDomainDefHasRAID(virDomainDefPtr def)
+{
+size_t i;
+
+for (i = 0; i < def->ndisks; ++i) {
+if (virStorageSourceIsRAID(def->disks[i]->src))
+return true;
+}
+return true;
+}
+
+
 void virDomainObjAssignDef(virDomainObjPtr domain,
virDomainDefPtr def,
bool live,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 90d8e13..d193ab4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2560,6 +2560,7 @@ void virDomainDefClearPCIAddresses(virDomainDefPtr def);
 void virDomainDefClearCCWAddresses(virDomainDefPtr def);
 void virDomainDefClearDeviceAliases(virDomainDefPtr def);
 void virDomainTPMDefFree(virDomainTPMDefPtr def);
+bool virDomainDefHasRAID(virDomainDefPtr def);
 
 typedef int (*virDomainDeviceInfoCallback)(virDomainDefPtr def,
virDomainDeviceDefPtr dev,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 571b6f7..a0c1a88 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -219,6 +219,7 @@ virDomainDefGetMemoryInitial;
 virDomainDefGetSecurityLabelDef;
 virDomainDefHasDeviceAddress;
 virDomainDefHasMemoryHotplug;
+virDomainDefHasRAID;
 virDomainDefMaybeAddController;
 virDomainDefMaybeAddInput;
 virDomainDefNeedsPlacementAdvice;
-- 
2.6.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v7 00/13] qemu: Add quorum support to libvirt

2015-12-03 Thread Matthias Gatto
The purpose of these patches is to introduce quorum for libvirt
I've try to follow this proposal:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

This feature ask for 5 task:

1) Allow a _virStorageSource to contain more than one backing store.

Because all the actual libvirt code use the backingStore field
as a pointer and we needs want to change that, I've decide to encapsulate
the backingStore field to simplifie the array manipulation.

2) Add the missing field a quorum need in _virStorageSource and
the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
their respectives enums.

3) Parse and format the xml
Because a quorum allows to have more than one backing store at the same level
we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
in a loop.
virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
call themself recursively in a loop because a quorum can contain another
quorum

4) Build qemu string
As for the xml, we have to call the function which create quorum recursively.
But this task have the problem explained here:
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
The _virStorageSource missing some informations that can be passed to
a child, and therefore this version of quorum is incomplet.

5) Allow to hotplug/change a disk in a quorum
This part is not present in these patches because for this task
we have to use blockdev-add, and currently libvirt use
device_add for hotpluging that doesn't allow to hotplug quorum childs.


V2:
-Rebase on master
-Add Documentation

V3:
-Transforme the backingStore field in virStorageSource into
 an array of pointer instead of a pointer
-Modify virStorageSourceSetBackingStore to allow it to expand
 the backingStore size.

V4:
-Rebase on master

V5:
-Rebase on master
-patch 1-4/9: use patchs from John Ferlan 
-patch 4/9: check return of virStorageSourceSetBackingStore
-patch 5/9: report type of error on virStorageSourceSetBackingStore

v6:
-Rebase on master
-Remove node-name patch
-patch 06/13: Add virStorageSourceIsRAID
-patch 10/13: Add virDomainDefHasRAID
-patch 11-13/13: Block all unsupported operations

v7:
-Rebase on master.
-Parse unconditionally backing store.
-fold qemuBuildRAIDFileSourceStr into qemuBuildRAIDStr.
-use 0/-1 return values when failing instead of bool.
-virStorageSourceSetBackingStore now free backing store when they are
already set.

Matthias Gatto (13):
  virstoragefile: Add virStorageSourceGetBackingStore
  virstoragefile: Always use virStorageSourceGetBackingStore to get
backing store
  virstoragefile: Add virStorageSourceSetBackingStore
  virstoragefile: Always use virStorageSourceSetBackingStore to set
backing store
  virstoragefile: change backingStore to backingStores.
  virstoragefile: Add virStorageSourceIsRAID
  virstoragefile: Add quorum in virstoragefile
  domain_conf: Read and Write quorum config
  qemu: Add quorum support in qemuBuildDriveDevStr
  domain: Add virDomainDefHasRAID
  qemu: Forbid blocks operations with quorum
  qemu: qemuDomainGetBlockInfo quorum support
  qemu: qemuDiskPathToAlias quorum support

 docs/formatdomain.html.in |  23 -
 docs/schemas/domaincommon.rng |  21 +++-
 docs/schemas/storagecommon.rng|   1 +
 docs/schemas/storagevol.rng   |   1 +
 src/conf/domain_conf.c| 174 --
 src/conf/domain_conf.h|   1 +
 src/conf/storage_conf.c   |  23 +++--
 src/libvirt_private.syms  |   4 +
 src/qemu/qemu_cgroup.c|   4 +-
 src/qemu/qemu_command.c   |  78 +++
 src/qemu/qemu_domain.c|   2 +-
 src/qemu/qemu_driver.c|  72 ++
 src/qemu/qemu_migration.c |   1 +
 src/qemu/qemu_monitor_json.c  |   4 +-
 src/security/security_dac.c   |   2 +-
 src/security/security_selinux.c   |   4 +-
 src/security/virt-aa-helper.c |   2 +-
 src/storage/storage_backend.c |  24 +++--
 src/storage/storage_backend_fs.c  |  45 +
 src/storage/storage_backend_gluster.c |  11 ++-
 src/storage/storage_backend_logical.c |  15 ++-
 src/storage/storage_driver.c  |   3 +-
 src/util/virstoragefile.c | 121 ---
 src/util/virstoragefile.h |  15 ++-
 tests/virstoragetest.c|  18 ++--
 25 files changed, 518 insertions(+), 151 deletions(-)

-- 
2.6.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v7 08/13] domain_conf: Read and Write quorum config

2015-12-03 Thread Matthias Gatto
Add the capabiltty to libvirt to parse and format the quorum syntax
as described here:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

We need a different unique index for each backing store
to manipulate individually each child of a quorum.

If a disk have 2 childs A and B, the index will be 1 for A and 2 for B,
but if A have 2 childs C and D, so A will have the index 1, C and D: 2 and 3
and B will be 4.

Here is a representation of our disk tree and they indexs:

 C[2]
/
A[1]
   /\D[3]
HDA
   \
B[4]

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/conf/domain_conf.c | 157 +
 1 file changed, 106 insertions(+), 51 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e2a1870..5178e57 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6306,17 +6306,45 @@ virDomainDiskSourceParse(xmlNodePtr node,
 
 
 static int
+virDomainDiskThresholdParse(virStorageSourcePtr src,
+xmlXPathContextPtr ctxt)
+{
+char *threshold = virXPathString("string(./@threshold)", ctxt);
+int ret;
+
+if (!threshold)
+return 0;
+ret = virStrToLong_ul(threshold, NULL, 10, >threshold);
+if (ret < 0 || src->threshold < 2) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("threshold must be a decimal number greater than 2 "
+ "and less than the number of children"));
+VIR_FREE(threshold);
+return -1;
+}
+VIR_FREE(threshold);
+return 0;
+}
+
+#define VIR_DOMAIN_DISK_BACKING_STORE_PARSE_RECALL 1
+
+static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
-   virStorageSourcePtr src)
+   virStorageSourcePtr src,
+   size_t pos)
 {
 virStorageSourcePtr backingStore = NULL;
 xmlNodePtr save_ctxt = ctxt->node;
 xmlNodePtr source;
 char *type = NULL;
 char *format = NULL;
+char *path;
 int ret = -1;
 
-if (!(ctxt->node = virXPathNode("./backingStore[*]", ctxt))) {
+if (virAsprintf(, "./backingStore[%lu][*]", pos + 1) < 0)
+return -1;
+
+if (!(ctxt->node = virXPathNode(path, ctxt))) {
 ret = 0;
 goto cleanup;
 }
@@ -6350,29 +6378,35 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
-if (!(source = virXPathNode("./source", ctxt))) {
-virReportError(VIR_ERR_XML_ERROR, "%s",
-   _("missing disk backing store source"));
+source = virXPathNode("./source", ctxt);
+
+if (source && virDomainDiskSourceParse(source, ctxt, backingStore) < 0)
 goto cleanup;
-}
 
-if (virDomainDiskSourceParse(source, ctxt, backingStore) < 0 ||
-virDomainDiskBackingStoreParse(ctxt, backingStore) < 0)
+if (virDomainDiskBackingStoreParse(ctxt, backingStore, 0) < 0)
 goto cleanup;
 
-if (virStorageSourceSetBackingStore(src, backingStore, 0) < 0)
+if (virDomainDiskThresholdParse(backingStore, ctxt) < 0)
 goto cleanup;
-ret = 0;
+
+if (virStorageSourceSetBackingStore(src, backingStore, pos) < 0)
+goto cleanup;
+
+ret = VIR_DOMAIN_DISK_BACKING_STORE_PARSE_RECALL;
 
  cleanup:
 if (ret < 0)
 virStorageSourceFree(backingStore);
+VIR_FREE(path);
 VIR_FREE(type);
 VIR_FREE(format);
 ctxt->node = save_ctxt;
-return ret;
+if (ret != VIR_DOMAIN_DISK_BACKING_STORE_PARSE_RECALL)
+return ret;
+return virDomainDiskBackingStoreParse(ctxt, src, pos + 1);
 }
 
+#undef VIR_DOMAIN_DISK_BACKING_STORE_PARSE_RECALL
 
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
@@ -6902,12 +6936,16 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 def->device = VIR_DOMAIN_DISK_DEVICE_DISK;
 }
 
+if (virDomainDiskThresholdParse(def->src, ctxt) < 0)
+goto error;
+
 /* Only CDROM and Floppy devices are allowed missing source path
  * to indicate no media present. LUN is for raw access CD-ROMs
  * that are not attached to a physical device presently */
 if (virStorageSourceIsEmpty(def->src) &&
 (def->device == VIR_DOMAIN_DISK_DEVICE_DISK ||
- (flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE))) {
+ (flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE)) &&
+!(virStorageSourceIsRAID(def->src))) {
 virReportError(VIR_ERR_NO_SOURCE,
target ? "%s" : NULL, target);
 goto error;
@@ -7250,10 +7288,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 }
 
-if (!(flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE)) {
-if (vir

[libvirt] [PATCH v7 07/13] virstoragefile: Add quorum in virstoragefile

2015-12-03 Thread Matthias Gatto
Add VIR_STORAGE_TYPE_QUORUM in virStorageType.
Add VIR_STORAGE_FILE_QUORUM in virStorageFileFormat.

Add threshold value in _virStorageSource

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 docs/formatdomain.html.in  | 23 ---
 docs/schemas/domaincommon.rng  | 21 -
 docs/schemas/storagecommon.rng |  1 +
 docs/schemas/storagevol.rng|  1 +
 src/conf/domain_conf.c |  2 ++
 src/qemu/qemu_command.c|  1 +
 src/qemu/qemu_driver.c |  4 
 src/qemu/qemu_migration.c  |  1 +
 src/util/virstoragefile.c  |  8 ++--
 src/util/virstoragefile.h  |  3 +++
 10 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index a8bd48e..9bef852 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1958,8 +1958,9 @@
 
 Valid values are "file", "block",
 "dir" (since 0.7.5),
-"network" (since 0.8.7), or
-"volume" (since 1.0.5)
+"network" (since 0.8.7),
+"volume" (since 1.0.5), or
+"quorum" (since 1.3.1)
 and refer to the underlying source for the disk.
 
   device attribute
@@ -2025,6 +2026,14 @@
 snapshot='yes' with a transient disk generally
 does not make sense.
 
+  threshold attribute
+  since 1.3.1
+
+Only use with a quorum disk.
+Indicate the minimum of positive vote a quorum must have to 
validate
+a data to be write. The minimum value is "2". The number of 
backingStores
+contain by the quorum must be superior to the threshold.
+
 
   
   source
@@ -2102,6 +2111,11 @@
 
   
   
+type='quorum'
+since 1.3.1
+  
+  A quorum contain no source element, but a serie of backingStores 
instead.
+  
   
 With "file", "block", and "volume", one or more optional
 sub-elements seclabel, described
@@ -2241,7 +2255,10 @@
 property, but using existing external files for snapshot or
 block copy operations requires the end user to pre-create the
 file correctly). The following attributes and sub-elements are
-supported in backingStore:
+supported in.
+Since 1.3.1. This elements is used to
+describe a quorum child.
+backingStore:
 
   type attribute
   
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 8d12606..ee08542 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1240,9 +1240,15 @@
 
   
 
+  
+
+  
+
+  
+
   
 
-  
+  
   
 
   
@@ -1284,9 +1290,22 @@
   
   
   
+  
 
   
 
+  
+
+  
+quorum
+  
+  
+
+  
+
+  
+
+
   
 
   
diff --git a/docs/schemas/storagecommon.rng b/docs/schemas/storagecommon.rng
index 7c04462..0ebc2ef 100644
--- a/docs/schemas/storagecommon.rng
+++ b/docs/schemas/storagecommon.rng
@@ -76,6 +76,7 @@
   fat
   vhd
   ploop
+  quorum
   
 
   
diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 7450547..a718576 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -20,6 +20,7 @@
 dir
 network
 netdir
+quorum
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d146811..e2a1870 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6281,6 +6281,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
 if (virDomainDiskSourcePoolDefParse(node, >srcpool) < 0)
 goto cleanup;
 break;
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -18565,6 +18566,7 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
  skipSeclabels);
 break;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 4ff31dc..7e5a9ab 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3517,6 +3517,7 @@ qemuGetDriveSourceString(virStorageSourcePtr src,
 goto cleanup;
 break;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_VOLUME:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
diff --git a/src/qemu/qemu_driver.c b

[libvirt] [PATCH v7 06/13] virstoragefile: Add virStorageSourceIsRAID

2015-12-03 Thread Matthias Gatto
Add a new function which return true if a virStorageSourcePtr is
a RAID.

For now, quorum is the only RAID we have.

This function is usefull, because, a lot of code access directly
to a virStorageSource internal member (like path) with some functions
like "virDomainDiskGetSource".
This beavious won't work with Quorum, and so we need to add
exeptions for these functions, but I'm not convinced by the idea to add a lot
of "disk->format == QUORUM" in all the code that deserve
exeption for Quorum, so I've add a generic function for this.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 27 +++
 src/util/virstoragefile.h |  2 ++
 3 files changed, 30 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d3baee8..571b6f7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2195,6 +2195,7 @@ virStorageSourceGetSecurityLabelDef;
 virStorageSourceInitChainElement;
 virStorageSourceIsEmpty;
 virStorageSourceIsLocalStorage;
+virStorageSourceIsRAID;
 virStorageSourceNewFromBacking;
 virStorageSourceParseRBDColonString;
 virStorageSourcePoolDefFree;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 8c05786..0d27ca6 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1808,6 +1808,33 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 return NULL;
 }
 
+/**
+ * virStorageSourceIsRAID:
+ * return true if the backingStores field inside @src is use
+ * as a child of a contener
+ */
+bool virStorageSourceIsRAID(virStorageSourcePtr src)
+{
+virStorageType type;
+
+if (!src)
+return false;
+type = virStorageSourceGetActualType(src);
+switch (type) {
+case VIR_STORAGE_TYPE_NONE:
+case VIR_STORAGE_TYPE_FILE:
+case VIR_STORAGE_TYPE_BLOCK:
+case VIR_STORAGE_TYPE_DIR:
+case VIR_STORAGE_TYPE_NETWORK:
+case VIR_STORAGE_TYPE_VOLUME:
+case VIR_STORAGE_TYPE_LAST:
+return false;
+
+case VIR_STORAGE_TYPE_QUORUM:
+return true;
+}
+return false;
+}
 
 /**
  * virStorageSourceGetBackingStore:
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 290c20f..68a21d0 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -290,6 +290,8 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+bool virStorageSourceIsRAID(virStorageSourcePtr src);
+
 int virStorageSourceSetBackingStore(virStorageSourcePtr src,
 virStorageSourcePtr backingStore,
 size_t pos);
-- 
2.6.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v7 09/13] qemu: Add quorum support in qemuBuildDriveDevStr

2015-12-03 Thread Matthias Gatto
Allow libvirt to build the quorum string use by qemu.

Add 2astatic function: qemuBuildRAIDStr

qemuBuildRAIDStr is made because a quorum can have another quorum
as a child, so we may need to call qemuBuildRAIDStr recursively.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/qemu/qemu_command.c | 77 +
 1 file changed, 77 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7e5a9ab..c7d554b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3596,6 +3596,77 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk)
 }
 
 
+static int
+qemuBuildRAIDStr(virConnectPtr conn,
+ virDomainDiskDefPtr disk,
+ virStorageSourcePtr src,
+ virBuffer *opt,
+ const char *prefix)
+{
+char *tmp = NULL;
+int ret;
+virStorageSourcePtr backingStore;
+size_t i;
+int actualType = virStorageSourceGetActualType(src);
+char *source = NULL;
+
+if (actualType == VIR_STORAGE_TYPE_QUORUM) {
+if (!src->threshold) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("threshold missing in the quorum configuration"));
+return -1;
+}
+if (src->nBackingStores < 2) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("a quorum must have at last 2 children"));
+return -1;
+}
+if (src->threshold > src->nBackingStores) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("threshold must not exceed the number of 
children"));
+return -1;
+}
+virBufferAsprintf(opt, ",%svote-threshold=%lu",
+  prefix, src->threshold);
+} else if (actualType == VIR_STORAGE_TYPE_DIR) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("unsupported disk driver type for '%s'"),
+   virStorageFileFormatTypeToString(src->format));
+return -1;
+}
+
+for (i = 0;  i < src->nBackingStores; ++i) {
+backingStore = virStorageSourceGetBackingStore(src, i);
+ret = virAsprintf(, "%schildren.%lu.", prefix, i);
+if (ret < 0)
+return -1;
+
+virBufferAsprintf(opt, ",%schildren.%lu.driver=%s",
+  prefix, i,
+  
virStorageFileFormatTypeToString(backingStore->format));
+
+if (qemuGetDriveSourceString(backingStore, conn, ) < 0)
+goto error;
+
+if (source) {
+virBufferStrcat(opt, ",", tmp, "file.filename=", NULL);
+virBufferAdd(opt, source, -1);
+}
+
+/* This operation avoid us to made another copy */
+if (virStorageSourceIsRAID(backingStore)) {
+if (qemuBuildRAIDStr(conn, disk, backingStore, opt, tmp) < 0)
+goto error;
+}
+VIR_FREE(tmp);
+}
+return 0;
+ error:
+VIR_FREE(tmp);
+return -1;
+}
+
+
 /* Check whether the device address is using either 'ccw' or default s390
  * address format and whether that's "legal" for the current qemu and/or
  * guest os.machine type. This is the corollary to the code which doesn't
@@ -3764,6 +3835,7 @@ qemuBuildDriveStr(virConnectPtr conn,
 goto error;
 
 if (source &&
+!virStorageSourceIsRAID(disk->src) &&
 !((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
   disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
@@ -4110,6 +4182,11 @@ qemuBuildDriveStr(virConnectPtr conn,
   disk->blkdeviotune.size_iops_sec);
 }
 
+if (virStorageSourceIsRAID(disk->src)) {
+if (qemuBuildRAIDStr(conn, disk, disk->src, , "") < 0)
+goto error;
+}
+
 if (virBufferCheckError() < 0)
 goto error;
 
-- 
2.6.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v6 02/13] virstoragefile: Always use virStorageSourceGetBackingStore to get backing store

2015-11-02 Thread Matthias Gatto
On Mon, Nov 2, 2015 at 8:42 AM, Peter Krempa  wrote:

>
>> @@ -99,37 +100,39 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
>>  if (!(target->backingStore = virStorageSourceNewFromBacking(meta)))
>>  goto cleanup;
>>
>> -target->backingStore->format = backingStoreFormat;
>> +backingStore = virStorageSourceGetBackingStore(target, 0);
>> +backingStore->format = backingStoreFormat;
>>
>>  /* XXX: Remote storage doesn't play nicely with volumes backed by
>>   * remote storage. To avoid trouble, just fake the backing store is 
>> RAW
>>   * and put the string from the metadata as the path of the target. 
>> */
>> -if (!virStorageSourceIsLocalStorage(target->backingStore)) {
>> -virStorageSourceFree(target->backingStore);
>> +if (!virStorageSourceIsLocalStorage(backingStore)) {
>> +virStorageSourceFree(backingStore);
>
> So this frees the new backingStore variable, which also corresponds to
> target->backingStore at this point, but ...
>
>>
>> -if (VIR_ALLOC(target->backingStore) < 0)
>> +if (VIR_ALLOC(backingStore) < 0)
>
> ... here only the local copy is allocated, so target->backingStore
> contains an invalid pointer ...
>
>>  goto cleanup;
>>
>> -target->backingStore->type = VIR_STORAGE_TYPE_NETWORK;
>> -target->backingStore->path = meta->backingStoreRaw;
>> +target->backingStore = backingStore;
>> +backingStore->type = VIR_STORAGE_TYPE_NETWORK;
>> +backingStore->path = meta->backingStoreRaw;
>>  meta->backingStoreRaw = NULL;
>> -target->backingStore->format = VIR_STORAGE_FILE_RAW;
>> +backingStore->format = VIR_STORAGE_FILE_RAW;
>>  }
>>
>> -if (target->backingStore->format == VIR_STORAGE_FILE_AUTO) {
>> -if ((rc = virStorageFileProbeFormat(target->backingStore->path,
>> +if (backingStore->format == VIR_STORAGE_FILE_AUTO) {
>> +if ((rc = virStorageFileProbeFormat(backingStore->path,
>>  -1, -1)) < 0) {
>>  /* If the backing file is currently unavailable or is
>>   * accessed via remote protocol only log an error, fake the
>>   * format as RAW and continue. Returning -1 here would
>>   * disable the whole storage pool, making it unavailable for
>>   * even maintenance. */
>> -target->backingStore->format = VIR_STORAGE_FILE_RAW;
>> +backingStore->format = VIR_STORAGE_FILE_RAW;
>>  virReportError(VIR_ERR_INTERNAL_ERROR,
>> _("cannot probe backing volume format: %s"),
>> -   target->backingStore->path);
>> +   backingStore->path);
>>  } else {
>> -target->backingStore->format = rc;
>> +backingStore->format = rc;
>
> ... and I couldn't find a place where you update it back.


>> -target->backingStore->type = VIR_STORAGE_TYPE_NETWORK;
>> -target->backingStore->path = meta->backingStoreRaw;
>> +target->backingStore = backingStore;

I do it here.


Still, you have a good point about temp variables, and long line,
I'm working on this now.

Thank you for the review.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 05/13] virstoragefile: change backingStore to backingStores.

2015-10-29 Thread Matthias Gatto
The backingStore field was a virStorageSourcePtr.
Because a quorum can contain more that one backingStore at the same level,
it's now an array of 'virStorageSourcePtr'.

This patch rename  src->backingStore to src->backingStores,
Made the necessary changes to virStorageSourceSetBackingStore
and virStorageSourceGetBackingStore.
virStorageSourceSetBackingStore can now expand the size of src->backingStores.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/storage/storage_backend.c|  2 +-
 src/storage/storage_backend_fs.c |  2 +-
 src/util/virstoragefile.c| 48 +---
 src/util/virstoragefile.h|  3 ++-
 4 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 3b504e9..f6ed91a 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -497,7 +497,7 @@ virStorageBackendCreateRaw(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 goto cleanup;
 }
 
-if (vol->target.backingStore) {
+if (vol->target.backingStores) {
 virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("backing storage not supported for raw volumes"));
 goto cleanup;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index d065a5f..ef86ecd 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1097,7 +1097,7 @@ static int createFileDir(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 return -1;
 }
 
-if (vol->target.backingStore) {
+if (vol->target.backingStores) {
 virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("backing storage not supported for directories 
volumes"));
 return -1;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index cb96c5b..44bce91 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1809,21 +1809,48 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+/**
+ * virStorageSourceGetBackingStore:
+ * @src: virStorageSourcePtr containing the backing stores
+ * @pos: position of the backing store to get
+ *
+ * return the backingStore at the position of @pos
+ */
 virStorageSourcePtr
-virStorageSourceGetBackingStore(const virStorageSource *src,
-size_t pos ATTRIBUTE_UNUSED)
+virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos)
 {
-return src->backingStore;
+if (!src || !src->backingStores || pos >= src->nBackingStores)
+return NULL;
+return src->backingStores[pos];
 }
 
 
+/**
+ * virStorageSourceSetBackingStore:
+ * @src: virStorageSourcePtr to hold @backingStore
+ * @backingStore: backingStore to store
+ * @pos: position of the backing store to store
+ *
+ * Set @backingStore at @pos in src->backingStores.
+ * If src->backingStores don't have the space to contain
+ * @backingStore, we expand src->backingStores
+ */
 bool
 virStorageSourceSetBackingStore(virStorageSourcePtr src,
 virStorageSourcePtr backingStore,
-size_t pos ATTRIBUTE_UNUSED)
+size_t pos)
 {
-src->backingStore = backingStore;
-return !!src->backingStore;
+if (!src)
+return false;
+
+if (pos >= src->nBackingStores) {
+int nbr = pos - src->nBackingStores + 1;
+if (VIR_EXPAND_N(src->backingStores, src->nBackingStores, nbr) < 0)
+return false;
+}
+
+src->backingStores[pos] = backingStore;
+return true;
 }
 
 
@@ -2038,6 +2065,8 @@ virStorageSourceIsEmpty(virStorageSourcePtr src)
 void
 virStorageSourceBackingStoreClear(virStorageSourcePtr def)
 {
+size_t i;
+
 if (!def)
 return;
 
@@ -2045,8 +2074,11 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr 
def)
 VIR_FREE(def->backingStoreRaw);
 
 /* recursively free backing chain */
-virStorageSourceFree(virStorageSourceGetBackingStore(def, 0));
-virStorageSourceSetBackingStore(def, NULL, 0);
+for (i = 0; i < def->nBackingStores; ++i)
+virStorageSourceFree(virStorageSourceGetBackingStore(def, i));
+if (def->nBackingStores > 0)
+VIR_FREE(def->backingStores);
+def->nBackingStores = 0;
 }
 
 
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 5c5c29d..5f76b4b 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -270,7 +270,8 @@ struct _virStorageSource {
 bool shared;
 
 /* backing chain of the storage source */
-virStorageSourcePtr backingStore;
+virStorageSourcePtr *backingStores;
+size_t  nBackingStores;
 
 /* metadata for storage driver access to remote and local volumes */
 virStorageDriverDataPtr drv;
-- 
2.6.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v6 11/11] quorum: Block snapshot operation with RAID

2015-10-29 Thread Matthias Gatto
On Thu, Oct 29, 2015 at 2:43 PM, Matthias Gatto
<matthias.ga...@outscale.com> wrote:
> For now we block all snapshot operations with quorum, because it would require
> a lot more code, espacially because Qemu doesn't really suport it.
>
> I guess, we can use node-name, and manually snapshoot all qcow from a
> virStorageSource and use this as a quorum's snapshot,
> but libvirt doesn't support node-name, and we don't need node-name
> anymore to use a quorum in qemu.
>
> I actually have some patchs which could partially support quorum snapshot
> on my computer, but nothing suitable to be upstream, so I prefer to have
> a stable versions of quorum inside libvirt before dealling with
> snapshot.
>
> Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
> ---
>  src/qemu/qemu_driver.c | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 25be0d9..0e43966 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -14674,6 +14674,12 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
>  if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
>  goto cleanup;
>
> +if (virDomainDefHasRAID(vm->def)) {
> +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> +   _("Snapshot does not support domain with RAID(like 
> quorum) yet"));
> +goto cleanup;
> +}
> +
>  if (qemuProcessAutoDestroyActive(driver, vm)) {
>  virReportError(VIR_ERR_OPERATION_INVALID,
> "%s", _("domain is marked for auto destroy"));
> --
> 2.6.1
>

Oups, I've send this patch twice, sorry for my mistake.

This one is not the good one, the good one is this one:
http://www.redhat.com/archives/libvir-list/2015-October/msg00863.html

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 01/13] virstoragefile: Add virStorageSourceGetBackingStore

2015-10-29 Thread Matthias Gatto
Create virStorageSourceGetBackingStore function in
preparation for quorum:
Actually, if we want to get a backing store inside a virStorageSource
we have to do it manually(src->backingStore = backingStore).
The problem is that with a quorum, a virStorageSource
can contain multiple backing stores, and src->backingStore can
be treated as a virStorageSourcePtr or a virStorageSourcePtrPtr.

Due to these reason, we need to simplify the manipulation of
virStorageSource, and create a function to get the asked
backingStore in a virStorageSource

For now, this function only return the backingStore field

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/libvirt_private.syms  | 1 +
 src/util/virstoragefile.c | 8 
 src/util/virstoragefile.h | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4b7e165..8854b26 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2163,6 +2163,7 @@ virStorageSourceClear;
 virStorageSourceCopy;
 virStorageSourceFree;
 virStorageSourceGetActualType;
+virStorageSourceGetBackingStore;
 virStorageSourceGetSecurityLabelDef;
 virStorageSourceInitChainElement;
 virStorageSourceIsEmpty;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 2aa1d90..3fad323 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1809,6 +1809,14 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+virStorageSourcePtr
+virStorageSourceGetBackingStore(const virStorageSource *src,
+size_t pos ATTRIBUTE_UNUSED)
+{
+return src->backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index b98fe25..8cd4854 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
+size_t pos);
+
 int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
 int virStorageFileProbeFormatFromBuf(const char *path,
  char *buf,
-- 
2.6.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 06/13] virstoragefile: Add virStorageSourceIsRAID

2015-10-29 Thread Matthias Gatto
Add a new function which return true if a virStorageSourcePtr is
a RAID.

For now, quorum is the only RAID we have.

This function is usefull, because, a lot of code access directly
to a virStorageSource internal member (like path) with some functions
like "virDomainDiskGetSource".
This beavious won't work with Quorum, and so we need to add
exeptions for these functions, but I'm not convinced by the idea to add a lot
of "disk->format == QUORUM" in all the code that deserve
exeption for Quorum, so I've add a generic function for this.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 27 +++
 src/util/virstoragefile.h |  2 ++
 3 files changed, 30 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4aa923a..efcea49 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2168,6 +2168,7 @@ virStorageSourceGetSecurityLabelDef;
 virStorageSourceInitChainElement;
 virStorageSourceIsEmpty;
 virStorageSourceIsLocalStorage;
+virStorageSourceIsRAID;
 virStorageSourceNewFromBacking;
 virStorageSourceParseRBDColonString;
 virStorageSourcePoolDefFree;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 44bce91..a9cc0c8 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1808,6 +1808,33 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 return NULL;
 }
 
+/**
+ * virStorageSourceIsRAID:
+ * return true if the backingStores field inside @src is use
+ * as a child of a contener
+ */
+bool virStorageSourceIsRAID(virStorageSourcePtr src)
+{
+virStorageType type;
+
+if (!src)
+return false;
+type = virStorageSourceGetActualType(src);
+switch (type) {
+case VIR_STORAGE_TYPE_NONE:
+case VIR_STORAGE_TYPE_FILE:
+case VIR_STORAGE_TYPE_BLOCK:
+case VIR_STORAGE_TYPE_DIR:
+case VIR_STORAGE_TYPE_NETWORK:
+case VIR_STORAGE_TYPE_VOLUME:
+case VIR_STORAGE_TYPE_LAST:
+return false;
+
+case VIR_STORAGE_TYPE_QUORUM:
+return true;
+}
+return false;
+}
 
 /**
  * virStorageSourceGetBackingStore:
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 5f76b4b..c9f2afa 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -290,6 +290,8 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+bool virStorageSourceIsRAID(virStorageSourcePtr src);
+
 bool virStorageSourceSetBackingStore(virStorageSourcePtr src,
  virStorageSourcePtr backingStore,
  size_t pos);
-- 
2.6.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 09/13] qemu: Add quorum support in qemuBuildDriveDevStr

2015-10-29 Thread Matthias Gatto
Allow libvirt to build the quorum string used by quemu.

Add 2 static functions: qemuBuildRAIDStr and
qemuBuildRAIDFileSourceStr.
qemuBuildRAIDStr is made because a quorum can have another quorum
as a child, so we may need to call qemuBuildRAIDStr recursively.

qemuBuildRAIDFileSourceStr was basically made to share
the code use to build the source between qemuBuildRAIDStr and
qemuBuildDriveStr, but there is some difference betwin the syntax
use by libvirt to declare a disk and the one qemu need to build a quorum:
a quorum need a syntaxe like:
"domaine_name.children.X.file.filename=filename"
where libvirt don't use "file.filename=" but directly "file=".
Therfore I use this function only for quorum.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/qemu/qemu_command.c | 93 +
 1 file changed, 93 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 50cf8cc..4ca0011 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3612,6 +3612,93 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk)
 return -1;
 }
 
+static bool
+qemuBuildRAIDFileSourceStr(virConnectPtr conn,
+   virStorageSourcePtr src,
+   virBuffer *opt,
+   const char *toAppend)
+{
+char *source = NULL;
+int actualType = virStorageSourceGetActualType(src);
+
+if (qemuGetDriveSourceString(src, conn, ) < 0)
+return false;
+
+if (source) {
+virBufferStrcat(opt, ",", toAppend, "filename=", NULL);
+
+if (actualType == VIR_STORAGE_TYPE_DIR) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("unsupported disk driver type for '%s'"),
+   virStorageFileFormatTypeToString(src->format));
+return false;
+}
+virBufferAdd(opt, source, -1);
+}
+
+return true;
+}
+
+
+static bool
+qemuBuildRAIDStr(virConnectPtr conn,
+ virDomainDiskDefPtr disk,
+ virStorageSourcePtr src,
+ virBuffer *opt,
+ const char *toAppend)
+{
+char *tmp = NULL;
+int ret;
+virStorageSourcePtr backingStore;
+size_t i;
+
+if (virStorageSourceGetActualType(src) == VIR_STORAGE_TYPE_QUORUM) {
+if (!src->threshold) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("threshold missing in the quorum configuration"));
+return false;
+}
+if (src->nBackingStores < 2) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("a quorum must have at last 2 children"));
+return false;
+}
+if (src->threshold > src->nBackingStores) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("threshold must not exceed the number of 
children"));
+return false;
+}
+virBufferAsprintf(opt, ",%svote-threshold=%lu",
+  toAppend, src->threshold);
+}
+
+for (i = 0;  i < src->nBackingStores; ++i) {
+backingStore = virStorageSourceGetBackingStore(src, i);
+ret = virAsprintf(, "%schildren.%lu.file.", toAppend, i);
+if (ret < 0)
+return false;
+
+virBufferAsprintf(opt, ",%schildren.%lu.driver=%s",
+  toAppend, i,
+  
virStorageFileFormatTypeToString(backingStore->format));
+
+if (qemuBuildRAIDFileSourceStr(conn, backingStore, opt, tmp) == false)
+goto error;
+
+/* This operation avoid us to made another copy */
+tmp[ret - sizeof("file")] = '\0';
+if (virStorageSourceIsRAID(backingStore)) {
+if (!qemuBuildRAIDStr(conn, disk, backingStore, opt, tmp))
+goto error;
+}
+VIR_FREE(tmp);
+}
+return true;
+ error:
+VIR_FREE(tmp);
+return false;
+}
+
 
 /* Check whether the device address is using either 'ccw' or default s390
  * address format and whether that's "legal" for the current qemu and/or
@@ -3781,6 +3868,7 @@ qemuBuildDriveStr(virConnectPtr conn,
 goto error;
 
 if (source &&
+!virStorageSourceIsRAID(disk->src) &&
 !((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
   disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
@@ -4132,6 +4220,11 @@ qemuBuildDriveStr(virConnectPtr conn,
   disk->blkdeviotune.size_iops_sec);
 }
 
+if (virStorageSourceIsRAID(disk->src)) {
+if (!qemuBuildRAIDStr(conn, disk, disk->src, , ""))
+goto error;
+}
+
 if (virBufferCheckError() < 0)
 goto error;
 
-- 
2.6.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 04/13] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store

2015-10-29 Thread Matthias Gatto
Replace the parts of the code where a backing store is set manually
with virStorageSourceSetBackingStore

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/conf/domain_conf.c|  3 ++-
 src/conf/storage_conf.c   | 17 ++---
 src/qemu/qemu_driver.c| 17 +++--
 src/storage/storage_backend_fs.c  |  7 +--
 src/storage/storage_backend_gluster.c |  5 +++--
 src/storage/storage_backend_logical.c |  9 ++---
 src/storage/storage_driver.c  |  3 ++-
 src/util/virstoragefile.c |  8 +---
 tests/virstoragetest.c|  4 ++--
 9 files changed, 46 insertions(+), 27 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e0befc3..101cfeb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6661,7 +6661,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 virDomainDiskBackingStoreParse(ctxt, backingStore) < 0)
 goto cleanup;
 
-src->backingStore = backingStore;
+if (!virStorageSourceSetBackingStore(src, backingStore, 0))
+goto cleanup;
 ret = 0;
 
  cleanup:
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index d048e39..183c80c 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1259,6 +1259,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 char *capacity = NULL;
 char *unit = NULL;
 char *backingStore = NULL;
+virStorageSourcePtr backingStorePtr;
 xmlNodePtr node;
 xmlNodePtr *nodes = NULL;
 size_t i;
@@ -1295,20 +1296,22 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 }
 
 if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
-if (VIR_ALLOC(ret->target.backingStore) < 0)
+if (VIR_ALLOC(backingStorePtr) < 0)
 goto error;
 
-ret->target.backingStore->path = backingStore;
+if (!virStorageSourceSetBackingStore(>target, backingStorePtr, 0))
+goto error;
+backingStorePtr->path = backingStore;
 backingStore = NULL;
 
 if (options->formatFromString) {
 char *format = 
virXPathString("string(./backingStore/format/@type)", ctxt);
 if (format == NULL)
-ret->target.backingStore->format = options->defaultFormat;
+backingStorePtr->format = options->defaultFormat;
 else
-ret->target.backingStore->format = 
(options->formatFromString)(format);
+backingStorePtr->format = (options->formatFromString)(format);
 
-if (ret->target.backingStore->format < 0) {
+if (backingStorePtr->format < 0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown volume format type %s"), format);
 VIR_FREE(format);
@@ -1317,9 +1320,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 VIR_FREE(format);
 }
 
-if (VIR_ALLOC(ret->target.backingStore->perms) < 0)
+if (VIR_ALLOC(backingStorePtr->perms) < 0)
 goto error;
-if (virStorageDefParsePerms(ctxt, ret->target.backingStore->perms,
+if (virStorageDefParsePerms(ctxt, backingStorePtr->perms,
 "./backingStore/permissions") < 0)
 goto error;
 }
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ac45d56..cbc508c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14253,13 +14253,18 @@ 
qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes.  */
 need_unlink = false;
 
-newDiskSrc->backingStore = disk->src;
-disk->src = newDiskSrc;
+if (!virStorageSourceSetBackingStore(newDiskSrc, disk->src, 0)) {
+ret = -1;
+goto cleanup;
+}
 newDiskSrc = NULL;
 
 if (persistDisk) {
-persistDiskSrc->backingStore = persistDisk->src;
-persistDisk->src = persistDiskSrc;
+if (!virStorageSourceSetBackingStore(persistDiskSrc,
+ persistDisk->src, 0)) {
+ret = -1;
+goto cleanup;
+}
 persistDiskSrc = NULL;
 }
 
@@ -14302,13 +14307,13 @@ 
qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes. */
 tmp = disk->src;
 disk->src = virStorageSourceGetBackingStore(tmp, 0);
-tmp->backingStore = NULL;
+ignore_value(virStorageSourceSetBackingStore(tmp, NULL, 0));
 virStorageSourceFree(tmp);
 
 if (persistDisk) {
 tmp = persistDisk->src;
 persistDisk->src = virStorageSourceGetBack

[libvirt] [PATCH v6 00/13] qemu: Add quorum support to libvirt

2015-10-29 Thread Matthias Gatto
The purpose of these patches is to introduce quorum for libvirt
I've try to follow this proposal:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

This feature ask for 6 task:

1) Allow a _virStorageSource to contain more than one backing store.

Because all the actual libvirt code use the backingStore field
as a pointer and we needs want to change that, I've decide to encapsulate
the backingStore field to simplifie the array manipulation.

2) Add the missing field a quorum need in _virStorageSource and
the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
their respectives enums.

3) Parse and format the xml
Because a quorum allows to have more than one backing store at the same level
we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
in a loop.
virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
call themself recursively in a loop because a quorum can contain another
quorum

4) Build qemu string
As for the xml, we have to call the function which create quorum recursively.
But this task have the problem explained here:
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
The _virStorageSource missing some informations that can be passed to
a child, and therefore this version of quorum is incomplet.

5) Allow to hotplug/change a disk in a quorum
This part is not present in these patches because for this task
we have to use blockdev-add, and currently libvirt use
device_add for hotpluging that doesn't allow to hotplug quorum childs.

There is 3 way to handle this problem:
  1) create a virDomainBlockDevAdd function in libvirt witch call
 blockdev-add.

  2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice

  3) write a hack which uses blockdev-add only when attaching a quorum child

V2:
-Rebase on master
-Add Documentation

V3:
-Transforme the backingStore field in virStorageSource into
 an array of pointer instead of a pointer
-Modify virStorageSourceSetBackingStore to allow it to expand
 the backingStore size.

V4:
-Rebase on master

V5:
-Rebase on master
-patch 1-4/9: use patchs from John Ferlan 
-patch 4/9: check return of virStorageSourceSetBackingStore
-patch 5/9: report type of error on virStorageSourceSetBackingStore

v6 note:
First at all, I'm sorry for the time between v5 and v6,
I had other projects to work on and was unable to work at full time
on libvirt, moreover I've try at first to support all snapshot and
block jobs operations for quorum, but encounter a lot a problems.
At the end I had a versions which was only handling some few operations,
so I've block all unsupported operations for quorum,
I plan to continue working on the quorum unsupported operations,
and send it when it will be ready, but in the meantime I hope to 
upstream
this serie of patch which should provide a very basic(but stable)
quorum suport.

v6 modifications:
-Rebase on master
-Remove node-name patch
-patch 06/13: Add virStorageSourceIsRAID
-patch 10/13: Add virDomainDefHasRAID
-patch 11-13/13: Block all unsupported operations


Matthias Gatto (13):
  virstoragefile: Add virStorageSourceGetBackingStore
  virstoragefile: Always use virStorageSourceGetBackingStore to get
backing store
  virstoragefile: Add virStorageSourceSetBackingStore
  virstoragefile: Always use virStorageSourceSetBackingStore to set
backing store
  virstoragefile: change backingStore to backingStores.
  virstoragefile: Add virStorageSourceIsRAID
  virstoragefile: Add quorum in virstoragefile
  domain_conf: Read and Write quorum config
  qemu: Add quorum support in qemuBuildDriveDevStr
  domain: add virDomainDefHasRAID
  qemu: Block snapshot operation with RAID
  qemu: qemuDomainGetBlockInfo quorum support
  qemu: qemuDiskPathToAlias quorum support

 docs/formatdomain.html.in |  23 +++-
 docs/schemas/domaincommon.rng |  21 +++-
 docs/schemas/storagecommon.rng|   1 +
 docs/schemas/storagevol.rng   |   1 +
 src/conf/domain_conf.c| 196 +-
 src/conf/domain_conf.h|   1 +
 src/conf/storage_conf.c   |  23 ++--
 src/libvirt_private.syms  |   4 +
 src/qemu/qemu_cgroup.c|   4 +-
 src/qemu/qemu_command.c   |  94 
 src/qemu/qemu_domain.c|   2 +-
 src/qemu/qemu_driver.c|  50 ++---
 src/qemu/qemu_migration.c |   1 +
 src/qemu/qemu_monitor_json.c  |   4 +-
 src/security/security_dac.c   |   2 +-
 src/security/security_selinux.c   |   4 +-
 src/security/virt-aa-helper.c |   2 +-
 src/storage/storage_backend.c |  22

[libvirt] [PATCH v6 10/13] domain: Add virDomainDefHasRAID

2015-10-29 Thread Matthias Gatto
This function check if a domain has a RAID as a disk.
This function is useful to block snapshot operation on domain
which contain quorum.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/conf/domain_conf.c   | 13 +
 src/conf/domain_conf.h   |  1 +
 src/libvirt_private.syms |  1 +
 3 files changed, 15 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 363ef5d..9b947a6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2711,6 +2711,19 @@ virDomainDefNewFull(const char *name,
 }
 
 
+bool
+virDomainDefHasRAID(virDomainDefPtr def)
+{
+size_t i;
+
+for (i = 0; i < def->ndisks; ++i) {
+if (virStorageSourceIsRAID(def->disks[i]->src))
+return true;
+}
+return true;
+}
+
+
 void virDomainObjAssignDef(virDomainObjPtr domain,
virDomainDefPtr def,
bool live,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fd4ef82..bf768d8 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2556,6 +2556,7 @@ void virDomainDefClearPCIAddresses(virDomainDefPtr def);
 void virDomainDefClearCCWAddresses(virDomainDefPtr def);
 void virDomainDefClearDeviceAliases(virDomainDefPtr def);
 void virDomainTPMDefFree(virDomainTPMDefPtr def);
+bool virDomainDefHasRAID(virDomainDefPtr def);
 
 typedef int (*virDomainDeviceInfoCallback)(virDomainDefPtr def,
virDomainDeviceDefPtr dev,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index efcea49..1f5b106 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -218,6 +218,7 @@ virDomainDefGetMemoryInitial;
 virDomainDefGetSecurityLabelDef;
 virDomainDefHasDeviceAddress;
 virDomainDefHasMemoryHotplug;
+virDomainDefHasRAID;
 virDomainDefMaybeAddController;
 virDomainDefMaybeAddInput;
 virDomainDefNeedsPlacementAdvice;
-- 
2.6.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 03/13] virstoragefile: Add virStorageSourceSetBackingStore

2015-10-29 Thread Matthias Gatto
As explained for virStorageSourceGetBackingStore, quorum allows
multiple backing store, this make the operation to set bs complex
because we have to check if the backingStore is used as an array
or a pointer, and set it differently in both case.

In order to help the manipulation of backing store, I've added a
function virStorageSourceSetBackingStore.

For now virStorageSourceSetBackingStore don't handle the case where
we have more than one backing store in virStorageSource.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 10 ++
 src/util/virstoragefile.h |  4 
 3 files changed, 15 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8854b26..4aa923a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2173,6 +2173,7 @@ virStorageSourceParseRBDColonString;
 virStorageSourcePoolDefFree;
 virStorageSourcePoolModeTypeFromString;
 virStorageSourcePoolModeTypeToString;
+virStorageSourceSetBackingStore;
 virStorageSourceUpdateBlockPhysicalSize;
 virStorageTypeFromString;
 virStorageTypeToString;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index cb8e248..731e0c3 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1817,6 +1817,16 @@ virStorageSourceGetBackingStore(const virStorageSource 
*src,
 }
 
 
+bool
+virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr backingStore,
+size_t pos ATTRIBUTE_UNUSED)
+{
+src->backingStore = backingStore;
+return !!src->backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 8cd4854..5c5c29d 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,10 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+bool virStorageSourceSetBackingStore(virStorageSourcePtr src,
+ virStorageSourcePtr backingStore,
+ size_t pos);
+
 virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
 size_t pos);
 
-- 
2.6.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 11/11] quorum: Block snapshot operation with RAID

2015-10-29 Thread Matthias Gatto
For now we block all snapshot operations with quorum, because it would require
a lot more code, espacially because Qemu doesn't really suport it.

I guess, we can use node-name, and manually snapshoot all qcow from a
virStorageSource and use this as a quorum's snapshot,
but libvirt doesn't support node-name, and we don't need node-name
anymore to use a quorum in qemu.

I actually have some patchs which could partially support quorum snapshot
on my computer, but nothing suitable to be upstream, so I prefer to have
a stable versions of quorum inside libvirt before dealling with
snapshot.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/qemu/qemu_driver.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 25be0d9..0e43966 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14674,6 +14674,12 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
 if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
 goto cleanup;
 
+if (virDomainDefHasRAID(vm->def)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Snapshot does not support domain with RAID(like 
quorum) yet"));
+goto cleanup;
+}
+
 if (qemuProcessAutoDestroyActive(driver, vm)) {
 virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is marked for auto destroy"));
-- 
2.6.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 11/13] qemu: Block snapshot operation with RAID

2015-10-29 Thread Matthias Gatto
For now we block all snapshot operations with quorum,
because it would require a lot more code,
especially because Qemu doesn't really suport it.

I guess, we can use node-name, and manually snapshot all qcow
from a virStorageSource and use this as a quorum's snapshot,
but libvirt doesn't support node-name, and we don't need
node-name anymore to use a quorum in qemu.

I have some patchs which could partially support quorum snapshot
on my computer, but nothing suitable to be upstream, so I prefer to have
a stable versions of quorum inside libvirt before dealing with
snapshot.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/qemu/qemu_driver.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 193c25d..1ec0cf2 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14674,6 +14674,12 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
 if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
 goto cleanup;
 
+if (virDomainDefHasRAID(vm->def)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Snapshot does not support domain with RAID(like 
quorum) yet"));
+goto cleanup;
+}
+
 if (qemuProcessAutoDestroyActive(driver, vm)) {
 virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is marked for auto destroy"));
-- 
2.6.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 08/13] domain_conf: Read and Write quorum config

2015-10-29 Thread Matthias Gatto
Add the capabiltty to libvirt to parse and format the quorum syntax
as described here:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

As explain Peter Krempa in the V5, we need a different index for each child to
manipulate individually each child of a quorum,
this tack is done in this patch.

Sadly this versions is a little buggy: if one day we allow a quorum child
to have a backing store, we would be unable to made a difference
between a quorum child and a backing store, worst than that,
if we have a quorum, with a quorum as a child, we have no way to
use the index for quorum child manipulation.

For now, this serie of patch forbid all actions which need
to use indexes with quorum.
Therefore even if the index manipulation is buggy, this should not be a problem
because the buggy code should never be call.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/conf/domain_conf.c | 178 ++---
 1 file changed, 126 insertions(+), 52 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ce8edef..363ef5d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6607,20 +6607,56 @@ virDomainDiskSourceParse(xmlNodePtr node,
 }
 
 
+static bool
+virDomainDiskThresholdParse(virStorageSourcePtr src,
+xmlNodePtr node)
+{
+char *threshold = virXMLPropString(node, "threshold");
+int ret;
+
+if (!threshold) {
+virReportError(VIR_ERR_XML_ERROR,
+   "%s", _("missing threshold in quorum"));
+return false;
+}
+ret = virStrToLong_ul(threshold, NULL, 10, >threshold);
+if (ret < 0 || src->threshold < 2) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("unexpected threshold %s"),
+   "threshold must be a decimal number superior to 2 "
+   "and inferior to the number of children");
+VIR_FREE(threshold);
+return false;
+}
+VIR_FREE(threshold);
+return true;
+}
+
+
 static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
-   virStorageSourcePtr src)
+   virStorageSourcePtr src,
+   xmlNodePtr node,
+   size_t pos)
 {
 virStorageSourcePtr backingStore = NULL;
 xmlNodePtr save_ctxt = ctxt->node;
-xmlNodePtr source;
+xmlNodePtr source = NULL;
 char *type = NULL;
 char *format = NULL;
 int ret = -1;
 
-if (!(ctxt->node = virXPathNode("./backingStore[*]", ctxt))) {
-ret = 0;
-goto cleanup;
+if (virStorageSourceIsRAID(src)) {
+if (!node) {
+ret = 0;
+goto cleanup;
+}
+ctxt->node = node;
+} else {
+if (!(ctxt->node = virXPathNode("./backingStore[*]", ctxt))) {
+ret = 0;
+goto cleanup;
+}
 }
 
 if (VIR_ALLOC(backingStore) < 0)
@@ -6652,17 +6688,36 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
-if (!(source = virXPathNode("./source", ctxt))) {
-virReportError(VIR_ERR_XML_ERROR, "%s",
-   _("missing disk backing store source"));
-goto cleanup;
-}
+if (virStorageSourceIsRAID(backingStore)) {
+xmlNodePtr cur = NULL;
 
-if (virDomainDiskSourceParse(source, ctxt, backingStore) < 0 ||
-virDomainDiskBackingStoreParse(ctxt, backingStore) < 0)
-goto cleanup;
+if (!virDomainDiskThresholdParse(backingStore, node))
+goto cleanup;
 
-if (!virStorageSourceSetBackingStore(src, backingStore, 0))
+for (cur = node->children; cur != NULL; cur = cur->next) {
+if (xmlStrEqual(cur->name, BAD_CAST "backingStore")) {
+if ((virDomainDiskBackingStoreParse(ctxt,
+backingStore,
+cur,
+
backingStore->nBackingStores) < 0)) {
+goto cleanup;
+}
+}
+}
+} else {
+
+if (!(source = virXPathNode("./source", ctxt))) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("missing disk backing store source"));
+goto cleanup;
+}
+
+if (virDomainDiskSourceParse(source, ctxt, backingStore) < 0 ||
+virDomainDiskBackingStoreParse(ctxt, backingStore, NULL, 0) < 0)
+goto cleanup;
+}
+
+if (!virStorageSourceSetBackingStore(src, backingStore, pos))
 goto cleanup;
 ret = 0;
 
@@ -7177,6 +7232,10 @@ virD

[libvirt] [PATCH v6 12/13] qemu: qemuDomainGetBlockInfo quorum support

2015-10-29 Thread Matthias Gatto
Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/qemu/qemu_driver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1ec0cf2..f70f1dd 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11826,7 +11826,8 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
 goto endjob;
 }
 
-if (virStorageSourceIsEmpty(disk->src)) {
+if (!virStorageSourceIsRAID(disk->src) &&
+virStorageSourceIsEmpty(disk->src)) {
 virReportError(VIR_ERR_INVALID_ARG,
_("disk '%s' does not currently have a source 
assigned"),
path);
-- 
2.6.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 07/13] virstoragefile: Add quorum in virstoragefile

2015-10-29 Thread Matthias Gatto
Add VIR_STORAGE_TYPE_QUORUM in virStorageType.
Add VIR_STORAGE_FILE_QUORUM in virStorageFileFormat.

Add threshold value in _virStorageSource

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 docs/formatdomain.html.in  | 23 ---
 docs/schemas/domaincommon.rng  | 21 -
 docs/schemas/storagecommon.rng |  1 +
 docs/schemas/storagevol.rng|  1 +
 src/conf/domain_conf.c |  2 ++
 src/qemu/qemu_command.c|  1 +
 src/qemu/qemu_driver.c |  4 
 src/qemu/qemu_migration.c  |  1 +
 src/util/virstoragefile.c  | 25 +
 src/util/virstoragefile.h  |  3 +++
 10 files changed, 70 insertions(+), 12 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index c88b032..a52b60b 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1958,8 +1958,9 @@
 
 Valid values are "file", "block",
 "dir" (since 0.7.5),
-"network" (since 0.8.7), or
-"volume" (since 1.0.5)
+"network" (since 0.8.7),
+"volume" (since 1.0.5), or
+"quorum" (since 1.2.21)
 and refer to the underlying source for the disk.
 
   device attribute
@@ -2025,6 +2026,14 @@
 snapshot='yes' with a transient disk generally
 does not make sense.
 
+  threshold attribute
+  since 1.2.21
+
+Only use with a quorum disk.
+Indicate the minimum of positive vote a quorum must have to 
validate
+a data to be write. The minimum value is "2". The number of 
backingStores
+contain by the quorum must be superior to the threshold.
+
 
   
   source
@@ -2102,6 +2111,11 @@
 
   
   
+type='quorum'
+since 1.2.21
+  
+  A quorum contain no source element, but a serie of backingStores 
instead.
+  
   
 With "file", "block", and "volume", one or more optional
 sub-elements seclabel, described
@@ -2241,7 +2255,10 @@
 property, but using existing external files for snapshot or
 block copy operations requires the end user to pre-create the
 file correctly). The following attributes and sub-elements are
-supported in backingStore:
+supported in.
+Since 1.2.21. This elements is used to
+describe a quorum child.
+backingStore:
 
   type attribute
   
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index f196177..067140b 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1240,9 +1240,15 @@
 
   
 
+  
+
+  
+
+  
+
   
 
-  
+  
   
 
   
@@ -1284,9 +1290,22 @@
   
   
   
+  
 
   
 
+  
+
+  
+quorum
+  
+  
+
+  
+
+  
+
+
   
 
   
diff --git a/docs/schemas/storagecommon.rng b/docs/schemas/storagecommon.rng
index 7c04462..0ebc2ef 100644
--- a/docs/schemas/storagecommon.rng
+++ b/docs/schemas/storagecommon.rng
@@ -76,6 +76,7 @@
   fat
   vhd
   ploop
+  quorum
   
 
   
diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 7450547..a718576 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -20,6 +20,7 @@
 dir
 network
 netdir
+quorum
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 101cfeb..ce8edef 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6583,6 +6583,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
 if (virDomainDiskSourcePoolDefParse(node, >srcpool) < 0)
 goto cleanup;
 break;
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -18837,6 +18838,7 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
  skipSeclabels);
 break;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8824541..50cf8cc 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3534,6 +3534,7 @@ qemuGetDriveSourceString(virStorageSourcePtr src,
 goto cleanup;
 break;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_VOLUME:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
diff --git a/src

[libvirt] [PATCH v6 13/13] qemu: qemuDiskPathToAlias quorum support

2015-10-29 Thread Matthias Gatto
By adding quorum support to qemuDiskPathToAlias, we're adding support to
qemuDomainGetBlkioParameters, which was returning an error when the domain
was active.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
---
 src/qemu/qemu_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f70f1dd..50d90b5 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16115,7 +16115,7 @@ qemuDiskPathToAlias(virDomainObjPtr vm, const char 
*path, int *idxret)
 if (idxret)
 *idxret = idx;
 
-if (virDomainDiskGetSource(disk)) {
+if (virDomainDiskGetSource(disk) || virStorageSourceIsRAID(disk->src)) {
 if (virAsprintf(, "drive-%s", disk->info.alias) < 0)
 return NULL;
 }
-- 
2.6.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 02/13] virstoragefile: Always use virStorageSourceGetBackingStore to get backing store

2015-10-29 Thread Matthias Gatto
Uniformize backing store usage by calling virStorageSourceGetBackingStore
instead of setting backing store manually.

Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com>
Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/conf/domain_conf.c|  7 ---
 src/conf/storage_conf.c   |  6 +++---
 src/qemu/qemu_cgroup.c|  4 ++--
 src/qemu/qemu_domain.c|  2 +-
 src/qemu/qemu_driver.c| 18 ++
 src/qemu/qemu_monitor_json.c  |  4 +++-
 src/security/security_dac.c   |  2 +-
 src/security/security_selinux.c   |  4 ++--
 src/security/virt-aa-helper.c |  2 +-
 src/storage/storage_backend.c | 20 
 src/storage/storage_backend_fs.c  | 31 +--
 src/storage/storage_backend_gluster.c |  8 +---
 src/storage/storage_backend_logical.c | 10 ++
 src/util/virstoragefile.c | 20 ++--
 tests/virstoragetest.c| 14 +++---
 15 files changed, 84 insertions(+), 68 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9a0c7fc..e0befc3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18897,7 +18897,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
 /* We currently don't output seclabels for backing chain element */
 if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true) < 0 ||
 virDomainDiskBackingStoreFormat(buf,
-backingStore->backingStore,
+
virStorageSourceGetBackingStore(backingStore, 0),
 backingStore->backingStoreRaw,
 idx + 1) < 0)
 return -1;
@@ -19018,7 +19018,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
 /* Don't format backingStore to inactive XMLs until the code for
  * persistent storage of backing chains is ready. */
 if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) &&
-virDomainDiskBackingStoreFormat(buf, def->src->backingStore,
+virDomainDiskBackingStoreFormat(buf,
+
virStorageSourceGetBackingStore(def->src, 0),
 def->src->backingStoreRaw, 1) < 0)
 return -1;
 
@@ -23317,7 +23318,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
 }
 }
 
-for (tmp = disk->src; tmp; tmp = tmp->backingStore) {
+for (tmp = disk->src; tmp; tmp = virStorageSourceGetBackingStore(tmp, 0)) {
 int actualType = virStorageSourceGetActualType(tmp);
 /* execute the callback only for local storage */
 if (actualType != VIR_STORAGE_TYPE_NETWORK &&
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 9b8abea..d048e39 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1330,7 +1330,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 if (virStorageSize(unit, capacity, >target.capacity) < 0)
 goto error;
 } else if (!(flags & VIR_VOL_XML_PARSE_NO_CAPACITY) &&
-   !((flags & VIR_VOL_XML_PARSE_OPT_CAPACITY) && 
ret->target.backingStore)) {
+   !((flags & VIR_VOL_XML_PARSE_OPT_CAPACITY) && 
virStorageSourceGetBackingStore(>target, 0))) {
 virReportError(VIR_ERR_XML_ERROR, "%s", _("missing capacity element"));
 goto error;
 }
@@ -1644,9 +1644,9 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
  >target, "target") < 0)
 goto cleanup;
 
-if (def->target.backingStore &&
+if (virStorageSourceGetBackingStore(>target, 0) &&
 virStorageVolTargetDefFormat(options, ,
- def->target.backingStore,
+ 
virStorageSourceGetBackingStore(>target, 0),
  "backingStore") < 0)
 goto cleanup;
 
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index a8e0b8c..f93782b 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -121,7 +121,7 @@ qemuSetupDiskCgroup(virDomainObjPtr vm,
 virStorageSourcePtr next;
 bool forceReadonly = false;
 
-for (next = disk->src; next; next = next->backingStore) {
+for (next = disk->src; next; next = virStorageSourceGetBackingStore(next, 
0)) {
 if (qemuSetImageCgroupInternal(vm, next, false, forceReadonly) < 0)
 return -1;
 
@@ -139,7 +139,7 @@ qemuTeardownDiskCgroup(virDomainObjPtr vm,
 {
 virStorageSourcePtr next;
 
-for (next = disk->src; next; next = next->backingStore) {
+for (next = disk->src; next; next = virStorageSourceG

Re: [libvirt] [PATCH v5 8/9] qemu: Add quorum support in qemuBuildDriveDevStr

2015-06-04 Thread Matthias Gatto
On Tue, May 12, 2015 at 5:38 PM, Peter Krempa pkre...@redhat.com wrote:
 On Thu, Apr 23, 2015 at 14:41:20 +0200, Matthias Gatto wrote:
 Allow to libvirt to build the quorum string used by quemu.

 Add 2 static functions: qemuBuildQuorumStr and
 qemuBuildAndAppendDriveStrToVirBuffer.
 qemuBuildQuorumStr is made because a quorum can have another quorum
 as a child, so we may need to call qemuBuildQuorumStr recursively.

 qemuBuildQuorumFileSourceStr was basically made to share
 the code use to build the source between qemuBuildQuorumStr and
 qemuBuildDriveStr, but there is some difference betwin the syntax
 use by libvirt to declare a disk and the one qemu need to build a quorum:
 a quorum need a syntaxe like:
 domaine_name.children.X.file.filename=filename
 where libvirt don't use file.filename= but directly file=.
 Therfore I use this function only for quorum.

 But as explained in the cover letter and here:
 http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
 We miss some informations in _virStorageSource to have a complet
 quorum support in libvirt.
 Ideally I'd like to refactore virDomainDiskDefFormat to allow
 qemuBuildQuorumStr to call this function in a loop.

 Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
 ---
  src/qemu/qemu_command.c | 110 
 
  1 file changed, 110 insertions(+)


 ...

 diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
 index 6c40d3e..80cbb7d 100644
 --- a/src/qemu/qemu_command.c
 +++ b/src/qemu/qemu_command.c
 @@ -3479,6 +3479,111 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk)
  return -1;
  }

 +static bool
 +qemuBuildQuorumFileSourceStr(virConnectPtr conn,
 +  virStorageSourcePtr src,
 +  virBuffer *opt,
 +  const char *toAppend)
 +{
 +char *source = NULL;
 +int actualType = virStorageSourceGetActualType(src);
 +
 +if (qemuGetDriveSourceString(src, conn, source)  0)
 +goto error;
 +
 +if (source) {
 +
 +virBufferAsprintf(opt, ,%sfilename=, toAppend);

 virBufferStrcat

 +
 +switch (actualType) {
 +case VIR_STORAGE_TYPE_DIR:

 I'd forbid the DIR type altogether with quorums.

 +/* QEMU only supports magic FAT format for now */
 +if (src-format  0 
 +src-format != VIR_STORAGE_FILE_FAT) {
 +virReportError(VIR_ERR_INTERNAL_ERROR,
 +   _(unsupported disk driver type for '%s'),
 +   
 virStorageFileFormatTypeToString(src-format));
 +goto error;
 +}
 +
 +if (!src-readonly) {
 +virReportError(VIR_ERR_INTERNAL_ERROR, %s,
 +   _(cannot create virtual FAT disks in 
 read-write mode));
 +goto error;
 +}
 +
 +virBufferAddLit(opt, fat:);
 +
 +break;
 +
 +default:
 +break;
 +}
 +virBufferAsprintf(opt, %s, source);

 virBufferAdd

 +}
 +
 +return true;
 + error:
 +return false;

 Error can be returned right away since there is nothing to clean up.

 +}
 +
 +
 +static bool
 +qemuBuildQuorumStr(virConnectPtr conn,
 +   virDomainDiskDefPtr disk,
 +   virStorageSourcePtr src,
 +   virBuffer *opt,
 +   const char *toAppend)
 +{
 +char *tmp = NULL;
 +int ret;
 +virStorageSourcePtr backingStore;
 +size_t i;
 +
 +if (!src-threshold) {
 +virReportError(VIR_ERR_INTERNAL_ERROR, %s,
 +   _(threshold missing in the quorum configuration));
 +return false;
 +}
 +if (src-nBackingStores  2) {
 +virReportError(VIR_ERR_INTERNAL_ERROR, %s,
 +   _(a quorum must have at last 2 children));
 +return false;
 +}
 +if (src-threshold  src-nBackingStores) {
 +virReportError(VIR_ERR_INTERNAL_ERROR, %s,
 +   _(threshold must not exceed the number of 
 childrens));

 'children' is the proper plural

 +return false;
 +}
 +virBufferAsprintf(opt, ,%svote-threshold=%lu,
 +  toAppend, src-threshold);
 +for (i = 0;  i  src-nBackingStores; ++i) {
 +backingStore = virStorageSourceGetBackingStore(src, i);
 +ret = virAsprintf(tmp, %schildren.%lu.file., toAppend, i);
 +if (ret  0)
 +return false;
 +
 +virBufferAsprintf(opt, ,%schildren.%lu.driver=%s,
 +  toAppend, i,
 +  
 virStorageFileFormatTypeToString(backingStore-format));
 +
 +if (qemuBuildQuorumFileSourceStr(conn, backingStore, opt, tmp) == 
 false)
 +goto error;
 +
 +/* This operation avoid me to made another copy */
 +tmp[ret - sizeof(file)] = '\0';
 +if (backingStore

Re: [libvirt] [PATCH v5 7/9] domain_conf: Read and Write quorum config

2015-06-04 Thread Matthias Gatto
On Tue, May 12, 2015 at 5:04 PM, Peter Krempa pkre...@redhat.com wrote:
 On Thu, Apr 23, 2015 at 14:41:19 +0200, Matthias Gatto wrote:
 Add the capabiltty to libvirt to parse and format the quorum syntax
 as described here:
 http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

 Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
 ---
  src/conf/domain_conf.c | 164 
 +++--
  1 file changed, 119 insertions(+), 45 deletions(-)

 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
 index a3a6c13..ec93b6f 100644
 --- a/src/conf/domain_conf.c
 +++ b/src/conf/domain_conf.c
 @@ -5952,20 +5952,56 @@ virDomainDiskSourceParse(xmlNodePtr node,
  }


 +static bool
 +virDomainDiskThresholdParse(virStorageSourcePtr src,
 +xmlNodePtr node)
 +{
 +char *threshold = virXMLPropString(node, threshold);
 +int ret;
 +
 +if (!threshold) {
 +virReportError(VIR_ERR_XML_ERROR,
 +   %s, _(missing threshold in quorum));
 +return false;
 +}
 +ret = virStrToLong_ul(threshold, NULL, 10, src-threshold);
 +if (ret  0 || src-threshold  2) {
 +virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
 +   _(unexpected threshold %s),
 +   threshold must be a decimal number superior to 2 
 + and inferior to the number of children);
 +VIR_FREE(threshold);
 +return false;
 +}
 +VIR_FREE(threshold);
 +return true;
 +}
 +
 +
  static int
  virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 -   virStorageSourcePtr src)
 +   virStorageSourcePtr src,
 +   xmlNodePtr node,
 +   size_t pos)
  {
  virStorageSourcePtr backingStore = NULL;
  xmlNodePtr save_ctxt = ctxt-node;
 -xmlNodePtr source;
 +xmlNodePtr source = NULL;
  char *type = NULL;
  char *format = NULL;
  int ret = -1;

 -if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
 -ret = 0;
 -goto cleanup;
 +if (src-type == VIR_STORAGE_TYPE_QUORUM) {
 +if (!node) {
 +ret = 0;
 +goto cleanup;
 +}
 +ctxt-node = node;
 +} else {
 +if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
 +ret = 0;
 +goto cleanup;
 +}
  }

  if (VIR_ALLOC(backingStore)  0)
 @@ -5997,6 +6033,25 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr 
 ctxt,
  goto cleanup;
  }

 +if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) {
 +xmlNodePtr cur = NULL;
 +
 +if (!virDomainDiskThresholdParse(backingStore, node))
 +goto cleanup;
 +
 +for (cur = node-children; cur != NULL; cur = cur-next) {
 +if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
 +if ((virDomainDiskBackingStoreParse(ctxt,
 +backingStore,
 +cur,
 +
 backingStore-nBackingStores)  0)) {
 +goto cleanup;
 +}
 +}
 +}
 +goto exit;
 +}
 +
  if (!(source = virXPathNode(./source, ctxt))) {
  virReportError(VIR_ERR_XML_ERROR, %s,
 _(missing disk backing store source));
 @@ -6004,10 +6059,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr 
 ctxt,
  }

  if (virDomainDiskSourceParse(source, ctxt, backingStore)  0 ||
 -virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
 +virDomainDiskBackingStoreParse(ctxt, backingStore, NULL, 0)  0)
  goto cleanup;

 -if (!virStorageSourceSetBackingStore(src, backingStore, 0))
 + exit:
 +if (!virStorageSourceSetBackingStore(src, backingStore, pos))
  goto cleanup;
  ret = 0;

 @@ -6020,7 +6076,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
  return ret;
  }

 -
  #define VENDOR_LEN  8
  #define PRODUCT_LEN 16

 @@ -6518,6 +6573,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
  }
  } else if (xmlStrEqual(cur-name, BAD_CAST boot)) {
  /* boot is parsed as part of virDomainDeviceInfoParseXML */
 +} else if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
 +if (virDomainDiskBackingStoreParse(ctxt, def-src, cur,
 +   
 def-src-nBackingStores)  0)
 +goto error;
  }
  }
  cur = cur-next;
 @@ -6541,12 +6600,19 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr 
 xmlopt,
  def-device = VIR_DOMAIN_DISK_DEVICE_DISK;
  }

 +if (def-src-type == VIR_STORAGE_TYPE_QUORUM 
 +!virDomainDiskThresholdParse(def-src, node

Re: [libvirt] [PATCH v5 4/9] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store

2015-05-05 Thread Matthias Gatto
On Mon, May 4, 2015 at 7:21 PM, John Ferlan jfer...@redhat.com wrote:


 On 04/23/2015 08:41 AM, Matthias Gatto wrote:
 Replace the parts of the code where a backing store is set manually
 with virStorageSourceSetBackingStore

 Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
 Signed-off-by: John Ferlan jfer...@redhat.com
 ---
  src/conf/domain_conf.c|  3 ++-
  src/conf/storage_conf.c   | 17 ++---
  src/qemu/qemu_driver.c| 17 +++--
  src/storage/storage_backend_fs.c  |  7 +--
  src/storage/storage_backend_gluster.c |  5 +++--
  src/storage/storage_backend_logical.c |  9 ++---
  src/storage/storage_driver.c  |  3 ++-
  src/util/virstoragefile.c |  8 +---
  tests/virstoragetest.c|  4 ++--
  9 files changed, 46 insertions(+), 27 deletions(-)


 Other than a minor goto error issue in storage_backend_gluster.c - up
 through here things seem fine to me.  Doesn't seem to be any new readers
 or setters of -backingStore in recent changes (since patches 5-9
 compile too). The only references are now -backingStoreRaw fetches and
 saves.

 However, for patches 5-9 as I understand it have some concerns from
 Peter which hopefully he can elaborate on.

 So that progress can be made and readers/writers of backingStore go
 through the virStorageSource{Get|Set}BackingStore API's until the rest
 of the concerns are understood - I'm of the opinion the patches 1-4 can
 be pushed, but I'll wait until Peter chimes in before doing so...

 John
 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
 index 2a05291..09f0bca 100644
 --- a/src/conf/domain_conf.c
 +++ b/src/conf/domain_conf.c
 @@ -6006,7 +6006,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
  virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
  goto cleanup;

 -src-backingStore = backingStore;
 +if (!virStorageSourceSetBackingStore(src, backingStore, 0))
 +goto cleanup;
  ret = 0;

   cleanup:
 diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
 index 5781374..ca3a6d5 100644
 --- a/src/conf/storage_conf.c
 +++ b/src/conf/storage_conf.c
 @@ -1254,6 +1254,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
  char *capacity = NULL;
  char *unit = NULL;
  char *backingStore = NULL;
 +virStorageSourcePtr backingStorePtr;
  xmlNodePtr node;
  xmlNodePtr *nodes = NULL;
  size_t i;
 @@ -1290,20 +1291,22 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
  }

  if ((backingStore = virXPathString(string(./backingStore/path), 
 ctxt))) {
 -if (VIR_ALLOC(ret-target.backingStore)  0)
 +if (VIR_ALLOC(backingStorePtr)  0)
  goto error;

 -ret-target.backingStore-path = backingStore;
 +if (!virStorageSourceSetBackingStore(ret-target, backingStorePtr, 
 0))
 +goto error;
 +backingStorePtr-path = backingStore;
  backingStore = NULL;

  if (options-formatFromString) {
  char *format = 
 virXPathString(string(./backingStore/format/@type), ctxt);
  if (format == NULL)
 -ret-target.backingStore-format = options-defaultFormat;
 +backingStorePtr-format = options-defaultFormat;
  else
 -ret-target.backingStore-format = 
 (options-formatFromString)(format);
 +backingStorePtr-format = 
 (options-formatFromString)(format);

 -if (ret-target.backingStore-format  0) {
 +if (backingStorePtr-format  0) {
  virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
 _(unknown volume format type %s), format);
  VIR_FREE(format);
 @@ -1312,9 +1315,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
  VIR_FREE(format);
  }

 -if (VIR_ALLOC(ret-target.backingStore-perms)  0)
 +if (VIR_ALLOC(backingStorePtr-perms)  0)
  goto error;
 -if (virStorageDefParsePerms(ctxt, ret-target.backingStore-perms,
 +if (virStorageDefParsePerms(ctxt, backingStorePtr-perms,
  ./backingStore/permissions,
  DEFAULT_VOL_PERM_MODE)  0)
  goto error;
 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
 index 26be9d6..1a98601 100644
 --- a/src/qemu/qemu_driver.c
 +++ b/src/qemu/qemu_driver.c
 @@ -14274,13 +14274,18 @@ 
 qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
  /* Update vm in place to match changes.  */
  need_unlink = false;

 -newDiskSrc-backingStore = disk-src;
 -disk-src = newDiskSrc;
 +if (!virStorageSourceSetBackingStore(newDiskSrc, disk-src, 0)) {
 +ret = -1;
 +goto cleanup;
 +}
  newDiskSrc = NULL;

  if (persistDisk) {
 -persistDiskSrc-backingStore = persistDisk-src;
 -persistDisk

Re: [libvirt] [PATCH v5 0/9] qemu: Add quorum support to libvirt

2015-05-04 Thread Matthias Gatto
On Thu, Apr 23, 2015 at 2:41 PM, Matthias Gatto
matthias.ga...@outscale.com wrote:
 The purpose of these patches is to introduce quorum for libvirt
 I've try to follow this proposal:
 http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

 This feature ask for 6 task:

 1) Allow a _virStorageSource to contain more than one backing store.

 Because all the actual libvirt code use the backingStore field
 as a pointer and we needs want to change that, I've decide to encapsulate
 the backingStore field to simplifie the array manipulation.

 2) Add the missing field a quorum need in _virStorageSource and
 the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
 their respectives enums.

 3) Parse and format the xml
 Because a quorum allows to have more than one backing store at the same level
 we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
 to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
 in a loop.
 virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
 call themself recursively in a loop because a quorum can contain another
 quorum

 4) Add nodename
 We need to add nodename support in _virStorageSource because qemu
 use them for their child.

 5) Build qemu string
 As for the xml, we have to call the function which create quorum recursively.
 But this task have the problem explained here:
 http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
 The _virStorageSource missing some informations that can be passed to
 a child, and therefore this version of quorum is incomplet.

 6) Allow to hotplug/change a disk in a quorum
 This part is not present in these patches because for this task
 we have to use blockdev-add, and currently libvirt use
 device_add for hotpluging that doesn't allow to hotplug quorum childs.

 There is 3 way to handle this problem:
   1) create a virDomainBlockDevAdd function in libvirt witch call
  blockdev-add.

   2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice

   3) write a hack which uses blockdev-add when only attaching quorum
 (but i'm pretty sure this solution is not the good one)

 V2:
 -Rebase on master
 -Add Documentation

 V3:
 -Transforme the backingStore field in virStorageSource into
  an array of pointer instead of a pointer
 -Modify virStorageSourceSetBackingStore to allow it to expand
  the backingStore size.

 V4:
 -Rebase on master

 V5:
 -Rebase on master
 -patch 1-4/9: use patchs from John Ferlan
 -patch 4/9: check return of virStorageSourceSetBackingStore
 -patch 5/9: report type of error on virStorageSourceSetBackingStore

 Matthias Gatto (9):
   virstoragefile: Add virStorageSourceGetBackingStore
   virstoragefile: Always use virStorageSourceGetBackingStore to get
 backing store
   virstoragefile: Add virStorageSourceSetBackingStore
   virstoragefile: Always use virStorageSourceSetBackingStore to set
 backing store
   virstoragefile: change backingStore to backingStores.
   virstoragefile: Add quorum in virstoragefile
   domain_conf: Read and Write quorum config
   qemu: Add quorum support in qemuBuildDriveDevStr
   virstoragefile: Add node-name

  docs/formatdomain.html.in |  30 +-
  docs/schemas/domaincommon.rng |  26 -
  docs/schemas/storagecommon.rng|   1 +
  docs/schemas/storagevol.rng   |   1 +
  src/conf/domain_conf.c| 195 
 ++
  src/conf/storage_conf.c   |  23 ++--
  src/libvirt_private.syms  |   2 +
  src/qemu/qemu_cgroup.c|   4 +-
  src/qemu/qemu_command.c   | 114 
  src/qemu/qemu_domain.c|   2 +-
  src/qemu/qemu_driver.c|  39 ---
  src/qemu/qemu_migration.c |   1 +
  src/qemu/qemu_monitor_json.c  |   4 +-
  src/security/security_dac.c   |   2 +-
  src/security/security_selinux.c   |   4 +-
  src/security/virt-aa-helper.c |   2 +-
  src/storage/storage_backend.c |  22 ++--
  src/storage/storage_backend_fs.c  |  38 ---
  src/storage/storage_backend_gluster.c |  11 +-
  src/storage/storage_backend_logical.c |  15 ++-
  src/storage/storage_driver.c  |   3 +-
  src/util/virstoragefile.c | 122 ++---
  src/util/virstoragefile.h |  13 ++-
  tests/virstoragetest.c|  18 ++--
  24 files changed, 551 insertions(+), 141 deletions(-)

 --
 2.3.5

ping

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v5 6/9] virstoragefile: Add quorum in virstoragefile

2015-04-23 Thread Matthias Gatto
Add VIR_STORAGE_TYPE_QUORUM in virStorageType.
Add VIR_STORAGE_FILE_QUORUM in virStorageFileFormat.

Add threshold value in _virStorageSource

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 docs/formatdomain.html.in  | 23 ---
 docs/schemas/domaincommon.rng  | 21 -
 docs/schemas/storagecommon.rng |  1 +
 docs/schemas/storagevol.rng|  1 +
 src/conf/domain_conf.c |  2 ++
 src/qemu/qemu_command.c|  1 +
 src/qemu/qemu_driver.c |  4 
 src/qemu/qemu_migration.c  |  1 +
 src/util/virstoragefile.c  | 25 +
 src/util/virstoragefile.h  |  3 +++
 10 files changed, 70 insertions(+), 12 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index e921749..7d058ec 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1878,8 +1878,9 @@
 dd
 Valid values are file, block,
 dir (span class=sincesince 0.7.5/span),
-network (span class=sincesince 0.8.7/span), or
-volume (span class=sincesince 1.0.5/span)
+network (span class=sincesince 0.8.7/span),
+volume (span class=sincesince 1.0.5/span), or
+quorum (span class=sincesince 1.2.13/span)
 and refer to the underlying source for the disk.
 /dd
   dtcodedevice/code attribute
@@ -1940,6 +1941,14 @@
 codesnapshot='yes'/code with a transient disk generally
 does not make sense.
 /dd
+  dtcodethreshold/code attribute
+  span class=sincesince 1.2.13/span/dt
+dd
+Only use with a quorum disk.
+Indicate the minimum of positive vote a quorum must have to 
validate
+a data to be write. The minimum value is 2. The number of 
backingStores
+contain by the quorum must be superior to the threshold.
+/dd
 /dl
   /dd
   dtcodesource/code/dt
@@ -2010,6 +2019,11 @@
   
'file=/dev/disk/by-path/ip-example.com:3260-iscsi-iqn.2013-07.com.example:iscsi-pool-lun-1').
   /p
   /dd
+dtcodetype='quorum'/code
+span class=sincesince 1.2.13/span/dt
+  dd
+  A quorum contain no source element, but a serie of backingStores 
instead.
+  /dd
   /dl
 With file, block, and volume, one or more optional
 sub-elements codeseclabel/code, a href=#seclabeldescribed
@@ -2149,7 +2163,10 @@
 property, but using existing external files for snapshot or
 block copy operations requires the end user to pre-create the
 file correctly). The following attributes and sub-elements are
-supported in codebackingStore/code:
+supported in.
+span class=sinceSince 1.2.15/span. This elements is used to
+describe a quorum child.
+codebackingStore/code:
 dl
   dtcodetype/code attribute/dt
   dd
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 19461f5..6cd834e 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1217,9 +1217,15 @@
 /interleave
   /define
 
+  define name=diskBackingStoreArray
+zeroOrMore
+  ref name=diskBackingStore/
+/zeroOrMore
+  /define
+
   define name=diskBackingChain
 choice
-  ref name=diskBackingStore/
+  ref name=diskBackingStoreArray/
   ref name=diskBackingStoreLast/
 /choice
   /define
@@ -1261,9 +1267,22 @@
   ref name=diskSourceDir/
   ref name=diskSourceNetwork/
   ref name=diskSourceVolume/
+  ref name=diskSourceQuorum/
 /choice
   /define
 
+  define name=diskSourceQuorum
+optional
+  attribute name=type
+valuequorum/value
+  /attribute
+  attribute name=threshold
+ref name=unsignedInt/
+  /attribute
+/optional
+  /define
+
+
   define name=diskSourceFile
 optional
   attribute name=type
diff --git a/docs/schemas/storagecommon.rng b/docs/schemas/storagecommon.rng
index 5f71b10..ba9f485 100644
--- a/docs/schemas/storagecommon.rng
+++ b/docs/schemas/storagecommon.rng
@@ -76,6 +76,7 @@
   valuefat/value
   valuevhd/value
   valueploop/value
+  valuequorum/value
   ref name='storageFormatBacking'/
 /choice
   /define
diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 7450547..a718576 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -20,6 +20,7 @@
 valuedir/value
 valuenetwork/value
 valuenetdir/value
+valuequorum/value
   /choice
 /attribute
   /optional
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 09f0bca..a3a6c13 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5928,6 +5928,7 @@ virDomainDiskSourceParse(xmlNodePtr node

[libvirt] [PATCH v5 8/9] qemu: Add quorum support in qemuBuildDriveDevStr

2015-04-23 Thread Matthias Gatto
Allow to libvirt to build the quorum string used by quemu.

Add 2 static functions: qemuBuildQuorumStr and
qemuBuildAndAppendDriveStrToVirBuffer.
qemuBuildQuorumStr is made because a quorum can have another quorum
as a child, so we may need to call qemuBuildQuorumStr recursively.

qemuBuildQuorumFileSourceStr was basically made to share
the code use to build the source between qemuBuildQuorumStr and
qemuBuildDriveStr, but there is some difference betwin the syntax
use by libvirt to declare a disk and the one qemu need to build a quorum:
a quorum need a syntaxe like:
domaine_name.children.X.file.filename=filename
where libvirt don't use file.filename= but directly file=.
Therfore I use this function only for quorum.

But as explained in the cover letter and here:
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
We miss some informations in _virStorageSource to have a complet
quorum support in libvirt.
Ideally I'd like to refactore virDomainDiskDefFormat to allow
qemuBuildQuorumStr to call this function in a loop.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/qemu/qemu_command.c | 110 
 1 file changed, 110 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6c40d3e..80cbb7d 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3479,6 +3479,111 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk)
 return -1;
 }
 
+static bool
+qemuBuildQuorumFileSourceStr(virConnectPtr conn,
+  virStorageSourcePtr src,
+  virBuffer *opt,
+  const char *toAppend)
+{
+char *source = NULL;
+int actualType = virStorageSourceGetActualType(src);
+
+if (qemuGetDriveSourceString(src, conn, source)  0)
+goto error;
+
+if (source) {
+
+virBufferAsprintf(opt, ,%sfilename=, toAppend);
+
+switch (actualType) {
+case VIR_STORAGE_TYPE_DIR:
+/* QEMU only supports magic FAT format for now */
+if (src-format  0 
+src-format != VIR_STORAGE_FILE_FAT) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(unsupported disk driver type for '%s'),
+   virStorageFileFormatTypeToString(src-format));
+goto error;
+}
+
+if (!src-readonly) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(cannot create virtual FAT disks in 
read-write mode));
+goto error;
+}
+
+virBufferAddLit(opt, fat:);
+
+break;
+
+default:
+break;
+}
+virBufferAsprintf(opt, %s, source);
+}
+
+return true;
+ error:
+return false;
+}
+
+
+static bool
+qemuBuildQuorumStr(virConnectPtr conn,
+   virDomainDiskDefPtr disk,
+   virStorageSourcePtr src,
+   virBuffer *opt,
+   const char *toAppend)
+{
+char *tmp = NULL;
+int ret;
+virStorageSourcePtr backingStore;
+size_t i;
+
+if (!src-threshold) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(threshold missing in the quorum configuration));
+return false;
+}
+if (src-nBackingStores  2) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(a quorum must have at last 2 children));
+return false;
+}
+if (src-threshold  src-nBackingStores) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(threshold must not exceed the number of childrens));
+return false;
+}
+virBufferAsprintf(opt, ,%svote-threshold=%lu,
+  toAppend, src-threshold);
+for (i = 0;  i  src-nBackingStores; ++i) {
+backingStore = virStorageSourceGetBackingStore(src, i);
+ret = virAsprintf(tmp, %schildren.%lu.file., toAppend, i);
+if (ret  0)
+return false;
+
+virBufferAsprintf(opt, ,%schildren.%lu.driver=%s,
+  toAppend, i,
+  
virStorageFileFormatTypeToString(backingStore-format));
+
+if (qemuBuildQuorumFileSourceStr(conn, backingStore, opt, tmp) == 
false)
+goto error;
+
+/* This operation avoid me to made another copy */
+tmp[ret - sizeof(file)] = '\0';
+if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!qemuBuildQuorumStr(conn, disk, backingStore, opt, tmp))
+goto error;
+}
+VIR_FREE(tmp);
+}
+return true;
+ error:
+VIR_FREE(tmp);
+return false;
+}
+
 
 /* Qemu 1.2 and later have a binary flag -enable-fips that must be
  * used for VNC auth to obey FIPS settings; but the flag only
@@ -3952,6 +4057,11 @@ qemuBuildDriveStr(virConnectPtr conn

[libvirt] [PATCH v5 2/9] virstoragefile: Always use virStorageSourceGetBackingStore to get backing store

2015-04-23 Thread Matthias Gatto
Uniformize backing store usage by calling virStorageSourceGetBackingStore
instead of setting backing store manually.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
Signed-off-by: John Ferlan jfer...@redhat.com
---
 src/conf/domain_conf.c|  7 ---
 src/conf/storage_conf.c   |  6 +++---
 src/qemu/qemu_cgroup.c|  4 ++--
 src/qemu/qemu_domain.c|  2 +-
 src/qemu/qemu_driver.c| 18 ++
 src/qemu/qemu_monitor_json.c  |  4 +++-
 src/security/security_dac.c   |  2 +-
 src/security/security_selinux.c   |  4 ++--
 src/security/virt-aa-helper.c |  2 +-
 src/storage/storage_backend.c | 20 
 src/storage/storage_backend_fs.c  | 31 +--
 src/storage/storage_backend_gluster.c |  8 +---
 src/storage/storage_backend_logical.c | 10 ++
 src/util/virstoragefile.c | 20 ++--
 tests/virstoragetest.c| 14 +++---
 15 files changed, 84 insertions(+), 68 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9aad782..2a05291 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17751,7 +17751,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
 /* We currently don't output seclabels for backing chain element */
 if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true)  0 ||
 virDomainDiskBackingStoreFormat(buf,
-backingStore-backingStore,
+
virStorageSourceGetBackingStore(backingStore, 0),
 backingStore-backingStoreRaw,
 idx + 1)  0)
 return -1;
@@ -17873,7 +17873,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
 /* Don't format backingStore to inactive XMLs until the code for
  * persistent storage of backing chains is ready. */
 if (!(flags  VIR_DOMAIN_DEF_FORMAT_INACTIVE) 
-virDomainDiskBackingStoreFormat(buf, def-src-backingStore,
+virDomainDiskBackingStoreFormat(buf,
+
virStorageSourceGetBackingStore(def-src, 0),
 def-src-backingStoreRaw, 1)  0)
 return -1;
 
@@ -22044,7 +22045,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
 }
 }
 
-for (tmp = disk-src; tmp; tmp = tmp-backingStore) {
+for (tmp = disk-src; tmp; tmp = virStorageSourceGetBackingStore(tmp, 0)) {
 int actualType = virStorageSourceGetActualType(tmp);
 /* execute the callback only for local storage */
 if (actualType != VIR_STORAGE_TYPE_NETWORK 
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 4852dfb..5781374 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1326,7 +1326,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 if (virStorageSize(unit, capacity, ret-target.capacity)  0)
 goto error;
 } else if (!(flags  VIR_VOL_XML_PARSE_NO_CAPACITY) 
-   !((flags  VIR_VOL_XML_PARSE_OPT_CAPACITY)  
ret-target.backingStore)) {
+   !((flags  VIR_VOL_XML_PARSE_OPT_CAPACITY)  
virStorageSourceGetBackingStore(ret-target, 0))) {
 virReportError(VIR_ERR_XML_ERROR, %s, _(missing capacity element));
 goto error;
 }
@@ -1635,9 +1635,9 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
  def-target, target)  0)
 goto cleanup;
 
-if (def-target.backingStore 
+if (virStorageSourceGetBackingStore(def-target, 0) 
 virStorageVolTargetDefFormat(options, buf,
- def-target.backingStore,
+ 
virStorageSourceGetBackingStore(def-target, 0),
  backingStore)  0)
 goto cleanup;
 
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index e83342d..44363c9 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -121,7 +121,7 @@ qemuSetupDiskCgroup(virDomainObjPtr vm,
 virStorageSourcePtr next;
 bool forceReadonly = false;
 
-for (next = disk-src; next; next = next-backingStore) {
+for (next = disk-src; next; next = virStorageSourceGetBackingStore(next, 
0)) {
 if (qemuSetImageCgroupInternal(vm, next, false, forceReadonly)  0)
 return -1;
 
@@ -139,7 +139,7 @@ qemuTeardownDiskCgroup(virDomainObjPtr vm,
 {
 virStorageSourcePtr next;
 
-for (next = disk-src; next; next = next-backingStore) {
+for (next = disk-src; next; next = virStorageSourceGetBackingStore(next, 
0)) {
 if (qemuSetImageCgroup(vm, next, true)  0)
 return -1;
 }
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 1368386..5415f04 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c

[libvirt] [PATCH v5 7/9] domain_conf: Read and Write quorum config

2015-04-23 Thread Matthias Gatto
Add the capabiltty to libvirt to parse and format the quorum syntax
as described here:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c | 164 +++--
 1 file changed, 119 insertions(+), 45 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a3a6c13..ec93b6f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5952,20 +5952,56 @@ virDomainDiskSourceParse(xmlNodePtr node,
 }
 
 
+static bool
+virDomainDiskThresholdParse(virStorageSourcePtr src,
+xmlNodePtr node)
+{
+char *threshold = virXMLPropString(node, threshold);
+int ret;
+
+if (!threshold) {
+virReportError(VIR_ERR_XML_ERROR,
+   %s, _(missing threshold in quorum));
+return false;
+}
+ret = virStrToLong_ul(threshold, NULL, 10, src-threshold);
+if (ret  0 || src-threshold  2) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _(unexpected threshold %s),
+   threshold must be a decimal number superior to 2 
+ and inferior to the number of children);
+VIR_FREE(threshold);
+return false;
+}
+VIR_FREE(threshold);
+return true;
+}
+
+
 static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
-   virStorageSourcePtr src)
+   virStorageSourcePtr src,
+   xmlNodePtr node,
+   size_t pos)
 {
 virStorageSourcePtr backingStore = NULL;
 xmlNodePtr save_ctxt = ctxt-node;
-xmlNodePtr source;
+xmlNodePtr source = NULL;
 char *type = NULL;
 char *format = NULL;
 int ret = -1;
 
-if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
-ret = 0;
-goto cleanup;
+if (src-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!node) {
+ret = 0;
+goto cleanup;
+}
+ctxt-node = node;
+} else {
+if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
+ret = 0;
+goto cleanup;
+}
 }
 
 if (VIR_ALLOC(backingStore)  0)
@@ -5997,6 +6033,25 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
+if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) {
+xmlNodePtr cur = NULL;
+
+if (!virDomainDiskThresholdParse(backingStore, node))
+goto cleanup;
+
+for (cur = node-children; cur != NULL; cur = cur-next) {
+if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
+if ((virDomainDiskBackingStoreParse(ctxt,
+backingStore,
+cur,
+
backingStore-nBackingStores)  0)) {
+goto cleanup;
+}
+}
+}
+goto exit;
+}
+
 if (!(source = virXPathNode(./source, ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, %s,
_(missing disk backing store source));
@@ -6004,10 +6059,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 }
 
 if (virDomainDiskSourceParse(source, ctxt, backingStore)  0 ||
-virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
+virDomainDiskBackingStoreParse(ctxt, backingStore, NULL, 0)  0)
 goto cleanup;
 
-if (!virStorageSourceSetBackingStore(src, backingStore, 0))
+ exit:
+if (!virStorageSourceSetBackingStore(src, backingStore, pos))
 goto cleanup;
 ret = 0;
 
@@ -6020,7 +6076,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 return ret;
 }
 
-
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
 
@@ -6518,6 +6573,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 } else if (xmlStrEqual(cur-name, BAD_CAST boot)) {
 /* boot is parsed as part of virDomainDeviceInfoParseXML */
+} else if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
+if (virDomainDiskBackingStoreParse(ctxt, def-src, cur,
+   def-src-nBackingStores)  
0)
+goto error;
 }
 }
 cur = cur-next;
@@ -6541,12 +6600,19 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 def-device = VIR_DOMAIN_DISK_DEVICE_DISK;
 }
 
+if (def-src-type == VIR_STORAGE_TYPE_QUORUM 
+!virDomainDiskThresholdParse(def-src, node))
+goto error;
+
+snapshot = virXMLPropString(node, snapshot);
+
 /* Only CDROM and Floppy devices are allowed missing source path
  * to indicate no media present. LUN is for raw access CD-ROMs
  * that are not attached to a physical device

[libvirt] [PATCH v5 3/9] virstoragefile: Add virStorageSourceSetBackingStore

2015-04-23 Thread Matthias Gatto
As explained for virStorageSourceGetBackingStore, quorum allows
multiple backing store, this make the operation to set bs complex
because we have to check if the backingStore is used as an array
or a pointer, and set it differently in both case.

In order to help the manipulation of backing store, I've added a
function virStorageSourceSetBackingStore.

For now virStorageSourceSetBackingStore don't handle the case where
we have more than one backing store in virStorageSource.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
Signed-off-by: John Ferlan jfer...@redhat.com
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 10 ++
 src/util/virstoragefile.h |  3 +++
 3 files changed, 14 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6893054..ee0db4f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2124,6 +2124,7 @@ virStorageSourceParseRBDColonString;
 virStorageSourcePoolDefFree;
 virStorageSourcePoolModeTypeFromString;
 virStorageSourcePoolModeTypeToString;
+virStorageSourceSetBackingStore;
 virStorageTypeFromString;
 virStorageTypeToString;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 620f490..d69f49d 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1817,6 +1817,16 @@ virStorageSourceGetBackingStore(const virStorageSource 
*src,
 }
 
 
+bool
+virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr backingStore,
+size_t pos ATTRIBUTE_UNUSED)
+{
+src-backingStore = backingStore;
+return !!src-backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 4262b36..5f76324 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+bool virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr 
backingStore,
+size_t pos);
 virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
 size_t pos);
 
-- 
2.3.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v5 0/9] qemu: Add quorum support to libvirt

2015-04-23 Thread Matthias Gatto
The purpose of these patches is to introduce quorum for libvirt
I've try to follow this proposal:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

This feature ask for 6 task:

1) Allow a _virStorageSource to contain more than one backing store.

Because all the actual libvirt code use the backingStore field
as a pointer and we needs want to change that, I've decide to encapsulate
the backingStore field to simplifie the array manipulation.

2) Add the missing field a quorum need in _virStorageSource and
the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
their respectives enums.

3) Parse and format the xml
Because a quorum allows to have more than one backing store at the same level
we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
in a loop.
virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
call themself recursively in a loop because a quorum can contain another
quorum

4) Add nodename
We need to add nodename support in _virStorageSource because qemu
use them for their child.

5) Build qemu string
As for the xml, we have to call the function which create quorum recursively.
But this task have the problem explained here:
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
The _virStorageSource missing some informations that can be passed to
a child, and therefore this version of quorum is incomplet.

6) Allow to hotplug/change a disk in a quorum
This part is not present in these patches because for this task
we have to use blockdev-add, and currently libvirt use
device_add for hotpluging that doesn't allow to hotplug quorum childs.

There is 3 way to handle this problem:
  1) create a virDomainBlockDevAdd function in libvirt witch call
 blockdev-add.

  2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice

  3) write a hack which uses blockdev-add when only attaching quorum
(but i'm pretty sure this solution is not the good one)

V2:
-Rebase on master
-Add Documentation

V3:
-Transforme the backingStore field in virStorageSource into
 an array of pointer instead of a pointer
-Modify virStorageSourceSetBackingStore to allow it to expand
 the backingStore size.

V4:
-Rebase on master

V5:
-Rebase on master
-patch 1-4/9: use patchs from John Ferlan 
-patch 4/9: check return of virStorageSourceSetBackingStore
-patch 5/9: report type of error on virStorageSourceSetBackingStore

Matthias Gatto (9):
  virstoragefile: Add virStorageSourceGetBackingStore
  virstoragefile: Always use virStorageSourceGetBackingStore to get
backing store
  virstoragefile: Add virStorageSourceSetBackingStore
  virstoragefile: Always use virStorageSourceSetBackingStore to set
backing store
  virstoragefile: change backingStore to backingStores.
  virstoragefile: Add quorum in virstoragefile
  domain_conf: Read and Write quorum config
  qemu: Add quorum support in qemuBuildDriveDevStr
  virstoragefile: Add node-name

 docs/formatdomain.html.in |  30 +-
 docs/schemas/domaincommon.rng |  26 -
 docs/schemas/storagecommon.rng|   1 +
 docs/schemas/storagevol.rng   |   1 +
 src/conf/domain_conf.c| 195 ++
 src/conf/storage_conf.c   |  23 ++--
 src/libvirt_private.syms  |   2 +
 src/qemu/qemu_cgroup.c|   4 +-
 src/qemu/qemu_command.c   | 114 
 src/qemu/qemu_domain.c|   2 +-
 src/qemu/qemu_driver.c|  39 ---
 src/qemu/qemu_migration.c |   1 +
 src/qemu/qemu_monitor_json.c  |   4 +-
 src/security/security_dac.c   |   2 +-
 src/security/security_selinux.c   |   4 +-
 src/security/virt-aa-helper.c |   2 +-
 src/storage/storage_backend.c |  22 ++--
 src/storage/storage_backend_fs.c  |  38 ---
 src/storage/storage_backend_gluster.c |  11 +-
 src/storage/storage_backend_logical.c |  15 ++-
 src/storage/storage_driver.c  |   3 +-
 src/util/virstoragefile.c | 122 ++---
 src/util/virstoragefile.h |  13 ++-
 tests/virstoragetest.c|  18 ++--
 24 files changed, 551 insertions(+), 141 deletions(-)

-- 
2.3.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v5 1/9] virstoragefile: Add virStorageSourceGetBackingStore

2015-04-23 Thread Matthias Gatto
Create virStorageSourceGetBackingStore function in
preparation for quorum:
Actually, if we want to get a backing store inside a virStorageSource
we have to do it manually(src-backingStore = backingStore).
The problem is that with a quorum, a virStorageSource
can contain multiple backing stores, and src-backingStore can
be treated as a virStorageSourcePtr or a virStorageSourcePtrPtr.

Due to these reason, we need to simplify the manipulation of
virStorageSource, and create a function to get the asked
backingStore in a virStorageSource

For now, this function only return the backingStore field

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/libvirt_private.syms  | 1 +
 src/util/virstoragefile.c | 8 
 src/util/virstoragefile.h | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8c50ea2..6893054 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2114,6 +2114,7 @@ virStorageSourceClear;
 virStorageSourceCopy;
 virStorageSourceFree;
 virStorageSourceGetActualType;
+virStorageSourceGetBackingStore;
 virStorageSourceGetSecurityLabelDef;
 virStorageSourceInitChainElement;
 virStorageSourceIsEmpty;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 9507ca1..e6ed573 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1809,6 +1809,14 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+virStorageSourcePtr
+virStorageSourceGetBackingStore(const virStorageSource *src,
+size_t pos ATTRIBUTE_UNUSED)
+{
+return src-backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index aa17a00..4262b36 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
+size_t pos);
+
 int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
 int virStorageFileProbeFormatFromBuf(const char *path,
  char *buf,
-- 
2.3.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v5 4/9] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store

2015-04-23 Thread Matthias Gatto
Replace the parts of the code where a backing store is set manually
with virStorageSourceSetBackingStore

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
Signed-off-by: John Ferlan jfer...@redhat.com
---
 src/conf/domain_conf.c|  3 ++-
 src/conf/storage_conf.c   | 17 ++---
 src/qemu/qemu_driver.c| 17 +++--
 src/storage/storage_backend_fs.c  |  7 +--
 src/storage/storage_backend_gluster.c |  5 +++--
 src/storage/storage_backend_logical.c |  9 ++---
 src/storage/storage_driver.c  |  3 ++-
 src/util/virstoragefile.c |  8 +---
 tests/virstoragetest.c|  4 ++--
 9 files changed, 46 insertions(+), 27 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2a05291..09f0bca 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6006,7 +6006,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
 goto cleanup;
 
-src-backingStore = backingStore;
+if (!virStorageSourceSetBackingStore(src, backingStore, 0))
+goto cleanup;
 ret = 0;
 
  cleanup:
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 5781374..ca3a6d5 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1254,6 +1254,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 char *capacity = NULL;
 char *unit = NULL;
 char *backingStore = NULL;
+virStorageSourcePtr backingStorePtr;
 xmlNodePtr node;
 xmlNodePtr *nodes = NULL;
 size_t i;
@@ -1290,20 +1291,22 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 }
 
 if ((backingStore = virXPathString(string(./backingStore/path), ctxt))) {
-if (VIR_ALLOC(ret-target.backingStore)  0)
+if (VIR_ALLOC(backingStorePtr)  0)
 goto error;
 
-ret-target.backingStore-path = backingStore;
+if (!virStorageSourceSetBackingStore(ret-target, backingStorePtr, 0))
+goto error;
+backingStorePtr-path = backingStore;
 backingStore = NULL;
 
 if (options-formatFromString) {
 char *format = 
virXPathString(string(./backingStore/format/@type), ctxt);
 if (format == NULL)
-ret-target.backingStore-format = options-defaultFormat;
+backingStorePtr-format = options-defaultFormat;
 else
-ret-target.backingStore-format = 
(options-formatFromString)(format);
+backingStorePtr-format = (options-formatFromString)(format);
 
-if (ret-target.backingStore-format  0) {
+if (backingStorePtr-format  0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_(unknown volume format type %s), format);
 VIR_FREE(format);
@@ -1312,9 +1315,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 VIR_FREE(format);
 }
 
-if (VIR_ALLOC(ret-target.backingStore-perms)  0)
+if (VIR_ALLOC(backingStorePtr-perms)  0)
 goto error;
-if (virStorageDefParsePerms(ctxt, ret-target.backingStore-perms,
+if (virStorageDefParsePerms(ctxt, backingStorePtr-perms,
 ./backingStore/permissions,
 DEFAULT_VOL_PERM_MODE)  0)
 goto error;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 26be9d6..1a98601 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14274,13 +14274,18 @@ 
qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes.  */
 need_unlink = false;
 
-newDiskSrc-backingStore = disk-src;
-disk-src = newDiskSrc;
+if (!virStorageSourceSetBackingStore(newDiskSrc, disk-src, 0)) {
+ret = -1;
+goto cleanup;
+}
 newDiskSrc = NULL;
 
 if (persistDisk) {
-persistDiskSrc-backingStore = persistDisk-src;
-persistDisk-src = persistDiskSrc;
+if (!virStorageSourceSetBackingStore(persistDiskSrc,
+ persistDisk-src, 0)) {
+ret = -1;
+goto cleanup;
+}
 persistDiskSrc = NULL;
 }
 
@@ -14323,13 +14328,13 @@ 
qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes. */
 tmp = disk-src;
 disk-src = virStorageSourceGetBackingStore(tmp, 0);
-tmp-backingStore = NULL;
+ignore_value(virStorageSourceSetBackingStore(tmp, NULL, 0));
 virStorageSourceFree(tmp);
 
 if (persistDisk) {
 tmp = persistDisk-src;
 persistDisk-src = virStorageSourceGetBackingStore(tmp, 0);
-tmp-backingStore = NULL;
+ignore_value(virStorageSourceSetBackingStore(tmp, NULL, 0));
 virStorageSourceFree(tmp);
 }
 }
diff --git a/src/storage

[libvirt] [PATCH v5 9/9] virstoragefile: Add node-name

2015-04-23 Thread Matthias Gatto
Add nodename inside virstoragefile
During xml backingStore parsing, look for a nodename attribute in the disk
declaration if this one is a quorum, if a nodename is found, add it to
the virStorageSource otherwise create a new one with a random name.
Take inspiration from this patch to create the nodename:
http://lists.gnu.org/archive/html/qemu-devel/2014-05/msg03209.html

Durring xml backingStore formating, look for a nodename attribute inside the
virStorageSource struct, and add it to the disk element.

Use the nodename to create the quorum in qemuBuildQuorumStr.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 docs/formatdomain.html.in |  7 +++
 docs/schemas/domaincommon.rng |  5 +
 src/conf/domain_conf.c| 27 +++
 src/qemu/qemu_command.c   |  3 +++
 src/util/virstoragefile.c |  4 
 src/util/virstoragefile.h |  1 +
 6 files changed, 47 insertions(+)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 7d058ec..d9afe36 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2183,6 +2183,13 @@
 codevda[2]/code refers to the backing store with
 codeindex='2'/code of the disk with codevda/code target.
   /dd
+  dtcodenodename/code attribute
+  span class=sincesince 1.2.13/span/dt
+  dd
+When the backing store is a quorum child, we can use this attribute
+to define the node-name of a child. If this atribute is undefine,
+a random nodename is generate.
+  /dd
   dtcodeformat/code sub-element/dt
   dd
 The codeformat/code element contains codetype/code
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 6cd834e..30694d9 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1236,6 +1236,11 @@
 ref name=positiveInteger/
   /attribute
   interleave
+optional
+  attribute name=nodename
+text/
+  /attribute
+/optional
 ref name=diskSource/
 ref name=diskBackingChain/
 ref name=diskFormat/
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ec93b6f..46eeae2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -54,6 +54,7 @@
 #include network_conf.h
 #include virtpm.h
 #include virstring.h
+#include virrandom.h
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -5978,6 +5979,8 @@ virDomainDiskThresholdParse(virStorageSourcePtr src,
 }
 
 
+#define GEN_NODE_NAME_PREFIXlibvirt
+#define GEN_NODE_NAME_MAX_LEN   (sizeof(GEN_NODE_NAME_PREFIX) + 8 + 8)
 static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
virStorageSourcePtr src,
@@ -6020,6 +6023,26 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
+if (src-type == VIR_STORAGE_TYPE_QUORUM) {
+char *nodeName = NULL;
+
+if ((nodeName = virXMLPropString(ctxt-node, nodename))) {
+backingStore-nodeName = nodeName;
+} else {
+size_t len;
+
+if (VIR_ALLOC_N(nodeName, GEN_NODE_NAME_MAX_LEN)  0)
+goto cleanup;
+if (snprintf(nodeName, GEN_NODE_NAME_MAX_LEN,
+ %s%08x, GEN_NODE_NAME_PREFIX, (int)pos)  0)
+goto cleanup;
+for (len = strlen(nodeName); len  GEN_NODE_NAME_MAX_LEN - 1; 
++len)
+nodeName[len] = virRandomInt('Z' - 'A') + 'A';
+nodeName[GEN_NODE_NAME_MAX_LEN - 1] = '\0';
+backingStore-nodeName = nodeName;
+}
+}
+
 if (!(format = virXPathString(string(./format/@type), ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, %s,
_(missing disk backing store format));
@@ -6075,6 +6098,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 ctxt-node = save_ctxt;
 return ret;
 }
+#undef GEN_NODE_NAME_PREFIX
+#undef GEN_NODE_NAME_MAX_LEN
 
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
@@ -17817,6 +17842,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
   type, idx);
 if (backingStore-threshold)
 virBufferAsprintf(buf,  threshold='%lu', 
backingStore-threshold);
+if (backingStore-nodeName)
+virBufferAsprintf(buf,  nodename='%s', backingStore-nodeName);
 virBufferAddLit(buf, \n);
 virBufferAdjustIndent(buf, 2);
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 80cbb7d..ac09750 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3567,6 +3567,9 @@ qemuBuildQuorumStr(virConnectPtr conn,
   toAppend, i,
   
virStorageFileFormatTypeToString(backingStore-format));
 
+virBufferAsprintf(opt, ,%schildren.%lu.node-name=%s,
+  toAppend, i, backingStore-nodeName

[libvirt] [PATCH v5 5/9] virstoragefile: change backingStore to backingStores.

2015-04-23 Thread Matthias Gatto
The backingStore field was a virStorageSourcePtr.
because a quorum can contain more that one backingStore at the same level
it's now a 'virStorageSourcePtr *'.

This patch rename  src-backingStore to src-backingStores,
add a static function virStorageSourceExpandBackingStore
(virStorageSourcePushBackingStore in the V2) and made the necessary 
modification to
virStorageSourceSetBackingStore and virStorageSourceGetBackingStore.
virStorageSourceSetBackingStore can now expand size of src-backingStores
by calling virStorageSourceExpandBackingStore if necessary.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/storage/storage_backend.c|  2 +-
 src/storage/storage_backend_fs.c |  2 +-
 src/util/virstoragefile.c| 75 +++-
 src/util/virstoragefile.h|  3 +-
 4 files changed, 71 insertions(+), 11 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 269a93b..b0eb976 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -487,7 +487,7 @@ virStorageBackendCreateRaw(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 goto cleanup;
 }
 
-if (vol-target.backingStore) {
+if (vol-target.backingStores) {
 virReportError(VIR_ERR_NO_SUPPORT, %s,
_(backing storage not supported for raw volumes));
 goto cleanup;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index bab2569..dd9ccb5 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1048,7 +1048,7 @@ static int createFileDir(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 return -1;
 }
 
-if (vol-target.backingStore) {
+if (vol-target.backingStores) {
 virReportError(VIR_ERR_NO_SUPPORT, %s,
_(backing storage not supported for directories 
volumes));
 return -1;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 234a72b..f0450b5 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1809,21 +1809,72 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+/**
+ * virStorageSourceGetBackingStore:
+ * @src: virStorageSourcePtr containing the backing stores
+ * @pos: position of the backing store to get
+ *
+ * return the backingStore at the position of @pos
+ */
 virStorageSourcePtr
-virStorageSourceGetBackingStore(const virStorageSource *src,
-size_t pos ATTRIBUTE_UNUSED)
+virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos)
 {
-return src-backingStore;
+if (!src || !src-backingStores || pos = src-nBackingStores)
+return NULL;
+return src-backingStores[pos];
 }
 
 
+/**
+ * virStorageSourcePushBackingStore:
+ *
+ * Expand src-backingStores and update src-nBackingStores
+ */
+static bool
+virStorageSourceExpandBackingStore(virStorageSourcePtr src, size_t nbr)
+{
+if (!src) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   %s, _(src is NULL));
+return false;
+}
+if (src-nBackingStores  0) {
+if (VIR_EXPAND_N(src-backingStores, src-nBackingStores, nbr)  0)
+goto allocation_failed;
+} else {
+if (VIR_ALLOC_N(src-backingStores, nbr)  0)
+goto allocation_failed;
+src-nBackingStores += nbr;
+}
+return true;
+ allocation_failed:
+virReportOOMError();
+return false;
+}
+
+
+/**
+ * virStorageSourceSetBackingStore:
+ * @src: virStorageSourcePtr to hold @backingStore
+ * @backingStore: backingStore to store
+ * @pos: position of the backing store to store
+ *
+ * Set @backingStore at @pos in src-backingStores.
+ * If src-backingStores don't have the space to contain
+ * @backingStore, we expand src-backingStores
+ */
 bool
 virStorageSourceSetBackingStore(virStorageSourcePtr src,
 virStorageSourcePtr backingStore,
-size_t pos ATTRIBUTE_UNUSED)
+size_t pos)
 {
-src-backingStore = backingStore;
-return !!src-backingStore;
+if (!src)
+return false;
+if (pos = src-nBackingStores 
+!virStorageSourceExpandBackingStore(src, pos - src-nBackingStores + 
1))
+return false;
+src-backingStores[pos] = backingStore;
+return true;
 }
 
 
@@ -2038,6 +2089,8 @@ virStorageSourceIsEmpty(virStorageSourcePtr src)
 void
 virStorageSourceBackingStoreClear(virStorageSourcePtr def)
 {
+size_t i;
+
 if (!def)
 return;
 
@@ -2045,8 +2098,14 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr 
def)
 VIR_FREE(def-backingStoreRaw);
 
 /* recursively free backing chain */
-virStorageSourceFree(virStorageSourceGetBackingStore(def, 0));
-virStorageSourceSetBackingStore(def, NULL, 0);
+for (i = 0; i  def-nBackingStores; ++i)
+virStorageSourceFree(virStorageSourceGetBackingStore(def, i

Re: [libvirt] [PATCH v4 0/9] qemu: Add quorum support to libvirt

2015-04-20 Thread Matthias Gatto
On Thu, Apr 16, 2015 at 3:43 PM, John Ferlan jfer...@redhat.com wrote:


 On 03/17/2015 03:25 PM, Matthias Gatto wrote:
 The purpose of these patches is to introduce quorum for libvirt
 I've try to follow this proposal:
 http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html



 Before we reach a year waiting on this and so we make some progress...

 I started looking at the series and naturally found conflicts with the
 patches. Not to be deterred I started with the first 5 patches since I
 figured they were mostly setup and not functional change.

 Of those patch 2 had the most conflict. Once resolved, patches 3-5
 applied without issue... Patch 6, more conflicts, so I just focused on
 1-5...

 Patch 2 had numerous conflicts in virStorageBackendCreateQemuImgCmd due
 to commit id fbcf7da95b872ac45cabc4356fc9c06e809d0237.

 After applying patch 5, I cscope searched on -backingStore in order
 to find any 'new' references that might have crept in (ignoring any
 backingStoreRaw references) and found:

 f9ea3d60119e82c02c00fbf3678c3ed20634dea1 (qemu_monitor_json.c)

 which I adjusted patch 2 in order to keep it in line.

 Beyond that in patch 2:

   * In storage_conf.c/*VolDefFormat() - I changed the (def-target)
 to just def-target which was mostly a consistency thing. I found a
 couple of others as well and adjusted them. I don't think it matters,
 since none of the references were (x-y)-z

   * In storage_backend_fs.c/virStorageBackendProbeTarget() - you created
 a *local* backingStore reference and then used that for an assignment,
 but didn't update target-backingStore in at least the first
 case/instance, so since we're not updating the setting in this pass, I
 adjusted the code as follows:

 -if (!(target-backingStore = virStorageSourceNewFromBacking(meta)))
 +backingStore = virStorageSourceGetBackingStore(target, 0);
 +if (!(backingStore = virStorageSourceNewFromBacking(meta)))

 back to setting target-backingStore in the if statement, then fetching
 after the if statement into the local variable:

 -backingStore = virStorageSourceGetBackingStore(target, 0);
 -if (!(backingStore = virStorageSourceNewFromBacking(meta)))
 +if (!(target-backingStore = virStorageSourceNewFromBacking(meta)))
  goto cleanup;

 +backingStore = virStorageSourceGetBackingStore(target, 0);


 I believe the virStorageSourceFree(backingStore) that follows will be OK
 since you'd be replacing it anyway in the if statement.

 I'll post my changes as a reply to patch 2 shortly.

 Of course changing the storage_backend_fs.c in patch 2 caused a ripple
 effect (like I expected) in patch 4, but no changes were necessary since
 patch 4 did the set and I had added the fetch after the set as part of
 my patch 2 adjustment.

 In patch 3, you have a 'bool' function returning a pointer value (which
 can either be something or NULL.  I'm changing that to return
 !!src-backingStore;, which is what I believe you're really trying to
 return here.  There's a couple places where it's checked, but luckily so
 far nothing happens with those checks and from what I read...

  * virDomainDiskBackingStoreParse - Code has already dereferenced
 backingStore so we know it won't return false

  * virStorageBackendProbeTarget - virStorageSourceNewFromBacking
 fetch/failure would be the same

  * virStorageBackendLogicalMakeVol - If backingStore was NULL we would
 have failed earlier

  * virStorageSourceCopy - virStorageSourceCopy fetch/failure would be
 the same

 As long as you think that looks good - I can push patches 1-4.

 While Patch 5 did apply cleanly, there are some issues with it. In patch
 3 it's returning true/false and failures in virStorageBackendProbeTarget
 and virStorageSourceCopy would return some message as to why it failed
 (most likely memory allocation failures) which then propagate back to
 the caller to get a reason for the failure. With your change to patch
 5, you're returning true/false only without always setting the reason
 (eg virReportError). That reason needs to be set so failure reason can
 be propagated back to the caller instead of the infamous failed for
 some reason.

 Additionally in all the places that don't check the return, you should
 add a ignore_value() around them to signify the code doesn't care (or
 maybe check those places to see if that don't care assumption is true).

 Once 5 is reworked, you'll have to rework patches 6-9 and repost since
 that's where the real/new functionality starts.

 Tks,

 John

 This feature ask for 6 task:

 1) Allow a _virStorageSource to contain more than one backing store.

 Because all the actual libvirt code use the backingStore field
 as a pointer and we needs want to change that, I've decide to encapsulate
 the backingStore field to simplifie the array manipulation.

 2) Add the missing field a quorum need in _virStorageSource and
 the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM

Re: [libvirt] [PATCH v4 0/9] qemu: Add quorum support to libvirt

2015-03-31 Thread Matthias Gatto
On Tue, Mar 17, 2015 at 8:25 PM, Matthias Gatto
matthias.ga...@outscale.com wrote:
 The purpose of these patches is to introduce quorum for libvirt
 I've try to follow this proposal:
 http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

 This feature ask for 6 task:

 1) Allow a _virStorageSource to contain more than one backing store.

 Because all the actual libvirt code use the backingStore field
 as a pointer and we needs want to change that, I've decide to encapsulate
 the backingStore field to simplifie the array manipulation.

 2) Add the missing field a quorum need in _virStorageSource and
 the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
 their respectives enums.

 3) Parse and format the xml
 Because a quorum allows to have more than one backing store at the same level
 we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
 to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
 in a loop.
 virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
 call themself recursively in a loop because a quorum can contain another
 quorum

 4) Add nodename
 We need to add nodename support in _virStorageSource because qemu
 use them for their child.

 5) Build qemu string
 As for the xml, we have to call the function which create quorum recursively.
 But this task have the problem explained here:
 http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
 The _virStorageSource missing some informations that can be passed to
 a child, and therefore this version of quorum is incomplet.

 6) Allow to hotplug/change a disk in a quorum
 This part is not present in these patches because for this task
 we have to use blockdev-add, and currently libvirt use
 device_add for hotpluging that doesn't allow to hotplug quorum childs.

 There is 3 way to handle this problem:
   1) create a virDomainBlockDevAdd function in libvirt witch call
   blockdev-add.

   2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice

   3) write a hack which uses blockdev-add when only attaching quorum
   (but i'm pretty sure this solution is not the good one)

 V2:
 -Rebase on master
 -Add Documentation

 V3:
 -Transforme the backingStore field in virStorageSource into
  an array of pointer instead of a pointer
 -Modify virStorageSourceSetBackingStore to allow it to expand
  the backingStore size.

 V4:
 -Rebase on master

 Matthias Gatto (9):
   virstoragefile: Add virStorageSourceGetBackingStore
   virstoragefile: Always use virStorageSourceGetBackingStore to get
 backing store
   virstoragefile: Add virStorageSourceSetBackingStore
   virstoragefile: Always use virStorageSourceSetBackingStore to set
 backing store
   virstoragefile: change backingStore to backingStores.
   virstoragefile: Add quorum in virstoragefile
   domain_conf: Read and Write quorum config
   qemu: Add quorum support in qemuBuildDriveDevStr
   virstoragefile: Add node-name

  docs/formatdomain.html.in |  27 -
  docs/schemas/domaincommon.rng |  95 +++--
  docs/schemas/storagecommon.rng|   1 +
  docs/schemas/storagevol.rng   |   1 +
  src/conf/domain_conf.c| 195 
 ++
  src/conf/storage_conf.c   |  22 ++--
  src/libvirt_private.syms  |   2 +
  src/qemu/qemu_cgroup.c|   4 +-
  src/qemu/qemu_command.c   | 114 
  src/qemu/qemu_domain.c|   2 +-
  src/qemu/qemu_driver.c|  30 +++---
  src/qemu/qemu_migration.c |   1 +
  src/security/security_dac.c   |   2 +-
  src/security/security_selinux.c   |   4 +-
  src/security/virt-aa-helper.c |   2 +-
  src/storage/storage_backend.c |  35 +++---
  src/storage/storage_backend_fs.c  |  37 ---
  src/storage/storage_backend_gluster.c |  10 +-
  src/storage/storage_backend_logical.c |  15 ++-
  src/storage/storage_driver.c  |   2 +-
  src/util/virstoragefile.c | 116 +---
  src/util/virstoragefile.h |  13 ++-
  tests/virstoragetest.c|  18 ++--
  23 files changed, 573 insertions(+), 175 deletions(-)

 --
 1.8.3.1


ping

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v4 4/9] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store

2015-03-17 Thread Matthias Gatto
Replace the parts of the code where a backing store is set manually
with virStorageSourceSetBackingStore

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c|  3 ++-
 src/conf/storage_conf.c   | 16 +---
 src/qemu/qemu_driver.c|  8 
 src/storage/storage_backend_fs.c  |  8 +---
 src/storage/storage_backend_gluster.c |  4 ++--
 src/storage/storage_backend_logical.c |  9 ++---
 src/storage/storage_driver.c  |  2 +-
 src/util/virstoragefile.c |  8 +---
 tests/virstoragetest.c|  4 ++--
 9 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3fd73d7..74f6efa 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5869,7 +5869,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
 goto cleanup;
 
-src-backingStore = backingStore;
+if (!virStorageSourceSetBackingStore(src, backingStore, 0))
+goto cleanup;
 ret = 0;
 
  cleanup:
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 7ca678b..a6753e6 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1255,6 +1255,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 char *capacity = NULL;
 char *unit = NULL;
 char *backingStore = NULL;
+virStorageSourcePtr backingStorePtr;
 xmlNodePtr node;
 xmlNodePtr *nodes = NULL;
 size_t i;
@@ -1291,20 +1292,21 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 }
 
 if ((backingStore = virXPathString(string(./backingStore/path), ctxt))) {
-if (VIR_ALLOC(ret-target.backingStore)  0)
+if (VIR_ALLOC(backingStorePtr)  0)
 goto error;
 
-ret-target.backingStore-path = backingStore;
+virStorageSourceSetBackingStore(ret-target, backingStorePtr, 0);
+backingStorePtr-path = backingStore;
 backingStore = NULL;
 
 if (options-formatFromString) {
 char *format = 
virXPathString(string(./backingStore/format/@type), ctxt);
 if (format == NULL)
-ret-target.backingStore-format = options-defaultFormat;
+backingStorePtr-format = options-defaultFormat;
 else
-ret-target.backingStore-format = 
(options-formatFromString)(format);
+backingStorePtr-format = (options-formatFromString)(format);
 
-if (ret-target.backingStore-format  0) {
+if (backingStorePtr-format  0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_(unknown volume format type %s), format);
 VIR_FREE(format);
@@ -1313,9 +1315,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 VIR_FREE(format);
 }
 
-if (VIR_ALLOC(ret-target.backingStore-perms)  0)
+if (VIR_ALLOC(backingStorePtr-perms)  0)
 goto error;
-if (virStorageDefParsePerms(ctxt, ret-target.backingStore-perms,
+if (virStorageDefParsePerms(ctxt, backingStorePtr-perms,
 ./backingStore/permissions,
 DEFAULT_VOL_PERM_MODE)  0)
 goto error;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e6fb2ae..8f33970 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14123,12 +14123,12 @@ 
qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes.  */
 need_unlink = false;
 
-newDiskSrc-backingStore = disk-src;
+virStorageSourceSetBackingStore(newDiskSrc, disk-src, 0);
 disk-src = newDiskSrc;
 newDiskSrc = NULL;
 
 if (persistDisk) {
-persistDiskSrc-backingStore = persistDisk-src;
+virStorageSourceSetBackingStore(persistDiskSrc, persistDisk-src, 0);
 persistDisk-src = persistDiskSrc;
 persistDiskSrc = NULL;
 }
@@ -14172,13 +14172,13 @@ 
qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes. */
 tmp = disk-src;
 disk-src = virStorageSourceGetBackingStore(tmp, 0);
-tmp-backingStore = NULL;
+virStorageSourceSetBackingStore(tmp, NULL, 0);
 virStorageSourceFree(tmp);
 
 if (persistDisk) {
 tmp = persistDisk-src;
 persistDisk-src = virStorageSourceGetBackingStore(tmp, 0);
-tmp-backingStore = NULL;
+virStorageSourceSetBackingStore(tmp, NULL, 0);
 virStorageSourceFree(tmp);
 }
 }
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 8df2c0d..8c6d0b2 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -97,10 +97,12 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
 goto cleanup;
 
 if (meta

[libvirt] [PATCH v4 2/9] virstoragefile: Always use virStorageSourceGetBackingStore to get backing store

2015-03-17 Thread Matthias Gatto
Uniformize backing store usage by calling virStorageSourceGetBackingStore
instead of setting backing store manually.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c|  7 ---
 src/conf/storage_conf.c   |  6 +++---
 src/qemu/qemu_cgroup.c|  4 ++--
 src/qemu/qemu_domain.c|  2 +-
 src/qemu/qemu_driver.c| 18 ++
 src/security/security_dac.c   |  2 +-
 src/security/security_selinux.c   |  4 ++--
 src/security/virt-aa-helper.c |  2 +-
 src/storage/storage_backend.c | 33 ++---
 src/storage/storage_backend_fs.c  | 33 ++---
 src/storage/storage_backend_gluster.c |  8 +---
 src/storage/storage_backend_logical.c | 10 ++
 src/util/virstoragefile.c | 20 ++--
 tests/virstoragetest.c| 14 +++---
 14 files changed, 88 insertions(+), 75 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c75b543..3fd73d7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17252,7 +17252,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
 /* We currently don't output seclabels for backing chain element */
 if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true)  0 ||
 virDomainDiskBackingStoreFormat(buf,
-backingStore-backingStore,
+
virStorageSourceGetBackingStore(backingStore, 0),
 backingStore-backingStoreRaw,
 idx + 1)  0)
 return -1;
@@ -17374,7 +17374,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
 /* Don't format backingStore to inactive XMLs until the code for
  * persistent storage of backing chains is ready. */
 if (!(flags  VIR_DOMAIN_DEF_FORMAT_INACTIVE) 
-virDomainDiskBackingStoreFormat(buf, def-src-backingStore,
+virDomainDiskBackingStoreFormat(buf,
+
virStorageSourceGetBackingStore(def-src, 0),
 def-src-backingStoreRaw, 1)  0)
 return -1;
 
@@ -21456,7 +21457,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
 }
 }
 
-for (tmp = disk-src; tmp; tmp = tmp-backingStore) {
+for (tmp = disk-src; tmp; tmp = virStorageSourceGetBackingStore(tmp, 0)) {
 int actualType = virStorageSourceGetActualType(tmp);
 /* execute the callback only for local storage */
 if (actualType != VIR_STORAGE_TYPE_NETWORK 
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index b070448..7ca678b 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1327,7 +1327,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 if (virStorageSize(unit, capacity, ret-target.capacity)  0)
 goto error;
 } else if (!(flags  VIR_VOL_XML_PARSE_NO_CAPACITY) 
-   !((flags  VIR_VOL_XML_PARSE_OPT_CAPACITY)  
ret-target.backingStore)) {
+   !((flags  VIR_VOL_XML_PARSE_OPT_CAPACITY)  
virStorageSourceGetBackingStore(ret-target, 0))) {
 virReportError(VIR_ERR_XML_ERROR, %s, _(missing capacity element));
 goto error;
 }
@@ -1648,9 +1648,9 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
  def-target, target)  0)
 goto cleanup;
 
-if (def-target.backingStore 
+if (virStorageSourceGetBackingStore((def-target), 0) 
 virStorageVolTargetDefFormat(options, buf,
- def-target.backingStore,
+ 
virStorageSourceGetBackingStore((def-target), 0),
  backingStore)  0)
 goto cleanup;
 
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 3e30767..f04b0bf 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -121,7 +121,7 @@ qemuSetupDiskCgroup(virDomainObjPtr vm,
 virStorageSourcePtr next;
 bool forceReadonly = false;
 
-for (next = disk-src; next; next = next-backingStore) {
+for (next = disk-src; next; next = virStorageSourceGetBackingStore(next, 
0)) {
 if (qemuSetImageCgroupInternal(vm, next, false, forceReadonly)  0)
 return -1;
 
@@ -139,7 +139,7 @@ qemuTeardownDiskCgroup(virDomainObjPtr vm,
 {
 virStorageSourcePtr next;
 
-for (next = disk-src; next; next = next-backingStore) {
+for (next = disk-src; next; next = virStorageSourceGetBackingStore(next, 
0)) {
 if (qemuSetImageCgroup(vm, next, true)  0)
 return -1;
 }
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2eacef2..9ac62e5 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2736,7 +2736,7 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver

[libvirt] [PATCH v4 0/9] qemu: Add quorum support to libvirt

2015-03-17 Thread Matthias Gatto
The purpose of these patches is to introduce quorum for libvirt
I've try to follow this proposal:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

This feature ask for 6 task:

1) Allow a _virStorageSource to contain more than one backing store.

Because all the actual libvirt code use the backingStore field
as a pointer and we needs want to change that, I've decide to encapsulate
the backingStore field to simplifie the array manipulation.

2) Add the missing field a quorum need in _virStorageSource and
the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
their respectives enums.

3) Parse and format the xml
Because a quorum allows to have more than one backing store at the same level
we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
in a loop.
virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
call themself recursively in a loop because a quorum can contain another
quorum

4) Add nodename
We need to add nodename support in _virStorageSource because qemu
use them for their child.

5) Build qemu string
As for the xml, we have to call the function which create quorum recursively.
But this task have the problem explained here: 
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
The _virStorageSource missing some informations that can be passed to
a child, and therefore this version of quorum is incomplet.

6) Allow to hotplug/change a disk in a quorum
This part is not present in these patches because for this task
we have to use blockdev-add, and currently libvirt use
device_add for hotpluging that doesn't allow to hotplug quorum childs.

There is 3 way to handle this problem:
  1) create a virDomainBlockDevAdd function in libvirt witch call
  blockdev-add.

  2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice

  3) write a hack which uses blockdev-add when only attaching quorum
  (but i'm pretty sure this solution is not the good one)

V2:
-Rebase on master
-Add Documentation

V3:
-Transforme the backingStore field in virStorageSource into
 an array of pointer instead of a pointer
-Modify virStorageSourceSetBackingStore to allow it to expand
 the backingStore size.

V4:
-Rebase on master

Matthias Gatto (9):
  virstoragefile: Add virStorageSourceGetBackingStore
  virstoragefile: Always use virStorageSourceGetBackingStore to get
backing store
  virstoragefile: Add virStorageSourceSetBackingStore
  virstoragefile: Always use virStorageSourceSetBackingStore to set
backing store
  virstoragefile: change backingStore to backingStores.
  virstoragefile: Add quorum in virstoragefile
  domain_conf: Read and Write quorum config
  qemu: Add quorum support in qemuBuildDriveDevStr
  virstoragefile: Add node-name

 docs/formatdomain.html.in |  27 -
 docs/schemas/domaincommon.rng |  95 +++--
 docs/schemas/storagecommon.rng|   1 +
 docs/schemas/storagevol.rng   |   1 +
 src/conf/domain_conf.c| 195 ++
 src/conf/storage_conf.c   |  22 ++--
 src/libvirt_private.syms  |   2 +
 src/qemu/qemu_cgroup.c|   4 +-
 src/qemu/qemu_command.c   | 114 
 src/qemu/qemu_domain.c|   2 +-
 src/qemu/qemu_driver.c|  30 +++---
 src/qemu/qemu_migration.c |   1 +
 src/security/security_dac.c   |   2 +-
 src/security/security_selinux.c   |   4 +-
 src/security/virt-aa-helper.c |   2 +-
 src/storage/storage_backend.c |  35 +++---
 src/storage/storage_backend_fs.c  |  37 ---
 src/storage/storage_backend_gluster.c |  10 +-
 src/storage/storage_backend_logical.c |  15 ++-
 src/storage/storage_driver.c  |   2 +-
 src/util/virstoragefile.c | 116 +---
 src/util/virstoragefile.h |  13 ++-
 tests/virstoragetest.c|  18 ++--
 23 files changed, 573 insertions(+), 175 deletions(-)

-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v4 6/9] virstoragefile: Add quorum in virstoragefile

2015-03-17 Thread Matthias Gatto
Add VIR_STORAGE_TYPE_QUORUM in virStorageType.
Add VIR_STORAGE_FILE_QUORUM in virStorageFileFormat.

Add threshold value in _virStorageSource

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 docs/formatdomain.html.in  | 20 +-
 docs/schemas/domaincommon.rng  | 90 +++---
 docs/schemas/storagecommon.rng |  1 +
 docs/schemas/storagevol.rng|  1 +
 src/conf/domain_conf.c |  2 +
 src/qemu/qemu_command.c|  1 +
 src/qemu/qemu_driver.c |  4 ++
 src/qemu/qemu_migration.c  |  1 +
 src/util/virstoragefile.c  | 25 
 src/util/virstoragefile.h  |  3 ++
 10 files changed, 106 insertions(+), 42 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8d98915..6fb87fd 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1852,8 +1852,9 @@
 dd
 Valid values are file, block,
 dir (span class=sincesince 0.7.5/span),
-network (span class=sincesince 0.8.7/span), or
-volume (span class=sincesince 1.0.5/span)
+network (span class=sincesince 0.8.7/span),
+volume (span class=sincesince 1.0.5/span), or
+quorum (span class=sincesince 1.2.13/span)
 and refer to the underlying source for the disk.
 /dd
   dtcodedevice/code attribute
@@ -1914,6 +1915,14 @@
 codesnapshot='yes'/code with a transient disk generally
 does not make sense.
 /dd
+  dtcodethreshold/code attribute
+  span class=sincesince 1.2.13/span/dt
+dd
+Only use with a quorum disk.
+Indicate the minimum of positive vote a quorum must have to 
validate
+a data to be write. The minimum value is 2. The number of 
backingStores
+contain by the quorum must be superior to the threshold.
+/dd
 /dl
   /dd
   dtcodesource/code/dt
@@ -1984,6 +1993,11 @@
   
'file=/dev/disk/by-path/ip-example.com:3260-iscsi-iqn.2013-07.com.example:iscsi-pool-lun-1').
   /p
   /dd
+dtcodetype='quorum'/code
+span class=sincesince 1.2.13/span/dt
+  dd
+  A quorum contain no source element, but a serie of backingStores 
instead.
+  /dd
   /dl
 With file, block, and volume, one or more optional
 sub-elements codeseclabel/code, a href=#seclabeldescribed
@@ -2115,6 +2129,8 @@
 codebackingStore/code element means the sibling source is
 self-contained and is not based on any backing store. The following
 attributes and sub-elements are supported in
+span class=sinceSince 1.2.11/span. This elements is used to
+describe a quorum child.
 codebackingStore/code:
 dl
   dtcodetype/code attribute/dt
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index ebd9299..5a76ae7 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1290,6 +1290,40 @@
 /attribute
   /define
 
+  define name='diskDevice'
+choice
+  group
+optional
+  attribute name=device
+choice
+  valuefloppy/value
+  valuedisk/value
+  valuecdrom/value
+/choice
+  /attribute
+/optional
+  /group
+  group
+attribute name=device
+  choice
+valuelun/value
+  /choice
+/attribute
+optional
+  ref name=rawIO/
+/optional
+optional
+  attribute name=sgio
+choice
+  valuefiltered/value
+  valueunfiltered/value
+/choice
+  /attribute
+/optional
+  /group
+/choice
+  /define
+
   !--
   A disk description can be either of type file or block
   The name of the attribute on the source element depends on the type
@@ -1297,37 +1331,7 @@
 --
   define name=disk
 element name=disk
-  choice
-group
-  optional
-attribute name=device
-  choice
-valuefloppy/value
-valuedisk/value
-valuecdrom/value
-  /choice
-/attribute
-  /optional
-/group
-group
-  attribute name=device
-choice
-  valuelun/value
-/choice
-  /attribute
-  optional
-ref name=rawIO/
-  /optional
-  optional
-attribute name=sgio
-  choice
-valuefiltered/value
-valueunfiltered/value
-  /choice
-/attribute
-  /optional
-/group
-  /choice
+  ref name=diskDevice/
   optional
 ref name=snapshot/
   /optional
@@ -1339,9 +1343,15

[libvirt] [PATCH v4 7/9] domain_conf: Read and Write quorum config

2015-03-17 Thread Matthias Gatto
Add the capabiltty to libvirt to parse and format the quorum syntax
as described here:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c | 164 +++--
 1 file changed, 119 insertions(+), 45 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 79dc29f..5ffa4ce 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5815,20 +5815,56 @@ virDomainDiskSourceParse(xmlNodePtr node,
 }
 
 
+static bool
+virDomainDiskThresholdParse(virStorageSourcePtr src,
+xmlNodePtr node)
+{
+char *threshold = virXMLPropString(node, threshold);
+int ret;
+
+if (!threshold) {
+virReportError(VIR_ERR_XML_ERROR,
+   %s, _(missing threshold in quorum));
+return false;
+}
+ret = virStrToLong_ul(threshold, NULL, 10, src-threshold);
+if (ret  0 || src-threshold  2) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _(unexpected threshold %s),
+   threshold must be a decimal number superior to 2 
+ and inferior to the number of children);
+VIR_FREE(threshold);
+return false;
+}
+VIR_FREE(threshold);
+return true;
+}
+
+
 static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
-   virStorageSourcePtr src)
+   virStorageSourcePtr src,
+   xmlNodePtr node,
+   size_t pos)
 {
 virStorageSourcePtr backingStore = NULL;
 xmlNodePtr save_ctxt = ctxt-node;
-xmlNodePtr source;
+xmlNodePtr source = NULL;
 char *type = NULL;
 char *format = NULL;
 int ret = -1;
 
-if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
-ret = 0;
-goto cleanup;
+if (src-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!node) {
+ret = 0;
+goto cleanup;
+}
+ctxt-node = node;
+} else {
+if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
+ret = 0;
+goto cleanup;
+}
 }
 
 if (VIR_ALLOC(backingStore)  0)
@@ -5860,6 +5896,25 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
+if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) {
+xmlNodePtr cur = NULL;
+
+if (!virDomainDiskThresholdParse(backingStore, node))
+goto cleanup;
+
+for (cur = node-children; cur != NULL; cur = cur-next) {
+if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
+if ((virDomainDiskBackingStoreParse(ctxt,
+backingStore,
+cur,
+
backingStore-nBackingStores)  0)) {
+goto cleanup;
+}
+}
+}
+goto exit;
+}
+
 if (!(source = virXPathNode(./source, ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, %s,
_(missing disk backing store source));
@@ -5867,10 +5922,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 }
 
 if (virDomainDiskSourceParse(source, ctxt, backingStore)  0 ||
-virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
+virDomainDiskBackingStoreParse(ctxt, backingStore, NULL, 0)  0)
 goto cleanup;
 
-if (!virStorageSourceSetBackingStore(src, backingStore, 0))
+ exit:
+if (!virStorageSourceSetBackingStore(src, backingStore, pos))
 goto cleanup;
 ret = 0;
 
@@ -5883,7 +5939,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 return ret;
 }
 
-
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
 
@@ -6381,6 +6436,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 } else if (xmlStrEqual(cur-name, BAD_CAST boot)) {
 /* boot is parsed as part of virDomainDeviceInfoParseXML */
+} else if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
+if (virDomainDiskBackingStoreParse(ctxt, def-src, cur,
+   def-src-nBackingStores)  
0)
+goto error;
 }
 }
 cur = cur-next;
@@ -6404,12 +6463,19 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 def-device = VIR_DOMAIN_DISK_DEVICE_DISK;
 }
 
+if (def-src-type == VIR_STORAGE_TYPE_QUORUM 
+!virDomainDiskThresholdParse(def-src, node))
+goto error;
+
+snapshot = virXMLPropString(node, snapshot);
+
 /* Only CDROM and Floppy devices are allowed missing source path
  * to indicate no media present. LUN is for raw access CD-ROMs
  * that are not attached to a physical device

[libvirt] [PATCH v4 9/9] virstoragefile: Add node-name

2015-03-17 Thread Matthias Gatto
Add nodename inside virstoragefile
During xml backingStore parsing, look for a nodename attribute in the disk
declaration if this one is a quorum, if a nodename is found, add it to
the virStorageSource otherwise create a new one with a random name.
Take inspiration from this patch to create the nodename:
http://lists.gnu.org/archive/html/qemu-devel/2014-05/msg03209.html

Durring xml backingStore formating, look for a nodename attribute inside the
virStorageSource struct, and add it to the disk element.

Use the nodename to create the quorum in qemuBuildQuorumStr.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 docs/formatdomain.html.in |  7 +++
 docs/schemas/domaincommon.rng |  5 +
 src/conf/domain_conf.c| 27 +++
 src/qemu/qemu_command.c   |  3 +++
 src/util/virstoragefile.c |  4 
 src/util/virstoragefile.h |  1 +
 6 files changed, 47 insertions(+)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 6fb87fd..80167e4 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2148,6 +2148,13 @@
 codevda[2]/code refers to the backing store with
 codeindex='2'/code of the disk with codevda/code target.
   /dd
+  dtcodenodename/code attribute
+  span class=sincesince 1.2.13/span/dt
+  dd
+When the backing store is a quorum child, we can use this attribute
+to define the node-name of a child. If this atribute is undefine,
+a random nodename is generate.
+  /dd
   dtcodeformat/code sub-element/dt
   dd
 The codeformat/code element contains codetype/code
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 5a76ae7..6e7c87f 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1363,6 +1363,11 @@
   /attribute
   interleave
 optional
+  attribute name=nodename
+text/
+  /attribute
+/optional
+optional
   ref name=diskDevice/
 /optional
 ref name=diskSource/
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5ffa4ce..66e14d4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -56,6 +56,7 @@
 #include network_conf.h
 #include virtpm.h
 #include virstring.h
+#include virrandom.h
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -5841,6 +5842,8 @@ virDomainDiskThresholdParse(virStorageSourcePtr src,
 }
 
 
+#define GEN_NODE_NAME_PREFIXlibvirt
+#define GEN_NODE_NAME_MAX_LEN   (sizeof(GEN_NODE_NAME_PREFIX) + 8 + 8)
 static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
virStorageSourcePtr src,
@@ -5883,6 +5886,26 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
+if (src-type == VIR_STORAGE_TYPE_QUORUM) {
+char *nodeName = NULL;
+
+if ((nodeName = virXMLPropString(ctxt-node, nodename))) {
+backingStore-nodeName = nodeName;
+} else {
+size_t len;
+
+if (VIR_ALLOC_N(nodeName, GEN_NODE_NAME_MAX_LEN)  0)
+goto cleanup;
+if (snprintf(nodeName, GEN_NODE_NAME_MAX_LEN,
+ %s%08x, GEN_NODE_NAME_PREFIX, (int)pos)  0)
+goto cleanup;
+for (len = strlen(nodeName); len  GEN_NODE_NAME_MAX_LEN - 1; 
++len)
+nodeName[len] = virRandomInt('Z' - 'A') + 'A';
+nodeName[GEN_NODE_NAME_MAX_LEN - 1] = '\0';
+backingStore-nodeName = nodeName;
+}
+}
+
 if (!(format = virXPathString(string(./format/@type), ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, %s,
_(missing disk backing store format));
@@ -5938,6 +5961,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 ctxt-node = save_ctxt;
 return ret;
 }
+#undef GEN_NODE_NAME_PREFIX
+#undef GEN_NODE_NAME_MAX_LEN
 
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
@@ -17318,6 +17343,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
   type, idx);
 if (backingStore-threshold)
 virBufferAsprintf(buf,  threshold='%lu', 
backingStore-threshold);
+if (backingStore-nodeName)
+virBufferAsprintf(buf,  nodename='%s', backingStore-nodeName);
 virBufferAddLit(buf, \n);
 virBufferAdjustIndent(buf, 2);
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 5fc7956..26ddd89 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3495,6 +3495,9 @@ qemuBuildQuorumStr(virConnectPtr conn,
   toAppend, i,
   
virStorageFileFormatTypeToString(backingStore-format));
 
+virBufferAsprintf(opt, ,%schildren.%lu.node-name=%s,
+  toAppend, i, backingStore-nodeName

[libvirt] [PATCH v4 3/9] virstoragefile: Add virStorageSourceSetBackingStore

2015-03-17 Thread Matthias Gatto
As explained for virStorageSourceGetBackingStore, quorum allows
multiple backing store, this make the operation to set bs complex
because we have to check if the backingStore is used as an array
or a pointer, and set it differently in both case.

In order to help the manipulation of backing store, I've added a
function virStorageSourceSetBackingStore.

For now virStorageSourceSetBackingStore don't handle the case where
we have more than one backing store in virStorageSource.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 10 ++
 src/util/virstoragefile.h |  3 +++
 3 files changed, 14 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7b8038b..f7f8923 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2089,6 +2089,7 @@ virStorageSourceParseRBDColonString;
 virStorageSourcePoolDefFree;
 virStorageSourcePoolModeTypeFromString;
 virStorageSourcePoolModeTypeToString;
+virStorageSourceSetBackingStore;
 virStorageTypeFromString;
 virStorageTypeToString;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index ef8053d..9ee5aff 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1806,6 +1806,16 @@ virStorageSourceGetBackingStore(const virStorageSource 
*src,
 }
 
 
+bool
+virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr backingStore,
+size_t pos ATTRIBUTE_UNUSED)
+{
+src-backingStore = backingStore;
+return src-backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index c37ddcf..85b8d6e 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+bool virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr 
backingStore,
+size_t pos);
 virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
 size_t pos);
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v4 8/9] qemu: Add quorum support in qemuBuildDriveDevStr

2015-03-17 Thread Matthias Gatto
Allow to libvirt to build the quorum string used by quemu.

Add 2 static functions: qemuBuildQuorumStr and
qemuBuildAndAppendDriveStrToVirBuffer.
qemuBuildQuorumStr is made because a quorum can have another quorum
as a child, so we may need to call qemuBuildQuorumStr recursively.

qemuBuildQuorumFileSourceStr was basically made to share
the code use to build the source between qemuBuildQuorumStr and
qemuBuildDriveStr, but there is some difference betwin the syntax
use by libvirt to declare a disk and the one qemu need to build a quorum:
a quorum need a syntaxe like:
domaine_name.children.X.file.filename=filename
where libvirt don't use file.filename= but directly file=.
Therfore I use this function only for quorum.

But as explained in the cover letter and here:
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
We miss some informations in _virStorageSource to have a complet
quorum support in libvirt.
Ideally I'd like to refactore virDomainDiskDefFormat to allow
qemuBuildQuorumStr to call this function in a loop.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/qemu/qemu_command.c | 110 
 1 file changed, 110 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index cf2c95e..5fc7956 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3407,6 +3407,111 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk)
 return -1;
 }
 
+static bool
+qemuBuildQuorumFileSourceStr(virConnectPtr conn,
+  virStorageSourcePtr src,
+  virBuffer *opt,
+  const char *toAppend)
+{
+char *source = NULL;
+int actualType = virStorageSourceGetActualType(src);
+
+if (qemuGetDriveSourceString(src, conn, source)  0)
+goto error;
+
+if (source) {
+
+virBufferAsprintf(opt, ,%sfilename=, toAppend);
+
+switch (actualType) {
+case VIR_STORAGE_TYPE_DIR:
+/* QEMU only supports magic FAT format for now */
+if (src-format  0 
+src-format != VIR_STORAGE_FILE_FAT) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(unsupported disk driver type for '%s'),
+   virStorageFileFormatTypeToString(src-format));
+goto error;
+}
+
+if (!src-readonly) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(cannot create virtual FAT disks in 
read-write mode));
+goto error;
+}
+
+virBufferAddLit(opt, fat:);
+
+break;
+
+default:
+break;
+}
+virBufferAsprintf(opt, %s, source);
+}
+
+return true;
+ error:
+return false;
+}
+
+
+static bool
+qemuBuildQuorumStr(virConnectPtr conn,
+   virDomainDiskDefPtr disk,
+   virStorageSourcePtr src,
+   virBuffer *opt,
+   const char *toAppend)
+{
+char *tmp = NULL;
+int ret;
+virStorageSourcePtr backingStore;
+size_t i;
+
+if (!src-threshold) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(threshold missing in the quorum configuration));
+return false;
+}
+if (src-nBackingStores  2) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(a quorum must have at last 2 children));
+return false;
+}
+if (src-threshold  src-nBackingStores) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(threshold must not exceed the number of childrens));
+return false;
+}
+virBufferAsprintf(opt, ,%svote-threshold=%lu,
+  toAppend, src-threshold);
+for (i = 0;  i  src-nBackingStores; ++i) {
+backingStore = virStorageSourceGetBackingStore(src, i);
+ret = virAsprintf(tmp, %schildren.%lu.file., toAppend, i);
+if (ret  0)
+return false;
+
+virBufferAsprintf(opt, ,%schildren.%lu.driver=%s,
+  toAppend, i,
+  
virStorageFileFormatTypeToString(backingStore-format));
+
+if (qemuBuildQuorumFileSourceStr(conn, backingStore, opt, tmp) == 
false)
+goto error;
+
+/* This operation avoid me to made another copy */
+tmp[ret - sizeof(file)] = '\0';
+if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!qemuBuildQuorumStr(conn, disk, backingStore, opt, tmp))
+goto error;
+}
+VIR_FREE(tmp);
+}
+return true;
+ error:
+VIR_FREE(tmp);
+return false;
+}
+
 
 /* Qemu 1.2 and later have a binary flag -enable-fips that must be
  * used for VNC auth to obey FIPS settings; but the flag only
@@ -3880,6 +3985,11 @@ qemuBuildDriveStr(virConnectPtr conn

[libvirt] [PATCH v4 1/9] virstoragefile: Add virStorageSourceGetBackingStore

2015-03-17 Thread Matthias Gatto
Create virStorageSourceGetBackingStore function in
preparation for quorum:
Actually, if we want to get a backing store inside a virStorageSource
we have to do it manually(src-backingStore = backingStore).
The problem is that with a quorum, a virStorageSource
can contain multiple backing stores, and src-backingStore can
be treated as a virStorageSourcePtr or a virStorageSourcePtrPtr.

Due to these reason, we need to simplify the manipulation of
virStorageSource, and create a function to get the asked
backingStore in a virStorageSource

For now, this function only return the backingStore field

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/libvirt_private.syms  | 1 +
 src/util/virstoragefile.c | 8 
 src/util/virstoragefile.h | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1fb42ac..7b8038b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2079,6 +2079,7 @@ virStorageSourceClear;
 virStorageSourceCopy;
 virStorageSourceFree;
 virStorageSourceGetActualType;
+virStorageSourceGetBackingStore;
 virStorageSourceGetSecurityLabelDef;
 virStorageSourceInitChainElement;
 virStorageSourceIsEmpty;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 78a7a9f..9a3e39b 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1798,6 +1798,14 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+virStorageSourcePtr
+virStorageSourceGetBackingStore(const virStorageSource *src,
+size_t pos ATTRIBUTE_UNUSED)
+{
+return src-backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index b4c3808..c37ddcf 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
+size_t pos);
+
 int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
 int virStorageFileProbeFormatFromBuf(const char *path,
  char *buf,
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v4 5/9] virstoragefile: change backingStore to backingStores.

2015-03-17 Thread Matthias Gatto
The backingStore field was a virStorageSourcePtr.
because a quorum can contain more that one backingStore at the same level
it's now a 'virStorageSourcePtr *'.

This patch rename  src-backingStore to src-backingStores,
add a static function virStorageSourceExpandBackingStore
(virStorageSourcePushBackingStore in the V2) and made the necessary 
modification to
virStorageSourceSetBackingStore and virStorageSourceGetBackingStore.
virStorageSourceSetBackingStore can now expand size of src-backingStores
by calling virStorageSourceExpandBackingStore if necessary.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/storage/storage_backend.c|  2 +-
 src/storage/storage_backend_fs.c |  2 +-
 src/util/virstoragefile.c| 69 +++-
 src/util/virstoragefile.h|  3 +-
 4 files changed, 65 insertions(+), 11 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 884c7cd..bee56a1 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -487,7 +487,7 @@ virStorageBackendCreateRaw(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 goto cleanup;
 }
 
-if (vol-target.backingStore) {
+if (vol-target.backingStores) {
 virReportError(VIR_ERR_NO_SUPPORT, %s,
_(backing storage not supported for raw volumes));
 goto cleanup;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 8c6d0b2..b9a7588 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1042,7 +1042,7 @@ static int createFileDir(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 return -1;
 }
 
-if (vol-target.backingStore) {
+if (vol-target.backingStores) {
 virReportError(VIR_ERR_NO_SUPPORT, %s,
_(backing storage not supported for directories 
volumes));
 return -1;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 9da4bdf..b3d84b9 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1798,21 +1798,66 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+/**
+ * virStorageSourceGetBackingStore:
+ * @src: virStorageSourcePtr containing the backing stores
+ * @pos: position of the backing store to get
+ *
+ * return the backingStore at the position of @pos
+ */
 virStorageSourcePtr
-virStorageSourceGetBackingStore(const virStorageSource *src,
-size_t pos ATTRIBUTE_UNUSED)
+virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos)
+{
+if (!src || !src-backingStores || pos = src-nBackingStores)
+return NULL;
+return src-backingStores[pos];
+}
+
+
+/**
+ * virStorageSourcePushBackingStore:
+ *
+ * Expand src-backingStores and update src-nBackingStores
+ */
+static bool
+virStorageSourceExpandBackingStore(virStorageSourcePtr src, size_t nbr)
 {
-return src-backingStore;
+if (!src)
+return false;
+if (src-nBackingStores  0) {
+if (VIR_EXPAND_N(src-backingStores, src-nBackingStores, nbr)  0)
+return false;
+} else {
+if (VIR_ALLOC_N(src-backingStores, nbr)  0)
+return false;
+src-nBackingStores += nbr;
+}
+return true;
 }
 
 
+/**
+ * virStorageSourceSetBackingStore:
+ * @src: virStorageSourcePtr to hold @backingStore
+ * @backingStore: backingStore to store
+ * @pos: position of the backing store to store
+ *
+ * Set @backingStore at @pos in src-backingStores.
+ * If src-backingStores don't have the space to contain
+ * @backingStore, we expand src-backingStores
+ */
 bool
 virStorageSourceSetBackingStore(virStorageSourcePtr src,
 virStorageSourcePtr backingStore,
-size_t pos ATTRIBUTE_UNUSED)
+size_t pos)
 {
-src-backingStore = backingStore;
-return src-backingStore;
+if (!src)
+return false;
+if (pos = src-nBackingStores 
+!virStorageSourceExpandBackingStore(src, pos - src-nBackingStores + 
1))
+return false;
+src-backingStores[pos] = backingStore;
+return true;
 }
 
 
@@ -2023,6 +2068,8 @@ virStorageSourceIsEmpty(virStorageSourcePtr src)
 void
 virStorageSourceBackingStoreClear(virStorageSourcePtr def)
 {
+size_t i;
+
 if (!def)
 return;
 
@@ -2030,8 +2077,14 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr 
def)
 VIR_FREE(def-backingStoreRaw);
 
 /* recursively free backing chain */
-virStorageSourceFree(virStorageSourceGetBackingStore(def, 0));
-virStorageSourceSetBackingStore(def, NULL, 0);
+for (i = 0; i  def-nBackingStores; ++i)
+virStorageSourceFree(virStorageSourceGetBackingStore(def, i));
+if (def-nBackingStores  0) {
+/* in this case def-backingStores is treat as an array so we have to 
free it*/
+VIR_FREE(def-backingStores);
+}
+def-nBackingStores

Re: [libvirt] [PATCH v3 0/9] qemu: Add quorum support to libvirt

2015-03-03 Thread Matthias Gatto
On Thu, Feb 26, 2015 at 5:04 PM, Peter Krempa pkre...@redhat.com wrote:
 On Mon, Feb 23, 2015 at 14:18:31 +0100, Matthias Gatto wrote:
 On Tue, Feb 10, 2015 at 4:43 PM, Matthias Gatto
 matthias.ga...@outscale.com wrote:
  The purpose of these patches is to introduce quorum for libvirt
  I've try to follow this proposal:
  http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html
 
  This feature ask for 6 task:
 
  1) Allow a _virStorageSource to contain more than one backing store.
 
  Because all the actual libvirt code use the backingStore field
  as a pointer and we needs want to change that, I've decide to encapsulate
  the backingStore field to simplifie the array manipulation.
 
  2) Add the missing field a quorum need in _virStorageSource and
  the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
  their respectives enums.
 
  3) Parse and format the xml
  Because a quorum allows to have more than one backing store at the same 
  level
  we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
  to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
  in a loop.
  virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
  call themself recursively in a loop because a quorum can contain another
  quorum
 
  4) Add nodename
  We need to add nodename support in _virStorageSource because qemu
  use them for their child.
 
  5) Build qemu string
  As for the xml, we have to call the function which create quorum 
  recursively.
  But this task have the problem explained here:
  http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
  The _virStorageSource missing some informations that can be passed to
  a child, and therefore this version of quorum is incomplet.
 
  6) Allow to hotplug/change a disk in a quorum
  This part is not present in these patches because for this task
  we have to use blockdev-add, and currently libvirt use
  device_add for hotpluging that doesn't allow to hotplug quorum childs.
 
  There is 3 way to handle this problem:
1) create a virDomainBlockDevAdd function in libvirt witch call
blockdev-add.
 
2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice
 
3) write a hack which uses blockdev-add when only attaching quorum
(but i'm pretty sure this solution is not the good one)
 
  V2:
  -Rebase on master
  -Add Documentation
 
  V3:
  -Transforme the backingStore field in virStorageSource into
   an array of pointer instead of a pointer
  -Modify virStorageSourceSetBackingStore to allow it to expand
   the backingStore size.
 
  Matthias Gatto (9):
virstoragefile: Add virStorageSourceGetBackingStore
virstoragefile: Always use virStorageSourceGetBackingStore to get
  backing store
virstoragefile: Add virStorageSourceSetBackingStore
virstoragefile: Always use virStorageSourceSetBackingStore to set
  backing store
virstoragefile: change backingStore to backingStores.
virstoragefile: Add quorum in virstoragefile
domain_conf: Read and Write quorum config
qemu: Add quorum support in qemuBuildDriveDevStr
virstoragefile: Add node-name
 
   docs/formatdomain.html.in |  27 -
   docs/schemas/domaincommon.rng |  96 +++--
   docs/schemas/storagecommon.rng|   1 +
   docs/schemas/storagevol.rng   |   1 +
   src/conf/domain_conf.c| 195 
  ++
   src/conf/storage_conf.c   |  23 ++--
   src/libvirt_private.syms  |   2 +
   src/qemu/qemu_cgroup.c|   4 +-
   src/qemu/qemu_command.c   | 114 
   src/qemu/qemu_domain.c|   2 +-
   src/qemu/qemu_driver.c|  30 +++---
   src/qemu/qemu_migration.c |   1 +
   src/security/security_dac.c   |   2 +-
   src/security/security_selinux.c   |   4 +-
   src/security/virt-aa-helper.c |   2 +-
   src/storage/storage_backend.c |  33 +++---
   src/storage/storage_backend_fs.c  |  36 ---
   src/storage/storage_backend_gluster.c |  10 +-
   src/storage/storage_backend_logical.c |  15 ++-
   src/storage/storage_driver.c  |   2 +-
   src/util/virstoragefile.c | 116 +---
   src/util/virstoragefile.h |  12 ++-
   tests/virstoragetest.c|  18 ++--
   23 files changed, 573 insertions(+), 173 deletions(-)
 
  --
  1.8.3.1
 

 ping

 Sorry for taking so long. I was pretty busy in the last time and need to
 switch context to the storage part of libvirt again at first.

 I have this series on the radar and will try to review it once I get rid
 of some stuff.

 Peter

ok,
Thank you

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v3 0/9] qemu: Add quorum support to libvirt

2015-02-23 Thread Matthias Gatto
On Tue, Feb 10, 2015 at 4:43 PM, Matthias Gatto
matthias.ga...@outscale.com wrote:
 The purpose of these patches is to introduce quorum for libvirt
 I've try to follow this proposal:
 http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

 This feature ask for 6 task:

 1) Allow a _virStorageSource to contain more than one backing store.

 Because all the actual libvirt code use the backingStore field
 as a pointer and we needs want to change that, I've decide to encapsulate
 the backingStore field to simplifie the array manipulation.

 2) Add the missing field a quorum need in _virStorageSource and
 the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
 their respectives enums.

 3) Parse and format the xml
 Because a quorum allows to have more than one backing store at the same level
 we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
 to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
 in a loop.
 virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
 call themself recursively in a loop because a quorum can contain another
 quorum

 4) Add nodename
 We need to add nodename support in _virStorageSource because qemu
 use them for their child.

 5) Build qemu string
 As for the xml, we have to call the function which create quorum recursively.
 But this task have the problem explained here:
 http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
 The _virStorageSource missing some informations that can be passed to
 a child, and therefore this version of quorum is incomplet.

 6) Allow to hotplug/change a disk in a quorum
 This part is not present in these patches because for this task
 we have to use blockdev-add, and currently libvirt use
 device_add for hotpluging that doesn't allow to hotplug quorum childs.

 There is 3 way to handle this problem:
   1) create a virDomainBlockDevAdd function in libvirt witch call
   blockdev-add.

   2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice

   3) write a hack which uses blockdev-add when only attaching quorum
   (but i'm pretty sure this solution is not the good one)

 V2:
 -Rebase on master
 -Add Documentation

 V3:
 -Transforme the backingStore field in virStorageSource into
  an array of pointer instead of a pointer
 -Modify virStorageSourceSetBackingStore to allow it to expand
  the backingStore size.

 Matthias Gatto (9):
   virstoragefile: Add virStorageSourceGetBackingStore
   virstoragefile: Always use virStorageSourceGetBackingStore to get
 backing store
   virstoragefile: Add virStorageSourceSetBackingStore
   virstoragefile: Always use virStorageSourceSetBackingStore to set
 backing store
   virstoragefile: change backingStore to backingStores.
   virstoragefile: Add quorum in virstoragefile
   domain_conf: Read and Write quorum config
   qemu: Add quorum support in qemuBuildDriveDevStr
   virstoragefile: Add node-name

  docs/formatdomain.html.in |  27 -
  docs/schemas/domaincommon.rng |  96 +++--
  docs/schemas/storagecommon.rng|   1 +
  docs/schemas/storagevol.rng   |   1 +
  src/conf/domain_conf.c| 195 
 ++
  src/conf/storage_conf.c   |  23 ++--
  src/libvirt_private.syms  |   2 +
  src/qemu/qemu_cgroup.c|   4 +-
  src/qemu/qemu_command.c   | 114 
  src/qemu/qemu_domain.c|   2 +-
  src/qemu/qemu_driver.c|  30 +++---
  src/qemu/qemu_migration.c |   1 +
  src/security/security_dac.c   |   2 +-
  src/security/security_selinux.c   |   4 +-
  src/security/virt-aa-helper.c |   2 +-
  src/storage/storage_backend.c |  33 +++---
  src/storage/storage_backend_fs.c  |  36 ---
  src/storage/storage_backend_gluster.c |  10 +-
  src/storage/storage_backend_logical.c |  15 ++-
  src/storage/storage_driver.c  |   2 +-
  src/util/virstoragefile.c | 116 +---
  src/util/virstoragefile.h |  12 ++-
  tests/virstoragetest.c|  18 ++--
  23 files changed, 573 insertions(+), 173 deletions(-)

 --
 1.8.3.1


ping

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] qemu: check the validity of a pointer

2015-02-16 Thread Matthias Gatto
In the current code if mem_mask is NULL there is a goto error, but
we freeing it without knowing if mem_mask is NULL or not, therefor
I've had a check.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/qemu/qemu_cgroup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index ca255c8..926726c 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -810,7 +810,8 @@ qemuRestoreCgroupState(virDomainObjPtr vm)
 goto error;
 
  cleanup:
-VIR_FREE(mem_mask);
+if (mem_mask)
+VIR_FREE(mem_mask);
 virBitmapFree(all_nodes);
 return;
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 5/9] virstoragefile: change backingStore to backingStores.

2015-02-10 Thread Matthias Gatto
The backingStore field was a virStorageSourcePtr.
because a quorum can contain more that one backingStore at the same level
it's now a 'virStorageSourcePtr *'.

This patch rename  src-backingStore to src-backingStores,
add a static function virStorageSourceExpandBackingStore
(virStorageSourcePushBackingStore in the V2) and made the necessary 
modification to
virStorageSourceSetBackingStore and virStorageSourceGetBackingStore.
virStorageSourceSetBackingStore can now expand size of src-backingStores
by calling virStorageSourceExpandBackingStore if necessary.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/util/virstoragefile.c | 69 +--
 src/util/virstoragefile.h |  3 ++-
 2 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index d573aba..2a5321c 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1798,21 +1798,66 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+/**
+ * virStorageSourceGetBackingStore:
+ * @src: virStorageSourcePtr containing the backing stores
+ * @pos: position of the backing store to get
+ *
+ * return the backingStore at the position of @pos
+ */
 virStorageSourcePtr
-virStorageSourceGetBackingStore(const virStorageSource *src,
-size_t pos ATTRIBUTE_UNUSED)
+virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos)
+{
+if (!src || !src-backingStores || pos = src-nBackingStores)
+return NULL;
+return src-backingStores[pos];
+}
+
+
+/**
+ * virStorageSourcePushBackingStore:
+ *
+ * Expand src-backingStores and update src-nBackingStores
+ */
+static bool
+virStorageSourceExpandBackingStore(virStorageSourcePtr src, size_t nbr)
 {
-return src-backingStore;
+if (!src)
+return false;
+if (src-nBackingStores  0) {
+if (VIR_EXPAND_N(src-backingStores, src-nBackingStores, nbr)  0)
+return false;
+} else {
+if (VIR_ALLOC_N(src-backingStores, nbr)  0)
+return false;
+src-nBackingStores += nbr;
+}
+return true;
 }
 
 
+/**
+ * virStorageSourceSetBackingStore:
+ * @src: virStorageSourcePtr to hold @backingStore
+ * @backingStore: backingStore to store
+ * @pos: position of the backing store to store
+ *
+ * Set @backingStore at @pos in src-backingStores.
+ * If src-backingStores don't have the space to contain
+ * @backingStore, we expand src-backingStores
+ */
 bool
 virStorageSourceSetBackingStore(virStorageSourcePtr src,
 virStorageSourcePtr backingStore,
-size_t pos ATTRIBUTE_UNUSED)
+size_t pos)
 {
-src-backingStore = backingStore;
-return src-backingStore;
+if (!src)
+return false;
+if (pos = src-nBackingStores 
+!virStorageSourceExpandBackingStore(src, pos - src-nBackingStores + 
1))
+return false;
+src-backingStores[pos] = backingStore;
+return true;
 }
 
 
@@ -2023,6 +2068,8 @@ virStorageSourceIsEmpty(virStorageSourcePtr src)
 void
 virStorageSourceBackingStoreClear(virStorageSourcePtr def)
 {
+size_t i;
+
 if (!def)
 return;
 
@@ -2030,8 +2077,14 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr 
def)
 VIR_FREE(def-backingStoreRaw);
 
 /* recursively free backing chain */
-virStorageSourceFree(virStorageSourceGetBackingStore(def, 0));
-virStorageSourceSetBackingStore(def, NULL, 0);
+for (i = 0; i  def-nBackingStores; ++i)
+virStorageSourceFree(virStorageSourceGetBackingStore(def, i));
+if (def-nBackingStores  0) {
+/* in this case def-backingStores is treat as an array so we have to 
free it*/
+VIR_FREE(def-backingStores);
+}
+def-nBackingStores = 0;
+def-backingStores = NULL;
 }
 
 
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 85b8d6e..b94f9d9 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -270,7 +270,8 @@ struct _virStorageSource {
 bool shared;
 
 /* backing chain of the storage source */
-virStorageSourcePtr backingStore;
+virStorageSourcePtr *backingStores;
+size_t  nBackingStores;
 
 /* metadata for storage driver access to remote and local volumes */
 virStorageDriverDataPtr drv;
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 8/9] qemu: Add quorum support in qemuBuildDriveDevStr

2015-02-10 Thread Matthias Gatto
Allow to libvirt to build the quorum string used by quemu.

Add 2 static functions: qemuBuildQuorumStr and
qemuBuildAndAppendDriveStrToVirBuffer.
qemuBuildQuorumStr is made because a quorum can have another quorum
as a child, so we may need to call qemuBuildQuorumStr recursively.

qemuBuildQuorumFileSourceStr was basically made to share
the code use to build the source between qemuBuildQuorumStr and
qemuBuildDriveStr, but there is some difference betwin the syntax
use by libvirt to declare a disk and the one qemu need to build a quorum:
a quorum need a syntaxe like:
domaine_name.children.X.file.filename=filename
where libvirt don't use file.filename= but directly file=.
Therfore I use this function only for quorum.

But as explained in the cover letter and here:
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
We miss some informations in _virStorageSource to have a complet
quorum support in libvirt.
Ideally I'd like to refactore virDomainDiskDefFormat to allow
qemuBuildQuorumStr to call this function in a loop.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/qemu/qemu_command.c | 110 
 1 file changed, 110 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d4123a0..acbff19 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3347,6 +3347,111 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk)
 return -1;
 }
 
+static bool
+qemuBuildQuorumFileSourceStr(virConnectPtr conn,
+  virStorageSourcePtr src,
+  virBuffer *opt,
+  const char *toAppend)
+{
+char *source = NULL;
+int actualType = virStorageSourceGetActualType(src);
+
+if (qemuGetDriveSourceString(src, conn, source)  0)
+goto error;
+
+if (source) {
+
+virBufferAsprintf(opt, ,%sfilename=, toAppend);
+
+switch (actualType) {
+case VIR_STORAGE_TYPE_DIR:
+/* QEMU only supports magic FAT format for now */
+if (src-format  0 
+src-format != VIR_STORAGE_FILE_FAT) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(unsupported disk driver type for '%s'),
+   virStorageFileFormatTypeToString(src-format));
+goto error;
+}
+
+if (!src-readonly) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(cannot create virtual FAT disks in 
read-write mode));
+goto error;
+}
+
+virBufferAddLit(opt, fat:);
+
+break;
+
+default:
+break;
+}
+virBufferAsprintf(opt, %s, source);
+}
+
+return true;
+ error:
+return false;
+}
+
+
+static bool
+qemuBuildQuorumStr(virConnectPtr conn,
+   virDomainDiskDefPtr disk,
+   virStorageSourcePtr src,
+   virBuffer *opt,
+   const char *toAppend)
+{
+char *tmp = NULL;
+int ret;
+virStorageSourcePtr backingStore;
+size_t i;
+
+if (!src-threshold) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(threshold missing in the quorum configuration));
+return false;
+}
+if (src-nBackingStores  2) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(a quorum must have at last 2 children));
+return false;
+}
+if (src-threshold  src-nBackingStores) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(threshold must not exceed the number of childrens));
+return false;
+}
+virBufferAsprintf(opt, ,%svote-threshold=%lu,
+  toAppend, src-threshold);
+for (i = 0;  i  src-nBackingStores; ++i) {
+backingStore = virStorageSourceGetBackingStore(src, i);
+ret = virAsprintf(tmp, %schildren.%lu.file., toAppend, i);
+if (ret  0)
+return false;
+
+virBufferAsprintf(opt, ,%schildren.%lu.driver=%s,
+  toAppend, i,
+  
virStorageFileFormatTypeToString(backingStore-format));
+
+if (qemuBuildQuorumFileSourceStr(conn, backingStore, opt, tmp) == 
false)
+goto error;
+
+/* This operation avoid me to made another copy */
+tmp[ret - sizeof(file)] = '\0';
+if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!qemuBuildQuorumStr(conn, disk, backingStore, opt, tmp))
+goto error;
+}
+VIR_FREE(tmp);
+}
+return true;
+ error:
+VIR_FREE(tmp);
+return false;
+}
+
 
 /* Qemu 1.2 and later have a binary flag -enable-fips that must be
  * used for VNC auth to obey FIPS settings; but the flag only
@@ -3819,6 +3924,11 @@ qemuBuildDriveStr(virConnectPtr conn

[libvirt] [PATCH v3 6/9] virstoragefile: Add quorum in virstoragefile

2015-02-10 Thread Matthias Gatto
Add VIR_STORAGE_TYPE_QUORUM in virStorageType.
Add VIR_STORAGE_FILE_QUORUM in virStorageFileFormat.

Add threshold value in _virStorageSource

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 docs/formatdomain.html.in  | 20 +-
 docs/schemas/domaincommon.rng  | 90 +++---
 docs/schemas/storagecommon.rng |  1 +
 docs/schemas/storagevol.rng|  1 +
 src/conf/domain_conf.c |  2 +
 src/qemu/qemu_command.c|  1 +
 src/qemu/qemu_driver.c |  4 ++
 src/qemu/qemu_migration.c  |  1 +
 src/util/virstoragefile.c  | 25 
 src/util/virstoragefile.h  |  3 ++
 10 files changed, 106 insertions(+), 42 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 679194f..263baaf 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1835,8 +1835,9 @@
 dd
 Valid values are file, block,
 dir (span class=sincesince 0.7.5/span),
-network (span class=sincesince 0.8.7/span), or
-volume (span class=sincesince 1.0.5/span)
+network (span class=sincesince 0.8.7/span),
+volume (span class=sincesince 1.0.5/span), or
+quorum (span class=sincesince 1.2.13/span)
 and refer to the underlying source for the disk.
 /dd
   dtcodedevice/code attribute
@@ -1897,6 +1898,14 @@
 codesnapshot='yes'/code with a transient disk generally
 does not make sense.
 /dd
+  dtcodethreshold/code attribute
+  span class=sincesince 1.2.13/span/dt
+dd
+Only use with a quorum disk.
+Indicate the minimum of positive vote a quorum must have to 
validate
+a data to be write. The minimum value is 2. The number of 
backingStores
+contain by the quorum must be superior to the threshold.
+/dd
 /dl
   /dd
   dtcodesource/code/dt
@@ -1967,6 +1976,11 @@
   
'file=/dev/disk/by-path/ip-example.com:3260-iscsi-iqn.2013-07.com.example:iscsi-pool-lun-1').
   /p
   /dd
+dtcodetype='quorum'/code
+span class=sincesince 1.2.13/span/dt
+  dd
+  A quorum contain no source element, but a serie of backingStores 
instead.
+  /dd
   /dl
 With file, block, and volume, one or more optional
 sub-elements codeseclabel/code, a href=#seclabeldescribed
@@ -2098,6 +2112,8 @@
 codebackingStore/code element means the sibling source is
 self-contained and is not based on any backing store. The following
 attributes and sub-elements are supported in
+span class=sinceSince 1.2.11/span. This elements is used to
+describe a quorum child.
 codebackingStore/code:
 dl
   dtcodetype/code attribute/dt
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index d467dce..2556489 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1231,6 +1231,40 @@
 /attribute
   /define
 
+  define name='diskDevice'
+choice
+  group
+optional
+  attribute name=device
+choice
+  valuefloppy/value
+  valuedisk/value
+  valuecdrom/value
+/choice
+  /attribute
+/optional
+  /group
+  group
+attribute name=device
+  choice
+valuelun/value
+  /choice
+/attribute
+optional
+  ref name=rawIO/
+/optional
+optional
+  attribute name=sgio
+choice
+  valuefiltered/value
+  valueunfiltered/value
+/choice
+  /attribute
+/optional
+  /group
+/choice
+  /define
+
   !--
   A disk description can be either of type file or block
   The name of the attribute on the source element depends on the type
@@ -1238,37 +1272,7 @@
 --
   define name=disk
 element name=disk
-  choice
-group
-  optional
-attribute name=device
-  choice
-valuefloppy/value
-valuedisk/value
-valuecdrom/value
-  /choice
-/attribute
-  /optional
-/group
-group
-  attribute name=device
-choice
-  valuelun/value
-/choice
-  /attribute
-  optional
-ref name=rawIO/
-  /optional
-  optional
-attribute name=sgio
-  choice
-valuefiltered/value
-valueunfiltered/value
-  /choice
-/attribute
-  /optional
-/group
-  /choice
+  ref name=diskDevice/
   optional
 ref name=snapshot/
   /optional
@@ -1280,9 +1284,15

[libvirt] [PATCH v3 0/9] qemu: Add quorum support to libvirt

2015-02-10 Thread Matthias Gatto
The purpose of these patches is to introduce quorum for libvirt
I've try to follow this proposal:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

This feature ask for 6 task:

1) Allow a _virStorageSource to contain more than one backing store.

Because all the actual libvirt code use the backingStore field
as a pointer and we needs want to change that, I've decide to encapsulate
the backingStore field to simplifie the array manipulation.

2) Add the missing field a quorum need in _virStorageSource and
the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
their respectives enums.

3) Parse and format the xml
Because a quorum allows to have more than one backing store at the same level
we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
in a loop.
virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
call themself recursively in a loop because a quorum can contain another
quorum

4) Add nodename
We need to add nodename support in _virStorageSource because qemu
use them for their child.

5) Build qemu string
As for the xml, we have to call the function which create quorum recursively.
But this task have the problem explained here: 
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
The _virStorageSource missing some informations that can be passed to
a child, and therefore this version of quorum is incomplet.

6) Allow to hotplug/change a disk in a quorum
This part is not present in these patches because for this task
we have to use blockdev-add, and currently libvirt use
device_add for hotpluging that doesn't allow to hotplug quorum childs.

There is 3 way to handle this problem:
  1) create a virDomainBlockDevAdd function in libvirt witch call
  blockdev-add.

  2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice

  3) write a hack which uses blockdev-add when only attaching quorum
  (but i'm pretty sure this solution is not the good one)

V2:
-Rebase on master
-Add Documentation

V3:
-Transforme the backingStore field in virStorageSource into
 an array of pointer instead of a pointer
-Modify virStorageSourceSetBackingStore to allow it to expand
 the backingStore size.

Matthias Gatto (9):
  virstoragefile: Add virStorageSourceGetBackingStore
  virstoragefile: Always use virStorageSourceGetBackingStore to get
backing store
  virstoragefile: Add virStorageSourceSetBackingStore
  virstoragefile: Always use virStorageSourceSetBackingStore to set
backing store
  virstoragefile: change backingStore to backingStores.
  virstoragefile: Add quorum in virstoragefile
  domain_conf: Read and Write quorum config
  qemu: Add quorum support in qemuBuildDriveDevStr
  virstoragefile: Add node-name

 docs/formatdomain.html.in |  27 -
 docs/schemas/domaincommon.rng |  96 +++--
 docs/schemas/storagecommon.rng|   1 +
 docs/schemas/storagevol.rng   |   1 +
 src/conf/domain_conf.c| 195 ++
 src/conf/storage_conf.c   |  23 ++--
 src/libvirt_private.syms  |   2 +
 src/qemu/qemu_cgroup.c|   4 +-
 src/qemu/qemu_command.c   | 114 
 src/qemu/qemu_domain.c|   2 +-
 src/qemu/qemu_driver.c|  30 +++---
 src/qemu/qemu_migration.c |   1 +
 src/security/security_dac.c   |   2 +-
 src/security/security_selinux.c   |   4 +-
 src/security/virt-aa-helper.c |   2 +-
 src/storage/storage_backend.c |  33 +++---
 src/storage/storage_backend_fs.c  |  36 ---
 src/storage/storage_backend_gluster.c |  10 +-
 src/storage/storage_backend_logical.c |  15 ++-
 src/storage/storage_driver.c  |   2 +-
 src/util/virstoragefile.c | 116 +---
 src/util/virstoragefile.h |  12 ++-
 tests/virstoragetest.c|  18 ++--
 23 files changed, 573 insertions(+), 173 deletions(-)

-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 3/9] virstoragefile: Add virStorageSourceSetBackingStore

2015-02-10 Thread Matthias Gatto
As explained for virStorageSourceGetBackingStore, quorum allows
multiple backing store, this make the operation to set bs complex
because we have to check if the backingStore is used as an array
or a pointer, and set it differently in both case.

In order to help the manipulation of backing store, I've added a
function virStorageSourceSetBackingStore.

For now virStorageSourceSetBackingStore don't handle the case where
we have more than one backing store in virStorageSource.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 10 ++
 src/util/virstoragefile.h |  3 +++
 3 files changed, 14 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 30b7429..c08f6c8 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2054,6 +2054,7 @@ virStorageSourceParseRBDColonString;
 virStorageSourcePoolDefFree;
 virStorageSourcePoolModeTypeFromString;
 virStorageSourcePoolModeTypeToString;
+virStorageSourceSetBackingStore;
 virStorageTypeFromString;
 virStorageTypeToString;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index f78f74c..0cc7c5e 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1806,6 +1806,16 @@ virStorageSourceGetBackingStore(const virStorageSource 
*src,
 }
 
 
+bool
+virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr backingStore,
+size_t pos ATTRIBUTE_UNUSED)
+{
+src-backingStore = backingStore;
+return src-backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index c37ddcf..85b8d6e 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+bool virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr 
backingStore,
+size_t pos);
 virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
 size_t pos);
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 7/9] domain_conf: Read and Write quorum config

2015-02-10 Thread Matthias Gatto
Add the capabiltty to libvirt to parse and format the quorum syntax
as described here:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c | 164 +++--
 1 file changed, 119 insertions(+), 45 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b149065..35ac9f4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5605,20 +5605,56 @@ virDomainDiskSourceParse(xmlNodePtr node,
 }
 
 
+static bool
+virDomainDiskThresholdParse(virStorageSourcePtr src,
+xmlNodePtr node)
+{
+char *threshold = virXMLPropString(node, threshold);
+int ret;
+
+if (!threshold) {
+virReportError(VIR_ERR_XML_ERROR,
+   %s, _(missing threshold in quorum));
+return false;
+}
+ret = virStrToLong_ul(threshold, NULL, 10, src-threshold);
+if (ret  0 || src-threshold  2) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _(unexpected threshold %s),
+   threshold must be a decimal number superior to 2 
+ and inferior to the number of children);
+VIR_FREE(threshold);
+return false;
+}
+VIR_FREE(threshold);
+return true;
+}
+
+
 static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
-   virStorageSourcePtr src)
+   virStorageSourcePtr src,
+   xmlNodePtr node,
+   size_t pos)
 {
 virStorageSourcePtr backingStore = NULL;
 xmlNodePtr save_ctxt = ctxt-node;
-xmlNodePtr source;
+xmlNodePtr source = NULL;
 char *type = NULL;
 char *format = NULL;
 int ret = -1;
 
-if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
-ret = 0;
-goto cleanup;
+if (src-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!node) {
+ret = 0;
+goto cleanup;
+}
+ctxt-node = node;
+} else {
+if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
+ret = 0;
+goto cleanup;
+}
 }
 
 if (VIR_ALLOC(backingStore)  0)
@@ -5650,6 +5686,25 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
+if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) {
+xmlNodePtr cur = NULL;
+
+if (!virDomainDiskThresholdParse(backingStore, node))
+goto cleanup;
+
+for (cur = node-children; cur != NULL; cur = cur-next) {
+if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
+if ((virDomainDiskBackingStoreParse(ctxt,
+backingStore,
+cur,
+
backingStore-nBackingStores)  0)) {
+goto cleanup;
+}
+}
+}
+goto exit;
+}
+
 if (!(source = virXPathNode(./source, ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, %s,
_(missing disk backing store source));
@@ -5657,10 +5712,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 }
 
 if (virDomainDiskSourceParse(source, ctxt, backingStore)  0 ||
-virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
+virDomainDiskBackingStoreParse(ctxt, backingStore, NULL, 0)  0)
 goto cleanup;
 
-if (!virStorageSourceSetBackingStore(src, backingStore, 0))
+ exit:
+if (!virStorageSourceSetBackingStore(src, backingStore, pos))
 goto cleanup;
 ret = 0;
 
@@ -5673,7 +5729,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 return ret;
 }
 
-
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
 
@@ -6167,6 +6222,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 } else if (xmlStrEqual(cur-name, BAD_CAST boot)) {
 /* boot is parsed as part of virDomainDeviceInfoParseXML */
+} else if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
+if (virDomainDiskBackingStoreParse(ctxt, def-src, cur,
+   def-src-nBackingStores)  
0)
+goto error;
 }
 }
 cur = cur-next;
@@ -6190,12 +6249,19 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 def-device = VIR_DOMAIN_DISK_DEVICE_DISK;
 }
 
+if (def-src-type == VIR_STORAGE_TYPE_QUORUM 
+!virDomainDiskThresholdParse(def-src, node))
+goto error;
+
+snapshot = virXMLPropString(node, snapshot);
+
 /* Only CDROM and Floppy devices are allowed missing source path
  * to indicate no media present. LUN is for raw access CD-ROMs
  * that are not attached to a physical device

[libvirt] [PATCH v3 1/9] virstoragefile: Add virStorageSourceGetBackingStore

2015-02-10 Thread Matthias Gatto
Create virStorageSourceGetBackingStore function in
preparation for quorum:
Actually, if we want to get a backing store inside a virStorageSource
we have to do it manually(src-backingStore = backingStore).
The problem is that with a quorum, a virStorageSource
can contain multiple backing stores, and src-backingStore can
be treated as a virStorageSourcePtr or a virStorageSourcePtrPtr.

Due to these reason, we need to simplify the manipulation of
virStorageSource, and create a function to get the asked
backingStore in a virStorageSource

For now, this function only return the backingStore field

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/libvirt_private.syms  | 1 +
 src/util/virstoragefile.c | 8 
 src/util/virstoragefile.h | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 376c69b..30b7429 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2044,6 +2044,7 @@ virStorageSourceClear;
 virStorageSourceCopy;
 virStorageSourceFree;
 virStorageSourceGetActualType;
+virStorageSourceGetBackingStore;
 virStorageSourceGetSecurityLabelDef;
 virStorageSourceInitChainElement;
 virStorageSourceIsEmpty;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 8d3d1f5..1fc27ef 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1798,6 +1798,14 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+virStorageSourcePtr
+virStorageSourceGetBackingStore(const virStorageSource *src,
+size_t pos ATTRIBUTE_UNUSED)
+{
+return src-backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index b4c3808..c37ddcf 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
+size_t pos);
+
 int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
 int virStorageFileProbeFormatFromBuf(const char *path,
  char *buf,
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 4/9] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store

2015-02-10 Thread Matthias Gatto
Replace the parts of the code where a backing store is set manually
with virStorageSourceSetBackingStore

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c| 3 ++-
 src/conf/storage_conf.c   | 7 +--
 src/qemu/qemu_driver.c| 8 
 src/storage/storage_backend_fs.c  | 8 +---
 src/storage/storage_backend_gluster.c | 4 ++--
 src/storage/storage_backend_logical.c | 9 ++---
 src/storage/storage_driver.c  | 2 +-
 src/util/virstoragefile.c | 8 +---
 tests/virstoragetest.c| 4 ++--
 9 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 32bf05c..2286665 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5659,7 +5659,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
 goto cleanup;
 
-src-backingStore = backingStore;
+if (!virStorageSourceSetBackingStore(src, backingStore, 0))
+goto cleanup;
 ret = 0;
 
  cleanup:
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index f4f7e24..a3dac90 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1340,10 +1340,13 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 
 if ((backingStore = virXPathString(string(./backingStore/path), ctxt))) {
 virStorageSourcePtr backingStorePtr;
-if (VIR_ALLOC(ret-target.backingStore)  0)
+if (VIR_ALLOC(backingStorePtr)  0)
 goto error;
 
-backingStorePtr = virStorageSourceGetBackingStore(ret-target, 0);
+if (!virStorageSourceSetBackingStore(ret-target, backingStorePtr, 
0)) {
+VIR_FREE(backingStorePtr);
+goto error;
+}
 backingStorePtr-path = backingStore;
 backingStore = NULL;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8c65fd3..bdca5e0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13590,12 +13590,12 @@ 
qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes.  */
 need_unlink = false;
 
-newDiskSrc-backingStore = disk-src;
+virStorageSourceSetBackingStore(newDiskSrc, disk-src, 0);
 disk-src = newDiskSrc;
 newDiskSrc = NULL;
 
 if (persistDisk) {
-persistDiskSrc-backingStore = persistDisk-src;
+virStorageSourceSetBackingStore(persistDiskSrc, persistDisk-src, 0);
 persistDisk-src = persistDiskSrc;
 persistDiskSrc = NULL;
 }
@@ -13639,13 +13639,13 @@ 
qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes. */
 tmp = disk-src;
 disk-src = virStorageSourceGetBackingStore(tmp, 0);
-tmp-backingStore = NULL;
+virStorageSourceSetBackingStore(tmp, NULL, 0);
 virStorageSourceFree(tmp);
 
 if (persistDisk) {
 tmp = persistDisk-src;
 persistDisk-src = virStorageSourceGetBackingStore(tmp, 0);
-tmp-backingStore = NULL;
+virStorageSourceSetBackingStore(tmp, NULL, 0);
 virStorageSourceFree(tmp);
 }
 }
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 445d11d..18e19fe 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -97,10 +97,12 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
 goto cleanup;
 
 if (meta-backingStoreRaw) {
-backingStore = virStorageSourceGetBackingStore(target, 0);
-if (!(backingStore = virStorageSourceNewFromBacking(meta)))
+if (!virStorageSourceSetBackingStore(target,
+ 
virStorageSourceNewFromBacking(meta),
+ 0))
 goto cleanup;
 
+backingStore = virStorageSourceGetBackingStore(target, 0);
 backingStore-format = backingStoreFormat;
 
 /* XXX: Remote storage doesn't play nicely with volumes backed by
@@ -112,7 +114,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
 if (VIR_ALLOC(backingStore)  0)
 goto cleanup;
 
-target-backingStore = backingStore;
+virStorageSourceSetBackingStore(target, backingStore, 0);
 backingStore-type = VIR_STORAGE_TYPE_NETWORK;
 backingStore-path = meta-backingStoreRaw;
 meta-backingStoreRaw = NULL;
diff --git a/src/storage/storage_backend_gluster.c 
b/src/storage/storage_backend_gluster.c
index fc48f0f..bb79024 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -301,9 +301,9 @@ 
virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
 goto cleanup;
 
 if (meta-backingStoreRaw) {
-if (VIR_ALLOC(vol-target.backingStore)  0)
+if (VIR_ALLOC(backingStore

[libvirt] [PATCH v3 2/9] virstoragefile: Always use virStorageSourceGetBackingStore to get backing store

2015-02-10 Thread Matthias Gatto
Uniformize backing store usage by calling virStorageSourceGetBackingStore
instead of setting backing store manually.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c|  7 ---
 src/conf/storage_conf.c   | 18 ++
 src/qemu/qemu_cgroup.c|  4 ++--
 src/qemu/qemu_domain.c|  2 +-
 src/qemu/qemu_driver.c| 18 ++
 src/security/security_dac.c   |  2 +-
 src/security/security_selinux.c   |  4 ++--
 src/security/virt-aa-helper.c |  2 +-
 src/storage/storage_backend.c | 33 ++---
 src/storage/storage_backend_fs.c  | 33 ++---
 src/storage/storage_backend_gluster.c |  8 +---
 src/storage/storage_backend_logical.c | 10 ++
 src/util/virstoragefile.c | 20 ++--
 tests/virstoragetest.c| 14 +++---
 14 files changed, 95 insertions(+), 80 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d5b15db..32bf05c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16698,7 +16698,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
 /* We currently don't output seclabels for backing chain element */
 if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true)  0 ||
 virDomainDiskBackingStoreFormat(buf,
-backingStore-backingStore,
+
virStorageSourceGetBackingStore(backingStore, 0),
 backingStore-backingStoreRaw,
 idx + 1)  0)
 return -1;
@@ -16820,7 +16820,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
 /* Don't format backingStore to inactive XMLs until the code for
  * persistent storage of backing chains is ready. */
 if (!(flags  VIR_DOMAIN_DEF_FORMAT_INACTIVE) 
-virDomainDiskBackingStoreFormat(buf, def-src-backingStore,
+virDomainDiskBackingStoreFormat(buf,
+
virStorageSourceGetBackingStore(def-src, 0),
 def-src-backingStoreRaw, 1)  0)
 return -1;
 
@@ -20850,7 +20851,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
 }
 }
 
-for (tmp = disk-src; tmp; tmp = tmp-backingStore) {
+for (tmp = disk-src; tmp; tmp = virStorageSourceGetBackingStore(tmp, 0)) {
 int actualType = virStorageSourceGetActualType(tmp);
 /* execute the callback only for local storage */
 if (actualType != VIR_STORAGE_TYPE_NETWORK 
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index e9aaa8a..f4f7e24 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1339,20 +1339,22 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 }
 
 if ((backingStore = virXPathString(string(./backingStore/path), ctxt))) {
+virStorageSourcePtr backingStorePtr;
 if (VIR_ALLOC(ret-target.backingStore)  0)
 goto error;
 
-ret-target.backingStore-path = backingStore;
+backingStorePtr = virStorageSourceGetBackingStore(ret-target, 0);
+backingStorePtr-path = backingStore;
 backingStore = NULL;
 
 if (options-formatFromString) {
 char *format = 
virXPathString(string(./backingStore/format/@type), ctxt);
 if (format == NULL)
-ret-target.backingStore-format = options-defaultFormat;
+backingStorePtr-format = options-defaultFormat;
 else
-ret-target.backingStore-format = 
(options-formatFromString)(format);
+backingStorePtr-format = (options-formatFromString)(format);
 
-if (ret-target.backingStore-format  0) {
+if (backingStorePtr-format  0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_(unknown volume format type %s), format);
 VIR_FREE(format);
@@ -1361,9 +1363,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 VIR_FREE(format);
 }
 
-if (VIR_ALLOC(ret-target.backingStore-perms)  0)
+if (VIR_ALLOC(backingStorePtr-perms)  0)
 goto error;
-if (virStorageDefParsePerms(ctxt, ret-target.backingStore-perms,
+if (virStorageDefParsePerms(ctxt, backingStorePtr-perms,
 ./backingStore/permissions,
 DEFAULT_VOL_PERM_MODE)  0)
 goto error;
@@ -1641,9 +1643,9 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
  def-target, target)  0)
 goto cleanup;
 
-if (def-target.backingStore 
+if (virStorageSourceGetBackingStore((def-target), 0) 
 virStorageVolTargetDefFormat(options, buf

[libvirt] [PATCH v3 9/9] virstoragefile: Add node-name

2015-02-10 Thread Matthias Gatto
Add nodename inside virstoragefile
During xml backingStore parsing, look for a nodename attribute in the disk
declaration if this one is a quorum, if a nodename is found, add it to
the virStorageSource otherwise create a new one with a random name.
Take inspiration from this patch to create the nodename:
http://lists.gnu.org/archive/html/qemu-devel/2014-05/msg03209.html

Durring xml backingStore formating, look for a nodename attribute inside the
virStorageSource struct, and add it to the disk element.

Use the nodename to create the quorum in qemuBuildQuorumStr.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 docs/formatdomain.html.in |  7 +++
 docs/schemas/domaincommon.rng |  5 +
 src/conf/domain_conf.c| 27 +++
 src/qemu/qemu_command.c   |  3 +++
 src/util/virstoragefile.c |  4 
 src/util/virstoragefile.h |  1 +
 6 files changed, 47 insertions(+)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 263baaf..6429e86 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2131,6 +2131,13 @@
 codevda[2]/code refers to the backing store with
 codeindex='2'/code of the disk with codevda/code target.
   /dd
+  dtcodenodename/code attribute
+  span class=sincesince 1.2.13/span/dt
+  dd
+When the backing store is a quorum child, we can use this attribute
+to define the node-name of a child. If this atribute is undefine,
+a random nodename is generate.
+  /dd
   dtcodeformat/code sub-element/dt
   dd
 The codeformat/code element contains codetype/code
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 2556489..a1c5a39 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1304,6 +1304,11 @@
   /attribute
   interleave
 optional
+  attribute name=nodename
+text/
+  /attribute
+/optional
+optional
   ref name=diskDevice/
 /optional
 ref name=diskSource/
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 35ac9f4..e3ac5fb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -56,6 +56,7 @@
 #include network_conf.h
 #include virtpm.h
 #include virstring.h
+#include virrandom.h
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -5631,6 +5632,8 @@ virDomainDiskThresholdParse(virStorageSourcePtr src,
 }
 
 
+#define GEN_NODE_NAME_PREFIXlibvirt
+#define GEN_NODE_NAME_MAX_LEN   (sizeof(GEN_NODE_NAME_PREFIX) + 8 + 8)
 static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
virStorageSourcePtr src,
@@ -5673,6 +5676,26 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
+if (src-type == VIR_STORAGE_TYPE_QUORUM) {
+char *nodeName = NULL;
+
+if ((nodeName = virXMLPropString(ctxt-node, nodename))) {
+backingStore-nodeName = nodeName;
+} else {
+size_t len;
+
+if (VIR_ALLOC_N(nodeName, GEN_NODE_NAME_MAX_LEN)  0)
+goto cleanup;
+if (snprintf(nodeName, GEN_NODE_NAME_MAX_LEN,
+ %s%08x, GEN_NODE_NAME_PREFIX, (int)pos)  0)
+goto cleanup;
+for (len = strlen(nodeName); len  GEN_NODE_NAME_MAX_LEN - 1; 
++len)
+nodeName[len] = virRandomInt('Z' - 'A') + 'A';
+nodeName[GEN_NODE_NAME_MAX_LEN - 1] = '\0';
+backingStore-nodeName = nodeName;
+}
+}
+
 if (!(format = virXPathString(string(./format/@type), ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, %s,
_(missing disk backing store format));
@@ -5728,6 +5751,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 ctxt-node = save_ctxt;
 return ret;
 }
+#undef GEN_NODE_NAME_PREFIX
+#undef GEN_NODE_NAME_MAX_LEN
 
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
@@ -16764,6 +16789,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
   type, idx);
 if (backingStore-threshold)
 virBufferAsprintf(buf,  threshold='%lu', 
backingStore-threshold);
+if (backingStore-nodeName)
+virBufferAsprintf(buf,  nodename='%s', backingStore-nodeName);
 virBufferAddLit(buf, \n);
 virBufferAdjustIndent(buf, 2);
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index acbff19..de971c8 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3435,6 +3435,9 @@ qemuBuildQuorumStr(virConnectPtr conn,
   toAppend, i,
   
virStorageFileFormatTypeToString(backingStore-format));
 
+virBufferAsprintf(opt, ,%schildren.%lu.node-name=%s,
+  toAppend, i, backingStore-nodeName

Re: [libvirt] [PATCH v2 5/9] virstoragefile: Treat backingStore as a pointer or an array

2015-01-28 Thread Matthias Gatto
On Wed, Jan 28, 2015 at 11:10 AM, Michal Privoznik mpriv...@redhat.com wrote:
 On 21.01.2015 16:29, Matthias Gatto wrote:
 As explain in the former patchs, backingStore can be treat an array or
 a pointer.
 If we have only one backingStore we have to use it as a normal ptr
 but if there is more backing store, we use it as a pointer's array.

 Because it would be complicated to expend backingStore manually, and do
 the convertion from a pointer to an array, I've created the
 virStorageSourcePushBackingStore function to help.

 This function allocate an array of pointer only if there is more than 1 bs.

 Because we can not remove a child from a quorum, i didn't create the function
 virStorageSourcePopBackingStore.

 I've changed virStorageSourceBackingStoreClear, 
 virStorageSourceSetBackingStore
 and virStorageSourceGetBackingStore to handle the case where backingStore
 is an array.

 Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
 ---
  src/conf/storage_conf.c   |  7 ++-
  src/libvirt_private.syms  |  1 +
  src/storage/storage_backend_fs.c  |  2 +
  src/storage/storage_backend_logical.c |  2 +-
  src/util/virstoragefile.c | 89 
 ---
  src/util/virstoragefile.h |  2 +
  6 files changed, 94 insertions(+), 9 deletions(-)

 diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
 index fac85fa..41887eb 100644
 --- a/src/conf/storage_conf.c
 +++ b/src/conf/storage_conf.c
 @@ -1343,7 +1343,12 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
  if (VIR_ALLOC(backingStorePtr)  0)
  goto error;

 -backingStorePtr = virStorageSourceSetBackingStore(ret-target, 
 backingStorePtr, 0);
 +if (!virStorageSourcePushBackingStore(ret-target))
 +goto error;
 +
 +backingStorePtr = virStorageSourceSetBackingStore(ret-target,
 +  backingStorePtr,
 +  
 ret-target.nBackingStores - 1);
  backingStorePtr-path = backingStore;
  backingStore = NULL;

 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
 index 980235b..5752907 100644
 --- a/src/libvirt_private.syms
 +++ b/src/libvirt_private.syms
 @@ -2033,6 +2033,7 @@ virStorageSourceParseRBDColonString;
  virStorageSourcePoolDefFree;
  virStorageSourcePoolModeTypeFromString;
  virStorageSourcePoolModeTypeToString;
 +virStorageSourcePushBackingStore;
  virStorageSourceSetBackingStore;
  virStorageTypeFromString;
  virStorageTypeToString;
 diff --git a/src/storage/storage_backend_fs.c 
 b/src/storage/storage_backend_fs.c
 index a3b6688..0d8c5ad 100644
 --- a/src/storage/storage_backend_fs.c
 +++ b/src/storage/storage_backend_fs.c
 @@ -112,6 +112,8 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,

  if (VIR_ALLOC(backingStore)  0)
  goto cleanup;
 +if (virStorageSourcePushBackingStore(target) == false)
 +goto cleanup;
  virStorageSourceSetBackingStore(target, backingStore, 0);
  backingStore-type = VIR_STORAGE_TYPE_NETWORK;
  backingStore-path = meta-backingStoreRaw;
 diff --git a/src/storage/storage_backend_logical.c 
 b/src/storage/storage_backend_logical.c
 index fcec31f..cd8de85 100644
 --- a/src/storage/storage_backend_logical.c
 +++ b/src/storage/storage_backend_logical.c
 @@ -148,7 +148,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
   *  lv is created with --virtualsize).
   */
  if (groups[1]  !STREQ(groups[1], )  (groups[1][0] != '[')) {
 -if (VIR_ALLOC(vol-target.backingStore)  0)
 +if (virStorageSourcePushBackingStore(vol-target) == false)
  goto cleanup;

  if (virAsprintf(virStorageSourceGetBackingStore(vol-target, 
 0)-path, %s/%s,
 diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
 index ba38827..554aa8b 100644
 --- a/src/util/virstoragefile.c
 +++ b/src/util/virstoragefile.c
 @@ -1798,21 +1798,88 @@ virStorageSourcePoolDefCopy(const 
 virStorageSourcePoolDef *src)
  }


 +/**
 + * virStorageSourceGetBackingStore:
 + * @src: virStorageSourcePtr containing the backing stores
 + * @pos: position of the backing store to get
 + *
 + * return the backingStore at the position of @pos
 + */
  virStorageSourcePtr
 -virStorageSourceGetBackingStore(const virStorageSource *src,
 -size_t pos ATTRIBUTE_UNUSED)
 +virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos)
 +{
 +if (!src-backingStore || (pos  1  pos = src-nBackingStores))
 +return NULL;
 +if (src-nBackingStores  2)
 +return src-backingStore;
 +return ((virStorageSourcePtr *)src-backingStore)[pos];
 +}
 +
 +
 +/**
 + * virStorageSourcePushBackingStore:
 + * @src: virStorageSourcePtr to allocate the new backing store
 + *
 + * Allocate size for a new backingStorePtr in src

[libvirt] [PATCH v2 7/9] domain_conf: Read and Write quorum config

2015-01-21 Thread Matthias Gatto
Add the capabiltty to libvirt to parse and format the quorum syntax
as described here:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c | 165 +++--
 1 file changed, 120 insertions(+), 45 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 849e63a..64fe06b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5605,20 +5605,58 @@ virDomainDiskSourceParse(xmlNodePtr node,
 }
 
 
+static bool
+virDomainDiskThresholdParse(virStorageSourcePtr src,
+xmlNodePtr node)
+{
+char *threshold = virXMLPropString(node, threshold);
+int ret;
+
+if (!threshold) {
+virReportError(VIR_ERR_XML_ERROR,
+   %s, _(missing threshold in quorum));
+return false;
+}
+ret = virStrToLong_ul(threshold, NULL, 10, src-threshold);
+if (ret  0 || src-threshold  2) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _(unexpected threshold %s),
+   threshold must be a decimal number superior to 2 
+ and inferior to the number of children);
+VIR_FREE(threshold);
+return false;
+}
+VIR_FREE(threshold);
+return true;
+}
+
+
 static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
-   virStorageSourcePtr src)
+   virStorageSourcePtr src,
+   xmlNodePtr node,
+   size_t pos)
 {
 virStorageSourcePtr backingStore = NULL;
 xmlNodePtr save_ctxt = ctxt-node;
-xmlNodePtr source;
+xmlNodePtr source = NULL;
+xmlNodePtr cur = NULL;
 char *type = NULL;
 char *format = NULL;
 int ret = -1;
+size_t i = 0;
 
-if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
-ret = 0;
-goto cleanup;
+if (src-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!node) {
+ret = 0;
+goto cleanup;
+}
+ctxt-node = node;
+} else {
+if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
+ret = 0;
+goto cleanup;
+}
 }
 
 if (VIR_ALLOC(backingStore)  0)
@@ -5650,6 +5688,22 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
+if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!virDomainDiskThresholdParse(backingStore, node))
+goto cleanup;
+
+for (cur = node-children, i = 0; cur != NULL; cur = cur-next) {
+if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
+if (virStorageSourcePushBackingStore(backingStore) == false)
+goto cleanup;
+if ((virDomainDiskBackingStoreParse(ctxt, backingStore, cur, 
i)  0))
+goto cleanup;
+++i;
+}
+}
+goto exit;
+}
+
 if (!(source = virXPathNode(./source, ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, %s,
_(missing disk backing store source));
@@ -5657,10 +5711,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 }
 
 if (virDomainDiskSourceParse(source, ctxt, backingStore)  0 ||
-virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
+virDomainDiskBackingStoreParse(ctxt, backingStore, NULL, 0)  0)
 goto cleanup;
 
-virStorageSourceSetBackingStore(src, backingStore, 0);
+ exit:
+virStorageSourceSetBackingStore(src, backingStore, pos);
 ret = 0;
 
  cleanup:
@@ -5672,7 +5727,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 return ret;
 }
 
-
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
 
@@ -6166,6 +6220,12 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 } else if (xmlStrEqual(cur-name, BAD_CAST boot)) {
 /* boot is parsed as part of virDomainDeviceInfoParseXML */
+} else if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
+if (virStorageSourcePushBackingStore(def-src) == false)
+goto error;
+if (virDomainDiskBackingStoreParse(ctxt, def-src, cur,
+   def-src-nBackingStores - 
1)  0)
+goto error;
 }
 }
 cur = cur-next;
@@ -6189,12 +6249,19 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 def-device = VIR_DOMAIN_DISK_DEVICE_DISK;
 }
 
+if (def-src-type == VIR_STORAGE_TYPE_QUORUM 
+!virDomainDiskThresholdParse(def-src, node))
+goto error;
+
+snapshot = virXMLPropString(node, snapshot);
+
 /* Only CDROM and Floppy devices are allowed missing source path
  * to indicate no media present. LUN is for raw access CD-ROMs

[libvirt] [PATCH v2 0/9] qemu: Add quorum support to libvirt

2015-01-21 Thread Matthias Gatto
The purpose of these patches is to introduce quorum for libvirt
I've try to follow this proposal:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

This feature ask for 6 task:

1) Allow a _virStorageSource
to contain more than one backing store.

Therefore we have to treat the field virStorageSourcePtr backingStores
as an array instead of a pointer.
But doing that, most of the backingStore field would be an array contening
only one element.
So I've decide to allocate the array only if there is more than 1
backing store in a _virStorageSource.
Because all the actual libvirt code use the backingStore field
as a pointer and we needs want to change that, I've decide to encapsulate
the backingStore field to simplifie the array manipulation.

2) Add the missing field a quorum need in _virStorageSource and
the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
their respectives enums.

3) Parse and format the xml
Because a quorum allows to have more than one backing store at the same level
we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
in a loop.
virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
call themself recursively in a loop because a quorum can contain another
quorum

4) Add nodename
We need to add nodename support in _virStorageSource because qemu
use them for their child.

5) Build qemu string
As for the xml, we have to call the function which create quorum recursively.
But this task have the problem explained here: 
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
The _virStorageSource missing some informations that can be passed to
a child, and therefore this version of quorum is incomplet.

6) Allow to hotplug/change a disk in a quorum
This part is not present in these patches because for this task
we have to use blockdev-add, and currently libvirt use
device_add for hotpluging that doesn't allow to hotplug quorum childs.

There is 3 way to handle this problem:
  1) create a virDomainBlockDevAdd function in libvirt witch call
  blockdev-add.

  2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice

  3) write a hack which uses blockdev-add when only attaching quorum
  (but i'm pretty sure this solution is not the good one)

V2:
-Rebase on master
-Add Documentation

Matthias Gatto (9):
  virstoragefile: Add virStorageSourceGetBackingStore
  virstoragefile: Always use virStorageSourceGetBackingStore to get
backing store
  virstoragefile: Add virStorageSourceSetBackingStore
  virstoragefile: Always use virStorageSourceSetBackingStore to set
backing store
  virstoragefile: Treat backingStore as a pointer or an array
  virstoragefile: Add quorum in virstoragefile
  domain_conf: Read and Write quorum config
  qemu: Add quorum support in qemuBuildDriveDevStr
  virstoragefile: Add node-name

 docs/formatdomain.html.in |  27 -
 docs/schemas/storagecommon.rng|   1 +
 docs/schemas/storagevol.rng   |   1 +
 src/conf/domain_conf.c| 193 ++
 src/conf/storage_conf.c   |  25 +++--
 src/libvirt_private.syms  |   3 +
 src/qemu/qemu_cgroup.c|   4 +-
 src/qemu/qemu_command.c   | 114 
 src/qemu/qemu_domain.c|   2 +-
 src/qemu/qemu_driver.c|  20 ++--
 src/qemu/qemu_migration.c |   1 +
 src/security/security_dac.c   |   2 +-
 src/security/security_selinux.c   |   4 +-
 src/security/virt-aa-helper.c |   2 +-
 src/storage/storage_backend.c |  30 +++---
 src/storage/storage_backend_fs.c  |  35 +++---
 src/storage/storage_backend_gluster.c |   8 +-
 src/storage/storage_backend_logical.c |   8 +-
 src/storage/storage_driver.c  |   2 +-
 src/util/virstoragefile.c | 138 +---
 src/util/virstoragefile.h |  12 +++
 tests/virstoragetest.c|  18 ++--
 22 files changed, 518 insertions(+), 132 deletions(-)

-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 3/9] virstoragefile: Add virStorageSourceSetBackingStore

2015-01-21 Thread Matthias Gatto
As explained for virStorageSourceGetBackingStore, quorum allows
multiple backing store, this make the operation to set bs complex
because we have to check if the backingStore is used as an array
or a pointer, and set it differently in both case.

In order to help the manipulation of backing store, I've added a
function virStorageSourceSetBackingStore.

For now virStorageSourceSetBackingStore don't handle the case where
we have more than one backing store in virStorageSource.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 10 ++
 src/util/virstoragefile.h |  3 +++
 3 files changed, 14 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3f4d02c..980235b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2033,6 +2033,7 @@ virStorageSourceParseRBDColonString;
 virStorageSourcePoolDefFree;
 virStorageSourcePoolModeTypeFromString;
 virStorageSourcePoolModeTypeToString;
+virStorageSourceSetBackingStore;
 virStorageTypeFromString;
 virStorageTypeToString;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 052debf..84eefa3 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1806,6 +1806,16 @@ virStorageSourceGetBackingStore(const virStorageSource 
*src,
 }
 
 
+virStorageSourcePtr
+virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr backingStore,
+size_t pos ATTRIBUTE_UNUSED)
+{
+src-backingStore = backingStore;
+return src-backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index c37ddcf..d5cf7e6 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+virStorageSourcePtr virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr 
backingStore,
+size_t pos);
 virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
 size_t pos);
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 2/9] virstoragefile: Always use virStorageSourceGetBackingStore to get backing store

2015-01-21 Thread Matthias Gatto
Uniformize backing store usage by calling virStorageSourceGetBackingStore
instead of setting backing store manually.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c|  7 ---
 src/conf/storage_conf.c   | 18 ++
 src/qemu/qemu_cgroup.c|  4 ++--
 src/qemu/qemu_domain.c|  2 +-
 src/qemu/qemu_driver.c| 12 ++--
 src/security/security_dac.c   |  2 +-
 src/security/security_selinux.c   |  4 ++--
 src/security/virt-aa-helper.c |  2 +-
 src/storage/storage_backend.c | 30 --
 src/storage/storage_backend_fs.c  | 31 +--
 src/storage/storage_backend_gluster.c |  8 +---
 src/storage/storage_backend_logical.c |  6 +++---
 src/util/virstoragefile.c | 20 ++--
 tests/virstoragetest.c| 14 +++---
 14 files changed, 85 insertions(+), 75 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8792f5e..0668a5b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16704,7 +16704,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
 /* We currently don't output seclabels for backing chain element */
 if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true)  0 ||
 virDomainDiskBackingStoreFormat(buf,
-backingStore-backingStore,
+
virStorageSourceGetBackingStore(backingStore, 0),
 backingStore-backingStoreRaw,
 idx + 1)  0)
 return -1;
@@ -16826,7 +16826,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
 /* Don't format backingStore to inactive XMLs until the code for
  * persistent storage of backing chains is ready. */
 if (!(flags  VIR_DOMAIN_DEF_FORMAT_INACTIVE) 
-virDomainDiskBackingStoreFormat(buf, def-src-backingStore,
+virDomainDiskBackingStoreFormat(buf,
+
virStorageSourceGetBackingStore(def-src, 0),
 def-src-backingStoreRaw, 1)  0)
 return -1;
 
@@ -20868,7 +20869,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
 }
 }
 
-for (tmp = disk-src; tmp; tmp = tmp-backingStore) {
+for (tmp = disk-src; tmp; tmp = virStorageSourceGetBackingStore(tmp, 0)) {
 int actualType = virStorageSourceGetActualType(tmp);
 /* execute the callback only for local storage */
 if (actualType != VIR_STORAGE_TYPE_NETWORK 
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index e9aaa8a..f4f7e24 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1339,20 +1339,22 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 }
 
 if ((backingStore = virXPathString(string(./backingStore/path), ctxt))) {
+virStorageSourcePtr backingStorePtr;
 if (VIR_ALLOC(ret-target.backingStore)  0)
 goto error;
 
-ret-target.backingStore-path = backingStore;
+backingStorePtr = virStorageSourceGetBackingStore(ret-target, 0);
+backingStorePtr-path = backingStore;
 backingStore = NULL;
 
 if (options-formatFromString) {
 char *format = 
virXPathString(string(./backingStore/format/@type), ctxt);
 if (format == NULL)
-ret-target.backingStore-format = options-defaultFormat;
+backingStorePtr-format = options-defaultFormat;
 else
-ret-target.backingStore-format = 
(options-formatFromString)(format);
+backingStorePtr-format = (options-formatFromString)(format);
 
-if (ret-target.backingStore-format  0) {
+if (backingStorePtr-format  0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_(unknown volume format type %s), format);
 VIR_FREE(format);
@@ -1361,9 +1363,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 VIR_FREE(format);
 }
 
-if (VIR_ALLOC(ret-target.backingStore-perms)  0)
+if (VIR_ALLOC(backingStorePtr-perms)  0)
 goto error;
-if (virStorageDefParsePerms(ctxt, ret-target.backingStore-perms,
+if (virStorageDefParsePerms(ctxt, backingStorePtr-perms,
 ./backingStore/permissions,
 DEFAULT_VOL_PERM_MODE)  0)
 goto error;
@@ -1641,9 +1643,9 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
  def-target, target)  0)
 goto cleanup;
 
-if (def-target.backingStore 
+if (virStorageSourceGetBackingStore((def-target), 0) 
 virStorageVolTargetDefFormat(options, buf,
- def

[libvirt] [PATCH v2 8/9] qemu: Add quorum support in qemuBuildDriveDevStr

2015-01-21 Thread Matthias Gatto
Allow to libvirt to build the quorum string used by quemu.

Add 2 static functions: qemuBuildQuorumStr and
qemuBuildAndAppendDriveStrToVirBuffer.
qemuBuildQuorumStr is made because a quorum can have another quorum
as a child, so we may need to call qemuBuildQuorumStr recursively.

qemuBuildQuorumFileSourceStr was basically made to share
the code use to build the source between qemuBuildQuorumStr and
qemuBuildDriveStr, but there is some difference betwin the syntax
use by libvirt to declare a disk and the one qemu need to build a quorum:
a quorum need a syntaxe like:
domaine_name.children.X.file.filename=filename
where libvirt don't use file.filename= but directly file=.
Therfore I use this function only for quorum.

But as explained in the cover letter and here:
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
We miss some informations in _virStorageSource to have a complet
quorum support in libvirt.
Ideally I'd like to refactore virDomainDiskDefFormat to allow
qemuBuildQuorumStr to call this function in a loop.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/qemu/qemu_command.c | 110 
 1 file changed, 110 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2ee3ac3..be7f66c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3185,6 +3185,111 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk)
 return -1;
 }
 
+static bool
+qemuBuildQuorumFileSourceStr(virConnectPtr conn,
+  virStorageSourcePtr src,
+  virBuffer *opt,
+  const char *toAppend)
+{
+char *source = NULL;
+int actualType = virStorageSourceGetActualType(src);
+
+if (qemuGetDriveSourceString(src, conn, source)  0)
+goto error;
+
+if (source) {
+
+virBufferAsprintf(opt, ,%sfilename=, toAppend);
+
+switch (actualType) {
+case VIR_STORAGE_TYPE_DIR:
+/* QEMU only supports magic FAT format for now */
+if (src-format  0 
+src-format != VIR_STORAGE_FILE_FAT) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(unsupported disk driver type for '%s'),
+   virStorageFileFormatTypeToString(src-format));
+goto error;
+}
+
+if (!src-readonly) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(cannot create virtual FAT disks in 
read-write mode));
+goto error;
+}
+
+virBufferAddLit(opt, fat:);
+
+break;
+
+default:
+break;
+}
+virBufferAsprintf(opt, %s, source);
+}
+
+return true;
+ error:
+return false;
+}
+
+
+static bool
+qemuBuildQuorumStr(virConnectPtr conn,
+   virDomainDiskDefPtr disk,
+   virStorageSourcePtr src,
+   virBuffer *opt,
+   const char *toAppend)
+{
+char *tmp = NULL;
+int ret;
+virStorageSourcePtr backingStore;
+size_t i;
+
+if (!src-threshold) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(threshold missing in the quorum configuration));
+return false;
+}
+if (src-nBackingStores  2) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(a quorum must have at last 2 children));
+return false;
+}
+if (src-threshold  src-nBackingStores) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(threshold must not exceed the number of childrens));
+return false;
+}
+virBufferAsprintf(opt, ,%svote-threshold=%lu,
+  toAppend, src-threshold);
+for (i = 0;  i  src-nBackingStores; ++i) {
+backingStore = virStorageSourceGetBackingStore(src, i);
+ret = virAsprintf(tmp, %schildren.%lu.file., toAppend, i);
+if (ret  0)
+return false;
+
+virBufferAsprintf(opt, ,%schildren.%lu.driver=%s,
+  toAppend, i,
+  
virStorageFileFormatTypeToString(backingStore-format));
+
+if (qemuBuildQuorumFileSourceStr(conn, backingStore, opt, tmp) == 
false)
+goto error;
+
+/* This operation avoid me to made another copy */
+tmp[ret - sizeof(file)] = '\0';
+if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!qemuBuildQuorumStr(conn, disk, backingStore, opt, tmp))
+goto error;
+}
+VIR_FREE(tmp);
+}
+return true;
+ error:
+VIR_FREE(tmp);
+return false;
+}
+
 
 /* Qemu 1.2 and later have a binary flag -enable-fips that must be
  * used for VNC auth to obey FIPS settings; but the flag only
@@ -3657,6 +3762,11 @@ qemuBuildDriveStr(virConnectPtr conn

[libvirt] [PATCH v2 5/9] virstoragefile: Treat backingStore as a pointer or an array

2015-01-21 Thread Matthias Gatto
As explain in the former patchs, backingStore can be treat an array or
a pointer.
If we have only one backingStore we have to use it as a normal ptr
but if there is more backing store, we use it as a pointer's array.

Because it would be complicated to expend backingStore manually, and do
the convertion from a pointer to an array, I've created the
virStorageSourcePushBackingStore function to help.

This function allocate an array of pointer only if there is more than 1 bs.

Because we can not remove a child from a quorum, i didn't create the function
virStorageSourcePopBackingStore.

I've changed virStorageSourceBackingStoreClear, virStorageSourceSetBackingStore
and virStorageSourceGetBackingStore to handle the case where backingStore
is an array.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/storage_conf.c   |  7 ++-
 src/libvirt_private.syms  |  1 +
 src/storage/storage_backend_fs.c  |  2 +
 src/storage/storage_backend_logical.c |  2 +-
 src/util/virstoragefile.c | 89 ---
 src/util/virstoragefile.h |  2 +
 6 files changed, 94 insertions(+), 9 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index fac85fa..41887eb 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1343,7 +1343,12 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 if (VIR_ALLOC(backingStorePtr)  0)
 goto error;
 
-backingStorePtr = virStorageSourceSetBackingStore(ret-target, 
backingStorePtr, 0);
+if (!virStorageSourcePushBackingStore(ret-target))
+goto error;
+
+backingStorePtr = virStorageSourceSetBackingStore(ret-target,
+  backingStorePtr,
+  
ret-target.nBackingStores - 1);
 backingStorePtr-path = backingStore;
 backingStore = NULL;
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 980235b..5752907 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2033,6 +2033,7 @@ virStorageSourceParseRBDColonString;
 virStorageSourcePoolDefFree;
 virStorageSourcePoolModeTypeFromString;
 virStorageSourcePoolModeTypeToString;
+virStorageSourcePushBackingStore;
 virStorageSourceSetBackingStore;
 virStorageTypeFromString;
 virStorageTypeToString;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index a3b6688..0d8c5ad 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -112,6 +112,8 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
 
 if (VIR_ALLOC(backingStore)  0)
 goto cleanup;
+if (virStorageSourcePushBackingStore(target) == false)
+goto cleanup;
 virStorageSourceSetBackingStore(target, backingStore, 0);
 backingStore-type = VIR_STORAGE_TYPE_NETWORK;
 backingStore-path = meta-backingStoreRaw;
diff --git a/src/storage/storage_backend_logical.c 
b/src/storage/storage_backend_logical.c
index fcec31f..cd8de85 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -148,7 +148,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
  *  lv is created with --virtualsize).
  */
 if (groups[1]  !STREQ(groups[1], )  (groups[1][0] != '[')) {
-if (VIR_ALLOC(vol-target.backingStore)  0)
+if (virStorageSourcePushBackingStore(vol-target) == false)
 goto cleanup;
 
 if (virAsprintf(virStorageSourceGetBackingStore(vol-target, 
0)-path, %s/%s,
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index ba38827..554aa8b 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1798,21 +1798,88 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+/**
+ * virStorageSourceGetBackingStore:
+ * @src: virStorageSourcePtr containing the backing stores
+ * @pos: position of the backing store to get
+ *
+ * return the backingStore at the position of @pos
+ */
 virStorageSourcePtr
-virStorageSourceGetBackingStore(const virStorageSource *src,
-size_t pos ATTRIBUTE_UNUSED)
+virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos)
+{
+if (!src-backingStore || (pos  1  pos = src-nBackingStores))
+return NULL;
+if (src-nBackingStores  2)
+return src-backingStore;
+return ((virStorageSourcePtr *)src-backingStore)[pos];
+}
+
+
+/**
+ * virStorageSourcePushBackingStore:
+ * @src: virStorageSourcePtr to allocate the new backing store
+ *
+ * Allocate size for a new backingStorePtr in src-backingStore
+ * and update src-nBackingStores
+ * If we have less than 2 backing stores, we treat src-backingStore
+ * as a pointer otherwise we treat it as an array of virStorageSourcePtr
+ */
+bool

[libvirt] [PATCH v2 9/9] virstoragefile: Add node-name

2015-01-21 Thread Matthias Gatto
Add nodename inside virstoragefile
During xml backingStore parsing, look for a nodename attribute in the disk
declaration if this one is a quorum, if a nodename is found, add it to
the virStorageSource otherwise create a new one with a random name.
Take inspiration from this patch to create the nodename:
http://lists.gnu.org/archive/html/qemu-devel/2014-05/msg03209.html

Durring xml backingStore formating, look for a nodename attribute inside the
virStorageSource struct, and add it to the disk element.

Use the nodename to create the quorum in qemuBuildQuorumStr.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 docs/formatdomain.html.in |  7 +++
 src/conf/domain_conf.c| 25 +
 src/qemu/qemu_command.c   |  3 +++
 src/util/virstoragefile.c |  4 
 src/util/virstoragefile.h |  1 +
 5 files changed, 40 insertions(+)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 7ab8cbb..1e1baf8 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2135,6 +2135,13 @@
 codevda[2]/code refers to the backing store with
 codeindex='2'/code of the disk with codevda/code target.
   /dd
+  dtcodenodename/code attribute
+  span class=sincesince 1.2.13/span/dt
+  dd
+When the backing store is a quorum child, we can use this attribute
+to define the node-name of a child. If this atribute is undefine,
+a random nodename is generate.
+  /dd
   dtcodeformat/code sub-element/dt
   dd
 The codeformat/code element contains codetype/code
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 64fe06b..e674960 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -56,6 +56,7 @@
 #include network_conf.h
 #include virtpm.h
 #include virstring.h
+#include virrandom.h
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -5631,6 +5632,8 @@ virDomainDiskThresholdParse(virStorageSourcePtr src,
 }
 
 
+#define GEN_NODE_NAME_PREFIXlibvirt
+#define GEN_NODE_NAME_MAX_LEN   (sizeof(GEN_NODE_NAME_PREFIX) + 8 + 8)
 static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
virStorageSourcePtr src,
@@ -5642,6 +5645,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 xmlNodePtr source = NULL;
 xmlNodePtr cur = NULL;
 char *type = NULL;
+char *nodeName = NULL;
 char *format = NULL;
 int ret = -1;
 size_t i = 0;
@@ -5675,6 +5679,23 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
+if (src-type == VIR_STORAGE_TYPE_QUORUM) {
+if ((nodeName = virXMLPropString(ctxt-node, nodename))) {
+backingStore-nodeName = nodeName;
+} else {
+int len;
+if (VIR_ALLOC_N(nodeName, GEN_NODE_NAME_MAX_LEN)  0)
+goto cleanup;
+snprintf(nodeName, GEN_NODE_NAME_MAX_LEN,
+ %s%08x, GEN_NODE_NAME_PREFIX, (int)pos);
+len = strlen(nodeName);
+while (len  GEN_NODE_NAME_MAX_LEN - 1)
+nodeName[len++] = virRandomInt('Z' - 'A') + 'A';
+nodeName[GEN_NODE_NAME_MAX_LEN - 1] = '\0';
+backingStore-nodeName = nodeName;
+}
+}
+
 if (!(format = virXPathString(string(./format/@type), ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, %s,
_(missing disk backing store format));
@@ -5726,6 +5747,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 ctxt-node = save_ctxt;
 return ret;
 }
+#undef GEN_NODE_NAME_PREFIX
+#undef GEN_NODE_NAME_MAX_LEN
 
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
@@ -16770,6 +16793,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
   type, idx);
 if (backingStore-threshold)
 virBufferAsprintf(buf,  threshold='%lu', 
backingStore-threshold);
+if (backingStore-nodeName)
+virBufferAsprintf(buf,  nodename='%s', backingStore-nodeName);
 virBufferAddLit(buf, \n);
 virBufferAdjustIndent(buf, 2);
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index be7f66c..5a5e9cd 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3273,6 +3273,9 @@ qemuBuildQuorumStr(virConnectPtr conn,
   toAppend, i,
   
virStorageFileFormatTypeToString(backingStore-format));
 
+virBufferAsprintf(opt, ,%schildren.%lu.node-name=%s,
+  toAppend, i, backingStore-nodeName);
+
 if (qemuBuildQuorumFileSourceStr(conn, backingStore, opt, tmp) == 
false)
 goto error;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index d0aa404..1623618 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1961,6 +1961,9 @@ virStorageSourceCopy(const virStorageSource *src,
 !(ret-auth

[libvirt] [PATCH v2 1/9] virstoragefile: Add virStorageSourceGetBackingStore

2015-01-21 Thread Matthias Gatto
Create virStorageSourceGetBackingStore function in
preparation for quorum:
Actually, if we want to get a backing store inside a virStorageSource
we have to do it manually(src-backingStore = backingStore).
The problem is that with a quorum, a virStorageSource
can contain multiple backing stores, and src-backingStore can
be treated as a virStorageSourcePtr or a virStorageSourcePtrPtr.

Due to these reason, we need to simplify the manipulation of
virStorageSource, and create a function to get the asked
backingStore in a virStorageSource

For now, this function only return the backingStore field

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/libvirt_private.syms  | 1 +
 src/util/virstoragefile.c | 8 
 src/util/virstoragefile.h | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a2eec83..3f4d02c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2023,6 +2023,7 @@ virStorageSourceClear;
 virStorageSourceCopy;
 virStorageSourceFree;
 virStorageSourceGetActualType;
+virStorageSourceGetBackingStore;
 virStorageSourceGetSecurityLabelDef;
 virStorageSourceInitChainElement;
 virStorageSourceIsEmpty;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 7a4f9a0..dc6cf8f 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1798,6 +1798,14 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+virStorageSourcePtr
+virStorageSourceGetBackingStore(const virStorageSource *src,
+size_t pos ATTRIBUTE_UNUSED)
+{
+return src-backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index b4c3808..c37ddcf 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -289,6 +289,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
+size_t pos);
+
 int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
 int virStorageFileProbeFormatFromBuf(const char *path,
  char *buf,
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 6/9] virstoragefile: Add quorum in virstoragefile

2015-01-21 Thread Matthias Gatto
Add VIR_STORAGE_TYPE_QUORUM in virStorageType.
Add VIR_STORAGE_FILE_QUORUM in virStorageFileFormat.

Add threshold value in _virStorageSource

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 docs/formatdomain.html.in  | 20 ++--
 docs/schemas/storagecommon.rng |  1 +
 docs/schemas/storagevol.rng|  1 +
 src/conf/domain_conf.c |  2 ++
 src/qemu/qemu_command.c|  1 +
 src/qemu/qemu_driver.c |  4 
 src/qemu/qemu_migration.c  |  1 +
 src/util/virstoragefile.c  | 25 +
 src/util/virstoragefile.h  |  3 +++
 9 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index f8d5f89..7ab8cbb 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1839,8 +1839,9 @@
 dd
 Valid values are file, block,
 dir (span class=sincesince 0.7.5/span),
-network (span class=sincesince 0.8.7/span), or
-volume (span class=sincesince 1.0.5/span)
+network (span class=sincesince 0.8.7/span),
+volume (span class=sincesince 1.0.5/span), or
+quorum (span class=sincesince 1.2.13/span)
 and refer to the underlying source for the disk.
 /dd
   dtcodedevice/code attribute
@@ -1901,6 +1902,14 @@
 codesnapshot='yes'/code with a transient disk generally
 does not make sense.
 /dd
+  dtcodethreshold/code attribute
+  span class=sincesince 1.2.13/span/dt
+dd
+Only use with a quorum disk.
+Indicate the minimum of positive vote a quorum must have to 
validate
+a data to be write. The minimum value is 2. The number of 
backingStores
+contain by the quorum must be superior to the threshold.
+/dd
 /dl
   /dd
   dtcodesource/code/dt
@@ -1971,6 +1980,11 @@
   
'file=/dev/disk/by-path/ip-example.com:3260-iscsi-iqn.2013-07.com.example:iscsi-pool-lun-1').
   /p
   /dd
+dtcodetype='quorum'/code
+span class=sincesince 1.2.13/span/dt
+  dd
+  A quorum contain no source element, but a serie of backingStores 
instead.
+  /dd
   /dl
 With file, block, and volume, one or more optional
 sub-elements codeseclabel/code, a href=#seclabeldescribed
@@ -2102,6 +2116,8 @@
 codebackingStore/code element means the sibling source is
 self-contained and is not based on any backing store. The following
 attributes and sub-elements are supported in
+span class=sinceSince 1.2.11/span. This elements is used to
+describe a quorum child.
 codebackingStore/code:
 dl
   dtcodetype/code attribute/dt
diff --git a/docs/schemas/storagecommon.rng b/docs/schemas/storagecommon.rng
index 5f71b10..ba9f485 100644
--- a/docs/schemas/storagecommon.rng
+++ b/docs/schemas/storagecommon.rng
@@ -76,6 +76,7 @@
   valuefat/value
   valuevhd/value
   valueploop/value
+  valuequorum/value
   ref name='storageFormatBacking'/
 /choice
   /define
diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 7450547..a718576 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -20,6 +20,7 @@
 valuedir/value
 valuenetwork/value
 valuenetdir/value
+valuequorum/value
   /choice
 /attribute
   /optional
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9d6b888..849e63a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5581,6 +5581,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
 if (virDomainDiskSourcePoolDefParse(node, src-srcpool)  0)
 goto cleanup;
 break;
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -16643,6 +16644,7 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
  skipSeclabels);
 break;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7e1f3d0..2ee3ac3 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3104,6 +3104,7 @@ qemuGetDriveSourceString(virStorageSourcePtr src,
 goto cleanup;
 break;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_VOLUME:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b3afccd..88a24fb 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12984,6 +12984,7

[libvirt] [PATCH v2 4/9] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store

2015-01-21 Thread Matthias Gatto
Replace the parts of the code where a backing store is set manually
with virStorageSourceSetBackingStore

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c   | 2 +-
 src/conf/storage_conf.c  | 4 ++--
 src/qemu/qemu_driver.c   | 4 ++--
 src/storage/storage_backend_fs.c | 8 
 src/storage/storage_driver.c | 2 +-
 src/util/virstoragefile.c| 8 +---
 tests/virstoragetest.c   | 4 ++--
 7 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0668a5b..9d6b888 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5659,7 +5659,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
 goto cleanup;
 
-src-backingStore = backingStore;
+virStorageSourceSetBackingStore(src, backingStore, 0);
 ret = 0;
 
  cleanup:
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index f4f7e24..fac85fa 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1340,10 +1340,10 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 
 if ((backingStore = virXPathString(string(./backingStore/path), ctxt))) {
 virStorageSourcePtr backingStorePtr;
-if (VIR_ALLOC(ret-target.backingStore)  0)
+if (VIR_ALLOC(backingStorePtr)  0)
 goto error;
 
-backingStorePtr = virStorageSourceGetBackingStore(ret-target, 0);
+backingStorePtr = virStorageSourceSetBackingStore(ret-target, 
backingStorePtr, 0);
 backingStorePtr-path = backingStore;
 backingStore = NULL;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 547d2b5..b3afccd 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13500,13 +13500,13 @@ 
qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes. */
 tmp = disk-src;
 disk-src = virStorageSourceGetBackingStore(tmp, 0);
-tmp-backingStore = NULL;
+virStorageSourceSetBackingStore(tmp, NULL, 0);
 virStorageSourceFree(tmp);
 
 if (persistDisk) {
 tmp = persistDisk-src;
 persistDisk-src = virStorageSourceGetBackingStore(tmp, 0);
-tmp-backingStore = NULL;
+virStorageSourceSetBackingStore(tmp, NULL, 0);
 virStorageSourceFree(tmp);
 }
 }
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 56cfc56..a3b6688 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -97,8 +97,9 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
 goto cleanup;
 
 if (meta-backingStoreRaw) {
-backingStore = virStorageSourceGetBackingStore(target, 0);
-if (!(backingStore = virStorageSourceNewFromBacking(meta)))
+if (!(backingStore = virStorageSourceSetBackingStore(target,
+ 
virStorageSourceNewFromBacking(meta),
+ 0)))
 goto cleanup;
 
 backingStore-format = backingStoreFormat;
@@ -111,8 +112,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
 
 if (VIR_ALLOC(backingStore)  0)
 goto cleanup;
-
-target-backingStore = backingStore;
+virStorageSourceSetBackingStore(target, backingStore, 0);
 backingStore-type = VIR_STORAGE_TYPE_NETWORK;
 backingStore-path = meta-backingStoreRaw;
 meta-backingStoreRaw = NULL;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 66dc994..eeb2a4c 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -2899,7 +2899,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
 goto cleanup;
 }
 
-src-backingStore = backingStore;
+virStorageSourceSetBackingStore(src, backingStore, 0);
 backingStore = NULL;
 ret = 0;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 84eefa3..ba38827 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1891,8 +1891,10 @@ virStorageSourceCopy(const virStorageSource *src,
 goto error;
 
 if (backingChain  virStorageSourceGetBackingStore(src, 0)) {
-if (!(ret-backingStore = 
virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0),
-   true)))
+if (!virStorageSourceSetBackingStore(ret,
+ 
virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0),
+  true),
+ 0))
 goto error;
 }
 
@@ -2029,7 +2031,7 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def)
 
 /* recursively free backing chain

Re: [libvirt] [PATCH 0/9] qemu: Add quorum support to libvirt

2015-01-05 Thread Matthias Gatto
On Wed, Dec 17, 2014 at 10:53 AM, Matthias Gatto
matthias.ga...@outscale.com wrote:
 On Mon, Dec 8, 2014 at 7:31 PM, Matthias Gatto
 matthias.ga...@outscale.com wrote:
 The purpose of these patches is to introduce quorum for libvirt
 I've try to follow this proposal:
 http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

 This feature ask for 6 task:

 1) Allow a _virStorageSource
 to contain more than one backing store.

 Therefore we have to treat the field virStorageSourcePtr backingStores
 as an array instead of a pointer.
 But doing that, most of the backingStore field would be an array contening
 only one element.
 So I've decide to allocate the array only if there is more than 1
 backing store in a _virStorageSource.
 Because all the actual libvirt code use the backingStore field
 as a pointer and we needs want to change that, I've decide to encapsulate
 the backingStore field to simplifie the array manipulation.

 2) Add the missing field a quorum need in _virStorageSource and
 the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
 their respectives enums.

 3) Parse and format the xml
 Because a quorum allows to have more than one backing store at the same level
 we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
 to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
 in a loop.
 virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
 call themself recursively in a loop because a quorum can contain another
 quorum

 4) Add nodename
 We need to add nodename support in _virStorageSource because qemu
 use them for their child.

 5) Build qemu string
 As for the xml, we have to call the function which create quorum recursively.
 But this task have the problem explained here:
 http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
 The _virStorageSource missing some informations that can be passed to
 a child, and therefore this version of quorum is incomplet.

 6) Allow to hotplug/change a disk in a quorum
 This part is not present in these patches because for this task
 we have to use blockdev-add, and currently libvirt use
 device_add for hotpluging that doesn't allow to hotplug quorum childs.

 There is 3 way to handle this problem:
   1) create a virDomainBlockDevAdd function in libvirt witch call
   blockdev-add.

   2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice

   3) write a hack which uses blockdev-add when only attaching quorum
   (but i'm pretty sure this solution is not the good one)

 Matthias Gatto (9):
   virstoragefile: Add virStorageSourceGetBackingStore
   virstoragefile: Always use virStorageSourceGetBackingStore to get
 backing store
   virstoragefile: Add virStorageSourceSetBackingStore
   virstoragefile: Always use virStorageSourceSetBackingStore to set
 backing store
   virstoragefile: Treat backingStore as a pointer or an array
   virstoragefile: Add quorum in virstoragefile
   domain_conf: Read and Write quorum config
   qemu: Add quorum support in qemuBuildDriveDevStr
   virstoragefile: Add node-name

  src/conf/domain_conf.c| 193 
 ++
  src/conf/storage_conf.c   |   7 +-
  src/libvirt_private.syms  |   3 +
  src/qemu/qemu_cgroup.c|   4 +-
  src/qemu/qemu_command.c   | 114 
  src/qemu/qemu_domain.c|   3 +-
  src/qemu/qemu_driver.c|  20 ++--
  src/security/security_dac.c   |   2 +-
  src/security/security_selinux.c   |   4 +-
  src/security/virt-aa-helper.c |   2 +-
  src/storage/storage_backend.c |  12 +--
  src/storage/storage_backend_fs.c  |  12 +--
  src/storage/storage_backend_logical.c |   4 +-
  src/storage/storage_driver.c  |   2 +-
  src/util/virstoragefile.c | 136 +---
  src/util/virstoragefile.h |  12 +++
  tests/virstoragetest.c|  18 ++--
  17 files changed, 445 insertions(+), 103 deletions(-)

 --
 1.8.3.1


 ping
ping

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 0/9] qemu: Add quorum support to libvirt

2014-12-17 Thread Matthias Gatto
On Mon, Dec 8, 2014 at 7:31 PM, Matthias Gatto
matthias.ga...@outscale.com wrote:
 The purpose of these patches is to introduce quorum for libvirt
 I've try to follow this proposal:
 http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

 This feature ask for 6 task:

 1) Allow a _virStorageSource
 to contain more than one backing store.

 Therefore we have to treat the field virStorageSourcePtr backingStores
 as an array instead of a pointer.
 But doing that, most of the backingStore field would be an array contening
 only one element.
 So I've decide to allocate the array only if there is more than 1
 backing store in a _virStorageSource.
 Because all the actual libvirt code use the backingStore field
 as a pointer and we needs want to change that, I've decide to encapsulate
 the backingStore field to simplifie the array manipulation.

 2) Add the missing field a quorum need in _virStorageSource and
 the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
 their respectives enums.

 3) Parse and format the xml
 Because a quorum allows to have more than one backing store at the same level
 we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
 to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
 in a loop.
 virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
 call themself recursively in a loop because a quorum can contain another
 quorum

 4) Add nodename
 We need to add nodename support in _virStorageSource because qemu
 use them for their child.

 5) Build qemu string
 As for the xml, we have to call the function which create quorum recursively.
 But this task have the problem explained here:
 http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
 The _virStorageSource missing some informations that can be passed to
 a child, and therefore this version of quorum is incomplet.

 6) Allow to hotplug/change a disk in a quorum
 This part is not present in these patches because for this task
 we have to use blockdev-add, and currently libvirt use
 device_add for hotpluging that doesn't allow to hotplug quorum childs.

 There is 3 way to handle this problem:
   1) create a virDomainBlockDevAdd function in libvirt witch call
   blockdev-add.

   2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice

   3) write a hack which uses blockdev-add when only attaching quorum
   (but i'm pretty sure this solution is not the good one)

 Matthias Gatto (9):
   virstoragefile: Add virStorageSourceGetBackingStore
   virstoragefile: Always use virStorageSourceGetBackingStore to get
 backing store
   virstoragefile: Add virStorageSourceSetBackingStore
   virstoragefile: Always use virStorageSourceSetBackingStore to set
 backing store
   virstoragefile: Treat backingStore as a pointer or an array
   virstoragefile: Add quorum in virstoragefile
   domain_conf: Read and Write quorum config
   qemu: Add quorum support in qemuBuildDriveDevStr
   virstoragefile: Add node-name

  src/conf/domain_conf.c| 193 
 ++
  src/conf/storage_conf.c   |   7 +-
  src/libvirt_private.syms  |   3 +
  src/qemu/qemu_cgroup.c|   4 +-
  src/qemu/qemu_command.c   | 114 
  src/qemu/qemu_domain.c|   3 +-
  src/qemu/qemu_driver.c|  20 ++--
  src/security/security_dac.c   |   2 +-
  src/security/security_selinux.c   |   4 +-
  src/security/virt-aa-helper.c |   2 +-
  src/storage/storage_backend.c |  12 +--
  src/storage/storage_backend_fs.c  |  12 +--
  src/storage/storage_backend_logical.c |   4 +-
  src/storage/storage_driver.c  |   2 +-
  src/util/virstoragefile.c | 136 +---
  src/util/virstoragefile.h |  12 +++
  tests/virstoragetest.c|  18 ++--
  17 files changed, 445 insertions(+), 103 deletions(-)

 --
 1.8.3.1


ping

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 4/9] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store

2014-12-08 Thread Matthias Gatto
Replace the parts of the code where a backing store is set manually
with virStorageSourceSetBackingStore

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c   | 2 +-
 src/qemu/qemu_domain.c   | 1 -
 src/qemu/qemu_driver.c   | 4 ++--
 src/storage/storage_backend_fs.c | 2 +-
 src/storage/storage_driver.c | 2 +-
 src/util/virstoragefile.c| 8 +---
 tests/virstoragetest.c   | 4 ++--
 7 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b790fc5..00e0470 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5523,7 +5523,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
 goto cleanup;
 
-src-backingStore = backingStore;
+virStorageSourceSetBackingStore(src, backingStore, 0);
 ret = 0;
 
  cleanup:
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 9157e4d..458ceb0 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2534,7 +2534,6 @@ qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
 int ret = -1;
 size_t i;
 
-VIR_DEBUG(Checking for disk presence);
 for (i = vm-def-ndisks; i  0; i--) {
 size_t idx = i - 1;
 virDomainDiskDefPtr disk = vm-def-disks[idx];
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9ed5035..8e3a492 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13497,13 +13497,13 @@ 
qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
 /* Update vm in place to match changes. */
 tmp = disk-src;
 disk-src = virStorageSourceGetBackingStore(tmp, 0);
-tmp-backingStore = NULL;
+virStorageSourceSetBackingStore(tmp, NULL, 0);
 virStorageSourceFree(tmp);
 
 if (persistDisk) {
 tmp = persistDisk-src;
 persistDisk-src = virStorageSourceGetBackingStore(tmp, 0);
-tmp-backingStore = NULL;
+virStorageSourceSetBackingStore(tmp, NULL, 0);
 virStorageSourceFree(tmp);
 }
 }
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index d7bd1fb..07fd6ee 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -96,7 +96,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
 goto cleanup;
 
 if (meta-backingStoreRaw) {
-if (!(target-backingStore = virStorageSourceNewFromBacking(meta)))
+if (!virStorageSourceSetBackingStore(target, 
virStorageSourceNewFromBacking(meta), 0))
 goto cleanup;
 
 target-backingStore-format = backingStoreFormat;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 66dc994..eeb2a4c 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -2899,7 +2899,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
 goto cleanup;
 }
 
-src-backingStore = backingStore;
+virStorageSourceSetBackingStore(src, backingStore, 0);
 backingStore = NULL;
 ret = 0;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 88b0ce6..20f45f3 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1906,8 +1906,10 @@ virStorageSourceCopy(const virStorageSource *src,
 goto error;
 
 if (backingChain  virStorageSourceGetBackingStore(src, 0)) {
-if (!(ret-backingStore = 
virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0),
-   true)))
+if (!virStorageSourceSetBackingStore(ret,
+ 
virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0),
+  true),
+ 0))
 goto error;
 }
 
@@ -2044,7 +2046,7 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def)
 
 /* recursively free backing chain */
 virStorageSourceFree(virStorageSourceGetBackingStore(def, 0));
-def-backingStore = NULL;
+virStorageSourceSetBackingStore(def, NULL, 0);
 }
 
 
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 12670da..b7820d4 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -583,9 +583,9 @@ testPathRelativePrepare(void)
 
 for (i = 0; i  ARRAY_CARDINALITY(backingchain); i++) {
 if (i  ARRAY_CARDINALITY(backingchain) - 1)
-backingchain[i].backingStore = backingchain[i + 1];
+virStorageSourceSetBackingStore(backingchain[i], backingchain[i 
+ 1], 0);
 else
-backingchain[i].backingStore = NULL;
+virStorageSourceSetBackingStore(backingchain[i], NULL, 0);
 
 backingchain[i].relPath = NULL;
 }
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 3/9] virstoragefile: Add virStorageSourceSetBackingStore

2014-12-08 Thread Matthias Gatto
As explained for virStorageSourceGetBackingStore, quorum allows
multiple backing store, this make the operation to set bs complex
because we have to check if the backingStore is used as an array
or a pointer, and set it differently in both case.

In order to help the manipulation of backing store, I've added a
function virStorageSourceSetBackingStore.

For now virStorageSourceSetBackingStore don't handle the case where
we have more than one backing store in virStorageSource.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 10 ++
 src/util/virstoragefile.h |  3 +++
 3 files changed, 14 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 12dd399..dd83518 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2002,6 +2002,7 @@ virStorageSourceParseRBDColonString;
 virStorageSourcePoolDefFree;
 virStorageSourcePoolModeTypeFromString;
 virStorageSourcePoolModeTypeToString;
+virStorageSourceSetBackingStore;
 virStorageTypeFromString;
 virStorageTypeToString;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index fd0e68c..88b0ce6 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1822,6 +1822,16 @@ virStorageSourceGetBackingStore(const virStorageSource 
*src,
 }
 
 
+virStorageSourcePtr
+virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr backingStore,
+size_t pos ATTRIBUTE_UNUSED)
+{
+src-backingStore = backingStore;
+return src-backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index fe07dde..4cba66b 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -288,6 +288,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+virStorageSourcePtr virStorageSourceSetBackingStore(virStorageSourcePtr src,
+virStorageSourcePtr 
backingStore,
+size_t pos);
 virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
 size_t pos);
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/9] virstoragefile: Add virStorageSourceGetBackingStore

2014-12-08 Thread Matthias Gatto
Create virStorageSourceGetBackingStore function in
preparation for quorum:
Actually, if we want to get a backing store inside a virStorageSource
we have to do it manually(src-backingStore = backingStore).
The problem is that with a quorum, a virStorageSource
can contain multiple backing stores, and src-backingStore can
be treated as a virStorageSourcePtr or a virStorageSourcePtrPtr.

Due to these reason, we need to simplify the manipulation of
virStorageSource, and create a function to get the asked
backingStore in a virStorageSource

For now, this function only return the backingStore field

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/libvirt_private.syms  | 1 +
 src/util/virstoragefile.c | 8 
 src/util/virstoragefile.h | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1853a9c..12dd399 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1992,6 +1992,7 @@ virStorageSourceClear;
 virStorageSourceCopy;
 virStorageSourceFree;
 virStorageSourceGetActualType;
+virStorageSourceGetBackingStore;
 virStorageSourceGetSecurityLabelDef;
 virStorageSourceInitChainElement;
 virStorageSourceIsEmpty;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index c424251..ebcf7c3 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1814,6 +1814,14 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+virStorageSourcePtr
+virStorageSourceGetBackingStore(const virStorageSource *src,
+size_t pos ATTRIBUTE_UNUSED)
+{
+return src-backingStore;
+}
+
+
 /**
  * virStorageSourcePtr:
  *
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index e05b843..fe07dde 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -288,6 +288,9 @@ struct _virStorageSource {
 #  define DEV_BSIZE 512
 # endif
 
+virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource 
*src,
+size_t pos);
+
 int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
 int virStorageFileProbeFormatFromBuf(const char *path,
  char *buf,
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 5/9] virstoragefile: Treat backingStore as a pointer or an array

2014-12-08 Thread Matthias Gatto
As explain in the former patchs, backingStore can be treat an array or
a pointer.
If we have only one backingStore we have to use it as a normal ptr
but if there is more backing store, we use it as a pointer's array.

Because it would be complicated to expend backingStore manually, and do
the convertion from a pointer to an array, I've created the
virStorageSourcePushBackingStore function to help.

This function allocate an array of pointer only if there is more than 1 bs.

Because we can not remove a child from a quorum, i didn't create the function
virStorageSourcePopBackingStore.

I've changed virStorageSourceBackingStoreClear, virStorageSourceSetBackingStore
and virStorageSourceGetBackingStore to handle the case where backingStore
is an array.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/storage_conf.c   |  3 +-
 src/libvirt_private.syms  |  1 +
 src/storage/storage_backend_fs.c  |  2 +-
 src/storage/storage_backend_logical.c |  2 +-
 src/util/virstoragefile.c | 87 ---
 src/util/virstoragefile.h |  2 +
 6 files changed, 87 insertions(+), 10 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index a8a90b4..fc51d47 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1340,8 +1340,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 }
 
 if ((backingStore = virXPathString(string(./backingStore/path), ctxt))) {
-if (VIR_ALLOC(ret-target.backingStore)  0)
+if (VIR_ALLOC_N(ret-target.backingStore, 1)  0)
 goto error;
+ret-target.nBackingStores = 1;
 
 ret-target.backingStore-path = backingStore;
 backingStore = NULL;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index dd83518..71e8625 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2002,6 +2002,7 @@ virStorageSourceParseRBDColonString;
 virStorageSourcePoolDefFree;
 virStorageSourcePoolModeTypeFromString;
 virStorageSourcePoolModeTypeToString;
+virStorageSourcePushBackingStore;
 virStorageSourceSetBackingStore;
 virStorageTypeFromString;
 virStorageTypeToString;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 07fd6ee..979abd3 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -107,7 +107,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
 if 
(!virStorageSourceIsLocalStorage(virStorageSourceGetBackingStore(target, 0))) {
 virStorageSourceFree(virStorageSourceGetBackingStore(target, 0));
 
-if (VIR_ALLOC(target-backingStore)  0)
+if (virStorageSourcePushBackingStore(target) == false)
 goto cleanup;
 
 target-backingStore-type = VIR_STORAGE_TYPE_NETWORK;
diff --git a/src/storage/storage_backend_logical.c 
b/src/storage/storage_backend_logical.c
index 300c990..edec124 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -148,7 +148,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
  *  lv is created with --virtualsize).
  */
 if (groups[1]  !STREQ(groups[1], )  (groups[1][0] != '[')) {
-if (VIR_ALLOC(vol-target.backingStore)  0)
+if (virStorageSourcePushBackingStore(vol-target) == false)
 goto cleanup;
 
 if (virAsprintf(vol-target.backingStore-path, %s/%s,
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 20f45f3..4217a80 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1814,21 +1814,86 @@ virStorageSourcePoolDefCopy(const 
virStorageSourcePoolDef *src)
 }
 
 
+/**
+ * virStorageSourceGetBackingStore:
+ * @src: virStorageSourcePtr containing the backing stores
+ * @pos: position of the backing store to get
+ *
+ * return the backingStore at the position of @pos
+ */
 virStorageSourcePtr
-virStorageSourceGetBackingStore(const virStorageSource *src,
-size_t pos ATTRIBUTE_UNUSED)
+virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos)
 {
-return src-backingStore;
+if (!src-backingStore || (pos  1  pos = src-nBackingStores))
+return NULL;
+if (src-nBackingStores  2)
+return src-backingStore;
+return ((virStorageSourcePtr *)src-backingStore)[pos];
 }
 
 
+/**
+ * virStorageSourcePushBackingStore:
+ * @src: virStorageSourcePtr to allocate the new backing store
+ *
+ * Allocate size for a new backing store in src-backingStore
+ * and update src-nBackingStores
+ * If we have less than 2 backing stores, we treat src-backingStore
+ * as a pointer otherwise we treat it as an array of virStorageSourcePtr
+ */
+bool
+virStorageSourcePushBackingStore(virStorageSourcePtr src)
+{
+virStorageSourcePtr tmp;
+virStorageSourcePtr *tmp2;
+
+if (src-nBackingStores == 1) {
+/* If we need more than one backing store we

[libvirt] [PATCH 8/9] qemu: Add quorum support in qemuBuildDriveDevStr

2014-12-08 Thread Matthias Gatto
Allow to libvirt to build the quorum string used by quemu.

Add 2 static functions: qemuBuildQuorumStr and
qemuBuildAndAppendDriveStrToVirBuffer.
qemuBuildQuorumStr is made because a quorum can have another quorum
as a child, so we may need to call qemuBuildQuorumStr recursively.

qemuBuildQuorumFileSourceStr was basically made to share
the code use to build the source between qemuBuildQuorumStr and
qemuBuildDriveStr, but there is some difference betwin the syntax
use by libvirt to declare a disk and the one qemu need to build a quorum:
a quorum need a syntaxe like:
domaine_name.children.X.file.filename=filename
where libvirt don't use file.filename= but directly file=.
Therfore I use this function only for quorum.

But as explained in the cover letter and here:
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
We miss some informations in _virStorageSource to have a complet
quorum support in libvirt.
Ideally I'd like to refactore virDomainDiskDefFormat to allow
qemuBuildQuorumStr to call this function in a loop.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/qemu/qemu_command.c | 110 
 1 file changed, 110 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 525a49c..03ff1b7 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3167,6 +3167,111 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk)
 return -1;
 }
 
+static bool
+qemuBuildQuorumFileSourceStr(virConnectPtr conn,
+  virStorageSourcePtr src,
+  virBuffer *opt,
+  const char *toAppend)
+{
+char *source = NULL;
+int actualType = virStorageSourceGetActualType(src);
+
+if (qemuGetDriveSourceString(src, conn, source)  0)
+goto error;
+
+if (source) {
+
+virBufferAsprintf(opt, ,%sfilename=, toAppend);
+
+switch (actualType) {
+case VIR_STORAGE_TYPE_DIR:
+/* QEMU only supports magic FAT format for now */
+if (src-format  0 
+src-format != VIR_STORAGE_FILE_FAT) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(unsupported disk driver type for '%s'),
+   virStorageFileFormatTypeToString(src-format));
+goto error;
+}
+
+if (!src-readonly) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(cannot create virtual FAT disks in 
read-write mode));
+goto error;
+}
+
+virBufferAddLit(opt, fat:);
+
+break;
+
+default:
+break;
+}
+virBufferAsprintf(opt, %s, source);
+}
+
+return true;
+ error:
+return false;
+}
+
+
+static bool
+qemuBuildQuorumStr(virConnectPtr conn,
+   virDomainDiskDefPtr disk,
+   virStorageSourcePtr src,
+   virBuffer *opt,
+   const char *toAppend)
+{
+char *tmp = NULL;
+int ret;
+virStorageSourcePtr backingStore;
+size_t i;
+
+if (!src-threshold) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(threshold missing in the quorum configuration));
+return false;
+}
+if (src-nBackingStores  2) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(a quorum must have at last 2 children));
+return false;
+}
+if (src-threshold  src-nBackingStores) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(threshold must not exceed the number of childrens));
+return false;
+}
+virBufferAsprintf(opt, ,%svote-threshold=%lu,
+  toAppend, src-threshold);
+for (i = 0;  i  src-nBackingStores; ++i) {
+backingStore = virStorageSourceGetBackingStore(src, i);
+ret = virAsprintf(tmp, %schildren.%lu.file., toAppend, i);
+if (ret  0)
+return false;
+
+virBufferAsprintf(opt, ,%schildren.%lu.driver=%s,
+  toAppend, i,
+  
virStorageFileFormatTypeToString(backingStore-format));
+
+if (qemuBuildQuorumFileSourceStr(conn, backingStore, opt, tmp) == 
false)
+goto error;
+
+/* This operation avoid me to made another copy */
+tmp[ret - sizeof(file)] = '\0';
+if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!qemuBuildQuorumStr(conn, disk, backingStore, opt, tmp))
+goto error;
+}
+VIR_FREE(tmp);
+}
+return true;
+ error:
+VIR_FREE(tmp);
+return false;
+}
+
 
 /* Qemu 1.2 and later have a binary flag -enable-fips that must be
  * used for VNC auth to obey FIPS settings; but the flag only
@@ -3639,6 +3744,11 @@ qemuBuildDriveStr(virConnectPtr conn

[libvirt] [PATCH 0/9] qemu: Add quorum support to libvirt

2014-12-08 Thread Matthias Gatto
The purpose of these patches is to introduce quorum for libvirt
I've try to follow this proposal:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

This feature ask for 6 task:

1) Allow a _virStorageSource
to contain more than one backing store.

Therefore we have to treat the field virStorageSourcePtr backingStores
as an array instead of a pointer.
But doing that, most of the backingStore field would be an array contening
only one element.
So I've decide to allocate the array only if there is more than 1
backing store in a _virStorageSource.
Because all the actual libvirt code use the backingStore field
as a pointer and we needs want to change that, I've decide to encapsulate
the backingStore field to simplifie the array manipulation.

2) Add the missing field a quorum need in _virStorageSource and
the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in
their respectives enums.

3) Parse and format the xml
Because a quorum allows to have more than one backing store at the same level
we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML
to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse
in a loop.
virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can
call themself recursively in a loop because a quorum can contain another
quorum

4) Add nodename
We need to add nodename support in _virStorageSource because qemu
use them for their child.

5) Build qemu string
As for the xml, we have to call the function which create quorum recursively.
But this task have the problem explained here: 
http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html
The _virStorageSource missing some informations that can be passed to
a child, and therefore this version of quorum is incomplet.

6) Allow to hotplug/change a disk in a quorum
This part is not present in these patches because for this task
we have to use blockdev-add, and currently libvirt use
device_add for hotpluging that doesn't allow to hotplug quorum childs.

There is 3 way to handle this problem:
  1) create a virDomainBlockDevAdd function in libvirt witch call
  blockdev-add.

  2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice

  3) write a hack which uses blockdev-add when only attaching quorum
  (but i'm pretty sure this solution is not the good one)

Matthias Gatto (9):
  virstoragefile: Add virStorageSourceGetBackingStore
  virstoragefile: Always use virStorageSourceGetBackingStore to get
backing store
  virstoragefile: Add virStorageSourceSetBackingStore
  virstoragefile: Always use virStorageSourceSetBackingStore to set
backing store
  virstoragefile: Treat backingStore as a pointer or an array
  virstoragefile: Add quorum in virstoragefile
  domain_conf: Read and Write quorum config
  qemu: Add quorum support in qemuBuildDriveDevStr
  virstoragefile: Add node-name

 src/conf/domain_conf.c| 193 ++
 src/conf/storage_conf.c   |   7 +-
 src/libvirt_private.syms  |   3 +
 src/qemu/qemu_cgroup.c|   4 +-
 src/qemu/qemu_command.c   | 114 
 src/qemu/qemu_domain.c|   3 +-
 src/qemu/qemu_driver.c|  20 ++--
 src/security/security_dac.c   |   2 +-
 src/security/security_selinux.c   |   4 +-
 src/security/virt-aa-helper.c |   2 +-
 src/storage/storage_backend.c |  12 +--
 src/storage/storage_backend_fs.c  |  12 +--
 src/storage/storage_backend_logical.c |   4 +-
 src/storage/storage_driver.c  |   2 +-
 src/util/virstoragefile.c | 136 +---
 src/util/virstoragefile.h |  12 +++
 tests/virstoragetest.c|  18 ++--
 17 files changed, 445 insertions(+), 103 deletions(-)

-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 9/9] virstoragefile: Add node-name

2014-12-08 Thread Matthias Gatto
Add nodename inside virstoragefile
During xml backingStore parsing, look for a nodename attribute in the disk
declaration if this one is a quorum, if a nodename is found, add it to
the virStorageSource otherwise create a new one with a random name.
Take inspiration from this patch to create the nodename:
http://lists.gnu.org/archive/html/qemu-devel/2014-05/msg03209.html

Durring xml backingStore formating, look for a nodename attribute inside the
virStorageSource struct, and add it to the disk element.

Use the nodename to create the quorum in qemuBuildQuorumStr.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c| 25 +
 src/qemu/qemu_command.c   |  3 +++
 src/util/virstoragefile.c |  4 
 src/util/virstoragefile.h |  1 +
 4 files changed, 33 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9164cf3..a572516 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -53,6 +53,7 @@
 #include device_conf.h
 #include virtpm.h
 #include virstring.h
+#include virrandom.h
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -5495,6 +5496,8 @@ virDomainDiskThresholdParse(virStorageSourcePtr src,
 }
 
 
+#define GEN_NODE_NAME_PREFIXlibvirt
+#define GEN_NODE_NAME_MAX_LEN   (sizeof(GEN_NODE_NAME_PREFIX) + 8 + 8)
 static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
virStorageSourcePtr src,
@@ -5506,6 +5509,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 xmlNodePtr source = NULL;
 xmlNodePtr cur = NULL;
 char *type = NULL;
+char *nodeName = NULL;
 char *format = NULL;
 int ret = -1;
 size_t i = 0;
@@ -5539,6 +5543,23 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
+if (src-type == VIR_STORAGE_TYPE_QUORUM) {
+if ((nodeName = virXMLPropString(ctxt-node, nodename))) {
+backingStore-nodeName = nodeName;
+} else {
+int len;
+if (VIR_ALLOC_N(nodeName, GEN_NODE_NAME_MAX_LEN)  0)
+goto cleanup;
+snprintf(nodeName, GEN_NODE_NAME_MAX_LEN,
+ %s%08x, GEN_NODE_NAME_PREFIX, (int)pos);
+len = strlen(nodeName);
+while (len  GEN_NODE_NAME_MAX_LEN - 1)
+nodeName[len++] = virRandomInt('Z' - 'A') + 'A';
+nodeName[GEN_NODE_NAME_MAX_LEN - 1] = '\0';
+backingStore-nodeName = nodeName;
+}
+}
+
 if (!(format = virXPathString(string(./format/@type), ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, %s,
_(missing disk backing store format));
@@ -5590,6 +5611,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 ctxt-node = save_ctxt;
 return ret;
 }
+#undef GEN_NODE_NAME_PREFIX
+#undef GEN_NODE_NAME_MAX_LEN
 
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
@@ -16539,6 +16562,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
   type, idx);
 if (backingStore-threshold)
 virBufferAsprintf(buf,  threshold='%lu', 
backingStore-threshold);
+if (backingStore-nodeName)
+virBufferAsprintf(buf,  nodename='%s', backingStore-nodeName);
 virBufferAddLit(buf, \n);
 virBufferAdjustIndent(buf, 2);
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 03ff1b7..77c38c4 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3255,6 +3255,9 @@ qemuBuildQuorumStr(virConnectPtr conn,
   toAppend, i,
   
virStorageFileFormatTypeToString(backingStore-format));
 
+virBufferAsprintf(opt, ,%schildren.%lu.node-name=%s,
+  toAppend, i, backingStore-nodeName);
+
 if (qemuBuildQuorumFileSourceStr(conn, backingStore, opt, tmp) == 
false)
 goto error;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index ad87e80..cd0098c 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1974,6 +1974,9 @@ virStorageSourceCopy(const virStorageSource *src,
 !(ret-auth = virStorageAuthDefCopy(src-auth)))
 goto error;
 
+if (src-nodeName  VIR_STRDUP(ret-nodeName, src-nodeName)  0)
+goto error;
+
 for (i = 0; i  src-nBackingStores; ++i) {
 if (backingChain  virStorageSourceGetBackingStore(src, i)) {
 if (!virStorageSourceSetBackingStore(ret,
@@ -2119,6 +2122,7 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def)
 
 VIR_FREE(def-relPath);
 VIR_FREE(def-backingStoreRaw);
+VIR_FREE(def-nodeName);
 
 /* recursively free backing chain */
 for (i = 0; i  def-nBackingStores; ++i)
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 40d221c..b53dd70 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -274,6 +274,7 @@ struct _virStorageSource {
 virStorageSourcePtr

[libvirt] [PATCH 7/9] domain_conf: Read and Write quorum config

2014-12-08 Thread Matthias Gatto
Add the capabiltty to libvirt to parse and format the quorum syntax
as described here:
http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c | 165 +++--
 1 file changed, 120 insertions(+), 45 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1add21f..9164cf3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5469,20 +5469,58 @@ virDomainDiskSourceParse(xmlNodePtr node,
 }
 
 
+static bool
+virDomainDiskThresholdParse(virStorageSourcePtr src,
+xmlNodePtr node)
+{
+char *threshold = virXMLPropString(node, threshold);
+int ret;
+
+if (!threshold) {
+virReportError(VIR_ERR_XML_ERROR,
+   %s, _(missing threshold in quorum));
+return false;
+}
+ret = virStrToLong_ul(threshold, NULL, 10, src-threshold);
+if (ret  0 || src-threshold  2) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _(unexpected threshold %s),
+   threshold must be a decimal number superior to 2 
+ and inferior to the number of children);
+VIR_FREE(threshold);
+return false;
+}
+VIR_FREE(threshold);
+return true;
+}
+
+
 static int
 virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
-   virStorageSourcePtr src)
+   virStorageSourcePtr src,
+   xmlNodePtr node,
+   size_t pos)
 {
 virStorageSourcePtr backingStore = NULL;
 xmlNodePtr save_ctxt = ctxt-node;
-xmlNodePtr source;
+xmlNodePtr source = NULL;
+xmlNodePtr cur = NULL;
 char *type = NULL;
 char *format = NULL;
 int ret = -1;
+size_t i = 0;
 
-if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
-ret = 0;
-goto cleanup;
+if (src-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!node) {
+ret = 0;
+goto cleanup;
+}
+ctxt-node = node;
+} else {
+if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) {
+ret = 0;
+goto cleanup;
+}
 }
 
 if (VIR_ALLOC(backingStore)  0)
@@ -5514,6 +5552,22 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
+if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) {
+if (!virDomainDiskThresholdParse(backingStore, node))
+goto cleanup;
+
+for (cur = node-children, i = 0; cur != NULL; cur = cur-next) {
+if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
+if (virStorageSourcePushBackingStore(backingStore) == false)
+goto cleanup;
+if ((virDomainDiskBackingStoreParse(ctxt, backingStore, cur, 
i)  0))
+goto cleanup;
+++i;
+}
+}
+goto exit;
+}
+
 if (!(source = virXPathNode(./source, ctxt))) {
 virReportError(VIR_ERR_XML_ERROR, %s,
_(missing disk backing store source));
@@ -5521,10 +5575,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 }
 
 if (virDomainDiskSourceParse(source, ctxt, backingStore)  0 ||
-virDomainDiskBackingStoreParse(ctxt, backingStore)  0)
+virDomainDiskBackingStoreParse(ctxt, backingStore, NULL, 0)  0)
 goto cleanup;
 
-virStorageSourceSetBackingStore(src, backingStore, 0);
+ exit:
+virStorageSourceSetBackingStore(src, backingStore, pos);
 ret = 0;
 
  cleanup:
@@ -5536,7 +5591,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 return ret;
 }
 
-
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
 
@@ -6030,6 +6084,12 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 } else if (xmlStrEqual(cur-name, BAD_CAST boot)) {
 /* boot is parsed as part of virDomainDeviceInfoParseXML */
+} else if (xmlStrEqual(cur-name, BAD_CAST backingStore)) {
+if (virStorageSourcePushBackingStore(def-src) == false)
+goto error;
+if (virDomainDiskBackingStoreParse(ctxt, def-src, cur,
+   def-src-nBackingStores - 
1)  0)
+goto error;
 }
 }
 cur = cur-next;
@@ -6053,12 +6113,19 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 def-device = VIR_DOMAIN_DISK_DEVICE_DISK;
 }
 
+if (def-src-type == VIR_STORAGE_TYPE_QUORUM 
+!virDomainDiskThresholdParse(def-src, node))
+goto error;
+
+snapshot = virXMLPropString(node, snapshot);
+
 /* Only CDROM and Floppy devices are allowed missing source path
  * to indicate no media present. LUN is for raw access CD-ROMs

[libvirt] [PATCH 2/9] virstoragefile: Always use virStorageSourceGetBackingStore to get backing store

2014-12-08 Thread Matthias Gatto
Uniformize backing store usage by calling virStorageSourceGetBackingStore
instead of setting backing store manually.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c|  7 ---
 src/conf/storage_conf.c   |  4 ++--
 src/qemu/qemu_cgroup.c|  4 ++--
 src/qemu/qemu_domain.c|  2 +-
 src/qemu/qemu_driver.c| 12 ++--
 src/security/security_dac.c   |  2 +-
 src/security/security_selinux.c   |  4 ++--
 src/security/virt-aa-helper.c |  2 +-
 src/storage/storage_backend.c | 12 ++--
 src/storage/storage_backend_fs.c  |  8 
 src/storage/storage_backend_logical.c |  2 +-
 src/util/virstoragefile.c | 20 ++--
 tests/virstoragetest.c| 14 +++---
 13 files changed, 47 insertions(+), 46 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2d81c37..b790fc5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16473,7 +16473,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
 /* We currently don't output seclabels for backing chain element */
 if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true)  0 ||
 virDomainDiskBackingStoreFormat(buf,
-backingStore-backingStore,
+
virStorageSourceGetBackingStore(backingStore, 0),
 backingStore-backingStoreRaw,
 idx + 1)  0)
 return -1;
@@ -16595,7 +16595,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
 /* Don't format backingStore to inactive XMLs until the code for
  * persistent storage of backing chains is ready. */
 if (!(flags  VIR_DOMAIN_XML_INACTIVE) 
-virDomainDiskBackingStoreFormat(buf, def-src-backingStore,
+virDomainDiskBackingStoreFormat(buf,
+
virStorageSourceGetBackingStore(def-src, 0),
 def-src-backingStoreRaw, 1)  0)
 return -1;
 
@@ -20554,7 +20555,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
 }
 }
 
-for (tmp = disk-src; tmp; tmp = tmp-backingStore) {
+for (tmp = disk-src; tmp; tmp = virStorageSourceGetBackingStore(tmp, 0)) {
 int actualType = virStorageSourceGetActualType(tmp);
 /* execute the callback only for local storage */
 if (actualType != VIR_STORAGE_TYPE_NETWORK 
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 3987470..a8a90b4 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1642,9 +1642,9 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
  def-target, target)  0)
 goto cleanup;
 
-if (def-target.backingStore 
+if (virStorageSourceGetBackingStore((def-target), 0) 
 virStorageVolTargetDefFormat(options, buf,
- def-target.backingStore,
+ 
virStorageSourceGetBackingStore((def-target), 0),
  backingStore)  0)
 goto cleanup;
 
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 0e94cae..f878f4b 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -120,7 +120,7 @@ qemuSetupDiskCgroup(virDomainObjPtr vm,
 virStorageSourcePtr next;
 bool forceReadonly = false;
 
-for (next = disk-src; next; next = next-backingStore) {
+for (next = disk-src; next; next = virStorageSourceGetBackingStore(next, 
0)) {
 if (qemuSetImageCgroupInternal(vm, next, false, forceReadonly)  0)
 return -1;
 
@@ -138,7 +138,7 @@ qemuTeardownDiskCgroup(virDomainObjPtr vm,
 {
 virStorageSourcePtr next;
 
-for (next = disk-src; next; next = next-backingStore) {
+for (next = disk-src; next; next = virStorageSourceGetBackingStore(next, 
0)) {
 if (qemuSetImageCgroup(vm, next, true)  0)
 return -1;
 }
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 220304f..9157e4d 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2708,7 +2708,7 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
 if (virStorageSourceIsEmpty(disk-src))
 goto cleanup;
 
-if (disk-src-backingStore) {
+if (virStorageSourceGetBackingStore(disk-src, 0)) {
 if (force_probe)
 virStorageSourceBackingStoreClear(disk-src);
 else
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9152cf5..9ed5035 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13496,13 +13496,13 @@ 
qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
 
 /* Update vm in place to match changes. */
 tmp = disk-src;
-disk-src = tmp-backingStore;
+disk-src = virStorageSourceGetBackingStore

[libvirt] [PATCH 6/9] virstoragefile: Add quorum in virstoragefile

2014-12-08 Thread Matthias Gatto
Add VIR_STORAGE_TYPE_QUORUM in virStorageType.
Add VIR_STORAGE_FILE_QUORUM in virStorageFileFormat.

Add threshold value in _virStorageSource

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/conf/domain_conf.c|  2 ++
 src/qemu/qemu_command.c   |  1 +
 src/qemu/qemu_driver.c|  4 
 src/qemu/qemu_migration.c |  1 +
 src/util/virstoragefile.c | 25 +
 src/util/virstoragefile.h |  3 +++
 6 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 00e0470..1add21f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5445,6 +5445,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
 if (virDomainDiskSourcePoolDefParse(node, src-srcpool)  0)
 goto cleanup;
 break;
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -16412,6 +16413,7 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
  skipSeclabels);
 break;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1831323..525a49c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3086,6 +3086,7 @@ qemuGetDriveSourceString(virStorageSourcePtr src,
 goto cleanup;
 break;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_VOLUME:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8e3a492..1dc7558 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12977,6 +12977,7 @@ 
qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk)
 }
 break;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_DIR:
 case VIR_STORAGE_TYPE_VOLUME:
 case VIR_STORAGE_TYPE_NONE:
@@ -13040,6 +13041,7 @@ 
qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d
 }
 break;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_DIR:
 case VIR_STORAGE_TYPE_VOLUME:
 case VIR_STORAGE_TYPE_NONE:
@@ -13064,6 +13066,7 @@ 
qemuDomainSnapshotPrepareDiskExternalOverlayInactive(virDomainSnapshotDiskDefPtr
 case VIR_STORAGE_TYPE_FILE:
 return 0;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_NETWORK:
 case VIR_STORAGE_TYPE_DIR:
 case VIR_STORAGE_TYPE_VOLUME:
@@ -13183,6 +13186,7 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr 
conn,
 }
 break;
 
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_DIR:
 case VIR_STORAGE_TYPE_VOLUME:
 case VIR_STORAGE_TYPE_NONE:
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 0acbb57..5efd753 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1515,6 +1515,7 @@ qemuMigrationPrecreateDisk(virConnectPtr conn,
 case VIR_STORAGE_TYPE_BLOCK:
 case VIR_STORAGE_TYPE_DIR:
 case VIR_STORAGE_TYPE_NETWORK:
+case VIR_STORAGE_TYPE_QUORUM:
 case VIR_STORAGE_TYPE_NONE:
 case VIR_STORAGE_TYPE_LAST:
 virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 4217a80..ad87e80 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -57,7 +57,8 @@ VIR_ENUM_IMPL(virStorage, VIR_STORAGE_TYPE_LAST,
   block,
   dir,
   network,
-  volume)
+  volume,
+  quorum)
 
 VIR_ENUM_IMPL(virStorageFileFormat,
   VIR_STORAGE_FILE_LAST,
@@ -66,7 +67,7 @@ VIR_ENUM_IMPL(virStorageFileFormat,
   cloop, dmg, iso,
   vpc, vdi,
   /* Not direct file formats, but used for various drivers */
-  fat, vhd, ploop,
+  fat, vhd, ploop, quorum,
   /* Formats with backing file below here */
   cow, qcow, qcow2, qed, vmdk)
 
@@ -1911,6 +1912,7 @@ virStorageSourceCopy(const virStorageSource *src,
  bool backingChain)
 {
 virStorageSourcePtr ret = NULL;
+size_t i;
 
 if (VIR_ALLOC(ret)  0)
 return NULL;
@@ -1922,6 +1924,8 @@ virStorageSourceCopy(const virStorageSource *src,
 ret-capacity = src-capacity;
 ret-readonly = src-readonly;
 ret-shared = src-shared;
+ret-nBackingStores = src-nBackingStores;
+ret-threshold = src-threshold;
 
 /* storage driver metadata are not copied */
 ret-drv = NULL;
@@ -1970,12 +1974,14 @@ virStorageSourceCopy(const virStorageSource *src,
 !(ret-auth = virStorageAuthDefCopy(src-auth)))
 goto error;
 
-if (backingChain  virStorageSourceGetBackingStore(src, 0

Re: [libvirt] [PATCH v6 6/7] qemu: Add bps_max and friends to qemu command generation

2014-11-12 Thread Matthias Gatto
On Tue, Nov 11, 2014 at 1:20 PM, John Ferlan jfer...@redhat.com wrote:


 On 10/29/2014 08:16 AM, Matthias Gatto wrote:
 Check the arability of the options with the current qemu binary,
 add them in the varable opt if yes, print a message if not.

 Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
 ---
  src/qemu/qemu_command.c | 57 
 -
  1 file changed, 56 insertions(+), 1 deletion(-)


 Coverity was a bit unhappy about this change...


 diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
 index 2e5af4f..b3dc919 100644
 --- a/src/qemu/qemu_command.c
 +++ b/src/qemu/qemu_command.c
 @@ -3669,12 +3669,32 @@ qemuBuildDriveStr(virConnectPtr conn,
  goto error;
  }

 +/* block I/O throttling 1.7 */
 +if ((disk-blkdeviotune.total_bytes_sec_max ||
 + disk-blkdeviotune.read_bytes_sec_max ||
 + disk-blkdeviotune.write_bytes_sec_max ||
 + disk-blkdeviotune.total_iops_sec_max ||
 + disk-blkdeviotune.read_iops_sec_max ||
 + disk-blkdeviotune.write_iops_sec_max) 
 +!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_MAX)) {
 +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
 +   _(there is some block I/O throttling paramater that 
 are not supported with this 
 + QEMU binary(need QEMU 1.7 or superior)));
 +goto error;
 +}
 +
  if (disk-blkdeviotune.total_bytes_sec  LLONG_MAX ||
  disk-blkdeviotune.read_bytes_sec  LLONG_MAX ||
  disk-blkdeviotune.write_bytes_sec  LLONG_MAX ||
  disk-blkdeviotune.total_iops_sec  LLONG_MAX ||
  disk-blkdeviotune.read_iops_sec  LLONG_MAX ||
 -disk-blkdeviotune.write_iops_sec  LLONG_MAX) {
 +disk-blkdeviotune.write_iops_sec  LLONG_MAX ||
 +disk-blkdeviotune.total_bytes_sec_max  LLONG_MAX ||
 +disk-blkdeviotune.read_bytes_sec_max  LLONG_MAX ||
 +disk-blkdeviotune.write_bytes_sec_max  LLONG_MAX ||
 +disk-blkdeviotune.total_iops_sec_max  LLONG_MAX ||
 +disk-blkdeviotune.read_iops_sec_max  LLONG_MAX ||
 +disk-blkdeviotune.write_iops_sec_max  LLONG_MAX) {
  virReportError(VIR_ERR_OVERFLOW,
_(block I/O throttle limit must 
  be less than %llu using QEMU), LLONG_MAX);
 @@ -3711,6 +3731,41 @@ qemuBuildDriveStr(virConnectPtr conn,
disk-blkdeviotune.write_iops_sec);
  }

 +if (disk-blkdeviotune.total_bytes_sec_max) {
 +virBufferAsprintf(opt, ,bps_max=%llu,
 +  disk-blkdeviotune.total_bytes_sec_max);
 +}
 +
 +if (disk-blkdeviotune.read_bytes_sec_max) {
 +virBufferAsprintf(opt, ,bps_rd_max=%llu,
 +  disk-blkdeviotune.read_bytes_sec_max);
 +}
 +
 +if (disk-blkdeviotune.write_bytes_sec_max) {
 +virBufferAsprintf(opt, ,bps_wr_max=%llu,
 +  disk-blkdeviotune.write_bytes_sec_max);
 +}
 +
 +if (disk-blkdeviotune.total_iops_sec_max) {
 +virBufferAsprintf(opt, ,iops_max=%llu,
 +  disk-blkdeviotune.total_iops_sec_max);
 +}
 +
 +if (disk-blkdeviotune.read_iops_sec_max) {
 +virBufferAsprintf(opt, ,iops_rd_max=%llu,
 +  disk-blkdeviotune.read_iops_sec_max);
 +}
 +
 +if (disk-blkdeviotune.write_iops_sec_max) {
 +virBufferAsprintf(opt, ,iops_wr_max=%llu,
 +  disk-blkdeviotune.write_iops_sec_max);
 +}
 +
 +if (disk-blkdeviotune.write_iops_sec_max) {
 +virBufferAsprintf(opt, ,iops_size=%llu,
 +  disk-blkdeviotune.size_iops_sec);
 +}
 +

 3755if (disk-blkdeviotune.read_iops_sec_max) {
 3756virBufferAsprintf(opt, ,iops_rd_max=%llu,
 3757  disk-blkdeviotune.read_iops_sec_max);
 3758}
 3759

 (1) Event original: disk-blkdeviotune.write_iops_sec_max looks like 
 the original copy.
 Also see events:[copy_paste_error][remediation]

 3760if (disk-blkdeviotune.write_iops_sec_max) {
 3761virBufferAsprintf(opt, ,iops_wr_max=%llu,
 3762  disk-blkdeviotune.write_iops_sec_max);
 3763}
 3764

 (2) Event copy_paste_error: write_iops_sec_max in 
 disk-blkdeviotune.write_iops_sec_max looks like a copy-paste error.
 (3) Event remediation:  Should it say size_iops_sec instead?
 Also see events:[original]

 3765if (disk-blkdeviotune.write_iops_sec_max) {
 3766virBufferAsprintf(opt, ,iops_size=%llu,
 3767  disk-blkdeviotune.size_iops_sec);
 3768}


 I assume the (2) if should be if (disk-blkdeviotune.size_iops_sec) {, 
 correct?


 John
  if (virBufferCheckError(opt)  0)
  goto error;



Yes your right, I've made a mistake here.
I send the correction now.

--
libvir-list mailing list

[libvirt] [PATCH 1/2] qemu: Fix copy_paste_error in qemuBuildDriveStr.

2014-11-12 Thread Matthias Gatto
Fix for this: 
http://www.redhat.com/archives/libvir-list/2014-November/msg00324.html

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/qemu/qemu_command.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a5ed8ed..f674ba9 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3762,7 +3762,7 @@ qemuBuildDriveStr(virConnectPtr conn,
   disk-blkdeviotune.write_iops_sec_max);
 }
 
-if (disk-blkdeviotune.write_iops_sec_max) {
+if (disk-blkdeviotune.size_iops_sec) {
 virBufferAsprintf(opt, ,iops_size=%llu,
   disk-blkdeviotune.size_iops_sec);
 }
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/2] qemu: Fix DEATHCODE error in qemuDomainGetBlockIoTune.

2014-11-12 Thread Matthias Gatto
reported here: 
http://www.redhat.com/archives/libvir-list/2014-November/msg00327.html

I could have just remove bool supportMaxOptions variable, but
if I had do this, we could not check anymore if the nparams variable is
superior to QEMU_NB_BLOCK_IO_TUNE_PARAM_MAX.

Signed-off-by: Matthias Gatto matthias.ga...@outscale.com
---
 src/qemu/qemu_driver.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 56e8430..61c4af6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17024,6 +17024,7 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
 
 if (flags  VIR_DOMAIN_AFFECT_LIVE) {
 priv = vm-privateData;
+supportMaxOptions = virQEMUCapsGet(priv-qemuCaps, 
QEMU_CAPS_DRIVE_IOTUNE_MAX);
 qemuDomainObjEnterMonitor(driver, vm);
 ret = qemuMonitorGetBlockIoThrottle(priv-mon, device, reply, 
supportMaxOptions);
 qemuDomainObjExitMonitor(driver, vm);
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 0/2] qemu: Fix Coverity error on throttle.

2014-11-12 Thread Matthias Gatto
Fix the errors reported by John Ferlan about therse patchs:
http://www.redhat.com/archives/libvir-list/2014-November/msg00327.html
http://www.redhat.com/archives/libvir-list/2014-November/msg00324.html

Matthias Gatto (2):
  qemu: Fix copy_paste_error in qemuBuildDriveStr.
  qemu: Fix DEATHCODE error in qemuDomainGetBlockIoTune.

 src/qemu/qemu_command.c | 2 +-
 src/qemu/qemu_driver.c  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


  1   2   >