/** * @depends testRadosCreatePool */ public function testRadosPoolLookup($cluster) { $pool = getenv('pool'); $id = rados_pool_lookup($cluster, $pool); $this->assertGreaterThanOrEqual(0, $id); $info['cluster'] = $cluster; $info['id'] = $id; $info['pool'] = getenv('pool'); return $info; }
<?php $rados = rados_create(); rados_conf_read_file($rados, "/etc/ceph/ceph.conf"); rados_connect($rados); var_dump(rados_pool_lookup($rados, "rbd")); var_dump(rados_pool_reverse_lookup($rados, 36)); rados_shutdown($rados);
/** * @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; }