]>
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);
16 my $rbdpool = $scfg->{rbd_pool
};
17 my $monhost = $scfg->{rbd_monhost
};
20 my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{rbd_id
} ,'--key',$scfg->{rbd_key
} ,'ls' ];
22 run_command
($cmd, errfunc
=> sub {},outfunc
=> sub {
28 $list->{$rbdpool}->{$image} = {
49 PVE
::JSONSchema
::register_format
('pve-storage-rbd-mon', \
&parse_rbd_mon
);
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
=> "RBD Pool.",
83 description
=> "RBD Id.",
87 description
=> "Key.",
90 rbd_authsupported
=> {
91 description
=> "Authsupported.",
99 rbd_monhost
=> { fixed
=> 1 },
100 rbd_pool
=> { fixed
=> 1 },
101 rbd_id
=> { fixed
=> 1 },
102 rbd_key
=> { fixed
=> 1 },
103 rbd_authsupported
=> { fixed
=> 1 },
104 content
=> { optional
=> 1 },
108 # Storage implementation
111 my ($class, $volname) = @_;
113 if ($volname =~ m/^(vm-(\d+)-\S+)$/) {
114 return ('images', $1, $2);
117 die "unable to parse rbd volume name '$volname'\n";
121 my ($class, $scfg, $volname) = @_;
123 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
125 my $monhost = addslashes
($scfg->{rbd_monhost
});
126 my $pool = $scfg->{rbd_pool
};
127 my $id = $scfg->{rbd_id
};
128 my $key = $scfg->{rbd_key
};
129 my $authsupported = addslashes
($scfg->{rbd_authsupported
});
131 my $path = "rbd:$pool/$name:id=$id:key=$key:auth_supported=$authsupported:mon_host=$monhost";
133 return ($path, $vmid, $vtype);
137 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
140 die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
141 if $name && $name !~ m/^vm-$vmid-/;
142 my $rbdpool = $scfg->{rbd_pool
};
143 my $monhost = $scfg->{rbd_monhost
};
147 my $rdb = rbd_ls
($scfg);
149 for (my $i = 1; $i < 100; $i++) {
150 my $tn = "vm-$vmid-disk-$i";
151 if (!defined ($rdb->{$rbdpool}->{$tn})) {
158 die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
161 my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{rbd_id
}, '--key', $scfg->{rbd_key
}, 'create', '--size', ($size/1024), $name ];
162 run_command
($cmd, errmsg
=> "rbd create $name' error");
168 my ($class, $storeid, $scfg, $volname) = @_;
170 my $rbdpool = $scfg->{rbd_pool
};
171 my $monhost = $scfg->{rbd_monhost
};
174 my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{rbd_id
}, '--key',$scfg->{rbd_key
}, 'rm', $volname ];
175 run_command
($cmd, errmsg
=> "rbd rm $volname' error");
181 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
183 $cache->{rbd
} = rbd_ls
($scfg) if !$cache->{rbd
};
184 my $rbdpool = $scfg->{rbd_pool
};
187 if (my $dat = $cache->{rbd
}->{$rbdpool}) {
188 foreach my $image (keys %$dat) {
190 my $volname = $dat->{$image}->{name
};
192 my $volid = "$storeid:$volname";
195 my $owner = $dat->{$volname}->{vmid
};
197 my $found = grep { $_ eq $volid } @$vollist;
200 next if defined ($vmid) && ($owner ne $vmid);
203 my $info = $dat->{$volname};
204 $info->{volid
} = $volid;
215 my ($class, $storeid, $scfg, $cache) = @_;
222 return ($total,$free,$used,$active);
227 sub activate_storage
{
228 my ($class, $storeid, $scfg, $cache) = @_;
232 sub deactivate_storage
{
233 my ($class, $storeid, $scfg, $cache) = @_;
237 sub activate_volume
{
238 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
242 sub deactivate_volume
{
243 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;