]> git.proxmox.com Git - mirror_zfs-debian.git/log
mirror_zfs-debian.git
12 years agoMove udev rules from /etc/udev to /lib/udev
Kyle Fuller [Fri, 5 Aug 2011 19:22:58 +0000 (20:22 +0100)]
Move udev rules from /etc/udev to /lib/udev

This change moves the default install location for the zfs udev
rules from /etc/udev/ to /lib/udev/.  The correct convention is
for rules provided by a package to be installed in /lib/udev/.
The /etc/udev/ directory is reserved for custom rules or local
overrides.

Additionally, this patch cleans up some abuse of the bindir install
location by adding a udevdir and udevruledir install directories.
This allows us to revert to the default bin install location.  The
udev install directories can be set with the following new options.

  --with-udevdir=DIR      install udev helpers [EPREFIX/lib/udev]
  --with-udevruledir=DIR  install udev rules [UDEVDIR/rules.d]

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

12 years agoCorrectly lock pages for .readpages()
Brian Behlendorf [Thu, 4 Aug 2011 23:25:43 +0000 (16:25 -0700)]
Correctly lock pages for .readpages()

Unlike the .readpage() callback which is passed a single locked page
to be populated.  The .readpages() callback is passed a list of unlocked
pages which are all marked for read-ahead (PG_readahead set).  It is
the responsibly of .readpages() to ensure to pages are properly locked
before being populated.

Prior to this change the requested read-ahead pages would be updated
outside of the page lock which is unsafe.  The unlocked pages would then
be unlocked again which is harmless but should have been immediately
detected as bug.  Unfortunately, newer kernels failed detect this issue
because the check is done with a VM_BUG_ON which is disabled by default.
Luckily, the old Debian Lenny 2.6.26 kernel caught this because it
simply uses a BUG_ON.

The straight forward fix for this is to update the .readpages() callback
to use the read_cache_pages() helper function.  The helper function will
ensure that each page in the list is properly locked before it is passed
to the .readpage() callback.  In addition resolving the bug, this results
in a nice simplification of the existing code.

The downside to this change is that instead of passing one large read
request to the dmu multiple smaller ones are submitted.  All of these
requests however are marked for readahead so the lower layers should
issue a large I/O regardless.  Thus most of the request should hit the
ARC cache.

Futher optimization of this code can be done in the future is a perform
analysis determines it to be worthwhile.  But for the moment, it is
preferable that code be correct and understandable.

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

12 years agoAdd backing_device_info per-filesystem
Brian Behlendorf [Tue, 2 Aug 2011 01:24:40 +0000 (18:24 -0700)]
Add backing_device_info per-filesystem

For a long time now the kernel has been moving away from using the
pdflush daemon to write 'old' dirty pages to disk.  The primary reason
for this is because the pdflush daemon is single threaded and can be
a limiting factor for performance.  Since pdflush sequentially walks
the dirty inode list for each super block any delay in processing can
slow down dirty page writeback for all filesystems.

The replacement for pdflush is called bdi (backing device info).  The
bdi system involves creating a per-filesystem control structure each
with its own private sets of queues to manage writeback.  The advantage
is greater parallelism which improves performance and prevents a single
filesystem from slowing writeback to the others.

For a long time both systems co-existed in the kernel so it wasn't
strictly required to implement the bdi scheme.  However, as of
Linux 2.6.36 kernels the pdflush functionality has been retired.

Since ZFS already bypasses the page cache for most I/O this is only
an issue for mmap(2) writes which must go through the page cache.
Even then adding this missing support for newer kernels was overlooked
because there are other mechanisms which can trigger writeback.

However, there is one critical case where not implementing the bdi
functionality can cause problems.  If an application handles a page
fault it can enter the balance_dirty_pages() callpath.  This will
result in the application hanging until the number of dirty pages in
the system drops below the dirty ratio.

Without a registered backing_device_info for the filesystem the
dirty pages will not get written out.  Thus the application will hang.
As mentioned above this was less of an issue with older kernels because
pdflush would eventually write out the dirty pages.

This change adds a backing_device_info structure to the zfs_sb_t
which is already allocated per-super block.  It is then registered
when the filesystem mounted and unregistered on unmount.  It will
not be registered for mounted snapshots which are read-only.  This
change will result in flush-<pool> thread being dynamically created
and destroyed per-mounted filesystem for writeback.

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

12 years agoCleanup mmap(2) writes
Brian Behlendorf [Tue, 2 Aug 2011 04:28:51 +0000 (21:28 -0700)]
Cleanup mmap(2) writes

While the existing implementation of .writepage()/zpl_putpage() was
functional it was not entirely correct.  In particular, it would move
dirty pages in to a clean state simply after copying them in to the
ARC cache.  This would result in the pages being lost if the system
were to crash enough though the Linux VFS believed them to be safe on
stable storage.

Since at the moment virtually all I/O, except mmap(2), bypasses the
page cache this isn't as bad as it sounds.  However, as hopefully
start using the page cache more getting this right becomes more
important so it's good to improve this now.

This patch takes a big step in that direction by updating the code
to correctly move dirty pages through a writeback phase before they
are marked clean.  When a dirty page is copied in to the ARC it will
now be set in writeback and a completion callback is registered with
the transaction.  The page will stay in writeback until the dmu runs
the completion callback indicating the page is on stable storage.
At this point the page can be safely marked clean.

This process is normally entirely asynchronous and will be repeated
for every dirty page.  This may initially sound inefficient but most
of these pages will end up in a few txgs.  That means when they are
eventually written to disk they should be nicely batched.  However,
there is room for improvement.  It may still be desirable to batch
up the pages in to larger writes for the dmu.  This would reduce
the number of callbacks and small 4k buffer required by the ARC.

Finally, if the caller requires that the I/O be done synchronously
by setting WB_SYNC_ALL or if ZFS_SYNC_ALWAYS is set.  Then the I/O
will trigger a zil_commit() to flush the data to stable storage.
At which point the registered callbacks will be run leaving the
date safe of disk and marked clean before returning from .writepage.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoUse libzfs_run_process() in libshare.
Gunnar Beutner [Fri, 29 Jul 2011 08:17:50 +0000 (10:17 +0200)]
Use libzfs_run_process() in libshare.

This should simplify the code a bit by re-using existing code
to fork and exec a process.

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

12 years agoUse /dev/null for stdout/stderr in libzfs_run_process().
Gunnar Beutner [Fri, 29 Jul 2011 08:17:46 +0000 (10:17 +0200)]
Use /dev/null for stdout/stderr in libzfs_run_process().

Simply closing the stdout and/or stderr file descriptors for
the child process can have bad side effects if for example
the child writes to stdout/stderr after open()ing a file.
The open() call might have returned the same file descriptor
one would usually expect for stdout/stderr (1 and 2), thereby
causing mis-directed writes.

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

12 years agoCall exportfs -v once for NFS shares.
James H [Tue, 26 Jul 2011 10:47:20 +0000 (11:47 +0100)]
Call exportfs -v once for NFS shares.

At the moment we call exportfs -v every time we check whether an
NFS share is active. This happens every time you run a zfs or
zpool command, making them extremely slow when you have a lot of
exports. The time taken is approx O(n2) of the number of shares.

This commit stores the output from exportfs -v in a temporary file
and use this to speed up subsequent accesses.

This mechanism is still too slow - if you have tens of thousands
of NFS shares it will still be painful running ANY zfs/zpool
command.

Signed-off-by: Gunnar Beutner <gunnar@beutner.name>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #341

12 years agoMerge branch 'illumos'
Brian Behlendorf [Mon, 1 Aug 2011 19:10:54 +0000 (12:10 -0700)]
Merge branch 'illumos'

Merge in ten upstream fixes which have already been made to both
the Illumos and FreeBSD ZFS implementations.  This brings us up
to date with the latest ZFS changes in Illumos.

Credit goes to Martin Matuska of the FreeBSD project for posting
an excellent summary of the upstream patches we were missing.

Illumos #1313: Integer overflow in txg_delay()
Illumos #278:  get rid zfs of python and pyzfs dependencies
Illumos #1043: Recursive zfs snapshot destroy fails
Illumos #883:  ZIL reuse during remount corruption
Illumos #1092: zfs refratio property
Illumos #1051: zfs should handle
Illumos #510:  'zfs get' enhancement - mountpoint as an argument
Illumos #175:  zfs vdev cache consumes excessive memory
Illumos #764:  panic in zfs:dbuf_sync_list
Illumos #xxx:  zdb -vvv broken after zfs diff integration

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

12 years agoIllumos #1313: Integer overflow in txg_delay()
Martin Matuska [Mon, 1 Aug 2011 17:34:06 +0000 (10:34 -0700)]
Illumos #1313: Integer overflow in txg_delay()

The function txg_delay() is used to delay txg (transaction group)
threads in ZFS.  The timeout value for this function is calculated
using:

    int timeout = ddi_get_lbolt() + ticks;

Later, the actual wait is performed:

    while (ddi_get_lbolt() < timeout &&
        tx->tx_syncing_txg < txg-1 && !txg_stalled(dp))
            (void) cv_timedwait(&tx->tx_quiesce_more_cv, &tx->tx_sync_lock,
                timeout - ddi_get_lbolt());

The ddi_get_lbolt() function returns current uptime in clock ticks
and is typed as clock_t.  The clock_t type on 64-bit architectures
is int64_t.

