qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 3/3] sheepdog: add support for connecting to unix domain socket
Date: Mon, 21 Jan 2013 09:57:36 +0100	[thread overview]
Message-ID: <50FD0300.8030006@redhat.com> (raw)
In-Reply-To: <1358727810-24055-4-git-send-email-morita.kazutaka@lab.ntt.co.jp>

Il 21/01/2013 01:23, MORITA Kazutaka ha scritto:
> This patch adds support for a unix domain socket for a connection
> between qemu and local sheepdog server.  You can use the unix domain
> socket with the following syntax like NBD driver:
> 
>  $ qemu sheepdog:unix:<socket path>:<image name>
> 
> Note that <socket path> must be an absolute path.

Please look at how NBD supports URIs.  Something like

  sheepdog[+tcp|+unix]://[host:port]/vdiname[/snapid|/tag][?socket=path]

or

  sheepdog[+tcp|+unix]://[host:port]/vdiname[?socket=path][#snapid|#tag]

would be similar to what we use for NBD and Gluster.

Paolo

> 
> Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
> ---
>  block/sheepdog.c |   37 +++++++++++++++++++++----------------
>  qemu-options.hx  |   19 +++++++++----------
>  2 files changed, 30 insertions(+), 26 deletions(-)
> 
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index c287827..34685fd 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -296,7 +296,9 @@ typedef struct BDRVSheepdogState {
>      bool is_snapshot;
>      uint32_t cache_flags;
>  
> -    /* It's a string of the form <hostname>:<port> */
> +    /* If it begins with  'unix:/', this is a UNIX domain socket. Otherwise,
> +     * it's a string of the form <hostname>:<port>
> +     */
>      char *host_spec;
>  
>      int fd;
> @@ -449,13 +451,25 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov,
>  static int connect_to_sdog(const char *host_spec)
>  {
>      int fd;
> +    const char *path;
>      Error *err = NULL;
>  
>      if (host_spec == NULL) {
>          host_spec = SD_DEFAULT_ADDR_AND_PORT;
>      }
>  
> -    fd = inet_connect(host_spec, &err);
> +    if (strstart(host_spec, "unix:", &path) && path[0] == '/') {
> +        fd = unix_connect(path, &err);
> +    } else {
> +        fd = inet_connect(host_spec, &err);
> +
> +        if (err == NULL) {
> +            int ret = socket_set_nodelay(fd);
> +            if (ret < 0) {
> +                error_report("%s", strerror(errno));
> +            }
> +        }
> +    }
>  
>      if (err != NULL) {
>          qerror_report_err(err);
> @@ -761,7 +775,7 @@ static int aio_flush_request(void *opaque)
>   */
>  static int get_sheep_fd(BDRVSheepdogState *s)
>  {
> -    int ret, fd;
> +    int fd;
>  
>      fd = connect_to_sdog(s->host_spec);
>      if (fd < 0) {
> @@ -770,13 +784,6 @@ static int get_sheep_fd(BDRVSheepdogState *s)
>  
>      socket_set_nonblock(fd);
>  
> -    ret = socket_set_nodelay(fd);
> -    if (ret) {
> -        error_report("%s", strerror(errno));
> -        closesocket(fd);
> -        return -errno;
> -    }
> -
>      qemu_aio_set_fd_handler(fd, co_read_response, NULL, aio_flush_request, s);
>      return fd;
>  }
> @@ -785,12 +792,10 @@ static int get_sheep_fd(BDRVSheepdogState *s)
>   * Parse a filename
>   *
>   * filename must be one of the following formats:
> - *   1. [vdiname]
> - *   2. [vdiname]:[snapid]
> - *   3. [vdiname]:[tag]
> - *   4. [hostname]:[port]:[vdiname]
> - *   5. [hostname]:[port]:[vdiname]:[snapid]
> - *   6. [hostname]:[port]:[vdiname]:[tag]
> + *   - using TCP
> + *     [<hostname>:<port>:]<vdiname>[:<snapid or tag>]
> + *   - using Unix Domain Socket
> + *     unix:<domain-socket>:<vdiname>[:<snapid or tag>]
>   *
>   * You can boot from the snapshot images by specifying `snapid` or
>   * `tag'.
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 40cd683..0583b4a 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -2061,17 +2061,16 @@ devices.
>  
>  Syntax for specifying a sheepdog device
>  @table @list
> -``sheepdog:<vdiname>''
> -
> -``sheepdog:<vdiname>:<snapid>''
> -
> -``sheepdog:<vdiname>:<tag>''
> -
> -``sheepdog:<host>:<port>:<vdiname>''
> -
> -``sheepdog:<host>:<port>:<vdiname>:<snapid>''
> +using TCP:
> +@example
> +sheepdog:[<hostname>:<port>:]<vdiname>[:<snapid or tag>]
> +@end example
>  
> -``sheepdog:<host>:<port>:<vdiname>:<tag>''
> +using Unix Domain Socket:
> +@example
> +sheepdog:unix:<domain-socket>:<vdiname>[:<snapid or tag>]
> +@end example
> +Note that <domain-socket> must be an absolute path.
>  @end table
>  
>  Example
> 

      reply	other threads:[~2013-01-21  8:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-21  0:23 [Qemu-devel] [PATCH v2 0/3] sheepdog: unix domain socket support MORITA Kazutaka
2013-01-21  0:23 ` [Qemu-devel] [PATCH v2 1/3] move socket_set_nodelay to osdep.c MORITA Kazutaka
2013-01-21  0:23 ` [Qemu-devel] [PATCH v2 2/3] sheepdog: use inet_connect to simplify connect code MORITA Kazutaka
2013-01-21  0:23 ` [Qemu-devel] [PATCH v2 3/3] sheepdog: add support for connecting to unix domain socket MORITA Kazutaka
2013-01-21  8:57   ` Paolo Bonzini [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50FD0300.8030006@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=morita.kazutaka@lab.ntt.co.jp \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).