]>
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', 'list', '-r');
32 run_command
($cmd, outfunc
=> sub {
35 if ($line =~ /= (vm-(\d+)-\S+)\s+(\d+)\s+(\d+)\s(\d+)\s(\d+)\s/) {
40 $list->{$storeid}->{$image} = {
60 content
=> [ {images
=> 1}, { images
=> 1 }],
67 nodes
=> { optional
=> 1 },
68 disable
=> { optional
=> 1 },
69 portal
=> { fixed
=> 1 },
70 content
=> { optional
=> 1 },
74 # Storage implementation
77 my ($class, $volname) = @_;
79 if ($volname =~ m/^(vm-(\d+)-\S+)$/) {
80 return ('images', $1, $2);
83 die "unable to parse rbd volume name '$volname'\n";
87 my ($class, $scfg, $volname, $storeid) = @_;
89 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
91 my $portal = $scfg->{portal
};
92 my ($server, $port) = split(':', $portal);
93 $port = 7000 if !$port;
95 my $path = "sheepdog:$server:$port:$name";
97 return ($path, $vmid, $vtype);
101 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
104 die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
105 if $name && $name !~ m/^vm-$vmid-/;
108 my $sheepdog = sheepdog_ls
($scfg, $storeid);
110 for (my $i = 1; $i < 100; $i++) {
111 my $tn = "vm-$vmid-disk-$i";
112 if (!defined ($sheepdog->{$storeid}->{$tn})) {
119 die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
122 my $cmd = &$collie_cmd($scfg, 'vdi', 'create', $name , "${size}KB");
124 run_command
($cmd, errmsg
=> "sheepdog create $name' error");
130 my ($class, $storeid, $scfg, $volname) = @_;
132 my $cmd = &$collie_cmd($scfg, 'vdi', 'delete' , $volname);
134 run_command
($cmd, errmsg
=> "sheepdog delete $volname' error");
140 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
142 $cache->{sheepdog
} = sheepdog_ls
($scfg, $storeid) if !$cache->{sheepdog
};
145 if (my $dat = $cache->{sheepdog
}->{$storeid}) {
146 foreach my $image (keys %$dat) {
148 my $volname = $dat->{$image}->{name
};
150 my $volid = "$storeid:$volname";
152 my $owner = $dat->{$volname}->{vmid
};
154 my $found = grep { $_ eq $volid } @$vollist;
157 next if defined ($vmid) && ($owner ne $vmid);
160 my $info = $dat->{$volname};
161 $info->{volid
} = $volid;
162 $info->{format
} = 'raw';
172 my ($class, $storeid, $scfg, $cache) = @_;
179 my $cmd = &$collie_cmd($scfg, 'node', 'info' , '-r');
183 if ($line =~ m/^Total\s(\d+)\s(\d+)\s/) {
186 $free = $total - $used;
190 run_command
($cmd, outfunc
=> $parser, errmsg
=> "sheepdog node info error");
192 return ($total,$free,$used,$active);
197 sub activate_storage
{
198 my ($class, $storeid, $scfg, $cache) = @_;
202 sub deactivate_storage
{
203 my ($class, $storeid, $scfg, $cache) = @_;
207 sub activate_volume
{
208 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
212 sub deactivate_volume
{
213 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
217 sub volume_size_info
{
218 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
222 my $cmd = &$collie_cmd($scfg, 'vdi', 'list', '-r', $volname);
224 run_command
($cmd, outfunc
=> sub {
227 if ($line =~ /= (vm-(\d+)-\S+)\s+(\d+)\s+(\d+)\s(\d+)\s(\d+)\s/) {
237 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
239 my $cmd = &$collie_cmd($scfg, 'vdi', 'resize' , $volname, $size);
240 run_command
($cmd, errmsg
=> "sheepdog resize $volname' error");
245 sub volume_snapshot
{
246 my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
248 return 1 if $running;
250 my $cmd = &$collie_cmd($scfg, 'vdi', 'snapshot', '-s', $snap, $volname);
251 run_command
($cmd, errmsg
=> "sheepdog snapshot $volname' error");
256 sub volume_snapshot_rollback
{
257 my ($class, $scfg, $storeid, $volname, $snap) = @_;
259 my $cmd = &$collie_cmd($scfg, 'vdi', 'rollback', '-s', $snap, $volname);
260 run_command
($cmd, errmsg
=> "sheepdog snapshot $volname' error");
264 sub volume_snapshot_delete
{
265 my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
267 return 1 if $running;
269 my $cmd = &$collie_cmd($scfg, 'vdi', 'delete', '-s', $snap, $volname);
270 run_command
($cmd, errmsg
=> "sheepdog snapshot $volname' error");