From patchwork Fri May 20 18:41:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Joshi X-Patchwork-Id: 804502 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4KIg2HL031870 for ; Fri, 20 May 2011 18:42:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935071Ab1ETSl6 (ORCPT ); Fri, 20 May 2011 14:41:58 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:33350 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934278Ab1ETSly (ORCPT ); Fri, 20 May 2011 14:41:54 -0400 Received: by wwa36 with SMTP id 36so4309146wwa.1 for ; Fri, 20 May 2011 11:41:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=d3LDcDmZX/Dz1t8XbOaap1wpNrIR2sV0Xs8+FKgbEE4=; b=nqSOcbH6ZiYT/XzsAkPB08OlOovHk+XauErKB5rZBaUNWIIiT9CIYJUq+NC/l60eU/ YLRX+dxm3DkDaN4pBtMcOLzbSJRCt8BQ+SofnBcVuMPkDuimbZt0Z7NUtzZLlCUYXi5u VqrESdmfxIp/1gs3cw3O3Nf+F44o0DsYv1b9I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=vWaPueB8FHuloLQFIytw8aPFBAql9/TjOVuTJzT3efGECQYtu3su58JoLdeG44TYkJ As3EN75gCBiPTVdyWfAQEks956EsZRWWekna6oC3/lrggQ9K7Yooso2oZqKfkdmhpqUw wUY2T0YM7toIeXGccE4Eam+x97Wloe8TABcfU= Received: by 10.227.198.199 with SMTP id ep7mr4511073wbb.40.1305916913758; Fri, 20 May 2011 11:41:53 -0700 (PDT) Received: from prasad-kvm.localdomain (pineapple.rdg.ac.uk [134.225.206.123]) by mx.google.com with ESMTPS id s20sm2462445wbh.6.2011.05.20.11.41.51 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 May 2011 11:41:51 -0700 (PDT) Received: by prasad-kvm.localdomain (Postfix, from userid 1000) id DF4C426E004D; Fri, 20 May 2011 19:41:50 +0100 (BST) From: Prasad Joshi To: prasadjoshi124@gmail.com Cc: mingo@elte.hu, kvm@vger.kernel.org, penberg@kernel.org, asias.hejun@gmail.com, gorcunov@gmail.com, levinsasha928@gmail.com, chaitanyakulkarni15@gmail.com, ashwini.kulkarni@gmail.com Subject: [PATCH v3 4/4] kvm tools: Release memory allocated during virtio block initialization Date: Fri, 20 May 2011 19:41:49 +0100 Message-Id: <1305916909-21734-4-git-send-email-prasadjoshi124@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1305916909-21734-1-git-send-email-prasadjoshi124@gmail.com> References: <1305916909-21734-1-git-send-email-prasadjoshi124@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 20 May 2011 18:42:02 +0000 (UTC) Add a new function virtio_blk__delete() goes through array of block devices and releases memory allocated for block device. Signed-off-by: Prasad Joshi --- tools/kvm/include/kvm/virtio-blk.h | 1 + tools/kvm/kvm-run.c | 2 ++ tools/kvm/virtio/blk.c | 8 ++++++++ 3 files changed, 11 insertions(+), 0 deletions(-) diff --git a/tools/kvm/include/kvm/virtio-blk.h b/tools/kvm/include/kvm/virtio-blk.h index 72f6491..8c4fb91 100644 --- a/tools/kvm/include/kvm/virtio-blk.h +++ b/tools/kvm/include/kvm/virtio-blk.h @@ -7,5 +7,6 @@ struct kvm; void virtio_blk__init(struct kvm *kvm, struct disk_image *disk); void virtio_blk__init_all(struct kvm *kvm); +void virtio_blk__delete_all(struct kvm *kvm); #endif /* KVM__BLK_VIRTIO_H */ diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index 6c96337..53b5db0 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -615,6 +615,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) exit_code = 1; } + virtio_blk__delete_all(kvm); + disk_image__close_all(kvm->disks, image_count); kvm__delete(kvm); diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c index 2ee5854..3981cb4 100644 --- a/tools/kvm/virtio/blk.c +++ b/tools/kvm/virtio/blk.c @@ -328,3 +328,11 @@ void virtio_blk__init_all(struct kvm *kvm) for (i = 0; i < kvm->ndisks; i++) virtio_blk__init(kvm, kvm->disks[i]); } + +void virtio_blk__delete_all(struct kvm *kvm) +{ + int i; + + for (i = 0; i < kvm->ndisks; i++) + free(bdevs[i]); +}