Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7e5fca58 authored by Dennis Shen's avatar Dennis Shen
Browse files

aconfig: create aconfig_storage_write_api crate

aconfig_storage_write_api crate is the lib to be used by aconfig storage
daemon to update flag value at a given offset.

Note that mmap api is unsafe from memmap2 crate. This is due to the
possibility of other code write to the file after mmaping the file into
memory. Therefore the api to write to storage value file is also marked
as unsafe. In reality, the persistent storage value file is protected by
SELinux policy to allow write access only to aconfig storage daemon. In
addition, aconfig storage daemon is single threaded. So at any time,
only one thread is writing to a storage file, and only thru the mmapped
file in memory (not thru direct file write). So it would safe for
storage daemon to call this api.

Bug: b/312444587
Test: m libaconfig_storage_write_api; atest
aconfig_storage_write_api.test

Change-Id: I93cffea0d94e4c40e711d809418c0b18b6d9bfe1
parent 05b128bf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ members = [
    "aconfig_protos",
    "aconfig_storage_file",
    "aconfig_storage_read_api",
    "aconfig_storage_write_api",
    "aflags",
    "printflags"
]
+4 −0
Original line number Diff line number Diff line
@@ -69,6 +69,10 @@
    }
  ],
  "postsubmit": [
    {
      // aconfig_storage_write_api unit tests
      "name": "aconfig_storage_write_api.test"
    },
    {
      // aconfig_storage_read_api unit tests
      "name": "aconfig_storage_read_api.test"
+6 −0
Original line number Diff line number Diff line
@@ -163,6 +163,12 @@ pub enum AconfigStorageError {
    #[error("fail to map storage file")]
    MapFileFail(#[source] anyhow::Error),

    #[error("fail to get mapped file")]
    ObtainMappedFileFail(#[source] anyhow::Error),

    #[error("fail to flush mapped storage file")]
    MapFlushFail(#[source] anyhow::Error),

    #[error("number of items in hash table exceed limit")]
    HashTableSizeLimit(#[source] anyhow::Error),

+37 −0
Original line number Diff line number Diff line
package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

rust_defaults {
    name: "aconfig_storage_write_api.defaults",
    edition: "2021",
    lints: "none",
    srcs: ["src/lib.rs"],
    rustlibs: [
        "libanyhow",
        "libtempfile",
        "libmemmap2",
        "libcxx",
        "libthiserror",
        "libaconfig_storage_file",
    ],
}

rust_library {
    name: "libaconfig_storage_write_api",
    crate_name: "aconfig_storage_write_api",
    host_supported: true,
    defaults: ["aconfig_storage_write_api.defaults"],
}

rust_test_host {
    name: "aconfig_storage_write_api.test",
    test_suites: ["general-tests"],
    defaults: ["aconfig_storage_write_api.defaults"],
    data: [
        "tests/flag.val",
    ],
    rustlibs: [
        "libaconfig_storage_read_api",
    ],
}
+21 −0
Original line number Diff line number Diff line
[package]
name = "aconfig_storage_write_api"
version = "0.1.0"
edition = "2021"

[features]
default = ["cargo"]
cargo = []

[dependencies]
anyhow = "1.0.69"
memmap2 = "0.8.0"
tempfile = "3.9.0"
thiserror = "1.0.56"
protobuf = "3.2.0"
once_cell = "1.19.0"
aconfig_storage_file = { path = "../aconfig_storage_file" }
aconfig_storage_read_api = { path = "../aconfig_storage_read_api" }

[build-dependencies]
cxx-build = "1.0"
Loading