From patchwork Sat Oct 15 09:04:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9377745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C7EA60779 for ; Sat, 15 Oct 2016 09:13:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8517293F7 for ; Sat, 15 Oct 2016 09:13:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB402293F9; Sat, 15 Oct 2016 09:13:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 785DE293F7 for ; Sat, 15 Oct 2016 09:13:18 +0000 (UTC) Received: from localhost ([::1]:51042 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvL1p-0000sp-Iq for patchwork-qemu-devel@patchwork.kernel.org; Sat, 15 Oct 2016 05:13:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvKw5-00058n-K7 for qemu-devel@nongnu.org; Sat, 15 Oct 2016 05:07:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bvKw4-0001qa-H0 for qemu-devel@nongnu.org; Sat, 15 Oct 2016 05:07:21 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:35837) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bvKw4-0001qK-AV; Sat, 15 Oct 2016 05:07:20 -0400 Received: by mail-pf0-x243.google.com with SMTP id s8so8834896pfj.2; Sat, 15 Oct 2016 02:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ot8Jrac7neCC/CAzERyzfkF0TnCH+N1luimcnvhJwto=; b=foQIfYqMSFczsTaGIr4s14WRPrM0whM3rvG6Rn45ERYNyj/oxvJhZktpPYXIl1FF/C iww0YLvDUZuNkzIuJBj2UJIMmE7kTASYP8QXlp/3rALvWOmeA3szQLHTVnts8++JYrWT x8pGxKynjWdybTzbT1N8hJOd/Xn86fytl7rY+wufq9x99ARkukJ7kgisZHji0Azs+fzx bh3PfiqfBC8jtyWSnlc4xnjmn9cIdJx4747aTtgRrub7OUxad/2R7778f8R8KSMcahT5 usFizwtRXdbZCzkK1qaO7pbyAdb7b1dsV/c8OAxKC8KFD+NG9ZefmKcyqHbVOdiowapF 7m9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ot8Jrac7neCC/CAzERyzfkF0TnCH+N1luimcnvhJwto=; b=YnA73qoPGfwnAsiAlM0Zf2nkQsfyHWQPz/W6itK0MxrM23dJEjQivoWAr7AbjQPEZB Mtr/bN/L6tOK1uM0E6kmKiTtZ6T7103sFpOFj9zmc6hYpaRudjab4Ao2ebQq+e1EA2kR vedW+NABAuesQxiJ1nFOB1HFdRb3IEVMbURXEtwLOIpwR+54BUCmdkqkmF/jYJ7HfnWV HH/hz6rFb6dwYgh4mBPheXsrBOBjX+gPlI3zZxfupqVcfP/kgVYIa8Ug/wv/o88V0vYu ZhlCS7MeyA6zdATQwi27q6itn7y8zv8o1kAnPXsLNf/f3GG3ol8nFG1Sn4qRTqk2hJ7r /x4w== X-Gm-Message-State: AA6/9Rl6KHAtf8uU10hXtxmmy8VK/A0E4cAxY5rhPJKwCDYJduJW/nztu1kX6CNPhQvHoQ== X-Received: by 10.99.63.3 with SMTP id m3mr19878353pga.62.1476522439229; Sat, 15 Oct 2016 02:07:19 -0700 (PDT) Received: from linux.local ([27.251.197.196]) by smtp.gmail.com with ESMTPSA id a7sm5295159pan.34.2016.10.15.02.07.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 15 Oct 2016 02:07:18 -0700 (PDT) From: Ashijeet Acharya To: kwolf@redhat.com Date: Sat, 15 Oct 2016 14:34:38 +0530 Message-Id: <1476522280-23211-4-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1476522280-23211-1-git-send-email-ashijeetacharya@gmail.com> References: <1476522280-23211-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [v2 3/5] block/ssh: Use inet_connect_saddr() to establish socket connection X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, jcody@redhat.com, armbru@redhat.com, rjones@redhat.com, kraxel@redhat.com, Ashijeet Acharya , pbonzini@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- block/ssh.c | 5 +---- include/qemu/sockets.h | 2 ++ util/qemu-sockets.c | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) 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;