From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:56572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rv91B-0007p1-QW for qemu-devel@nongnu.org; Wed, 08 Feb 2012 10:01:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rv911-0003E3-2Z for qemu-devel@nongnu.org; Wed, 08 Feb 2012 10:01:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51064) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rv910-0003Dr-L1 for qemu-devel@nongnu.org; Wed, 08 Feb 2012 10:00:59 -0500 Message-ID: <4F328E9F.1040106@redhat.com> Date: Wed, 08 Feb 2012 16:02:55 +0100 From: Kevin Wolf MIME-Version: 1.0 References: <20120201030557.2990.74150.sendpatchset@skannery.in.ibm.com> <20120201030726.2990.68290.sendpatchset@skannery.in.ibm.com> In-Reply-To: <20120201030726.2990.68290.sendpatchset@skannery.in.ibm.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC Patch 6/7]Qemu: raw-win32 image file reopen List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Supriya Kannery Cc: Stefan Hajnoczi , Christoph Hellwig , qemu-devel@nongnu.org, Luiz Capitulino Am 01.02.2012 04:07, schrieb Supriya Kannery: > win32 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 > > Index: qemu/block/raw-win32.c > =================================================================== > --- qemu.orig/block/raw-win32.c > +++ qemu/block/raw-win32.c > @@ -26,18 +26,27 @@ > #include "block_int.h" > #include "module.h" > #include > +#include > #include > > #define FTYPE_FILE 0 > #define FTYPE_CD 1 > #define FTYPE_HARDDISK 2 > +#define WINDOWS_VISTA 6 > > typedef struct BDRVRawState { > HANDLE hfile; > int type; > char drive_path[16]; /* format: "d:\" */ > + DWORD overlapped; > } BDRVRawState; > > +typedef struct BDRVRawReopenState { > + BDRVReopenState reopen_state; > + HANDLE stash_hfile; > + DWORD stash_overlapped; > +} BDRVRawReopenState; > + > int qemu_ftruncate64(int fd, int64_t length) > { > LARGE_INTEGER li; > @@ -106,9 +115,96 @@ static int raw_open(BlockDriverState *bs > return -EACCES; > return -1; > } > + s->overlapped = overlapped; > return 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; > + OSVERSIONINFO osvi; > + BOOL bIsWindowsVistaorLater; > + > + raw_rs->bs = bs; > + raw_rs->stash_hfile = s->hfile; > + raw_rs->stash_overlapped = s->overlapped; > + *prs = raw_rs; > + > + if (flags & BDRV_O_NOCACHE) { > + s->overlapped |= FILE_FLAG_NO_BUFFERING; > + } else { > + s->overlapped &= ~FILE_FLAG_NO_BUFFERING; > + } > + > + if (!(flags & BDRV_O_CACHE_WB)) { > + s->overlapped |= FILE_FLAG_WRITE_THROUGH; > + } else { > + s->overlapped &= ~FILE_FLAG_WRITE_THROUGH; > + } > + > + ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); > + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); > + > + GetVersionEx(&osvi); > + > + if (osvi.dwMajorVersion >= WINDOWS_VISTA) { > + s->hfile = ReOpenFile(raw_rs->stash_hfile, 0, FILE_SHARE_READ, > + overlapped); > + if (s->hfile == INVALID_HANDLE_VALUE) { > + int err = GetLastError(); > + if (err == ERROR_ACCESS_DENIED) { > + ret = -EACCES; > + } else { > + ret = -1; Returning -1 where -errno is expected is bad (turns out as -EPERM on Linux, which is misleading). Maybe -EIO here. Kevin