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"
45 #ifdef AFS_PTHREAD_ENV
46 pthread_once_t ih_glock_once = PTHREAD_ONCE_INIT;
47 pthread_mutex_t ih_glock_mutex;
48 #endif /* AFS_PTHREAD_ENV */
50 /* Linked list of available inode handles */
51 IHandle_t *ihAvailHead;
52 IHandle_t *ihAvailTail;
54 /* Linked list of available file descriptor handles */
55 FdHandle_t *fdAvailHead;
56 FdHandle_t *fdAvailTail;
58 /* Linked list of available stream descriptor handles */
59 StreamHandle_t *streamAvailHead;
60 StreamHandle_t *streamAvailTail;
62 /* LRU list for file descriptor handles */
63 FdHandle_t *fdLruHead;
64 FdHandle_t *fdLruTail;
67 int ih_PkgDefaultsSet = 0;
69 /* Most of the servers use fopen/fdopen. Since the FILE structure
70 * only has eight bits for the file descriptor, the cache size
71 * has to be less than 256. The cache can be made larger as long
72 * as you are sure you don't need fopen/fdopen. */
74 /* As noted in ihandle.h, the fileno member of FILE on most platforms
75 * in 2008 is a 16- or 32-bit signed int. -Matt
77 int fdMaxCacheSize = 0;
80 /* Number of in use file descriptors */
83 /* Hash table for inode handles */
84 IHashBucket_t ihashTable[I_HANDLE_HASH_SIZE];
86 void *ih_sync_thread(void *);
88 /* start-time configurable I/O limits */
89 ih_init_params vol_io_params;
91 void ih_PkgDefaults(void)
94 ih_PkgDefaultsSet = 1;
96 /* default to well-known values */
97 vol_io_params.fd_handle_setaside = FD_HANDLE_SETASIDE;
99 /* initial fd cachesize. the only one that will be used if
100 * the application does not call ih_UseLargeCache(). set this
101 * to a value representable in fileno member of the system's
102 * FILE structure (or equivalent). */
103 vol_io_params.fd_initial_cachesize = FD_DEFAULT_CACHESIZE;
105 /* fd cache size that will be used if/when ih_UseLargeCache()
107 vol_io_params.fd_max_cachesize = FD_MAX_CACHESIZE;
110 #ifdef AFS_PTHREAD_ENV
111 /* Initialize the global ihandle mutex */
115 MUTEX_INIT(&ih_glock_mutex, "ih glock", MUTEX_DEFAULT, 0);
117 #endif /* AFS_PTHREAD_ENV */
119 /* Initialize the file descriptor cache */
124 osi_Assert(!ih_Inited);
126 DLL_INIT_LIST(ihAvailHead, ihAvailTail);
127 DLL_INIT_LIST(fdAvailHead, fdAvailTail);
128 DLL_INIT_LIST(fdLruHead, fdLruTail);
129 for (i = 0; i < I_HANDLE_HASH_SIZE; i++) {
130 DLL_INIT_LIST(ihashTable[i].ihash_head, ihashTable[i].ihash_tail);
132 #if defined(AFS_NT40_ENV)
133 fdMaxCacheSize = vol_io_params.fd_max_cachesize;
134 #elif defined(AFS_SUN5_ENV) || defined(AFS_NBSD_ENV)
137 osi_Assert(getrlimit(RLIMIT_NOFILE, &rlim) == 0);
138 rlim.rlim_cur = rlim.rlim_max;
139 osi_Assert(setrlimit(RLIMIT_NOFILE, &rlim) == 0);
140 fdMaxCacheSize = rlim.rlim_cur - vol_io_params.fd_handle_setaside;
142 /* XXX this is to avoid using up all system fd netbsd is
143 * somewhat broken and have set maximum fd for a root process
144 * to the same as system fd that is avaible, so if the
145 * fileserver uses all up process fds, all system fd will be
148 * Check for this better
152 fdMaxCacheSize = MIN(fdMaxCacheSize, vol_io_params.fd_max_cachesize);
153 osi_Assert(fdMaxCacheSize > 0);
155 #elif defined(AFS_HPUX_ENV)
156 /* Avoid problems with "UFSOpen: igetinode failed" panics on HPUX 11.0 */
160 long fdMax = MAX(sysconf(_SC_OPEN_MAX) - vol_io_params.fd_handle_setaside,
162 fdMaxCacheSize = (int)MIN(fdMax, vol_io_params.fd_max_cachesize);
165 fdCacheSize = MIN(fdMaxCacheSize, vol_io_params.fd_initial_cachesize);
168 #ifdef AFS_PTHREAD_ENV
170 pthread_attr_t tattr;
172 pthread_attr_init(&tattr);
173 pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
175 pthread_create(&syncer, &tattr, ih_sync_thread, NULL);
176 #else /* AFS_PTHREAD_ENV */
178 LWP_CreateProcess(ih_sync_thread, 16*1024, LWP_MAX_PRIORITY - 2,
179 NULL, "ih_syncer", &syncer);
180 #endif /* AFS_PTHREAD_ENV */
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 osi_Assert(ihAvailHead == NULL);
216 ihP = (IHandle_t *) malloc(I_HANDLE_MALLOCSIZE * sizeof(IHandle_t));
217 osi_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 osi_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 osi_Assert(ih_Inited);
275 osi_Assert(ihP->ih_refcnt > 0);
281 /* Allocate a chunk of file descriptor handles */
283 fdHandleAllocateChunk(void)
288 osi_Assert(fdAvailHead == NULL);
289 fdP = (FdHandle_t *) malloc(FD_HANDLE_MALLOCSIZE * sizeof(FdHandle_t));
290 osi_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 fdP[i].fd_needs_rclose = 0;
299 DLL_INSERT_TAIL(&fdP[i], fdAvailHead, fdAvailTail, fd_next, fd_prev);
303 /* Allocate a chunk of stream handles */
305 streamHandleAllocateChunk(void)
308 StreamHandle_t *streamP;
310 osi_Assert(streamAvailHead == NULL);
311 streamP = (StreamHandle_t *)
312 malloc(STREAM_HANDLE_MALLOCSIZE * sizeof(StreamHandle_t));
313 osi_Assert(streamP != NULL);
314 for (i = 0; i < STREAM_HANDLE_MALLOCSIZE; i++) {
315 streamP[i].str_fd = INVALID_FD;
316 DLL_INSERT_TAIL(&streamP[i], streamAvailHead, streamAvailTail,
322 * Get a file descriptor handle given an Inode handle
325 ih_open(IHandle_t * ihP)
331 if (!ihP) /* XXX should log here in the fileserver */
336 /* Do we already have an open file handle for this Inode? */
337 for (fdP = ihP->ih_fdtail; fdP != NULL; fdP = fdP->fd_ihprev) {
340 * If we don't have positional i/o, don't try to share fds, since
341 * we can't do so in a threadsafe way.
343 if (fdP->fd_status != FD_HANDLE_INUSE) {
344 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
346 if (fdP->fd_status != FD_HANDLE_AVAIL) {
347 #endif /* HAVE_PIO */
349 if (fdP->fd_status == FD_HANDLE_OPEN) {
350 fdP->fd_status = FD_HANDLE_INUSE;
351 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
360 * Try to open the Inode, return NULL on error.
367 if (fd == INVALID_FD && (errno != EMFILE || fdLruHead == NULL) ) {
373 /* fdCacheSize limits the size of the descriptor cache, but
374 * we permit the number of open files to exceed fdCacheSize.
375 * We only recycle open file descriptors when the number
376 * of open files reaches the size of the cache */
377 if ((fdInUseCount > fdCacheSize || fd == INVALID_FD) && fdLruHead != NULL) {
379 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
380 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
381 DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail,
382 fd_ihnext, fd_ihprev);
383 closeFd = fdP->fd_fd;
384 if (fd == INVALID_FD) {
385 fdCacheSize--; /* reduce in order to not run into here too often */
386 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
387 fdP->fd_status = FD_HANDLE_AVAIL;
389 fdP->fd_fd = INVALID_FD;
390 fdP->fd_needs_rclose = 0;
396 if (fdAvailHead == NULL) {
397 fdHandleAllocateChunk();
400 osi_Assert(fdP->fd_status == FD_HANDLE_AVAIL);
401 DLL_DELETE(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
402 closeFd = INVALID_FD;
405 fdP->fd_status = FD_HANDLE_INUSE;
408 fdP->fd_needs_rclose = 0;
413 /* Add this handle to the Inode's list of open descriptors */
414 DLL_INSERT_TAIL(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
417 if (closeFd != INVALID_FD) {
429 * Return a file descriptor handle to the cache
432 fd_close(FdHandle_t * fdP)
440 osi_Assert(ih_Inited);
441 osi_Assert(fdInUseCount > 0);
442 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
446 /* Call fd_reallyclose to really close the unused file handles if
447 * the previous attempt to close (ih_reallyclose()) all file handles
448 * failed (this is determined by checking the ihandle for the flag
449 * IH_REALLY_CLOSED) or we have too many open files.
451 if (ihP->ih_flags & IH_REALLY_CLOSED || fdInUseCount > fdCacheSize ||
452 fdP->fd_needs_rclose) {
455 return fd_reallyclose(fdP);
459 if (fdP->fd_refcnt == 0) {
460 /* Put this descriptor back into the cache */
461 fdP->fd_status = FD_HANDLE_OPEN;
462 DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
465 /* If this is not the only reference to the Inode then we can decrement
466 * the reference count, otherwise we need to call ih_release.
468 if (ihP->ih_refcnt > 1) {
480 * Actually close the file descriptor handle and return it to
484 fd_reallyclose(FdHandle_t * fdP)
493 osi_Assert(ih_Inited);
494 osi_Assert(fdInUseCount > 0);
495 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
498 closeFd = fdP->fd_fd;
501 if (fdP->fd_refcnt == 0) {
502 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev);
503 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
505 fdP->fd_status = FD_HANDLE_AVAIL;
508 fdP->fd_fd = INVALID_FD;
509 fdP->fd_needs_rclose = 0;
511 fdP->fd_needs_rclose = 1;
514 /* All the file descriptor handles have been closed; reset
515 * the IH_REALLY_CLOSED flag indicating that ih_reallyclose
516 * has completed its job.
518 if (!ihP->ih_fdhead) {
519 ihP->ih_flags &= ~IH_REALLY_CLOSED;
522 if (fdP->fd_refcnt == 0) {
529 /* If this is not the only reference to the Inode then we can decrement
530 * the reference count, otherwise we need to call ih_release. */
531 if (ihP->ih_refcnt > 1) {
542 /* Enable buffered I/O on a file descriptor */
544 stream_fdopen(FD_t fd)
546 StreamHandle_t *streamP;
549 if (streamAvailHead == NULL) {
550 streamHandleAllocateChunk();
552 streamP = streamAvailHead;
553 DLL_DELETE(streamP, streamAvailHead, streamAvailTail, str_next, str_prev);
555 streamP->str_fd = fd;
556 streamP->str_buflen = 0;
557 streamP->str_bufoff = 0;
558 streamP->str_fdoff = 0;
559 streamP->str_error = 0;
560 streamP->str_eof = 0;
561 streamP->str_direction = STREAM_DIRECTION_NONE;
565 /* Open a file for buffered I/O */
567 stream_open(const char *filename, const char *mode)
569 FD_t fd = INVALID_FD;
571 if (strcmp(mode, "r") == 0) {
572 fd = OS_OPEN(filename, O_RDONLY, 0);
573 } else if (strcmp(mode, "r+") == 0) {
574 fd = OS_OPEN(filename, O_RDWR, 0);
575 } else if (strcmp(mode, "w") == 0) {
576 fd = OS_OPEN(filename, O_WRONLY | O_TRUNC | O_CREAT, 0);
577 } else if (strcmp(mode, "w+") == 0) {
578 fd = OS_OPEN(filename, O_RDWR | O_TRUNC | O_CREAT, 0);
579 } else if (strcmp(mode, "a") == 0) {
580 fd = OS_OPEN(filename, O_WRONLY | O_APPEND | O_CREAT, 0);
581 } else if (strcmp(mode, "a+") == 0) {
582 fd = OS_OPEN(filename, O_RDWR | O_APPEND | O_CREAT, 0);
584 osi_Assert(FALSE); /* not implemented */
587 if (fd == INVALID_FD) {
590 return stream_fdopen(fd);
593 /* fread for buffered I/O handles */
595 stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
596 StreamHandle_t * streamP)
598 afs_fsize_t nbytes, bytesRead, bytesToRead;
601 /* Need to seek before changing direction */
602 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
603 streamP->str_direction = STREAM_DIRECTION_READ;
604 streamP->str_bufoff = 0;
605 streamP->str_buflen = 0;
607 osi_Assert(streamP->str_direction == STREAM_DIRECTION_READ);
611 nbytes = size * nitems;
613 while (nbytes > 0 && !streamP->str_eof) {
614 if (streamP->str_buflen == 0) {
615 streamP->str_bufoff = 0;
616 streamP->str_buflen =
617 OS_PREAD(streamP->str_fd, streamP->str_buffer,
618 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
619 if (streamP->str_buflen < 0) {
620 streamP->str_error = errno;
621 streamP->str_buflen = 0;
624 } else if (streamP->str_buflen == 0) {
625 streamP->str_eof = 1;
628 streamP->str_fdoff += streamP->str_buflen;
631 bytesToRead = nbytes;
632 if (bytesToRead > streamP->str_buflen) {
633 bytesToRead = streamP->str_buflen;
635 memcpy(p, streamP->str_buffer + streamP->str_bufoff, bytesToRead);
637 streamP->str_bufoff += bytesToRead;
638 streamP->str_buflen -= bytesToRead;
639 bytesRead += bytesToRead;
640 nbytes -= bytesToRead;
643 return (bytesRead / size);
646 /* fwrite for buffered I/O handles */
648 stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
649 StreamHandle_t * streamP)
653 afs_fsize_t nbytes, bytesWritten, bytesToWrite;
655 /* Need to seek before changing direction */
656 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
657 streamP->str_direction = STREAM_DIRECTION_WRITE;
658 streamP->str_bufoff = 0;
659 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
661 osi_Assert(streamP->str_direction == STREAM_DIRECTION_WRITE);
664 nbytes = size * nitems;
668 if (streamP->str_buflen == 0) {
669 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
670 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
672 streamP->str_error = errno;
676 streamP->str_fdoff += rc;
677 streamP->str_bufoff = 0;
678 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
681 bytesToWrite = nbytes;
682 if (bytesToWrite > streamP->str_buflen) {
683 bytesToWrite = streamP->str_buflen;
685 memcpy(streamP->str_buffer + streamP->str_bufoff, p, bytesToWrite);
687 streamP->str_bufoff += bytesToWrite;
688 streamP->str_buflen -= bytesToWrite;
689 bytesWritten += bytesToWrite;
690 nbytes -= bytesToWrite;
693 return (bytesWritten / size);
696 /* fseek for buffered I/O handles */
698 stream_aseek(StreamHandle_t * streamP, afs_foff_t offset)
703 if (streamP->str_direction == STREAM_DIRECTION_WRITE
704 && streamP->str_bufoff > 0) {
705 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
706 streamP->str_bufoff, streamP->str_fdoff);
708 streamP->str_error = errno;
712 streamP->str_fdoff = offset;
713 streamP->str_bufoff = 0;
714 streamP->str_buflen = 0;
715 streamP->str_eof = 0;
716 streamP->str_direction = STREAM_DIRECTION_NONE;
720 /* fflush for buffered I/O handles */
722 stream_flush(StreamHandle_t * streamP)
727 if (streamP->str_direction == STREAM_DIRECTION_WRITE
728 && streamP->str_bufoff > 0) {
729 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
730 streamP->str_bufoff, streamP->str_fdoff);
732 streamP->str_error = errno;
735 streamP->str_fdoff += rc;
737 streamP->str_bufoff = 0;
738 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
744 /* Free a buffered I/O handle */
746 stream_close(StreamHandle_t * streamP, int reallyClose)
751 osi_Assert(streamP != NULL);
752 if (streamP->str_direction == STREAM_DIRECTION_WRITE
753 && streamP->str_bufoff > 0) {
754 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
755 streamP->str_bufoff, streamP->str_fdoff);
759 streamP->str_fdoff += rc;
763 rc = OS_CLOSE(streamP->str_fd);
768 streamP->str_fd = INVALID_FD;
771 DLL_INSERT_TAIL(streamP, streamAvailHead, streamAvailTail,
777 /* Close all unused file descriptors associated with the inode
778 * handle. Called with IH_LOCK held. May drop and reacquire
779 * IH_LOCK. Sets the IH_REALLY_CLOSED flag in the inode handle
780 * if it fails to close all file handles.
783 ih_fdclose(IHandle_t * ihP)
785 int closeCount, closedAll;
786 FdHandle_t *fdP, *head, *tail, *next;
788 osi_Assert(ihP->ih_refcnt > 0);
791 DLL_INIT_LIST(head, tail);
792 ihP->ih_flags &= ~IH_REALLY_CLOSED;
795 * Remove the file descriptors for this Inode from the LRU queue
796 * and the IHandle queue and put them on a temporary queue so we
797 * can drop the lock before we close the files.
799 for (fdP = ihP->ih_fdhead; fdP != NULL; fdP = next) {
800 next = fdP->fd_ihnext;
801 osi_Assert(fdP->fd_ih == ihP);
802 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN
803 || fdP->fd_status == FD_HANDLE_INUSE);
804 if (fdP->fd_status == FD_HANDLE_OPEN) {
805 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
807 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
808 DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev);
811 ihP->ih_flags |= IH_REALLY_CLOSED;
815 /* If the ihandle reference count is 1, we should have
816 * closed all file descriptors.
818 if (ihP->ih_refcnt == 1 || closedAll) {
819 osi_Assert(closedAll);
820 osi_Assert(!ihP->ih_fdhead);
821 osi_Assert(!ihP->ih_fdtail);
825 return 0; /* No file descriptors closed */
830 * Close the file descriptors
833 for (fdP = head; fdP != NULL; fdP = fdP->fd_next) {
834 OS_CLOSE(fdP->fd_fd);
835 fdP->fd_status = FD_HANDLE_AVAIL;
837 fdP->fd_fd = INVALID_FD;
839 fdP->fd_needs_rclose = 0;
844 osi_Assert(fdInUseCount >= closeCount);
845 fdInUseCount -= closeCount;
848 * Append the temporary queue to the list of available descriptors
850 if (fdAvailHead == NULL) {
854 fdAvailTail->fd_next = head;
855 head->fd_prev = fdAvailTail;
862 /* Close all cached file descriptors for this inode. */
864 ih_reallyclose(IHandle_t * ihP)
870 ihP->ih_refcnt++; /* must not disappear over unlock */
871 if (ihP->ih_synced) {
885 osi_Assert(ihP->ih_refcnt > 0);
889 if (ihP->ih_refcnt > 1) {
899 /* Release an Inode handle. All cached file descriptors for this
900 * inode are closed when the last reference to this handle is released
903 ih_release(IHandle_t * ihP)
911 osi_Assert(ihP->ih_refcnt > 0);
913 if (ihP->ih_refcnt > 1) {
919 ihash = IH_HASH(ihP->ih_dev, ihP->ih_vid, ihP->ih_ino);
920 DLL_DELETE(ihP, ihashTable[ihash].ihash_head,
921 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
927 DLL_INSERT_TAIL(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
933 /* Sync an inode to disk if its handle isn't NULL */
935 ih_condsync(IHandle_t * ihP)
947 code = FDH_SYNC(fdP);
959 for (ihash = 0; ihash < I_HANDLE_HASH_SIZE; ihash++) {
960 IHandle_t *ihP, *ihPnext;
962 ihP = ihashTable[ihash].ihash_head;
964 ihP->ih_refcnt++; /* must not disappear over unlock */
965 for (; ihP; ihP = ihPnext) {
967 if (ihP->ih_synced) {
982 /* when decrementing the refcount, the ihandle might disappear
983 and we might not even be able to proceed to the next one.
984 Hence the gymnastics putting a hold on the next one already */
985 ihPnext = ihP->ih_next;
986 if (ihPnext) ihPnext->ih_refcnt++;
988 if (ihP->ih_refcnt > 1) {
1002 ih_sync_thread(void *dummy) {
1005 #ifdef AFS_PTHREAD_ENV
1007 #else /* AFS_PTHREAD_ENV */
1009 #endif /* AFS_PTHREAD_ENV */
1017 /*************************************************************************
1018 * OS specific support routines.
1019 *************************************************************************/
1020 #ifndef AFS_NAMEI_ENV
1022 ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, int p2,
1026 #ifdef AFS_3DISPARES
1027 /* See viceinode.h */
1028 if (p2 == INODESPECIAL) {
1034 ino = ICREATE(dev, part, nI, p1, p2, p3, p4);
1037 #endif /* AFS_NAMEI_ENV */
1044 if (!GetFileSizeEx(fd, &size))
1046 return size.QuadPart;
1048 struct afs_stat_st status;
1049 if (afs_fstat(fd, &status) < 0)
1051 return status.st_size;
1057 ih_pread(int fd, void * buf, size_t count, afs_foff_t offset)
1060 code = OS_SEEK(fd, offset, 0);
1063 return OS_READ(fd, buf, count);
1067 ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset)
1070 code = OS_SEEK(fd, offset, 0);
1073 return OS_WRITE(fd, buf, count);
1075 #endif /* !HAVE_PIO */