]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
6 years agoMFV r329766: 8962 zdb should work on non-idle pools
Alexander Motin [Thu, 22 Feb 2018 00:42:12 +0000 (00:42 +0000)]
MFV r329766: 8962 zdb should work on non-idle pools

illumos/illumos-gate@e144c4e6c90e7d4dccaad6db660ee42b6e7ba04f

Currently `zdb` consistently fails to examine non-idle pools as it fails
during the `spa_load()` process. The main problem seems to be that
`spa_load_verify()` fails as can be seen below:

$ sudo zdb -d -G dcenter
    zdb: can't open 'dcenter': I/O error

ZFS_DBGMSG(zdb):
    spa_open_common: opening dcenter
    spa_load(dcenter): LOADING
    disk vdev '/dev/dsk/c4t11d0s0': best uberblock found for spa dcenter. txg 40824950
    spa_load(dcenter): using uberblock with txg=40824950
    spa_load(dcenter): UNLOADING
    spa_load(dcenter): RELOADING
    spa_load(dcenter): LOADING
    disk vdev '/dev/dsk/c3t10d0s0': best uberblock found for spa dcenter. txg 40824952
    spa_load(dcenter): using uberblock with txg=40824952
    spa_load(dcenter): FAILED: spa_load_verify failed [error=5]
    spa_load(dcenter): UNLOADING

This change makes `spa_load_verify()` a dryrun when ran from `zdb`. This is
done by creating a global flag in zfs and then setting it in `zdb`.

Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Andy Stormont <astormont@racktopsystems.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Pavel Zakharov <pavel.zakharov@delphix.com>

6 years agoAdd two new ioctls to bhyve for batch register fetch/store operations.
John Baldwin [Thu, 22 Feb 2018 00:39:25 +0000 (00:39 +0000)]
Add two new ioctls to bhyve for batch register fetch/store operations.

These are a convenience for bhyve's debug server to use a single
ioctl for 'g' and 'G' rather than a loop of individual get/set
ioctl requests.

Reviewed by: grehan
MFC after: 2 months
Differential Revision: https://reviews.freebsd.org/D14074

6 years ago8962 zdb should work on non-idle pools
Alexander Motin [Thu, 22 Feb 2018 00:09:15 +0000 (00:09 +0000)]
8962 zdb should work on non-idle pools

illumos/illumos-gate@e144c4e6c90e7d4dccaad6db660ee42b6e7ba04f

Currently `zdb` consistently fails to examine non-idle pools as it fails
during the `spa_load()` process. The main problem seems to be that
`spa_load_verify()` fails as can be seen below:

$ sudo zdb -d -G dcenter
    zdb: can't open 'dcenter': I/O error

ZFS_DBGMSG(zdb):
    spa_open_common: opening dcenter
    spa_load(dcenter): LOADING
    disk vdev '/dev/dsk/c4t11d0s0': best uberblock found for spa dcenter. txg 40824950
    spa_load(dcenter): using uberblock with txg=40824950
    spa_load(dcenter): UNLOADING
    spa_load(dcenter): RELOADING
    spa_load(dcenter): LOADING
    disk vdev '/dev/dsk/c3t10d0s0': best uberblock found for spa dcenter. txg 40824952
    spa_load(dcenter): using uberblock with txg=40824952
    spa_load(dcenter): FAILED: spa_load_verify failed [error=5]
    spa_load(dcenter): UNLOADING

This change makes `spa_load_verify()` a dryrun when ran from `zdb`. This is
done by creating a global flag in zfs and then setting it in `zdb`.

Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Andy Stormont <astormont@racktopsystems.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Pavel Zakharov <pavel.zakharov@delphix.com>

6 years agoMFV r329762: 8961 SPA load/import should tell us why it failed
Alexander Motin [Thu, 22 Feb 2018 00:03:14 +0000 (00:03 +0000)]
MFV r329762: 8961 SPA load/import should tell us why it failed

illumos/illumos-gate@3ee8c80c747c4aa3f83351a6920f30c411236e1b

When we fail to open or import a storage pool, we typically don't get any
additional diagnostic information, just "no pool found" or "can not import".

While there may be no additional user-consumable information, we should at
least make this situation easier to debug/diagnose for developers and support.
For example, we could start by using `zfs_dbgmsg()` to log each thing that we
try when importing, and which things failed. E.g. "tried uberblock of txg X
from label Y of device Z". Also, we could log each of the stages that we go
through in `spa_load_impl()`.

Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Pavel Zakharov <pavel.zakharov@delphix.com>

6 years agoMinor formatting nits.
Warner Losh [Wed, 21 Feb 2018 23:49:35 +0000 (23:49 +0000)]
Minor formatting nits.

6 years agoAdd LOADER_DEBUG regression test
Warner Losh [Wed, 21 Feb 2018 23:49:18 +0000 (23:49 +0000)]
Add LOADER_DEBUG regression test

6 years ago8961 SPA load/import should tell us why it failed
Alexander Motin [Wed, 21 Feb 2018 23:42:30 +0000 (23:42 +0000)]
8961 SPA load/import should tell us why it failed

illumos/illumos-gate@3ee8c80c747c4aa3f83351a6920f30c411236e1b

When we fail to open or import a storage pool, we typically don't get any
additional diagnostic information, just "no pool found" or "can not import".

While there may be no additional user-consumable information, we should at
least make this situation easier to debug/diagnose for developers and support.
For example, we could start by using `zfs_dbgmsg()` to log each thing that we
try when importing, and which things failed. E.g. "tried uberblock of txg X
from label Y of device Z". Also, we could log each of the stages that we go
through in `spa_load_impl()`.

Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Pavel Zakharov <pavel.zakharov@delphix.com>

6 years agoMFV r329760: 7638 Refactor spa_load_impl into several functions
Alexander Motin [Wed, 21 Feb 2018 23:38:30 +0000 (23:38 +0000)]
MFV r329760: 7638 Refactor spa_load_impl into several functions

illumos/illumos-gate@1fd3785ff6601d3e391378c2dcbf4c5f27e1fe32

spa_load_impl has grown out of proportions.  It is currently over 700
lines long and makes it very hard to follow or debug the import process
even for experienced ZFS developers.  The objective is to split it up
in a series of well commented functions.

Reviewed by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Pavel Zakharov <pavel.zakharov@delphix.com>

6 years ago7638 Refactor spa_load_impl into several functions
Alexander Motin [Wed, 21 Feb 2018 23:25:11 +0000 (23:25 +0000)]
7638 Refactor spa_load_impl into several functions

illumos/illumos-gate@1fd3785ff6601d3e391378c2dcbf4c5f27e1fe32

spa_load_impl has grown out of proportions.  It is currently over 700
lines long and makes it very hard to follow or debug the import process
even for experienced ZFS developers.  The objective is to split it up
in a series of well commented functions.

Reviewed by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Pavel Zakharov <pavel.zakharov@delphix.com>

6 years ago9018 Replace kmem_cache_reap_now() with kmem_cache_reap_soon()
Alexander Motin [Wed, 21 Feb 2018 23:15:06 +0000 (23:15 +0000)]
9018 Replace kmem_cache_reap_now() with kmem_cache_reap_soon()

illumos/illumos-gate@36a64e62848b51ac5a9a5216e894ec723cfef14e

To prevent kmem_cache reaping from blocking other system resources, turn
kmem_cache_reap_now() (which blocks) into kmem_cache_reap_soon(). Callers
to kmem_cache_reap_soon() should use kmem_cache_reap_active(), which
exploits #9017's new taskq_empty().

Reviewed by: Bryan Cantrill <bryan@joyent.com>
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Yuri Pankov <yuripv@yuripv.net>
Author: Tim Kordas <tim.kordas@joyent.com>

FreeBSD does not use taskqueue for kmem caches reaping, so this change
is less dramatic then it is on Illumos, just limiting reaping to 1 time
per second.  It may possibly be improved later, if needed.

6 years agoFix compilation with LOADER_DEBUG defined after r329725.
Marius Strobl [Wed, 21 Feb 2018 22:24:49 +0000 (22:24 +0000)]
Fix compilation with LOADER_DEBUG defined after r329725.

