nachoparker / btrfs-du

Easily print BTRFS subvolume/snapshot disk usage
GNU General Public License v3.0
112 stars 17 forks source link

Legacy `btrfs` gives `btrfs qgroup show: unrecognized option '--raw'` #4

Closed jpluimers closed 6 years ago

jpluimers commented 6 years ago

Another legacy btrfs thing: btrfs qgroup show: unrecognized option '--raw'

Full output:

# btrfs --version
Btrfs v3.12+20131125
# ./btrfs-du /
btrfs qgroup show: unrecognized option '--raw'
usage: btrfs qgroup show -pcreFf [--sort=qgroupid,rfer,excl,max_rfer,max_excl] <path>

    Show subvolume quota groups.

    -p      print parent qgroup id
    -c      print child qgroup id
    -r      print max referenced size of qgroup
    -e      print max exclusive size of qgroup
    -F      list all qgroups which impact the given path(include ancestral qgroups)
    -f      list all qgroups which impact the given path(exclude ancestral qgroups)
    --sort=qgroupid,rfer,excl,max_rfer,max_excl
            list qgroups in order of qgroupid,rfer,max_rfer or max_excl
            you can use '+' or '-' in front of each item.
            (+:ascending, -:descending, ascending default)

Subvolume                                                    Total      Exclusive  ID        
─────────────────────────────────────────────────────────────────────────────────────────
tmp                                                          subvolume  quota      256       
./btrfs-du: line 75: EXCL_TOTAL +  : syntax error: operand expected (error token is "+  ")
─────────────────────────────────────────────────────────────────────────────────────────
                                                                Total exclusive data: 

However, for this version, it looks like the default output already is like --raw:

# btrfs qgroup show /
qgroupid rfer       excl      
-------- ----       ----      
0/5      3235164160 62259200  
0/256    24576      24576     
0/258    4096       4096      
0/259    135168     135168    
0/260    4096       4096      
0/261    208527360  208527360 
0/262    484941824  484941824 
0/263    4096       4096      
0/265    1343488    1343488   
0/21711  3214688256 106496    
0/21712  3214688256 94208     
0/21713  3214688256 94208     
0/21714  3214688256 94208     
0/21715  3214688256 94208     
0/21716  3214688256 94208     
0/21717  3214688256 94208     
0/21718  3214688256 94208     
0/21719  3214688256 90112     
0/21720  3214688256 90112     
0/21721  3214688256 94208     
0/21722  3214688256 94208     
0/21723  3214688256 94208     
0/21724  3214688256 94208     
0/21725  3214688256 94208     
0/21726  3224350720 93044736  
0/21731  3235061760 524288    
0/21732  3235061760 450560    
0/21733  3235119104 106246144 
0/21873  3238502400 74907648  
0/21891  3238760448 21725184  
0/21896  3217539072 61440     
0/21897  3217539072 49152     
0/21898  3217539072 45056     
0/21899  3217539072 45056     
0/21900  3217539072 45056     
0/21901  3217539072 45056     
0/21902  3217539072 53248     
0/21927  3238608896 75386880  
0/21940  3235270656 74199040  
0/21964  3235299328 21319680  
0/21968  3235364864 21147648  
0/21969  3235364864 21143552  
0/21970  3235364864 21139456  
0/21971  3235364864 21139456  
0/21972  3235364864 21143552  
0/21973  3235368960 21143552  
0/21974  3235368960 21147648  
0/21975  3235368960 21164032  
0/21976  3235147776 21221376  
0/21977  3235295232 21192704  
0/21978  3235319808 10752000 

Note that this version also lacks support for --si:

# btrfs qgroup show --si --sort=qgroupid /
btrfs qgroup show: unrecognized option '--si'
usage: btrfs qgroup show -pcreFf [--sort=qgroupid,rfer,excl,max_rfer,max_excl] <path>

    Show subvolume quota groups.

    -p      print parent qgroup id
    -c      print child qgroup id
    -r      print max referenced size of qgroup
    -e      print max exclusive size of qgroup
    -F      list all qgroups which impact the given path(include ancestral qgroups)
    -f      list all qgroups which impact the given path(exclude ancestral qgroups)
    --sort=qgroupid,rfer,excl,max_rfer,max_excl
            list qgroups in order of qgroupid,rfer,max_rfer or max_excl
            you can use '+' or '-' in front of each item.
            (+:ascending, -:descending, ascending default)
nachoparker commented 6 years ago

