]> git.proxmox.com Git - librados2-perl.git/blobdiff - PVE/RADOS.pm
allow to specify the userid with rados_create
[librados2-perl.git] / PVE / RADOS.pm
index 86c0df667683b424437006d2b7aca0bc37348f4e..d53f655a9646b62fa31d51bc2af67644eea28b22 100644 (file)
@@ -13,6 +13,8 @@ use PVE::RPCEnvironment;
 require Exporter;
 
 my $rados_default_timeout = 5;
+my $ceph_default_conf = '/etc/ceph/ceph.conf';
+my $ceph_default_user = 'admin';
 
 
 our @ISA = qw(Exporter);
@@ -43,7 +45,7 @@ my $writedata = sub {
     my ($fh, $cmd, $data) = @_;
 
     local $SIG{PIPE} = 'IGNORE';
+
     my $bin = pack "a L/a*", $cmd, $data || '';
     my $res = syswrite $fh, $bin;
 
@@ -63,7 +65,7 @@ my $readdata = sub {
     return undef if $allow_eof && length($head) == 0;
 
     die "partial read\n" if length($head) < 5;
-    
+
     my ($cmd, $len) = unpack "a L", $head;
 
     my $data = '';
@@ -86,7 +88,7 @@ my $kill_worker = sub {
     close($self->{child}) if defined($self->{child});
 
     # only kill if we created the process
-    return if $self->{pid} != $$; 
+    return if $self->{pid} != $$;
 
     kill(9, $self->{cpid});
     waitpid($self->{cpid}, 0);
@@ -140,7 +142,7 @@ sub new {
 
     if ($cpid) { # parent
        close $parent;
+
        $self->{cpid} = $cpid;
        $self->{child} = $child;
 
@@ -161,9 +163,20 @@ sub new {
 
        my $conn;
        eval {
-           $conn = pve_rados_create() ||
+           my $ceph_user = delete $params{userid} || $ceph_default_user;
+           $conn = pve_rados_create($ceph_user) ||
                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) {
@@ -182,7 +195,7 @@ sub new {
 
        for (;;) {
            my ($cmd, $data) = &$readdata($parent, 1);
-           
+
            last if !$cmd || $cmd eq 'Q';
 
            my $res;
@@ -203,13 +216,21 @@ sub new {
            }
            &$writedata($parent, '>', $res);
        }
+
        exit(0);
     }
 
     return $self;
 }
 
+sub timeout {
+    my ($self, $new_timeout) = @_;
+
+    $self->{timeout} = $new_timeout if $new_timeout;
+
+    return $self->{timeout};
+}
+
 sub DESTROY {
     my ($self) = @_;