--------------------- PatchSet 4634 Date: 2002/08/11 16:45:09 Author: serassio Branch: cygwin Tag: (none) Log: Synced with nt work Members: doc/win32-relnotes.txt:1.1.2.4->1.1.2.5 helpers/basic_auth/win32_locallogon/NT_auth.c:1.1.6.2->1.1.6.3 helpers/basic_auth/winbind/wb_basic_auth.c:1.2.12.3->1.2.12.4 helpers/external_acl/win32_group/win32_check_group.c:1.1.2.2->1.1.2.3 helpers/ntlm_auth/NTLMSSP-WIN32/ntlm.h:1.1.8.1->1.1.8.2 helpers/ntlm_auth/NTLMSSP-WIN32/ntlm_auth.c:1.1.8.2->1.1.8.3 src/fs/awin32/aiops.c:1.1.2.3->1.1.2.4 src/fs/awin32/async_io.c:1.1.2.2->1.1.2.3 src/fs/awin32/store_asyncufs.h:1.1.2.2->1.1.2.3 src/fs/awin32/store_dir_aufs.c:1.1.2.2->1.1.2.3 src/fs/awin32/store_io_aufs.c:1.1.2.2->1.1.2.3 src/fs/ufs/store_dir_ufs.c:1.5.10.18->1.5.10.19 src/fs/ufs/store_io_ufs.c:1.2.24.6->1.2.24.7 Index: squid/doc/win32-relnotes.txt =================================================================== RCS file: /cvsroot/squid-sf//squid/doc/Attic/win32-relnotes.txt,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid/doc/win32-relnotes.txt 16 Jul 2002 13:34:35 -0000 1.1.2.4 +++ squid/doc/win32-relnotes.txt 11 Aug 2002 16:45:09 -0000 1.1.2.5 @@ -29,3 +29,10 @@ squid.conf or in the /etc/resolv.conf file, the list of DNS name servers are taken from the Windows registry, both static and dynamic DHCP configurations are supported. + + +Awin32 fs module + +awin32 is a native WIN32 Async I/O Squid fs module derived from aufs. Configuration +in squid.conf is identical to aufs, but You nedd to specify awin32 instead aufs as +cache type. Index: squid/helpers/basic_auth/win32_locallogon/NT_auth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/helpers/basic_auth/win32_locallogon/Attic/NT_auth.c,v retrieving revision 1.1.6.2 retrieving revision 1.1.6.3 diff -u -r1.1.6.2 -r1.1.6.3 --- squid/helpers/basic_auth/win32_locallogon/NT_auth.c 16 Jul 2002 13:34:36 -0000 1.1.6.2 +++ squid/helpers/basic_auth/win32_locallogon/NT_auth.c 11 Aug 2002 16:45:09 -0000 1.1.6.3 @@ -52,9 +52,10 @@ { fprintf(stderr, "%s usage:\n%s [-a UserGroup] [-d UserGroup] [-D DefaultDomain] \n" - "-a can specify a Windows Local Group name allowed to authenticate.\n" - "-d can specify a Windows Local Group name not allowed to authenticate.\n", - "-D can specify the default Domain against to authenticate.\n\n", + "-a can specify a Windows Local Group name allowed to authenticate\n" + "-d can specify a Windows Local Group name not allowed to authenticate\n" + "-D can specify the default Domain against to authenticate\n" + "-h this message\n\n", my_program_name, my_program_name); } @@ -62,7 +63,7 @@ process_options(int argc, char *argv[]) { int opt, had_error = 0; - while (-1 != (opt = getopt(argc, argv, "a:d:D:"))) { + while (-1 != (opt = getopt(argc, argv, "ha:d:D:"))) { switch (opt) { case 'a': safe_free(NTAllowedGroup); @@ -77,8 +78,14 @@ case 'D': strcpy(Default_NTDomain, optarg); break; + case 'h': + usage(argv[0]); + exit(0); + case '?': + opt = optopt; + /* fall thru to default */ default: - fprintf(stderr, "unknown option: -%c. Exiting\n", opt); + fprintf(stderr, "Unknown option: -%c. Exiting\n", opt); had_error = 1; } } @@ -100,6 +107,7 @@ char username[256]; char password[256]; char *p; + int err = 0; my_program_name = argv[0]; process_options(argc, argv); @@ -118,6 +126,16 @@ /* Read whole line from standard input. Terminate on break. */ if (fgets(wstr, 255, stdin) == NULL) break; + + if (NULL == strchr(wstr, '\n')) { + err = 1; + continue; + } + if (err) { + fprintf(stderr, "Oversized message\n"); + goto error; + } + if ((p = strchr(wstr, '\n')) != NULL) *p = '\0'; /* strip \n */ if ((p = strchr(wstr, '\r')) != NULL) @@ -126,8 +144,10 @@ username[0] = '\0'; password[0] = '\0'; sscanf(wstr, "%s %s", username, password); /* Extract parameters */ + /* Check for invalid or blank entries */ if ((username[0] == '\0') || (password[0] == '\0')) { + fprintf(stderr, "Invalid Request\n"); puts("ERR"); fflush(stdout); continue; @@ -135,7 +155,9 @@ if (Valid_User(username, password, NTGroup) == NTV_NO_ERROR) puts("OK"); else +error: puts("ERR"); + err = 0; fflush(stdout); } return 0; Index: squid/helpers/basic_auth/winbind/wb_basic_auth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/helpers/basic_auth/winbind/Attic/wb_basic_auth.c,v retrieving revision 1.2.12.3 retrieving revision 1.2.12.4 diff -u -r1.2.12.3 -r1.2.12.4 --- squid/helpers/basic_auth/winbind/wb_basic_auth.c 20 Jul 2002 14:55:12 -0000 1.2.12.3 +++ squid/helpers/basic_auth/winbind/wb_basic_auth.c 11 Aug 2002 16:45:09 -0000 1.2.12.4 @@ -113,8 +113,8 @@ c=memchr(buf,'\n',BUFFER_SIZE); if (c) { - *c = '\0'; - length = c-buf; + *c='\0'; + length=c-buf; } else { err = 1; return; Index: squid/helpers/external_acl/win32_group/win32_check_group.c =================================================================== RCS file: /cvsroot/squid-sf//squid/helpers/external_acl/win32_group/Attic/win32_check_group.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/helpers/external_acl/win32_group/win32_check_group.c 16 Jul 2002 13:34:36 -0000 1.1.2.2 +++ squid/helpers/external_acl/win32_group/win32_check_group.c 11 Aug 2002 16:45:09 -0000 1.1.2.3 @@ -1,5 +1,5 @@ /* - * $Id: win32_check_group.c,v 1.1.2.2 2002/07/16 13:34:36 serassio Exp $ + * $Id: win32_check_group.c,v 1.1.2.3 2002/08/11 16:45:09 serassio Exp $ * * This is a helper for the external ACL interface for Squid Cache * Copyright (C) 2002 Guido Serassio @@ -395,13 +395,23 @@ return result; } +static void +usage(char *program) +{ + fprintf(stderr,"Usage: %s [-d] [-h]\n" + " -d enable debugging\n" + " -G enable Domain Global group mode\n" + " -h this message\n", + program); +} void process_options(int argc, char *argv[]) { int opt; - while (-1 != (opt = getopt(argc, argv, "Gd"))) { + opterr = 0; + while (-1 != (opt = getopt(argc, argv, "Gdh"))) { switch (opt) { case 'G': use_global = 1; @@ -409,8 +419,15 @@ case 'd': debug_enabled = 1; break; + case 'h': + usage(argv[0]); + exit(0); + case '?': + opt = optopt; + /* fall thru to default */ default: fprintf(stderr, "%s Unknown option: -%c. Exiting\n", myname, opt); + usage(argv[0]); exit(1); break; /* not reached */ } @@ -426,6 +443,7 @@ char buf[BUFSIZE]; char *username; char *group; + int err = 0; if (argc > 0) { /* should always be true */ myname=strrchr(argv[0],'/'); @@ -456,6 +474,14 @@ /* Main Loop */ while (fgets (buf, BUFSIZE, stdin)) { + if (NULL == strchr(buf, '\n')) { + err = 1; + continue; + } + if (err) { + fprintf(stderr, "Oversized message\n"); + goto error; + } if ((p = strchr(buf, '\n')) != NULL) *p = '\0'; /* strip \n */ @@ -464,14 +490,21 @@ debug("Got '%s' from Squid (length: %d).\n",buf,sizeof(buf)); + if (buf[0] == '\0') { + fprintf(stderr, "Invalid Request\n"); + goto error; + } + username = strwordtok(buf, &t); group = strwordtok(NULL, &t); if ((use_global ? Valid_Global_Group(username, group) : Valid_Local_Group(username, group))) { printf ("OK\n"); } else { +error: printf ("ERR\n"); } + err = 0; } return 0; } Index: squid/helpers/ntlm_auth/NTLMSSP-WIN32/ntlm.h =================================================================== RCS file: /cvsroot/squid-sf//squid/helpers/ntlm_auth/NTLMSSP-WIN32/Attic/ntlm.h,v retrieving revision 1.1.8.1 retrieving revision 1.1.8.2 diff -u -r1.1.8.1 -r1.1.8.2 --- squid/helpers/ntlm_auth/NTLMSSP-WIN32/ntlm.h 16 Jul 2002 13:22:02 -0000 1.1.8.1 +++ squid/helpers/ntlm_auth/NTLMSSP-WIN32/ntlm.h 11 Aug 2002 16:45:09 -0000 1.1.8.2 @@ -29,17 +29,9 @@ /* * define this if you want debugging */ -#ifdef _SQUID_MSWIN_ -#ifdef _DEBUG -#define DEBUG -#endif -#else #ifndef DEBUG #define DEBUG #endif -#endif - -#define DEAD_DC_RETRY_INTERVAL 30 /************* END CONFIGURATION ***************/ Index: squid/helpers/ntlm_auth/NTLMSSP-WIN32/ntlm_auth.c =================================================================== RCS file: /cvsroot/squid-sf//squid/helpers/ntlm_auth/NTLMSSP-WIN32/Attic/ntlm_auth.c,v retrieving revision 1.1.8.2 retrieving revision 1.1.8.3 diff -u -r1.1.8.2 -r1.1.8.3 --- squid/helpers/ntlm_auth/NTLMSSP-WIN32/ntlm_auth.c 16 Jul 2002 13:34:36 -0000 1.1.8.2 +++ squid/helpers/ntlm_auth/NTLMSSP-WIN32/ntlm_auth.c 11 Aug 2002 16:45:10 -0000 1.1.8.3 @@ -1,5 +1,5 @@ /* - * $Id: ntlm_auth.c,v 1.1.8.2 2002/07/16 13:34:36 serassio Exp $ + * $Id: ntlm_auth.c,v 1.1.8.3 2002/08/11 16:45:10 serassio Exp $ * * This is a helper for NTLM Authentication for Squid Cache * Copyright (C) 2002 Guido Serassio @@ -65,6 +65,11 @@ } } +void +helperfail(const char *reason) +{ + SEND2("BH %s", reason); +} void send_bh_or_ld(char *bhmessage, ntlm_authenticate * failedauth, int authlen) @@ -102,16 +107,17 @@ { fprintf(stderr, #ifdef NTLM_FAIL_OPEN - "%s usage:\n%s [-v] [-a UserGroup] [-d UserGroup] [-l]\n" + "%s usage:\n%s [-v] [-a UserGroup] [-d UserGroup] [-l] [-h]\n" #else - "%s usage:\n%s [-v] [-a UserGroup] [-d UserGroup]\n" + "%s usage:\n%s [-v] [-a UserGroup] [-d UserGroup] [-h]\n" #endif - "-v enables verbose debugging statements if DEBUG was defined at build-time.\n" + "-v enables verbose debugging.\n" #ifdef NTLM_FAIL_OPEN - "-l if specified, changes behavior on failures to last-ditch.\n" + "-l if specified, changes behavior on failures to last-ditch\n" #endif - "-a can specify a Windows Local Group name allowed to authenticate.\n" - "-d can specify a Windows Local Group name not allowed to authenticate.\n\n", + "-a specify a Windows Local Group name allowed to authenticate\n" + "-d specify a Windows Local Group name not allowed to authenticate\n" + "-h this message\n\n", my_program_name, my_program_name); } @@ -120,10 +126,12 @@ process_options(int argc, char *argv[]) { int opt, had_error = 0; + + opterr =0; #ifdef NTLM_FAIL_OPEN - while (-1 != (opt = getopt(argc, argv, "vla:d:"))) { + while (-1 != (opt = getopt(argc, argv, "hvla:d:"))) { #else - while (-1 != (opt = getopt(argc, argv, "va:d:"))) { + while (-1 != (opt = getopt(argc, argv, "hva:d:"))) { #endif switch (opt) { case 'a': @@ -144,6 +152,12 @@ case 'v': debug_enabled=1; break; + case 'h': + usage(); + exit(0); + case '?': + opt = optopt; + /* fall thru to default */ default: fprintf(stderr, "unknown option: -%c. Exiting\n", opt); usage(); @@ -179,23 +193,37 @@ { ntlmhdr *fast_header; char buf[BUFFER_SIZE]; - const char *ch; - char *ch2, *decoded, *cred; + char *c, *decoded, *cred; int plen; + int oversized = 0; +try_again: if (fgets(buf, BUFFER_SIZE, stdin) == NULL) { debug("fgets() failed! dying..... errno=%d (%s)\n", errno, strerror(errno)); exit(1); /* BIIG buffer */ } - debug("managing request\n"); - ch2 = memchr(buf, '\n', BUFFER_SIZE); /* safer against overrun than strchr */ - if (ch2) { - *ch2 = '\0'; /* terminate the string at newline. */ - ch = ch2; + c = memchr(buf, '\n', BUFFER_SIZE); /* safer against overrun than strchr */ + if (c) { + if (oversized) { + helperfail("illegal request received"); + fprintf(stderr, "Illegal request received: '%s'\n", buf); + return; + } + *c = '\0'; + } else { + fprintf(stderr, "No newline in '%s'\n", buf); + oversized = 1; + goto try_again; } - debug("ntlm authenticator. Got '%s' from Squid\n", buf); + debug("Got '%s' from Squid\n", buf); + + if (memcmp(buf, "YR", 2) == 0) { /* refresh-request */ + c = (char *) obtain_challenge(); + SEND2("TT %s", c); + return; + } if (memcmp(buf, "KK ", 3) == 0) { /* authenticate-request */ /* figure out what we got */ decoded = base64_decode(buf + 3); @@ -249,17 +277,16 @@ SEND2("AF %s", cred); return; default: - SEND("BH unknown authentication packet type"); + helperfail("unknown authentication packet type"); return; } return; - } - if (memcmp(buf, "YR", 2) == 0) { /* refresh-request */ - ch = obtain_challenge(); - SEND2("TT %s", ch); + } else { /* not an auth-request */ + helperfail("illegal request received"); + fprintf(stderr, "Illegal request received: '%s'\n", buf); return; } - SEND("BH Helper detected protocol error"); + helperfail("detected protocol error"); return; /********* END ********/ } Index: squid/src/fs/awin32/aiops.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/aiops.c,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid/src/fs/awin32/aiops.c 16 Mar 2002 10:36:42 -0000 1.1.2.3 +++ squid/src/fs/awin32/aiops.c 11 Aug 2002 16:45:10 -0000 1.1.2.4 @@ -1,5 +1,5 @@ /* - * $Id: aiops.c,v 1.1.2.3 2002/03/16 10:36:42 serassio Exp $ + * $Id: aiops.c,v 1.1.2.4 2002/08/11 16:45:10 serassio Exp $ * * DEBUG: section 43 AIOPS * AUTHOR: Stewart Forster @@ -36,7 +36,6 @@ #include #include "store_asyncufs.h" - #include #include #include @@ -90,8 +89,8 @@ } squidaio_request_t; typedef struct squidaio_request_queue_t { - HANDLE mutex; /* pthread_mutex_t mutex; */ - HANDLE cond; /*pthread_cond_t cond; */ /* See Event objects */ + HANDLE mutex; + HANDLE cond; /* See Event objects */ squidaio_request_t *volatile head; squidaio_request_t *volatile *volatile tailp; unsigned long requests; @@ -101,11 +100,12 @@ typedef struct squidaio_thread_t squidaio_thread_t; struct squidaio_thread_t { squidaio_thread_t *next; - HANDLE thread; /* pthread_t thread; */ + HANDLE thread; DWORD dwThreadId; /* thread ID */ squidaio_thread_status status; struct squidaio_request_t *current_req; unsigned long requests; + int volatile exit; }; int squidaio_cancel(squidaio_result_t *); @@ -122,7 +122,6 @@ static void squidaio_init(void); static void squidaio_queue_request(squidaio_request_t *); static void squidaio_cleanup_request(squidaio_request_t *); -/* static void *squidaio_thread_loop(void *); */ static DWORD WINAPI squidaio_thread_loop( LPVOID lpParam ); static void squidaio_do_open(squidaio_request_t *); static void squidaio_do_read(squidaio_request_t *); @@ -148,7 +147,7 @@ #define AIO_MICRO_BUFS 128 static MemPool *squidaio_large_bufs = NULL; /* 16K */ -static MemPool *squidaio_medium_bufs = NULL; /* 8K */ +static MemPool *squidaio_medium_bufs = NULL; /* 8K */ static MemPool *squidaio_small_bufs = NULL; /* 4K */ static MemPool *squidaio_tiny_bufs = NULL; /* 2K */ static MemPool *squidaio_micro_bufs = NULL; /* 128K */ @@ -170,9 +169,7 @@ NULL, &done_requests.head }; -/* static pthread_attr_t globattr; The attributes of a created thread */ -/*static struct sched_param globsched; */ -/* static pthread_t main_thread; */ + static HANDLE main_thread; static MemPool * @@ -253,42 +250,28 @@ if (squidaio_initialised) return; - if (!DuplicateHandle(GetCurrentProcess(), /* pseudo handle, don't close */ - GetCurrentThread(), /* pseudo handle to copy */ - GetCurrentProcess(), /* pseudo handle, don't close */ - &main_thread, - 0, /* required access */ - FALSE, /* child process's don't inherit the handle */ - DUPLICATE_SAME_ACCESS)) { + if (!DuplicateHandle(GetCurrentProcess(), /* pseudo handle, don't close */ + GetCurrentThread(), /* pseudo handle to copy */ + GetCurrentProcess(),/* pseudo handle, don't close */ + &main_thread, + 0, /* required access */ + FALSE, /* child process's don't inherit the handle */ + DUPLICATE_SAME_ACCESS)) { /* spit errors */ fatal("couldn't get current thread handle\n"); } - /* FIXME: where do we CloseHandle the main_thread ?*/ -#if 0 -/* FIXME set the current thread to priority 1 */ -#if HAVE_PTHREAD_SETSCHEDPARAM - pthread_setschedparam(main_thread, SCHED_OTHER, &globsched); -#endif -/* FIXME set new threads to priority 2 - globsched.sched_priority = 2; -#if HAVE_PTHREAD_ATTR_SETSCHEDPARAM - pthread_attr_setschedparam(&globattr, &globsched); -#endif -*/ -#endif - /* Initialize request queue */ - if ((request_queue.mutex=CreateMutex( NULL, /* no inheritance */ - FALSE, /* start unowned (as per mutex_init) */ - NULL /* no name */ ) - )==NULL) { + if ((request_queue.mutex = CreateMutex(NULL, /* no inheritance */ + FALSE, /* start unowned (as per mutex_init) */ + NULL) /* no name */ + ) == NULL) { fatal("failed to create mutex\n"); } - if ((request_queue.cond=CreateEvent( NULL, /* no inheritance */ - FALSE, /* auto signal reset - which I think is pthreads like ? */ - FALSE, /* start non signaled */ - NULL /* no name */ ) - )==NULL) { + if ((request_queue.cond = CreateEvent(NULL, /* no inheritance */ + FALSE, /* auto signal reset - which I think is pthreads like ? */ + FALSE, /* start non signaled */ + NULL) /* no name */ + ) == NULL) { fatal("failed to create condition event variable.\n"); } request_queue.head = NULL; @@ -297,17 +280,17 @@ request_queue.blocked = 0; /* Initialize done queue */ - if ((done_queue.mutex=CreateMutex( NULL, /* no inheritance */ - FALSE, /* start unowned (as per mutex_init) */ - NULL /* no name */ ) - )==NULL) { + if ((done_queue.mutex = CreateMutex(NULL, /* no inheritance */ + FALSE, /* start unowned (as per mutex_init) */ + NULL) /* no name */ + ) == NULL) { fatal("failed to create mutex\n"); } - if ((done_queue.cond=CreateEvent( NULL, /* no inheritance */ - TRUE, /* manually signaled - which I think is pthreads like ? */ - FALSE, /* start non signaled */ - NULL /* no name */ ) - )==NULL) { + if ((done_queue.cond = CreateEvent(NULL, /* no inheritance */ + TRUE, /* manually signaled - which I think is pthreads like ? */ + FALSE, /* start non signaled */ + NULL) /* no name */ + ) == NULL) { fatal("failed to create condition event variable.\n"); } done_queue.head = NULL; @@ -324,18 +307,19 @@ threadp->requests = 0; threadp->next = threads; threads = threadp; - if ((threadp->thread = CreateThread( - NULL, // no security attributes - 0, // use default stack size - squidaio_thread_loop, // thread function - threadp, // argument to thread function - 0, // use default creation flags - &(threadp->dwThreadId)) // returns the thread identifier - )==NULL) { + if ((threadp->thread = CreateThread(NULL, /* no security attributes */ + 0, /* use default stack size */ + squidaio_thread_loop, /* thread function */ + threadp, /* argument to thread function */ + 0, /* use default creation flags */ + &(threadp->dwThreadId)) /* returns the thread identifier */ + ) == NULL) { fprintf(stderr, "Thread creation failed\n"); threadp->status = _THREAD_FAILED; continue; } + /* Set the new thread priority above parent process */ + SetThreadPriority(threadp->thread,THREAD_PRIORITY_ABOVE_NORMAL); } /* Create request pool */ @@ -349,65 +333,62 @@ squidaio_initialised = 1; } +void +squidaio_shutdown(void) +{ + squidaio_thread_t *threadp; + int i; + HANDLE hthreads[NUMTHREADS]; + + if (!squidaio_initialised) + return; + + threadp = threads; + for (i = 0; i < NUMTHREADS; i++) { + threadp->exit = 1; + hthreads[i] = threadp->thread; + threadp = threadp->next; + } + ReleaseMutex(request_queue.mutex); + ResetEvent(request_queue.cond); + ReleaseMutex(done_queue.mutex); + ResetEvent(done_queue.cond); + Sleep(0); + + WaitForMultipleObjects(NUMTHREADS, hthreads, TRUE, 2000); + for (i = 0; i < NUMTHREADS; i++) { + CloseHandle(hthreads[i]); + } + CloseHandle(main_thread); + squidaio_initialised = 0; +} static DWORD WINAPI -squidaio_thread_loop( LPVOID lpParam ) +squidaio_thread_loop(LPVOID lpParam) { squidaio_thread_t *threadp = lpParam; squidaio_request_t *request; HANDLE cond; /* local copy of the event queue because win32 event handles * don't atomically release the mutex as cond variables do. */ -#if 0 -/* sigset_t new; */ - /* - * Does WIN32 have this problem? - */ - - /* - * Make sure to ignore signals which may possibly get sent to - * the parent squid thread. Causes havoc with mutex's and - * condition waits otherwise - */ - - sigemptyset(&new); - sigaddset(&new, SIGPIPE); - sigaddset(&new, SIGCHLD); -#ifdef _SQUID_LINUX_THREADS_ - sigaddset(&new, SIGQUIT); - sigaddset(&new, SIGTRAP); -#else - sigaddset(&new, SIGUSR1); - sigaddset(&new, SIGUSR2); -#endif - sigaddset(&new, SIGHUP); - sigaddset(&new, SIGTERM); - sigaddset(&new, SIGINT); - sigaddset(&new, SIGALRM); - pthread_sigmask(SIG_BLOCK, &new, NULL); -#endif /* 0 */ - /* lock the thread info */ - if (WAIT_FAILED == WaitForSingleObject( - request_queue.mutex, // handle to object - INFINITE // time-out interval - )) { - /* wait failed.... what to do ? */ + if (WAIT_FAILED == WaitForSingleObject(request_queue.mutex, INFINITE)) { + fatal("Can't get ownership of mutex\n"); } /* duplicate the handle */ - if (!DuplicateHandle(GetCurrentProcess(), /* pseudo handle, don't close */ - request_queue.cond, /* handle to copy */ - GetCurrentProcess(), /* pseudo handle, don't close */ - &cond, - 0, /* required access */ - FALSE, /* child process's don't inherit the handle */ - DUPLICATE_SAME_ACCESS)) - exit(1); + if (!DuplicateHandle(GetCurrentProcess(), /* pseudo handle, don't close */ + request_queue.cond, /* handle to copy */ + GetCurrentProcess(), /* pseudo handle, don't close */ + &cond, + 0, /* required access */ + FALSE, /* child process's don't inherit the handle */ + DUPLICATE_SAME_ACCESS)) + fatal("Can't duplicate mutex handle\n"); if (!ReleaseMutex(request_queue.mutex)) { CloseHandle(cond); - exit(1); + fatal("Can't release mutex\n"); } - + Sleep(0); while (1) { DWORD rv; @@ -415,34 +396,30 @@ request = NULL; /* Get a request to process */ threadp->status = _THREAD_WAITING; - rv = WaitForSingleObject( - request_queue.mutex, // handle to object - INFINITE // time-out interval - ); + if (threadp->exit) { + CloseHandle(request_queue.mutex); + CloseHandle(cond); + return 0; + } + rv = WaitForSingleObject(request_queue.mutex, INFINITE); if (rv == WAIT_FAILED) { CloseHandle(cond); return 1; } - while (!request_queue.head) { if (!ReleaseMutex(request_queue.mutex)) { CloseHandle(cond); threadp->status = _THREAD_FAILED; return 1; } - rv = WaitForSingleObject( - cond, // handle to object - INFINITE // time-out interval - ); + Sleep(0); + rv = WaitForSingleObject(cond, INFINITE); if (rv == WAIT_FAILED) { CloseHandle(cond); return 1; } - rv = WaitForSingleObject( - request_queue.mutex, // handle to object - INFINITE // time-out interval - ); + rv = WaitForSingleObject(request_queue.mutex, INFINITE); if (rv == WAIT_FAILED) { CloseHandle(cond); return 1; @@ -457,6 +434,7 @@ CloseHandle(cond); return 1; } + Sleep(0); /* process the request */ threadp->status = _THREAD_BUSY; request->next = NULL; @@ -501,10 +479,7 @@ } threadp->status = _THREAD_DONE; /* put the request in the done queue */ - rv = WaitForSingleObject( - done_queue.mutex, // handle to object - INFINITE // time-out interval - ); + rv = WaitForSingleObject(done_queue.mutex, INFINITE); if (rv == WAIT_FAILED) { CloseHandle(cond); return 1; @@ -515,6 +490,7 @@ CloseHandle(cond); return 1; } + Sleep(0); threadp->requests++; } /* while forever */ CloseHandle(cond); @@ -525,7 +501,7 @@ squidaio_queue_request(squidaio_request_t * request) { static int high_start = 0; - debug(41, 9) ("squidaio_queue_request: %p type=%d result=%p\n", + debug(43, 9) ("squidaio_queue_request: %p type=%d result=%p\n", request, request->request_type, request->resultp); /* Mark it as not executed (failing result, no error) */ request->ret = -1; @@ -538,16 +514,17 @@ if (!request_queue2.head) { /* If queue2 is empty, insert into queue 1 and try to "push" the queue If the "push" fails, queue it via queue2 */ - if (WaitForSingleObject(request_queue.mutex, 0)==WAIT_OBJECT_0) { + if (WaitForSingleObject(request_queue.mutex, 0) == WAIT_OBJECT_0) { /* Normal path */ *request_queue.tailp = request; request_queue.tailp = &request->next; - if (!SetEvent(request_queue.cond)) + if (!SetEvent(request_queue.cond)) fatal("couldn't push queue\n"); if (!ReleaseMutex(request_queue.mutex)) { /* unexpected error */ fatal("couldn't push queue\n"); } + Sleep(0); } else { /* Oops, the request queue is blocked, use request_queue2 */ *request_queue2.tailp = request; @@ -567,6 +544,7 @@ /* unexpected error */ fatal("couldn't push queue\n"); } + Sleep(0); request_queue2.head = NULL; request_queue2.tailp = &request_queue2.head; } else { @@ -672,7 +650,7 @@ squidaio_request_t *request = resultp->_data; if (request && request->resultp == resultp) { - debug(41, 9) ("squidaio_cancel: %p type=%d result=%p\n", + debug(43, 9) ("squidaio_cancel: %p type=%d result=%p\n", request, request->request_type, request->resultp); request->cancelled = 1; request->resultp = NULL; @@ -738,7 +716,15 @@ squidaio_do_read(squidaio_request_t * requestp) { lseek(requestp->fd, requestp->offset, requestp->whence); +#ifdef _SQUID_MSWIN_ + if (!ReadFile((HANDLE)_get_osfhandle(requestp->fd), requestp->tmpbufp, + requestp->buflen, (LPDWORD)&requestp->ret, NULL)) { + _dosmaperr(GetLastError()); + requestp->ret = -1; + } +#else requestp->ret = read(requestp->fd, requestp->tmpbufp, requestp->buflen); +#endif requestp->err = errno; } @@ -769,7 +755,15 @@ static void squidaio_do_write(squidaio_request_t * requestp) { +#ifdef _SQUID_MSWIN_ + if (!WriteFile((HANDLE)_get_osfhandle(requestp->fd), requestp->tmpbufp, + requestp->buflen, (LPDWORD)&requestp->ret, NULL)) { + _dosmaperr(GetLastError()); + requestp->ret = -1; + } +#else requestp->ret = write(requestp->fd, requestp->tmpbufp, requestp->buflen); +#endif requestp->err = errno; } @@ -795,7 +789,10 @@ static void squidaio_do_close(squidaio_request_t * requestp) { - requestp->ret = close(requestp->fd); + if((requestp->ret = close(requestp->fd)) < 0) { + debug(43, 0) ("squidaio_do_close: FD %d, errno %d\n", requestp->fd, errno); + close(requestp->fd); + } requestp->err = errno; } @@ -916,6 +913,7 @@ if (!ReleaseMutex(request_queue.mutex)) { /* unexpected error */ } + Sleep(0); request_queue2.head = NULL; request_queue2.tailp = &request_queue2.head; } @@ -928,6 +926,7 @@ if (!ReleaseMutex(done_queue.mutex)) { /* unexpected error */ } + Sleep(0); *done_requests.tailp = requests; request_queue_len -= 1; while (requests->next) { @@ -956,7 +955,7 @@ if (!request) { return NULL; } - debug(41, 9) ("squidaio_poll_done: %p type=%d result=%p\n", + debug(43, 9) ("squidaio_poll_done: %p type=%d result=%p\n", request, request->request_type, request->resultp); done_requests.head = request->next; if (!done_requests.head) @@ -1019,3 +1018,22 @@ break; } } + +void +squidaio_stats(StoreEntry * sentry) +{ + squidaio_thread_t *threadp; + int i; + + if (!squidaio_initialised) + return; + + storeAppendPrintf(sentry, "\n\nThreads Status:\n"); + storeAppendPrintf(sentry, "#\tID\t# Requests\n"); + + threadp = threads; + for (i = 0; i < NUMTHREADS; i++) { + storeAppendPrintf(sentry, "%i\t0x%lx\t%d\n", i + 1, threadp->dwThreadId, threadp->requests); + threadp = threadp->next; + } +} Index: squid/src/fs/awin32/async_io.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/async_io.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/src/fs/awin32/async_io.c 16 Mar 2002 10:36:42 -0000 1.1.2.2 +++ squid/src/fs/awin32/async_io.c 11 Aug 2002 16:45:10 -0000 1.1.2.3 @@ -1,6 +1,6 @@ /* - * $Id: async_io.c,v 1.1.2.2 2002/03/16 10:36:42 serassio Exp $ + * $Id: async_io.c,v 1.1.2.3 2002/08/11 16:45:10 serassio Exp $ * * DEBUG: section 32 Asynchronous Disk I/O * AUTHOR: Pete Bentley @@ -102,7 +102,10 @@ void aioDone(void) { - memPoolDestroy(squidaio_ctrl_pool); + if (!initialised) + return; + squidaio_shutdown(); + memPoolDestroy(&squidaio_ctrl_pool); initialised = 0; } @@ -116,9 +119,8 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = -2; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_OPEN; - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_open(path, oflag, mode, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -148,8 +150,6 @@ aioCancel(int fd) { squidaio_ctrl_t *curr; - AIOCB *done_handler; - void *their_data; dlink_node *m, *next; assert(initialised); @@ -162,14 +162,13 @@ squidaio_cancel(&curr->result); - if ((done_handler = curr->done_handler)) { - their_data = curr->done_handler_data; + if (curr->done_handler) { + AIOCB *callback = curr->done_handler; + void *cbdata; curr->done_handler = NULL; - curr->done_handler_data = NULL; debug(32, 2) ("this be aioCancel\n"); - if (cbdataValid(their_data)) - done_handler(fd, their_data, -2, -2); - cbdataUnlock(their_data); + if (cbdataReferenceValidDone(curr->done_handler_data, &cbdata)) + callback(fd, cbdata, -2, -2); } dlinkDelete(m, &used_list); memPoolFree(squidaio_ctrl_pool, curr); @@ -188,7 +187,7 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = fd; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_WRITE; ctrlp->bufp = bufp; ctrlp->free_func = free_func; @@ -198,7 +197,6 @@ seekmode = SEEK_END; offset = 0; } - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_write(fd, bufp, len, offset, seekmode, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -216,7 +214,7 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = fd; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_READ; if (offset >= 0) seekmode = SEEK_SET; @@ -224,7 +222,6 @@ seekmode = SEEK_CUR; offset = 0; } - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_read(fd, bufp, len, offset, seekmode, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -241,9 +238,8 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = -2; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_STAT; - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_stat(path, sb, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -259,9 +255,8 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = -2; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_UNLINK; - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_unlink(path, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -276,9 +271,8 @@ ctrlp = memPoolAlloc(squidaio_ctrl_pool); ctrlp->fd = -2; ctrlp->done_handler = callback; - ctrlp->done_handler_data = callback_data; + ctrlp->done_handler_data = cbdataReference(callback_data); ctrlp->operation = _AIO_TRUNCATE; - cbdataLock(callback_data); ctrlp->result.data = ctrlp; squidaio_truncate(path, length, &ctrlp->result); dlinkAdd(ctrlp, &ctrlp->node, &used_list); @@ -290,8 +284,6 @@ { squidaio_result_t *resultp; squidaio_ctrl_t *ctrlp; - AIOCB *done_handler; - void *their_data; int retval = 0; assert(initialised); @@ -303,16 +295,15 @@ if (ctrlp == NULL) continue; /* XXX Should not happen */ dlinkDelete(&ctrlp->node, &used_list); - if ((done_handler = ctrlp->done_handler)) { - their_data = ctrlp->done_handler_data; + if (ctrlp->done_handler) { + AIOCB *callback = ctrlp->done_handler; + void *cbdata; ctrlp->done_handler = NULL; - ctrlp->done_handler_data = NULL; - if (cbdataValid(their_data)) { + if (cbdataReferenceValidDone(ctrlp->done_handler_data, &cbdata)) { retval = 1; /* Return that we've actually done some work */ - done_handler(ctrlp->fd, their_data, + callback(ctrlp->fd, cbdata, ctrlp->result.aio_return, ctrlp->result.aio_errno); } - cbdataUnlock(their_data); } /* free data if requested to aioWrite() */ if (ctrlp->free_func) @@ -328,6 +319,7 @@ aioStats(StoreEntry * sentry) { storeAppendPrintf(sentry, "ASYNC IO Counters:\n"); + storeAppendPrintf(sentry, "Operation\t# Requests\n"); storeAppendPrintf(sentry, "open\t%d\n", squidaio_counts.open); storeAppendPrintf(sentry, "close\t%d\n", squidaio_counts.close); storeAppendPrintf(sentry, "cancel\t%d\n", squidaio_counts.cancel); @@ -337,6 +329,7 @@ storeAppendPrintf(sentry, "unlink\t%d\n", squidaio_counts.unlink); storeAppendPrintf(sentry, "check_callback\t%d\n", squidaio_counts.check_callback); storeAppendPrintf(sentry, "queue\t%d\n", squidaio_get_queue_len()); + squidaio_stats(sentry); } /* Flush all pending I/O */ Index: squid/src/fs/awin32/store_asyncufs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/store_asyncufs.h,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/src/fs/awin32/store_asyncufs.h 16 Mar 2002 10:36:42 -0000 1.1.2.2 +++ squid/src/fs/awin32/store_asyncufs.h 11 Aug 2002 16:45:10 -0000 1.1.2.3 @@ -49,6 +49,8 @@ int squidaio_operations_pending(void); int squidaio_sync(void); int squidaio_get_queue_len(void); +void squidaio_shutdown(void); +void squidaio_stats(StoreEntry *); void aioInit(void); void aioDone(void); Index: squid/src/fs/awin32/store_dir_aufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/store_dir_aufs.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/src/fs/awin32/store_dir_aufs.c 16 Mar 2002 10:36:42 -0000 1.1.2.2 +++ squid/src/fs/awin32/store_dir_aufs.c 11 Aug 2002 16:45:10 -0000 1.1.2.3 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_aufs.c,v 1.1.2.2 2002/03/16 10:36:42 serassio Exp $ + * $Id: store_dir_aufs.c,v 1.1.2.3 2002/08/11 16:45:10 serassio Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -87,8 +87,8 @@ time_t timestamp, time_t lastref, time_t lastmod, - u_num32 refcount, - u_short flags, + u_int32_t refcount, + u_int16_t flags, int clean); static void storeAufsDirRebuild(SwapDir * sd); static void storeAufsDirCloseTmpSwapLog(SwapDir * sd); @@ -211,12 +211,12 @@ getCurrentTime(); if (0 == stat(path, &st)) { if (S_ISDIR(st.st_mode)) { - debug(20, should_exist ? 3 : 1) ("%s exists\n", path); + debug(47, should_exist ? 3 : 1) ("%s exists\n", path); } else { fatalf("Swap directory %s is not a directory.", path); } } else if (0 == mkdir(path, 0755)) { - debug(20, should_exist ? 1 : 3) ("%s created\n", path); + debug(47, should_exist ? 1 : 3) ("%s created\n", path); created = 1; } else { fatalf("Failed to make swap directory %s: %s", @@ -230,11 +230,11 @@ { struct stat sb; if (stat(path, &sb) < 0) { - debug(20, 0) ("%s: %s\n", path, xstrerror()); + debug(47, 0) ("%s: %s\n", path, xstrerror()); return -1; } if (S_ISDIR(sb.st_mode) == 0) { - debug(20, 0) ("%s is not a directory\n", path); + debug(47, 0) ("%s is not a directory\n", path); return -1; } return 0; @@ -325,7 +325,7 @@ debug(50, 1) ("%s: %s\n", path, xstrerror()); fatal("storeAufsDirOpenSwapLog: Failed to open swap log."); } - debug(47, 3) ("Cache Dir #%d log opened on FD %d\n", sd->index, fd); + debug(50, 3) ("Cache Dir #%d log opened on FD %d\n", sd->index, fd); aioinfo->swaplog_fd = fd; if (0 == n_asyncufs_dirs) assert(NULL == asyncufs_dir_index); @@ -387,12 +387,12 @@ tlv *tlv_list; tlv *t; assert(rb != NULL); - debug(20, 3) ("storeAufsDirRebuildFromDirectory: DIR #%d\n", rb->sd->index); + debug(47, 3) ("storeAufsDirRebuildFromDirectory: DIR #%d\n", rb->sd->index); for (count = 0; count < rb->speed; count++) { assert(fd == -1); fd = storeAufsDirGetNextFile(rb, &filn, &size); if (fd == -2) { - debug(20, 1) ("Done scanning %s swaplog (%d entries)\n", + debug(47, 1) ("Done scanning %s swaplog (%d entries)\n", rb->sd->path, rb->n_read); store_dirs_rebuilding--; storeAufsDirCloseTmpSwapLog(rb->sd); @@ -405,7 +405,7 @@ assert(fd > -1); /* lets get file stats here */ if (fstat(fd, &sb) < 0) { - debug(20, 1) ("storeAufsDirRebuildFromDirectory: fstat(FD %d): %s\n", + debug(47, 1) ("storeAufsDirRebuildFromDirectory: fstat(FD %d): %s\n", fd, xstrerror()); file_close(fd); store_open_disk_fd--; @@ -413,12 +413,12 @@ continue; } if ((++rb->counts.scancount & 0xFFFF) == 0) - debug(20, 3) (" %s %7d files opened so far.\n", + debug(47, 3) (" %s %7d files opened so far.\n", rb->sd->path, rb->counts.scancount); - debug(20, 9) ("file_in: fd=%d %08X\n", fd, filn); + debug(47, 9) ("file_in: fd=%d %08X\n", fd, filn); statCounter.syscalls.disk.reads++; - if (read(fd, hdr_buf, SM_PAGE_SIZE) < 0) { - debug(20, 1) ("storeAufsDirRebuildFromDirectory: read(FD %d): %s\n", + if (FD_READ_METHOD(fd, hdr_buf, SM_PAGE_SIZE) < 0) { + debug(47, 1) ("storeAufsDirRebuildFromDirectory: read(FD %d): %s\n", fd, xstrerror()); file_close(fd); store_open_disk_fd--; @@ -435,12 +435,12 @@ #endif tlv_list = storeSwapMetaUnpack(hdr_buf, &swap_hdr_len); if (tlv_list == NULL) { - debug(20, 1) ("storeAufsDirRebuildFromDirectory: failed to get meta data\n"); + debug(47, 1) ("storeAufsDirRebuildFromDirectory: failed to get meta data\n"); /* XXX shouldn't this be a call to storeAufsUnlink ? */ storeAufsDirUnlinkFile(SD, filn); continue; } - debug(20, 3) ("storeAufsDirRebuildFromDirectory: successful swap meta unpacking\n"); + debug(47, 3) ("storeAufsDirRebuildFromDirectory: successful swap meta unpacking\n"); memset(key, '\0', MD5_DIGEST_CHARS); memset(&tmpe, '\0', sizeof(StoreEntry)); for (t = tlv_list; t; t = t->next) { @@ -460,18 +460,18 @@ storeSwapTLVFree(tlv_list); tlv_list = NULL; if (storeKeyNull(key)) { - debug(20, 1) ("storeAufsDirRebuildFromDirectory: NULL key\n"); + debug(47, 1) ("storeAufsDirRebuildFromDirectory: NULL key\n"); storeAufsDirUnlinkFile(SD, filn); continue; } tmpe.hash.key = key; /* check sizes */ if (tmpe.swap_file_sz == 0) { - tmpe.swap_file_sz = sb.st_size; + tmpe.swap_file_sz = (size_t) sb.st_size; } else if (tmpe.swap_file_sz == sb.st_size - swap_hdr_len) { - tmpe.swap_file_sz = sb.st_size; + tmpe.swap_file_sz = (size_t) sb.st_size; } else if (tmpe.swap_file_sz != sb.st_size) { - debug(20, 1) ("storeAufsDirRebuildFromDirectory: SIZE MISMATCH %ld!=%ld\n", + debug(47, 1) ("storeAufsDirRebuildFromDirectory: SIZE MISMATCH %ld!=%ld\n", (long int) tmpe.swap_file_sz, (long int) sb.st_size); storeAufsDirUnlinkFile(SD, filn); continue; @@ -526,7 +526,7 @@ /* load a number of objects per invocation */ for (count = 0; count < rb->speed; count++) { if (fread(&s, ss, 1, rb->log) != 1) { - debug(20, 1) ("Done reading %s swaplog (%d entries)\n", + debug(47, 1) ("Done reading %s swaplog (%d entries)\n", rb->sd->path, rb->n_read); fclose(rb->log); rb->log = NULL; @@ -550,7 +550,7 @@ * to mask it off. */ s.swap_filen &= 0x00FFFFFF; - debug(20, 3) ("storeAufsDirRebuildFromSwapLog: %s %s %08X\n", + debug(47, 3) ("storeAufsDirRebuildFromSwapLog: %s %s %08X\n", swap_log_op_str[(int) s.op], storeKeyText(s.key), s.swap_filen); @@ -581,7 +581,7 @@ } else { x = log(++rb->counts.bad_log_op) / log(10.0); if (0.0 == x - (double) (int) x) - debug(20, 1) ("WARNING: %d invalid swap log entries found\n", + debug(47, 1) ("WARNING: %d invalid swap log entries found\n", rb->counts.bad_log_op); rb->counts.invalid++; continue; @@ -622,7 +622,7 @@ storeAufsDirUnrefObj(SD, e); } else { debug_trap("storeAufsDirRebuildFromSwapLog: bad condition"); - debug(20, 1) ("\tSee %s:%d\n", __FILE__, __LINE__); + debug(47, 1) ("\tSee %s:%d\n", __FILE__, __LINE__); } continue; } else if (used) { @@ -631,7 +631,7 @@ * point. If the log is dirty, the filesize check should have * caught this. If the log is clean, there should never be a * newer entry. */ - debug(20, 1) ("WARNING: newer swaplog entry for dirno %d, fileno %08X\n", + debug(47, 1) ("WARNING: newer swaplog entry for dirno %d, fileno %08X\n", SD->index, s.swap_filen); /* I'm tempted to remove the swapfile here just to be safe, * but there is a bad race condition in the NOVM version if @@ -694,11 +694,10 @@ int fd = -1; int used = 0; int dirs_opened = 0; - debug(20, 3) ("storeAufsDirGetNextFile: flag=%d, %d: /%02X/%02X\n", + debug(47, 3) ("storeAufsDirGetNextFile: flag=%d, %d: /%02X/%02X\n", rb->flags.init, rb->sd->index, - rb->curlvl1, - rb->curlvl2); + rb->curlvl1, rb->curlvl2); if (rb->done) return -2; while (fd < 0 && rb->done == 0) { @@ -714,52 +713,53 @@ if (0 == rb->in_dir) { /* we need to read in a new directory */ snprintf(rb->fullpath, SQUID_MAXPATHLEN, "%s/%02X/%02X", rb->sd->path, - rb->curlvl1, rb->curlvl2); - if (rb->flags.init && rb->td != NULL) - closedir(rb->td); - rb->td = NULL; + rb->curlvl1, + rb->curlvl2); if (dirs_opened) return -1; rb->td = opendir(rb->fullpath); dirs_opened++; if (rb->td == NULL) { - debug(50, 1) ("storeAufsDirGetNextFile: opendir: %s: %s\n", + debug(47, 1) ("storeAufsDirGetNextFile: opendir: %s: %s\n", rb->fullpath, xstrerror()); } else { rb->entry = readdir(rb->td); /* skip . and .. */ rb->entry = readdir(rb->td); if (rb->entry == NULL && errno == ENOENT) - debug(20, 1) ("storeAufsDirGetNextFile: directory does not exist!.\n"); - debug(20, 3) ("storeAufsDirGetNextFile: Directory %s\n", rb->fullpath); + debug(47, 1) ("storeAufsDirGetNextFile: directory does not exist!.\n"); + debug(47, 3) ("storeAufsDirGetNextFile: Directory %s\n", rb->fullpath); } } if (rb->td != NULL && (rb->entry = readdir(rb->td)) != NULL) { rb->in_dir++; if (sscanf(rb->entry->d_name, "%x", &rb->fn) != 1) { - debug(20, 3) ("storeAufsDirGetNextFile: invalid %s\n", + debug(47, 3) ("storeAufsDirGetNextFile: invalid %s\n", rb->entry->d_name); continue; } if (!storeAufsFilenoBelongsHere(rb->fn, rb->sd->index, rb->curlvl1, rb->curlvl2)) { - debug(20, 3) ("storeAufsDirGetNextFile: %08X does not belong in %d/%d/%d\n", + debug(47, 3) ("storeAufsDirGetNextFile: %08X does not belong in %d/%d/%d\n", rb->fn, rb->sd->index, rb->curlvl1, rb->curlvl2); continue; } used = storeAufsDirMapBitTest(SD, rb->fn); if (used) { - debug(20, 3) ("storeAufsDirGetNextFile: Locked, continuing with next.\n"); + debug(47, 3) ("storeAufsDirGetNextFile: Locked, continuing with next.\n"); continue; } snprintf(rb->fullfilename, SQUID_MAXPATHLEN, "%s/%s", rb->fullpath, rb->entry->d_name); - debug(20, 3) ("storeAufsDirGetNextFile: Opening %s\n", rb->fullfilename); + debug(47, 3) ("storeAufsDirGetNextFile: Opening %s\n", rb->fullfilename); fd = file_open(rb->fullfilename, O_RDONLY | O_BINARY); if (fd < 0) - debug(50, 1) ("storeAufsDirGetNextFile: %s: %s\n", rb->fullfilename, xstrerror()); + debug(47, 1) ("storeAufsDirGetNextFile: %s: %s\n", rb->fullfilename, xstrerror()); else store_open_disk_fd++; continue; } + if (rb->td != NULL) + closedir(rb->td); + rb->td = NULL; rb->in_dir = 0; if (++rb->curlvl2 < aioinfo->l2) continue; @@ -783,12 +783,12 @@ time_t timestamp, time_t lastref, time_t lastmod, - u_num32 refcount, - u_short flags, + u_int32_t refcount, + u_int16_t flags, int clean) { StoreEntry *e = NULL; - debug(20, 5) ("storeAufsAddDiskRestore: %s, fileno=%08X\n", storeKeyText(key), file_number); + debug(47, 5) ("storeAufsAddDiskRestore: %s, fileno=%08X\n", storeKeyText(key), file_number); /* if you call this you'd better be sure file_number is not * already in use! */ e = new_StoreEntry(STORE_ENTRY_WITHOUT_MEMOBJ, NULL, NULL); @@ -848,7 +848,7 @@ } if (!clean) rb->flags.need_to_validate = 1; - debug(20, 1) ("Rebuilding storage in %s (%s)\n", + debug(47, 1) ("Rebuilding storage in %s (%s)\n", sd->path, clean ? "CLEAN" : "DIRTY"); store_dirs_rebuilding++; eventAdd("storeRebuild", func, rb, 0.0, 1); @@ -905,14 +905,14 @@ if (aioinfo->swaplog_fd >= 0) file_close(aioinfo->swaplog_fd); /* open a write-only FD for the new log */ - fd = file_open(new_path, O_WRONLY | O_CREAT | O_TRUNC); + fd = file_open(new_path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); if (fd < 0) { debug(50, 1) ("%s: %s\n", new_path, xstrerror()); fatal("storeDirOpenTmpSwapLog: Failed to open swap log."); } aioinfo->swaplog_fd = fd; /* open a read-only stream of the old log */ - fp = fopen(swaplog_path, "r"); + fp = fopen(swaplog_path, "rb"); if (fp == NULL) { debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); fatal("Failed to open swap log for reading"); @@ -951,9 +951,9 @@ storeAufsDirWriteCleanStart(SwapDir * sd) { struct _clean_state *state = xcalloc(1, sizeof(*state)); -#if HAVE_FCHMOD +#if HAVE_FCHMOD struct stat sb; -#endif +#endif sd->log.clean.write = NULL; sd->log.clean.state = NULL; state->new = xstrdup(storeAufsDirSwapLogFile(sd, ".clean")); @@ -968,9 +968,8 @@ state->outbuf = xcalloc(CLEAN_BUF_SZ, 1); state->outbuf_offset = 0; state->walker = sd->repl->WalkInit(sd->repl); - unlink(state->new); unlink(state->cln); - debug(20, 3) ("storeDirWriteCleanLogs: opened %s, FD %d\n", + debug(47, 3) ("storeDirWriteCleanLogs: opened %s, FD %d\n", state->new, state->fd); #if HAVE_FCHMOD if (stat(state->cur, &sb) == 0) @@ -1018,16 +1017,17 @@ state->outbuf_offset += ss; /* buffered write */ if (state->outbuf_offset + ss > CLEAN_BUF_SZ) { - if (write(state->fd, state->outbuf, state->outbuf_offset) < 0) { + if (FD_WRITE_METHOD(state->fd, state->outbuf, state->outbuf_offset) < 0) { debug(50, 0) ("storeDirWriteCleanLogs: %s: write: %s\n", state->new, xstrerror()); - debug(20, 0) ("storeDirWriteCleanLogs: Current swap logfile not replaced.\n"); + debug(50, 0) ("storeDirWriteCleanLogs: Current swap logfile not replaced.\n"); file_close(state->fd); state->fd = -1; unlink(state->new); safe_free(state); sd->log.clean.state = NULL; sd->log.clean.write = NULL; + return; } state->outbuf_offset = 0; } @@ -1043,10 +1043,10 @@ if (state->fd < 0) return; state->walker->Done(state->walker); - if (write(state->fd, state->outbuf, state->outbuf_offset) < 0) { + if (FD_WRITE_METHOD(state->fd, state->outbuf, state->outbuf_offset) < 0) { debug(50, 0) ("storeDirWriteCleanLogs: %s: write: %s\n", state->new, xstrerror()); - debug(20, 0) ("storeDirWriteCleanLogs: Current swap logfile " + debug(50, 0) ("storeDirWriteCleanLogs: Current swap logfile " "not replaced.\n"); file_close(state->fd); state->fd = -1; @@ -1062,7 +1062,7 @@ fd = state->fd; /* rename */ if (state->fd >= 0) { -#if defined(_SQUID_OS2_) || defined (_SQUID_CYGWIN_) || defined(_SQUID_MSWIN_) +#if defined(_SQUID_OS2_) || defined(_SQUID_CYGWIN_) || defined(_SQUID_MSWIN_) file_close(state->fd); state->fd = -1; if (unlink(state->cur) < 0) @@ -1259,7 +1259,7 @@ static int storeAufsDirIs(SwapDir * sd) { - if (strncmp(sd->type, "awin32", 3) == 0) + if (strncmp(sd->type, "awin32", 6) == 0) return 1; return 0; } @@ -1325,8 +1325,7 @@ * This is kinda cheap, but so we need this priority hack? */ } - debug(20, 3) ("storeMaintainSwapSpace: f=%f, max_scan=%d, max_remove=%d\n", - f, max_scan, max_remove); + debug(47, 3) ("storeMaintainSwapSpace: f=%f, max_scan=%d, max_remove=%d\n", f, max_scan, max_remove); walker = SD->repl->PurgeInit(SD->repl, max_scan); while (1) { if (SD->cur_size < SD->low_size) @@ -1340,7 +1339,7 @@ storeRelease(e); } walker->Done(walker); - debug(20, (removed ? 2 : 3)) ("storeUfsDirMaintain: %s removed %d/%d f=%.03f max_scan=%d\n", + debug(47, (removed ? 2 : 3)) ("storeUfsDirMaintain: %s removed %d/%d f=%.03f max_scan=%d\n", SD->path, removed, max_remove, f, max_scan); } @@ -1359,7 +1358,7 @@ #if OLD_UNUSED_CODE if (storeAufsDirExpiredReferenceAge(SD) < 300) { - debug(20, 3) ("storeAufsDirCheckObj: NO: LRU Age = %d\n", + debug(47, 3) ("storeAufsDirCheckObj: NO: LRU Age = %d\n", storeAufsDirExpiredReferenceAge(SD)); /* store_check_cachable_hist.no.lru_age_too_low++; */ return -1; @@ -1369,7 +1368,7 @@ if (ql == 0) loadav = 0; loadav = ql * 1000 / MAGIC1; - debug(41, 9) ("storeAufsDirCheckObj: load=%d\n", loadav); + debug(47, 9) ("storeAufsDirCheckObj: load=%d\n", loadav); return loadav; } @@ -1382,7 +1381,7 @@ void storeAufsDirRefObj(SwapDir * SD, StoreEntry * e) { - debug(1, 3) ("storeAufsDirRefObj: referencing %p %d/%d\n", e, e->swap_dirn, + debug(47, 3) ("storeAufsDirRefObj: referencing %p %d/%d\n", e, e->swap_dirn, e->swap_filen); if (SD->repl->Referenced) SD->repl->Referenced(SD->repl, e, &e->repl); @@ -1396,7 +1395,7 @@ void storeAufsDirUnrefObj(SwapDir * SD, StoreEntry * e) { - debug(1, 3) ("storeAufsDirUnrefObj: referencing %p %d/%d\n", e, e->swap_dirn, + debug(47, 3) ("storeAufsDirUnrefObj: referencing %p %d/%d\n", e, e->swap_dirn, e->swap_filen); if (SD->repl->Dereferenced) SD->repl->Dereferenced(SD->repl, e, &e->repl); @@ -1429,7 +1428,7 @@ void storeAufsDirReplAdd(SwapDir * SD, StoreEntry * e) { - debug(20, 4) ("storeAufsDirReplAdd: added node %p to dir %d\n", e, + debug(47, 4) ("storeAufsDirReplAdd: added node %p to dir %d\n", e, SD->index); SD->repl->Add(SD->repl, e, &e->repl); } @@ -1439,7 +1438,7 @@ storeAufsDirReplRemove(StoreEntry * e) { SwapDir *SD = INDEXSD(e->swap_dirn); - debug(20, 4) ("storeAufsDirReplRemove: remove node %p from dir %d\n", e, + debug(47, 4) ("storeAufsDirReplRemove: remove node %p from dir %d\n", e, SD->index); SD->repl->Remove(SD->repl, e, &e->repl); } @@ -1488,8 +1487,8 @@ static struct cache_dir_option options[] = { #if NOT_YET_DONE - {"L1", storeAufsDirParseL1}, - {"L2", storeAufsDirParseL2}, + {"L1", storeAufsDirParseL1, storeAufsDirDumpL1}, + {"L2", storeAufsDirParseL2, storeAufsDirDumpL2}, #endif {NULL, NULL} }; @@ -1587,27 +1586,25 @@ static int storeAufsCleanupDoubleCheck(SwapDir * sd, StoreEntry * e) { -#ifndef _SQUID_MSWIN_ struct stat sb; if (stat(storeAufsDirFullPath(sd, e->swap_filen, NULL), &sb) < 0) { - debug(20, 0) ("storeAufsCleanupDoubleCheck: MISSING SWAP FILE\n"); - debug(20, 0) ("storeAufsCleanupDoubleCheck: FILENO %08X\n", e->swap_filen); - debug(20, 0) ("storeAufsCleanupDoubleCheck: PATH %s\n", + debug(47, 0) ("storeAufsCleanupDoubleCheck: MISSING SWAP FILE\n"); + debug(47, 0) ("storeAufsCleanupDoubleCheck: FILENO %08X\n", e->swap_filen); + debug(47, 0) ("storeAufsCleanupDoubleCheck: PATH %s\n", storeAufsDirFullPath(sd, e->swap_filen, NULL)); storeEntryDump(e, 0); return -1; } if (e->swap_file_sz != sb.st_size) { - debug(20, 0) ("storeAufsCleanupDoubleCheck: SIZE MISMATCH\n"); - debug(20, 0) ("storeAufsCleanupDoubleCheck: FILENO %08X\n", e->swap_filen); - debug(20, 0) ("storeAufsCleanupDoubleCheck: PATH %s\n", + debug(47, 0) ("storeAufsCleanupDoubleCheck: SIZE MISMATCH\n"); + debug(47, 0) ("storeAufsCleanupDoubleCheck: FILENO %08X\n", e->swap_filen); + debug(47, 0) ("storeAufsCleanupDoubleCheck: PATH %s\n", storeAufsDirFullPath(sd, e->swap_filen, NULL)); - debug(20, 0) ("storeAufsCleanupDoubleCheck: ENTRY SIZE: %ld, FILE SIZE: %ld\n", + debug(47, 0) ("storeAufsCleanupDoubleCheck: ENTRY SIZE: %ld, FILE SIZE: %ld\n", (long int) e->swap_file_sz, (long int) sb.st_size); storeEntryDump(e, 0); return -1; } -#endif return 0; } @@ -1688,9 +1685,9 @@ storeAufsDirDone(void) { aioDone(); - memPoolDestroy(squidaio_state_pool); - memPoolDestroy(aufs_qread_pool); - memPoolDestroy(aufs_qwrite_pool); + memPoolDestroy(&squidaio_state_pool); + memPoolDestroy(&aufs_qread_pool); + memPoolDestroy(&aufs_qwrite_pool); asyncufs_initialised = 0; } @@ -1701,10 +1698,10 @@ storefs->parsefunc = storeAufsDirParse; storefs->reconfigurefunc = storeAufsDirReconfigure; storefs->donefunc = storeAufsDirDone; - squidaio_state_pool = memPoolCreate("AUFS IO State data", sizeof(squidaiostate_t)); - aufs_qread_pool = memPoolCreate("AUFS Queued read data", + squidaio_state_pool = memPoolCreate("AWIN32 IO State data", sizeof(squidaiostate_t)); + aufs_qread_pool = memPoolCreate("AWIN32 Queued read data", sizeof(queued_read)); - aufs_qwrite_pool = memPoolCreate("AUFS Queued write data", + aufs_qwrite_pool = memPoolCreate("AWIN32 Queued write data", sizeof(queued_write)); asyncufs_initialised = 1; Index: squid/src/fs/awin32/store_io_aufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/store_io_aufs.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/src/fs/awin32/store_io_aufs.c 16 Mar 2002 10:36:42 -0000 1.1.2.2 +++ squid/src/fs/awin32/store_io_aufs.c 11 Aug 2002 16:45:10 -0000 1.1.2.3 @@ -1,6 +1,36 @@ /* - * DEBUG 78 + * $Id: store_io_aufs.c,v 1.1.2.3 2002/08/11 16:45:10 serassio Exp $ + * + * DEBUG: section 79 Storage Manager awin32 Interface + * AUTHOR: Robert Collins + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * */ #include "squid.h" @@ -37,7 +67,7 @@ #if !ASYNC_OPEN int fd; #endif - debug(78, 3) ("storeAufsOpen: fileno %08X\n", f); + debug(79, 3) ("storeAufsOpen: fileno %08X\n", f); /* * we should detect some 'too many files open' condition and return * NULL here. @@ -49,7 +79,7 @@ #if !ASYNC_OPEN fd = file_open(path, O_RDONLY | O_BINARY); if (fd < 0) { - debug(78, 3) ("storeAufsOpen: got failude (%d)\n", errno); + debug(79, 3) ("storeAufsOpen: got failure (%d)\n", errno); return NULL; } #endif @@ -60,11 +90,10 @@ ((squidaiostate_t *) (sio->fsstate))->flags.opening = 1; sio->swap_filen = f; sio->swap_dirn = SD->index; - sio->mode = O_RDONLY; + sio->mode = O_RDONLY | O_BINARY; sio->callback = callback; - sio->callback_data = callback_data; + sio->callback_data = cbdataReference(callback_data); sio->e = e; - cbdataLock(callback_data); Opening_FD++; #if ASYNC_OPEN aioOpen(path, O_RDONLY | O_BINARY, 0644, storeAufsOpenDone, sio); @@ -91,7 +120,7 @@ filn = storeAufsDirMapBitAllocate(SD); path = storeAufsDirFullPath(SD, filn, NULL); - debug(78, 3) ("storeAufsCreate: fileno %08X\n", filn); + debug(79, 3) ("storeAufsCreate: fileno %08X\n", filn); /* * we should detect some 'too many files open' condition and return * NULL here. @@ -103,7 +132,7 @@ #if !ASYNC_CREATE fd = file_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); if (fd < 0) { - debug(78, 3) ("storeAufsCreate: got failude (%d)\n", errno); + debug(79, 3) ("storeAufsCreate: got failure (%d)\n", errno); return NULL; } #endif @@ -116,9 +145,8 @@ sio->swap_dirn = dirn; sio->mode = O_WRONLY | O_BINARY; sio->callback = callback; - sio->callback_data = callback_data; + sio->callback_data = cbdataReference(callback_data); sio->e = (StoreEntry *) e; - cbdataLock(callback_data); Opening_FD++; #if ASYNC_CREATE aioOpen(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644, storeAufsOpenDone, sio); @@ -139,7 +167,7 @@ storeAufsClose(SwapDir * SD, storeIOState * sio) { squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; - debug(78, 3) ("storeAufsClose: dirno %d, fileno %08X, FD %d\n", + debug(79, 3) ("storeAufsClose: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, aiostate->fd); if (storeAufsSomethingPending(sio)) { aiostate->flags.close_request = 1; @@ -159,7 +187,7 @@ assert(!aiostate->flags.reading); if (aiostate->fd < 0) { struct _queued_read *q; - debug(78, 3) ("storeAufsRead: queueing read because FD < 0\n"); + debug(79, 3) ("storeAufsRead: queueing read because FD < 0\n"); assert(aiostate->flags.opening); assert(aiostate->pending_reads == NULL); q = memPoolAlloc(aufs_qread_pool); @@ -172,17 +200,16 @@ return; } sio->read.callback = callback; - sio->read.callback_data = callback_data; + sio->read.callback_data = cbdataReference(callback_data); aiostate->read_buf = buf; - cbdataLock(callback_data); - debug(78, 3) ("storeAufsRead: dirno %d, fileno %08X, FD %d\n", + debug(79, 3) ("storeAufsRead: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, aiostate->fd); sio->offset = offset; aiostate->flags.reading = 1; #if ASYNC_READ aioRead(aiostate->fd, offset, buf, size, storeAufsReadDone, sio); #else - file_read(aiostate->fd, offset, buf, size, storeAufsReadDone, sio); + file_read(aiostate->fd, buf, size, offset, storeAufsReadDone, sio); #endif } @@ -192,7 +219,7 @@ storeAufsWrite(SwapDir * SD, storeIOState * sio, char *buf, size_t size, off_t offset, FREE * free_func) { squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; - debug(78, 3) ("storeAufsWrite: dirno %d, fileno %08X, FD %d\n", + debug(79, 3) ("storeAufsWrite: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, aiostate->fd); if (aiostate->fd < 0) { /* disk file not opened yet */ @@ -209,7 +236,7 @@ #if ASYNC_WRITE if (aiostate->flags.writing) { struct _queued_write *q; - debug(78, 3) ("storeAufsWrite: queuing write\n"); + debug(79, 3) ("storeAufsWrite: queuing write\n"); q = memPoolAlloc(aufs_qwrite_pool); q->buf = buf; q->size = size; @@ -231,7 +258,7 @@ void storeAufsUnlink(SwapDir * SD, StoreEntry * e) { - debug(78, 3) ("storeAufsUnlink: dirno %d, fileno %08X\n", SD->index, e->swap_filen); + debug(79, 3) ("storeAufsUnlink: dirno %d, fileno %08X\n", SD->index, e->swap_filen); storeAufsDirReplRemove(e); storeAufsDirMapBitReset(SD, e->swap_filen); storeAufsDirUnlinkFile(SD, e->swap_filen); @@ -246,7 +273,7 @@ struct _queued_write *q = linklistShift(&aiostate->pending_writes); if (NULL == q) return 0; - debug(78, 3) ("storeAufsKickWriteQueue: writing queued chunk of %ld bytes\n", + debug(79, 3) ("storeAufsKickWriteQueue: writing queued chunk of %ld bytes\n", (long int) q->size); storeAufsWrite(INDEXSD(sio->swap_dirn), sio, q->buf, q->size, q->offset, q->free_func); memPoolFree(aufs_qwrite_pool, q); @@ -260,7 +287,7 @@ struct _queued_read *q = linklistShift(&(aiostate->pending_reads)); if (NULL == q) return 0; - debug(78, 3) ("storeAufsKickReadQueue: reading queued request of %ld bytes\n", + debug(79, 3) ("storeAufsKickReadQueue: reading queued request of %ld bytes\n", (long int) q->size); storeAufsRead(INDEXSD(sio->swap_dirn), sio, q->buf, q->size, q->offset, q->callback, q->callback_data); memPoolFree(aufs_qread_pool, q); @@ -272,13 +299,13 @@ { storeIOState *sio = my_data; squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; - debug(78, 3) ("storeAufsOpenDone: FD %d, errflag %d\n", fd, errflag); + debug(79, 3) ("storeAufsOpenDone: FD %d, errflag %d\n", fd, errflag); Opening_FD--; aiostate->flags.opening = 0; if (errflag || fd < 0) { errno = errflag; - debug(78, 0) ("storeAufsOpenDone: %s\n", xstrerror()); - debug(78, 1) ("\t%s\n", storeAufsDirFullPath(INDEXSD(sio->swap_dirn), sio->swap_filen, NULL)); + debug(79, 0) ("storeAufsOpenDone: %s\n", xstrerror()); + debug(79, 1) ("\t%s\n", storeAufsDirFullPath(INDEXSD(sio->swap_dirn), sio->swap_filen, NULL)); storeAufsIOCallback(sio, DISK_ERROR); return; } @@ -286,13 +313,13 @@ aiostate->fd = fd; commSetCloseOnExec(fd); fd_open(fd, FD_FILE, storeAufsDirFullPath(INDEXSD(sio->swap_dirn), sio->swap_filen, NULL)); - if (sio->mode == O_WRONLY) + if (FILE_MODE(sio->mode) == O_WRONLY) storeAufsKickWriteQueue(sio); - else if (sio->mode == O_RDONLY) + else if (FILE_MODE(sio->mode) == O_RDONLY) storeAufsKickReadQueue(sio); if (aiostate->flags.close_request) storeAufsIOCallback(sio, errflag); - debug(78, 3) ("storeAufsOpenDone: exiting\n"); + debug(79, 3) ("storeAufsOpenDone: exiting\n"); } #if ASYNC_READ @@ -300,20 +327,20 @@ storeAufsReadDone(int fd, void *my_data, int len, int errflag) #else static void -storeAufsReadDone(int fd, int errflag, size_t len, void *my_data) +storeAufsReadDone(int fd, const char *buf, int len, int errflag, void *my_data) #endif { storeIOState *sio = my_data; squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; STRCB *callback = sio->read.callback; - void *their_data = sio->read.callback_data; + void *cbdata; ssize_t rlen; - debug(78, 3) ("storeAufsReadDone: dirno %d, fileno %08X, FD %d, len %d\n", + debug(79, 3) ("storeAufsReadDone: dirno %d, fileno %08X, FD %d, len %d\n", sio->swap_dirn, sio->swap_filen, fd, len); aiostate->flags.inreaddone = 1; aiostate->flags.reading = 0; if (errflag) { - debug(78, 3) ("storeAufsReadDone: got failure (%d)\n", errflag); + debug(79, 3) ("storeAufsReadDone: got failure (%d)\n", errflag); rlen = -1; } else { rlen = (ssize_t) len; @@ -331,12 +358,9 @@ errflag = DISK_OK; /* EOF is signalled by len == 0, not errors... */ #endif assert(callback); - assert(their_data); sio->read.callback = NULL; - sio->read.callback_data = NULL; - if (cbdataValid(their_data)) - callback(their_data, aiostate->read_buf, rlen); - cbdataUnlock(their_data); + if (cbdataReferenceValidDone(sio->read.callback_data, &cbdata)) + callback(cbdata, aiostate->read_buf, rlen); aiostate->flags.inreaddone = 0; if (aiostate->flags.close_request) storeAufsIOCallback(sio, errflag); @@ -353,20 +377,20 @@ static int loop_detect = 0; storeIOState *sio = my_data; squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; - debug(78, 3) ("storeAufsWriteDone: dirno %d, fileno %08X, FD %d, len %ld, err=%d\n", + debug(79, 3) ("storeAufsWriteDone: dirno %d, fileno %08X, FD %d, len %ld, err=%d\n", sio->swap_dirn, sio->swap_filen, fd, (long int) len, errflag); #if ASYNC_WRITE /* Translate from errno to Squid disk error */ errno = errflag; if (errflag) - errflag = errno == ENOSP ? DISK_NO_SPACE_LEFT : DISK_ERROR; + errflag = errno == ENOSPC ? DISK_NO_SPACE_LEFT : DISK_ERROR; else errflag = DISK_OK; #endif assert(++loop_detect < 10); aiostate->flags.writing = 0; if (errflag) { - debug(78, 0) ("storeAufsWriteDone: got failure (%d)\n", errflag); + debug(79, 0) ("storeAufsWriteDone: got failure (%d)\n", errflag); storeAufsIOCallback(sio, errflag); loop_detect--; return; @@ -394,27 +418,26 @@ storeAufsIOCallback(storeIOState * sio, int errflag) { STIOCB *callback = sio->callback; - void *their_data = sio->callback_data; squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; int fd = aiostate->fd; - debug(78, 3) ("storeAufsIOCallback: errflag=%d\n", errflag); - sio->callback = NULL; - sio->callback_data = NULL; - debug(78, 3) ("%s:%d\n", __FILE__, __LINE__); - if (callback) - if (NULL == their_data || cbdataValid(their_data)) - callback(their_data, errflag, sio); - debug(78, 3) ("%s:%d\n", __FILE__, __LINE__); - cbdataUnlock(their_data); + debug(79, 3) ("storeAufsIOCallback: errflag=%d\n", errflag); + debug(79, 3) ("%s:%d\n", __FILE__, __LINE__); + if (callback) { + void *cbdata; + sio->callback = NULL; + if (cbdataReferenceValidDone(sio->callback_data, &cbdata)) + callback(cbdata, errflag, sio); + } + debug(79, 3) ("%s:%d\n", __FILE__, __LINE__); aiostate->fd = -1; cbdataFree(sio); if (fd < 0) return; - debug(78, 3) ("%s:%d\n", __FILE__, __LINE__); + debug(79, 3) ("%s:%d\n", __FILE__, __LINE__); aioClose(fd); fd_close(fd); store_open_disk_fd--; - debug(78, 3) ("%s:%d\n", __FILE__, __LINE__); + debug(79, 3) ("%s:%d\n", __FILE__, __LINE__); } Index: squid/src/fs/ufs/store_dir_ufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/ufs/store_dir_ufs.c,v retrieving revision 1.5.10.18 retrieving revision 1.5.10.19 diff -u -r1.5.10.18 -r1.5.10.19 --- squid/src/fs/ufs/store_dir_ufs.c 10 Aug 2002 08:54:11 -0000 1.5.10.18 +++ squid/src/fs/ufs/store_dir_ufs.c 11 Aug 2002 16:45:10 -0000 1.5.10.19 @@ -466,9 +466,9 @@ tmpe.hash.key = key; /* check sizes */ if (tmpe.swap_file_sz == 0) { - tmpe.swap_file_sz = sb.st_size; + tmpe.swap_file_sz = (size_t) sb.st_size; } else if (tmpe.swap_file_sz == sb.st_size - swap_hdr_len) { - tmpe.swap_file_sz = sb.st_size; + tmpe.swap_file_sz = (size_t) sb.st_size; } else if (tmpe.swap_file_sz != sb.st_size) { debug(47, 1) ("storeUfsDirRebuildFromDirectory: SIZE MISMATCH %ld!=%ld\n", (long int) tmpe.swap_file_sz, (long int) sb.st_size); @@ -1060,7 +1060,7 @@ fd = state->fd; /* rename */ if (state->fd >= 0) { -#if defined(_SQUID_OS2_) || defined (_SQUID_CYGWIN_) || defined (_SQUID_MSWIN_) +#if defined(_SQUID_OS2_) || defined(_SQUID_CYGWIN_) || defined(_SQUID_MSWIN_) file_close(state->fd); state->fd = -1; if (unlink(state->cur) < 0) Index: squid/src/fs/ufs/store_io_ufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/ufs/store_io_ufs.c,v retrieving revision 1.2.24.6 retrieving revision 1.2.24.7 diff -u -r1.2.24.6 -r1.2.24.7 --- squid/src/fs/ufs/store_io_ufs.c 10 Aug 2002 08:54:11 -0000 1.2.24.6 +++ squid/src/fs/ufs/store_io_ufs.c 11 Aug 2002 16:45:10 -0000 1.2.24.7 @@ -77,7 +77,7 @@ ((ufsstate_t *) (sio->fsstate))->flags.reading = 0; ((ufsstate_t *) (sio->fsstate))->flags.close_request = 0; if (fstat(fd, &sb) == 0) - sio->st_size = sb.st_size; + sio->st_size = (size_t) sb.st_size; store_open_disk_fd++; /* We should update the heap/dlink position here ! */