]>
git.datanom.net - omvzfs.git/blob - src/Zvol.php
4 * XXX detailed description
10 class OMVModuleZFSZvol
{
30 * Mountpoint of the Zvol
32 * @var string $mountPoint
38 * Array with properties assigned to the Zvol
40 * @var array $properties
49 * Constructor. If the Zvol already exists in the system the object will be updated with all
50 * associated properties from commandline.
52 * @param string $name Name of the new Zvol
56 public function __construct($name) {
58 $qname = preg_quote($name, '/');
59 $cmd = "zfs list -H -t volume";
60 $this->exec($cmd, $out, $res);
61 foreach ($out as $line) {
62 if (preg_match('/^' . $qname . '\t.*$/', $line)) {
63 $this->updateAllProperties();
64 $this->mountPoint
= $this->properties
["mountpoint"]["value"];
65 $this->size
= $this->properties
["size"]["value"];
72 * Return name of the Zvol
74 * @return string $name
77 public function getName() {
82 * Get the mountpoint of the Zvol
84 * @return string $mountPoint
87 public function getMountPoint() {
88 return $this->mountPoint
;
92 * Get a single property value associated with the Zvol
94 * @param string $property Name of the property to fetch
95 * @return array The returned array with the property. The property is an associative array with
96 * two elements, <value> and <source>.
99 public function getProperty($property) {
100 return $this->properties
["$property"];
104 * Get an associative array of all properties associated with the Zvol
106 * @return array $properties Each entry is an associative array with two elements
107 * <value> and <source>
110 public function getProperties() {
111 return $this->properties
;
121 public function getSize() {
122 trigger_error('Not Implemented!', E_USER_WARNING
);
128 * @param $list<Feature> XXX
132 public function setProperties($properties) {
133 trigger_error('Not Implemented!', E_USER_WARNING
);
137 * Get all Zvol properties from commandline and update object properties attribute
142 private function updateAllProperties() {
143 $cmd = "zfs get -H all " . $this->name
;
144 $this->exec($cmd,$out,$res);
145 unset($this->properties
);
146 foreach ($out as $line) {
147 $tmpary = preg_split('/\t+/', $line);
148 $this->properties
["$tmpary[1]"] = array("value" => $tmpary[2], "source" => $tmpary[3]);
153 * Helper function to execute a command and throw an exception on error
154 * (requires stderr redirected to stdout for proper exception message).
156 * @param string $cmd Command to execute
157 * @param array &$out If provided will contain output in an array
158 * @param int &$res If provided will contain Exit status of the command
159 * @return string Last line of output when executing the command
160 * @throws OMVModuleZFSException
163 private function exec($cmd, &$out = null, &$res = null) {
164 $tmp = OMVUtil
::exec($cmd, $out, $res);
166 throw new OMVModuleZFSException(implode("\n", $out));
This page took 0.079312 seconds and 6 git commands to generate.