Re: [PATCH 7/9] conf: Fix bugs on disk source formating

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/30/2013 01:11 PM, Osier Yang wrote:
> One simple demo:
> 
>   * Edit the disk conf like:
>     <source startupPolicy='optional'/>
> 
> The output will be like:
> 
> startupPolicy='optional'/>
> ---
>  src/conf/domain_conf.c |   36 +++++++++++++++++++++---------------
>  1 files changed, 21 insertions(+), 15 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 9f61c57..7b08b69 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -12249,11 +12249,14 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
>          def->startupPolicy) {
>          switch (def->type) {
>          case VIR_DOMAIN_DISK_TYPE_FILE:
> +            if (def->src || def->startupPolicy || def->nseclabels)
> +                virBufferAddLit(buf, "      <source");
> +
>              if (def->src)
> -                virBufferEscapeString(buf, "      <source file='%s'", def->src);
> +                virBufferEscapeString(buf, " file='%s'", def->src);
>              if (def->startupPolicy)
> -                virBufferEscapeString(buf, " startupPolicy='%s'",
> -                                      startupPolicy);
> +                virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
> +
>              if (def->nseclabels) {
>                  virBufferAddLit(buf, ">\n");
>                  virBufferAdjustIndent(buf, 8);
> @@ -12261,13 +12264,16 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
>                      virSecurityDeviceLabelDefFormat(buf, def->seclabels[n]);
>                  virBufferAdjustIndent(buf, -8);
>                  virBufferAddLit(buf, "      </source>\n");
> -            } else {
> +            } else if (def->src || def->startupPolicy) {
>                  virBufferAddLit(buf, "/>\n");
>              }
>              break;
>          case VIR_DOMAIN_DISK_TYPE_BLOCK:
> -            virBufferEscapeString(buf, "      <source dev='%s'",
> -                                  def->src);
> +            if (def->src || def->nseclabels)
> +                virBufferAddLit(buf, "      <source");
> +
> +            virBufferEscapeString(buf, " dev='%s'", def->src);
> +
>              if (def->nseclabels) {
>                  virBufferAddLit(buf, ">\n");
>                  virBufferAdjustIndent(buf, 8);
> @@ -12275,13 +12281,12 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
>                      virSecurityDeviceLabelDefFormat(buf, def->seclabels[n]);
>                  virBufferAdjustIndent(buf, -8);
>                  virBufferAddLit(buf, "      </source>\n");
> -            } else {
> +            } else if (def->src) {
>                  virBufferAddLit(buf, "/>\n");
>              }
>              break;
>          case VIR_DOMAIN_DISK_TYPE_DIR:
> -            virBufferEscapeString(buf, "      <source dir='%s'/>\n",
> -                                  def->src);
> +            virBufferEscapeString(buf, "      <source dir='%s'/>\n", def->src);
>              break;
>          case VIR_DOMAIN_DISK_TYPE_NETWORK:
>              virBufferAsprintf(buf, "      <source protocol='%s'",
> @@ -12317,15 +12322,16 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
>              }
>              break;
>          case VIR_DOMAIN_DISK_TYPE_VOLUME:
> -            /* Parsing guarantees the def->srcpool->volume cannot be NULL
> -             * if def->srcpool->pool is not NULL.
> -             */
> +            if (def->srcpool || def->startupPolicy)
> +                virBufferAddLit(buf, "      <source");
> +
>              if (def->srcpool)
> -                virBufferAsprintf(buf, "      <source pool='%s' volume='%s'",
> +                virBufferAsprintf(buf, " pool='%s' volume='%s'",
>                                    def->srcpool->pool, def->srcpool->volume);
>              if (def->startupPolicy)
> -                virBufferEscapeString(buf, " startupPolicy='%s'/>\n", startupPolicy);
> -            else
> +                virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
> +
> +            if (def->srcpool || def->startupPolicy)
>                  virBufferAddLit(buf, "/>\n");
>              break;
>          default:
> 

ACK

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]