From patchwork Wed Apr 27 22:34:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 66846 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2445081qge; Wed, 27 Apr 2016 15:37:28 -0700 (PDT) X-Received: by 10.194.85.161 with SMTP id i1mr12655426wjz.95.1461796648202; Wed, 27 Apr 2016 15:37:28 -0700 (PDT) Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com. [209.132.183.37]) by mx.google.com with ESMTPS id qg18si7023555wjb.19.2016.04.27.15.37.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Apr 2016 15:37:28 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3RMYp08062963; Wed, 27 Apr 2016 18:34:52 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u3RMYBHr031666 for ; Wed, 27 Apr 2016 18:34:11 -0400 Received: from colepc.redhat.com (ovpn-113-44.phx2.redhat.com [10.3.113.44]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3RMY8og021727; Wed, 27 Apr 2016 18:34:11 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Wed, 27 Apr 2016 18:34:01 -0400 Message-Id: <8171c46716d9b00536a5bacd11e3949f4d33f561.1461796325.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/4] rpc: use virNetMessageClearPayload in client X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com This removes the opencoded payload freeing in the client, to use the shared virNetMessageClearPayload call. Two changes: - ClearPayload sets nfds=0, which fixes a potential crash if an error path called virNetMessageFree/Clear on the message after fds was free'd - We drop the inner loop VIR_FORCE_CLOSE... this may mean fds are kept open a little bit longer if the call is blocking but in practice I don't think it will have any effect --- src/libvirt_remote.syms | 1 + src/rpc/virnetclient.c | 6 +----- src/rpc/virnetmessage.c | 2 +- src/rpc/virnetmessage.h | 2 ++ 4 files changed, 5 insertions(+), 6 deletions(-) -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 66f9383..2c0b7f3 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -79,6 +79,7 @@ virNetDaemonUpdateServices; # rpc/virnetmessage.h virNetMessageClear; +virNetMessageClearPayload; virNetMessageDecodeHeader; virNetMessageDecodeLength; virNetMessageDecodeNumFDs; diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index d8ed15b..9c0d190 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -1184,12 +1184,8 @@ virNetClientIOWriteMessage(virNetClientPtr client, if (rv == 0) /* Blocking */ return 0; thecall->msg->donefds++; - VIR_FORCE_CLOSE(thecall->msg->fds[i]); } - thecall->msg->donefds = 0; - thecall->msg->bufferOffset = thecall->msg->bufferLength = 0; - VIR_FREE(thecall->msg->fds); - VIR_FREE(thecall->msg->buffer); + virNetMessageClearPayload(thecall->msg); if (thecall->expectReply) thecall->mode = VIR_NET_CLIENT_MODE_WAIT_RX; else diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index 673fb8d..c3a2e59 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -49,7 +49,7 @@ virNetMessagePtr virNetMessageNew(bool tracked) } -static void +void virNetMessageClearPayload(virNetMessagePtr msg) { size_t i; diff --git a/src/rpc/virnetmessage.h b/src/rpc/virnetmessage.h index 89a2ebf..d7406fc 100644 --- a/src/rpc/virnetmessage.h +++ b/src/rpc/virnetmessage.h @@ -54,6 +54,8 @@ struct _virNetMessage { virNetMessagePtr virNetMessageNew(bool tracked); +void virNetMessageClearPayload(virNetMessagePtr msg); + void virNetMessageClear(virNetMessagePtr); void virNetMessageFree(virNetMessagePtr msg);