On 06/15/2012 02:48 PM, Supriya Kannery wrote: > 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 > > > +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)); */ Why the comment? > + raw_stash_state(raw_rs->stash_s, s); > + s->fd = dup(raw_rs->stash_s->fd); Needs to handle O_CLOEXEC open flag, which means using fcntl(F_DUPFD_CLOEXEC) when available for atomic support, and a fallback to fcntl(F_GETFD/F_SETFD) if not. > + > + *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; > + } > + ret = fcntl_setfl(s->fd, s->open_flags); > + } else { > + > + /* close and reopen using new flags */ > + bs->drv->bdrv_close(bs); > + ret = bs->drv->bdrv_file_open(bs, bs->filename, flags); Is this a case where Paolo's proposed bdrv_swap command would be useful? > + /* revert to stashed state */ > + if (s->fd != -1) { > + close(s->fd); > + } > +/* memcpy(s, raw_rs->stash_s, sizeof(BDRVRawState)); */ Why the comment? -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org