[libvirt] [PATCHv1.5 09/27] qemu: Split out NBD command generation

Michal Privoznik mprivozn at redhat.com
Wed Nov 27 11:15:56 UTC 2013


On 26.11.2013 17:48, Peter Krempa wrote:
> ---
>  src/qemu/qemu_command.c | 117 +++++++++++++++++++++++++-----------------------
>  1 file changed, 61 insertions(+), 56 deletions(-)
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 6ba8df9..15a6e9b 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -3680,7 +3680,7 @@ qemuNetworkDriveGetPort(int protocol,
>      return -1;
>  }
> 
> -
> +#define QEMU_DEFAULT_NBD_PORT "10809"
> 
>  char *
>  qemuBuildNetworkDriveURI(int protocol,
> @@ -3691,9 +3691,67 @@ qemuBuildNetworkDriveURI(int protocol,
>                           const char *secret)
>  {
>      char *ret = NULL;
> +    virBuffer buf = VIR_BUFFER_INITIALIZER;
>      virURIPtr uri = NULL;
> 
>      switch ((enum virDomainDiskProtocol) protocol) {
> +        case VIR_DOMAIN_DISK_PROTOCOL_NBD:
> +            if (nhosts != 1) {
> +                virReportError(VIR_ERR_INTERNAL_ERROR,
> +                               _("protocol '%s' accepts only one host"),
> +                               virDomainDiskProtocolTypeToString(protocol));
> +                goto cleanup;
> +            }
> +
> +            if (!((hosts->name && strchr(hosts->name, ':')) ||
> +                  (hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP &&
> +                   !hosts->name) ||
> +                  (hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX &&
> +                   hosts->socket &&
> +                   hosts->socket[0] != '/'))) {
> +
> +                virBufferAddLit(&buf, "nbd:");
> +
> +                switch (hosts->transport) {
> +                case VIR_DOMAIN_DISK_PROTO_TRANS_TCP:
> +                    virBufferStrcat(&buf, hosts->name, NULL);
> +                    virBufferAsprintf(&buf, ":%s",
> +                                      hosts->port ? hosts->port :
> +                                      QEMU_DEFAULT_NBD_PORT);
> +                    break;
> +
> +                case VIR_DOMAIN_DISK_PROTO_TRANS_UNIX:
> +                    if (!hosts->socket) {
> +                        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                                       _("socket attribute required for "
> +                                         "nix transport"));

s/nix/unix/

> +                        goto cleanup;
> +                    }
> +
> +                    virBufferAsprintf(&buf, "unix:%s", hosts->socket);
> +                    break;
> +
> +                default:
> +                    virReportError(VIR_ERR_INTERNAL_ERROR,
> +                                   _("nbd does not support transport '%s'"),
> +                                   virDomainDiskProtocolTransportTypeToString(hosts->transport));
> +                    goto cleanup;
> +                }
> +
> +                if (src)
> +                    virBufferAsprintf(&buf, ":exportname=%s", src);
> +
> +                if (virBufferError(&buf) < 0) {
> +                    virReportOOMError();
> +                    goto cleanup;
> +                }
> +
> +                ret = virBufferContentAndReset(&buf);
> +                goto cleanup;
> +            }
> +            /* fallthrough */
> +            /* NBD code uses same formatting scheme as others in some cases */
> +
>          case VIR_DOMAIN_DISK_PROTOCOL_HTTP:
>          case VIR_DOMAIN_DISK_PROTOCOL_HTTPS:
>          case VIR_DOMAIN_DISK_PROTOCOL_FTP:


ACK

Michal




More information about the libvir-list mailing list