From: Asias He <asias.hejun@gmail.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>,
Sasha Levin <levinsasha928@gmail.com>,
Prasad Joshi <prasadjoshi124@gmail.com>,
kvm@vger.kernel.org, Asias He <asias.hejun@gmail.com>
Subject: [PATCH 13/14] kvm tools: Add debug info for disk_image__{read, write}
Date: Wed, 18 May 2011 16:19:14 +0800 [thread overview]
Message-ID: <1305706755-2816-13-git-send-email-asias.hejun@gmail.com> (raw)
In-Reply-To: <1305706755-2816-1-git-send-email-asias.hejun@gmail.com>
Print debug info when read/write error occurs
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/disk/core.c | 91 +++++++++++++++++++++++++++++++++++--------------
1 files changed, 65 insertions(+), 26 deletions(-)
diff --git a/tools/kvm/disk/core.c b/tools/kvm/disk/core.c
index f3dd0bb..b229f83 100644
--- a/tools/kvm/disk/core.c
+++ b/tools/kvm/disk/core.c
@@ -84,40 +84,79 @@ int disk_image__close(struct disk_image *disk)
return 0;
}
-/* Fill iov with disk data, starting from sector 'sector'. Return amount of bytes read. */
+/*
+ * Fill iov with disk data, starting from sector 'sector'.
+ * Return amount of bytes read.
+ */
ssize_t disk_image__read(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount)
{
- u64 first_sector = sector;
+ ssize_t total = 0;
+ ssize_t nr;
- if (disk->ops->read_sector_iov)
- return disk->ops->read_sector_iov(disk, sector, iov, iovcount);
-
- while (iovcount--) {
- if (disk->ops->read_sector(disk, sector, iov->iov_base, iov->iov_len) < 0)
+ if (disk->ops->read_sector_iov) {
+ /*
+ * Try mulitple buffer based operation first
+ */
+ total = disk->ops->read_sector_iov(disk, sector, iov, iovcount);
+ if (total < 0) {
+ info("disk_image__read error: total=%ld\n", (long)total);
return -1;
-
- sector += iov->iov_len >> SECTOR_SHIFT;
- iov++;
- }
-
- return (sector - first_sector) << SECTOR_SHIFT;
+ }
+ } else if (disk->ops->read_sector) {
+ /*
+ * Fallback to single buffer based operation
+ */
+ while (iovcount--) {
+ nr = disk->ops->read_sector(disk, sector, iov->iov_base, iov->iov_len);
+ if (nr != (ssize_t)iov->iov_len) {
+ info("disk_image__read error: nr = %ld iov_len=%ld\n", (long)nr, (long)iov->iov_len);
+ return -1;
+ }
+ sector += iov->iov_len >> SECTOR_SHIFT;
+ iov++;
+ total += nr;
+ }
+ } else
+ die("No disk image operation for read\n");
+
+ return total;
}
-/* Write iov to disk, starting from sector 'sector'. Return amount of bytes written. */
+/*
+ * Write iov to disk, starting from sector 'sector'.
+ * Return amount of bytes written.
+ */
ssize_t disk_image__write(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount)
{
- u64 first_sector = sector;
+ ssize_t total = 0;
+ ssize_t nr;
- if (disk->ops->write_sector_iov)
- return disk->ops->write_sector_iov(disk, sector, iov, iovcount);
-
- while (iovcount--) {
- if (disk->ops->write_sector(disk, sector, iov->iov_base, iov->iov_len) < 0)
+ if (disk->ops->write_sector_iov) {
+ /*
+ * Try writev based operation first
+ */
+ total = disk->ops->write_sector_iov(disk, sector, iov, iovcount);
+ if (total < 0) {
+ info("disk_image__write error: total=%ld\n", (long)total);
return -1;
-
- sector += iov->iov_len >> SECTOR_SHIFT;
- iov++;
- }
-
- return (sector - first_sector) << SECTOR_SHIFT;
+ }
+ } else if (disk->ops->write_sector) {
+ /*
+ * Fallback to single buffer based operation
+ */
+ while (iovcount--) {
+ nr = disk->ops->write_sector(disk, sector, iov->iov_base, iov->iov_len);
+ if (nr != (ssize_t)iov->iov_len) {
+ info("disk_image__write error: nr=%ld iov_len=%ld\n", (long)nr, (long)iov->iov_len);
+ return -1;
+ }
+
+ sector += iov->iov_len >> SECTOR_SHIFT;
+ iov++;
+ total += nr;
+ }
+ } else
+ die("No disk image operation for read\n");
+
+ return total;
}
--
1.7.5.1
next prev parent reply other threads:[~2011-05-18 8:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-18 8:19 [PATCH 01/14] kvm tools: Move disk image related code under disk directory Asias He
2011-05-18 8:19 ` [PATCH 02/14] kvm tools: Rename disk-image.c to core.c Asias He
2011-05-18 8:19 ` [PATCH 03/14] kvm tools: Split raw image and blk device code from disk/core.c Asias He
2011-05-18 8:19 ` [PATCH 04/14] kvm tools: Rename disk_image__{read, write}_sector_iov Asias He
2011-05-18 8:19 ` [PATCH 05/14] kvm tools: Remove dead coe disk_image__{read, write}_sector Asias He
2011-05-18 8:19 ` [PATCH 06/14] kvm tools: Consolidate disk_image__{new, new_readonly} Asias He
2011-05-18 8:19 ` [PATCH 07/14] kvm tools: Split blk device code from raw.c to blk.c Asias He
2011-05-18 8:19 ` [PATCH 08/14] kvm tools: Tune up ops in 'struct disk_image_operations' Asias He
2011-05-18 8:19 ` [PATCH 09/14] kvm tools: Rename struct disk_image_operations ops name for raw image Asias He
2011-05-18 8:19 ` [PATCH 10/14] kvm tools: Rename raw_image_ops to blk_dev_ops Asias He
2011-05-18 8:51 ` Ingo Molnar
2011-05-18 8:19 ` [PATCH 11/14] kvm tools: Remove unnecessary S_ISBLK check Asias He
2011-05-18 8:19 ` [PATCH 12/14] kvm tools: Do not use 'inline' for disk_image__flush Asias He
2011-05-18 8:19 ` Asias He [this message]
2011-05-18 8:19 ` [PATCH 14/14] kvm tools: Print debug info for qcow1_nowrite_sector Asias He
2011-05-18 8:45 ` Ingo Molnar
2011-05-18 8:46 ` Ingo Molnar
2011-05-18 8:47 ` Cyrill Gorcunov
2011-05-18 8:42 ` [PATCH 01/14] kvm tools: Move disk image related code under disk directory Ingo Molnar
2011-05-18 8:43 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1305706755-2816-13-git-send-email-asias.hejun@gmail.com \
--to=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
--cc=prasadjoshi124@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.