zfs.git
13 years agoMinimal libshare infrastructure
Brian Behlendorf [Thu, 16 Dec 2010 21:47:30 +0000 (13:47 -0800)]
Minimal libshare infrastructure

ZFS even under Solaris does not strictly require libshare to be
available.  The current implementation attempts to dlopen() the
library to access the needed symbols.  If this fails libshare
support is simply disabled.

This means that on Linux we only need the most minimal libshare
implementation.  In fact just enough to prevent the build from
failing.  Longer term we can decide if we want to implement a
libshare library like Solaris.  At best this would be an abstraction
layer between ZFS and NFS/SMB.  Alternately, we can drop libshare
entirely and directly integrate ZFS with Linux's NFS/SMB.

Finally the bare bones user-libshare.m4 test was dropped.  If we
do decide to implement libshare at some point it will surely be
as part of this package so the check is not needed.

13 years agoAdd 'zfs mount' support
Brian Behlendorf [Fri, 17 Dec 2010 00:16:25 +0000 (16:16 -0800)]
Add 'zfs mount' support

By design the zfs utility is supposed to handle mounting and unmounting
a zfs filesystem.  We could allow zfs to do this directly.  There are
system calls available to mount/umount a filesystem.  And there are
library calls available to manipulate /etc/mtab.  But there are a
couple very good reasons not to take this appraoch... for now.

Instead of directly calling the system and library calls to (u)mount
the filesystem we fork and exec a (u)mount process.  The principle
reason for this is to delegate the responsibility for locking and
updating /etc/mtab to (u)mount(8).  This ensures maximum portability
and ensures the right locking scheme for your version of (u)mount
will be used.  If we didn't do this we would have to resort to an
autoconf test to determine what locking mechanism is used.

The downside to using mount(8) instead of mount(2) is that we lose
the exact errno which was returned by the kernel.  The return code
from mount(8) provides some insight in to what went wrong but it
not quite as good.  For the moment this is translated as a best
guess in to a errno for the higher layers of zfs.

In the long term a shared library called libmount is under development
which provides a common API to address the locking and errno issues.
Once the standard mount utility has been updated to use this library
we can then leverage it.  Until then this is the only safe solution.

  http://www.kernel.org/pub/linux/utils/util-linux/libmount-docs/index.html

13 years agoOpen up libzfs_run_process/libzfs_load_module
Brian Behlendorf [Thu, 16 Dec 2010 23:47:40 +0000 (15:47 -0800)]
Open up libzfs_run_process/libzfs_load_module

Recently helper functions were added to libzfs_util to load a kernel
module or execute a process.  Initially this functionality was limited
to libzfs but it has become clear there will be other consumers.  This
change opens up the interface so it may be used where appropriate.

13 years agoDisable umount.zfs helper
Brian Behlendorf [Thu, 16 Dec 2010 20:56:10 +0000 (12:56 -0800)]
Disable umount.zfs helper

For the moment, the only advantage in registering a umount helper
would be to automatically unshare a zfs filesystem.  Since under
Linux this would be unexpected (but nice) behavior there is no
harm in disabling it.

This is desirable because the 'zfs unmount' path invokes the system
umount.  This is done to ensure correct mtab locking but has the
side effect that the umount.zfs helper would be called if it exists.
By default this helper calls back in to zfs to do the unmount on
Solaris which we don't want under Linux.

Once libmount is available and we have a safe way to correctly
lock and update the /etc/mtab file we can reconsider the need
for a umount helper.  Using libmount is the prefered solution.

13 years agoEnable mount.zfs helper
Brian Behlendorf [Thu, 9 Dec 2010 00:40:11 +0000 (16:40 -0800)]
Enable mount.zfs helper

While not strictly required to mount a zfs filesystem using a
mount helper has certain advantages.

First, we need it if we want to honor the mount behavior as found
on Solaris.  As part of the mount we need to validate that the
dataset has the legacy mount property set if we are using 'mount'
instead of 'zfs mount'.

Secondly, by using a mount helper we can automatically load the
zpl kernel module.  This way you can just issue a 'mount' or
'zfs mount' and it will just work.

Finally, it gives us common hook in user space to add any zfs
specific mount options we might want.  At the moment we don't
have any but now the infrastructure is at least in place.

13 years agoAutoconf selinux support
Brian Behlendorf [Thu, 16 Dec 2010 22:26:08 +0000 (14:26 -0800)]
Autoconf selinux support

If libselinux is detected on your system at configure time link
against it.  This allows us to use a library call to detect if
selinux is enabled and if it is to pass the mount option:

  "context=\"system_u:object_r:file_t:s0"

For now this is required because none of the existing selinux
policies are aware of the zfs filesystem type.  Because of this
they do not properly enable xattr based labeling even though
zfs supports all of the required hooks.

Until distro's add zfs as a known xattr friendly fs type we
must use mntpoint labeling.  Alternately, end users could modify
their existing selinux policy with a little guidance.

13 years agoFix ZVOL rename minor devices
Brian Behlendorf [Fri, 7 Jan 2011 20:24:03 +0000 (12:24 -0800)]
Fix ZVOL rename minor devices

During a rename we need to be careful to destroy and create a
new minor for the ZVOL _only_ if the rename succeeded.  The previous
code would both destroy you minor device unconditionally, it would
also fail to create the new minor device on success.

13 years agoFix minor compiler warnings
Brian Behlendorf [Thu, 16 Dec 2010 22:05:42 +0000 (14:05 -0800)]
Fix minor compiler warnings

These compiler warnings were introduced when code which was
previously #ifdef'ed out by HAVE_ZPL was re-added for use
by the posix layer.  All of the following changes should be
obviously correct and will cause no semantic changes.

13 years agoAdd missing mkdirp prototype
Brian Behlendorf [Fri, 10 Dec 2010 20:54:30 +0000 (12:54 -0800)]
Add missing mkdirp prototype

For while now mkdirp has been built as part of libspl however
the protoype was never added to libgen.h.  This went unnoticed
until enabling the mount support which uses mkdirp().

13 years agoUse cv_timedwait_interruptible in arc
Brian Behlendorf [Fri, 10 Dec 2010 20:00:00 +0000 (12:00 -0800)]
Use cv_timedwait_interruptible in arc

The issue is that cv_timedwait() sleeps uninterruptibly to block signals
and avoid waking up early.  Under Linux this counts against the load
average keeping it artificially high.  This change allows the arc to
sleep interruptibly which mean it may be woken up early due to a signal.

Normally this means some extra care must be taken to handle a potential
signal.  But for the arcs usage of cv_timedwait() there is no harm in
waking up before the timeout expires so no extra handling is required.

13 years agoFix block device-related issues in zdb.
Ricardo M. Correia [Tue, 14 Dec 2010 17:50:37 +0000 (09:50 -0800)]
Fix block device-related issues in zdb.

Specifically, this fixes the two following errors in zdb when a pool
is composed of block devices:

1) 'Value too large for defined data type' when running 'zdb <dataset>'.
2) 'character device required' when running 'zdb -l <block-device>'.

Signed-off-by: Ricardo M. Correia <ricardo.correia@oracle.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoEnable rrwlock.c compilation
Brian Behlendorf [Wed, 8 Dec 2010 00:05:25 +0000 (16:05 -0800)]
Enable rrwlock.c compilation

