Permalink
Browse files

Do not use uncommon zfs list -p (fixes #1).

zfs list -p is super nice but not implemented in the Oracle builds.
  • Loading branch information...
1 parent f2ee207 commit 3fd54858a062f71f658811b5bd0871e52a06f6c8 @calmh committed May 17, 2012
Showing with 73 additions and 44 deletions.
  1. +26 −4 lib/zfs.js
  2. +8 −6 test/zfs
  3. +39 −34 test/zfs.js
View
@@ -36,6 +36,28 @@ function zfs(args, callback) {
});
}
+function parseNumber(str) {
+ var m = str.match(/^([0-9.]+)([KMGT]?)$/);
+ if (!m) {
+ return -1;
+ }
+
+ var n = parseFloat(m[1]);
+ if (m[2] === 'K') {
+ n *= 1024;
+ } else if (m[2] === 'M') {
+ n *= 1024 * 1024;
+ } else if (m[2] === 'G') {
+ n *= 1024 * 1024 * 1024;
+ } else if (m[2] === 'T') {
+ n *= 1024 * 1024 * 1024 * 1024;
+ } else if (m[2] === 'P') {
+ n *= 1024 * 1024 * 1024 * 1024 * 1024;
+ }
+
+ return Math.floor(n);
+}
+
function ZFS(info) {
"use strict";
@@ -49,11 +71,11 @@ function ZFS(info) {
}
obj.name = info[0];
- obj.used = parseInt(info[1], 10);
+ obj.used = parseNumber(info[1]);
if (info[2] !== '-') { // Snapshots don't have 'avail' field.
- obj.avail = parseInt(info[2], 10);
+ obj.avail = parseNumber(info[2]);
}
- obj.refer = parseInt(info[3], 10);
+ obj.refer = parseNumber(info[3]);
obj.mountpoint = info[4];
Object.freeze(obj);
@@ -89,7 +111,7 @@ function list(opts, cb) {
opts = undefined;
}
- var params = ['list', '-pH'];
+ var params = ['list', '-H'];
if (opts && opts.type) {
params.push('-t');
View
@@ -2,17 +2,19 @@
function listFs {
cat <<EOD
-zones 1004799731712 956926580736 328704 /zones
-zones/f78f9208-9c26-47f7-9e03-881a96d17c04 590843904 10146574336 694054400 /zones/f78f9208-9c26-47f7-9e03-881a96d17c04
-zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data 73728 10146574336 31744 /data
+zones 947G 880G 321K /zones
+zones/37a67136-6cdf-4f65-add2-85e4fce60d63 664M 9.35G 664M /zones/37a67136-6cdf-4f65-add2-85e4fce60d63
+zones/37a67136-6cdf-4f65-add2-85e4fce60d63-disk0 1.40G 880G 1.04G -
+zones/37a67136-6cdf-4f65-add2-85e4fce60d63/cores 31K 2.25G 31K /zones/37a67136-6cdf-4f65-add2-85e4fce60d63/cores
+zones/39a4f744-85cf-416c-ad37-1b933f9e7b13 152K 10.0G 122K /zones/39a4f744-85cf-416c-ad37-1b933f9e7b13
EOD
}
function listSnaps {
cat << EOD
-zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120430 1024 - 32768 -
-zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120501 1024 - 32768 -
-zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120502 1024 - 32768 -
+zones/var@daily-20120516T043000Z 134K - 2.69M -
+zones/var@hourly-20120516T160000Z 38.5K - 2.70M -
+zones/var@hourly-20120516T170000Z 38.5K - 2.70M -
EOD
}
View
@@ -9,24 +9,34 @@ describe('zfs', function () {
it('returns a list of ZFS filesystems', function (done) {
var expected = [ {
name: 'zones',
- used: 1004799731712,
- avail: 956926580736,
+ used: 1016833507328,
+ avail: 944892805120,
refer: 328704,
mountpoint: '/zones'
- },
- {
- name: 'zones/f78f9208-9c26-47f7-9e03-881a96d17c04',
- used: 590843904,
- avail: 10146574336,
- refer: 694054400,
- mountpoint: '/zones/f78f9208-9c26-47f7-9e03-881a96d17c04'
- },
- {
- name: 'zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data',
- used: 73728,
- avail: 10146574336,
+ }, {
+ name: 'zones/37a67136-6cdf-4f65-add2-85e4fce60d63',
+ used: 696254464,
+ avail: 10039486054,
+ refer: 696254464,
+ mountpoint: '/zones/37a67136-6cdf-4f65-add2-85e4fce60d63'
+ }, {
+ name: 'zones/37a67136-6cdf-4f65-add2-85e4fce60d63-disk0',
+ used: 1503238553,
+ avail: 944892805120,
+ refer: 1116691496,
+ mountpoint: '-'
+ }, {
+ name: 'zones/37a67136-6cdf-4f65-add2-85e4fce60d63/cores',
+ used: 31744,
+ avail: 2415919104,
refer: 31744,
- mountpoint: '/data'
+ mountpoint: '/zones/37a67136-6cdf-4f65-add2-85e4fce60d63/cores'
+ }, {
+ name: 'zones/39a4f744-85cf-416c-ad37-1b933f9e7b13',
+ used: 155648,
+ avail: 10737418240,
+ refer: 124928,
+ mountpoint: '/zones/39a4f744-85cf-416c-ad37-1b933f9e7b13'
} ];
zfs.list(function (err, list) {
should.not.exist(err);
@@ -36,21 +46,19 @@ describe('zfs', function () {
});
it('returns a list of ZFS snapshots', function (done) {
var expected = [ {
- name: 'zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120430',
- used: 1024,
- refer: 32768,
+ name: 'zones/var@daily-20120516T043000Z',
+ used: 137216,
+ refer: 2820669,
mountpoint: '-'
- },
- {
- name: 'zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120501',
- used: 1024,
- refer: 32768,
+ }, {
+ name: 'zones/var@hourly-20120516T160000Z',
+ used: 39424,
+ refer: 2831155,
mountpoint: '-'
- },
- {
- name: 'zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120502',
- used: 1024,
- refer: 32768,
+ }, {
+ name: 'zones/var@hourly-20120516T170000Z',
+ used: 39424,
+ refer: 2831155,
mountpoint: '-'
} ];
zfs.list({ type: 'snapshot' }, function (err, list) {
@@ -67,20 +75,17 @@ describe('zfs', function () {
property: 'compression',
value: 'on',
source: 'local'
- },
- {
+ }, {
name: 'zones/f78f9208-9c26-47f7-9e03-881a96d17c04',
property: 'compression',
value: 'on',
source: 'inherited'
- },
- {
+ }, {
name: 'zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data',
property: 'compression',
value: 'on',
source: 'inherited'
- },
- {
+ }, {
name: 'zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120430',
property: 'compression',
value: '-',

0 comments on commit 3fd5485

Please sign in to comment.