Skip to content

Commit

Permalink
printf3
Browse files Browse the repository at this point in the history
  • Loading branch information
pothos committed Nov 22, 2023
1 parent e49954f commit 14c858f
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From b459311246ddc4f20f231a8e27ed9a26689a6d44 Mon Sep 17 00:00:00 2001
From 741e7bd66c3ca4bc7b30388f91f9350b57d8ad53 Mon Sep 17 00:00:00 2001
From: Kai Lueke <[email protected]>
Date: Mon, 20 Nov 2023 15:47:24 +0100
Subject: [PATCH 1/2] disks: Refuse to modify disks/partitions in use
Subject: [PATCH 1/3] disks: Refuse to modify disks/partitions in use

When a partition or the whole disk is in use, sgdisk should not execute
the destructive operation.
Expand All @@ -12,7 +12,7 @@ to be destroyed.
1 file changed, 136 insertions(+)

diff --git a/internal/exec/stages/disks/partitions.go b/internal/exec/stages/disks/partitions.go
index 747f08dc..83ec02df 100644
index 747f08dc..f94cc5c5 100644
--- a/internal/exec/stages/disks/partitions.go
+++ b/internal/exec/stages/disks/partitions.go
@@ -19,8 +19,12 @@
Expand Down Expand Up @@ -91,7 +91,7 @@ index 747f08dc..83ec02df 100644
+ }
+ var partitions []string
+ for _, entry := range entries {
+ if strings.HasPrefix(entry.Name(), blockDevNode+"p") {
+ if strings.HasPrefix(entry.Name(), blockDevNode) {
+ partitions = append(partitions, "/dev/"+entry.Name())
+ }
+ }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From cfa96ca05825ee07ac2d944e2b199c9e337863bd Mon Sep 17 00:00:00 2001
From 561ced7e2d1b7385499ead7f99d658d82ebbdf77 Mon Sep 17 00:00:00 2001
From: Kai Lueke <[email protected]>
Date: Fri, 29 Sep 2023 18:06:09 +0200
Subject: [PATCH 2/2] sgdisk: Run partx after partition changes
Subject: [PATCH 2/3] sgdisk: Run partx after partition changes

The sgdisk tool does not update the kernel partition table with BLKPG in
contrast to other similar tools but only uses BLKRRPART which fails as
Expand Down Expand Up @@ -60,7 +60,7 @@ index 9e96166e..f295a572 100644
func UdevadmCmd() string { return udevadmCmd }
func UsermodCmd() string { return usermodCmd }
diff --git a/internal/exec/stages/disks/partitions.go b/internal/exec/stages/disks/partitions.go
index 83ec02df..97591c2f 100644
index f94cc5c5..1d61cd0e 100644
--- a/internal/exec/stages/disks/partitions.go
+++ b/internal/exec/stages/disks/partitions.go
@@ -24,12 +24,14 @@ import (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
From 8cbded573447b31f497aff099c46e47a3b3da40e Mon Sep 17 00:00:00 2001
From: Kai Lueke <[email protected]>
Date: Tue, 21 Nov 2023 17:39:23 +0100
Subject: [PATCH 3/3] printf

---
internal/exec/stages/disks/partitions.go | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/internal/exec/stages/disks/partitions.go b/internal/exec/stages/disks/partitions.go
index 1d61cd0e..9ecc32ef 100644
--- a/internal/exec/stages/disks/partitions.go
+++ b/internal/exec/stages/disks/partitions.go
@@ -335,6 +335,7 @@ func blockDevHeld(blockDev string) (bool, error) {
if err != nil {
return false, fmt.Errorf("failed to retrieve holders of %q: %v", blockDev, err)
}
+ fmt.Printf("blockDevHeld: dir %v, entries: %v\n", holdersDir, entries)
return len(entries) > 0, nil
}

@@ -356,6 +357,7 @@ func blockDevMounted(blockDev string) (bool, error) {
if err != nil {
return false, fmt.Errorf("failed to resolve %q: %v", mountSource, err)
}
+ fmt.Printf("mountcheck: %v vs %v\n", mountSourceResolved, blockDevResolved)
if mountSourceResolved == blockDevResolved {
return true, nil
}
@@ -382,6 +384,7 @@ func blockDevPartitions(blockDev string) ([]string, error) {
}
var partitions []string
for _, entry := range entries {
+ fmt.Printf("blockDevPartitions: name: %v node prefix: %v\n", entry.Name(), blockDevNode)
if strings.HasPrefix(entry.Name(), blockDevNode) {
partitions = append(partitions, "/dev/"+entry.Name())
}
@@ -406,13 +409,16 @@ func blockDevInUse(blockDev string) (bool, []string, error) {
if err != nil {
return false, nil, fmt.Errorf("failed to retrieve partitions of %q: %v", blockDev, err)
}
+ fmt.Printf("blockDevInUse: partitions: %v\n", partitions)
var activePartitions []string
for _, partition := range partitions {
held, err := blockDevHeld(partition)
+ fmt.Printf("blockDevInUse: partition %v held: %v\n", partition, held)
if err != nil {
return false, nil, fmt.Errorf("failed to check if %q is held: %v", partition, err)
}
mounted, err := blockDevMounted(partition)
+ fmt.Printf("blockDevInUse: partition %v mounted: %v\n", partition, mounted)
if err != nil {
return false, nil, fmt.Errorf("failed to check if %q is mounted: %v", partition, err)
}
@@ -433,6 +439,7 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
if inUse && len(activeParts) == 0 {
return fmt.Errorf("refusing to operate on directly active disk %q", devAlias)
}
+ fmt.Printf("PRINT: inUse: %v activeParts: %v\n", inUse, activeParts)
if cutil.IsTrue(dev.WipeTable) {
op := sgdisk.Begin(s.Logger, devAlias)
s.Logger.Info("wiping partition table requested on %q", devAlias)
@@ -459,6 +466,7 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
if err != nil {
return fmt.Errorf("failed to resolve %q: %v", devAlias, err)
}
+ fmt.Printf("PRINT: blockDevResolved: %v\n", blockDevResolved)

// get a list of parititions that have size and start 0 replaced with the real sizes
// that would be used if all specified partitions were to be created anew.
@@ -527,6 +535,7 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
if partInUse && modification {
return fmt.Errorf("refusing to modfiy active partition %d on %q", part.Number, devAlias)
}
+ fmt.Printf("PRINT: partInUse %v, modification %v\n", partInUse, modification)
}

if err := op.Commit(); err != nil {
@@ -538,10 +547,13 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
// kernel partition table with BLKPG but only uses BLKRRPART which fails
// as soon as one partition of the disk is mounted
cmd := exec.Command(distro.PartxCmd(), "-u", "-", blockDevResolved)
+ fmt.Printf("PRINT: cmd: %v\n", cmd)
if _, err := s.Logger.LogCmd(cmd, "triggering partition table reread on %q", devAlias); err != nil {
return fmt.Errorf("re-reading partitions failed: %v", err)
}
+ fmt.Printf("PRINT: partx ran\n")
}
+ fmt.Printf("PRINT: wait for udev\n")

// It's best to wait here for the /dev/ABC entries to be
// (re)created, not only for other parts of the initramfs but
--
2.42.0

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ PATCHES=(
"${FILESDIR}/0021-internal-exec-stages-mount-Mount-oem.patch"
"${FILESDIR}/0022-disks-Refuse-to-modify-disks-partitions-in-use.patch"
"${FILESDIR}/0023-sgdisk-Run-partx-after-partition-changes.patch"
"${FILESDIR}/0024-printf.patch"
)

src_compile() {
Expand Down

0 comments on commit 14c858f

Please sign in to comment.