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 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 osi_Assert(streamAvailHead == NULL);
310 streamP = (StreamHandle_t *)
311 malloc(STREAM_HANDLE_MALLOCSIZE * sizeof(StreamHandle_t));
312 osi_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) {
339 * If we don't have positional i/o, don't try to share fds, since
340 * we can't do so in a threadsafe way.
342 if (fdP->fd_status != FD_HANDLE_INUSE) {
343 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
345 if (fdP->fd_status != FD_HANDLE_AVAIL) {
346 #endif /* HAVE_PIO */
348 if (fdP->fd_status == FD_HANDLE_OPEN) {
349 fdP->fd_status = FD_HANDLE_INUSE;
350 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
359 * Try to open the Inode, return NULL on error.
366 if (fd == INVALID_FD && (errno != EMFILE || fdLruHead == NULL) ) {
372 /* fdCacheSize limits the size of the descriptor cache, but
373 * we permit the number of open files to exceed fdCacheSize.
374 * We only recycle open file descriptors when the number
375 * of open files reaches the size of the cache */
376 if ((fdInUseCount > fdCacheSize || fd == INVALID_FD) && fdLruHead != NULL) {
378 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
379 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
380 DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail,
381 fd_ihnext, fd_ihprev);
382 closeFd = fdP->fd_fd;
383 if (fd == INVALID_FD) {
384 fdCacheSize--; /* reduce in order to not run into here too often */
385 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
386 fdP->fd_status = FD_HANDLE_AVAIL;
388 fdP->fd_fd = INVALID_FD;
394 if (fdAvailHead == NULL) {
395 fdHandleAllocateChunk();
398 osi_Assert(fdP->fd_status == FD_HANDLE_AVAIL);
399 DLL_DELETE(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
400 closeFd = INVALID_FD;
403 fdP->fd_status = FD_HANDLE_INUSE;
410 /* Add this handle to the Inode's list of open descriptors */
411 DLL_INSERT_TAIL(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
414 if (closeFd != INVALID_FD) {
426 * Return a file descriptor handle to the cache
429 fd_close(FdHandle_t * fdP)
437 osi_Assert(ih_Inited);
438 osi_Assert(fdInUseCount > 0);
439 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
443 /* Call fd_reallyclose to really close the unused file handles if
444 * the previous attempt to close (ih_reallyclose()) all file handles
445 * failed (this is determined by checking the ihandle for the flag
446 * IH_REALLY_CLOSED) or we have too many open files.
448 if (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) {
475 * Actually close the file descriptor handle and return it to
479 fd_reallyclose(FdHandle_t * fdP)
488 osi_Assert(ih_Inited);
489 osi_Assert(fdInUseCount > 0);
490 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
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) {
534 /* Enable buffered I/O on a file descriptor */
536 stream_fdopen(FD_t fd)
538 StreamHandle_t *streamP;
541 if (streamAvailHead == NULL) {
542 streamHandleAllocateChunk();
544 streamP = streamAvailHead;
545 DLL_DELETE(streamP, streamAvailHead, streamAvailTail, str_next, str_prev);
547 streamP->str_fd = fd;
548 streamP->str_buflen = 0;
549 streamP->str_bufoff = 0;
550 streamP->str_fdoff = 0;
551 streamP->str_error = 0;
552 streamP->str_eof = 0;
553 streamP->str_direction = STREAM_DIRECTION_NONE;
557 /* Open a file for buffered I/O */
559 stream_open(const char *filename, const char *mode)
561 FD_t fd = INVALID_FD;
563 if (strcmp(mode, "r") == 0) {
564 fd = OS_OPEN(filename, O_RDONLY, 0);
565 } else if (strcmp(mode, "r+") == 0) {
566 fd = OS_OPEN(filename, O_RDWR, 0);
567 } else if (strcmp(mode, "w") == 0) {
568 fd = OS_OPEN(filename, O_WRONLY | O_TRUNC | O_CREAT, 0);
569 } else if (strcmp(mode, "w+") == 0) {
570 fd = OS_OPEN(filename, O_RDWR | O_TRUNC | O_CREAT, 0);
571 } else if (strcmp(mode, "a") == 0) {
572 fd = OS_OPEN(filename, O_WRONLY | O_APPEND | O_CREAT, 0);
573 } else if (strcmp(mode, "a+") == 0) {
574 fd = OS_OPEN(filename, O_RDWR | O_APPEND | O_CREAT, 0);
576 osi_Assert(FALSE); /* not implemented */
579 if (fd == INVALID_FD) {
582 return stream_fdopen(fd);
585 /* fread for buffered I/O handles */
587 stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
588 StreamHandle_t * streamP)
590 afs_fsize_t nbytes, bytesRead, bytesToRead;
593 /* Need to seek before changing direction */
594 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
595 streamP->str_direction = STREAM_DIRECTION_READ;
596 streamP->str_bufoff = 0;
597 streamP->str_buflen = 0;
599 osi_Assert(streamP->str_direction == STREAM_DIRECTION_READ);
603 nbytes = size * nitems;
605 while (nbytes > 0 && !streamP->str_eof) {
606 if (streamP->str_buflen == 0) {
607 streamP->str_bufoff = 0;
608 streamP->str_buflen =
609 OS_PREAD(streamP->str_fd, streamP->str_buffer,
610 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
611 if (streamP->str_buflen < 0) {
612 streamP->str_error = errno;
613 streamP->str_buflen = 0;
616 } else if (streamP->str_buflen == 0) {
617 streamP->str_eof = 1;
620 streamP->str_fdoff += streamP->str_buflen;
623 bytesToRead = nbytes;
624 if (bytesToRead > streamP->str_buflen) {
625 bytesToRead = streamP->str_buflen;
627 memcpy(p, streamP->str_buffer + streamP->str_bufoff, bytesToRead);
629 streamP->str_bufoff += bytesToRead;
630 streamP->str_buflen -= bytesToRead;
631 bytesRead += bytesToRead;
632 nbytes -= bytesToRead;
635 return (bytesRead / size);
638 /* fwrite for buffered I/O handles */
640 stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
641 StreamHandle_t * streamP)
645 afs_fsize_t nbytes, bytesWritten, bytesToWrite;
647 /* Need to seek before changing direction */
648 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
649 streamP->str_direction = STREAM_DIRECTION_WRITE;
650 streamP->str_bufoff = 0;
651 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
653 osi_Assert(streamP->str_direction == STREAM_DIRECTION_WRITE);
656 nbytes = size * nitems;
660 if (streamP->str_buflen == 0) {
661 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
662 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
664 streamP->str_error = errno;
668 streamP->str_fdoff += rc;
669 streamP->str_bufoff = 0;
670 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
673 bytesToWrite = nbytes;
674 if (bytesToWrite > streamP->str_buflen) {
675 bytesToWrite = streamP->str_buflen;
677 memcpy(streamP->str_buffer + streamP->str_bufoff, p, bytesToWrite);
679 streamP->str_bufoff += bytesToWrite;
680 streamP->str_buflen -= bytesToWrite;
681 bytesWritten += bytesToWrite;
682 nbytes -= bytesToWrite;
685 return (bytesWritten / size);
688 /* fseek for buffered I/O handles */
690 stream_aseek(StreamHandle_t * streamP, afs_foff_t offset)
695 if (streamP->str_direction == STREAM_DIRECTION_WRITE
696 && streamP->str_bufoff > 0) {
697 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
698 streamP->str_bufoff, streamP->str_fdoff);
700 streamP->str_error = errno;
704 streamP->str_fdoff = offset;
705 streamP->str_bufoff = 0;
706 streamP->str_buflen = 0;
707 streamP->str_eof = 0;
708 streamP->str_direction = STREAM_DIRECTION_NONE;
712 /* fflush for buffered I/O handles */
714 stream_flush(StreamHandle_t * streamP)
719 if (streamP->str_direction == STREAM_DIRECTION_WRITE
720 && streamP->str_bufoff > 0) {
721 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
722 streamP->str_bufoff, streamP->str_fdoff);
724 streamP->str_error = errno;
727 streamP->str_fdoff += rc;
729 streamP->str_bufoff = 0;
730 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
736 /* Free a buffered I/O handle */
738 stream_close(StreamHandle_t * streamP, int reallyClose)
743 osi_Assert(streamP != NULL);
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);
751 streamP->str_fdoff += rc;
755 rc = OS_CLOSE(streamP->str_fd);
760 streamP->str_fd = INVALID_FD;
763 DLL_INSERT_TAIL(streamP, streamAvailHead, streamAvailTail,
769 /* Close all unused file descriptors associated with the inode
770 * handle. Called with IH_LOCK held. May drop and reacquire
771 * IH_LOCK. Sets the IH_REALLY_CLOSED flag in the inode handle
772 * if it fails to close all file handles.
775 ih_fdclose(IHandle_t * ihP)
777 int closeCount, closedAll;
778 FdHandle_t *fdP, *head, *tail, *next;
780 osi_Assert(ihP->ih_refcnt > 0);
783 DLL_INIT_LIST(head, tail);
784 ihP->ih_flags &= ~IH_REALLY_CLOSED;
787 * Remove the file descriptors for this Inode from the LRU queue
788 * and the IHandle queue and put them on a temporary queue so we
789 * can drop the lock before we close the files.
791 for (fdP = ihP->ih_fdhead; fdP != NULL; fdP = next) {
792 next = fdP->fd_ihnext;
793 osi_Assert(fdP->fd_ih == ihP);
794 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN
795 || fdP->fd_status == FD_HANDLE_INUSE);
796 if (fdP->fd_status == FD_HANDLE_OPEN) {
797 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
799 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
800 DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev);
803 ihP->ih_flags |= IH_REALLY_CLOSED;
807 /* If the ihandle reference count is 1, we should have
808 * closed all file descriptors.
810 if (ihP->ih_refcnt == 1 || closedAll) {
811 osi_Assert(closedAll);
812 osi_Assert(!ihP->ih_fdhead);
813 osi_Assert(!ihP->ih_fdtail);
817 return 0; /* No file descriptors closed */
822 * Close the file descriptors
825 for (fdP = head; fdP != NULL; fdP = fdP->fd_next) {
826 OS_CLOSE(fdP->fd_fd);
827 fdP->fd_status = FD_HANDLE_AVAIL;
829 fdP->fd_fd = INVALID_FD;
835 osi_Assert(fdInUseCount >= closeCount);
836 fdInUseCount -= closeCount;
839 * Append the temporary queue to the list of available descriptors
841 if (fdAvailHead == NULL) {
845 fdAvailTail->fd_next = head;
846 head->fd_prev = fdAvailTail;
853 /* Close all cached file descriptors for this inode. */
855 ih_reallyclose(IHandle_t * ihP)
861 ihP->ih_refcnt++; /* must not disappear over unlock */
862 if (ihP->ih_synced) {
876 osi_Assert(ihP->ih_refcnt > 0);
880 if (ihP->ih_refcnt > 1) {
890 /* Release an Inode handle. All cached file descriptors for this
891 * inode are closed when the last reference to this handle is released
894 ih_release(IHandle_t * ihP)
902 osi_Assert(ihP->ih_refcnt > 0);
904 if (ihP->ih_refcnt > 1) {
910 ihash = IH_HASH(ihP->ih_dev, ihP->ih_vid, ihP->ih_ino);
911 DLL_DELETE(ihP, ihashTable[ihash].ihash_head,
912 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
918 DLL_INSERT_TAIL(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
924 /* Sync an inode to disk if its handle isn't NULL */
926 ih_condsync(IHandle_t * ihP)
938 code = FDH_SYNC(fdP);
950 for (ihash = 0; ihash < I_HANDLE_HASH_SIZE; ihash++) {
951 IHandle_t *ihP, *ihPnext;
953 ihP = ihashTable[ihash].ihash_head;
955 ihP->ih_refcnt++; /* must not disappear over unlock */
956 for (; ihP; ihP = ihPnext) {
958 if (ihP->ih_synced) {
973 /* when decrementing the refcount, the ihandle might disappear
974 and we might not even be able to proceed to the next one.
975 Hence the gymnastics putting a hold on the next one already */
976 ihPnext = ihP->ih_next;
977 if (ihPnext) ihPnext->ih_refcnt++;
979 if (ihP->ih_refcnt > 1) {
993 ih_sync_thread(void *dummy) {
996 #ifdef AFS_PTHREAD_ENV
998 #else /* AFS_PTHREAD_ENV */
1000 #endif /* AFS_PTHREAD_ENV */
1008 /*************************************************************************
1009 * OS specific support routines.
1010 *************************************************************************/
1011 #ifndef AFS_NAMEI_ENV
1013 ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, int p2,
1017 #ifdef AFS_3DISPARES
1018 /* See viceinode.h */
1019 if (p2 == INODESPECIAL) {
1025 ino = ICREATE(dev, part, nI, p1, p2, p3, p4);
1028 #endif /* AFS_NAMEI_ENV */
1035 if (!GetFileSizeEx(fd, &size))
1037 return size.QuadPart;
1039 struct afs_stat_st status;
1040 if (afs_fstat(fd, &status) < 0)
1042 return status.st_size;
1048 ih_pread(int fd, void * buf, size_t count, afs_foff_t offset)
1051 code = OS_SEEK(fd, offset, 0);
1054 return OS_READ(fd, buf, count);
1058 ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset)
1061 code = OS_SEEK(fd, offset, 0);
1064 return OS_WRITE(fd, buf, count);
1066 #endif /* !HAVE_PIO */