Skip to content

Commit

Permalink
feat: add real size to backing image
Browse files Browse the repository at this point in the history
ref: longhorn/longhonr 8757

Signed-off-by: Jack Lin <jack.lin@suse.com>
  • Loading branch information
ChanYiLin committed Sep 24, 2024
1 parent 3ac6b93 commit 1d932c4
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 5 deletions.
15 changes: 15 additions & 0 deletions controller/backing_image_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,21 @@ func (bic *BackingImageController) syncBackingImageFileInfo(bi *longhorn.Backing
}
}
}
if info.RealSize > 0 {
if bi.Status.RealSize == 0 {
bi.Status.RealSize = info.RealSize
bic.eventRecorder.Eventf(bi, corev1.EventTypeNormal, constant.EventReasonUpdate, "Set realSize to %v", bi.Status.RealSize)
}
if bi.Status.RealSize != info.RealSize {
if bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].State != longhorn.BackingImageStateFailed {
msg := fmt.Sprintf("found mismatching realSize %v reported by backing image manager %v in disk %v, the realSoze recorded in status is %v",
info.RealSize, bim.Name, bim.Spec.DiskUUID, bi.Status.RealSize)
log.Error(msg)
bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].State = longhorn.BackingImageStateFailed
bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].Message = msg
}
}
}
}

