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>
21 #ifdef HAVE_SYS_RESOURCE_H
22 #include <sys/resource.h>
26 #include <afs/afsint.h>
27 #include <afs/afssyscalls.h>
31 #include "viceinode.h"
32 #include "afs/afs_assert.h"
34 #ifdef AFS_PTHREAD_ENV
35 pthread_once_t ih_glock_once = PTHREAD_ONCE_INIT;
36 pthread_mutex_t ih_glock_mutex;
37 #endif /* AFS_PTHREAD_ENV */
39 /* Linked list of available inode handles */
40 IHandle_t *ihAvailHead;
41 IHandle_t *ihAvailTail;
43 /* Linked list of available file descriptor handles */
44 FdHandle_t *fdAvailHead;
45 FdHandle_t *fdAvailTail;
47 /* Linked list of available stream descriptor handles */
48 StreamHandle_t *streamAvailHead;
49 StreamHandle_t *streamAvailTail;
51 /* LRU list for file descriptor handles */
52 FdHandle_t *fdLruHead;
53 FdHandle_t *fdLruTail;
56 int ih_PkgDefaultsSet = 0;
58 /* Most of the servers use fopen/fdopen. Since the FILE structure
59 * only has eight bits for the file descriptor, the cache size
60 * has to be less than 256. The cache can be made larger as long
61 * as you are sure you don't need fopen/fdopen. */
63 /* As noted in ihandle.h, the fileno member of FILE on most platforms
64 * in 2008 is a 16- or 32-bit signed int. -Matt
66 int fdMaxCacheSize = 0;
69 /* Number of in use file descriptors */
72 /* Hash table for inode handles */
73 IHashBucket_t ihashTable[I_HANDLE_HASH_SIZE];
75 static int _ih_release_r(IHandle_t * ihP);
76 void *ih_sync_thread(void *);
78 /* start-time configurable I/O limits */
79 ih_init_params vol_io_params;
81 void ih_PkgDefaults(void)
84 ih_PkgDefaultsSet = 1;
86 /* default to well-known values */
87 vol_io_params.fd_handle_setaside = FD_HANDLE_SETASIDE;
89 /* initial fd cachesize. the only one that will be used if
90 * the application does not call ih_UseLargeCache(). set this
91 * to a value representable in fileno member of the system's
92 * FILE structure (or equivalent). */
93 vol_io_params.fd_initial_cachesize = FD_DEFAULT_CACHESIZE;
95 /* fd cache size that will be used if/when ih_UseLargeCache()
97 vol_io_params.fd_max_cachesize = FD_MAX_CACHESIZE;
100 #ifdef AFS_PTHREAD_ENV
101 /* Initialize the global ihandle mutex */
105 MUTEX_INIT(&ih_glock_mutex, "ih glock", MUTEX_DEFAULT, 0);
107 #endif /* AFS_PTHREAD_ENV */
109 /* Initialize the file descriptor cache */
114 osi_Assert(!ih_Inited);
116 DLL_INIT_LIST(ihAvailHead, ihAvailTail);
117 DLL_INIT_LIST(fdAvailHead, fdAvailTail);
118 DLL_INIT_LIST(fdLruHead, fdLruTail);
119 for (i = 0; i < I_HANDLE_HASH_SIZE; i++) {
120 DLL_INIT_LIST(ihashTable[i].ihash_head, ihashTable[i].ihash_tail);
122 #if defined(AFS_NT40_ENV)
123 fdMaxCacheSize = vol_io_params.fd_max_cachesize;
124 #elif defined(AFS_SUN5_ENV) || defined(AFS_NBSD_ENV)
127 osi_Assert(getrlimit(RLIMIT_NOFILE, &rlim) == 0);
128 rlim.rlim_cur = rlim.rlim_max;
129 osi_Assert(setrlimit(RLIMIT_NOFILE, &rlim) == 0);
130 fdMaxCacheSize = rlim.rlim_cur - vol_io_params.fd_handle_setaside;
132 /* XXX this is to avoid using up all system fd netbsd is
133 * somewhat broken and have set maximum fd for a root process
134 * to the same as system fd that is avaible, so if the
135 * fileserver uses all up process fds, all system fd will be
138 * Check for this better
142 fdMaxCacheSize = MIN(fdMaxCacheSize, vol_io_params.fd_max_cachesize);
143 osi_Assert(fdMaxCacheSize > 0);
145 #elif defined(AFS_HPUX_ENV)
146 /* Avoid problems with "UFSOpen: igetinode failed" panics on HPUX 11.0 */
150 long fdMax = MAX(sysconf(_SC_OPEN_MAX) - vol_io_params.fd_handle_setaside,
152 fdMaxCacheSize = (int)MIN(fdMax, vol_io_params.fd_max_cachesize);
155 fdCacheSize = MIN(fdMaxCacheSize, vol_io_params.fd_initial_cachesize);
158 #ifdef AFS_PTHREAD_ENV
160 pthread_attr_t tattr;
162 pthread_attr_init(&tattr);
163 pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
165 pthread_create(&syncer, &tattr, ih_sync_thread, NULL);
166 #else /* AFS_PTHREAD_ENV */
168 LWP_CreateProcess(ih_sync_thread, 16*1024, LWP_MAX_PRIORITY - 2,
169 NULL, "ih_syncer", &syncer);
170 #endif /* AFS_PTHREAD_ENV */
175 /* Make the file descriptor cache as big as possible. Don't this call
176 * if the program uses fopen or fdopen, if fd_max_cachesize cannot be
177 * represented in the fileno member of the system FILE structure (or
181 ih_UseLargeCache(void)
185 if (!ih_PkgDefaultsSet) {
193 fdCacheSize = fdMaxCacheSize;
198 /* Allocate a chunk of inode handles */
200 iHandleAllocateChunk(void)
205 osi_Assert(ihAvailHead == NULL);
206 ihP = (IHandle_t *) malloc(I_HANDLE_MALLOCSIZE * sizeof(IHandle_t));
207 osi_Assert(ihP != NULL);
208 for (i = 0; i < I_HANDLE_MALLOCSIZE; i++) {
209 ihP[i].ih_refcnt = 0;
210 DLL_INSERT_TAIL(&ihP[i], ihAvailHead, ihAvailTail, ih_next, ih_prev);
214 /* Initialize an inode handle */
216 ih_init(int dev, int vid, Inode ino)
218 int ihash = IH_HASH(dev, vid, ino);
221 if (!ih_PkgDefaultsSet) {
230 /* Do we already have a handle for this Inode? */
231 for (ihP = ihashTable[ihash].ihash_head; ihP; ihP = ihP->ih_next) {
232 if (ihP->ih_ino == ino && ihP->ih_vid == vid && ihP->ih_dev == dev) {
239 /* Allocate and initialize a new Inode handle */
240 if (ihAvailHead == NULL) {
241 iHandleAllocateChunk();
244 osi_Assert(ihP->ih_refcnt == 0);
245 DLL_DELETE(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
252 DLL_INIT_LIST(ihP->ih_fdhead, ihP->ih_fdtail);
253 DLL_INSERT_TAIL(ihP, ihashTable[ihash].ihash_head,
254 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
259 /* Copy an inode handle */
261 ih_copy(IHandle_t * ihP)
264 osi_Assert(ih_Inited);
265 osi_Assert(ihP->ih_refcnt > 0);
271 /* Allocate a chunk of file descriptor handles */
273 fdHandleAllocateChunk(void)
278 osi_Assert(fdAvailHead == NULL);
279 fdP = (FdHandle_t *) malloc(FD_HANDLE_MALLOCSIZE * sizeof(FdHandle_t));
280 osi_Assert(fdP != NULL);
281 for (i = 0; i < FD_HANDLE_MALLOCSIZE; i++) {
282 fdP[i].fd_status = FD_HANDLE_AVAIL;
283 fdP[i].fd_refcnt = 0;
285 fdP[i].fd_fd = INVALID_FD;
286 fdP[i].fd_ihnext = NULL;
287 fdP[i].fd_ihprev = NULL;
288 DLL_INSERT_TAIL(&fdP[i], fdAvailHead, fdAvailTail, fd_next, fd_prev);
292 /* Allocate a chunk of stream handles */
294 streamHandleAllocateChunk(void)
297 StreamHandle_t *streamP;
299 osi_Assert(streamAvailHead == NULL);
300 streamP = (StreamHandle_t *)
301 malloc(STREAM_HANDLE_MALLOCSIZE * sizeof(StreamHandle_t));
302 osi_Assert(streamP != NULL);
303 for (i = 0; i < STREAM_HANDLE_MALLOCSIZE; i++) {
304 streamP[i].str_fd = INVALID_FD;
305 DLL_INSERT_TAIL(&streamP[i], streamAvailHead, streamAvailTail,
311 * Get a file descriptor handle given an Inode handle
314 ih_open(IHandle_t * ihP)
320 if (!ihP) /* XXX should log here in the fileserver */
325 /* Do we already have an open file handle for this Inode? */
326 for (fdP = ihP->ih_fdtail; fdP != NULL; fdP = fdP->fd_ihprev) {
329 * If we don't have positional i/o, don't try to share fds, since
330 * we can't do so in a threadsafe way.
332 if (fdP->fd_status != FD_HANDLE_INUSE) {
333 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
335 if (fdP->fd_status != FD_HANDLE_AVAIL) {
336 #endif /* HAVE_PIO */
338 if (fdP->fd_status == FD_HANDLE_OPEN) {
339 fdP->fd_status = FD_HANDLE_INUSE;
340 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
349 * Try to open the Inode, return NULL on error.
356 if (fd == INVALID_FD && (errno != EMFILE || fdLruHead == NULL) ) {
362 /* fdCacheSize limits the size of the descriptor cache, but
363 * we permit the number of open files to exceed fdCacheSize.
364 * We only recycle open file descriptors when the number
365 * of open files reaches the size of the cache */
366 if ((fdInUseCount > fdCacheSize || fd == INVALID_FD) && fdLruHead != NULL) {
368 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
369 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
370 DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail,
371 fd_ihnext, fd_ihprev);
372 closeFd = fdP->fd_fd;
373 if (fd == INVALID_FD) {
374 fdCacheSize--; /* reduce in order to not run into here too often */
375 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
376 fdP->fd_status = FD_HANDLE_AVAIL;
378 fdP->fd_fd = INVALID_FD;
384 if (fdAvailHead == NULL) {
385 fdHandleAllocateChunk();
388 osi_Assert(fdP->fd_status == FD_HANDLE_AVAIL);
389 DLL_DELETE(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
390 closeFd = INVALID_FD;
393 fdP->fd_status = FD_HANDLE_INUSE;
400 /* Add this handle to the Inode's list of open descriptors */
401 DLL_INSERT_TAIL(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
404 if (closeFd != INVALID_FD) {
416 * Return a file descriptor handle to the cache
419 fd_close(FdHandle_t * fdP)
427 osi_Assert(ih_Inited);
428 osi_Assert(fdInUseCount > 0);
429 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
433 /* Call fd_reallyclose to really close the unused file handles if
434 * the previous attempt to close (ih_reallyclose()) all file handles
435 * failed (this is determined by checking the ihandle for the flag
436 * IH_REALLY_CLOSED) or we have too many open files.
438 if (ihP->ih_flags & IH_REALLY_CLOSED || fdInUseCount > fdCacheSize) {
440 return fd_reallyclose(fdP);
444 if (fdP->fd_refcnt == 0) {
445 /* Put this descriptor back into the cache */
446 fdP->fd_status = FD_HANDLE_OPEN;
447 DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
450 /* If this is not the only reference to the Inode then we can decrement
451 * the reference count, otherwise we need to call ih_release.
453 if (ihP->ih_refcnt > 1)
464 * Actually close the file descriptor handle and return it to
468 fd_reallyclose(FdHandle_t * fdP)
477 osi_Assert(ih_Inited);
478 osi_Assert(fdInUseCount > 0);
479 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
482 closeFd = fdP->fd_fd;
485 if (fdP->fd_refcnt == 0) {
486 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev);
487 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
489 fdP->fd_status = FD_HANDLE_AVAIL;
492 fdP->fd_fd = INVALID_FD;
495 /* All the file descriptor handles have been closed; reset
496 * the IH_REALLY_CLOSED flag indicating that ih_reallyclose
497 * has completed its job.
499 if (!ihP->ih_fdhead) {
500 ihP->ih_flags &= ~IH_REALLY_CLOSED;
503 if (fdP->fd_refcnt == 0) {
510 /* If this is not the only reference to the Inode then we can decrement
511 * the reference count, otherwise we need to call ih_release. */
512 if (ihP->ih_refcnt > 1)
522 /* Enable buffered I/O on a file descriptor */
524 stream_fdopen(FD_t fd)
526 StreamHandle_t *streamP;
529 if (streamAvailHead == NULL) {
530 streamHandleAllocateChunk();
532 streamP = streamAvailHead;
533 DLL_DELETE(streamP, streamAvailHead, streamAvailTail, str_next, str_prev);
535 streamP->str_fd = fd;
536 streamP->str_buflen = 0;
537 streamP->str_bufoff = 0;
538 streamP->str_fdoff = 0;
539 streamP->str_error = 0;
540 streamP->str_eof = 0;
541 streamP->str_direction = STREAM_DIRECTION_NONE;
545 /* Open a file for buffered I/O */
547 stream_open(const char *filename, const char *mode)
549 FD_t fd = INVALID_FD;
551 if (strcmp(mode, "r") == 0) {
552 fd = OS_OPEN(filename, O_RDONLY, 0);
553 } else if (strcmp(mode, "r+") == 0) {
554 fd = OS_OPEN(filename, O_RDWR, 0);
555 } else if (strcmp(mode, "w") == 0) {
556 fd = OS_OPEN(filename, O_WRONLY | O_TRUNC | O_CREAT, 0);
557 } else if (strcmp(mode, "w+") == 0) {
558 fd = OS_OPEN(filename, O_RDWR | O_TRUNC | O_CREAT, 0);
559 } else if (strcmp(mode, "a") == 0) {
560 fd = OS_OPEN(filename, O_WRONLY | O_APPEND | O_CREAT, 0);
561 } else if (strcmp(mode, "a+") == 0) {
562 fd = OS_OPEN(filename, O_RDWR | O_APPEND | O_CREAT, 0);
564 osi_Assert(FALSE); /* not implemented */
567 if (fd == INVALID_FD) {
570 return stream_fdopen(fd);
573 /* fread for buffered I/O handles */
575 stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
576 StreamHandle_t * streamP)
578 afs_fsize_t nbytes, bytesRead, bytesToRead;
581 /* Need to seek before changing direction */
582 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
583 streamP->str_direction = STREAM_DIRECTION_READ;
584 streamP->str_bufoff = 0;
585 streamP->str_buflen = 0;
587 osi_Assert(streamP->str_direction == STREAM_DIRECTION_READ);
591 nbytes = size * nitems;
593 while (nbytes > 0 && !streamP->str_eof) {
594 if (streamP->str_buflen == 0) {
595 streamP->str_bufoff = 0;
596 streamP->str_buflen =
597 OS_PREAD(streamP->str_fd, streamP->str_buffer,
598 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
599 if (streamP->str_buflen < 0) {
600 streamP->str_error = errno;
601 streamP->str_buflen = 0;
604 } else if (streamP->str_buflen == 0) {
605 streamP->str_eof = 1;
608 streamP->str_fdoff += streamP->str_buflen;
611 bytesToRead = nbytes;
612 if (bytesToRead > streamP->str_buflen) {
613 bytesToRead = streamP->str_buflen;
615 memcpy(p, streamP->str_buffer + streamP->str_bufoff, bytesToRead);
617 streamP->str_bufoff += bytesToRead;
618 streamP->str_buflen -= bytesToRead;
619 bytesRead += bytesToRead;
620 nbytes -= bytesToRead;
623 return (bytesRead / size);
626 /* fwrite for buffered I/O handles */
628 stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
629 StreamHandle_t * streamP)
633 afs_fsize_t nbytes, bytesWritten, bytesToWrite;
635 /* Need to seek before changing direction */
636 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
637 streamP->str_direction = STREAM_DIRECTION_WRITE;
638 streamP->str_bufoff = 0;
639 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
641 osi_Assert(streamP->str_direction == STREAM_DIRECTION_WRITE);
644 nbytes = size * nitems;
648 if (streamP->str_buflen == 0) {
649 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
650 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
652 streamP->str_error = errno;
656 streamP->str_fdoff += rc;
657 streamP->str_bufoff = 0;
658 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
661 bytesToWrite = nbytes;
662 if (bytesToWrite > streamP->str_buflen) {
663 bytesToWrite = streamP->str_buflen;
665 memcpy(streamP->str_buffer + streamP->str_bufoff, p, bytesToWrite);
667 streamP->str_bufoff += bytesToWrite;
668 streamP->str_buflen -= bytesToWrite;
669 bytesWritten += bytesToWrite;
670 nbytes -= bytesToWrite;
673 return (bytesWritten / size);
676 /* fseek for buffered I/O handles */
678 stream_aseek(StreamHandle_t * streamP, afs_foff_t offset)
683 if (streamP->str_direction == STREAM_DIRECTION_WRITE
684 && streamP->str_bufoff > 0) {
685 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
686 streamP->str_bufoff, streamP->str_fdoff);
688 streamP->str_error = errno;
692 streamP->str_fdoff = offset;
693 streamP->str_bufoff = 0;
694 streamP->str_buflen = 0;
695 streamP->str_eof = 0;
696 streamP->str_direction = STREAM_DIRECTION_NONE;
700 /* fflush for buffered I/O handles */
702 stream_flush(StreamHandle_t * streamP)
707 if (streamP->str_direction == STREAM_DIRECTION_WRITE
708 && streamP->str_bufoff > 0) {
709 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
710 streamP->str_bufoff, streamP->str_fdoff);
712 streamP->str_error = errno;
715 streamP->str_fdoff += rc;
717 streamP->str_bufoff = 0;
718 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
724 /* Free a buffered I/O handle */
726 stream_close(StreamHandle_t * streamP, int reallyClose)
731 osi_Assert(streamP != NULL);
732 if (streamP->str_direction == STREAM_DIRECTION_WRITE
733 && streamP->str_bufoff > 0) {
734 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
735 streamP->str_bufoff, streamP->str_fdoff);
739 streamP->str_fdoff += rc;
743 rc = OS_CLOSE(streamP->str_fd);
748 streamP->str_fd = INVALID_FD;
751 DLL_INSERT_TAIL(streamP, streamAvailHead, streamAvailTail,
757 /* Close all unused file descriptors associated with the inode
758 * handle. Called with IH_LOCK held. May drop and reacquire
759 * IH_LOCK. Sets the IH_REALLY_CLOSED flag in the inode handle
760 * if it fails to close all file handles.
763 ih_fdclose(IHandle_t * ihP)
765 int closeCount, closedAll;
766 FdHandle_t *fdP, *head, *tail, *next;
768 osi_Assert(ihP->ih_refcnt > 0);
771 DLL_INIT_LIST(head, tail);
772 ihP->ih_flags &= ~IH_REALLY_CLOSED;
775 * Remove the file descriptors for this Inode from the LRU queue
776 * and the IHandle queue and put them on a temporary queue so we
777 * can drop the lock before we close the files.
779 for (fdP = ihP->ih_fdhead; fdP != NULL; fdP = next) {
780 next = fdP->fd_ihnext;
781 osi_Assert(fdP->fd_ih == ihP);
782 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN
783 || fdP->fd_status == FD_HANDLE_INUSE);
784 if (fdP->fd_status == FD_HANDLE_OPEN) {
785 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
787 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
788 DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev);
791 ihP->ih_flags |= IH_REALLY_CLOSED;
795 /* If the ihandle reference count is 1, we should have
796 * closed all file descriptors.
798 if (ihP->ih_refcnt == 1 || closedAll) {
799 osi_Assert(closedAll);
800 osi_Assert(!ihP->ih_fdhead);
801 osi_Assert(!ihP->ih_fdtail);
805 return 0; /* No file descriptors closed */
810 * Close the file descriptors
813 for (fdP = head; fdP != NULL; fdP = fdP->fd_next) {
814 OS_CLOSE(fdP->fd_fd);
815 fdP->fd_status = FD_HANDLE_AVAIL;
817 fdP->fd_fd = INVALID_FD;
823 osi_Assert(fdInUseCount >= closeCount);
824 fdInUseCount -= closeCount;
827 * Append the temporary queue to the list of available descriptors
829 if (fdAvailHead == NULL) {
833 fdAvailTail->fd_next = head;
834 head->fd_prev = fdAvailTail;
841 /* Close all cached file descriptors for this inode. */
843 ih_reallyclose(IHandle_t * ihP)
849 ihP->ih_refcnt++; /* must not disappear over unlock */
850 if (ihP->ih_synced) {
864 osi_Assert(ihP->ih_refcnt > 0);
868 if (ihP->ih_refcnt > 1)
877 /* Release an Inode handle. All cached file descriptors for this
878 * inode are closed when the last reference to this handle is released
881 _ih_release_r(IHandle_t * ihP)
888 osi_Assert(ihP->ih_refcnt > 0);
890 if (ihP->ih_refcnt > 1) {
895 ihash = IH_HASH(ihP->ih_dev, ihP->ih_vid, ihP->ih_ino);
896 DLL_DELETE(ihP, ihashTable[ihash].ihash_head,
897 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
903 DLL_INSERT_TAIL(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
908 /* Release an Inode handle. All cached file descriptors for this
909 * inode are closed when the last reference to this handle is released
912 ih_release(IHandle_t * ihP)
920 ret = _ih_release_r(ihP);
925 /* Sync an inode to disk if its handle isn't NULL */
927 ih_condsync(IHandle_t * ihP)
939 code = FDH_SYNC(fdP);
951 for (ihash = 0; ihash < I_HANDLE_HASH_SIZE; ihash++) {
952 IHandle_t *ihP, *ihPnext;
954 ihP = ihashTable[ihash].ihash_head;
956 ihP->ih_refcnt++; /* must not disappear over unlock */
957 for (; ihP; ihP = ihPnext) {
959 if (ihP->ih_synced) {
974 /* when decrementing the refcount, the ihandle might disappear
975 and we might not even be able to proceed to the next one.
976 Hence the gymnastics putting a hold on the next one already */
977 ihPnext = ihP->ih_next;
978 if (ihPnext) ihPnext->ih_refcnt++;
980 if (ihP->ih_refcnt > 1)
990 ih_sync_thread(void *dummy) {
993 #ifdef AFS_PTHREAD_ENV
995 #else /* AFS_PTHREAD_ENV */
997 #endif /* AFS_PTHREAD_ENV */
1005 /*************************************************************************
1006 * OS specific support routines.
1007 *************************************************************************/
1008 #ifndef AFS_NAMEI_ENV
1010 ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, int p2,
1014 #ifdef AFS_3DISPARES
1015 /* See viceinode.h */
1016 if (p2 == INODESPECIAL) {
1022 ino = ICREATE(dev, part, nI, p1, p2, p3, p4);
1025 #endif /* AFS_NAMEI_ENV */
1032 if (!GetFileSizeEx(fd, &size))
1034 return size.QuadPart;
1036 struct afs_stat_st status;
1037 if (afs_fstat(fd, &status) < 0)
1039 return status.st_size;
1045 ih_pread(int fd, void * buf, size_t count, afs_foff_t offset)
1048 code = OS_SEEK(fd, offset, 0);
1051 return OS_READ(fd, buf, count);
1055 ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset)
1058 code = OS_SEEK(fd, offset, 0);
1061 return OS_WRITE(fd, buf, count);
1063 #endif /* !HAVE_PIO */