[pve-devel] [PATCH v2 librados2-perl 2/3] Split method pve_rados_connect
Alwin Antreich
a.antreich at proxmox.com
Thu Apr 5 10:41:35 CEST 2018
To be able to connect through librados2 without a config file, the
method pve_rados_connect is split up into pve_rados_connect and
pve_rados_conf_read_file.
Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
PVE/RADOS.pm | 11 +++++++++++
RADOS.xs | 26 +++++++++++++++++++++-----
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/PVE/RADOS.pm b/PVE/RADOS.pm
index aff8141..2ed92b7 100644
--- a/PVE/RADOS.pm
+++ b/PVE/RADOS.pm
@@ -13,6 +13,7 @@ use PVE::RPCEnvironment;
require Exporter;
my $rados_default_timeout = 5;
+my $ceph_default_conf = '/etc/ceph/ceph.conf';
our @ISA = qw(Exporter);
@@ -164,6 +165,16 @@ sub new {
$conn = pve_rados_create() ||
die "unable to create RADOS object\n";
+ if (defined($params{ceph_conf}) && (!-e $params{ceph_conf})) {
+ die "Supplied ceph config doesn't exist, $params{ceph_conf}";
+ }
+
+ my $ceph_conf = delete $params{ceph_conf} || $ceph_default_conf;
+
+ if (-e $ceph_conf) {
+ pve_rados_conf_read_file($conn, $ceph_conf);
+ }
+
pve_rados_conf_set($conn, 'client_mount_timeout', $timeout);
foreach my $k (keys %params) {
diff --git a/RADOS.xs b/RADOS.xs
index 66fa65a..ad3cf96 100644
--- a/RADOS.xs
+++ b/RADOS.xs
@@ -47,19 +47,35 @@ CODE:
}
void
-pve_rados_connect(cluster)
+pve_rados_conf_read_file(cluster, path)
rados_t cluster
-PROTOTYPE: $
+SV *path
+PROTOTYPE: $$
CODE:
{
- DPRINTF("pve_rados_connect\n");
+ char *p = NULL;
- int res = rados_conf_read_file(cluster, NULL);
+ if (SvOK(path)) {
+ p = SvPV_nolen(path);
+ }
+
+ DPRINTF("pve_rados_conf_read_file %s\n", p);
+
+ int res = rados_conf_read_file(cluster, p);
if (res < 0) {
die("rados_conf_read_file failed - %s\n", strerror(-res));
}
+}
+
+void
+pve_rados_connect(cluster)
+rados_t cluster
+PROTOTYPE: $
+CODE:
+{
+ DPRINTF("pve_rados_connect\n");
- res = rados_connect(cluster);
+ int res = rados_connect(cluster);
if (res < 0) {
die("rados_connect failed - %s\n", strerror(-res));
}
--
2.11.0
More information about the pve-devel
mailing list