[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC Patch 5/7]Qemu: raw-posix image file reopen
From: |
Kevin Wolf |
Subject: |
Re: [Qemu-devel] [RFC Patch 5/7]Qemu: raw-posix image file reopen |
Date: |
Wed, 08 Feb 2012 15:54:40 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0 |
Am 01.02.2012 04:07, schrieb Supriya Kannery:
> raw-posix driver changes for bdrv_reopen_xx functions to
> safely reopen image files. Reopening of image files while
> changing hostcache dynamically is handled here.
>
> Signed-off-by: Supriya Kannery <address@hidden>
>
> Index: qemu/block/raw.c
> ===================================================================
> --- qemu.orig/block/raw.c
> +++ qemu/block/raw.c
> @@ -9,6 +9,22 @@ static int raw_open(BlockDriverState *bs
> return 0;
> }
>
> +static int raw_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs,
> + int flags)
> +{
> + return bdrv_reopen_prepare(bs->file, prs, flags);
> +}
> +
> +static void raw_reopen_commit(BlockDriverState *bs, BDRVReopenState *rs)
> +{
> + bdrv_reopen_commit(bs->file, rs);
> +}
> +
> +static void raw_reopen_abort(BlockDriverState *bs, BDRVReopenState *rs)
> +{
> + bdrv_reopen_abort(bs->file, rs);
> +}
> +
> static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t
> sector_num,
> int nb_sectors, QEMUIOVector *qiov)
> {
> @@ -109,6 +125,10 @@ static BlockDriver bdrv_raw = {
> .instance_size = 1,
>
> .bdrv_open = raw_open,
> + .bdrv_reopen_prepare
> + = raw_reopen_prepare,
You can just indent to the next level instead of line wrapping.
> + .bdrv_reopen_commit = raw_reopen_commit,
> + .bdrv_reopen_abort = raw_reopen_abort,
> .bdrv_close = raw_close,
>
> .bdrv_co_readv = raw_co_readv,
> Index: qemu/block/raw-posix.c
> ===================================================================
> --- qemu.orig/block/raw-posix.c
> +++ qemu/block/raw-posix.c
> @@ -136,6 +136,11 @@ typedef struct BDRVRawState {
> #endif
> } BDRVRawState;
>
> +typedef struct BDRVRawReopenState {
> + BDRVReopenState reopen_state;
> + BDRVRawState *stash_s;
> +} BDRVRawReopenState;
See Stefan's comment. If it's possible to save only the fd and maybe one
or two other fields, then we should do that.
> static int fd_open(BlockDriverState *bs);
> static int64_t raw_getlength(BlockDriverState *bs);
>
> @@ -279,6 +284,71 @@ static int raw_open(BlockDriverState *bs
> return raw_open_common(bs, filename, flags, 0);
> }
>
> +static int raw_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs,
> + int flags)
> +{
> + BDRVRawReopenState *raw_rs = g_malloc0(sizeof(BDRVRawReopenState));
> + BDRVRawState *s = bs->opaque;
> + int ret = 0;
> +
> + raw_rs->reopen_state.bs = bs;
> +
> + /* stash state before reopen */
> + raw_rs->stash_s = g_malloc0(sizeof(BDRVRawState));
> + memcpy(raw_rs->stash_s, s, sizeof(BDRVRawState));
> + s->fd = dup(raw_rs->stash_s->fd);
> +
> + *prs = &(raw_rs->reopen_state);
> +
> + /* Flags that can be set using fcntl */
> + int fcntl_flags = BDRV_O_NOCACHE;
> +
> + if ((bs->open_flags & ~fcntl_flags) == (flags & ~fcntl_flags)) {
> + if ((flags & BDRV_O_NOCACHE)) {
> + s->open_flags |= O_DIRECT;
> + } else {
> + s->open_flags &= ~O_DIRECT;
> + }
> + printf("O_DIRECT flag\n");
Debugging leftover?
> + ret = fcntl_setfl(s->fd, s->open_flags);
> + } else {
> +
> + printf("close and open with new flags\n");
Same here.
Kevin