With the addition of the thread specific data interfaces to the
SPL it is safe to enable compilation of the re-enterant read
reader/writer locks.

13 years agoRefresh autogen.sh products
Brian Behlendorf [Tue, 7 Dec 2010 23:33:12 +0000 (15:33 -0800)]
Refresh autogen.sh products

Refresh the autogen.sh products based on the versions which are
installed by default in the GA RHEL6.0 release.

autoconf (GNU Autoconf) 2.63
automake (GNU automake) 1.11.1
ltmain.sh (GNU libtool) 2.2.6b

13 years agoRemove partition from vdev name in zfault.sh
Ned Bass [Tue, 23 Nov 2010 19:19:57 +0000 (11:19 -0800)]
Remove partition from vdev name in zfault.sh

As of the 0.5.2 tag, names of whole-disk vdevs must be specified to
the command line tools without partition identifiers.  This commit
fixes a 'zpool online' command in zfault.sh that incorrectly includes
he partition in the vdev name, causing test 9 to fail.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoSkip /dev/hpet during 'zpool import'
Brian Behlendorf [Fri, 12 Nov 2010 17:33:17 +0000 (09:33 -0800)]
Skip /dev/hpet during 'zpool import'

If libblkid does not contain ZFS support, then 'zpool import' will scan
all block devices in /dev/ to determine which ones are components of a
ZFS filesystem.  It does this by opening all the devices and stat'ing
them to determine which ones are block devices.  If the device turns
out not to be a block device it is skipped.

Usually, this whole process is pretty harmless (although slow).  But
there are certain devices in /dev/ which must be handled in a very
specific way or your system may crash.  For example, if /dev/watchdog
is simply opened the watchdog timer will be started and your system
will panic when the timer expires.

It turns out the /dev/hpet causes similiar problems although only when
accessed under a virtual machine.  For some reason accessing /dev/hpet
causes qemu to crash.  To address this issue this commit adds /dev/hpet
to the device blacklist, it will be skipped solely based on its name.

13 years agoAdd '-ts' options to zconfig.sh/zfault.sh usage
Brian Behlendorf [Thu, 11 Nov 2010 18:22:36 +0000 (10:22 -0800)]
Add '-ts' options to zconfig.sh/zfault.sh usage

When adding this functionality originally the options to only
run specific tests (-t), or conversely skip specific tests (-s)
were omitted from the usage page.  This commit adds the missing
documentation.

13 years agoRemove spl/zfs modules as part of cleanup
Brian Behlendorf [Thu, 11 Nov 2010 18:17:02 +0000 (10:17 -0800)]
Remove spl/zfs modules as part of cleanup

The idea behind the '-c' flag is to cleanup everything from a
previous test run which might cause the test script to fail.
This should also include removing the previously loaded module.
This makes it a little easier to run 'zconfig.sh -c', however
remember this is a test script and it will take all of your
other zpools offline for the purposes of the test.  This notion
has also been extended to the default 'make check' behavior.

13 years agoUnconditionally load core kernel modules
Brian Behlendorf [Thu, 11 Nov 2010 18:00:39 +0000 (10:00 -0800)]
Unconditionally load core kernel modules

Loading and unloading the zlib modules as part of the zfs.sh
script has proven a little problematic for a few reasons.

  * First, your kernel may not need to load either zlib_inflate
    or zlib_deflate.  This functionality may be built directly in
    to your kernel.  It depends entirely on what your distribution
    decided was the right thing to do.

  * Second, even if you do manage to load the correct modules you
    may not be able to unload them.  There may other consumers
    of the modules with a reference preventing the unload.

To avoid both of these issues the test scripts have been updated to
attempt to unconditionally load all modules listed in KERNEL_MODULES.
If the module is successfully loaded you must have needed it. If
the module can't be loaded that almost certainly means either it is
built in to your kernel or is already being used by another consumer.
In both cases this is not an issue and we can move on to the spl/zfs
modules.

Finally, by removing these kernel modules from the MODULES list
we ensure they are never unloaded during 'zfs.sh -u'.  This avoids
the issue of the script failing because there is another consumer
using the module we were not aware of.  In other words the script
restricts unloading modules to only the spl/zfs modules.

Closes #78

13 years agoFix for access beyond end of device error
Ned Bass [Wed, 10 Nov 2010 21:36:18 +0000 (13:36 -0800)]
Fix for access beyond end of device error

This commit fixes a sign extension bug affecting l2arc devices.  Extremely
large offsets may be passed down to the low level block device driver on
reads, generating errors similar to

    attempt to access beyond end of device
    sdbi1: rw=14, want=36028797014862705, limit=125026959

The unwanted sign extension occurrs because the function arc_read_nolock()
stores the offset as a daddr_t, a 32-bit signed int type in the Linux kernel.
This offset is then passed to zio_read_phys() as a uint64_t argument, causing
sign extension for values of 0x80000000 or greater.  To avoid this, we store
the offset in a uint64_t.

This change also changes a few daddr_t struct members to uint64_t in the libspl
headers to avoid similar bugs cropping up in the future.  We also add an ASSERT
to __vdev_disk_physio() to check for invalid offsets.

Closes #66
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoLinux 2.6.36 compat, use fops->unlocked_ioctl()
Brian Behlendorf [Thu, 11 Nov 2010 00:44:20 +0000 (16:44 -0800)]
Linux 2.6.36 compat, use fops->unlocked_ioctl()

As of linux-2.6.36 the last in-tree consumer of fops->ioctl() has
been removed and thus fops()->ioctl() has also been removed.  The
replacement hook is fops->unlocked_ioctl() which has existed in
kernel since 2.6.12.  Since the ZFS code only contains support
back to 2.6.18 vintage kernels, I'm not adding an autoconf check
for this and simply moving everything to use fops->unlocked_ioctl().

13 years agoLinux 2.6.36 compat, blk_* macros removed
Brian Behlendorf [Thu, 11 Nov 2010 00:38:14 +0000 (16:38 -0800)]
Linux 2.6.36 compat, blk_* macros removed

Most of the blk_* macros were removed in 2.6.36.  Ostensibly this was
done to improve readability and allow easier grepping.  However, from
a portability stand point the macros are helpful.  Therefore the needed
macros are redefined here if they are missing from the kernel.

13 years agoLinux 2.6.36 compat, synchronous bio flag
Brian Behlendorf [Wed, 10 Nov 2010 23:49:40 +0000 (15:49 -0800)]
Linux 2.6.36 compat, synchronous bio flag

The name of the flag used to mark a bio as synchronous has changed
again in the 2.6.36 kernel due to the unification of the BIO_RW_*
and REQ_* flags.  The new flag is called REQ_SYNC.  To simplify
checking this flag I have introduced the vdev_disk_dio_is_sync()
helper function.  Based on the results of several new autoconf
tests it uses the correct mask to check for a synchronous bio.

Preferred interface for flagging a synchronous bio:
  2.6.12-2.6.29: BIO_RW_SYNC
  2.6.30-2.6.35: BIO_RW_SYNCIO
  2.6.36-2.6.xx: REQ_SYNC

13 years agoLinux 2.6.36 compat, use REQ_FAILFAST_MASK
Brian Behlendorf [Wed, 10 Nov 2010 22:40:38 +0000 (14:40 -0800)]
Linux 2.6.36 compat, use REQ_FAILFAST_MASK

