[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#769576: linux: Btrfs goes forced readonly when qgroup already exists



Source: linux
Version: 3.16.3-2~bpo70+1
Severity: important
Tags: patch, upstream

Dear Maintainers,

[This bug is actually upstream, and I originally intended to send this
report upstream as well, but 3.16 has gone EOL before I got the time to
do this.  I hope the Debian maintainers will be able to tackle this
instead.]

Currently Btrfs does not destroy qgroups when the corresponding
subvolume is deleted.  Since Linux 3.16, it looks like Btrfs in some
cases tries to reuse subvolume IDs.  It then tries to create a qgroup
that already exists, as a consequence the filesystem is forced to
readonly.

The number of users effected by this is small, I think, because you must
use a Btrfs filesystem and enable quota on it (by default they're
disabled).  Nevertheless, for those that are affected, the system can
become practically unusable.  In my case, the filesystem went readonly
within an hour of every boot-up, when the backup program tried to create
snapshots.

There is a patch for this bug upstream [1], which has been applied to
3.17 [2].  As far as I know, it wasn't applied to 3.16.  I have not
tried this patch for reasons of time, but I can if you want me to.  The
patch is also included at the end of this mail.

 [1] https://patchwork.kernel.org/patch/4739211/
 [2] https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=fe9133f10ca56e54c5f5075a802bc08e61ad8456

This is what I tried to reproduce the bug on a 3.16 kernel:

$ sudo btrfs sub snap / /test
Create a snapshot of '/' in '//test'
$ sudo btrfs sub del /test
Transaction commit: none (default)
Delete subvolume '//test'
$ sudo reboot
[*snip*]
$ sudo btrfs sub snap / /test
Create a snapshot of '/' in '//test'
ERROR: cannot snapshot '/' - File exists

Here are the details of the kernel and the Btrfs utilities, and the
dmesg output generated when doing the above procedure:

$ uname -a
Linux andromeda 3.16-0.bpo.2-amd64 #1 SMP Debian 3.16.3-2~bpo70+1 (2014-09-21) x86_64 GNU/Linux
$ /sbin/btrfs --version
Btrfs v3.14.1
$ sudo btrfs fi show
Label: 'Root'  uuid: 38dcce9b-0514-4690-b20c-cd203de41fce
    Total devices 1 FS bytes used 107.49GiB
    devid    1 size 465.70GiB used 117.04GiB path /dev/disk/by-uuid/38dcce9b-0514-4690-b20c-cd203de41fce

Btrfs v3.14.1
$ sudo btrfs fi df /
Data, single: total=113.01GiB, used=106.33GiB
System, DUP: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00
Metadata, DUP: total=2.00GiB, used=1.16GiB
Metadata, single: total=8.00MiB, used=0.00
unknown, single: total=400.00MiB, used=0.00
$ dmesg
[*snip*]
[  115.885014] ------------[ cut here ]------------
[  115.885042] WARNING: CPU: 2 PID: 3426 at /build/linux-nBoDV9/linux-3.16.3/fs/btrfs/super.c:259 __btrfs_abort_transaction+0x5f/0x140 [btrfs]()
[  115.885043] BTRFS: Transaction aborted (error -17)
[  115.885044] Modules linked in: ppdev lp nfsd auth_rpcgss oid_registry nfs_acl nfs lockd fscache sunrpc ctr ccm ext4 crc16 mbcache jbd2 arc4 snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic ath9k ath9k_common ath9k_hw ath i915 snd_hda_intel pcspkr psmouse evdev serio_raw iTCO_wdt iTCO_vendor_support parport_pc mac80211 cfg80211 intel_powerclamp video parport rfkill snd_hda_controller tpm_infineon drm_kms_helper snd_hda_codec drm i2c_algo_bit asus_atk0110 tpm_tis tpm snd_hwdep lpc_ich mfd_core snd_pcm snd_seq snd_seq_device snd_timer mei_me mei acpi_cpufreq i2c_i801 i2c_core kvm_intel processor snd kvm thermal_sys button soundcore btrfs xor raid6_pq dm_crypt dm_mod ses enclosure usb_storage hid_generic usbhid hid sg sr_mod cdrom sd_mod crc_t10dif crct10dif_pclmul crct10dif_common crc32_pclmul crc32c_intel ata_generic ghash_clmulni_intel aesni_intel aes_x86_64 lrw gf128mul glue_helper ablk_helper cryptd ata_piix pata_via libata ehci_pci ehci_hcd r8169 scsi_mod mii usbcore usb_common
[  115.885095] CPU: 2 PID: 3426 Comm: btrfs Not tainted 3.16-0.bpo.2-amd64 #1 Debian 3.16.3-2~bpo70+1
[  115.885096] Hardware name: System manufacturer System Product Name/P7H55-M, BIOS 1101    08/18/2010
[  115.885097]  0000000000000000 ffffffffa02d7a28 ffffffff8153ff96 ffff8800ccaef9f8
[  115.885099]  ffffffff8106be4c 00000000ffffffef ffff88007f8d4800 ffff8800c81d6020
[  115.885100]  000000000000050d ffffffffa02d4080 ffffffff8106bf3a ffffffffa02d7b08
[  115.885102] Call Trace:
[  115.885110]  [<ffffffff8153ff96>] ? dump_stack+0x41/0x51
[  115.885114]  [<ffffffff8106be4c>] ? warn_slowpath_common+0x8c/0xc0
[  115.885116]  [<ffffffff8106bf3a>] ? warn_slowpath_fmt+0x4a/0x50
[  115.885124]  [<ffffffffa0248906>] ? btrfs_run_delayed_refs+0x246/0x2a0 [btrfs]
[  115.885128]  [<ffffffffa022ae0f>] ? __btrfs_abort_transaction+0x5f/0x140 [btrfs]
[  115.885136]  [<ffffffffa02581ff>] ? create_pending_snapshot+0x60f/0xa00 [btrfs]
[  115.885148]  [<ffffffffa0258679>] ? create_pending_snapshots+0x89/0xa0 [btrfs]
[  115.885160]  [<ffffffffa025996a>] ? btrfs_commit_transaction+0x35a/0xa10 [btrfs]
[  115.885170]  [<ffffffffa028db83>] ? btrfs_mksubvol.isra.62+0x4d3/0x4f0 [btrfs]
[  115.885174]  [<ffffffff810af070>] ? __wake_up_sync+0x20/0x20
[  115.885181]  [<ffffffffa028dd5e>] ? btrfs_ioctl_snap_create_transid+0x1be/0x1d0 [btrfs]
[  115.885188]  [<ffffffffa028df15>] ? btrfs_ioctl_snap_create_v2+0x115/0x150 [btrfs]
[  115.885195]  [<ffffffffa029109b>] ? btrfs_ioctl+0x10bb/0x1ea0 [btrfs]
[  115.885198]  [<ffffffff81392010>] ? pty_write+0x60/0x70
[  115.885199]  [<ffffffff810aed8e>] ? remove_wait_queue+0x1e/0x70
[  115.885202]  [<ffffffff8105beda>] ? __do_page_fault+0x29a/0x530
[  115.885204]  [<ffffffff810a5e81>] ? put_prev_entity+0x81/0x290
[  115.885206]  [<ffffffff810a222a>] ? set_next_entity+0x3a/0x80
[  115.885208]  [<ffffffff811cc796>] ? do_vfs_ioctl+0x86/0x4e0
[  115.885211]  [<ffffffff8154267e>] ? __schedule+0x2de/0x770
[  115.885213]  [<ffffffff811babfc>] ? vfs_write+0x17c/0x1f0
[  115.885214]  [<ffffffff811ccc91>] ? SyS_ioctl+0xa1/0xc0
[  115.885216]  [<ffffffff81547f4e>] ? device_not_available+0x1e/0x30
[  115.885218]  [<ffffffff8154646d>] ? system_call_fast_compare_end+0x10/0x15
[  115.885219] ---[ end trace 06f56799d100cd01 ]---
[  115.885221] BTRFS: error (device dm-0) in create_pending_snapshot:1293: errno=-17 Object already exists
[  115.885223] BTRFS info (device dm-0): forced readonly
[  115.885226] BTRFS warning (device dm-0): Skipping commit of aborted transaction.
[  115.885227] BTRFS: error (device dm-0) in cleanup_transaction:1571: errno=-17 Object already exists

(I know, I'm using a backported kernel, but since this is an upstream
bug, it is most likely also present in the kernel that will be shipped
with jessie.)

When I repeat the procedure with a 3.14 kernel, everything goes fine.
Here are the details of that kernel:

$ uname -a
Linux andromeda 3.14-0.bpo.2-amd64 #1 SMP Debian 3.14.15-2~bpo70+1 (2014-08-21) x86_64 GNU/Linux

This is the upstream patch I talked about:

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index b497498..8477d33 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -551,9 +551,15 @@  static int add_qgroup_item(struct btrfs_trans_handle *trans,
    key.type = BTRFS_QGROUP_INFO_KEY;
    key.offset = qgroupid;
 
+       /*
+        * Avoid a transaction abort by catching -EEXIST here. In that
+        * case, we proceed by re-initializing the existing structure
+        * on disk.
+        */
+
    ret = btrfs_insert_empty_item(trans, quota_root, path, &key,
                      sizeof(*qgroup_info));
-       if (ret)
+       if (ret && ret != -EEXIST)
        goto out;
 
    leaf = path->nodes[0];
@@ -572,7 +578,7 @@  static int add_qgroup_item(struct btrfs_trans_handle *trans,
    key.type = BTRFS_QGROUP_LIMIT_KEY;
    ret = btrfs_insert_empty_item(trans, quota_root, path, &key,
                      sizeof(*qgroup_limit));
-       if (ret)
+       if (ret && ret != -EEXIST)
        goto out;
 
    leaf = path->nodes[0];

Sorry for the length of this report, I hope it contains all you need.  I
also hope I filed this bug correctly, this is my first report.  Please
tell me if I did something wrong.  If you need any more information, or
if you want me to test something, please ask.

-- System Information:
Debian Release: 7.7
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.14-0.bpo.2-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_GB.utf8, LC_CTYPE=en_GB.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash


Reply to: