1--
2-- This file and its contents are supplied under the terms of the
3-- Common Development and Distribution License ("CDDL"), version 1.0.
4-- You may only use this file in accordance with the terms of version
5-- 1.0 of the CDDL.
6--
7-- A full copy of the text of the CDDL should have accompanied this
8-- source.  A copy of the CDDL is also available via the Internet at
9-- http://www.illumos.org/license/CDDL.
10--
11
12--
13-- Copyright (c) 2016 by Delphix. All rights reserved.
14--
15
16arg = ...
17fs = arg["argv"][1]
18snap = arg["argv"][2]
19vol = arg["argv"][3]
20
21props = {}
22
23-- The values indicate whether or not a property should be returned,
24-- not the value of the property. A better approach might be to compare
25-- their values to the output of 'zfs get <prop>'
26
27-- prop                          filesystem         snapshot     volume
28props['used']                 = {{true,       nil}, {true, nil}, {true,       nil}}
29props['available']            = {{true,       nil}, {nil,  nil}, {true,       nil}}
30props['referenced']           = {{true,       nil}, {true, nil}, {true,       nil}}
31props['compressratio']        = {{true,       nil}, {true, nil}, {true,       nil}}
32props['refcompressratio']     = {{true,       nil}, {true, nil}, {true,       nil}}
33props['volblocksize']         = {{nil,        nil}, {nil,  nil}, {true,       nil}}
34props['usedbysnapshots']      = {{true,       nil}, {nil,  nil}, {true,       nil}}
35props['usedbydataset']        = {{true,       nil}, {nil,  nil}, {true,       nil}}
36props['usedbychildren']       = {{true,       nil}, {nil,  nil}, {true,       nil}}
37props['usedbyrefreservation'] = {{true,       nil}, {nil,  nil}, {true,       nil}}
38props['userrefs']             = {{nil,        nil}, {true, nil}, {nil,        nil}}
39props['written']              = {{true,       nil}, {true, nil}, {true,       nil}}
40props['logicalused']          = {{true,       nil}, {nil,  nil}, {true,       nil}}
41props['logicalreferenced']    = {{true,       nil}, {true, nil}, {true,       nil}}
42props['quota']                = {{true, 'default'}, {nil,  nil}, {nil,        nil}}
43props['reservation']          = {{true, 'default'}, {nil,  nil}, {true, 'default'}}
44props['volsize']              = {{nil,        nil}, {nil,  nil}, {true,       vol}}
45props['refquota']             = {{true, 'default'}, {nil,  nil}, {nil,        nil}}
46props['refreservation']       = {{true, 'default'}, {nil,  nil}, {true,       vol}}
47props['filesystem_limit']     = {{true,        fs}, {nil,  nil}, {nil,        nil}}
48props['snapshot_limit']       = {{true,        fs}, {nil,  nil}, {true,       vol}}
49props['filesystem_count']     = {{true,       nil}, {nil,  nil}, {nil,        nil}}
50props['snapshot_count']       = {{true,       nil}, {nil,  nil}, {true,       nil}}
51props['recordsize']           = {{true, 'default'}, {nil,  nil}, {nil,        nil}}
52props['creation']             = {{true,       nil}, {true, nil}, {true,       nil}}
53-- hidden props
54props['createtxg']            = {{true,       nil}, {true, nil}, {true,       nil}}
55props['numclones']            = {{nil,        nil}, {true, nil}, {nil,        nil}}
56props['guid']                 = {{true,       nil}, {true, nil}, {true,       nil}}
57props['useraccounting']       = {{true,       nil}, {true, nil}, {true,       nil}}
58props['unique']               = {{true,       nil}, {true, nil}, {true,       nil}}
59props['objsetid']             = {{true,       nil}, {true, nil}, {true,       nil}}
60props['inconsistent']         = {{true,       nil}, {true, nil}, {true,       nil}}
61
62
63fs_fails = {}
64snap_fails = {}
65vol_fails = {}
66
67function match(n, ans, src, expected)
68    if ((expected[n][1] == nil) and (ans ~= nil)) then
69        return false
70    end
71
72    if ((expected[n][1] == true) and (ans == nil)) then
73        return false
74    end
75
76    if (expected[n][2] ~= src) then
77        return false
78    end
79
80    return true
81end
82
83for prop, expected in pairs(props) do
84	ans, src = zfs.get_prop(fs, prop)
85	if not (match(1, ans, src, expected)) then
86		fs_fails[prop] = {ans, src}
87	end
88
89        ans, src = zfs.get_prop(snap, prop)
90	if not (match(2, ans, src, expected)) then
91		snap_fails[prop] = {ans, src}
92	end
93
94	ans, src = zfs.get_prop(vol, prop)
95	if not (match(3, ans, src, expected)) then
96		vol_fails[prop] = {ans, src}
97	end
98end
99
100return {fs_fails, snap_fails, vol_fails}
101