swapon/swapoff: size reduction, cleanup, fixes, improvements
authorTito Ragusa <farmatito@tiscali.it>
Mon, 31 Mar 2014 14:39:26 +0000 (16:39 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 31 Mar 2014 14:39:26 +0000 (16:39 +0200)
commita3f326cd6619cadb44cb4bb051b1d4e54bcd3477
treed14296cbe3ff31c322e825b842d5aac868b92fee
parentfaa9e94db619d1110061687278cde93a651e69de
swapon/swapoff: size reduction, cleanup, fixes, improvements

1) real swapon/swapoff handles also devices on the commandline with -a;
2) xstat(device)  in  swap_enable_disable aborts on error when cycling through
   fstab so some devices  are not handled;
3) duplicated code for ENABLE_FEATURE_SWAPON_DISCARD and
   ENABLE_FEATURE_SWAPON_PRI was moved to functions.
4) silence some error messages with -a;
5) minor cleanups and code refactoring reduced the size as per bloat-check:
6) I also added support for /proc/swaps handling to swapoff:
"When the -a flag is given, swapping is disabled on all known  swap  devices
 and  files  (as  found  in  /proc/swaps  or /etc/fstab)."
So now swapoff first cycles through  /proc/swaps and then through fstab
to swapoff all devices.

function                                             old     new   delta
set_discard_flag                                       -     106    +106
swap_enable_disable                                  147     238     +91
set_priority_flag                                      -      79     +79
retrieve_file_data                                   470     467      -3
swap_on_off_main                                     638     418    -220
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 1/2 up/down: 276/-223)           Total: 53 bytes

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
util-linux/swaponoff.c