aboutsummaryrefslogtreecommitdiffstats
path: root/FuseArchive
diff options
context:
space:
mode:
authorSteve Slaven <bpk@hoopajoo.net>2009-08-07 23:36:35 (GMT)
committerSteve Slaven <bpk@hoopajoo.net>2009-08-07 23:36:35 (GMT)
commit7e3c04cae6be4ff4b0e5c016f656650b0cf73ed3 (patch)
tree46278a13226e0e66418cbb196c9e73b7a2588092 /FuseArchive
parente6f651fcde73181c236bd48aaebc653675859f34 (diff)
downloadfusearchive-7e3c04cae6be4ff4b0e5c016f656650b0cf73ed3.zip
fusearchive-7e3c04cae6be4ff4b0e5c016f656650b0cf73ed3.tar.gz
fusearchive-7e3c04cae6be4ff4b0e5c016f656650b0cf73ed3.tar.bz2
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
Diffstat (limited to 'FuseArchive')
-rw-r--r--FuseArchive/ChunkFile.py81
1 files changed, 44 insertions, 37 deletions
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" )