for diskUUID := range bi.Status.DiskFileStatusMap {
Expand Down
14 changes: 14 additions & 0 deletions controller/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ func (nc *NodeController) updateDiskStatusSchedulableCondition(node *longhorn.No
if err != nil {
return err
}
backingImages, err := nc.ds.ListBackingImagesRO()
if err != nil {
return err
}

for diskName, disk := range node.Spec.Disks {
diskStatus := diskStatusMap[diskName]
Expand Down Expand Up @@ -843,6 +847,7 @@ func (nc *NodeController) updateDiskStatusSchedulableCondition(node *longhorn.No
return err
}
scheduledReplica := map[string]int64{}
scheduledBackingImage := map[string]int64{}
storageScheduled := int64(0)
for _, replica := range replicas {
if replica.Spec.NodeID != node.Name || replica.Spec.DiskPath != disk.Path {
Expand All @@ -857,8 +862,17 @@ func (nc *NodeController) updateDiskStatusSchedulableCondition(node *longhorn.No
storageScheduled += replica.Spec.VolumeSize
scheduledReplica[replica.Name] = replica.Spec.VolumeSize
}

for _, backingImage := range backingImages {
if _, exists := backingImage.Spec.DiskFileSpecMap[diskStatus.DiskUUID]; exists {
storageScheduled += backingImage.Status.RealSize
scheduledBackingImage[backingImage.Name] = backingImage.Status.RealSize
}
}

diskStatus.StorageScheduled = storageScheduled
diskStatus.ScheduledReplica = scheduledReplica
diskStatus.ScheduledBackingImage = scheduledBackingImage
// check disk pressure
info, err := nc.scheduler.GetDiskSchedulingInfo(disk, diskStatus)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions engineapi/backing_image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (c *BackingImageManagerClient) parseBackingImageFileInfo(bi *bimapi.Backing
UUID: bi.UUID,
Size: bi.Size,
VirtualSize: bi.VirtualSize,
RealSize: bi.RealSize,

State: longhorn.BackingImageState(bi.Status.State),
CurrentChecksum: bi.Status.CurrentChecksum,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ require (
github.com/gorilla/websocket v1.5.3
github.com/jinzhu/copier v0.4.0
github.com/kubernetes-csi/csi-lib-utils v0.19.0
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922.0.20240923074219-9aff32760277
github.com/longhorn/backupstore v0.0.0-20240922062439-e33cb1230db9
github.com/longhorn/go-common-libs v0.0.0-20240921050101-797b589b669d
github.com/longhorn/go-iscsi-helper v0.0.0-20240922062410-c17a624e50c1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922 h1:Ikx3UIgHD90DHr1CBfu9IUTdyt+NzM313IHau5DMzJQ=
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922/go.mod h1:raIdWG9r1P0YlnVRCqsCpavnEHd3TsqREQE2skKNQEA=
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922.0.20240923074219-9aff32760277 h1:b0IhPPH+F2ZOC701kzLDExSAAKN9FLVTHikhGaKYJWo=
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922.0.20240923074219-9aff32760277/go.mod h1:rLnxTIs4uEY0FUkHalr//1IKePxlqKXBhv+NRQ968yg=
github.com/longhorn/backupstore v0.0.0-20240922062439-e33cb1230db9 h1:ua4PCfArX2TyPVnldF+m7I9c2eGi+TcP8pcPPx2wp0w=
github.com/longhorn/backupstore v0.0.0-20240922062439-e33cb1230db9/go.mod h1:UTONYTgRryrw0RgDZbxwU+r1s4PeKQ+v0Z8Pb6jUWn4=
github.com/longhorn/go-common-libs v0.0.0-20240921050101-797b589b669d h1:MXJlzyXLptspJEc1UC7ee2eBIYksTl0RT2bXUAXU+8Q=
Expand Down
14 changes: 14 additions & 0 deletions k8s/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ spec:
type: string
progress:
type: integer
realSize:
format: int64
type: integer
senderManagerAddress:
type: string
sendingReference:
Expand Down Expand Up @@ -560,6 +563,11 @@ spec:
type: object
ownerID:
type: string
realSize:
description: Real size of image, which may be smaller than the size
when the file is a sparse file. Will be zero until known (e.g. while a backing image is uploading)
format: int64
type: integer
size:
format: int64
type: integer
Expand Down Expand Up @@ -2507,6 +2515,12 @@ spec:
type: string
instanceManagerName:
type: string
scheduledBackingImage:
additionalProperties:
format: int64
type: integer
nullable: true
type: object
scheduledReplica:
additionalProperties:
format: int64
Expand Down
3 changes: 3 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/backingimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ type BackingImageStatus struct {
// Virtual size of image, which may be larger than physical size. Will be zero until known (e.g. while a backing image is uploading)
// +optional
VirtualSize int64 `json:"virtualSize"`
// Real size of image, which may be smaller than the size when the file is a sparse file. Will be zero until known (e.g. while a backing image is uploading)
// +optional
RealSize int64 `json:"realSize"`
// +optional
Checksum string `json:"checksum"`
// +optional
Expand Down
2 changes: 2 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/backingimagemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type BackingImageFileInfo struct {
// +optional
VirtualSize int64 `json:"virtualSize"`
// +optional
RealSize int64 `json:"realSize"`
// +optional
State BackingImageState `json:"state"`
// +optional
CurrentChecksum string `json:"currentChecksum"`
Expand Down
3 changes: 3 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ type DiskStatus struct {
// +nullable
ScheduledReplica map[string]int64 `json:"scheduledReplica"`
// +optional
// +nullable
ScheduledBackingImage map[string]int64 `json:"scheduledBackingImage"`
// +optional
DiskUUID string `json:"diskUUID"`
// +optional
DiskName string `json:"diskName"`
Expand Down
7 changes: 7 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/longhorn/backing-image-manager/api/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions vendor/github.com/longhorn/backing-image-manager/pkg/util/util.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ github.com/kylelemons/godebug/diff
# github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
## explicit
github.com/liggitt/tabwriter
# github.com/longhorn/backing-image-manager v1.8.0-dev-20240922
# github.com/longhorn/backing-image-manager v1.8.0-dev-20240922.0.20240923074219-9aff32760277
## explicit; go 1.22.2
github.com/longhorn/backing-image-manager/api
github.com/longhorn/backing-image-manager/pkg/client
Expand Down

0 comments on commit 1d932c4

Please sign in to comment.