]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/SheepdogPlugin.pm
1 package PVE
::Storage
::SheepdogPlugin
;
6 use PVE
::Tools
qw(run_command trim);
7 use PVE
::Storage
::Plugin
;
8 use PVE
::JSONSchema
qw(get_standard_option);
10 use base
qw(PVE::Storage::Plugin);
12 my $collie_cmd = sub {
13 my ($scfg, $class, $op, @options) = @_;
15 my $portal = $scfg->{portal
};
16 my ($server, $port) = split(':', $portal);
17 my $cmd = ['/usr/sbin/collie', $class, $op, '-a', $server];
18 push @$cmd, '-p', $port if $port;
20 push @$cmd, @options if scalar(@options);
26 my ($scfg, $storeid) = @_;
28 my $cmd = &$collie_cmd($scfg, 'vdi', 'graph');
30 my $relationship = {};
33 run_command
($cmd, outfunc
=> sub {
41 if ($line =~ /\"(\S+)\"\s->\s\"(\S+)\"/) {
44 $relationship->{$child}->{parent
} = $parent;
46 elsif ($line =~ /group\s\=\s\"(\S+)\",/) {
48 $relationship->{$child}->{name
} = $name if $child;
55 $cmd = &$collie_cmd($scfg, 'vdi', 'list', '-r');
59 run_command
($cmd, outfunc
=> sub {
62 if ($line =~ /(=|c) (vm-(\d+)-\S+)\s+(\d+)\s+(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S+)\s(\d+)/) {
67 my $parentid = $relationship->{$idvdi}->{parent
} if $relationship->{$idvdi}->{parent
};
68 my $parent = $relationship->{$parentid}->{name
} if $parentid;
69 $list->{$storeid}->{$image} = {
81 sub sheepdog_snapshot_ls
{
82 my ($scfg, $volname) = @_;
84 my $cmd = &$collie_cmd($scfg, 'vdi', 'list', '-r');
87 run_command
($cmd, outfunc
=> sub {
90 if ($line =~ /s\s(\S+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S+)\s(\d+)\s(\S+)/) {
107 content
=> [ {images
=> 1}, { images
=> 1 }],
114 nodes
=> { optional
=> 1 },
115 disable
=> { optional
=> 1 },
116 portal
=> { fixed
=> 1 },
117 content
=> { optional
=> 1 },
121 # Storage implementation
124 my ($class, $volname) = @_;
126 if ($volname =~ m/^(vm-(\d+)-\S+)$/) {
127 return ('images', $1, $2);
130 die "unable to parse rbd volume name '$volname'\n";
134 my ($class, $scfg, $volname, $storeid) = @_;
136 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
138 my $portal = $scfg->{portal
};
139 my ($server, $port) = split(':', $portal);
140 $port = 7000 if !$port;
142 my $path = "sheepdog:$server:$port:$name";
144 return ($path, $vmid, $vtype);
148 my ($class, $storeid, $scfg, $volname) = @_;
150 die "not implemented";
154 my ($class, $scfg, $storeid, $volname, $vmid) = @_;
156 die "not implemented";
160 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
163 die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
164 if $name && $name !~ m/^vm-$vmid-/;
167 my $sheepdog = sheepdog_ls
($scfg, $storeid);
169 for (my $i = 1; $i < 100; $i++) {
170 my $tn = "vm-$vmid-disk-$i";
171 if (!defined ($sheepdog->{$storeid}->{$tn})) {
178 die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
181 my $cmd = &$collie_cmd($scfg, 'vdi', 'create', $name , "${size}KB");
183 run_command
($cmd, errmsg
=> "sheepdog create $name' error");
189 my ($class, $storeid, $scfg, $volname, $isBase) = @_;
191 my $snapshots = sheepdog_snapshot_ls
($scfg, $volname);
192 while (my ($snapname) = each %$snapshots) {
193 my $cmd = &$collie_cmd($scfg, 'vdi', 'delete' , '-s', $snapname, $volname);
194 run_command
($cmd, errmsg
=> "sheepdog delete snapshot $snapname $volname' error");
197 my $cmd = &$collie_cmd($scfg, 'vdi', 'delete' , $volname);
199 run_command
($cmd, errmsg
=> "sheepdog delete $volname' error");
205 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
207 $cache->{sheepdog
} = sheepdog_ls
($scfg, $storeid) if !$cache->{sheepdog
};
210 if (my $dat = $cache->{sheepdog
}->{$storeid}) {
211 foreach my $image (keys %$dat) {
213 my $volname = $dat->{$image}->{name
};
215 my $volid = "$storeid:$volname";
217 my $owner = $dat->{$volname}->{vmid
};
219 my $found = grep { $_ eq $volid } @$vollist;
222 next if defined ($vmid) && ($owner ne $vmid);
225 my $info = $dat->{$volname};
226 $info->{volid
} = $volid;
227 $info->{format
} = 'raw';
237 my ($class, $storeid, $scfg, $cache) = @_;
244 my $cmd = &$collie_cmd($scfg, 'node', 'info' , '-r');
248 if ($line =~ m/^Total\s(\d+)\s(\d+)\s/) {
251 $free = $total - $used;
255 run_command
($cmd, outfunc
=> $parser, errmsg
=> "sheepdog node info error");
257 return ($total,$free,$used,$active);
262 sub activate_storage
{
263 my ($class, $storeid, $scfg, $cache) = @_;
267 sub deactivate_storage
{
268 my ($class, $storeid, $scfg, $cache) = @_;
272 sub activate_volume
{
273 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
277 sub deactivate_volume
{
278 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
282 sub volume_size_info
{
283 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
287 my $cmd = &$collie_cmd($scfg, 'vdi', 'list', '-r');
289 run_command
($cmd, outfunc
=> sub {
292 if ($line =~ /(=|c) $volname\s+(\d+)\s+(\d+)\s(\d+)\s(\d+)\s/) {
302 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
304 my $cmd = &$collie_cmd($scfg, 'vdi', 'resize' , $volname, $size);
305 run_command
($cmd, errmsg
=> "sheepdog resize $volname' error");
310 sub volume_snapshot
{
311 my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
313 return 1 if $running;
315 my $cmd = &$collie_cmd($scfg, 'vdi', 'snapshot', '-s', $snap, $volname);
316 run_command
($cmd, errmsg
=> "sheepdog snapshot $volname' error");
321 sub volume_snapshot_rollback
{
322 my ($class, $scfg, $storeid, $volname, $snap) = @_;
324 my $cmd = &$collie_cmd($scfg, 'vdi', 'rollback', '-s', $snap, $volname);
325 run_command
($cmd, errmsg
=> "sheepdog snapshot $volname' error");
329 sub volume_snapshot_delete
{
330 my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
332 return 1 if $running;
334 my $cmd = &$collie_cmd($scfg, 'vdi', 'delete', '-s', $snap, $volname);
335 run_command
($cmd, errmsg
=> "sheepdog snapshot $volname' error");
340 sub volume_has_feature
{
341 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
344 snapshot
=> { current
=> 1, snap
=> 1},
345 clone
=> { snap
=> 1},
348 my $snap = $snapname ?
'snap' : 'current';
349 return 1 if $features->{$feature}->{$snap};