The "timeout" variable will overflow depending on the tick frequency
(e.g. for 1000 it will overflow in 28.855 days). This will make the
expression "ddi_get_lbolt() < timeout" always false - txg threads will
not be delayed anymore at all. This leads to a slowdown in ZFS writes.

The attached patch initializes timeout as clock_t to match the return
value of ddi_get_lbolt().

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

12 years agoIllumos #278: get rid zfs of python and pyzfs dependencies
Alexander Stetsenko [Tue, 26 Jul 2011 22:44:36 +0000 (15:44 -0700)]
Illumos #278: get rid zfs of python and pyzfs dependencies

Remove all python and pyzfs dependencies for consistency and
to ensure full functionality even in a mimimalist environment.

Reviewed by: gordon.w.ross@gmail.com
Reviewed by: trisk@opensolaris.org
Reviewed by: alexander.r.eremin@gmail.com
Reviewed by: jerry.jelinek@joyent.com
Approved by: garrett@nexenta.com

References to Illumos issue and patch:
- https://www.illumos.org/issues/278
- https://github.com/illumos/illumos-gate/commit/1af68beac3

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #340
Issue #160

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoIllumos #1043: Recursive zfs snapshot destroy fails
Martin Matuska [Tue, 26 Jul 2011 20:08:02 +0000 (13:08 -0700)]
Illumos #1043: Recursive zfs snapshot destroy fails

Prior to revision 11314 if a user was recursively destroying
snapshots of a dataset the target dataset was not required to
exist.  The zfs_secpolicy_destroy_snaps() function introduced
the security check on the target dataset, so since then if the
target dataset does not exist, the recursive destroy is not
performed.  Before 11314, only a delete permission check on
the snapshot's master dataset was performed.

Steps to reproduce:
zfs create pool/a
zfs snapshot pool/a@s1
zfs destroy -r pool@s1

Therefore I suggest to fallback to the old security check, if
the target snapshot does not exist and continue with the destroy.

References to Illumos issue and patch:
- https://www.illumos.org/issues/1043
- https://www.illumos.org/attachments/217/recursive_dataset_destroy.patch

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

12 years agoIllumos #883: ZIL reuse during remount corruption
Eric Schrock [Tue, 26 Jul 2011 19:41:53 +0000 (12:41 -0700)]
Illumos #883: ZIL reuse during remount corruption

Moving the zil_free() cleanup to zil_close() prevents this
problem from occurring in the first place.  There is a very
good description of the issue and fix in Illumus #883.

Reviewed by: Matt Ahrens <Matt.Ahrens@delphix.com>
Reviewed by: Adam Leventhal <Adam.Leventhal@delphix.com>
Reviewed by: Albert Lee <trisk@nexenta.com>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Garrett D'Amore <garrett@nexenta.com>
Reivewed by: Dan McDonald <danmcd@nexenta.com>
Approved by: Gordon Ross <gwr@nexenta.com>

References to Illumos issue and patch:
- https://www.illumos.org/issues/883
- https://github.com/illumos/illumos-gate/commit/c9ba2a43cb

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

12 years agoIllumos #1092: zfs refratio property
Matt Ahrens [Tue, 26 Jul 2011 19:23:00 +0000 (12:23 -0700)]
Illumos #1092: zfs refratio property

Add a "REFRATIO" property, which is the compression ratio based on
data referenced. For snapshots, this is the same as COMPRESSRATIO,
but for filesystems/volumes, the COMPRESSRATIO is based on the
data "USED" (ie, includes blocks in children, but not blocks
shared with the origin).

This is needed to figure out how much space a filesystem would
use if it were not compressed (ignoring snapshots).

Reviewed by: George Wilson <George.Wilson@delphix.com>
Reviewed by: Adam Leventhal <Adam.Leventhal@delphix.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
Reviewed by: Richard Elling <richard.elling@richardelling.com>
Reviewed by: Mark Musante <Mark.Musante@oracle.com>
Reviewed by: Garrett D'Amore <garrett@nexenta.com>
Approved by: Garrett D'Amore <garrett@nexenta.com>

References to Illumos issue and patch:
- https://www.illumos.org/issues/1092
- https://github.com/illumos/illumos-gate/commit/187d6ac08a

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

12 years agoIllumos #1051: zfs should handle imbalanced luns
George Wilson [Tue, 26 Jul 2011 19:08:52 +0000 (12:08 -0700)]
Illumos #1051: zfs should handle imbalanced luns

Today zfs tries to allocate blocks evenly across all devices.
This means when devices are imbalanced zfs will use lots of
CPU searching for space on devices which tend to be pretty
full.  It should instead fail quickly on the full LUNs and
move onto devices which have more availability.

Reviewed by: Eric Schrock <Eric.Schrock@delphix.com>
Reviewed by: Matt Ahrens <Matt.Ahrens@delphix.com>
Reviewed by: Adam Leventhal <Adam.Leventhal@delphix.com>
Reviewed by: Albert Lee <trisk@nexenta.com>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Approved by: Garrett D'Amore <garrett@nexenta.com>

References to Illumos issue and patch:
- https://www.illumos.org/issues/510
- https://github.com/illumos/illumos-gate/commit/5ead3ed965

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

12 years agoIllumos #510: 'zfs get' enhancement - mountpoint as an argument
Shampavman [Tue, 26 Jul 2011 18:53:09 +0000 (11:53 -0700)]
Illumos #510: 'zfs get' enhancement - mountpoint as an argument

The 'zfs get' command should be able to deal with mountpoint
as an argument.  It already works with 'zfs list' command:

  # zfs list /export/home/estibi
  NAME                       USED  AVAIL  REFER  MOUNTPOINT
  rpool/export/home/estibi  1.14G  3.86G  1.14G  /export/home/estibi

but it fails with 'zfs get':

  # zfs get all /export/home/estibi
  cannot open '/export/home/estibi': invalid dataset name

Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Reviewed by: Deano <deano@rattie.demon.co.uk>
Reviewed by: Garrett D'Amore <garrett@nexenta.com>
Approved by: Garrett D'Amore <garrett@nexenta.com>

References to Illumos issue and patch:
- https://www.illumos.org/issues/510
- https://github.com/illumos/illumos-gate/commit/5ead3ed965

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

12 years agoIllumos #175: zfs vdev cache consumes excessive memory
Garrett D'Amore [Fri, 22 Apr 2011 07:49:41 +0000 (00:49 -0700)]
Illumos #175: zfs vdev cache consumes excessive memory

Note that with the current ZFS code, it turns out that the vdev
cache is not helpful, and in some cases actually harmful.  It
is better if we disable this.  Once some time has passed, we
should actually remove this to simplify the code.  For now we
just disable it by setting the zfs_vdev_cache_size to zero.
Note that Solaris 11 has made these same changes.

References to Illumos issue and patch:
- https://www.illumos.org/issues/175
- https://github.com/illumos/illumos-gate/commit/b68a40a845

Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Approved by: Richard Lowe <richlowe@richlowe.net>

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

12 years agoIllumos #764: panic in zfs:dbuf_sync_list
Gordon Ross [Tue, 26 Jul 2011 18:37:06 +0000 (11:37 -0700)]
Illumos #764: panic in zfs:dbuf_sync_list

Hypothesis about what's going on here.

At some time in the past, something, i.e. dnode_reallocate()
calls one of:
dbuf_rm_spill(dn, tx);

These will do:
dbuf_rm_spill(dnode_t *dn, dmu_tx_t *tx)
dbuf_free_range(dn, DMU_SPILL_BLKID, DMU_SPILL_BLKID, tx)
dbuf_undirty(db, tx)

Currently dbuf_undirty can leave a spill block in dn_dirty_records[],
(it having been put there previously by dbuf_dirty) and free it.
Sometime later, dbuf_sync_list trips over this reference to free'd
(and typically reused) memory.

Also, dbuf_undirty can call dnode_clear_range with a bogus
block ID. It needs to test for DMU_SPILL_BLKID, similar to
how dnode_clear_range is called in dbuf_dirty().

References to Illumos issue and patch:
- https://www.illumos.org/issues/764
- https://github.com/illumos/illumos-gate/commit/3f2366c2bb

Reviewed by: George Wilson <gwilson@zfsmail.com>
Reviewed by: Mark.Maybe@oracle.com
Reviewed by: Albert Lee <trisk@nexenta.com
Approved by: Garrett D'Amore <garrett@nexenta.com>

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

12 years agoIllumos #xxx: zdb -vvv broken after zfs diff integration
Tim Haley [Tue, 26 Jul 2011 23:38:27 +0000 (16:38 -0700)]
Illumos #xxx: zdb -vvv broken after zfs diff integration

References to Illumos issue and patch:
- https://github.com/illumos/illumos-gate/commit/163eb7ff

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

12 years agoAdd .gitignore for zfs.<distro> init scripts
Brian Behlendorf [Mon, 1 Aug 2011 17:27:54 +0000 (10:27 -0700)]
Add .gitignore for zfs.<distro> init scripts

Treat the automatically generated zfs.<distro> init scripts
as build products by adding them to a directory specific
.gitignore file.

12 years agoTurn the init.d scripts into autoconf config files
Kyle Fuller [Mon, 25 Jul 2011 00:00:53 +0000 (01:00 +0100)]
Turn the init.d scripts into autoconf config files

This change ensures the paths used by the provided init scripts
always reference the prefixes provided at configure time.  The
@sbindir@ and @sysconfdir@ prefixes will be correctly replaced
at build time.

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

12 years agoWrap dracut scripts to 79 chars
Zachary Bedell [Sun, 31 Jul 2011 04:21:40 +0000 (00:21 -0400)]
Wrap dracut scripts to 79 chars

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

