--------------------- PatchSet 1387 Date: 2001/01/26 12:31:18 Author: darius Branch: sfs Tag: (none) Log: tweaking comments and small changes - getting familiar with the code again. Members: src/fs/sfs/sfs_llo.c:1.1.2.4->1.1.2.5 src/fs/sfs/sfs_test.c:1.1.2.2->1.1.2.3 Index: squid/src/fs/sfs/sfs_llo.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/sfs/Attic/sfs_llo.c,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid/src/fs/sfs/sfs_llo.c 25 Jan 2001 16:08:54 -0000 1.1.2.4 +++ squid/src/fs/sfs/sfs_llo.c 26 Jan 2001 12:31:18 -0000 1.1.2.5 @@ -83,20 +83,20 @@ printf("DEBUG: Coming out of wait... (%d pending)\n",mount_point->pending_requests); tnode = mount_point->request_queue.head; -/* Should I lock the request queue while I cycle through these? Probably - wise, but slow... */ + /* Should I lock the request queue while I cycle through these? + * Probably wise, but slow... */ while ((mount_point->pending_requests > 0) && (tnode != NULL)) { - printf("DEBUG: %d pending requests\n",mount_point->pending_requests); + printf("DEBUG: %d pending requests left\n",mount_point->pending_requests); req = tnode->data; if (req->request_state == _SFS_PENDING) { -/* If we're not accepting requests, return fail for each request. */ -/* Note, we can't just lock the request queue, as things are still being -removed from it by other threads. */ + /* If we're not accepting requests, return fail for each + * request. Note, we can't just lock the request queue, as + * things are still being removed from it by other threads. */ if (!(mount_point->accepting_requests)) { _sfs_done_request(req,-1); } else { -/* This portion sets the state, and works out exactly what to do - open, - read, write, close, sync, unlink. */ + /* This portion sets the state, and works out exactly what + * to do - open, read, write, close, sync, unlink. */ req->request_state = _SFS_IN_PROGRESS; mount_point->pending_requests--; switch (req->request_type) { @@ -126,6 +126,7 @@ } tnode = tnode->next; } + /* Flush the bitmaps every 10 seconds */ i = (i + 1) % 10; if (i == 0) { _sfs_flush_bitmaps(mount_point->sfsid); @@ -140,7 +141,7 @@ sfs_openfile_t *openfd; sfsblock_t diskpos; int offset, retlen, fragsize; - void *buf, *tmp; + void *buf; if (!(openfd = _sfs_find_fd(req->sfsfd))) { _sfs_done_request(req,-1); @@ -164,22 +165,16 @@ _sfs_done_request(req,retlen); return; } - tmp = buf; - if ((retlen + new->buflen) > req->buflen) - fragsize = req->buflen - retlen; - else - fragsize = new->buflen; - buf = (char *)xcalloc(1, retlen + fragsize + 1); - memcpy(buf, tmp, retlen); - if (new->type == _SFS_INODE) { - if (fragsize > inode_data_size) - fragsize = inode_data_size; + /* In case of request only wanting a certain amount, work out how much + * to copy into req->buf */ + fragsize = min(req->buflen - retlen,new->buflen); + if (new->type == _SFS_INODE) + fragsize = min(fragsize,inode_data_size); + buf = (char *)xrealloc(buf, retlen + fragsize); + if (new->type == _SFS_INODE) memcpy(((char *)buf)+retlen, new->buf+sizeof(sfs_inode_t), fragsize); - } else { + else memcpy(((char *)buf)+retlen, new->buf, fragsize); - } - if (tmp) - xfree(tmp); retlen += fragsize; openfd->pos += fragsize; } @@ -194,7 +189,7 @@ sfs_blockbuf_t *new, *current = NULL; int offset, retlen, fragsize, inblock, maxfragsize; sfsblock_t diskpos; - void *buf, *tmp; + void *buf; int type; if (!(openfd = _sfs_find_fd(req->sfsfd))) { @@ -208,9 +203,12 @@ offset = req->offset; retlen = 0; - buf = tmp = NULL; -/* Work out type and where in the block this write should go */ + buf = NULL; + /* Work out type and where in the block this write should go */ while (retlen < req->buflen) { + /* If the total file is smaller than the inode block data size, then + * we're best off storing it in an inode data block - fastest retrieval + * and all that. */ if (offset + retlen < inode_data_size) { type = _SFS_INODE; inblock = offset + retlen + sizeof(sfs_inode_t); @@ -221,7 +219,7 @@ maxfragsize = FRAGSIZE - inblock; current = NULL; -/* Figure out where on disk it should be... */ + /* Figure out where on disk it should be... */ if (!(diskpos = _sfs_calculate_diskpos(req->sfsid, openfd, offset+retlen))) { if (!(diskpos = _sfs_allocate_block(req->sfsid, type))) { _sfs_done_request(req,retlen); @@ -230,14 +228,15 @@ if ((offset + retlen) < 261632) { openfd->inode->dip[(offset + retlen - inode_data_size) / FRAGSIZE] = diskpos; } else { -/* XXX indirect pointer - youch */ + /* XXX indirect pointer - youch. This has not yet been + * implemented :( */ } } else { printf("DEBUG: sfs_do_write Reading in old block\n"); current = _sfs_read_block(req->sfsid,diskpos); } -/* How much more to write? */ + /* How much more to write? */ if ((req->buflen - retlen) >= maxfragsize) { fragsize = maxfragsize; } else { @@ -279,11 +278,11 @@ _sfs_mounted[req->sfsid].accepting_requests = 0; mnt = &(_sfs_mounted[req->sfsid]); -/* Flush all the dirty blocks out to HDD */ + /* Flush all the dirty blocks out to HDD */ openfd = _sfs_openfiles[req->sfsid]; while(openfd) { -/* flush_file has to get rid of stuff then, which is bad :( */ -/* The structures get kinda confused at this point */ + /* flush_file has to get rid of stuff then, which is bad :( + * The structures get kinda confused at this point */ printf("DEBUG: flushing file...\n"); _sfs_flush_file(req->sfsid,openfd); _sfs_openfiles[req->sfsid] = openfd->next; @@ -303,15 +302,16 @@ if (mnt->mhb) xfree(mnt->mhb); block_ptr = mnt->clean; -/* Need to clean out the clean list */ + /* Need to clean out the clean list */ while (mnt->clean) { mnt->clean = sfs_splay_delete(req->sfsid, mnt->clean); } if (mnt->request_queue.head != NULL) { -/* Make doubly sure we've cleared any pending requests - shouldn't need to, -but we _are_ umounting... This is actually bodgy code, if it ever does anything, -then something's gone wrong. Probably shouldn't do this, but it saves deadlock, -and we'd rather see corruption than hang indefinately.*/ + /* Make doubly sure we've cleared any pending requests - shouldn't need to, + * but we _are_ umounting... This is actually bodgy code, if it ever does + * anything, then something's gone wrong. Probably shouldn't do this, but + * it saves deadlock, and we'd rather see corruption than hang + * indefinately.*/ lnode = mnt->request_queue.head; while (lnode) { req = lnode->data; @@ -328,15 +328,16 @@ sleep(1); } } -/* At this stage, all I need to do is kill the thread :) */ -/* I could shuffle these, do the done_request before actually completely -finishing - that would guarantee the requests are all collected properly */ + /* At this stage, all I need to do is kill the thread :) + * I could shuffle these, do the done_request before actually completely + * finishing - that would guarantee the requests are all collected + * properly */ _sfs_done_request(req,0); if (mnt->rootblock) { xfree(mnt->rootblock); mnt->rootblock = NULL; } -/* Should also free all open fd's */ + /* Should also free all open fd's */ pthread_exit(NULL); } @@ -356,13 +357,13 @@ fd->sfsinode = req->sfsinode; fd->inodebuf_p = _sfs_read_block(req->sfsid, req->sfsinode); } else { -/* Doesn't need to lock, as all allocation is within thread. */ + /* Doesn't need to lock, as all allocation is within thread. */ if (!(fd->sfsinode = _sfs_allocate_block(req->sfsid, _SFS_INODE))) { xfree(fd); _sfs_done_request(req,-1); return; } -/* Fill the new inode */ + /* Fill the new inode */ if (!(fd->inodebuf_p = _sfs_blockbuf_create())) { printf("DEBUG: Couldn't create a blockbuf\n"); xfree(fd); @@ -383,8 +384,8 @@ } fd->pos = 0; fd->next = fd->prev = NULL; -/* Add this one to the sfsid list of open fd's */ -/* Allocating an fd */ + /* Add this one to the sfsid list of open fd's */ + /* Allocating an fd */ fdptr = _sfs_openfiles[req->sfsid]; if (fdptr) { while(fdptr->next) { @@ -433,8 +434,8 @@ printf("DEBUG: flushing file %d\n",req->sfsfd); _sfs_flush_file(req->sfsid, ptr); if (ptr) { -/* Assuming _sfs_flush_file clears the other stuff from the openfd - will - check that later... */ + /* Assuming _sfs_flush_file clears the other stuff from the openfd - + * will check that later... */ xfree(ptr); } _sfs_done_request(req,0); Index: squid/src/fs/sfs/sfs_test.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/sfs/Attic/sfs_test.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_test.c 24 Jan 2001 15:34:16 -0000 1.1.2.2 +++ squid/src/fs/sfs/sfs_test.c 26 Jan 2001 12:31:18 -0000 1.1.2.3 @@ -1,4 +1,4 @@ -/* $Id: sfs_test.c,v 1.1.2.2 2001/01/24 15:34:16 adri Exp $ */ +/* $Id: sfs_test.c,v 1.1.2.3 2001/01/26 12:31:18 darius Exp $ */ #include #include @@ -8,6 +8,7 @@ #include #include +#include "squid.h" #include "sfs_defines.h" #include "sfs_lib.h"