⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 store_io_diskd.c

📁 功能强大的代理服务器
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * $Id$ * * DEBUG: section 79    Squid-side DISKD I/O functions. * AUTHOR: Duane Wessels * * 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 "config.h"#include "squid.h"#include <sys/ipc.h>#include <sys/msg.h>#include <sys/shm.h>#include "store_diskd.h"static int storeDiskdSend(int, SwapDir *, int, storeIOState *, int, off_t, int);static void storeDiskdIOCallback(storeIOState * sio, int errflag);static CBDUNL storeDiskdIOFreeEntry;CBDATA_TYPE(storeIOState);/* === PUBLIC =========================================================== */storeIOState *storeDiskdOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback,    STIOCB * callback, void *callback_data){    sfileno f = e->swap_filen;    int x;    storeIOState *sio;    char *buf;    diskdstate_t *diskdstate;    int shm_offset;    diskdinfo_t *diskdinfo = SD->fsdata;    debug(79, 3) ("storeDiskdOpen: fileno %08X\n", f);    /*     * Fail on open() if there are too many requests queued.     */    if (diskdinfo->away > diskdinfo->magic1) {	debug(79, 3) ("storeDiskdOpen: FAILING, too many requests away\n");	diskd_stats.open_fail_queue_len++;	return NULL;    }    CBDATA_INIT_TYPE_FREECB(storeIOState, storeDiskdIOFreeEntry);    sio = cbdataAlloc(storeIOState);    sio->fsstate = diskdstate = memPoolAlloc(diskd_state_pool);    sio->swap_filen = f;    sio->swap_dirn = SD->index;    sio->mode = O_RDONLY | O_BINARY | O_NOATIME;    sio->callback = callback;    sio->callback_data = callback_data;    sio->e = e;    cbdataLock(callback_data);    diskdstate->flags.writing = 0;    diskdstate->flags.reading = 0;    diskdstate->flags.close_request = 0;    diskdstate->id = diskd_stats.sio_id++;    buf = storeDiskdShmGet(SD, &shm_offset);    xstrncpy(buf, storeDiskdDirFullPath(SD, f, NULL), SHMBUF_BLKSZ);    x = storeDiskdSend(_MQD_OPEN,	SD,	diskdstate->id,	sio,	strlen(buf) + 1,	O_RDONLY,	shm_offset);    if (x < 0) {	debug(79, 1) ("storeDiskdSend OPEN: %s\n", xstrerror());	storeDiskdShmPut(SD, shm_offset);	cbdataUnlock(sio->callback_data);	cbdataFree(sio);	return NULL;    }    diskd_stats.open.ops++;    return sio;}storeIOState *storeDiskdCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback,    STIOCB * callback, void *callback_data){    sfileno f;    int x;    storeIOState *sio;    char *buf;    int shm_offset;    diskdinfo_t *diskdinfo = SD->fsdata;    diskdstate_t *diskdstate;    /*     * Fail on open() if there are too many requests queued.     */    if (diskdinfo->away > diskdinfo->magic1) {	diskd_stats.open_fail_queue_len++;	return NULL;    }    /* Allocate a number */    f = storeDiskdDirMapBitAllocate(SD);    debug(79, 3) ("storeDiskdCreate: fileno %08X\n", f);    CBDATA_INIT_TYPE_FREECB(storeIOState, storeDiskdIOFreeEntry);    sio = cbdataAlloc(storeIOState);    sio->fsstate = diskdstate = memPoolAlloc(diskd_state_pool);    sio->swap_filen = f;    sio->swap_dirn = SD->index;    sio->mode = O_WRONLY | O_CREAT | O_TRUNC;    sio->callback = callback;    sio->callback_data = callback_data;    sio->e = e;    cbdataLock(callback_data);    diskdstate->flags.writing = 0;    diskdstate->flags.reading = 0;    diskdstate->flags.close_request = 0;    diskdstate->id = diskd_stats.sio_id++;    buf = storeDiskdShmGet(SD, &shm_offset);    xstrncpy(buf, storeDiskdDirFullPath(SD, f, NULL), SHMBUF_BLKSZ);    x = storeDiskdSend(_MQD_OPEN,	SD,	diskdstate->id,	sio,	strlen(buf) + 1,	sio->mode,	shm_offset);    if (x < 0) {	debug(79, 1) ("storeDiskdSend OPEN: %s\n", xstrerror());	storeDiskdShmPut(SD, shm_offset);	cbdataUnlock(sio->callback_data);	cbdataFree(sio);	return NULL;    }    storeDiskdDirReplAdd(SD, e);    diskd_stats.create.ops++;    return sio;}voidstoreDiskdClose(SwapDir * SD, storeIOState * sio){    int x;    diskdstate_t *diskdstate = sio->fsstate;    debug(79, 3) ("storeDiskdClose: dirno %d, fileno %08X\n", SD->index,	sio->swap_filen);    diskdstate->flags.close_request = 1;    x = storeDiskdSend(_MQD_CLOSE,	SD,	diskdstate->id,	sio,	0,	0,	-1);    if (x < 0) {	debug(79, 1) ("storeDiskdSend CLOSE: %s\n", xstrerror());	storeDiskdIOCallback(sio, DISK_ERROR);    }    diskd_stats.close.ops++;}voidstoreDiskdRead(SwapDir * SD, storeIOState * sio, char *buf, size_t size, squid_off_t offset, STRCB * callback, void *callback_data){    int x;    int shm_offset;    char *rbuf;    diskdstate_t *diskdstate = sio->fsstate;    debug(79, 3) ("storeDiskdRead: dirno %d, fileno %08X\n", sio->swap_dirn, sio->swap_filen);    if (diskdstate->flags.close_request) {	debug(79, 2) ("storeDiskRead: closing, so ignore!\n");	return;    }    if (!cbdataValid(sio))	return;    if (diskdstate->flags.reading) {	debug(79, 1) ("storeDiskdRead: already reading!\n");	return;    }    assert(sio->read.callback == NULL);    assert(sio->read.callback_data == NULL);    sio->read.callback = callback;    sio->read.callback_data = callback_data;    diskdstate->read_buf = buf;	/* the one passed from above */    cbdataLock(sio->read.callback_data);    sio->offset = offset;    diskdstate->flags.reading = 1;    rbuf = storeDiskdShmGet(SD, &shm_offset);    assert(rbuf);    x = storeDiskdSend(_MQD_READ,	SD,	diskdstate->id,	sio,	size,	(off_t) offset,	shm_offset);    if (x < 0) {	debug(79, 1) ("storeDiskdSend READ: %s\n", xstrerror());	storeDiskdShmPut(SD, shm_offset);	storeDiskdIOCallback(sio, DISK_ERROR);    }    diskd_stats.read.ops++;}voidstoreDiskdWrite(SwapDir * SD, storeIOState * sio, char *buf, size_t size, squid_off_t offset, FREE * free_func){    int x;    char *sbuf;    int shm_offset;    diskdstate_t *diskdstate = sio->fsstate;    debug(79, 3) ("storeDiskdWrite: dirno %d, fileno %08X\n", SD->index, sio->swap_filen);    assert(!diskdstate->flags.close_request);    if (diskdstate->flags.close_request) {	debug(79, 2) ("storeDiskWrite: closing, so ignore!\n");	free_func(buf);	return;    }    if (!cbdataValid(sio)) {	free_func(buf);	return;    }    diskdstate->flags.writing = 1;    sbuf = storeDiskdShmGet(SD, &shm_offset);    xmemcpy(sbuf, buf, size);    if (free_func)	free_func(buf);    x = storeDiskdSend(_MQD_WRITE,	SD,	diskdstate->id,	sio,	size,	(off_t) offset,	shm_offset);    if (x < 0) {	debug(79, 1) ("storeDiskdSend WRITE: %s\n", xstrerror());	storeDiskdShmPut(SD, shm_offset);	storeDiskdIOCallback(sio, DISK_ERROR);    }    diskd_stats.write.ops++;}voidstoreDiskdUnlink(SwapDir * SD, StoreEntry * e){    int x;    int shm_offset;    char *buf;    diskdinfo_t *diskdinfo = SD->fsdata;    debug(79, 3) ("storeDiskdUnlink: dirno %d, fileno %08X\n", SD->index,	e->swap_filen);    storeDiskdDirReplRemove(e);    storeDiskdDirMapBitReset(SD, e->swap_filen);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -