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

📄 store_io_diskd.c

📁 功能强大的代理服务器
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (diskdinfo->away >= diskdinfo->magic1) {	/* Damn, we need to issue a sync unlink here :( */	debug(79, 2) ("storeDiskUnlink: Out of queue space, sync unlink\n");	storeDiskdDirUnlinkFile(SD, e->swap_filen);	return;    }    /* We can attempt a diskd unlink */    buf = storeDiskdShmGet(SD, &shm_offset);    xstrncpy(buf, storeDiskdDirFullPath(SD, e->swap_filen, NULL), SHMBUF_BLKSZ);    x = storeDiskdSend(_MQD_UNLINK,	SD,	e->swap_filen,	NULL,	0,	0,	shm_offset);    if (x < 0) {	debug(79, 1) ("storeDiskdSend UNLINK: %s\n", xstrerror());	unlink(buf);		/* XXX EWW! */	storeDiskdShmPut(SD, shm_offset);    }    diskd_stats.unlink.ops++;}voidstoreDiskdRecycle(SwapDir * SD, StoreEntry * e){    debug(79, 3) ("storeDiskdUnlink: fileno %08X\n", e->swap_filen);    /* Detach from the underlying physical object */    if (e->swap_filen > -1) {	storeDiskdDirReplRemove(e);	storeDiskdDirMapBitReset(SD, e->swap_filen);	e->swap_filen = -1;	e->swap_dirn = -1;    }}/*  === STATIC =========================================================== */static voidstoreDiskdOpenDone(diomsg * M){    storeIOState *sio = M->callback_data;    statCounter.syscalls.disk.opens++;    debug(79, 3) ("storeDiskdOpenDone: dirno %d, fileno %08x status %d\n",	sio->swap_dirn, sio->swap_filen, M->status);    if (M->status < 0) {	FILE_MODE(sio->mode) == O_RDONLY ? diskd_stats.open.fail++ : diskd_stats.create.fail++;	storeDiskdIOCallback(sio, DISK_ERROR);    } else {	FILE_MODE(sio->mode) == O_RDONLY ? diskd_stats.open.success++ : diskd_stats.create.success++;    }}static voidstoreDiskdCloseDone(diomsg * M){    storeIOState *sio = M->callback_data;    statCounter.syscalls.disk.closes++;    debug(79, 3) ("storeDiskdCloseDone: dirno %d, fileno %08x status %d\n",	sio->swap_dirn, sio->swap_filen, M->status);    if (M->status < 0) {	diskd_stats.close.fail++;	storeDiskdIOCallback(sio, DISK_ERROR);	return;    }    diskd_stats.close.success++;    storeDiskdIOCallback(sio, DISK_OK);}static voidstoreDiskdReadDone(diomsg * M){    storeIOState *sio = M->callback_data;    STRCB *callback = sio->read.callback;    SwapDir *sd = INDEXSD(sio->swap_dirn);    diskdstate_t *diskdstate = sio->fsstate;    diskdinfo_t *diskdinfo = sd->fsdata;    void *their_data = sio->read.callback_data;    char *their_buf = diskdstate->read_buf;    char *sbuf;    size_t len;    int valid;    statCounter.syscalls.disk.reads++;    diskdstate->flags.reading = 0;    if (diskdstate->flags.close_request) {	debug(79, 2) ("storeDiskReadDone: closing, so ignore!\n");	return;    }    valid = cbdataValid(sio->read.callback_data);    cbdataUnlock(sio->read.callback_data);    debug(79, 3) ("storeDiskdReadDone: dirno %d, fileno %08x status %d\n",	sio->swap_dirn, sio->swap_filen, M->status);    if (M->status < 0) {	diskd_stats.read.fail++;	storeDiskdIOCallback(sio, DISK_ERROR);	return;    }    diskd_stats.read.success++;    sbuf = diskdinfo->shm.buf + M->shm_offset;    len = M->status;    sio->offset += len;    assert(callback);    assert(their_data);    sio->read.callback = NULL;    sio->read.callback_data = NULL;    if (valid) {	assert(!diskdstate->flags.close_request);	/*	 * Only copy the data if the callback is still valid,	 * if it isn't valid then the request should have been	 * aborted.	 *   -- adrian	 */	xmemcpy(their_buf, sbuf, len);	/* yucky copy */	callback(their_data, their_buf, len);    }}static voidstoreDiskdWriteDone(diomsg * M){    storeIOState *sio = M->callback_data;    diskdstate_t *diskdstate = sio->fsstate;    statCounter.syscalls.disk.writes++;    diskdstate->flags.writing = 0;    debug(79, 3) ("storeDiskdWriteDone: dirno %d, fileno %08x status %d\n",	sio->swap_dirn, sio->swap_filen, M->status);    if (M->status < 0) {	diskd_stats.write.fail++;	if (!diskdstate->flags.close_request)	    storeDiskdIOCallback(sio, DISK_ERROR);	return;    }    diskd_stats.write.success++;    sio->offset += M->status;}static voidstoreDiskdUnlinkDone(diomsg * M){    debug(79, 3) ("storeDiskdUnlinkDone: fileno %08x status %d\n",	M->id, M->status);    statCounter.syscalls.disk.unlinks++;    if (M->status < 0)	diskd_stats.unlink.fail++;    else	diskd_stats.unlink.success++;}voidstoreDiskdHandle(diomsg * M){    int valid = M->callback_data ? cbdataValid(M->callback_data) : 1;    if (M->callback_data)	cbdataUnlock(M->callback_data);    if (!valid) {	debug(79, 3) ("storeDiskdHandle: Invalid callback_data %p\n",	    M->callback_data);	/*	 * The read operation has its own callback.  If we don't	 * call storeDiskdReadDone(), then we must make sure the	 * callback_data gets unlocked!	 */	if (_MQD_READ == M->mtype) {	    storeIOState *sio = M->callback_data;	    cbdataUnlock(sio->read.callback_data);	}	return;    }    /* set errno passed from diskd.  makes debugging more meaningful */    if (M->status < 0)	errno = -M->status;    switch (M->mtype) {    case _MQD_OPEN:	storeDiskdOpenDone(M);	break;    case _MQD_CLOSE:	storeDiskdCloseDone(M);	break;    case _MQD_READ:	storeDiskdReadDone(M);	break;    case _MQD_WRITE:	storeDiskdWriteDone(M);	break;    case _MQD_UNLINK:	storeDiskdUnlinkDone(M);	break;    default:	assert(0);	break;    }}static voidstoreDiskdIOCallback(storeIOState * sio, int errflag){    void *p = sio->callback_data;    debug(79, 3) ("storeDiskdIOCallback: errflag=%d\n", errflag);    if (cbdataValid(p))	sio->callback(p, errflag, sio);    cbdataUnlock(p);    cbdataFree(sio);}static intstoreDiskdSend(int mtype, SwapDir * sd, int id, storeIOState * sio, int size, off_t offset, int shm_offset){    int x;    diomsg M;    static int send_errors = 0;    static int last_seq_no = 0;    static int seq_no = 0;    diskdinfo_t *diskdinfo = sd->fsdata;    struct timeval delay =    {0, 1};    M.mtype = mtype;    M.callback_data = sio;    M.size = size;    M.offset = offset;    M.status = -1;    M.shm_offset = (int) shm_offset;    M.id = id;    M.seq_no = ++seq_no;    if (M.callback_data)	cbdataLock(M.callback_data);    if (M.seq_no < last_seq_no)	debug(79, 1) ("WARNING: sequencing out of order\n");    /*     * We have to drain the queue here if necessary.  If we don't,     * then we can have a lot of messages in the queue (probably     * up to 2*magic1) and we can run out of shared memory buffers.     */    /*     * NOTE that it is important that we call storeDirCallback AFTER     * locking the callback data M.callback_data because we need     * to make sure the cbdata lock count doesn't go to zero (and     * get freed) before we have a chance to send the current message     * M!     */    /*     * Note that we call storeDirCallback (for all SDs), rather     * than storeDiskdDirCallback for just this SD, so that while     * we're "blocking" on this SD we can also handle callbacks     * from other SDs that might be ready.     */    while (diskdinfo->away > diskdinfo->magic2) {	select(0, NULL, NULL, NULL, &delay);	storeDirCallback();	if (delay.tv_usec < 1000000)	    delay.tv_usec <<= 1;    }    x = msgsnd(diskdinfo->smsgid, &M, msg_snd_rcv_sz, IPC_NOWAIT);    last_seq_no = M.seq_no;    if (0 == x) {	diskd_stats.sent_count++;	diskdinfo->away++;    } else {	debug(79, 1) ("storeDiskdSend: msgsnd: %s\n", xstrerror());	if (M.callback_data)	    cbdataUnlock(M.callback_data);	assert(++send_errors < 100);    }    return x;}/* * We can't pass memFree() as a free function here, because we need to free * the fsstate variable .. */static voidstoreDiskdIOFreeEntry(void *sio){    memPoolFree(diskd_state_pool, ((storeIOState *) sio)->fsstate);}

⌨️ 快捷键说明

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