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

Re: [libvirt] [PATCH 2/9] Introduce new XMLs to specify disk source using libvirt storage



On Thu, Jan 31, 2013 at 02:11:27AM +0800, Osier Yang wrote:
> With this patch, one can specify the disk source using libvirt
> storage like:
> 
>   <disk type='volume' device='disk'>
>     <driver name='qemu' type='raw' cache='none'/>
>     <source pool='default' volume='fc18.img'/>
>     <target dev='vdb' bus='virtio'/>
>   </disk>
> 
> "seclables" and "startupPolicy" are not supported for this new
> disk type ("volume"). They will be supported in later patches.
> @@ -12168,6 +12237,102 @@ static void virDomainDiskBlockIoDefFormat(virBufferPtr buf,
>      }
>  }
>  
> +static int
> +virDomainDiskSourceDefFormat(virBufferPtr buf,
> +                             virDomainDiskDefPtr def)
> +{
> +    int n;
> +    const char *startupPolicy = virDomainStartupPolicyTypeToString(def->startupPolicy);
> +
> +    if (def->src || def->nhosts > 0 || def->srcpool ||
> +        def->startupPolicy) {
> +        switch (def->type) {
> +        case VIR_DOMAIN_DISK_TYPE_FILE:
> +            if (def->src)
> +                virBufferEscapeString(buf, "      <source file='%s'", def->src);
> +            if (def->startupPolicy)
> +                virBufferEscapeString(buf, " startupPolicy='%s'",
> +                                      startupPolicy);
> +            if (def->nseclabels) {
> +                virBufferAddLit(buf, ">\n");
> +                virBufferAdjustIndent(buf, 8);
> +                for (n = 0; n < def->nseclabels; n++)
> +                    virSecurityDeviceLabelDefFormat(buf, def->seclabels[n]);
> +                virBufferAdjustIndent(buf, -8);
> +                virBufferAddLit(buf, "      </source>\n");
> +            } else {
> +                virBufferAddLit(buf, "/>\n");
> +            }
> +            break;
> +        case VIR_DOMAIN_DISK_TYPE_BLOCK:
> +            virBufferEscapeString(buf, "      <source dev='%s'",
> +                                  def->src);
> +            if (def->nseclabels) {
> +                virBufferAddLit(buf, ">\n");
> +                virBufferAdjustIndent(buf, 8);
> +                for (n = 0; n < def->nseclabels; n++)
> +                    virSecurityDeviceLabelDefFormat(buf, def->seclabels[n]);
> +                virBufferAdjustIndent(buf, -8);
> +                virBufferAddLit(buf, "      </source>\n");
> +            } else {
> +                virBufferAddLit(buf, "/>\n");
> +            }
> +            break;
> +        case VIR_DOMAIN_DISK_TYPE_DIR:
> +            virBufferEscapeString(buf, "      <source dir='%s'/>\n",
> +                                  def->src);
> +            break;
> +        case VIR_DOMAIN_DISK_TYPE_NETWORK:
> +            virBufferAsprintf(buf, "      <source protocol='%s'",
> +                              virDomainDiskProtocolTypeToString(def->protocol));
> +            if (def->src) {
> +                virBufferEscapeString(buf, " name='%s'", def->src);
> +            }
> +            if (def->nhosts == 0) {
> +                virBufferAddLit(buf, "/>\n");
> +            } else {
> +                int i;
> +
> +                virBufferAddLit(buf, ">\n");
> +                for (i = 0; i < def->nhosts; i++) {
> +                    virBufferAddLit(buf, "        <host");
> +                    if (def->hosts[i].name) {
> +                        virBufferEscapeString(buf, " name='%s'", def->hosts[i].name);
> +                    }
> +                    if (def->hosts[i].port) {
> +                        virBufferEscapeString(buf, " port='%s'",
> +                                              def->hosts[i].port);
> +                    }
> +                    if (def->hosts[i].transport) {
> +                        virBufferAsprintf(buf, " transport='%s'",
> +                                          virDomainDiskProtocolTransportTypeToString(def->hosts[i].transport));
> +                    }
> +                    if (def->hosts[i].socket) {
> +                        virBufferEscapeString(buf, " socket='%s'", def->hosts[i].socket);
> +                    }
> +                    virBufferAddLit(buf, "/>\n");
> +                }
> +                virBufferAddLit(buf, "      </source>\n");
> +            }
> +            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->pool)
> +                virBufferAsprintf(buf, "      <source pool='%s' volume='%s'/>\n",
> +                                  def->srcpool->pool, def->srcpool->volume);
> +            break;
> +        default:
> +            virReportError(VIR_ERR_INTERNAL_ERROR,
> +                           _("unexpected disk type %s"),
> +                           virDomainDiskTypeToString(def->type));
> +            return -1;
> +        }
> +    }
> +
> +    return 0;
> +}

You've got a big refactoring here, mixed in with new features. it is
really desirable to separate the refactoring into a patch on its own

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


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