On 13 January 2017 at 23:04, Jorge Almeida <jjalme...@gmail.com> wrote:
>
> process foobard requires a library foo.so. foobard was started when /
> was ro. Then / is mounted rw and a new version of foo.so is installed.
> Of course, foobard still uses foo.so (old). What prevents / to be
> remounted ro? foo.so (new) is already on disk, foo.so (old) is still
> being used, kept in RAM (I assume...)
>

Almost, but not quite. The problem is that the POSIX standard requires that
any file *must* continue to exist until all file handles pointing to it are
closed. Thus, using your example, when file foo.so gets replaced, the new
foo.so is written to the disk somewhere, but, since foobard holds an open
file handle, the old file is not deleted from the disk yet. At that point,
the content of *both* files (and relevant inodes, etc.) exists on the
*disk*, and, in addition, there is a pending delete operation for the old
file (that is, a "write" operation to /). This prevents / from being
mounted ro, since the pending write must be executed first (hence the
message "/ is busy").

One reason for this behaviour is that foobard may duplicate its file
handle, pass it to some other process, and that process must then still be
able to read the file (from disk, that is, since it doesn't share memory
with the foobard process). This generally doesn't happen for library files,
but this is just how the system behaves for *any* file with an open handle.

But apart from these technical details, usually when you update a library,
you want all programs relying on it to start using the new version. So a
restart would be required anyways. As Dale just wrote while I was typing
this, the needrestart and checkrestart scripts basically check for all
processes that have open handles for files which have a pending delete
operation and output a list for you. The needrestart script can also try to
automatically restart them for you.

Hope this helps,
Michael

Reply via email to