diff mbox

[v2,07/16] block: move allocating aligned_buf into a helper function in raw_posix.c

Message ID 60c0aeea2beda33af8409ff05aa8484540913ac5.1347548248.git.jcody@redhat.com
State New
Headers show

Commit Message

Jeff Cody Sept. 13, 2012, 3:49 p.m. UTC
Code motion, to move allocating aligned_buf and setting aligned_buf_size
into a helper function.

Signed-off-by: Jeff Cody <jcody@redhat.com>
---
 block/raw-posix.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

Comments

Eric Blake Sept. 13, 2012, 5:29 p.m. UTC | #1
On 09/13/2012 09:49 AM, Jeff Cody wrote:
> Code motion, to move allocating aligned_buf and setting aligned_buf_size
> into a helper function.
> 
> Signed-off-by: Jeff Cody <jcody@redhat.com>
> ---
>  block/raw-posix.c | 31 ++++++++++++++++++++++---------
>  1 file changed, 22 insertions(+), 9 deletions(-)
> 

> +    if ((bdrv_flags & BDRV_O_NOCACHE)) {
> +        /*
> +         * Allocate a buffer for read/modify/write cycles.  Chose the size

Pre-existing typo, but as long as you are moving it,

s/Chose/Choose/
diff mbox

Patch

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 4a1047c..47cab9f 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -238,6 +238,26 @@  error:
 #endif
 }
 
+static int raw_allocate_aligned_buf(uint8_t **aligned_buf,
+                                    unsigned *aligned_buf_size, int bdrv_flags)
+{
+    assert(aligned_buf != NULL);
+    assert(aligned_buf_size != NULL);
+
+    if ((bdrv_flags & BDRV_O_NOCACHE)) {
+        /*
+         * Allocate a buffer for read/modify/write cycles.  Chose the size
+         * pessimistically as we don't know the block size yet.
+         */
+        *aligned_buf_size = 32 * MAX_BLOCKSIZE;
+        *aligned_buf = qemu_memalign(MAX_BLOCKSIZE, *aligned_buf_size);
+        if (*aligned_buf == NULL) {
+            return -1;
+        }
+    }
+    return 0;
+}
+
 static int raw_open_common(BlockDriverState *bs, const char *filename,
                            int bdrv_flags, int open_flags)
 {
@@ -263,16 +283,9 @@  static int raw_open_common(BlockDriverState *bs, const char *filename,
     s->fd = fd;
     s->aligned_buf = NULL;
 
-    if ((bdrv_flags & BDRV_O_NOCACHE)) {
-        /*
-         * Allocate a buffer for read/modify/write cycles.  Chose the size
-         * pessimistically as we don't know the block size yet.
-         */
-        s->aligned_buf_size = 32 * MAX_BLOCKSIZE;
-        s->aligned_buf = qemu_memalign(MAX_BLOCKSIZE, s->aligned_buf_size);
-        if (s->aligned_buf == NULL) {
+    if (raw_allocate_aligned_buf(&s->aligned_buf, &s->aligned_buf_size,
+                                 bdrv_flags)) {
             goto out_close;
-        }
     }
 
     /* We're falling back to POSIX AIO in some cases so init always */