]>
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
} ,'--keyfile', '/etc/pve/priv/ceph/'.$storeid.'.'.$scfg->{username
}.'.key', '--auth_supported',$scfg->{authsupported
}, 'ls' ];
22 run_command
($cmd, errfunc
=> sub {},outfunc
=> sub {
28 $list->{$rbdpool}->{$image} = {
49 PVE
::JSONSchema
::register_format
('pve-storage-monhost', \
&parse_monhost
);
51 my ($name, $noerr) = @_;
53 if ($name !~ m/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i) {
54 return undef if $noerr;
55 die "lvm name '$name' contains illegal characters\n";
68 content
=> [ {images
=> 1}, { images
=> 1 }],
75 description
=> "Monitors daemon ips.",
79 description
=> "Pool.",
83 description
=> "RBD Id.",
87 description
=> "Authsupported.",
95 monhost
=> { fixed
=> 1 },
96 pool
=> { fixed
=> 1 },
97 username
=> { fixed
=> 1 },
98 authsupported
=> { fixed
=> 1 },
99 content
=> { optional
=> 1 },
103 # Storage implementation
106 my ($class, $volname) = @_;
108 if ($volname =~ m/^(vm-(\d+)-\S+)$/) {
109 return ('images', $1, $2);
112 die "unable to parse rbd volume name '$volname'\n";
116 my ($class, $scfg, $volname, $storeid) = @_;
118 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
120 my $monhost = addslashes
($scfg->{monhost
});
121 my $pool = $scfg->{pool
};
122 my $username = $scfg->{username
};
123 my $authsupported = addslashes
($scfg->{authsupported
});
125 my $path = "rbd:$pool/$name:id=$username:auth_supported=$authsupported:keyfile=/etc/pve/priv/ceph/$storeid.$username.key:mon_host=$monhost";
127 return ($path, $vmid, $vtype);
131 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
134 die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
135 if $name && $name !~ m/^vm-$vmid-/;
136 my $rbdpool = $scfg->{pool
};
137 my $monhost = $scfg->{monhost
};
141 my $rdb = rbd_ls
($scfg, $storeid);
143 for (my $i = 1; $i < 100; $i++) {
144 my $tn = "vm-$vmid-disk-$i";
145 if (!defined ($rdb->{$rbdpool}->{$tn})) {
152 die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
155 my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{username
}, '--keyfile','/etc/pve/priv/ceph/'.$storeid.'.'.$scfg->{username
}.'.key','--auth_supported', $scfg->{authsupported
}, 'create', '--size', ($size/1024), $name ];
156 run_command
($cmd, errmsg
=> "rbd create $name' error");
162 my ($class, $storeid, $scfg, $volname) = @_;
164 my $rbdpool = $scfg->{pool
};
165 my $monhost = $scfg->{monhost
};
168 my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{username
}, '--keyfile','/etc/pve/priv/ceph/'.$storeid.'.'.$scfg->{username
}.'.key','--auth_supported',$scfg->{authsupported
}, 'rm', $volname ];
169 run_command
($cmd, errmsg
=> "rbd rm $volname' error");
175 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
177 $cache->{rbd
} = rbd_ls
($scfg, $storeid) if !$cache->{rbd
};
178 my $rbdpool = $scfg->{pool
};
181 if (my $dat = $cache->{rbd
}->{$rbdpool}) {
182 foreach my $image (keys %$dat) {
184 my $volname = $dat->{$image}->{name
};
186 my $volid = "$storeid:$volname";
189 my $owner = $dat->{$volname}->{vmid
};
191 my $found = grep { $_ eq $volid } @$vollist;
194 next if defined ($vmid) && ($owner ne $vmid);
197 my $info = $dat->{$volname};
198 $info->{volid
} = $volid;
209 my ($class, $storeid, $scfg, $cache) = @_;
215 return ($total,$free,$used,$active);
220 sub activate_storage
{
221 my ($class, $storeid, $scfg, $cache) = @_;
225 sub deactivate_storage
{
226 my ($class, $storeid, $scfg, $cache) = @_;
230 sub activate_volume
{
231 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
235 sub deactivate_volume
{
236 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;