12 years agoMake autogen.sh executable
Kyle Fuller [Mon, 25 Jul 2011 00:36:37 +0000 (01:36 +0100)]
Make autogen.sh executable

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoCatch return errors from zpool commands
Zachary Bedell [Sun, 24 Jul 2011 20:53:15 +0000 (16:53 -0400)]
Catch return errors from zpool commands

This fixes a bug that can effect first reboot after install
using Dracut.  The Dracut module didn't check the return
value from several calls to z* functions.  This resulted in
"Using no pools available as root" on boot if the ZFS module
didn't auto-import the pools.  It's most likely to happen on
initial restart after a fresh install & requires juggling in
the Dracut emergency holographic shell to fix.

This patch checks return codes & output from zpool list and
related functions and correctly falls into the explicit zpool
import code branch if the module didn't import the pool at load.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoSoft to hard tabs
Zachary Bedell [Sun, 24 Jul 2011 20:46:16 +0000 (16:46 -0400)]
Soft to hard tabs

For consistency with the upstream sources and the rest of the
project use hard instead of soft tabs.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoFix txg_sync_thread deadlock
Brian Behlendorf [Fri, 22 Jul 2011 20:55:27 +0000 (13:55 -0700)]
Fix txg_sync_thread deadlock

Update two kmem_alloc()'s in dbuf_dirty() to use KM_PUSHPAGE.
Because these functions are called from txg_sync_thread we
must ensure they don't reenter the zfs filesystem code via
the .writepage callback.  This would result in a deadlock.

This deadlock is rare and has only been observed once under
an abusive mmap() write workload.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoAdd missing <pool> option
Brian Behlendorf [Fri, 22 Jul 2011 20:56:03 +0000 (13:56 -0700)]
Add missing <pool> option

The bootfs example in the dracut documentation was sightly incorrect
because it lacked the trailing required pool argument.  Add it.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoFix the configure CONFIG_* option detection
Brian Behlendorf [Fri, 22 Jul 2011 21:10:38 +0000 (14:10 -0700)]
Fix the configure CONFIG_* option detection

The latest kernels no longer define AUTOCONF_INCLUDED which was
being used to detect the new style autoconf.h kernel configure
options.  This results in the CONFIG_* checks always failing
incorrectly for newer kernels.

The fix for this is a simplification of the testing method.
Rather than attempting to explicitly include to renamed config
header.  It is simpler to unconditionally include <linux/module.h>
which must pick up the correctly named header.

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

12 years agoUse zfs_mknode() to create dataset root
Brian Behlendorf [Wed, 20 Jul 2011 23:50:22 +0000 (16:50 -0700)]
Use zfs_mknode() to create dataset root

Long, long, long ago when the effort to port ZFS was begun
the zfs_create_fs() function was heavily modified to remove
all of its VFS dependencies.  This allowed Lustre to use
the dataset without us having to spend the time porting all
the required VFS code.

Fast-forward several years and we now have all the VFS code
in place but are still relying on the modified zfs_create_fs().
This isn't required anymore and we can now use zfs_mknode()
to create the root znode for the filesystem.

This commit reverts the contents of zfs_create_fs() to largely
match the upstream OpenSolaris code.  There have been minor
modifications to accomidate the Linux VFS but that is all.

This code fixes issue #116 by bootstraping enough of the VFS
data structures so we can rely on zfs_mknode() to create the
root directory.  This ensures it is created properly with
support for system attributes.  Previously it wasn't which
is why it behaved differently that all other directories
when modified.

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

12 years agoHonor setgit bit on directories
Brian Behlendorf [Wed, 20 Jul 2011 20:10:07 +0000 (13:10 -0700)]
Honor setgit bit on directories

Newly created files were always being created with the fsuid/fsgid
in the current users credentials.  This is correct except in the
case when the parent directory sets the 'setgit' bit.  In this
case according to posix the newly created file/directory should
inherit the gid of the parent directory.  Additionally, in the
case of a subdirectory it should also inherit the 'setgit' bit.

Finally, this commit performs a little cleanup of the vattr_t
initialization by moving it to a common helper function.

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

12 years agoFix 'make install' overly broad 'rm'
Brian Behlendorf [Wed, 20 Jul 2011 04:44:07 +0000 (21:44 -0700)]
Fix 'make install' overly broad 'rm'

When running 'make install' without DESTDIR set the module install
rules would mistakenly destroy the 'modules.*' files for ALL of
your installed kernels.  This could lead to a non-functional system
for the alternate kernels because 'depmod -a' will only be run for
the kernel which was compiled against.  This issue would not impact
anyone using the 'make <deb|rpm|pkg>' build targets to build and
install packages.

The fix for this issue is to only remove extraneous build products
when DESTDIR is set.  This almost exclusively indicates we are
building packages and installed the build products in to a temporary
staging location.  Additionally, limit the removal the unneeded
build products to the target kernel version.

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

12 years agoFix zpl_writepage() deadlock
Brian Behlendorf [Tue, 19 Jul 2011 18:48:46 +0000 (11:48 -0700)]
Fix zpl_writepage() deadlock

Disable the normal reclaim path for zpl_putpage().  This ensures that
all memory allocations under this call path will never enter direct
reclaim.  If this were to happen the VM might try to write out
additional pages by calling zpl_putpage() again resulting in a
deadlock.

This sitution is typically handled in Linux by marking each offending
allocation GFP_NOFS.  However, since much of the code used is common
it makes more sense to use PF_MEMALLOC to flag the entire call tree.
Alternately, the code could be updated to pass the needed allocation
flags but that's a more invasive change.

The following example of the above described deadlock was triggered
by test 074 in the xfstest suite.

Call Trace:
 [<ffffffff814dcdb2>] down_write+0x32/0x40
 [<ffffffffa05af6e4>] dnode_new_blkid+0x94/0x2d0 [zfs]
 [<ffffffffa0597d66>] dbuf_dirty+0x556/0x750 [zfs]
 [<ffffffffa05987d1>] dmu_buf_will_dirty+0x81/0xd0 [zfs]
 [<ffffffffa059ee70>] dmu_write+0x90/0x170 [zfs]
 [<ffffffffa0611afe>] zfs_putpage+0x2ce/0x360 [zfs]
 [<ffffffffa062875e>] zpl_putpage+0x1e/0x60 [zfs]
 [<ffffffffa06287b2>] zpl_writepage+0x12/0x20 [zfs]
 [<ffffffff8115f907>] writeout+0xa7/0xd0
 [<ffffffff8115fa6b>] move_to_new_page+0x13b/0x170
 [<ffffffff8115fed4>] migrate_pages+0x434/0x4c0
 [<ffffffff811559ab>] compact_zone+0x4fb/0x780
 [<ffffffff81155ed1>] compact_zone_order+0xa1/0xe0
 [<ffffffff8115602c>] try_to_compact_pages+0x11c/0x190
 [<ffffffff811200bb>] __alloc_pages_nodemask+0x5eb/0x8b0
 [<ffffffff8115464a>] alloc_pages_current+0xaa/0x110
 [<ffffffff8111e36e>] __get_free_pages+0xe/0x50
 [<ffffffffa03f0e2f>] kv_alloc+0x3f/0xb0 [spl]
 [<ffffffffa03f11d9>] spl_kmem_cache_alloc+0x339/0x660 [spl]
 [<ffffffffa05950b3>] dbuf_create+0x43/0x370 [zfs]
 [<ffffffffa0596fb1>] __dbuf_hold_impl+0x241/0x480 [zfs]
 [<ffffffffa0597276>] dbuf_hold_impl+0x86/0xc0 [zfs]
 [<ffffffffa05977ff>] dbuf_hold_level+0x1f/0x30 [zfs]
 [<ffffffffa05a9dde>] dmu_tx_check_ioerr+0x4e/0x110 [zfs]
 [<ffffffffa05aa1f9>] dmu_tx_count_write+0x359/0x6f0 [zfs]
 [<ffffffffa05aa5df>] dmu_tx_hold_write+0x4f/0x70 [zfs]
 [<ffffffffa0611a6d>] zfs_putpage+0x23d/0x360 [zfs]
 [<ffffffffa062875e>] zpl_putpage+0x1e/0x60 [zfs]
 [<ffffffff811221f9>] write_cache_pages+0x1c9/0x4a0
 [<ffffffffa0628738>] zpl_writepages+0x18/0x20 [zfs]
 [<ffffffff81122521>] do_writepages+0x21/0x40
 [<ffffffff8119bbbd>] writeback_single_inode+0xdd/0x2c0
 [<ffffffff8119bfbe>] writeback_sb_inodes+0xce/0x180
 [<ffffffff8119c11b>] writeback_inodes_wb+0xab/0x1b0
 [<ffffffff8119c4bb>] wb_writeback+0x29b/0x3f0
 [<ffffffff8119c6cb>] wb_do_writeback+0xbb/0x240
 [<ffffffff811308ea>] bdi_forker_task+0x6a/0x310
 [<ffffffff8108ddf6>] kthread+0x96/0xa0

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

12 years agoFix zio_execute() deadlock
Brian Behlendorf [Tue, 19 Jul 2011 16:31:23 +0000 (09:31 -0700)]
Fix zio_execute() deadlock

To avoid deadlocking the system it is crucial that all memory
allocations performed in the zio_execute() call path are marked
KM_PUSHPAGE (GFP_NOFS).  This ensures that while a z_wr_iss
thread is processing the syncing transaction group it does
not re-enter the filesystem code and deadlock on itself.

