mirror of https://github.com/xemu-project/xemu.git
block: move open flag parsing in raw block drivers to helper functions
Code motion, to move parsing of open flags into a helper function. Signed-off-by: Jeff Cody <jcody@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
fc32a72dc1
commit
6a8dc0422e
|
@ -185,6 +185,28 @@ static int raw_normalize_devicepath(const char **filename)
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
#ifdef CONFIG_LINUX_AIO
|
||||||
static int raw_set_aio(void **aio_ctx, int *use_aio, int bdrv_flags)
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->open_flags = open_flags | O_BINARY;
|
s->open_flags = open_flags;
|
||||||
s->open_flags &= ~O_ACCMODE;
|
raw_parse_flags(bdrv_flags, &s->open_flags);
|
||||||
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->fd = -1;
|
s->fd = -1;
|
||||||
fd = qemu_open(filename, s->open_flags, 0644);
|
fd = qemu_open(filename, s->open_flags, 0644);
|
||||||
|
|
|
@ -77,6 +77,26 @@ static int set_sparse(int fd)
|
||||||
NULL, 0, NULL, 0, &returned, NULL);
|
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)
|
static int raw_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
{
|
{
|
||||||
BDRVRawState *s = bs->opaque;
|
BDRVRawState *s = bs->opaque;
|
||||||
|
@ -85,17 +105,8 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
|
|
||||||
s->type = FTYPE_FILE;
|
s->type = FTYPE_FILE;
|
||||||
|
|
||||||
if (flags & BDRV_O_RDWR) {
|
raw_parse_flags(flags, &access_flags, &overlapped);
|
||||||
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;
|
|
||||||
s->hfile = CreateFile(filename, access_flags,
|
s->hfile = CreateFile(filename, access_flags,
|
||||||
FILE_SHARE_READ, NULL,
|
FILE_SHARE_READ, NULL,
|
||||||
OPEN_EXISTING, overlapped, 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);
|
s->type = find_device_type(bs, filename);
|
||||||
|
|
||||||
if (flags & BDRV_O_RDWR) {
|
raw_parse_flags(flags, &access_flags, &overlapped);
|
||||||
access_flags = GENERIC_READ | GENERIC_WRITE;
|
|
||||||
} else {
|
|
||||||
access_flags = GENERIC_READ;
|
|
||||||
}
|
|
||||||
create_flags = OPEN_EXISTING;
|
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,
|
s->hfile = CreateFile(filename, access_flags,
|
||||||
FILE_SHARE_READ, NULL,
|
FILE_SHARE_READ, NULL,
|
||||||
create_flags, overlapped, NULL);
|
create_flags, overlapped, NULL);
|
||||||
|
|
Loading…
Reference in New Issue