VM Manager: "Remove VM & Disks" destroys the whole share dataset (e.g. cache/domains) when the VM folder is a plain directory on ZFS

オープン
#2,792 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@SimonFair がすでに取り組んでいます。

2026年10月21日 から。

  • #2793 @SimonFair による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
php
領域
backend

調査の方向性

Read my_rmdir() in emhttp/plugins/dynamix/include/Helpers.php around lines 466–486, then trace its caller domain_delete() in emhttp/plugins/dynamix.vm.manager/include/libvirt.php around lines 1766–1786. Compare the ZFS handling with the my_mkdir() fix in #1968. Done means deleting a VM in a plain directory preserves the containing share dataset, while deleting an empty dataset mountpoint still removes that dataset; an open linked pull request (#2793) already addresses this issue.

索引モデルが issue の本文から書いたものです。

説明

Summary

VMs → Remove VM & Disks destroys the whole share dataset (e.g. cache/domains) when the VM's folder on a ZFS pool is a plain directory rather than its own dataset. Every other file in that share's dataset is destroyed with it, including the vdisks of other VMs that are stopped.

my_rmdir() runs zfs list -H -o name <dir>, which for a plain directory returns the dataset that contains it (the share), and then runs zfs destroy on that name.

Where

case "zfs":
  $zfsdataset = trim(shell_exec("zfs list -H -o name  ".escapeshellarg($dirname))) ;
  $cmdstr = "zfs destroy \"$zfsdataset\"  2>&1 ";

The same assumption was fixed in my_mkdir() in #1968 ("Fix for dir not a dataset"), which now falls back to mkdir when the parent is not a dataset. my_rmdir() has no such check.

What happened (Unraid 7.1.1)

  • The pool cache is a ZFS mirror, and the share domains (primary storage cache, cache only) is the dataset cache/domains.
  • The VM Ubuntu-20.04-research was created in 2024. Its folder /mnt/cache/domains/Ubuntu-20.04-research was a plain directory, not a dataset, and held one vdisk. It was the only VM.
  • I used Remove VM & Disks (the same domain-delete request with the VM's UUID that vmmanager.js sends). The response was {"success":true}.
  • Result: cache/domains no longer existed in zfs list, and /mnt/user/domains was gone. The share's domains.cfg was left behind.

The VM's log shows the destroy of the share's dataset:

delete empty zfs /mnt/user/domains/Ubuntu-20.04-research 0
dataset cache/domains
Command zfs destroy 'cache/domains'  2>&1
Output  end

Nothing else was lost here, because this was the only VM in the share. With other stopped VMs in the same dataset, zfs destroy would succeed as well and take their vdisks with it. Only a busy dataset (a running VM) makes it fail.

The lookup behaviour is easy to confirm on any ZFS pool:

# zfs list -H -o name /mnt/cache/appdata/Jellyfin   # a plain directory inside the appdata dataset
cache/appdata

Steps to reproduce

  1. On a ZFS pool, make sure the share domains is a dataset, e.g. cache/domains.
  2. Create a plain directory in it (mkdir /mnt/cache/domains/test), put a small vdisk in it, and define a VM that uses only that vdisk. VM folders created before a pool became ZFS, or by hand, are in this state.
  3. Optionally add a second, stopped VM with its vdisk in another folder of the same share.
  4. VMs → the test VM → Remove VM & Disks.
  5. zfs list: cache/domains is gone, and so is the second VM's vdisk.

Expected

Destroy a dataset only if the directory itself is a dataset's mountpoint. Otherwise rmdir() the empty directory. For example:

case "zfs":
  [$zfsdataset, $mountpoint] = array_pad(explode("\t", trim(shell_exec("zfs list -H -o name,mountpoint ".escapeshellarg($dirname)))), 2, '');
  if ($zfsdataset && realpath($mountpoint) === realpath($dirname)) {
    exec("zfs destroy ".escapeshellarg($zfsdataset)." 2>&1", $zfsoutput, $rtncode);
  } else {
    $rtncode = rmdir($dirname) ? 0 : 1;   // a plain directory: never touch the parent dataset
  }

Environment

  • Unraid 7.1.1 (observed). The code is unchanged on master at 26eb1b5.
  • Cache pool: a 2-device ZFS mirror.
主要言語
PHP
スター
266
フォーク
116
平均マージ
1日 5時間
マージ済み PR(30日)
4

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

unraid/webgui のほかの issue

unraid/webgui の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。