repart: split ListCandidateDevices handler into its own file

repart.c is already 11 kLOC. The candidate-device enumeration path is
about to grow a subscription mode that brings its own helpers and
per-link state, which doesn't belong in the partitioning core.

Move vl_method_list_candidate_devices() (and only that function -- the
header exports just that symbol) into a new src/repart/repart-list-candidate-devices.{c,h}.
No behavior change.
This commit is contained in:
Lennart Poettering
2026-06-01 11:24:51 +02:00
parent 8ff7a5cd09
commit 3e29bd9880
4 changed files with 84 additions and 64 deletions
+2 -1
View File
@@ -9,8 +9,9 @@ executables += [
'name' : 'systemd-repart',
'public' : true,
'extract' : files(
'repart.c',
'iso9660.c',
'repart.c',
'repart-list-candidate-devices.c',
),
'dependencies' : [
libblkid_cflags,
@@ -0,0 +1,71 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "sd-json.h"
#include "sd-varlink.h"
#include "blockdev-list.h"
#include "json-util.h"
#include "repart-list-candidate-devices.h"
int vl_method_list_candidate_devices(
sd_varlink *link,
sd_json_variant *parameters,
sd_varlink_method_flags_t flags,
void *userdata) {
struct {
bool ignore_root;
bool ignore_empty;
} p = {};
static const sd_json_dispatch_field dispatch_table[] = {
{ "ignoreRoot", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, voffsetof(p, ignore_root), 0 },
{ "ignoreEmpty", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, voffsetof(p, ignore_empty), 0 },
{}
};
int r;
assert(link);
assert(FLAGS_SET(flags, SD_VARLINK_METHOD_MORE));
r = sd_varlink_dispatch(link, parameters, dispatch_table, &p);
if (r != 0)
return r;
BlockDevice *l = NULL;
size_t n = 0;
CLEANUP_ARRAY(l, n, block_device_array_free);
r = blockdev_list(
BLOCKDEV_LIST_SHOW_SYMLINKS|
BLOCKDEV_LIST_REQUIRE_PARTITION_SCANNING|
BLOCKDEV_LIST_IGNORE_ZRAM|
BLOCKDEV_LIST_METADATA|
BLOCKDEV_LIST_IGNORE_READ_ONLY|
(p.ignore_empty ? BLOCKDEV_LIST_IGNORE_EMPTY : 0)|
(p.ignore_root ? BLOCKDEV_LIST_IGNORE_ROOT : 0),
&l,
&n);
if (r < 0)
return r;
r = sd_varlink_set_sentinel(link, "io.systemd.Repart.NoCandidateDevices");
if (r < 0)
return r;
FOREACH_ARRAY(d, l, n) {
r = sd_varlink_replybo(link,
SD_JSON_BUILD_PAIR_STRING("node", d->node),
JSON_BUILD_PAIR_STRV_NON_EMPTY("symlinks", d->symlinks),
JSON_BUILD_PAIR_UNSIGNED_NOT_EQUAL("diskseq", d->diskseq, UINT64_MAX),
JSON_BUILD_PAIR_UNSIGNED_NOT_EQUAL("sizeBytes", d->size, UINT64_MAX),
JSON_BUILD_PAIR_STRING_NON_EMPTY("model", d->model),
JSON_BUILD_PAIR_STRING_NON_EMPTY("vendor", d->vendor),
JSON_BUILD_PAIR_STRING_NON_EMPTY("subsystem", d->subsystem));
if (r < 0)
return r;
}
return 0;
}
@@ -0,0 +1,10 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "sd-forward.h"
int vl_method_list_candidate_devices(
sd_varlink *link,
sd_json_variant *parameters,
sd_varlink_method_flags_t flags,
void *userdata);
+1 -63
View File
@@ -70,6 +70,7 @@
#include "process-util.h"
#include "random-util.h"
#include "ratelimit.h"
#include "repart-list-candidate-devices.h"
#include "reread-partition-table.h"
#include "resize-fs.h"
#include "rm-rf.h"
@@ -11254,69 +11255,6 @@ static int context_ponder(Context *context) {
return 0;
}
static int vl_method_list_candidate_devices(
sd_varlink *link,
sd_json_variant *parameters,
sd_varlink_method_flags_t flags,
void *userdata) {
struct {
bool ignore_root;
bool ignore_empty;
} p = {};
static const sd_json_dispatch_field dispatch_table[] = {
{ "ignoreRoot", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, voffsetof(p, ignore_root), 0 },
{ "ignoreEmpty", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, voffsetof(p, ignore_empty), 0 },
{}
};
int r;
assert(link);
assert(FLAGS_SET(flags, SD_VARLINK_METHOD_MORE));
r = sd_varlink_dispatch(link, parameters, dispatch_table, &p);
if (r != 0)
return r;
BlockDevice *l = NULL;
size_t n = 0;
CLEANUP_ARRAY(l, n, block_device_array_free);
r = blockdev_list(
BLOCKDEV_LIST_SHOW_SYMLINKS|
BLOCKDEV_LIST_REQUIRE_PARTITION_SCANNING|
BLOCKDEV_LIST_IGNORE_ZRAM|
BLOCKDEV_LIST_METADATA|
BLOCKDEV_LIST_IGNORE_READ_ONLY|
(p.ignore_empty ? BLOCKDEV_LIST_IGNORE_EMPTY : 0)|
(p.ignore_root ? BLOCKDEV_LIST_IGNORE_ROOT : 0),
&l,
&n);
if (r < 0)
return r;
r = sd_varlink_set_sentinel(link, "io.systemd.Repart.NoCandidateDevices");
if (r < 0)
return r;
FOREACH_ARRAY(d, l, n) {
r = sd_varlink_replybo(link,
SD_JSON_BUILD_PAIR_STRING("node", d->node),
JSON_BUILD_PAIR_STRV_NON_EMPTY("symlinks", d->symlinks),
JSON_BUILD_PAIR_UNSIGNED_NOT_EQUAL("diskseq", d->diskseq, UINT64_MAX),
JSON_BUILD_PAIR_UNSIGNED_NOT_EQUAL("sizeBytes", d->size, UINT64_MAX),
JSON_BUILD_PAIR_STRING_NON_EMPTY("model", d->model),
JSON_BUILD_PAIR_STRING_NON_EMPTY("vendor", d->vendor),
JSON_BUILD_PAIR_STRING_NON_EMPTY("subsystem", d->subsystem));
if (r < 0)
return r;
}
return 0;
}
static JSON_DISPATCH_ENUM_DEFINE(json_dispatch_empty_mode, EmptyMode, empty_mode_from_string);
typedef struct RunParameters {