Esempio n. 1
0
 /**
  * @param string $path
  * @param string $mode
  * @param int $options
  * @param string $opened_path
  * @return bool
  * @throws IOException
  */
 public function stream_open($path, $mode, $options, &$opened_path)
 {
     $ret = $this->rados = \rados_create();
     if (!$ret) {
         throw new IOException('Could not create rados resource');
     }
     $configPath = '/etc/ceph/ceph.conf';
     $ret = \rados_conf_read_file($this->rados, $configPath);
     if (!$ret) {
         throw new IOException("Could not read config from {$configPath}");
     }
     $ret = \rados_connect($this->rados);
     if (!$ret) {
         throw new IOException('Could not connect to rados');
     }
     $id = \rados_pool_lookup($this->rados, $this->pool);
     //TODO make autocreation configurable
     if ($id < 0) {
         $ret = \rados_pool_create($this->rados, $this->pool);
         if ($ret < 0) {
             throw new IOException("Could not create pool '{$this->pool}'");
         }
     }
     $this->ioctx = \rados_ioctx_create($this->rados, $this->pool);
     if (!$this->ioctx) {
         throw new IOException("Could not create io context before reading object {$path}");
     }
     $oid = $this->path2oid($path);
     $this->stat = \rados_stat($this->ioctx, $oid);
     switch ($mode[0]) {
         case 'r':
             if (!$this->stat) {
                 return false;
             }
             $this->writable = isset($mode[1]) && $mode[1] == '+';
             break;
         case 'a':
             if ($this->stat && $this->stat['psize']) {
                 $this->pos = $this->stat['psize'];
             }
             break;
         case 'x':
             if (!$this->stat) {
                 return false;
             }
             break;
         case 'w':
         case 'c':
             if (!$this->stat) {
                 $this->stat = ['psize' => 0, 'oid' => $oid];
             }
             break;
         default:
             return false;
     }
     return true;
 }
Esempio n. 2
0
 public function testRadosConnect()
 {
     $cluster = rados_create(getenv('id'));
     $this->assertNotNull($cluster);
     rados_conf_set($cluster, "mon_host", getenv('mon_host'));
     rados_conf_set($cluster, "key", getenv('key'));
     $this->assertTrue(rados_connect($cluster));
     return $cluster;
 }
Esempio n. 3
0
<?php

$rados = rados_create();
rados_conf_read_file($rados, "/etc/ceph/ceph.conf");
rados_connect($rados);
$io = rados_ioctx_create($rados, "rbd");
var_dump(rados_ioctx_pool_stat($io));
rados_ioctx_destroy($io);
rados_shutdown($rados);
Esempio n. 4
0
 /**
  * 
  * @return self
  */
 public function connect()
 {
     \rados_connect($this->_cluster);
     return $this;
 }