Download tasks/DSK/DSK_task_10_btrfs_subvol_snapshot_diff.md from wanlilll/WeaveBench: direct link, hf CLI and curl.
- Browser
- Download file 19.4 kB
-
https://huggingface.co/datasets/wanlilll/WeaveBench/resolve/main/tasks/DSK/DSK_task_10_btrfs_subvol_snapshot_diff.md
- Command line
-
hf download hf://datasets/wanlilll/WeaveBench/tasks/DSK/DSK_task_10_btrfs_subvol_snapshot_diff.md
-
curl -L -o DSK_task_10_btrfs_subvol_snapshot_diff.md https://huggingface.co/datasets/wanlilll/WeaveBench/resolve/main/tasks/DSK/DSK_task_10_btrfs_subvol_snapshot_diff.md
id: DSK_task_10_btrfs_subvol_snapshot_diff
name: Btrfs 子卷 reflink 快照差异审计
category: DSK
timeout_seconds: 1500
Prompt
Background: an ops ticket reports that the Btrfs lab volume mounted at /mnt/btrfs_lab appears to consume about 64 MiB more after the latest snapshot, while block-level usage only grew by about 30 MiB. The suspicion is that someone used a reflink/COW clone, producing a gap between the inode-level "apparent" size and the extent-level real footprint. Please produce a snapshot diff audit report.
Environment (already prepared by warmup):
/mnt/btrfs_labis a 1 GiB Btrfs filesystem (mounted on a loop device)- Subvolume topology:
data_a/data_b/data_c/snapshots(the latter containssnap1andsnap2, both read-only) snap1captures an earlier state ofdata_a;snap2was taken later, with unknown topology changes- Passwordless sudo available;
btrfs-progsalready installed
Deliverables to produce under /tmp_workspace/results/:
Subvolume and snapshot inventory
subvolume_list.txt: list every subvolume on the volume (with path / id / parent); the five entriesdata_a,data_b,data_c,snap1,snap2must all be visible.subvolume_show_snap1.txt/subvolume_show_snap2.txt: metadata for snap1 / snap2 respectively, content must include theUUIDandGenerationfields.
Extent-level real accounting
fs_usage.txt: physical usage breakdown for the whole volume, must contain theDevice sizeandData,singlefields.fs_du_snap2.txt: extent-level usage forsnapshots/snap2. A line must contain the three column headersTotal/Exclusive/Set sharedsimultaneously, and a row forpayload_alpha_clone.binmust be visible (its Exclusive byte count is 0, Set shared is non-zero).
Precise change stream between snapshots
send_dump.txt: human-readable dump of the incremental send stream fromsnap1 → snap2(≥ 500 bytes). The format should include entries such asclone offset=... len=...,mkfile path=...,truncate path=... size=...,utimes path=....clonelines represent reflink reuse;write/update_extent/truncatelines represent genuinely new writes.send_stderr.log: stderr of the same process, for troubleshooting.
Visual evidence of
payload_alpha_clone.bin's attributes (any resolution, all ≥ 4 KB, rendered in a real working environment, no synthetic images)view_nautilus_snap1.png: browse the "Properties" detail panel of any file under/mnt/btrfs_lab/snapshots/snap1/. The text must show the wordPropertiesorSize, and must relate to the snap1 path or a payload name.view_nautilus_snap2.png: browse the Properties panel of/mnt/btrfs_lab/snapshots/snap2/payload_alpha_clone.bin, withPropertiesorSizevisible and the clone filename identifiable.view_terminal_du.png: image showing the extent-level usage listing. The text must simultaneously show the three column headersTotal/Exclusive/Set sharedand the literalalpha_clone.
Structured conclusions JSON —
results/changes.json, strict schema:{ "subvolumes": ["data_a","data_b","data_c","snapshots/snap1","snapshots/snap2"], "added": ["payload_alpha_clone.bin","logs/run6.log"], "modified": ["NOTES.txt","payload_beta.bin"], "removed": ["logs/run5.log"], "reflink_pairs": [["payload_alpha.bin","payload_alpha_clone.bin"]], "snap2_apparent_bytes": <int, inode-level total of snap2>, "snap2_exclusive_bytes": <int, bytes exclusively owned by snap2 at extent level>, "snap2_shared_bytes": <int, bytes of extents shared between snap2 and others>, "evidence": { "cli": ["subvolume_list.txt","fs_du_snap2.txt","send_dump.txt"], "gui": ["view_nautilus_snap1.png","view_nautilus_snap2.png","view_terminal_du.png"] } }Hard constraints:
snap2_apparent_bytes > snap2_exclusive_bytes > 0andsnap2_shared_bytes > 0(otherwise the reflink saving was not captured);reflink_pairsmust include(payload_alpha.bin, payload_alpha_clone.bin).Narrative report —
results/report.md(≥ 400 characters, Markdown):- Explain why
payload_alpha_clone.binappears to "occupy several MiB" from the inode/apparent perspective but adds almost no new physical footprint from the extent perspective; - Provide a lower-bound estimate of the real new-write bytes from
snap1 → snap2(the size of the incremental send stream can serve as a reference); - Cover at least 4 of the keywords:
reflink/extent/exclusive/shared/apparent/snapshot.
- Explain why
Hard constraints:
- The
snap1/snap2read-only snapshots must not be deleted or unmounted; they must remain readable at the original mount points. - No fabricating data or hard-coding answers into the JSON — all numbers must come from the actual lab volume.
Expected Behavior
成功的解答会在 /tmp_workspace/results/ 留下完整审计链路:
- 三份子卷清单文件,5 个子卷 / snapshot 全部可见,且 snap1 / snap2 的 UUID 与 Generation 都被记录;
- 两份 extent 真值文件,
fs_du_snap2.txt同时含Total/Exclusive/Set shared三列且能看到克隆文件行; - 一份
send_dump.txt,其中既出现clone(reflink 复用)又出现write/update_extent/truncate(真新写),二者字节数差距即"幻觉差"的根因; - 三张工作环境内真实采集的可视化证据,分别证明 snap1 文件的属性面板、snap2 中
payload_alpha_clone.bin的属性面板,以及 extent 级用量(三列表头与克隆行); - 一份
changes.json,added / modified / removed 与 lab 真值对齐,reflink 对命中(payload_alpha.bin, payload_alpha_clone.bin),且数值满足apparent > exclusive > 0与shared > 0的不变量; - 一份
report.md(≥ 400 字符),用人类语言串联上述证据,说明 inode-apparent 与 extent-real 的差异、reflink 共享 extent 为何在 apparent 视角"看不见",以及 snap1→snap2 的真实新写量下界。
Source
- Btrfs Wiki — Incremental Backup + SysadminGuide#Subvolumes (https://btrfs.readthedocs.io/en/latest/btrfs-send.html, https://btrfs.readthedocs.io/en/latest/Subvolumes.html)
- Reddit r/btrfs "snapshot size accounting confusion with cp --reflink"
- 灵感来源:DESIGNER_BRIEF DSK 行 "Btrfs subvolume CLI + Cinnamon File Manager + verify with btrfs filesystem usage"
Grading Criteria
-
- 5 个 subvolume 在
subvolume_list.txt中可见
- 5 个 subvolume 在
-
fs_du_snap2.txt含Total / Exclusive / Set shared三列表头
-
send_dump.txt含clone与write/update_extent行
-
changes.jsonschema 完整且 added/modified/removed 与真值对齐
-
changes.json.reflink_pairs命中(payload_alpha.bin, payload_alpha_clone.bin)
-
snap2_exclusive_bytes < snap2_apparent_bytes(reflink 节省被显式记录)
-
- 三张 GUI 截图存在且 OCR 命中关键词
-
report.md字符 ≥ 400 且解释了 reflink/extent 关系
-
- VLM 判分:文件管理器 Properties 对话框真实可见
Automated Checks
def grade(workspace_path=None, **kwargs) -> dict:
"""Btrfs reflink-aware snapshot diff grader.
Sub-scores:
- subvol_list / subvol_show / fs_usage / fs_du presence + content
- send_dump structure (must contain clone + write ops)
- changes.json schema + content alignment vs gt/expected.json
- reflink pair detection (must include payload_alpha_clone.bin)
- apparent > exclusive invariant (numeric)
- 3 GUI screenshots present + OCR keyword hits
- report.md length + keyword coverage
- VLM rubric on file-manager Properties screenshot
Hard gates: missing CLI artifacts cap at 0.4; missing GUI screenshots
cap at 0.4; VLM judge < 0.6 caps at 0.6.
"""
import json, re, os
from pathlib import Path
rd = Path("/tmp_workspace/results")
gt_dir = Path("/opt/dsk10_gt")
if not gt_dir.exists():
gt_dir = Path(workspace_path or "/tmp_workspace") / "gt"
if not gt_dir.exists():
gt_dir = Path("/tmp_workspace/gt")
s = {}
expected = {}
ej = gt_dir / "expected.json"
if ej.exists():
try: expected = json.loads(ej.read_text())
except Exception: expected = {}
def read(p):
try: return p.read_text(errors="ignore")
except Exception: return ""
# 1. subvolume_list.txt — 5 subvolumes
sl = read(rd / "subvolume_list.txt")
sv_hits = sum(1 for x in ("data_a","data_b","data_c","snap1","snap2") if x in sl)
s["subvol_list"] = sv_hits / 5.0
# 2. subvolume_show — Generation, UUID lines visible
show1 = read(rd / "subvolume_show_snap1.txt")
show2 = read(rd / "subvolume_show_snap2.txt")
s["subvol_show"] = (
(1.0 if ("UUID" in show1 and "Generation" in show1) else 0.0) +
(1.0 if ("UUID" in show2 and "Generation" in show2) else 0.0)
) / 2.0
# 3. fs_usage / fs_du with three-column header
fu = read(rd / "fs_usage.txt")
s["fs_usage"] = 1.0 if ("Device size" in fu and "Data,single" in fu) else (0.5 if fu else 0.0)
fd = read(rd / "fs_du_snap2.txt")
has_three_col = bool(re.search(r"Total\s+Exclusive\s+Set shared", fd))
has_clone_row = ("payload_alpha_clone.bin" in fd)
s["fs_du_header"] = 1.0 if has_three_col else 0.0
s["fs_du_clone_visible"] = 1.0 if has_clone_row else 0.0
# 4. send_dump structure
sd = read(rd / "send_dump.txt")
has_clone_op = len(re.findall(r"^clone\s.+len=\d+", sd, re.M)) >= 1
has_write_op = len(re.findall(r"^(write|update_extent)\s.+len=\d+", sd, re.M)) >= 2
has_mkfile_op = bool(re.search(r"^mkfile\s+.*payload_alpha_clone", sd))
clone_bytes = sum(int(m.group(1)) for m in re.finditer(r"^clone\s.+len=(\d+)", sd, re.M))
has_mkfile = bool(re.search(r"^(mkfile|link)\s", sd, re.M))
s["send_dump_clone"] = 1.0 if (has_clone_op and clone_bytes >= 20_000_000 and has_mkfile_op) else 0.0
s["send_dump_write"] = 1.0 if has_write_op else 0.0
s["send_dump_size"] = 1.0 if len(sd) >= 4000 else len(sd)/4000.0
# 5. changes.json schema + content alignment
cj_path = rd / "changes.json"
cj = {}
if cj_path.exists():
try: cj = json.loads(cj_path.read_text())
except Exception: cj = {}
required_keys = {"subvolumes","added","modified","removed",
"reflink_pairs","snap2_apparent_bytes",
"snap2_exclusive_bytes","snap2_shared_bytes","evidence"}
s["changes_schema"] = 1.0 if required_keys.issubset(cj.keys()) else \
(len(required_keys & set(cj.keys())) / len(required_keys))
def setify(xs):
return set(os.path.basename(str(x)).strip() for x in (xs or []) if x)
exp_changes = expected.get("changes_snap1_to_snap2", {})
add_score = mod_score = rm_score = 0.0
for key, score_key in [("added","added"),("modified","modified"),("removed","removed")]:
ag = setify(cj.get(key, []))
gt = setify(exp_changes.get(key, []))
if not gt: continue
inter = ag & gt
precision = len(inter) / max(len(ag), 1)
recall = len(inter) / len(gt)
f1 = 0.0 if (precision + recall) == 0 else 2*precision*recall/(precision+recall)
if key == "added": add_score = f1
if key == "modified": mod_score = f1
if key == "removed": rm_score = f1
s["changes_added"] = add_score
s["changes_modified"] = mod_score
s["changes_removed"] = rm_score
# 6. reflink_pairs hit
reflink_hit = 0.0
for pair in cj.get("reflink_pairs", []) or []:
try:
a, b = (os.path.basename(str(pair[0])), os.path.basename(str(pair[1])))
names = {a, b}
if "payload_alpha.bin" in names and "payload_alpha_clone.bin" in names:
reflink_hit = 1.0; break
except Exception: pass
s["reflink_pair_detected"] = reflink_hit
# 7. numeric invariant: exclusive < apparent (the whole point of the task)
try:
ap = int(cj.get("snap2_apparent_bytes", 0))
ex = int(cj.get("snap2_exclusive_bytes", 0))
sh = int(cj.get("snap2_shared_bytes", 0))
sh_min = int(expected.get("expected_shared_bytes_snap2_min", 30_000_000))
invariant = (ap > ex > 0) and (sh >= sh_min) and (ap - ex) >= 25_000_000 and (ap == ex + sh or abs(ap-(ex+sh)) <= ap*0.15)
magnitude_ok = (1.1e8 <= ap <= 2.5e8) and (ex <= 8e7) and (sh >= sh_min)
s["numeric_invariant"] = 1.0 if invariant else 0.0
s["numeric_magnitude"] = 1.0 if magnitude_ok else 0.5 if invariant else 0.0
except Exception:
s["numeric_invariant"] = 0.0
s["numeric_magnitude"] = 0.0
return _finalise_btrfs(s, rd, cj, expected)
def _finalise_btrfs(s, rd, cj, expected):
import re
from pathlib import Path
# 8. GUI screenshots present + OCR
gui_shots = [
"view_nautilus_snap1.png",
"view_nautilus_snap2.png",
"view_terminal_du.png",
]
present = sum(1 for n in gui_shots if (rd/n).exists())
s["gui_shots_present"] = present / len(gui_shots)
try:
import pytesseract
from PIL import Image
kws = {
"view_nautilus_snap1.png": [["Properties","属性"], ["snap1","payload_alpha","payload_beta"]],
"view_nautilus_snap2.png": [["Properties","属性"], ["payload_alpha_clone"]],
"view_terminal_du.png": [["Total"], ["Exclusive"], ["Set shared"], ["alpha_clone"]],
}
ocr_hits = 0
for n, groups in kws.items():
p = rd/n
if not p.exists(): continue
try: tx = pytesseract.image_to_string(Image.open(p)).lower()
except Exception: tx = ""
if all(any(k.lower() in tx for k in grp) for grp in groups): ocr_hits += 1
s["gui_shots_ocr"] = ocr_hits / len(gui_shots)
except ImportError:
s["gui_shots_ocr"] = 0.5
# 9. report.md length + keywords
rm = (rd/"report.md")
rt = rm.read_text(errors="ignore") if rm.exists() else ""
s["report_length"] = 1.0 if len(rt) >= 400 else len(rt)/400.0
kw_needed = ["reflink","extent","exclusive","shared","apparent","snapshot","payload_alpha_clone"]
kw_hits = sum(1 for k in kw_needed if k.lower() in rt.lower())
has_num = bool(re.search(r"\b\d{2,}\s*(MiB|MB|bytes|B)\b", rt))
s["report_keywords"] = (kw_hits/len(kw_needed)) * (1.0 if has_num else 0.5)
# 10. VLM rubric
try:
from _judge_helper import vlm_score_rubric
except Exception:
vlm_score_rubric = None
vlm_judge = None
imgs = [str(rd/n) for n in (
"view_nautilus_snap1.png","view_nautilus_snap2.png","view_terminal_du.png"
) if (rd/n).exists()]
if vlm_score_rubric and imgs:
rubric = {
"vlm_nautilus_window": "截图里能看到文件管理器窗口与文件列表",
"vlm_properties_dlg": "至少一张截图里出现 Properties / 属性 对话框且含 Size 字段",
"vlm_terminal_three_col": "终端截图里能看到 Total / Exclusive / Set shared 三列",
"vlm_evidence_authentic": "截图明显是真实桌面会话(有窗口装饰、光标、状态栏),不是拼接图",
}
try:
vlm = vlm_score_rubric(imgs[:3], rubric,
instruction="评估 Btrfs reflink 快照差异审计任务的 GUI 取证截图。")
for k in rubric: s[k] = vlm.get(k, 0.0)
vlm_judge = sum(s.get(k,0.0) for k in rubric) / len(rubric)
except Exception:
for k in rubric: s[k] = 0.0
vlm_judge = 0.0
# Aggregate
nums = [v for v in s.values() if isinstance(v,(int,float))]
base = sum(nums) / max(len(nums), 1)
has_cli_evidence = (rd/"send_dump.txt").exists() and (rd/"fs_du_snap2.txt").exists() \
and len((rd/"fs_du_snap2.txt").read_text(errors="ignore")) > 50
has_gui_screenshot = any((rd/n).exists() for n in
("view_nautilus_snap1.png","view_nautilus_snap2.png","view_terminal_du.png"))
if not has_cli_evidence: base = min(base, 0.4)
# GUI hard-cap removed: rely on per-shot VLM/OCR sub-scores instead.
if vlm_score_rubric is not None and vlm_judge is not None and vlm_judge < 0.6:
base = min(base, 0.6)
if s.get("vlm_properties_dlg",1.0) < 0.6 or s.get("vlm_terminal_three_col",1.0) < 0.6:
base = min(base, 0.55)
if s.get("gui_shots_ocr",0.0) < 0.34: base = min(base, 0.6)
try:
_sl_txt = (rd/"subvolume_list.txt").read_text(errors="ignore") if (rd/"subvolume_list.txt").exists() else ""
except Exception:
_sl_txt = ""
if not re.search(r"ID\s+\d+\s+gen\s+\d+", _sl_txt or ""): base = min(base, 0.6)
if s.get("changes_schema",0) < 1.0: base = min(base, 0.7)
if s.get("numeric_invariant",0) == 0.0: base = min(base, 0.65)
if s.get("reflink_pair_detected",0) == 0.0: base = min(base, 0.7)
s["overall_score"] = round(base, 3)
return s
Workspace Path
workspace/DSK/task_10_btrfs_subvol_snapshot_diff
Skills
Env
Warmup
mkdir -p /tmp_workspace/results /tmp_workspace/state /tmp_workspace/exec /opt/dsk10_gt
chmod 1777 /tmp_workspace/results /tmp_workspace/state /tmp_workspace/exec 2>/dev/null || true
chmod 700 /opt/dsk10_gt 2>/dev/null || true
cat > /opt/dsk10_gt/expected.json <<'JSON'
{
"subvolumes_expected": ["data_a", "data_b", "data_c", "snapshots/snap1", "snapshots/snap2"],
"snap1_files": ["NOTES.txt","payload_alpha.bin","payload_beta.bin","logs/run1.log","logs/run2.log","logs/run3.log","logs/run4.log","logs/run5.log"],
"snap2_files": ["NOTES.txt","payload_alpha.bin","payload_beta.bin","payload_alpha_clone.bin","logs/run1.log","logs/run2.log","logs/run3.log","logs/run4.log","logs/run6.log"],
"changes_snap1_to_snap2": {
"added": ["payload_alpha_clone.bin", "logs/run6.log"],
"modified": ["NOTES.txt", "payload_beta.bin"],
"removed": ["logs/run5.log"]
},
"reflink_pairs": [["payload_alpha.bin", "payload_alpha_clone.bin"]],
"expected_apparent_bytes_snap2_min": 100000000,
"expected_exclusive_bytes_snap2_max": 80000000,
"expected_shared_bytes_snap2_min": 30000000,
"send_stream_min_bytes": 30000000
}
JSON
chmod 600 /opt/dsk10_gt/expected.json 2>/dev/null || true
chown -R root:root /opt/dsk10_gt 2>/dev/null || true
export DEBIAN_FRONTEND=noninteractive
which btrfs || (apt-get update -o Acquire::Retries=10 -qq && DEBIAN_FRONTEND=noninteractive apt-get install -o Acquire::Retries=10 -y -qq btrfs-progs poppler-utils tesseract-ocr python3-pip util-linux) || true
pip install -q --break-system-packages pytesseract Pillow 2>/dev/null || pip install -q pytesseract Pillow 2>/dev/null || true
[ -f /tmp_workspace/setup/btrfs_setup.sh ] && cp -f /tmp_workspace/setup/btrfs_setup.sh /tmp_workspace/exec/btrfs_setup.sh || true
chmod +x /tmp_workspace/exec/btrfs_setup.sh 2>/dev/null || true
modprobe btrfs 2>/dev/null || true
bash /tmp_workspace/exec/btrfs_setup.sh >/tmp_workspace/state/btrfs_setup.log 2>&1 || true
mount | grep btrfs_lab || echo WARN_btrfs_not_mounted
btrfs subvolume list /mnt/btrfs_lab 2>/dev/null | head -20 || true