From patchwork Fri May 20 18:41:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Joshi X-Patchwork-Id: 804512 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 p4KIg47U028134 for ; Fri, 20 May 2011 18:42:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935118Ab1ETSl7 (ORCPT ); Fri, 20 May 2011 14:41:59 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:45774 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934089Ab1ETSly (ORCPT ); Fri, 20 May 2011 14:41:54 -0400 Received: by wwa36 with SMTP id 36so4309116wwa.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=C/kyxmb29qL9Fh7fxo/tCS8TZnYnztRzJUdy20CyXXo=; b=TEA5CG1jgYD7dyBurzSp80QH02If6iC/fG66muM9uzdhLPt5PKzKRmI6wI0YAEMG8U qHrjIiBmm65Af3YNq3Sb+o7zLKasVNtcXBKWAl8fV9c2rrFt0LlAVjPhATmQMqS3ylCz Zu0vK3o0FJ3mHyWoXm+KyeFPwPYGzgFq6JlZ4= 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=Vq4jxeKrWI83okSoebLDAKGMlwXANn1pIeMElgPvXGl+9VfdddN/TStBRXkopjscQU lbSmxAaLW/YQqjfBPXpz1nzKp0LfNPa2vZ9q5hdGhVzSDgkwEfR1PukKsSQVBsqE+SV9 rrR87YUVPVV//PtAQUKi7PZzH86bWFCXylHz0= Received: by 10.216.152.170 with SMTP id d42mr4937836wek.39.1305916913051; 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 m84sm1992468weq.36.2011.05.20.11.41.50 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 May 2011 11:41:51 -0700 (PDT) Received: by prasad-kvm.localdomain (Postfix, from userid 1000) id D0E2826E004F; 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 2/4] kvm tools: Close the disk images after the guest shuts down Date: Fri, 20 May 2011 19:41:47 +0100 Message-Id: <1305916909-21734-2-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 (demeter2.kernel.org [140.211.167.43]); Fri, 20 May 2011 18:42:05 +0000 (UTC) Signed-off-by: Prasad Joshi --- tools/kvm/disk/core.c | 11 +++++++++++ tools/kvm/include/kvm/disk-image.h | 1 + tools/kvm/kvm-run.c | 1 + 3 files changed, 13 insertions(+), 0 deletions(-) diff --git a/tools/kvm/disk/core.c b/tools/kvm/disk/core.c index fa603cc..4a9d0c9 100644 --- a/tools/kvm/disk/core.c +++ b/tools/kvm/disk/core.c @@ -118,6 +118,17 @@ int disk_image__close(struct disk_image *disk) return 0; } +void disk_image__close_all(struct disk_image **disks, int count) +{ + if (count <= 0) + return; + + while (count) + disk_image__close(disks[--count]); + + free(disks); +} + /* * Fill iov with disk data, starting from sector 'sector'. * Return amount of bytes read. diff --git a/tools/kvm/include/kvm/disk-image.h b/tools/kvm/include/kvm/disk-image.h index bf2bfa9..1363fe1 100644 --- a/tools/kvm/include/kvm/disk-image.h +++ b/tools/kvm/include/kvm/disk-image.h @@ -55,6 +55,7 @@ struct disk_image *disk_image__open(const char *filename, bool readonly); struct disk_image **disk_image__open_all(const char **filenames, bool *readonly, int count); struct disk_image *disk_image__new(int fd, u64 size, struct disk_image_operations *ops, int mmap); int disk_image__close(struct disk_image *disk); +void disk_image__close_all(struct disk_image **disks, int count); int disk_image__flush(struct disk_image *disk); ssize_t disk_image__read(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount); ssize_t disk_image__write(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount); diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index 28e3ed6..32b34fe 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -615,6 +615,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) exit_code = 1; } + disk_image__close_all(kvm->disks, image_count); kvm__delete(kvm); if (!exit_code)