From patchwork Thu May 30 10:00:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 247517 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 B024C2C0091 for ; Thu, 30 May 2013 20:03:09 +1000 (EST) Received: from localhost ([::1]:40022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhzhL-0007Tw-HE for incoming@patchwork.ozlabs.org; Thu, 30 May 2013 06:03:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhzfO-0004Bi-3V for qemu-devel@nongnu.org; Thu, 30 May 2013 06:01:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UhzfJ-0007ZV-0T for qemu-devel@nongnu.org; Thu, 30 May 2013 06:01:06 -0400 Received: from mail-yh0-x22c.google.com ([2607:f8b0:4002:c01::22c]:62741) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhzfI-0007ZN-SS for qemu-devel@nongnu.org; Thu, 30 May 2013 06:01:00 -0400 Received: by mail-yh0-f44.google.com with SMTP id 29so5426yhl.17 for ; Thu, 30 May 2013 03:01:00 -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=url6Eu6bOzCX4bQl3X+qTaxY3MWh1qY3AyBcF7hNvIk=; b=IG1v893NPpsnquVyNr5JavK8EiPfgc4pkXNNopZ2VJMQf7L72HALknoD4ye/nm3hte sgExrJO3p8eXHTHY04ZhPsto1uyvT2ESLSUzO7zNM/ib3KdootpS4MCtq8k3VbNYIYm6 rFabQeleMxwIWTJkdzmvitUXpbtuO67Rad8piBBBD9i1m+sIHbqcXXTSDyWuakg1tH1M nYRDYhyp+XVkfUomAq7XTvk37wHUgkjuAjAn2bK5XOtHwstSP0mQYWp0tn6lFmYlK8S4 tDNPBa3k0AqpGoHb4qx3gP55hj5c4u732ce3gPGDRi0TY8fQ+7DufSjCYi0e4TcyjgLl U8fA== X-Received: by 10.236.31.37 with SMTP id l25mr3084706yha.196.1369908060438; Thu, 30 May 2013 03:01:00 -0700 (PDT) Received: from 11.wdongxu.kvm58 ([202.108.130.153]) by mx.google.com with ESMTPSA id j64sm58764867yhj.25.2013.05.30.03.00.57 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 30 May 2013 03:00:59 -0700 (PDT) From: Dongxu Wang To: qemu-devel@nongnu.org Date: Thu, 30 May 2013 18:00:20 +0800 Message-Id: <1369908025-9556-4-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1369908025-9556-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1369908025-9556-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:4002:c01::22c Cc: kwolf@redhat.com, Dong Xu Wang , wdongxu@cn.ibm.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH V19 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 From: Dong Xu Wang Make qed_read_string function to a common interface, so move it to block.c. Signed-off-by: Dong Xu Wang Signed-off-by: Dongxu 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 5135044..65c5e76 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 88daf22..077da76 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 fd776a1..2989da6 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -175,6 +175,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,