static int do_sync (int fd, u_int32_t flags) { if (flags & SYNC_THREAD) return toggle_sync_thread (fd, flags, sSYNC); return fd_sync (fd, flags); }
static void* thread_run (void* arg) { int rc = 0; long l = 0; size_t nsync = 0; (void) arg; (void) printf ("Thread %ld started\n", (long)pthread_self()); rc = pthread_mutex_lock (&g_st.mtx); if (rc) { (void) fprintf (stderr, "\npthread_mutex_lock error [%d]\n", rc); return (void*)(l = rc); } do { while (sWAIT == g_st.state) { rc = pthread_cond_wait (&g_st.cond, &g_st.mtx); } if (sSYNC == g_st.state || sQUIT == g_st.state) { rc = fd_sync (g_st.fd, g_st.flags); if (rc) { (void) fprintf (stderr, "\n%s: fd_sync error %d\n", __func__, rc); break; } ++nsync; } if (sQUIT == g_st.state) break; else g_st.state = sWAIT; } while (1); rc = pthread_mutex_unlock (&g_st.mtx); if (rc) { (void) fprintf (stderr, "\npthread_mutex_unlock error [%d]\n", rc); return (void*)(l = rc); } (void) printf ("%ld syncs, thread %ld is exiting\n", (long)nsync, (long)pthread_self()); return NULL; }
int openwritenclose_unsafe_internal (char const *fn, char const *s, unsigned int len, uint64 *dev, uint64 *ino, int dosync) { struct stat st ; int fd = open_trunc(fn) ; if (fd < 0) return 0 ; if (allwrite(fd, s, len) < len) goto fail ; if ((dev || ino) && (fstat(fd, &st) < 0)) goto fail ; if (dosync && (fd_sync(fd) < 0) && (errno != EINVAL)) goto fail ; fd_close(fd) ; if (dev) *dev = (uint64)st.st_dev ; if (ino) *ino = (uint64)st.st_ino ; return 1 ; fail: { register int e = errno ; fd_close(fd) ; unlink(fn) ; errno = e ; } return 0 ; }
COMMIT3res *nfsproc3_commit_3_svc(COMMIT3args * argp, struct svc_req * rqstp) { static COMMIT3res result; char *path; int res; PREP(path, argp->file); result.status = join(is_reg(), exports_rw()); if (result.status == NFS3_OK) { res = fd_sync(argp->file); if (res != -1) memcpy(result.COMMIT3res_u.resok.verf, wverf, NFS3_WRITEVERFSIZE); else /* error during fsync() or close() */ result.status = NFS3ERR_IO; } /* overlaps with resfail */ result.COMMIT3res_u.resfail.file_wcc.before = get_pre_cached(); result.COMMIT3res_u.resfail.file_wcc.after = get_post_stat(path, rqstp); return &result; }