Skip to content

Commit cea65b1

Browse files
authored
Implement method for changing Docker storage driver in OS 17.0+ (#238)
* Implement property for toggling Docker Containerd snapshotter in OS 17.0+ Add API for creating/removing the flag file that controls whether Containerd snapshotter is used as implemented in [1]. This is needed for higher level API that can be used for user opt-in per [2]. Once the property is toggled, OS needs to be rebooted for the change to take effect. [1] home-assistant/operating-system#4360 [2] home-assistant/operating-system#4253 * Implement as MigrateDockerStorageDriver instead of the property * Suppress gosec linter error
1 parent 3b26627 commit cea65b1

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

system/system.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import (
77

88
"github.com/godbus/dbus/v5"
99
"github.com/godbus/dbus/v5/introspect"
10-
"github.com/godbus/dbus/v5/prop"
1110

1211
logging "github.com/home-assistant/os-agent/utils/log"
1312
)
1413

1514
const (
16-
objectPath = "/io/hass/os/System"
17-
ifaceName = "io.hass.os.System"
18-
labelDataFileSystem = "hassos-data"
19-
labelOverlayFileSystem = "hassos-overlay"
20-
kernelCommandLine = "/mnt/boot/cmdline.txt"
21-
tmpKernelCommandLine = "/mnt/boot/.tmp.cmdline.txt"
22-
sshAuthKeyFileName = "/root/.ssh/authorized_keys"
15+
objectPath = "/io/hass/os/System"
16+
ifaceName = "io.hass.os.System"
17+
labelDataFileSystem = "hassos-data"
18+
labelOverlayFileSystem = "hassos-overlay"
19+
kernelCommandLine = "/mnt/boot/cmdline.txt"
20+
tmpKernelCommandLine = "/mnt/boot/.tmp.cmdline.txt"
21+
sshAuthKeyFileName = "/root/.ssh/authorized_keys"
22+
containerdSnapshotterFlag = "/mnt/data/.docker-use-containerd-snapshotter"
2323
)
2424

2525
type system struct {
@@ -83,6 +83,30 @@ func (d system) ClearSSHAuthKeys() *dbus.Error {
8383
return nil
8484
}
8585

86+
func (d system) MigrateDockerStorageDriver(backend string) *dbus.Error {
87+
switch backend {
88+
case "overlayfs":
89+
// Write the backend name to the flag file
90+
err := os.WriteFile(containerdSnapshotterFlag, []byte(backend), 0644) //nolint:gosec
91+
if err != nil {
92+
logging.Error.Printf("Failed to write containerd snapshotter flag: %s", err)
93+
return dbus.MakeFailedError(err)
94+
}
95+
logging.Info.Printf("Storage driver set to overlayfs containerd snapshotter")
96+
case "overlay2":
97+
// Graph driver -> remove the flag file to disable the snapshotter
98+
if err := os.Remove(containerdSnapshotterFlag); err != nil && !os.IsNotExist(err) {
99+
logging.Error.Printf("Failed to remove containerd snapshotter flag: %s", err)
100+
return dbus.MakeFailedError(err)
101+
}
102+
logging.Info.Printf("Storage driver set to overlay2 graph driver")
103+
default:
104+
return dbus.MakeFailedError(fmt.Errorf("unsupported driver: %s (only 'overlayfs' and 'overlay2' are supported)", backend))
105+
}
106+
107+
return nil
108+
}
109+
86110
func InitializeDBus(conn *dbus.Conn) {
87111
d := system{
88112
conn: conn,
@@ -97,7 +121,6 @@ func InitializeDBus(conn *dbus.Conn) {
97121
Name: objectPath,
98122
Interfaces: []introspect.Interface{
99123
introspect.IntrospectData,
100-
prop.IntrospectData,
101124
{
102125
Name: ifaceName,
103126
Methods: introspect.Methods(d),

0 commit comments

Comments
 (0)