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 #ifdef AFS_PTHREAD_ENV
27 # include <opr/lock.h>
29 #include <afs/afsint.h>
30 #include <afs/afssyscalls.h>
31 #include <afs/afsutil.h>
35 #include "viceinode.h"
37 #ifdef AFS_PTHREAD_ENV
38 pthread_once_t ih_glock_once = PTHREAD_ONCE_INIT;
39 pthread_mutex_t ih_glock_mutex;
40 #endif /* AFS_PTHREAD_ENV */
42 /* Linked list of available inode handles */
43 IHandle_t *ihAvailHead;
44 IHandle_t *ihAvailTail;
46 /* Linked list of available file descriptor handles */
47 FdHandle_t *fdAvailHead;
48 FdHandle_t *fdAvailTail;
50 /* Linked list of available stream descriptor handles */
51 StreamHandle_t *streamAvailHead;
52 StreamHandle_t *streamAvailTail;
54 /* LRU list for file descriptor handles */
55 FdHandle_t *fdLruHead;
56 FdHandle_t *fdLruTail;
59 int ih_PkgDefaultsSet = 0;
61 /* Most of the servers use fopen/fdopen. Since the FILE structure
62 * only has eight bits for the file descriptor, the cache size
63 * has to be less than 256. The cache can be made larger as long
64 * as you are sure you don't need fopen/fdopen. */
66 /* As noted in ihandle.h, the fileno member of FILE on most platforms
67 * in 2008 is a 16- or 32-bit signed int. -Matt
69 int fdMaxCacheSize = 0;
72 /* Number of in use file descriptors */
75 /* Hash table for inode handles */
76 IHashBucket_t ihashTable[I_HANDLE_HASH_SIZE];
78 static int _ih_release_r(IHandle_t * ihP);
80 /* start-time configurable I/O limits */
81 ih_init_params vol_io_params;
83 void ih_PkgDefaults(void)
86 ih_PkgDefaultsSet = 1;
88 /* default to well-known values */
89 vol_io_params.fd_handle_setaside = FD_HANDLE_SETASIDE;
91 /* initial fd cachesize. the only one that will be used if
92 * the application does not call ih_UseLargeCache(). set this
93 * to a value representable in fileno member of the system's
94 * FILE structure (or equivalent). */
95 vol_io_params.fd_initial_cachesize = FD_DEFAULT_CACHESIZE;
97 /* fd cache size that will be used if/when ih_UseLargeCache()
99 vol_io_params.fd_max_cachesize = FD_MAX_CACHESIZE;
101 vol_io_params.sync_behavior = IH_SYNC_ONCLOSE;
105 ih_SetSyncBehavior(const char *behavior)
109 if (strcmp(behavior, "always") == 0) {
110 val = IH_SYNC_ALWAYS;
112 } else if (strcmp(behavior, "onclose") == 0) {
113 val = IH_SYNC_ONCLOSE;
115 } else if (strcmp(behavior, "never") == 0) {
119 /* invalid behavior name */
123 vol_io_params.sync_behavior = val;
127 #ifdef AFS_PTHREAD_ENV
128 /* Initialize the global ihandle mutex */
132 opr_mutex_init(&ih_glock_mutex);
134 #endif /* AFS_PTHREAD_ENV */
136 /* Initialize the file descriptor cache */
141 opr_Assert(!ih_Inited);
143 DLL_INIT_LIST(ihAvailHead, ihAvailTail);
144 DLL_INIT_LIST(fdAvailHead, fdAvailTail);
145 DLL_INIT_LIST(fdLruHead, fdLruTail);
146 for (i = 0; i < I_HANDLE_HASH_SIZE; i++) {
147 DLL_INIT_LIST(ihashTable[i].ihash_head, ihashTable[i].ihash_tail);
149 #if defined(AFS_NT40_ENV)
150 fdMaxCacheSize = vol_io_params.fd_max_cachesize;
151 #elif defined(AFS_SUN5_ENV) || defined(AFS_NBSD_ENV)
154 opr_Verify(getrlimit(RLIMIT_NOFILE, &rlim) == 0);
155 rlim.rlim_cur = rlim.rlim_max;
156 opr_Verify(setrlimit(RLIMIT_NOFILE, &rlim) == 0);
157 fdMaxCacheSize = rlim.rlim_cur - vol_io_params.fd_handle_setaside;
159 /* XXX this is to avoid using up all system fd netbsd is
160 * somewhat broken and have set maximum fd for a root process
161 * to the same as system fd that is avaible, so if the
162 * fileserver uses all up process fds, all system fd will be
165 * Check for this better
169 fdMaxCacheSize = min(fdMaxCacheSize, vol_io_params.fd_max_cachesize);
170 opr_Assert(fdMaxCacheSize > 0);
172 #elif defined(AFS_HPUX_ENV)
173 /* Avoid problems with "UFSOpen: igetinode failed" panics on HPUX 11.0 */
177 long fdMax = max(sysconf(_SC_OPEN_MAX) - vol_io_params.fd_handle_setaside,
179 fdMaxCacheSize = (int)min(fdMax, vol_io_params.fd_max_cachesize);
182 fdCacheSize = min(fdMaxCacheSize, vol_io_params.fd_initial_cachesize);
185 /* Make the file descriptor cache as big as possible. Don't this call
186 * if the program uses fopen or fdopen, if fd_max_cachesize cannot be
187 * represented in the fileno member of the system FILE structure (or
191 ih_UseLargeCache(void)
195 if (!ih_PkgDefaultsSet) {
203 fdCacheSize = fdMaxCacheSize;
208 /* Allocate a chunk of inode handles */
210 iHandleAllocateChunk(void)
215 opr_Assert(ihAvailHead == NULL);
216 ihP = malloc(I_HANDLE_MALLOCSIZE * sizeof(IHandle_t));
217 opr_Assert(ihP != NULL);
218 for (i = 0; i < I_HANDLE_MALLOCSIZE; i++) {
219 ihP[i].ih_refcnt = 0;
220 DLL_INSERT_TAIL(&ihP[i], ihAvailHead, ihAvailTail, ih_next, ih_prev);
224 /* Initialize an inode handle */
226 ih_init(int dev, int vid, Inode ino)
228 int ihash = IH_HASH(dev, vid, ino);
231 if (!ih_PkgDefaultsSet) {
240 /* Do we already have a handle for this Inode? */
241 for (ihP = ihashTable[ihash].ihash_head; ihP; ihP = ihP->ih_next) {
242 if (ihP->ih_ino == ino && ihP->ih_vid == vid && ihP->ih_dev == dev) {
249 /* Allocate and initialize a new Inode handle */
250 if (ihAvailHead == NULL) {
251 iHandleAllocateChunk();
254 opr_Assert(ihP->ih_refcnt == 0);
255 DLL_DELETE(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
262 DLL_INIT_LIST(ihP->ih_fdhead, ihP->ih_fdtail);
263 DLL_INSERT_TAIL(ihP, ihashTable[ihash].ihash_head,
264 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
269 /* Copy an inode handle */
271 ih_copy(IHandle_t * ihP)
274 opr_Assert(ih_Inited);
275 opr_Assert(ihP->ih_refcnt > 0);
281 /* Allocate a chunk of file descriptor handles */
283 fdHandleAllocateChunk(void)
288 opr_Assert(fdAvailHead == NULL);
289 fdP = malloc(FD_HANDLE_MALLOCSIZE * sizeof(FdHandle_t));
290 opr_Assert(fdP != NULL);
291 for (i = 0; i < FD_HANDLE_MALLOCSIZE; i++) {
292 fdP[i].fd_status = FD_HANDLE_AVAIL;
293 fdP[i].fd_refcnt = 0;
295 fdP[i].fd_fd = INVALID_FD;
296 fdP[i].fd_ihnext = NULL;
297 fdP[i].fd_ihprev = NULL;
298 DLL_INSERT_TAIL(&fdP[i], fdAvailHead, fdAvailTail, fd_next, fd_prev);
302 /* Allocate a chunk of stream handles */
304 streamHandleAllocateChunk(void)
307 StreamHandle_t *streamP;
309 opr_Assert(streamAvailHead == NULL);
310 streamP = (StreamHandle_t *)
311 malloc(STREAM_HANDLE_MALLOCSIZE * sizeof(StreamHandle_t));
312 opr_Assert(streamP != NULL);
313 for (i = 0; i < STREAM_HANDLE_MALLOCSIZE; i++) {
314 streamP[i].str_fd = INVALID_FD;
315 DLL_INSERT_TAIL(&streamP[i], streamAvailHead, streamAvailTail,
321 * Get a file descriptor handle given an Inode handle
324 ih_open(IHandle_t * ihP)
330 if (!ihP) /* XXX should log here in the fileserver */
335 /* Do we already have an open file handle for this Inode? */
336 for (fdP = ihP->ih_fdtail; fdP != NULL; fdP = fdP->fd_ihprev) {
337 if (fdP->fd_status == FD_HANDLE_CLOSING) {
338 /* The handle was open when an IH_REALLYCLOSE was issued, so we
339 * cannot reuse it; it will be closed soon. */
344 * If we don't have positional i/o, don't try to share fds, since
345 * we can't do so in a threadsafe way.
347 if (fdP->fd_status == FD_HANDLE_INUSE) {
350 opr_Assert(fdP->fd_status == FD_HANDLE_OPEN);
352 opr_Assert(fdP->fd_status != FD_HANDLE_AVAIL);
353 #endif /* HAVE_PIO */
356 if (fdP->fd_status == FD_HANDLE_OPEN) {
357 fdP->fd_status = FD_HANDLE_INUSE;
358 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
366 * Try to open the Inode, return NULL on error.
373 if (fd == INVALID_FD && (errno != EMFILE || fdLruHead == NULL) ) {
379 /* fdCacheSize limits the size of the descriptor cache, but
380 * we permit the number of open files to exceed fdCacheSize.
381 * We only recycle open file descriptors when the number
382 * of open files reaches the size of the cache */
383 if ((fdInUseCount > fdCacheSize || fd == INVALID_FD) && fdLruHead != NULL) {
385 opr_Assert(fdP->fd_status == FD_HANDLE_OPEN);
386 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
387 DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail,
388 fd_ihnext, fd_ihprev);
389 closeFd = fdP->fd_fd;
390 if (fd == INVALID_FD) {
391 fdCacheSize--; /* reduce in order to not run into here too often */
392 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
393 fdP->fd_status = FD_HANDLE_AVAIL;
395 fdP->fd_fd = INVALID_FD;
404 if (fdAvailHead == NULL) {
405 fdHandleAllocateChunk();
408 opr_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 opr_Assert(ih_Inited);
448 opr_Assert(fdInUseCount > 0);
449 opr_Assert(fdP->fd_status == FD_HANDLE_INUSE ||
450 fdP->fd_status == FD_HANDLE_CLOSING);
454 /* Call fd_reallyclose to really close the unused file handles if
455 * the previous attempt to close (ih_reallyclose()) all file handles
456 * failed (this is determined by checking the ihandle for the flag
457 * IH_REALLY_CLOSED) or we have too many open files.
459 if (fdP->fd_status == FD_HANDLE_CLOSING ||
460 ihP->ih_flags & IH_REALLY_CLOSED || fdInUseCount > fdCacheSize) {
462 return fd_reallyclose(fdP);
466 if (fdP->fd_refcnt == 0) {
467 /* Put this descriptor back into the cache */
468 fdP->fd_status = FD_HANDLE_OPEN;
469 DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
472 /* If this is not the only reference to the Inode then we can decrement
473 * the reference count, otherwise we need to call ih_release.
475 if (ihP->ih_refcnt > 1)
486 * Actually close the file descriptor handle and return it to
490 fd_reallyclose(FdHandle_t * fdP)
499 opr_Assert(ih_Inited);
500 opr_Assert(fdInUseCount > 0);
501 opr_Assert(fdP->fd_status == FD_HANDLE_INUSE ||
502 fdP->fd_status == FD_HANDLE_CLOSING);
505 closeFd = fdP->fd_fd;
508 if (fdP->fd_refcnt == 0) {
509 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev);
510 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
512 fdP->fd_status = FD_HANDLE_AVAIL;
515 fdP->fd_fd = INVALID_FD;
518 /* All the file descriptor handles have been closed; reset
519 * the IH_REALLY_CLOSED flag indicating that ih_reallyclose
520 * has completed its job.
522 if (!ihP->ih_fdhead) {
523 ihP->ih_flags &= ~IH_REALLY_CLOSED;
525 FdHandle_t *lfdP, *next;
527 for (lfdP = ihP->ih_fdhead; lfdP != NULL; lfdP = next) {
528 next = lfdP->fd_ihnext;
529 osi_Assert(lfdP->fd_ih == ihP);
530 if (lfdP->fd_status != FD_HANDLE_CLOSING) {
535 /* no *future* fd should be subjected to this */
537 ihP->ih_flags &= ~IH_REALLY_CLOSED;
540 if (fdP->fd_refcnt == 0) {
547 /* If this is not the only reference to the Inode then we can decrement
548 * the reference count, otherwise we need to call ih_release. */
549 if (ihP->ih_refcnt > 1)
559 /* Enable buffered I/O on a file descriptor */
561 stream_fdopen(FD_t fd)
563 StreamHandle_t *streamP;
566 if (streamAvailHead == NULL) {
567 streamHandleAllocateChunk();
569 streamP = streamAvailHead;
570 DLL_DELETE(streamP, streamAvailHead, streamAvailTail, str_next, str_prev);
572 streamP->str_fd = fd;
573 streamP->str_buflen = 0;
574 streamP->str_bufoff = 0;
575 streamP->str_fdoff = 0;
576 streamP->str_error = 0;
577 streamP->str_eof = 0;
578 streamP->str_direction = STREAM_DIRECTION_NONE;
582 /* Open a file for buffered I/O */
584 stream_open(const char *filename, const char *mode)
586 FD_t fd = INVALID_FD;
588 if (strcmp(mode, "r") == 0) {
589 fd = OS_OPEN(filename, O_RDONLY, 0);
590 } else if (strcmp(mode, "r+") == 0) {
591 fd = OS_OPEN(filename, O_RDWR, 0);
592 } else if (strcmp(mode, "w") == 0) {
593 fd = OS_OPEN(filename, O_WRONLY | O_TRUNC | O_CREAT, 0);
594 } else if (strcmp(mode, "w+") == 0) {
595 fd = OS_OPEN(filename, O_RDWR | O_TRUNC | O_CREAT, 0);
596 } else if (strcmp(mode, "a") == 0) {
597 fd = OS_OPEN(filename, O_WRONLY | O_APPEND | O_CREAT, 0);
598 } else if (strcmp(mode, "a+") == 0) {
599 fd = OS_OPEN(filename, O_RDWR | O_APPEND | O_CREAT, 0);
601 opr_abort(); /* not implemented */
604 if (fd == INVALID_FD) {
607 return stream_fdopen(fd);
610 /* fread for buffered I/O handles */
612 stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
613 StreamHandle_t * streamP)
615 afs_fsize_t nbytes, bytesRead, bytesToRead;
618 /* Need to seek before changing direction */
619 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
620 streamP->str_direction = STREAM_DIRECTION_READ;
621 streamP->str_bufoff = 0;
622 streamP->str_buflen = 0;
624 opr_Assert(streamP->str_direction == STREAM_DIRECTION_READ);
628 nbytes = size * nitems;
630 while (nbytes > 0 && !streamP->str_eof) {
631 if (streamP->str_buflen == 0) {
632 streamP->str_bufoff = 0;
633 streamP->str_buflen =
634 OS_PREAD(streamP->str_fd, streamP->str_buffer,
635 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
636 if (streamP->str_buflen < 0) {
637 streamP->str_error = errno;
638 streamP->str_buflen = 0;
641 } else if (streamP->str_buflen == 0) {
642 streamP->str_eof = 1;
645 streamP->str_fdoff += streamP->str_buflen;
648 bytesToRead = nbytes;
649 if (bytesToRead > streamP->str_buflen) {
650 bytesToRead = streamP->str_buflen;
652 memcpy(p, streamP->str_buffer + streamP->str_bufoff, bytesToRead);
654 streamP->str_bufoff += bytesToRead;
655 streamP->str_buflen -= bytesToRead;
656 bytesRead += bytesToRead;
657 nbytes -= bytesToRead;
660 return (bytesRead / size);
663 /* fwrite for buffered I/O handles */
665 stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
666 StreamHandle_t * streamP)
670 afs_fsize_t nbytes, bytesWritten, bytesToWrite;
672 /* Need to seek before changing direction */
673 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
674 streamP->str_direction = STREAM_DIRECTION_WRITE;
675 streamP->str_bufoff = 0;
676 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
678 opr_Assert(streamP->str_direction == STREAM_DIRECTION_WRITE);
681 nbytes = size * nitems;
685 if (streamP->str_buflen == 0) {
686 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
687 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
689 streamP->str_error = errno;
693 streamP->str_fdoff += rc;
694 streamP->str_bufoff = 0;
695 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
698 bytesToWrite = nbytes;
699 if (bytesToWrite > streamP->str_buflen) {
700 bytesToWrite = streamP->str_buflen;
702 memcpy(streamP->str_buffer + streamP->str_bufoff, p, bytesToWrite);
704 streamP->str_bufoff += bytesToWrite;
705 streamP->str_buflen -= bytesToWrite;
706 bytesWritten += bytesToWrite;
707 nbytes -= bytesToWrite;
710 return (bytesWritten / size);
713 /* fseek for buffered I/O handles */
715 stream_aseek(StreamHandle_t * streamP, afs_foff_t offset)
720 if (streamP->str_direction == STREAM_DIRECTION_WRITE
721 && streamP->str_bufoff > 0) {
722 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
723 streamP->str_bufoff, streamP->str_fdoff);
725 streamP->str_error = errno;
729 streamP->str_fdoff = offset;
730 streamP->str_bufoff = 0;
731 streamP->str_buflen = 0;
732 streamP->str_eof = 0;
733 streamP->str_direction = STREAM_DIRECTION_NONE;
737 /* fflush for buffered I/O handles */
739 stream_flush(StreamHandle_t * streamP)
744 if (streamP->str_direction == STREAM_DIRECTION_WRITE
745 && streamP->str_bufoff > 0) {
746 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
747 streamP->str_bufoff, streamP->str_fdoff);
749 streamP->str_error = errno;
752 streamP->str_fdoff += rc;
754 streamP->str_bufoff = 0;
755 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
761 /* Free a buffered I/O handle */
763 stream_close(StreamHandle_t * streamP, int reallyClose)
768 opr_Assert(streamP != NULL);
769 if (streamP->str_direction == STREAM_DIRECTION_WRITE
770 && streamP->str_bufoff > 0) {
771 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
772 streamP->str_bufoff, streamP->str_fdoff);
776 streamP->str_fdoff += rc;
780 rc = OS_CLOSE(streamP->str_fd);
785 streamP->str_fd = INVALID_FD;
788 DLL_INSERT_TAIL(streamP, streamAvailHead, streamAvailTail,
794 /* Close all unused file descriptors associated with the inode
795 * handle. Called with IH_LOCK held. May drop and reacquire
796 * IH_LOCK. Sets the IH_REALLY_CLOSED flag in the inode handle
797 * if it fails to close all file handles.
800 ih_fdclose(IHandle_t * ihP)
802 int closeCount, closedAll;
803 FdHandle_t *fdP, *head, *tail, *next;
805 opr_Assert(ihP->ih_refcnt > 0);
808 DLL_INIT_LIST(head, tail);
809 ihP->ih_flags &= ~IH_REALLY_CLOSED;
812 * Remove the file descriptors for this Inode from the LRU queue
813 * and the IHandle queue and put them on a temporary queue so we
814 * can drop the lock before we close the files.
816 for (fdP = ihP->ih_fdhead; fdP != NULL; fdP = next) {
817 next = fdP->fd_ihnext;
818 opr_Assert(fdP->fd_ih == ihP);
819 opr_Assert(fdP->fd_status == FD_HANDLE_OPEN
820 || fdP->fd_status == FD_HANDLE_INUSE
821 || fdP->fd_status == FD_HANDLE_CLOSING);
822 if (fdP->fd_status == FD_HANDLE_OPEN) {
823 /* Note that FdHandle_t's do not count against the parent
824 * IHandle_t ref count when they are FD_HANDLE_OPEN. So, we don't
825 * need to dec the parent IHandle_t ref count for each one we pull
827 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
829 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
830 DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev);
833 fdP->fd_status = FD_HANDLE_CLOSING;
834 ihP->ih_flags |= IH_REALLY_CLOSED;
838 /* If the ihandle reference count is 1, we should have
839 * closed all file descriptors.
841 if (ihP->ih_refcnt == 1 || closedAll) {
842 opr_Assert(closedAll);
843 opr_Assert(!ihP->ih_fdhead);
844 opr_Assert(!ihP->ih_fdtail);
848 return 0; /* No file descriptors closed */
853 * Close the file descriptors
856 for (fdP = head; fdP != NULL; fdP = fdP->fd_next) {
857 OS_CLOSE(fdP->fd_fd);
858 fdP->fd_status = FD_HANDLE_AVAIL;
860 fdP->fd_fd = INVALID_FD;
866 opr_Assert(fdInUseCount >= closeCount);
867 fdInUseCount -= closeCount;
870 * Append the temporary queue to the list of available descriptors
872 if (fdAvailHead == NULL) {
876 fdAvailTail->fd_next = head;
877 head->fd_prev = fdAvailTail;
884 /* Close all cached file descriptors for this inode. */
886 ih_reallyclose(IHandle_t * ihP)
892 ihP->ih_refcnt++; /* must not disappear over unlock */
893 if (ihP->ih_synced) {
895 opr_Assert(vol_io_params.sync_behavior != IH_SYNC_ALWAYS);
896 opr_Assert(vol_io_params.sync_behavior != IH_SYNC_NEVER);
909 opr_Assert(ihP->ih_refcnt > 0);
913 if (ihP->ih_refcnt > 1)
922 /* Release an Inode handle. All cached file descriptors for this
923 * inode are closed when the last reference to this handle is released
926 _ih_release_r(IHandle_t * ihP)
933 opr_Assert(ihP->ih_refcnt > 0);
935 if (ihP->ih_refcnt > 1) {
940 ihash = IH_HASH(ihP->ih_dev, ihP->ih_vid, ihP->ih_ino);
941 DLL_DELETE(ihP, ihashTable[ihash].ihash_head,
942 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
948 DLL_INSERT_TAIL(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
953 /* Release an Inode handle. All cached file descriptors for this
954 * inode are closed when the last reference to this handle is released
957 ih_release(IHandle_t * ihP)
965 ret = _ih_release_r(ihP);
970 /* Sync an inode to disk if its handle isn't NULL */
972 ih_condsync(IHandle_t * ihP)
984 code = FDH_SYNC(fdP);
990 /*************************************************************************
991 * OS specific support routines.
992 *************************************************************************/
993 #ifndef AFS_NAMEI_ENV
995 ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, int p2,
1000 /* See viceinode.h */
1001 if (p2 == INODESPECIAL) {
1007 ino = ICREATE(dev, part, nI, p1, p2, p3, p4);
1010 #endif /* AFS_NAMEI_ENV */
1017 if (!GetFileSizeEx(fd, &size))
1019 return size.QuadPart;
1021 struct afs_stat_st status;
1022 if (afs_fstat(fd, &status) < 0)
1024 return status.st_size;
1030 ih_pread(int fd, void * buf, size_t count, afs_foff_t offset)
1033 code = OS_SEEK(fd, offset, 0);
1036 return OS_READ(fd, buf, count);
1040 ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset)
1043 code = OS_SEEK(fd, offset, 0);
1046 return OS_WRITE(fd, buf, count);
1048 #endif /* !HAVE_PIO */
1050 #ifndef AFS_NT40_ENV
1052 ih_isunlinked(int fd)
1054 struct afs_stat_st status;
1055 if (afs_fstat(fd, &status) < 0) {
1058 if (status.st_nlink < 1) {
1063 #endif /* !AFS_NT40_ENV */
1066 ih_fdsync(FdHandle_t *fdP)
1068 switch (vol_io_params.sync_behavior) {
1069 case IH_SYNC_ALWAYS:
1070 return OS_SYNC(fdP->fd_fd);
1071 case IH_SYNC_ONCLOSE:
1073 fdP->fd_ih->ih_synced = 1;