--------------------- PatchSet 1405 Date: 2001/01/27 10:20:44 Author: darius Branch: sfs Tag: (none) Log: code cleanups, streamlining - mostly more comments ;) Readability etc. Members: src/fs/sfs/sfs_shim.c:1.1.2.2->1.1.2.3 src/fs/sfs/sfs_util.c:1.1.2.9->1.1.2.10 Index: squid/src/fs/sfs/sfs_shim.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/sfs/Attic/sfs_shim.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/sfs/sfs_shim.c 27 Jan 2001 01:24:20 -0000 1.1.2.2 +++ squid/src/fs/sfs/sfs_shim.c 27 Jan 2001 10:20:44 -0000 1.1.2.3 @@ -44,5 +44,5 @@ xassert(const char *msg, const char *file, int line) { printf("Assertion failed: %s:%d - %s\n", file, line, msg); + abort(); } - Index: squid/src/fs/sfs/sfs_util.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/sfs/Attic/sfs_util.c,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -u -r1.1.2.9 -r1.1.2.10 --- squid/src/fs/sfs/sfs_util.c 26 Jan 2001 19:52:04 -0000 1.1.2.9 +++ squid/src/fs/sfs/sfs_util.c 27 Jan 2001 10:20:44 -0000 1.1.2.10 @@ -9,19 +9,12 @@ void _sfs_waitfor_request(sfs_requestor *req) /* You know, we could count the number of seconds a request has had to wait to - be serviced here... */ + * be serviced here... */ { - struct timespec waittime; - assert(req->io_type == _SFS_IO_SYNC); - while ((req) && (req->request_state != _SFS_DONE)) { - waittime.tv_sec = squid_curtime; - waittime.tv_sec += 1; - waittime.tv_nsec = 0; - pthread_mutex_lock(&(req->done_signal_lock)); - pthread_cond_timedwait(&(req->done_signal),&(req->done_signal_lock),&waittime); - pthread_mutex_unlock(&(req->done_signal_lock)); - } + pthread_mutex_lock(&(req->done_signal_lock)); + pthread_cond_wait(&(req->done_signal),&(req->done_signal_lock)); + pthread_mutex_unlock(&(req->done_signal_lock)); } /* @@ -32,7 +25,9 @@ int _sfs_remove_request(sfs_requestor *req) /* This doesn't free the buffer - not sure whether we have any need to keep -the buffer anywhere or not, but the option is there... */ + * the buffer anywhere or not, but the option is there... This will be changed + * by various commloops/modio changes - hopefully, we won't even be supplying + * the buffer. */ { printf("DEBUG: Removing %d request from queue\n",req->request_type); pthread_mutex_lock(&(_sfs_mounted[req->sfsid].done_lock)); @@ -56,15 +51,19 @@ req->ret = retval; req->request_state = _SFS_DONE; + /* Take it off the mount point request queue */ pthread_mutex_lock(&(_sfs_mounted[req->sfsid].req_lock)); dlinkDelete(&req->node, &(_sfs_mounted[req->sfsid].request_queue)); pthread_mutex_unlock(&(_sfs_mounted[req->sfsid].req_lock)); + /* Add it to the squid done queue */ pthread_mutex_lock(&(_sfs_mounted[req->sfsid].done_lock)); dlinkAddTail(req, &req->node, &(_sfs_mounted[req->sfsid].done_queue)); _sfs_mounted[req->sfsid].done_requests++; pthread_mutex_unlock(&(_sfs_mounted[req->sfsid].done_lock)); + /* If it's a sync operation, signal it's done - that allows sfs_interface + * to pick up and return */ if (req->io_type == _SFS_IO_SYNC) { pthread_mutex_lock(&(req->done_signal_lock)); pthread_cond_signal(&(req->done_signal)); @@ -91,30 +90,29 @@ req->buf = NULL; pthread_cond_init(&(req->done_signal), NULL); pthread_mutex_init(&(req->done_signal_lock), NULL); - /* pthread_mutex_lock(&(req->done_signal_lock)); */ return req; } int _sfs_submit_request(sfs_requestor *req) { - pthread_mutex_lock(&(_sfs_mounted[req->sfsid].req_lock)); - /* add the request to the end of the list rather than the start */ + pthread_mutex_lock(&(_sfs_mounted[req->sfsid].req_lock)); dlinkAddTail(req, &req->node, &_sfs_mounted[req->sfsid].request_queue); - _sfs_mounted[req->sfsid].pending_requests++; pthread_mutex_unlock(&(_sfs_mounted[req->sfsid].req_lock)); + /* and signal that the request has been made */ pthread_mutex_lock(&(_sfs_mounted[req->sfsid].req_signal_lock)); pthread_cond_signal(&(_sfs_mounted[req->sfsid].req_signal)); pthread_mutex_unlock(&(_sfs_mounted[req->sfsid].req_signal_lock)); + printf("DEBUG: request %u submitted\n",req->sfsid); return(0); } sfs_blockbuf_t * -_sfs_read_block(int sfsid, uint diskpos) +_sfs_read_block(uint sfsid, uint diskpos) { /* This takes an sfsid, and a diskpos, and returns a blockbuf filled in with the correct data. */ @@ -129,17 +127,18 @@ return _sfs_mounted[sfsid].clean; } } -/* And in the dirty list */ -/* We probably shouldn't find things in the dirty list - they should probably -be served by squid's own cache first. Might be worth measuring the frequency -of this one... */ + /* And in the dirty list */ + /* We probably shouldn't find things in the dirty list - they should + * probably be served by squid's own cache first (assuming squid's still + * keeping a cache...) Might be worth measuring the frequency of this + * one. */ if (_sfs_mounted[sfsid].dirty) { _sfs_mounted[sfsid].dirty = sfs_splay_find(diskpos,_sfs_mounted[sfsid].dirty); if (_sfs_mounted[sfsid].dirty->diskpos == diskpos) { return _sfs_mounted[sfsid].dirty; } } -/* Otherwise we're reading a new one in off the disk. */ + /* Otherwise we're reading a new one in off the disk. */ dpos = diskpos * FRAGSIZE; if (!(new = _sfs_blockbuf_create())) @@ -154,32 +153,30 @@ xfree(new); return NULL; } - printf("DEBUG: read %d bytes (fragsize = %d)\n",readlen,FRAGSIZE); new->sfsid = sfsid; new->diskpos = diskpos; new->buflen = FRAGSIZE; if (CBIT_TEST(_sfs_mounted[sfsid].ibm, diskpos)) { new->type = _SFS_INODE; - printf("DEBUG: just read inode %s\n",new->buf+sizeof(sfs_inode_t)); } else { new->type = _SFS_DATA; - printf("DEBUG: just read data %s\n",new->buf); } -/* Add it to the clean list on the spot. */ + /* Add it to the clean list on the spot. */ _sfs_mounted[sfsid].clean = sfs_splay_insert(sfsid, new, _sfs_mounted[sfsid].clean); return new; } uint -_sfs_calculate_diskpos(int sfsid, sfs_openfile_t *openfd, uint offset) +_sfs_calculate_diskpos(sfs_openfile_t *openfd, uint offset) { /* This function returns the disk position of the block into which bytes should be written, or from which bytes should be read. It is granular to a block level only. */ sfs_blockbuf_t *din; uint *dinptr; - uint ret; + sfsid_t sfsid; + sfsid = openfd->sfsid; if (offset < inode_data_size) return openfd->inodebuf_p->diskpos; /* Otherwise subtract inode_data_size, then div by FRAGSIZE to get entry in @@ -202,10 +199,9 @@ store state information so we don't read three times for each distinct read call. */ - din = _sfs_read_block(sfsid, openfd->inode->sin[(offset - direct_pointer_threshold) / (FRAGSIZE * (CHUNKSIZE / sizeof(uint)))]); + din = _sfs_read_block(sfsid,openfd->inode->sin[(offset - direct_pointer_threshold) / (FRAGSIZE * (CHUNKSIZE / sizeof(uint)))]); dinptr = (uint *)din->buf; - ret = dinptr[(offset - direct_pointer_threshold) / FRAGSIZE]; - return ret; + return dinptr[(offset - direct_pointer_threshold) / FRAGSIZE]; } } @@ -225,7 +221,7 @@ } sfs_blockbuf_t * -_sfs_write_block(int sfsid, uint diskpos, void *buf, int buflen, enum sfs_block_type type) +_sfs_write_block(uint sfsid, uint diskpos, void *buf, int buflen, enum sfs_block_type type) { sfs_blockbuf_t *new; sfs_blockbuf_t *old; @@ -233,11 +229,11 @@ printf("DEBUG: sfsid = %d, diskpos = %d, buflen = %d\n",sfsid,diskpos,buflen); new = old = NULL; -/* If it's an inode, make sure we have it in clean or dirty - gotta preserve - the inode data */ + /* If it's an inode, make sure we have it in clean or dirty - gotta + * preserve the inode data */ if (CBIT_TEST(_sfs_mounted[sfsid].ibm, diskpos)) _sfs_read_block(sfsid, diskpos); -/* If it's in the clean list, remove it - it's now incorrect */ + /* If it's in the clean list, remove it - it's now incorrect */ if (_sfs_mounted[sfsid].clean) { _sfs_mounted[sfsid].clean = sfs_splay_find(diskpos,_sfs_mounted[sfsid].clean); if (_sfs_mounted[sfsid].clean->diskpos == diskpos) { @@ -247,16 +243,11 @@ _sfs_mounted[sfsid].dirty = sfs_splay_insert(sfsid, _sfs_mounted[sfsid].dirty, old); } } -/* Likewise the dirty list - we'll be simply replacing the contents if it's -there */ + /* Likewise the dirty list - we'll be simply replacing the contents if it's + * there */ if (_sfs_mounted[sfsid].dirty) { _sfs_mounted[sfsid].dirty = sfs_splay_find(diskpos,_sfs_mounted[sfsid].dirty); if (_sfs_mounted[sfsid].dirty->diskpos == diskpos) { - if (type == _SFS_INODE) { - if (temp_inode.len == 0) - temp_inode.len = 1; - memcpy(&temp_inode,_sfs_mounted[sfsid].dirty->buf,sizeof(sfs_inode_t)); - } xfree(_sfs_mounted[sfsid].dirty->buf); _sfs_mounted[sfsid].dirty->buf = (char *)xcalloc(1, FRAGSIZE); new = _sfs_mounted[sfsid].dirty; @@ -269,17 +260,12 @@ new->sfsid = sfsid; new->diskpos = diskpos; new->dirty = 1; + new->type = type; CBIT_SET(_sfs_mounted[sfsid].mhb, diskpos); printf("DEBUG: inserting block into dirty list\n"); _sfs_mounted[sfsid].dirty = sfs_splay_insert(sfsid, new, _sfs_mounted[sfsid].dirty); } - if (type == _SFS_INODE) { - new->type = _SFS_INODE; - memcpy(new->buf,&temp_inode,sizeof(sfs_inode_t)); - memcpy(new->buf+sizeof(sfs_inode_t),buf,buflen); - } else { - memcpy(new->buf,buf,buflen); - } + memcpy(new->buf,buf,buflen); return new; }