Skip to content

Commit

Permalink
[LibOS,Docs] Remove deprecated syntax for FS mount points
Browse files Browse the repository at this point in the history
The following syntax was deprecated in Gramine v1.2:
- `fs.mount.[identifier].type`
- `fs.mount.[identifier].path`
- `fs.mount.[identifier].uri`

Now that the next version of Gramine will be v1.5, we can safely remove
this syntax.

This commit also drops the deprecated relative mount paths.

Signed-off-by: Kailun Qin <kailun.qin@intel.com>
  • Loading branch information
kailun-qin authored and dimakuv committed Apr 11, 2023
1 parent d51ff41 commit e2f7e7e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 133 deletions.
12 changes: 0 additions & 12 deletions Documentation/manifest-syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -964,18 +964,6 @@ See :ref:`vtune-sgx-profiling` for more information.
Deprecated options
------------------

FS mount points (deprecated syntax)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

::

fs.mount.[identifier].type = "[chroot|...]"
fs.mount.[identifier].path = "[PATH]"
fs.mount.[identifier].uri = "[URI]"

This syntax used a TOML table schema with keys for each mount. It has been
replaced with the ``fs.mounts`` TOML array.

Experimental sysfs topology support
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
114 changes: 3 additions & 111 deletions libos/src/fs/libos_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,11 @@ static int mount_one_nonroot(toml_table_t* mount, const char* prefix) {
}

if (mount_path[0] != '/') {
/* FIXME: Relative paths are deprecated starting from Gramine v1.2, we can disallow them
* completely two versions after it. */
if (is_dot_or_dotdot(mount_path)) {
log_error("Mount points '.' and '..' are not allowed, use absolute paths instead.");
ret = -EINVAL;
goto out;
}
log_error("Detected deprecated syntax: '%s.path' (\"%s\") is not absolute. "
log_error("Relative mount path: '%s.path' (\"%s\") is disallowed! "
"Consider converting it to absolute by adding \"/\" at the beginning.",
prefix, mount_path);
ret = -EINVAL;
goto out;
}

if (!mount_type || !strcmp(mount_type, "chroot")) {
Expand Down Expand Up @@ -296,105 +291,6 @@ static int mount_one_nonroot(toml_table_t* mount, const char* prefix) {
return ret;
}

/*
* Mount filesystems using the deprecated TOML-table syntax.
*
* FIXME: This is deprecated starting from Gramine v1.2 and can be removed two versions after it.
*/
static int mount_nonroot_from_toml_table(void) {
int ret = 0;

assert(g_manifest_root);
toml_table_t* manifest_fs = toml_table_in(g_manifest_root, "fs");
if (!manifest_fs)
return 0;

toml_table_t* manifest_fs_mounts = toml_table_in(manifest_fs, "mount");
if (!manifest_fs_mounts)
return 0;

ssize_t mounts_cnt = toml_table_ntab(manifest_fs_mounts);
if (mounts_cnt < 0)
return -EINVAL;
if (mounts_cnt == 0)
return 0;

log_error("Detected deprecated syntax: 'fs.mount'. Consider converting to the new array "
"syntax: 'fs.mounts = [{ type = \"chroot\", uri = \"...\", path = \"...\" }]'.");

/*
* *** Warning: A _very_ ugly hack below ***
*
* In the TOML-table syntax, the entries are not ordered, but Gramine actually relies on the
* specific mounting order (e.g. you can't mount /lib/asdf first and then /lib, but the other
* way around works). The problem is, that TOML structure is just a dictionary, so the order of
* keys is not preserved.
*
* To fix the issue, we use an ugly heuristic - we apply mounts sorted by the path length, which
* in most cases should result in a proper mount order.
*
* We do this in O(n^2) because we don't have a sort function, but that shouldn't be an issue -
* usually there are around 5 mountpoints with ~30 chars in paths, so it should still be quite
* fast.
*
* Fortunately, the table syntax is deprecated, so we'll be able to remove this code in a future
* Gramine release.
*
* Corresponding issue: https://github.com/gramineproject/gramine/issues/23.
*/
const char** keys = malloc(mounts_cnt * sizeof(*keys));
if (!keys)
return -ENOMEM;

size_t* lengths = malloc(mounts_cnt * sizeof(*lengths));
if (!lengths) {
ret = -ENOMEM;
goto out;
}

size_t longest = 0;
for (ssize_t i = 0; i < mounts_cnt; i++) {
keys[i] = toml_key_in(manifest_fs_mounts, i);
assert(keys[i]);

toml_table_t* mount = toml_table_in(manifest_fs_mounts, keys[i]);
assert(mount);
char* mount_path;
ret = toml_string_in(mount, "path", &mount_path);
if (ret < 0 || !mount_path) {
if (!ret)
ret = -ENOENT;
goto out;
}
lengths[i] = strlen(mount_path);
longest = MAX(longest, lengths[i]);
free(mount_path);
}

for (size_t i = 0; i <= longest; i++) {
for (ssize_t j = 0; j < mounts_cnt; j++) {
if (lengths[j] != i)
continue;
toml_table_t* mount = toml_table_in(manifest_fs_mounts, keys[j]);
assert(mount);

char* prefix = alloc_concat("fs.mount.", -1, keys[j], -1);
if (!prefix) {
ret = -ENOMEM;
goto out;
}
ret = mount_one_nonroot(mount, prefix);
free(prefix);
if (ret < 0)
goto out;
}
}
out:
free(keys);
free(lengths);
return ret;
}

static int mount_nonroot_from_toml_array(void) {
int ret;

Expand Down Expand Up @@ -466,10 +362,6 @@ int init_mount(void) {

int ret;

ret = mount_nonroot_from_toml_table();
if (ret < 0)
return ret;

ret = mount_nonroot_from_toml_array();
if (ret < 0)
return ret;
Expand Down
14 changes: 4 additions & 10 deletions libos/test/regression/toml_parsing.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ libos.entrypoint = "{{ entrypoint }}"

loader.env.LD_LIBRARY_PATH = "/lib"

# keep the deprecated `fs.mount` syntax for test purposes
# TODO: this syntax is deprecated in v1.2 and will be removed two versions after it.

fs.mount.lib.type = "chroot"
fs.mount.lib.path = "/lib"
fs.mount.lib.uri = "file:{{ gramine.runtimedir(libc) }}"

fs.mount.entrypoint.type = "chroot"
fs.mount.entrypoint.path = "{{ entrypoint }}"
fs.mount.entrypoint.uri = "file:{{ binary_dir }}/{{ entrypoint }}"
fs.mounts = [
{ path = "/lib", uri = "file:{{ gramine.runtimedir(libc) }}" },
{ path = "/{{ entrypoint }}", uri = "file:{{ binary_dir }}/{{ entrypoint }}" },
]

# the manifest option below added only so that this feature has any test coverage
libos.check_invalid_pointers = false
Expand Down

0 comments on commit e2f7e7e

Please sign in to comment.