mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 17:06:09 +00:00
fix(storages): a share or LVM pool a VM's disk path is in is not deleted
Deleting a pool was refused only while a VM's definition named the pool for a disk; a disk given by its file path was taken not to need it. That holds for a directory pool, but a share's or a file system's pool mounts the path and an LVM pool activates it: with the pool deleted, the path is gone at the next boot and the VM no longer starts (seen live with an NFS pool). Such a disk now refuses the delete too: a path under the pool's mount point, or an LVM volume by its /dev/<group> or /dev/mapper name. iSCSI and disk pools share their device directories with other pools and are left as they were. A pool libvirt reports as inaccessible (state 4: running, its storage out of reach) made the pool page fail with an IndexError; it now shows an Inaccessible badge.
This commit is contained in:
parent
044945bd97
commit
fb3b2f479e
7 changed files with 86 additions and 24 deletions
Binary file not shown.
|
|
@ -11,7 +11,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-11-13 07:26+0000\n"
|
||||
"POT-Creation-Date: 2026-11-13 07:27+0000\n"
|
||||
"PO-Revision-Date: 2020-11-04 12:00+0000\n"
|
||||
"Last-Translator: catborise <muhammetalisag@gmail.com>, 2020\n"
|
||||
"Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n"
|
||||
|
|
@ -8620,6 +8620,10 @@ msgstr "Havuz"
|
|||
msgid "Degraded"
|
||||
msgstr "Bozulmuş"
|
||||
|
||||
#: storages/templates/storage.html:94
|
||||
msgid "Inaccessible"
|
||||
msgstr "Erişilemiyor"
|
||||
|
||||
#: storages/templates/storage.html:112
|
||||
msgid ""
|
||||
"This pool is stopped: its volumes cannot be listed or managed until it is "
|
||||
|
|
@ -10280,7 +10284,7 @@ msgstr ""
|
|||
msgid "Enter one <rule> element"
|
||||
msgstr "Tek bir <rule> öğesi girin"
|
||||
|
||||
#: vrtManager/storage.py:213
|
||||
#: vrtManager/storage.py:214
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Pool %(name)s holds disks of the running VMs %(vms)s; shut them down first"
|
||||
|
|
@ -10288,16 +10292,16 @@ msgstr ""
|
|||
"%(name)s havuzu çalışan %(vms)s sanal makinelerinin disklerini tutuyor; önce "
|
||||
"onları kapatın"
|
||||
|
||||
#: vrtManager/storage.py:221
|
||||
#: vrtManager/storage.py:231
|
||||
#, python-format
|
||||
msgid ""
|
||||
"VMs %(vms)s have disks in pool %(name)s by its name and would no longer "
|
||||
"start; detach those disks first"
|
||||
"VMs %(vms)s have disks in pool %(name)s and would no longer start; detach "
|
||||
"those disks first"
|
||||
msgstr ""
|
||||
"%(vms)s sanal makinelerinin %(name)s havuzunda adıyla bağlı diskleri var ve "
|
||||
"artık başlamaz; önce bu diskleri ayırın"
|
||||
"%(vms)s sanal makinelerinin %(name)s havuzunda diskleri var ve artık "
|
||||
"başlamaz; önce bu diskleri ayırın"
|
||||
|
||||
#: vrtManager/storage.py:253
|
||||
#: vrtManager/storage.py:263
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Volume %(name)s is in use: a VM's disk, a backing file or a snapshot's file"
|
||||
|
|
@ -10305,7 +10309,7 @@ msgstr ""
|
|||
"%(name)s birimi kullanımda: bir sanal makinenin diski, bir temel (backing) "
|
||||
"dosya ya da bir anlık görüntünün dosyası"
|
||||
|
||||
#: vrtManager/storage.py:346
|
||||
#: vrtManager/storage.py:356
|
||||
#, python-format
|
||||
msgid "The running VMs %(vms)s use volume %(name)s; shut them down to copy it"
|
||||
msgstr ""
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-11-13 07:26+0000\n"
|
||||
"POT-Creation-Date: 2026-11-13 07:27+0000\n"
|
||||
"PO-Revision-Date: \n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
|
|
@ -8147,6 +8147,10 @@ msgstr "存储池"
|
|||
msgid "Degraded"
|
||||
msgstr "降级"
|
||||
|
||||
#: storages/templates/storage.html:94
|
||||
msgid "Inaccessible"
|
||||
msgstr "无法访问"
|
||||
|
||||
#: storages/templates/storage.html:112
|
||||
msgid ""
|
||||
"This pool is stopped: its volumes cannot be listed or managed until it is "
|
||||
|
|
@ -9675,26 +9679,26 @@ msgstr "无法引用过滤器 %(name)s:它就是本过滤器、已被引用或
|
|||
msgid "Enter one <rule> element"
|
||||
msgstr "请输入一个 <rule> 元素"
|
||||
|
||||
#: vrtManager/storage.py:213
|
||||
#: vrtManager/storage.py:214
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Pool %(name)s holds disks of the running VMs %(vms)s; shut them down first"
|
||||
msgstr "存储池 %(name)s 中有运行中的虚拟机 %(vms)s 的磁盘;请先关闭它们"
|
||||
|
||||
#: vrtManager/storage.py:221
|
||||
#: vrtManager/storage.py:231
|
||||
#, python-format
|
||||
msgid ""
|
||||
"VMs %(vms)s have disks in pool %(name)s by its name and would no longer "
|
||||
"start; detach those disks first"
|
||||
msgstr "虚拟机 %(vms)s 通过名称使用存储池 %(name)s 中的磁盘,将无法再启动;请先分离这些磁盘"
|
||||
"VMs %(vms)s have disks in pool %(name)s and would no longer start; detach "
|
||||
"those disks first"
|
||||
msgstr "虚拟机 %(vms)s 使用存储池 %(name)s 中的磁盘,将无法再启动;请先分离这些磁盘"
|
||||
|
||||
#: vrtManager/storage.py:253
|
||||
#: vrtManager/storage.py:263
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Volume %(name)s is in use: a VM's disk, a backing file or a snapshot's file"
|
||||
msgstr "卷 %(name)s 正在使用中:它是虚拟机的磁盘、后备文件或快照文件"
|
||||
|
||||
#: vrtManager/storage.py:346
|
||||
#: vrtManager/storage.py:356
|
||||
#, python-format
|
||||
msgid "The running VMs %(vms)s use volume %(name)s; shut them down to copy it"
|
||||
msgstr "正在运行的虚拟机 %(vms)s 使用卷 %(name)s;请先将其关闭再复制"
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@
|
|||
<span class="text-body-secondary">{% trans "State" %}</span>
|
||||
<span class="d-flex flex-wrap justify-content-end gap-1">
|
||||
{% if state %}<span class="badge text-bg-success">{% trans "Active" %}</span>{% else %}<span class="badge text-bg-secondary">{% trans "Stopped" %}</span>{% endif %}
|
||||
{% if status == "Running degraded" %}<span class="badge text-bg-warning">{% trans "Degraded" %}</span>{% endif %}
|
||||
{% if status == "Running degraded" %}<span class="badge text-bg-warning">{% trans "Degraded" %}</span>{% elif status == "Inaccessible" %}<span class="badge text-bg-warning">{% trans "Inaccessible" %}</span>{% endif %}
|
||||
{% if autostart %}<span class="badge text-bg-light border">{% trans "Autostart" %}</span>{% endif %}
|
||||
</span>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
"""A pool a VM needs is not stopped or deleted: stopping one that holds a
|
||||
running VM's disk would take that disk away, deleting one a VM's definition
|
||||
names (a disk of type volume) would keep that VM from starting. A disk given
|
||||
by its file path keeps working without the pool's definition. Runs on a
|
||||
by its file path keeps working without a directory pool's definition, not
|
||||
without a share's, which mounts it. Runs on a
|
||||
private libvirt test driver: "test:///default" is shared by the whole process."""
|
||||
|
||||
import tempfile
|
||||
|
|
@ -75,3 +76,43 @@ class PoolInUseTests(TestCase):
|
|||
self.conn.lookupByName("by-name").undefine()
|
||||
self.post("delete")
|
||||
self.assertNotIn("use-pool", self.conn.listDefinedStoragePools())
|
||||
|
||||
def test_a_share_a_vm_disk_path_is_in_is_not_deleted(self):
|
||||
# undefined, the share is not mounted at the next boot: the path is gone
|
||||
self.conn.storagePoolDefineXML(
|
||||
"<pool type='netfs'><name>share</name><source><host name='192.0.2.1'/><dir path='/export'/>"
|
||||
"<format type='nfs'/></source><target><path>/mnt/share</path></target></pool>", 0)
|
||||
self.conn.defineXML(domain("on-share", "type='file'><source file='/mnt/share/v.qcow2'/>"))
|
||||
self.conn.defineXML(domain("beside", "type='file'><source file='/mnt/share-2/v.qcow2'/>"))
|
||||
url = reverse("storage", args=[self.compute.id, "share"])
|
||||
response = self.client.post(url, {"delete": ""})
|
||||
messages = [str(m) for m in get_messages(response.wsgi_request)]
|
||||
self.assertEqual(messages, ["VMs on-share have disks in pool share and would no longer start; detach those disks first"])
|
||||
self.conn.lookupByName("on-share").undefine()
|
||||
self.client.post(url, {"delete": ""})
|
||||
self.assertNotIn("share", self.conn.listDefinedStoragePools())
|
||||
|
||||
def test_an_lvm_pool_counts_its_device_mapper_names_and_iscsi_pools_do_not_share_their_directory(self):
|
||||
self.conn.storagePoolDefineXML(
|
||||
"<pool type='logical'><name>lvm</name><source><name>vg-data</name><format type='lvm2'/></source>"
|
||||
"<target><path>/dev/vg-data</path></target></pool>", 0)
|
||||
self.conn.storagePoolDefineXML(
|
||||
"<pool type='iscsi'><name>lun</name><source><host name='192.0.2.1'/><device path='iqn.2026-01.test:a'/>"
|
||||
"</source><target><path>/dev/disk/by-path</path></target></pool>", 0)
|
||||
self.conn.defineXML(domain("on-lv", "type='block'><source dev='/dev/mapper/vg--data-lv1'/>"))
|
||||
# another iSCSI pool's LUN: every iSCSI pool's target is /dev/disk/by-path
|
||||
self.conn.defineXML(domain("other-lun", "type='block'><source dev='/dev/disk/by-path/ip-192.0.2.9-lun-0'/>"))
|
||||
self.client.post(reverse("storage", args=[self.compute.id, "lvm"]), {"delete": ""})
|
||||
self.client.post(reverse("storage", args=[self.compute.id, "lun"]), {"delete": ""})
|
||||
self.assertIn("lvm", self.conn.listDefinedStoragePools())
|
||||
self.assertNotIn("lun", self.conn.listDefinedStoragePools())
|
||||
|
||||
def test_an_inaccessible_pool_has_its_state(self):
|
||||
# libvirt's state 4: running, but its storage cannot be reached
|
||||
from vrtManager.storage import wvmStorage
|
||||
|
||||
storage = wvmStorage.__new__(wvmStorage)
|
||||
for state, status in ((2, "Running normally"), (4, "Inaccessible"), (9, "Unknown")):
|
||||
with self.subTest(state=state):
|
||||
storage.pool = type("Pool", (), {"info": lambda self, state=state: [state, 0, 0, 0]})()
|
||||
self.assertEqual(storage.get_status(), status)
|
||||
|
|
|
|||
|
|
@ -168,10 +168,11 @@ class wvmStorage(wvmConnect):
|
|||
"Initializing pool, not available",
|
||||
"Running normally",
|
||||
"Running degraded",
|
||||
"Inaccessible", # running, but its storage cannot be reached: a share whose server is gone
|
||||
]
|
||||
try:
|
||||
return status[self.pool.info()[0]]
|
||||
except ValueError:
|
||||
except IndexError: # a state newer than these
|
||||
return "Unknown"
|
||||
|
||||
def get_size(self):
|
||||
|
|
@ -215,10 +216,22 @@ class wvmStorage(wvmConnect):
|
|||
|
||||
def delete(self):
|
||||
"""Refused while a VM's definition names it for a disk: that VM would
|
||||
no longer start. A disk given by its file path does not need it."""
|
||||
name = self.pool.name()
|
||||
if vms := self.domains_using(lambda domain: domain.xpath("devices/disk/source[@pool=$name]", name=name)):
|
||||
raise util.OperationError(gettext_noop("VMs %(vms)s have disks in pool %(name)s by its name and would no longer start; detach those disks first"), vms=', '.join(vms), name=name)
|
||||
no longer start. So is a disk given by its path in a pool that mounts
|
||||
or activates its storage (a share, a file system, an LVM group): the
|
||||
path is gone with the pool. A directory pool's files stay; the device
|
||||
directories of iSCSI and disk pools are every pool's, not this one's."""
|
||||
name, kind = self.pool.name(), self.get_type()
|
||||
target = (self.get_target_path() or "").rstrip("/")
|
||||
under = (target + "/",) if kind in ("fs", "netfs", "logical") and target else ()
|
||||
if kind == "logical" and (group := self.get_source_name()):
|
||||
under += ("/dev/mapper/" + group.replace("-", "--") + "-",) # device mapper's name of its volumes
|
||||
|
||||
def needs(domain):
|
||||
return domain.xpath("devices/disk/source[@pool=$name]", name=name) or any(
|
||||
path.startswith(under) for path in domain.xpath("devices/disk//source/@file | devices/disk//source/@dev"))
|
||||
|
||||
if vms := self.domains_using(needs):
|
||||
raise util.OperationError(gettext_noop("VMs %(vms)s have disks in pool %(name)s and would no longer start; detach those disks first"), vms=', '.join(vms), name=name)
|
||||
self.pool.undefine()
|
||||
|
||||
def get_autostart(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue