diff options
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r-- | fs/btrfs/transaction.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index f0f03121b7b2..bf7eef67ba0b 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -8,6 +8,8 @@ static int total_trans = 0; | |||
8 | extern struct kmem_cache *btrfs_trans_handle_cachep; | 8 | extern struct kmem_cache *btrfs_trans_handle_cachep; |
9 | extern struct kmem_cache *btrfs_transaction_cachep; | 9 | extern struct kmem_cache *btrfs_transaction_cachep; |
10 | 10 | ||
11 | static struct workqueue_struct *trans_wq; | ||
12 | |||
11 | #define BTRFS_ROOT_TRANS_TAG 0 | 13 | #define BTRFS_ROOT_TRANS_TAG 0 |
12 | 14 | ||
13 | #define TRANS_MAGIC 0xE1E10E | 15 | #define TRANS_MAGIC 0xE1E10E |
@@ -44,6 +46,7 @@ static int join_transaction(struct btrfs_root *root) | |||
44 | cur_trans->in_commit = 0; | 46 | cur_trans->in_commit = 0; |
45 | cur_trans->use_count = 1; | 47 | cur_trans->use_count = 1; |
46 | cur_trans->commit_done = 0; | 48 | cur_trans->commit_done = 0; |
49 | cur_trans->start_time = get_seconds(); | ||
47 | list_add_tail(&cur_trans->list, &root->fs_info->trans_list); | 50 | list_add_tail(&cur_trans->list, &root->fs_info->trans_list); |
48 | init_bit_radix(&cur_trans->dirty_pages); | 51 | init_bit_radix(&cur_trans->dirty_pages); |
49 | } | 52 | } |
@@ -350,3 +353,60 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, | |||
350 | return ret; | 353 | return ret; |
351 | } | 354 | } |
352 | 355 | ||
356 | void btrfs_transaction_cleaner(struct work_struct *work) | ||
357 | { | ||
358 | struct btrfs_fs_info *fs_info = container_of(work, | ||
359 | struct btrfs_fs_info, | ||
360 | trans_work.work); | ||
361 | |||
362 | struct btrfs_root *root = fs_info->tree_root; | ||
363 | struct btrfs_transaction *cur; | ||
364 | struct btrfs_trans_handle *trans; | ||
365 | unsigned long now; | ||
366 | unsigned long delay = HZ * 30; | ||
367 | int ret; | ||
368 | |||
369 | printk("btrfs transaction cleaner\n"); | ||
370 | mutex_lock(&root->fs_info->fs_mutex); | ||
371 | mutex_lock(&root->fs_info->trans_mutex); | ||
372 | cur = root->fs_info->running_transaction; | ||
373 | if (!cur) { | ||
374 | mutex_unlock(&root->fs_info->trans_mutex); | ||
375 | goto out; | ||
376 | } | ||
377 | now = get_seconds(); | ||
378 | if (now < cur->start_time || now - cur->start_time < 30) { | ||
379 | mutex_unlock(&root->fs_info->trans_mutex); | ||
380 | delay = HZ * 5; | ||
381 | goto out; | ||
382 | } | ||
383 | mutex_unlock(&root->fs_info->trans_mutex); | ||
384 | printk("forcing commit\n"); | ||
385 | trans = btrfs_start_transaction(root, 1); | ||
386 | ret = btrfs_commit_transaction(trans, root); | ||
387 | out: | ||
388 | mutex_unlock(&root->fs_info->fs_mutex); | ||
389 | btrfs_transaction_queue_work(root, delay); | ||
390 | } | ||
391 | |||
392 | void btrfs_transaction_queue_work(struct btrfs_root *root, int delay) | ||
393 | { | ||
394 | queue_delayed_work(trans_wq, &root->fs_info->trans_work, delay); | ||
395 | } | ||
396 | |||
397 | void btrfs_transaction_flush_work(struct btrfs_root *root) | ||
398 | { | ||
399 | cancel_rearming_delayed_workqueue(trans_wq, &root->fs_info->trans_work); | ||
400 | flush_workqueue(trans_wq); | ||
401 | } | ||
402 | |||
403 | void __init btrfs_init_transaction_sys(void) | ||
404 | { | ||
405 | trans_wq = create_workqueue("btrfs"); | ||
406 | } | ||
407 | |||
408 | void __exit btrfs_exit_transaction_sys(void) | ||
409 | { | ||
410 | destroy_workqueue(trans_wq); | ||
411 | } | ||
412 | |||