Call Trace:
 [<ffffffffa02580e8>] cv_wait_common+0x78/0xe0 [spl]
 [<ffffffffa0347bab>] txg_wait_open+0x7b/0xa0 [zfs]
 [<ffffffffa030e73d>] dmu_tx_wait+0xed/0xf0 [zfs]
 [<ffffffffa0376a49>] zfs_putpage+0x219/0x360 [zfs]
 [<ffffffffa038d75e>] zpl_putpage+0x1e/0x60 [zfs]
 [<ffffffffa038d7b2>] zpl_writepage+0x12/0x20 [zfs]
 [<ffffffff8115f907>] writeout+0xa7/0xd0
 [<ffffffff8115fa6b>] move_to_new_page+0x13b/0x170
 [<ffffffff8115fed4>] migrate_pages+0x434/0x4c0
 [<ffffffff811559ab>] compact_zone+0x4fb/0x780
 [<ffffffff81155ed1>] compact_zone_order+0xa1/0xe0
 [<ffffffff8115602c>] try_to_compact_pages+0x11c/0x190
 [<ffffffff811200bb>] __alloc_pages_nodemask+0x5eb/0x8b0
 [<ffffffff81159932>] kmem_getpages+0x62/0x170
 [<ffffffff8115a54a>] fallback_alloc+0x1ba/0x270
 [<ffffffff8115a2c9>] ____cache_alloc_node+0x99/0x160
 [<ffffffff8115b059>] __kmalloc+0x189/0x220
 [<ffffffffa02539fb>] kmem_alloc_debug+0xeb/0x130 [spl]
 [<ffffffffa031454a>] dnode_hold_impl+0x46a/0x550 [zfs]
 [<ffffffffa0314649>] dnode_hold+0x19/0x20 [zfs]
 [<ffffffffa03042e3>] dmu_read+0x33/0x180 [zfs]
 [<ffffffffa034729d>] space_map_load+0xfd/0x320 [zfs]
 [<ffffffffa03300bc>] metaslab_activate+0x10c/0x170 [zfs]
 [<ffffffffa0330ad9>] metaslab_alloc+0x469/0x800 [zfs]
 [<ffffffffa038963c>] zio_dva_allocate+0x6c/0x2f0 [zfs]
 [<ffffffffa038a249>] zio_execute+0x99/0xf0 [zfs]
 [<ffffffffa0254b1c>] taskq_thread+0x1cc/0x330 [spl]
 [<ffffffff8108ddf6>] kthread+0x96/0xa0

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

12 years agoFix mmap(2)/write(2)/read(2) deadlock
Brian Behlendorf [Tue, 19 Jul 2011 03:06:32 +0000 (20:06 -0700)]
Fix mmap(2)/write(2)/read(2) deadlock

When modifing overlapping regions of a file using mmap(2) and
write(2)/read(2) it is possible to deadlock due to a lock inversion.
The zfs_write() and zfs_read() hooks first take the zfs range lock
and then lock the individual pages.  Conversely, when using mmap'ed
I/O the zpl_writepage() hook is called with the individual page
locks already taken and then zfs_putpage() takes the zfs range lock.

The most straight forward fix is to simply not take the zfs range
lock in the mmap(2) case.  The individual pages will still be locked
thus serializing access.  Updating the same region of a file with
write(2) and mmap(2) has always been a dodgy thing to do.  This change
at a minimum ensures we don't deadlock and is consistent with the
existing Linux semantics enforced by the VFS.

This isn't an issue under Solaris because the only range locking
performed will be with the zfs range locks.  It's up to each filesystem
to perform its own file locking.  Under Linux the VFS provides many
of these services.

It may be possible/desirable at a latter date to entirely dump the
existing zfs range locking and rely on the Linux VFS page locks.
However, for now its safest to perform both layers of locking until
zfs is more tightly integrated with the page cache.

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

12 years agoUpdate 'zpool import' man page
Brian Behlendorf [Tue, 19 Jul 2011 18:22:29 +0000 (11:22 -0700)]
Update 'zpool import' man page

The following supported options were missing from the zpool.8
man page.  The OpenSolaris man pages originally used were simply
out of date with the code.

zpool import
  -F Recovery mode
  -m Allow missing log devices
  -N Import but don't mount
  -n Determine if recoverable but don't do it

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoFix send/recv 'dataset is busy' errors
Brian Behlendorf [Fri, 15 Jul 2011 23:15:27 +0000 (16:15 -0700)]
Fix send/recv 'dataset is busy' errors

This commit fixes a regression which was accidentally introduced by
the Linux 2.6.39 compatibility chanages.  As part of these changes
instead of holding an active reference on the namepsace (which is
no longer posible) a reference is taken on the super block.  This
reference ensures the super block remains valid while it is in use.

To handle the unlikely race condition of the filesystem being
unmounted concurrently with the start of a 'zfs send/recv' the
code was updated to only take the super block reference when there
was an existing reference.  This indicates that the filesystem is
active and in use.

Unfortunately, in the 'zfs recv' case this is not the case.  The
newly created dataset will not have a super block without an
active reference which results in the 'dataset is busy' error.

The most straight forward fix for this is to simply update the
code to always take the reference even when it's zero.  This
may expose us to very very unlikely concurrent umount/send/recv
case but the consequences of that are minor.

Closes #319

12 years agoProvide a rc.d script for archlinux
Kyle Fuller [Sun, 10 Jul 2011 15:57:33 +0000 (16:57 +0100)]
Provide a rc.d script for archlinux

Unlike most other Linux distributions archlinux installs its
init scripts in /etc/rc.d insead of /etc/init.d.  This commit
provides an archlinux rc.d script for zfs and extends the
build infrastructure to ensure it get's installed in the
correct place.

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

12 years agoImprove fstat(2) performance
Brian Behlendorf [Sat, 9 Jul 2011 22:44:16 +0000 (15:44 -0700)]
Improve fstat(2) performance

There is at most a factor of 3x performance improvement to be
had by using the Linux generic_fillattr() helper.  However, to
use it safely we need to ensure the values in a cached inode
are kept rigerously up to date.  Unfortunately, this isn't
the case for the blksize, blocks, and atime fields.  At the
moment the authoritative values are still stored in the znode.

This patch introduces an optimized zfs_getattr_fast() call.
The idea is to use the up to date values from the inode and
the blksize, block, and atime fields from the znode.  At some
latter date we should be able to strictly use the inode values
and further improve performance.

The remaining overhead in the zfs_getattr_fast() call can be
attributed to having to take the znode mutex.  This overhead is
unavoidable until the inode is kept strictly up to date.  The
the careful reader will notice the we do not use the customary
ZFS_ENTER()/ZFS_EXIT() macros.  These macro's are designed to
ensure the filesystem is not torn down in the middle of an
operation.  However, in this case the VFS is holding a
reference on the active inode so we know this is impossible.

=================== Performance Tests ========================

This test calls the fstat(2) system call 10,000,000 times on
an open file description in a tight loop.  The test results
show the zfs stat(2) performance is now only 22% slower than
ext4.  This is a 2.5x improvement and there is a clear long
term plan to get to parity with ext4.

filesystem    | test-1  test-2  test-3  | average | times-ext4
--------------+-------------------------+---------+-----------
ext4          |  7.785s  7.899s  7.284s |  7.656s | 1.000x
zfs-0.6.0-rc4 | 24.052s 22.531s 23.857s | 23.480s | 3.066x
zfs-faststat  |  9.224s  9.398s  9.485s |  9.369s | 1.223x

The second test is to run 'du' of a copy of the /usr tree
which contains 110514 files.  The test is run multiple times
both using both a cold cache (/proc/sys/vm/drop_caches) and
a hot cache.  As expected this change signigicantly improved
the zfs hot cache performance and doesn't quite bring zfs to
parity with ext4.

A little surprisingly the zfs cold cache performance is better
than ext4.  This can probably be attributed to the zfs allocation
policy of co-locating all the meta data on disk which minimizes
seek times.  By default the ext4 allocator will spread the data
over the entire disk only co-locating each directory.

filesystem    | cold    | hot
--------------+---------+--------
ext4          | 13.318s | 1.040s
zfs-0.6.0-rc4 |  4.982s | 1.762s
zfs-faststat  |  4.933s | 1.345s

12 years agoAdd L2ARC tunables
Brian Behlendorf [Fri, 8 Jul 2011 19:41:57 +0000 (12:41 -0700)]
Add L2ARC tunables

The performance of the L2ARC can be tweaked by a number of tunables, which
may be necessary for different workloads:

     l2arc_write_max         max write bytes per interval
     l2arc_write_boost       extra write bytes during device warmup
     l2arc_noprefetch        skip caching prefetched buffers
     l2arc_headroom          number of max device writes to precache
     l2arc_feed_secs         seconds between L2ARC writing
     l2arc_feed_min_ms       min feed interval in milliseconds
     l2arc_feed_again        turbo L2ARC warmup
     l2arc_norw              no reads during writes

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

12 years agoUpdate 'zfs send' documentation
Brian Behlendorf [Fri, 8 Jul 2011 19:16:09 +0000 (12:16 -0700)]
Update 'zfs send' documentation

The -D and -p options were missing from the manpage.  This commit
adds documentation for these features.

Closes #311

12 years agoRemove zfs service only on uninstall, not on upgrade
Fajar A. Nugraha [Thu, 7 Jul 2011 07:25:53 +0000 (14:25 +0700)]
Remove zfs service only on uninstall, not on upgrade

