Skip to content

Commit

Permalink
Add FreeBSD support to ZoL
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmacy authored and malbertoni committed Jul 3, 2019
1 parent df358db commit d51c99b
Show file tree
Hide file tree
Showing 707 changed files with 105,431 additions and 2,004 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,13 @@ cscope.*
*.log
venv

*.so
*.so.debug
*.so.full
*.tmp
*.log
module/export_syms
module/machine
module/x86
module/zfs.ko.debug
module/zfs.ko.full
15 changes: 13 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@ include config/rpm.am
include config/deb.am
include config/tgz.am

SUBDIRS = include rpm
SUBDIRS = include
if BUILD_LINUX
SUBDIRS+= rpm
endif

if CONFIG_USER
SUBDIRS += udev etc man scripts lib tests cmd contrib
SUBDIRS += etc man scripts lib tests cmd contrib
if BUILD_LINUX
SUBDIRS+= udev
endif
endif
if CONFIG_KERNEL
SUBDIRS += module

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

if BUILD_LINUX
kerneldir = $(prefix)/src/zfs-$(VERSION)/$(LINUX_VERSION)
nodist_kernel_HEADERS = zfs.release zfs_config.h module/$(LINUX_SYMBOLS)
endif
endif

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

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

codecheck: cstyle shellcheck flake8 mancheck testscheck vcscheck

Expand Down
2 changes: 2 additions & 0 deletions cmd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ if USING_PYTHON
SUBDIRS += arcstat arc_summary dbufstat
endif

if BUILD_LINUX
SUBDIRS += mount_zfs zed zvol_id
endif
10 changes: 8 additions & 2 deletions cmd/arc_summary/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
EXTRA_DIST = arc_summary2 arc_summary3

transform = $(program_transform_name)

if USING_PYTHON_2
dist_bin_SCRIPTS = arc_summary2
install-exec-hook:
mv $(DESTDIR)$(bindir)/arc_summary2 $(DESTDIR)$(bindir)/arc_summary
before=$$(echo arc_summary2 | sed '$(transform)'); \
after=$$(echo arc_summary | sed '$(transform)'); \
mv "$(DESTDIR)$(bindir)/$$before" "$(DESTDIR)$(bindir)/$$after"
else
dist_bin_SCRIPTS = arc_summary3
install-exec-hook:
mv $(DESTDIR)$(bindir)/arc_summary3 $(DESTDIR)$(bindir)/arc_summary
before=$$(echo arc_summary3 | sed '$(transform)'); \
after=$$(echo arc_summary | sed '$(transform)'); \
mv "$(DESTDIR)$(bindir)/$$before" "$(DESTDIR)$(bindir)/$$after"
endif
60 changes: 41 additions & 19 deletions cmd/arc_summary/arc_summary2
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ import errno
from subprocess import Popen, PIPE
from decimal import Decimal as D

#Requires py27-sysctl on FreeBSD
if sys.platform.startswith('freebsd'):
import sysctl

show_tunable_descriptions = False
alternate_tunable_layout = False

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

kstats = [line.strip() for line in open(fn)]
del kstats[0:2]
for kstat in kstats:
kstat = kstat.strip()
name, _, value = kstat.split()
Kstat[namespace + name] = D(value)
if sys.platform.startswith('freebsd'):
kstats = sysctl.filter(namespace)
for kstat in kstats:
name, value = kstat.name, kstat.value
Kstat[name] = D(value)
else:
kstats = [line.strip() for line in open(fn)]
del kstats[0:2]
for kstat in kstats:
kstat = kstat.strip()
name, _, value = kstat.split()
Kstat[namespace + name] = D(value)

