[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V20 3/8] qed_read_string to bdrv_read_string
From: |
Dong Xu Wang |
Subject: |
[Qemu-devel] [PATCH V20 3/8] qed_read_string to bdrv_read_string |
Date: |
Mon, 26 Aug 2013 00:06:15 +0800 |
Make qed_read_string function to a common interface, so move it to
block.c.
Signed-off-by: Dong Xu Wang <address@hidden>
---
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,
--
1.7.11.7
- [Qemu-devel] [PATCH V20 0/7] add-cow file format, Dong Xu Wang, 2013/08/25
- [Qemu-devel] [PATCH V20 1/8] docs: document for add-cow file format, Dong Xu Wang, 2013/08/25
- [Qemu-devel] [PATCH V20 2/8] make path_has_protocol non static, Dong Xu Wang, 2013/08/25
- [Qemu-devel] [PATCH V20 3/8] qed_read_string to bdrv_read_string,
Dong Xu Wang <=
- [Qemu-devel] [PATCH V20 4/8] rename qcow2_cache functions to block_cache, Dong Xu Wang, 2013/08/25
- [Qemu-devel] [PATCH V20 5/8] move qcow2-cache.c to block-cache.c, Dong Xu Wang, 2013/08/25
- [Qemu-devel] [PATCH V20 6/8] Make block-cache.c be common interface, Dong Xu Wang, 2013/08/25
- [Qemu-devel] [PATCH V20 7/8] add-cow file format core code, Dong Xu Wang, 2013/08/25
- [Qemu-devel] [PATCH V20 8/8] qemu-iotests: add add-cow iotests support, Dong Xu Wang, 2013/08/25