Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.zstack.header.storage.addon;

public abstract class StorageResource {
protected String installPath;
protected Long size;
protected Long actualSize;
protected String parentUri;

public String getInstallPath() {
return installPath;
}

public void setInstallPath(String installPath) {
this.installPath = installPath;
}

public Long getSize() {
return size;
}

public void setSize(long size) {
this.size = size;
}

public Long getResourceActualSize() {
return actualSize;
}

public void setActualSize(Long actualSize) {
this.actualSize = actualSize;
}

public void setActualSize(long actualSize) {
this.actualSize = actualSize;
}

public String getParentUri() {
return parentUri;
}

public void setParentUri(String parentUri) {
this.parentUri = parentUri;
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public interface PrimaryStorageControllerSvc {
void flattenVolume(String installPath, ReturnValueCompletion<VolumeStats>comp);

// support uri or path
void stats(String installPath, ReturnValueCompletion<VolumeStats> comp);
void stats(String installPath, ReturnValueCompletion<StorageResource> comp);

void batchStats(Collection<String> installPath, ReturnValueCompletion<List<VolumeStats>> comp);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
package org.zstack.header.storage.snapshot;

public class VolumeSnapshotStats {
private String installPath;
private long actualSize;

public String getInstallPath() {
return installPath;
}

public void setInstallPath(String installPath) {
this.installPath = installPath;
}
import org.zstack.header.storage.addon.StorageResource;

public class VolumeSnapshotStats extends StorageResource {
public long getActualSize() {
return actualSize;
}

public void setActualSize(long actualSize) {
this.actualSize = actualSize;
return actualSize == null ? 0L : actualSize;
}
}
39 changes: 3 additions & 36 deletions header/src/main/java/org/zstack/header/volume/VolumeStats.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package org.zstack.header.volume;

public class VolumeStats {
protected String installPath;
import org.zstack.header.storage.addon.StorageResource;

public class VolumeStats extends StorageResource {
protected String format;
protected Long actualSize;
protected Long size;
/**
* The parent uri of the volume, vendor://pool/path@snapshot or snapshot://uuid
*/
protected String parentUri;

// TODO(shenjin): remove it
@Deprecated
Expand All @@ -29,30 +24,10 @@ public VolumeStats(String installPath, Long actualSize, Long size) {
public VolumeStats() {
}

public String getInstallPath() {
return installPath;
}

public void setInstallPath(String installPath) {
this.installPath = installPath;
}

public Long getActualSize() {
return actualSize;
}

public void setActualSize(Long actualSize) {
this.actualSize = actualSize;
}

public Long getSize() {
return size;
}

public void setSize(long size) {
this.size = size;
}

public void setFormat(String format) {
this.format = format;
}
Expand All @@ -61,14 +36,6 @@ public String getFormat() {
return format;
}

public void setParentUri(String parentUri) {
this.parentUri = parentUri;
}

public String getParentUri() {
return parentUri;
}

@Deprecated
public String getRunStatus() {
return runStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1143,18 +1143,32 @@ public void fail(ErrorCode errorCode) {
@Override
public void flattenVolume(String installPath, ReturnValueCompletion<VolumeStats> comp) {
// TODO flatten snapshot
stats(installPath, comp);
comp.success(getVolumeStats(installPath));
}

@Override
public void stats(String installPath, ReturnValueCompletion<VolumeStats> comp) {
public void stats(String installPath, ReturnValueCompletion<StorageResource> comp) {
if (installPath.contains("@")) {
VolumeSnapshotModule snap = apiHelper.getVolumeSnapshot(getSnapIdFromPath(installPath));
VolumeSnapshotStats stats = new VolumeSnapshotStats();
stats.setInstallPath(installPath);
stats.setSize(snap.getSnapSize());
stats.setActualSize(snap.getDataSize());
comp.success(stats);
return;
}

comp.success(getVolumeStats(installPath));
}

private VolumeStats getVolumeStats(String installPath) {
VolumeModule vol = apiHelper.getVolume(getVolIdFromPath(installPath));
VolumeStats stats = new VolumeStats();
stats.setInstallPath(installPath);
stats.setSize(vol.getVolumeSize());
stats.setActualSize(vol.getDataSize());
stats.setFormat(VolumeConstant.VOLUME_FORMAT_RAW);
comp.success(stats);
return stats;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.zstack.core.retry.RetryCondition;
import org.zstack.header.core.Completion;
import org.zstack.header.errorcode.OperationFailureException;
import org.zstack.header.errorcode.SysErrors;
import org.zstack.header.volume.VolumeConfigs;
import org.zstack.header.volume.VolumeVO;
import org.zstack.header.volume.VolumeVO_;
Expand Down Expand Up @@ -36,6 +37,7 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static org.zstack.core.Platform.err;
import static org.zstack.core.Platform.operr;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;

Expand Down Expand Up @@ -102,6 +104,11 @@ public <T extends XInfiniResponse> void call(XInfiniRequest req, Completion comp
}

public void errorOut(XInfiniResponse rsp) {
if (rsp.resourceIsDeleted()) {
throw new OperationFailureException(err(ORG_ZSTACK_XINFINI_10002, SysErrors.RESOURCE_NOT_FOUND,
"xinfini request failed, message: %s.", rsp.getMessage()));
}

if (!rsp.isSuccess()) {
throw new OperationFailureException(operr(ORG_ZSTACK_XINFINI_10002, "xinfini request failed, message: %s.", rsp.getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,15 +851,31 @@ public void flattenVolume(String installPath, ReturnValueCompletion<VolumeStats>
}

@Override
public void stats(String installPath, ReturnValueCompletion<VolumeStats> comp) {
public void stats(String installPath, ReturnValueCompletion<StorageResource> comp) {
if (installPath.contains("@")) {
VolumeSnapshotModule snapshot = apiHelper.getVolumeSnapshot(getSnapIdFromPath(installPath));
VolumeSnapshotStats stats = new VolumeSnapshotStats();
long size = SizeUnit.MEGABYTE.toByte(snapshot.getSpec().getSizeMb());
stats.setInstallPath(installPath);
stats.setSize(size);
stats.setActualSize(size);
stats.setParentUri(getParentUri(apiHelper.getVolume(snapshot.getSpec().getBsVolumeId())));
comp.success(stats);
return;
}

comp.success(getVolumeStats(installPath));
}
Comment on lines +854 to +868

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n 'class VolumeSnapshotModule|class VolumeSnapshotSpec' plugin/xinfini/src/main/java/org/zstack/xinfini
rg -n 'getDataSize|getAllocatedSize|DataSize' plugin/xinfini/src/main/java/org/zstack/xinfini

Repository: MatheMatrix/zstack

Length of output: 1490


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant methods and surrounding context
sed -n '840,900p' plugin/xinfini/src/main/java/org/zstack/xinfini/XInfiniStorageController.java

echo '--- getParentUri / buildXInfiniPath / getParentChain ---'
rg -n 'getParentUri\\(|buildXInfiniPath\\(|getParentChain\\(' plugin/xinfini/src/main/java/org/zstack/xinfini -A 12 -B 6

echo '--- VolumeSnapshotModule / VolumeSnapshotSpec ---'
sed -n '1,180p' plugin/xinfini/src/main/java/org/zstack/xinfini/sdk/volume/VolumeSnapshotModule.java

Repository: MatheMatrix/zstack

Length of output: 3134


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n 'buildXInfiniSnapshotPath|getParentChain|parentUri' plugin/xinfini/src/main/java/org/zstack/xinfini -A 6 -B 6

echo '--- VolumeSnapshotStats definition ---'
sed -n '1,220p' plugin/xinfini/src/main/java/org/zstack/xinfini/sdk/volume/VolumeSnapshotStats.java

Repository: MatheMatrix/zstack

Length of output: 5606


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find every consumer of parentUri and the stats classes involved.
rg -n 'getParentUri\\(|setParentUri\\(|parentUri' plugin/xinfini/src/main/java -A 4 -B 4

echo '--- stats interfaces / models ---'
rg -n 'class .*Stats|interface .*Stats|extends .*Stats|implements .*Stats' plugin/xinfini/src/main/java/org/zstack/xinfini -A 3 -B 3

Repository: MatheMatrix/zstack

Length of output: 279


快照统计的 parentUri 需要直接指向 backing volume
stats() 这里把 snapshot.getSpec().getBsVolumeId() 对应的 volume 再传给 getParentUri(),拿到的是该 volume 的父快照路径,结果会跳过当前快照的直接父节点。这里应改为返回 backing volume 自身的路径。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@plugin/xinfini/src/main/java/org/zstack/xinfini/XInfiniStorageController.java`
around lines 854 - 868, Update the snapshot branch of
XInfiniStorageController.stats so parentUri points directly to the backing
volume identified by snapshot.getSpec().getBsVolumeId(), rather than passing
that volume through getParentUri. Preserve the existing size and installPath
handling.


private VolumeStats getVolumeStats(String installPath) {
VolumeModule vol = apiHelper.getVolume(getVolIdFromPath(installPath));
VolumeStats stats = new VolumeStats();
stats.setInstallPath(installPath);
stats.setSize(SizeUnit.MEGABYTE.toByte(vol.getSpec().getSizeMb()));
stats.setActualSize(vol.getStatus().getAllocatedSizeByte());
stats.setFormat(VolumeConstant.VOLUME_FORMAT_RAW);
stats.setParentUri(getParentUri(vol));
comp.success(stats);
return stats;
}

private String getParentUri(VolumeModule vol) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,19 +1315,21 @@ public void fail(ErrorCode errorCode) {
}

@Override
public void stats(String installPath, ReturnValueCompletion<VolumeStats> comp) {
public void stats(String installPath, ReturnValueCompletion<StorageResource> comp) {
QueryVolumeCmd cmd = new QueryVolumeCmd();
cmd.setPath(installPath);

httpCall(QUERY_VOLUME_PATH, cmd, QueryVolumeRsp.class, new ReturnValueCompletion<QueryVolumeRsp>(comp) {
@Override
public void success(QueryVolumeRsp returnValue) {
VolumeStats stats = new VolumeStats();
StorageResource stats = installPath.contains("@") ? new VolumeSnapshotStats() : new VolumeStats();
stats.setInstallPath(installPath);
stats.setSize(returnValue.getSize());
stats.setActualSize(returnValue.getActualSize());
stats.setFormat(VolumeConstant.VOLUME_FORMAT_RAW);
stats.setParentUri(ZbsHelper.normalizeToZbsPath(returnValue.getParentUri()));
if (stats instanceof VolumeStats) {
((VolumeStats) stats).setFormat(VolumeConstant.VOLUME_FORMAT_RAW);
}
comp.success(stats);
}

Expand Down
Loading