6 years ago9018 Replace kmem_cache_reap_now() with kmem_cache_reap_soon()
Alexander Motin [Wed, 21 Feb 2018 22:14:19 +0000 (22:14 +0000)]
9018 Replace kmem_cache_reap_now() with kmem_cache_reap_soon()

illumos/illumos-gate@36a64e62848b51ac5a9a5216e894ec723cfef14e

To prevent kmem_cache reaping from blocking other system resources, turn
kmem_cache_reap_now() (which blocks) into kmem_cache_reap_soon(). Callers
to kmem_cache_reap_soon() should use kmem_cache_reap_active(), which
exploits #9017's new taskq_empty().

Reviewed by: Bryan Cantrill <bryan@joyent.com>
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Yuri Pankov <yuripv@yuripv.net>
Author: Tim Kordas <tim.kordas@joyent.com>

6 years agolualoader: Remove nasty hack for not printing out ".0"
Kyle Evans [Wed, 21 Feb 2018 21:39:47 +0000 (21:39 +0000)]
lualoader: Remove nasty hack for not printing out ".0"

luaconf.h has a LUA_COMPAT_FLOATSTRING option that may be defined to do this
instead of needing intstring.

Reported by: Dan Nelson

6 years agoMFV r329753: 8809 libzpool should leverage work done in libfakekernel
Alexander Motin [Wed, 21 Feb 2018 21:18:04 +0000 (21:18 +0000)]
MFV r329753: 8809 libzpool should leverage work done in libfakekernel

illumos/illumos-gate@f06dce2c1f0f3af78581e7574f65bfba843ddb6e

Reviewed by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Gordon Ross <gordon.w.ross@gmail.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
Author: Andrew Stormont <astormont@racktopsystems.com>

6 years agodhclient: raise WARNS to 4
Alan Somers [Wed, 21 Feb 2018 21:13:08 +0000 (21:13 +0000)]
dhclient: raise WARNS to 4

Mostly const-correctness fixes. There were also some variable-shadowing,
unused variable, and a couple of sockaddr type-correctness changes. I also had
trouble with cast-align warnings. I was able to prove that one of them was a
false positive. But ultimately I had to disable the warning program-wide to
deal with the others.

Reviewed by: cem
MFC after: 3 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D14460

6 years ago8809 libzpool should leverage work done in libfakekernel
Alexander Motin [Wed, 21 Feb 2018 21:04:46 +0000 (21:04 +0000)]
8809 libzpool should leverage work done in libfakekernel

illumos/illumos-gate@f06dce2c1f0f3af78581e7574f65bfba843ddb6e

Reviewed by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Gordon Ross <gordon.w.ross@gmail.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
Author: Andrew Stormont <astormont@racktopsystems.com>

6 years agolibifconfig: fix ifconfig_set_metric
Alan Somers [Wed, 21 Feb 2018 20:45:43 +0000 (20:45 +0000)]
libifconfig: fix ifconfig_set_metric

Due to a copy/paste error, ifconfig_set_metric actually set the mtu, not the
metric.

See Also: https://github.com/Savagedlight/libifconfig/issues/48

MFC after: 3 weeks
Sponsored by: Spectra Logic Corp

6 years agoFix a read past the end of a buffer in fsck.
Kirk McKusick [Wed, 21 Feb 2018 20:32:23 +0000 (20:32 +0000)]
Fix a read past the end of a buffer in fsck.

To minimize the time spent scanning all of the directories in pass 2
(Check Pathnames), fsck uses a search order based on the location
of their first block. Zero length directories have no first block,
so the array being used to hold the block numbers of directory
inodes was of zero length. Thus a lookup was done past the end of
the array getting at best a random value and at worst a segment
fault.  For zero length directories, this change allocates a one
element block array and initializes it to zero. The effect is that
all zero length directories are handled first in pass 2.

Reviewed by: brooks
Differential Revision: https://reviews.freebsd.org/D14163

6 years agolualoader: Drop password length restrictions
Kyle Evans [Wed, 21 Feb 2018 20:17:08 +0000 (20:17 +0000)]
lualoader: Drop password length restrictions

This seems to have been arbitrary; bootlock_password and password don't seem
to have any documented length restrictions, and loader(8) probably shouldn't
care about whatever GELI passphrase length restrictions might exist.

Reported by: Kalle Carlbark <kalle.carlbark+freebsd@kcbark.net>

6 years agolualoader: Replace 8-space indentation with a single tab
Kyle Evans [Wed, 21 Feb 2018 19:56:34 +0000 (19:56 +0000)]
lualoader: Replace 8-space indentation with a single tab

6 years agoRefactor fix in r329600 to do its check once in readsuper() rather
Kirk McKusick [Wed, 21 Feb 2018 19:56:19 +0000 (19:56 +0000)]
Refactor fix in r329600 to do its check once in readsuper() rather
than in the two places that call readsuper().

No semantic change intended.

Reviewed by: kib

6 years agoload_elf.c: Use consistent indentation
Ed Maste [Wed, 21 Feb 2018 19:42:54 +0000 (19:42 +0000)]
load_elf.c: Use consistent indentation

As noted in D14267 load_elf.c has a variety of indentation styles.  Move
to standard 8 column hard tab indents, 4 space second level indents.
Also includes some whitespace cleanups found by clang-format.

6 years agoFix route manpage to show correct flush syntax
Ryan Stone [Wed, 21 Feb 2018 19:13:27 +0000 (19:13 +0000)]
Fix route manpage to show correct flush syntax

The current route(8) manpage shows that "flush" is an argument to
the optional -n flag, rather than a separate subcommand.  Correct
this to properly show flush as a route subcommand.

MFC after: 2 weeks
Sponsored by: Dell EMC Isilon
Reviewed by: rgrimes
Differential Revision: https://reviews.freebsd.org/D14401

6 years agoAllow route change requests to not specify the gateway.
Ryan Stone [Wed, 21 Feb 2018 19:13:23 +0000 (19:13 +0000)]
Allow route change requests to not specify the gateway.

Only require a gateway to be specified on a route add request.  On
a route change request that does not specify the gateway, the
gateway will remain the same.  This allows changing other route
parameters without having to re-specifying the gateway, like in
"route change 10.0.0.0/8 -mtu 9000".

Update the route(8) manpage to explicitly call out this usage
as being supported.

MFC after: 2 weeks
Sponsored by: Dell EMC Isilon
Reviewed By: eugen (rtsock.c change), rgrimes
Differential Revision: https://reviews.freebsd.org/D14291

6 years agoIFLIB: Make isc_magic unsigned
Stephen Hurd [Wed, 21 Feb 2018 18:57:00 +0000 (18:57 +0000)]
IFLIB: Make isc_magic unsigned

The IFLIB_MAGIC macro is > INT_MAX, so isc_magic should
be able to contain it.

Reported by: jeb
Sponsored by: Limelight  Networks

6 years agoFurther style(9) changes.
Benno Rice [Wed, 21 Feb 2018 18:32:06 +0000 (18:32 +0000)]
Further style(9) changes.

Tested by: objdump -d | md5 (both in-tree clang and lang/gcc6)

6 years agoMFV r329736: 8969 Cannot boot from RAIDZ with parity > 1
Alexander Motin [Wed, 21 Feb 2018 18:12:19 +0000 (18:12 +0000)]
MFV r329736: 8969 Cannot boot from RAIDZ with parity > 1

illumos/illumos-gate@0fb055e81fd0cda5221da8ddd98b2f8d1fc6bdbe

At present it is possible to boot from a root pool that is on RAIDZ but not
one that is on RAIDZ2 or RAIDZ3.  This is because, at the time the pool
version is checked to ensure support for dual/triple parity, the uberblock
has not yet been loaded into the SPA and therefore the code determines that
the pool version is too old and returns ENOTSUP.

Reviewed by: Igor Kozhukhov <igor@dilos.org>
Reviewed by: Andriy Gapon <avg@FreeBSD.org>
Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: Andy Stormont <astormont@racktopsystems.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Gordon Ross <gwr@nexenta.com>
Author: Andy Fiddaman <omnios@citrus-it.co.uk>

FreeBSD already had this fixed, so this is just a diff reduction.

6 years agoPurely whitespace changes bringing this file closer to style(9).
Benno Rice [Wed, 21 Feb 2018 18:10:50 +0000 (18:10 +0000)]
Purely whitespace changes bringing this file closer to style(9).

