1 Star 0 Fork 98

Mingtai/systemd

forked from src-openEuler/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-fstab-generator-skip-root-directory-handling-when-nf.patch 3.64 KB
一键复制 编辑 原始数据 按行查看 历史
From 60d4ac20d8b02dd8f67150aaf55a4e0d019f58d2 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Wed, 5 Jan 2022 19:24:46 +0900
Subject: [PATCH] fstab-generator: skip root directory handling when nfsroot is
requested
Fixes RHBZ#2037233 (https://bugzilla.redhat.com/show_bug.cgi?id=2037233).
(cherry picked from commit 77b8e92de8264c0b656a7d2fb437dd8d598ab597)
(cherry picked from commit 7ca41c509e6549abbfc753e560c822b5e32a63cc)
Conflict:NA
Reference:https://github.com/systemd/systemd/commit/60d4ac20d8b02dd8f67150aaf55a4e0d019f58d2
---
src/fstab-generator/fstab-generator.c | 59 ++++++++++++++++++++++++++-
1 file changed, 57 insertions(+), 2 deletions(-)
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 1dee728233..0f3892789f 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -10,6 +10,7 @@
#include "fs-util.h"
#include "fstab-util.h"
#include "generator.h"
+#include "in-addr-util.h"
#include "log.h"
#include "main-func.h"
#include "mkdir.h"
@@ -691,6 +692,57 @@ static int parse_fstab(bool initrd) {
return r;
}
+static int sysroot_is_nfsroot(void) {
+ union in_addr_union u;
+ const char *sep, *a;
+ int r;
+
+ assert(arg_root_what);
+
+ /* From dracut.cmdline(7).
+ *
+ * root=[<server-ip>:]<root-dir>[:<nfs-options>]
+ * root=nfs:[<server-ip>:]<root-dir>[:<nfs-options>],
+ * root=nfs4:[<server-ip>:]<root-dir>[:<nfs-options>],
+ * root={dhcp|dhcp6}
+ *
+ * mount nfs share from <server-ip>:/<root-dir>, if no server-ip is given, use dhcp next_server.
+ * If server-ip is an IPv6 address it has to be put in brackets, e.g. [2001:DB8::1]. NFS options
+ * can be appended with the prefix ":" or "," and are separated by ",". */
+
+ if (path_equal(arg_root_what, "/dev/nfs") ||
+ STR_IN_SET(arg_root_what, "dhcp", "dhcp6") ||
+ STARTSWITH_SET(arg_root_what, "nfs:", "nfs4:"))
+ return true;
+
+ /* IPv6 address */
+ if (arg_root_what[0] == '[') {
+ sep = strchr(arg_root_what + 1, ']');
+ if (!sep)
+ return -EINVAL;
+
+ a = strndupa(arg_root_what + 1, sep - arg_root_what - 1);
+
+ r = in_addr_from_string(AF_INET6, a, &u);
+ if (r < 0)
+ return r;
+
+ return true;
+ }
+
+ /* IPv4 address */
+ sep = strchr(arg_root_what, ':');
+ if (sep) {
+ a = strndupa(arg_root_what, sep - arg_root_what);
+
+ if (in_addr_from_string(AF_INET, a, &u) >= 0)
+ return true;
+ }
+
+ /* root directory without address */
+ return path_is_absolute(arg_root_what) && !path_startswith(arg_root_what, "/dev");
+}
+
static int add_sysroot_mount(void) {
_cleanup_free_ char *what = NULL;
const char *opts, *fstype;
@@ -708,9 +760,12 @@ static int add_sysroot_mount(void) {
return 0;
}
- if (path_equal(arg_root_what, "/dev/nfs")) {
+ r = sysroot_is_nfsroot();
+ if (r < 0)
+ log_debug_errno(r, "Failed to determine if the root directory is on NFS, assuming not: %m");
+ else if (r > 0) {
/* This is handled by the kernel or the initrd */
- log_debug("Skipping root directory handling, as /dev/nfs was requested.");
+ log_debug("Skipping root directory handling, as root on NFS was requested.");
return 0;
}
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangmingtaip/systemd.git
git@gitee.com:yangmingtaip/systemd.git
yangmingtaip
systemd
systemd
master

搜索帮助