qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH v2 3/3] sheepdog: add support for connecting to unix


From: MORITA Kazutaka
Subject: [Qemu-devel] [PATCH v2 3/3] sheepdog: add support for connecting to unix domain socket
Date: Mon, 21 Jan 2013 09:23:30 +0900

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.

Signed-off-by: MORITA Kazutaka <address@hidden>
---
 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:
address@hidden
+sheepdog:[<hostname>:<port>:]<vdiname>[:<snapid or tag>]
address@hidden example
 
-``sheepdog:<host>:<port>:<vdiname>:<tag>''
+using Unix Domain Socket:
address@hidden
+sheepdog:unix:<domain-socket>:<vdiname>[:<snapid or tag>]
address@hidden example
+Note that <domain-socket> must be an absolute path.
 @end table
 
 Example
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]