qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/3] sheepdog: unix domain socket support
@ 2013-01-21  0:23 MORITA Kazutaka
  2013-01-21  0:23 ` [Qemu-devel] [PATCH v2 1/3] move socket_set_nodelay to osdep.c MORITA Kazutaka
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: MORITA Kazutaka @ 2013-01-21  0:23 UTC (permalink / raw)
  To: qemu-devel, stefanha; +Cc: kwolf

This series adds support for a unix domain socket for a connection
between qemu and local sheepdog server.  The first two patches are
cleanups for the third patch.

Changes from v1:
 - split patch for easy review
 - move set_nodelay to lib/osdep.c
 - remove redundant error checks
 - add a bit more explanation to qemu-options.hx

MORITA Kazutaka (3):
  move socket_set_nodelay to osdep.c
  sheepdog: use inet_connect to simplify connect code
  sheepdog: add support for connecting to unix domain socket

 block/sheepdog.c       |  150 +++++++++++++++++-------------------------------
 gdbstub.c              |    5 +-
 include/qemu/sockets.h |    1 +
 qemu-char.c            |    6 --
 qemu-options.hx        |   19 +++---
 slirp/tcp_subr.c       |    3 +-
 util/osdep.c           |    6 ++
 7 files changed, 71 insertions(+), 119 deletions(-)

-- 
1.7.2.5

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH v2 1/3] move socket_set_nodelay to osdep.c
  2013-01-21  0:23 [Qemu-devel] [PATCH v2 0/3] sheepdog: unix domain socket support MORITA Kazutaka
@ 2013-01-21  0:23 ` 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
  2 siblings, 0 replies; 5+ messages in thread
From: MORITA Kazutaka @ 2013-01-21  0:23 UTC (permalink / raw)
  To: qemu-devel, stefanha; +Cc: kwolf

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
---
 block/sheepdog.c       |   11 +----------
 gdbstub.c              |    5 ++---
 include/qemu/sockets.h |    1 +
 qemu-char.c            |    6 ------
 slirp/tcp_subr.c       |    3 +--
 util/osdep.c           |    6 ++++++
 6 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 3e49bb8..9746037 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -787,15 +787,6 @@ static int aio_flush_request(void *opaque)
         !QLIST_EMPTY(&s->pending_aio_head);
 }
 
-static int set_nodelay(int fd)
-{
-    int ret, opt;
-
-    opt = 1;
-    ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&opt, sizeof(opt));
-    return ret;
-}
-
 /*
  * Return a socket discriptor to read/write objects.
  *
@@ -814,7 +805,7 @@ static int get_sheep_fd(BDRVSheepdogState *s)
 
     socket_set_nonblock(fd);
 
-    ret = set_nodelay(fd);
+    ret = socket_set_nodelay(fd);
     if (ret) {
         error_report("%s", strerror(errno));
         closesocket(fd);
diff --git a/gdbstub.c b/gdbstub.c
index 6cd26f1..4cc1812 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2837,7 +2837,7 @@ static void gdb_accept(void)
     GDBState *s;
     struct sockaddr_in sockaddr;
     socklen_t len;
-    int val, fd;
+    int fd;
 
     for(;;) {
         len = sizeof(sockaddr);
@@ -2854,8 +2854,7 @@ static void gdb_accept(void)
     }
 
     /* set short latency */
-    val = 1;
-    setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
+    socket_set_nodelay(fd);
 
     s = g_malloc0(sizeof(GDBState));
     s->c_cpu = first_cpu;
diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index 803ae17..6125bf7 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -34,6 +34,7 @@ int inet_aton(const char *cp, struct in_addr *ia);
 int qemu_socket(int domain, int type, int protocol);
 int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
 int socket_set_cork(int fd, int v);
+int socket_set_nodelay(int fd);
 void socket_set_block(int fd);
 void socket_set_nonblock(int fd);
 int send_all(int fd, const void *buf, int len1);
