From 7e3c04cae6be4ff4b0e5c016f656650b0cf73ed3 Mon Sep 17 00:00:00 2001 From: Steve Slaven Date: Fri, 7 Aug 2009 16:36:35 -0700 Subject: Update chunk references on chunk flush too, so we don't lose partially used chunks that never get locked or unlocked because we haven't sync'd the whole file yet diff --git a/FuseArchive/ChunkFile.py b/FuseArchive/ChunkFile.py index b9f114f..6a0ea34 100644 --- a/FuseArchive/ChunkFile.py +++ b/FuseArchive/ChunkFile.py @@ -230,6 +230,8 @@ class ChunkFile(object): logging.debug( "Key was %s" % key ) self.dirty_chunks = 0 + self._update_chunk_references() + def read(self, length, offset): logging.debug( "Reading from %s offset: %d (0x%x) length: %d (0x%d)" % ( self.orig_path, offset, offset, length, length ) ) @@ -435,43 +437,7 @@ class ChunkFile(object): lock_chunk( key ) self.original_key = key - # Now update our chunk ref counts - logging.debug( "Updating chunk references" ) - for index in range( len( self.chunks ) ): - # Is this chunk changed from what was here before? - oldkey = None - key = self.chunks[ index ] - - changed = False - # Is the old chunks at least this big? - if index >= len( self.original_chunks ): - logging.debug( "No old chunk at this spot, changed for sure" ) - changed = True - else: - oldkey = self.original_chunks[ index ] - if oldkey != key: - logging.debug( "Key has changed at index %d" % index ) - changed = True - logging.debug( "%s is now %s" % (oldkey, key) ) - - if changed: - logging.debug( "Chunk at index %d has changed" % index ) - if oldkey != None: - unlock_chunk( oldkey ) - - lock_chunk( key ) - - # Free any unused chunks because of ftruncate - logging.debug( "Freeing chunks beyond our new chunk count" ) - index = len( self.chunks ) - while index < len( self.original_chunks ): - logging.debug( "Unlocking chunk at index %d" % index ) - unlock_chunk( self.original_chunks[ index ] ) - index += 1 - - # Update our original_chunks since we've locked/unlocked some - # things - self.original_chunks = copy.deepcopy( self.chunks ) + self._update_chunk_references() # Not dirty anymore if self.orig_path in dirty_cache: @@ -481,6 +447,47 @@ class ChunkFile(object): logging.debug( "_fflush exit" ) return 1 + + def _update_chunk_references(self): + # Now update our chunk ref counts + logging.debug( "Updating chunk references" ) + for index in range( len( self.chunks ) ): + # Is this chunk changed from what was here before? + oldkey = None + key = self.chunks[ index ] + + changed = False + # Is the old chunks at least this big? + if index >= len( self.original_chunks ): + logging.debug( "No old chunk at this spot, changed for sure" ) + changed = True + else: + oldkey = self.original_chunks[ index ] + if oldkey != key: + logging.debug( "Key has changed at index %d" % index ) + changed = True + logging.debug( "%s is now %s" % (oldkey, key) ) + + if changed: + logging.debug( "Chunk at index %d has changed" % index ) + if oldkey != None: + unlock_chunk( oldkey ) + + lock_chunk( key ) + + # Free any unused chunks because of ftruncate + logging.debug( "Freeing chunks beyond our new chunk count" ) + index = len( self.chunks ) + while index < len( self.original_chunks ): + logging.debug( "Unlocking chunk at index %d" % index ) + unlock_chunk( self.original_chunks[ index ] ) + index += 1 + + # Update our original_chunks since we've locked/unlocked some + # things + self.original_chunks = copy.deepcopy( self.chunks ) + + def pre_unlink(self): # Release all our blocks and our main file key logging.debug( "Unlocking all our chunks for unlink" ) -- cgit v0.10.2