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) {
328 if (fdP->fd_status == FD_HANDLE_CLOSING) {
329 /* The handle was open when an IH_REALLYCLOSE was issued, so we
330 * cannot reuse it; it will be closed soon. */
335 * If we don't have positional i/o, don't try to share fds, since
336 * we can't do so in a threadsafe way.
338 if (fdP->fd_status == FD_HANDLE_INUSE) {
341 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
343 osi_Assert(fdP->fd_status != FD_HANDLE_AVAIL);
344 #endif /* HAVE_PIO */
347 if (fdP->fd_status == FD_HANDLE_OPEN) {
348 fdP->fd_status = FD_HANDLE_INUSE;
349 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
357 * Try to open the Inode, return NULL on error.
364 if (fd == INVALID_FD && (errno != EMFILE || fdLruHead == NULL) ) {
370 /* fdCacheSize limits the size of the descriptor cache, but
371 * we permit the number of open files to exceed fdCacheSize.
372 * We only recycle open file descriptors when the number
373 * of open files reaches the size of the cache */
374 if ((fdInUseCount > fdCacheSize || fd == INVALID_FD) && fdLruHead != NULL) {
376 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
377 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
378 DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail,
379 fd_ihnext, fd_ihprev);
380 closeFd = fdP->fd_fd;
381 if (fd == INVALID_FD) {
382 fdCacheSize--; /* reduce in order to not run into here too often */
383 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
384 fdP->fd_status = FD_HANDLE_AVAIL;
386 fdP->fd_fd = INVALID_FD;
392 if (fdAvailHead == NULL) {
393 fdHandleAllocateChunk();
396 osi_Assert(fdP->fd_status == FD_HANDLE_AVAIL);
397 DLL_DELETE(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
398 closeFd = INVALID_FD;
401 fdP->fd_status = FD_HANDLE_INUSE;
408 /* Add this handle to the Inode's list of open descriptors */
409 DLL_INSERT_TAIL(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
412 if (closeFd != INVALID_FD) {
424 * Return a file descriptor handle to the cache
427 fd_close(FdHandle_t * fdP)
435 osi_Assert(ih_Inited);
436 osi_Assert(fdInUseCount > 0);
437 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE ||
438 fdP->fd_status == FD_HANDLE_CLOSING);
442 /* Call fd_reallyclose to really close the unused file handles if
443 * the previous attempt to close (ih_reallyclose()) all file handles
444 * failed (this is determined by checking the ihandle for the flag
445 * IH_REALLY_CLOSED) or we have too many open files.
447 if (fdP->fd_status == FD_HANDLE_CLOSING ||
448 ihP->ih_flags & IH_REALLY_CLOSED || fdInUseCount > fdCacheSize) {
450 return fd_reallyclose(fdP);
454 if (fdP->fd_refcnt == 0) {
455 /* Put this descriptor back into the cache */
456 fdP->fd_status = FD_HANDLE_OPEN;
457 DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
460 /* If this is not the only reference to the Inode then we can decrement
461 * the reference count, otherwise we need to call ih_release.
463 if (ihP->ih_refcnt > 1)
474 * Actually close the file descriptor handle and return it to
478 fd_reallyclose(FdHandle_t * fdP)
487 osi_Assert(ih_Inited);
488 osi_Assert(fdInUseCount > 0);
489 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE ||
490 fdP->fd_status == FD_HANDLE_CLOSING);
493 closeFd = fdP->fd_fd;
496 if (fdP->fd_refcnt == 0) {
497 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev);
498 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
500 fdP->fd_status = FD_HANDLE_AVAIL;
503 fdP->fd_fd = INVALID_FD;
506 /* All the file descriptor handles have been closed; reset
507 * the IH_REALLY_CLOSED flag indicating that ih_reallyclose
508 * has completed its job.
510 if (!ihP->ih_fdhead) {
511 ihP->ih_flags &= ~IH_REALLY_CLOSED;
514 if (fdP->fd_refcnt == 0) {
521 /* If this is not the only reference to the Inode then we can decrement
522 * the reference count, otherwise we need to call ih_release. */
523 if (ihP->ih_refcnt > 1)
533 /* Enable buffered I/O on a file descriptor */
535 stream_fdopen(FD_t fd)
537 StreamHandle_t *streamP;
540 if (streamAvailHead == NULL) {
541 streamHandleAllocateChunk();
543 streamP = streamAvailHead;
544 DLL_DELETE(streamP, streamAvailHead, streamAvailTail, str_next, str_prev);
546 streamP->str_fd = fd;
547 streamP->str_buflen = 0;
548 streamP->str_bufoff = 0;
549 streamP->str_fdoff = 0;
550 streamP->str_error = 0;
551 streamP->str_eof = 0;
552 streamP->str_direction = STREAM_DIRECTION_NONE;
556 /* Open a file for buffered I/O */
558 stream_open(const char *filename, const char *mode)
560 FD_t fd = INVALID_FD;
562 if (strcmp(mode, "r") == 0) {
563 fd = OS_OPEN(filename, O_RDONLY, 0);
564 } else if (strcmp(mode, "r+") == 0) {
565 fd = OS_OPEN(filename, O_RDWR, 0);
566 } else if (strcmp(mode, "w") == 0) {
567 fd = OS_OPEN(filename, O_WRONLY | O_TRUNC | O_CREAT, 0);
568 } else if (strcmp(mode, "w+") == 0) {
569 fd = OS_OPEN(filename, O_RDWR | O_TRUNC | O_CREAT, 0);
570 } else if (strcmp(mode, "a") == 0) {
571 fd = OS_OPEN(filename, O_WRONLY | O_APPEND | O_CREAT, 0);
572 } else if (strcmp(mode, "a+") == 0) {
573 fd = OS_OPEN(filename, O_RDWR | O_APPEND | O_CREAT, 0);
575 osi_Assert(FALSE); /* not implemented */
578 if (fd == INVALID_FD) {
581 return stream_fdopen(fd);
584 /* fread for buffered I/O handles */
586 stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
587 StreamHandle_t * streamP)
589 afs_fsize_t nbytes, bytesRead, bytesToRead;
592 /* Need to seek before changing direction */
593 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
594 streamP->str_direction = STREAM_DIRECTION_READ;
595 streamP->str_bufoff = 0;
596 streamP->str_buflen = 0;
598 osi_Assert(streamP->str_direction == STREAM_DIRECTION_READ);
602 nbytes = size * nitems;
604 while (nbytes > 0 && !streamP->str_eof) {
605 if (streamP->str_buflen == 0) {
606 streamP->str_bufoff = 0;
607 streamP->str_buflen =
608 OS_PREAD(streamP->str_fd, streamP->str_buffer,
609 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
610 if (streamP->str_buflen < 0) {
611 streamP->str_error = errno;
612 streamP->str_buflen = 0;
615 } else if (streamP->str_buflen == 0) {
616 streamP->str_eof = 1;
619 streamP->str_fdoff += streamP->str_buflen;
622 bytesToRead = nbytes;
623 if (bytesToRead > streamP->str_buflen) {
624 bytesToRead = streamP->str_buflen;
626 memcpy(p, streamP->str_buffer + streamP->str_bufoff, bytesToRead);
628 streamP->str_bufoff += bytesToRead;
629 streamP->str_buflen -= bytesToRead;
630 bytesRead += bytesToRead;
631 nbytes -= bytesToRead;
634 return (bytesRead / size);
637 /* fwrite for buffered I/O handles */
639 stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
640 StreamHandle_t * streamP)
644 afs_fsize_t nbytes, bytesWritten, bytesToWrite;
646 /* Need to seek before changing direction */
647 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
648 streamP->str_direction = STREAM_DIRECTION_WRITE;
649 streamP->str_bufoff = 0;
650 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
652 osi_Assert(streamP->str_direction == STREAM_DIRECTION_WRITE);
655 nbytes = size * nitems;
659 if (streamP->str_buflen == 0) {
660 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
661 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
663 streamP->str_error = errno;
667 streamP->str_fdoff += rc;
668 streamP->str_bufoff = 0;
669 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
672 bytesToWrite = nbytes;
673 if (bytesToWrite > streamP->str_buflen) {
674 bytesToWrite = streamP->str_buflen;
676 memcpy(streamP->str_buffer + streamP->str_bufoff, p, bytesToWrite);
678 streamP->str_bufoff += bytesToWrite;
679 streamP->str_buflen -= bytesToWrite;
680 bytesWritten += bytesToWrite;
681 nbytes -= bytesToWrite;
684 return (bytesWritten / size);
687 /* fseek for buffered I/O handles */
689 stream_aseek(StreamHandle_t * streamP, afs_foff_t offset)
694 if (streamP->str_direction == STREAM_DIRECTION_WRITE
695 && streamP->str_bufoff > 0) {
696 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
697 streamP->str_bufoff, streamP->str_fdoff);
699 streamP->str_error = errno;
703 streamP->str_fdoff = offset;
704 streamP->str_bufoff = 0;
705 streamP->str_buflen = 0;
706 streamP->str_eof = 0;
707 streamP->str_direction = STREAM_DIRECTION_NONE;
711 /* fflush for buffered I/O handles */
713 stream_flush(StreamHandle_t * streamP)
718 if (streamP->str_direction == STREAM_DIRECTION_WRITE
719 && streamP->str_bufoff > 0) {
720 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
721 streamP->str_bufoff, streamP->str_fdoff);
723 streamP->str_error = errno;
726 streamP->str_fdoff += rc;
728 streamP->str_bufoff = 0;
729 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
735 /* Free a buffered I/O handle */
737 stream_close(StreamHandle_t * streamP, int reallyClose)
742 osi_Assert(streamP != NULL);
743 if (streamP->str_direction == STREAM_DIRECTION_WRITE
744 && streamP->str_bufoff > 0) {
745 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
746 streamP->str_bufoff, streamP->str_fdoff);
750 streamP->str_fdoff += rc;
754 rc = OS_CLOSE(streamP->str_fd);
759 streamP->str_fd = INVALID_FD;
762 DLL_INSERT_TAIL(streamP, streamAvailHead, streamAvailTail,
768 /* Close all unused file descriptors associated with the inode
769 * handle. Called with IH_LOCK held. May drop and reacquire
770 * IH_LOCK. Sets the IH_REALLY_CLOSED flag in the inode handle
771 * if it fails to close all file handles.
774 ih_fdclose(IHandle_t * ihP)
776 int closeCount, closedAll;
777 FdHandle_t *fdP, *head, *tail, *next;
779 osi_Assert(ihP->ih_refcnt > 0);
782 DLL_INIT_LIST(head, tail);
783 ihP->ih_flags &= ~IH_REALLY_CLOSED;
786 * Remove the file descriptors for this Inode from the LRU queue
787 * and the IHandle queue and put them on a temporary queue so we
788 * can drop the lock before we close the files.
790 for (fdP = ihP->ih_fdhead; fdP != NULL; fdP = next) {
791 next = fdP->fd_ihnext;
792 osi_Assert(fdP->fd_ih == ihP);
793 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN
794 || fdP->fd_status == FD_HANDLE_INUSE
795 || fdP->fd_status == FD_HANDLE_CLOSING);
796 if (fdP->fd_status == FD_HANDLE_OPEN) {
797 /* Note that FdHandle_t's do not count against the parent
798 * IHandle_t ref count when they are FD_HANDLE_OPEN. So, we don't
799 * need to dec the parent IHandle_t ref count for each one we pull
801 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
803 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
804 DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev);
807 fdP->fd_status = FD_HANDLE_CLOSING;
808 ihP->ih_flags |= IH_REALLY_CLOSED;
812 /* If the ihandle reference count is 1, we should have
813 * closed all file descriptors.
815 if (ihP->ih_refcnt == 1 || closedAll) {
816 osi_Assert(closedAll);
817 osi_Assert(!ihP->ih_fdhead);
818 osi_Assert(!ihP->ih_fdtail);
822 return 0; /* No file descriptors closed */
827 * Close the file descriptors
830 for (fdP = head; fdP != NULL; fdP = fdP->fd_next) {
831 OS_CLOSE(fdP->fd_fd);
832 fdP->fd_status = FD_HANDLE_AVAIL;
834 fdP->fd_fd = INVALID_FD;
840 osi_Assert(fdInUseCount >= closeCount);
841 fdInUseCount -= closeCount;
844 * Append the temporary queue to the list of available descriptors
846 if (fdAvailHead == NULL) {
850 fdAvailTail->fd_next = head;
851 head->fd_prev = fdAvailTail;
858 /* Close all cached file descriptors for this inode. */
860 ih_reallyclose(IHandle_t * ihP)
866 ihP->ih_refcnt++; /* must not disappear over unlock */
867 if (ihP->ih_synced) {
881 osi_Assert(ihP->ih_refcnt > 0);
885 if (ihP->ih_refcnt > 1)
894 /* Release an Inode handle. All cached file descriptors for this
895 * inode are closed when the last reference to this handle is released
898 _ih_release_r(IHandle_t * ihP)
905 osi_Assert(ihP->ih_refcnt > 0);
907 if (ihP->ih_refcnt > 1) {
912 ihash = IH_HASH(ihP->ih_dev, ihP->ih_vid, ihP->ih_ino);
913 DLL_DELETE(ihP, ihashTable[ihash].ihash_head,
914 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
920 DLL_INSERT_TAIL(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
925 /* Release an Inode handle. All cached file descriptors for this
926 * inode are closed when the last reference to this handle is released
929 ih_release(IHandle_t * ihP)
937 ret = _ih_release_r(ihP);
942 /* Sync an inode to disk if its handle isn't NULL */
944 ih_condsync(IHandle_t * ihP)
956 code = FDH_SYNC(fdP);
968 for (ihash = 0; ihash < I_HANDLE_HASH_SIZE; ihash++) {
969 IHandle_t *ihP, *ihPnext;
971 ihP = ihashTable[ihash].ihash_head;
973 ihP->ih_refcnt++; /* must not disappear over unlock */
974 for (; ihP; ihP = ihPnext) {
976 if (ihP->ih_synced) {
991 /* when decrementing the refcount, the ihandle might disappear
992 and we might not even be able to proceed to the next one.
993 Hence the gymnastics putting a hold on the next one already */
994 ihPnext = ihP->ih_next;
995 if (ihPnext) ihPnext->ih_refcnt++;
997 if (ihP->ih_refcnt > 1)
1007 ih_sync_thread(void *dummy) {
1008 afs_pthread_setname_self("ih_syncer");
1011 #ifdef AFS_PTHREAD_ENV
1013 #else /* AFS_PTHREAD_ENV */
1015 #endif /* AFS_PTHREAD_ENV */
1023 /*************************************************************************
1024 * OS specific support routines.
1025 *************************************************************************/
1026 #ifndef AFS_NAMEI_ENV
1028 ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, int p2,
1032 #ifdef AFS_3DISPARES
1033 /* See viceinode.h */
1034 if (p2 == INODESPECIAL) {
1040 ino = ICREATE(dev, part, nI, p1, p2, p3, p4);
1043 #endif /* AFS_NAMEI_ENV */
1050 if (!GetFileSizeEx(fd, &size))
1052 return size.QuadPart;
1054 struct afs_stat_st status;
1055 if (afs_fstat(fd, &status) < 0)
1057 return status.st_size;
1063 ih_pread(int fd, void * buf, size_t count, afs_foff_t offset)
1066 code = OS_SEEK(fd, offset, 0);
1069 return OS_READ(fd, buf, count);
1073 ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset)
1076 code = OS_SEEK(fd, offset, 0);
1079 return OS_WRITE(fd, buf, count);
1081 #endif /* !HAVE_PIO */