diff --git a/qemu-char.c b/qemu-char.c
index 9ba0573..156164c 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2365,12 +2365,6 @@ static void tcp_chr_telnet_init(int fd)
     send(fd, (char *)buf, 3, 0);
 }
 
-static void socket_set_nodelay(int fd)
-{
-    int val = 1;
-    setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
-}
-
 static int tcp_chr_add_client(CharDriverState *chr, int fd)
 {
     TCPCharDriver *s = chr->opaque;
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 1542e43..abc6662 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -429,8 +429,7 @@ tcp_connect(struct socket *inso)
 	setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
 	opt = 1;
 	setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
-	opt = 1;
-	setsockopt(s,IPPROTO_TCP,TCP_NODELAY,(char *)&opt,sizeof(int));
+    socket_set_nodelay(s);
 
 	so->so_fport = addr.sin_port;
 	so->so_faddr = addr.sin_addr;
diff --git a/util/osdep.c b/util/osdep.c
index 5b51a03..c408261 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -63,6 +63,12 @@ int socket_set_cork(int fd, int v)
 #endif
 }
 
+int socket_set_nodelay(int fd)
+{
+    int v = 1;
+    return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v));
+}
+
 int qemu_madvise(void *addr, size_t len, int advice)
 {
     if (advice == QEMU_MADV_INVALID) {
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH v2 2/3] sheepdog: use inet_connect to simplify connect code
  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 ` MORITA Kazutaka
  2013-01-21  0:23 ` [Qemu-devel] [PATCH v2 3/3] sheepdog: add support for connecting to unix domain socket MORITA Kazutaka
  2 siblings, 0 replies; 5+ messages in thread
From: MORITA Kazutaka @ 2013-01-21  0:23 UTC (permalink / raw)
  To: qemu-devel, stefanha; +Cc: kwolf

This uses the form "<host>:<port>" for the representation of the
sheepdog server to use inet_connect.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
---
 block/sheepdog.c |  112 +++++++++++++++++-------------------------------------
 1 files changed, 35 insertions(+), 77 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 9746037..c287827 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -20,8 +20,7 @@
 
 #define SD_PROTO_VER 0x01
 
-#define SD_DEFAULT_ADDR "localhost"
-#define SD_DEFAULT_PORT "7000"
+#define SD_DEFAULT_ADDR_AND_PORT "localhost:7000"
 
 #define SD_OP_CREATE_AND_WRITE_OBJ  0x01
 #define SD_OP_READ_OBJ       0x02
@@ -297,8 +296,9 @@ typedef struct BDRVSheepdogState {
     bool is_snapshot;
     uint32_t cache_flags;
 
-    char *addr;
-    char *port;
+    /* It's a string of the form <hostname>:<port> */
+    char *host_spec;
+
     int fd;
 
     CoMutex lock;
@@ -446,56 +446,22 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov,
     return acb;
 }
 
-static int connect_to_sdog(const char *addr, const char *port)
+static int connect_to_sdog(const char *host_spec)
 {
-    char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
-    int fd, ret;
-    struct addrinfo hints, *res, *res0;
+    int fd;
+    Error *err = NULL;
 
-    if (!addr) {
-        addr = SD_DEFAULT_ADDR;
-        port = SD_DEFAULT_PORT;
+    if (host_spec == NULL) {
+        host_spec = SD_DEFAULT_ADDR_AND_PORT;
     }
 
-    memset(&hints, 0, sizeof(hints));
-    hints.ai_socktype = SOCK_STREAM;
+    fd = inet_connect(host_spec, &err);
 
-    ret = getaddrinfo(addr, port, &hints, &res0);
-    if (ret) {
-        error_report("unable to get address info %s, %s",
-                     addr, strerror(errno));
-        return -errno;
+    if (err != NULL) {
+        qerror_report_err(err);
+        error_free(err);
     }
 
-    for (res = res0; res; res = res->ai_next) {
-        ret = getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
-                          sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
-        if (ret) {
-            continue;
-        }
-
-        fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
-        if (fd < 0) {
-            continue;
-        }
-
-    reconnect:
-        ret = connect(fd, res->ai_addr, res->ai_addrlen);
-        if (ret < 0) {
-            if (errno == EINTR) {
-                goto reconnect;
-            }
-            close(fd);
-            break;
-        }
-
-        dprintf("connected to %s:%s\n", addr, port);
-        goto success;
-    }
-    fd = -errno;
-    error_report("failed connect to %s:%s", addr, port);
-success:
-    freeaddrinfo(res0);
     return fd;
 }
 
@@ -797,9 +763,8 @@ static int get_sheep_fd(BDRVSheepdogState *s)
 {
     int ret, fd;
 
-    fd = connect_to_sdog(s->addr, s->port);
+    fd = connect_to_sdog(s->host_spec);
     if (fd < 0) {
-        error_report("%s", strerror(errno));
         return fd;
     }
 
@@ -851,18 +816,15 @@ static int parse_vdiname(BDRVSheepdogState *s, const char *filename,
     }
     p = q;
 
-    /* use the first two tokens as hostname and port number. */
+    /* use the first two tokens as host_spec. */
     if (nr_sep >= 2) {
-        s->addr = p;
+        s->host_spec = p;
         p = strchr(p, ':');
-        *p++ = '\0';
-
-        s->port = p;
+        p++;
         p = strchr(p, ':');
         *p++ = '\0';
     } else {
-        s->addr = NULL;
-        s->port = 0;
+        s->host_spec = NULL;
     }
 
     pstrcpy(vdi, SD_MAX_VDI_LEN, p);
@@ -878,7 +840,7 @@ static int parse_vdiname(BDRVSheepdogState *s, const char *filename,
         *snapid = CURRENT_VDI_ID; /* search current vdi */
     }
 
-    if (s->addr == NULL) {
+    if (s->host_spec == NULL) {
         g_free(q);
     }
 
@@ -894,7 +856,7 @@ static int find_vdi_name(BDRVSheepdogState *s, char *filename, uint32_t snapid,
     unsigned int wlen, rlen = 0;
     char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];
 
-    fd = connect_to_sdog(s->addr, s->port);
+    fd = connect_to_sdog(s->host_spec);
     if (fd < 0) {
         return fd;
     }
@@ -1134,9 +1096,8 @@ static int sd_open(BlockDriverState *bs, const char *filename, int flags)
         s->is_snapshot = true;
     }
 
-    fd = connect_to_sdog(s->addr, s->port);
+    fd = connect_to_sdog(s->host_spec);
     if (fd < 0) {
-        error_report("failed to connect");
         ret = fd;
         goto out;
     }
@@ -1171,7 +1132,7 @@ out:
 
 static int do_sd_create(char *filename, int64_t vdi_size,
                         uint32_t base_vid, uint32_t *vdi_id, int snapshot,
-                        const char *addr, const char *port)
+                        const char *host_spec)
 {
     SheepdogVdiReq hdr;
     SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;
@@ -1179,7 +1140,7 @@ static int do_sd_create(char *filename, int64_t vdi_size,
     unsigned int wlen, rlen = 0;
     char buf[SD_MAX_VDI_LEN];
 
-    fd = connect_to_sdog(addr, port);
+    fd = connect_to_sdog(host_spec);
     if (fd < 0) {
         return fd;
     }
@@ -1346,7 +1307,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options)
         bdrv_delete(bs);
     }
 
-    ret = do_sd_create(vdi, vdi_size, base_vid, &vid, 0, s->addr, s->port);
+    ret = do_sd_create(vdi, vdi_size, base_vid, &vid, 0, s->host_spec);
     if (!prealloc || ret) {
         goto out;
     }
@@ -1367,7 +1328,7 @@ static void sd_close(BlockDriverState *bs)
 
     dprintf("%s\n", s->name);
 
-    fd = connect_to_sdog(s->addr, s->port);
+    fd = connect_to_sdog(s->host_spec);
     if (fd < 0) {
         return;
     }
@@ -1390,7 +1351,7 @@ static void sd_close(BlockDriverState *bs)
 
     qemu_aio_set_fd_handler(s->fd, NULL, NULL, NULL, NULL);
     closesocket(s->fd);
-    g_free(s->addr);
+    g_free(s->host_spec);
 }
 
 static int64_t sd_getlength(BlockDriverState *bs)
@@ -1414,7 +1375,7 @@ static int sd_truncate(BlockDriverState *bs, int64_t offset)
         return -EINVAL;
     }
 
-    fd = connect_to_sdog(s->addr, s->port);
+    fd = connect_to_sdog(s->host_spec);
     if (fd < 0) {
         return fd;
     }
@@ -1491,16 +1452,15 @@ static int sd_create_branch(BDRVSheepdogState *s)
     buf = g_malloc(SD_INODE_SIZE);
 
     ret = do_sd_create(s->name, s->inode.vdi_size, s->inode.vdi_id, &vid, 1,
-                       s->addr, s->port);
+                       s->host_spec);
     if (ret) {
         goto out;
     }
 
     dprintf("%" PRIx32 " is created.\n", vid);
 
