--------------------- PatchSet 1379 Date: 2001/01/24 16:06:38 Author: adri Branch: sfs Tag: (none) Log: * move sfsid_t to be a signed int. It limits us to 127 filesystems, but its more consistent in error returns (ie -1.. :-) * Newfs() now checks to see whether the given storedir is a valid fs, and doesn't sfs_format()s it. This way, you won't lose a FS if you're just running squid -z to add a new fs Members: src/fs/sfs/sfs_defines.h:1.1.2.1->1.1.2.2 src/fs/sfs/sfs_fslo.c:1.1.2.1->1.1.2.2 src/fs/sfs/sfs_interface.c:1.1.2.1->1.1.2.2 src/fs/sfs/store_dir_sfs.c:1.1.2.1->1.1.2.2 Index: squid/src/fs/sfs/sfs_defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/sfs/Attic/sfs_defines.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/fs/sfs/sfs_defines.h 24 Jan 2001 14:11:54 -0000 1.1.2.1 +++ squid/src/fs/sfs/sfs_defines.h 24 Jan 2001 16:06:38 -0000 1.1.2.2 @@ -1,4 +1,4 @@ -/* $Id: sfs_defines.h,v 1.1.2.1 2001/01/24 14:11:54 adri Exp $ */ +/* $Id: sfs_defines.h,v 1.1.2.2 2001/01/24 16:06:38 adri Exp $ */ #ifndef SFS_DEFINES_H #define SFS_DEFINES_H @@ -21,7 +21,7 @@ #endif #define sfsfd_t uint32_t -#define sfsid_t uint8_t +#define sfsid_t int8_t #define sfsblock_t uint32_t /* Code assumes CHUNKSIZE is twice FRAGSIZE. If it isn't things will break */ @@ -31,13 +31,16 @@ #define CHUNKSIZE 8192 #define POINTERSIZE 4 /* Number of bytes in a pointer */ #define MINFSFRAGS 1024 /* Minimum acceptable number of FS frags */ -#define MAXFILESYS 512 /* Maximum number of mounted filesystems */ +#define MAXFILESYS 127 /* Maximum number of mounted filesystems */ #define NUMDIP 62 #define NUMSIN 64 #define BITINBYTE 8 +/* Magic! */ +#define SFS_MAGIC 0xdeadf00d + /* The below defines assume there are 8 bits in a byte */ #define TSTBIT(a, b) (((a[b>>3]) << (b & 0x7)) & 0x80) @@ -104,6 +107,7 @@ sfsblock_t ibmpos; sfsblock_t fbmpos; uint32_t bmlen; + uint32_t magic; } sfs_rootblock_t; /* These structures exist as members of linked lists hanging off a */ Index: squid/src/fs/sfs/sfs_fslo.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/sfs/Attic/sfs_fslo.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/fs/sfs/sfs_fslo.c 24 Jan 2001 14:11:54 -0000 1.1.2.1 +++ squid/src/fs/sfs/sfs_fslo.c 24 Jan 2001 16:06:38 -0000 1.1.2.2 @@ -60,6 +60,7 @@ rblock->ibmpos = ibmpos; rblock->fbmpos = fbmpos; rblock->bmlen = bmlen; + rblock->magic = SFS_MAGIC; os = 0; if(lseek(fd, os, SEEK_SET) < 0) { xfree(rbbuf); 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.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/fs/sfs/sfs_interface.c 24 Jan 2001 14:11:54 -0000 1.1.2.1 +++ squid/src/fs/sfs/sfs_interface.c 24 Jan 2001 16:06:38 -0000 1.1.2.2 @@ -226,16 +226,13 @@ return ret; } -/* I believe the return value on this to be bogus - but I need an error value -to return. Oh for exceptions, hey? */ -/* Using 0 as the error value is also pretty crufty :( I'm not sure what - else to do here - I really want to use an unsigned int for this... */ sfsid_t sfs_mount(const char *rawdevpath) { sfsid_t i; sfsblock_t j, bmlen; sfsblock_t ibmpos, fbmpos; + sfsblock_t magic; /* This hunt is not thread-safe - assume only one thread doing these things (initialising/mounting) - otherwise bad things happen(tm). @@ -243,28 +240,45 @@ array */ for(i = 1; (_sfs_mounted[i].rootblock != NULL) && (i < MAXFILESYS); i++); if (i == MAXFILESYS) - return 0; + return -1; if ((_sfs_mounted[i].fd = open(rawdevpath, O_RDWR)) < 0) - return 0; + return -1; if (lseek(_sfs_mounted[i].fd, (uint64_t)0, SEEK_SET) < (uint64_t)0) { printf("Didn't manage to lseek in mount :(\n"); close(_sfs_mounted[i].fd); - return 0; + return -1; } if ((_sfs_mounted[i].rootblock = (sfs_rootblock_t *)xcalloc(1,CHUNKSIZE)) == NULL) { close(_sfs_mounted[i].fd); _sfs_mounted[i].rootblock = NULL; - return 0; + return -1; } if (read(_sfs_mounted[i].fd, _sfs_mounted[i].rootblock, CHUNKSIZE) < 0) { close(_sfs_mounted[i].fd); xfree(_sfs_mounted[i].rootblock); _sfs_mounted[i].rootblock = NULL; - return 0; + return -1; } ibmpos = _sfs_mounted[i].rootblock->ibmpos; fbmpos = _sfs_mounted[i].rootblock->fbmpos; bmlen = _sfs_mounted[i].rootblock->bmlen; + magic = _sfs_mounted[i].rootblock->magic; + + printf("DEBUG: sfs root: ibmpos %d, fbmpos %d, bmlen %d, numfrags %d, magic %d\n", + _sfs_mounted[i].rootblock->ibmpos, + _sfs_mounted[i].rootblock->fbmpos, + _sfs_mounted[i].rootblock->bmlen, + _sfs_mounted[i].rootblock->numfrags, + _sfs_mounted[i].rootblock->magic); + + /* Check magic! */ + if (magic != SFS_MAGIC) + return -1; + + /* If any of the rootblock stuff == 0, we have a bad fs */ + if ((ibmpos == 0) || (fbmpos == 0) || (bmlen == 0)) + return -1; + _sfs_mounted[i].sfsid = i; _sfs_mounted[i].fbm = (char *)xcalloc(1,bmlen); _sfs_mounted[i].ibm = (char *)xcalloc(1,bmlen); @@ -275,25 +289,25 @@ close(_sfs_mounted[i].fd); xfree(_sfs_mounted[i].rootblock); _sfs_mounted[i].rootblock = NULL; - return 0; + return -1; } if (read(_sfs_mounted[i].fd, _sfs_mounted[i].fbm, bmlen) < 0) { close(_sfs_mounted[i].fd); xfree(_sfs_mounted[i].rootblock); _sfs_mounted[i].rootblock = NULL; - return 0; + return -1; } if (read(_sfs_mounted[i].fd, _sfs_mounted[i].ibm, bmlen) < 0) { close(_sfs_mounted[i].fd); xfree(_sfs_mounted[i].rootblock); _sfs_mounted[i].rootblock = NULL; - return 0; + return -1; } if ((_sfs_mounted[i].mhb = (char *)xcalloc(1,bmlen)) == NULL) { close(_sfs_mounted[i].fd); xfree(_sfs_mounted[i].rootblock); _sfs_mounted[i].rootblock = NULL; - return 0; + return -1; } for (j = 0; j <= bmlen; j++) { if (CBIT_TEST(_sfs_mounted[i].ibm, j) || CBIT_TEST(_sfs_mounted[i].fbm, j)) Index: squid/src/fs/sfs/store_dir_sfs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/sfs/Attic/store_dir_sfs.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/fs/sfs/store_dir_sfs.c 24 Jan 2001 14:11:54 -0000 1.1.2.1 +++ squid/src/fs/sfs/store_dir_sfs.c 24 Jan 2001 16:06:38 -0000 1.1.2.2 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_sfs.c,v 1.1.2.1 2001/01/24 14:11:54 adri Exp $ + * $Id: store_dir_sfs.c,v 1.1.2.2 2001/01/24 16:06:38 adri Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -70,10 +70,8 @@ static int sfs_initialised = 0; static char *storeSfsDirSwapSubDir(SwapDir *, int subdirn); -static int storeSfsDirCreateDirectory(const char *path, int); static int storeSfsDirVerifyCacheDirs(SwapDir *); static int storeSfsDirVerifyDirectory(const char *path); -static void storeSfsDirCreateSwapSubDirs(SwapDir *); static char *storeSfsDirSwapLogFile(SwapDir *, const char *); static EVH storeSfsDirRebuildFromDirectory; static EVH storeSfsDirRebuildFromSwapLog; @@ -202,28 +200,6 @@ } static int -storeSfsDirCreateDirectory(const char *path, int should_exist) -{ - int created = 0; - struct stat st; - getCurrentTime(); - if (0 == stat(path, &st)) { - if (S_ISDIR(st.st_mode)) { - debug(20, should_exist ? 3 : 1) ("%s exists\n", path); - } else { - fatalf("Swap directory %s is not a directory.", path); - } - } else if (0 == mkdir(path, 0755)) { - debug(20, should_exist ? 1 : 3) ("%s created\n", path); - created = 1; - } else { - fatalf("Failed to make swap directory %s: %s", - path, xstrerror()); - } - return created; -} - -static int storeSfsDirVerifyDirectory(const char *path) { struct stat sb; @@ -260,26 +236,6 @@ return 0; } -static void -storeSfsDirCreateSwapSubDirs(SwapDir * sd) -{ - sfsinfo_t *sfsinfo = (sfsinfo_t *) sd->fsdata; - int i, k; - int should_exist; - LOCAL_ARRAY(char, name, MAXPATHLEN); - for (i = 0; i < sfsinfo->l1; i++) { - snprintf(name, MAXPATHLEN, "%s/%02X", sd->path, i); - if (storeSfsDirCreateDirectory(name, 0)) - should_exist = 0; - else - should_exist = 1; - debug(47, 1) ("Making directories in %s\n", name); - for (k = 0; k < sfsinfo->l2; k++) { - snprintf(name, MAXPATHLEN, "%s/%02X/%02X", sd->path, i, k); - storeSfsDirCreateDirectory(name, should_exist); - } - } -} static char * storeSfsDirSwapLogFile(SwapDir * sd, const char *ext) @@ -1122,9 +1078,28 @@ static void storeSfsDirNewfs(SwapDir * sd) { + int sfsid; + debug(47, 3) ("Creating swap space in %s\n", sd->path); - storeSfsDirCreateDirectory(sd->path, 0); - storeSfsDirCreateSwapSubDirs(sd); + + /* Check to see whether we have a sfs store. */ + sfsid = sfs_mount(sd->path); + if (sfsid < 0) { + /* it failed, we can do stuff.. */ + /* + * note - the FS *data* size will be max_size, but sfs metadata + * will make it bigger. Just like normal FSes. + */ + if (sfs_format(sd->path, (sd->max_size * 1024) / FRAGSIZE) < 0) + fatalf("error whilst formatting %s! : (%d) %s\n", sd->path, + errno, strerror(errno)); + } else { + /* it suceeded, unmount */ + debug(47, 3) ("Swap space in %s is already formatted\n", sd->path); + sfs_umount(sfsid); + } + + } static int