shared: move storage-util to libshared
The storage backend providers (block, fs) and storagectl currently each
extract storage-util.c into their target. Several upcoming consumers
(machine-util's BindVolume parser, vmspawn's hotplug glue, machinectl's
new bind-volume verbs) need the StorageProvider type/string-table
helpers and a future shared Acquire client helper.
Move storage-util.{c,h} to src/shared so libshared exports the symbols
once and every consumer (storage providers, storagectl, libshared
itself) picks them up by linking libshared. Drop the now-redundant
'extract'/'objects' wiring in src/storage/meson.build.
No code changes; this is purely a relocation.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
@@ -199,6 +199,7 @@ shared_sources = files(
|
||||
'socket-netlink.c',
|
||||
'specifier.c',
|
||||
'ssl-util.c',
|
||||
'storage-util.c',
|
||||
'switch-root.c',
|
||||
'swtpm-util.c',
|
||||
'tar-util.c',
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "json-util.h"
|
||||
#include "string-table.h"
|
||||
#include "storage-util.h"
|
||||
|
||||
static const char *volume_type_table[_VOLUME_TYPE_MAX] = {
|
||||
[VOLUME_BLK] = "blk",
|
||||
[VOLUME_REG] = "reg",
|
||||
[VOLUME_DIR] = "dir",
|
||||
};
|
||||
|
||||
static const char *create_mode_table[_CREATE_MODE_MAX] = {
|
||||
[CREATE_ANY] = "any",
|
||||
[CREATE_NEW] = "new",
|
||||
[CREATE_OPEN] = "open",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(volume_type, VolumeType);
|
||||
DEFINE_STRING_TABLE_LOOKUP(create_mode, CreateMode);
|
||||
|
||||
JSON_DISPATCH_ENUM_DEFINE(json_dispatch_volume_type, VolumeType, volume_type_from_string);
|
||||
JSON_DISPATCH_ENUM_DEFINE(json_dispatch_create_mode, CreateMode, create_mode_from_string);
|
||||
@@ -0,0 +1,43 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "string-table-fundamental.h"
|
||||
#include "string-util.h"
|
||||
|
||||
/* This closely follows the kernel's inode type naming, i.e. is supposed to be a subset of what
|
||||
* inode_type_from_string() parses. */
|
||||
typedef enum VolumeType {
|
||||
VOLUME_BLK,
|
||||
VOLUME_REG,
|
||||
VOLUME_DIR,
|
||||
_VOLUME_TYPE_MAX,
|
||||
_VOLUME_TYPE_INVALID = -EINVAL,
|
||||
} VolumeType;
|
||||
|
||||
typedef enum CreateMode {
|
||||
CREATE_ANY,
|
||||
CREATE_NEW,
|
||||
CREATE_OPEN,
|
||||
_CREATE_MODE_MAX,
|
||||
_CREATE_MODE_INVALID = -EINVAL,
|
||||
} CreateMode;
|
||||
|
||||
DECLARE_STRING_TABLE_LOOKUP(volume_type, VolumeType);
|
||||
DECLARE_STRING_TABLE_LOOKUP(create_mode, CreateMode);
|
||||
|
||||
int json_dispatch_volume_type(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
|
||||
int json_dispatch_create_mode(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
|
||||
|
||||
static inline bool storage_volume_name_is_valid(const char *n) {
|
||||
return string_is_safe(n, /* flags= */ 0);
|
||||
}
|
||||
|
||||
static inline bool storage_template_name_is_valid(const char *n) {
|
||||
return string_is_safe(n, /* flags= */ 0);
|
||||
}
|
||||
|
||||
static inline bool storage_provider_name_is_valid(const char *n) {
|
||||
return string_is_safe(n, STRING_FILENAME);
|
||||
}
|
||||
Reference in New Issue
Block a user