This caused problems on upgrade using RPM:

* The new version will run chkconfig --add, which has no effect
  since the service was already added.

* The old version will run chkconfig --del, which caused zfs
  service removal.

Only run "chkconfig --del" on complete uninstall, by checking
the value of "$1" to %preun, which will be "0" on uninstall,
and "1" on upgrade.

  http://www.rpm.org/max-rpm/s1-rpm-inside-scripts.html

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

12 years agoCheck for "udevadm settle" vs "udevsettle"
Fajar A. Nugraha [Thu, 7 Jul 2011 07:22:19 +0000 (14:22 +0700)]
Check for "udevadm settle" vs "udevsettle"

RHEL5 does not have udevadm, so fix initscript accordingly

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

12 years agoUpdate ztest paths
Brian Behlendorf [Wed, 6 Jul 2011 18:36:54 +0000 (11:36 -0700)]
Update ztest paths

Unfortunately, ztest is hard coded to export the zdb utility to
be installed in a certain location.  When the packaging was updated
to install zdb in /sbin/ ztest was broken.  To fix this I'm updating
ztest to check both common install paths.

12 years agoAdd proper library versioning
Brian Behlendorf [Tue, 5 Jul 2011 19:12:08 +0000 (12:12 -0700)]
Add proper library versioning

The zfs libraries were never properly versioned.  Since the API has
remained static for quite some time this we never an issue.  However,
going forward they should be versioned.  This commit versions all
of the libraries to 1.0.0.  From here on out this version must be
updated to reflect changes to the library.

12 years agoUpdated init scripts to enable automatic sharing of ZFS datasets.
Gunnar Beutner [Sun, 3 Jul 2011 00:43:25 +0000 (02:43 +0200)]
Updated init scripts to enable automatic sharing of ZFS datasets.

The relevant init scripts were updated so as to automatically share
ZFS datasets using "zfs share -a" at boot time.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoRenamed HAVE_SHARE ifdefs to HAVE_SMB_SHARE.
Gunnar Beutner [Sat, 2 Jul 2011 19:34:12 +0000 (21:34 +0200)]
Renamed HAVE_SHARE ifdefs to HAVE_SMB_SHARE.

The remaining code that is guarded by HAVE_SHARE ifdefs is related to the
.zfs/shares functionality which is currently not available on Linux.

On Solaris the .zfs/shares directory can be used to set permissions for
SMB shares.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoLink libshare directly to libzfs
Gunnar Beutner [Sat, 2 Jul 2011 19:34:08 +0000 (21:34 +0200)]
Link libshare directly to libzfs

Drop usage of dlopen/dlsym for libshare.  There is no need to do
this because the zfs packages provide libshare.  Unlike on Solaris
we are guaranteed it will be available.

This avoids possible problems with hardcoding the libshare path in
the code (e.g. when users specify a different install path via
configure options).  It additionally simplifies the code which is
good for maintainability.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoImplemented sharing datasets via NFS using libshare.
Gunnar Beutner [Sat, 2 Jul 2011 19:34:05 +0000 (21:34 +0200)]
Implemented sharing datasets via NFS using libshare.

The sharenfs and sharesmb properties depend on the libshare library
to export datasets via NFS and SMB. This commit implements the base
libshare functionality as well as support for managing NFS shares.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoDocument initramfs process
Zachary Bedell [Mon, 4 Jul 2011 18:38:10 +0000 (14:38 -0400)]
Document initramfs process

Add documentation for Dracut and the initramfs process.  This includes
detailing the basic boot process and options available.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoUpdate for Dracut-010
Zachary Bedell [Mon, 4 Jul 2011 17:25:31 +0000 (13:25 -0400)]
Update for Dracut-010

Update Dracut module for Dracut-010 and fix race conditions that
caused boot to fail on MP systems.  Add support for zfs_force flag
and parsing of spl_hostid from kernel command line.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoUpdate zfs.gentoo/zfs.lsb init script
Zachary Bedell [Mon, 4 Jul 2011 21:58:51 +0000 (14:58 -0700)]
Update zfs.gentoo/zfs.lsb init script

* Update paths to zpool/zfs tools,
* Log less for non-error conditions,
* Don't be fatal if umount fails at shutdown -- final init remount
  will take care of it if /usr or / are in use

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoRemoved erroneous backticks in the zfs.lunar init script.
Gunnar Beutner [Sun, 3 Jul 2011 00:38:50 +0000 (02:38 +0200)]
Removed erroneous backticks in the zfs.lunar init script.

The backticks would cause the output of the zfs commands
to be evaluated as input for the if construct rather than
their exit status.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoFixed indentation in the zfs.lunar init script.
Gunnar Beutner [Sun, 3 Jul 2011 00:35:58 +0000 (02:35 +0200)]
Fixed indentation in the zfs.lunar init script.

One of the blocks in the init script wasn't indented properly.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoUse consistent error message in zpool sub-command
Prasad Joshi [Mon, 4 Jul 2011 22:45:35 +0000 (23:45 +0100)]
Use consistent error message in zpool sub-command

The zpool sub-commands like iostat, list, and status should
display consistent message when a given pool is unavailable or
no pool is present.  This change unifies the default behavior
as follows:

  root@prasad:~# ./zpool list 1 2
  no pools available
  no pools available

  root@prasad:~# ./zpool iostat  1 2
  no pools available
  no pools available

  root@prasad:~# ./zpool status 1 2
  no pools available
  no pools available

  root@prasad:~# ./zpool list tan 1 2
  cannot open 'tan': no such pool

  root@prasad:~# ./zpool iostat tan 1 2
  cannot open 'tan': no such pool

  root@prasad:~# ./zpool status tan 1 2
  cannot open 'tan': no such pool

Reported-by: Rajshree Thorat <rthorat@stec-inc.com>
Signed-off-by: Prasad Joshi <pjoshi@stec-inc.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #306

12 years agoFix 'rc_parallel="YES"' error
Andrew Tselischev [Mon, 4 Jul 2011 08:49:41 +0000 (01:49 -0700)]
Fix 'rc_parallel="YES"' error

If rc_parallel="YES" zfs starts before localmount, which leads
to "No such file or directory" error on systems with /usr on a
separate partition.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoPrep zfs-0.6.0-rc5 tag
Brian Behlendorf [Fri, 1 Jul 2011 22:24:34 +0000 (15:24 -0700)]
Prep zfs-0.6.0-rc5 tag

Create the fifth 0.6.0 release candidate tag (rc5).

12 years agoAlways allow non-user xattrs
Brian Behlendorf [Thu, 30 Jun 2011 16:38:52 +0000 (09:38 -0700)]
Always allow non-user xattrs

Under Linux you may only disable USER xattrs.  The SECURITY,
SYSTEM, and TRUSTED xattr namespaces must always be available
if xattrs are supported by the filesystem.  The enforcement
of USER xattrs is performed in the zpl_xattr_user_* handlers.

Under Solaris there is only a single xattr namespace which
is managed globally.

12 years agoFix implicit declaration of 'mkdirp'
Brian Behlendorf [Wed, 29 Jun 2011 22:03:36 +0000 (15:03 -0700)]
Fix implicit declaration of 'mkdirp'

The lib/libspl/include/libgen.h header file was being mistakenly
left out of the 'make dist' tarball.  It just happens this doesn't
cause a build failure when creating packages because the system
libgen/h is included instead.  This simply results in the following
warning due to the missing forward declaration of mkdirp().

  ../../lib/libzfs/libzfs_mount.c:417:3: warning: implicit declaration
  of function 'mkdirp' [-Wimplicit-function-declaration]

12 years agoSupport mandatory locks (nbmand)
Rohan Puri [Wed, 29 Jun 2011 18:00:58 +0000 (11:00 -0700)]
Support mandatory locks (nbmand)

The Linux kernel already has support for mandatory locking.  This
change just replaces the Solaris mandatory locking calls with the
Linux equivilants.  In fact, it looks like this code could be
removed entirely because this checking is already done generically
in the Linux VFS.  However, for now we'll leave it in place even
if it is redundant just in case we missed something.

The original patch to update the code to support mandatory locking
was done by Rohan Puri.  This patch is an updated version which is
compatible with the previous mount option handling changes.

Original-Patch-by: Rohan Puri <rohan.puri15@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #222
Closes #253

12 years agoLinux compat 2.6.39: mount_nodev()
Brian Behlendorf [Thu, 19 May 2011 18:44:07 +0000 (11:44 -0700)]
Linux compat 2.6.39: mount_nodev()

The .get_sb callback has been replaced by a .mount callback
in the file_system_type structure.  When using the new
interface the caller must now use the mount_nodev() helper.

Unfortunately, the new interface no longer passes the vfsmount
down to the zfs layers.  This poses a problem for the existing
implementation because we currently save this pointer in the
super block for latter use.  It provides our only entry point
in to the namespace layer for manipulating certain mount options.

This needed to be done originally to allow commands like
'zfs set atime=off tank' to work properly.  It also allowed me
to keep more of the original Solaris code unmodified.  Under
Solaris there is a 1-to-1 mapping between a mount point and a
file system so this is a fairly natural thing to do.  However,
under Linux they many be multiple entries in the namespace
which reference the same filesystem.  Thus keeping a back
reference from the filesystem to the namespace is complicated.

Rather than introduce some ugly hack to get the vfsmount and
continue as before.  I'm leveraging this API change to update
the ZFS code to do things in a more natural way for Linux.
This has the upside that is resolves the compatibility issue
for the long term and fixes several other minor bugs which
have been reported.

