]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/RBDPlugin.pm
1 package PVE
::Storage
::RBDPlugin
;
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);
13 my ($scfg, $storeid, $op, @options) = @_;
15 my $monhost = $scfg->{monhost
};
18 my $cmd = ['/usr/bin/rbd', '-p', $scfg->{pool
}, '-m', $monhost, '-n',
19 "client.$scfg->{username}",
20 '--keyring', "/etc/pve/priv/ceph/${storeid}.keyring",
21 '--auth_supported', $scfg->{authsupported
}, $op];
23 push @$cmd, @options if scalar(@options);
29 my ($scfg, $storeid) = @_;
31 my $cmd = &$rbd_cmd($scfg, $storeid, 'ls');
38 if ($line =~ m/^(vm-(\d+)-\S+)$/) {
39 my ($image, $owner) = ($1, $2);
41 $list->{$scfg->{pool
}}->{$image} = {
50 run_command
($cmd, errmsg
=> "rbd error", errfunc
=> sub {}, outfunc
=> $parser);
54 die $err if $err && $err !~ m/doesn't contain rbd images/ ;
68 PVE
::JSONSchema
::register_format
('pve-storage-monhost', \
&parse_monhost
);
70 my ($name, $noerr) = @_;
72 if ($name !~ m/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i) {
73 return undef if $noerr;
74 die "lvm name '$name' contains illegal characters\n";
86 content
=> [ {images
=> 1}, { images
=> 1 }],
93 description
=> "Monitors daemon ips.",
97 description
=> "Pool.",
101 description
=> "RBD Id.",
105 description
=> "Authsupported.",
113 monhost
=> { fixed
=> 1 },
114 pool
=> { fixed
=> 1 },
115 username
=> { fixed
=> 1 },
116 authsupported
=> { 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 $monhost = addslashes
($scfg->{monhost
});
139 my $pool = $scfg->{pool
};
140 my $username = $scfg->{username
};
141 my $authsupported = addslashes
($scfg->{authsupported
});
143 my $path = "rbd:$pool/$name:id=$username:auth_supported=$authsupported:keyring=/etc/pve/priv/ceph/$storeid.keyring:mon_host=$monhost";
145 return ($path, $vmid, $vtype);
149 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
152 die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
153 if $name && $name !~ m/^vm-$vmid-/;
156 my $rdb = rbd_ls
($scfg, $storeid);
158 for (my $i = 1; $i < 100; $i++) {
159 my $tn = "vm-$vmid-disk-$i";
160 if (!defined ($rdb->{$scfg->{pool
}}->{$tn})) {
167 die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
170 my $cmd = &$rbd_cmd($scfg, $storeid, 'create', '--size', ($size/1024), $name);
171 run_command
($cmd, errmsg
=> "rbd create $name' error", errfunc
=> sub {});
177 my ($class, $storeid, $scfg, $volname) = @_;
179 my $cmd = &$rbd_cmd($scfg, $storeid, 'rm', $volname);
180 run_command
($cmd, errmsg
=> "rbd rm $volname' error", outfunc
=> sub {}, errfunc
=> sub {});
186 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
188 $cache->{rbd
} = rbd_ls
($scfg, $storeid) if !$cache->{rbd
};
192 if (my $dat = $cache->{rbd
}->{$scfg->{pool
}}) {
193 foreach my $image (keys %$dat) {
195 my $volname = $dat->{$image}->{name
};
197 my $volid = "$storeid:$volname";
199 my $owner = $dat->{$volname}->{vmid
};
201 my $found = grep { $_ eq $volid } @$vollist;
204 next if defined ($vmid) && ($owner ne $vmid);
207 my $info = $dat->{$volname};
208 $info->{volid
} = $volid;
209 $info->{format
} = 'raw';
219 my ($class, $storeid, $scfg, $cache) = @_;
226 return ($total, $free, $used, $active);
229 sub activate_storage
{
230 my ($class, $storeid, $scfg, $cache) = @_;
234 sub deactivate_storage
{
235 my ($class, $storeid, $scfg, $cache) = @_;
239 sub activate_volume
{
240 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
244 sub deactivate_volume
{
245 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
249 sub volume_size_info
{
250 my ($class, $scfg, $storeid, $volname, $timeout) = @_;