[systemd-devel] [PATCH 2/2] Adding binary to shutdown the system

Lennart Poettering lennart at poettering.net
Wed Oct 6 05:56:19 PDT 2010


On Wed, 06.10.10 14:25, Karel Zak (kzak at redhat.com) wrote:

> > +                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).

The Fedora shutdown scripts unmount tmpfs before swap, to make sure that
the removal of the swaps does not cause heavy unswapping for data that
will be dumped right-away after, because the tmpfs that has its data in
the swap is killed anyway. I think that is an optimization that might be
worth it and hence I asked Gustavo to implement it in the shutdown code.

The right way I think is to call all this in a loop: i.e. first get rid
of mounts as far as possible, then get rid of swaps as far as possible,
then try mounts again, until nothing can be removed anymore. Which is
more or less exactly what Gustavo's patch does.

> 
> > +                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 );

We really need the information whether there are still some mounts/swaps
left to be removed so that we can loop around this properly. I am pretty
sure swapoff -a does not return that to us, does it?

Given that we want to loop around this in a tight loop I think it's
kinda nice to implement this in C instead of forking off processes, in
particular because the code in question is not overly complex.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list