2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* ihandle.c - file descriptor cacheing for Inode handles. */
12 /************************************************************************/
14 #include <afsconfig.h>
15 #include <afs/param.h>
20 #include <sys/types.h>
29 #if defined(AFS_SUN5_ENV) || defined(AFS_NBSD_ENV)
30 #include <sys/fcntl.h>
31 #include <sys/resource.h>
36 #include <afs/afsint.h>
38 #include <afs/afssyscalls.h>
41 #include "viceinode.h"
42 #include "afs/afs_assert.h"
47 #define afs_stat stat64
48 #define afs_fstat fstat64
49 #else /* !O_LARGEFILE */
51 #define afs_fstat fstat
52 #endif /* !O_LARGEFILE */
53 #endif /* AFS_NT40_ENV */
55 #ifdef AFS_PTHREAD_ENV
56 pthread_once_t ih_glock_once = PTHREAD_ONCE_INIT;
57 pthread_mutex_t ih_glock_mutex;
58 #endif /* AFS_PTHREAD_ENV */
60 /* Linked list of available inode handles */
61 IHandle_t *ihAvailHead;
62 IHandle_t *ihAvailTail;
64 /* Linked list of available file descriptor handles */
65 FdHandle_t *fdAvailHead;
66 FdHandle_t *fdAvailTail;
68 /* Linked list of available stream descriptor handles */
69 StreamHandle_t *streamAvailHead;
70 StreamHandle_t *streamAvailTail;
72 /* LRU list for file descriptor handles */
73 FdHandle_t *fdLruHead;
74 FdHandle_t *fdLruTail;
77 int ih_PkgDefaultsSet = 0;
79 /* Most of the servers use fopen/fdopen. Since the FILE structure
80 * only has eight bits for the file descriptor, the cache size
81 * has to be less than 256. The cache can be made larger as long
82 * as you are sure you don't need fopen/fdopen. */
84 /* As noted in ihandle.h, the fileno member of FILE on most platforms
85 * in 2008 is a 16- or 32-bit signed int. -Matt
87 int fdMaxCacheSize = 0;
90 /* Number of in use file descriptors */
93 /* Hash table for inode handles */
94 IHashBucket_t ihashTable[I_HANDLE_HASH_SIZE];
96 void *ih_sync_thread(void *);
98 /* start-time configurable I/O limits */
99 ih_init_params vol_io_params;
101 void ih_PkgDefaults(void)
104 ih_PkgDefaultsSet = 1;
106 /* default to well-known values */
107 vol_io_params.fd_handle_setaside = FD_HANDLE_SETASIDE;
109 /* initial fd cachesize. the only one that will be used if
110 * the application does not call ih_UseLargeCache(). set this
111 * to a value representable in fileno member of the system's
112 * FILE structure (or equivalent). */
113 vol_io_params.fd_initial_cachesize = FD_DEFAULT_CACHESIZE;
115 /* fd cache size that will be used if/when ih_UseLargeCache()
117 vol_io_params.fd_max_cachesize = FD_MAX_CACHESIZE;
120 #ifdef AFS_PTHREAD_ENV
121 /* Initialize the global ihandle mutex */
125 MUTEX_INIT(&ih_glock_mutex, "ih glock", MUTEX_DEFAULT, 0);
127 #endif /* AFS_PTHREAD_ENV */
129 /* Initialize the file descriptor cache */
134 osi_Assert(!ih_Inited);
136 DLL_INIT_LIST(ihAvailHead, ihAvailTail);
137 DLL_INIT_LIST(fdAvailHead, fdAvailTail);
138 DLL_INIT_LIST(fdLruHead, fdLruTail);
139 for (i = 0; i < I_HANDLE_HASH_SIZE; i++) {
140 DLL_INIT_LIST(ihashTable[i].ihash_head, ihashTable[i].ihash_tail);
142 #if defined(AFS_NT40_ENV)
143 fdMaxCacheSize = vol_io_params.fd_max_cachesize;
144 #elif defined(AFS_SUN5_ENV) || defined(AFS_NBSD_ENV)
147 osi_Assert(getrlimit(RLIMIT_NOFILE, &rlim) == 0);
148 rlim.rlim_cur = rlim.rlim_max;
149 osi_Assert(setrlimit(RLIMIT_NOFILE, &rlim) == 0);
150 fdMaxCacheSize = rlim.rlim_cur - vol_io_params.fd_handle_setaside;
152 /* XXX this is to avoid using up all system fd netbsd is
153 * somewhat broken and have set maximum fd for a root process
154 * to the same as system fd that is avaible, so if the
155 * fileserver uses all up process fds, all system fd will be
158 * Check for this better
162 fdMaxCacheSize = MIN(fdMaxCacheSize, vol_io_params.fd_max_cachesize);
163 osi_Assert(fdMaxCacheSize > 0);
165 #elif defined(AFS_HPUX_ENV)
166 /* Avoid problems with "UFSOpen: igetinode failed" panics on HPUX 11.0 */
170 long fdMax = MAX(sysconf(_SC_OPEN_MAX) - vol_io_params.fd_handle_setaside,
172 fdMaxCacheSize = (int)MIN(fdMax, vol_io_params.fd_max_cachesize);
175 fdCacheSize = MIN(fdMaxCacheSize, vol_io_params.fd_initial_cachesize);
178 #ifdef AFS_PTHREAD_ENV
180 pthread_attr_t tattr;
182 pthread_attr_init(&tattr);
183 pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
185 pthread_create(&syncer, &tattr, ih_sync_thread, NULL);
186 #else /* AFS_PTHREAD_ENV */
188 LWP_CreateProcess(ih_sync_thread, 16*1024, LWP_MAX_PRIORITY - 2,
189 NULL, "ih_syncer", &syncer);
190 #endif /* AFS_PTHREAD_ENV */
195 /* Make the file descriptor cache as big as possible. Don't this call
196 * if the program uses fopen or fdopen, if fd_max_cachesize cannot be
197 * represented in the fileno member of the system FILE structure (or
201 ih_UseLargeCache(void)
205 if (!ih_PkgDefaultsSet) {
213 fdCacheSize = fdMaxCacheSize;
218 /* Allocate a chunk of inode handles */
220 iHandleAllocateChunk(void)
225 osi_Assert(ihAvailHead == NULL);
226 ihP = (IHandle_t *) malloc(I_HANDLE_MALLOCSIZE * sizeof(IHandle_t));
227 osi_Assert(ihP != NULL);
228 for (i = 0; i < I_HANDLE_MALLOCSIZE; i++) {
229 ihP[i].ih_refcnt = 0;
230 DLL_INSERT_TAIL(&ihP[i], ihAvailHead, ihAvailTail, ih_next, ih_prev);
234 /* Initialize an inode handle */
236 ih_init(int dev, int vid, Inode ino)
238 int ihash = IH_HASH(dev, vid, ino);
241 if (!ih_PkgDefaultsSet) {
250 /* Do we already have a handle for this Inode? */
251 for (ihP = ihashTable[ihash].ihash_head; ihP; ihP = ihP->ih_next) {
252 if (ihP->ih_ino == ino && ihP->ih_vid == vid && ihP->ih_dev == dev) {
259 /* Allocate and initialize a new Inode handle */
260 if (ihAvailHead == NULL) {
261 iHandleAllocateChunk();
264 osi_Assert(ihP->ih_refcnt == 0);
265 DLL_DELETE(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
272 DLL_INIT_LIST(ihP->ih_fdhead, ihP->ih_fdtail);
273 DLL_INSERT_TAIL(ihP, ihashTable[ihash].ihash_head,
274 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
279 /* Copy an inode handle */
281 ih_copy(IHandle_t * ihP)
284 osi_Assert(ih_Inited);
285 osi_Assert(ihP->ih_refcnt > 0);
291 /* Allocate a chunk of file descriptor handles */
293 fdHandleAllocateChunk(void)
298 osi_Assert(fdAvailHead == NULL);
299 fdP = (FdHandle_t *) malloc(FD_HANDLE_MALLOCSIZE * sizeof(FdHandle_t));
300 osi_Assert(fdP != NULL);
301 for (i = 0; i < FD_HANDLE_MALLOCSIZE; i++) {
302 fdP[i].fd_status = FD_HANDLE_AVAIL;
303 fdP[i].fd_refcnt = 0;
305 fdP[i].fd_fd = INVALID_FD;
306 fdP[i].fd_ihnext = NULL;
307 fdP[i].fd_ihprev = NULL;
308 DLL_INSERT_TAIL(&fdP[i], fdAvailHead, fdAvailTail, fd_next, fd_prev);
312 /* Allocate a chunk of stream handles */
314 streamHandleAllocateChunk(void)
317 StreamHandle_t *streamP;
319 osi_Assert(streamAvailHead == NULL);
320 streamP = (StreamHandle_t *)
321 malloc(STREAM_HANDLE_MALLOCSIZE * sizeof(StreamHandle_t));
322 osi_Assert(streamP != NULL);
323 for (i = 0; i < STREAM_HANDLE_MALLOCSIZE; i++) {
324 streamP[i].str_fd = INVALID_FD;
325 DLL_INSERT_TAIL(&streamP[i], streamAvailHead, streamAvailTail,
331 * Get a file descriptor handle given an Inode handle
334 ih_open(IHandle_t * ihP)
340 if (!ihP) /* XXX should log here in the fileserver */
345 /* Do we already have an open file handle for this Inode? */
346 for (fdP = ihP->ih_fdtail; fdP != NULL; fdP = fdP->fd_ihprev) {
349 * If we don't have positional i/o, don't try to share fds, since
350 * we can't do so in a threadsafe way.
352 if (fdP->fd_status != FD_HANDLE_INUSE) {
353 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
355 if (fdP->fd_status != FD_HANDLE_AVAIL) {
356 #endif /* HAVE_PIO */
358 if (fdP->fd_status == FD_HANDLE_OPEN) {
359 fdP->fd_status = FD_HANDLE_INUSE;
360 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
369 * Try to open the Inode, return NULL on error.
376 if (fd == INVALID_FD && (errno != EMFILE || fdLruHead == NULL) ) {
382 /* fdCacheSize limits the size of the descriptor cache, but
383 * we permit the number of open files to exceed fdCacheSize.
384 * We only recycle open file descriptors when the number
385 * of open files reaches the size of the cache */
386 if ((fdInUseCount > fdCacheSize || fd == INVALID_FD) && fdLruHead != NULL) {
388 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
389 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
390 DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail,
391 fd_ihnext, fd_ihprev);
392 closeFd = fdP->fd_fd;
393 if (fd == INVALID_FD) {
394 fdCacheSize--; /* reduce in order to not run into here too often */
395 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
396 fdP->fd_status = FD_HANDLE_AVAIL;
398 fdP->fd_fd = INVALID_FD;
404 if (fdAvailHead == NULL) {
405 fdHandleAllocateChunk();
408 osi_Assert(fdP->fd_status == FD_HANDLE_AVAIL);
409 DLL_DELETE(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
410 closeFd = INVALID_FD;
413 fdP->fd_status = FD_HANDLE_INUSE;
420 /* Add this handle to the Inode's list of open descriptors */
421 DLL_INSERT_TAIL(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
424 if (closeFd != INVALID_FD) {
436 * Return a file descriptor handle to the cache
439 fd_close(FdHandle_t * fdP)
447 osi_Assert(ih_Inited);
448 osi_Assert(fdInUseCount > 0);
449 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
453 /* Call fd_reallyclose to really close the unused file handles if
454 * the previous attempt to close (ih_reallyclose()) all file handles
455 * failed (this is determined by checking the ihandle for the flag
456 * IH_REALLY_CLOSED) or we have too many open files.
458 if (ihP->ih_flags & IH_REALLY_CLOSED || fdInUseCount > fdCacheSize) {
460 return fd_reallyclose(fdP);
464 if (fdP->fd_refcnt == 0) {
465 /* Put this descriptor back into the cache */
466 fdP->fd_status = FD_HANDLE_OPEN;
467 DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
470 /* If this is not the only reference to the Inode then we can decrement
471 * the reference count, otherwise we need to call ih_release.
473 if (ihP->ih_refcnt > 1) {
485 * Actually close the file descriptor handle and return it to
489 fd_reallyclose(FdHandle_t * fdP)
498 osi_Assert(ih_Inited);
499 osi_Assert(fdInUseCount > 0);
500 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
503 closeFd = fdP->fd_fd;
506 if (fdP->fd_refcnt == 0) {
507 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev);
508 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
510 fdP->fd_status = FD_HANDLE_AVAIL;
513 fdP->fd_fd = INVALID_FD;
516 /* All the file descriptor handles have been closed; reset
517 * the IH_REALLY_CLOSED flag indicating that ih_reallyclose
518 * has completed its job.
520 if (!ihP->ih_fdhead) {
521 ihP->ih_flags &= ~IH_REALLY_CLOSED;
524 if (fdP->fd_refcnt == 0) {
531 /* If this is not the only reference to the Inode then we can decrement
532 * the reference count, otherwise we need to call ih_release. */
533 if (ihP->ih_refcnt > 1) {
544 /* Enable buffered I/O on a file descriptor */
546 stream_fdopen(FD_t fd)
548 StreamHandle_t *streamP;
551 if (streamAvailHead == NULL) {
552 streamHandleAllocateChunk();
554 streamP = streamAvailHead;
555 DLL_DELETE(streamP, streamAvailHead, streamAvailTail, str_next, str_prev);
557 streamP->str_fd = fd;
558 streamP->str_buflen = 0;
559 streamP->str_bufoff = 0;
560 streamP->str_fdoff = 0;
561 streamP->str_error = 0;
562 streamP->str_eof = 0;
563 streamP->str_direction = STREAM_DIRECTION_NONE;
567 /* Open a file for buffered I/O */
569 stream_open(const char *filename, const char *mode)
571 FD_t fd = INVALID_FD;
573 if (strcmp(mode, "r") == 0) {
574 fd = OS_OPEN(filename, O_RDONLY, 0);
575 } else if (strcmp(mode, "r+") == 0) {
576 fd = OS_OPEN(filename, O_RDWR, 0);
577 } else if (strcmp(mode, "w") == 0) {
578 fd = OS_OPEN(filename, O_WRONLY | O_TRUNC | O_CREAT, 0);
579 } else if (strcmp(mode, "w+") == 0) {
580 fd = OS_OPEN(filename, O_RDWR | O_TRUNC | O_CREAT, 0);
581 } else if (strcmp(mode, "a") == 0) {
582 fd = OS_OPEN(filename, O_WRONLY | O_APPEND | O_CREAT, 0);
583 } else if (strcmp(mode, "a+") == 0) {
584 fd = OS_OPEN(filename, O_RDWR | O_APPEND | O_CREAT, 0);
586 osi_Assert(FALSE); /* not implemented */
589 if (fd == INVALID_FD) {
592 return stream_fdopen(fd);
595 /* fread for buffered I/O handles */
597 stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
598 StreamHandle_t * streamP)
600 afs_fsize_t nbytes, bytesRead, bytesToRead;
603 /* Need to seek before changing direction */
604 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
605 streamP->str_direction = STREAM_DIRECTION_READ;
606 streamP->str_bufoff = 0;
607 streamP->str_buflen = 0;
609 osi_Assert(streamP->str_direction == STREAM_DIRECTION_READ);
613 nbytes = size * nitems;
615 while (nbytes > 0 && !streamP->str_eof) {
616 if (streamP->str_buflen == 0) {
617 streamP->str_bufoff = 0;
618 streamP->str_buflen =
619 OS_PREAD(streamP->str_fd, streamP->str_buffer,
620 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
621 if (streamP->str_buflen < 0) {
622 streamP->str_error = errno;
623 streamP->str_buflen = 0;
626 } else if (streamP->str_buflen == 0) {
627 streamP->str_eof = 1;
630 streamP->str_fdoff += streamP->str_buflen;
633 bytesToRead = nbytes;
634 if (bytesToRead > streamP->str_buflen) {
635 bytesToRead = streamP->str_buflen;
637 memcpy(p, streamP->str_buffer + streamP->str_bufoff, bytesToRead);
639 streamP->str_bufoff += bytesToRead;
640 streamP->str_buflen -= bytesToRead;
641 bytesRead += bytesToRead;
642 nbytes -= bytesToRead;
645 return (bytesRead / size);
648 /* fwrite for buffered I/O handles */
650 stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
651 StreamHandle_t * streamP)
655 afs_fsize_t nbytes, bytesWritten, bytesToWrite;
657 /* Need to seek before changing direction */
658 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
659 streamP->str_direction = STREAM_DIRECTION_WRITE;
660 streamP->str_bufoff = 0;
661 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
663 osi_Assert(streamP->str_direction == STREAM_DIRECTION_WRITE);
666 nbytes = size * nitems;
670 if (streamP->str_buflen == 0) {
671 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
672 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
674 streamP->str_error = errno;
678 streamP->str_fdoff += rc;
679 streamP->str_bufoff = 0;
680 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
683 bytesToWrite = nbytes;
684 if (bytesToWrite > streamP->str_buflen) {
685 bytesToWrite = streamP->str_buflen;
687 memcpy(streamP->str_buffer + streamP->str_bufoff, p, bytesToWrite);
689 streamP->str_bufoff += bytesToWrite;
690 streamP->str_buflen -= bytesToWrite;
691 bytesWritten += bytesToWrite;
692 nbytes -= bytesToWrite;
695 return (bytesWritten / size);
698 /* fseek for buffered I/O handles */
700 stream_aseek(StreamHandle_t * streamP, afs_foff_t offset)
705 if (streamP->str_direction == STREAM_DIRECTION_WRITE
706 && streamP->str_bufoff > 0) {
707 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
708 streamP->str_bufoff, streamP->str_fdoff);
710 streamP->str_error = errno;
714 streamP->str_fdoff = offset;
715 streamP->str_bufoff = 0;
716 streamP->str_buflen = 0;
717 streamP->str_eof = 0;
718 streamP->str_direction = STREAM_DIRECTION_NONE;
722 /* fflush for buffered I/O handles */
724 stream_flush(StreamHandle_t * streamP)
729 if (streamP->str_direction == STREAM_DIRECTION_WRITE
730 && streamP->str_bufoff > 0) {
731 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
732 streamP->str_bufoff, streamP->str_fdoff);
734 streamP->str_error = errno;
737 streamP->str_fdoff += rc;
739 streamP->str_bufoff = 0;
740 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
746 /* Free a buffered I/O handle */
748 stream_close(StreamHandle_t * streamP, int reallyClose)
753 osi_Assert(streamP != NULL);
754 if (streamP->str_direction == STREAM_DIRECTION_WRITE
755 && streamP->str_bufoff > 0) {
756 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
757 streamP->str_bufoff, streamP->str_fdoff);
761 streamP->str_fdoff += rc;
765 rc = OS_CLOSE(streamP->str_fd);
770 streamP->str_fd = INVALID_FD;
773 DLL_INSERT_TAIL(streamP, streamAvailHead, streamAvailTail,
779 /* Close all unused file descriptors associated with the inode
780 * handle. Called with IH_LOCK held. May drop and reacquire
781 * IH_LOCK. Sets the IH_REALLY_CLOSED flag in the inode handle
782 * if it fails to close all file handles.
785 ih_fdclose(IHandle_t * ihP)
787 int closeCount, closedAll;
788 FdHandle_t *fdP, *head, *tail, *next;
790 osi_Assert(ihP->ih_refcnt > 0);
793 DLL_INIT_LIST(head, tail);
794 ihP->ih_flags &= ~IH_REALLY_CLOSED;
797 * Remove the file descriptors for this Inode from the LRU queue
798 * and the IHandle queue and put them on a temporary queue so we
799 * can drop the lock before we close the files.
801 for (fdP = ihP->ih_fdhead; fdP != NULL; fdP = next) {
802 next = fdP->fd_ihnext;
803 osi_Assert(fdP->fd_ih == ihP);
804 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN
805 || fdP->fd_status == FD_HANDLE_INUSE);
806 if (fdP->fd_status == FD_HANDLE_OPEN) {
807 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
809 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
810 DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev);
813 ihP->ih_flags |= IH_REALLY_CLOSED;
817 /* If the ihandle reference count is 1, we should have
818 * closed all file descriptors.
820 if (ihP->ih_refcnt == 1 || closedAll) {
821 osi_Assert(closedAll);
822 osi_Assert(!ihP->ih_fdhead);
823 osi_Assert(!ihP->ih_fdtail);
827 return 0; /* No file descriptors closed */
832 * Close the file descriptors
835 for (fdP = head; fdP != NULL; fdP = fdP->fd_next) {
836 OS_CLOSE(fdP->fd_fd);
837 fdP->fd_status = FD_HANDLE_AVAIL;
839 fdP->fd_fd = INVALID_FD;
845 osi_Assert(fdInUseCount >= closeCount);
846 fdInUseCount -= closeCount;
849 * Append the temporary queue to the list of available descriptors
851 if (fdAvailHead == NULL) {
855 fdAvailTail->fd_next = head;
856 head->fd_prev = fdAvailTail;
863 /* Close all cached file descriptors for this inode. */
865 ih_reallyclose(IHandle_t * ihP)
871 ihP->ih_refcnt++; /* must not disappear over unlock */
872 if (ihP->ih_synced) {
885 osi_Assert(ihP->ih_refcnt > 0);
890 if (ihP->ih_refcnt > 1) {
900 /* Release an Inode handle. All cached file descriptors for this
901 * inode are closed when the last reference to this handle is released
904 ih_release(IHandle_t * ihP)
912 osi_Assert(ihP->ih_refcnt > 0);
914 if (ihP->ih_refcnt > 1) {
920 ihash = IH_HASH(ihP->ih_dev, ihP->ih_vid, ihP->ih_ino);
921 DLL_DELETE(ihP, ihashTable[ihash].ihash_head,
922 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
928 DLL_INSERT_TAIL(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
934 /* Sync an inode to disk if its handle isn't NULL */
936 ih_condsync(IHandle_t * ihP)
948 code = FDH_SYNC(fdP);
960 for (ihash = 0; ihash < I_HANDLE_HASH_SIZE; ihash++) {
961 IHandle_t *ihP, *ihPnext;
963 ihP = ihashTable[ihash].ihash_head;
965 ihP->ih_refcnt++; /* must not disappear over unlock */
966 for (; ihP; ihP = ihPnext) {
968 if (ihP->ih_synced) {
983 /* when decrementing the refcount, the ihandle might disappear
984 and we might not even be able to proceed to the next one.
985 Hence the gymnastics putting a hold on the next one already */
986 ihPnext = ihP->ih_next;
987 if (ihPnext) ihPnext->ih_refcnt++;
989 if (ihP->ih_refcnt > 1) {
1003 ih_sync_thread(void *dummy) {
1006 #ifdef AFS_PTHREAD_ENV
1008 #else /* AFS_PTHREAD_ENV */
1010 #endif /* AFS_PTHREAD_ENV */
1018 /*************************************************************************
1019 * OS specific support routines.
1020 *************************************************************************/
1021 #ifndef AFS_NAMEI_ENV
1023 ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, int p2,
1027 #ifdef AFS_3DISPARES
1028 /* See viceinode.h */
1029 if (p2 == INODESPECIAL) {
1035 ino = ICREATE(dev, part, nI, p1, p2, p3, p4);
1038 #endif /* AFS_NAMEI_ENV */
1045 if (!GetFileSizeEx(fd, &size))
1047 return size.QuadPart;
1049 struct afs_stat status;
1050 if (afs_fstat(fd, &status) < 0)
1052 return status.st_size;
1058 ih_pread(int fd, void * buf, size_t count, afs_foff_t offset)
1061 code = OS_SEEK(fd, offset, 0);
1064 return OS_READ(fd, buf, count);
1068 ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset)
1071 code = OS_SEEK(fd, offset, 0);
1074 return OS_WRITE(fd, buf, count);
1076 #endif /* !HAVE_PIO */