Skip to content

[sled-agent] spawn check for unmanaged zpools to unblock InstanceManager - #11492

Closed
hawkw wants to merge 2 commits into
mainfrom
eliza/filesystem-zpool-setonce
Closed

hawkw wants to merge 2 commits into
mainfrom
eliza/filesystem-zpool-setonce

Conversation

@hawkw

@hawkw hawkw commented Oct 14, 2026

Copy link
Copy Markdown
Member

This commit reworks InstanceManager::use_only_currently_managed_zpools to ensure that it cannot block the InstanceManager main loop indefinitely. This is accomplished by spawning a separate task for each instance immediately, which then waits for the zone to start if it is in the process of starting, checks if the zpool is managed, and terminates it if it is not. This also removes get_filesystem_zpool from the main instance request channel, so that a full request channel cannot cause us to skip a Propolis zone, and instead publishes the filesystem zpool using a SetOnce. Because there are no HTTP entrypoints that call get_filesystem_zpool, it need not be an actor-style request/response thingy like the actual API requests.

See: #11462 (comment) and #11462 (comment)

unmanaged zpools

This commit reworks `InstanceManager::use_only_currently_managed_zpools`
to ensure that it cannot block the `InstanceManager` main loop
indefinitely. This is accomplished by spawning a separate task for each
instance immediately, which then waits for the zone to start if it is in
the process of starting, checks if the zpool is managed, and terminates
it if it is not. This also removes `get_filesystem_zpool` from the main
instance request channel, so that a full request channel cannot cause us
to skip a Propolis zone, and instead publishes the filesystem zpool
using a `SetOnce`. Because there are no HTTP entrypoints that call
`get_filesystem_zpool`, it need not be an actor-style request/response
thingy like the actual API requests.
///
/// This returns `None` if the zone is running but its root filesystem is on
/// the ramdisk rather than a zpool.
pub async fn wait_for_filesystem_zpool(&self) -> Option<&ZpoolName> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit - ZpoolName is Copy (it's just a UUID wrapped in a couple layers of enums), so I think we could return Option<ZpoolName> here if you'd like.

// we may as well jam the propolis ID in there...
let log = self.log.new(o!("propolis_id" => id.to_string()));
let instance = instance.clone();
tokio::spawn(async move {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a problem that this basically spawns a bunch of tasks with no backpressure, since it never awaits them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♀️ i think it's a much less bad problem than exerting backpressure on the entire InstanceManager loop. In the longer term, I think we may want to consider decoupling all of this from that and having some way to limit the number of these tasks, but I'm still a lot less concerned about it than the alternative?

Comment thread sled-agent/src/instance_manager.rs Outdated
// be set up before checking if it is using an unknown zpool, and we
// do not want to block the main instance-manager loop waiting for
// all instances to finish having their Propolis zones set up.
let current_zpools = current_zpools.clone();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is new, but is it possible for this to race with setting up an instance?

E.g., imagine the following:

  • Someone starts a propolis instance (put_state through the instance manager, which hands off to the instance task). The InstanceRunner has not chosen which zpool to use yet. But it is registered, and shows up in self.jobs.
  • The InstanceManager calls use_only_currently_managed_zpools, for some reason (maybe an old zpool got removed. Doesn't really matter. just needs to fire somehow). Let's imagine this is the set of pools: {zpool = A, zpool = B}. Since we clone the current_zpools, that's what we'll see later in the spawned task too.
  • Suppose a new {zpool = C} is added to the set of "currently managed zpools".
  • Suppose the instance picks that new zpool C for it's root filesystem, and starts.
  • ... Now the spawned tasks here run to completion. use_only_currently_managed_zpools would have an out-dated view of current zpools, and would kill the new instance, even though it's using a valid zpool.

I think this issues comes from "the instance manager / instance both monitoring data from the reconciler, but reading them mostly-independently". I wonder if we could mitigate this by only letting instances choose pools seen by the instance manager, to ensure "the view used by instances cannot get ahead of the view used by the instance manager".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this issues comes from "the instance manager / instance both monitoring data from the reconciler, but reading them mostly-independently". I wonder if we could mitigate this by only letting instances choose pools seen by the instance manager, to ensure "the view used by instances cannot get ahead of the view used by the instance manager".

Hmm. Is another option "only monitor from instance"? It's already watching for a termination signal; could it also watch for .changed() and terminate itself if the zpool it picked is gone at some later point?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I bet that could work too

/// This returns `None` if the zone is running but its root filesystem is on
/// the ramdisk rather than a zpool.
pub async fn wait_for_filesystem_zpool(&self) -> Option<&ZpoolName> {
self.root_fs_zpool.wait().await.as_ref()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we register a propolis zone, but never start it, does anything stop this task from waiting? Is that possible?

(or I guess, if the startup fails before we set root_fs_zpool?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, yup. I think we need the instance runner task to send None when it terminates, or something.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read @jgallagher 's feedback in #11492 (comment) before doing this! I wonder if we move the "watching responsibility" to the instance itself, if that simplifies the lifetime, and avoids the need to "wait for a filesystem zpool" at all

Comment thread sled-agent/src/instance_manager.rs Outdated
let Some(filesystem_pool) =
instance.wait_for_filesystem_zpool().await
else {
// Zone is not on the ramdisk, so skip it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this case (function returns None) mean the zone is on the ramdisk?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what I meant. Whoops.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW #11495 gets rid of this branch entirely, since we never actually start instance zones on ramdisks.

Comment thread sled-agent/src/instance_manager.rs Outdated
@@ -1090,31 +1090,39 @@ impl InstanceManagerRunner {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW as written, I don't think this function needs to be async - it's not awaiting anything, right?

@bnaecker bnaecker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another good simplification, thanks!

Comment thread sled-agent/src/instance_manager.rs Outdated
// Zone is not on the ramdisk, so skip it.
return;
};
if !current_zpools.contains(filesystem_pool) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to Sean's question above, should we wait until this point to actually fetch the set of current pools? By the time the instance has started, this view could be outdated.

Comment thread sled-agent/src/instance_manager.rs Outdated
let current_zpools = current_zpools.clone();
// Since we must clone the logger anyway in order to spawn the task,
// we may as well jam the propolis ID in there...
let log = self.log.new(o!("propolis_id" => id.to_string()));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might add the instance ID to the logger too.

@hawkw hawkw closed this in #11497 Oct 15, 2026
jgallagher pushed a commit that referenced this pull request Oct 15, 2026
This change makes it so that sled-agent can ensure that it's using only
currently-managed zpools without using
`use_only_currently_managed_zpools`. :)

At present, the mechanism that sled-agent uses to ensure that any
Propolis zones whose zone-root filesystems are on zpools that no longer
exist is the `InstanceManager::use_only_currently_managed_zpools`
method. This is called in the `InstanceManager` main loop when the set
of currently-managed zpools changes, and works by looping over all
managed instances, asking them which zpool the root filesystem for the
Propolis zone is on, and then telling the `InstanceRunner` to terminate
the Propolis zone if it is on a zpool that is no longer managed. Because
this occurs within the `InstanceManager` main loop, it's important that
nothing that happens here can prevent that loop from making progress
indefinitely, as it would prevent any unrelated instance management
operations from running.

In #11492, I made an attempt to tidy this up a bit by having the
`InstanceRunner` publish its zpool separately from its main request
channel. After thinking it through, though, @smklein, @jgallagher, and I
all came to the conclusion (see [this comment][1]) that there's actually
a much better way of doing this. Rather than having the
`InstanceManager` loop over all *instances* and check if they are using
un-managed zpools, we can just give the `watch` channel of currently
managed zpools to each `InstanceRunner`, and have it wait for changes to
that set and check whether its zpools are still in the currently managed
set.

This avoids a lot of the potential raciness with publishing the zpool
name once the zone is running, since we can just wait to spawn a task to
wait for changes to the set of currently-managed zpools only once a zone
is actually running. After that point, the zpool name will never change,
and we cannot race with creating the zone *or* get stuck if the zone
fails to start. This simplifies a lot of other aspects of the
implementation, too, since it makes one of the two paths to instance
termination completely internal to the `instance.rs` module, and we no
longer have to do any of this work in the `InstanceManager` main loop.
We no longer need the `GetFilesystemZpool` request to the
`InstanceRunner` actor at all, because the task is now spawned with the
zpool name once it's determined. Building on the changes to termination
in #11462, the entire "zpool no longer managed, terminate propolis
forcefully" path is now completely separate from the synchronous (well,
async-but-actor-blocking) request/response channels in both
`InstanceManager` and `InstanceRunner`.

Closes #11492

[1]:
https://github.com/oxidecomputer/omicron/pull/11492/changes/BASE..837f552c06380587eba3526da5236cce68983bea#r4275100226
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants