knorrie / python-btrfs

Python Btrfs module
GNU Lesser General Public License v3.0
112 stars 22 forks source link

show_usage crash on newly created filesystem #5

Closed arvidjaar closed 7 years ago

arvidjaar commented 7 years ago

Just download version 6.

10:~/src/python-btrfs-6/examples # mkfs -t btrfs /dev/sdb1
btrfs-progs v4.10.2+20170406
See http://btrfs.wiki.kernel.org for more information.

Performing full device TRIM /dev/sdb1 (5.00GiB) ...
Label:              (null)
UUID:               a50f32b1-7c10-4bd1-b5d5-7f43e9f68832
Node size:          16384
Sector size:        4096
Filesystem size:    5.00GiB
Block group profiles:
  Data:             single            8.00MiB
  Metadata:         DUP             255.94MiB
  System:           DUP               8.00MiB
SSD detected:       no
Incompat features:  extref, skinny-metadata
Number of devices:  1
Devices:
   ID        SIZE  PATH
    1     5.00GiB  /dev/sdb1

10:~/src/python-btrfs-6/examples # mount /dev/sdb1 /mnt
10:~/src/python-btrfs-6/examples # mkdir /mnt/test
10:~/src/python-btrfs-6/examples # chattr +C /mnt/test
10:~/src/python-btrfs-6/examples # ./show_dev_extents.py /mnt
devid 1 type DATA pstart 12582912 length 8388608 pend 20971520 vaddr 12582912
devid 1 type SYSTEM|DUP pstart 20971520 length 8388608 pend 29360128 vaddr 20971520
devid 1 type SYSTEM|DUP pstart 29360128 length 8388608 pend 37748736 vaddr 20971520
devid 1 type METADATA|DUP pstart 37748736 length 268369920 pend 306118656 vaddr 29360128
devid 1 type METADATA|DUP pstart 306118656 length 268369920 pend 574488576 vaddr 29360128
10:~/src/python-btrfs-6/examples # ./show_usage.py  /mnt
dev item devid 1 total bytes 5367660544 bytes used 561905664
block group vaddr 12582912 transid 7 length 8388608 flags DATA used 65536 used_pct 1
Traceback (most recent call last):
  File "./show_usage.py", line 17, in <module>
    print("    " + str(chunk))
  File "/root/src/python-btrfs-6/examples/btrfs/ctree.py", line 623, in __str__
    "num_stripes {self.num_stripes}".format(self=self)
  File "/root/src/python-btrfs-6/examples/btrfs/ctree.py", line 619, in flags_str
    return btrfs.utils.flags_str(self.flags, _block_group_flags_str_map)
AttributeError: 'Chunk' object has no attribute 'flags'
knorrie commented 7 years ago

Oh wow, this is bad. Yeah, I managed to break the str() functionality of Chunk in 3d029f46

@@ -586,7 +605,7 @@ class Chunk(object):

     @property
     def flags_str(self):
-        return btrfs.utils.block_group_flags_str(self.type)
+        return btrfs.utils.flags_str(self.flags, _block_group_flags_str_map)

     def __str__(self):
         return "chunk vaddr {self.vaddr} type {self.flags_str} length {self.length} " \

In the chunk_item struct, it's called type, not flags.

Fixed in 3106bb8, thanks for reporting the error.