Skip to content

Commit 2e75044

Browse files
poetteringbluca
authored andcommitted
docs: various updates to the fdstore docs
ispell made some suggestions which I applied. Addresses: systemd/systemd#29209 (review) Also adds a brief paragraph about initrd transitions. (Plymouth really should start using the fdstore for pinning DRM objects, and stop trying to survive the initrd→host transition) (cherry picked from commit 1df74d1)
1 parent 6d6eba5 commit 2e75044

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

docs/FILE_DESCRIPTOR_STORE.md

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: The File Descriptor Store
2+
title: File Descriptor Store
33
category: Interfaces
44
layout: default
55
SPDX-License-Identifier: LGPL-2.1-or-later
@@ -8,9 +8,9 @@ SPDX-License-Identifier: LGPL-2.1-or-later
88
# The File Descriptor Store
99

1010
*TL;DR: The systemd service manager may optionally maintain a set of file
11-
descriptors for each service, that are under control of the service and that
12-
help making service restarts without losing connectivity or context easier to
13-
implement.*
11+
descriptors for each service. Those file descriptors are under control of the
12+
service. Storing file descriptors in the manager makes is easier to restart
13+
services without dropping connections or losing state.*
1414

1515
Since its inception `systemd` has supported the *socket* *activation*
1616
mechanism: the service manager creates and listens on some sockets (and similar
@@ -32,12 +32,12 @@ maintains a duplicate of it (in the sense of UNIX
3232
also in possession of the service itself, and it may (and is expected to)
3333
invoke any operations on it that it likes.
3434

35-
The primary use case of this logic is to permit services to restart seamlessly
35+
The primary use-case of this logic is to permit services to restart seamlessly
3636
(for example to update them to a newer version), without losing execution
3737
context, dropping pinned resources, terminating established connections or even
3838
just momentarily losing connectivity. In fact, as the file descriptors can be
39-
uploaded freely at any time during the service runtime, this can even be used to
40-
implement services that robustly handle abnormal termination and can recover
39+
uploaded freely at any time during the service runtime, this can even be used
40+
to implement services that robustly handle abnormal termination and can recover
4141
from that without losing pinned resources.
4242

4343
Note that Linux supports the
@@ -58,7 +58,7 @@ permit the service to upload to the service manager to keep simultaneously.
5858
If set to values > 0, the fdstore is enabled. When invoked the service may now
5959
(asynchronously) upload file descriptors to the fdstore via the
6060
[`sd_pid_notify_with_fds()`](https://www.freedesktop.org/software/systemd/man/sd_pid_notify_with_fds.html)
61-
API call (or an equivalent reimplementation). When uploading the fds it is
61+
API call (or an equivalent re-implementation). When uploading the fds it is
6262
necessary to set the `FDSTORE=1` field in the message, to indicate what the fd
6363
is intended for. It's recommended to also set the `FDNAME=…` field to any
6464
string of choice, which may be used to identify the fd later.
@@ -98,28 +98,28 @@ updates, hence leaving two version of the service running at the same time is
9898
generally problematic. It also collides with the systemd service manager's
9999
general principle of guaranteeing a pristine execution environment, a pristine
100100
security context, and a pristine resource management context for freshly
101-
started services, without uncontrolled "left-overs" from previous runs. For
101+
started services, without uncontrolled "leftovers" from previous runs. For
102102
example: leaving processes from previous runs generally negatively affects
103-
lifecycle management (i.e. `KillMode=none` must be set), which disables large
103+
life-cycle management (i.e. `KillMode=none` must be set), which disables large
104104
parts of the service managers state tracking, resource management (as resource
105105
counters cannot start at zero during service activation anymore, since the old
106106
processes remaining skew them), security policies (as processes with possibly
107107
out-of-date security policies – SElinux, AppArmor, any LSM, seccomp, BPF — in
108108
effect remain), and similar.
109109

110-
# File Descriptor Store Lifecycle
110+
# File Descriptor Store Life-cycle
111111

112112
By default any file descriptor stored in the fdstore for which a `POLLHUP` or
113113
`POLLERR` is seen is automatically closed and removed from the fdstore. This
114-
behaviour can be turned off, by setting the `FDPOLL=0` field when uploading the
114+
behavior can be turned off, by setting the `FDPOLL=0` field when uploading the
115115
fd via `sd_notify_with_fds()`.
116116

117117
The fdstore is automatically closed whenever the service is fully deactivated
118118
and no jobs are queued for it anymore. This means that a restart job for a
119119
service will leave the fdstore intact, but a separate stop and start job for
120120
it — executed synchronously one after the other — will likely not.
121121

122-
This behaviour can be modified via the
122+
This behavior can be modified via the
123123
[`FileDescriptorStorePreserve=`](https://www.freedesktop.org/software/systemd/man/systemd.service.html#FileDescriptorStorePreserve=)
124124
setting in service unit files. If set to `yes` the fdstore will be kept as long
125125
as the service definition is loaded into memory by the service manager, i.e. as
@@ -141,12 +141,12 @@ received, to make the service robust for code updates: if an old version
141141
uploaded an fd that the new version doesn't recognize anymore it's good idea to
142142
close it both in the service and in the fdstore.
143143

144-
Note that storing a duplicate of an fd in the fdstore means the fd remains
145-
pinned even if the service closes it. This in particular means that peers on a
146-
connection socket uploaded this way will not receive an automatic `POLLHUP`
147-
event anymore if the service code issues `close()` on the socket. It must
148-
accompany it with an `FDSTOREREMOVE=1` notification to the service manager, so
149-
that the fd is comprehensively closed.
144+
Note that storing a duplicate of an fd in the fdstore means the resource pinned
145+
by the fd remains pinned even if the service closes its duplicate of the
146+
fd. This in particular means that peers on a connection socket uploaded this
147+
way will not receive an automatic `POLLHUP` event anymore if the service code
148+
issues `close()` on the socket. It must accompany it with an `FDSTOREREMOVE=1`
149+
notification to the service manager, so that the fd is comprehensively closed.
150150

151151
# Access Control
152152

@@ -175,9 +175,28 @@ interrupting connectivity or established connections and similar.
175175
This mechanism can be enabled either by making sure the service survives until
176176
the very end (i.e. by setting `DefaultDependencies=no` so that it keeps running
177177
for the whole system lifetime without being regularly deactivated at shutdown)
178-
or by setting `FileDescriptorStorePresever=yes` (and referencing the unit
178+
or by setting `FileDescriptorStorePreserve=yes` (and referencing the unit
179179
continuously).
180180

181+
For further details see [Resource
182+
Pass-Through](https://www.freedesktop.org/software/systemd/man/systemd-soft-reboot.service.html#Resource%20Pass-Through).
183+
184+
# initrd Transitions
185+
186+
The fdstore may also be used to hand over file descriptor to resources from the
187+
initrd context to the main system. This is important as code running off the
188+
initrd should generally not continue to run after the initrd to host
189+
transition, since it pins the backing files from the initrd, and might run a
190+
slightly different version of things than the host.
191+
192+
Any service that still runs during the initrd→host transition will have its
193+
fdstore passed over the transition, where it will be passed back to any queued
194+
services of the same name.
195+
196+
The soft reboot cycle transition and the initrd→host transition are
197+
semantically very similar, hence similar rules apply, and in both cases it is
198+
recommended to use the fdstore if pinned resources shall be passed over.
199+
181200
# Debugging
182201

183202
The

0 commit comments

Comments
 (0)