Curiously, changing whitespace seems to cause the md5 of the .o files to differ
these days hence the following testing strategy:

Tested by: objdump -d | md5 (both in-tree clang and lang/gcc6)

6 years ago8969 Cannot boot from RAIDZ with parity > 1
Alexander Motin [Wed, 21 Feb 2018 18:09:07 +0000 (18:09 +0000)]
8969 Cannot boot from RAIDZ with parity > 1

illumos/illumos-gate@0fb055e81fd0cda5221da8ddd98b2f8d1fc6bdbe

At present it is possible to boot from a root pool that is on RAIDZ but not
one that is on RAIDZ2 or RAIDZ3.  This is because, at the time the pool
version is checked to ensure support for dual/triple parity, the uberblock
has not yet been loaded into the SPA and therefore the code determines that
the pool version is too old and returns ENOTSUP.

Reviewed by: Igor Kozhukhov <igor@dilos.org>
Reviewed by: Andriy Gapon <avg@FreeBSD.org>
Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: Andy Stormont <astormont@racktopsystems.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Gordon Ross <gwr@nexenta.com>
Author: Andy Fiddaman <omnios@citrus-it.co.uk>

6 years agolualoader: Don't execute menu.autoboot() for every opened menu
Kyle Evans [Wed, 21 Feb 2018 17:33:01 +0000 (17:33 +0000)]
lualoader: Don't execute menu.autoboot() for every opened menu

Attempt to autoboot when we open the default menu, and only when we open the
default menu. This alleviates the need for checking menu.already_autoboot,
because we're not trying to autoboot every time we open a submenu.

I note that escaping to loader prompt and going back to the menu (by running
require('menu').run() at the loader prompt) will happily work and not
re-initiate the autoboot sequence since "Escape to loader prompt" disables
the autoboot_delay.

6 years agolualoader: Make kernel autodetection contingent on loader.conf(5) var
Kyle Evans [Wed, 21 Feb 2018 16:57:03 +0000 (16:57 +0000)]
lualoader: Make kernel autodetection contingent on loader.conf(5) var

Instead of based it off of whether 'kernels' was specified, base it off of a
new variable: kernels_autodetect. If set to yes, we'll run the autodetection
bits and add any detected kernels to the already existing list *after* both
'kernel' and 'kernels'.

6 years agoMFV r329502: 7614 zfs device evacuation/removal
Alexander Motin [Wed, 21 Feb 2018 16:51:02 +0000 (16:51 +0000)]
MFV r329502: 7614 zfs device evacuation/removal

illumos/illumos-gate@5cabbc6b49070407fb9610cfe73d4c0e0dea3e77

https://www.illumos.org/issues/7614:
This project allows top-level vdevs to be removed from the storage pool with
“zpool remove”, reducing the total amount of storage in the pool. This
operation copies all allocated regions of the device to be removed onto other
devices, recording the mapping from old to new location. After the removal is
complete, read and free operations to the removed (now “indirect”) vdev must
be remapped and performed at the new location on disk. The indirect mapping
table is kept in memory whenever the pool is loaded, so there is minimal
performance overhead when doing operations on the indirect vdev.

The size of the in-memory mapping table will be reduced when its entries
become “obsolete” because they are no longer used by any block pointers in
the pool. An entry becomes obsolete when all the blocks that use it are
freed. An entry can also become obsolete when all the snapshots that
reference it are deleted, and the block pointers that reference it have been
“remapped” in all filesystems/zvols (and clones). Whenever an indirect block
is written, all the block pointers in it will be “remapped” to their new
(concrete) locations if possible. This process can be accelerated by using
the “zfs remap” command to proactively rewrite all indirect blocks that
reference indirect (removed) vdevs.

Note that when a device is removed, we do not verify the checksum of the data
that is copied. This makes the process much faster, but if it were used on
redundant vdevs (i.e. mirror or raidz vdevs), it would be possible to copy
the wrong data, when we have the correct data on e.g. the other side of the
mirror. Therefore, mirror and raidz devices can not be removed.

Reviewed by: Alex Reece <alex@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: John Kennedy <john.kennedy@delphix.com>
Reviewed by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Richard Laager <rlaager@wiktel.com>
Reviewed by: Tim Chase <tim@chase2k.com>
Approved by: Garrett D'Amore <garrett@damore.org>
Author: Prashanth Sreenivasa <pks@delphix.com>

6 years agolualoader: Add boot environment support
Kyle Evans [Wed, 21 Feb 2018 16:50:41 +0000 (16:50 +0000)]
lualoader: Add boot environment support

This looks a little bit differently than the forth version for the time
being, just to get off the ground- rather than a paging system, it's
implemented as a simple carousel like the kernel selector.

Reviewed by: cem
Differential Revision: https://reviews.freebsd.org/D14436

6 years agoAdd required header files.
Ian Lepore [Wed, 21 Feb 2018 16:36:44 +0000 (16:36 +0000)]
Add required header files.

Reported by: andreast@

6 years agoRemove some files that snuck in via cut and paste.
Ian Lepore [Wed, 21 Feb 2018 16:34:04 +0000 (16:34 +0000)]
Remove some files that snuck in via cut and paste.

Having these compiled into the module causes the kobj method descriptors
to be resolved incorrectly (by the compile-time linker instead of the
kernel linker), which then leads to hours of frustrating debugging.

6 years agostand/zfs: Unbreak build, 'truct' ~= 'struct'
Kyle Evans [Wed, 21 Feb 2018 16:33:08 +0000 (16:33 +0000)]
stand/zfs: Unbreak build, 'truct' ~= 'struct'

6 years agostand/zfs: Add all bootenvs to environment
Kyle Evans [Wed, 21 Feb 2018 16:26:16 +0000 (16:26 +0000)]
stand/zfs: Add all bootenvs to environment

For the benefit of lualoader, add all bootenvs to environment when
init_zfs_bootenv is invoked. All of the boot environment logic can then be
implemented in pure lua, rather than going back and forth with C to
implement paging.

This stores all boot environments in bootenvs[idx] and the final count of
bootenvs in bootenvs_count.

While here, make a copy of currdev for init_zfs_bootenv since it will be
modifying it and the caller may not necessarily want that. Some of the logic
was shifted around so that the 'currdev' pointer remains at the beginning of
the string and 'beroot' is moved around as needed to modify it or ultimately
store it in zfs_be_root.

The original zfs_bootenv that this was copied from will be able to go away
only if/when forth eventually goes away.

Tested with: lualoader (and local changes to add boot env. support)
Tested with: forth
Reviewed by: cem (earlier version), imp
Differential Revision: https://reviews.freebsd.org/D14435

6 years agoHonor settings for including / excluding cd9660, ufs, ext2fs and msdos.
Warner Losh [Wed, 21 Feb 2018 15:58:00 +0000 (15:58 +0000)]
Honor settings for including / excluding cd9660, ufs, ext2fs and msdos.

