On Fri, Nov 11, 2011 at 6:48 AM, Supriya Kannery <supri...@linux.vnet.ibm.com> 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.reopen_flags = s->open_flags; > + raw_rs->reopen_state.bs = bs; > + raw_rs->reopen_fd = -1; > + *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)) { > + raw_rs->reopen_fd = dup(s->fd); > + if (raw_rs->reopen_fd <= 0) { > + return -1;
return -errno; > + } > + if ((flags & BDRV_O_NOCACHE)) { > + raw_rs->reopen_state.reopen_flags |= O_DIRECT; > + } else { > + raw_rs->reopen_state.reopen_flags &= ~O_DIRECT; > + } > + ret = fcntl_setfl(raw_rs->reopen_fd, > raw_rs->reopen_state.reopen_flags); I wonder if this works on Solaris, FreeBSD, etc? Perhaps there needs to be a fallback to the missing "else" case below... > + } else { > + > + /* TBD: Handle O_DSYNC and other flags. For now return error */ > + ret = -1; ...and this needs to be implemented. > + } > + return ret; > +} Stefan