This commit updates the code to remove this vfsmount back
reference entirely.  All modifications to filesystem mount
options are now passed in to the kernel via a '-o remount'.
This is the expected Linux mechanism and allows the namespace
to properly handle any options which apply to it before passing
them on to the file system itself.

Aside from fixing the compatibility issue, removing the
vfsmount has had the benefit of simplifying the code.  This
change which fairly involved has turned out nicely.

Closes #246
Closes #217
Closes #187
Closes #248
Closes #231

12 years agoLinux compat 2.6.39: security_inode_init_security()
Brian Behlendorf [Thu, 19 May 2011 19:47:32 +0000 (12:47 -0700)]
Linux compat 2.6.39: security_inode_init_security()

The security_inode_init_security() function now takes an additional
qstr argument which must be passed in from the dentry if available.
Passing a NULL is safe when no qstr is available the relevant
security checks will just be skipped.

Closes #246
Closes #217
Closes #187

12 years agoAvoid 'rpm -q' bug for 'make pkg'
Brian Behlendorf [Thu, 16 Jun 2011 19:14:33 +0000 (12:14 -0700)]
Avoid 'rpm -q' bug for 'make pkg'

RPM version 4.9.0 has been observed to generate extra debug
messages in certain cases.  These debug messages prevent us
from cleanly acquiring the architecture.  This is clearly
an upstream RPM bug which will get fixed.  But until then
a safe solution is to pipe the result through 'tail -1'
to just grab the architecture bit we care about.

Example 'rpm -qp spl-0.6.0-rc4.src.rpm --qf %{arch}' output:

Freeing read locks for locker 0x166: 28031/47480843735008
Freeing read locks for locker 0x168: 28031/47480843735008
x86_64

12 years agoAdd ZFS specific mmap() checks
Brian Behlendorf [Fri, 1 Jul 2011 18:25:07 +0000 (11:25 -0700)]
Add ZFS specific mmap() checks

Under Linux the VFS handles virtually all of the mmap() access
checks.  Filesystem specific checks are left to be handled in
the .mmap() hook and normally there arn't any.

However, ZFS provides a few attributes which can influence the
mmap behavior and should be honored.  Note, currently the code
to modify these attributes has not been implemented under Linux.

* ZFS_IMMUTABLE | ZFS_READONLY | ZFS_APPENDONLY: when any of these
  attributes are set a file may not be mmaped with write access.

* ZFS_AV_QUARANTINED: when set a file file may not be mmaped with
  read or exec access.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoRemove unused MMAP functions
Brian Behlendorf [Fri, 1 Jul 2011 16:16:15 +0000 (09:16 -0700)]
Remove unused MMAP functions

The following functions were required for the OpenSolaris mmap
implementation.  Because the Linux VFS does most the most heavy
lifting for us they are not required and are being removed to
keep the code clean and easy to understand.

  * zfs_null_putapage()
  * zfs_frlock()
  * zfs_no_putpage()

Signed-off-by: Brian Behlendorf <behlendorf@llnl.gov>
12 years agoMMAP Optimization
Prasad Joshi [Sat, 28 May 2011 01:53:07 +0000 (02:53 +0100)]
MMAP Optimization

Enable zfs_getpage, zfs_fillpage, zfs_putpage, zfs_putapage functions.
The functions have been modified to make them Linux friendly.

ZFS uses these functions to read/write the mmapped pages. Using them
from readpage/writepage results in clear code. The patch also adds
readpages and writepages interface functions to read/write list of
pages in one function call.

The code change handles the first mmap optimization mentioned on
https://github.com/behlendorf/zfs/issues/225

Signed-off-by: Prasad Joshi <pjoshi@stec-inc.com>
Signed-off-by: Brian Behlendorf <behlendorf@llnl.gov>
Issue #255

12 years agoEnsure all block devices are available
Brian Behlendorf [Thu, 30 Jun 2011 21:45:33 +0000 (14:45 -0700)]
Ensure all block devices are available

These days most disk drivers will probe for devices asynchronously.
This means it's possible that when you zfs init script runs all the
required block devices may not yet have been discovered.  The result
is the pool may fail to cleanly import at boot time.  This is
particularly common when you have a large number of devices.

The fix is for the init script to block until udev settles and we
are no longer detecting new devices.  Once the system has settled
the zfs modules can be loaded and the pool with be automatically
imported.

12 years agoUse truncate_setsize in zfs_setattr
Prasad Joshi [Sat, 25 Jun 2011 14:06:37 +0000 (15:06 +0100)]
Use truncate_setsize in zfs_setattr

According to Linux kernel commit 2c27c65e, using truncate_setsize in
setattr simplifies the code. Therefore, the patch replaces the call
to vmtruncate() with truncate_setsize().

zfs_setattr uses zfs_freesp to free the disk space belonging to the
file.  As truncate_setsize may release the page cache and flushing
the dirty data to disk, it must be called before the zfs_freesp.

Suggested-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Prasad Joshi <pjoshi@stec-inc.com>
Closes #255

12 years agoTear down and flush the mmap region
Prasad Joshi [Sat, 25 Jun 2011 12:30:29 +0000 (13:30 +0100)]
Tear down and flush the mmap region

The inode eviction should unmap the pages associated with the inode.
These pages should also be flushed to disk to avoid the data loss.
Therefore, use truncate_setsize() in evict_inode() to release the
pagecache.

The API truncate_setsize() was added in 2.6.35 kernel. To ensure
compatibility with the old kernel, the patch defines its own
truncate_setsize function.

Signed-off-by: Prasad Joshi <pjoshi@stec-inc.com>
Closes #255

12 years agoMultipath device manageability improvements
Ned A. Bass [Tue, 21 Jun 2011 23:18:27 +0000 (16:18 -0700)]
Multipath device manageability improvements

Update udev helper scripts to deal with device-mapper devices created
by multipathd.  These enhancements are targeted at a particular
storage network topology under evaluation at LLNL consisting of two
SAS switches providing redundant connectivity between multiple server
nodes and disk enclosures.

The key to making these systems manageable is to create shortnames for
each disk that conveys its physical location in a drawer.  In a
direct-attached topology we infer a disk's enclosure from the PCI bus
number and HBA port number in the by-path name provided by udev.  In a
switched topology, however, multiple drawers are accessed via a single
HBA port.  We therefore resort to assigning drawer identifiers based
on which switch port a drive's enclosure is connected to.  This
information is available from sysfs.

Add options to zpool_layout to generate an /etc/zfs/zdev.conf using
symbolic links in /dev/disk/by-id of the form
<label>-<UUID>-switch-port:<X>-slot:<Y>.  <label> is a string that
depends on the subsystem that created the link and defaults to
"dm-uuid-mpath" (this prefix is used by multipathd).  <UUID> is a
unique identifier for the disk typically obtained from the scsi_id
program, and <X> and <Y> denote the switch port and disk slot numbers,
respectively.

Add a callout script sas_switch_id for use by multipathd to help
create symlinks of the form described above.  Update zpool_id and the
udev zpool rules file to handle both multipath devices and
conventional drives.

12 years agoLinux 3.0 compat, shrinker compatibility
Brian Behlendorf [Tue, 21 Jun 2011 21:26:51 +0000 (14:26 -0700)]
Linux 3.0 compat, shrinker compatibility

To accomindate the updated Linux 3.0 shrinker API the spl
shrinker compatibility code was updated.  Unfortunately, this
couldn't be done cleanly without slightly adjusting the comapt
API.  See spl commit a55bcaad181096d764e12d847e3091cd7b15509a.

This commit updates the ZFS code to use the slightly modified
API.  You must use the latest SPL if your building ZFS.

12 years agoFix unlink/xattr deadlock
Gunnar Beutner [Mon, 20 Jun 2011 17:36:58 +0000 (10:36 -0700)]
Fix unlink/xattr deadlock

The problem here is that prune_icache() tries to evict/delete
both the xattr directory inode as well as at least one xattr
inode contained in that directory. Here's what happens:

1. File is created.
2. xattr is created for that file (behind the scenes a xattr
   directory and a file in that xattr directory are created)
3. File is deleted.
4. Both the xattr directory inode and at least one xattr
   inode from that directory are evicted by prune_icache();
   prune_icache() acquires a lock on both inodes before it
   calls ->evict() on the inodes

When the xattr directory inode is evicted zfs_zinactive attempts
to delete the xattr files contained in that directory. While
enumerating these files zfs_zget() is called to obtain a reference
to the xattr file znode - which tries to lock the xattr inode.
However that very same xattr inode was already locked by
prune_icache() further up the call stack, thus leading to a
deadlock.

This can be reliably reproduced like this:
$ touch test
$ attr -s a -V b test
$ rm test
$ echo 3 > /proc/sys/vm/drop_caches

This patch fixes the deadlock by moving the zfs_purgedir() call to
zfs_unlinked_drain().  Instead zfs_rmnode() now checks whether the
xattr dir is empty and leaves the xattr dir in the unlinked set if
it finds any xattrs.

To ensure zfs_unlinked_drain() never accesses a stale super block
zfsvfs_teardown() has been update to block until the iput taskq
has been drained.  This avoids a potential race where a file with
an xattr directory is removed and the file system is immediately
unmounted.

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

12 years agoRemoved erroneous zfs_inode_destroy() calls from zfs_rmnode().
Gunnar Beutner [Thu, 16 Jun 2011 18:59:56 +0000 (20:59 +0200)]
Removed erroneous zfs_inode_destroy() calls from zfs_rmnode().

