osdep: Fix compilation failure on BSD systems
PATCH 1/1 osdep: Fix compilation failure on BSD systems
Fix compilation failure on BSD systems (which don't have O_DIRECT or O_NOATIME:
osdep.c:116: error: ‘O_DIRECT’ undeclared (first use in this function) osdep.c:116: error: (Each undeclared identifier is reported only once osdep.c:116: error: for each function it appears in.) osdep.c:116: error: ‘O_NOATIME’ undeclared (first use in this function)
---
PS: Do we care about O_DSYNC, O_RSYNC, O_SYNC? POSIX says those can be used via fcntl() too...
osdep.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
osdep.c +7 -1
@@ -113,7 +113,13 @@ static int qemu_dup_flags(int fd, int flags) }/* Set/unset flags that we can with fcntl */ - setfl_flags =O_APPEND |O_ASYNC |O_DIRECT |O_NOATIME |O_NONBLOCK ; + setfl_flags =O_APPEND |O_ASYNC |O_NONBLOCK ; +#ifdef O_NOATIME + setfl_flags |=O_NOATIME ; +#endif +#ifdef O_DIRECT + setfl_flags |=O_DIRECT ; +#endif dup_flags &= ~setfl_flags; dup_flags |= (flags & setfl_flags);if (fcntl (ret,F_SETFL , dup_flags) ==-1 ) {
Signature · 1 line
1.7.11.4
Am 16.08.2012 13:15, schrieb Peter Maydell:
Quoted 24 lines
Fix compilation failure on BSD systems (which don't have
O_DIRECTorO_NOATIME:
osdep.c:116: error: ‘O_DIRECT’ undeclared (first use in this function) osdep.c:116: error: (Each undeclared identifier is reported only once osdep.c:116: error: for each function it appears in.) osdep.c:116: error: ‘O_NOATIME’ undeclared (first use in this function)Signed-off-by Peter Maydell <[email protected]>---
PS: Do we care aboutO_DSYNC,O_RSYNC,O_SYNC? POSIX says those can be used viafcntl()too...osdep.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)osdep.c +0
-1@@ -113,7 +113,13 @@ static int qemu_dup_flags(int fd, int flags) }/* Set/unset flags that we can with fcntl */ - setfl_flags =O_APPEND |O_ASYNC |O_DIRECT |O_NOATIME |O_NONBLOCK ;
osdep.c static int qemu_dup_flags(int fd, int flags) · line 125
Quoted 10 lines
osdep.c +7
-0+ setfl_flags =O_APPEND |O_ASYNC |O_NONBLOCK ; +#ifdef O_NOATIME + setfl_flags |=O_NOATIME ; +#endif +#ifdef O_DIRECT + setfl_flags |=O_DIRECT ; +#endif dup_flags &= ~setfl_flags; dup_flags |= (flags & setfl_flags);if (fcntl (ret,F_SETFL , dup_flags) ==-1 ) {
Would O_DSYNC be a good replacement here for an undefined O_DIRECT? block/raw-posix.c does it like that.
What about defining O_NOATIME and O_DIRECT in qemu-common.h when needed (like it is done for O_BINARY)?
But I don't want to delay 1.2, therefore
Regards,
Stefan W.
Quoted 31 lines · Stefan Weil
Am 16.08.2012 13:15, schrieb Peter Maydell:
Quoted 29 lines
Fix compilation failure on BSD systems (which don't have
O_DIRECTorO_NOATIME:
osdep.c:116: error: ‘O_DIRECT’ undeclared (first use in this function) osdep.c:116: error: (Each undeclared identifier is reported only once osdep.c:116: error: for each function it appears in.) osdep.c:116: error: ‘O_NOATIME’ undeclared (first use in this function)Signed-off-by Peter Maydell <[email protected]>---
PS: Do we care aboutO_DSYNC,O_RSYNC,O_SYNC? POSIX says those can be used viafcntl()too...osdep.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)osdep.c +6
-1@@ -113,7 +113,13 @@ static int qemu_dup_flags(int fd, int flags) }/* Set/unset flags that we can with fcntl */ - setfl_flags =O_APPEND |O_ASYNC |O_DIRECT |O_NOATIME |O_NONBLOCK ; + setfl_flags =O_APPEND |O_ASYNC |O_NONBLOCK ; +#ifdef O_NOATIME + setfl_flags |=O_NOATIME ; +#endif +#ifdef O_DIRECT + setfl_flags |=O_DIRECT ;
Quoted 8 lines
osdep.c static int qemu_dup_flags(int fd, int flags) · line 125
Quoted 4 lines
osdep.c +1
-0+#endif dup_flags &= ~setfl_flags; dup_flags |= (flags & setfl_flags);if (fcntl (ret,F_SETFL , dup_flags) ==-1 ) {Would
O_DSYNCbe a good replacement here for an undefinedO_DIRECT?block/raw-posix.cdoes it like that.
I think it would be better to have this function handle O_DSYNC as a flag to go in setfl_flags independently of whether O_DIRECT is defined or not; at this level I don't think it makes sense to try to #define O_DIRECT O_DSYNC (we are interpreting flags given us by a caller, not picking flags to try to get the behaviour we want from a function we're going to call).
Quoted 2 lines
What about defining
O_NOATIMEandO_DIRECTinqemu-common.hwhen needed (like it is done forO_BINARY)?
Again, I think that would be a fix at the wrong level: it might be OK if we wanted to allow people to call this function with those flags even if the host OS didn't know about them, but it's not what you need to make the function itself perform correctly. What we might want is to add
#ifdef O_DSYNC
setfl_flags |= O_DSYNC;#endif
etc, but I'm not sure about that.
Quoted 3 lines
But I don't want to delay 1.2, therefore
Reviewed-by Stefan Weil <[email protected]>
Thanks; this is indeed really just a minimal "make it compile" fix.
-- PMM
Quoted 11 lines · Peter Maydell
Fix compilation failure on BSD systems (which don't have
O_DIRECTorO_NOATIME:
osdep.c:116: error: ‘O_DIRECT’ undeclared (first use in this function) osdep.c:116: error: (Each undeclared identifier is reported only once osdep.c:116: error: for each function it appears in.) osdep.c:116: error: ‘O_NOATIME’ undeclared (first use in this function)Signed-off-by Peter Maydell <[email protected]>---
PS: Do we care aboutO_DSYNC,O_RSYNC,O_SYNC? POSIX says those can be used viafcntl()too...
Thanks very much Peter. The patch looks good to me.
Could you point me to the reference you saw the fcntl description in? I didn't notice any flags mentioned here: http://pubs.opengroup.org/onlinepubs/009695399/functions/fcntl.html
The choice of flags was based on the Linux man page for fcntl() which says F_SETFL can change only the O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME, and O_NONBLOCK flags.
Signature · 2 lines
Regards, Corey
Quoted 19 lines · Corey Bryant
Quoted 8 lines · Peter Maydell
Fix compilation failure on BSD systems (which don't have
O_DIRECTorO_NOATIME:
osdep.c:116: error: ‘O_DIRECT’ undeclared (first use in this function) osdep.c:116: error: (Each undeclared identifier is reported only once osdep.c:116: error: for each function it appears in.) osdep.c:116: error: ‘O_NOATIME’ undeclared (first use in this function)Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>---
PS: Do we care aboutO_DSYNC,O_RSYNC,O_SYNC? POSIX says those can be used viafcntl()too...Thanks very much Peter. The patch looks good to me.
Quoted 7 lines
Could you point me to the reference you saw the fcntl description in? I didn't notice any flags mentioned here:
http://pubs.opengroup.org/onlinepubs/009695399/functions/fcntl.htmlThe choice of flags was based on the Linux man page for
fcntl()which saysF_SETFLcan change only theO_APPEND,O_ASYNC,O_DIRECT,O_NOATIME, andO_NONBLOCKflags.
The posix spec for fcntl.h
http://pubs.opengroup.org/onlinepubs/007908799/xsh/fcntl.h.html
describes all of O_APPEND O_DSYNC O_NONBLOCK O_RSYNC O_SYNC as "File status flags used for open() and fcntl()".
(However the MacOS fcntl manpage lists only O_APPEND, O_ASYNC and O_NONBLOCK for F_GETFL/F_SETFL flags.)
-- PMM