--------------------- PatchSet 1393 Date: 2001/01/26 19:28:21 Author: darius Branch: sfs Tag: (none) Log: Various fixes for the basic sfs_test case (incidentally, I'm cheating for now and have a local sfs_shim.c that contains dlink* definitions so I can run the test program). sfs as a filesystem now successfully does a cycle of: format/mount/open/write/write/close/umount/mount/read/close/umount (see sfs_test.c for exactly what it's doing). Next tasks are larger files (I note support for the calculations for double- indirect pointers is lacking), and unlink. Oh, also removed the aforementioned small race condition ;) KevinL Members: src/fs/sfs/Makefile.in:1.1.2.3->1.1.2.4 src/fs/sfs/sfs_interface.c:1.1.2.7->1.1.2.8 src/fs/sfs/sfs_llo.c:1.1.2.5->1.1.2.6 src/fs/sfs/sfs_test.c:1.1.2.3->1.1.2.4 src/fs/sfs/sfs_util.c:1.1.2.6->1.1.2.7 Index: squid/src/fs/sfs/Makefile.in =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/sfs/Attic/Makefile.in,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid/src/fs/sfs/Makefile.in 26 Jan 2001 13:46:11 -0000 1.1.2.3 +++ squid/src/fs/sfs/Makefile.in 26 Jan 2001 19:28:21 -0000 1.1.2.4 @@ -1,7 +1,7 @@ # # Makefile for the sfs storage driver for the Squid Object Cache server # -# $Id: Makefile.in,v 1.1.2.3 2001/01/26 13:46:11 adri Exp $ +# $Id: Makefile.in,v 1.1.2.4 2001/01/26 19:28:21 darius Exp $ # FS = sfs @@ -35,9 +35,7 @@ all: $(OUT) test: $(SFSOBJS) sfs_test.o - $(CC) $(CFLAGS) -L../../../lib $(SFSOBJS) sfs_test.o -lmiscutil -lpthread -lm -o sfs_test - - + $(CC) $(CFLAGS) -L../../../lib $(SFSOBJS) sfs_test.o ../../globals.o -lmiscutil -lpthread -lm -o sfs_test $(OUT): $(OBJS) @rm -f ../stamp Index: squid/src/fs/sfs/sfs_interface.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/sfs/Attic/sfs_interface.c,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -u -r1.1.2.7 -r1.1.2.8 --- squid/src/fs/sfs/sfs_interface.c 26 Jan 2001 15:43:41 -0000 1.1.2.7 +++ squid/src/fs/sfs/sfs_interface.c 26 Jan 2001 19:28:21 -0000 1.1.2.8 @@ -29,10 +29,10 @@ sfsblock_t sfsinode; uint temp_sfsid; -/* Currently, you have to specify either an inode, or O_CREAT */ -/* We also make the rather brash assumption that if we're opening to write, - we're creating a new file - that assumption can change. */ -/* Could do with error checking on the sscanf... */ + /* Currently, you have to specify either an inode, or O_CREAT. + * We also make the rather brash assumption that if we're opening to + * write, we're creating a new file - that assumption can change. + * Could do with error checking on the sscanf... */ sfsid = 0; sfsinode = 0; if (path != (char *)NULL) { @@ -43,7 +43,7 @@ rt = _SFS_OP_OPEN_WRITE; } else { rt = _SFS_OP_OPEN_READ; -/* If we're trying to open something that's not an inode, return. */ + /* If we're trying to open something that's not an inode, return. */ if (!(CBIT_TEST(_sfs_mounted[sfsid].ibm, sfsinode))) { printf("DEBUG: sfs_open opening non-inode\n"); return -1; @@ -53,7 +53,9 @@ return -1; req->sfsinode = sfsinode; _sfs_submit_request(req); + printf("DEBUG: open request submitted...\n"); _sfs_waitfor_request(req); + printf("DEBUG: response received\n"); ret = req->ret; _sfs_remove_request(req); return ret; @@ -128,6 +130,7 @@ } req->buflen = buflen; _sfs_submit_request(req); + printf("DEBUG: sfs_write id=%d, fd=%d\n",sfsid,sfsfd); _sfs_waitfor_request(req); ret = req->ret; if (req->buf) 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.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- squid/src/fs/sfs/sfs_llo.c 26 Jan 2001 12:31:18 -0000 1.1.2.5 +++ squid/src/fs/sfs/sfs_llo.c 26 Jan 2001 19:28:21 -0000 1.1.2.6 @@ -70,12 +70,10 @@ sigaddset(&new, SIGALRM); pthread_sigmask(SIG_BLOCK, &new, NULL); - /* tiny race condition here - this should be done with pthread_locks of - * some sort */ - mount_point->accepting_requests = 1; /* Set a conditional, when it's realised scan through the service list. */ pthread_cond_init(&(mount_point->req_signal), NULL); pthread_mutex_lock(&(mount_point->req_signal_lock)); + mount_point->accepting_requests = 1; i = 0; while (1) { printf("DEBUG: Going into wait... (%d pending)\n",mount_point->pending_requests); @@ -187,7 +185,7 @@ { sfs_openfile_t *openfd; sfs_blockbuf_t *new, *current = NULL; - int offset, retlen, fragsize, inblock, maxfragsize; + int offset, written, fragsize, inblock, maxfragsize; sfsblock_t diskpos; void *buf; int type; @@ -202,31 +200,39 @@ else offset = req->offset; - retlen = 0; + /* written tracks how much we've written so far in total. */ + written = 0; 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 write one block at a time - the process to find which block to write + * to next is a little, um, involved at present. */ + while (written < req->buflen) { + /* Work out type and where in the block this write should go. + * 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) { + if (offset + written < inode_data_size) { type = _SFS_INODE; - inblock = offset + retlen + sizeof(sfs_inode_t); + inblock = offset + written + sizeof(sfs_inode_t); } else { type = _SFS_DATA; - inblock = ((offset + retlen) - sizeof(sfs_inode_t)) - ((((offset + retlen) - sizeof(sfs_inode_t)) / FRAGSIZE) * FRAGSIZE); + inblock = ((offset + written) - sizeof(sfs_inode_t)) - ((((offset + written) - sizeof(sfs_inode_t)) / FRAGSIZE) * FRAGSIZE); } + /* maxfragsize indicates the maximum amount of data to write in this + * block. */ maxfragsize = FRAGSIZE - inblock; current = NULL; /* Figure out where on disk it should be... */ - if (!(diskpos = _sfs_calculate_diskpos(req->sfsid, openfd, offset+retlen))) { + if (!(diskpos = _sfs_calculate_diskpos(req->sfsid, openfd, offset+written))) { + /* If we're not within the file, allocate a new block */ if (!(diskpos = _sfs_allocate_block(req->sfsid, type))) { - _sfs_done_request(req,retlen); + _sfs_done_request(req,written); return; } - if ((offset + retlen) < 261632) { - openfd->inode->dip[(offset + retlen - inode_data_size) / FRAGSIZE] = diskpos; + /* Magic number? What magic number? */ + /* This sets the appropriate inode block pointer */ + if ((offset + written) < 261632) { + openfd->inode->dip[(offset + written - inode_data_size) / FRAGSIZE] = diskpos; } else { /* XXX indirect pointer - youch. This has not yet been * implemented :( */ @@ -237,11 +243,7 @@ } /* How much more to write? */ - if ((req->buflen - retlen) >= maxfragsize) { - fragsize = maxfragsize; - } else { - fragsize = req->buflen - retlen; - } + fragsize = min(req->buflen - written,maxfragsize); if (current) { printf("DEBUG: current block found\n"); buf = current->buf; @@ -249,22 +251,22 @@ printf("DEBUG: sfs_do_write new buf created\n"); buf = (char *)xcalloc(1, FRAGSIZE); } - printf("DEBUG: buf = %p, inblock = %d, fragsize = %d, retlen = %d, buflen = %d\n",buf,inblock,fragsize,retlen,req->buflen); - memcpy(((char *)buf)+inblock,((char *)req->buf)+retlen,fragsize); + printf("DEBUG: buf = %p, inblock = %d, fragsize = %d, written = %d, buflen = %d\n",buf,inblock,fragsize,written,req->buflen); + memcpy(((char *)buf)+inblock,((char *)req->buf)+written,fragsize); if (!current) { if (!(new = _sfs_write_block(req->sfsid, diskpos, buf, fragsize, type))) { - _sfs_done_request(req,retlen); + _sfs_done_request(req,written); return; } new->sfsinode = openfd->sfsinode; new->type = type; current = new; } - retlen += fragsize; + written += fragsize; openfd->pos += fragsize; } printf("DEBUG: written %d bytes to fd %d (%s)\n",req->buflen,req->sfsfd,current->buf+sizeof(sfs_inode_t)); - _sfs_done_request(req,retlen); + _sfs_done_request(req,written); } void 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.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid/src/fs/sfs/sfs_test.c 26 Jan 2001 12:31:18 -0000 1.1.2.3 +++ squid/src/fs/sfs/sfs_test.c 26 Jan 2001 19:28:21 -0000 1.1.2.4 @@ -1,4 +1,4 @@ -/* $Id: sfs_test.c,v 1.1.2.3 2001/01/26 12:31:18 darius Exp $ */ +/* $Id: sfs_test.c,v 1.1.2.4 2001/01/26 19:28:21 darius Exp $ */ #include #include @@ -29,8 +29,8 @@ } sfsid = sfs_mount("test.drv"); printf("sfsid = %d\n",sfsid); - sleep(1); - sprintf(filename,"%d/0",sfsid); + snprintf(filename,20,"%d/0",sfsid); + printf("opening %s",filename); sfsfd = sfs_open(filename, O_CREAT, 0); sfsinode = sfs_get_inode(sfsfd); printf("sfsfd = %d, sfsinode = %d\n",sfsfd,sfsinode); @@ -38,13 +38,11 @@ sfs_write(sfsfd,"Hello, again!\n",strlen("Hello, again!\n")); printf("close result = %d\n",sfs_close(sfsfd)); printf("umount result = %d\n",sfs_umount(sfsid)); - sleep(1); printf("About to remount and read...\n"); sfsid = sfs_mount("test.drv"); printf("sfsid = %d\n",sfsid); - sleep(1); printf("Opening %d/%d\n",sfsid,sfsinode); - sprintf(filename,"%d/%d",sfsid,sfsinode); + snprintf(filename,20,"%d/%d",sfsid,sfsinode); printf("DEBUG: %s\n",filename); sfsfd = sfs_open(filename, O_RDONLY, 0); printf("sfsfd = %d, sfsinode = %d\n",sfsfd,sfsinode); 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.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- squid/src/fs/sfs/sfs_util.c 26 Jan 2001 15:43:41 -0000 1.1.2.6 +++ squid/src/fs/sfs/sfs_util.c 26 Jan 2001 19:28:21 -0000 1.1.2.7 @@ -17,7 +17,9 @@ 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)); } } @@ -62,7 +64,9 @@ _sfs_mounted[req->sfsid].done_requests++; pthread_mutex_unlock(&(_sfs_mounted[req->sfsid].done_lock)); + pthread_mutex_lock(&(req->done_signal_lock)); pthread_cond_signal(&(req->done_signal)); + pthread_mutex_unlock(&(req->done_signal_lock)); } sfs_requestor * @@ -82,7 +86,7 @@ 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)); + /* pthread_mutex_lock(&(req->done_signal_lock)); */ return req; } @@ -100,6 +104,7 @@ 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); } @@ -112,7 +117,6 @@ uint64_t dpos; int readlen; - printf("DEBUG: _sfs_read_block\n"); /* Searching for the appropriate block in the clean list */ if (_sfs_mounted[sfsid].clean) { _sfs_mounted[sfsid].clean = sfs_splay_find(diskpos,_sfs_mounted[sfsid].clean);