@@ -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 */
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(-)