Skip to content

Commit f39206d

Browse files
committed
add sled-agent endpoints to control destroying orphaned datasets
1 parent 173c7c3 commit f39206d

File tree

6 files changed

+146
-0
lines changed

6 files changed

+146
-0
lines changed

openapi/sled-agent.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,57 @@
334334
}
335335
}
336336
},
337+
"/chicken-switch/destroy-orphaned-datasets": {
338+
"get": {
339+
"summary": "This endpoint reports the status of the `destroy_orphaned_datasets`",
340+
"description": "chicken switch. It will be removed with omicron#6177.",
341+
"operationId": "chicken_switch_destroy_orphaned_datasets_get",
342+
"responses": {
343+
"200": {
344+
"description": "successful operation",
345+
"content": {
346+
"application/json": {
347+
"schema": {
348+
"$ref": "#/components/schemas/ChickenSwitchDestroyOrphanedDatasets"
349+
}
350+
}
351+
}
352+
},
353+
"4XX": {
354+
"$ref": "#/components/responses/Error"
355+
},
356+
"5XX": {
357+
"$ref": "#/components/responses/Error"
358+
}
359+
}
360+
},
361+
"put": {
362+
"summary": "This endpoint sets the `destroy_orphaned_datasets` chicken switch",
363+
"description": "(allowing sled-agent to delete datasets it believes are orphaned). It will be removed with omicron#6177.",
364+
"operationId": "chicken_switch_destroy_orphaned_datasets_put",
365+
"requestBody": {
366+
"content": {
367+
"application/json": {
368+
"schema": {
369+
"$ref": "#/components/schemas/ChickenSwitchDestroyOrphanedDatasets"
370+
}
371+
}
372+
},
373+
"required": true
374+
},
375+
"responses": {
376+
"204": {
377+
"description": "resource updated"
378+
},
379+
"4XX": {
380+
"$ref": "#/components/responses/Error"
381+
},
382+
"5XX": {
383+
"$ref": "#/components/responses/Error"
384+
}
385+
}
386+
}
387+
},
337388
"/disks/{disk_id}": {
338389
"put": {
339390
"operationId": "disk_put",
@@ -2926,6 +2977,18 @@
29262977
"format": "uint64",
29272978
"minimum": 0
29282979
},
2980+
"ChickenSwitchDestroyOrphanedDatasets": {
2981+
"type": "object",
2982+
"properties": {
2983+
"destroy_orphans": {
2984+
"description": "If true, sled-agent will attempt to destroy durable ZFS datasets that it believes were associated with now-expunged Omicron zones.",
2985+
"type": "boolean"
2986+
}
2987+
},
2988+
"required": [
2989+
"destroy_orphans"
2990+
]
2991+
},
29292992
"Chipset": {
29302993
"description": "A kind of virtual chipset.",
29312994
"oneOf": [

sled-agent/api/src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,35 @@ pub trait SledAgentApi {
682682
path_params: Path<SledDiagnosticsLogsDownloadPathParm>,
683683
query_params: Query<SledDiagnosticsLogsDownloadQueryParam>,
684684
) -> Result<http::Response<Body>, HttpError>;
685+
686+
/// This endpoint reports the status of the `destroy_orphaned_datasets`
687+
/// chicken switch. It will be removed with omicron#6177.
688+
#[endpoint {
689+
method = GET,
690+
path = "/chicken-switch/destroy-orphaned-datasets",
691+
}]
692+
async fn chicken_switch_destroy_orphaned_datasets_get(
693+
request_context: RequestContext<Self::Context>,
694+
) -> Result<HttpResponseOk<ChickenSwitchDestroyOrphanedDatasets>, HttpError>;
695+
696+
/// This endpoint sets the `destroy_orphaned_datasets` chicken switch
697+
/// (allowing sled-agent to delete datasets it believes are orphaned). It
698+
/// will be removed with omicron#6177.
699+
#[endpoint {
700+
method = PUT,
701+
path = "/chicken-switch/destroy-orphaned-datasets",
702+
}]
703+
async fn chicken_switch_destroy_orphaned_datasets_put(
704+
request_context: RequestContext<Self::Context>,
705+
body: TypedBody<ChickenSwitchDestroyOrphanedDatasets>,
706+
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
707+
}
708+
709+
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
710+
pub struct ChickenSwitchDestroyOrphanedDatasets {
711+
/// If true, sled-agent will attempt to destroy durable ZFS datasets that it
712+
/// believes were associated with now-expunged Omicron zones.
713+
pub destroy_orphans: bool,
685714
}
686715

