Skip to content

PR#23218 introduced a regression for devices with db_persist option #23429

Closed

Description

@fbuihuu

Devices with OPTIONS+="db_persist" are not supposed to create dead->plugged transition right after switching root, at least that wasn't the case before and the udev man page describes the option to actually prevent it from happening.

However pr #23218 changed this behavior. I don't know currently whether it will cause any real regression in practice but I think it deserves a discussion before releasing v251.

Activity

  1. added
    regression ⚠️
    on May 18, 2022
  2. added this to the v251 milestone on May 18, 2022
  3. mwilck commented on May 18, 2022

    @mwilck
    Contributor

    I wouldn't call this a regression. No actual negative impact is known except the debug messages.

    See also #23218 (comment)

  4. added a commit that references this issue on May 19, 2022
    e6b22ab
  5. fbuihuu commented on May 19, 2022

    @fbuihuu
    ContributorAuthor

    Hi Martin, it's pretty hard to say for sure that it won't have any negative impact but the facts are that this transition never happened before and the doc clearly describes the use of "db_persist" as way to make sure that the device unit state remains always plugged.

  6. yuwata commented on May 19, 2022

    @yuwata
    Member

    @mwilck

    #23218 (comment)

    It's not clear to me whether it will cause issue in practice (maybe @mwilck knows ?) but this dead->plugged transition for devices with db_persist doen't look correct and wasn't present before. And udev man page seems to indicate that this transition should not occur.

    Why would this even be mentioned in an the udev man page? It's genuine systemd functionality.

    I have observed these transitions (I see them all the time actually because I work with multipath-tools, but I didn't bother about it), but definitely no negative impact.

    I have a test case here where root FS (btrfs) is on top of LVM on top of MD RAID on top of multipath. Thus the multipath devices (which have db_persist set) are in use once root is mounted, but from the PoV of systemd, they have neither DEVICE_FOUND_MOUNT nor DEVICE_FOUND_SWAP set. Thus they start out "dead" after switching root, just like in @fbuihuu's example. I can see these dead→plugged transitions with loglevel debug, but everything works just fine during boot.

    #23218 (comment)

    @yuwata. recall this discussion we had previously? If we removed the lines

    +                if (found == DEVICE_NOT_FOUND)
    +                        state = DEVICE_DEAD; /* If nobody sees the device, downgrade more */
    

    from 75d7b59, we'd still see transition messages but only "tentative→plugged", not the confusing "dead→plugged". I don't think this can be completely avoided. We apply the result from enumeration after the result from deserialization on purpose.

    Yeah, the condition seems slightly offensive, I will fix it after dinner. But, the basic idea of the block is that setting DEVICE_TENTATIVE with DEVICE_NOT_FOUND is super strange.

  7. mwilck commented on May 19, 2022

    @mwilck
    Contributor

    But, the basic idea of the block is that setting DEVICE_TENTATIVE with DEVICE_NOT_FOUND is super strange.

    Not if you consider complex storage stacks. If a device has been "plugged" but not mounted (instead, member of an MD RAID, or an LVM PV or what not), and you mask out DEVICE_FOUND_UDEV, you get this combination. You can of course try to build a model of complex storage stacks in systemd, but I wouldn't recommend it, at least not short term.

    DEVICE_TENTATIVE makes a lot of sense for me in this case. At the given point in time (before device_catchup(), systemd has no confirmation from udev whether the device exists, but it existed before, which makes "tentative" a reasonable guess.

  8. mwilck commented on May 19, 2022

    @mwilck
    Contributor

    Hi Martin, it's pretty hard to say for sure that it won't have any negative impact but the facts are that this transition never happened before and the doc clearly describes the use of "db_persist" as way to make sure that the device unit state remains always plugged.

    Correct me if I'm wrong: the issue in #12953 was that we observed plugged→dead transitions. These transitions are fatal, as are dead→plugged transitions based on "guessing" (rather than actual udev device detection). Both these types of wrong transitions are fixed by @yuwata's patch set.

    What you've been observing is that db_persist devices undergo dead→plugged transitions repeatedly. The first transition is "real", while the others are just caused by the fact that the devices start out "dead" after re-execution unless they're mounted. I am quite positive that this is harmless, and I am not sure if it can be avoided. We would need to start out with DEVICE_PLUGGED, DEVICE_FOUND_UDEV if enumerated_state == DEVICE_PLUGGED, enumerated_found == DEVICE_FOUND_UDEV after device_enumerate(). While that would fix your issue, my gut feeling is that it might cause problems in other cases like the "systemd reloads while booting" case that we've discussed elsewhere.

  9. added a commit that references this issue on May 19, 2022
    588ca27
  10. yuwata commented on May 19, 2022

    @yuwata
    Member

    @mwilck I'd like to recall that it is dangerous to set DEVICE_TENTATIVE with DEVICE_NOT_FOUND. If we do so in device_coldplug(), then the device will not enter the dead state even if enumerated_found == DEVICE_NOT_FOUND, and it is stuck in the tentative state, and no corresponding unit will be stopped.

  11. yuwata commented on May 19, 2022

    @yuwata
    Member

    If a device has persistent database, then the Device.enumerated_found can be 'reliable' in some sense, and if it has DEVICE_FOUND_UDEV flag, it is not necessary to downgrade the flag and state, as device_catchup() will fix the state soon later. If we adjust the found and state in device_coldplug(), it generates unnecessary state transition, as reported in this issue.

  12. yuwata commented on May 19, 2022

    @yuwata
    Member

    I guess the unnecessary state transition reported in this issue triggers the following mount unit being stopped:

    [Unit]
    Requires=sys-devices-WithPersistentDatabase.device  <-- maybe BoundTo=??
    After=sys-devices-WithPersistentDatabase.device
    
    [Mount]
    What=/dev/BlockWithoutPersistentDatabase
    Where=/mnt/foo
    

    Here, important point is the devices in What= and Requires= are different.
    If the block device corresponds to sys-devices-WithPersistentDatabase.device is not mounted, then its Device.enumerated_found == DEVICE_NOT_FOUND on switching root and it enters DEVICE_DEAD, hence even if the device unit corresponds to /dev/BlockWithoutPersistentDatabase is in the tentative state, the mount unit is stopped during the switching root.

  13. mwilck commented on May 19, 2022

    @mwilck
    Contributor

    @mwilck I'd like to recall that it is dangerous to set DEVICE_TENTATIVE with DEVICE_NOT_FOUND. If we do so in device_coldplug(), then the device will not enter the dead state even if enumerated_found == DEVICE_NOT_FOUND, and it is stuck in the tentative state, and no corresponding unit will be stopped.

    IIUC "tentative" corresponds to "activating", and thus will be subject to systemd's general timeout handling for unit activation. IOW if a device was actually "plugged" before switching root, but not found any more in the root FS, it would switch to "dead" state when the timeout expires. Am I missing something?

    As noted before, the combination DEVICE_PLUGGED, DEVICE_FOUND_UDEV frequently occurs with multipath, MD, LVM etc. If we mask out DEVICE_FOUND_UDEV after switching root, we end up with found = DEVICE_NOT_FOUND. Resetting state from DEVICE_PLUGGED to DEVICE_DEAD in this case sounds counter-intuitive to me; calling device_set_state(DEVICE_DEAD) would be outright dangerous because it would stop dependent units.

    Here, important point is the devices in What= and Requires= are different. If the block device corresponds to sys-devices-WithPersistentDatabase.device is not mounted, then its Device.enumerated_found == DEVICE_NOT_FOUND on switching root and it enters DEVICE_DEAD

    But nothing bad would happen with DEVICE_TENTATIVE.

  14. added a commit that references this issue on May 19, 2022
    a5dedd6
  15. 34 remaining items

  16. added 2 commits that reference this issue on Jan 27, 2023
    b927b30
    a96ef94
  17. added 2 commits that reference this issue on Nov 1, 2023
    1e4058a
    6b3bb11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pid1regression ⚠️

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions