Permalink
Browse files

defrag-dirtree.sh: support for defragging all btrfs filesystems on host

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
  • Loading branch information...
1 parent dd6be60 commit 8f910c571a0ccff91757cb5a9587e7ec03b23ac5 @trofi committed Nov 1, 2012
Showing with 32 additions and 12 deletions.
  1. +32 −12 gentoo/defrag-dirtree.sh
@@ -1,22 +1,42 @@
#!/bin/sh
-do_defrag() {
+do_defrag_path() {
path=$1
- set -- sudo btrfs fi defrag $path
+ set -- sudo btrfs fi defrag "${path}"
echo "RUN: $@"
time "$@"
}
-root=/
+do_defrag_filesystem() {
+ root=$1
-sudo btrfs su li $root | while read args
+ echo "found btrfs mount on: ${root}"
+
+ sudo btrfs su li "${root}" | while read subvol_line
+ do
+ # parse something like that:
+ # #1 #2 #3 #4 #5 #6 #7 #8 #9
+ # ID 498 gen 703177 top level 5 path subvolumes/var_tmp
+ # ID 517 gen 658092 top level 5 path subvolumes/home_prefix
+ set -- ${subvol_line}
+ subvol_path=${root}$9
+ do_defrag_path "${subvol_path}"
+ done
+
+ do_defrag_path "${root}"
+}
+
+while read mounts_line
do
+ set -- ${mounts_line}
+
# parse something like that:
- # #1 #2 #3 #4 #5 #6 #7
- # ID 673 top level 5 path subvolumes/var_tmp
- set -- $args
- subvol_path=$root$7
- do_defrag "$subvol_path"
-done
-
-do_defrag "$root"
+ # #1 #2 #3 #4
+ # /dev/sda5 / btrfs rw,noatime,nodiratime,thread_pool=1,compress=lzo,space_cache 0 0
+ # none /proc proc rw,relatime 0 0
+ # tmpfs /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0
+ # /dev/loop0 /gentoo-4k btrfs rw,noatime,nodiratime,nodatasum,nodatacow,thread_pool=1,space_cache 0 0
+
+ [ x$3 = xbtrfs ] && do_defrag_filesystem $2
+
+done </etc/mtab

0 comments on commit 8f910c5

Please sign in to comment.