Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Before writing to partition check for sufficient space on partition #3276

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkg/pillar/cmd/baseosmgr/handlebaseos.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,33 @@ func doBaseOsActivate(ctx *baseOsMgrContext, uuidStr string,

log.Functionf("doBaseOsActivate: %s activating", uuidStr)

// Before writing to partition lets make sure we have enough space on the partition
// 1. Get the size of the image using contenttree status
// 2. Get the size of the partition using zboot
// 3. If partition size is < image size, error out

cts := lookupContentTreeStatus(ctx, status.ContentTreeUUID)

if cts == nil {
errString := fmt.Sprintf("doBaseOsActivate: ContentTreeStatus not found for %s", status.ContentTreeUUID)
log.Error(errString)
status.SetErrorNow(errString)
changed = true
return changed
}

if cts.State == types.LOADED {
partSize := zboot.GetPartitionSizeInBytes(status.PartitionLabel)
imageSize := cts.MaxDownloadSize
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have an actual size which could be smaller than MaxDownloadSize?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaxDownloadSize seems to be the size of image sent from the controller in the content tree config. zedagent is parsing that value from the config. To me that seems to be the actual size of the image. Let me know if that is not correct.

if partSize < imageSize {
errString := fmt.Sprintf("doBaseOsActivate: Image size %v bytes greater than partition size %v bytes", imageSize, partSize)
log.Error(errString)
status.SetErrorNow(errString)
changed = true
return changed
}
}

// install the image at proper partition; dd etc
changed, proceed, err = installDownloadedObjects(ctx, uuidStr, status.PartitionLabel,
status.ContentTreeUUID)
Expand Down
15 changes: 12 additions & 3 deletions pkg/pillar/zboot/zboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ package zboot

import (
"context"
"encoding/binary"
"errors"
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -256,11 +256,20 @@ func GetPartitionSizeInBytes(partName string) uint64 {
validatePartitionName(partName)
_, ok := partDev[partName]
if ok {
partsize, err := execWithRetry(nil, "zboot", "partdevsize", partName)
ret, err := execWithRetry(nil, "zboot", "partdevsize", partName)
if err != nil {
logrus.Fatalf("zboot partdevsize %s: err %v\n", partName, err)
eriknordmark marked this conversation as resolved.
Show resolved Hide resolved
}
return binary.BigEndian.Uint64(partsize)
partsize := string(ret)
partsize = strings.TrimSpace(partsize)
logrus.Infof("partsize in bytes %s", partsize)
value, err := strconv.ParseUint(partsize, 10, 64)
if err != nil {
logrus.Errorf("Strconv failed for partsize err %v\n", err)
eriknordmark marked this conversation as resolved.
Show resolved Hide resolved
return 0
}

return value
}

// Invalid partition
Expand Down