diff options
author | Zhang Qiang <qiang.z.zhang@intel.com> | 2012-05-29 12:22:00 +0800 |
---|---|---|
committer | Zhang Qiang <qiang.z.zhang@intel.com> | 2012-05-29 12:22:00 +0800 |
commit | 02f0634ac29e19c68279e5544cac963e7f1203b8 (patch) | |
tree | b983472f94ef063cedf866d8ecfb55939171779d /os_qnx/os_qnx_fsync.c | |
parent | e776056ea09ba0b6d9505ced6913c9190a12d632 (diff) | |
download | db4-master.tar.gz db4-master.tar.bz2 db4-master.zip |
Diffstat (limited to 'os_qnx/os_qnx_fsync.c')
-rw-r--r-- | os_qnx/os_qnx_fsync.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/os_qnx/os_qnx_fsync.c b/os_qnx/os_qnx_fsync.c new file mode 100644 index 0000000..f22f995 --- /dev/null +++ b/os_qnx/os_qnx_fsync.c @@ -0,0 +1,73 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 1997-2009 Oracle. All rights reserved. + * + * $Id$ + */ + +#include "db_config.h" + +#include "db_int.h" + +/* + * QNX has special requirements on FSYNC: if the file is a shared memory + * object, we can not call fsync because it is not implemented, instead, + * we set the O_DSYNC flag to the file descriptor and then do an empty + * write so that all data are synced. We only sync this way if the file + * is a shared memory object, other types of ordinary files are still synced + * using fsync, to be not only faster but also atomic. + * We don't just set the O_DSYNC flag on open, since it would force all writes + * to be sync'ed. And we remove the O_DSYNC if it is not originally set to + * the file descriptor before passed in to this function. + * This is slightly different to the VxWorks and hp code above, since QNX does + * supply a fsync call, it just has a unique requirement. + */ +int +__qnx_fsync(fhp) + DB_FH *fhp; +{ + int ret; + int fd, unset, flags; + + fd = fhp->fd; + unset = 1; + ret = flags = 0; + if (F_ISSET(fhp, DB_FH_REGION)) + { + RETRY_CHK(fcntl(fd, F_GETFL), ret); + if (ret == -1) + goto err; + /* + * if already has O_DSYNC flag, we can't remove it + * after the empty write + */ + if (ret & O_DSYNC != 0) + unset = 0; + else { + ret |= O_DSYNC; + flags = ret; + RETRY_CHK(fcntl(fd, F_SETFL, flags), ret); + if (ret == -1) + goto err; + } + /* Do an empty write, to force a sync */ + RETRY_CHK(write(fd, "", 0), ret); + if (ret == -1) + goto err; + /* remove the O_DSYNC flag if necessary */ + if (unset) { + RETRY_CHK(fcntl(fd, F_GETFL), ret); + if (ret == -1) + goto err; + ret &= ~O_DSYNC; + flags = ret; + RETRY_CHK(fcntl(fd, F_SETFL, flags), ret); + if (ret == -1) + goto err; + } + } else + RETRY_CHK(fdatasync(fd), ret); + +err: return (ret); +} |