From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Seoh5-0004gq-8c for qemu-devel@nongnu.org; Wed, 13 Jun 2012 10:37:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Seogy-0001sf-OJ for qemu-devel@nongnu.org; Wed, 13 Jun 2012 10:37:10 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:36734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Seogy-0001rp-Fi for qemu-devel@nongnu.org; Wed, 13 Jun 2012 10:37:04 -0400 Received: by pbbro12 with SMTP id ro12so2480408pbb.4 for ; Wed, 13 Jun 2012 07:37:02 -0700 (PDT) Sender: Dong Xu Wang From: Dong Xu Wang Date: Wed, 13 Jun 2012 22:36:25 +0800 Message-Id: <1339598189-17933-2-git-send-email-wdongxu@linux.vnet.ibm.com> In-Reply-To: <1339598189-17933-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1339598189-17933-1-git-send-email-wdongxu@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 2/6] block: make some functions public List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, Dong Xu Wang In add-cow file format, we will use path_has_protocol and we will read a NUL-terminated string from image , qed_read_string has done the samething, so make the two functions public, then we will reuse them directly. Signed-off-by: Dong Xu Wang --- block.c | 17 ++++++++++++++++- block.h | 3 +++ block/qed.c | 29 +---------------------------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/block.c b/block.c index 7547051..3cf5fe9 100644 --- a/block.c +++ b/block.c @@ -196,7 +196,7 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs, } /* check if the path starts with ":" */ -static int path_has_protocol(const char *path) +int path_has_protocol(const char *path) { const char *p; @@ -1606,6 +1606,21 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num, return bdrv_rw_co(bs, sector_num, buf, nb_sectors, false); } +int bdrv_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; +} + #define BITS_PER_LONG (sizeof(unsigned long) * 8) static void set_dirty_bitmap(BlockDriverState *bs, int64_t sector_num, diff --git a/block.h b/block.h index 7408acc..fd4f8cf 100644 --- a/block.h +++ b/block.h @@ -149,6 +149,8 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset, const void *buf, int count); int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset, const void *buf, int count); +int bdrv_read_string(BlockDriverState *file, uint64_t offset, size_t n, + char *buf, size_t buflen); int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs, @@ -321,6 +323,7 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn); char *get_human_readable_size(char *buf, int buf_size, int64_t size); int path_is_absolute(const char *path); +int path_has_protocol(const char *path); void path_combine(char *dest, int dest_size, const char *base_path, const char *filename); diff --git a/block/qed.c b/block/qed.c index 30a31f9..b300584 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,7 +410,7 @@ static int bdrv_qed_open(BlockDriverState *bs, int flags) return -EINVAL; } - ret = qed_read_string(bs->file, s->header.backing_filename_offset, + 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) { -- 1.7.1