Skip to content

Commit 0328700

Browse files
authored
Merge pull request #1232 from kernelkit/boot-warnings2
Fixes to misc. boot warnings
2 parents 7ea340d + f089470 commit 0328700

File tree

6 files changed

+203
-153
lines changed

6 files changed

+203
-153
lines changed

board/common/rootfs/etc/fstab

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ cfgfs /config configfs nofail,noauto 0 0
1515
# The chosen backing storage for the overlays placed on /cfg, /etc,
1616
# /home, /root, and /var, are determined dynamically by /usr/libexec/infix/mnt
1717
# depending on the available devices.
18-
mnttmp /mnt/tmp tmpfs defaults 0 0
19-
LABEL=aux /mnt/aux auto noatime,nodiratime,noauto,commit=30,errors=remount-ro 0 0
20-
LABEL=var /mnt/var auto noatime,nodiratime,noauto,commit=30,errors=remount-ro 0 0
21-
LABEL=cfg /mnt/cfg auto noatime,nodiratime,noauto,commit=30,errors=remount-ro 0 0
22-
hostfs /mnt/host 9p cache=none,msize=16384,noauto 0 0
23-
/usr/libexec/infix/mnt# /cfg helper none 0 0
18+
mnttmp /mnt/tmp tmpfs defaults 0 0
19+
LABEL=aux /mnt/aux auto noatime,nodiratime,noauto,errors=remount-ro 0 0
20+
LABEL=var /mnt/var ext4 noatime,nodiratime,noauto,commit=30,errors=remount-ro 0 0
21+
LABEL=cfg /mnt/cfg ext4 noatime,nodiratime,noauto,commit=30,errors=remount-ro 0 0
22+
hostfs /mnt/host 9p cache=none,msize=16384,noauto 0 0
23+
/usr/libexec/infix/mnt# /cfg helper none 0 0

