[PATCH 1/8] Added a few attach-disk parameters

Han Han hhan at redhat.com
Wed Nov 11 01:08:42 UTC 2020


It is better to format the patch summary like this format: "SUBSYSTEM:
TITLE"
For example, this patch could be "virsh: Added a few attach-disk parameters"
You can see the git log of libvirt for more reference:
https://libvirt.org/git/?p=libvirt.git;a=summary

On Wed, Nov 11, 2020 at 5:58 AM Ryan Gahagan <rgahagan at cs.utexas.edu> wrote:

> Signed-off-by: Ryan Gahagan <rgahagan at cs.utexas.edu>
> ---
>  tools/virsh-domain.c | 76 +++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 68 insertions(+), 8 deletions(-)
>
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index 12b35c037d..16227085cc 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -224,6 +224,26 @@ static const vshCmdOptDef opts_attach_disk[] = {
>       .flags = VSH_OFLAG_REQ | VSH_OFLAG_EMPTY_OK,
>       .help = N_("source of disk device")
>      },
> +    {.name = "source-protocol",
> +     .type = VSH_OT_STRING,
> +     .help = N_("protocol used by disk device source")
> +    }
> +    {.name = "source-name",
> +     .type = VSH_OT_STRING,
> +     .help = N_("name of disk device source")
> +    },
> +    {.name = "source-host-name",
> +     .type = VSH_OT_STRING,
> +     .help = N_("host name for source of disk device")
> +    },
> +    {.name = "source-host-transport",
> +     .type = VSH_OT_STRING,
> +     .help = N_("host transport for source of disk device")
> +    },
> +    {.name = "source-host-socket",
> +     .type = VSH_OT_STRING,
> +     .help = N_("host socket for source of disk device")
> +    },
>      {.name = "target",
>       .type = VSH_OT_DATA,
>       .flags = VSH_OFLAG_REQ,
> @@ -562,11 +582,13 @@ static bool
>  cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
>  {
>      virDomainPtr dom = NULL;
> -    const char *source = NULL, *target = NULL, *driver = NULL,
> -                *subdriver = NULL, *type = NULL, *mode = NULL,
> -                *iothread = NULL, *cache = NULL, *io = NULL,
> -                *serial = NULL, *straddr = NULL, *wwn = NULL,
> -                *targetbus = NULL, *alias = NULL;
> +    const char *source = NULL, *source_name = NULL, *source_protocol =
> NULL,
> +                *target = NULL, *driver = NULL, *subdriver = NULL, *type
> = NULL,
> +                *mode = NULL, *iothread = NULL, *cache = NULL,
> +                *io = NULL, *serial = NULL, *straddr = NULL,
> +                *wwn = NULL, *targetbus = NULL, *alias = NULL,
> +                *host_name = NULL, *host_transport = NULL,
> +                *host_port = NULL, *host_socket = NULL;
>      struct DiskAddress diskAddr;
>      bool isFile = false, functionReturn = false;
>      int ret;
> @@ -591,6 +613,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
>          flags |= VIR_DOMAIN_AFFECT_LIVE;
>
>      if (vshCommandOptStringReq(ctl, cmd, "source", &source) < 0 ||
> +        vshCommandOptStringReq(ctl, cmd, "source-name", &source_name) < 0
> ||
> +        vshCommandOptStringReq(ctl, cmd, "source-protocol",
> &source_protocol) < 0 ||
>          vshCommandOptStringReq(ctl, cmd, "target", &target) < 0 ||
>          vshCommandOptStringReq(ctl, cmd, "driver", &driver) < 0 ||
>          vshCommandOptStringReq(ctl, cmd, "subdriver", &subdriver) < 0 ||
> @@ -604,7 +628,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
>          vshCommandOptStringReq(ctl, cmd, "address", &straddr) < 0 ||
>          vshCommandOptStringReq(ctl, cmd, "targetbus", &targetbus) < 0 ||
>          vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 ||
> -        vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0)
> +        vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0 ||
> +        vshCommandOptStringReq(ctl, cmd, "source-host-name", &host_name)
> < 0 ||
> +        vshCommandOptStringReq(ctl, cmd, "source-host-transport",
> &host_transport) < 0 ||
> +        vshCommandOptStringReq(ctl, cmd, "source-host-socket",
> &host_socket) < 0)
>          goto cleanup;
>
>      if (!stype) {
> @@ -659,9 +686,42 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
>          virBufferAddLit(&buf, "/>\n");
>      }
>
> -    if (source)
> -        virBufferAsprintf(&buf, "<source %s='%s'/>\n",
> +    if (source || source_protocol || source_name ||
> +        host_name || host_transport || host_socket) {
> +        virBufferAsprintf(&buf, "<source");
> +
> +        if (source)
> +            virBufferAsprintf(&buf, " %s='%s'",
>                            isFile ? "file" : "dev", source);
> +        if (source_protocol)
> +            virBufferAsprintf(&buf, " protocol='%s'", source_protocol);
> +        if (source_name)
> +            virBufferAsprintf(&buf, " name='%s'", source_name);
> +
> +        if (host_name || host_transport || host_socket) {
> +            virBufferAsprintf(">\n<host");
> +
> +            if (host_name) {
> +                host_port = strchr(host_name, ':');
> +
> +                if (!host_port)
> +                    virBufferAsprintf(" name='%s'", host_name);
> +                else {
> +                    host_name[host_port - host_name] = '\0';
> +                    virBufferAsprintf(" name='%s' port='%s'", host_name,
> host_port + 1);
> +                }
> +            }
> +            if (host_transport)
> +                virBufferAsprintf(" transport='%s'", host_transport);
> +            if (host_socket)
> +                virBufferAsprintf(" socket='%s'", host_socket);
> +
> +            virBufferAsprintf(" />\n</source>\n");
> +        } else {
> +            virBufferAsprintf(" />\n");
> +        }
> +    }
> +
>      virBufferAsprintf(&buf, "<target dev='%s'", target);
>      if (targetbus)
>          virBufferAsprintf(&buf, " bus='%s'", targetbus);
> --
> 2.29.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20201111/ec8f2851/attachment-0001.htm>


More information about the libvir-list mailing list