I see... that's a pretty old one!

is that on openSUSE? My Debian Stretch is in 4.7.3, and my Arch is on 4.13

jpluimers commented 6 years ago

Indeed (: It is an openSUSE 13.2 installation that I want to phase out next year.

nachoparker commented 6 years ago

well, I don't have such old version in my systems, so if anybody wants to adapt this, PRs are welcome

jpluimers commented 6 years ago

@nachoparker I'd need some help as I'm far from fluent in writing bash.

It'd basically would come down to finding out which features the btrfs supports, then adopting the commands because of that.

Can you help me with some code-reviews?

nachoparker commented 6 years ago

sure,

you can either parse the version ( output of btrfs version ), or just check for an error message, like here

jpluimers commented 6 years ago

@nachoparker thanks. It doesn't help much that btrfs --version has changed the format over time. On my systems, I see these:

btrfs-progs v4.13.3
Btrfs v3.12+20131125

What do you see on your systems?

nachoparker commented 6 years ago

the first type in all my versions

jpluimers commented 6 years ago

Thanks.

In the mean time, I tried checking on features, but the comparisons fail both using the bash one and the grep one.

Do you have an idea why?

Fragment that I changed:

_btrfs_qgroup_show="btrfs qgroup show --si --sort=qgroupid \""$LOCATION\"" 2>&1"
echo "Command: $_btrfs_qgroup_show"

# if we just enabled quota, might have to wait for rescan
#OUT=$( btrfs qgroup show --si --sort=qgroupid "$LOCATION" 2>&1 )
OUT=$( $_btrfs_qgroup_show )
echo "$OUT" 

if [[ "$OUT" == *"unrecognized option"* ]]; then 
  echo "INFO: Legacy btrfs version; trying 'btrfs qgroup show' without '--si'..." 
  _btrfs_qgroup_show="btrfs qgroup show --sort=qgroupid \""$LOCATION\"" 2>&1" 
fi     

## This check fails to recognise the failure:    
grep -q "unrecognized option" <<< "$OUT" && {
  echo "INFO: Legacy btrfs version; trying 'btrfs qgroup show' without '--si'..."
  _btrfs_qgroup_show="btrfs qgroup show --sort=qgroupid \""$LOCATION\"" 2>&1"
}

echo "Command: $_btrfs_qgroup_show"
OUT=$( $_btrfs_qgroup_show )
echo "$OUT"

exit 1

Output:

# ./btrfs-du
Command: btrfs qgroup show --si --sort=qgroupid "/" 2>&1
btrfs qgroup show: unrecognized option '--si'
usage: btrfs qgroup show -pcreFf [--sort=qgroupid,rfer,excl,max_rfer,max_excl] <path>

    Show subvolume quota groups.

    -p      print parent qgroup id
    -c      print child qgroup id
    -r      print max referenced size of qgroup
    -e      print max exclusive size of qgroup
    -F      list all qgroups which impact the given path(include ancestral qgroups)
    -f      list all qgroups which impact the given path(exclude ancestral qgroups)
    --sort=qgroupid,rfer,excl,max_rfer,max_excl
            list qgroups in order of qgroupid,rfer,max_rfer or max_excl
            you can use '+' or '-' in front of each item.
            (+:ascending, -:descending, ascending default)

Command: btrfs qgroup show --si --sort=qgroupid "/" 2>&1
btrfs qgroup show: unrecognized option '--si'
usage: btrfs qgroup show -pcreFf [--sort=qgroupid,rfer,excl,max_rfer,max_excl] <path>

    Show subvolume quota groups.

    -p      print parent qgroup id
    -c      print child qgroup id
    -r      print max referenced size of qgroup
    -e      print max exclusive size of qgroup
    -F      list all qgroups which impact the given path(include ancestral qgroups)
    -f      list all qgroups which impact the given path(exclude ancestral qgroups)
    --sort=qgroupid,rfer,excl,max_rfer,max_excl
            list qgroups in order of qgroupid,rfer,max_rfer or max_excl
            you can use '+' or '-' in front of each item.
            (+:ascending, -:descending, ascending default)
jpluimers commented 6 years ago

Found the cause for the last question: you cannot have the 2>&1 bit within a string and later execute it.

jpluimers commented 6 years ago

@nachoparker can you shoot some comments at https://github.com/jpluimers/btrfs-du/commit/da51a999897bc6e0c0f1c9523bfbd8ad866e9152 ???

nachoparker commented 6 years ago

on it