BlueSkyCloudLog *bluesky_cloudlog_new(BlueSkyFS *fs, const BlueSkyCloudID *id);
gchar *bluesky_cloudlog_id_to_string(BlueSkyCloudID id);
BlueSkyCloudID bluesky_cloudlog_id_from_string(const gchar *idstr);
+void bluesky_cloudlog_threads_init(BlueSkyFS *fs);
void bluesky_cloudlog_ref(BlueSkyCloudLog *log);
void bluesky_cloudlog_unref(BlueSkyCloudLog *log);
+void bluesky_cloudlog_unref_delayed(BlueSkyCloudLog *log);
void bluesky_cloudlog_erase(BlueSkyCloudLog *log);
void bluesky_cloudlog_stats_update(BlueSkyCloudLog *log, int type);
void bluesky_cloudlog_sync(BlueSkyCloudLog *log);
/* The inode map, which maps inode numbers to the location of the most
* recent version. */
GSequence *inode_map;
+
+ /* Queue for asynchronous cloudlog unrefs, where needed. */
+ GAsyncQueue *unref_queue;
} BlueSkyFS;
/* Inode number of the root directory. */
}
}
+/* For locking reasons cloudlog unrefs may sometimes need to be performed in
+ * the future. We launch a thread for handling these delayed unreference
+ * requests. */
+static gpointer cloudlog_unref_thread(gpointer q)
+{
+ GAsyncQueue *queue = (GAsyncQueue *)q;
+
+ while (TRUE) {
+ BlueSkyCloudLog *item = (BlueSkyCloudLog *)g_async_queue_pop(queue);
+ bluesky_cloudlog_unref(item);
+ }
+
+ return NULL;
+}
+
+void bluesky_cloudlog_unref_delayed(BlueSkyCloudLog *log)
+{
+ if (log != NULL)
+ g_async_queue_push(log->fs->unref_queue, log);
+}
+
+void bluesky_cloudlog_threads_init(BlueSkyFS *fs)
+{
+ fs->unref_queue = g_async_queue_new();
+ g_thread_create(cloudlog_unref_thread, fs->unref_queue, FALSE, NULL);
+}
+
/* Erase the information contained within the in-memory cloud log
* representation. This does not free up the item itself, but frees the data
* and references to other log items and resets the type back to unknown. If
void bluesky_cloudlog_insert(BlueSkyCloudLog *log)
{
g_mutex_lock(log->fs->lock);
- bluesky_cloudlog_insert(log);
+ bluesky_cloudlog_insert_locked(log);
g_mutex_unlock(log->fs->lock);
}
}
if (action != 0) {
- bluesky_cloudlog_unref(range->serialized);
+ bluesky_cloudlog_unref_delayed(range->serialized);
range->serialized = NULL;
}
fs->log_state = g_new0(BlueSkyCloudLogState, 1);
fs->log_state->data = g_string_new("");
+ bluesky_cloudlog_threads_init(fs);
+
return fs;
}
g_assert(data3 + len3 - data <= len);
item->type = header->type - '0';
item->inum = GUINT64_FROM_LE(header->inum);
+ } else {
+ g_warning("Deserializing garbage cloud log item!");
+ return;
}
BlueSkyFS *fs = item->fs;