[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 06/19] block: move open flag parsing in raw block dr
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 06/19] block: move open flag parsing in raw block drivers to helper functions |
Date: |
Mon, 24 Sep 2012 16:26:35 +0200 |
From: Jeff Cody <address@hidden>
Code motion, to move parsing of open flags into a helper function.
Signed-off-by: Jeff Cody <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/raw-posix.c | 38 ++++++++++++++++++++++++--------------
block/raw-win32.c | 43 +++++++++++++++++++++++--------------------
2 files changed, 47 insertions(+), 34 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 5981d04..155205f 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -185,6 +185,28 @@ static int raw_normalize_devicepath(const char **filename)
}
#endif
+static void raw_parse_flags(int bdrv_flags, int *open_flags)
+{
+ assert(open_flags != NULL);
+
+ *open_flags |= O_BINARY;
+ *open_flags &= ~O_ACCMODE;
+ if (bdrv_flags & BDRV_O_RDWR) {
+ *open_flags |= O_RDWR;
+ } else {
+ *open_flags |= O_RDONLY;
+ }
+
+ /* Use O_DSYNC for write-through caching, no flags for write-back caching,
+ * and O_DIRECT for no caching. */
+ if ((bdrv_flags & BDRV_O_NOCACHE)) {
+ *open_flags |= O_DIRECT;
+ }
+ if (!(bdrv_flags & BDRV_O_CACHE_WB)) {
+ *open_flags |= O_DSYNC;
+ }
+}
+
#ifdef CONFIG_LINUX_AIO
static int raw_set_aio(void **aio_ctx, int *use_aio, int bdrv_flags)
{
@@ -228,20 +250,8 @@ static int raw_open_common(BlockDriverState *bs, const
char *filename,
return ret;
}
- s->open_flags = open_flags | O_BINARY;
- s->open_flags &= ~O_ACCMODE;
- if (bdrv_flags & BDRV_O_RDWR) {
- s->open_flags |= O_RDWR;
- } else {
- s->open_flags |= O_RDONLY;
- }
-
- /* Use O_DSYNC for write-through caching, no flags for write-back caching,
- * and O_DIRECT for no caching. */
- if ((bdrv_flags & BDRV_O_NOCACHE))
- s->open_flags |= O_DIRECT;
- if (!(bdrv_flags & BDRV_O_CACHE_WB))
- s->open_flags |= O_DSYNC;
+ s->open_flags = open_flags;
+ raw_parse_flags(bdrv_flags, &s->open_flags);
s->fd = -1;
fd = qemu_open(filename, s->open_flags, 0644);
diff --git a/block/raw-win32.c b/block/raw-win32.c
index c56bf83..335c06a 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -77,6 +77,26 @@ static int set_sparse(int fd)
NULL, 0, NULL, 0, &returned, NULL);
}
+static void raw_parse_flags(int flags, int *access_flags, DWORD *overlapped)
+{
+ assert(access_flags != NULL);
+ assert(overlapped != NULL);
+
+ if (flags & BDRV_O_RDWR) {
+ *access_flags = GENERIC_READ | GENERIC_WRITE;
+ } else {
+ *access_flags = GENERIC_READ;
+ }
+
+ *overlapped = FILE_ATTRIBUTE_NORMAL;
+ if (flags & BDRV_O_NOCACHE) {
+ *overlapped |= FILE_FLAG_NO_BUFFERING;
+ }
+ if (!(flags & BDRV_O_CACHE_WB)) {
+ *overlapped |= FILE_FLAG_WRITE_THROUGH;
+ }
+}
+
static int raw_open(BlockDriverState *bs, const char *filename, int flags)
{
BDRVRawState *s = bs->opaque;
@@ -85,17 +105,8 @@ static int raw_open(BlockDriverState *bs, const char
*filename, int flags)
s->type = FTYPE_FILE;
- if (flags & BDRV_O_RDWR) {
- access_flags = GENERIC_READ | GENERIC_WRITE;
- } else {
- access_flags = GENERIC_READ;
- }
+ raw_parse_flags(flags, &access_flags, &overlapped);
- overlapped = FILE_ATTRIBUTE_NORMAL;
- if (flags & BDRV_O_NOCACHE)
- overlapped |= FILE_FLAG_NO_BUFFERING;
- if (!(flags & BDRV_O_CACHE_WB))
- overlapped |= FILE_FLAG_WRITE_THROUGH;
s->hfile = CreateFile(filename, access_flags,
FILE_SHARE_READ, NULL,
OPEN_EXISTING, overlapped, NULL);
@@ -374,18 +385,10 @@ static int hdev_open(BlockDriverState *bs, const char
*filename, int flags)
}
s->type = find_device_type(bs, filename);
- if (flags & BDRV_O_RDWR) {
- access_flags = GENERIC_READ | GENERIC_WRITE;
- } else {
- access_flags = GENERIC_READ;
- }
+ raw_parse_flags(flags, &access_flags, &overlapped);
+
create_flags = OPEN_EXISTING;
- overlapped = FILE_ATTRIBUTE_NORMAL;
- if (flags & BDRV_O_NOCACHE)
- overlapped |= FILE_FLAG_NO_BUFFERING;
- if (!(flags & BDRV_O_CACHE_WB))
- overlapped |= FILE_FLAG_WRITE_THROUGH;
s->hfile = CreateFile(filename, access_flags,
FILE_SHARE_READ, NULL,
create_flags, overlapped, NULL);
--
1.7.6.5
- [Qemu-devel] [PULL 00/19] Block patches, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 01/19] blockdev: preserve readonly and snapshot states across media changes, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 02/19] block: correctly set the keep_read_only flag, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 03/19] block: make bdrv_set_enable_write_cache() modify open_flags, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 10/19] block: raw-posix image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 05/19] block: move aio initialization into a helper function, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 13/19] block: qcow2 image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 06/19] block: move open flag parsing in raw block drivers to helper functions,
Kevin Wolf <=
- [Qemu-devel] [PATCH 08/19] block: use BDRV_O_NOCACHE instead of s->aligned_buf in raw-posix.c, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 12/19] block: qed image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 11/19] block: raw image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 09/19] block: purge s->aligned_buf and s->aligned_buf_size from raw-posix.c, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 07/19] block: do not parse BDRV_O_CACHE_WB in block drivers, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 18/19] block: convert bdrv_commit() to use bdrv_reopen(), Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 04/19] block: Framework for reopening files safely, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 14/19] block: qcow image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 15/19] block: vmdk image file reopen, Kevin Wolf, 2012/09/24
- [Qemu-devel] [PATCH 17/19] block: vpc image file reopen, Kevin Wolf, 2012/09/24