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

Abierto
#2,792 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@SimonFair ya está trabajando en esto.

Desde el 21/10/2026.

  • #2793 de @SimonFair — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
php
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
PHP
Estrellas
266
Forks
116
Merge medio
1 d 5 h
PR fusionados (30 d)
4

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de unraid/webgui

Todos los issues de unraid/webgui

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.