{"action":"created","issue":{"url":"https://api.github.com/repos/knorrie/python-btrfs/issues/19","repository_url":"https://api.github.com/repos/knorrie/python-btrfs","labels_url":"https://api.github.com/repos/knorrie/python-btrfs/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/knorrie/python-btrfs/issues/19/comments","events_url":"https://api.github.com/repos/knorrie/python-btrfs/issues/19/events","html_url":"https://github.com/knorrie/python-btrfs/issues/19","id":421884344,"node_id":"MDU6SXNzdWU0MjE4ODQzNDQ=","number":19,"title":"btrfs-space-calculator crashes with raid5","user":{"login":"arvidjaar","id":187138,"node_id":"MDQ6VXNlcjE4NzEzOA==","avatar_url":"https://avatars3.githubusercontent.com/u/187138?v=4","gravatar_id":"","url":"https://api.github.com/users/arvidjaar","html_url":"https://github.com/arvidjaar","followers_url":"https://api.github.com/users/arvidjaar/followers","following_url":"https://api.github.com/users/arvidjaar/following{/other_user}","gists_url":"https://api.github.com/users/arvidjaar/gists{/gist_id}","starred_url":"https://api.github.com/users/arvidjaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arvidjaar/subscriptions","organizations_url":"https://api.github.com/users/arvidjaar/orgs","repos_url":"https://api.github.com/users/arvidjaar/repos","events_url":"https://api.github.com/users/arvidjaar/events{/privacy}","received_events_url":"https://api.github.com/users/arvidjaar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-03-17T05:32:13Z","updated_at":"2019-03-17T22:13:08Z","closed_at":null,"author_association":"NONE","body":"```\r\nbor@bor-Latitude-E5450:~/src/python-btrfs$ git describe HEAD\r\nv11\r\nbor@bor-Latitude-E5450:~/src/python-btrfs$ ./bin/btrfs-space-calculator -m raid0 -d raid5 3T 1T 2T\r\nTraceback (most recent call last):\r\n  File \"./bin/btrfs-space-calculator\", line 189, in <module>\r\n    main()\r\n  File \"./bin/btrfs-space-calculator\", line 158, in main\r\n    usage = btrfs.fs_usage.FsUsage(fs)\r\n  File \"/home/bor/src/python-btrfs/bin/btrfs/fs_usage.py\", line 449, in __init__\r\n    dev_extent_length = btrfs.volumes.chunk_to_dev_extent_length(chunk)\r\n  File \"/home/bor/src/python-btrfs/bin/btrfs/volumes.py\", line 212, in chunk_to_dev_extent_length\r\n    return chunk_length_to_dev_extent_length(chunk.type, chunk.num_stripes, chunk.length)\r\n  File \"/home/bor/src/python-btrfs/bin/btrfs/volumes.py\", line 192, in chunk_length_to_dev_extent_length\r\n    dev_extent_length = raw_data_bytes // num_data_stripes\r\nZeroDivisionError: integer division or modulo by zero\r\nbor@bor-Latitude-E5450:~/src/python-btrfs$ ./bin/btrfs-space-calculator -m raid0 -d raid6 3T 1T 2T\r\nTarget metadata profile: RAID0\r\nTarget data profile: RAID6\r\nMixed block groups: False\r\nTotal raw filesystem size: 5.46TiB\r\nDevice sizes:\r\n  Device 1: 2.73TiB\r\n  Device 2: 931.32GiB\r\n  Device 3: 1.82TiB\r\nMetadata to data ratio: 1:200\r\nEstimated virtual space to use for metadata: 5.00GiB\r\nEstimated virtual space to use for data: 929.66GiB\r\nTotal unallocatable raw amount: 2.73TiB\r\nUnallocatable raw bytes per device:\r\n  Device 1: 1.82TiB\r\n  Device 2: 0.00B\r\n  Device 3: 931.32GiB\r\nbor@bor-Latitude-E5450:~/src/python-btrfs$ \r\n```\r\n\r\nIt does not matter whether I use `raid5` for data or metadata. Other profiles seem to work after quick testing."},"comment":{"url":"https://api.github.com/repos/knorrie/python-btrfs/issues/comments/473720310","html_url":"https://github.com/knorrie/python-btrfs/issues/19#issuecomment-473720310","issue_url":"https://api.github.com/repos/knorrie/python-btrfs/issues/19","id":473720310,"node_id":"MDEyOklzc3VlQ29tbWVudDQ3MzcyMDMxMA==","user":{"login":"knorrie","id":627100,"node_id":"MDQ6VXNlcjYyNzEwMA==","avatar_url":"https://avatars3.githubusercontent.com/u/627100?v=4","gravatar_id":"","url":"https://api.github.com/users/knorrie","html_url":"https://github.com/knorrie","followers_url":"https://api.github.com/users/knorrie/followers","following_url":"https://api.github.com/users/knorrie/following{/other_user}","gists_url":"https://api.github.com/users/knorrie/gists{/gist_id}","starred_url":"https://api.github.com/users/knorrie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knorrie/subscriptions","organizations_url":"https://api.github.com/users/knorrie/orgs","repos_url":"https://api.github.com/users/knorrie/repos","events_url":"https://api.github.com/users/knorrie/events{/privacy}","received_events_url":"https://api.github.com/users/knorrie/received_events","type":"User","site_admin":false},"created_at":"2019-03-17T22:13:08Z","updated_at":"2019-03-17T22:13:08Z","author_association":"OWNER","body":"Thanks for the report.\r\n\r\nThe way this space calculator works is a little bit naughty. By constructing some fake replacements for the official Chunk, Stripe etc classes, we fool the usage report module and have it believe it's looking at an actual filesystem. The input in those fake objects is rather simple, and not completely correct. (A 1 byte chunk etc...) This is fragile, because FakeChunk has num_stripes 1 and then RAID5 subtracts the amount of parity, then it's 0 and BOOM. Funny enough, raid6 makes it end up as -1.\r\n    \r\nI just looked back at my bash history, grepping for all the options I ever used while writing this, and I see a lot of raid6, raid1 and other things, but no raid5. Great.\r\n\r\nI guess starting to add proper tests will full code coverage and testing a lot of inputs on scripts is not a luxury at this point. I might start doing that during this year, but I'll first continue on the turorial.\r\n\r\nAnyway, this can be quick fixed by just putting any number >=3 in that place, but it doesn't feel right, because this type of bug will appear in the future again.\r\n\r\nThe other way to fix it, is to have the usage report system accept some extra options, like forcibly setting target profiles (this is why the fake chunk exists, to have it detect target profile)."}}
{"actor":{"display_login":"knorrie"}}