@@ -163,57 +163,14 @@ static int device_coldplug(Unit *u) {
163163 assert (d -> state == DEVICE_DEAD );
164164
165165 /* First, let's put the deserialized state and found mask into effect, if we have it. */
166- if (d -> deserialized_state < 0 )
167- return 0 ;
168-
169- Manager * m = u -> manager ;
170- DeviceFound found = d -> deserialized_found ;
171- DeviceState state = d -> deserialized_state ;
172-
173- /* On initial boot, switch-root, reload, reexecute, the following happen:
174- * 1. MANAGER_IS_RUNNING() == false
175- * 2. enumerate devices: manager_enumerate() -> device_enumerate()
176- * Device.enumerated_found is set.
177- * 3. deserialize devices: manager_deserialize() -> device_deserialize()
178- * Device.deserialize_state and Device.deserialized_found are set.
179- * 4. coldplug devices: manager_coldplug() -> device_coldplug()
180- * deserialized properties are copied to the main properties.
181- * 5. MANAGER_IS_RUNNING() == true: manager_ready()
182- * 6. catchup devices: manager_catchup() -> device_catchup()
183- * Device.enumerated_found is applied to Device.found, and state is updated based on that.
184- *
185- * Notes:
186- * - On initial boot, no udev database exists. Hence, no devices are enumerated in the step 2.
187- * Also, there is no deserialized device. Device units are (a) generated based on dependencies of
188- * other units, or (b) generated when uevents are received.
189- *
190- * - On switch-root, the udev database may be cleared, except for devices with sticky bit, i.e.
191- * OPTIONS="db_persist". Hence, almost no devices are enumerated in the step 2. However, in general,
192- * we have several serialized devices. So, DEVICE_FOUND_UDEV bit in the deserialized_found must be
193- * ignored, as udev rules in initramfs and the main system are often different. If the deserialized
194- * state is DEVICE_PLUGGED, we need to downgrade it to DEVICE_TENTATIVE (or DEVICE_DEAD if nobody
195- * sees the device). Unlike the other starting mode, Manager.honor_device_enumeration == false
196- * (maybe, it is better to rename the flag) when device_coldplug() and device_catchup() are called.
197- * Hence, let's conditionalize the operations by using the flag. After switch-root, systemd-udevd
198- * will (re-)process all devices, and the Device.found and Device.state will be adjusted.
199- *
200- * - On reload or reexecute, we can trust enumerated_found, deserialized_found, and deserialized_state.
201- * Of course, deserialized parameters may be outdated, but the unit state can be adjusted later by
202- * device_catchup() or uevents. */
203-
204- if (!m -> honor_device_enumeration && !MANAGER_IS_USER (m )) {
205- found &= ~DEVICE_FOUND_UDEV ; /* ignore DEVICE_FOUND_UDEV bit */
206- if (state == DEVICE_PLUGGED )
207- state = DEVICE_TENTATIVE ; /* downgrade state */
208- if (found == DEVICE_NOT_FOUND )
209- state = DEVICE_DEAD ; /* If nobody sees the device, downgrade more */
210- }
211166
212- if (d -> found == found && d -> state == state )
167+ if (d -> deserialized_state < 0 ||
168+ (d -> deserialized_state == d -> state &&
169+ d -> deserialized_found == d -> found ))
213170 return 0 ;
214171
215- d -> found = found ;
216- device_set_state (d , state );
172+ d -> found = d -> deserialized_found ;
173+ device_set_state (d , d -> deserialized_state );
217174 return 0 ;
218175}
219176
@@ -687,9 +644,13 @@ static void device_found_changed(Device *d, DeviceFound previous, DeviceFound no
687644}
688645
689646static void device_update_found_one (Device * d , DeviceFound found , DeviceFound mask ) {
647+ Manager * m ;
648+
690649 assert (d );
691650
692- if (MANAGER_IS_RUNNING (UNIT (d )-> manager )) {
651+ m = UNIT (d )-> manager ;
652+
653+ if (MANAGER_IS_RUNNING (m ) && (m -> honor_device_enumeration || MANAGER_IS_USER (m ))) {
693654 DeviceFound n , previous ;
694655
695656 /* When we are already running, then apply the new mask right-away, and trigger state changes
0 commit comments