As of linux-2.6.36 the BIO_RW_FAILFAST and REQ_FAILFAST flags
have been unified under the REQ_* names.  These flags always had
to be kept in-sync so this is a nice step forward, unfortunately
it means we need to be careful to only use the new unified flags
when the BIO_RW_* flags are not defined.  Additional autoconf
checks were added for this and if it is ever unclear which method
to use no flags are set.  This is safe but may result in longer
delays before a disk is failed.

Perferred interface for setting FAILFAST on a bio:
  2.6.12-2.6.27: BIO_RW_FAILFAST
  2.6.28-2.6.35: BIO_RW_FAILFAST_{DEV|TRANSPORT|DRIVER}
  2.6.36-2.6.xx: REQ_FAILFAST_{DEV|TRANSPORT|DRIVER}

13 years agoRemove inconsistent use of EOPNOTSUPP
Ned Bass [Tue, 9 Nov 2010 22:20:01 +0000 (14:20 -0800)]
Remove inconsistent use of EOPNOTSUPP

Commit 3ee56c292bbcd7e6b26e3c2ad8f0e50eee236bcc changed an ENOTSUP return value
in one location to ENOTSUPP to fix user programs seeing an invalid ioctl()
error code.  However, use of ENOTSUP is widespread in the zfs module.  Instead
of changing all of those uses, we fixed the ENOTSUP definition in the SPL to be
consistent with user space.  The changed return value in the above commit is
therefore no longer needed, so this commit reverses it to maintain consistency.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd lustre zpios-test workload
Brian Behlendorf [Fri, 5 Nov 2010 19:29:58 +0000 (12:29 -0700)]
Add lustre zpios-test workload

The lustre zpios-test simulates a reasonable lustre workload.  It will
create 128 threads, the same as a Lustre OSS, and then 4096 individual
objects.  Each objects is 16MiB in size and will be written/read in 1MiB
from a random thread.  This is fundamentally how we expect Lustre to behave
for large IO intensive workloads.

13 years agoPrep for 0.5.2 tag
Brian Behlendorf [Fri, 5 Nov 2010 18:51:24 +0000 (11:51 -0700)]
Prep for 0.5.2 tag

Update META file to prep for 0.5.2 tag.

13 years agoReplace custom zpool configs with generic configs
Brian Behlendorf [Fri, 5 Nov 2010 18:43:20 +0000 (11:43 -0700)]
Replace custom zpool configs with generic configs

To streamline testing I have in the past added several custom configs
to the zpool-config directory.  This change reverts those custom configs
and replaces them with three generic config which can do the same thing.
The generic config behavior can be set by setting various environment
variables when calling either the zpool-create.sh or zpios.sh scripts.

For example if you wanted to create and test a single 4-disk Raid-Z2
configuration using disks [A-D]1 with dedicated ZIL and L2ARC devices
you could run the following.

$ ZIL="log A2" L2ARC="cache B2" RANKS=1 CHANNELS=4 LEVEL=2 \
  zpool-create.sh -c zpool-raidz

$ zpool status tank
  pool: tank
 state: ONLINE
 scan: none requested
config:

      NAME        STATE     READ WRITE CKSUM
      tank        ONLINE       0     0     0
        raidz2-0  ONLINE       0     0     0
          A1      ONLINE       0     0     0
          B1      ONLINE       0     0     0
          C1      ONLINE       0     0     0
          D1      ONLINE       0     0     0
      logs
        A2        ONLINE       0     0     0
      cache
        B2        ONLINE       0     0     0

errors: No known data errors

13 years agoMake rollbacks fail gracefully
Ned Bass [Fri, 29 Oct 2010 22:27:03 +0000 (15:27 -0700)]
Make rollbacks fail gracefully

Support for rolling back datasets require a functional ZPL, which we currently
do not have.  The zfs command does not check for ZPL support before attempting
a rollback, and in preparation for rolling back a zvol it removes the minor
node of the device.  To prevent the zvol device node from disappearing after a
failed rollback operation, this change wraps the zfs_do_rollback() function in
an #ifdef HAVE_ZPL and returns ENOSYS in the absence of a ZPL.  This is
consistent with the behavior of other ZPL dependent commands such as mount.

The orginal error message observed with this bug was rather confusing:

    internal error: Unknown error 524
    Aborted

This was because zfs_ioc_rollback() returns ENOTSUP if we don't HAVE_ZPL, but
Linux actually has no such error code.  It should instead return EOPNOTSUPP, as
that is how ENOTSUP is defined in user space.  With that we would have gotten
the somewhat more helpful message

    cannot rollback 'tank/fish': unsupported version

This is rather a moot point with the above changes since we will no longer make
that ioctl call without a ZPL.  But, this change updates the error code just in
case.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoIncreate zio write interrupt thread count.
Brian Behlendorf [Thu, 28 Oct 2010 17:42:38 +0000 (10:42 -0700)]
Increate zio write interrupt thread count.

Increasing the default zio_wr_int thread count from 8 to 16 improves
write performence by 13% on large systems.  More testing need to be
done but I suspect the ideal tuning here is ZTI_BATCH() with a minimum
of 8 threads.

13 years agoShorten zio_* thread names
Brian Behlendorf [Thu, 28 Oct 2010 17:36:50 +0000 (10:36 -0700)]
Shorten zio_* thread names

Linux kernel thread names are expected to be short.  This change shortens
the zio thread names to 10 characters leaving a few chracters to append
the /<cpuid> to which the thread is bound.  For example: z_wr_iss/0.

13 years agoFix panic mounting unformatted zvol
Ned Bass [Fri, 29 Oct 2010 19:13:52 +0000 (12:13 -0700)]
Fix panic mounting unformatted zvol

On some older kernels, i.e. 2.6.18, zvol_ioctl_by_inode() may get passed a NULL
file pointer if the user tries to mount a zvol without a filesystem on it.
This change adds checks to prevent a null pointer dereference.

Closes #73.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoCall modprobe with absolute path
Ned Bass [Fri, 22 Oct 2010 18:13:16 +0000 (11:13 -0700)]
Call modprobe with absolute path

Some sudo configurations may not include /sbin in the PATH.
libzfs_load_module() currently does not call modprobe with an absolute path, so
it may fail under such configurations if called under sudo.  This change adds
the absolute path to modprobe so we no longer rely on how PATH is set.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoFix intermittent 'zpool add' failures
Ned Bass [Fri, 22 Oct 2010 00:08:30 +0000 (17:08 -0700)]
Fix intermittent 'zpool add' failures

Creating whole-disk vdevs can intermittently fail if a udev-managed symlink to
the disk partition is already in place.  To avoid this, we now remove any such
symlink before partitioning the disk.  This makes zpool_label_disk_wait() truly
wait for the new link to show up instead of returning if it finds an old link
still in place.  Otherwise there is a window between when udev deletes and
recreates the link during which access attempts will fail with ENOENT.

Also, clean up a comment about waiting for udev to create symlinks.  It no
longer needs to describe the special cases for the link names, since that is
now handled in a separate helper function.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd zconfig test for adding and removing vdevs
Ned Bass [Mon, 18 Oct 2010 18:07:20 +0000 (11:07 -0700)]
Add zconfig test for adding and removing vdevs

