Skip to content

Commit

Permalink
code structure: rename load_extension-series rpc methods to `regist…
Browse files Browse the repository at this point in the history
…er_extension`
  • Loading branch information
sisungo committed May 18, 2024
1 parent 324c192 commit 98e95f7
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 35 deletions.
8 changes: 4 additions & 4 deletions airup-sdk/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ pub trait ConnectionExt<'a>: crate::Connection {
}

/// Loads an extension.
fn load_extension(&'a mut self, name: &'a str, path: &'a str) -> Self::Invoke<'a, ()> {
self.invoke("system.load_extension", (name, path))
fn register_extension(&'a mut self, name: &'a str, path: &'a str) -> Self::Invoke<'a, ()> {
self.invoke("system.register_extension", (name, path))
}

/// Unloads an extension.
fn unload_extension(&'a mut self, name: &'a str) -> Self::Invoke<'a, ()> {
self.invoke("system.load_extension", name)
fn unregister_extension(&'a mut self, name: &'a str) -> Self::Invoke<'a, ()> {
self.invoke("system.unregister_extension", name)
}
}
impl<'a, T> ConnectionExt<'a> for T where T: crate::Connection {}
12 changes: 6 additions & 6 deletions airup/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub struct Cmdline {
#[arg(long)]
print_local_build_manifest: bool,

/// Unloads an Airup extension
/// Unregisters an Airup extension
#[arg(long)]
unload_extension: Option<String>,
unregister_extension: Option<String>,
}

pub fn main(cmdline: Cmdline) -> anyhow::Result<()> {
Expand All @@ -27,16 +27,16 @@ pub fn main(cmdline: Cmdline) -> anyhow::Result<()> {
return print_local_build_manifest();
}

if let Some(name) = cmdline.unload_extension {
return unload_extension(&name);
if let Some(name) = cmdline.unregister_extension {
return unregister_extension(&name);
}

Ok(())
}

pub fn unload_extension(name: &str) -> anyhow::Result<()> {
pub fn unregister_extension(name: &str) -> anyhow::Result<()> {
let mut conn = super::connect()?;
conn.unload_extension(name)??;
conn.unregister_extension(name)??;

Ok(())
}
Expand Down
8 changes: 6 additions & 2 deletions airupd/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ impl Extensions {
Self::default()
}

pub async fn load(&self, name: String, path: &str) -> Result<(), airup_sdk::Error> {
/// Registers an extension.
pub async fn register(&self, name: String, path: &str) -> Result<(), airup_sdk::Error> {
let mut lock = self.0.write().await;
if lock.contains_key(&name) {
return Err(airup_sdk::Error::Exists);
Expand All @@ -38,6 +39,7 @@ impl Extensions {
Ok(())
}

/// Invokes an RPC invokation to an extension.
pub async fn rpc_invoke(&self, mut req: airup_sdk::ipc::Request) -> airup_sdk::ipc::Response {
let mut method_splited = req.method.splitn(2, '.');
let extension = method_splited.next().unwrap();
Expand All @@ -56,7 +58,8 @@ impl Extensions {
})
}

pub async fn unload(&self, name: &str) -> Result<(), airup_sdk::Error> {
/// Unregisters an extension.
pub async fn unregister(&self, name: &str) -> Result<(), airup_sdk::Error> {
self.0
.write()
.await
Expand Down Expand Up @@ -107,6 +110,7 @@ struct ExtensionHost {
gate: mpsc::Receiver<(Request, oneshot::Sender<ciborium::Value>)>,
}
impl ExtensionHost {
/// Maximum size of received message from an extension, in bytes.
const SIZE_LIMIT: usize = 8 * 1024 * 1024;

fn run_on_the_fly(mut self) {
Expand Down
12 changes: 6 additions & 6 deletions airupd/src/ipc/api/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub(super) fn init<H: BuildHasher>(methods: &mut HashMap<&'static str, Method, H
list_services,
enter_milestone,
trigger_event,
load_extension,
unload_extension,
register_extension,
unregister_extension,
]
)
.iter()
Expand Down Expand Up @@ -133,11 +133,11 @@ async fn trigger_event(event: Event) -> Result<(), Error> {
}

#[airupfx::macros::api]
async fn load_extension(name: String, path: String) -> Result<(), Error> {
airupd().extensions.load(name, &path).await
async fn register_extension(name: String, path: String) -> Result<(), Error> {
airupd().extensions.register(name, &path).await
}

#[airupfx::macros::api]
async fn unload_extension(name: String) -> Result<(), Error> {
airupd().extensions.unload(&name).await
async fn unregister_extension(name: String) -> Result<(), Error> {
airupd().extensions.unregister(&name).await
}
4 changes: 2 additions & 2 deletions airupd/src/supervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ impl LastErrorContext {
}

fn set_autosave(&self, val: bool) -> bool {
self.auto_save.swap(val, atomic::Ordering::SeqCst)
self.auto_save.swap(val, atomic::Ordering::AcqRel)
}

fn take_autosave(&self) -> bool {
Expand Down Expand Up @@ -668,7 +668,7 @@ impl RetryContext {

/// Sets the retry count to zero.
fn reset_count(&self) {
self.count.store(0, atomic::Ordering::SeqCst);
self.count.store(0, atomic::Ordering::Release);
}

/// Enables retrying if disabled.
Expand Down
2 changes: 1 addition & 1 deletion airupfx/airupfx-env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ sysinfo = "0.30"
tokio = { workspace = true }

[target.'cfg(target_family = "unix")'.dependencies]
libc = "0.2"
libc = "0.2"
7 changes: 5 additions & 2 deletions airupfx/airupfx-extensions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! # AirupFX Extension Framework
//! This crate provides a high-level framework for writing Airup extensions in Rust.
use airup_sdk::{
info::ConnectionExt,
ipc::MessageProto,
Expand Down Expand Up @@ -69,7 +72,7 @@ impl Server {
airup_sdk::nonblocking::Connection::connect(airup_sdk::socket_path()).await?;

match airup_rpc_conn
.load_extension(&extension_name, &self.path)
.register_extension(&extension_name, &self.path)
.await
{
Ok(Ok(())) => (),
Expand Down Expand Up @@ -98,7 +101,7 @@ impl Server {
return;
};

_ = airup_rpc_conn.unload_extension(&extension_name).await;
_ = airup_rpc_conn.unregister_extension(&extension_name).await;

std::process::exit(0);
});
Expand Down
2 changes: 1 addition & 1 deletion airupfx/airupfx-fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ cfg-if = "1"
tokio = { workspace = true }

[target.'cfg(target_family = "unix")'.dependencies]
libc = "0.2"
libc = "0.2"
2 changes: 1 addition & 1 deletion airupfx/airupfx-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { workspace = true }
tokio = { workspace = true }
4 changes: 2 additions & 2 deletions airupfx/airupfx-isolator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
cgroups = ["cgroups-rs"]
cgroups = ["dep:cgroups-rs"]

[dependencies]
airupfx-time = { path = "../airupfx-time" }
cfg-if = "1"

[target.'cfg(target_os = "linux")'.dependencies]
cgroups-rs = { version = "0.3", optional = true }
cgroups-rs = { version = "0.3", optional = true }
2 changes: 1 addition & 1 deletion airupfx/airupfx-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ proc-macro = true
[dependencies]
proc-macro2 = "1"
quote = "1"
syn = "2"
syn = "2"
2 changes: 1 addition & 1 deletion airupfx/airupfx-power/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ cfg-if = "1"
tokio = { workspace = true }

[target.'cfg(target_family = "unix")'.dependencies]
libc = "0.2"
libc = "0.2"
2 changes: 1 addition & 1 deletion airupfx/airupfx-process/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ airupfx-env = { path = "../airupfx-env" }
airupfx-io = { path = "../airupfx-io" }
libc = "0.2"
thiserror = "1"
tokio = { workspace = true }
tokio = { workspace = true }
2 changes: 1 addition & 1 deletion airupfx/airupfx-signal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ publish = false
[dependencies]
cfg-if = "1"
libc = "0.2"
tokio = { workspace = true }
tokio = { workspace = true }
2 changes: 1 addition & 1 deletion airupfx/airupfx-time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { workspace = true }
tokio = { workspace = true }
1 change: 1 addition & 0 deletions airupfx/airupfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ publish = false

[features]
cgroups = ["airupfx-isolator/cgroups"]
selinux = ["dep:selinux"]

[dependencies]
airupfx-env = { path = "../airupfx-env" }
Expand Down
2 changes: 2 additions & 0 deletions docs/en-US/api_manual/ipc/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ Module `debug` provides methods that are used for Airup debugging.
**Return Value**: Content of the parameter.

**Description**: Returns the `Response` object provided by the parameter.

**NOTE**: This is an API exposed as an Airup internal implementation detail and is subject to change.

1 change: 1 addition & 0 deletions docs/en-US/api_manual/ipc/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,5 @@ with the same name will be overridden, rather than returning an error.
**Description**: Unloads an Airup extension.

**Possible Errors**:

- `NOT_FOUND`: The specified extension was not installed yet.
2 changes: 2 additions & 0 deletions docs/zh-CN/api_manual/ipc/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@
**返回值**:参数的内容

**描述**:返回参数中提供的 `Response` 对象。

**注意**:这是作为 Airup 的内部实现细节而暴露的 API,可能随时发生变更。

2 changes: 1 addition & 1 deletion docs/zh-CN/api_manual/ipc/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@
**描述**:卸载一个 Airup 扩展。

**可能的错误**
`NOT_FOUND`:指定的扩展还未被安装。

`NOT_FOUND`:指定的扩展还未被安装。
8 changes: 6 additions & 2 deletions extensions/fallback-logger/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A simple logger.
//! A simple logger for fallback use.
//!
//! This has some limitations and has bad performance. Being designed as an "fallback choice", the implementation aims to be
//! This has some limitations and has poor performance. Being designed as an "fallback choice", the implementation aims to be
//! small.
use airup_sdk::{blocking::fs::DirChain, system::LogRecord, Error};
Expand Down Expand Up @@ -46,6 +46,10 @@ async fn append(subject: String, module: String, msg: Vec<u8>) -> Result<(), Err

#[airupfx::macros::api]
async fn tail(subject: String, n: usize) -> Result<Vec<LogRecord>, Error> {
if n > 1536 {
return Err(Error::TimedOut);
}

let reader = open_subject_read(&subject).map_err(|x| Error::Io {
message: x.to_string(),
})?;
Expand Down

0 comments on commit 98e95f7

Please sign in to comment.