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

Storage: Delete potentially left snapshot temporary volume #14920

Merged
merged 5 commits into from
Feb 4, 2025
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
5 changes: 2 additions & 3 deletions lxd/storage/connectors/connector_iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *connectorISCSI) Version() (string, error) {

fields := strings.Split(strings.TrimSpace(out), " ")
if strings.HasPrefix(out, "iscsiadm version ") && len(fields) > 2 {
version := fmt.Sprintf("%s (iscsiadm)", fields[2])
version := fields[2] + " (iscsiadm)"
return version, nil
}

Expand Down Expand Up @@ -97,8 +97,7 @@ func (c *connectorISCSI) QualifiedName() (string, error) {

// discoverTargets discovers the available iSCSI targets on a given address.
func (c *connectorISCSI) discoverTargets(ctx context.Context, targetAddr string) error {
// Discover the available iSCSI targets on a given address.
_, _, err := shared.RunCommandSplit(ctx, nil, nil, "iscsiadm", "--mode", "discovery", "--type", "sendtargets", "--portal", targetAddr)
_, err := shared.RunCommandContext(ctx, "iscsiadm", "--mode", "discovery", "--type", "sendtargets", "--portal", targetAddr)
if err != nil {
return fmt.Errorf("Failed to discover available iSCSI targets on %q: %w", targetAddr, err)
}
Expand Down
14 changes: 7 additions & 7 deletions lxd/storage/drivers/driver_pure_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ func (p *pureClient) restoreVolumeSnapshot(poolName string, volName string, snap
// copyVolumeSnapshot copies the volume snapshot into destination volume. Destination volume is overwritten
// if already exists.
func (p *pureClient) copyVolumeSnapshot(srcPoolName string, srcVolName string, srcSnapshotName string, dstPoolName string, dstVolName string) error {
return p.copyVolume(srcPoolName, fmt.Sprintf("%s.%s", srcVolName, srcSnapshotName), dstPoolName, dstVolName, true)
return p.copyVolume(srcPoolName, srcVolName+"."+srcSnapshotName, dstPoolName, dstVolName, true)
}

// getHosts retrieves an existing Pure Storage host.
Expand Down Expand Up @@ -1365,7 +1365,7 @@ func (d *pure) unmapVolume(vol Volume) error {
if connector.Type() == connectors.TypeISCSI {
// removeDevice removes device from the system if the device is removable.
removeDevice := func(devName string) error {
path := fmt.Sprintf("/sys/block/%s/device/delete", devName)
path := "/sys/block/" + devName + "/device/delete"
if shared.PathExists(path) {
// Delete device.
err := os.WriteFile(path, []byte("1"), 0400)
Expand All @@ -1381,7 +1381,7 @@ func (d *pure) unmapVolume(vol Volume) error {
if strings.HasPrefix(devName, "dm-") {
// Multipath device (/dev/dm-*) itself is not removable.
// Therefore, we remove its slaves instead.
slaves, err := filepath.Glob(fmt.Sprintf("/sys/block/%s/slaves/*", devName))
slaves, err := filepath.Glob("/sys/block/" + devName + "/slaves/*")
if err != nil {
return fmt.Errorf("Failed to unmap volume %q: Failed to list slaves for device %q: %w", vol.name, devName, err)
}
Expand Down Expand Up @@ -1488,7 +1488,7 @@ func (d *pure) getMappedDevPath(vol Volume, mapVolume bool) (string, revert.Hook
// - "00" - Padding
// - "8726b5033af243" - First 14 characters of serial number
// - "24a937" - OUI (Organizationally Unique Identifier)
// - "3d00014196" - Last 10 characters of serail number
// - "3d00014196" - Last 10 characters of serial number
diskSuffix = "00" + pureVol.Serial[0:14] + "24a937" + pureVol.Serial[14:]
default:
return "", nil, fmt.Errorf("Unsupported Pure Storage mode %q", connector.Type())
Expand Down Expand Up @@ -1532,18 +1532,18 @@ func (d *pure) getVolumeName(vol Volume) (string, error) {
// Search for the volume type prefix, and if found, prepend it to the volume name.
volumeTypePrefix, ok := pureVolTypePrefixes[vol.volType]
if ok {
volName = fmt.Sprintf("%s-%s", volumeTypePrefix, volName)
volName = volumeTypePrefix + "-" + volName
}

// Search for the content type suffix, and if found, append it to the volume name.
contentTypeSuffix, ok := pureContentTypeSuffixes[vol.contentType]
if ok {
volName = fmt.Sprintf("%s-%s", volName, contentTypeSuffix)
volName = volName + "-" + contentTypeSuffix
}

// If volume is snapshot, prepend snapshot prefix to its name.
if vol.IsSnapshot() {
volName = fmt.Sprintf("%s%s", pureSnapshotPrefix, volName)
volName = pureSnapshotPrefix + volName
}

return volName, nil
Expand Down
17 changes: 17 additions & 0 deletions lxd/storage/drivers/driver_pure_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,23 @@ func (d *pure) DeleteVolumeSnapshot(snapVol Volume, op *operations.Operation) er
return err
}

// Snapshots cannot be mounted directly, so when this is needed, the snapshot is copied
// into a temporary volume. In case LXD was abruptly stopped in the moment when
// temporary volume was created, it is possible that the volume was not removed.
tmpVol, err := d.client().getVolume(snapVol.pool, snapVolName)
if err != nil && !api.StatusErrorCheck(err, http.StatusNotFound) {
return fmt.Errorf("Failed retrieving temporary snapshot volume: %w", err)
}

if tmpVol != nil {
// Temporary volume found, delete it.
err = d.client().deleteVolume(snapVol.pool, snapVolName)
if err != nil {
return fmt.Errorf("Failed deleting temporary snapshot volume: %w", err)
}
}

// Delete snapshot.
err = d.client().deleteVolumeSnapshot(snapVol.pool, parentVolName, snapVolName)
if err != nil {
return err
Expand Down
Loading