This test performs a sanity check of the zpool add and remove commands.  It
tests adding and removing both a cache disk and a log disk to and from a zpool.
Usage of both a shorthand device path and a full path is covered.  The test
uses a scsi_debug device as the disk to be added and removed.  This is done so
that zpool will see it as a whole disk and partition it, which it does not
currently done for loopback devices.  We want to verify that the manipulation
done to whole disks paths to hide the parition information does not break the
add/remove interface.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoRemove solaris-specific code from make_leaf_vdev()
Ned Bass [Mon, 18 Oct 2010 18:26:04 +0000 (11:26 -0700)]
Remove solaris-specific code from make_leaf_vdev()

Portability between Solaris and Linux isn't really an issue for us anymore, and
removing sections like this one helps simplify the code.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoSupport shorthand names with zpool remove
Ned Bass [Thu, 14 Oct 2010 00:27:41 +0000 (17:27 -0700)]
Support shorthand names with zpool remove

zpool status displays abbreviated vdev names without leading path components
and, in the case of whole disks, without partition information.  Also, the
zpool subcommands 'create' and 'add' support using shorthand devices names
without qualified paths.  Prior to this change, however, removing a device
generally required specifying its name as it is stored in the vdev label.  So
while zpool status might list a cache disk with a name like A16, removing it
would require a full path such as /dev/disk/zpool/A16-part1, which is
non-intuitive.

This change adds support for shorthand device names with the remove subcommand
so one can simply type, for example,

        zpool remove tank A16

A consequence of this change is that including the partition information when
removing a whole-disk vdev now results in an error.  While this is arguably the
correct behavior, it is a departure from how zpool previously worked in this
project.

This change removes the only reference to ctd_check_path(), so that function is
also removed to avoid compiler warnings.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd helper functions for manipulating device names
Ned Bass [Wed, 13 Oct 2010 23:16:25 +0000 (16:16 -0700)]
Add helper functions for manipulating device names

This change adds two helper functions for working with vdev names and paths.
zfs_resolve_shortname() resolves a shorthand vdev name to an absolute path
of a file in /dev, /dev/disk/by-id, /dev/disk/by-label, /dev/disk/by-path,
/dev/disk/by-uuid, /dev/disk/zpool.  This was previously done only in the
function is_shorthand_path(), but we need a general helper function to
implement shorthand names for additional zpool subcommands like remove.
is_shorthand_path() is accordingly updated to call the helper function.

There is a minor change in the way zfs_resolve_shortname() tests if a file
exists.  is_shorthand_path() effectively used open() and stat64() to test for
file existence, since its scope includes testing if a device is a whole disk
and collecting file status information.  zfs_resolve_shortname(), on the other
hand, only uses access() to test for existence and leaves it to the caller to
perform any additional file operations.  This seemed like the most general and
lightweight approach, and still preserves the semantics of is_shorthand_path().

zfs_append_partition() appends a partition suffix to a device path.  This
should be used to generate the name of a whole disk as it is stored in the vdev
label. The user-visible names of whole disks do not contain the partition
information, while the name in the vdev label does.   The code was lifted from
the function make_disks(), which now just calls the helper function.  Again,
having a helper function to do this supports general handling of shorthand
names in the user interface.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd zfault zpool configurations and tests
Brian Behlendorf [Tue, 28 Sep 2010 23:32:12 +0000 (16:32 -0700)]
Add zfault zpool configurations and tests

Eleven new zpool configurations were added to allow testing of various
failure cases.  The first 5 zpool configurations leverage the 'faulty'
md device type which allow us to simuluate IO errors at the block layer.
The last 6 zpool configurations leverage the scsi_debug module provided
by modern kernels.  This device allows you to create virtual scsi
devices which are backed by a ram disk.  With this setup we can verify
the full IO stack by injecting faults at the lowest layer.  Both methods
of fault injection are important to verifying the IO stack.

The zfs code itself also provides a mechanism for error injection
via the zinject command line tool.  While we should also take advantage
of this appraoch to validate the code it does not address any of the
Linux integration issues which are the most concerning.  For the
moment we're trusting that the upstream Solaris guys are running
zinject and would have caught internal zfs logic errors.

Currently, there are 6 r/w test cases layered on top of the 'faulty'
md devices.  They include 3 writes tests for soft/transient errors,
hard/permenant errors, and all writes error to the device.  There
are 3 matching read tests for soft/transient errors, hard/permenant
errors, and fixable read error with a write.  Although for this last
case zfs doesn't do anything special.

The seventh test case verifies zfs detects and corrects checksum
errors.  In this case one of the drives is extensively damaged and
by dd'ing over large sections of it.  We then ensure zfs logs the
issue and correctly rebuilds the damage.

The next  test cases use the scsi_debug configuration to injects error
at the bottom of the scsi stack.  This ensures we find any flaws in the
scsi midlayer or our usage of it.  Plus it stresses the device specific
retry, timeout, and error handling outside of zfs's control.

The eighth test case is to verify that the system correctly handles an
intermittent device timeout.  Here the scsi_debug device drops 1 in N
requests resulting in a retry either at the block level.  The ZFS code
does specify the FAILFAST option but it turns out that for this case
the Linux IO stack with still retry the command.  The FAILFAST logic
located in scsi_noretry_cmd() does no seem to apply to the simply
timeout case.  It appears to be more targeted to specific device or
transport errors from the lower layers.

The ninth test case handles a persistent failure in which the device
is removed from the system by Linux.  The test verifies that the failure
is detected, the device is made unavailable, and then can be successfully
re-add when brought back online.  Additionally, it ensures that errors
and events are logged to the correct places and the no data corruption
has occured due to the failure.

13 years agoFix missing 'zpool events'
Brian Behlendorf [Mon, 4 Oct 2010 23:21:04 +0000 (16:21 -0700)]
Fix missing 'zpool events'

It turns out that 'zpool events' over 1024 bytes in size where being
silently dropped.  This was discovered while writing the zfault.sh
tests to validate common failure modes.

This could occur because the zfs interface for passing an arbitrary
size nvlist_t over an ioctl() is to provide a buffer for the packed
nvlist which is usually big enough.  In this case 1024 byte is the
default.  If the kernel determines the buffer is to small it returns
ENOMEM and the minimum required size of the nvlist_t.  This was
working properly but in the case of 'zpool events' the event stream
was advanced dispite the error.  Thus the retry with the bigger
buffer would succeed but it would skip over the previous event.

The fix is to pass this size to zfs_zevent_next() and determine
before removing the event from the list if it will fit.  This was
preferable to checking after the event was returned because this
avoids the need to rewind the stream.

13 years agoInitial zio delay timing
Brian Behlendorf [Fri, 1 Oct 2010 23:54:52 +0000 (16:54 -0700)]
Initial zio delay timing

While there is no right maximum timeout for a disk IO we can start
laying the ground work to measure how long they do take in practice.
This change simply measures the IO time and if it exceeds 30s an
event is posted for 'zpool events'.

This value was carefully selected because for sd devices it implies
that at least one timeout (SD_TIMEOUT) has occured.  Unfortunately,
even with FAILFAST set we may retry and request and not get an
error.  This behavior is strongly dependant on the device driver
and how it is hooked in to the scsi error handling stack.  However
by setting the limit at 30s we can log the event even if no error
was returned.

Slightly longer term we can start recording these delays perhaps
as a simple power-of-two histrogram.  This histogram can then be
reported as part of the 'zpool status' command when given an command
line option.

