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 #if defined(AFS_SUN5_ENV) || defined(AFS_NBSD_ENV)
22 #include <sys/fcntl.h>
23 #include <sys/resource.h>
27 #include <afs/afsint.h>
28 #include <afs/afssyscalls.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 void *ih_sync_thread(void *);
78 /* start-time configurable I/O limits */
79 ih_init_params vol_io_params;
81 void ih_PkgDefaults(void)
84 ih_PkgDefaultsSet = 1;
86 /* default to well-known values */
87 vol_io_params.fd_handle_setaside = FD_HANDLE_SETASIDE;
89 /* initial fd cachesize. the only one that will be used if
90 * the application does not call ih_UseLargeCache(). set this
91 * to a value representable in fileno member of the system's
92 * FILE structure (or equivalent). */
93 vol_io_params.fd_initial_cachesize = FD_DEFAULT_CACHESIZE;
95 /* fd cache size that will be used if/when ih_UseLargeCache()
97 vol_io_params.fd_max_cachesize = FD_MAX_CACHESIZE;
100 #ifdef AFS_PTHREAD_ENV
101 /* Initialize the global ihandle mutex */
105 MUTEX_INIT(&ih_glock_mutex, "ih glock", MUTEX_DEFAULT, 0);
107 #endif /* AFS_PTHREAD_ENV */
109 /* Initialize the file descriptor cache */
114 osi_Assert(!ih_Inited);
116 DLL_INIT_LIST(ihAvailHead, ihAvailTail);
117 DLL_INIT_LIST(fdAvailHead, fdAvailTail);
118 DLL_INIT_LIST(fdLruHead, fdLruTail);
119 for (i = 0; i < I_HANDLE_HASH_SIZE; i++) {
120 DLL_INIT_LIST(ihashTable[i].ihash_head, ihashTable[i].ihash_tail);
122 #if defined(AFS_NT40_ENV)
123 fdMaxCacheSize = vol_io_params.fd_max_cachesize;
124 #elif defined(AFS_SUN5_ENV) || defined(AFS_NBSD_ENV)
127 osi_Assert(getrlimit(RLIMIT_NOFILE, &rlim) == 0);
128 rlim.rlim_cur = rlim.rlim_max;
129 osi_Assert(setrlimit(RLIMIT_NOFILE, &rlim) == 0);
130 fdMaxCacheSize = rlim.rlim_cur - vol_io_params.fd_handle_setaside;
132 /* XXX this is to avoid using up all system fd netbsd is
133 * somewhat broken and have set maximum fd for a root process
134 * to the same as system fd that is avaible, so if the
135 * fileserver uses all up process fds, all system fd will be
138 * Check for this better
142 fdMaxCacheSize = MIN(fdMaxCacheSize, vol_io_params.fd_max_cachesize);
143 osi_Assert(fdMaxCacheSize > 0);
145 #elif defined(AFS_HPUX_ENV)
146 /* Avoid problems with "UFSOpen: igetinode failed" panics on HPUX 11.0 */
150 long fdMax = MAX(sysconf(_SC_OPEN_MAX) - vol_io_params.fd_handle_setaside,
152 fdMaxCacheSize = (int)MIN(fdMax, vol_io_params.fd_max_cachesize);
155 fdCacheSize = MIN(fdMaxCacheSize, vol_io_params.fd_initial_cachesize);
158 #ifdef AFS_PTHREAD_ENV
160 pthread_attr_t tattr;
162 pthread_attr_init(&tattr);
163 pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
165 pthread_create(&syncer, &tattr, ih_sync_thread, NULL);
166 #else /* AFS_PTHREAD_ENV */
168 LWP_CreateProcess(ih_sync_thread, 16*1024, LWP_MAX_PRIORITY - 2,
169 NULL, "ih_syncer", &syncer);
170 #endif /* AFS_PTHREAD_ENV */
175 /* Make the file descriptor cache as big as possible. Don't this call
176 * if the program uses fopen or fdopen, if fd_max_cachesize cannot be
177 * represented in the fileno member of the system FILE structure (or
181 ih_UseLargeCache(void)
185 if (!ih_PkgDefaultsSet) {
193 fdCacheSize = fdMaxCacheSize;
198 /* Allocate a chunk of inode handles */
200 iHandleAllocateChunk(void)
205 osi_Assert(ihAvailHead == NULL);
206 ihP = (IHandle_t *) malloc(I_HANDLE_MALLOCSIZE * sizeof(IHandle_t));
207 osi_Assert(ihP != NULL);
208 for (i = 0; i < I_HANDLE_MALLOCSIZE; i++) {
209 ihP[i].ih_refcnt = 0;
210 DLL_INSERT_TAIL(&ihP[i], ihAvailHead, ihAvailTail, ih_next, ih_prev);
214 /* Initialize an inode handle */
216 ih_init(int dev, int vid, Inode ino)
218 int ihash = IH_HASH(dev, vid, ino);
221 if (!ih_PkgDefaultsSet) {
230 /* Do we already have a handle for this Inode? */
231 for (ihP = ihashTable[ihash].ihash_head; ihP; ihP = ihP->ih_next) {
232 if (ihP->ih_ino == ino && ihP->ih_vid == vid && ihP->ih_dev == dev) {
239 /* Allocate and initialize a new Inode handle */
240 if (ihAvailHead == NULL) {
241 iHandleAllocateChunk();
244 osi_Assert(ihP->ih_refcnt == 0);
245 DLL_DELETE(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
252 DLL_INIT_LIST(ihP->ih_fdhead, ihP->ih_fdtail);
253 DLL_INSERT_TAIL(ihP, ihashTable[ihash].ihash_head,
254 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
259 /* Copy an inode handle */
261 ih_copy(IHandle_t * ihP)
264 osi_Assert(ih_Inited);
265 osi_Assert(ihP->ih_refcnt > 0);
271 /* Allocate a chunk of file descriptor handles */
273 fdHandleAllocateChunk(void)
278 osi_Assert(fdAvailHead == NULL);
279 fdP = (FdHandle_t *) malloc(FD_HANDLE_MALLOCSIZE * sizeof(FdHandle_t));
280 osi_Assert(fdP != NULL);
281 for (i = 0; i < FD_HANDLE_MALLOCSIZE; i++) {
282 fdP[i].fd_status = FD_HANDLE_AVAIL;
283 fdP[i].fd_refcnt = 0;
285 fdP[i].fd_fd = INVALID_FD;
286 fdP[i].fd_ihnext = NULL;
287 fdP[i].fd_ihprev = NULL;
288 DLL_INSERT_TAIL(&fdP[i], fdAvailHead, fdAvailTail, fd_next, fd_prev);
292 /* Allocate a chunk of stream handles */
294 streamHandleAllocateChunk(void)
297 StreamHandle_t *streamP;
299 osi_Assert(streamAvailHead == NULL);
300 streamP = (StreamHandle_t *)
301 malloc(STREAM_HANDLE_MALLOCSIZE * sizeof(StreamHandle_t));
302 osi_Assert(streamP != NULL);
303 for (i = 0; i < STREAM_HANDLE_MALLOCSIZE; i++) {
304 streamP[i].str_fd = INVALID_FD;
305 DLL_INSERT_TAIL(&streamP[i], streamAvailHead, streamAvailTail,
311 * Get a file descriptor handle given an Inode handle
314 ih_open(IHandle_t * ihP)
320 if (!ihP) /* XXX should log here in the fileserver */
325 /* Do we already have an open file handle for this Inode? */
326 for (fdP = ihP->ih_fdtail; fdP != NULL; fdP = fdP->fd_ihprev) {
329 * If we don't have positional i/o, don't try to share fds, since
330 * we can't do so in a threadsafe way.
332 if (fdP->fd_status != FD_HANDLE_INUSE) {
333 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
335 if (fdP->fd_status != FD_HANDLE_AVAIL) {
336 #endif /* HAVE_PIO */
338 if (fdP->fd_status == FD_HANDLE_OPEN) {
339 fdP->fd_status = FD_HANDLE_INUSE;
340 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
349 * Try to open the Inode, return NULL on error.
356 if (fd == INVALID_FD && (errno != EMFILE || fdLruHead == NULL) ) {
362 /* fdCacheSize limits the size of the descriptor cache, but
363 * we permit the number of open files to exceed fdCacheSize.
364 * We only recycle open file descriptors when the number
365 * of open files reaches the size of the cache */
366 if ((fdInUseCount > fdCacheSize || fd == INVALID_FD) && fdLruHead != NULL) {
368 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN);
369 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
370 DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail,
371 fd_ihnext, fd_ihprev);
372 closeFd = fdP->fd_fd;
373 if (fd == INVALID_FD) {
374 fdCacheSize--; /* reduce in order to not run into here too often */
375 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
376 fdP->fd_status = FD_HANDLE_AVAIL;
378 fdP->fd_fd = INVALID_FD;
384 if (fdAvailHead == NULL) {
385 fdHandleAllocateChunk();
388 osi_Assert(fdP->fd_status == FD_HANDLE_AVAIL);
389 DLL_DELETE(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
390 closeFd = INVALID_FD;
393 fdP->fd_status = FD_HANDLE_INUSE;
400 /* Add this handle to the Inode's list of open descriptors */
401 DLL_INSERT_TAIL(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
404 if (closeFd != INVALID_FD) {
416 * Return a file descriptor handle to the cache
419 fd_close(FdHandle_t * fdP)
427 osi_Assert(ih_Inited);
428 osi_Assert(fdInUseCount > 0);
429 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
433 /* Call fd_reallyclose to really close the unused file handles if
434 * the previous attempt to close (ih_reallyclose()) all file handles
435 * failed (this is determined by checking the ihandle for the flag
436 * IH_REALLY_CLOSED) or we have too many open files.
438 if (ihP->ih_flags & IH_REALLY_CLOSED || fdInUseCount > fdCacheSize) {
440 return fd_reallyclose(fdP);
444 if (fdP->fd_refcnt == 0) {
445 /* Put this descriptor back into the cache */
446 fdP->fd_status = FD_HANDLE_OPEN;
447 DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
450 /* If this is not the only reference to the Inode then we can decrement
451 * the reference count, otherwise we need to call ih_release.
453 if (ihP->ih_refcnt > 1) {
465 * Actually close the file descriptor handle and return it to
469 fd_reallyclose(FdHandle_t * fdP)
478 osi_Assert(ih_Inited);
479 osi_Assert(fdInUseCount > 0);
480 osi_Assert(fdP->fd_status == FD_HANDLE_INUSE);
483 closeFd = fdP->fd_fd;
486 if (fdP->fd_refcnt == 0) {
487 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev);
488 DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
490 fdP->fd_status = FD_HANDLE_AVAIL;
493 fdP->fd_fd = INVALID_FD;
496 /* All the file descriptor handles have been closed; reset
497 * the IH_REALLY_CLOSED flag indicating that ih_reallyclose
498 * has completed its job.
500 if (!ihP->ih_fdhead) {
501 ihP->ih_flags &= ~IH_REALLY_CLOSED;
504 if (fdP->fd_refcnt == 0) {
511 /* If this is not the only reference to the Inode then we can decrement
512 * the reference count, otherwise we need to call ih_release. */
513 if (ihP->ih_refcnt > 1) {
524 /* Enable buffered I/O on a file descriptor */
526 stream_fdopen(FD_t fd)
528 StreamHandle_t *streamP;
531 if (streamAvailHead == NULL) {
532 streamHandleAllocateChunk();
534 streamP = streamAvailHead;
535 DLL_DELETE(streamP, streamAvailHead, streamAvailTail, str_next, str_prev);
537 streamP->str_fd = fd;
538 streamP->str_buflen = 0;
539 streamP->str_bufoff = 0;
540 streamP->str_fdoff = 0;
541 streamP->str_error = 0;
542 streamP->str_eof = 0;
543 streamP->str_direction = STREAM_DIRECTION_NONE;
547 /* Open a file for buffered I/O */
549 stream_open(const char *filename, const char *mode)
551 FD_t fd = INVALID_FD;
553 if (strcmp(mode, "r") == 0) {
554 fd = OS_OPEN(filename, O_RDONLY, 0);
555 } else if (strcmp(mode, "r+") == 0) {
556 fd = OS_OPEN(filename, O_RDWR, 0);
557 } else if (strcmp(mode, "w") == 0) {
558 fd = OS_OPEN(filename, O_WRONLY | O_TRUNC | O_CREAT, 0);
559 } else if (strcmp(mode, "w+") == 0) {
560 fd = OS_OPEN(filename, O_RDWR | O_TRUNC | O_CREAT, 0);
561 } else if (strcmp(mode, "a") == 0) {
562 fd = OS_OPEN(filename, O_WRONLY | O_APPEND | O_CREAT, 0);
563 } else if (strcmp(mode, "a+") == 0) {
564 fd = OS_OPEN(filename, O_RDWR | O_APPEND | O_CREAT, 0);
566 osi_Assert(FALSE); /* not implemented */
569 if (fd == INVALID_FD) {
572 return stream_fdopen(fd);
575 /* fread for buffered I/O handles */
577 stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
578 StreamHandle_t * streamP)
580 afs_fsize_t nbytes, bytesRead, bytesToRead;
583 /* Need to seek before changing direction */
584 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
585 streamP->str_direction = STREAM_DIRECTION_READ;
586 streamP->str_bufoff = 0;
587 streamP->str_buflen = 0;
589 osi_Assert(streamP->str_direction == STREAM_DIRECTION_READ);
593 nbytes = size * nitems;
595 while (nbytes > 0 && !streamP->str_eof) {
596 if (streamP->str_buflen == 0) {
597 streamP->str_bufoff = 0;
598 streamP->str_buflen =
599 OS_PREAD(streamP->str_fd, streamP->str_buffer,
600 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
601 if (streamP->str_buflen < 0) {
602 streamP->str_error = errno;
603 streamP->str_buflen = 0;
606 } else if (streamP->str_buflen == 0) {
607 streamP->str_eof = 1;
610 streamP->str_fdoff += streamP->str_buflen;
613 bytesToRead = nbytes;
614 if (bytesToRead > streamP->str_buflen) {
615 bytesToRead = streamP->str_buflen;
617 memcpy(p, streamP->str_buffer + streamP->str_bufoff, bytesToRead);
619 streamP->str_bufoff += bytesToRead;
620 streamP->str_buflen -= bytesToRead;
621 bytesRead += bytesToRead;
622 nbytes -= bytesToRead;
625 return (bytesRead / size);
628 /* fwrite for buffered I/O handles */
630 stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems,
631 StreamHandle_t * streamP)
635 afs_fsize_t nbytes, bytesWritten, bytesToWrite;
637 /* Need to seek before changing direction */
638 if (streamP->str_direction == STREAM_DIRECTION_NONE) {
639 streamP->str_direction = STREAM_DIRECTION_WRITE;
640 streamP->str_bufoff = 0;
641 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
643 osi_Assert(streamP->str_direction == STREAM_DIRECTION_WRITE);
646 nbytes = size * nitems;
650 if (streamP->str_buflen == 0) {
651 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
652 STREAM_HANDLE_BUFSIZE, streamP->str_fdoff);
654 streamP->str_error = errno;
658 streamP->str_fdoff += rc;
659 streamP->str_bufoff = 0;
660 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
663 bytesToWrite = nbytes;
664 if (bytesToWrite > streamP->str_buflen) {
665 bytesToWrite = streamP->str_buflen;
667 memcpy(streamP->str_buffer + streamP->str_bufoff, p, bytesToWrite);
669 streamP->str_bufoff += bytesToWrite;
670 streamP->str_buflen -= bytesToWrite;
671 bytesWritten += bytesToWrite;
672 nbytes -= bytesToWrite;
675 return (bytesWritten / size);
678 /* fseek for buffered I/O handles */
680 stream_aseek(StreamHandle_t * streamP, afs_foff_t offset)
685 if (streamP->str_direction == STREAM_DIRECTION_WRITE
686 && streamP->str_bufoff > 0) {
687 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
688 streamP->str_bufoff, streamP->str_fdoff);
690 streamP->str_error = errno;
694 streamP->str_fdoff = offset;
695 streamP->str_bufoff = 0;
696 streamP->str_buflen = 0;
697 streamP->str_eof = 0;
698 streamP->str_direction = STREAM_DIRECTION_NONE;
702 /* fflush for buffered I/O handles */
704 stream_flush(StreamHandle_t * streamP)
709 if (streamP->str_direction == STREAM_DIRECTION_WRITE
710 && streamP->str_bufoff > 0) {
711 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
712 streamP->str_bufoff, streamP->str_fdoff);
714 streamP->str_error = errno;
717 streamP->str_fdoff += rc;
719 streamP->str_bufoff = 0;
720 streamP->str_buflen = STREAM_HANDLE_BUFSIZE;
726 /* Free a buffered I/O handle */
728 stream_close(StreamHandle_t * streamP, int reallyClose)
733 osi_Assert(streamP != NULL);
734 if (streamP->str_direction == STREAM_DIRECTION_WRITE
735 && streamP->str_bufoff > 0) {
736 rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer,
737 streamP->str_bufoff, streamP->str_fdoff);
741 streamP->str_fdoff += rc;
745 rc = OS_CLOSE(streamP->str_fd);
750 streamP->str_fd = INVALID_FD;
753 DLL_INSERT_TAIL(streamP, streamAvailHead, streamAvailTail,
759 /* Close all unused file descriptors associated with the inode
760 * handle. Called with IH_LOCK held. May drop and reacquire
761 * IH_LOCK. Sets the IH_REALLY_CLOSED flag in the inode handle
762 * if it fails to close all file handles.
765 ih_fdclose(IHandle_t * ihP)
767 int closeCount, closedAll;
768 FdHandle_t *fdP, *head, *tail, *next;
770 osi_Assert(ihP->ih_refcnt > 0);
773 DLL_INIT_LIST(head, tail);
774 ihP->ih_flags &= ~IH_REALLY_CLOSED;
777 * Remove the file descriptors for this Inode from the LRU queue
778 * and the IHandle queue and put them on a temporary queue so we
779 * can drop the lock before we close the files.
781 for (fdP = ihP->ih_fdhead; fdP != NULL; fdP = next) {
782 next = fdP->fd_ihnext;
783 osi_Assert(fdP->fd_ih == ihP);
784 osi_Assert(fdP->fd_status == FD_HANDLE_OPEN
785 || fdP->fd_status == FD_HANDLE_INUSE);
786 if (fdP->fd_status == FD_HANDLE_OPEN) {
787 DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext,
789 DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
790 DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev);
793 ihP->ih_flags |= IH_REALLY_CLOSED;
797 /* If the ihandle reference count is 1, we should have
798 * closed all file descriptors.
800 if (ihP->ih_refcnt == 1 || closedAll) {
801 osi_Assert(closedAll);
802 osi_Assert(!ihP->ih_fdhead);
803 osi_Assert(!ihP->ih_fdtail);
807 return 0; /* No file descriptors closed */
812 * Close the file descriptors
815 for (fdP = head; fdP != NULL; fdP = fdP->fd_next) {
816 OS_CLOSE(fdP->fd_fd);
817 fdP->fd_status = FD_HANDLE_AVAIL;
819 fdP->fd_fd = INVALID_FD;
825 osi_Assert(fdInUseCount >= closeCount);
826 fdInUseCount -= closeCount;
829 * Append the temporary queue to the list of available descriptors
831 if (fdAvailHead == NULL) {
835 fdAvailTail->fd_next = head;
836 head->fd_prev = fdAvailTail;
843 /* Close all cached file descriptors for this inode. */
845 ih_reallyclose(IHandle_t * ihP)
851 ihP->ih_refcnt++; /* must not disappear over unlock */
852 if (ihP->ih_synced) {
866 osi_Assert(ihP->ih_refcnt > 0);
870 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(IHandle_t * ihP)
892 osi_Assert(ihP->ih_refcnt > 0);
894 if (ihP->ih_refcnt > 1) {
900 ihash = IH_HASH(ihP->ih_dev, ihP->ih_vid, ihP->ih_ino);
901 DLL_DELETE(ihP, ihashTable[ihash].ihash_head,
902 ihashTable[ihash].ihash_tail, ih_next, ih_prev);
908 DLL_INSERT_TAIL(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev);
914 /* Sync an inode to disk if its handle isn't NULL */
916 ih_condsync(IHandle_t * ihP)
928 code = FDH_SYNC(fdP);
940 for (ihash = 0; ihash < I_HANDLE_HASH_SIZE; ihash++) {
941 IHandle_t *ihP, *ihPnext;
943 ihP = ihashTable[ihash].ihash_head;
945 ihP->ih_refcnt++; /* must not disappear over unlock */
946 for (; ihP; ihP = ihPnext) {
948 if (ihP->ih_synced) {
963 /* when decrementing the refcount, the ihandle might disappear
964 and we might not even be able to proceed to the next one.
965 Hence the gymnastics putting a hold on the next one already */
966 ihPnext = ihP->ih_next;
967 if (ihPnext) ihPnext->ih_refcnt++;
969 if (ihP->ih_refcnt > 1) {
983 ih_sync_thread(void *dummy) {
986 #ifdef AFS_PTHREAD_ENV
988 #else /* AFS_PTHREAD_ENV */
990 #endif /* AFS_PTHREAD_ENV */
998 /*************************************************************************
999 * OS specific support routines.
1000 *************************************************************************/
1001 #ifndef AFS_NAMEI_ENV
1003 ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, int p2,
1007 #ifdef AFS_3DISPARES
1008 /* See viceinode.h */
1009 if (p2 == INODESPECIAL) {
1015 ino = ICREATE(dev, part, nI, p1, p2, p3, p4);
1018 #endif /* AFS_NAMEI_ENV */
1025 if (!GetFileSizeEx(fd, &size))
1027 return size.QuadPart;
1029 struct afs_stat_st status;
1030 if (afs_fstat(fd, &status) < 0)
1032 return status.st_size;
1038 ih_pread(int fd, void * buf, size_t count, afs_foff_t offset)
1041 code = OS_SEEK(fd, offset, 0);
1044 return OS_READ(fd, buf, count);
1048 ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset)
1051 code = OS_SEEK(fd, offset, 0);
1054 return OS_WRITE(fd, buf, count);
1056 #endif /* !HAVE_PIO */