687716
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]

sled-agent/config-reconciler/src/handle.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ impl ConfigReconcilerHandle {
250250
);
251251
}
252252

253+
/// Read whether or not we try to destroy orphaned datasets.
254+
pub fn will_destroy_orphans(&self) -> bool {
255+
self.destroy_orphans.load(Ordering::Relaxed)
256+
}
257+
253258
/// Control whether or not we try to destroy orphaned datasets.
254259
pub fn set_destroy_orphans(&self, destroy_orphans: bool) {
255260
self.destroy_orphans.store(destroy_orphans, Ordering::Relaxed);

sled-agent/src/http_entrypoints.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,4 +1053,26 @@ impl SledAgentApi for SledAgentImpl {
10531053
.await
10541054
.map_err(HttpError::from)
10551055
}
1056+
1057+
async fn chicken_switch_destroy_orphaned_datasets_get(
1058+
request_context: RequestContext<Self::Context>,
1059+
) -> Result<HttpResponseOk<ChickenSwitchDestroyOrphanedDatasets>, HttpError>
1060+
{
1061+
let sa = request_context.context();
1062+
let destroy_orphans = sa.chicken_switch_destroy_orphaned_datasets();
1063+
Ok(HttpResponseOk(ChickenSwitchDestroyOrphanedDatasets {
1064+
destroy_orphans,
1065+
}))
1066+
}
1067+
1068+
async fn chicken_switch_destroy_orphaned_datasets_put(
1069+
request_context: RequestContext<Self::Context>,
1070+
body: TypedBody<ChickenSwitchDestroyOrphanedDatasets>,
1071+
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
1072+
let ChickenSwitchDestroyOrphanedDatasets { destroy_orphans } =
1073+
body.into_inner();
1074+
let sa = request_context.context();
1075+
sa.set_chicken_switch_destroy_orphaned_datasets(destroy_orphans);
1076+
Ok(HttpResponseUpdatedNoContent())
1077+
}
10561078
}

sled-agent/src/sim/http_entrypoints.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,20 @@ impl SledAgentApi for SledAgentSimImpl {
768768
) -> Result<http::Response<dropshot::Body>, HttpError> {
769769
method_unimplemented()
770770
}
771+
772+
async fn chicken_switch_destroy_orphaned_datasets_get(
773+
_request_context: RequestContext<Self::Context>,
774+
) -> Result<HttpResponseOk<ChickenSwitchDestroyOrphanedDatasets>, HttpError>
775+
{
776+
method_unimplemented()
777+
}
778+
779+
async fn chicken_switch_destroy_orphaned_datasets_put(
780+
_request_context: RequestContext<Self::Context>,
781+
_body: TypedBody<ChickenSwitchDestroyOrphanedDatasets>,
782+
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
783+
method_unimplemented()
784+
}
771785
}
772786

773787
fn method_unimplemented<T>() -> Result<T, HttpError> {

sled-agent/src/sled_agent.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,19 @@ impl SledAgent {
828828
self.inner.config_reconciler.set_sled_config(config).await
829829
}
830830

831+
/// Get the status of the "destroy orphaned datasets" chicken switch.
832+
pub(crate) fn chicken_switch_destroy_orphaned_datasets(&self) -> bool {
833+
self.inner.config_reconciler.will_destroy_orphans()
834+
}
835+
836+
/// Set the status of the "destroy orphaned datasets" chicken switch.
837+
pub(crate) fn set_chicken_switch_destroy_orphaned_datasets(
838+
&self,
839+
destroy_orphans: bool,
840+
) {
841+
self.inner.config_reconciler.set_destroy_orphans(destroy_orphans);
842+
}
843+
831844
/// Returns whether or not the sled believes itself to be a scrimlet
832845
pub fn get_role(&self) -> SledRole {
833846
if self.inner.hardware.is_scrimlet() {

0 commit comments

Comments
 (0)