None of this code changes the internal behavior of ZFS.  Currently
it is simply for reporting excessively long delays.

13 years agoAdd FAILFAST support
Brian Behlendorf [Fri, 1 Oct 2010 17:57:56 +0000 (10:57 -0700)]
Add FAILFAST support

ZFS works best when it is notified as soon as possible when a device
failure occurs.  This allows it to immediately start any recovery
actions which may be needed.  In theory Linux supports a flag which
can be set on bio's called FAILFAST which provides this quick
notification by disabling the retry logic in the lower scsi layers.

That's the theory at least.  In practice is turns out that while the
flag exists you oddly have to set it with the BIO_RW_AHEAD flag.
And even when it's set it you may get retries in the low level
drivers decides that's the right behavior, or if you don't get the
right error codes reported to the scsi midlayer.

Unfortunately, without additional kernels patchs there's not much
which can be done to improve this.  Basically, this just means that
it may take 2-3 minutes before a ZFS is notified properly that a
device has failed.  This can be improved and I suspect I'll be
submitting patches upstream to handle this.

13 years agoFix 'zpool events' formatting for awk
Brian Behlendorf [Tue, 28 Sep 2010 23:30:54 +0000 (16:30 -0700)]
Fix 'zpool events' formatting for awk

To make the 'zpool events' output simple to parse with awk the extra
newline after embedded nvlists has been dropped.  This allows the
entire event to be parsed as a single whitespace seperated record.

The -H option has been added to operate in scripted mode.  For the
'zpool events' command this means don't print the header.  The usage
of -H is consistent with scripted mode for other zpool commands.

13 years agoGenerate zevents for speculative and soft errors
Brian Behlendorf [Mon, 27 Sep 2010 23:55:05 +0000 (16:55 -0700)]
Generate zevents for speculative and soft errors

By default the Solaris code does not log speculative or soft io errors
in either 'zpool status' or post an event.  Under Linux we don't want
to change the expected behavior of 'zpool status' so these io errors
are still suppressed there.

However, since we do need to know about these events for Linux FMA and
the 'zpool events' interface is new we do post the events.  With the
addition of the zio_flags field the posted events now contain enough
information that a user space consumer can identify and discard these
events if it sees fit.

13 years agoFix negative zio->io_error which must be positive.
Brian Behlendorf [Mon, 27 Sep 2010 22:30:14 +0000 (15:30 -0700)]
Fix negative zio->io_error which must be positive.

All the upper layers of zfs expect zio->io_error to be positive.  I was
careful but I missed one instance in vdev_disk_physio_completion() which
could return a negative error.  To ensure all cases are always caught I
had additionally added an ASSERT() to check this before zio_interpret().

Finally, as a debugging aid when zfs is build with --enable-debug all
errors from the backing block devices will be reported to the console
with an error message like this:

ZFS: zio error=5 type=1 offset=4217856 size=8192 flags=60440

13 years agoSuppress large kmem_alloc() warning.
Brian Behlendorf [Mon, 27 Sep 2010 22:04:24 +0000 (15:04 -0700)]
Suppress large kmem_alloc() warning.

Observed during failure mode testing, dsl_scan_setup_sync() allocates
73920 bytes.  This is way over the limit of what is wise to do with a
kmem_alloc() and it should probably be moved to a slab.  For now I'm
just flagging it with KM_NODEBUG to quiet the error until this can be
revisited.

13 years agoFix undersized buffer in is_shorthand_path()
Ned Bass [Mon, 11 Oct 2010 21:48:52 +0000 (14:48 -0700)]
Fix undersized buffer in is_shorthand_path()

The string array 'char dirs[5][8]' was too small to accomodate the terminating
NUL character in "by-label". This change adds the needed additional byte.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoMake commands load zfs module on demand
Ned Bass [Thu, 7 Oct 2010 01:00:55 +0000 (18:00 -0700)]
Make commands load zfs module on demand

This commit modifies libzfs_init() to attempt to load the zfs kernel module if
it is not already loaded.  This is done to simplify initialization by letting
users simply import their zpools without having to first load the module.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoStrip partition from device name for whole disks
Ned Bass [Fri, 1 Oct 2010 19:00:58 +0000 (12:00 -0700)]
Strip partition from device name for whole disks

Under Solaris, the slice number is chopped off when displaying the device name
if the vdev is a whole disk.  Under Linux we should similarly discard the
partition number.  This commit adds the logic to perform the name truncation
for devices ending in -partX, XpX, or X, where X is a string of digits.  The
second case handles devices like md0p0. The third case is limited to scsi and
ide disks, i.e. those beginning with "sd" or "hd", in order to avoid stripping
the number from names like "loop0".

This commit removes the Solaris-specific code for removing slices, since we no
longer reasonably expect our changes to be merged in upstream.  The partition
stripping code was moved off to a helper function to improve readability.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoUse stored whole_disk property when opening a vdev
Ned Bass [Mon, 4 Oct 2010 20:08:24 +0000 (13:08 -0700)]
Use stored whole_disk property when opening a vdev

This commit fixes a bug in vdev_disk_open() in which the whole_disk property
was getting set to 0 for disk devices, even when it was stored as a 1 when the
zpool was created.  The whole_disk property lets us detect when the partition
suffix should be stripped from the device name in CLI output.  It is also used
to determine how writeback cache should be set for a device.

When an existing zpool is imported its configuration is read from the vdev
label by user space in zpool_read_label().  The whole_disk property is saved in
the nvlist which gets passed into the kernel, where it in turn gets saved in
the vdev struct in vdev_alloc().  Therefore, this value is available in
vdev_disk_open() and should not be overridden by checking the provided device
path, since that path will likely point to a partition and the check will
return the wrong result.

We also add an ASSERT that the whole_disk property is set.  We are not aware of
any cases where vdev_disk_open() should be called with a config that doesn't
have this property set.  The ASSERT is there so that when debugging is enabled
we can identify any legitimate cases that we are missing.  If we never hit the
ASSERT, we can at some point remove it along with the conditional whole_disk
check.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoRegister the space accounting callback even when we don't have the ZPL.
Ricardo M. Correia [Mon, 4 Oct 2010 17:19:17 +0000 (10:19 -0700)]
Register the space accounting callback even when we don't have the ZPL.

This callback is needed for properly accounting the per-uid and per-gid
space usage.  Even if we don't have the ZPL, we still need this callback
in order to have proper on-disk ZPL compatibility and to be able to use
Lustre quotas.

Fortunately, the callback doesn't have any ZPL/VFS dependencies so we
can just move it out of #ifdef HAVE_ZPL.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoFix missing vdev names in zpool status output
Ned Bass [Thu, 23 Sep 2010 01:53:59 +0000 (18:53 -0700)]
Fix missing vdev names in zpool status output

Top-level vdev names in zpool status output should follow a <type-id> naming
convention.  In the case of raidz devices, the type portion of the name was
missing.

This commit fixes a bug in zpool_vdev_name() where in this snprintf call

(void) snprintf(buf, sizeof (buf), "%s-%llu", path,
(u_longlong_t)id);

buf and path may point to the same location.  The result is that buf ends up
containing only the "-id" part.  This only occurred for raidz devices because
the code for appending the parity level to the type string stored its result in
buf then set path to point there.  To fix this we allocate a new temporary
buffer on the stack instead of reusing buf.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #57

