前回記事から時間が空いてしまいましたが、予約ブロックを解放したあとに戻せる条件について調べたいと思います。
おっと、その前にちょっと寄り道をして tune2fs
コマンドのmanを覗いてみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 $ man tune2fs TUNE2FS(8) TUNE2FS(8) NAME tune2fs - adjust tunable filesystem parameters on ext2/ext3/ext4 filesystems SYNOPSIS tune2fs [ -l ] [ -c max-mount-counts ] [ -e errors-behavior ] [ -f ] [ -i interval-between-checks ] [ -j ] [ -J journal-options ] [ -m reserved-blocks-percentage ] [ -o [^]mount-options[,...] ] [ -r reserved-blocks-count ] [ -s sparse-super-flag ] [ -u user ] [ -g group ] [ -C mount-count ] [ -E extended-options ] [ -L vol- ume-name ] [ -M last-mounted-directory ] [ -O [^]feature[,...] ] [ -T time-last-checked ] [ -U UUID ] device DESCRIPTION tune2fs allows the system administrator to adjust various tunable filesystem parameters on Linux ext2, ext3, or ext4 filesystems. The current values of these options can be displayed by using the -l option to tune2fs(8) program, or by using the dumpe2fs(8) program.
まず冒頭部分。
ファイルシステムの調整を行うコマンドであるため頻繁に叩くものではないですがいろんなオプションがありますね。
1 -l List the contents of the filesystem superblock, including the current values of the parameters that can be set via this program.
-l
スーパーブロックに書かれた情報を表示します。ここでどれだけの予約領域が確保されているのか確認できます。
1 2 3 4 5 6 7 -m reserved-blocks-percentage Set the percentage of the filesystem which may only be allocated by privileged processes. Reserving some number of filesystem blocks for use by privileged processes is done to avoid filesystem fragmentation, and to allow system daemons, such as syslogd(8), to continue to function correctly after non-privileged processes are prevented from writing to the filesystem. Normally, the default percentage of reserved blocks is 5%. -r reserved-blocks-count Set the number of reserved filesystem blocks.
-r
-m
はともに予約領域として確保したい領域を設定するオプションです。
自分は主に-m 3
のように予約領域を解放する用途でこれまで使ってきたので「解放のため」のオプションだと思っていました。
実際には解放だけではなく現在の領域より大きい値を指定することで、予約領域の確保も行うことが出来ます。
では本日の本題。予約領域を増やすことのできる条件を e2fsprogs のソースコードから調べます。
ソースは このあたり にあります。
まずは main関数から追っていきます。
misc/tune2fs.c 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 int main (int argc, char **argv) #else int tune2fs_main (int argc, char **argv) #endif { errcode_t retval; ext2_filsys fs; struct ext2_super_block *sb ; io_manager io_ptr, io_ptr_orig = NULL ; int rc = 0 ; char default_undo_file[1 ] = { 0 };
ざーっと行を進めていって
misc/tune2fs.c 2679 2680 2681 2682 if (strcmp(get_progname(argv [0]) , "e2label" ) == 0 ) parse_e2label_options(argc , argv ) ; else parse_tune2fs_options(argc , argv ) ;
今回は tune2fs
コマンドなので
misc/tune2fs.c 1561 static void parse_tune2fs_options(int argc , char ** argv )
に移動します。
今回使うオプションは -m
-r
misc/tune2fs.c 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 case 'm' : reserved_ratio = strtod(optarg, &tmp); if (*tmp || reserved_ratio > 50 || reserved_ratio < 0 ) { com_err(program_name, 0 , _ ("bad reserved block ratio - %s" ), optarg); usage(); } m_flag = 1 ; open_flag = EXT2_FLAG_RW; break ;
strtod
で整数に変換できない文字が予含まれていた場合や、約領域の割合が50%を超えるような指定や、マイナスの値を渡すとエラーになるようです。
misc/tune2fs.c 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 case 'r' : reserved_blocks = strtoul(optarg, &tmp, 0 ); if (*tmp) { com_err(program_name, 0 , _ ("bad reserved blocks count - %s" ), optarg); usage(); } r_flag = 1 ; open_flag = EXT2_FLAG_RW; break ;
こちらは strtoul
で unsigned long に変換できない場合エラーになる模様。
parse_tune2fs_options
関数の処理はざっとこれぐらいかな。 で、mainに戻ります。
misc/tune2fs.c 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 if (m_flag) { ext2fs_r_blocks_count_set(sb, reserved_ratio * ext2fs_blocks_count(sb) / 100.0 ); ext2fs_mark_super_dirty(fs); printf (_ ("Setting reserved blocks percentage to %g%% (%llu blocks)\n" ), reserved_ratio, ext2fs_r_blocks_count(sb)); } if (r_flag) { if (reserved_blocks > ext2fs_blocks_count(sb)/2 ) { com_err(program_name, 0 , _ ("reserved blocks count is too big (%llu)" ), reserved_blocks); rc = 1 ; goto closefs; } ext2fs_r_blocks_count_set(sb, reserved_blocks); ext2fs_mark_super_dirty(fs); printf (_ ("Setting reserved blocks count to %llu\n" ), reserved_blocks); }
どうやら -r
オプションの場合も 2845行目付近で全ブロック数の半分までしか予約させない処理が入っているようです。
どちらの場合も ext2fs_r_blocks_count_set
関数と ext2fs_mark_super_dirty
関数を呼ぶだけ、というあっさりした作り。
この辺りでお腹いっぱいになってきたので、もっと詳しいところはそのうちまた見てみたいと思います。 では、さようならー。