my sub get_rbd_path {
my ($scfg, $volume) = @_;
- my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
- my $namespace = $scfg->{namespace};
-
- return "${pool}/${namespace}/${volume}" if defined($namespace);
- return "${pool}/${volume}";
+ my $path = $scfg->{pool} ? $scfg->{pool} : 'rbd';
+ $path .= "/$scfg->{namespace}" if defined($scfg->{namespace});
+ $path .= "/$volume" if defined($volume);
+ return $path;
};
my $build_cmd = sub {
*STDERR->flush();
};
}
-
+
eval { run_command($cmd, %args); };
if (my $err = $@) {
die $errmsg . $lasterr if length($lasterr);
description => "Pool.",
type => 'string',
},
- namespace=> {
+ namespace => {
description => "RBD Namespace.",
type => 'string',
},
description => "Always access rbd through krbd kernel module.",
type => 'boolean',
},
+ keyring => {
+ description => "Client keyring contents (for external clusters).",
+ type => 'string',
+ },
};
}
username => { optional => 1 },
content => { optional => 1 },
krbd => { optional => 1 },
+ keyring => { optional => 1 },
bwlimit => { optional => 1 },
};
}
sub on_add_hook {
my ($class, $storeid, $scfg, %param) = @_;
- return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
+ my $secret = $param{keyring} if defined $param{keyring} // undef;
+ PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid, $secret);
- PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid);
+ return;
+}
+
+sub on_update_hook {
+ my ($class, $storeid, $scfg, %param) = @_;
+
+ if (exists($param{keyring})) {
+ if (defined($param{keyring})) {
+ PVE::CephConfig::ceph_create_keyfile($scfg->{type}, $storeid, $param{keyring});
+ } else {
+ PVE::CephConfig::ceph_remove_keyfile($scfg->{type}, $storeid);
+ }
+ }
return;
}
sub on_delete_hook {
my ($class, $storeid, $scfg) = @_;
-
- return if defined($scfg->{monhost}); # nothing to do if not pve managed ceph
-
PVE::CephConfig::ceph_remove_keyfile($scfg->{type}, $storeid);
-
return;
}
$name = $class->find_free_diskname($storeid, $scfg, $vmid) if !$name;
my $cmd = $rbd_cmd->($scfg, $storeid, 'create', '--image-format' , 2, '--size', int(($size+1023)/1024), $name);
- run_rbd_command($cmd, errmsg => "rbd create $name' error");
+ run_rbd_command($cmd, errmsg => "rbd create '$name' error");
return $name;
}
my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
$cache->{rbd} = rbd_ls($scfg, $storeid) if !$cache->{rbd};
- my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
- $pool .= "/$scfg->{namespace}" if defined($scfg->{namespace});
- my $res = [];
-
- if (my $dat = $cache->{rbd}->{$pool}) {
- foreach my $image (keys %$dat) {
-
- my $info = $dat->{$image};
+ my $dat = $cache->{rbd}->{get_rbd_path($scfg)};
+ return [] if !$dat; # nothing found
- my $volname = $info->{name};
- my $parent = $info->{parent};
- my $owner = $info->{vmid};
-
- if ($parent && $parent =~ m/^(base-\d+-\S+)\@__base__$/) {
- $info->{volid} = "$storeid:$1/$volname";
- } else {
- $info->{volid} = "$storeid:$volname";
- }
+ my $res = [];
+ for my $image (sort keys %$dat) {
+ my $info = $dat->{$image};
+ my ($volname, $parent, $owner) = $info->@{'name', 'parent', 'vmid'};
+
+ if ($parent && $parent =~ m/^(base-\d+-\S+)\@__base__$/) {
+ $info->{volid} = "$storeid:$1/$volname";
+ } else {
+ $info->{volid} = "$storeid:$volname";
+ }
- if ($vollist) {
- my $found = grep { $_ eq $info->{volid} } @$vollist;
- next if !$found;
- } else {
- next if defined ($vmid) && ($owner ne $vmid);
- }
+ if ($vollist) {
+ my $found = grep { $_ eq $info->{volid} } @$vollist;
+ next if !$found;
+ } else {
+ next if defined ($vmid) && ($owner ne $vmid);
+ }
- $info->{format} = 'raw';
+ $info->{format} = 'raw';
- push @$res, $info;
- }
+ push @$res, $info;
}
-
+
return $res;
}
}
sub volume_snapshot_needs_fsfreeze {
-
return 1;
}
sparseinit => { base => 1, current => 1},
};
- my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
- $class->parse_volname($volname);
+ my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) = $class->parse_volname($volname);
my $key = undef;
- if($snapname){
+ if ($snapname){
$key = 'snap';
- }else{
- $key = $isBase ? 'base' : 'current';
+ } else {
+ $key = $isBase ? 'base' : 'current';
}
return 1 if $features->{$feature}->{$key};