13 years agoExport ZFS symbols needed by Lustre.
Ricardo M. Correia [Fri, 17 Sep 2010 23:07:24 +0000 (16:07 -0700)]
Export ZFS symbols needed by Lustre.

Required for the DB_DNODE_ENTER()/DB_DNODE_EXIT() helpers.

Signed-off-by: Ricardo M. Correia <ricardo.correia@oracle.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoQuiet down very frequent large allocation warning in ZFS.
Ricardo M. Correia [Fri, 17 Sep 2010 23:08:56 +0000 (16:08 -0700)]
Quiet down very frequent large allocation warning in ZFS.

In my machine, dnode_hold_impl() allocates 9992 bytes in DEBUG mode and it
causes a large stream of stack traces in the logs. Instead, use KM_NODEBUG
to quiet down this known large alloc.

Signed-off-by: Ricardo M. Correia <ricardo.correia@oracle.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd missing Makefile.in from zpool_layout commit
Brian Behlendorf [Fri, 17 Sep 2010 23:22:08 +0000 (16:22 -0700)]
Add missing Makefile.in from zpool_layout commit

The scripts/zpool-layout/Makefile.in file generated by autogen.sh
was accidentally omitted from the previous commit.  Add it.

13 years agoAdd [-m map] option to zpool_layout
Brian Behlendorf [Wed, 15 Sep 2010 22:32:27 +0000 (15:32 -0700)]
Add [-m map] option to zpool_layout

By default the zpool_layout command would always use the slot
number assigned by Linux when generating the zdev.conf file.
This is a reasonable default there are cases when it makes
sense to remap the slot id assigned by Linux using your own
custom mapping.

This commit adds support to zpool_layout to provide a custom
slot mapping file.  The file contains in the first column the
Linux slot it and in the second column the custom slot mapping.
By passing this map file with '-m map' to zpool_config the
mapping will be applied when generating zdev.conf.

Additionally, two sample mapping have been added which reflect
different ways to map the slots in the dragon drawers.

13 years agoFix markdown rendering
Brian Behlendorf [Wed, 15 Sep 2010 16:09:37 +0000 (09:09 -0700)]
Fix markdown rendering

These two lines were being rendered incorrectly on the GitHub
site.  To fix the issue there needs to be leading whitespace
before each line to ensure each command is rendered on its
own line.

$ ./configure
$ make pkg

13 years agoReference new zfsonlinux.org website
Brian Behlendorf [Tue, 14 Sep 2010 22:58:25 +0000 (15:58 -0700)]
Reference new zfsonlinux.org website

The wiki contents have been converted to html and made available
at their new home http://zfsonlinux.org.  The wiki has also been
disabled the html pages are now the official documentation.

13 years agoWait up to timeout seconds for udev device
Brian Behlendorf [Sat, 11 Sep 2010 04:44:17 +0000 (21:44 -0700)]
Wait up to timeout seconds for udev device

Occasional failures were observed in zconfig.sh because udev
could be delayed for a few seconds.  To handle this the wait_udev
function has been added to wait for timeout seconds for an
expected device before returning an error.  By default callers
currently use a 30 seconds timeout which should be much longer
than udev ever needs but not so long to worry the test suite
is hung.

13 years agoReduce volume size in zconfig.sh
Brian Behlendorf [Sat, 11 Sep 2010 04:35:27 +0000 (21:35 -0700)]
Reduce volume size in zconfig.sh

Due to occasional ENOSPC failures on certain platforms I've reduced
the size of the ZVOL from 400M to 300M for the zvol+ext2 clone tests.

13 years agoUse top level object directory in zfs-module.spec
Brian Behlendorf [Fri, 10 Sep 2010 19:33:31 +0000 (12:33 -0700)]
Use top level object directory in zfs-module.spec

Commit 6283f55ea1b91e680386388c17d14b89e344fa8d updated _almost_
everything to use the correct top level object directory.  This
was done to correctly supporting building in custom directories.
Unfortunately, I missed this one instance in the zfs-module.spec.in
rpm spec file.  Fix it.

13 years agoExclude atomic.S source from dist rules
Brian Behlendorf [Fri, 10 Sep 2010 18:43:12 +0000 (11:43 -0700)]
Exclude atomic.S source from dist rules

The zfs package supports the option --with-config=srpm which
is used to bootstrap configure to allow the 'make srpm' target
to work.  This has the advantage of allowing creation of source
rpms without having all your -devel packages installed.  This
source package can then be feed back in to an automated build
farm which only installs the required packages listed by the
srpm.  This ensures that all proper dependencies are expressed
by the source package, because if they are not you will get
configure/build failures.

The trouble here is that --with-config=srpm prevents the
architecture check from running resulting in TARGET_ASM_DIR
being set to the default asm-generic.  The 'make dist' rule
then fails because there is no asm-generic/atomic.S file
because it is generated at build time.  To handle this I
have added an empty file asm-generic/atomic.S simply as a
place holder for 'make dist'.

13 years agoUse linux __KERNEL__ define
Brian Behlendorf [Fri, 10 Sep 2010 16:36:39 +0000 (09:36 -0700)]
Use linux __KERNEL__ define

Previously the project contained who zfs_context.h files,
one for user space builds and one for kernel space builds.
It was the responsibility of the source including the file
to ensure the right one was included based on the order of
the include paths.

This was the way it was done in OpenSolaris but for our
purposes I felt it was overly obscure.  The user and kernel
zfs_context.h files have been combined in to a single file
and a #define determines if you get the user or kernel
context.

The issue here was that I used the _KERNEL macro which is
defined as part of the spl which will only be defined for
most builds after you include the right zfs_context.  It is
safer to use the __KERNEL__ macro which is automatically
defined as part of the kernel build process and passed as
a command line compiler option.  It will always be defined
if your building in the kernel and never for user space.

13 years agoFix "format not a string literal" warning
Brian Behlendorf [Thu, 9 Sep 2010 04:39:28 +0000 (21:39 -0700)]
Fix "format not a string literal" warning

Under Ubuntu 10.04 the default compiler flags include -Wformat
and -Wformat-security which cause the above warning.  In particular,
cases where "%s" was forgotten as part of the format specifier.

https://wiki.ubuntu.com/CompilerFlags

13 years agoSupport custom build directories and move includes
Brian Behlendorf [Sat, 4 Sep 2010 20:26:23 +0000 (13:26 -0700)]
Support custom build directories and move includes

One of the neat tricks an autoconf style project is capable of
is allow configurion/building in a directory other than the
source directory.  The major advantage to this is that you can
build the project various different ways while making changes
in a single source tree.

For example, this project is designed to work on various different
Linux distributions each of which work slightly differently.  This
means that changes need to verified on each of those supported
distributions perferably before the change is committed to the
public git repo.

Using nfs and custom build directories makes this much easier.
I now have a single source tree in nfs mounted on several different
systems each running a supported distribution.  When I make a
change to the source base I suspect may break things I can
concurrently build from the same source on all the systems each
in their own subdirectory.

wget -c http://github.com/downloads/behlendorf/zfs/zfs-x.y.z.tar.gz
tar -xzf zfs-x.y.z.tar.gz
cd zfs-x-y-z

------------------------- run concurrently ----------------------
<ubuntu system>  <fedora system>  <debian system>  <rhel6 system>
mkdir ubuntu     mkdir fedora     mkdir debian     mkdir rhel6
cd ubuntu        cd fedora        cd debian        cd rhel6
../configure     ../configure     ../configure     ../configure
make             make             make             make
make check       make check       make check       make check

