How to fix btrfs extent issue

2

1

I think I have been hit by a known bug in btrfs:

https://www.spinics.net/lists/linux-btrfs/msg60984.html

Certainly, the error messages seem similar. If it is the same issue, it seems somewhat unfortunate that the fix for a 2 year old issue hasn't been ported into the V4.9 stable kernel (which is what Debian 9 uses)

I am now in the situation where one of the filesystem inodes has extent problems (as reported by btrfs check):

root 257 inode 2607184 errors 100, file extent discount
Found file extent holes:
       start: 0, len: 81920

It seems there isn't much advice or documentation on how to get out of such a situation (fortunately I do have backups of the filesystem concerned, so worst case could reformat and restore)

It seems btrfs check --repair just loops printing the same error over and over, without actually fixing it.

Is there any way to fix the existing filesystem, or am I best to recreate it and restore the backup?

Michael Firth

Posted 2018-10-01T16:06:34.710

Reputation: 95

Thanks - I went for a similar (but slightly more extreme) option of deleting the subvolume with the problems in. It seems freeing up the inode made the file system check cleanly. If you want to make an answer based on this, I will vote it as correct – Michael Firth – 2018-10-01T18:24:48.280

Answers

4

I think root 257 refers to the subvolume ID, then inode 2607184 points to the problematic inode. I would try to remove (unlink) every path linked to the inode.

  1. Mount the subvolume:

    mount /dev/sdXN -o subvolid=257 /mnt/mountpoint
    
  2. Locate every entry with matching inode number:

    find /mnt/mountpoint -xdev -inum 2607184
    
  3. Investigate the objects. Hopefully you can afford to delete them.

    • (I'm not sure if it may be a directory in your case). If it's a directory, I suspect its listing may be incomplete.
      1. Move its contents (if any) to another, new directory (create it with the same ownership, permissions maybe); remove the old directory; mv the new directory to the old name.
      2. Compare to your backup, restore missing objects.
    • If it's one or more files –
      1. Remove them all.
      2. Restore the files from backup.
  4. Unmount:

    umount /mnt/mountpoint
    
  5. Check the filesystem. The problematic inode should be no more.


Alternatively you can delete the entire subvolume. This seems like overkill, yet it should get rid of the problematic inode.

  1. Mount the root of the filesystem:

    mount /dev/sdXN -o subvol=/ /mnt/mountpoint
    
  2. List subvolumes:

    btrfs subvolume list /mnt/mountpoint
    

    and locate the one with ID 257.

  3. Delete the subvolume:

    btrfs subvolume delete -c /mnt/mountpoint/path/to/the/subvolume/with/ID/257
    
  4. Unmount:

    umount /mnt/mountpoint
    
  5. Check the filesystem. The problematic inode should be no more.

  6. Restore your data from backup.

Kamil Maciorowski

Posted 2018-10-01T16:06:34.710

Reputation: 38 429

As it was newly created files that had triggered the bug (a git checkout), and I have periodic snapshot creation for use with Samba, I eventually accepted rolling back by 20 minutes in time and deleted the subvolume. btrfs check now reports no errors, hopefully there is no underlying corruption that will bite later – Michael Firth – 2018-10-02T08:32:35.367

I had new files corrupted (filled with zeros) until I discovered the issue. btrfs check ... seems to have fixed it. I don't know yet what files are corrupted/lost :-( – zoechi – 2019-07-15T17:31:11.763

Seems the USB hub used to connect the SSDs caused this. – zoechi – 2019-07-18T14:10:52.797