Skip to content

Commit

Permalink
Expose virtual size of backing images
Browse files Browse the repository at this point in the history
This commit adds virtualSize to the BackingImageStatus and
BackingImageFileInfo structs, and thus to the BackingImage and
BackingImageManager CRDs.  We can see how this works in practice by
creating a new backing image downloaded from a URL, then periodically
running `kubectl -n longhorn-system get lhbi`.  I'm using
https://download.opensuse.org/distribution/leap/15.5/appliances/openSUSE-Leap-15.5-Minimal-VM.x86_64-Cloud.qcow2
in the example below.

Initially, when the download is just started, before the file size is known:

```
> kubectl -n longhorn-system get lhbi/default-image-7mplj
NAME                  UUID       SOURCETYPE   SIZE        VIRTUALSIZE   AGE
default-image-7mplj   6d5a98b0   download     0           0             9s
```

A little later, while the download is running:

```
> kubectl -n longhorn-system get lhbi/default-image-7mplj
NAME                  UUID       SOURCETYPE   SIZE        VIRTUALSIZE   AGE
default-image-7mplj   6d5a98b0   download     255701504   0             3m33s
```

Finally, once the download is complete:

```
> kubectl -n longhorn-system get lhbi/default-image-7mplj
NAME                  UUID       SOURCETYPE   SIZE        VIRTUALSIZE   AGE
default-image-7mplj   6d5a98b0   download     255701504   821035008     4m26s
```

Compare size and virtualSize above with the image downloaded manually:

```
> wget https://download.opensuse.org/distribution/leap/15.5/appliances/openSUSE-Leap-15.5-Minimal-VM.x86_64-Cloud.qcow2
[...]

> ls -l openSUSE-Leap-15.5-Minimal-VM.x86_64-Cloud.qcow2
-rw-r--r-- 1 tserong users 255701504 Dec 19 23:26 openSUSE-Leap-15.5-Minimal-VM.x86_64-Cloud.qcow2

> qemu-img info openSUSE-Leap-15.5-Minimal-VM.x86_64-Cloud.qcow2 | grep virtual
virtual size: 783 MiB (821035008 bytes)
```

Related issue: longhorn/longhorn#7923

Signed-off-by: Tim Serong <tserong@suse.com>
(cherry picked from commit d438e9b)
  • Loading branch information
tserong authored and innobead committed Apr 10, 2024
1 parent 687941c commit d5a05cc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions controller/backing_image_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,16 @@ func (bic *BackingImageController) syncBackingImageFileInfo(bi *longhorn.Backing
return fmt.Errorf("found mismatching size %v reported by backing image manager %v in disk %v, the size recorded in status is %v", info.Size, bim.Name, bim.Spec.DiskUUID, bi.Status.Size)
}
}
if info.VirtualSize > 0 {
if bi.Status.VirtualSize == 0 {
bi.Status.VirtualSize = info.VirtualSize
bic.eventRecorder.Eventf(bi, corev1.EventTypeNormal, constant.EventReasonUpdate, "Set virtualSize to %v", bi.Status.VirtualSize)
}
if bi.Status.VirtualSize != info.VirtualSize {
return fmt.Errorf("found mismatching virtualSize %v reported by backing image manager %v in disk %v, the virtualSize recorded in status is %v",
info.VirtualSize, bim.Name, bim.Spec.DiskUUID, bi.Status.VirtualSize)
}
}
}

for diskUUID := range bi.Status.DiskFileStatusMap {
Expand Down
7 changes: 4 additions & 3 deletions engineapi/backing_image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ func (c *BackingImageManagerClient) parseBackingImageFileInfo(bi *bimapi.Backing
return nil
}
return &longhorn.BackingImageFileInfo{
Name: bi.Name,
UUID: bi.UUID,
Size: bi.Size,
Name: bi.Name,
UUID: bi.UUID,
Size: bi.Size,
VirtualSize: bi.VirtualSize,

State: longhorn.BackingImageState(bi.Status.State),
CurrentChecksum: bi.Status.CurrentChecksum,
Expand Down
11 changes: 11 additions & 0 deletions k8s/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ spec:
type: string
uuid:
type: string
virtualSize:
format: int64
type: integer
type: object
nullable: true
type: object
Expand Down Expand Up @@ -412,6 +415,10 @@ spec:
jsonPath: .status.size
name: Size
type: string
- description: The virtual size of the image (may be larger than file size)
jsonPath: .status.virtualSize
name: VirtualSize
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
Expand Down Expand Up @@ -479,6 +486,10 @@ spec:
type: integer
uuid:
type: string
virtualSize:
description: Virtual size of image, which may be larger than physical size. Will be zero until known (e.g. while a backing image is uploading)
format: int64
type: integer
type: object
type: object
served: true
Expand Down
4 changes: 4 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/backingimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type BackingImageStatus struct {
UUID string `json:"uuid"`
// +optional
Size int64 `json:"size"`
// 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"`
// +optional
Checksum string `json:"checksum"`
// +optional
Expand All @@ -74,6 +77,7 @@ type BackingImageStatus struct {
// +kubebuilder:printcolumn:name="UUID",type=string,JSONPath=`.status.uuid`,description="The system generated UUID"
// +kubebuilder:printcolumn:name="SourceType",type=string,JSONPath=`.spec.sourceType`,description="The source of the backing image file data"
// +kubebuilder:printcolumn:name="Size",type=string,JSONPath=`.status.size`,description="The backing image file size in each disk"
// +kubebuilder:printcolumn:name="VirtualSize",type=string,JSONPath=`.status.virtualSize`,description="The virtual size of the image (may be larger than file size)"
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

// BackingImage is where Longhorn stores backing image object.
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 @@ -20,6 +20,8 @@ type BackingImageFileInfo struct {
// +optional
Size int64 `json:"size"`
// +optional
VirtualSize int64 `json:"virtualSize"`
// +optional
State BackingImageState `json:"state"`
// +optional
CurrentChecksum string `json:"currentChecksum"`
Expand Down

0 comments on commit d5a05cc

Please sign in to comment.