From patchwork Thu Nov 1 09:23:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 196140 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CE4292C032B for ; Thu, 1 Nov 2012 21:15:08 +1100 (EST) Received: from localhost ([::1]:33974 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTr0u-00074L-OE for incoming@patchwork.ozlabs.org; Thu, 01 Nov 2012 05:24:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50137) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTr06-0004oS-4Y for qemu-devel@nongnu.org; Thu, 01 Nov 2012 05:23:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTr05-0003Ih-07 for qemu-devel@nongnu.org; Thu, 01 Nov 2012 05:23:45 -0400 Received: from mail-da0-f45.google.com ([209.85.210.45]:43171) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTr04-0003Hw-P8 for qemu-devel@nongnu.org; Thu, 01 Nov 2012 05:23:44 -0400 Received: by mail-da0-f45.google.com with SMTP id n15so1044274dad.4 for ; Thu, 01 Nov 2012 02:23:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=X/TxslvjwoElfEhxorbuW7tNVXUSc1SxdhRuRlxmr1E=; b=V4EpOwCqPmJDiBpGh9W0+uGrBK+tbpcro/9CN+PTl3d3lBXKaLVpY0rchtJ6Wfvv/z lWujkoLTE9HPqzPNgOy7gHH4sGS6rUx7TPGl1P5cagz8UjFpb3vL3Zp6yqPKFBl4Q5uh Tom/ymKwK/1sAr5TzQtYkjeFgtWuuWFw/bkEPX07NMhjRyVaQ0S8VmeWM9g03EK7XJPc fqL42APrF/juAy6wLObnMSJfoa/RW9kT5+5I3frM8IKpHi1LIF4vOCppMNgWc64ftddx CS/VcMLVnQ3f3snFhDm3qyhEsh60eoFs7lnT1nn49NnnaRulq1CzMPR3Jx4YjGgzPz3X 5BbQ== Received: by 10.66.81.138 with SMTP id a10mr109292592pay.53.1351761824459; Thu, 01 Nov 2012 02:23:44 -0700 (PDT) Received: from localhost.localdomain ([202.108.130.138]) by mx.google.com with ESMTPS id b6sm3679258pav.33.2012.11.01.02.23.41 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 01 Nov 2012 02:23:43 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 1 Nov 2012 17:23:30 +0800 Message-Id: <1351761813-21044-4-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1351761813-21044-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1351761813-21044-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.45 Cc: kwolf@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH V15 3/6] qed_read_string to bdrv_read_string X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make qed_read_string function to a common interface, so move it to block.c. Signed-off-by: Dong Xu Wang --- block.c | 27 +++++++++++++++++++++++++++ block.h | 2 ++ block/qed.c | 34 ++++------------------------------ 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/block.c b/block.c index 826a9ba..88163af 100644 --- a/block.c +++ b/block.c @@ -216,6 +216,33 @@ int path_has_protocol(const char *path) return *p == ':'; } +/** + * Read a string of known length from the image file + * + * @bs: Image file + * @offset: File offset to start of string, in bytes + * @n: String length in bytes + * @buf: Destination buffer + * @buflen: Destination buffer length in bytes + * @ret: 0 on success, -errno on failure + * + * The string is NUL-terminated. + */ +int bdrv_read_string(BlockDriverState *bs, uint64_t offset, size_t n, + char *buf, size_t buflen) +{ + int ret; + if (n >= buflen) { + return -EINVAL; + } + ret = bdrv_pread(bs, offset, buf, n); + if (ret < 0) { + return ret; + } + buf[n] = '\0'; + return 0; +} + int path_is_absolute(const char *path) { #ifdef _WIN32 diff --git a/block.h b/block.h index fcf392b..301d6c5 100644 --- a/block.h +++ b/block.h @@ -170,6 +170,8 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset, const void *buf, int count); int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); +int bdrv_read_string(BlockDriverState *bs, uint64_t offset, size_t n, + char *buf, size_t buflen); int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, diff --git a/block/qed.c b/block/qed.c index 08799b0..5336b9b 100644 --- a/block/qed.c +++ b/block/qed.c @@ -217,33 +217,6 @@ static bool qed_is_image_size_valid(uint64_t image_size, uint32_t cluster_size, } /** - * Read a string of known length from the image file - * - * @file: Image file - * @offset: File offset to start of string, in bytes - * @n: String length in bytes - * @buf: Destination buffer - * @buflen: Destination buffer length in bytes - * @ret: 0 on success, -errno on failure - * - * The string is NUL-terminated. - */ -static int qed_read_string(BlockDriverState *file, uint64_t offset, size_t n, - char *buf, size_t buflen) -{ - int ret; - if (n >= buflen) { - return -EINVAL; - } - ret = bdrv_pread(file, offset, buf, n); - if (ret < 0) { - return ret; - } - buf[n] = '\0'; - return 0; -} - -/** * Allocate new clusters * * @s: QED state @@ -437,9 +410,10 @@ static int bdrv_qed_open(BlockDriverState *bs, int flags) return -EINVAL; } - ret = qed_read_string(bs->file, s->header.backing_filename_offset, - s->header.backing_filename_size, bs->backing_file, - sizeof(bs->backing_file)); + ret = bdrv_read_string(bs->file, s->header.backing_filename_offset, + s->header.backing_filename_size, + bs->backing_file, + sizeof(bs->backing_file)); if (ret < 0) { return ret; }