Kstat = {}
load_proc_kstats('/proc/spl/kstat/zfs/arcstats',
Expand Down Expand Up @@ -921,13 +931,16 @@ def _tunable_summary(Kstat):
global show_tunable_descriptions
global alternate_tunable_layout

names = os.listdir("/sys/module/zfs/parameters/")
if sys.platform.startswith('freebsd'):
ctls = sysctl.filter('vfs.zfs')
else:
names = os.listdir("/sys/module/zfs/parameters/")

values = {}
for name in names:
with open("/sys/module/zfs/parameters/" + name) as f:
value = f.read()
values[name] = value.strip()
values = {}
for name in names:
with open("/sys/module/zfs/parameters/" + name) as f:
value = f.read()
values[name] = value.strip()

descriptions = {}

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

sys.stdout.write("ZFS Tunables:\n")
names.sort()
if not sys.platform.startswith('freebsd'):
names.sort()

if alternate_tunable_layout:
fmt = "\t%s=%s\n"
else:
fmt = "\t%-50s%s\n"

for name in names:
if sys.platform.startswith('freebsd'):
for ctl in ctls:

if show_tunable_descriptions and ctl.name in descriptions:
sys.stdout.write("\t# %s\n" % descriptions[ctl.name])

sys.stdout.write(fmt % (ctl.name, ctl.value))
else:
for name in names:

if not name:
continue
if not name:
continue

if show_tunable_descriptions and name in descriptions:
sys.stdout.write("\t# %s\n" % descriptions[name])
if show_tunable_descriptions and name in descriptions:
sys.stdout.write("\t# %s\n" % descriptions[name])

sys.stdout.write(fmt % (name, values[name]))
sys.stdout.write(fmt % (name, values[name]))


unSub = [
Expand Down
98 changes: 68 additions & 30 deletions cmd/arc_summary/arc_summary3
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ import subprocess
import sys
import time

#Requires py36-sysctl on FreeBSD
if sys.platform.startswith('freebsd'):
import sysctl

DECRIPTION = 'Print ARC and other statistics for ZFS on Linux'
INDENT = ' '*8
LINE_LENGTH = 72
Expand Down Expand Up @@ -89,7 +93,10 @@ def cleanup_line(single_line):
middle '4'. For example "arc_no_grow 4 0" returns the tuple
("arc_no_grow", "0").
"""
name, _, value = single_line.split()
if sys.platform.startswith('freebsd'):
name, value = single_line.split()
else:
name, _, value = single_line.split()

return name, value

Expand Down Expand Up @@ -238,7 +245,10 @@ def format_raw_line(name, value):
if ARGS.alt:
result = '{0}{1}={2}'.format(INDENT, name, value)
else:
spc = LINE_LENGTH-(len(INDENT)+len(value))
if sys.platform.startswith('freebsd'):
spc = LINE_LENGTH-(len(INDENT)+len(str(value)))
else:
spc = LINE_LENGTH-(len(INDENT)+len(value))
result = '{0}{1:<{spc}}{2}'.format(INDENT, name, value, spc=spc)

return result
Expand All @@ -256,11 +266,19 @@ def get_kstats():

for section in secs:

with open(PROC_PATH+section, 'r') as proc_location:
lines = [line for line in proc_location]
if sys.platform.startswith('freebsd'):
kstats = sysctl.filter('kstat.zfs.misc.'+section+'.')
lines = []
for kstat in kstats:
#Removes kstat.zfs.misc.+section+'.' from the name
lines.append(kstat.name[15+len(section)+1:] + ' ' + str(kstat.value))
result[section] = lines
else:
with open(PROC_PATH+section, 'r') as proc_location:
lines = [line for line in proc_location]

del lines[0:2] # Get rid of header
result[section] = lines
del lines[0:2] # Get rid of header
result[section] = lines

return result

Expand All @@ -272,13 +290,24 @@ def get_spl_tunables(PATH):
"""

result = {}
parameters = os.listdir(PATH)
if sys.platform.startswith('freebsd'):
if PATH == "VDEV":
ctls = sysctl.filter('vfs.zfs.vdev')
elif PATH == "SPL": #No SPL support in FreeBSD
pass
else:
ctls = sysctl.filter('vfs.zfs.')
for ctl in ctls:
#Removes 'vfs.zfs.' from the name
result[ctl.name[8:]] = ctl.value
else:
parameters = os.listdir(PATH)

for name in parameters:
for name in parameters:

with open(PATH+name, 'r') as para_file:
value = para_file.read()
result[name] = value.strip()
with open(PATH+name, 'r') as para_file:
value = para_file.read()
result[name] = value.strip()

return result

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

spls = get_spl_tunables(SPL_PATH)
keylist = sorted(spls.keys())
print('Solaris Porting Layer (SPL):')
if sys.platform.startswith('freebsd'): #No SPL support in FreeBSD
#spls = get_spl_tunables("SPL")
pass
else:
spls = get_spl_tunables(SPL_PATH)
keylist = sorted(spls.keys())
print('Solaris Porting Layer (SPL):')

if ARGS.desc:
descriptions = get_descriptions('spl')
if ARGS.desc:
descriptions = get_descriptions('spl')

for key in keylist:
value = spls[key]
for key in keylist:
value = spls[key]

if ARGS.desc:
try:
print(INDENT+'#', descriptions[key])
except KeyError:
print(INDENT+'# (No decription found)') # paranoid
if ARGS.desc:
try:
print(INDENT+'#', descriptions[key])
except KeyError:
print(INDENT+'# (No decription found)') # paranoid

print(format_raw_line(key, value))
print(format_raw_line(key, value))

print()

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

tunables = get_spl_tunables(TUNABLES_PATH)
if sys.platform.startswith('freebsd'):
tunables = get_spl_tunables("ALL")
else:
tunables = get_spl_tunables(TUNABLES_PATH)
keylist = sorted(tunables.keys())
print('Tunables:')

Expand Down Expand Up @@ -765,11 +801,13 @@ def section_vdev(kstats_dict):
# harmful. When this is the case, we just skip the whole entry. See
# https://github.com/zfsonlinux/zfs/blob/master/module/zfs/vdev_cache.c
# for details
tunables = get_spl_tunables(TUNABLES_PATH)

if tunables['zfs_vdev_cache_size'] == '0':
print('VDEV cache disabled, skipping section\n')
return
if sys.platform.startswith('freebsd'):
tunables = get_spl_tunables("VDEV")
if tunables['vdev.cache.size'] == '0':
print('VDEV cache disabled, skipping section\n')
return
else:
tunables = get_spl_tunables(TUNABLES_PATH)

vdev_stats = isolate_section('vdev_cache_stats', kstats_dict)

Expand Down
Loading

0 comments on commit d51c99b

Please sign in to comment.