This change also moves many of the include headers from individual
incude/sys directories under the modules directory in to a single
top level include directory.  This has the advantage of making
the build rules cleaner and logically it makes a bit more sense.

13 years agoFix spl version check
Brian Behlendorf [Fri, 3 Sep 2010 03:44:41 +0000 (20:44 -0700)]
Fix spl version check

The spl_config.h file is checked to determine the spl version.
However, the zfs code was looking for it in the source directory
and not the build directory.

13 years agoRemove zfs-x.y.z.zip creation in 'make dist'
Brian Behlendorf [Thu, 2 Sep 2010 20:18:17 +0000 (13:18 -0700)]
Remove zfs-x.y.z.zip creation in 'make dist'

Do no create a zfs-x.y.z.zip file as part of 'make dist'.  Simply
create the standard zfs-x.y.z.tar.gz file.

13 years agoPrep for zfs-0.5.1 tag
Brian Behlendorf [Wed, 1 Sep 2010 18:23:32 +0000 (11:23 -0700)]
Prep for zfs-0.5.1 tag

13 years agoFix zfsdev_compat_ioctl() case
Brian Behlendorf [Wed, 1 Sep 2010 22:58:09 +0000 (15:58 -0700)]
Fix zfsdev_compat_ioctl() case

For the !CONFIG_COMPAT case fix the zfsdev_compat_ioctl()
compatibility function name.  This was caught by the
chaos4.3 builder.

13 years agoMinor packaging fixes
Brian Behlendorf [Wed, 1 Sep 2010 19:54:51 +0000 (12:54 -0700)]
Minor packaging fixes

The GIT file was removed from the tree because I have stopped
using TopGit.  Because of this is must also be removed from
the top level Makefile.am as will as the zfs.spec.in file
which referenced it.

Fix type in lib/libzpool/Makefile.am which was preventing
the needed zrlock.h header from being included by 'make dist'.
I simply had the name wrong in the Makefile.am.

Regenerated autogen.sh build products.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoRemove scripts/common.sh
Brian Behlendorf [Wed, 1 Sep 2010 19:50:44 +0000 (12:50 -0700)]
Remove scripts/common.sh

This script is now dynamically generated at configure time
from scripts/common.sh.in.  This change was made by commit
26e61dd074df64f9e1d779273efd56fa9d92cdc5 but we accidentally
kept the common.sh file around.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd quick build instructions
Brian Behlendorf [Wed, 1 Sep 2010 18:23:13 +0000 (11:23 -0700)]
Add quick build instructions

Full update to date build information will stay on the wiki for
now, but there is no harm in adding the bare bones instructions
to the README.  They shouldn't change and are a reasonable
quick start.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd initial autoconf products
Brian Behlendorf [Thu, 26 Aug 2010 19:28:14 +0000 (12:28 -0700)]
Add initial autoconf products

Add the initial products from autogen.sh.  These products will
be updated incrementally after this point as development occurs.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux ztest support
Brian Behlendorf [Thu, 26 Aug 2010 18:59:11 +0000 (11:59 -0700)]
Add linux ztest support

Minor changes to ztest for this environment.  These including
updating ztest to run in the local development tree, as well
as relocating some local variables in this function to the heap.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux zpios support
Brian Behlendorf [Thu, 26 Aug 2010 18:58:00 +0000 (11:58 -0700)]
Add linux zpios support

Linux kernel implementation of PIOS test app.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux user util support
Brian Behlendorf [Thu, 26 Aug 2010 18:57:29 +0000 (11:57 -0700)]
Add linux user util support

This topic branch contains required changes to the user space
utilities to allow them to integrate cleanly with Linux.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux user disk support
Brian Behlendorf [Thu, 26 Aug 2010 18:56:53 +0000 (11:56 -0700)]
Add linux user disk support

This topic branch contains all the changes needed to integrate the user
side zfs tools with Linux style devices.  Primarily this includes fixing
up the Solaris libefi library to be Linux friendly, and integrating with
the libblkid library which is provided by e2fsprogs.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux unused code tracking
Brian Behlendorf [Thu, 26 Aug 2010 18:55:32 +0000 (11:55 -0700)]
Add linux unused code tracking

Track various large hunks which have been dropped simply
because they are not relevant to this port.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux topology support
Brian Behlendorf [Thu, 26 Aug 2010 18:55:19 +0000 (11:55 -0700)]
Add linux topology support

Solaris recently introduced the idea of drive topology because
where a drive is located does matter.  I have already handled
this with udev/blkid integration under Linux so I'm hopeful
this case can simply be removed but for now I've just stubbed
out what is needed in libspl and commented out the rest here.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux compatibility
Brian Behlendorf [Thu, 26 Aug 2010 18:54:51 +0000 (11:54 -0700)]
Add linux compatibility

Resolve minor Linux compatibility issues.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux spa thread support
Brian Behlendorf [Thu, 26 Aug 2010 18:52:20 +0000 (11:52 -0700)]
Add linux spa thread support

Disable the spa thread under Linux until it can be implemented.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux sha2 support
Brian Behlendorf [Thu, 26 Aug 2010 18:52:05 +0000 (11:52 -0700)]
Add linux sha2 support

The upstream ZFS code has correctly moved to a faster native sha2
implementation.  Unfortunately, under Linux that's going to be a little
problematic so we revert the code to the more portable version contained
in earlier ZFS releases.  Using the native sha2 implementation in Linux
is possible but the API is slightly different in kernel version user
space depending on which libraries are used.  Ideally, we need a fast
implementation of SHA256 which builds as part of ZFS this shouldn't be
that hard to do but it will take some effort.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux libspl support
Brian Behlendorf [Thu, 26 Aug 2010 18:50:56 +0000 (11:50 -0700)]
Add linux libspl support

All changes needed for the libspl layer.  This includes modifications
to files directly copied from OpenSolaris and the addition of new
files needed to fill in the gaps.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux kernel module support
Brian Behlendorf [Thu, 26 Aug 2010 18:49:16 +0000 (11:49 -0700)]
Add linux kernel module support

Setup linux kernel module support, this includes:
- zfs context for kernel/user
- kernel module build system integration
- kernel module macros
- kernel module symbol export
- kernel module options

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux kernel memory support
Brian Behlendorf [Thu, 26 Aug 2010 18:46:09 +0000 (11:46 -0700)]
Add linux kernel memory support

Required kmem/vmem changes

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux kernel disk support
Brian Behlendorf [Thu, 26 Aug 2010 18:45:02 +0000 (11:45 -0700)]
Add linux kernel disk support

Native Linux vdev disk interfaces

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux kernel device support
Brian Behlendorf [Thu, 26 Aug 2010 18:44:39 +0000 (11:44 -0700)]
Add linux kernel device support

This branch contains the majority of the changes required to cleanly
intergrate with Linux style special devices (/dev/zfs).  Mainly this
means dropping all the Solaris style callbacks and replacing them
with the Linux equivilants.

