]> git.karo-electronics.de Git - karo-tx-linux.git/commit
Btrfs: fix orphan transaction on the freezed filesystem
authorMiao Xie <miaox@cn.fujitsu.com>
Thu, 20 Sep 2012 07:54:00 +0000 (01:54 -0600)
committerChris Mason <chris.mason@fusionio.com>
Thu, 4 Oct 2012 13:40:06 +0000 (09:40 -0400)
commite6900f2aa877d5ada0f97c979b2c3d8bd7fcb31e
treea01867a6df895fcc0da85dbaa9d3c9ec91348ac0
parenta0a58775c1aaf9307c2ff2812d7e1cd9cedea81a
Btrfs: fix orphan transaction on the freezed filesystem

With the following debug patch:

 static int btrfs_freeze(struct super_block *sb)
 {
+  struct btrfs_fs_info *fs_info = btrfs_sb(sb);
+ struct btrfs_transaction *trans;
+
+ spin_lock(&fs_info->trans_lock);
+ trans = fs_info->running_transaction;
+ if (trans) {
+ printk("Transid %llu, use_count %d, num_writer %d\n",
+ trans->transid, atomic_read(&trans->use_count),
+ atomic_read(&trans->num_writers));
+ }
+ spin_unlock(&fs_info->trans_lock);
  return 0;
 }

I found there was a orphan transaction after the freeze operation was done.

It is because the transaction may not be committed when the transaction handle
end even though it is the last handle of the current transaction. This design
avoid committing the transaction frequently, but also introduce the above
problem.

So I add btrfs_attach_transaction() which can catch the current transaction
and commit it. If there is no transaction, it will return ENOENT, and do not
anything.

This function also can be used to instead of btrfs_join_transaction_freeze()
because it don't increase the writer counter and don't start a new transaction,
so it also can fix the deadlock between sync and freeze.

Besides that, it is used to instead of btrfs_join_transaction() in
transaction_kthread(), because if there is no transaction, the transaction
kthread needn't anything.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
fs/btrfs/disk-io.c
fs/btrfs/super.c
fs/btrfs/transaction.c
fs/btrfs/transaction.h