[Libguestfs] [PATCH 4/4] Check that a RHEV export storage domain has been attached to a Data Center

Matthew Booth mbooth at redhat.com
Mon Sep 13 13:24:52 UTC 2010


The master/vms directory in an export storage domain is only created when the
domain is attached to a Data Center, not when it is initialised. Because we
write to this directory last, virt-v2v will only currently fail at the very end
of the conversion process. This patch checks for the existence of this directory
early and reports a useful error to the user.

Fixes RHBZ#601535
---
 lib/Sys/VirtV2V/Target/RHEV.pm |   31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/lib/Sys/VirtV2V/Target/RHEV.pm b/lib/Sys/VirtV2V/Target/RHEV.pm
index 218cf63..b865c56 100644
--- a/lib/Sys/VirtV2V/Target/RHEV.pm
+++ b/lib/Sys/VirtV2V/Target/RHEV.pm
@@ -497,24 +497,43 @@ sub new
     my $fromchild = $nfs->{fromchild};
     while (<$fromchild>) {
         if (defined($domainuuid)) {
-            die(user_message(__x("{mountdir} contains multiple possible ".
+            die(user_message(__x("{domain_path} contains multiple possible ".
                                  "domains. It may only contain one.",
-                                 mountdir => $mountdir)));
+                                 domain_path => $domain_path)));
         }
         chomp;
         $domainuuid = $_;
     }
-
     $nfs->check_exit();
 
     if (!defined($domainuuid)) {
-        die(user_message(__x("{mountdir} does not contain an initialised ".
+        die(user_message(__x("{domain_path} does not contain an initialised ".
                              "storage domain",
-                             mountdir => $mountdir)));
+                             domain_path => $domain_path)));
     }
-
     $self->{domainuuid} = $domainuuid;
 
+    # Check that the domain has been attached to a Data Center by checking that
+    # the master/vms directory exists
+    my $vms_rel = $domainuuid.'/master/vms';
+    my $vms_abs = $mountdir.'/'.$vms_rel;
+    $nfs = Sys::VirtV2V::Target::RHEV::NFSHelper->new(sub {
+        if (-d $vms_abs) {
+            print "1\n";
+        } else {
+            print "0\n";
+        }
+    });
+    $fromchild = $nfs->{fromchild};
+    while (<$fromchild>) {
+        chomp;
+        die(user_message(__x("{domain_path} has not been attached to a RHEV ".
+                             "data center ({path} does not exist).",
+                             domain_path => $domain_path,
+                             path => $vms_rel))) if ($_ eq "0");
+    }
+    $nfs->check_exit();
+
     return $self;
 }
 
-- 
1.7.2.3




More information about the Libguestfs mailing list