diff mbox

[v2,3/5] block/ssh: Use inet_connect_saddr() to establish socket connection

Message ID 1476522280-23211-4-git-send-email-ashijeetacharya@gmail.com
State New
Headers show

Commit Message

Ashijeet Acharya Oct. 15, 2016, 9:04 a.m. UTC
Make inet_connect_saddr() in util/qemu-socktets.c public and use it
instead of inet_connect() because this directly takes the
InetSocketAddress to establish a socket connection for the SSH
block driver.

Signed-off-by: Ashijeet Acharya <ashijeetacharya@gmail.com>
---
 block/ssh.c            | 5 +----
 include/qemu/sockets.h | 2 ++
 util/qemu-sockets.c    | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

Comments

Max Reitz Oct. 15, 2016, 10:34 p.m. UTC | #1
On 15.10.2016 11:04, Ashijeet Acharya wrote:
> Make inet_connect_saddr() in util/qemu-socktets.c public and use it

*util/qemu-sockets.c

> instead of inet_connect() because this directly takes the
> InetSocketAddress to establish a socket connection for the SSH
> block driver.
> 
> Signed-off-by: Ashijeet Acharya <ashijeetacharya@gmail.com>
> ---
>  block/ssh.c            | 5 +----
>  include/qemu/sockets.h | 2 ++
>  util/qemu-sockets.c    | 2 +-
>  3 files changed, 4 insertions(+), 5 deletions(-)

As I said for patch 3, I'd split this one and pull the part of it that
is making inet_connect_saddr() public in front of patch 2 and squash the
rest into patch 2.

> 
> diff --git a/block/ssh.c b/block/ssh.c
> index 3b18907..6420359 100644
> --- a/block/ssh.c
> +++ b/block/ssh.c
> @@ -666,13 +666,10 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
>          goto err;
>      }
>  
> -    /* Construct the host:port name for inet_connect. */
> -    g_free(s->hostport);
>      port = atoi(s->inet->port);
> -    s->hostport = g_strdup_printf("%s:%d", s->inet->host, port);
>  
>      /* Open the socket and connect. */
> -    s->sock = inet_connect(s->hostport, errp);
> +    s->sock = inet_connect_saddr(s->inet, errp, NULL, NULL);
>      if (s->sock < 0) {
>          ret = -EIO;
>          goto err;
> diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
> index 9eb2470..5589e68 100644
> --- a/include/qemu/sockets.h
> +++ b/include/qemu/sockets.h
> @@ -34,6 +34,8 @@ typedef void NonBlockingConnectHandler(int fd, Error *err, void *opaque);
>  
>  InetSocketAddress *inet_parse(const char *str, Error **errp);
>  int inet_connect(const char *str, Error **errp);
> +int inet_connect_saddr(InetSocketAddress *saddr, Error **errp,
> +                       NonBlockingConnectHandler *callback, void *opaque);
>  
>  NetworkAddressFamily inet_netfamily(int family);
>  
> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> index 4cef549..3411888 100644
> --- a/util/qemu-sockets.c
> +++ b/util/qemu-sockets.c
> @@ -412,7 +412,7 @@ static struct addrinfo *inet_parse_connect_saddr(InetSocketAddress *saddr,
>   * function succeeds, callback will be called when the connection
>   * completes, with the file descriptor on success, or -1 on error.
>   */
> -static int inet_connect_saddr(InetSocketAddress *saddr, Error **errp,
> +int inet_connect_saddr(InetSocketAddress *saddr, Error **errp,
>                                NonBlockingConnectHandler *callback, void *opaque)

You should keep the second line aligned to the opening parenthesis.

Max

>  {
>      Error *local_err = NULL;
>
diff mbox

Patch

diff --git a/block/ssh.c b/block/ssh.c
index 3b18907..6420359 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -666,13 +666,10 @@  static int connect_to_ssh(BDRVSSHState *s, QDict *options,
         goto err;
     }
 
-    /* Construct the host:port name for inet_connect. */
-    g_free(s->hostport);
     port = atoi(s->inet->port);
-    s->hostport = g_strdup_printf("%s:%d", s->inet->host, port);
 
     /* Open the socket and connect. */
-    s->sock = inet_connect(s->hostport, errp);
+    s->sock = inet_connect_saddr(s->inet, errp, NULL, NULL);
     if (s->sock < 0) {
         ret = -EIO;
         goto err;
diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index 9eb2470..5589e68 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -34,6 +34,8 @@  typedef void NonBlockingConnectHandler(int fd, Error *err, void *opaque);
 
 InetSocketAddress *inet_parse(const char *str, Error **errp);
 int inet_connect(const char *str, Error **errp);
+int inet_connect_saddr(InetSocketAddress *saddr, Error **errp,
+                       NonBlockingConnectHandler *callback, void *opaque);
 
 NetworkAddressFamily inet_netfamily(int family);
 
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 4cef549..3411888 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -412,7 +412,7 @@  static struct addrinfo *inet_parse_connect_saddr(InetSocketAddress *saddr,
  * function succeeds, callback will be called when the connection
  * completes, with the file descriptor on success, or -1 on error.
  */
-static int inet_connect_saddr(InetSocketAddress *saddr, Error **errp,
+int inet_connect_saddr(InetSocketAddress *saddr, Error **errp,
                               NonBlockingConnectHandler *callback, void *opaque)
 {
     Error *local_err = NULL;