Skip to content

Commit b430d00

Browse files
mayastor-borsdaclash
andcommitted
Merge #1911
1911: set PR_SET_IO_FLUSHER for io-engine r=daclash a=daclash This pull request introduces a new functionality to set the PR_SET_IO_FLUSHER flag in io-engine for improved I/O process handling. The changes add a new module that implements a helper function to invoke the prctl system call with the PR_SET_IO_FLUSHER flag and integrates this call into the io-engine startup routine. This ensures that processes involved in I/O operations are configured correctly. Follow-on changes: - Update runner scripts to include CAP_SYS_RESOURCE capability - Update systemd service examples in documentation - Required for PR_SET_IO_FLUSHER system call in direct execution contexts Co-authored-by: Dan Clash <[email protected]>
2 parents 8c73ae7 + e025344 commit b430d00

File tree

7 files changed

+39
-9
lines changed

7 files changed

+39
-9
lines changed

doc/run.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ systemd.services.mayastor = {
230230
Type = "forking";
231231
User = "nobody";
232232
ExecStart = "${pkgs.mayastor}/bin/mayastor";
233-
AmbientCapabilities = "CAP_SETPCAP CAP_SYS_ADMIN CAP_IPC_LOCK CAP_SYS_NICE";
233+
AmbientCapabilities = "CAP_SETPCAP CAP_SYS_ADMIN CAP_IPC_LOCK CAP_SYS_NICE CAP_SYS_RESOURCE";
234234
};
235235
};
236236
```
@@ -245,7 +245,7 @@ After=network.target
245245
Description=A cloud native declarative data plane.
246246
247247
[Service]
248-
AmbientCapabilities=CAP_SETPCAP CAP_SYS_ADMIN CAP_IPC_LOCK CAP_SYS_NICE
248+
AmbientCapabilities=CAP_SETPCAP CAP_SYS_ADMIN CAP_IPC_LOCK CAP_SYS_NICE CAP_SYS_RESOURCE
249249
ExecStart=/usr/bin/mayastor
250250
Type=simple
251251
User=nobody

io-engine-bench/.cargo/runner.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ fi
2020
#
2121
# * Set `cap_setpcap` to be able to set [ambient capabilities](https://lwn.net/Articles/636533/) which can be inherited
2222
# by children.
23-
# * Set `cap_sys_admin,cap_ipc_lock,cap_sys_nice` as they are required by the io-engine.
23+
# * Set `cap_sys_admin,cap_ipc_lock,cap_sys_nice,cap_sys_resource` as they are required by the io-engine.
2424
${MAYBE_SUDO} capsh \
25-
--caps="cap_setpcap+iep cap_sys_admin,cap_ipc_lock,cap_sys_nice+iep" \
26-
--addamb=cap_sys_admin --addamb=cap_ipc_lock --addamb=cap_sys_nice \
25+
--caps="cap_setpcap+iep cap_sys_admin,cap_ipc_lock,cap_sys_nice,cap_sys_resource+iep" \
26+
--addamb=cap_sys_admin --addamb=cap_ipc_lock --addamb=cap_sys_nice --addamb=cap_sys_resource \
2727
-- -c "${ARGS}"
2828

2929
if [ -d "$TARGET_CRITERION" ]; then

io-engine/.cargo/runner.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fi
1313
#
1414
# * Set `cap_setpcap` to be able to set [ambient capabilities](https://lwn.net/Articles/636533/) which can be inherited
1515
# by children.
16-
# * Set `cap_sys_admin,cap_ipc_lock,cap_sys_nice` as they are required by `mayastor`.
16+
# * Set `cap_sys_admin,cap_ipc_lock,cap_sys_nice,cap_sys_resource` as they are required by `mayastor`.
1717
${MAYBE_SUDO} capsh \
18-
--caps="cap_setpcap+iep cap_sys_admin,cap_ipc_lock,cap_sys_nice+iep" \
19-
--addamb=cap_sys_admin --addamb=cap_ipc_lock --addamb=cap_sys_nice \
18+
--caps="cap_setpcap+iep cap_sys_admin,cap_ipc_lock,cap_sys_nice,cap_sys_resource+iep" \
19+
--addamb=cap_sys_admin --addamb=cap_ipc_lock --addamb=cap_sys_nice --addamb=cap_sys_resource \
2020
-- -c "${ARGS}"

io-engine/src/bin/io-engine.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use io_engine::{
2121
eventing::Event,
2222
grpc, logger,
2323
persistent_store::PersistentStoreBuilder,
24+
prctl::Prctl,
2425
subsys::Registration,
2526
};
2627
use version_info::fmt_package_info;
@@ -273,6 +274,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
273274

274275
info!("{}", fmt_package_info!());
275276

277+
if let Err(err) = Prctl::set_io_flusher() {
278+
error!("Failed to set PR_SET_IO_FLUSHER, CAP_SYS_RESOURCE is required error: {err}");
279+
} else {
280+
info!("PR_SET_IO_FLUSHER is configured");
281+
}
282+
276283
// Handle diagnostics-related commands before initializing the agent.
277284
// Once diagnostics command is executed (regardless of status), exit the
278285
// agent.

io-engine/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub mod lvm;
3030
pub mod lvs;
3131
pub mod persistent_store;
3232
pub mod pool_backend;
33+
pub mod prctl;
3334
pub mod rebuild;
3435
pub mod replica_backend;
3536
pub mod sleep;

io-engine/src/prctl.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use libc::c_int;
2+
use std::io::{Error, Result};
3+
4+
const PR_SET_IO_FLUSHER: c_int = 57;
5+
6+
pub struct Prctl;
7+
8+
impl Prctl {
9+
/// From man page of prctl: If a user process is involved in the block layer
10+
/// or filesystem I/O path, and can allocate memory while processing I/O requests
11+
/// it must set arg2 to 1. This will put the process in the IO_FLUSHER state,
12+
/// which allows it special treatment to make progress when allocating memory.
13+
/// If arg2 is 0, the process will clear the IO_FLUSHER state, and the default
14+
/// behavior will be used.
15+
pub fn set_io_flusher() -> Result<()> {
16+
let ret = unsafe { libc::prctl(PR_SET_IO_FLUSHER, 1, 0, 0, 0) };
17+
if ret != 0 {
18+
return Err(Error::last_os_error());
19+
}
20+
Ok(())
21+
}
22+
}

utils/dependencies

0 commit comments

Comments
 (0)