[pve-devel] [PATCH pve-zsync 4/5] add disk parser for LXC

Wolfgang Link w.link at proxmox.com
Thu Nov 5 09:00:29 CET 2015


---
 pve-zsync | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/pve-zsync b/pve-zsync
index 3af504b..caf0712 100644
--- a/pve-zsync
+++ b/pve-zsync
@@ -699,11 +699,18 @@ sub get_disks {
 
     my $cmd = [];
     push @$cmd, 'ssh', "root\@$target->{ip}", '--', if $target->{ip};
-    push @$cmd, 'qm', 'config', $target->{vmid};
+
+    if ($target->{vm_type} eq 'qemu') {
+	push @$cmd, 'qm', 'config', $target->{vmid};
+    } elsif ($target->{vm_type} eq 'lxc') {
+	push @$cmd, 'pct', 'config', $target->{vmid};
+    } else {
+	die "VM Type unknown\n";
+    }
 
     my $res = run_cmd($cmd);
 
-    my $disks = parse_disks($res, $target->{ip});
+    my $disks = parse_disks($res, $target->{ip}, $target->{vm_type});
 
     return $disks;
 }
@@ -735,13 +742,13 @@ sub parse_disks {
 	my $line = $1;
 
 	next if $line =~ /cdrom|none/;
-	next if $line !~ m/^(?:virtio|ide|scsi|sata)\d+: /;
+	next if $line !~ m/^(?:((?:virtio|ide|scsi|sata|mp)\d+)|rootfs): /;
 
 	my $disk = undef;
 	my $stor = undef;
-	if($line =~ m/^(?:virtio|ide|scsi|sata)\d+: (.+:)([A-Za-z0-9\-]+),(.*)$/) {
-	    $disk = $2;
-	    $stor = $1;
+	if($line =~ m/^(?:((?:virtio|ide|scsi|sata|mp)\d+)|rootfs): (.+:)([A-Za-z0-9\-]+),(.*)$/) {
+	    $disk = $3;
+	    $stor = $2;
 	} else {
 	    die "disk is not on ZFS Storage\n";
 	}
@@ -751,7 +758,7 @@ sub parse_disks {
 	push @$cmd, 'pvesm', 'path', "$stor$disk";
 	my $path = run_cmd($cmd);
 
-	if ($path =~ m/^\/dev\/zvol\/(\w+.*)(\/$disk)$/) {
+	if ($vm_type eq 'qemu' && $path =~ m/^\/dev\/zvol\/(\w+.*)(\/$disk)$/) {
 
 	    my @array = split('/', $1);
 	    $disks->{$num}->{pool} = shift(@array);
@@ -764,6 +771,20 @@ sub parse_disks {
 	    $disks->{$num}->{all} .= "\/$disk";
 
 	    $num++;
+	} elsif ($vm_type eq 'lxc' && $path =~ m/^\/(\w+.+)\/(\w+.*)(\/$disk)$/) {
+
+	    $disks->{$num}->{pool} = $1;
+	    $disks->{$num}->{all} = $disks->{$num}->{pool};
+
+	    if ($2) {
+		$disks->{$num}->{path} = $2;
+		$disks->{$num}->{all} .= "\/$disks->{$num}->{path}";
+	    }
+
+	    $disks->{$num}->{last_part} = $disk;
+	    $disks->{$num}->{all} .= "\/$disk";
+
+	    $num++;
 
 	} else {
 	    die "ERROR: in path\n";
-- 
2.1.4




More information about the pve-devel mailing list