The Makefile gives the impression that ext2fs and msdos were excluded
(they weren't) and that you could exclude cd9660 and ufs support (you
couldn't). Allow those to be excluded.

We need to look, in the future, at trimming the number of supported
filesystems, and this will make that easier.

6 years agoConsolidate three copies of ZFS commands into a central location.
Warner Losh [Wed, 21 Feb 2018 15:57:36 +0000 (15:57 +0000)]
Consolidate three copies of ZFS commands into a central location.

There's no reason to have multiple copies of lszfs and
reloadbe. Consolidate them into one location. Also ldi_get_size is the
same everywhere (except sparc64). Make it the same everywhere as the
common definition is more general and will work on spar64.

6 years agoBuild getty(8) with WARNS=6.
Edward Tomasz Napierala [Wed, 21 Feb 2018 15:57:24 +0000 (15:57 +0000)]
Build getty(8) with WARNS=6.

Reviewed by: imp@
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D14197

6 years agoministat: disallow negative variance / nan Stddev
Ed Maste [Wed, 21 Feb 2018 15:54:23 +0000 (15:54 +0000)]
ministat: disallow negative variance / nan Stddev

With all values identical it was possible for Var() to return a negative
value due to limited floating point precision, resulting in "nan"
reported as Stddev.

Variance cannot actually be negative, so just return 0.  We can later
investigate alternate algorithms for calculating variance to reduce the
effect of catastrophic cancellation here.

Reported by: Arshan Khanifar <arshankhanifar_gmail.com>
Approved by: phk
Sponsored by: The FreeBSD Foundation

6 years agozdb: raise WARNS from 0 to 2
Alan Somers [Wed, 21 Feb 2018 15:51:48 +0000 (15:51 +0000)]
zdb: raise WARNS from 0 to 2

This has only been possible since r329694 and r329508

MFC after: 3 weeks
X-MFC-With: 329694
X-MFC-With: 329508
Sponsored by: Spectra Logic

6 years agoAdd definition for the PowerPC A2.
Nathan Whitehorn [Wed, 21 Feb 2018 15:15:58 +0000 (15:15 +0000)]
Add definition for the PowerPC A2.

6 years agoAdd definitions for the new Radix MMU mode on POWER9+ CPUs.
Nathan Whitehorn [Wed, 21 Feb 2018 15:15:31 +0000 (15:15 +0000)]
Add definitions for the new Radix MMU mode on POWER9+ CPUs.

6 years agoMFV r329718: 8520 7198 lzc_rollback_to should support rolling back to origin
Andriy Gapon [Wed, 21 Feb 2018 15:12:14 +0000 (15:12 +0000)]
MFV r329718: 8520 7198 lzc_rollback_to should support rolling back to origin

illumos/illumos-gate@95643f75d23914a3e332adc9661ed51749e9858d
https://github.com/illumos/illumos-gate/commit/95643f75d23914a3e332adc9661ed51749e9858d

https://www.illumos.org/issues/8520
  lzc_rollback_to() should support rolling back to a clone's origin.
  The current checks in zfs_ioc_rollback() would not allow that because the
  origin snapshot belongs to a different filesystem.
  The overly restrictive check was introduced in 7600, but it was not a
  regression as none of the existing tools provided a way to rollback to the
  origin.

https://www.illumos.org/issues/7198
  EINVAL is returned when a dataset does not have any snapshots, so there is
  nothing to roll back to.
  Although the code in zfs_do_rollback checks for that condition in advance, it's
  still possible that the snapshot(s) gets removed after the check and before the
  rollback sync task is executed.
  At the moment zfs command would crash when that happens.

Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Andriy Gapon <avg@FreeBSD.org>
MFC after: 2 weeks

6 years ago8520 7198 lzc_rollback_to should support rolling back to origin
Andriy Gapon [Wed, 21 Feb 2018 15:10:33 +0000 (15:10 +0000)]
8520 7198 lzc_rollback_to should support rolling back to origin

illumos/illumos-gate@95643f75d23914a3e332adc9661ed51749e9858d
https://github.com/illumos/illumos-gate/commit/95643f75d23914a3e332adc9661ed51749e9858d

https://www.illumos.org/issues/8520
  lzc_rollback_to() should support rolling back to a clone's origin.
  The current checks in zfs_ioc_rollback() would not allow that because the
  origin snapshot belongs to a different filesystem.
  The overly restrictive check was introduced in 7600, but it was not a
  regression as none of the existing tools provided a way to rollback to the
  origin.

https://www.illumos.org/issues/7198
  EINVAL is returned when a dataset does not have any snapshots, so there is
  nothing to roll back to.
  Although the code in zfs_do_rollback checks for that condition in advance, it's
  still possible that the snapshot(s) gets removed after the check and before the
  rollback sync task is executed.
  At the moment zfs command would crash when that happens.

Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Andriy Gapon <avg@FreeBSD.org>

6 years agoMFV r329715: 8997 ztest assertion failure in zil_lwb_write_issue
Andriy Gapon [Wed, 21 Feb 2018 15:07:49 +0000 (15:07 +0000)]
MFV r329715: 8997 ztest assertion failure in zil_lwb_write_issue

illumos/illumos-gate@f864f99efe57685e1762590c1a880dd16bca6da9
https://github.com/illumos/illumos-gate/commit/f864f99efe57685e1762590c1a880dd16bca6da9

https://www.illumos.org/issues/8997
  When dmu_tx_assign is called from zil_lwb_write_issue, it's possible
  for either ERESTART or EIO to be returned.
  If ERESTART is returned, this will cause an assertion to fail directly
  in zil_lwb_write_issue, where the code assumes the return value is
  EIO if dmu_tx_assign returns a non-zero value. This can occur if the
  SPA is suspended when dmu_tx_assign is called, and most often occurs
  when running zloop.
  If EIO is returned, this can cause assertions to fail elsewhere in the
  ZIL code. For example, zil_commit_waiter_timeout contains the
  following logic:
    lwb_t *nlwb = zil_lwb_write_issue(zilog, lwb);
    ASSERT3S(lwb->lwb_state, !=, LWB_STATE_OPENED);
  In this case, if dmu_tx_assign returned EIO from within
  zil_lwb_write_issue, the lwb variable passed in will not be issued
  to disk. Thus, it's lwb_state field will remain LWB_STATE_OPENED and
  this assertion will fail. zil_commit_waiter_timeout assumes that after
  it calls zil_lwb_write_issue, the lwb will be issued to disk, and
  doesn't handle the case where this is not true; i.e. it doesn't handle
  the case where dmu_tx_assign returns EIO.

Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: Andriy Gapon <avg@FreeBSD.org>
Approved by: Robert Mustacchi <rm@joyent.com>
Author: Prakash Surya <prakash.surya@delphix.com>
MFC after: 3 weeks

6 years agolualoader: Use the key that interrupts autoboot as a menu choice
Kyle Evans [Wed, 21 Feb 2018 14:37:49 +0000 (14:37 +0000)]
lualoader: Use the key that interrupts autoboot as a menu choice

This matches forth behavior. Hitting "6" when autobooting at the welcome
menu will now take you directly to the "Boot Options" menu.

We likely have some slight optimizations we should make, like not checking
autoboot every time we open a new menu and things of this nature. Further
work will go towards this end.

6 years ago8997 ztest assertion failure in zil_lwb_write_issue
Andriy Gapon [Wed, 21 Feb 2018 14:33:00 +0000 (14:33 +0000)]
8997 ztest assertion failure in zil_lwb_write_issue

illumos/illumos-gate@f864f99efe57685e1762590c1a880dd16bca6da9
https://github.com/illumos/illumos-gate/commit/f864f99efe57685e1762590c1a880dd16bca6da9

https://www.illumos.org/issues/8997
  When dmu_tx_assign is called from zil_lwb_write_issue, it's possible
  for either ERESTART or EIO to be returned.
  If ERESTART is returned, this will cause an assertion to fail directly
  in zil_lwb_write_issue, where the code assumes the return value is
  EIO if dmu_tx_assign returns a non-zero value. This can occur if the
  SPA is suspended when dmu_tx_assign is called, and most often occurs
  when running zloop.
  If EIO is returned, this can cause assertions to fail elsewhere in the
  ZIL code. For example, zil_commit_waiter_timeout contains the
  following logic:
    lwb_t *nlwb = zil_lwb_write_issue(zilog, lwb);
    ASSERT3S(lwb->lwb_state, !=, LWB_STATE_OPENED);
  In this case, if dmu_tx_assign returned EIO from within
  zil_lwb_write_issue, the lwb variable passed in will not be issued
  to disk. Thus, it's lwb_state field will remain LWB_STATE_OPENED and
  this assertion will fail. zil_commit_waiter_timeout assumes that after
  it calls zil_lwb_write_issue, the lwb will be issued to disk, and
  doesn't handle the case where this is not true; i.e. it doesn't handle
  the case where dmu_tx_assign returns EIO.

Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: Andriy Gapon <avg@FreeBSD.org>
Approved by: Robert Mustacchi <rm@joyent.com>
Author: Prakash Surya <prakash.surya@delphix.com>

6 years agoMFV r329713: 8731 ASSERT3U(nui64s, <=, UINT16_MAX) fails for large blocks
Andriy Gapon [Wed, 21 Feb 2018 14:31:48 +0000 (14:31 +0000)]
MFV r329713: 8731 ASSERT3U(nui64s, <=, UINT16_MAX) fails for large blocks

illumos/illumos-gate@a6c1eb3c08094a6db69aa1dc6315bc814e82e79c
https://github.com/illumos/illumos-gate/commit/a6c1eb3c08094a6db69aa1dc6315bc814e82e79c

https://www.illumos.org/issues/8731
  annotate_ecksum() asserts that nui64s, calculated as nui64s = size / sizeof
  (uint64_t), is not greater than UINT16_MAX.
  This restriction is needed because histograms of incorrectly set and cleared
  bits have 16 bit counters and if the buffer consists of too many 64-bit words,
  then a counter can potentially overflow producing an incorrect result.
  When the largest buffer size was 128KB the greatest value of nui64s was 16K,
  well within the limit.
  But now we have support for large buffers and for buffer sizes of 512KB and
  above the restriction is violated.

Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Andriy Gapon <avg@FreeBSD.org>
MFC after: 2 weeks

6 years ago8731 ASSERT3U(nui64s, <=, UINT16_MAX) fails for large blocks
Andriy Gapon [Wed, 21 Feb 2018 14:30:34 +0000 (14:30 +0000)]
8731 ASSERT3U(nui64s, <=, UINT16_MAX) fails for large blocks

illumos/illumos-gate@a6c1eb3c08094a6db69aa1dc6315bc814e82e79c
https://github.com/illumos/illumos-gate/commit/a6c1eb3c08094a6db69aa1dc6315bc814e82e79c

https://www.illumos.org/issues/8731
  annotate_ecksum() asserts that nui64s, calculated as nui64s = size / sizeof
  (uint64_t), is not greater than UINT16_MAX.
  This restriction is needed because histograms of incorrectly set and cleared
  bits have 16 bit counters and if the buffer consists of too many 64-bit words,
  then a counter can potentially overflow producing an incorrect result.
  When the largest buffer size was 128KB the greatest value of nui64s was 16K,
  well within the limit.
  But now we have support for large buffers and for buffer sizes of 512KB and
  above the restriction is violated.

Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Author: Andriy Gapon <avg@FreeBSD.org>

6 years agoPowerNV: Put processor to power-save state in idle thread
Wojciech Macek [Wed, 21 Feb 2018 14:28:40 +0000 (14:28 +0000)]
PowerNV: Put processor to power-save state in idle thread

When processor enters power-save state it releases resources shared with other
cpu threads which makes other cores working much faster.

This patch also implements saving and restoring registers that might get
corrupted in power-save state.

Submitted by:          Patryk Duda <pdk@semihalf.com>
Obtained from:         Semihalf
Reviewed by:           jhibbits, nwhitehorn, wma
Sponsored by:          IBM, QCM Technologies
Differential revision: https://reviews.freebsd.org/D14330

6 years agoMFV r329710: 8966 Source file zfs_acl.c, function zfs_aclset_common contains a use...
Andriy Gapon [Wed, 21 Feb 2018 14:17:07 +0000 (14:17 +0000)]
MFV r329710: 8966 Source file zfs_acl.c, function zfs_aclset_common contains a use after end of the lifetime of a local variable

illumos/illumos-gate@82693e09cc02331fa1b3b73b54b1060e73507a8d
https://github.com/illumos/illumos-gate/commit/82693e09cc02331fa1b3b73b54b1060e73507a8d
https://www.illumos.org/issues/8966

Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: Andriy Gapon <avg@FreeBSD.org>
Approved by: Richard Lowe <richlowe@richlowe.net>
Author: WHR <msl0000023508@gmail.com>
PR: 225162
Submitted by: WHR <msl0000023508@gmail.com>
Reported by: WHR <msl0000023508@gmail.com>
MFC after: 1 week

6 years ago8966 Source file zfs_acl.c, function zfs_aclset_common contains a use after end of...
Andriy Gapon [Wed, 21 Feb 2018 14:12:29 +0000 (14:12 +0000)]
8966 Source file zfs_acl.c, function zfs_aclset_common contains a use after end of the lifetime of a local variable

illumos/illumos-gate@82693e09cc02331fa1b3b73b54b1060e73507a8d
https://github.com/illumos/illumos-gate/commit/82693e09cc02331fa1b3b73b54b1060e73507a8d

https://www.illumos.org/issues/8966

Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: Andriy Gapon <avg@FreeBSD.org>
Approved by: Richard Lowe <richlowe@richlowe.net>
Author: WHR <msl0000023508@gmail.com>

6 years agolualoader: Don't autodetect kernels if 'kernels' is explicitly set
Kyle Evans [Wed, 21 Feb 2018 14:07:53 +0000 (14:07 +0000)]
lualoader: Don't autodetect kernels if 'kernels' is explicitly set

6 years agoUse proper buffer length (the announce_buf char pointer used to be anarray),
Edward Tomasz Napierala [Wed, 21 Feb 2018 14:05:13 +0000 (14:05 +0000)]
Use proper buffer length (the announce_buf char pointer used to be anarray),
broken in r317143. This fixes those weird "cd0: Attempt" messages at boot.

PR: 222103
Reviewed by: scottl@
MFC after: 2 weeks
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14369

6 years agoAllow LinuxKPI character devices to receive mmap() calls from the Linux
Hans Petter Selasky [Wed, 21 Feb 2018 10:13:17 +0000 (10:13 +0000)]
Allow LinuxKPI character devices to receive mmap() calls from the Linux
binary mode user-space emulation layer. This is a regression issue after
r328436, when LinuxKPI character devices started to use DTYPE_DEV in
the "f_type" field of the associated file structure(s).

MFC after: 3 days
Found by: Johannes Lundberg <johalun0@gmail.com>
Sponsored by: Mellanox Technologies

6 years agoPowerNV: add missing RTC_WRITE support
Wojciech Macek [Wed, 21 Feb 2018 08:13:17 +0000 (08:13 +0000)]
PowerNV: add missing RTC_WRITE support

Add function which can store RTC values to OPAL.

Submitted by:          Wojciech Macek <wma@semihalf.org>
Obtained from:         Semihalf
Sponsored by:          IBM, QCM Technologies

6 years agoCXGBE: implement prefetch on non-Intel architectures
Wojciech Macek [Wed, 21 Feb 2018 08:05:56 +0000 (08:05 +0000)]
CXGBE: implement prefetch on non-Intel architectures

Submitted by:          Michal Stanek <mst@semihalf.com>
Obtained from:         Semihalf
Reviewed by:           np, pdk@semihalf.com
Sponsored by:          IBM, QCM Technologies
Differential revision: https://reviews.freebsd.org/D14452

6 years agolualoader: Allow carousel 'items' to be a table as well as a function
Kyle Evans [Wed, 21 Feb 2018 05:04:58 +0000 (05:04 +0000)]
lualoader: Allow carousel 'items' to be a table as well as a function

We don't have any in-tree users of this, but for a static set of carousel
options having to define a callback is excessive.

6 years agolualoader: Simplify menu definitions a little further
Kyle Evans [Wed, 21 Feb 2018 04:48:37 +0000 (04:48 +0000)]
lualoader: Simplify menu definitions a little further

Allow "name" entries to be simple strings, instead of just functions. We
know whether we support colors or not by the time any of this is setup, so
all menu names that are basically static with colors sprinkled in are good
candidates for simplification.

Also simplify "func" in many cases where it's just invoking another function
with no arguments. The downside to this simplification is that the functions
called can no longer be trivially replaced by a local module. The upside is
that it removes another layer of indirection that we likely don't need.

These can be re-evaluated later if a compelling argument is raised, on a
case-by-case basis, for replacement.

6 years agolualoader: Directly reference submenu definition with submenu key
Kyle Evans [Wed, 21 Feb 2018 04:23:13 +0000 (04:23 +0000)]
lualoader: Directly reference submenu definition with submenu key

6 years agolualoader: Drop name requirement for menu separators
Kyle Evans [Wed, 21 Feb 2018 04:14:32 +0000 (04:14 +0000)]
lualoader: Drop name requirement for menu separators

6 years agolualoader: Add "menu.default", initialized to menu.welcome
Kyle Evans [Wed, 21 Feb 2018 03:37:46 +0000 (03:37 +0000)]
lualoader: Add "menu.default", initialized to menu.welcome

The intent here is to abstract away the name of the default menu. The
default menu is still the welcome menu, but this detail doesn't need to
matter to things outside of the menu module. You may change the default
menu, but one would need to modify a specific menu.

6 years agoSplit printtrap() into generic and CPU-specific components
Justin Hibbits [Wed, 21 Feb 2018 03:34:33 +0000 (03:34 +0000)]
Split printtrap() into generic and CPU-specific components

Summary:
This compartmentalizes the CPU-specific trap components into its own
function, rather than littering the general printtrap() with various checks.
This will let us replace a series of #ifdef's with a runtime conditional check
in the future.

Reviewed By: nwhitehorn
Differential Revision: https://reviews.freebsd.org/D14416

6 years agoMFV r324198: 8081 Compiler warnings in zdb
Alexander Motin [Wed, 21 Feb 2018 03:08:47 +0000 (03:08 +0000)]
MFV r324198: 8081 Compiler warnings in zdb

illumos/illumos-gate@3f7978d02b206a6ebc5652c91aa9f42da6fbe00c
https://github.com/illumos/illumos-gate/commit/3f7978d02b206a6ebc5652c91aa9f42da6fbe00c

https://www.illumos.org/issues/8081
  zdb(8) is full of minor problems that generate compiler warnings. On FreeBSD,
  which uses -WError, the only way to build it is to disable all compiler
  warnings. This makes it much harder to detect newly introduced bugs. We should
  cleanup all the warnings.

Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Prakash Surya <prakash.surya@delphix.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
Author: Alan Somers <asomers@gmail.com>

6 years agolualoader: Return only argstr if with_kernel not requested
Kyle Evans [Wed, 21 Feb 2018 03:06:36 +0000 (03:06 +0000)]
lualoader: Return only argstr if with_kernel not requested

6 years agolualoader: Bring in local.lua module if it exists
Kyle Evans [Wed, 21 Feb 2018 02:35:13 +0000 (02:35 +0000)]
lualoader: Bring in local.lua module if it exists

Provide a way for out-of-tree users of lualoader to patch into the loader
system without having to modify our distributed scripts.

Do note that we can't really offer any API compatibility guarantees at this
time due to the evolving nature of lualoader right now.

This still has some utility as local modules may add commands at the loader
prompt without relying heavily on lualoader features- this specific
functionality is less likely to change without more careful consideration.

Reviewed by: cem (earlier version)
Differential Revision: https://reviews.freebsd.org/D14439

6 years agoMFV r322231:
Alexander Motin [Wed, 21 Feb 2018 02:21:22 +0000 (02:21 +0000)]
MFV r322231:
8430 dir_is_empty_readdir() doesn't properly handle error from fdopendir()

illumos/illumos-gate@ba6e7e6505150388de6dc6a88741164118a421bf
https://github.com/illumos/illumos-gate/commit/ba6e7e6505150388de6dc6a88741164118a421bf

https://www.illumos.org/issues/8430
  we should close dirfd if fdopendir() fails.

Reviewed by: Serapheim Dimitropoulos <serapheim@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Igor Kozhukhov <igor@dilos.org>
Approved by: Robert Mustacchi <rm@joyent.com>
Author: Sowrabha Gopal <sowrabha.gopal@delphix.com>

6 years agoMFV r319737: 6939 add sysevents to zfs core for commands
Alexander Motin [Wed, 21 Feb 2018 02:19:42 +0000 (02:19 +0000)]
MFV r319737: 6939 add sysevents to zfs core for commands

illumos/illumos-gate@ce1577b04976f1d8bb5f235b6eaaab15b46a3068
https://github.com/illumos/illumos-gate/commit/ce1577b04976f1d8bb5f235b6eaaab15b46a3068

https://www.illumos.org/issues/6939
  Originally created https://smartos.org/bugview/OS-4489
       sysevents should be fired in the kernel from ZFS whenever a command
       is run that is logged in zpool history.
  Example output
  Terminal 1
  root - gz sunos ~ # zfs create zones/foobar
  root - gz sunos ~ # zfs set quota=10g zones/foobar
  root - gz sunos ~ # zfs destroy zones/foobar
  Terminal 2
  root - gz sunos ~ # sysevent EC_zfs
  nvlist version: 0
      date = 2016-04-28T14:50:08.964Z
      vendor = SUNW
      publisher = zfs
      class = EC_zfs
      subclass = ESC_ZFS_history_event
      pid = 0
      data = (embedded nvlist)
      nvlist version: 0
          pool_name = zones
          pool_guid = 0x40c964e8f9a7a694
          history_record = (embedded nvlist)
          nvlist version: 0
              dsname = zones/foobar
              dsid = 0x1525
              history internal str =
              internal_name = create
              history txg = 0x4c4ef3

Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
Reviewed by: Josh Wilsdon <jwilsdon@joyent.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Richard Elling <Richard.Elling@RichardElling.com>
Reviewed by: Alan Somers <asomers@gmail.com>
Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
Approved by: Matthew Ahrens <mahrens@delphix.com>
Author: Dave Eddy <dave@daveeddy.com>

6 years agolualoader: Output "Failed to parse" messages
Kyle Evans [Wed, 21 Feb 2018 01:52:42 +0000 (01:52 +0000)]
lualoader: Output "Failed to parse" messages

I can't find any good reason these aren't enabled, so enable them.

The silent runs will only return false on actual parse errors, so it's ok to
be loud about those failures.

6 years agolualoader: Don't return false for failure to open config on silent parse
Kyle Evans [Wed, 21 Feb 2018 01:50:46 +0000 (01:50 +0000)]
lualoader: Don't return false for failure to open config on silent parse

6 years agolualoader: Drop explicit boolean tests; b or not b
Kyle Evans [Wed, 21 Feb 2018 01:39:33 +0000 (01:39 +0000)]
lualoader: Drop explicit boolean tests; b or not b

6 years agostyle.lua(9): Drop notes about semicolons
Kyle Evans [Wed, 21 Feb 2018 01:37:22 +0000 (01:37 +0000)]
style.lua(9): Drop notes about semicolons

It is generally agreed upon that they are ugly and should not be used except
where needed.

6 years agolualoader: Drop excessive parenthesizing
Kyle Evans [Wed, 21 Feb 2018 01:35:19 +0000 (01:35 +0000)]
lualoader: Drop excessive parenthesizing

This was also a convenience convention (for me) that is not very lua-tic.
Drop it.

I've maintained some parentheses where I'd prefer them, for example,
'if x or y or (z and w) then', but these situations are far and few between.

6 years agolualoader: Drop terminating semicolons
Kyle Evans [Wed, 21 Feb 2018 01:10:03 +0000 (01:10 +0000)]
lualoader: Drop terminating semicolons

This was previously chosen out of convenience, as we had a mixed style and
needed to be consistent. I started learning Lua on Friday, so I switched
everything over. It is not a very lua-nic convention, though, so drop it.

Excessive parenthesizing around conditionals is next on the chopping block.

6 years agoMFV r319736: 6396 remove SVM
Alexander Motin [Wed, 21 Feb 2018 00:24:54 +0000 (00:24 +0000)]
MFV r319736: 6396 remove SVM

illumos/illumos-gate@5f10ef697f250374b7b917e10961c4e02d4e3112
https://github.com/illumos/illumos-gate/commit/5f10ef697f250374b7b917e10961c4e02d4e3112

https://www.illumos.org/issues/6396
  LVM = SVM = Solaris Volume Manager
  dead code and not using with ZFS based platform.

Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
Author: Yuri Pankov <yuri.pankov@nexenta.com>

6 years agomountd: Return proper errno values in a few error paths
Ravi Pokala [Wed, 21 Feb 2018 00:19:02 +0000 (00:19 +0000)]
mountd: Return proper errno values in a few error paths

When attempting to mount a non-directory which exists, return ENOTDIR instead
of ENOENT. If stat() or statfs() failed, don't pass part of the invalid
(struct statfs) to ex_search(). In that same case, preserve the value of "bad"
rather than overwriting with EACCES.

Submitted by: Bruce Leverett (Panasas)
Reviewed by: rmacklem
MFC after: 1 week
Sponsored by: Panasas
Differential Revision: https://reviews.freebsd.org/D14438

6 years agoMFV r318941: 7446 zpool create should support efi system partition
Alexander Motin [Wed, 21 Feb 2018 00:18:57 +0000 (00:18 +0000)]
MFV r318941: 7446 zpool create should support efi system partition

illumos/illumos-gate@7855d95b30fd903e3918bad5a29b777e765db821
https://github.com/illumos/illumos-gate/commit/7855d95b30fd903e3918bad5a29b777e765db821

https://www.illumos.org/issues/7446
  Since we support whole-disk configuration for boot pool, we also will need
  whole disk support with UEFI boot and for this, zpool create should create efi-
  system partition.
  I have borrowed the idea from oracle solaris, and introducing zpool create -
  B switch to provide an way to specify that boot partition should be created.
  However, there is still an question, how big should the system partition be.
  For time being, I have set default size 256MB (thats minimum size for FAT32
  with 4k blocks). To support custom size, the set on creation "bootsize"
  property is created and so the custom size can be set as: zpool create B -
  o bootsize=34MB rpool c0t0d0
  After pool is created, the "bootsize" property is read only. When -B switch is
  not used, the bootsize defaults to 0 and is shown in zpool get output with
  value ''. Older zfs/zpool implementations are ignoring this property.
  https://www.illumos.org/rb/r/219/

Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
Reviewed by: Yuri Pankov <yuri.pankov@gmail.com>
Approved by: Dan McDonald <danmcd@kebe.com>
Author: Toomas Soome <tsoome@me.com>

This commit makes no sense for FreeBSD, that is why I blocked the option,
but it should be good to stay closer to upstream.

6 years agolualoader: When restoring environment, only restore unchanged vars
Kyle Evans [Tue, 20 Feb 2018 22:47:49 +0000 (22:47 +0000)]
lualoader: When restoring environment, only restore unchanged vars

Track the latest value we've set an environment variable to, and only
restore those that are unchanged from that.

This gives us some leeway to make sure we're not clobbering variables
overwritten by menu changes.

6 years agoProperly lookup values if they were empty.
Bryan Drewery [Tue, 20 Feb 2018 22:03:08 +0000 (22:03 +0000)]
Properly lookup values if they were empty.

Spotted by: rpokala
X-MFC-With: r329676
MFC after: 2 weeks
Sponsored by: Dell EMC

6 years agoOnly lookup SVN once and rename to SVN_CMD.
Bryan Drewery [Tue, 20 Feb 2018 22:03:04 +0000 (22:03 +0000)]
Only lookup SVN once and rename to SVN_CMD.

MFC after: 2 weeks
Sponsored by: Dell EMC

6 years agoAvoid looking up VCS_REVISION for every sub-make call to Makefile.inc1.
Bryan Drewery [Tue, 20 Feb 2018 21:53:39 +0000 (21:53 +0000)]
Avoid looking up VCS_REVISION for every sub-make call to Makefile.inc1.

MFC after: 2 weeks
Sponsored by: Dell EMC

6 years agoMove SVNVERSION_CMD into the one place that uses it.
Bryan Drewery [Tue, 20 Feb 2018 21:48:16 +0000 (21:48 +0000)]
Move SVNVERSION_CMD into the one place that uses it.

This code, which is basically `svnversion || svnliteversion`, generates
2 fstatat(2) for every directory in PATH for every Makefile parsed that
includes bsd.own.mk.  This can add up for things like generating a Ports
index (Poudriere) or building a dependency graph for base.

Sponsored by: Dell EMC
MFC after: 2 weeks

6 years agoCatch up with the removal of nktr_slot_flags from upstream netmap. No
Navdeep Parhar [Tue, 20 Feb 2018 21:42:45 +0000 (21:42 +0000)]
Catch up with the removal of nktr_slot_flags from upstream netmap.  No
functional impact intended.

Submitted by: Vincenzo Maffione <v.maffione@gmail.com>

6 years agolualoader: Intercept the 'autoboot' cli command
Kyle Evans [Tue, 20 Feb 2018 21:37:55 +0000 (21:37 +0000)]
lualoader: Intercept the 'autoboot' cli command

6 years agolualoader: Intercept boot cli command
Kyle Evans [Tue, 20 Feb 2018 21:32:36 +0000 (21:32 +0000)]
lualoader: Intercept boot cli command

This should be functional and roughly equivalent to the Forth version.

Stop doing a loadelf() on menu exit now that we can DTRT with boot
invocations. autoboot interception will follow not long after.

6 years agoFix the broken subqueue assignment for the cleanq.
Jeff Roberson [Tue, 20 Feb 2018 21:27:17 +0000 (21:27 +0000)]
Fix the broken subqueue assignment for the cleanq.

Reported by: pho
Tested by: pho
Sponsored by: Netflix, Dell/EMC Isilon

6 years agolualoader: Prepare for interception of "boot" CLI cmd
Kyle Evans [Tue, 20 Feb 2018 21:23:01 +0000 (21:23 +0000)]
lualoader: Prepare for interception of "boot" CLI cmd

core.boot and core.autoboot may both take arguments; add a helper to cleanly
append an argstring to the given loader command.

Also provide a popFrontTable() that we'll use pop the command name off of an
argv table. We don't have the table library included, and including it is
non-trivial, so we'll implement this one function that we need in lua for
the time being.

6 years agolualoader: Don't try so hard to load a kernel
Kyle Evans [Tue, 20 Feb 2018 21:15:43 +0000 (21:15 +0000)]
lualoader: Don't try so hard to load a kernel

If the user's selected a kernel, we really should be trying to load that one
instead of falling back to some default kernel.

This should generally be a no-op and most desirable, unless you really
enjoyed surprises.

6 years agolualoader: Prefer selected kernel to currently loaded
Kyle Evans [Tue, 20 Feb 2018 21:13:21 +0000 (21:13 +0000)]
lualoader: Prefer selected kernel to currently loaded

6 years agoMFV r316918: 7990 libzfs: snapspec_cb() does not need to call zfs_strdup()
Alexander Motin [Tue, 20 Feb 2018 20:46:27 +0000 (20:46 +0000)]
MFV r316918: 7990 libzfs: snapspec_cb() does not need to call zfs_strdup()

illumos/illumos-gate@d8584ba6fb7a5e46da1725845b99ae5fab5a4baf
https://github.com/illumos/illumos-gate/commit/d8584ba6fb7a5e46da1725845b99ae5fab5a4baf

https://www.illumos.org/issues/7990
  The snapspec_cb() callback function in libzfs does not need to call zfs_strdup().

Reviewed by: Yuri Pankov <yuri.pankov@gmail.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Matthew Ahrens <mahrens@delphix.com>
Author: Marcel Telka <marcel@telka.sk>

6 years agoMFV r316902: 7745 print error if lzc_* is called before libzfs_core_init
Alexander Motin [Tue, 20 Feb 2018 20:40:55 +0000 (20:40 +0000)]
MFV r316902: 7745 print error if lzc_* is called before libzfs_core_init

illumos/illumos-gate@7c13517fff71be473e47531ef4330160c042bedc
https://github.com/illumos/illumos-gate/commit/7c13517fff71be473e47531ef4330160c042bedc

https://www.illumos.org/issues/7745
  The problem is that consumers of `libZFS_Core` that forget to call
  `libzfs_core_init()` before calling any other function of the library
  are having a hard time realizing their mistake. The library's internal
  file descriptor is declared as global static, which is ok, but it is not
  initialized explicitly; therefore, it defaults to 0, which is a valid
  file descriptor. If `libzfs_core_init()`, which explicitly initializes
  the correct fd, is skipped, the ioctl functions return errors that do
  not have anything to do with `libZFS_Core`, where the problem is
  actually located.
  Even though assertions for that existed within `libZFS_Core` for debug
  builds, they were never enabled because the `-DDEBUG` flag was missing
  from the compiler flags.
  This patch applies the following changes:
  1. It adds `-DDEBUG` for debug builds of `libZFS_Core` and `libzfs`,
         to enable their assertions on debug builds.
  2. It corrects an assertion within `libzfs`, where a function had
         been spelled incorrectly (`zpool_prop_unsupported()`) and nobody
         knew because the `-DDEBUG` flag was missing, and the preprocessor
         was taking that part of the code away.
  3. The library's internal fd is initialized to `-1` and `VERIFY`
         assertions have been placed to check that the fd is not equal to
         `-1` before issuing any ioctl. It is important here to note, that
         the `VERIFY` assertions exist in both debug and non-debug builds.
  4. In `libzfs_core_fini` we make sure to never increment the
         refcount of our fd below 0, and also reset the fd to `-1` when no
         one refers to it. The reason for this, is for the rare case that
         the consumer closes all references but then calls one of the
         library's functions without using `libzfs_core_init()` first, and
         in the mean time, a previous call to `open()` decided to reuse
         our previous fd. This scenario would have passed our assertion in

Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Dan McDonald <danmcd@omniti.com>
Author: Serapheim Dimitropoulos <serapheim@delphix.com>

6 years agomtx: add debug assertions to mtx_spin_wait_unlocked
Mateusz Guzik [Tue, 20 Feb 2018 20:39:34 +0000 (20:39 +0000)]
mtx: add debug assertions to mtx_spin_wait_unlocked

6 years agoMFV r316901:
Alexander Motin [Tue, 20 Feb 2018 20:37:01 +0000 (20:37 +0000)]
MFV r316901:
7730 libzfs`add_config() leaks config nvl when reading spare/l2cache devices

illumos/illumos-gate@105686550ee9cbf5d033166a8a2a5a763667d436
https://github.com/illumos/illumos-gate/commit/105686550ee9cbf5d033166a8a2a5a763667d436

https://www.illumos.org/issues/7730
  antares:root:~# mdb /usr/sbin/zpool
  > ::sysbp _exit
  > ::run import
     pool: data
       id: 2093977168778024605
    state: ONLINE
   action: The pool can be imported using its name or numeric identifier.
   config:

          data        ONLINE
            c6t0d0    ONLINE
            c6t1d0    ONLINE
          cache
            c6t2d0
  mdb: stop on entry to _exit
  mdb: target stopped at:
  0xfee556ba:     nop
  mdb: You've got symbols!
  Loading modules: [ ld.so.1 libumem.so.1 libc.so.1 libtopo.so.1 libavl.so.1
  libnvpair.so.1 ]
  > ::findleaks -d
  BYTES             LEAKED VMEM_SEG CALLER
  4096                  10 fda7b000 MMAP
  8192                   1 fea8d000 MMAP
  8192                   1 fe76d000 MMAP
  8192                   1 fe66e000 MMAP
  4096                   1 fe570000 MMAP
  8192                   1 fe470000 MMAP
  4096                   1 fe372000 MMAP
  4096                   1 fe273000 MMAP

Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Serapheim Dimitropoulos <serapheim@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Author: Yuri Pankov <yuri.pankov@nexenta.com>

6 years agoMFV r316893:
Alexander Motin [Tue, 20 Feb 2018 20:34:04 +0000 (20:34 +0000)]
MFV r316893:
7604 if volblocksize property is the default, it displays as "-" rather than 8K

illumos/illumos-gate@4d86c0eab246bdfddc2dd52410ba808433bd6266
https://github.com/illumos/illumos-gate/commit/4d86c0eab246bdfddc2dd52410ba808433bd6266

https://www.illumos.org/issues/7604
  If a zvol has the default setting for the "volblocksize" property, it is
  8KB. However, it is displayed as "-" (not present), rather than "8K".
  The problem was introduced by:
  commit 25228e830e86924a41243343b1de9daf2d7dd43a
      Author: Matthew Ahrens &lt;mahrens@delphix.com&gt;
      Date:   Thu Nov 17 14:37:24 2016 -0800
  7571 non-present readonly numeric ZFS props do not have default value
  which changed changed get_numeric_property() to indicate that readonly
  default properties are not present. However, zfs_prop_readonly() returns
  TRUE for both readonly and set-once properties (e.g. volblocksize).
  Amusingly, that commit essentially reverted:
  6900484 default volblocksize is no longer being reported correctly
  from November 2009. However, that change was not correct either; the
  correct solution is to only do this check for "truly readonly" (i.e. not
  setonce) properties.
  $ zfs list -t volume -o name,volblocksize
      NAME
  VOLBLOCK
      domain0/group-100/appdata_container-101/appdata_windows_timeflow-102/
  archive            -
      domain0/group-100/appdata_container-101/appdata_windows_timeflow-102/
  datafile           -
      domain0/group-100/appdata_container-101/appdata_windows_timeflow-102/
  external           -
      rpool/dump
  128K
      rpool/swap
  4K
      rpool/swap1
  ===============================================================================

Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: John Kennedy <john.kennedy@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Author: Matthew Ahrens <mahrens@delphix.com>

6 years agoMFV r316876: 7542 zfs_unmount failed with EZFS_UNSHARENFSFAILED
Alexander Motin [Tue, 20 Feb 2018 20:30:40 +0000 (20:30 +0000)]
MFV r316876: 7542 zfs_unmount failed with EZFS_UNSHARENFSFAILED

illumos/illumos-gate@09c9e6dc9b69d10b771bb87e01040ec320a0bfd3
https://github.com/illumos/illumos-gate/commit/09c9e6dc9b69d10b771bb87e01040ec320a0bfd3

https://www.illumos.org/issues/7542
  libshare keeps a cached copy of the sharetab listing in memory, which can
  become out of date if shares are destroyed or created while leaving a libzfs
  handle open. This results in a spurious unmounting failure when an NFS share
  exists but isn't in the stale libshare cache.

Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Matt Amdur <matt.amdur@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Author: Chris Williamson <chris.williamson@delphix.com>

6 years agolualoader: Replace invalid construct with valid construct
Kyle Evans [Tue, 20 Feb 2018 20:29:41 +0000 (20:29 +0000)]
lualoader: Replace invalid construct with valid construct

It only worked by coincidence, but it did work. Store varargs in a table
instead and work off of that.

6 years agoMFV r316875: 7336 vfork and O_CLOEXEC causes zfs_mount EBUSY
Alexander Motin [Tue, 20 Feb 2018 20:26:48 +0000 (20:26 +0000)]
MFV r316875: 7336 vfork and O_CLOEXEC causes zfs_mount EBUSY

illumos/illumos-gate@873c4903a52d089cd8234b79d24f5a3fc3bccc82
https://github.com/illumos/illumos-gate/commit/873c4903a52d089cd8234b79d24f5a3fc3bccc82

https://www.illumos.org/issues/7336
  We can run into a problem where we call into zfs_mount, which in turn calls
  is_dir_empty, which opens the directory to try and make sure it's empty. The
  issue with the current approach is that it holds the directory open while it
  traverses it with readdir, which, due to subtle interaction with the Java JVM,
  vfork, and exec can cause a tricky race condition resulting in zfs_mount
  failures.
  The approach to resolving the issue in this patch is to drop the usage of
  readdir altogether, and instead rely on the fact that ZFS stores the number of
  entries contained in a directory using the st_size field of the stat structure.
  Thus, if the directory in question is a ZFS directory, we can check to see if
  it's empty by calling stat() and inspecting the st_size field of structure
  returned.
  ===============================================================================
  The root cause appears to be an interesting race between vfork, exec, and
  zfs_mount's usage of O_CLOEXEC when calling openat. Here's what is going on:
  1. We call zfs_mount, and this in turn calls openat to check if the directory
  is empty, which results in opening the directory we're trying to mount onto,
  and increment v_count.
  2. As we're in the middle of reading the directory, vfork is called by the JVM
  and proceeds to exec the jspawnhelper utility. As a result of the vfork, we
  take an additional hold on the directory, which increments v_count a second
  time. The semantics of vfork mean the parent process will wait for the child
  process to exit or exec before the parent can continue; at this point the
  parent is in the middle of zfs_mount, reading the directory to determine if
  it's empty or not.
  3. The child process exec-ing jspawnhelper gets to the relvm call within
  exec_args (which is called by exec_common). relvm is the function that releases
  the parent process, allowing the parent to proceed. The problem is, at this
  point of calling relvm, the child hasn't yet called close_exec which is
  responsible for closing the file descriptors inherited from the parent process

Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Approved by: Dan McDonald <danmcd@omniti.com>
Author: Prakash Surya <prakash.surya@delphix.com>

6 years agoFix reaping on process fd close broken after r329449
Mateusz Guzik [Tue, 20 Feb 2018 20:19:38 +0000 (20:19 +0000)]
Fix reaping on process fd close broken after r329449

The only consumer of proc_reap other than proc_to_reap was not updated
to not PROC_SLOCK.

Reported by:    Juan Ramon Molina Menor <listjm club.fr>