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>
28 #include <afs/afsutil.h>
32 #include "viceinode.h"
33 #include "afs/afs_assert.h"
35 #ifdef AFS_PTHREAD_ENV
36 pthread_once_t ih_glock_once = PTHREAD_ONCE_INIT;
37 pthread_mutex_t ih_glock_mutex;
38 #endif /* AFS_PTHREAD_ENV */
40 /* Linked list of available inode handles */
41 IHandle_t *ihAvailHead;
42 IHandle_t *ihAvailTail;
44 /* Linked list of available file descriptor handles */
45 FdHandle_t *fdAvailHead;
46 FdHandle_t *fdAvailTail;
48 /* Linked list of available stream descriptor handles */
49 StreamHandle_t *streamAvailHead;
50 StreamHandle_t *streamAvailTail;
52 /* LRU list for file descriptor handles */
53 FdHandle_t *fdLruHead;
54 FdHandle_t *fdLruTail;
57 int ih_PkgDefaultsSet = 0;
59 /* Most of the servers use fopen/fdopen. Since the FILE structure
60 * only has eight bits for the file descriptor, the cache size
61 * has to be less than 256. The cache can be made larger as long
62 * as you are sure you don't need fopen/fdopen. */
64 /* As noted in ihandle.h, the fileno member of FILE on most platforms
65 * in 2008 is a 16- or 32-bit signed int. -Matt
67 int fdMaxCacheSize = 0;
70 /* Number of in use file descriptors */
73 /* Hash table for inode handles */
74 IHashBucket_t ihashTable[I_HANDLE_HASH_SIZE];
76 static int _ih_release_r(IHandle_t * ihP);
77 void *ih_sync_thread(void *);
79 /* start-time configurable I/O limits */
80 ih_init_params vol_io_params;
82 void ih_PkgDefaults(void)
85 ih_PkgDefaultsSet = 1;
87 /* default to well-known values */
88 vol_io_params.fd_handle_setaside = FD_HANDLE_SETASIDE;
90 /* initial fd cachesize. the only one that will be used if
91 * the application does not call ih_UseLargeCache(). set this
92 * to a value representable in fileno member of the system's
93 * FILE structure (or equivalent). */
94 vol_io_params.fd_initial_cachesize = FD_DEFAULT_CACHESIZE;
96 /* fd cache size that will be used if/when ih_UseLargeCache()
98 vol_io_params.fd_max_cachesize = FD_MAX_CACHESIZE;
101 #ifdef AFS_PTHREAD_ENV
102 /* Initialize the global ihandle mutex */
106 MUTEX_INIT(&ih_glock_mutex, "ih glock", MUTEX_DEFAULT, 0);
108 #endif /* AFS_PTHREAD_ENV */
110 /* Initialize the file descriptor cache */
115 osi_Assert(!ih_Inited);
117 DLL_INIT_LIST(ihAvailHead, ihAvailTail);
118 DLL_INIT_LIST(fdAvailHead, fdAvailTail);
119 DLL_INIT_LIST(fdLruHead, fdLruTail);
120 for (i = 0; i < I_HANDLE_HASH_SIZE; i++) {
121 DLL_INIT_LIST(ihashTable[i].ihash_head, ihashTable[i].ihash_tail);
123 #if defined(AFS_NT40_ENV)
124 fdMaxCacheSize = vol_io_params.fd_max_cachesize;
125 #elif defined(AFS_SUN5_ENV) || defined(AFS_NBSD_ENV)
128 osi_Assert(getrlimit(RLIMIT_NOFILE, &rlim) == 0);
129 rlim.rlim_cur = rlim.rlim_max;
130 osi_Assert(setrlimit(RLIMIT_NOFILE, &rlim) == 0);
131 fdMaxCacheSize = rlim.rlim_cur - vol_io_params.fd_handle_setaside;
133 /* XXX this is to avoid using up all system fd netbsd is
134 * somewhat broken and have set maximum fd for a root process
135 * to the same as system fd that is avaible, so if the
136 * fileserver uses all up process fds, all system fd will be
139 * Check for this better
143 fdMaxCacheSize = MIN(fdMaxCacheSize, vol_io_params.fd_max_cachesize);
144 osi_Assert(fdMaxCacheSize > 0);
146 #elif defined(AFS_HPUX_ENV)
147 /* Avoid problems with "UFSOpen: igetinode failed" panics on HPUX 11.0 */
151 long fdMax = MAX(sysconf(_SC_OPEN_MAX) - vol_io_params.fd_handle_setaside,
153 fdMaxCacheSize = (int)MIN(fdMax, vol_io_params.fd_max_cachesize);
156 fdCacheSize = MIN(fdMaxCacheSize, vol_io_params.fd_initial_cachesize);
159 #ifdef AFS_PTHREAD_ENV
161 pthread_attr_t tattr;
163 pthread_attr_init(&tattr);
164 pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
166 pthread_create(&syncer, &tattr, ih_sync_thread, NULL);
167 #else /* AFS_PTHREAD_ENV */
169 LWP_CreateProcess(ih_sync_thread, 16*1024, LWP_MAX_PRIORITY - 2,
170 NULL, "ih_syncer", &syncer);
171 #endif /* AFS_PTHREAD_ENV */
176 /* Make the file descriptor cache as big as possible. Don't this call
177 * if the program uses fopen or fdopen, if fd_max_cachesize cannot be
178 * represented in the fileno member of the system FILE structure (or
182 ih_UseLargeCache(void)
186 if (!ih_PkgDefaultsSet) {
194 fdCacheSize = fdMaxCacheSize;
199 /* Allocate a chunk of inode handles */
201 iHandleAllocateChunk(void)
206 osi_Assert(ihAvailHead == NULL);
207 ihP = (IHandle_t *) malloc(I_HANDLE_MALLOCSIZE * sizeof(IHandle_t));
208 osi_Assert(ihP != NULL);
209 for (i = 0; i < I_HANDLE_MALLOCSIZE; i++) {
210 ihP[i].ih_refcnt = 0;
211 DLL_INSERT_TAIL(&ihP[i], ihAvailHead, ihAvailTail, ih_next, ih_prev);
215 /* Initialize an inode handle */
217 ih_init(int dev, int vid, Inode ino)
219 int ihash = IH_HASH(dev, vid, ino);
222 if (!ih_PkgDefaultsSet) {
231 /* Do we already have a handle for this Inode? */
232 for (ihP = ihashTable[ihash].ihash_head; ihP; ihP = ihP->ih_next) {
233 if (ihP->ih_ino == ino && ihP->ih_vid == vid && ihP->ih_dev == dev) {
240 /* Allocate and initialize a new Inode handle */
241 if (ihAvailHead == NULL) {
242 iHandleAllocateChunk();
245 osi_Assert(ihP->ih_refcnt == 0);
246 DLL_DELETE(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
253 DLL_INIT_LIST(ihP->ih_fdhead, ihP->ih_fdtail);
254 DLL_INSERT_TAIL(ihP, ihashTable[ihash].ihash_head,
255 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
260 /* Copy an inode handle */
262 ih_copy(IHandle_t * ihP)
265 osi_Assert(ih_Inited);
266 osi_Assert(ihP->ih_refcnt > 0);
272 /* Allocate a chunk of file descriptor handles */
274 fdHandleAllocateChunk(void)
279 osi_Assert(fdAvailHead == NULL);
280 fdP = (FdHandle_t *) malloc(FD_HANDLE_MALLOCSIZE * sizeof(FdHandle_t));
281 osi_Assert(fdP != NULL);
282 for (i = 0; i < FD_HANDLE_MALLOCSIZE; i++) {
283 fdP[i].fd_status = FD_HANDLE_AVAIL;
284 fdP[i].fd_refcnt = 0;
286 fdP[i].fd_fd = INVALID_FD;
287 fdP[i].fd_ihnext = NULL;
288 fdP[i].fd_ihprev = NULL;
289 DLL_INSERT_TAIL(&fdP[i], fdAvailHead, fdAvailTail, fd_next, fd_prev);
293 /* Allocate a chunk of stream handles */
295 streamHandleAllocateChunk(void)
298 StreamHandle_t *streamP;
300 osi_Assert(streamAvailHead == NULL);
301 streamP = (StreamHandle_t *)
302 malloc(STREAM_HANDLE_MALLOCSIZE * sizeof(StreamHandle_t));
303 osi_Assert(streamP != NULL);
304 for (i = 0; i < STREAM_HANDLE_MALLOCSIZE; i++) {
305 streamP[i].str_fd = INVALID_FD;
306 DLL_INSERT_TAIL(&streamP[i], streamAvailHead, streamAvailTail,
312 * Get a file descriptor handle given an Inode handle
315 ih_open(IHandle_t * ihP)
321 if (!ihP) /* XXX should log here in the fileserver */
326 /* Do we already have an open file handle for this Inode? */
327 for (fdP = ihP->ih_fdtail; fdP != NULL; fdP = fdP->fd_ihprev) {
330 * If we don't have positional i/o, don't try to share fds, since
331 * we can't do so in a threadsafe way.
333 if (fdP->fd_status == FD_HANDLE_INUSE) {
336 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
338 osi_Assert(fdP->fd_status != FD_HANDLE_AVAIL);
339 #endif /* HAVE_PIO */
342 if (fdP->fd_status == FD_HANDLE_OPEN) {
343 fdP->fd_status = FD_HANDLE_INUSE;
344 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
352 * Try to open the Inode, return NULL on error.
359 if (fd == INVALID_FD && (errno != EMFILE || fdLruHead == NULL) ) {
365 /* fdCacheSize limits the size of the descriptor cache, but
366 * we permit the number of open files to exceed fdCacheSize.
367 * We only recycle open file descriptors when the number
368 * of open files reaches the size of the cache */
369 if ((fdInUseCount > fdCacheSize || fd == INVALID_FD) && fdLruHead != NULL) {
371 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
372 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
373 DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail,
374 fd_ihnext, fd_ihprev);
375 closeFd = fdP->fd_fd;
376 if (fd == INVALID_FD) {
377 fdCacheSize--; /* reduce in order to not run into here too often */
378 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
379 fdP->fd_status = FD_HANDLE_AVAIL;
381 fdP->fd_fd = INVALID_FD;
387 if (fdAvailHead == NULL) {
388 fdHandleAllocateChunk();
391 osi_Assert(fdP->fd_status == FD_HANDLE_AVAIL);
392 DLL_DELETE(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
393 closeFd = INVALID_FD;
396 fdP->fd_status = FD_HANDLE_INUSE;
403 /* Add this handle to the Inode's list of open descriptors */
404 DLL_INSERT_TAIL(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
407 if (closeFd != INVALID_FD) {
419 * Return a file descriptor handle to the cache
422 fd_close(FdHandle_t * fdP)
430 osi_Assert(ih_Inited);
431 osi_Assert(fdInUseCount > 0);
432 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
436 /* Call fd_reallyclose to really close the unused file handles if
437 * the previous attempt to close (ih_reallyclose()) all file handles
438 * failed (this is determined by checking the ihandle for the flag
439 * IH_REALLY_CLOSED) or we have too many open files.
441 if (ihP->ih_flags & IH_REALLY_CLOSED || fdInUseCount > fdCacheSize) {
443 return fd_reallyclose(fdP);
447 if (fdP->fd_refcnt == 0) {
448 /* Put this descriptor back into the cache */
449 fdP->fd_status = FD_HANDLE_OPEN;
450 DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
453 /* If this is not the only reference to the Inode then we can decrement
454 * the reference count, otherwise we need to call ih_release.
456 if (ihP->ih_refcnt > 1)
467 * Actually close the file descriptor handle and return it to
471 fd_reallyclose(FdHandle_t * fdP)
480 osi_Assert(ih_Inited);
481 osi_Assert(fdInUseCount > 0);
482 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
485 closeFd = fdP->fd_fd;
488 if (fdP->fd_refcnt == 0) {
489 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev);
490 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
492 fdP->fd_status = FD_HANDLE_AVAIL;
495 fdP->fd_fd = INVALID_FD;
498 /* All the file descriptor handles have been closed; reset
499 * the IH_REALLY_CLOSED flag indicating that ih_reallyclose
500 * has completed its job.
502 if (!ihP->ih_fdhead) {
503 ihP->ih_flags &= ~IH_REALLY_CLOSED;
506 if (fdP->fd_refcnt == 0) {
513 /* If this is not the only reference to the Inode then we can decrement
514 * the reference count, otherwise we need to call ih_release. */
515 if (ihP->ih_refcnt > 1)
525 /* Enable buffered I/O on a file descriptor */
527 stream_fdopen(FD_t fd)
529 StreamHandle_t *streamP;
532 if (streamAvailHead == NULL) {
533 streamHandleAllocateChunk();
535 streamP = streamAvailHead;
536 DLL_DELETE(streamP, streamAvailHead, streamAvailTail, str_next, str_prev);
538 streamP->str_fd = fd;
539 streamP->str_buflen = 0;
540 streamP->str_bufoff = 0;
541 streamP->str_fdoff = 0;
542 streamP->str_error = 0;
543 streamP->str_eof = 0;
544 streamP->str_direction = STREAM_DIRECTION_NONE;
548 /* Open a file for buffered I/O */
550 stream_open(const char *filename, const char *mode)
552 FD_t fd = INVALID_FD;
554 if (strcmp(mode, "r") == 0) {
555 fd = OS_OPEN(filename, O_RDONLY, 0);
556 } else if (strcmp(mode, "r+") == 0) {
557 fd = OS_OPEN(filename, O_RDWR, 0);
558 } else if (strcmp(mode, "w") == 0) {
559 fd = OS_OPEN(filename, O_WRONLY | O_TRUNC | O_CREAT, 0);
560 } else if (strcmp(mode, "w+") == 0) {
561 fd = OS_OPEN(filename, O_RDWR | O_TRUNC | O_CREAT, 0);
562 } else if (strcmp(mode, "a") == 0) {
563 fd = OS_OPEN(filename, O_WRONLY | O_APPEND | O_CREAT, 0);
564 } else if (strcmp(mode, "a+") == 0) {
565 fd = OS_OPEN(filename, O_RDWR | O_APPEND | O_CREAT, 0);
567 osi_Assert(FALSE); /* not implemented */
570 if (fd == INVALID_FD) {
573 return stream_fdopen(fd);
576 /* fread for buffered I/O handles */
578 stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
579 StreamHandle_t * streamP)
581 afs_fsize_t nbytes, bytesRead, bytesToRead;
584 /* Need to seek before changing direction */
585 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
586 streamP->str_direction = STREAM_DIRECTION_READ;
587 streamP->str_bufoff = 0;
588 streamP->str_buflen = 0;
590 osi_Assert(streamP->str_direction == STREAM_DIRECTION_READ);
594 nbytes = size * nitems;
596 while (nbytes > 0 && !streamP->str_eof) {
597 if (streamP->str_buflen == 0) {
598 streamP->str_bufoff = 0;
599 streamP->str_buflen =
600 OS_PREAD(streamP->str_fd, streamP->str_buffer,
601 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
602 if (streamP->str_buflen < 0) {
603 streamP->str_error = errno;
604 streamP->str_buflen = 0;
607 } else if (streamP->str_buflen == 0) {
608 streamP->str_eof = 1;
611 streamP->str_fdoff += streamP->str_buflen;
614 bytesToRead = nbytes;
615 if (bytesToRead > streamP->str_buflen) {
616 bytesToRead = streamP->str_buflen;
618 memcpy(p, streamP->str_buffer + streamP->str_bufoff, bytesToRead);
620 streamP->str_bufoff += bytesToRead;
621 streamP->str_buflen -= bytesToRead;
622 bytesRead += bytesToRead;
623 nbytes -= bytesToRead;
626 return (bytesRead / size);
629 /* fwrite for buffered I/O handles */
631 stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
632 StreamHandle_t * streamP)
636 afs_fsize_t nbytes, bytesWritten, bytesToWrite;
638 /* Need to seek before changing direction */
639 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
640 streamP->str_direction = STREAM_DIRECTION_WRITE;
641 streamP->str_bufoff = 0;
642 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
644 osi_Assert(streamP->str_direction == STREAM_DIRECTION_WRITE);
647 nbytes = size * nitems;
651 if (streamP->str_buflen == 0) {
652 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
653 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
655 streamP->str_error = errno;
659 streamP->str_fdoff += rc;
660 streamP->str_bufoff = 0;
661 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
664 bytesToWrite = nbytes;
665 if (bytesToWrite > streamP->str_buflen) {
666 bytesToWrite = streamP->str_buflen;
668 memcpy(streamP->str_buffer + streamP->str_bufoff, p, bytesToWrite);
670 streamP->str_bufoff += bytesToWrite;
671 streamP->str_buflen -= bytesToWrite;
672 bytesWritten += bytesToWrite;
673 nbytes -= bytesToWrite;
676 return (bytesWritten / size);
679 /* fseek for buffered I/O handles */
681 stream_aseek(StreamHandle_t * streamP, afs_foff_t offset)
686 if (streamP->str_direction == STREAM_DIRECTION_WRITE
687 && streamP->str_bufoff > 0) {
688 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
689 streamP->str_bufoff, streamP->str_fdoff);
691 streamP->str_error = errno;
695 streamP->str_fdoff = offset;
696 streamP->str_bufoff = 0;
697 streamP->str_buflen = 0;
698 streamP->str_eof = 0;
699 streamP->str_direction = STREAM_DIRECTION_NONE;
703 /* fflush for buffered I/O handles */
705 stream_flush(StreamHandle_t * streamP)
710 if (streamP->str_direction == STREAM_DIRECTION_WRITE
711 && streamP->str_bufoff > 0) {
712 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
713 streamP->str_bufoff, streamP->str_fdoff);
715 streamP->str_error = errno;
718 streamP->str_fdoff += rc;
720 streamP->str_bufoff = 0;
721 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
727 /* Free a buffered I/O handle */
729 stream_close(StreamHandle_t * streamP, int reallyClose)
734 osi_Assert(streamP != NULL);
735 if (streamP->str_direction == STREAM_DIRECTION_WRITE
736 && streamP->str_bufoff > 0) {
737 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
738 streamP->str_bufoff, streamP->str_fdoff);
742 streamP->str_fdoff += rc;
746 rc = OS_CLOSE(streamP->str_fd);
751 streamP->str_fd = INVALID_FD;
754 DLL_INSERT_TAIL(streamP, streamAvailHead, streamAvailTail,
760 /* Close all unused file descriptors associated with the inode
761 * handle. Called with IH_LOCK held. May drop and reacquire
762 * IH_LOCK. Sets the IH_REALLY_CLOSED flag in the inode handle
763 * if it fails to close all file handles.
766 ih_fdclose(IHandle_t * ihP)
768 int closeCount, closedAll;
769 FdHandle_t *fdP, *head, *tail, *next;
771 osi_Assert(ihP->ih_refcnt > 0);
774 DLL_INIT_LIST(head, tail);
775 ihP->ih_flags &= ~IH_REALLY_CLOSED;
778 * Remove the file descriptors for this Inode from the LRU queue
779 * and the IHandle queue and put them on a temporary queue so we
780 * can drop the lock before we close the files.
782 for (fdP = ihP->ih_fdhead; fdP != NULL; fdP = next) {
783 next = fdP->fd_ihnext;
784 osi_Assert(fdP->fd_ih == ihP);
785 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN
786 || fdP->fd_status == FD_HANDLE_INUSE);
787 if (fdP->fd_status == FD_HANDLE_OPEN) {
788 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
790 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
791 DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev);
794 ihP->ih_flags |= IH_REALLY_CLOSED;
798 /* If the ihandle reference count is 1, we should have
799 * closed all file descriptors.
801 if (ihP->ih_refcnt == 1 || closedAll) {
802 osi_Assert(closedAll);
803 osi_Assert(!ihP->ih_fdhead);
804 osi_Assert(!ihP->ih_fdtail);
808 return 0; /* No file descriptors closed */
813 * Close the file descriptors
816 for (fdP = head; fdP != NULL; fdP = fdP->fd_next) {
817 OS_CLOSE(fdP->fd_fd);
818 fdP->fd_status = FD_HANDLE_AVAIL;
820 fdP->fd_fd = INVALID_FD;
826 osi_Assert(fdInUseCount >= closeCount);
827 fdInUseCount -= closeCount;
830 * Append the temporary queue to the list of available descriptors
832 if (fdAvailHead == NULL) {
836 fdAvailTail->fd_next = head;
837 head->fd_prev = fdAvailTail;
844 /* Close all cached file descriptors for this inode. */
846 ih_reallyclose(IHandle_t * ihP)
852 ihP->ih_refcnt++; /* must not disappear over unlock */
853 if (ihP->ih_synced) {
867 osi_Assert(ihP->ih_refcnt > 0);
871 if (ihP->ih_refcnt > 1)
880 /* Release an Inode handle. All cached file descriptors for this
881 * inode are closed when the last reference to this handle is released
884 _ih_release_r(IHandle_t * ihP)
891 osi_Assert(ihP->ih_refcnt > 0);
893 if (ihP->ih_refcnt > 1) {
898 ihash = IH_HASH(ihP->ih_dev, ihP->ih_vid, ihP->ih_ino);
899 DLL_DELETE(ihP, ihashTable[ihash].ihash_head,
900 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
906 DLL_INSERT_TAIL(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
911 /* Release an Inode handle. All cached file descriptors for this
912 * inode are closed when the last reference to this handle is released
915 ih_release(IHandle_t * ihP)
923 ret = _ih_release_r(ihP);
928 /* Sync an inode to disk if its handle isn't NULL */
930 ih_condsync(IHandle_t * ihP)
942 code = FDH_SYNC(fdP);
954 for (ihash = 0; ihash < I_HANDLE_HASH_SIZE; ihash++) {
955 IHandle_t *ihP, *ihPnext;
957 ihP = ihashTable[ihash].ihash_head;
959 ihP->ih_refcnt++; /* must not disappear over unlock */
960 for (; ihP; ihP = ihPnext) {
962 if (ihP->ih_synced) {
977 /* when decrementing the refcount, the ihandle might disappear
978 and we might not even be able to proceed to the next one.
979 Hence the gymnastics putting a hold on the next one already */
980 ihPnext = ihP->ih_next;
981 if (ihPnext) ihPnext->ih_refcnt++;
983 if (ihP->ih_refcnt > 1)
993 ih_sync_thread(void *dummy) {
994 afs_pthread_setname_self("ih_syncer");
997 #ifdef AFS_PTHREAD_ENV
999 #else /* AFS_PTHREAD_ENV */
1001 #endif /* AFS_PTHREAD_ENV */
1009 /*************************************************************************
1010 * OS specific support routines.
1011 *************************************************************************/
1012 #ifndef AFS_NAMEI_ENV
1014 ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, int p2,
1018 #ifdef AFS_3DISPARES
1019 /* See viceinode.h */
1020 if (p2 == INODESPECIAL) {
1026 ino = ICREATE(dev, part, nI, p1, p2, p3, p4);
1029 #endif /* AFS_NAMEI_ENV */
1036 if (!GetFileSizeEx(fd, &size))
1038 return size.QuadPart;
1040 struct afs_stat_st status;
1041 if (afs_fstat(fd, &status) < 0)
1043 return status.st_size;
1049 ih_pread(int fd, void * buf, size_t count, afs_foff_t offset)
1052 code = OS_SEEK(fd, offset, 0);
1055 return OS_READ(fd, buf, count);
1059 ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset)
1062 code = OS_SEEK(fd, offset, 0);
1065 return OS_WRITE(fd, buf, count);
1067 #endif /* !HAVE_PIO */