Track when cached file data is written out.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Wed, 9 Dec 2009 19:34:11 +0000 (11:34 -0800)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Wed, 9 Dec 2009 19:34:11 +0000 (11:34 -0800)
bluesky/bluesky-private.h
bluesky/bluesky.h
bluesky/file.c
bluesky/inode.c

index e51c40f..d5e5d4f 100644 (file)
@@ -112,6 +112,10 @@ void bluesky_store_add_barrier(BlueSkyStoreAsync *barrier,
 
 void bluesky_inode_start_sync(BlueSkyInode *inode, BlueSkyStoreAsync *barrier);
 
+void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block,
+                         BlueSkyStoreAsync *barrier);
+void bluesky_file_flush(BlueSkyInode *inode, BlueSkyStoreAsync *barrier);
+
 #ifdef __cplusplus
 }
 #endif
index bd598e0..1d9f55c 100644 (file)
@@ -217,8 +217,6 @@ void bluesky_directory_dump(BlueSkyInode *dir);
 
 void bluesky_block_touch(BlueSkyInode *inode, uint64_t i);
 void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block);
-void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block);
-void bluesky_file_flush(BlueSkyInode *inode);
 void bluesky_file_truncate(BlueSkyInode *inode, uint64_t size);
 void bluesky_file_write(BlueSkyInode *inode, uint64_t offset,
                         const char *data, gint len);
index 8e16e91..3be40f0 100644 (file)
@@ -119,7 +119,6 @@ void bluesky_file_write(BlueSkyInode *inode, uint64_t offset,
         BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock,
                                          block_num);
         memcpy(&b->data->data[block_offset], data, bytes);
-        bluesky_block_flush(inode->fs, b);
 
         offset += bytes;
         data += bytes;
@@ -127,7 +126,6 @@ void bluesky_file_write(BlueSkyInode *inode, uint64_t offset,
     }
 
     bluesky_inode_update_ctime(inode, 1);
-    //bluesky_inode_flush(inode->fs, inode);
 }
 
 void bluesky_file_read(BlueSkyInode *inode, uint64_t offset,
@@ -182,13 +180,9 @@ void bluesky_block_fetch(BlueSkyFS *fs, BlueSkyBlock *block)
     block->type = BLUESKY_BLOCK_CACHED;
 }
 
-static void finished(gpointer a, gpointer b)
-{
-    g_print("Barrier completed!\n");
-}
-
 /* Write the given block to cloud-backed storage and mark it clean. */
-void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block)
+void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block,
+                         BlueSkyStoreAsync *barrier)
 {
     if (block->type != BLUESKY_BLOCK_DIRTY)
         return;
@@ -207,18 +201,13 @@ void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block)
     bluesky_string_ref(data);
     async->data = data;
     bluesky_store_async_submit(async);
+    if (barrier != NULL)
+        bluesky_store_add_barrier(barrier, async);
     bluesky_store_async_unref(async);
 
     g_free(block->ref);
     block->ref = name;
 
-    BlueSkyStoreAsync *barrier = bluesky_store_async_new(fs->store);
-    barrier->op = STORE_OP_BARRIER;
-    bluesky_store_add_barrier(barrier, async);
-    bluesky_store_async_add_notifier(barrier, finished, NULL);
-    bluesky_store_async_submit(barrier);
-    bluesky_store_async_unref(barrier);
-
     /* block->type = BLUESKY_BLOCK_CACHED; */
     bluesky_string_unref(block->data);
     block->data = NULL;
@@ -229,12 +218,12 @@ void bluesky_block_flush(BlueSkyFS *fs, BlueSkyBlock *block)
 }
 
 /* Flush all blocks in a file to stable storage. */
-void bluesky_file_flush(BlueSkyInode *inode)
+void bluesky_file_flush(BlueSkyInode *inode, BlueSkyStoreAsync *barrier)
 {
     g_return_if_fail(inode->type == BLUESKY_REGULAR);
 
     for (int i = 0; i < inode->blocks->len; i++) {
         BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock, i);
-        bluesky_block_flush(inode->fs, b);
+        bluesky_block_flush(inode->fs, b, barrier);
     }
 }
index 40f40ba..bdf01a1 100644 (file)
@@ -229,7 +229,7 @@ void bluesky_inode_start_sync(BlueSkyInode *inode, BlueSkyStoreAsync *barrier)
     BlueSkyRCStr *data = bluesky_string_new_from_gstring(buf);
 
     if (inode->type == BLUESKY_REGULAR)
-        bluesky_file_flush(inode);
+        bluesky_file_flush(inode, barrier);
 
     char key[64];
     sprintf(key, "inode-%016"PRIx64, inode->inum);