Example #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;
 }
Example #2
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);
Example #3
0
<?php

$rados = rados_create();
rados_conf_read_file($rados, '/etc/ceph/ceph.conf');
rados_connect($rados);
foreach (rados_pool_list($rados) as $pool) {
    echo $pool . "\n";
}
rados_shutdown($rados);
Example #4
0
 /**
  * 
  * @param string $fileName
  * @return self
  */
 public function readConfig($fileName)
 {
     \rados_conf_read_file($this->_cluster, $fileName);
     return $this;
 }