-    fd = connect_to_sdog(s->addr, s->port);
+    fd = connect_to_sdog(s->host_spec);
     if (fd < 0) {
-        error_report("failed to connect");
         ret = fd;
         goto out;
     }
@@ -1759,7 +1719,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
     datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);
 
     /* refresh inode. */
-    fd = connect_to_sdog(s->addr, s->port);
+    fd = connect_to_sdog(s->host_spec);
     if (fd < 0) {
         ret = fd;
         goto cleanup;
@@ -1773,7 +1733,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
     }
 
     ret = do_sd_create(s->name, s->inode.vdi_size, s->inode.vdi_id, &new_vid, 1,
-                       s->addr, s->port);
+                       s->host_spec);
     if (ret < 0) {
         error_report("failed to create inode for snapshot. %s",
                      strerror(errno));
@@ -1828,9 +1788,8 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
         goto out;
     }
 
-    fd = connect_to_sdog(s->addr, s->port);
+    fd = connect_to_sdog(s->host_spec);
     if (fd < 0) {
-        error_report("failed to connect");
         ret = fd;
         goto out;
     }
@@ -1892,7 +1851,7 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
 
     vdi_inuse = g_malloc(max);
 
-    fd = connect_to_sdog(s->addr, s->port);
+    fd = connect_to_sdog(s->host_spec);
     if (fd < 0) {
         ret = fd;
         goto out;
@@ -1919,9 +1878,8 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
     hval = fnv_64a_buf(s->name, strlen(s->name), FNV1A_64_INIT);
     start_nr = hval & (SD_NR_VDIS - 1);
 
-    fd = connect_to_sdog(s->addr, s->port);
+    fd = connect_to_sdog(s->host_spec);
     if (fd < 0) {
-        error_report("failed to connect");
         ret = fd;
         goto out;
     }
@@ -1978,7 +1936,7 @@ static int do_load_save_vmstate(BDRVSheepdogState *s, uint8_t *data,
     uint32_t vdi_index;
     uint64_t offset;
 
-    fd = connect_to_sdog(s->addr, s->port);
+    fd = connect_to_sdog(s->host_spec);
     if (fd < 0) {
         return fd;
     }
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH v2 3/3] sheepdog: add support for connecting to unix domain socket
  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 ` MORITA Kazutaka
  2013-01-21  8:57   ` Paolo Bonzini
  2 siblings, 1 reply; 5+ messages in thread
From: MORITA Kazutaka @ 2013-01-21  0:23 UTC (permalink / raw)
  To: qemu-devel, stefanha; +Cc: kwolf

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 <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
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v2 3/3] sheepdog: add support for connecting to unix domain socket
  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
  0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2013-01-21  8:57 UTC (permalink / raw)
  To: MORITA Kazutaka; +Cc: kwolf, qemu-devel, stefanha

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
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-01-21  8:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).