From patchwork Wed Apr 10 08:11:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 235332 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 B95052C00C6 for ; Wed, 10 Apr 2013 18:16:08 +1000 (EST) Received: from localhost ([::1]:35206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPqCM-0006ak-L8 for incoming@patchwork.ozlabs.org; Wed, 10 Apr 2013 04:16:06 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPq9E-0002g2-Hv for qemu-devel@nongnu.org; Wed, 10 Apr 2013 04:12:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UPq9B-0008QQ-7n for qemu-devel@nongnu.org; Wed, 10 Apr 2013 04:12:52 -0400 Received: from mail-da0-x22c.google.com ([2607:f8b0:400e:c00::22c]:56793) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPq9B-0008Q4-1y for qemu-devel@nongnu.org; Wed, 10 Apr 2013 04:12:49 -0400 Received: by mail-da0-f44.google.com with SMTP id z20so108639dae.17 for ; Wed, 10 Apr 2013 01:12:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=Kx0xFMcErnhxznybDV5nBLwQwORoON2ULowUoqxeGWY=; b=l6Ab8qQX4dO0+zL9XdivXrQnynzyrvDPi1BL2hfPisD7HwwA0AW2Bq4StIu9+h4/MN 2UG8Mmsvyd0m2IcQUcYY5HKmrX+3adNHUzw61mtXylQ5zsk6xInWsaQ+pqPbEwY3Iztp 5H4jXH3GLogrb4bnxWREIk6TiE4pgJo2wLF57XVEeRcd33ep1ls0xNOwvkC43V9cnuyl zB+g9NkPbCbHyhljHEv51bELSG+dcKiVCeqIp4JoQJ6UJj4sIVvxfqngVhOw9hKJdAyp 0BN6SMVKXk5hxjpqPm+61UEouP+MIKTOopg4pw5wzQGNwu67JxEY8MVP9KuQzDgX/kQA LT2A== X-Received: by 10.66.72.105 with SMTP id c9mr2008913pav.177.1365581568242; Wed, 10 Apr 2013 01:12:48 -0700 (PDT) Received: from localhost.localdomain ([202.108.130.138]) by mx.google.com with ESMTPS id wl5sm33042619pac.18.2013.04.10.01.12.40 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 10 Apr 2013 01:12:47 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Wed, 10 Apr 2013 16:11:50 +0800 Message-Id: <1365581513-3475-4-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1365581513-3475-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1365581513-3475-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:c00::22c Cc: Dong Xu Wang , kwol@redhat.com, wdongxu@cn.ibm.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH V18 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/qed.c | 34 ++++------------------------------ include/block/block.h | 2 ++ 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/block.c b/block.c index 1e7dab5..6aad45b 100644 --- a/block.c +++ b/block.c @@ -210,6 +210,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 acffc2d..d647792 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 7d34aa2..e737c9c 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -173,6 +173,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,