~ubuntu-branches/ubuntu/oneiric/openafs/oneiric-201305130334

« back to all changes in this revision

Viewing changes to src/vol/ihandle.c

  • Committer: Bazaar Package Importer
  • Author(s): Russ Allbery
  • Date: 2008-09-22 19:07:02 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080922190702-59m13d7kn6gkw32d
Tags: 1.4.7.dfsg1-6
* Apply upstream patch to free /proc entries in the correct order.
  Thanks, Marc Dionne.  (Closes: #493914)
* Apply upstream deltas to support 2.6.27 kernels and to stop using
  COMMON_KERN_CFLAGS for all 2.6 kernels uniformly, which fixes
  problems on amd64 with newer kernels.  Thanks, Björn Torkelsson.
  (LP: #267504)
* Translation updates:
  - Swedish, thanks Martin Bagge.  (Closes: #493120)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include <afs/param.h>
16
16
 
17
17
RCSID
18
 
    ("$Header: /cvs/openafs/src/vol/ihandle.c,v 1.18.2.1 2004/08/25 07:14:19 shadow Exp $");
 
18
    ("$Header: /cvs/openafs/src/vol/ihandle.c,v 1.18.2.5 2007/11/26 21:47:38 shadow Exp $");
19
19
 
20
20
#include <stdio.h>
21
21
#include <sys/types.h>
22
22
#include <errno.h>
 
23
#include <string.h>
23
24
#ifdef AFS_NT40_ENV
24
25
#include <fcntl.h>
25
26
#else
31
32
#include <sys/resource.h>
32
33
#endif
33
34
#endif
34
 
#ifdef HAVE_STRING_H
35
 
#include <string.h>
36
 
#else
37
 
#ifdef HAVE_STRINGS_H
38
 
#include <strings.h>
39
 
#endif
40
 
#endif
 
35
 
41
36
#include <rx/xdr.h>
42
37
#include <afs/afsint.h>
43
38
#include <errno.h>
154
149
    }
155
150
#endif
156
151
    fdCacheSize = MIN(fdMaxCacheSize, FD_DEFAULT_CACHESIZE);
 
152
 
 
153
    {
 
154
        void *ih_sync_thread();
 
155
#ifdef AFS_PTHREAD_ENV
 
156
        pthread_t syncer;
 
157
        pthread_attr_t tattr;
 
158
 
 
159
        pthread_attr_init(&tattr);
 
160
        pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED);
 
161
 
 
162
        pthread_create(&syncer, &tattr, ih_sync_thread, NULL);
 
163
#else /* AFS_PTHREAD_ENV */
 
164
        PROCESS syncer;
 
165
        LWP_CreateProcess(ih_sync_thread, 16*1024, LWP_MAX_PRIORITY - 2,
 
166
            NULL, "ih_syncer", &syncer);
 
167
#endif /* AFS_PTHREAD_ENV */
 
168
    }
 
169
 
157
170
}
158
171
 
159
172
/* Make the file descriptor cache as big as possible. Don't this call
307
320
     */
308
321
    fdInUseCount += 1;
309
322
    IH_UNLOCK;
 
323
ih_open_retry:
310
324
    fd = OS_IOPEN(ihP);
311
325
    IH_LOCK;
312
 
    if (fd == INVALID_FD) {
 
326
    if (fd == INVALID_FD && (errno != EMFILE || fdLruHead == NULL) ) {
313
327
        fdInUseCount -= 1;
314
328
        IH_UNLOCK;
315
329
        return NULL;
319
333
     * we permit the number of open files to exceed fdCacheSize.
320
334
     * We only recycle open file descriptors when the number
321
335
     * of open files reaches the size of the cache */
322
 
    if (fdInUseCount > fdCacheSize && fdLruHead != NULL) {
 
336
    if ((fdInUseCount > fdCacheSize || fd == INVALID_FD)  && fdLruHead != NULL) {
323
337
        fdP = fdLruHead;
324
338
        assert(fdP->fd_status == FD_HANDLE_OPEN);
325
339
        DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
326
340
        DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail,
327
341
                   fd_ihnext, fd_ihprev);
328
342
        closeFd = fdP->fd_fd;
 
343
        if (fd == INVALID_FD) {
 
344
            fdCacheSize--;          /* reduce in order to not run into here too often */
 
345
            DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
 
346
            fdP->fd_status = FD_HANDLE_AVAIL;
 
347
            fdP->fd_ih = NULL;
 
348
            fdP->fd_fd = INVALID_FD;
 
349
            IH_UNLOCK;
 
350
            OS_CLOSE(closeFd);
 
351
            goto ih_open_retry;
 
352
        }
329
353
    } else {
330
354
        if (fdAvailHead == NULL) {
331
355
            fdHandleAllocateChunk();
840
864
    return code;
841
865
}
842
866
 
 
867
void
 
868
ih_sync_all() {
 
869
    int ihash;
 
870
 
 
871
    IH_LOCK;
 
872
    for (ihash = 0; ihash < I_HANDLE_HASH_SIZE; ihash++) {
 
873
        IHandle_t *ihP, *ihPnext;
 
874
 
 
875
        ihP = ihashTable[ihash].ihash_head;
 
876
        if (ihP)
 
877
            ihP->ih_refcnt++;   /* must not disappear over unlock */
 
878
        for (; ihP; ihP = ihPnext) {
 
879
            
 
880
            if (ihP->ih_synced) {
 
881
                FdHandle_t *fdP;
 
882
 
 
883
                ihP->ih_synced = 0;
 
884
                IH_UNLOCK;
 
885
 
 
886
                fdP = IH_OPEN(ihP);
 
887
                if (fdP) OS_SYNC(fdP->fd_fd);
 
888
                FDH_CLOSE(fdP);
 
889
 
 
890
                IH_LOCK;
 
891
            }
 
892
 
 
893
            /* when decrementing the refcount, the ihandle might disappear
 
894
               and we might not even be able to proceed to the next one.
 
895
               Hence the gymnastics putting a hold on the next one already */
 
896
            ihPnext = ihP->ih_next;
 
897
            if (ihPnext) ihPnext->ih_refcnt++;
 
898
 
 
899
            if (ihP->ih_refcnt > 1) {
 
900
                ihP->ih_refcnt--;
 
901
            } else {
 
902
                IH_UNLOCK;
 
903
                ih_release(ihP);
 
904
                IH_LOCK;
 
905
            }
 
906
 
 
907
        }
 
908
    }
 
909
    IH_UNLOCK;
 
910
}
 
911
 
 
912
void *
 
913
ih_sync_thread() {
 
914
    while(1) {
 
915
 
 
916
#ifdef AFS_PTHREAD_ENV
 
917
        sleep(10);
 
918
#else /* AFS_PTHREAD_ENV */
 
919
        IOMGR_Sleep(60);
 
920
#endif /* AFS_PTHREAD_ENV */
 
921
 
 
922
#ifndef AFS_NT40_ENV
 
923
        sync();
 
924
#endif
 
925
        ih_sync_all();
 
926
    }
 
927
}
843
928
 
844
929
 
845
930
/*************************************************************************