validatefs: several follow-ups (#36910)

This commit is contained in:
Yu Watanabe
2025-04-01 05:35:21 +09:00
committed by GitHub
5 changed files with 16 additions and 17 deletions
+1 -1
View File
@@ -84,7 +84,7 @@
<term><option>--root=</option></term>
<listitem><para>Takes an absolute path or the special string <literal>auto</literal>. The specified
path if removed as prefix from the specified mount point argument before the validation. If set to
path is removed as prefix from the specified mount point argument before the validation. If set to
<literal>auto</literal> defaults to unspecified on the host and <filename>/sysroot/</filename> when
run in initrd context, in order to validate the mount constraint data relative to the future file
system root.</para>
+8 -5
View File
@@ -192,10 +192,11 @@ int getxattr_at_bool(int fd, const char *path, const char *name, int at_flags) {
}
int getxattr_at_strv(int fd, const char *path, const char *name, int at_flags, char ***ret_strv) {
_cleanup_free_ char *nulstr = NULL;
size_t nulstr_size;
int r;
_cleanup_free_ char *nulstr = NULL;
size_t nulstr_size = 0;
assert(ret_strv);
r = getxattr_at_malloc(fd, path, name, at_flags, &nulstr, &nulstr_size);
if (r < 0)
@@ -343,11 +344,13 @@ int xsetxattr_full(
return 0;
}
int xsetxattr_strv(int fd, const char *path, int at_flags, const char *name, char * const* l) {
int xsetxattr_strv(int fd, const char *path, int at_flags, const char *name, char * const *l) {
_cleanup_free_ char *nulstr = NULL;
size_t size;
int r;
_cleanup_free_ char *nulstr = NULL;
size_t size = 0;
assert(name);
r = strv_make_nulstr(l, &nulstr, &size);
if (r < 0)
return r;
+1 -1
View File
@@ -50,7 +50,7 @@ static inline int xsetxattr(
return xsetxattr_full(fd, path, at_flags, name, value, SIZE_MAX, 0);
}
int xsetxattr_strv(int fd, const char *path, int at_flags, const char *name, char *const*l);
int xsetxattr_strv(int fd, const char *path, int at_flags, const char *name, char * const *l);
int xremovexattr(int fd, const char *path, int at_flags, const char *name);
+5 -9
View File
@@ -33,7 +33,7 @@ static int help(void) {
return log_oom();
printf("%1$s [OPTIONS...] /path/to/mountpoint\n"
"\n%3$sCheck file system validation constraints.%4$s\n"
"\n%3$sCheck file system validation constraints.%4$s\n\n"
" -h --help Show this help and exit\n"
" --version Print version string and exit\n"
" --root=PATH|auto Operate relative to the specified path\n"
@@ -136,7 +136,7 @@ static int validate_fields_read(int fd, ValidateFields *ret) {
assert(ret);
_cleanup_free_ char *t = NULL;
r = getxattr_at_malloc(fd, /* path= */ NULL, "user.validatefs.gpt_type_uuid", AT_EMPTY_PATH, &t, /* ret_size= */ NULL);
r = fgetxattr_malloc(fd, "user.validatefs.gpt_type_uuid", &t, /* ret_size= */ NULL);
if (r < 0) {
if (r != -ENODATA && !ERRNO_IS_NOT_SUPPORTED(r))
return log_error_errno(r, "Failed to read 'user.validatefs.gpt_type_uuid' xattr: %m");
@@ -146,7 +146,7 @@ static int validate_fields_read(int fd, ValidateFields *ret) {
return log_error_errno(r, "Failed to parse 'user.validatefs.gpt_type_uuid' xattr: %s", t);
}
r = getxattr_at_malloc(fd, /* path= */ NULL, "user.validatefs.gpt_label", AT_EMPTY_PATH, &f.gpt_label, /* ret_size= */ NULL);
r = fgetxattr_malloc(fd, "user.validatefs.gpt_label", &f.gpt_label, /* ret_size= */ NULL);
if (r < 0) {
if (r != -ENODATA && !ERRNO_IS_NOT_SUPPORTED(r))
return log_error_errno(r, "Failed to read 'user.validatefs.gpt_label' xattr: %m");
@@ -318,14 +318,10 @@ static int run(int argc, char *argv[]) {
return r;
if (r == 0) {
log_info("File system '%s' has no validation constraints set, not validating.", resolved);
return EXIT_SUCCESS;
return 0;
}
r = validate_fields_check(target_fd, resolved, &f);
if (r < 0)
return r;
return EXIT_SUCCESS;
return validate_fields_check(target_fd, resolved, &f);
}
DEFINE_MAIN_FUNCTION(run);
+1 -1
View File
@@ -15,9 +15,9 @@ BindsTo=%i.mount
Conflicts=shutdown.target
After=%i.mount
Before=shutdown.target systemd-pcrfs@%i.service systemd-quotacheck@%i.service systemd-growfs@%i.service
FailureAction=reboot-immediate
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart={{LIBEXECDIR}}/systemd-validatefs --root=auto %f
FailureAction=reboot-immediate