X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Finode.c;h=26967136cf18d6f03bd0fac52e19d542367e4448;hb=83fd6b61a6e092a22d4d5e59ed95f05f5e287f11;hp=9d72f4d9c66141f1035f8a7289de5700f2bfad42;hpb=8ec7f79f834ff8c3493b1bbdd63314d276786aa4;p=bluesky.git diff --git a/bluesky/inode.c b/bluesky/inode.c index 9d72f4d..2696713 100644 --- a/bluesky/inode.c +++ b/bluesky/inode.c @@ -55,6 +55,9 @@ void bluesky_inode_update_ctime(BlueSkyInode *inode, gboolean update_mtime) bluesky_list_unlink(&inode->fs->accessed_list, inode->accessed_list); inode->accessed_list = bluesky_list_prepend(&inode->fs->accessed_list, inode); g_mutex_unlock(inode->fs->lock); + + bluesky_cloudlog_unref(inode->committed_item); + inode->committed_item = NULL; } /* Unfortunately a glib hash table is only guaranteed to be able to store @@ -88,6 +91,7 @@ BlueSkyFS *bluesky_new_fs(gchar *name) fs->next_inum = BLUESKY_ROOT_INUM + 1; fs->store = bluesky_store_new("file"); fs->flushd_lock = g_mutex_new(); + fs->flushd_cond = g_cond_new(); fs->locations = g_hash_table_new(bluesky_cloudlog_hash, bluesky_cloudlog_equal); @@ -173,8 +177,8 @@ void bluesky_inode_unref(BlueSkyInode *inode) if (b->type == BLUESKY_BLOCK_DIRTY) { g_error("Deleting an inode with dirty file data!"); } - bluesky_cloudlog_unref(b->cloudref); - bluesky_string_unref(b->data); + bluesky_cloudlog_unref(b->ref); + bluesky_string_unref(b->dirty); } g_array_unref(inode->blocks); break; @@ -292,46 +296,29 @@ void bluesky_insert_inode(BlueSkyFS *fs, BlueSkyInode *inode) void bluesky_inode_start_sync(BlueSkyInode *inode) { GList *log_items = NULL; - BlueSkyFS *fs = inode->fs; if (inode->type == BLUESKY_REGULAR) bluesky_file_flush(inode, &log_items); - GString *buf = g_string_new(""); - bluesky_serialize_inode(buf, inode); - BlueSkyRCStr *data = bluesky_string_new_from_gstring(buf); - - char key[64]; - sprintf(key, "inode-%016"PRIx64, inode->inum); - - BlueSkyCloudLog *cloudlog = bluesky_cloudlog_new(fs); - cloudlog->type = LOGTYPE_INODE; - cloudlog->inum = inode->inum; - cloudlog->data = data; - bluesky_string_ref(data); - - if (inode->type == BLUESKY_REGULAR) { - for (int i = 0; i < inode->blocks->len; i++) { - BlueSkyBlock *b = &g_array_index(inode->blocks, BlueSkyBlock, i); - if (b->type == BLUESKY_BLOCK_CACHED - || b->type == BLUESKY_BLOCK_REF) - { - BlueSkyCloudID id = b->cloudref->id; - g_array_append_val(cloudlog->pointers, id); - } - } - } + BlueSkyCloudLog *cloudlog = bluesky_serialize_inode(inode); - if (inode->committed_item != NULL) - bluesky_cloudlog_unref(inode->committed_item); + bluesky_cloudlog_unref(inode->committed_item); inode->committed_item = cloudlog; bluesky_cloudlog_sync(cloudlog); + bluesky_cloudlog_ref(cloudlog); log_items = g_list_prepend(log_items, cloudlog); - bluesky_cloudlog_insert(cloudlog); /* Wait for all log items to be committed to disk. */ bluesky_log_finish_all(log_items); + + /* Mark the inode as clean */ + inode->change_commit = inode->change_count; + inode->change_time = 0; + g_mutex_lock(inode->fs->lock); + bluesky_list_unlink(&inode->fs->unlogged_list, inode->unlogged_list); + inode->unlogged_list = NULL; + g_mutex_unlock(inode->fs->lock); } /* Write back an inode and all associated data and wait for completion. Inode