From patchwork Wed May 18 08:19:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 793142 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 p4I8O3ws004358 for ; Wed, 18 May 2011 08:24:07 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755816Ab1ERIXy (ORCPT ); Wed, 18 May 2011 04:23:54 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:53347 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755807Ab1ERIXx (ORCPT ); Wed, 18 May 2011 04:23:53 -0400 Received: by mail-pv0-f174.google.com with SMTP id 12so602294pvg.19 for ; Wed, 18 May 2011 01:23: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=THyNQiAVbQpFaWqY09zcBd9EoQLSKqKEpkWk0oEwQdM=; b=fQAPRg2l4PZOX3zsS9LBodIDW4icwo4nOobupZ7Lw+MlcNanb8Kn7hrS3leOmy5bsB xM9QpYgU9I0eB5iWXjizdFjb+Zd461lYsEklTBRdHc4ZkhN5r1wKNbaew9JAh/6xlYIW XBVe1n0k3Xzq2VIftwkeF+ZTtEP6dIeT4PuUo= 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=mZdmTfnp1P/DiLU5jwoqe1zdU55K6MbGOquuTrjwJFDYqwN30ceLuaKE7JdC81oqJf IassC/GlKnjJFBwmGaThS7VyxFcMzHLd3epdWWhiLCuoyG/EXUKkBVgX4Ec5ZzIg7Ou7 uLw9lQi6AYlv0pwu+unTAewr8BmYP6q0qrKiA= Received: by 10.68.30.73 with SMTP id q9mr2315836pbh.431.1305707033444; Wed, 18 May 2011 01:23:53 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id q10sm912018pbk.39.2011.05.18.01.23.47 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 18 May 2011 01:23:52 -0700 (PDT) From: Asias He To: Pekka Enberg Cc: Cyrill Gorcunov , Ingo Molnar , Sasha Levin , Prasad Joshi , kvm@vger.kernel.org, Asias He Subject: [PATCH 13/14] kvm tools: Add debug info for disk_image__{read, write} Date: Wed, 18 May 2011 16:19:14 +0800 Message-Id: <1305706755-2816-13-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.5.1 In-Reply-To: <1305706755-2816-1-git-send-email-asias.hejun@gmail.com> References: <1305706755-2816-1-git-send-email-asias.hejun@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]); Wed, 18 May 2011 08:24:07 +0000 (UTC) Print debug info when read/write error occurs Signed-off-by: Asias He --- 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; }