On 08/10/2012 07:15 PM, Corey Bryant wrote: > > > On 07/30/2012 05:34 PM, Supriya Kannery wrote:
>> +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)); >> + raw_stash_state(raw_rs->stash_s, s); >> + s->fd = dup3(raw_rs->stash_s->fd, s->fd, O_CLOEXEC); >> + >> + *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); > > Will this allow the fdset refcount to get to zero? I was hoping your > patches would prevent that from happening. Perhaps Kevin or Eric can > weigh in. qemu_open() increments the refcount for an fdset when an fd > from it is used, and qemu_close() decrements it. I think if you were > able to perform the open before the close here that refcount wouldn't > get to zero. > Since we are duping the file descriptor before reaching this bdrv_close(), refcount for fd won't become zero. - thanks, Supriya