commit clicfs for openSUSE:Factory
Hello community, here is the log from the commit of package clicfs for openSUSE:Factory checked in at Tue May 19 02:47:15 CEST 2009. -------- --- clicfs/clicfs.changes 2009-05-05 14:13:52.000000000 +0200 +++ clicfs/clicfs.changes 2009-05-18 13:48:13.000000000 +0200 @@ -1,0 +2,15 @@ +Mon May 18 13:47:55 CEST 2009 - coolo@novell.com + +- make the file size 64bit (bnc#504627) + +------------------------------------------------------------------- +Mon May 18 13:04:41 CEST 2009 - coolo@novell.com + +- don't confuse num_pages with write_pages (bnc#504700) + +------------------------------------------------------------------- +Mon May 11 15:10:36 CEST 2009 - coolo@suse.de + +- fix corruption when writing short blocks + +------------------------------------------------------------------- calling whatdependson for head-i586 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ clicfs.spec ++++++ --- /var/tmp/diff_new_pack.K15227/_old 2009-05-19 02:44:20.000000000 +0200 +++ /var/tmp/diff_new_pack.K15227/_new 2009-05-19 02:44:20.000000000 +0200 @@ -1,5 +1,5 @@ # -# spec file for package clicfs (Version 1.0) +# spec file for package clicfs (Version 1.1.2) # # Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany. # @@ -22,8 +22,8 @@ BuildRequires: cmake fuse-devel gcc-c++ openssl-devel xz-devel Requires: fuse Summary: Compressed Loop Image Container -Version: 1.0 -Release: 4 +Version: 1.1.2 +Release: 1 License: GPL v2 only Group: System/Filesystems Source: clicfs.tar.bz2 @@ -62,6 +62,12 @@ %_mandir/man1/* %changelog +* Mon May 18 2009 coolo@novell.com +- make the file size 64bit (bnc#504627) +* Mon May 18 2009 coolo@novell.com +- don't confuse num_pages with write_pages (bnc#504700) +* Mon May 11 2009 coolo@suse.de +- fix corruption when writing short blocks * Tue May 05 2009 coolo@suse.de - if the cow file is read only, then just read it * Mon Apr 20 2009 coolo@suse.de ++++++ clicfs.tar.bz2 ++++++ diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/src/clicfs.c new/src/clicfs.c --- old/src/clicfs.c 2009-05-05 14:13:03.000000000 +0200 +++ new/src/clicfs.c 2009-05-18 13:45:56.000000000 +0200 @@ -32,8 +32,6 @@ FILE *logger = 0; -static uint32_t write_pages = 0; - static size_t detached_allocated = 0; static size_t sparse_memory = 0; static char *cowfilename = 0; @@ -50,36 +48,39 @@ static int clic_write_cow() { - if (!cowfilename || cowfile_ro == 1) + if (!cowfilename || cowfile_ro == 1 || !detached_allocated) return 0; - uint32_t indexlen = sizeof(uint32_t) * 2; + fprintf(stderr, "cow detached %dMB\n", (int)(detached_allocated / 1024)); + + uint32_t indexlen = 0; uint32_t i; for (i = 0; i < num_pages; ++i) { long ptr = (long)blockmap[i]; - //fprintf(stderr, "ptr %ld %d\n", (long)i, (int)(ptr & 0x3)); - if (ptr && (ptr & 0x3) == 0) { // detached now + if ( ptr && PTR_CLASS(ptr) == CLASS_MEMORY ) { // detached now uint32_t cowindex = clic_find_next_cow(); lseek(cowfilefd, cowindex * pagesize, SEEK_SET); - write(cowfilefd, blockmap[i], pagesize); + size_t ret = write(cowfilefd, blockmap[i], pagesize); + assert(ret == pagesize); free(blockmap[i]); detached_allocated -= (pagesize / 1024); blockmap[i] = (unsigned char*)(long)(cowindex << 2) + 2; } } + assert(!detached_allocated); + lseek(cowfilefd, cow_pages * pagesize, SEEK_SET); - uint32_t stringlen = thefilesize; - write(cowfilefd, (char*)&stringlen, sizeof(uint32_t)); + uint64_t stringlen = thefilesize; + indexlen += write(cowfilefd, (char*)&stringlen, sizeof(uint64_t)); stringlen = cow_pages; - write(cowfilefd, (char*)&stringlen, sizeof(uint32_t)); - lseek(cowfilefd, cow_pages * pagesize + sizeof(uint32_t) * 2, SEEK_SET); + indexlen += write(cowfilefd, (char*)&stringlen, sizeof(uint32_t)); stringlen = 0; for (i = 0; i < num_pages; ++i) { long ptr = (long)blockmap[i]; - if ((ptr & 0x3) == 2) { // block + if (PTR_CLASS(ptr) == CLASS_COW) { // block uint32_t key = i, value = ptr >> 2; write(cowfilefd, (char*)&key, sizeof(uint32_t)); write(cowfilefd, (char*)&value, sizeof(uint32_t)); @@ -261,14 +262,13 @@ static int clic_detach(size_t block) { - if (detached_allocated > 1500 && cowfilefd != -1) - clic_write_cow(); - + assert(block < num_pages); + unsigned char *ptr = blockmap[block]; - if (((long)ptr & 0x3) == 1 || ((long)ptr & 0x3) == 2) + if ((PTR_CLASS(ptr) == CLASS_RO ) || (PTR_CLASS(ptr) == CLASS_COW)) { - if (((long)ptr & 0x3) == 2) { - if (cows_index == DOENER_COW_COUNT - 1) + if (PTR_CLASS(ptr) == CLASS_COW) { + if (cows_index == CLICFS_COW_COUNT - 1) clic_write_cow(); } @@ -277,7 +277,7 @@ if (logger && detached_allocated % 1024 == 0 ) fprintf(logger, "detached %dMB\n", (int)(detached_allocated / 1024)); clic_read_block(newptr, block); - if (((long)ptr & 0x3) == 2) // we need to mark the place in the cow obsolete + if (PTR_CLASS(ptr) == CLASS_COW) // we need to mark the place in the cow obsolete cows[cows_index++] = (long)ptr >> 2; blockmap[block] = (unsigned char*)newptr; @@ -287,7 +287,7 @@ if (!blockmap[block]) { blockmap[block] = malloc(pagesize); - assert(((long)ptr & 0x3) == 0); + assert(PTR_CLASS(ptr) == CLASS_MEMORY); detached_allocated += (pagesize / 1024); if (logger && detached_allocated % 1024 == 0 ) fprintf(logger, "detached %dMB\n", (int)(detached_allocated / 1024)); memset(blockmap[block],0,pagesize); @@ -297,10 +297,10 @@ return 0; } -static size_t clic_write_block(const char *buf, off_t block, size_t size) +static size_t clic_write_block(const char *buf, off_t block, off_t ioff, size_t size) { clic_detach(block); - memcpy(blockmap[block], buf, size); + memcpy(blockmap[block]+ioff, buf, size); return size; } @@ -312,9 +312,14 @@ if(path[0] == '/' && strcmp(path + 1, thefile) != 0) return -ENOENT; - if (offset >= (off_t)thefilesize) { + if (offset >= (off_t)thefilesize) return 0; - } + + if (offset+size > thefilesize) + size = thefilesize-offset; + + if (!size) + return 0; off_t block = offset / pagesize; off_t ioff = offset - block * pagesize; @@ -322,12 +327,13 @@ assert(ioff == 0 || ioff + size <= pagesize); if (size <= pagesize) { - return clic_write_block(buf+ioff, block, size); + return clic_write_block(buf, block, ioff, size); } else { size_t wrote = 0; do { - size_t diff = clic_write_block(buf, block, size > pagesize ? pagesize : size); + size_t diff = clic_write_block(buf, block, ioff, size > pagesize ? pagesize : size); + ioff = 0; size -= diff; buf += diff; block++; @@ -340,10 +346,9 @@ static size_t clic_read_block(char *buf, size_t block) { - if (block >= write_pages) - return 0; + if (block >= num_pages) + return -EFAULT; - assert(block < write_pages); clic_log_access(block); if (!blockmap[block]) { // sparse block @@ -352,18 +357,18 @@ } long ptr = (long)blockmap[block]; - if ((ptr & 0x3) == 0) { + if (PTR_CLASS(ptr) == CLASS_MEMORY) { // detached memcpy(buf, blockmap[block], pagesize); return pagesize; } - if ((ptr & 0x3) == 2) { + if (PTR_CLASS(ptr) == CLASS_COW) { lseek(cowfilefd, (ptr >> 2) * pagesize, SEEK_SET); return read(cowfilefd, buf, pagesize); } - assert((ptr & 0x3) == 1); // in read only part + assert(PTR_CLASS(ptr) == CLASS_RO); // in read only part assert(block < num_pages); off_t mapped_block = clic_map_block(block); @@ -451,11 +456,14 @@ char *packfilename = 0; char *logfile = 0; +int ignore_cow_errors = 0; -enum { FUSE_OPT_MEMORY, FUSE_OPT_LOGGER, FUSE_OPT_COWFILE }; +enum { FUSE_OPT_SPARSE, FUSE_OPT_LOGGER, FUSE_OPT_COWFILE, FUSE_OPT_IGNORE_COW_ERRORS }; struct fuse_opt clic_opt[] = { - FUSE_OPT_KEY("-m %s", FUSE_OPT_MEMORY), + FUSE_OPT_KEY("--resevere-sparse %s", FUSE_OPT_SPARSE), + FUSE_OPT_KEY("--ignore-cow-errors", FUSE_OPT_IGNORE_COW_ERRORS), + FUSE_OPT_KEY("-m %s", FUSE_OPT_SPARSE), FUSE_OPT_KEY("-l %s", FUSE_OPT_LOGGER), FUSE_OPT_KEY("-c %s", FUSE_OPT_COWFILE), FUSE_OPT_END @@ -473,7 +481,7 @@ return 0; } break; - case FUSE_OPT_MEMORY: + case FUSE_OPT_SPARSE: sparse_memory = atoi(arg+2); return 0; break; @@ -485,11 +493,33 @@ cowfilename = strdup(arg+2); return 0; break; + case FUSE_OPT_IGNORE_COW_ERRORS: + ignore_cow_errors = 1; + break; } return 1; } +static int init_cow() +{ + FILE *cow = fopen(cowfilename, "w"); + if (!cow) { + perror("opening cow"); + return 1; + } + uint64_t stringlen64 = (thefilesize / pagesize * pagesize) + sparse_memory * 1024 * 1024; + fwrite((char*)&stringlen64, 1, sizeof(uint64_t), cow); + uint32_t stringlen = 0; + // there are 0 blocks + fwrite((char*)&stringlen, 1, sizeof(uint32_t), cow); + // the whole index is 12 bytes long + stringlen = sizeof(uint32_t) + sizeof(uint64_t); + fwrite((char*)&stringlen, 1, sizeof(uint32_t), cow); + fclose(cow); + return 0; +} + int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); @@ -514,11 +544,8 @@ // not sure why but multiple threads make it slower fuse_opt_add_arg(&args, "-s"); - if (!packfilename || (cowfilename && sparse_memory)) { + if (!packfilename) { fprintf(stderr, "usage: [-m <mb>] [-l <logfile|->] [-c <cowfile>] <packfile> <mntpoint>\n"); - if (cowfilename && sparse_memory) { - fprintf(stderr, "writes can go either into cowfile or memory\n"); - } return 1; } @@ -530,39 +557,34 @@ free(packfilename); if (cowfilename) { - if (access(cowfilename, R_OK)) { - FILE *cow = fopen(cowfilename, "w"); - if (!cow) { - perror("opening cow"); - return 1; - } - uint32_t stringlen = (thefilesize / pagesize * pagesize) + 512 * 1024 * 1024; - fwrite((char*)&stringlen, 1, sizeof(uint32_t), cow); - stringlen = 0; - // there are 0 blocks - fwrite((char*)&stringlen, 1, sizeof(uint32_t), cow); - // the whole index is 8 bytes long - stringlen = sizeof(uint32_t) * 2; - fwrite((char*)&stringlen, 1, sizeof(uint32_t), cow); - fclose(cow); - } + + if (access(cowfilename, R_OK)) + init_cow(); + + if (clicfs_read_cow(cowfilename)) { + if (!ignore_cow_errors) + return 1; + + init_cow(); if (clicfs_read_cow(cowfilename)) - return 1; + return 1; + } + sparse_memory = 0; // ignore the option if we have a cow } // fake for write if (sparse_memory) { thefilesize = (thefilesize / pagesize * pagesize) + sparse_memory * 1024 * 1024; - write_pages = thefilesize / pagesize; + size_t write_pages = thefilesize / pagesize; blockmap = realloc(blockmap, sizeof(unsigned char*)*write_pages); - } else - write_pages = num_pages; + uint32_t i; + for (i = num_pages; i < write_pages; ++i) + blockmap[i] = 0; + num_pages = write_pages; + } uint32_t i; - for (i = num_pages; i < write_pages; ++i) - blockmap[i] = 0; - com_count = 6000000 / (bsize*pagesize); // get 6MB of cache coms = malloc(sizeof(struct buffer_combo) * com_count); for (i = 0; i < com_count; ++i) diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/src/clicfs_common.c new/src/clicfs_common.c --- old/src/clicfs_common.c 2009-05-05 14:13:03.000000000 +0200 +++ new/src/clicfs_common.c 2009-05-18 13:45:56.000000000 +0200 @@ -32,7 +32,7 @@ int cowfilefd = -1; char thefile[PATH_MAX]; -size_t thefilesize = 0; +uint64_t thefilesize = 0; size_t pagesize = 4096; uint64_t *sizes = 0; uint64_t *offs = 0; @@ -57,6 +57,15 @@ return stringlen; } +uint64_t clic_readindex_fd64(int fd) +{ + uint64_t stringlen = 0; + if (read(fd, &stringlen, sizeof(uint64_t)) != sizeof(uint64_t)) { + return 0; + } + return stringlen; +} + uint32_t clic_readindex_file(FILE * f) { uint32_t stringlen = 0; @@ -88,7 +97,7 @@ uint32_t indexlen = clic_readindex_fd(cowfilefd) + sizeof(uint32_t); if (lseek(cowfilefd, st.st_size - indexlen, SEEK_SET ) == -1) perror("seek"); - thefilesize = clic_readindex_fd(cowfilefd); + thefilesize = clic_readindex_fd64(cowfilefd); uint32_t newpages = thefilesize / pagesize; blockmap = realloc(blockmap, sizeof(unsigned char*)*newpages); uint32_t i; @@ -103,7 +112,7 @@ assert(pageindex < num_pages); blockmap[pageindex] = (unsigned char*)(long)(page << 2) + 2; } - cows = malloc(sizeof(uint32_t) * DOENER_COW_COUNT); + cows = malloc(sizeof(uint32_t) * CLICFS_COW_COUNT); cows_index = 0; return 0; } @@ -136,7 +145,7 @@ } thefile[stringlen] = 0; - size_t oparts = clic_readindex_file(packfile); + uint64_t oparts = clic_readindex_file(packfile); bsize = clic_readindex_file(packfile); pagesize = clic_readindex_file(packfile); thefilesize = oparts * bsize * pagesize; @@ -192,7 +201,7 @@ unsigned char *ptr = blockmap[block]; size_t ret = (long)ptr; // calling map_block for detached blocks is bogus - assert((ret & 0x3) == 1); + assert(PTR_CLASS(ret) == 1); return ret >> 2; } diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/src/clicfs.h new/src/clicfs.h --- old/src/clicfs.h 2009-05-05 14:13:03.000000000 +0200 +++ new/src/clicfs.h 2009-05-18 13:45:56.000000000 +0200 @@ -28,8 +28,14 @@ #define DOENER_MAGIC 1 +#define PTR_CLASS(x) ((long)x & 0x3) + +enum { CLASS_MEMORY = 0, + CLASS_RO = 1, + CLASS_COW = 2 }; + extern char thefile[PATH_MAX]; -extern size_t thefilesize; +extern uint64_t thefilesize; extern size_t pagesize; extern uint64_t *sizes; extern uint64_t *offs; @@ -42,7 +48,7 @@ // support temporary changes on ro medium extern int cowfile_ro; -#define DOENER_COW_COUNT 100 +#define CLICFS_COW_COUNT 1000 // an array extern uint32_t *cows; diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/src/mkclicfs.cpp new/src/mkclicfs.cpp --- old/src/mkclicfs.cpp 2009-05-05 14:13:03.000000000 +0200 +++ new/src/mkclicfs.cpp 2009-05-18 13:45:56.000000000 +0200 @@ -262,8 +262,6 @@ queue_put( from_reader, in ); } - fprintf( stderr, "thread 0 is gone\n" ); - thread[0] = 0; pthread_exit(NULL); @@ -473,6 +471,10 @@ struct stat st; stat(infile, &st); + if (!S_ISREG( st.st_mode )) { + fprintf(stderr, "expecting regular file as input: %s\n", infile); + return EXIT_FAILURE; + } num_pages = st.st_size / pagesize; /* ext3 should be X blocks */ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Remember to have fun... -- To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit+help@opensuse.org
participants (1)
-
root@Hilbert.suse.de