--------------------- PatchSet 8635 Date: 2006/09/13 07:07:23 Author: serassio Branch: nt Tag: (none) Log: Preliminary coss support on Windows Members: configure.in:1.87.2.52->1.87.2.53 src/fs/Makefile.am:1.3.30.9->1.3.30.10 src/fs/coss/aio_win32.c:1.1->1.1.2.1 src/fs/coss/aio_win32.h:1.1->1.1.2.1 src/fs/coss/async_io.c:1.7.8.1->1.7.8.2 src/fs/coss/store_dir_coss.c:1.26.8.12->1.26.8.13 src/fs/coss/store_io_coss.c:1.15.8.10->1.15.8.11 Index: squid/configure.in =================================================================== RCS file: /cvsroot/squid-sf//squid/configure.in,v retrieving revision 1.87.2.52 retrieving revision 1.87.2.53 diff -u -r1.87.2.52 -r1.87.2.53 --- squid/configure.in 9 Sep 2006 12:30:38 -0000 1.87.2.52 +++ squid/configure.in 13 Sep 2006 07:07:23 -0000 1.87.2.53 @@ -1,7 +1,7 @@ dnl dnl Configuration input file for Squid dnl -dnl $Id: configure.in,v 1.87.2.52 2006/09/09 12:30:38 serassio Exp $ +dnl $Id: configure.in,v 1.87.2.53 2006/09/13 07:07:23 serassio Exp $ dnl dnl dnl @@ -10,7 +10,7 @@ AM_CONFIG_HEADER(include/autoconf.h) AC_CONFIG_AUX_DIR(cfgaux) AM_INIT_AUTOMAKE -AC_REVISION($Revision: 1.87.2.52 $)dnl +AC_REVISION($Revision: 1.87.2.53 $)dnl AC_PREFIX_DEFAULT(/usr/local/squid) AM_MAINTAINER_MODE @@ -438,8 +438,17 @@ ;; coss) if test -z "$with_aio"; then + case "$host_os" in + mingw|mingw32|cygwin|cygwin32) + AM_CONDITIONAL(USE_AIO_WIN32, true) + echo "coss store used, Windows overlapped I/O support automatically enabled" + ;; + *) + AM_CONDITIONAL(USE_AIO_WIN32, false) echo "coss store used, aio support automatically enabled" - with_aio=yes + with_aio=yes + ;; + esac fi ;; esac Index: squid/src/fs/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/Makefile.am,v retrieving revision 1.3.30.9 retrieving revision 1.3.30.10 diff -u -r1.3.30.9 -r1.3.30.10 --- squid/src/fs/Makefile.am 9 Sep 2006 12:30:41 -0000 1.3.30.9 +++ squid/src/fs/Makefile.am 13 Sep 2006 07:07:24 -0000 1.3.30.10 @@ -11,14 +11,26 @@ AIOPS_SOURCE = aufs/aiops.c endif +AIO_WIN32_ALL_SOURCES = \ + DiskIO/AIO/aio_win32.c \ + DiskIO/AIO/aio_win32.h +if USE_AIO_WIN32 +AIO_WIN32_SOURCES = $(AIO_WIN32_ALL_SOURCES) +else +AIO_WIN32_SOURCES = +endif + EXTRA_LIBRARIES = libaufs.a libcoss.a libdiskd.a libnull.a libufs.a noinst_LIBRARIES = @STORE_LIBS@ EXTRA_libaufs_a_SOURCES = aufs/aiops.c aufs/aiops_win32.c +EXTRA_libcoss_a_SOURCES = $(AIO_WIN32_ALL_SOURCES) + libaufs_a_SOURCES = $(AIOPS_SOURCE) aufs/async_io.c aufs/store_asyncufs.h \ aufs/store_dir_aufs.c aufs/store_io_aufs.c aufs/async_io.h libcoss_a_SOURCES = coss/store_coss.h coss/store_io_coss.c coss/store_dir_coss.c \ + $(AIO_WIN32_SOURCES) \ coss/async_io.c coss/async_io.h libdiskd_a_SOURCES = diskd/diskd.c diskd/store_dir_diskd.c diskd/store_diskd.h \ diskd/store_io_diskd.c --- /dev/null Wed Feb 14 01:16:58 2007 +++ squid/src/fs/coss/aio_win32.c Wed Feb 14 01:17:07 2007 @@ -0,0 +1,197 @@ + +/* + * $Id: aio_win32.c,v 1.1.2.1 2006/09/13 07:07:24 serassio Exp $ + * + * DEBUG: section 81 aio_xxx() POSIX emulation on Windows + * AUTHOR: Guido Serassio + * + * 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 "util.h" +#include +#include +#include "aio_win32.h" + +#ifdef _SQUID_WIN32_ +VOID CALLBACK IoCompletionRoutine(DWORD dwErrorCode, + DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) +{ + struct aiocb *aiocbp = (struct aiocb *) lpOverlapped->hEvent; + + aiocbp->aio_sigevent.sigev_notify = dwErrorCode; + aiocbp->aio_sigevent.sigev_signo = dwNumberOfBytesTransfered; + debug(81,7) ("AIO operation complete: errorcode=%ld nbytes=%ld\n", dwErrorCode, dwNumberOfBytesTransfered); + xfree(lpOverlapped); +} + + +int aio_read(struct aiocb *aiocbp) +{ + LPOVERLAPPED Overlapped; + BOOL IoOperationStatus; + + /* Allocate an overlapped structure. */ + Overlapped = xcalloc(1, sizeof(OVERLAPPED)); + if (!Overlapped) { + errno = ENOMEM; + return -1; + } + +#if __USE_FILE_OFFSET64 + Overlapped->Offset = (DWORD) (aiocbp->aio_offset % 0x100000000); + Overlapped->OffsetHigh = (DWORD) (aiocbp->aio_offset / 0x100000000); +#else + Overlapped->Offset = aiocbp->aio_offset; + Overlapped->OffsetHigh = 0; +#endif + Overlapped->hEvent = aiocbp; + aiocbp->aio_sigevent.sigev_notify = EINPROGRESS; + aiocbp->aio_sigevent.sigev_signo = -1; + + IoOperationStatus = ReadFileEx((HANDLE)_get_osfhandle(aiocbp->aio_fildes), + aiocbp->aio_buf, + aiocbp->aio_nbytes, + Overlapped, + IoCompletionRoutine); + + /* Test to see if the I/O was queued successfully. */ + if (!IoOperationStatus) { + errno = GetLastError(); + return -1; + } + + /* The I/O queued successfully. Go back into the + alertable wait for I/O completion or for + more I/O requests. */ + return 0; +} + + +int aio_write(struct aiocb *aiocbp) + +{ + LPOVERLAPPED Overlapped; + BOOL IoOperationStatus; + + /* Allocate an overlapped structure. */ + Overlapped = xcalloc(1, sizeof(OVERLAPPED)); + if (!Overlapped) { + errno = ENOMEM; + return -1; + } +#if __USE_FILE_OFFSET64 + Overlapped->Offset = (DWORD) (aiocbp->aio_offset % 0x100000000); + Overlapped->OffsetHigh = (DWORD) (aiocbp->aio_offset / 0x100000000); +#else + Overlapped->Offset = aiocbp->aio_offset; + Overlapped->OffsetHigh = 0; +#endif + Overlapped->hEvent = aiocbp; + aiocbp->aio_sigevent.sigev_notify = EINPROGRESS; + aiocbp->aio_sigevent.sigev_signo = -1; + + IoOperationStatus = WriteFileEx((HANDLE)_get_osfhandle(aiocbp->aio_fildes), + aiocbp->aio_buf, + aiocbp->aio_nbytes, + Overlapped, + IoCompletionRoutine); + + /* Test to see if the I/O was queued successfully. */ + if (!IoOperationStatus) { + errno = GetLastError(); + return -1; + } + + /* The I/O queued successfully. Go back into the + alertable wait for I/O completion or for + more I/O requests. */ + return 0; +} + + +ssize_t aio_return(struct aiocb * aiocbp) + +{ + return aiocbp->aio_sigevent.sigev_signo; +} + + +int aio_error(const struct aiocb * aiocbp) + +{ + return aiocbp->aio_sigevent.sigev_notify; +} + + +int aio_open(const char *path, int mode, int mask) +{ + HANDLE hndl; + DWORD dwCreationDisposition; + DWORD dwDesiredAccess; + int fd; + + errno = 0; + if (FILE_MODE(mode) == O_WRONLY) + dwDesiredAccess = GENERIC_WRITE; + else + dwDesiredAccess = (FILE_MODE(mode) == O_RDONLY) ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE; + if (FILE_MODE(mode) == O_TRUNC) + dwCreationDisposition = CREATE_ALWAYS; + else + dwCreationDisposition = (FILE_MODE(mode) == O_CREAT) ? OPEN_ALWAYS : OPEN_EXISTING; + + if ((hndl = CreateFile(path, /* file name */ + dwDesiredAccess, /* access mode */ + 0, /* share mode */ + NULL, /* SD */ + dwCreationDisposition, /* how to create */ + FILE_FLAG_OVERLAPPED, /* file attributes */ + NULL /* handle to template file */ + )) != INVALID_HANDLE_VALUE) { + fd = _open_osfhandle((long) hndl, 0); + debug(81, 5) ("aio_open: FD %d\n", fd); + commSetCloseOnExec(fd); + fd_open(fd, FD_FILE, path); + } else { + errno = GetLastError(); + fd = DISK_ERROR; + debug(81, 3) ("aio_open: error opening file %s: %s\n", path, + xstrerror()); + } + statCounter.syscalls.disk.opens++; + return fd; +} + +void aio_close(int fd) +{ + CloseHandle((HANDLE)_get_osfhandle(fd)); + fd_close(fd); + statCounter.syscalls.disk.closes++; +} +#endif /* SQUID_WIN32_ */ --- /dev/null Wed Feb 14 01:16:58 2007 +++ squid/src/fs/coss/aio_win32.h Wed Feb 14 01:17:07 2007 @@ -0,0 +1,70 @@ +/* + * $Id: aio_win32.h,v 1.1.2.1 2006/09/13 07:07:24 serassio Exp $ + * + * aio_xxx() POSIX emulation on WIN32 for COSS + * AUTHOR: Guido Serassio + * + * 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. + * + */ + +#ifdef _SQUID_CYGWIN_ +#include +#endif + +union sigval { + int sival_int; /* integer value */ + void *sival_ptr; /* pointer value */ +}; + +struct sigevent { + int sigev_notify; /* notification mode */ + int sigev_signo; /* signal number */ + union sigval sigev_value; /* signal value */ +}; + +struct aiocb { + int aio_fildes; /* file descriptor */ + void *aio_buf; /* buffer location */ + size_t aio_nbytes; /* length of transfer */ +#if __USE_FILE_OFFSET64 + off64_t aio_offset; /* file offset */ +#else + off_t aio_offset; /* file offset */ + char __pad[sizeof (int64_t) - sizeof (off_t)]; +#endif + int aio_reqprio; /* request priority offset */ + struct sigevent aio_sigevent; /* signal number and offset */ + int aio_lio_opcode; /* listio operation */ +}; + +int aio_read(struct aiocb *); +int aio_write(struct aiocb *); +ssize_t aio_return(struct aiocb *); +int aio_error(const struct aiocb *); +int aio_open(const char *, int, int); +void aio_close(int); Index: squid/src/fs/coss/async_io.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/coss/async_io.c,v retrieving revision 1.7.8.1 retrieving revision 1.7.8.2 diff -u -r1.7.8.1 -r1.7.8.2 --- squid/src/fs/coss/async_io.c 21 May 2006 07:17:23 -0000 1.7.8.1 +++ squid/src/fs/coss/async_io.c 13 Sep 2006 07:07:24 -0000 1.7.8.2 @@ -16,7 +16,11 @@ #include "squid.h" #include +#ifdef _SQUID_WIN32_ +#include "aio_win32.h" +#else #include +#endif #include "async_io.h" Index: squid/src/fs/coss/store_dir_coss.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/coss/store_dir_coss.c,v retrieving revision 1.26.8.12 retrieving revision 1.26.8.13 diff -u -r1.26.8.12 -r1.26.8.13 --- squid/src/fs/coss/store_dir_coss.c 4 Sep 2006 17:16:49 -0000 1.26.8.12 +++ squid/src/fs/coss/store_dir_coss.c 13 Sep 2006 07:07:24 -0000 1.26.8.13 @@ -196,7 +196,11 @@ #else a_file_setupqueue(&cs->aq); #endif +#ifdef _SQUID_WIN32_ + cs->fd = aio_open(sd->path, O_RDWR | O_CREAT | O_BINARY); +#else cs->fd = file_open(sd->path, O_RDWR | O_CREAT | O_BINARY); +#endif if (cs->fd < 0) { debug(79, 1) ("%s: %s\n", sd->path, xstrerror()); fatal("storeCossDirInit: Failed to open a COSS file."); @@ -487,7 +491,7 @@ storeCossDirCloseSwapLog(sd); /* rename */ if (state->fd >= 0) { -#ifdef _SQUID_OS2_ +#if defined(_SQUID_OS2_) || defined(SQUID_WIN32_) file_close(state->fd); state->fd = -1; #endif @@ -562,7 +566,11 @@ #if !USE_AUFSOPS a_file_closequeue(&cs->aq); #endif +#ifdef _SQUID_WIN32_ + aio_close(cs->fd); +#else file_close(cs->fd); +#endif cs->fd = -1; if (cs->swaplog_fd > -1) { Index: squid/src/fs/coss/store_io_coss.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/coss/store_io_coss.c,v retrieving revision 1.15.8.10 retrieving revision 1.15.8.11 diff -u -r1.15.8.10 -r1.15.8.11 --- squid/src/fs/coss/store_io_coss.c 4 Sep 2006 17:16:49 -0000 1.15.8.10 +++ squid/src/fs/coss/store_io_coss.c 13 Sep 2006 07:07:24 -0000 1.15.8.11 @@ -34,7 +34,11 @@ */ #include "squid.h" +#ifdef _SQUID_WIN32_ +#include "aio_win32.h" +#else #include +#endif #include "async_io.h" #include "store_coss.h" #if USE_AUFSOPS @@ -694,8 +698,8 @@ debug(79, 1) ("WARNING: sleeping for 5 seconds in storeCossSync()\n"); sleep(5); /* XXX EEEWWW! */ } - lseek(cs->fd, t->diskstart, SEEK_SET); end = (t == cs->current_membuf) ? cs->current_offset : t->diskend; + lseek(cs->fd, t->diskstart, SEEK_SET); FD_WRITE_METHOD(cs->fd, t->buffer, end - t->diskstart); } }