iput_final() already calls zpl_inode_destroy() -> zfs_inode_destroy()
for us after zfs_zinactive(), thus making sure that the inode is
properly cleaned up.

The zfs_inode_destroy() calls in zfs_rmnode() would lead to a
double-free.

Fixes #282

12 years agoAdd "ashift" property to zpool create
Christian Kohlschütter [Thu, 16 Jun 2011 19:56:38 +0000 (21:56 +0200)]
Add "ashift" property to zpool create

Some disks with internal sectors larger than 512 bytes (e.g., 4k) can
suffer from bad write performance when ashift is not configured
correctly.  This is caused by the disk not reporting its actual sector
size, but a sector size of 512 bytes.  The drive may behave this way
for compatibility reasons.  For example, the WDC WD20EARS disks are
known to exhibit this behavior.

When creating a zpool, ZFS takes that wrong sector size and sets the
"ashift" property accordingly (to 9: 1<<9=512), whereas it should be
set to 12 for 4k sectors (1<<12=4096).

This patch allows an adminstrator to manual specify the known correct
ashift size at 'zpool create' time.  This can significantly improve
performance in certain cases.  However, it will have an impact on your
total pool capacity.  See the updated ashift property description
in the zpool.8 man page for additional details.

Valid values for the ashift property range from 9 to 17 (512B-128KB).
Additionally, you may set the ashift to 0 if you wish to auto-detect
the sector size based on what the disk reports, this is the default
behavior.  The most common ashift values are 9 and 12.

  Example:
  zpool create -o ashift=12 tank raidz2 sda sdb sdc sdd

Closes #280

Original-patch-by: Richard Laager <rlaager@wiktel.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
12 years agoLinux 2.6.37 compat, WRITE_FLUSH_FUA
Brian Behlendorf [Thu, 16 Jun 2011 18:20:22 +0000 (20:20 +0200)]
Linux 2.6.37 compat, WRITE_FLUSH_FUA

The WRITE_FLUSH, WRITE_FUA, and WRITE_FLUSH_FUA flags have been
introduced as a replacement for WRITE_BARRIER.  This was done
to allow richer semantics to be expressed to the block layer.
It is the block layers responsibility to choose the correct way
to implement these semantics.

This change simply updates the bio's to use the new kernel API
which should be absolutely safe.  However, since ZFS depends
entirely on this working as designed for correctness we do
want to be careful.

Closes #281

12 years agoUpdate rpm/deb packages to be FHS compliant
Brian Behlendorf [Fri, 17 Jun 2011 18:47:45 +0000 (11:47 -0700)]
Update rpm/deb packages to be FHS compliant

This change is the first step towards updating the default
rpm/deb packages to be FHS compliant.  It accomplishes this
by passing the following options to ./configure to ensure the
zfs build products are installed in FHS compliant locations.

  ./configure --prefix=/ --bindir=/lib/udev \
    --libexecdir=/usr/libexec --datadir=/usr/share

The core zfs utilities (zfs, zpool, zdb) are now be installed
in /sbin, the core libraries in /lib, and the udev helpers
(zpool_id, zvol_id) are in /lib/udev with the other udev
helpers.

The remaining files in the zfs package remain in their
previous locations under /usr.

12 years agoAutogen refresh.
Darik Horn [Fri, 17 Jun 2011 17:12:25 +0000 (10:12 -0700)]
Autogen refresh.

Run autogen.sh using the same autotools versions as upstream:

 * autoconf-2.63
 * automake-1.11.1
 * libtool-2.2.6b

12 years agoUse datadir not datarootdir for dracut
Brian Behlendorf [Fri, 17 Jun 2011 19:23:21 +0000 (12:23 -0700)]
Use datadir not datarootdir for dracut

The zfs dracut modules should be installed under the --datadir
not --datarootdir path.  This was just an oversight in the
original Makefile.am.

After this change %{_datadir} can now be set safely in the
zfs.spec file.  The 'make install' location is now consistent
with the location expected by the spec file.

12 years agoFix autoconf variable substitution in udev rules.
Darik Horn [Fri, 17 Jun 2011 15:02:36 +0000 (10:02 -0500)]
Fix autoconf variable substitution in udev rules.

Change the variable substitution in the udev rule templates
according to the method described in the Autoconf manual;
Chapter 4.7.2: Installation Directory Variables.

The udev rules are improperly generated if the bindir parameter
overrides the prefix parameter during configure. For example:

  # ./configure --prefix=/usr/local --bindir=/opt/zfs/bin

The udev helper is installed as /opt/zfs/bin/zpool_id, but the
corresponding udev rule has a different path:

  # /usr/local/etc/udev/rules.d/60-zpool.rules
  ENV{DEVTYPE}=="disk", IMPORT{program}="/usr/local/bin/zpool_id -d %p"

The @bindir@ variable expands to "${exec_prefix}/bin", so it cannot
be used instead of @prefix@ directly.

This also applies to the zvol_id helper.

Closes #283.

12 years agoHandle /etc/mtab -> /proc/mounts symlink
Brian Behlendorf [Tue, 14 Jun 2011 23:25:29 +0000 (16:25 -0700)]
Handle /etc/mtab -> /proc/mounts symlink

Under Fedora 15 /etc/mtab is now a symlink to /proc/mounts by
default.  When /etc/mtab is a symlink the mount.zfs helper
should not update it.   There was code in place to handle this
case but it used stat() which traverses the link and then issues
the stat on /proc/mounts.  We need to use lstat() to prevent the
link traversal and instead stat /etc/mtab.

Closes #270

12 years agoAlways check -Wno-unused-but-set-variable gcc support
Brian Behlendorf [Tue, 14 Jun 2011 22:09:05 +0000 (15:09 -0700)]
Always check -Wno-unused-but-set-variable gcc support

The previous commit 8a7e1ceefa430988c8f888ca708ab307333b4464 wasn't
quite right.  This check applies to both the user and kernel space
build and as such we must make sure it runs regardless of what
the --with-config option is set too.

For example, if --with-config=kernel then the autoconf test does
not run and we generate build warnings when compiling the kernel
packages.

12 years agoCheck for -Wno-unused-but-set-variable gcc support
Brian Behlendorf [Tue, 14 Jun 2011 18:02:13 +0000 (11:02 -0700)]
Check for -Wno-unused-but-set-variable gcc support

Gcc versions 4.3.2 and earlier do not support the compiler flag
-Wno-unused-but-set-variable.  This can lead to build failures
on older Linux platforms such as Debian Lenny.  Since this is
an optional build argument this changes add a new autoconf check
for the option.  If it is supported by the installed version of
gcc then it is used otherwise it is omited.

See commit's 12c1acde76683108441827ae9affba1872f3afe5 and
79713039a2b6e0ed223d141b4a8a8455f282d2f2 for the reason the
-Wno-unused-but-set-variable options was originally added.

12 years agoAdd default stack checking
Brian Behlendorf [Sun, 12 Jun 2011 05:48:49 +0000 (22:48 -0700)]
Add default stack checking

When your kernel is built with kernel stack tracing enabled and you
have the debugfs filesystem mounted.  Then the zfs.sh script will clear
the worst observed kernel stack depth on module load and check the worst
case usage on module removal.  If the stack depth ever exceeds 7000
bytes the full stack will be printed for debugging.  This is dangerously
close to overrunning the default 8k stack.

This additional advisory debugging is particularly valuable when running
the regression tests on a kernel built with 16k stacks.  In this case,
almost no matter how bad the stack overrun is you will see be able to
get a clean stack trace for debugging.  Since the worst case stack usage
can be highly variable it's helpful to always check the worst case usage.

12 years agoPass -f option for import
Brian Behlendorf [Fri, 10 Jun 2011 18:20:34 +0000 (11:20 -0700)]
Pass -f option for import

If a pool was not cleanly exported passing the -f flag may be required
at 'zpool import' time.  Since this test is simply validating that the
pool can be successfully imported in the absense of the cache file
always pass the -f to ensure it succeeds.  This failure was observed
under RHEL6.1.

12 years agoFix 'zfs send -D' segfault
Brian Behlendorf [Thu, 9 Jun 2011 20:41:55 +0000 (13:41 -0700)]
Fix 'zfs send -D' segfault

Sending pools with dedup results in a segfault due to a Solaris
portability issue.  Under Solaris the pipe(2) library call
creates a bidirectional data channel.  Unfortunately, on Linux
pipe(2) call creates unidirection data channel.  The fix is to
use the socketpair(2) function to create the expected
bidirectional channel.

Seth Heeren did the original leg work on this issue for zfs-fuse.
We finally just rediscovered the same portability issue and
dfurphy was able to point me at the original issue for the fix.

Closes #268

12 years agoSanatize zpios-sanity.sh environment
Brian Behlendorf [Fri, 3 Jun 2011 22:08:49 +0000 (15:08 -0700)]
Sanatize zpios-sanity.sh environment

Just like zconfig.sh the zpios-sanity.sh tests should run in a
sanatized environment.  This ensures they never conflict with an
installed /etc/zfs/zpool.cache file.

This commit additionally improves the -c cleanup option.  It now
removes the modules stack if loaded and destroys relevant md devices.
This behavior is now identical to zconfig.sh.

12 years agoDelay before destroying loopback devices
Brian Behlendorf [Fri, 3 Jun 2011 21:13:25 +0000 (14:13 -0700)]
Delay before destroying loopback devices

