From patchwork Fri May 20 15:02:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Joshi X-Patchwork-Id: 803902 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4KF3RJF028144 for ; Fri, 20 May 2011 15:03:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756928Ab1ETPDX (ORCPT ); Fri, 20 May 2011 11:03:23 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:60808 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756735Ab1ETPDW (ORCPT ); Fri, 20 May 2011 11:03:22 -0400 Received: by mail-ww0-f44.google.com with SMTP id 36so4116827wwa.1 for ; Fri, 20 May 2011 08:03:22 -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=TsFL33OitkzVnBBdq4aV6kCauX3eH3pkHmLFwrPA3J8=; b=VriFKd/URwsbZuV9UjZBckzJaKbzqKkNKj+dNDyIGTzAkAtY4aBskhraFJLyv6Xaw8 T2CqVUzgrWvoGBn4cIqG8gcFwkAJC7z+aGRkdgXLP7OQXxHrWCXny4vEPDTwrRkXtEmc vYKMYKPOY/vNLg8SLcNXFHOP3D5qy/yeDh1lA= 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=RqxLZCnCCEobALnjMUCJ1RTm54bA3ZPBaAbrv2lPGwuw9ce8R95l6sOz+dj3huYuhO 3HY/EkjRLZyv6ysiWe0LrKMi5EGU+abe7hI+jsBo67LFToN0CZGUBxEZS0uu6h9R0Af0 nNT803WlYh+Q92bL461+sI5Gv/aQ0JYoIiW8I= Received: by 10.227.61.142 with SMTP id t14mr4336214wbh.84.1305903801899; Fri, 20 May 2011 08:03:21 -0700 (PDT) Received: from prasad-kvm.localdomain (pineapple.rdg.ac.uk [134.225.206.123]) by mx.google.com with ESMTPS id bi13sm2346571wbb.8.2011.05.20.08.02.44 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 May 2011 08:02:54 -0700 (PDT) Received: by prasad-kvm.localdomain (Postfix, from userid 1000) id 7DFCA26E004F; Fri, 20 May 2011 16:02:41 +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 v2 4/4] kvm tools: Release memory allocated during virtio block initialization Date: Fri, 20 May 2011 16:02:40 +0100 Message-Id: <1305903760-7804-4-git-send-email-prasadjoshi124@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1305903760-7804-1-git-send-email-prasadjoshi124@gmail.com> References: <1305903760-7804-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 (demeter2.kernel.org [140.211.167.43]); Fri, 20 May 2011 15:03:27 +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 6b0c1fd..1acfa36 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]); +}