qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH V13 3/6] qed_read_string to bdrv_read_string
Date: Thu, 18 Oct 2012 17:51:32 +0800	[thread overview]
Message-ID: <1350553895-3388-4-git-send-email-wdongxu@linux.vnet.ibm.com> (raw)
In-Reply-To: <1350553895-3388-1-git-send-email-wdongxu@linux.vnet.ibm.com>

Make qed_read_string function to a common interface, so move it to block.c.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
---
 block.c     |   27 +++++++++++++++++++++++++++
 block.h     |    2 ++
 block/qed.c |   34 ++++------------------------------
 3 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/block.c b/block.c
index 03ba485..9afb7b5 100644
--- a/block.c
+++ b/block.c
@@ -215,6 +215,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.h b/block.h
index 364ba04..166e00c 100644
--- a/block.h
+++ b/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,
diff --git a/block/qed.c b/block/qed.c
index 0a9dbe8..096de21 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, 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;
         }
-- 
1.7.1

  parent reply	other threads:[~2012-10-18  9:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-18  9:51 [Qemu-devel] [PATCH V13 0/6] add-cow file format Dong Xu Wang
2012-10-18  9:51 ` [Qemu-devel] [PATCH V13 1/6] docs: document for " Dong Xu Wang
2012-10-18 16:10   ` Eric Blake
2012-10-19  2:14     ` Dong Xu Wang
2012-10-18  9:51 ` [Qemu-devel] [PATCH V13 2/6] make path_has_protocol non static Dong Xu Wang
2012-10-18  9:51 ` Dong Xu Wang [this message]
2012-10-18  9:51 ` [Qemu-devel] [PATCH V13 4/6] rename qcow2-cache.c to block-cache.c Dong Xu Wang
2012-10-22  8:22   ` Stefan Hajnoczi
2012-10-22  8:24     ` Dong Xu Wang
2012-10-18  9:51 ` [Qemu-devel] [PATCH V13 5/6] add-cow file format core code Dong Xu Wang
2012-10-22  9:29   ` Stefan Hajnoczi
2012-10-18  9:51 ` [Qemu-devel] [PATCH V13 6/6] qemu-iotests: add add-cow iotests support Dong Xu Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350553895-3388-4-git-send-email-wdongxu@linux.vnet.ibm.com \
    --to=wdongxu@linux.vnet.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).