Skip to content

Commit d51c99b

Browse files
Matt Macymalbertoni
authored andcommitted
Add FreeBSD support to ZoL
1 parent df358db commit d51c99b

File tree

707 files changed

+105431
-2004
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

707 files changed

+105431
-2004
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,13 @@ cscope.*
6363
*.log
6464
venv
6565

66+
*.so
67+
*.so.debug
68+
*.so.full
69+
*.tmp
70+
*.log
71+
module/export_syms
72+
module/machine
73+
module/x86
74+
module/zfs.ko.debug
75+
module/zfs.ko.full

Makefile.am

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,28 @@ include config/rpm.am
44
include config/deb.am
55
include config/tgz.am
66

7-
SUBDIRS = include rpm
7+
SUBDIRS = include
8+
if BUILD_LINUX
9+
SUBDIRS+= rpm
10+
endif
11+
812
if CONFIG_USER
9-
SUBDIRS += udev etc man scripts lib tests cmd contrib
13+
SUBDIRS += etc man scripts lib tests cmd contrib
14+
if BUILD_LINUX
15+
SUBDIRS+= udev
16+
endif
1017
endif
1118
if CONFIG_KERNEL
1219
SUBDIRS += module
1320

1421
extradir = $(prefix)/src/zfs-$(VERSION)
1522
extra_HEADERS = zfs.release.in zfs_config.h.in
1623

24+
if BUILD_LINUX
1725
kerneldir = $(prefix)/src/zfs-$(VERSION)/$(LINUX_VERSION)
1826
nodist_kernel_HEADERS = zfs.release zfs_config.h module/$(LINUX_SYMBOLS)
1927
endif
28+
endif
2029

2130
AUTOMAKE_OPTIONS = foreign
2231
EXTRA_DIST = autogen.sh copy-builtin
@@ -60,6 +69,7 @@ dist-hook: gitrev
6069
sed -i 's/Release:[[:print:]]*/Release: $(RELEASE)/' \
6170
$(distdir)/META
6271

72+
if BUILD_LINUX
6373
# For compatibility, create a matching spl-x.y.z directly which contains
6474
# symlinks to the updated header and object file locations. These
6575
# compatibility links will be removed in the next major release.
@@ -76,6 +86,7 @@ install-data-hook:
7686
ln -fs zfs_config.h spl_config.h && \
7787
ln -fs zfs.release spl.release
7888
endif
89+
endif
7990

8091
codecheck: cstyle shellcheck flake8 mancheck testscheck vcscheck
8192

cmd/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ if USING_PYTHON
55
SUBDIRS += arcstat arc_summary dbufstat
66
endif
77

8+
if BUILD_LINUX
89
SUBDIRS += mount_zfs zed zvol_id
10+
endif

cmd/arc_summary/Makefile.am

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
EXTRA_DIST = arc_summary2 arc_summary3
22

3+
transform = $(program_transform_name)
4+
35
if USING_PYTHON_2
46
dist_bin_SCRIPTS = arc_summary2
57
install-exec-hook:
6-
mv $(DESTDIR)$(bindir)/arc_summary2 $(DESTDIR)$(bindir)/arc_summary
8+
before=$$(echo arc_summary2 | sed '$(transform)'); \
9+
after=$$(echo arc_summary | sed '$(transform)'); \
10+
mv "$(DESTDIR)$(bindir)/$$before" "$(DESTDIR)$(bindir)/$$after"
711
else
812
dist_bin_SCRIPTS = arc_summary3
913
install-exec-hook:
10-
mv $(DESTDIR)$(bindir)/arc_summary3 $(DESTDIR)$(bindir)/arc_summary
14+
before=$$(echo arc_summary3 | sed '$(transform)'); \
15+
after=$$(echo arc_summary | sed '$(transform)'); \
16+
mv "$(DESTDIR)$(bindir)/$$before" "$(DESTDIR)$(bindir)/$$after"
1117
endif

cmd/arc_summary/arc_summary2

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ import errno
5454
from subprocess import Popen, PIPE
5555
from decimal import Decimal as D
5656

57+
#Requires py27-sysctl on FreeBSD
58+
if sys.platform.startswith('freebsd'):
59+
import sysctl
60+
5761
show_tunable_descriptions = False
5862
alternate_tunable_layout = False
5963

@@ -79,12 +83,18 @@ def get_Kstat():
7983
def load_proc_kstats(fn, namespace):
8084
"""Collect information on a specific subsystem of the ARC"""
8185

