]>
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 {
35 $list->{$rbdpool}->{$image} = {
44 die $err if $err && $err !~ m/doesn't contain rbd images/ ;
59 PVE
::JSONSchema
::register_format
('pve-storage-monhost', \
&parse_monhost
);
61 my ($name, $noerr) = @_;
63 if ($name !~ m/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i) {
64 return undef if $noerr;
65 die "lvm name '$name' contains illegal characters\n";
78 content
=> [ {images
=> 1}, { images
=> 1 }],
85 description
=> "Monitors daemon ips.",
89 description
=> "Pool.",
93 description
=> "RBD Id.",
97 description
=> "Authsupported.",
105 monhost
=> { fixed
=> 1 },
106 pool
=> { fixed
=> 1 },
107 username
=> { fixed
=> 1 },
108 authsupported
=> { fixed
=> 1 },
109 content
=> { optional
=> 1 },
113 # Storage implementation
116 my ($class, $volname) = @_;
118 if ($volname =~ m/^(vm-(\d+)-\S+)$/) {
119 return ('images', $1, $2);
122 die "unable to parse rbd volume name '$volname'\n";
126 my ($class, $scfg, $volname, $storeid) = @_;
128 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
130 my $monhost = addslashes
($scfg->{monhost
});
131 my $pool = $scfg->{pool
};
132 my $username = $scfg->{username
};
133 my $authsupported = addslashes
($scfg->{authsupported
});
135 my $path = "rbd:$pool/$name:id=$username:auth_supported=$authsupported:keyring=/etc/pve/priv/ceph/$storeid.keyring:mon_host=$monhost";
137 return ($path, $vmid, $vtype);
141 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
144 die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
145 if $name && $name !~ m/^vm-$vmid-/;
146 my $rbdpool = $scfg->{pool
};
147 my $monhost = $scfg->{monhost
};
151 my $rdb = rbd_ls
($scfg, $storeid);
153 for (my $i = 1; $i < 100; $i++) {
154 my $tn = "vm-$vmid-disk-$i";
155 if (!defined ($rdb->{$rbdpool}->{$tn})) {
162 die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
165 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 ];
166 run_command
($cmd, errmsg
=> "rbd create $name' error");
172 my ($class, $storeid, $scfg, $volname) = @_;
174 my $rbdpool = $scfg->{pool
};
175 my $monhost = $scfg->{monhost
};
178 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 ];
179 run_command
($cmd, errmsg
=> "rbd rm $volname' error");
185 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
187 $cache->{rbd
} = rbd_ls
($scfg, $storeid) if !$cache->{rbd
};
188 my $rbdpool = $scfg->{pool
};
191 if (my $dat = $cache->{rbd
}->{$rbdpool}) {
192 foreach my $image (keys %$dat) {
194 my $volname = $dat->{$image}->{name
};
196 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;
219 my ($class, $storeid, $scfg, $cache) = @_;
225 return ($total,$free,$used,$active);
230 sub activate_storage
{
231 my ($class, $storeid, $scfg, $cache) = @_;
235 sub deactivate_storage
{
236 my ($class, $storeid, $scfg, $cache) = @_;
240 sub activate_volume
{
241 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
245 sub deactivate_volume
{
246 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;