Generally I don't approve of just adding an arbitrary delay to
avoid a problem but in this case I'm going to let it slide.  We
may need to delay briefly after 'zpool destroy' returns to ensure
the loopback devices are closed.  If they aren't closed than
losetup -d will not be able to destroy them.  Unfortunately,
there's no easy state the check so we'll have to make due with
a simple delay.

12 years agoAlways unload zpios.ko on exit
Brian Behlendorf [Thu, 2 Jun 2011 17:25:35 +0000 (10:25 -0700)]
Always unload zpios.ko on exit

We should always unload zpios.ko on exit.  This ensures
that subsequent calls to 'zfs.sh -u' from other utilities
will be able to unload the module stack and properly
cleanup.  This is important for the the --cleanup option
which can be passed to zconfig.sh and zfault.sh.

12 years agoFix zpios-sanity.sh return code
Brian Behlendorf [Thu, 2 Jun 2011 17:13:15 +0000 (10:13 -0700)]
Fix zpios-sanity.sh return code

The zpios-sanity.sh script should return failure when any
of the individual zpios.sh tests fail.  The previous code
would always return success suppressing real failures.

13 years agoFix stack ddt_class_contains()
Brian Behlendorf [Wed, 25 May 2011 20:56:40 +0000 (13:56 -0700)]
Fix stack ddt_class_contains()

Stack usage for ddt_class_contains() reduced from 524 bytes to 68
bytes.  This large stack allocation significantly contributed to
the likelyhood of a stack overflow when scrubbing/resilvering
dedup pools.

13 years agoFix stack ddt_zap_lookup()
Brian Behlendorf [Wed, 25 May 2011 21:13:18 +0000 (14:13 -0700)]
Fix stack ddt_zap_lookup()

Stack usage for ddt_zap_lookup() reduced from 368 bytes to 120
bytes.  This large stack allocation significantly contributed to
the likelyhood of a stack overflow when scrubbing/resilvering
dedup pools.

13 years agoRevert "Fix stack traverse_visitbp()"
Brian Behlendorf [Wed, 25 May 2011 23:09:57 +0000 (16:09 -0700)]
Revert "Fix stack traverse_visitbp()"

This abomination is no longer required because the zio's issued
during this recursive call path will now be handled asynchronously
by the taskq thread pool.

This reverts commit 6656bf56216f36805731298ee0f4de87ae6b6b3d.

13 years agoMake tgx_sync_thread zio's async
Brian Behlendorf [Wed, 25 May 2011 22:22:04 +0000 (15:22 -0700)]
Make tgx_sync_thread zio's async

The majority of the recursive operations performed by the dsl
are done either in the context of the tgx_sync_thread or during
pool import.  It is these recursive operations which contribute
greatly to the stack depth.  When this recursion is coupled with
a synchronous I/O in the same context overflow becomes possible.

Previously to handle this case I have focused on keeping the
individual stack frames as light as possible.  This is a good
idea as long as it can be done in a way which doesn't overly
complicate the code.  However, there is a better solution.

If we treat all zio's issued by the tgx_sync_thread as async then
we can use the tgx_sync_thread stack for the recursive parts, and
the zio_* threads for the I/O parts.  This effectively doubles our
available stack space with the only drawback being a small delay
to schedule the I/O.  However, in practice the scheduling time
is so much smaller than the actual I/O time this isn't an issue.
Another benefit of making the zio async is that the zio pipeline
is now parallel.  That should mean for CPU intensive pipelines
such as compression or dedup performance may be improved.

With this change in place the worst case stack usage observed so
far is 6902 bytes.  This is still higher than I'd like but
significantly improved.  Additional changes to specific functions
should improve this further.  This change allows us to revent
commit 6656bf5 which did some horrible things to the recursive
traverse_visitbp() callpath in the name of saving stack.

13 years agoFix 4K sector support
Brian Behlendorf [Thu, 26 May 2011 23:48:16 +0000 (16:48 -0700)]
Fix 4K sector support

Yesterday I ran across a 3TB drive which exposed 4K sectors to
Linux.  While I thought I had gotten this support correct it
turns out there were 2 subtle bugs which prevented it from
working.

  sudo ./cmd/zpool/zpool create -f large-sector /dev/sda
  cannot create 'large-sector': one or more devices is currently unavailable

1) The first issue was that it was possible that bdev_capacity()
would return the number of 512 byte sectors rather than the number
of 4096 sectors.  Internally, certain Linux functions only operate
with 512 byte sectors so you need to be careful.  To avoid any
confusion in the future I've updated bdev_capacity() to simply
return the device (or partition) capacity in bytes.  The higher
levels of ZFS want the value in bytes anyway so this is cleaner.

2) When creating a bio the ->bi_sector count must always be
expressed in 512 byte sectors.  The existing code would scale
the byte offset by the logical sector size.   Until now this was
always 512 so it never caused problems.  Trying a 4K sector drive
clearly exposed the issue.  The problem has been fixed by
hard coding the 512 byte sector which is exactly what the bio
code does internally.

With these changes I'm now able to create ZFS pools using 4K
sector drives.  No issues were observed during fairly extensive
testing.  This is also a low risk change if your using 512b
sectors devices because none of the logic changes.

Closes #256

13 years agoUse vmem_alloc() for zfs_ioc_userspace_many()
Brian Behlendorf [Fri, 20 May 2011 21:23:18 +0000 (14:23 -0700)]
Use vmem_alloc() for zfs_ioc_userspace_many()

The default buffer size when requesting multiple quota entries
is 100 times the zfs_useracct_t size.  In practice this works out
to exactly 27200 bytes.  Since this will be a short lived buffer
in a non-performance critical path it is preferable to vmem_alloc()
the needed memory.

13 years agoDefault to internal 'zfs userspace' implementation
Brian Behlendorf [Fri, 20 May 2011 17:25:41 +0000 (10:25 -0700)]
Default to internal 'zfs userspace' implementation

We will never bring over the pyzfs.py helper script from Solaris
to Linux.  Instead the missing functionality will be directly
integrated in to the zfs commands and libraries.  To avoid
confusion remove the warning about the missing pyzfs.py utility
and simply use the default internal support.

The Illumous developers are of the same mind and have proposed an
initial patch to do this which has been integrated in to the 'allow'
development branch.  After some additional testing this code
can be merged in to master as the right long term solution.

13 years agoPass caller's credential in zfsdev_ioctl()
Brian Behlendorf [Fri, 20 May 2011 17:12:25 +0000 (10:12 -0700)]
Pass caller's credential in zfsdev_ioctl()

Initially when zfsdev_ioctl() was ported to Linux we didn't have
any credential support implemented.  So at the time we simply
passed NULL which wasn't much of a problem since most of the
secpolicy code was disabled.

However, one exception is quota handling which does require the
credential.  Now that proper credentials are supported we can
safely start passing the callers credential.  This is also an
initial step towards fully implemented the zfs secpolicy.

13 years agoFix 'negative objects to delete' warning
Brian Behlendorf [Mon, 9 May 2011 19:18:46 +0000 (12:18 -0700)]
Fix 'negative objects to delete' warning

Normally when the arc_shrinker_func() function is called the return
value should be:

   >=0 - To indicate the number of freeable objects in the cache, or
   -1  - To indicate this cache should be skipped

However, when the shrinker callback is called with 'nr_to_scan' equal
to zero.  The caller simply wants the number of freeable objects in
the cache and we must never return -1.  This patch reorders the
first two conditionals in arc_shrinker_func() to ensure this behavior.

This patch also now explictly casts arc_size and arc_c_min to signed
int64_t types so MAX(x, 0) works as expected.  As unsigned types
we would never see an negative value which defeated the purpose of
the MAX() lower bound and broke the shrinker logic.

Finally, when nr_to_scan is non-zero we explictly prevent all reclaim
below arc_c_min.  This is done to prevent the Linux page cache from
completely crowding out the ARC.  This limit is tunable and some
experimentation is likely going to be required to set it exactly right.
For now we're sticking with the OpenSolaris defaults.

Closes #218
Closes #243

13 years agoFix distribution detection for gentoo
Alexey Shvetsov [Sat, 14 May 2011 14:25:37 +0000 (18:25 +0400)]
Fix distribution detection for gentoo

Also this may fix other distros because some of them also provide
/etc/lsb-release not only ubuntu.

Closes #244

13 years agoUpdate synchronous open zfs_close() comment
Brian Behlendorf [Fri, 13 May 2011 15:16:10 +0000 (08:16 -0700)]
Update synchronous open zfs_close() comment

The comment in zfs_close() pertaining to decrementing the synchronous
open count needs to be updated for Linux.  The code was already
updated to be correct, but the comment was missed and is now misleading.
Under Linux the zfs_close() hook is only called once when the final
reference is dropped.  This differs from Solaris where zfs_close()
is called for each close.

Closes #237

13 years agoRemove root 'ls' after mount workaround
Alexey Shvetsov [Thu, 12 May 2011 21:54:03 +0000 (14:54 -0700)]
Remove root 'ls' after mount workaround

This workaround was introduced to workaround issue #164.  This
issue was fixed by commit 5f35b19 so the workaround can be safely
dropped from both the zfs.fedora and zfs.gentoo init scripts.

13 years agoFix zfs.gentoo init script logic
Alexey Shvetsov [Tue, 10 May 2011 20:22:35 +0000 (00:22 +0400)]
Fix zfs.gentoo init script logic

* Fix zfs.ko module check
* Check 'zfs umount -a' return value