Skip to content

Commit

Permalink
wip: remove locked dev when domain down
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Jun 14, 2024
1 parent 3e7cfb5 commit 011b252
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
22 changes: 18 additions & 4 deletions lib/Ravada/HostDevice.pm
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,27 @@ sub is_device($self, $device, $id_vm) {
}

sub _device_locked($self, $name, $id_vm=$self->id_vm) {
my $sth = $$CONNECTOR->dbh->prepare("SELECT id FROM host_devices_domain_locked "
my $sth = $$CONNECTOR->dbh->prepare(
"SELECT id,id_domain "
." FROM host_devices_domain_locked "
." WHERE id_vm=? AND name=? "
);
$sth->execute($id_vm, $name);
my ($is_locked) = $sth->fetchrow;
$is_locked = 0 if !defined $is_locked;
return $is_locked;
my $sth_status = $$CONNECTOR->dbh->prepare(
"SELECT status FROM domains WHERE id=?"
);

my $sth_unlock = $$CONNECTOR->dbh->prepare(
"DELETE FROM host_devices_domain_locked "
." WHERE id=?"
);
while ( my ($id_lock, $id_domain)= $sth->fetchrow ) {
$sth_status->execute($id_domain);
my ($status) = $sth_status->fetchrow;
return $id_domain if $status && $status ne 'down';
$sth_unlock->execute($id_lock);
}
return 0;
}

sub list_available_devices($self, $id_vm=$self->id_vm) {
Expand Down
17 changes: 16 additions & 1 deletion t/device/40_mediated_device.t
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ sub _check_used_mdev($vm, $hd) {
$dom_imported = $vm->import_domain($dom->get_name,user_admin)
unless $dom_imported;

$dom_imported->_data('status' => 'active');

$dom_imported->add_host_device($hd->id);
my ($dev) = grep /^$uuid/, $hd->list_devices;
if (!$dev) {
Expand Down Expand Up @@ -551,8 +553,21 @@ sub test_volatile_clones($vm, $domain, $host_device) {
sleep 3;
$clone->shutdown_now(user_admin);

$exp_avail++;

for (1 .. 3 ) {
$n_device = $host_device->list_available_devices();
last if $n_device == $exp_avail;
Ravada::Request->force_shutdown(
uid => user_admin->id
,id_domain => $clone->id
);
wait_request;
}
is($n_device,$exp_avail) or exit;

$n_device = $host_device->list_available_devices();
is($n_device,++$exp_avail) or exit;
is($n_device,$exp_avail) or exit;

my $clone_gone = rvd_back->search_domain($clone_data->{name});
ok(!$clone_gone,"Expecting $clone_data->{name} removed on shutdown");
Expand Down

0 comments on commit 011b252

Please sign in to comment.