82-
kstats = [line.strip() for line in open(fn)]
83-
del kstats[0:2]
84-
for kstat in kstats:
85-
kstat = kstat.strip()
86-
name, _, value = kstat.split()
87-
Kstat[namespace + name] = D(value)
86+
if sys.platform.startswith('freebsd'):
87+
kstats = sysctl.filter(namespace)
88+
for kstat in kstats:
89+
name, value = kstat.name, kstat.value
90+
Kstat[name] = D(value)
91+
else:
92+
kstats = [line.strip() for line in open(fn)]
93+
del kstats[0:2]
94+
for kstat in kstats:
95+
kstat = kstat.strip()
96+
name, _, value = kstat.split()
97+
Kstat[namespace + name] = D(value)
8898

8999
Kstat = {}
90100
load_proc_kstats('/proc/spl/kstat/zfs/arcstats',
@@ -921,13 +931,16 @@ def _tunable_summary(Kstat):
921931
global show_tunable_descriptions
922932
global alternate_tunable_layout
923933

924-
names = os.listdir("/sys/module/zfs/parameters/")
934+
if sys.platform.startswith('freebsd'):
935+
ctls = sysctl.filter('vfs.zfs')
936+
else:
937+
names = os.listdir("/sys/module/zfs/parameters/")
925938

926-
values = {}
927-
for name in names:
928-
with open("/sys/module/zfs/parameters/" + name) as f:
929-
value = f.read()
930-
values[name] = value.strip()
939+
values = {}
940+
for name in names:
941+
with open("/sys/module/zfs/parameters/" + name) as f:
942+
value = f.read()
943+
values[name] = value.strip()
931944

932945
descriptions = {}
933946

@@ -966,22 +979,31 @@ def _tunable_summary(Kstat):
966979
sys.stderr.write("Tunable descriptions will be disabled.\n")
967980

968981
sys.stdout.write("ZFS Tunables:\n")
969-
names.sort()
982+
if not sys.platform.startswith('freebsd'):
983+
names.sort()
970984

971985
if alternate_tunable_layout:
972986
fmt = "\t%s=%s\n"
973987
else:
974988
fmt = "\t%-50s%s\n"
975989

976-
for name in names:
990+
if sys.platform.startswith('freebsd'):
991+
for ctl in ctls:
992+
993+
if show_tunable_descriptions and ctl.name in descriptions:
994+
sys.stdout.write("\t# %s\n" % descriptions[ctl.name])
995+
996+
sys.stdout.write(fmt % (ctl.name, ctl.value))
997+
else:
998+
for name in names:
977999

978-
if not name:
979-
continue
1000+
if not name:
1001+
continue
9801002

981-
if show_tunable_descriptions and name in descriptions:
982-
sys.stdout.write("\t# %s\n" % descriptions[name])
1003+
if show_tunable_descriptions and name in descriptions:
1004+
sys.stdout.write("\t# %s\n" % descriptions[name])
9831005

984-
sys.stdout.write(fmt % (name, values[name]))
1006+
sys.stdout.write(fmt % (name, values[name]))
9851007

9861008

9871009
unSub = [

cmd/arc_summary/arc_summary3

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ import subprocess
4343
import sys
4444
import time
4545

46+
#Requires py36-sysctl on FreeBSD
47+
if sys.platform.startswith('freebsd'):
48+
import sysctl
49+
4650
DECRIPTION = 'Print ARC and other statistics for ZFS on Linux'
4751
INDENT = ' '*8
4852
LINE_LENGTH = 72
@@ -89,7 +93,10 @@ def cleanup_line(single_line):
8993
middle '4'. For example "arc_no_grow 4 0" returns the tuple
9094
("arc_no_grow", "0").
9195
"""
92-
name, _, value = single_line.split()
96+
if sys.platform.startswith('freebsd'):
97+
name, value = single_line.split()
98+
else:
99+
name, _, value = single_line.split()
93100

94101
return name, value
95102

@@ -238,7 +245,10 @@ def format_raw_line(name, value):
238245
if ARGS.alt:
239246
result = '{0}{1}={2}'.format(INDENT, name, value)
240247
else:
241-
spc = LINE_LENGTH-(len(INDENT)+len(value))
248+
if sys.platform.startswith('freebsd'):
249+
spc = LINE_LENGTH-(len(INDENT)+len(str(value)))
250+
else:
251+
spc = LINE_LENGTH-(len(INDENT)+len(value))
242252
result = '{0}{1:<{spc}}{2}'.format(INDENT, name, value, spc=spc)
243253

244254
return result
@@ -256,11 +266,19 @@ def get_kstats():
256266

257267
for section in secs:
258268

259-
with open(PROC_PATH+section, 'r') as proc_location:
260-
lines = [line for line in proc_location]
269+
if sys.platform.startswith('freebsd'):
270+
kstats = sysctl.filter('kstat.zfs.misc.'+section+'.')
271+
lines = []
272+
for kstat in kstats:
273+
#Removes kstat.zfs.misc.+section+'.' from the name
274+
lines.append(kstat.name[15+len(section)+1:] + ' ' + str(kstat.value))
275+
result[section] = lines
276+
else:
277+
with open(PROC_PATH+section, 'r') as proc_location:
278+
lines = [line for line in proc_location]
261279

262-
del lines[0:2] # Get rid of header
263-
result[section] = lines
280+
del lines[0:2] # Get rid of header
281+
result[section] = lines
264282

265283
return result
266284

@@ -272,13 +290,24 @@ def get_spl_tunables(PATH):
272290
"""
273291

274292
result = {}
275-
parameters = os.listdir(PATH)
293+
if sys.platform.startswith('freebsd'):
294+
if PATH == "VDEV":
295+
ctls = sysctl.filter('vfs.zfs.vdev')
296+
elif PATH == "SPL": #No SPL support in FreeBSD
297+
pass
298+
else:
299+
ctls = sysctl.filter('vfs.zfs.')
300+
for ctl in ctls:
301+
#Removes 'vfs.zfs.' from the name
302+
result[ctl.name[8:]] = ctl.value
303+
else:
304+
parameters = os.listdir(PATH)
276305

277-
for name in parameters:
306+
for name in parameters:
278307

279-
with open(PATH+name, 'r') as para_file:
280-
value = para_file.read()
281-
result[name] = value.strip()
308+
with open(PATH+name, 'r') as para_file:
309+
value = para_file.read()
310+
result[name] = value.strip()
282311

283312
return result
284313

@@ -711,23 +740,27 @@ def section_spl(*_):
711740
and/or decriptions. This does not use kstats.
712741
"""
713742

714-
spls = get_spl_tunables(SPL_PATH)
715-
keylist = sorted(spls.keys())
716-
print('Solaris Porting Layer (SPL):')
743+
if sys.platform.startswith('freebsd'): #No SPL support in FreeBSD
744+
#spls = get_spl_tunables("SPL")
745+
pass
746+
else:
747+
spls = get_spl_tunables(SPL_PATH)
748+
keylist = sorted(spls.keys())
749+
print('Solaris Porting Layer (SPL):')
717750

718-
if ARGS.desc:
719-
descriptions = get_descriptions('spl')
751+
if ARGS.desc:
752+
descriptions = get_descriptions('spl')
720753

721-
for key in keylist:
722-
value = spls[key]
754+
for key in keylist:
755+
value = spls[key]
723756

724-
if ARGS.desc:
725-
try:
726-
print(INDENT+'#', descriptions[key])
727-
except KeyError:
728-
print(INDENT+'# (No decription found)') # paranoid
757+
if ARGS.desc:
758+
try:
759+
print(INDENT+'#', descriptions[key])
760+
except KeyError:
761+
print(INDENT+'# (No decription found)') # paranoid
729762

730-
print(format_raw_line(key, value))
763+
print(format_raw_line(key, value))
731764

732765
print()
733766

@@ -737,7 +770,10 @@ def section_tunables(*_):
737770
decriptions. This does not use kstasts.
738771
"""
739772

740-
tunables = get_spl_tunables(TUNABLES_PATH)
773+
if sys.platform.startswith('freebsd'):
774+
tunables = get_spl_tunables("ALL")
775+
else:
776+
tunables = get_spl_tunables(TUNABLES_PATH)
741777
keylist = sorted(tunables.keys())
742778
print('Tunables:')
743779

@@ -765,11 +801,13 @@ def section_vdev(kstats_dict):
765801
# harmful. When this is the case, we just skip the whole entry. See
766802
# https://github.com/zfsonlinux/zfs/blob/master/module/zfs/vdev_cache.c
767803
# for details
768-
tunables = get_spl_tunables(TUNABLES_PATH)
769-
770-
if tunables['zfs_vdev_cache_size'] == '0':
771-
print('VDEV cache disabled, skipping section\n')
772-
return
804+
if sys.platform.startswith('freebsd'):
805+
tunables = get_spl_tunables("VDEV")
806+
if tunables['vdev.cache.size'] == '0':
807+
print('VDEV cache disabled, skipping section\n')
808+
return
809+
else:
810+
tunables = get_spl_tunables(TUNABLES_PATH)
773811

774812
vdev_stats = isolate_section('vdev_cache_stats', kstats_dict)
775813

0 commit comments

Comments
 (0)