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.kazut...@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 via email to