This patch also adds the onexit infrastructure needed to track
some minimal state between ioctls.  Under Linux it would be easy
to do this simply using the file->private_data.  But under Solaris
they apparent need to pass the file descriptor as part of the ioctl
data and then perform a lookup in the kernel.  Once again to keep
code change to a minimum I've implemented the Solaris solution.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux spl debug support
Brian Behlendorf [Thu, 26 Aug 2010 18:44:12 +0000 (11:44 -0700)]
Add linux spl debug support

Use spl debug if HAVE_SPL defined

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux mntent support
Brian Behlendorf [Thu, 26 Aug 2010 18:43:58 +0000 (11:43 -0700)]
Add linux mntent support

Use mount entry if HAVE_SETMNTENT defined

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux mlslabel support
Brian Behlendorf [Thu, 26 Aug 2010 18:43:42 +0000 (11:43 -0700)]
Add linux mlslabel support

The ZFS update to onnv_141 brought with it support for a
security label attribute called mlslabel.  This feature
depends on zones to work correctly and thus I am disabling
it under Linux.  Equivilant functionality could be added
at some point in the future.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux idmap support
Brian Behlendorf [Thu, 26 Aug 2010 18:43:07 +0000 (11:43 -0700)]
Add linux idmap support

Use idmap service if available.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd linux events
Brian Behlendorf [Thu, 26 Aug 2010 18:42:43 +0000 (11:42 -0700)]
Add linux events

This topic branch leverages the Solaris style FMA call points
in ZFS to create a user space visible event notification system
under Linux.  This new system is called zevent and it unifies
all previous Solaris style ereports and sysevent notifications.

Under this Linux specific scheme when a sysevent or ereport event
occurs an nvlist describing the event is created which looks almost
exactly like a Solaris ereport.  These events are queued up in the
kernel when they occur and conditionally logged to the console.
It is then up to a user space application to consume the events
and do whatever it likes with them.

To make this possible the existing /dev/zfs ABI has been extended
with two new ioctls which behave as follows.

* ZFS_IOC_EVENTS_NEXT
Get the next pending event.  The kernel will keep track of the last
event consumed by the file descriptor and provide the next one if
available.  If no new events are available the ioctl() will block
waiting for the next event.  This ioctl may also be called in a
non-blocking mode by setting zc.zc_guid = ZEVENT_NONBLOCK.  In the
non-blocking case if no events are available ENOENT will be returned.
It is possible that ESHUTDOWN will be returned if the ioctl() is
called while module unloading is in progress.  And finally ENOMEM
may occur if the provided nvlist buffer is not large enough to
contain the entire event.

* ZFS_IOC_EVENTS_CLEAR
Clear are events queued by the kernel.  The kernel will keep a fairly
large number of recent events queued, use this ioctl to clear the
in kernel list.  This will effect all user space processes consuming
events.

The zpool command has been extended to use this events ABI with the
'events' subcommand.  You may run 'zpool events -v' to output a
verbose log of all recent events.  This is very similar to the
Solaris 'fmdump -ev' command with the key difference being it also
includes what would be considered sysevents under Solaris.  You
may also run in follow mode with the '-f' option.  To clear the
in kernel event queue use the '-c' option.

$ sudo cmd/zpool/zpool events -fv
TIME                        CLASS
May 13 2010 16:31:15.777711000 ereport.fs.zfs.config.sync
        class = "ereport.fs.zfs.config.sync"
        ena = 0x40982b7897700001
        detector = (embedded nvlist)
                version = 0x0
                scheme = "zfs"
                pool = 0xed976600de75dfa6
        (end detector)

        time = 0x4bec8bc3 0x2e5aed98
        pool = "zpios"
        pool_guid = 0xed976600de75dfa6
        pool_context = 0x0

While the 'zpool events' command is handy for interactive debugging
it is not expected to be the primary consumer of zevents.  This ABI
was primarily added to facilitate the addition of a user space
monitoring daemon.  This daemon would consume all events posted by
the kernel and based on the type of event perform an action.  For
most events simply forwarding them on to syslog is likely enough.
But this interface also cleanly allows for more sophisticated
actions to be taken such as generating an email for a failed drive.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoAdd build system
Brian Behlendorf [Thu, 26 Aug 2010 18:22:58 +0000 (11:22 -0700)]
Add build system

Add autoconf style build infrastructure to the ZFS tree.  This
includes autogen.sh, configure.ac, m4 macros, some scripts/*,
and makefiles for all the core ZFS components.

13 years agoFix stack ztest
Brian Behlendorf [Thu, 26 Aug 2010 18:13:05 +0000 (11:13 -0700)]
Fix stack ztest

While ztest does run in user space we run it with the same stack
restrictions it would have in kernel space.  This ensures that any
stack related issues which would be hit in the kernel can be caught
and debugged in user space instead.

This patch is a first pass to limit the stack usage of every ztest
function to 1024 bytes.  Subsequent updates can further reduce this.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoFix stack traverse_visitbp()
Brian Behlendorf [Fri, 27 Aug 2010 23:48:18 +0000 (16:48 -0700)]
Fix stack traverse_visitbp()

Due to  limited stack space recursive functions are frowned upon in
the Linux kernel.  However, they often are the most elegant solution
to a problem.  The following code preserves the recursive function
traverse_visitbp() but moves the local variables AND function
arguments to the heap to minimize the stack frame size.  Enough
space is initially allocated on the stack for 20 levels of recursion.
This change does ugly-up-the-code but it reduces the worst case
usage from roughly 4160 bytes to 960 bytes on x86_64 archs.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoFix stack zio_execute()
Ned Bass [Thu, 26 Aug 2010 18:38:38 +0000 (11:38 -0700)]
Fix stack zio_execute()

Implement zio_execute() as a wrapper around the static function
__zio_execute() so that we can force  __zio_execute() to be inlined.
This reduces stack overhead which is important because __zio_execute()
is called recursively in several zio code paths.  zio_execute() itself
cannot be inlined because it is externally visible.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoFix stack zio_done()
Brian Behlendorf [Thu, 26 Aug 2010 18:04:17 +0000 (11:04 -0700)]
Fix stack zio_done()

Eliminated local variables pointing to members of the zio struct.
Just refer to the struct members directly.  This saved about 32 bytes per
call, but this function can be called recurisvely up to 19 levels deep,
so we potentially save up to 608 bytes.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoFix stack vn_open()
Brian Behlendorf [Thu, 26 Aug 2010 18:03:04 +0000 (11:03 -0700)]
Fix stack vn_open()

We should not put a 4k maxpathlen buffer on the stack, instead
locate it to the heap.  Even in user space we run ztest with 8K
stacks to verify correctness

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoFix stack vdev_cache_read()
Brian Behlendorf [Thu, 26 Aug 2010 18:00:46 +0000 (11:00 -0700)]
Fix stack vdev_cache_read()

Moving the vdev_cache_entry_t struct ve_search from the stack to
the heap saves ~100 bytes.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoFix stack traverse_impl()
Brian Behlendorf [Thu, 26 Aug 2010 17:58:47 +0000 (10:58 -0700)]
Fix stack traverse_impl()

Stack use reduced from 560 bytes to 128 bytes.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
13 years agoFix stack noinline
Brian Behlendorf [Thu, 26 Aug 2010 17:58:36 +0000 (10:58 -0700)]
Fix stack noinline

Certain function must never be automatically inlined by gcc because
they are stack heavy or called recursively.  This patch flags all
such functions I've found as 'noinline' to prevent gcc from making
the optimization.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>