]>
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);
14 my ($scfg, $storeid) = @_;
16 my $rbdpool = $scfg->{pool
};
17 my $monhost = $scfg->{monhost
};
20 my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{username
} ,'--keyring', '/etc/pve/priv/ceph/'.$storeid.'.keyring', '--auth_supported',$scfg->{authsupported
}, 'ls' ];
29 run_command
($cmd, errmsg
=> "rbd error", errfunc
=> $errfunc,outfunc => sub {
36 if ($image =~ m/^(vm-(\d+)-\S+)$/) {
40 $list->{$rbdpool}->{$image} = {
50 die $err if $err && $err !~ m/doesn't contain rbd images/ ;
65 PVE
::JSONSchema
::register_format
('pve-storage-monhost', \
&parse_monhost
);
67 my ($name, $noerr) = @_;
69 if ($name !~ m/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i) {
70 return undef if $noerr;
71 die "lvm name '$name' contains illegal characters\n";
84 content
=> [ {images
=> 1}, { images
=> 1 }],
91 description
=> "Monitors daemon ips.",
95 description
=> "Pool.",
99 description
=> "RBD Id.",
103 description
=> "Authsupported.",
111 monhost
=> { fixed
=> 1 },
112 pool
=> { fixed
=> 1 },
113 username
=> { fixed
=> 1 },
114 authsupported
=> { fixed
=> 1 },
115 content
=> { optional
=> 1 },
119 # Storage implementation
122 my ($class, $volname) = @_;
124 if ($volname =~ m/^(vm-(\d+)-\S+)$/) {
125 return ('images', $1, $2);
128 die "unable to parse rbd volume name '$volname'\n";
132 my ($class, $scfg, $volname, $storeid) = @_;
134 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
136 my $monhost = addslashes
($scfg->{monhost
});
137 my $pool = $scfg->{pool
};
138 my $username = $scfg->{username
};
139 my $authsupported = addslashes
($scfg->{authsupported
});
141 my $path = "rbd:$pool/$name:id=$username:auth_supported=$authsupported:keyring=/etc/pve/priv/ceph/$storeid.keyring:mon_host=$monhost";
143 return ($path, $vmid, $vtype);
147 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
150 die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
151 if $name && $name !~ m/^vm-$vmid-/;
152 my $rbdpool = $scfg->{pool
};
153 my $monhost = $scfg->{monhost
};
157 my $rdb = rbd_ls
($scfg, $storeid);
159 for (my $i = 1; $i < 100; $i++) {
160 my $tn = "vm-$vmid-disk-$i";
161 if (!defined ($rdb->{$rbdpool}->{$tn})) {
168 die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
171 my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{username
}, '--keyring','/etc/pve/priv/ceph/'.$storeid.'.keyring','--auth_supported', $scfg->{authsupported
}, 'create', '--size', ($size/1024), $name ];
172 run_command
($cmd, errmsg
=> "rbd create $name' error");
178 my ($class, $storeid, $scfg, $volname) = @_;
180 my $rbdpool = $scfg->{pool
};
181 my $monhost = $scfg->{monhost
};
184 my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{username
}, '--keyring','/etc/pve/priv/ceph/'.$storeid.'.keyring','--auth_supported',$scfg->{authsupported
}, 'rm', $volname ];
185 run_command
($cmd, errmsg
=> "rbd rm $volname' error");
191 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
193 $cache->{rbd
} = rbd_ls
($scfg, $storeid) if !$cache->{rbd
};
194 my $rbdpool = $scfg->{pool
};
197 if (my $dat = $cache->{rbd
}->{$rbdpool}) {
198 foreach my $image (keys %$dat) {
200 my $volname = $dat->{$image}->{name
};
202 my $volid = "$storeid:$volname";
205 my $owner = $dat->{$volname}->{vmid
};
207 my $found = grep { $_ eq $volid } @$vollist;
210 next if defined ($vmid) && ($owner ne $vmid);
213 my $info = $dat->{$volname};
214 $info->{volid
} = $volid;
225 my ($class, $storeid, $scfg, $cache) = @_;
231 return ($total,$free,$used,$active);
236 sub activate_storage
{
237 my ($class, $storeid, $scfg, $cache) = @_;
241 sub deactivate_storage
{
242 my ($class, $storeid, $scfg, $cache) = @_;
246 sub activate_volume
{
247 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
251 sub deactivate_volume
{
252 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;