[systemd-devel] [PATCH 2/2] Adding binary to shutdown the system
Karel Zak
kzak at redhat.com
Wed Oct 6 05:25:37 PDT 2010
On Wed, Oct 06, 2010 at 02:05:44AM -0300, Gustavo Sverzut Barbieri wrote:
> + /* umount all mountpoints, swaps, and loopback devices */
> + retries = FINALIZE_ATTEMPTS;
> + while (need_umount || need_swapoff || need_loop_detach) {
> + if (need_umount) {
> + log_info("Unmounting Filesystems");
> + r = umount_all();
> + if (r == 0)
> + need_umount = false;
> + else
> + log_warning("Not all filesystems unmounted");
> + }
> +
> + if (need_swapoff) {
> + log_info("Disabling Swaps");
> + r = swapoff_all();
> + if (r == 0)
> + need_swapoff = false;
> + else
> + log_warning("Not all swaps are off ");
> + }
it's probably better to call swapoff_all before umount_all (hint:
Linux supports swap-area in regular files).
> + if (need_loop_detach) {
> + log_info("Umounting and Detaching Loopback Devices");
> + r = loopback_detach_all();
> + if (r == 0)
> + need_loop_detach = false;
> + else
> + log_warning("Not all loop devices detached");
> + }
> +
> + if (need_umount || need_swapoff || need_loop_detach) {
> + retries--;
> +
> + if (retries <= FINALIZE_CRITICAL_ATTEMPTS) {
> + log_warning("Approaching critical level to finalize filesystem and devices, try to kill all processes.");
> + rescue_send_signal(SIGTERM);
> + rescue_send_signal(SIGKILL);
> + }
> +
> + if (retries > 0)
> + log_info("Action still required, %d tries left", retries);
> + else {
> + log_error("Tried enough but still action required need_umount=%d, need_swapoff=%d, need_loop_detach=%d", need_umount, need_swapoff, need_loop_detach);
> + r = -EBUSY;
> + goto error;
> + }
> + }
> + }
what about
exec( swapoff -a );
exec( umount -a );
Karel
--
Karel Zak <kzak at redhat.com>
http://karelzak.blogspot.com
More information about the systemd-devel
mailing list