From patchwork Sun Aug 25 16:06:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 269710 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 07EB62C00AA for ; Mon, 26 Aug 2013 02:07:33 +1000 (EST) Received: from localhost ([::1]:46690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDcqg-0002Ny-NH for incoming@patchwork.ozlabs.org; Sun, 25 Aug 2013 12:07:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDcq0-0002C4-PQ for qemu-devel@nongnu.org; Sun, 25 Aug 2013 12:06:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VDcps-0002AN-6Z for qemu-devel@nongnu.org; Sun, 25 Aug 2013 12:06:48 -0400 Received: from mail-pd0-x22e.google.com ([2607:f8b0:400e:c02::22e]:39103) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDcps-0002AH-0N for qemu-devel@nongnu.org; Sun, 25 Aug 2013 12:06:40 -0400 Received: by mail-pd0-f174.google.com with SMTP id y13so2531936pdi.33 for ; Sun, 25 Aug 2013 09:06:39 -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:in-reply-to:references; bh=ptXrOcjUx83+Lcylcw9htykhCeMCsed5BFj/mFBXCQg=; b=efbX2D7GqJVpRuGQkNRBjiSSzDkLAmmx/rauey/3nNSOMKwkmsHT0JCWxXax0EQlAb Wn2BJ8Jin4iDA5Yzgw1mOzQkxAU2CY39w0ftvdX0b1VQGDPed5vz8U7BI2iVFJjGeID4 88wxG9MZ2sdHLGwyN4e2PqGauh26tPIfPvu4roxVq4TM44Km5FSK6u63qBqg+zY4daAI V4wwP9V5XtGND/elzoWi9uQrq9ScfExGoE0inho+kfTNknW5Ew52VUIl4hpW7uDU78ro D9CjBweUA8YrnzDkNdsjI2J2HtRjZyrPBKpywQh2CyEL8guIgvSrhd2Wcg9r+yAYnhZa i9kg== X-Received: by 10.66.219.200 with SMTP id pq8mr9919249pac.123.1377446799289; Sun, 25 Aug 2013 09:06:39 -0700 (PDT) Received: from 11.wdongxu.kvm58 ([202.108.130.153]) by mx.google.com with ESMTPSA id oc10sm12666416pbb.3.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 25 Aug 2013 09:06:38 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Mon, 26 Aug 2013 00:06:15 +0800 Message-Id: <1377446780-15360-4-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1377446780-15360-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1377446780-15360-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c02::22e Cc: kwolf@redhat.com, Dong Xu Wang , wdongxu@cn.ibm.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH V20 3/8] 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/qed.c | 34 ++++------------------------------ include/block/block.h | 2 ++ 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/block.c b/block.c index b2711e9..e747afb 100644 --- a/block.c +++ b/block.c @@ -206,6 +206,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/qed.c b/block/qed.c index 6b02c47..09cc13f 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, QDict *options, 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; } diff --git a/include/block/block.h b/include/block/block.h index f025185..30c8e1a 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -168,6 +168,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,