board/common/rootfs/usr/libexec/infix/mnt

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ check_factory()
4444
factory_reset()
4545
{
4646
find /sys/class/leds/ -type l -exec sh -c 'echo 100 > $0/brightness' {} \;
47-
logger $opt -p user.crit -t "$nm" "Resetting to factory defaults."
47+
print_start "Resetting to factory defaults."
48+
logger $opt -p user.notice -t "$nm" "Resetting to factory defaults."
4849

4950
rm -rf /mnt/cfg/* /mnt/var/*
50-
51-
logger $opt -p user.crit -t "$nm" "Factory reset complete."
5251
sync
52+
53+
logger $opt -p user.notice -t "$nm" "Factory reset complete."
54+
print_end 0 "Factory reset complete."
55+
print_restore
5356
}
5457

5558
is_mmc()
@@ -105,15 +108,18 @@ find_partition_by_label()
105108
esac
106109

107110
disk="/dev/$devname"
111+
112+
#
113+
# 1. Try GPT/MBR partition label using sgdisk
114+
#
108115
result=$(sgdisk -p "$disk" 2>/dev/null | awk -v label="$label" -v devname="$devname" '
109-
/^ *[0-9]/ {
116+
/^ *[0-9]/ {
110117
if ($7 == label) {
111-
if (devname ~ /^(mmcblk|nvme|loop)/) {
112-
print devname "p" $1
113-
} else {
114-
print devname $1
115-
}
116-
exit 0
118+
if (devname ~ /^(mmcblk|nvme|loop)/)
119+
print devname "p" $1;
120+
else
121+
print devname $1;
122+
exit 0;
117123
}
118124
}
119125
')
@@ -122,7 +128,30 @@ find_partition_by_label()
122128
echo "$result"
123129
return 0
124130
fi
131+
132+
#
133+
# 2. Fallback: Check if the whole disk is an ext4/ext2/ext3 filesystem
134+
#
135+
136+
# Check for ext4/ext2/ext3 magic number (0xEF53) at offset 1080 (1024+56).
137+
magic_number=$(dd if="$disk" bs=1 skip=1080 count=2 2>/dev/null | od -t x2 -A n | tr -d ' \n')
138+
139+
# Check for both Little-Endian ('53ef') and Big-Endian ('ef53') interpretations of 0xEF53.
140+
# This supports bi-endian architectures like MIPS that may run in BE mode,
141+
# as well as the LE mode which is standard for RISC-V and ext filesystems.
142+
if [ "$magic_number" = "ef53" ] || [ "$magic_number" = "53ef" ]; then
143+
144+
# Read the volume label from offset 1144 (1024+120)
145+
fslabel=$(dd if="$disk" bs=1 skip=1144 count=16 2>/dev/null | tr -d '\000')
146+
logger $opt -p user.notice -t "$nm" "Found label $fslabel on disk $disk ..."
147+
148+
if [ "$fslabel" = "$label" ]; then
149+
echo "$devname"
150+
return 0
151+
fi
152+
fi
125153
done
154+
126155
return 1
127156
}
128157

@@ -273,6 +302,9 @@ mount_rw()
273302
# If something is already setup, leave it be.
274303
mountpoint -q "/$1" && return 0
275304

305+
# If partition doesn't exist (var is optional), signal caller.
306+
find_partition_by_label "$1" >/dev/null || return 1
307+
276308
# Check if /var has been resized to fill the sdcard/eMMC
277309
if [ "$1" = "var" ] && is_mmc; then
278310
if [ -f /mnt/aux/resized ] || [ -f /mnt/aux/resized.failed ]; then
@@ -289,8 +321,10 @@ mount_rw()
289321

290322
# TODO: Also look for UBI partitions
291323

292-
#
293-
tune2fs -c 0 -i 0 LABEL="$1" 2>/dev/null
324+
# Disable periodic fsck, yet keeping safety checks on ext4
325+
if grep "LABEL=$label" /etc/fstab |grep -q ext4; then
326+
tune2fs -c 0 -i 0 LABEL="$1" 2>/dev/null
327+
fi
294328
mount LABEL="$1" 2>/dev/null && return 0
295329

296330
return 1

src/confd/src/core.c

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@
88
struct confd confd;
99

1010

11-
int core_startup_save(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
12-
const char *xpath, sr_event_t event, unsigned request_id, void *priv)
11+
static int startup_save(sr_session_ctx_t *session, uint32_t sub_id, const char *model,
12+
const char *xpath, sr_event_t event, unsigned request_id, void *priv)
1313
{
14-
sr_event_t last_event = -1;
15-
static unsigned int last_request = -1;
16-
if (last_event == event && last_request == request_id)
17-
return SR_ERR_OK;
18-
last_event = event;
19-
last_request = request_id;
20-
2114
/* skip in bootstrap, triggered by load script to initialize startup datastore */
2215
if (systemf("runlevel >/dev/null 2>&1"))
2316
return SR_ERR_OK;
@@ -33,9 +26,10 @@ static confd_dependency_t add_dependencies(struct lyd_node **diff, const char *x
3326
struct lyd_node *new_node = NULL;
3427
struct lyd_node *target = NULL;
3528
struct lyd_node *root = NULL;
36-
int rc;
3729

3830
if (!lydx_get_xpathf(*diff, "%s", xpath)) {
31+
int rc;
32+
3933
/* Create the path, potentially creating a new tree */
4034
rc = lyd_new_path(NULL, LYD_CTX(*diff), xpath, value, LYD_NEW_PATH_UPDATE, &new_node);
4135
if (rc != LY_SUCCESS || !new_node) {
@@ -147,7 +141,7 @@ static confd_dependency_t handle_dependencies(struct lyd_node **diff, struct lyd
147141
return result;
148142
}
149143

150-
static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *module_name,
144+
static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *model_name,
151145
const char *xpath, sr_event_t event, uint32_t request_id, void *_confd)
152146
{
153147
struct lyd_node *diff = NULL, *config = NULL;
@@ -258,16 +252,20 @@ static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *mod
258252

259253
AUDIT("The new configuration has been applied.");
260254
}
255+
261256
free_diff:
262-
lyd_free_tree(diff);
263-
return rc;
257+
lyd_free_tree(diff);
258+
return rc;
264259
}
265260

266-
static inline int subscribe_module(char *model, struct confd *confd, int flags) {
267-
return sr_module_change_subscribe(confd->session, model, "//.", change_cb, confd,
268-
CB_PRIO_PRIMARY, SR_SUBSCR_CHANGE_ALL_MODULES | SR_SUBSCR_DEFAULT | flags, &confd->sub) &&
269-
sr_module_change_subscribe(confd->startup, model, "//.", core_startup_save, NULL,
270-
CB_PRIO_PASSIVE, SR_SUBSCR_PASSIVE | SR_SUBSCR_CHANGE_ALL_MODULES, &confd->sub);
261+
static inline int subscribe_model(char *model, struct confd *confd, int flags)
262+
{
263+
return sr_module_change_subscribe(confd->session, model, "//.", change_cb, confd,
264+
CB_PRIO_PRIMARY, SR_SUBSCR_CHANGE_ALL_MODULES |
265+
SR_SUBSCR_DEFAULT | flags, &confd->sub) ||
266+
sr_module_change_subscribe(confd->startup, model, "//.", startup_save, NULL,
267+
CB_PRIO_PASSIVE, SR_SUBSCR_CHANGE_ALL_MODULES |
268+
SR_SUBSCR_PASSIVE, &confd->sub);
271269
}
272270

273271
int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
@@ -295,7 +293,7 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
295293
if (!confd.conn)
296294
goto err;
297295

298-
/* The startup datastore is used for the core_startup_save() hook */
296+
/* The startup datastore is used for the startup_save() hook */
299297
rc = sr_session_start(confd.conn, SR_DS_STARTUP, &confd.startup);
300298
if (rc)
301299
goto err;
@@ -314,69 +312,69 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
314312
*/
315313
confd.ifquirks = json_load_file("/etc/product/interface-quirks.json", 0, NULL);
316314

317-
rc = subscribe_module("ietf-interfaces", &confd, 0);
315+
rc = subscribe_model("ietf-interfaces", &confd, 0);
318316
if (rc) {
319317
ERROR("Failed to subscribe to ietf-interfaces");
320318
goto err;
321319
}
322-
rc = subscribe_module("ietf-netconf-acm", &confd, 0);
320+
rc = subscribe_model("ietf-netconf-acm", &confd, 0);
323321
if (rc) {
324322
ERROR("Failed to subscribe to ietf-netconf-acm");
325323
goto err;
326324
}
327-
rc = subscribe_module("infix-dhcp-client", &confd, 0);
325+
rc = subscribe_model("infix-dhcp-client", &confd, 0);
328326
if (rc) {
329327
ERROR("Failed to subscribe to infix-dhcp-client");
330328
goto err;
331329
}
332-
rc = subscribe_module("ietf-keystore", &confd, SR_SUBSCR_UPDATE);
330+
rc = subscribe_model("ietf-keystore", &confd, SR_SUBSCR_UPDATE);
333331
if (rc) {
334332
ERROR("Failed to subscribe to ietf-keystore");
335333
goto err;
336334
}
337-
rc = subscribe_module("infix-services", &confd, 0);
335+
rc = subscribe_model("infix-services", &confd, 0);
338336
if (rc) {
339337
ERROR("Failed to subscribe to infix-services");
340338
goto err;
341339
}
342-
rc = subscribe_module("ietf-system", &confd, 0);
340+
rc = subscribe_model("ietf-system", &confd, 0);
343341
if (rc) {
344342
ERROR("Failed to subscribe to ietf-system");
345343
goto err;
346344
}
347-
rc = subscribe_module("ieee802-dot1ab-lldp", &confd, 0);
345+
rc = subscribe_model("ieee802-dot1ab-lldp", &confd, 0);
348346
if (rc) {
349347
ERROR("Failed to subscribe to ieee802-dot1ab-lldp");
350348
goto err;
351349
}
352350
#ifdef CONTAINERS
353-
rc = subscribe_module("infix-containers", &confd, 0);
351+
rc = subscribe_model("infix-containers", &confd, 0);
354352
if (rc) {
355353
ERROR("Failed to subscribe to infix-containers");
356354
goto err;
357355
}
358356
#endif
359-
rc = subscribe_module("infix-dhcp-server", &confd, 0);
357+
rc = subscribe_model("infix-dhcp-server", &confd, 0);
360358
if (rc) {
361359
ERROR("Failed to subscribe to infix-dhcp-server");
362360
goto err;
363361
}
364-
rc = subscribe_module("ietf-routing", &confd, 0);
362+
rc = subscribe_model("ietf-routing", &confd, 0);
365363
if (rc) {
366364
ERROR("Failed to subscribe to ietf-routing");
367365
goto err;
368366
}
369-
rc = subscribe_module("ietf-hardware", &confd, 0);
367+
rc = subscribe_model("ietf-hardware", &confd, 0);
370368
if (rc) {
371369
ERROR("Failed to subscribe to ietf-hardware");
372370
goto err;
373371
}
374-
rc = subscribe_module("infix-firewall", &confd, 0);
372+
rc = subscribe_model("infix-firewall", &confd, 0);
375373
if (rc) {
376374
ERROR("Failed to subscribe to infix-firewall");
377375
goto err;
378376
}
379-
rc = subscribe_module("infix-meta", &confd, SR_SUBSCR_UPDATE);
377+
rc = subscribe_model("infix-meta", &confd, SR_SUBSCR_UPDATE);
380378
if (rc) {
381379
ERROR("Failed to subscribe to infix-meta");
382380
goto err;

src/confd/src/core.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ struct confd {
135135
struct dagger netdag;
136136
};
137137

138-
int core_startup_save (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *);
139138

140139
static inline int register_change(sr_session_ctx_t *session, const char *module, const char *xpath,
141140
int flags, sr_module_change_cb cb, void *arg, sr_subscription_ctx_t **sub)

0 commit comments

Comments
 (0)