[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 07/16] block: move allocating aligned_buf into a
From: |
Jeff Cody |
Subject: |
[Qemu-devel] [PATCH v2 07/16] block: move allocating aligned_buf into a helper function in raw_posix.c |
Date: |
Thu, 13 Sep 2012 11:49:45 -0400 |
Code motion, to move allocating aligned_buf and setting aligned_buf_size
into a helper function.
Signed-off-by: Jeff Cody <address@hidden>
---
block/raw-posix.c | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
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 */
--
1.7.11.4
- [Qemu-devel] [PATCH v2 10/16] block: qed image file reopen, (continued)
[Qemu-devel] [PATCH v2 08/16] block: raw-posix image file reopen, Jeff Cody, 2012/09/13
[Qemu-devel] [PATCH v2 07/16] block: move allocating aligned_buf into a helper function in raw_posix.c,
Jeff Cody <=
[Qemu-devel] [PATCH v2 11/16] block: qcow2 image file reopen, Jeff Cody, 2012/09/13
[Qemu-devel] [PATCH v2 16/16] block: remove keep_read_only flag from BlockDriverState struct, Jeff Cody, 2012/09/13
[Qemu-devel] [PATCH v2 05/16] block: move open flag parsing in raw block drivers to helper functions, Jeff Cody, 2012/09/13
[Qemu-devel] [PATCH v2 15/16] block: convert bdrv_commit() to use bdrv_reopen(), Jeff Cody, 2012/09/13
[Qemu-devel] [PATCH v2 14/16] block: raw-win32 driver reopen support, Jeff Cody, 2012/09/13
[Qemu-devel] [PATCH v2 12/16] block: qcow image file reopen, Jeff Cody, 2012/09/13
[Qemu-devel] [PATCH v2 13/16] block: vmdk image file reopen, Jeff Cody, 2012/09/13