2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
2013-03-08 18:41:28 +00:00
|
|
|
* Copyright (c) 2013 by Delphix. All rights reserved.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Portions Copyright 2007 Jeremy Teo */
|
2010-05-28 20:45:14 +00:00
|
|
|
/* Portions Copyright 2010 Robert Milkowski */
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-26 18:45:02 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/vfs.h>
|
|
|
|
#include <sys/vfs_opreg.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/kmem.h>
|
|
|
|
#include <sys/taskq.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/vmsystm.h>
|
|
|
|
#include <sys/atomic.h>
|
|
|
|
#include <vm/pvn.h>
|
|
|
|
#include <sys/pathname.h>
|
|
|
|
#include <sys/cmn_err.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include <sys/zfs_dir.h>
|
|
|
|
#include <sys/zfs_acl.h>
|
|
|
|
#include <sys/zfs_ioctl.h>
|
|
|
|
#include <sys/fs/zfs.h>
|
|
|
|
#include <sys/dmu.h>
|
2010-05-28 20:45:14 +00:00
|
|
|
#include <sys/dmu_objset.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
#include <sys/spa.h>
|
|
|
|
#include <sys/txg.h>
|
|
|
|
#include <sys/dbuf.h>
|
|
|
|
#include <sys/zap.h>
|
2010-05-28 20:45:14 +00:00
|
|
|
#include <sys/sa.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
#include <sys/dirent.h>
|
|
|
|
#include <sys/policy.h>
|
|
|
|
#include <sys/sunddi.h>
|
2008-12-03 20:09:06 +00:00
|
|
|
#include <sys/sid.h>
|
2011-01-26 20:45:24 +00:00
|
|
|
#include <sys/mode.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
#include "fs/fs_subr.h"
|
2011-11-11 07:15:53 +00:00
|
|
|
#include <sys/zfs_ctldir.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
#include <sys/zfs_fuid.h>
|
2010-05-28 20:45:14 +00:00
|
|
|
#include <sys/zfs_sa.h>
|
2010-12-17 19:18:08 +00:00
|
|
|
#include <sys/zfs_vnops.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
#include <sys/dnlc.h>
|
|
|
|
#include <sys/zfs_rlock.h>
|
|
|
|
#include <sys/extdirent.h>
|
|
|
|
#include <sys/kidmap.h>
|
2010-05-28 20:45:14 +00:00
|
|
|
#include <sys/cred.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
#include <sys/attr.h>
|
2011-06-25 14:06:37 +00:00
|
|
|
#include <sys/zpl.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Programming rules.
|
|
|
|
*
|
|
|
|
* Each vnode op performs some logical unit of work. To do this, the ZPL must
|
|
|
|
* properly lock its in-core state, create a DMU transaction, do the work,
|
|
|
|
* record this work in the intent log (ZIL), commit the DMU transaction,
|
|
|
|
* and wait for the intent log to commit if it is a synchronous operation.
|
|
|
|
* Moreover, the vnode ops must work in both normal and log replay context.
|
|
|
|
* The ordering of events is important to avoid deadlocks and references
|
|
|
|
* to freed memory. The example below illustrates the following Big Rules:
|
|
|
|
*
|
|
|
|
* (1) A check must be made in each zfs thread for a mounted file system.
|
2011-02-08 19:16:06 +00:00
|
|
|
* This is done avoiding races using ZFS_ENTER(zsb).
|
|
|
|
* A ZFS_EXIT(zsb) is needed before all returns. Any znodes
|
2008-11-20 20:01:55 +00:00
|
|
|
* must be checked with ZFS_VERIFY_ZP(zp). Both of these macros
|
|
|
|
* can return EIO from the calling function.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* (2) iput() should always be the last thing except for zil_commit()
|
2008-11-20 20:01:55 +00:00
|
|
|
* (if necessary) and ZFS_EXIT(). This is for 3 reasons:
|
|
|
|
* First, if it's the last reference, the vnode/znode
|
|
|
|
* can be freed, so the zp may point to freed memory. Second, the last
|
|
|
|
* reference will call zfs_zinactive(), which may induce a lot of work --
|
|
|
|
* pushing cached pages (which acquires range locks) and syncing out
|
|
|
|
* cached atime changes. Third, zfs_zinactive() may require a new tx,
|
|
|
|
* which could deadlock the system if you were already holding one.
|
2014-08-04 20:30:20 +00:00
|
|
|
* If you must call iput() within a tx then use zfs_iput_async().
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* (3) All range locks must be grabbed before calling dmu_tx_assign(),
|
|
|
|
* as they can span dmu_tx_assign() calls.
|
|
|
|
*
|
2013-11-22 23:13:18 +00:00
|
|
|
* (4) If ZPL locks are held, pass TXG_NOWAIT as the second argument to
|
|
|
|
* dmu_tx_assign(). This is critical because we don't want to block
|
|
|
|
* while holding locks.
|
|
|
|
*
|
|
|
|
* If no ZPL locks are held (aside from ZFS_ENTER()), use TXG_WAIT. This
|
|
|
|
* reduces lock contention and CPU usage when we must wait (note that if
|
|
|
|
* throughput is constrained by the storage, nearly every transaction
|
|
|
|
* must wait).
|
|
|
|
*
|
|
|
|
* Note, in particular, that if a lock is sometimes acquired before
|
|
|
|
* the tx assigns, and sometimes after (e.g. z_lock), then failing
|
|
|
|
* to use a non-blocking assign can deadlock the system. The scenario:
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Thread A has grabbed a lock before calling dmu_tx_assign().
|
|
|
|
* Thread B is in an already-assigned tx, and blocks for this lock.
|
|
|
|
* Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open()
|
|
|
|
* forever, because the previous txg can't quiesce until B's tx commits.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* If dmu_tx_assign() returns ERESTART and zsb->z_assign is TXG_NOWAIT,
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
* then drop all locks, call dmu_tx_wait(), and try again. On subsequent
|
|
|
|
* calls to dmu_tx_assign(), pass TXG_WAITED rather than TXG_NOWAIT,
|
|
|
|
* to indicate that this operation has already called dmu_tx_wait().
|
|
|
|
* This will ensure that we don't retry forever, waiting a short bit
|
|
|
|
* each time.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* (5) If the operation succeeded, generate the intent log entry for it
|
|
|
|
* before dropping locks. This ensures that the ordering of events
|
|
|
|
* in the intent log matches the order in which they actually occurred.
|
2013-06-11 17:12:34 +00:00
|
|
|
* During ZIL replay the zfs_log_* functions will update the sequence
|
2009-01-15 21:59:39 +00:00
|
|
|
* number to indicate the zil transaction has replayed.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* (6) At the end of each vnode op, the DMU tx must always commit,
|
|
|
|
* regardless of whether there were any errors.
|
|
|
|
*
|
2010-08-26 21:24:34 +00:00
|
|
|
* (7) After dropping all locks, invoke zil_commit(zilog, foid)
|
2008-11-20 20:01:55 +00:00
|
|
|
* to ensure that synchronous semantics are provided when necessary.
|
|
|
|
*
|
|
|
|
* In general, this is how things should be ordered in each vnode op:
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* ZFS_ENTER(zsb); // exit if unmounted
|
2008-11-20 20:01:55 +00:00
|
|
|
* top:
|
2011-02-08 19:16:06 +00:00
|
|
|
* zfs_dirent_lock(&dl, ...) // lock directory entry (may igrab())
|
2008-11-20 20:01:55 +00:00
|
|
|
* rw_enter(...); // grab any other locks you need
|
|
|
|
* tx = dmu_tx_create(...); // get DMU tx
|
|
|
|
* dmu_tx_hold_*(); // hold each object you might modify
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
* error = dmu_tx_assign(tx, waited ? TXG_WAITED : TXG_NOWAIT);
|
2008-11-20 20:01:55 +00:00
|
|
|
* if (error) {
|
|
|
|
* rw_exit(...); // drop locks
|
|
|
|
* zfs_dirent_unlock(dl); // unlock directory entry
|
2011-02-08 19:16:06 +00:00
|
|
|
* iput(...); // release held vnodes
|
2009-01-15 21:59:39 +00:00
|
|
|
* if (error == ERESTART) {
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
* waited = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
* dmu_tx_wait(tx);
|
|
|
|
* dmu_tx_abort(tx);
|
|
|
|
* goto top;
|
|
|
|
* }
|
|
|
|
* dmu_tx_abort(tx); // abort DMU tx
|
2011-02-08 19:16:06 +00:00
|
|
|
* ZFS_EXIT(zsb); // finished in zfs
|
2008-11-20 20:01:55 +00:00
|
|
|
* return (error); // really out of space
|
|
|
|
* }
|
|
|
|
* error = do_real_work(); // do whatever this VOP does
|
|
|
|
* if (error == 0)
|
|
|
|
* zfs_log_*(...); // on success, make ZIL entry
|
|
|
|
* dmu_tx_commit(tx); // commit DMU tx -- error or not
|
|
|
|
* rw_exit(...); // drop locks
|
|
|
|
* zfs_dirent_unlock(dl); // unlock directory entry
|
2011-02-08 19:16:06 +00:00
|
|
|
* iput(...); // release held vnodes
|
2010-08-26 21:24:34 +00:00
|
|
|
* zil_commit(zilog, foid); // synchronous when necessary
|
2011-02-08 19:16:06 +00:00
|
|
|
* ZFS_EXIT(zsb); // finished in zfs
|
2008-11-20 20:01:55 +00:00
|
|
|
* return (error); // done, report error
|
|
|
|
*/
|
|
|
|
|
2011-03-08 19:04:51 +00:00
|
|
|
/*
|
|
|
|
* Virus scanning is unsupported. It would be possible to add a hook
|
|
|
|
* here to performance the required virus scan. This could be done
|
|
|
|
* entirely in the kernel or potentially as an update to invoke a
|
|
|
|
* scanning utility.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfs_vscan(struct inode *ip, cred_t *cr, int async)
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
zfs_open(struct inode *ip, int mode, int flag, cred_t *cr)
|
|
|
|
{
|
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
|
|
|
|
|
|
|
ZFS_ENTER(zsb);
|
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
|
|
|
/* Honor ZFS_APPENDONLY file attribute */
|
|
|
|
if ((mode & FMODE_WRITE) && (zp->z_pflags & ZFS_APPENDONLY) &&
|
|
|
|
((flag & O_APPEND) == 0)) {
|
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EPERM));
|
2011-03-08 19:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Virus scan eligible files on open */
|
|
|
|
if (!zfs_has_ctldir(zp) && zsb->z_vscan && S_ISREG(ip->i_mode) &&
|
|
|
|
!(zp->z_pflags & ZFS_AV_QUARANTINED) && zp->z_size > 0) {
|
|
|
|
if (zfs_vscan(ip, cr, 0) != 0) {
|
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EACCES));
|
2011-03-08 19:04:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keep a count of the synchronous opens in the znode */
|
|
|
|
if (flag & O_SYNC)
|
|
|
|
atomic_inc_32(&zp->z_sync_cnt);
|
|
|
|
|
|
|
|
ZFS_EXIT(zsb);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(zfs_open);
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
zfs_close(struct inode *ip, int flag, cred_t *cr)
|
|
|
|
{
|
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
|
|
|
|
|
|
|
ZFS_ENTER(zsb);
|
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
2013-12-17 18:18:25 +00:00
|
|
|
/* Decrement the synchronous opens in the znode */
|
2011-03-08 19:04:51 +00:00
|
|
|
if (flag & O_SYNC)
|
2013-12-17 18:18:25 +00:00
|
|
|
atomic_dec_32(&zp->z_sync_cnt);
|
2011-03-08 19:04:51 +00:00
|
|
|
|
|
|
|
if (!zfs_has_ctldir(zp) && zsb->z_vscan && S_ISREG(ip->i_mode) &&
|
|
|
|
!(zp->z_pflags & ZFS_AV_QUARANTINED) && zp->z_size > 0)
|
|
|
|
VERIFY(zfs_vscan(ip, cr, 1) == 0);
|
|
|
|
|
|
|
|
ZFS_EXIT(zsb);
|
2012-12-12 00:58:44 +00:00
|
|
|
return (0);
|
2011-03-08 19:04:51 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(zfs_close);
|
|
|
|
|
2013-06-13 17:51:09 +00:00
|
|
|
#if defined(SEEK_HOLE) && defined(SEEK_DATA)
|
2013-07-01 16:24:43 +00:00
|
|
|
/*
|
2013-06-13 17:51:09 +00:00
|
|
|
* Lseek support for finding holes (cmd == SEEK_HOLE) and
|
|
|
|
* data (cmd == SEEK_DATA). "off" is an in/out parameter.
|
2013-07-01 16:24:43 +00:00
|
|
|
*/
|
|
|
|
static int
|
2013-06-13 17:51:09 +00:00
|
|
|
zfs_holey_common(struct inode *ip, int cmd, loff_t *off)
|
2013-07-01 16:24:43 +00:00
|
|
|
{
|
2013-06-13 17:51:09 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
2013-07-01 16:24:43 +00:00
|
|
|
uint64_t noff = (uint64_t)*off; /* new offset */
|
|
|
|
uint64_t file_sz;
|
|
|
|
int error;
|
|
|
|
boolean_t hole;
|
|
|
|
|
|
|
|
file_sz = zp->z_size;
|
|
|
|
if (noff >= file_sz) {
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(ENXIO));
|
2013-07-01 16:24:43 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 17:51:09 +00:00
|
|
|
if (cmd == SEEK_HOLE)
|
2013-07-01 16:24:43 +00:00
|
|
|
hole = B_TRUE;
|
|
|
|
else
|
|
|
|
hole = B_FALSE;
|
|
|
|
|
2013-06-13 17:51:09 +00:00
|
|
|
error = dmu_offset_next(ZTOZSB(zp)->z_os, zp->z_id, hole, &noff);
|
2013-07-01 16:24:43 +00:00
|
|
|
|
2014-09-17 15:25:10 +00:00
|
|
|
if (error == ESRCH)
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(ENXIO));
|
2014-09-17 15:25:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We could find a hole that begins after the logical end-of-file,
|
|
|
|
* because dmu_offset_next() only works on whole blocks. If the
|
|
|
|
* EOF falls mid-block, then indicate that the "virtual hole"
|
|
|
|
* at the end of the file begins at the logical EOF, rather than
|
|
|
|
* at the end of the last block.
|
|
|
|
*/
|
|
|
|
if (noff > file_sz) {
|
|
|
|
ASSERT(hole);
|
|
|
|
noff = file_sz;
|
2013-07-01 16:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (noff < *off)
|
|
|
|
return (error);
|
|
|
|
*off = noff;
|
|
|
|
return (error);
|
|
|
|
}
|
2013-06-13 17:51:09 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
zfs_holey(struct inode *ip, int cmd, loff_t *off)
|
|
|
|
{
|
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ZFS_ENTER(zsb);
|
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
|
|
|
error = zfs_holey_common(ip, cmd, off);
|
|
|
|
|
|
|
|
ZFS_EXIT(zsb);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(zfs_holey);
|
|
|
|
#endif /* SEEK_HOLE && SEEK_DATA */
|
2013-07-01 16:24:43 +00:00
|
|
|
|
2011-02-03 18:34:05 +00:00
|
|
|
#if defined(_KERNEL)
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* When a file is memory mapped, we must keep the IO data synchronized
|
|
|
|
* between the DMU cache and the memory mapped pages. What this means:
|
|
|
|
*
|
|
|
|
* On Write: If we find a memory mapped page, we write to *both*
|
|
|
|
* the page and the dmu buffer.
|
|
|
|
*/
|
2009-02-18 20:51:31 +00:00
|
|
|
static void
|
2011-02-03 18:34:05 +00:00
|
|
|
update_pages(struct inode *ip, int64_t start, int len,
|
|
|
|
objset_t *os, uint64_t oid)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-03 18:34:05 +00:00
|
|
|
struct address_space *mp = ip->i_mapping;
|
|
|
|
struct page *pp;
|
|
|
|
uint64_t nbytes;
|
2009-02-18 20:51:31 +00:00
|
|
|
int64_t off;
|
2011-02-03 18:34:05 +00:00
|
|
|
void *pb;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-03 18:34:05 +00:00
|
|
|
off = start & (PAGE_CACHE_SIZE-1);
|
|
|
|
for (start &= PAGE_CACHE_MASK; len > 0; start += PAGE_CACHE_SIZE) {
|
|
|
|
nbytes = MIN(PAGE_CACHE_SIZE - off, len);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-03 18:34:05 +00:00
|
|
|
pp = find_lock_page(mp, start >> PAGE_CACHE_SHIFT);
|
|
|
|
if (pp) {
|
|
|
|
if (mapping_writably_mapped(mp))
|
|
|
|
flush_dcache_page(pp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-03 18:34:05 +00:00
|
|
|
pb = kmap(pp);
|
|
|
|
(void) dmu_read(os, oid, start+off, nbytes, pb+off,
|
2009-07-02 22:44:48 +00:00
|
|
|
DMU_READ_PREFETCH);
|
2011-02-03 18:34:05 +00:00
|
|
|
kunmap(pp);
|
|
|
|
|
|
|
|
if (mapping_writably_mapped(mp))
|
|
|
|
flush_dcache_page(pp);
|
|
|
|
|
|
|
|
mark_page_accessed(pp);
|
|
|
|
SetPageUptodate(pp);
|
|
|
|
ClearPageError(pp);
|
|
|
|
unlock_page(pp);
|
|
|
|
page_cache_release(pp);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2011-02-03 18:34:05 +00:00
|
|
|
|
2009-02-18 20:51:31 +00:00
|
|
|
len -= nbytes;
|
2008-11-20 20:01:55 +00:00
|
|
|
off = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When a file is memory mapped, we must keep the IO data synchronized
|
|
|
|
* between the DMU cache and the memory mapped pages. What this means:
|
|
|
|
*
|
|
|
|
* On Read: We "read" preferentially from memory mapped pages,
|
|
|
|
* else we default from the dmu buffer.
|
|
|
|
*
|
|
|
|
* NOTE: We will always "break up" the IO into PAGESIZE uiomoves when
|
2013-06-11 17:12:34 +00:00
|
|
|
* the file is memory mapped.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
static int
|
2011-02-08 19:16:06 +00:00
|
|
|
mappedread(struct inode *ip, int nbytes, uio_t *uio)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-03 18:34:05 +00:00
|
|
|
struct address_space *mp = ip->i_mapping;
|
|
|
|
struct page *pp;
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
objset_t *os = ITOZSB(ip)->z_os;
|
2008-11-20 20:01:55 +00:00
|
|
|
int64_t start, off;
|
2011-02-03 18:34:05 +00:00
|
|
|
uint64_t bytes;
|
2008-11-20 20:01:55 +00:00
|
|
|
int len = nbytes;
|
|
|
|
int error = 0;
|
2011-02-03 18:34:05 +00:00
|
|
|
void *pb;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
start = uio->uio_loffset;
|
2011-02-03 18:34:05 +00:00
|
|
|
off = start & (PAGE_CACHE_SIZE-1);
|
|
|
|
for (start &= PAGE_CACHE_MASK; len > 0; start += PAGE_CACHE_SIZE) {
|
|
|
|
bytes = MIN(PAGE_CACHE_SIZE - off, len);
|
|
|
|
|
|
|
|
pp = find_lock_page(mp, start >> PAGE_CACHE_SHIFT);
|
|
|
|
if (pp) {
|
|
|
|
ASSERT(PageUptodate(pp));
|
|
|
|
|
|
|
|
pb = kmap(pp);
|
|
|
|
error = uiomove(pb + off, bytes, UIO_READ, uio);
|
|
|
|
kunmap(pp);
|
|
|
|
|
|
|
|
if (mapping_writably_mapped(mp))
|
|
|
|
flush_dcache_page(pp);
|
|
|
|
|
|
|
|
mark_page_accessed(pp);
|
|
|
|
unlock_page(pp);
|
|
|
|
page_cache_release(pp);
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
|
|
|
error = dmu_read_uio(os, zp->z_id, uio, bytes);
|
|
|
|
}
|
2011-02-03 18:34:05 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
len -= bytes;
|
|
|
|
off = 0;
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
2011-02-03 18:34:05 +00:00
|
|
|
#endif /* _KERNEL */
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-05-03 22:09:28 +00:00
|
|
|
unsigned long zfs_read_chunk_size = 1024 * 1024; /* Tunable */
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read bytes from specified file into supplied buffer.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: ip - inode of file to be read from.
|
2008-11-20 20:01:55 +00:00
|
|
|
* uio - structure supplying read location, range info,
|
|
|
|
* and return buffer.
|
2011-02-03 18:34:05 +00:00
|
|
|
* ioflag - FSYNC flags; used to provide FRSYNC semantics.
|
|
|
|
* O_DIRECT flag; used to bypass page cache.
|
2008-11-20 20:01:55 +00:00
|
|
|
* cr - credentials of caller.
|
|
|
|
*
|
|
|
|
* OUT: uio - updated offset and range, buffer filled.
|
|
|
|
*
|
2013-06-11 17:12:34 +00:00
|
|
|
* RETURN: 0 on success, error code on failure.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Side Effects:
|
2011-02-08 19:16:06 +00:00
|
|
|
* inode - atime updated if byte count > 0
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_read(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
objset_t *os;
|
|
|
|
ssize_t n, nbytes;
|
2010-12-16 22:05:42 +00:00
|
|
|
int error = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
rl_t *rl;
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_UIO_ZEROCOPY
|
2010-05-28 20:45:14 +00:00
|
|
|
xuio_t *xuio = NULL;
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_UIO_ZEROCOPY */
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
2011-02-08 19:16:06 +00:00
|
|
|
os = zsb->z_os;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (zp->z_pflags & ZFS_AV_QUARANTINED) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EACCES));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate file offset
|
|
|
|
*/
|
|
|
|
if (uio->uio_loffset < (offset_t)0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fasttrack empty reads
|
|
|
|
*/
|
|
|
|
if (uio->uio_resid == 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're in FRSYNC mode, sync out this znode before reading it.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (ioflag & FRSYNC || zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
|
|
|
|
zil_commit(zsb->z_log, zp->z_id);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock the range against changes.
|
|
|
|
*/
|
|
|
|
rl = zfs_range_lock(zp, uio->uio_loffset, uio->uio_resid, RL_READER);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are reading past end-of-file we can skip
|
|
|
|
* to the end; but we might still need to set atime.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
if (uio->uio_loffset >= zp->z_size) {
|
2008-11-20 20:01:55 +00:00
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(uio->uio_loffset < zp->z_size);
|
|
|
|
n = MIN(uio->uio_resid, zp->z_size - uio->uio_loffset);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_UIO_ZEROCOPY
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((uio->uio_extflg == UIO_XUIO) &&
|
|
|
|
(((xuio_t *)uio)->xu_type == UIOTYPE_ZEROCOPY)) {
|
|
|
|
int nblk;
|
|
|
|
int blksz = zp->z_blksz;
|
|
|
|
uint64_t offset = uio->uio_loffset;
|
|
|
|
|
|
|
|
xuio = (xuio_t *)uio;
|
|
|
|
if ((ISP2(blksz))) {
|
|
|
|
nblk = (P2ROUNDUP(offset + n, blksz) - P2ALIGN(offset,
|
|
|
|
blksz)) / blksz;
|
|
|
|
} else {
|
|
|
|
ASSERT(offset + n <= blksz);
|
|
|
|
nblk = 1;
|
|
|
|
}
|
|
|
|
(void) dmu_xuio_init(xuio, nblk);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (vn_has_cached_data(ip)) {
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* For simplicity, we always allocate a full buffer
|
|
|
|
* even if we only expect to read a portion of a block.
|
|
|
|
*/
|
|
|
|
while (--nblk >= 0) {
|
|
|
|
(void) dmu_xuio_add(xuio,
|
|
|
|
dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
|
|
|
|
blksz), 0, blksz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_UIO_ZEROCOPY */
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
while (n > 0) {
|
|
|
|
nbytes = MIN(n, zfs_read_chunk_size -
|
|
|
|
P2PHASE(uio->uio_loffset, zfs_read_chunk_size));
|
|
|
|
|
2011-02-03 18:34:05 +00:00
|
|
|
if (zp->z_is_mapped && !(ioflag & O_DIRECT))
|
2011-02-08 19:16:06 +00:00
|
|
|
error = mappedread(ip, nbytes, uio);
|
2008-11-20 20:01:55 +00:00
|
|
|
else
|
|
|
|
error = dmu_read_uio(os, zp->z_id, uio, nbytes);
|
2011-02-03 18:34:05 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (error) {
|
|
|
|
/* convert checksum errors into IO errors */
|
|
|
|
if (error == ECKSUM)
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(EIO);
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
n -= nbytes;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
zfs_range_unlock(rl);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ACCESSTIME_STAMP(zsb, zp);
|
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_read);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the bytes to a file.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: ip - inode of file to be written to.
|
2008-11-20 20:01:55 +00:00
|
|
|
* uio - structure supplying write location, range info,
|
|
|
|
* and data buffer.
|
|
|
|
* ioflag - FAPPEND flag set if in append mode.
|
2011-02-03 18:34:05 +00:00
|
|
|
* O_DIRECT flag; used to bypass page cache.
|
2008-11-20 20:01:55 +00:00
|
|
|
* cr - credentials of caller.
|
|
|
|
*
|
|
|
|
* OUT: uio - updated offset and range.
|
|
|
|
*
|
|
|
|
* RETURN: 0 if success
|
|
|
|
* error code if failure
|
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* ip - ctime|mtime updated if byte count > 0
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/* ARGSUSED */
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
rlim64_t limit = uio->uio_limit;
|
2008-11-20 20:01:55 +00:00
|
|
|
ssize_t start_resid = uio->uio_resid;
|
|
|
|
ssize_t tx_bytes;
|
|
|
|
uint64_t end_size;
|
|
|
|
dmu_tx_t *tx;
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_sb_t *zsb = ZTOZSB(zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
zilog_t *zilog;
|
|
|
|
offset_t woff;
|
|
|
|
ssize_t n, nbytes;
|
|
|
|
rl_t *rl;
|
2011-02-08 19:16:06 +00:00
|
|
|
int max_blksz = zsb->z_max_blksz;
|
|
|
|
int error = 0;
|
2009-07-02 22:44:48 +00:00
|
|
|
arc_buf_t *abuf;
|
2011-02-08 19:16:06 +00:00
|
|
|
iovec_t *aiov = NULL;
|
2010-05-28 20:45:14 +00:00
|
|
|
xuio_t *xuio = NULL;
|
|
|
|
int i_iov = 0;
|
|
|
|
iovec_t *iovp = uio->uio_iov;
|
|
|
|
int write_eof;
|
|
|
|
int count = 0;
|
|
|
|
sa_bulk_attr_t bulk[4];
|
|
|
|
uint64_t mtime[2], ctime[2];
|
2011-02-08 19:16:06 +00:00
|
|
|
ASSERTV(int iovcnt = uio->uio_iovcnt);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fasttrack empty write
|
|
|
|
*/
|
|
|
|
n = start_resid;
|
|
|
|
if (n == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T)
|
|
|
|
limit = MAXOFFSET_T;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zsb), NULL, &mtime, 16);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zsb), NULL, &ctime, 16);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zsb), NULL, &zp->z_size, 8);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zsb), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&zp->z_pflags, 8);
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
/*
|
|
|
|
* If immutable or not appending then return EPERM
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((zp->z_pflags & (ZFS_IMMUTABLE | ZFS_READONLY)) ||
|
|
|
|
((zp->z_pflags & ZFS_APPENDONLY) && !(ioflag & FAPPEND) &&
|
|
|
|
(uio->uio_loffset < zp->z_size))) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EPERM));
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
zilog = zsb->z_log;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* Validate file offset
|
|
|
|
*/
|
|
|
|
woff = ioflag & FAPPEND ? zp->z_size : uio->uio_loffset;
|
|
|
|
if (woff < 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Pre-fault the pages to ensure slow (eg NFS) pages
|
|
|
|
* don't hold up txg.
|
2010-05-28 20:45:14 +00:00
|
|
|
* Skip this if uio contains loaned arc_buf.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2013-09-02 04:22:30 +00:00
|
|
|
#ifdef HAVE_UIO_ZEROCOPY
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((uio->uio_extflg == UIO_XUIO) &&
|
|
|
|
(((xuio_t *)uio)->xu_type == UIOTYPE_ZEROCOPY))
|
|
|
|
xuio = (xuio_t *)uio;
|
|
|
|
else
|
2013-09-02 04:22:30 +00:00
|
|
|
#endif
|
2010-08-26 21:24:34 +00:00
|
|
|
uio_prefaultpages(MIN(n, max_blksz), uio);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If in append mode, set the io offset pointer to eof.
|
|
|
|
*/
|
|
|
|
if (ioflag & FAPPEND) {
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* Obtain an appending range lock to guarantee file append
|
|
|
|
* semantics. We reset the write offset once we have the lock.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
rl = zfs_range_lock(zp, 0, n, RL_APPEND);
|
2010-05-28 20:45:14 +00:00
|
|
|
woff = rl->r_off;
|
2008-11-20 20:01:55 +00:00
|
|
|
if (rl->r_len == UINT64_MAX) {
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* We overlocked the file because this write will cause
|
|
|
|
* the file block size to increase.
|
|
|
|
* Note that zp_size cannot change with this lock held.
|
|
|
|
*/
|
|
|
|
woff = zp->z_size;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
uio->uio_loffset = woff;
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* Note that if the file block size will change as a result of
|
|
|
|
* this write, then this range lock will lock the entire file
|
|
|
|
* so that we can re-write the block safely.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
rl = zfs_range_lock(zp, woff, n, RL_WRITER);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (woff >= limit) {
|
|
|
|
zfs_range_unlock(rl);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EFBIG));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((woff + n) > limit || woff > (limit - n))
|
|
|
|
n = limit - woff;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/* Will this write extend the file length? */
|
|
|
|
write_eof = (woff + n > zp->z_size);
|
|
|
|
|
|
|
|
end_size = MAX(zp->z_size, woff + n);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the file in reasonable size chunks. Each chunk is written
|
|
|
|
* in a separate transaction; this keeps the intent log records small
|
|
|
|
* and allows us to do more fine-grained space accounting.
|
|
|
|
*/
|
|
|
|
while (n > 0) {
|
2009-07-02 22:44:48 +00:00
|
|
|
abuf = NULL;
|
|
|
|
woff = uio->uio_loffset;
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zfs_owner_overquota(zsb, zp, B_FALSE) ||
|
|
|
|
zfs_owner_overquota(zsb, zp, B_TRUE)) {
|
2009-07-02 22:44:48 +00:00
|
|
|
if (abuf != NULL)
|
|
|
|
dmu_return_arcbuf(abuf);
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(EDQUOT);
|
2009-07-02 22:44:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (xuio && abuf == NULL) {
|
|
|
|
ASSERT(i_iov < iovcnt);
|
|
|
|
aiov = &iovp[i_iov];
|
|
|
|
abuf = dmu_xuio_arcbuf(xuio, i_iov);
|
|
|
|
dmu_xuio_clear(xuio, i_iov);
|
|
|
|
ASSERT((aiov->iov_base == abuf->b_data) ||
|
|
|
|
((char *)aiov->iov_base - (char *)abuf->b_data +
|
|
|
|
aiov->iov_len == arc_buf_size(abuf)));
|
|
|
|
i_iov++;
|
|
|
|
} else if (abuf == NULL && n >= max_blksz &&
|
|
|
|
woff >= zp->z_size &&
|
2009-07-02 22:44:48 +00:00
|
|
|
P2PHASE(woff, max_blksz) == 0 &&
|
|
|
|
zp->z_blksz == max_blksz) {
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* This write covers a full block. "Borrow" a buffer
|
|
|
|
* from the dmu so that we can fill it before we enter
|
|
|
|
* a transaction. This avoids the possibility of
|
|
|
|
* holding up the transaction if the data copy hangs
|
|
|
|
* up on a pagefault (e.g., from an NFS server mapping).
|
|
|
|
*/
|
2009-07-02 22:44:48 +00:00
|
|
|
size_t cbytes;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
|
|
|
|
max_blksz);
|
2009-07-02 22:44:48 +00:00
|
|
|
ASSERT(abuf != NULL);
|
|
|
|
ASSERT(arc_buf_size(abuf) == max_blksz);
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = uiocopy(abuf->b_data, max_blksz,
|
|
|
|
UIO_WRITE, uio, &cbytes))) {
|
2009-07-02 22:44:48 +00:00
|
|
|
dmu_return_arcbuf(abuf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ASSERT(cbytes == max_blksz);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Start a transaction.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
tx = dmu_tx_create(zsb->z_os);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz));
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_sa_upgrade_txholds(tx, zp);
|
2013-11-22 23:13:18 +00:00
|
|
|
error = dmu_tx_assign(tx, TXG_WAIT);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error) {
|
|
|
|
dmu_tx_abort(tx);
|
2009-07-02 22:44:48 +00:00
|
|
|
if (abuf != NULL)
|
|
|
|
dmu_return_arcbuf(abuf);
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If zfs_range_lock() over-locked we grow the blocksize
|
|
|
|
* and then reduce the lock range. This will only happen
|
|
|
|
* on the first iteration since zfs_range_reduce() will
|
|
|
|
* shrink down r_len to the appropriate size.
|
|
|
|
*/
|
|
|
|
if (rl->r_len == UINT64_MAX) {
|
|
|
|
uint64_t new_blksz;
|
|
|
|
|
|
|
|
if (zp->z_blksz > max_blksz) {
|
|
|
|
ASSERT(!ISP2(zp->z_blksz));
|
|
|
|
new_blksz = MIN(end_size, SPA_MAXBLOCKSIZE);
|
|
|
|
} else {
|
|
|
|
new_blksz = MIN(end_size, max_blksz);
|
|
|
|
}
|
|
|
|
zfs_grow_blocksize(zp, new_blksz, tx);
|
|
|
|
zfs_range_reduce(rl, woff, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - should we really limit each write to z_max_blksz?
|
|
|
|
* Perhaps we should use SPA_MAXBLOCKSIZE chunks?
|
|
|
|
*/
|
|
|
|
nbytes = MIN(n, max_blksz - P2PHASE(woff, max_blksz));
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
if (abuf == NULL) {
|
|
|
|
tx_bytes = uio->uio_resid;
|
2010-05-28 20:45:14 +00:00
|
|
|
error = dmu_write_uio_dbuf(sa_get_db(zp->z_sa_hdl),
|
|
|
|
uio, nbytes, tx);
|
2009-07-02 22:44:48 +00:00
|
|
|
tx_bytes -= uio->uio_resid;
|
|
|
|
} else {
|
|
|
|
tx_bytes = nbytes;
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(xuio == NULL || tx_bytes == aiov->iov_len);
|
|
|
|
/*
|
|
|
|
* If this is not a full block write, but we are
|
|
|
|
* extending the file past EOF and this data starts
|
|
|
|
* block-aligned, use assign_arcbuf(). Otherwise,
|
|
|
|
* write via dmu_write().
|
|
|
|
*/
|
|
|
|
if (tx_bytes < max_blksz && (!write_eof ||
|
|
|
|
aiov->iov_base != abuf->b_data)) {
|
|
|
|
ASSERT(xuio);
|
2011-02-08 19:16:06 +00:00
|
|
|
dmu_write(zsb->z_os, zp->z_id, woff,
|
2010-05-28 20:45:14 +00:00
|
|
|
aiov->iov_len, aiov->iov_base, tx);
|
|
|
|
dmu_return_arcbuf(abuf);
|
|
|
|
xuio_stat_wbuf_copied();
|
|
|
|
} else {
|
|
|
|
ASSERT(xuio || tx_bytes == max_blksz);
|
|
|
|
dmu_assign_arcbuf(sa_get_db(zp->z_sa_hdl),
|
|
|
|
woff, abuf, tx);
|
|
|
|
}
|
2009-07-02 22:44:48 +00:00
|
|
|
ASSERT(tx_bytes <= uio->uio_resid);
|
|
|
|
uioskip(uio, tx_bytes);
|
|
|
|
}
|
2011-02-03 18:34:05 +00:00
|
|
|
|
|
|
|
if (tx_bytes && zp->z_is_mapped && !(ioflag & O_DIRECT))
|
|
|
|
update_pages(ip, woff, tx_bytes, zsb->z_os, zp->z_id);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we made no progress, we're done. If we made even
|
|
|
|
* partial progress, update the znode and ZIL accordingly.
|
|
|
|
*/
|
|
|
|
if (tx_bytes == 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
(void) sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
(void *)&zp->z_size, sizeof (uint64_t), tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_commit(tx);
|
|
|
|
ASSERT(error != 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear Set-UID/Set-GID bits on successful write if not
|
|
|
|
* privileged and at least one of the excute bits is set.
|
|
|
|
*
|
|
|
|
* It would be nice to to this after all writes have
|
|
|
|
* been done, but that would still expose the ISUID/ISGID
|
|
|
|
* to another app after the partial write is committed.
|
|
|
|
*
|
2010-08-26 21:24:34 +00:00
|
|
|
* Note: we don't call zfs_fuid_map_id() here because
|
|
|
|
* user 0 is not an ephemeral uid.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
mutex_enter(&zp->z_acl_lock);
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((zp->z_mode & (S_IXUSR | (S_IXUSR >> 3) |
|
2008-11-20 20:01:55 +00:00
|
|
|
(S_IXUSR >> 6))) != 0 &&
|
2010-05-28 20:45:14 +00:00
|
|
|
(zp->z_mode & (S_ISUID | S_ISGID)) != 0 &&
|
2008-11-20 20:01:55 +00:00
|
|
|
secpolicy_vnode_setid_retain(cr,
|
2010-05-28 20:45:14 +00:00
|
|
|
(zp->z_mode & S_ISUID) != 0 && zp->z_uid == 0) != 0) {
|
|
|
|
uint64_t newmode;
|
|
|
|
zp->z_mode &= ~(S_ISUID | S_ISGID);
|
|
|
|
newmode = zp->z_mode;
|
2011-02-08 19:16:06 +00:00
|
|
|
(void) sa_update(zp->z_sa_hdl, SA_ZPL_MODE(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
(void *)&newmode, sizeof (uint64_t), tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
mutex_exit(&zp->z_acl_lock);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime,
|
|
|
|
B_TRUE);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the file size (zp_size) if it has changed;
|
|
|
|
* account for possible concurrent updates.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
while ((end_size = zp->z_size) < uio->uio_loffset) {
|
|
|
|
(void) atomic_cas_64(&zp->z_size, end_size,
|
2008-11-20 20:01:55 +00:00
|
|
|
uio->uio_loffset);
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(error == 0);
|
|
|
|
}
|
2010-08-26 21:24:34 +00:00
|
|
|
/*
|
|
|
|
* If we are replaying and eof is non zero then force
|
|
|
|
* the file size to the specified eof. Note, there's no
|
|
|
|
* concurrency during replay.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_replay && zsb->z_replay_eof != 0)
|
|
|
|
zp->z_size = zsb->z_replay_eof;
|
2010-08-26 21:24:34 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
|
|
|
|
|
Only commit the ZIL once in zpl_writepages() (msync() case).
Currently, using msync() results in the following code path:
sys_msync -> zpl_fsync -> filemap_write_and_wait_range -> zpl_writepages -> write_cache_pages -> zpl_putpage
In such a code path, zil_commit() is called as part of zpl_putpage().
This means that for each page, the write is handed to the DMU, the ZIL
is committed, and only then do we move on to the next page. As one might
imagine, this results in atrocious performance where there is a large
number of pages to write: instead of committing a batch of N writes,
we do N commits containing one page each. In some extreme cases this
can result in msync() being ~700 times slower than it should be, as well
as very inefficient use of ZIL resources.
This patch fixes this issue by making sure that the requested writes
are batched and then committed only once. Unfortunately, the
implementation is somewhat non-trivial because there is no way to run
write_cache_pages in SYNC mode (so that we get all pages) without
making it wait on the writeback tag for each page.
The solution implemented here is composed of two parts:
- I added a new callback system to the ZIL, which allows the caller to
be notified when its ITX gets written to stable storage. One nice
thing is that the callback is called not only in zil_commit() but
in zil_sync() as well, which means that the caller doesn't have to
care whether the write ended up in the ZIL or the DMU: it will get
notified as soon as it's safe, period. This is an improvement over
dmu_tx_callback_register() that was used previously, which only
supports DMU writes. The rationale for this change is to allow
zpl_putpage() to be notified when a ZIL commit is completed without
having to block on zil_commit() itself.
- zpl_writepages() now calls write_cache_pages in non-SYNC mode, which
will prevent (1) write_cache_pages from blocking, and (2) zpl_putpage
from issuing ZIL commits. zpl_writepages() will issue the commit
itself instead of relying on zpl_putpage() to do it, thus nicely
batching the writes. Note, however, that we still have to call
write_cache_pages() again in SYNC mode because there is an edge case
documented in the implementation of write_cache_pages() whereas it
will not give us all dirty pages when running in non-SYNC mode. Thus
we need to run it at least once in SYNC mode to make sure we honor
persistency guarantees. This only happens when the pages are
modified at the same time msync() is running, which should be rare.
In most cases there won't be any additional pages and this second
call will do nothing.
Note that this change also fixes a bug related to #907 whereas calling
msync() on pages that were already handed over to the DMU in a previous
writepages() call would make msync() block until the next TXG sync
instead of returning as soon as the ZIL commit is complete. The new
callback system fixes that problem.
Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1849
Closes #907
2013-11-10 15:00:11 +00:00
|
|
|
zfs_log_write(zilog, tx, TX_WRITE, zp, woff, tx_bytes, ioflag,
|
|
|
|
NULL, NULL);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_commit(tx);
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
ASSERT(tx_bytes == nbytes);
|
|
|
|
n -= nbytes;
|
2010-08-26 21:24:34 +00:00
|
|
|
|
|
|
|
if (!xuio && n > 0)
|
|
|
|
uio_prefaultpages(MIN(n, max_blksz), uio);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zfs_range_unlock(rl);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're in replay mode, or we made no progress, return error.
|
|
|
|
* Otherwise, it's at least a partial write, so it's successful.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_replay || uio->uio_resid == start_resid) {
|
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (ioflag & (FSYNC | FDSYNC) ||
|
2011-02-08 19:16:06 +00:00
|
|
|
zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
|
2010-08-26 21:24:34 +00:00
|
|
|
zil_commit(zilog, zp->z_id);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-01-05 22:27:30 +00:00
|
|
|
zfs_inode_update(zp);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_write);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2014-08-04 20:30:20 +00:00
|
|
|
void
|
|
|
|
zfs_iput_async(struct inode *ip)
|
2011-02-08 19:16:06 +00:00
|
|
|
{
|
2014-08-04 20:30:20 +00:00
|
|
|
objset_t *os = ITOZSB(ip)->z_os;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ASSERT(atomic_read(&ip->i_count) > 0);
|
2014-08-04 20:30:20 +00:00
|
|
|
ASSERT(os != NULL);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (atomic_read(&ip->i_count) == 1)
|
2014-08-04 20:30:20 +00:00
|
|
|
taskq_dispatch(dsl_pool_iput_taskq(dmu_objset_pool(os)),
|
2014-11-21 00:09:39 +00:00
|
|
|
(task_func_t *)iput, ip, TQ_SLEEP);
|
2011-02-08 19:16:06 +00:00
|
|
|
else
|
|
|
|
iput(ip);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
void
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_get_done(zgd_t *zgd, int error)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
znode_t *zp = zgd->zgd_private;
|
|
|
|
|
|
|
|
if (zgd->zgd_db)
|
|
|
|
dmu_buf_rele(zgd->zgd_db, zgd);
|
|
|
|
|
|
|
|
zfs_range_unlock(zgd->zgd_rl);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
/*
|
|
|
|
* Release the vnode asynchronously as we currently have the
|
|
|
|
* txg stopped from syncing.
|
|
|
|
*/
|
2014-08-04 20:30:20 +00:00
|
|
|
zfs_iput_async(ZTOI(zp));
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (error == 0 && zgd->zgd_bp)
|
|
|
|
zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
kmem_free(zgd, sizeof (zgd_t));
|
|
|
|
}
|
|
|
|
|
2009-08-18 18:43:27 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
static int zil_fault_io = 0;
|
|
|
|
#endif
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Get data to generate a TX_WRITE intent log record.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
|
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_sb_t *zsb = arg;
|
|
|
|
objset_t *os = zsb->z_os;
|
2008-11-20 20:01:55 +00:00
|
|
|
znode_t *zp;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t object = lr->lr_foid;
|
|
|
|
uint64_t offset = lr->lr_offset;
|
|
|
|
uint64_t size = lr->lr_length;
|
|
|
|
blkptr_t *bp = &lr->lr_blkptr;
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_buf_t *db;
|
|
|
|
zgd_t *zgd;
|
|
|
|
int error = 0;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(zio != NULL);
|
|
|
|
ASSERT(size != 0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Nothing to do if the file has been removed
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zfs_zget(zsb, object, &zp) != 0)
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(ENOENT));
|
2008-11-20 20:01:55 +00:00
|
|
|
if (zp->z_unlinked) {
|
2009-07-02 22:44:48 +00:00
|
|
|
/*
|
|
|
|
* Release the vnode asynchronously as we currently have the
|
|
|
|
* txg stopped from syncing.
|
|
|
|
*/
|
2014-08-04 20:30:20 +00:00
|
|
|
zfs_iput_async(ZTOI(zp));
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(ENOENT));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 00:09:39 +00:00
|
|
|
zgd = (zgd_t *)kmem_zalloc(sizeof (zgd_t), KM_SLEEP);
|
2011-02-08 19:16:06 +00:00
|
|
|
zgd->zgd_zilog = zsb->z_log;
|
2010-05-28 20:45:14 +00:00
|
|
|
zgd->zgd_private = zp;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Write records come in two flavors: immediate and indirect.
|
|
|
|
* For small writes it's cheaper to store the data with the
|
|
|
|
* log record (immediate); for large writes it's cheaper to
|
|
|
|
* sync the data and get a pointer to it (indirect) so that
|
|
|
|
* we don't have to write the data twice.
|
|
|
|
*/
|
|
|
|
if (buf != NULL) { /* immediate write */
|
2010-05-28 20:45:14 +00:00
|
|
|
zgd->zgd_rl = zfs_range_lock(zp, offset, size, RL_READER);
|
2008-11-20 20:01:55 +00:00
|
|
|
/* test for truncation needs to be done while range locked */
|
2010-05-28 20:45:14 +00:00
|
|
|
if (offset >= zp->z_size) {
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(ENOENT);
|
2010-05-28 20:45:14 +00:00
|
|
|
} else {
|
|
|
|
error = dmu_read(os, object, offset, size, buf,
|
|
|
|
DMU_READ_NO_PREFETCH);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(error == 0 || error == ENOENT);
|
2008-11-20 20:01:55 +00:00
|
|
|
} else { /* indirect write */
|
|
|
|
/*
|
|
|
|
* Have to lock the whole block to ensure when it's
|
|
|
|
* written out and it's checksum is being calculated
|
|
|
|
* that no one can change the data. We need to re-check
|
|
|
|
* blocksize after we get the lock in case it's changed!
|
|
|
|
*/
|
|
|
|
for (;;) {
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t blkoff;
|
|
|
|
size = zp->z_blksz;
|
|
|
|
blkoff = ISP2(size) ? P2PHASE(offset, size) : offset;
|
|
|
|
offset -= blkoff;
|
|
|
|
zgd->zgd_rl = zfs_range_lock(zp, offset, size,
|
|
|
|
RL_READER);
|
|
|
|
if (zp->z_blksz == size)
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
2010-05-28 20:45:14 +00:00
|
|
|
offset += blkoff;
|
|
|
|
zfs_range_unlock(zgd->zgd_rl);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
/* test for truncation needs to be done while range locked */
|
2010-05-28 20:45:14 +00:00
|
|
|
if (lr->lr_offset >= zp->z_size)
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(ENOENT);
|
2009-08-18 18:43:27 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (zil_fault_io) {
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(EIO);
|
2009-08-18 18:43:27 +00:00
|
|
|
zil_fault_io = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error == 0)
|
2010-05-28 20:45:14 +00:00
|
|
|
error = dmu_buf_hold(os, object, offset, zgd, &db,
|
|
|
|
DMU_READ_NO_PREFETCH);
|
|
|
|
|
|
|
|
if (error == 0) {
|
2013-05-10 19:47:54 +00:00
|
|
|
blkptr_t *obp = dmu_buf_get_blkptr(db);
|
|
|
|
if (obp) {
|
|
|
|
ASSERT(BP_IS_HOLE(bp));
|
|
|
|
*bp = *obp;
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
zgd->zgd_db = db;
|
|
|
|
zgd->zgd_bp = bp;
|
|
|
|
|
|
|
|
ASSERT(db->db_offset == offset);
|
|
|
|
ASSERT(db->db_size == size);
|
|
|
|
|
|
|
|
error = dmu_sync(zio, lr->lr_common.lrc_txg,
|
|
|
|
zfs_get_done, zgd);
|
|
|
|
ASSERT(error || lr->lr_length <= zp->z_blksz);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On success, we need to wait for the write I/O
|
|
|
|
* initiated by dmu_sync() to complete before we can
|
|
|
|
* release this dbuf. We will finish everything up
|
|
|
|
* in the zfs_get_done() callback.
|
|
|
|
*/
|
|
|
|
if (error == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (error == EALREADY) {
|
|
|
|
lr->lr_common.lrc_txtype = TX_WRITE2;
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
zfs_get_done(zgd, error);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
2011-02-08 19:16:06 +00:00
|
|
|
int
|
|
|
|
zfs_access(struct inode *ip, int mode, int flag, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
int error;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
|
|
|
if (flag & V_ACE_MASK)
|
|
|
|
error = zfs_zaccess(zp, mode, flag, B_FALSE, cr);
|
|
|
|
else
|
|
|
|
error = zfs_zaccess_rwx(zp, mode, flag, cr);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2009-08-18 18:43:27 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
EXPORT_SYMBOL(zfs_access);
|
2009-08-18 18:43:27 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Lookup an entry in a directory, or an extended attribute directory.
|
2011-02-08 19:16:06 +00:00
|
|
|
* If it exists, return a held inode reference for it.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: dip - inode of directory to search.
|
2008-11-20 20:01:55 +00:00
|
|
|
* nm - name of entry to lookup.
|
|
|
|
* flags - LOOKUP_XATTR set if looking for an attribute.
|
|
|
|
* cr - credentials of caller.
|
|
|
|
* direntflags - directory lookup flags
|
|
|
|
* realpnp - returned pathname.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* OUT: ipp - inode of located entry, NULL if not found.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2013-06-11 17:12:34 +00:00
|
|
|
* RETURN: 0 on success, error code on failure.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Timestamps:
|
|
|
|
* NA
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_lookup(struct inode *dip, char *nm, struct inode **ipp, int flags,
|
|
|
|
cred_t *cr, int *direntflags, pathname_t *realpnp)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zdp = ITOZ(dip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(dip);
|
|
|
|
int error = 0;
|
2009-08-18 18:43:27 +00:00
|
|
|
|
|
|
|
/* fast path */
|
|
|
|
if (!(flags & (LOOKUP_XATTR | FIGNORECASE))) {
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (!S_ISDIR(dip->i_mode)) {
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(ENOTDIR));
|
2010-05-28 20:45:14 +00:00
|
|
|
} else if (zdp->z_sa_hdl == NULL) {
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EIO));
|
2009-08-18 18:43:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nm[0] == 0 || (nm[0] == '.' && nm[1] == '\0')) {
|
|
|
|
error = zfs_fastaccesschk_execute(zdp, cr);
|
|
|
|
if (!error) {
|
2011-02-08 19:16:06 +00:00
|
|
|
*ipp = dip;
|
|
|
|
igrab(*ipp);
|
2009-08-18 18:43:27 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (error);
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_DNLC
|
2009-08-18 18:43:27 +00:00
|
|
|
} else {
|
|
|
|
vnode_t *tvp = dnlc_lookup(dvp, nm);
|
|
|
|
|
|
|
|
if (tvp) {
|
|
|
|
error = zfs_fastaccesschk_execute(zdp, cr);
|
|
|
|
if (error) {
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(tvp);
|
2009-08-18 18:43:27 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
if (tvp == DNLC_NO_VNODE) {
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(tvp);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(ENOENT));
|
2009-08-18 18:43:27 +00:00
|
|
|
} else {
|
|
|
|
*vpp = tvp;
|
|
|
|
return (specvp_check(vpp, cr));
|
|
|
|
}
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_DNLC */
|
2009-08-18 18:43:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zdp);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
*ipp = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (flags & LOOKUP_XATTR) {
|
|
|
|
/*
|
|
|
|
* We don't allow recursive attributes..
|
|
|
|
* Maybe someday we will.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
if (zdp->z_pflags & ZFS_XATTR) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((error = zfs_get_xattrdir(zdp, ipp, cr, flags))) {
|
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do we have permission to get into attribute directory?
|
|
|
|
*/
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((error = zfs_zaccess(ITOZ(*ipp), ACE_EXECUTE, 0,
|
2010-12-16 22:05:42 +00:00
|
|
|
B_FALSE, cr))) {
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(*ipp);
|
|
|
|
*ipp = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (!S_ISDIR(dip->i_mode)) {
|
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(ENOTDIR));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check accessibility of directory.
|
|
|
|
*/
|
|
|
|
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_zaccess(zdp, ACE_EXECUTE, 0, B_FALSE, cr))) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_utf8 && u8_validate(nm, strlen(nm),
|
2008-11-20 20:01:55 +00:00
|
|
|
NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EILSEQ));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
error = zfs_dirlook(zdp, nm, ipp, flags, direntflags, realpnp);
|
|
|
|
if ((error == 0) && (*ipp))
|
|
|
|
zfs_inode_update(ITOZ(*ipp));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_lookup);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to create a new entry in a directory. If the entry
|
|
|
|
* already exists, truncate the file if permissible, else return
|
2011-02-08 19:16:06 +00:00
|
|
|
* an error. Return the ip of the created or trunc'd file.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: dip - inode of directory to put new file entry in.
|
2008-11-20 20:01:55 +00:00
|
|
|
* name - name of new file entry.
|
|
|
|
* vap - attributes of new file.
|
|
|
|
* excl - flag indicating exclusive or non-exclusive mode.
|
|
|
|
* mode - mode to open file with.
|
|
|
|
* cr - credentials of caller.
|
|
|
|
* flag - large file flag [UNUSED].
|
2011-02-08 19:16:06 +00:00
|
|
|
* vsecp - ACL to be set
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* OUT: ipp - inode of created or trunc'd entry.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2013-06-11 17:12:34 +00:00
|
|
|
* RETURN: 0 on success, error code on failure.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* dip - ctime|mtime updated if new entry created
|
|
|
|
* ip - ctime|mtime always, atime if new
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_create(struct inode *dip, char *name, vattr_t *vap, int excl,
|
|
|
|
int mode, struct inode **ipp, cred_t *cr, int flag, vsecattr_t *vsecp)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp, *dzp = ITOZ(dip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(dip);
|
2008-11-20 20:01:55 +00:00
|
|
|
zilog_t *zilog;
|
|
|
|
objset_t *os;
|
|
|
|
zfs_dirlock_t *dl;
|
|
|
|
dmu_tx_t *tx;
|
|
|
|
int error;
|
2008-12-03 20:09:06 +00:00
|
|
|
uid_t uid;
|
2010-12-16 22:05:42 +00:00
|
|
|
gid_t gid;
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_acl_ids_t acl_ids;
|
2009-07-02 22:44:48 +00:00
|
|
|
boolean_t fuid_dirtied;
|
2010-05-28 20:45:14 +00:00
|
|
|
boolean_t have_acl = B_FALSE;
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
boolean_t waited = B_FALSE;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have an ephemeral id, ACL, or XVATTR then
|
|
|
|
* make sure file system is at proper version
|
|
|
|
*/
|
|
|
|
|
2010-12-16 22:05:42 +00:00
|
|
|
gid = crgetgid(cr);
|
2011-02-08 19:16:06 +00:00
|
|
|
uid = crgetuid(cr);
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_use_fuids == B_FALSE &&
|
|
|
|
(vsecp || IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(dzp);
|
2011-02-08 19:16:06 +00:00
|
|
|
os = zsb->z_os;
|
|
|
|
zilog = zsb->z_log;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_utf8 && u8_validate(name, strlen(name),
|
2008-11-20 20:01:55 +00:00
|
|
|
NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EILSEQ));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
if (vap->va_mask & ATTR_XVATTR) {
|
2008-11-20 20:01:55 +00:00
|
|
|
if ((error = secpolicy_xvattr((xvattr_t *)vap,
|
2011-02-08 19:16:06 +00:00
|
|
|
crgetuid(cr), cr, vap->va_mode)) != 0) {
|
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
top:
|
|
|
|
*ipp = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
if (*name == '\0') {
|
|
|
|
/*
|
|
|
|
* Null component name refers to the directory itself.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
igrab(dip);
|
2008-11-20 20:01:55 +00:00
|
|
|
zp = dzp;
|
|
|
|
dl = NULL;
|
|
|
|
error = 0;
|
|
|
|
} else {
|
2011-02-08 19:16:06 +00:00
|
|
|
/* possible igrab(zp) */
|
2008-11-20 20:01:55 +00:00
|
|
|
int zflg = 0;
|
|
|
|
|
|
|
|
if (flag & FIGNORECASE)
|
|
|
|
zflg |= ZCILOOK;
|
|
|
|
|
|
|
|
error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
|
|
|
|
NULL, NULL);
|
|
|
|
if (error) {
|
2010-08-26 21:24:34 +00:00
|
|
|
if (have_acl)
|
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (strcmp(name, "..") == 0)
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(EISDIR);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (zp == NULL) {
|
|
|
|
uint64_t txtype;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new file object and update the directory
|
|
|
|
* to reference it.
|
|
|
|
*/
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr))) {
|
2010-08-26 21:24:34 +00:00
|
|
|
if (have_acl)
|
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only support the creation of regular files in
|
|
|
|
* extended attribute directories.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((dzp->z_pflags & ZFS_XATTR) && !S_ISREG(vap->va_mode)) {
|
2010-08-26 21:24:34 +00:00
|
|
|
if (have_acl)
|
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(EINVAL);
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (!have_acl && (error = zfs_acl_ids_create(dzp, 0, vap,
|
|
|
|
cr, vsecp, &acl_ids)) != 0)
|
2009-07-02 22:44:48 +00:00
|
|
|
goto out;
|
2010-05-28 20:45:14 +00:00
|
|
|
have_acl = B_TRUE;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zfs_acl_ids_overquota(zsb, &acl_ids)) {
|
2009-08-18 18:43:27 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(EDQUOT);
|
2009-07-02 22:44:48 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
tx = dmu_tx_create(os);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
|
|
|
|
ZFS_SA_BASE_ATTR_SIZE);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
fuid_dirtied = zsb->z_fuid_dirty;
|
2009-07-02 22:44:48 +00:00
|
|
|
if (fuid_dirtied)
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fuid_txhold(zsb, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
|
2011-02-08 19:16:06 +00:00
|
|
|
if (!zsb->z_use_sa &&
|
2010-05-28 20:45:14 +00:00
|
|
|
acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
|
2010-05-28 20:45:14 +00:00
|
|
|
0, acl_ids.z_aclp->z_acl_bytes);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
error = dmu_tx_assign(tx, waited ? TXG_WAITED : TXG_NOWAIT);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error) {
|
|
|
|
zfs_dirent_unlock(dl);
|
2009-01-15 21:59:39 +00:00
|
|
|
if (error == ERESTART) {
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
waited = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_wait(tx);
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
goto top;
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_abort(tx);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
|
|
|
if (fuid_dirtied)
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fuid_sync(zsb, tx);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) zfs_link_create(dl, zp, tx, ZNEW);
|
|
|
|
txtype = zfs_log_create_txtype(Z_FILE, vsecp, vap);
|
|
|
|
if (flag & FIGNORECASE)
|
|
|
|
txtype |= TX_CI;
|
|
|
|
zfs_log_create(zilog, tx, txtype, dzp, zp, name,
|
2009-07-02 22:44:48 +00:00
|
|
|
vsecp, acl_ids.z_fuidp, vap);
|
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_commit(tx);
|
|
|
|
} else {
|
|
|
|
int aflags = (flag & FAPPEND) ? V_APPEND : 0;
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if (have_acl)
|
|
|
|
zfs_acl_ids_free(&acl_ids);
|
|
|
|
have_acl = B_FALSE;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* A directory entry already exists for this name.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Can't truncate an existing file if in exclusive mode.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (excl) {
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(EEXIST);
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Can't open a directory for writing.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (S_ISDIR(ZTOI(zp)->i_mode)) {
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(EISDIR);
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Verify requested access to file.
|
|
|
|
*/
|
|
|
|
if (mode && (error = zfs_zaccess_rwx(zp, mode, aflags, cr))) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_enter(&dzp->z_lock);
|
|
|
|
dzp->z_seq++;
|
|
|
|
mutex_exit(&dzp->z_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Truncate regular files if requested.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (S_ISREG(ZTOI(zp)->i_mode) &&
|
|
|
|
(vap->va_mask & ATTR_SIZE) && (vap->va_size == 0)) {
|
2008-12-03 20:09:06 +00:00
|
|
|
/* we can't hold any locks when calling zfs_freesp() */
|
|
|
|
zfs_dirent_unlock(dl);
|
|
|
|
dl = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
error = zfs_freesp(zp, 0, 0, mode, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
|
|
|
|
if (dl)
|
|
|
|
zfs_dirent_unlock(dl);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
if (zp)
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(zp));
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
2011-01-05 22:27:30 +00:00
|
|
|
zfs_inode_update(dzp);
|
|
|
|
zfs_inode_update(zp);
|
2011-02-08 19:16:06 +00:00
|
|
|
*ipp = ZTOI(zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
|
2010-08-26 21:24:34 +00:00
|
|
|
zil_commit(zilog, 0);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_create);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove an entry from a directory.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: dip - inode of directory to remove entry from.
|
2008-11-20 20:01:55 +00:00
|
|
|
* name - name of entry to remove.
|
|
|
|
* cr - credentials of caller.
|
|
|
|
*
|
|
|
|
* RETURN: 0 if success
|
|
|
|
* error code if failure
|
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* dip - ctime|mtime
|
|
|
|
* ip - ctime (if nlink > 0)
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
uint64_t null_xattr = 0;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*ARGSUSED*/
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_remove(struct inode *dip, char *name, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp, *dzp = ITOZ(dip);
|
2010-08-26 21:24:34 +00:00
|
|
|
znode_t *xzp;
|
2011-02-08 19:16:06 +00:00
|
|
|
struct inode *ip;
|
|
|
|
zfs_sb_t *zsb = ITOZSB(dip);
|
2008-11-20 20:01:55 +00:00
|
|
|
zilog_t *zilog;
|
2011-02-08 19:16:06 +00:00
|
|
|
uint64_t xattr_obj;
|
|
|
|
uint64_t xattr_obj_unlinked = 0;
|
2010-08-26 21:24:34 +00:00
|
|
|
uint64_t obj = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
zfs_dirlock_t *dl;
|
|
|
|
dmu_tx_t *tx;
|
2011-02-08 19:16:06 +00:00
|
|
|
boolean_t unlinked;
|
2008-11-20 20:01:55 +00:00
|
|
|
uint64_t txtype;
|
|
|
|
pathname_t *realnmp = NULL;
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_PN_UTILS
|
2008-11-20 20:01:55 +00:00
|
|
|
pathname_t realnm;
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_PN_UTILS */
|
2008-11-20 20:01:55 +00:00
|
|
|
int error;
|
|
|
|
int zflg = ZEXISTS;
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
boolean_t waited = B_FALSE;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(dzp);
|
2011-02-08 19:16:06 +00:00
|
|
|
zilog = zsb->z_log;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_PN_UTILS
|
2008-11-20 20:01:55 +00:00
|
|
|
if (flags & FIGNORECASE) {
|
|
|
|
zflg |= ZCILOOK;
|
|
|
|
pn_alloc(&realnm);
|
|
|
|
realnmp = &realnm;
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_PN_UTILS */
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
top:
|
2010-08-26 21:24:34 +00:00
|
|
|
xattr_obj = 0;
|
|
|
|
xzp = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Attempt to lock directory; fail if entry doesn't exist.
|
|
|
|
*/
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
|
|
|
|
NULL, realnmp))) {
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_PN_UTILS
|
2008-11-20 20:01:55 +00:00
|
|
|
if (realnmp)
|
|
|
|
pn_free(realnmp);
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_PN_UTILS */
|
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ip = ZTOI(zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_zaccess_delete(dzp, zp, cr))) {
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Need to use rmdir for removing directories.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (S_ISDIR(ip->i_mode)) {
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(EPERM);
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_DNLC
|
2008-11-20 20:01:55 +00:00
|
|
|
if (realnmp)
|
|
|
|
dnlc_remove(dvp, realnmp->pn_buf);
|
|
|
|
else
|
|
|
|
dnlc_remove(dvp, name);
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_DNLC */
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
2011-02-08 19:16:06 +00:00
|
|
|
* We never delete the znode and always place it in the unlinked
|
|
|
|
* set. The dentry cache will always hold the last reference and
|
|
|
|
* is responsible for safely freeing the znode.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2010-08-26 21:24:34 +00:00
|
|
|
obj = zp->z_id;
|
2011-02-08 19:16:06 +00:00
|
|
|
tx = dmu_tx_create(zsb->z_os);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
|
|
|
|
zfs_sa_upgrade_txholds(tx, zp);
|
|
|
|
zfs_sa_upgrade_txholds(tx, dzp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* are there any extended attributes? */
|
2011-02-08 19:16:06 +00:00
|
|
|
error = sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
&xattr_obj, sizeof (xattr_obj));
|
2010-08-26 21:24:34 +00:00
|
|
|
if (error == 0 && xattr_obj) {
|
2011-02-08 19:16:06 +00:00
|
|
|
error = zfs_zget(zsb, xattr_obj, &xzp);
|
2013-05-10 21:17:03 +00:00
|
|
|
ASSERT0(error);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
|
|
|
|
dmu_tx_hold_sa(tx, xzp->z_sa_hdl, B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* charge as an update -- would be nice not to charge at all */
|
2011-02-08 19:16:06 +00:00
|
|
|
dmu_tx_hold_zap(tx, zsb->z_unlinkedobj, FALSE, NULL);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
error = dmu_tx_assign(tx, waited ? TXG_WAITED : TXG_NOWAIT);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error) {
|
|
|
|
zfs_dirent_unlock(dl);
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ip);
|
2010-08-26 21:24:34 +00:00
|
|
|
if (xzp)
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(xzp));
|
2009-01-15 21:59:39 +00:00
|
|
|
if (error == ERESTART) {
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
waited = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_wait(tx);
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
goto top;
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_PN_UTILS
|
2008-11-20 20:01:55 +00:00
|
|
|
if (realnmp)
|
|
|
|
pn_free(realnmp);
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_PN_UTILS */
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_abort(tx);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the directory entry.
|
|
|
|
*/
|
|
|
|
error = zfs_link_destroy(dl, zp, tx, zflg, &unlinked);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
dmu_tx_commit(tx);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlinked) {
|
2010-08-26 21:24:34 +00:00
|
|
|
/*
|
|
|
|
* Hold z_lock so that we can make sure that the ACL obj
|
|
|
|
* hasn't changed. Could have been deleted due to
|
|
|
|
* zfs_sa_upgrade().
|
|
|
|
*/
|
|
|
|
mutex_enter(&zp->z_lock);
|
2011-02-08 19:16:06 +00:00
|
|
|
(void) sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
&xattr_obj_unlinked, sizeof (xattr_obj_unlinked));
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_exit(&zp->z_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
zfs_unlinked_add(zp, tx);
|
|
|
|
}
|
|
|
|
|
|
|
|
txtype = TX_REMOVE;
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_PN_UTILS
|
2008-11-20 20:01:55 +00:00
|
|
|
if (flags & FIGNORECASE)
|
|
|
|
txtype |= TX_CI;
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_PN_UTILS */
|
2010-08-26 21:24:34 +00:00
|
|
|
zfs_log_remove(zilog, tx, txtype, dzp, name, obj);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
dmu_tx_commit(tx);
|
|
|
|
out:
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_PN_UTILS
|
2008-11-20 20:01:55 +00:00
|
|
|
if (realnmp)
|
|
|
|
pn_free(realnmp);
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_PN_UTILS */
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
zfs_dirent_unlock(dl);
|
2011-01-05 22:27:30 +00:00
|
|
|
zfs_inode_update(dzp);
|
|
|
|
zfs_inode_update(zp);
|
|
|
|
if (xzp)
|
|
|
|
zfs_inode_update(xzp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ip);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (xzp)
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(xzp));
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
|
2010-08-26 21:24:34 +00:00
|
|
|
zil_commit(zilog, 0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_remove);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
2011-02-08 19:16:06 +00:00
|
|
|
* Create a new directory and insert it into dip using the name
|
2008-11-20 20:01:55 +00:00
|
|
|
* provided. Return a pointer to the inserted directory.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: dip - inode of directory to add subdir to.
|
2008-11-20 20:01:55 +00:00
|
|
|
* dirname - name of new directory.
|
|
|
|
* vap - attributes of new directory.
|
|
|
|
* cr - credentials of caller.
|
|
|
|
* vsecp - ACL to be set
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* OUT: ipp - inode of created directory.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* RETURN: 0 if success
|
|
|
|
* error code if failure
|
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* dip - ctime|mtime updated
|
|
|
|
* ipp - ctime|mtime|atime updated
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_mkdir(struct inode *dip, char *dirname, vattr_t *vap, struct inode **ipp,
|
|
|
|
cred_t *cr, int flags, vsecattr_t *vsecp)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp, *dzp = ITOZ(dip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(dip);
|
2008-11-20 20:01:55 +00:00
|
|
|
zilog_t *zilog;
|
|
|
|
zfs_dirlock_t *dl;
|
|
|
|
uint64_t txtype;
|
|
|
|
dmu_tx_t *tx;
|
|
|
|
int error;
|
|
|
|
int zf = ZNEW;
|
2008-12-03 20:09:06 +00:00
|
|
|
uid_t uid;
|
|
|
|
gid_t gid = crgetgid(cr);
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_acl_ids_t acl_ids;
|
2009-07-02 22:44:48 +00:00
|
|
|
boolean_t fuid_dirtied;
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
boolean_t waited = B_FALSE;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ASSERT(S_ISDIR(vap->va_mode));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have an ephemeral id, ACL, or XVATTR then
|
|
|
|
* make sure file system is at proper version
|
|
|
|
*/
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
uid = crgetuid(cr);
|
|
|
|
if (zsb->z_use_fuids == B_FALSE &&
|
|
|
|
(vsecp || IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(dzp);
|
2011-02-08 19:16:06 +00:00
|
|
|
zilog = zsb->z_log;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (dzp->z_pflags & ZFS_XATTR) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_utf8 && u8_validate(dirname,
|
2008-11-20 20:01:55 +00:00
|
|
|
strlen(dirname), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EILSEQ));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
if (flags & FIGNORECASE)
|
|
|
|
zf |= ZCILOOK;
|
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
if (vap->va_mask & ATTR_XVATTR) {
|
2008-11-20 20:01:55 +00:00
|
|
|
if ((error = secpolicy_xvattr((xvattr_t *)vap,
|
2011-02-08 19:16:06 +00:00
|
|
|
crgetuid(cr), cr, vap->va_mode)) != 0) {
|
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((error = zfs_acl_ids_create(dzp, 0, vap, cr,
|
|
|
|
vsecp, &acl_ids)) != 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2010-05-28 20:45:14 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* First make sure the new directory doesn't exist.
|
2010-05-28 20:45:14 +00:00
|
|
|
*
|
|
|
|
* Existence is checked first to make sure we don't return
|
|
|
|
* EACCES instead of EEXIST which can cause some applications
|
|
|
|
* to fail.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
top:
|
2011-02-08 19:16:06 +00:00
|
|
|
*ipp = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_dirent_lock(&dl, dzp, dirname, &zp, zf,
|
|
|
|
NULL, NULL))) {
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_zaccess(dzp, ACE_ADD_SUBDIRECTORY, 0, B_FALSE, cr))) {
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2008-11-20 20:01:55 +00:00
|
|
|
zfs_dirent_unlock(dl);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zfs_acl_ids_overquota(zsb, &acl_ids)) {
|
2009-08-18 18:43:27 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2009-07-02 22:44:48 +00:00
|
|
|
zfs_dirent_unlock(dl);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EDQUOT));
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Add a new entry to the directory.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
tx = dmu_tx_create(zsb->z_os);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_hold_zap(tx, dzp->z_id, TRUE, dirname);
|
|
|
|
dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
|
2011-02-08 19:16:06 +00:00
|
|
|
fuid_dirtied = zsb->z_fuid_dirty;
|
2009-07-02 22:44:48 +00:00
|
|
|
if (fuid_dirtied)
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fuid_txhold(zsb, tx);
|
|
|
|
if (!zsb->z_use_sa && acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
|
|
|
|
acl_ids.z_aclp->z_acl_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
|
|
|
|
ZFS_SA_BASE_ATTR_SIZE);
|
|
|
|
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
error = dmu_tx_assign(tx, waited ? TXG_WAITED : TXG_NOWAIT);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error) {
|
|
|
|
zfs_dirent_unlock(dl);
|
2009-01-15 21:59:39 +00:00
|
|
|
if (error == ERESTART) {
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
waited = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_wait(tx);
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
goto top;
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_abort(tx);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create new node.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
if (fuid_dirtied)
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fuid_sync(zsb, tx);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Now put new name in parent dir.
|
|
|
|
*/
|
|
|
|
(void) zfs_link_create(dl, zp, tx, ZNEW);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
*ipp = ZTOI(zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
txtype = zfs_log_create_txtype(Z_DIR, vsecp, vap);
|
|
|
|
if (flags & FIGNORECASE)
|
|
|
|
txtype |= TX_CI;
|
2009-07-02 22:44:48 +00:00
|
|
|
zfs_log_create(zilog, tx, txtype, dzp, zp, dirname, vsecp,
|
|
|
|
acl_ids.z_fuidp, vap);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_commit(tx);
|
|
|
|
|
|
|
|
zfs_dirent_unlock(dl);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
|
2010-08-26 21:24:34 +00:00
|
|
|
zil_commit(zilog, 0);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-01-05 22:27:30 +00:00
|
|
|
zfs_inode_update(dzp);
|
|
|
|
zfs_inode_update(zp);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_mkdir);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a directory subdir entry. If the current working
|
|
|
|
* directory is the same as the subdir to be removed, the
|
|
|
|
* remove will fail.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: dip - inode of directory to remove from.
|
2008-11-20 20:01:55 +00:00
|
|
|
* name - name of directory to be removed.
|
2011-02-08 19:16:06 +00:00
|
|
|
* cwd - inode of current working directory.
|
2008-11-20 20:01:55 +00:00
|
|
|
* cr - credentials of caller.
|
|
|
|
* flags - case flags
|
|
|
|
*
|
2013-06-11 17:12:34 +00:00
|
|
|
* RETURN: 0 on success, error code on failure.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* dip - ctime|mtime updated
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_rmdir(struct inode *dip, char *name, struct inode *cwd, cred_t *cr,
|
|
|
|
int flags)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *dzp = ITOZ(dip);
|
2008-11-20 20:01:55 +00:00
|
|
|
znode_t *zp;
|
2011-02-08 19:16:06 +00:00
|
|
|
struct inode *ip;
|
|
|
|
zfs_sb_t *zsb = ITOZSB(dip);
|
2008-11-20 20:01:55 +00:00
|
|
|
zilog_t *zilog;
|
|
|
|
zfs_dirlock_t *dl;
|
|
|
|
dmu_tx_t *tx;
|
|
|
|
int error;
|
|
|
|
int zflg = ZEXISTS;
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
boolean_t waited = B_FALSE;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(dzp);
|
2011-02-08 19:16:06 +00:00
|
|
|
zilog = zsb->z_log;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (flags & FIGNORECASE)
|
|
|
|
zflg |= ZCILOOK;
|
|
|
|
top:
|
|
|
|
zp = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to lock directory; fail if entry doesn't exist.
|
|
|
|
*/
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
|
|
|
|
NULL, NULL))) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ip = ZTOI(zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_zaccess_delete(dzp, zp, cr))) {
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (!S_ISDIR(ip->i_mode)) {
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(ENOTDIR);
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (ip == cwd) {
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(EINVAL);
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab a lock on the directory to make sure that noone is
|
|
|
|
* trying to add (or lookup) entries while we are removing it.
|
|
|
|
*/
|
|
|
|
rw_enter(&zp->z_name_lock, RW_WRITER);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab a lock on the parent pointer to make sure we play well
|
|
|
|
* with the treewalk and directory rename code.
|
|
|
|
*/
|
|
|
|
rw_enter(&zp->z_parent_lock, RW_WRITER);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
tx = dmu_tx_create(zsb->z_os);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
|
2011-02-08 19:16:06 +00:00
|
|
|
dmu_tx_hold_zap(tx, zsb->z_unlinkedobj, FALSE, NULL);
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_sa_upgrade_txholds(tx, zp);
|
|
|
|
zfs_sa_upgrade_txholds(tx, dzp);
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
error = dmu_tx_assign(tx, waited ? TXG_WAITED : TXG_NOWAIT);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error) {
|
|
|
|
rw_exit(&zp->z_parent_lock);
|
|
|
|
rw_exit(&zp->z_name_lock);
|
|
|
|
zfs_dirent_unlock(dl);
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ip);
|
2009-01-15 21:59:39 +00:00
|
|
|
if (error == ERESTART) {
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
waited = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_wait(tx);
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
goto top;
|
|
|
|
}
|
|
|
|
dmu_tx_abort(tx);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = zfs_link_destroy(dl, zp, tx, zflg, NULL);
|
|
|
|
|
|
|
|
if (error == 0) {
|
|
|
|
uint64_t txtype = TX_RMDIR;
|
|
|
|
if (flags & FIGNORECASE)
|
|
|
|
txtype |= TX_CI;
|
2010-08-26 21:24:34 +00:00
|
|
|
zfs_log_remove(zilog, tx, txtype, dzp, name, ZFS_NO_OBJECT);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dmu_tx_commit(tx);
|
|
|
|
|
|
|
|
rw_exit(&zp->z_parent_lock);
|
|
|
|
rw_exit(&zp->z_name_lock);
|
|
|
|
out:
|
|
|
|
zfs_dirent_unlock(dl);
|
|
|
|
|
2012-09-12 18:16:08 +00:00
|
|
|
zfs_inode_update(dzp);
|
|
|
|
zfs_inode_update(zp);
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
|
2010-08-26 21:24:34 +00:00
|
|
|
zil_commit(zilog, 0);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_rmdir);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read as many directory entries as will fit into the provided
|
2011-02-08 19:16:06 +00:00
|
|
|
* dirent buffer from the given directory cursor position.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: ip - inode of directory to read.
|
|
|
|
* dirent - buffer for directory entries.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* OUT: dirent - filler buffer of directory entries.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* RETURN: 0 if success
|
|
|
|
* error code if failure
|
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* ip - atime updated
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Note that the low 4 bits of the cookie returned by zap is always zero.
|
|
|
|
* This allows us to use the low range for "special" directory entries:
|
|
|
|
* We use 0 for '.', and 1 for '..'. If this is the root of the filesystem,
|
|
|
|
* we use the offset 2 for the '.zfs' directory.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2011-02-08 19:16:06 +00:00
|
|
|
int
|
2013-08-07 12:53:45 +00:00
|
|
|
zfs_readdir(struct inode *ip, struct dir_context *ctx, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
objset_t *os;
|
|
|
|
zap_cursor_t zc;
|
|
|
|
zap_attribute_t zap;
|
|
|
|
int error;
|
|
|
|
uint8_t prefetch;
|
2013-10-02 15:22:53 +00:00
|
|
|
uint8_t type;
|
2011-02-08 19:16:06 +00:00
|
|
|
int done = 0;
|
|
|
|
uint64_t parent;
|
2013-10-02 15:22:53 +00:00
|
|
|
uint64_t offset; /* must be unsigned; checks for < 1 */
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(zsb),
|
|
|
|
&parent, sizeof (parent))) != 0)
|
|
|
|
goto out;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Quit if directory has been removed (posix)
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zp->z_unlinked)
|
|
|
|
goto out;
|
|
|
|
|
2013-10-02 15:22:53 +00:00
|
|
|
error = 0;
|
2011-02-08 19:16:06 +00:00
|
|
|
os = zsb->z_os;
|
2013-10-02 15:22:53 +00:00
|
|
|
offset = ctx->pos;
|
2008-11-20 20:01:55 +00:00
|
|
|
prefetch = zp->z_zn_prefetch;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the iterator cursor.
|
|
|
|
*/
|
2013-10-02 15:22:53 +00:00
|
|
|
if (offset <= 3) {
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Start iteration from the beginning of the directory.
|
|
|
|
*/
|
|
|
|
zap_cursor_init(&zc, os, zp->z_id);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The offset is a serialized cursor.
|
|
|
|
*/
|
2013-10-02 15:22:53 +00:00
|
|
|
zap_cursor_init_serialized(&zc, os, zp->z_id, offset);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transform to file-system independent format
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
while (!done) {
|
|
|
|
uint64_t objnum;
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Special case `.', `..', and `.zfs'.
|
|
|
|
*/
|
2013-10-02 15:22:53 +00:00
|
|
|
if (offset == 0) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) strcpy(zap.za_name, ".");
|
|
|
|
zap.za_normalization_conflict = 0;
|
|
|
|
objnum = zp->z_id;
|
2013-10-02 15:22:53 +00:00
|
|
|
type = DT_DIR;
|
|
|
|
} else if (offset == 1) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) strcpy(zap.za_name, "..");
|
|
|
|
zap.za_normalization_conflict = 0;
|
2010-05-28 20:45:14 +00:00
|
|
|
objnum = parent;
|
2013-10-02 15:22:53 +00:00
|
|
|
type = DT_DIR;
|
|
|
|
} else if (offset == 2 && zfs_show_ctldir(zp)) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) strcpy(zap.za_name, ZFS_CTLDIR_NAME);
|
|
|
|
zap.za_normalization_conflict = 0;
|
|
|
|
objnum = ZFSCTL_INO_ROOT;
|
2013-10-02 15:22:53 +00:00
|
|
|
type = DT_DIR;
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Grab next entry.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((error = zap_cursor_retrieve(&zc, &zap))) {
|
|
|
|
if (error == ENOENT)
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
else
|
|
|
|
goto update;
|
|
|
|
}
|
|
|
|
|
2012-01-27 21:43:23 +00:00
|
|
|
/*
|
|
|
|
* Allow multiple entries provided the first entry is
|
|
|
|
* the object id. Non-zpl consumers may safely make
|
|
|
|
* use of the additional space.
|
|
|
|
*
|
|
|
|
* XXX: This should be a feature flag for compatibility
|
|
|
|
*/
|
2008-11-20 20:01:55 +00:00
|
|
|
if (zap.za_integer_length != 8 ||
|
2012-01-27 21:43:23 +00:00
|
|
|
zap.za_num_integers == 0) {
|
2008-11-20 20:01:55 +00:00
|
|
|
cmn_err(CE_WARN, "zap_readdir: bad directory "
|
2012-01-27 21:43:23 +00:00
|
|
|
"entry, obj = %lld, offset = %lld, "
|
|
|
|
"length = %d, num = %lld\n",
|
2008-11-20 20:01:55 +00:00
|
|
|
(u_longlong_t)zp->z_id,
|
2013-10-02 15:22:53 +00:00
|
|
|
(u_longlong_t)offset,
|
2012-01-27 21:43:23 +00:00
|
|
|
zap.za_integer_length,
|
|
|
|
(u_longlong_t)zap.za_num_integers);
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(ENXIO);
|
2008-11-20 20:01:55 +00:00
|
|
|
goto update;
|
|
|
|
}
|
|
|
|
|
|
|
|
objnum = ZFS_DIRENT_OBJ(zap.za_first_integer);
|
2013-10-02 15:22:53 +00:00
|
|
|
type = ZFS_DIRENT_TYPE(zap.za_first_integer);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2013-08-07 12:53:45 +00:00
|
|
|
|
|
|
|
done = !dir_emit(ctx, zap.za_name, strlen(zap.za_name),
|
2013-10-02 15:22:53 +00:00
|
|
|
objnum, type);
|
2013-08-07 12:53:45 +00:00
|
|
|
if (done)
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Prefetch znode */
|
2011-02-08 19:16:06 +00:00
|
|
|
if (prefetch) {
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_prefetch(os, objnum, 0, 0);
|
2011-02-08 19:16:06 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2013-10-02 15:22:53 +00:00
|
|
|
/*
|
|
|
|
* Move to the next entry, fill in the previous offset.
|
|
|
|
*/
|
|
|
|
if (offset > 2 || (offset == 2 && !zfs_show_ctldir(zp))) {
|
2008-11-20 20:01:55 +00:00
|
|
|
zap_cursor_advance(&zc);
|
2013-10-02 15:22:53 +00:00
|
|
|
offset = zap_cursor_serialize(&zc);
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
2013-10-02 15:22:53 +00:00
|
|
|
offset += 1;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2013-10-02 15:22:53 +00:00
|
|
|
ctx->pos = offset;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
zp->z_zn_prefetch = B_FALSE; /* a lookup will re-enable pre-fetching */
|
|
|
|
|
|
|
|
update:
|
|
|
|
zap_cursor_fini(&zc);
|
|
|
|
if (error == ENOENT)
|
|
|
|
error = 0;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ACCESSTIME_STAMP(zsb, zp);
|
|
|
|
|
|
|
|
out:
|
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
EXPORT_SYMBOL(zfs_readdir);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2012-12-20 17:55:47 +00:00
|
|
|
ulong_t zfs_fsync_sync_cnt = 4;
|
|
|
|
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fsync(struct inode *ip, int syncflag, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2012-12-20 17:55:47 +00:00
|
|
|
(void) tsd_set(zfs_fsyncer_key, (void *)zfs_fsync_sync_cnt);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_os->os_sync != ZFS_SYNC_DISABLED) {
|
|
|
|
ZFS_ENTER(zsb);
|
2010-05-28 20:45:14 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
2011-02-08 19:16:06 +00:00
|
|
|
zil_commit(zsb->z_log, zp->z_id);
|
|
|
|
ZFS_EXIT(zsb);
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2015-04-01 18:18:05 +00:00
|
|
|
tsd_set(zfs_fsyncer_key, NULL);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_fsync);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the requested file attributes and place them in the provided
|
|
|
|
* vattr structure.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: ip - inode of file.
|
2011-03-01 20:24:09 +00:00
|
|
|
* vap - va_mask identifies requested attributes.
|
|
|
|
* If ATTR_XVATTR set, then optional attrs are requested
|
2008-11-20 20:01:55 +00:00
|
|
|
* flags - ATTR_NOACLCHECK (CIFS server context)
|
|
|
|
* cr - credentials of caller.
|
|
|
|
*
|
2011-03-01 20:24:09 +00:00
|
|
|
* OUT: vap - attribute values.
|
|
|
|
*
|
|
|
|
* RETURN: 0 (always succeeds)
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-03-01 20:24:09 +00:00
|
|
|
zfs_getattr(struct inode *ip, vattr_t *vap, int flags, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
int error = 0;
|
|
|
|
uint64_t links;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t mtime[2], ctime[2];
|
2011-03-01 20:24:09 +00:00
|
|
|
xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
|
|
|
|
xoptattr_t *xoap = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
|
2010-05-28 20:45:14 +00:00
|
|
|
sa_bulk_attr_t bulk[2];
|
|
|
|
int count = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
zfs_fuid_map_ids(zp, cr, &vap->va_uid, &vap->va_gid);
|
2010-08-26 21:24:34 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zsb), NULL, &mtime, 16);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zsb), NULL, &ctime, 16);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if ((error = sa_bulk_lookup(zp->z_sa_hdl, bulk, count)) != 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2010-05-28 20:45:14 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If ACL is trivial don't bother looking for ACE_READ_ATTRIBUTES.
|
|
|
|
* Also, if we are the owner don't bother, since owner should
|
|
|
|
* always be allowed to read basic attributes of file.
|
|
|
|
*/
|
2010-08-26 21:24:34 +00:00
|
|
|
if (!(zp->z_pflags & ZFS_ACL_TRIVIAL) &&
|
2011-03-01 20:24:09 +00:00
|
|
|
(vap->va_uid != crgetuid(cr))) {
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_zaccess(zp, ACE_READ_ATTRIBUTES, 0,
|
|
|
|
skipaclchk, cr))) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return all attributes. It's cheaper to provide the answer
|
|
|
|
* than to determine whether we were asked the question.
|
|
|
|
*/
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
mutex_enter(&zp->z_lock);
|
2011-03-01 20:24:09 +00:00
|
|
|
vap->va_type = vn_mode_to_vtype(zp->z_mode);
|
|
|
|
vap->va_mode = zp->z_mode;
|
2011-03-08 00:06:22 +00:00
|
|
|
vap->va_fsid = ZTOI(zp)->i_sb->s_dev;
|
2011-03-01 20:24:09 +00:00
|
|
|
vap->va_nodeid = zp->z_id;
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((zp->z_id == zsb->z_root) && zfs_show_ctldir(zp))
|
2010-05-28 20:45:14 +00:00
|
|
|
links = zp->z_links + 1;
|
2008-11-20 20:01:55 +00:00
|
|
|
else
|
2010-05-28 20:45:14 +00:00
|
|
|
links = zp->z_links;
|
2011-03-01 20:24:09 +00:00
|
|
|
vap->va_nlink = MIN(links, ZFS_LINK_MAX);
|
|
|
|
vap->va_size = i_size_read(ip);
|
|
|
|
vap->va_rdev = ip->i_rdev;
|
|
|
|
vap->va_seq = ip->i_generation;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add in any requested optional attributes and the create time.
|
|
|
|
* Also set the corresponding bits in the returned attribute bitmap.
|
|
|
|
*/
|
|
|
|
if ((xoap = xva_getxoptattr(xvap)) != NULL && zsb->z_use_fuids) {
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
|
|
|
|
xoap->xoa_archive =
|
|
|
|
((zp->z_pflags & ZFS_ARCHIVE) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_ARCHIVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
|
|
|
|
xoap->xoa_readonly =
|
|
|
|
((zp->z_pflags & ZFS_READONLY) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_READONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
|
|
|
|
xoap->xoa_system =
|
|
|
|
((zp->z_pflags & ZFS_SYSTEM) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_SYSTEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
|
|
|
|
xoap->xoa_hidden =
|
|
|
|
((zp->z_pflags & ZFS_HIDDEN) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_HIDDEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
|
|
|
|
xoap->xoa_nounlink =
|
|
|
|
((zp->z_pflags & ZFS_NOUNLINK) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_NOUNLINK);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
|
|
|
|
xoap->xoa_immutable =
|
|
|
|
((zp->z_pflags & ZFS_IMMUTABLE) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_IMMUTABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
|
|
|
|
xoap->xoa_appendonly =
|
|
|
|
((zp->z_pflags & ZFS_APPENDONLY) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_APPENDONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
|
|
|
|
xoap->xoa_nodump =
|
|
|
|
((zp->z_pflags & ZFS_NODUMP) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_NODUMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
|
|
|
|
xoap->xoa_opaque =
|
|
|
|
((zp->z_pflags & ZFS_OPAQUE) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_OPAQUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
|
|
|
|
xoap->xoa_av_quarantined =
|
|
|
|
((zp->z_pflags & ZFS_AV_QUARANTINED) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
|
|
|
|
xoap->xoa_av_modified =
|
|
|
|
((zp->z_pflags & ZFS_AV_MODIFIED) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) &&
|
|
|
|
S_ISREG(ip->i_mode)) {
|
|
|
|
zfs_sa_get_scanstamp(zp, xvap);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
|
|
|
|
uint64_t times[2];
|
|
|
|
|
|
|
|
(void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zsb),
|
|
|
|
times, sizeof (times));
|
|
|
|
ZFS_TIME_DECODE(&xoap->xoa_createtime, times);
|
|
|
|
XVA_SET_RTN(xvap, XAT_CREATETIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
|
|
|
|
xoap->xoa_reparse = ((zp->z_pflags & ZFS_REPARSE) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_REPARSE);
|
|
|
|
}
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_GEN)) {
|
|
|
|
xoap->xoa_generation = zp->z_gen;
|
|
|
|
XVA_SET_RTN(xvap, XAT_GEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_OFFLINE)) {
|
|
|
|
xoap->xoa_offline =
|
|
|
|
((zp->z_pflags & ZFS_OFFLINE) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_OFFLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_SPARSE)) {
|
|
|
|
xoap->xoa_sparse =
|
|
|
|
((zp->z_pflags & ZFS_SPARSE) != 0);
|
|
|
|
XVA_SET_RTN(xvap, XAT_SPARSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ZFS_TIME_DECODE(&vap->va_atime, zp->z_atime);
|
|
|
|
ZFS_TIME_DECODE(&vap->va_mtime, mtime);
|
|
|
|
ZFS_TIME_DECODE(&vap->va_ctime, ctime);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
mutex_exit(&zp->z_lock);
|
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
sa_object_size(zp->z_sa_hdl, &vap->va_blksize, &vap->va_nblocks);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (zp->z_blksz == 0) {
|
|
|
|
/*
|
|
|
|
* Block size hasn't been set; suggest maximal I/O transfers.
|
|
|
|
*/
|
2011-03-01 20:24:09 +00:00
|
|
|
vap->va_blksize = zsb->z_max_blksz;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_getattr);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-07-09 22:44:16 +00:00
|
|
|
/*
|
|
|
|
* Get the basic file attributes and place them in the provided kstat
|
|
|
|
* structure. The inode is assumed to be the authoritative source
|
|
|
|
* for most of the attributes. However, the znode currently has the
|
|
|
|
* authoritative atime, blksize, and block count.
|
|
|
|
*
|
|
|
|
* IN: ip - inode of file.
|
|
|
|
*
|
|
|
|
* OUT: sp - kstat values.
|
|
|
|
*
|
|
|
|
* RETURN: 0 (always succeeds)
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
zfs_getattr_fast(struct inode *ip, struct kstat *sp)
|
|
|
|
{
|
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2014-01-07 23:17:24 +00:00
|
|
|
uint32_t blksize;
|
|
|
|
u_longlong_t nblocks;
|
2011-07-09 22:44:16 +00:00
|
|
|
|
2011-11-03 05:48:13 +00:00
|
|
|
ZFS_ENTER(zsb);
|
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
2011-07-09 22:44:16 +00:00
|
|
|
mutex_enter(&zp->z_lock);
|
|
|
|
|
|
|
|
generic_fillattr(ip, sp);
|
|
|
|
ZFS_TIME_DECODE(&sp->atime, zp->z_atime);
|
|
|
|
|
2014-01-07 23:17:24 +00:00
|
|
|
sa_object_size(zp->z_sa_hdl, &blksize, &nblocks);
|
|
|
|
sp->blksize = blksize;
|
|
|
|
sp->blocks = nblocks;
|
|
|
|
|
2011-07-09 22:44:16 +00:00
|
|
|
if (unlikely(zp->z_blksz == 0)) {
|
|
|
|
/*
|
|
|
|
* Block size hasn't been set; suggest maximal I/O transfers.
|
|
|
|
*/
|
|
|
|
sp->blksize = zsb->z_max_blksz;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_exit(&zp->z_lock);
|
|
|
|
|
2011-11-03 05:48:13 +00:00
|
|
|
ZFS_EXIT(zsb);
|
|
|
|
|
2011-07-09 22:44:16 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(zfs_getattr_fast);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Set the file attributes to the values contained in the
|
|
|
|
* vattr structure.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: ip - inode of file to be modified.
|
2008-11-20 20:01:55 +00:00
|
|
|
* vap - new attribute values.
|
2011-03-01 20:24:09 +00:00
|
|
|
* If ATTR_XVATTR set, then optional attrs are being set
|
2008-11-20 20:01:55 +00:00
|
|
|
* flags - ATTR_UTIME set if non-default time values provided.
|
|
|
|
* - ATTR_NOACLCHECK (CIFS context only).
|
|
|
|
* cr - credentials of caller.
|
|
|
|
*
|
|
|
|
* RETURN: 0 if success
|
|
|
|
* error code if failure
|
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* ip - ctime updated, mtime updated if size changed.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-03-01 20:24:09 +00:00
|
|
|
zfs_setattr(struct inode *ip, vattr_t *vap, int flags, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
zilog_t *zilog;
|
|
|
|
dmu_tx_t *tx;
|
|
|
|
vattr_t oldva;
|
2011-03-02 22:18:40 +00:00
|
|
|
xvattr_t *tmpxvattr;
|
2011-03-01 20:24:09 +00:00
|
|
|
uint_t mask = vap->va_mask;
|
2013-02-11 06:21:05 +00:00
|
|
|
uint_t saved_mask = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
int trim_mask = 0;
|
|
|
|
uint64_t new_mode;
|
2009-07-02 22:44:48 +00:00
|
|
|
uint64_t new_uid, new_gid;
|
2010-08-26 21:24:34 +00:00
|
|
|
uint64_t xattr_obj;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t mtime[2], ctime[2];
|
2008-11-20 20:01:55 +00:00
|
|
|
znode_t *attrzp;
|
|
|
|
int need_policy = FALSE;
|
2010-05-28 20:45:14 +00:00
|
|
|
int err, err2;
|
2008-11-20 20:01:55 +00:00
|
|
|
zfs_fuid_info_t *fuidp = NULL;
|
2011-03-01 20:24:09 +00:00
|
|
|
xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
|
|
|
|
xoptattr_t *xoap;
|
|
|
|
zfs_acl_t *aclp;
|
2008-11-20 20:01:55 +00:00
|
|
|
boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
|
2010-05-28 20:45:14 +00:00
|
|
|
boolean_t fuid_dirtied = B_FALSE;
|
2011-03-09 18:48:49 +00:00
|
|
|
sa_bulk_attr_t *bulk, *xattr_bulk;
|
2010-05-28 20:45:14 +00:00
|
|
|
int count = 0, xattr_count = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (mask == 0)
|
|
|
|
return (0);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
zilog = zsb->z_log;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that if we have ephemeral uid/gid or xvattr specified
|
|
|
|
* that file system is at proper version level
|
|
|
|
*/
|
2011-03-01 20:24:09 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_use_fuids == B_FALSE &&
|
2011-03-01 20:24:09 +00:00
|
|
|
(((mask & ATTR_UID) && IS_EPHEMERAL(vap->va_uid)) ||
|
|
|
|
((mask & ATTR_GID) && IS_EPHEMERAL(vap->va_gid)) ||
|
|
|
|
(mask & ATTR_XVATTR))) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_SIZE && S_ISDIR(ip->i_mode)) {
|
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EISDIR));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_SIZE && !S_ISREG(ip->i_mode) && !S_ISFIFO(ip->i_mode)) {
|
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
/*
|
|
|
|
* If this is an xvattr_t, then get a pointer to the structure of
|
|
|
|
* optional attributes. If this is NULL, then we have a vattr_t.
|
|
|
|
*/
|
|
|
|
xoap = xva_getxoptattr(xvap);
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
tmpxvattr = kmem_alloc(sizeof (xvattr_t), KM_SLEEP);
|
2011-03-02 22:18:40 +00:00
|
|
|
xva_init(tmpxvattr);
|
2011-03-01 20:24:09 +00:00
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
bulk = kmem_alloc(sizeof (sa_bulk_attr_t) * 7, KM_SLEEP);
|
|
|
|
xattr_bulk = kmem_alloc(sizeof (sa_bulk_attr_t) * 7, KM_SLEEP);
|
2011-03-09 18:48:49 +00:00
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
/*
|
|
|
|
* Immutable files can only alter immutable bit and atime
|
|
|
|
*/
|
|
|
|
if ((zp->z_pflags & ZFS_IMMUTABLE) &&
|
|
|
|
((mask & (ATTR_SIZE|ATTR_UID|ATTR_GID|ATTR_MTIME|ATTR_MODE)) ||
|
|
|
|
((mask & ATTR_XVATTR) && XVA_ISSET_REQ(xvap, XAT_CREATETIME)))) {
|
2011-03-02 22:18:40 +00:00
|
|
|
err = EPERM;
|
|
|
|
goto out3;
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((mask & ATTR_SIZE) && (zp->z_pflags & ZFS_READONLY)) {
|
2011-03-02 22:18:40 +00:00
|
|
|
err = EPERM;
|
|
|
|
goto out3;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
/*
|
|
|
|
* Verify timestamps doesn't overflow 32 bits.
|
|
|
|
* ZFS can handle large timestamps, but 32bit syscalls can't
|
|
|
|
* handle times greater than 2039. This check should be removed
|
|
|
|
* once large timestamps are fully supported.
|
|
|
|
*/
|
|
|
|
if (mask & (ATTR_ATIME | ATTR_MTIME)) {
|
2013-11-01 19:26:11 +00:00
|
|
|
if (((mask & ATTR_ATIME) &&
|
|
|
|
TIMESPEC_OVERFLOW(&vap->va_atime)) ||
|
|
|
|
((mask & ATTR_MTIME) &&
|
|
|
|
TIMESPEC_OVERFLOW(&vap->va_mtime))) {
|
2011-03-02 22:18:40 +00:00
|
|
|
err = EOVERFLOW;
|
|
|
|
goto out3;
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
top:
|
|
|
|
attrzp = NULL;
|
2010-08-26 21:24:34 +00:00
|
|
|
aclp = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-08-18 18:43:27 +00:00
|
|
|
/* Can this be moved to before the top label? */
|
2011-05-19 18:44:07 +00:00
|
|
|
if (zfs_is_readonly(zsb)) {
|
2011-03-02 22:18:40 +00:00
|
|
|
err = EROFS;
|
|
|
|
goto out3;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First validate permissions
|
|
|
|
*/
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_SIZE) {
|
2008-11-20 20:01:55 +00:00
|
|
|
err = zfs_zaccess(zp, ACE_WRITE_DATA, 0, skipaclchk, cr);
|
2011-03-02 22:18:40 +00:00
|
|
|
if (err)
|
|
|
|
goto out3;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* XXX - Note, we are not providing any open
|
|
|
|
* mode flags here (like FNDELAY), so we may
|
|
|
|
* block if there are locks present... this
|
|
|
|
* should be addressed in openat().
|
|
|
|
*/
|
2008-12-03 20:09:06 +00:00
|
|
|
/* XXX - would it be OK to generate a log record here? */
|
2011-03-01 20:24:09 +00:00
|
|
|
err = zfs_freesp(zp, vap->va_size, 0, 0, FALSE);
|
2011-03-02 22:18:40 +00:00
|
|
|
if (err)
|
|
|
|
goto out3;
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
if (mask & (ATTR_ATIME|ATTR_MTIME) ||
|
|
|
|
((mask & ATTR_XVATTR) && (XVA_ISSET_REQ(xvap, XAT_HIDDEN) ||
|
|
|
|
XVA_ISSET_REQ(xvap, XAT_READONLY) ||
|
|
|
|
XVA_ISSET_REQ(xvap, XAT_ARCHIVE) ||
|
|
|
|
XVA_ISSET_REQ(xvap, XAT_OFFLINE) ||
|
|
|
|
XVA_ISSET_REQ(xvap, XAT_SPARSE) ||
|
|
|
|
XVA_ISSET_REQ(xvap, XAT_CREATETIME) ||
|
|
|
|
XVA_ISSET_REQ(xvap, XAT_SYSTEM)))) {
|
|
|
|
need_policy = zfs_zaccess(zp, ACE_WRITE_ATTRIBUTES, 0,
|
|
|
|
skipaclchk, cr);
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & (ATTR_UID|ATTR_GID)) {
|
|
|
|
int idmask = (mask & (ATTR_UID|ATTR_GID));
|
2008-11-20 20:01:55 +00:00
|
|
|
int take_owner;
|
|
|
|
int take_group;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: even if a new mode is being set,
|
|
|
|
* we may clear S_ISUID/S_ISGID bits.
|
|
|
|
*/
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (!(mask & ATTR_MODE))
|
2011-03-01 20:24:09 +00:00
|
|
|
vap->va_mode = zp->z_mode;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Take ownership or chgrp to group we are a member of
|
|
|
|
*/
|
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
take_owner = (mask & ATTR_UID) && (vap->va_uid == crgetuid(cr));
|
2011-02-08 19:16:06 +00:00
|
|
|
take_group = (mask & ATTR_GID) &&
|
2011-03-01 20:24:09 +00:00
|
|
|
zfs_groupmember(zsb, vap->va_gid, cr);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
2011-03-01 20:24:09 +00:00
|
|
|
* If both ATTR_UID and ATTR_GID are set then take_owner and
|
2008-11-20 20:01:55 +00:00
|
|
|
* take_group must both be set in order to allow taking
|
|
|
|
* ownership.
|
|
|
|
*
|
|
|
|
* Otherwise, send the check through secpolicy_vnode_setattr()
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (((idmask == (ATTR_UID|ATTR_GID)) &&
|
|
|
|
take_owner && take_group) ||
|
|
|
|
((idmask == ATTR_UID) && take_owner) ||
|
|
|
|
((idmask == ATTR_GID) && take_group)) {
|
2008-11-20 20:01:55 +00:00
|
|
|
if (zfs_zaccess(zp, ACE_WRITE_OWNER, 0,
|
|
|
|
skipaclchk, cr) == 0) {
|
|
|
|
/*
|
|
|
|
* Remove setuid/setgid for non-privileged users
|
|
|
|
*/
|
2011-03-01 20:24:09 +00:00
|
|
|
(void) secpolicy_setid_clear(vap, cr);
|
2011-02-08 19:16:06 +00:00
|
|
|
trim_mask = (mask & (ATTR_UID|ATTR_GID));
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
|
|
|
need_policy = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
need_policy = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_enter(&zp->z_lock);
|
2010-05-28 20:45:14 +00:00
|
|
|
oldva.va_mode = zp->z_mode;
|
2010-08-26 21:24:34 +00:00
|
|
|
zfs_fuid_map_ids(zp, cr, &oldva.va_uid, &oldva.va_gid);
|
2011-03-01 20:24:09 +00:00
|
|
|
if (mask & ATTR_XVATTR) {
|
|
|
|
/*
|
|
|
|
* Update xvattr mask to include only those attributes
|
|
|
|
* that are actually changing.
|
|
|
|
*
|
|
|
|
* the bits will be restored prior to actually setting
|
|
|
|
* the attributes so the caller thinks they were set.
|
|
|
|
*/
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
|
|
|
|
if (xoap->xoa_appendonly !=
|
|
|
|
((zp->z_pflags & ZFS_APPENDONLY) != 0)) {
|
|
|
|
need_policy = TRUE;
|
|
|
|
} else {
|
|
|
|
XVA_CLR_REQ(xvap, XAT_APPENDONLY);
|
2011-03-02 22:18:40 +00:00
|
|
|
XVA_SET_REQ(tmpxvattr, XAT_APPENDONLY);
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
|
|
|
|
if (xoap->xoa_nounlink !=
|
|
|
|
((zp->z_pflags & ZFS_NOUNLINK) != 0)) {
|
|
|
|
need_policy = TRUE;
|
|
|
|
} else {
|
|
|
|
XVA_CLR_REQ(xvap, XAT_NOUNLINK);
|
2011-03-02 22:18:40 +00:00
|
|
|
XVA_SET_REQ(tmpxvattr, XAT_NOUNLINK);
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
|
|
|
|
if (xoap->xoa_immutable !=
|
|
|
|
((zp->z_pflags & ZFS_IMMUTABLE) != 0)) {
|
|
|
|
need_policy = TRUE;
|
|
|
|
} else {
|
|
|
|
XVA_CLR_REQ(xvap, XAT_IMMUTABLE);
|
2011-03-02 22:18:40 +00:00
|
|
|
XVA_SET_REQ(tmpxvattr, XAT_IMMUTABLE);
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
|
|
|
|
if (xoap->xoa_nodump !=
|
|
|
|
((zp->z_pflags & ZFS_NODUMP) != 0)) {
|
|
|
|
need_policy = TRUE;
|
|
|
|
} else {
|
|
|
|
XVA_CLR_REQ(xvap, XAT_NODUMP);
|
2011-03-02 22:18:40 +00:00
|
|
|
XVA_SET_REQ(tmpxvattr, XAT_NODUMP);
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
|
|
|
|
if (xoap->xoa_av_modified !=
|
|
|
|
((zp->z_pflags & ZFS_AV_MODIFIED) != 0)) {
|
|
|
|
need_policy = TRUE;
|
|
|
|
} else {
|
|
|
|
XVA_CLR_REQ(xvap, XAT_AV_MODIFIED);
|
2011-03-02 22:18:40 +00:00
|
|
|
XVA_SET_REQ(tmpxvattr, XAT_AV_MODIFIED);
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
|
|
|
|
if ((!S_ISREG(ip->i_mode) &&
|
|
|
|
xoap->xoa_av_quarantined) ||
|
|
|
|
xoap->xoa_av_quarantined !=
|
|
|
|
((zp->z_pflags & ZFS_AV_QUARANTINED) != 0)) {
|
|
|
|
need_policy = TRUE;
|
|
|
|
} else {
|
|
|
|
XVA_CLR_REQ(xvap, XAT_AV_QUARANTINED);
|
2011-03-02 22:18:40 +00:00
|
|
|
XVA_SET_REQ(tmpxvattr, XAT_AV_QUARANTINED);
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
|
|
|
|
mutex_exit(&zp->z_lock);
|
2011-03-02 22:18:40 +00:00
|
|
|
err = EPERM;
|
|
|
|
goto out3;
|
2011-03-01 20:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (need_policy == FALSE &&
|
|
|
|
(XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) ||
|
|
|
|
XVA_ISSET_REQ(xvap, XAT_OPAQUE))) {
|
|
|
|
need_policy = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
mutex_exit(&zp->z_lock);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_MODE) {
|
2008-11-20 20:01:55 +00:00
|
|
|
if (zfs_zaccess(zp, ACE_WRITE_ACL, 0, skipaclchk, cr) == 0) {
|
2011-03-01 20:24:09 +00:00
|
|
|
err = secpolicy_setid_setsticky_clear(ip, vap,
|
2008-11-20 20:01:55 +00:00
|
|
|
&oldva, cr);
|
2011-03-02 22:18:40 +00:00
|
|
|
if (err)
|
|
|
|
goto out3;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
trim_mask |= ATTR_MODE;
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
|
|
|
need_policy = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_policy) {
|
|
|
|
/*
|
|
|
|
* If trim_mask is set then take ownership
|
|
|
|
* has been granted or write_acl is present and user
|
|
|
|
* has the ability to modify mode. In that case remove
|
|
|
|
* UID|GID and or MODE from mask so that
|
|
|
|
* secpolicy_vnode_setattr() doesn't revoke it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (trim_mask) {
|
2011-03-01 20:24:09 +00:00
|
|
|
saved_mask = vap->va_mask;
|
|
|
|
vap->va_mask &= ~trim_mask;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2011-03-01 20:24:09 +00:00
|
|
|
err = secpolicy_vnode_setattr(cr, ip, vap, &oldva, flags,
|
2008-11-20 20:01:55 +00:00
|
|
|
(int (*)(void *, int, cred_t *))zfs_zaccess_unix, zp);
|
2011-03-02 22:18:40 +00:00
|
|
|
if (err)
|
|
|
|
goto out3;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (trim_mask)
|
2011-03-01 20:24:09 +00:00
|
|
|
vap->va_mask |= saved_mask;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* secpolicy_vnode_setattr, or take ownership may have
|
|
|
|
* changed va_mask
|
|
|
|
*/
|
2011-03-01 20:24:09 +00:00
|
|
|
mask = vap->va_mask;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((mask & (ATTR_UID | ATTR_GID))) {
|
|
|
|
err = sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zsb),
|
2010-08-26 21:24:34 +00:00
|
|
|
&xattr_obj, sizeof (xattr_obj));
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if (err == 0 && xattr_obj) {
|
2011-02-08 19:16:06 +00:00
|
|
|
err = zfs_zget(ZTOZSB(zp), xattr_obj, &attrzp);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (err)
|
|
|
|
goto out2;
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_UID) {
|
|
|
|
new_uid = zfs_fuid_create(zsb,
|
2011-03-01 20:24:09 +00:00
|
|
|
(uint64_t)vap->va_uid, cr, ZFS_OWNER, &fuidp);
|
2010-08-26 21:24:34 +00:00
|
|
|
if (new_uid != zp->z_uid &&
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fuid_overquota(zsb, B_FALSE, new_uid)) {
|
2010-08-26 21:24:34 +00:00
|
|
|
if (attrzp)
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(attrzp));
|
2010-05-28 20:45:14 +00:00
|
|
|
err = EDQUOT;
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_GID) {
|
2011-03-01 20:24:09 +00:00
|
|
|
new_gid = zfs_fuid_create(zsb, (uint64_t)vap->va_gid,
|
2010-05-28 20:45:14 +00:00
|
|
|
cr, ZFS_GROUP, &fuidp);
|
|
|
|
if (new_gid != zp->z_gid &&
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fuid_overquota(zsb, B_TRUE, new_gid)) {
|
2010-08-26 21:24:34 +00:00
|
|
|
if (attrzp)
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(attrzp));
|
2010-05-28 20:45:14 +00:00
|
|
|
err = EDQUOT;
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
tx = dmu_tx_create(zsb->z_os);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_MODE) {
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t pmode = zp->z_mode;
|
2010-08-26 21:24:34 +00:00
|
|
|
uint64_t acl_obj;
|
2011-03-01 20:24:09 +00:00
|
|
|
new_mode = (pmode & S_IFMT) | (vap->va_mode & ~S_IFMT);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
zfs_acl_chmod_setattr(zp, &aclp, new_mode);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_enter(&zp->z_lock);
|
|
|
|
if (!zp->z_is_sa && ((acl_obj = zfs_external_acl(zp)) != 0)) {
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* Are we upgrading ACL from old V0 format
|
|
|
|
* to V1 format?
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_version >= ZPL_VERSION_FUID &&
|
2010-08-26 21:24:34 +00:00
|
|
|
zfs_znode_acl_version(zp) ==
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_ACL_VERSION_INITIAL) {
|
2010-08-26 21:24:34 +00:00
|
|
|
dmu_tx_hold_free(tx, acl_obj, 0,
|
2008-11-20 20:01:55 +00:00
|
|
|
DMU_OBJECT_END);
|
|
|
|
dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
|
|
|
|
0, aclp->z_acl_bytes);
|
|
|
|
} else {
|
2010-08-26 21:24:34 +00:00
|
|
|
dmu_tx_hold_write(tx, acl_obj, 0,
|
2008-11-20 20:01:55 +00:00
|
|
|
aclp->z_acl_bytes);
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
} else if (!zp->z_is_sa && aclp->z_acl_bytes > ZFS_ACE_SPACE) {
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
|
|
|
|
0, aclp->z_acl_bytes);
|
|
|
|
}
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_exit(&zp->z_lock);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
|
|
|
|
} else {
|
2011-03-01 20:24:09 +00:00
|
|
|
if ((mask & ATTR_XVATTR) &&
|
|
|
|
XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
|
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
|
|
|
|
else
|
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (attrzp) {
|
|
|
|
dmu_tx_hold_sa(tx, attrzp->z_sa_hdl, B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
fuid_dirtied = zsb->z_fuid_dirty;
|
2010-05-28 20:45:14 +00:00
|
|
|
if (fuid_dirtied)
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fuid_txhold(zsb, tx);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
zfs_sa_upgrade_txholds(tx, zp);
|
|
|
|
|
2013-11-22 23:13:18 +00:00
|
|
|
err = dmu_tx_assign(tx, TXG_WAIT);
|
|
|
|
if (err)
|
2009-07-02 22:44:48 +00:00
|
|
|
goto out;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
count = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Set each attribute requested.
|
|
|
|
* We group settings according to the locks they need to acquire.
|
|
|
|
*
|
|
|
|
* Note: you cannot set ctime directly, although it will be
|
|
|
|
* updated as a side-effect of calling this function.
|
|
|
|
*/
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & (ATTR_UID|ATTR_GID|ATTR_MODE))
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_enter(&zp->z_acl_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
mutex_enter(&zp->z_lock);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zsb), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&zp->z_pflags, sizeof (zp->z_pflags));
|
|
|
|
|
|
|
|
if (attrzp) {
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & (ATTR_UID|ATTR_GID|ATTR_MODE))
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_enter(&attrzp->z_acl_lock);
|
2010-05-28 20:45:14 +00:00
|
|
|
mutex_enter(&attrzp->z_lock);
|
|
|
|
SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
|
2011-02-08 19:16:06 +00:00
|
|
|
SA_ZPL_FLAGS(zsb), NULL, &attrzp->z_pflags,
|
2010-05-28 20:45:14 +00:00
|
|
|
sizeof (attrzp->z_pflags));
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & (ATTR_UID|ATTR_GID)) {
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_UID) {
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zsb), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&new_uid, sizeof (new_uid));
|
2010-08-26 21:24:34 +00:00
|
|
|
zp->z_uid = new_uid;
|
2010-05-28 20:45:14 +00:00
|
|
|
if (attrzp) {
|
|
|
|
SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
|
2011-02-08 19:16:06 +00:00
|
|
|
SA_ZPL_UID(zsb), NULL, &new_uid,
|
2010-05-28 20:45:14 +00:00
|
|
|
sizeof (new_uid));
|
2010-08-26 21:24:34 +00:00
|
|
|
attrzp->z_uid = new_uid;
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_GID) {
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &new_gid, sizeof (new_gid));
|
2010-08-26 21:24:34 +00:00
|
|
|
zp->z_gid = new_gid;
|
2010-05-28 20:45:14 +00:00
|
|
|
if (attrzp) {
|
|
|
|
SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
|
2011-02-08 19:16:06 +00:00
|
|
|
SA_ZPL_GID(zsb), NULL, &new_gid,
|
2010-05-28 20:45:14 +00:00
|
|
|
sizeof (new_gid));
|
2010-08-26 21:24:34 +00:00
|
|
|
attrzp->z_gid = new_gid;
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
if (!(mask & ATTR_MODE)) {
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, &new_mode, sizeof (new_mode));
|
|
|
|
new_mode = zp->z_mode;
|
|
|
|
}
|
|
|
|
err = zfs_acl_chown_setattr(zp);
|
|
|
|
ASSERT(err == 0);
|
|
|
|
if (attrzp) {
|
|
|
|
err = zfs_acl_chown_setattr(attrzp);
|
|
|
|
ASSERT(err == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_MODE) {
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zsb), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&new_mode, sizeof (new_mode));
|
|
|
|
zp->z_mode = new_mode;
|
2011-02-23 23:03:30 +00:00
|
|
|
ASSERT3P(aclp, !=, NULL);
|
2009-07-02 22:44:48 +00:00
|
|
|
err = zfs_aclset_common(zp, aclp, cr, tx);
|
2013-05-10 21:17:03 +00:00
|
|
|
ASSERT0(err);
|
2010-08-26 21:24:34 +00:00
|
|
|
if (zp->z_acl_cached)
|
|
|
|
zfs_acl_free(zp->z_acl_cached);
|
2009-08-18 18:43:27 +00:00
|
|
|
zp->z_acl_cached = aclp;
|
|
|
|
aclp = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_ATIME) {
|
2011-03-01 20:24:09 +00:00
|
|
|
ZFS_TIME_ENCODE(&vap->va_atime, zp->z_atime);
|
2011-02-08 19:16:06 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zsb), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&zp->z_atime, sizeof (zp->z_atime));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_MTIME) {
|
2011-03-01 20:24:09 +00:00
|
|
|
ZFS_TIME_ENCODE(&vap->va_mtime, mtime);
|
2011-02-08 19:16:06 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zsb), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
mtime, sizeof (mtime));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
/* XXX - shouldn't this be done *before* the ATIME/MTIME checks? */
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & ATTR_SIZE && !(mask & ATTR_MTIME)) {
|
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
NULL, mtime, sizeof (mtime));
|
2011-02-08 19:16:06 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zsb), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&ctime, sizeof (ctime));
|
|
|
|
zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime,
|
|
|
|
B_TRUE);
|
|
|
|
} else if (mask != 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zsb), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&ctime, sizeof (ctime));
|
|
|
|
zfs_tstamp_update_setup(zp, STATE_CHANGED, mtime, ctime,
|
|
|
|
B_TRUE);
|
|
|
|
if (attrzp) {
|
|
|
|
SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
|
2011-02-08 19:16:06 +00:00
|
|
|
SA_ZPL_CTIME(zsb), NULL,
|
2010-05-28 20:45:14 +00:00
|
|
|
&ctime, sizeof (ctime));
|
|
|
|
zfs_tstamp_update_setup(attrzp, STATE_CHANGED,
|
|
|
|
mtime, ctime, B_TRUE);
|
|
|
|
}
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Do this after setting timestamps to prevent timestamp
|
|
|
|
* update from toggling bit
|
|
|
|
*/
|
|
|
|
|
2011-03-01 20:24:09 +00:00
|
|
|
if (xoap && (mask & ATTR_XVATTR)) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* restore trimmed off masks
|
|
|
|
* so that return masks can be set for caller.
|
|
|
|
*/
|
|
|
|
|
2011-03-02 22:18:40 +00:00
|
|
|
if (XVA_ISSET_REQ(tmpxvattr, XAT_APPENDONLY)) {
|
2011-03-01 20:24:09 +00:00
|
|
|
XVA_SET_REQ(xvap, XAT_APPENDONLY);
|
|
|
|
}
|
2011-03-02 22:18:40 +00:00
|
|
|
if (XVA_ISSET_REQ(tmpxvattr, XAT_NOUNLINK)) {
|
2011-03-01 20:24:09 +00:00
|
|
|
XVA_SET_REQ(xvap, XAT_NOUNLINK);
|
|
|
|
}
|
2011-03-02 22:18:40 +00:00
|
|
|
if (XVA_ISSET_REQ(tmpxvattr, XAT_IMMUTABLE)) {
|
2011-03-01 20:24:09 +00:00
|
|
|
XVA_SET_REQ(xvap, XAT_IMMUTABLE);
|
|
|
|
}
|
2011-03-02 22:18:40 +00:00
|
|
|
if (XVA_ISSET_REQ(tmpxvattr, XAT_NODUMP)) {
|
2011-03-01 20:24:09 +00:00
|
|
|
XVA_SET_REQ(xvap, XAT_NODUMP);
|
|
|
|
}
|
2011-03-02 22:18:40 +00:00
|
|
|
if (XVA_ISSET_REQ(tmpxvattr, XAT_AV_MODIFIED)) {
|
2011-03-01 20:24:09 +00:00
|
|
|
XVA_SET_REQ(xvap, XAT_AV_MODIFIED);
|
|
|
|
}
|
2011-03-02 22:18:40 +00:00
|
|
|
if (XVA_ISSET_REQ(tmpxvattr, XAT_AV_QUARANTINED)) {
|
2011-03-01 20:24:09 +00:00
|
|
|
XVA_SET_REQ(xvap, XAT_AV_QUARANTINED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
|
|
|
|
ASSERT(S_ISREG(ip->i_mode));
|
|
|
|
|
|
|
|
zfs_xvattr_set(zp, xvap, tx);
|
|
|
|
}
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
if (fuid_dirtied)
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fuid_sync(zsb, tx);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (mask != 0)
|
2011-03-01 20:24:09 +00:00
|
|
|
zfs_log_setattr(zilog, tx, TX_SETATTR, zp, vap, mask, fuidp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
mutex_exit(&zp->z_lock);
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & (ATTR_UID|ATTR_GID|ATTR_MODE))
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_exit(&zp->z_acl_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if (attrzp) {
|
2011-02-08 19:16:06 +00:00
|
|
|
if (mask & (ATTR_UID|ATTR_GID|ATTR_MODE))
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_exit(&attrzp->z_acl_lock);
|
|
|
|
mutex_exit(&attrzp->z_lock);
|
|
|
|
}
|
2009-07-02 22:44:48 +00:00
|
|
|
out:
|
2010-05-28 20:45:14 +00:00
|
|
|
if (err == 0 && attrzp) {
|
|
|
|
err2 = sa_bulk_update(attrzp->z_sa_hdl, xattr_bulk,
|
|
|
|
xattr_count, tx);
|
|
|
|
ASSERT(err2 == 0);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (attrzp)
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(attrzp));
|
2009-08-18 18:43:27 +00:00
|
|
|
if (aclp)
|
2009-07-02 22:44:48 +00:00
|
|
|
zfs_acl_free(aclp);
|
|
|
|
|
|
|
|
if (fuidp) {
|
|
|
|
zfs_fuid_info_free(fuidp);
|
|
|
|
fuidp = NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (err) {
|
2009-07-02 22:44:48 +00:00
|
|
|
dmu_tx_abort(tx);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (err == ERESTART)
|
|
|
|
goto top;
|
|
|
|
} else {
|
|
|
|
err2 = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
|
2009-07-02 22:44:48 +00:00
|
|
|
dmu_tx_commit(tx);
|
2011-02-17 22:17:44 +00:00
|
|
|
zfs_inode_update(zp);
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out2:
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
|
2010-08-26 21:24:34 +00:00
|
|
|
zil_commit(zilog, 0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-03-02 22:18:40 +00:00
|
|
|
out3:
|
2013-11-01 19:26:11 +00:00
|
|
|
kmem_free(xattr_bulk, sizeof (sa_bulk_attr_t) * 7);
|
|
|
|
kmem_free(bulk, sizeof (sa_bulk_attr_t) * 7);
|
|
|
|
kmem_free(tmpxvattr, sizeof (xvattr_t));
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_setattr);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
typedef struct zfs_zlock {
|
|
|
|
krwlock_t *zl_rwlock; /* lock we acquired */
|
|
|
|
znode_t *zl_znode; /* znode we held */
|
|
|
|
struct zfs_zlock *zl_next; /* next in list */
|
|
|
|
} zfs_zlock_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Drop locks and release vnodes that were held by zfs_rename_lock().
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
zfs_rename_unlock(zfs_zlock_t **zlpp)
|
|
|
|
{
|
|
|
|
zfs_zlock_t *zl;
|
|
|
|
|
|
|
|
while ((zl = *zlpp) != NULL) {
|
|
|
|
if (zl->zl_znode != NULL)
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(zl->zl_znode));
|
2008-11-20 20:01:55 +00:00
|
|
|
rw_exit(zl->zl_rwlock);
|
|
|
|
*zlpp = zl->zl_next;
|
|
|
|
kmem_free(zl, sizeof (*zl));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search back through the directory tree, using the ".." entries.
|
|
|
|
* Lock each directory in the chain to prevent concurrent renames.
|
|
|
|
* Fail any attempt to move a directory into one of its own descendants.
|
|
|
|
* XXX - z_parent_lock can overlap with map or grow locks
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfs_rename_lock(znode_t *szp, znode_t *tdzp, znode_t *sdzp, zfs_zlock_t **zlpp)
|
|
|
|
{
|
|
|
|
zfs_zlock_t *zl;
|
|
|
|
znode_t *zp = tdzp;
|
2011-02-08 19:16:06 +00:00
|
|
|
uint64_t rootid = ZTOZSB(zp)->z_root;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t oidp = zp->z_id;
|
2008-11-20 20:01:55 +00:00
|
|
|
krwlock_t *rwlp = &szp->z_parent_lock;
|
|
|
|
krw_t rw = RW_WRITER;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First pass write-locks szp and compares to zp->z_id.
|
|
|
|
* Later passes read-lock zp and compare to zp->z_parent.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
if (!rw_tryenter(rwlp, rw)) {
|
|
|
|
/*
|
|
|
|
* Another thread is renaming in this path.
|
|
|
|
* Note that if we are a WRITER, we don't have any
|
|
|
|
* parent_locks held yet.
|
|
|
|
*/
|
|
|
|
if (rw == RW_READER && zp->z_id > szp->z_id) {
|
|
|
|
/*
|
|
|
|
* Drop our locks and restart
|
|
|
|
*/
|
|
|
|
zfs_rename_unlock(&zl);
|
|
|
|
*zlpp = NULL;
|
|
|
|
zp = tdzp;
|
2010-05-28 20:45:14 +00:00
|
|
|
oidp = zp->z_id;
|
2008-11-20 20:01:55 +00:00
|
|
|
rwlp = &szp->z_parent_lock;
|
|
|
|
rw = RW_WRITER;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Wait for other thread to drop its locks
|
|
|
|
*/
|
|
|
|
rw_enter(rwlp, rw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
zl = kmem_alloc(sizeof (*zl), KM_SLEEP);
|
|
|
|
zl->zl_rwlock = rwlp;
|
|
|
|
zl->zl_znode = NULL;
|
|
|
|
zl->zl_next = *zlpp;
|
|
|
|
*zlpp = zl;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (oidp == szp->z_id) /* We're a descendant of szp */
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (oidp == rootid) /* We've hit the top */
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (rw == RW_READER) { /* i.e. not the first pass */
|
2011-02-08 19:16:06 +00:00
|
|
|
int error = zfs_zget(ZTOZSB(zp), oidp, &zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
zl->zl_znode = zp;
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
(void) sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(ZTOZSB(zp)),
|
2010-05-28 20:45:14 +00:00
|
|
|
&oidp, sizeof (oidp));
|
2008-11-20 20:01:55 +00:00
|
|
|
rwlp = &zp->z_parent_lock;
|
|
|
|
rw = RW_READER;
|
|
|
|
|
|
|
|
} while (zp->z_id != sdzp->z_id);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move an entry from the provided source directory to the target
|
|
|
|
* directory. Change the entry name as indicated.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: sdip - Source directory containing the "old entry".
|
2008-11-20 20:01:55 +00:00
|
|
|
* snm - Old entry name.
|
2011-02-08 19:16:06 +00:00
|
|
|
* tdip - Target directory to contain the "new entry".
|
2008-11-20 20:01:55 +00:00
|
|
|
* tnm - New entry name.
|
|
|
|
* cr - credentials of caller.
|
|
|
|
* flags - case flags
|
|
|
|
*
|
2013-06-11 17:12:34 +00:00
|
|
|
* RETURN: 0 on success, error code on failure.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* sdip,tdip - ctime|mtime updated
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_rename(struct inode *sdip, char *snm, struct inode *tdip, char *tnm,
|
|
|
|
cred_t *cr, int flags)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
znode_t *tdzp, *szp, *tzp;
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *sdzp = ITOZ(sdip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(sdip);
|
2008-11-20 20:01:55 +00:00
|
|
|
zilog_t *zilog;
|
|
|
|
zfs_dirlock_t *sdl, *tdl;
|
|
|
|
dmu_tx_t *tx;
|
|
|
|
zfs_zlock_t *zl;
|
|
|
|
int cmp, serr, terr;
|
|
|
|
int error = 0;
|
|
|
|
int zflg = 0;
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
boolean_t waited = B_FALSE;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(sdzp);
|
2011-02-08 19:16:06 +00:00
|
|
|
zilog = zsb->z_log;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-04-06 01:59:44 +00:00
|
|
|
if (tdip->i_sb != sdip->i_sb || zfsctl_is_node(tdip)) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EXDEV));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
tdzp = ITOZ(tdip);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(tdzp);
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_utf8 && u8_validate(tnm,
|
2008-11-20 20:01:55 +00:00
|
|
|
strlen(tnm), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EILSEQ));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FIGNORECASE)
|
|
|
|
zflg |= ZCILOOK;
|
|
|
|
|
|
|
|
top:
|
|
|
|
szp = NULL;
|
|
|
|
tzp = NULL;
|
|
|
|
zl = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is to prevent the creation of links into attribute space
|
|
|
|
* by renaming a linked file into/outof an attribute directory.
|
|
|
|
* See the comment in zfs_link() for why this is considered bad.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((tdzp->z_pflags & ZFS_XATTR) != (sdzp->z_pflags & ZFS_XATTR)) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock source and target directory entries. To prevent deadlock,
|
|
|
|
* a lock ordering must be defined. We lock the directory with
|
|
|
|
* the smallest object id first, or if it's a tie, the one with
|
|
|
|
* the lexically first name.
|
|
|
|
*/
|
|
|
|
if (sdzp->z_id < tdzp->z_id) {
|
|
|
|
cmp = -1;
|
|
|
|
} else if (sdzp->z_id > tdzp->z_id) {
|
|
|
|
cmp = 1;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* First compare the two name arguments without
|
|
|
|
* considering any case folding.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
int nofold = (zsb->z_norm & ~U8_TEXTPREP_TOUPPER);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
cmp = u8_strcmp(snm, tnm, 0, nofold, U8_UNICODE_LATEST, &error);
|
2011-02-08 19:16:06 +00:00
|
|
|
ASSERT(error == 0 || !zsb->z_utf8);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (cmp == 0) {
|
|
|
|
/*
|
|
|
|
* POSIX: "If the old argument and the new argument
|
|
|
|
* both refer to links to the same existing file,
|
|
|
|
* the rename() function shall return successfully
|
|
|
|
* and perform no other action."
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the file system is case-folding, then we may
|
|
|
|
* have some more checking to do. A case-folding file
|
|
|
|
* system is either supporting mixed case sensitivity
|
|
|
|
* access or is completely case-insensitive. Note
|
|
|
|
* that the file system is always case preserving.
|
|
|
|
*
|
|
|
|
* In mixed sensitivity mode case sensitive behavior
|
|
|
|
* is the default. FIGNORECASE must be used to
|
|
|
|
* explicitly request case insensitive behavior.
|
|
|
|
*
|
|
|
|
* If the source and target names provided differ only
|
|
|
|
* by case (e.g., a request to rename 'tim' to 'Tim'),
|
|
|
|
* we will treat this as a special case in the
|
|
|
|
* case-insensitive mode: as long as the source name
|
|
|
|
* is an exact match, we will allow this to proceed as
|
|
|
|
* a name-change request.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((zsb->z_case == ZFS_CASE_INSENSITIVE ||
|
|
|
|
(zsb->z_case == ZFS_CASE_MIXED &&
|
2008-11-20 20:01:55 +00:00
|
|
|
flags & FIGNORECASE)) &&
|
2011-02-08 19:16:06 +00:00
|
|
|
u8_strcmp(snm, tnm, 0, zsb->z_norm, U8_UNICODE_LATEST,
|
2008-11-20 20:01:55 +00:00
|
|
|
&error) == 0) {
|
|
|
|
/*
|
|
|
|
* case preserving rename request, require exact
|
|
|
|
* name matches
|
|
|
|
*/
|
|
|
|
zflg |= ZCIEXACT;
|
|
|
|
zflg &= ~ZCILOOK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* If the source and destination directories are the same, we should
|
|
|
|
* grab the z_name_lock of that directory only once.
|
|
|
|
*/
|
|
|
|
if (sdzp == tdzp) {
|
|
|
|
zflg |= ZHAVELOCK;
|
|
|
|
rw_enter(&sdzp->z_name_lock, RW_READER);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (cmp < 0) {
|
|
|
|
serr = zfs_dirent_lock(&sdl, sdzp, snm, &szp,
|
|
|
|
ZEXISTS | zflg, NULL, NULL);
|
|
|
|
terr = zfs_dirent_lock(&tdl,
|
|
|
|
tdzp, tnm, &tzp, ZRENAMING | zflg, NULL, NULL);
|
|
|
|
} else {
|
|
|
|
terr = zfs_dirent_lock(&tdl,
|
|
|
|
tdzp, tnm, &tzp, zflg, NULL, NULL);
|
|
|
|
serr = zfs_dirent_lock(&sdl,
|
|
|
|
sdzp, snm, &szp, ZEXISTS | ZRENAMING | zflg,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serr) {
|
|
|
|
/*
|
|
|
|
* Source entry invalid or not there.
|
|
|
|
*/
|
|
|
|
if (!terr) {
|
|
|
|
zfs_dirent_unlock(tdl);
|
|
|
|
if (tzp)
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(tzp));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (sdzp == tdzp)
|
|
|
|
rw_exit(&sdzp->z_name_lock);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (strcmp(snm, "..") == 0)
|
|
|
|
serr = EINVAL;
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (serr);
|
|
|
|
}
|
|
|
|
if (terr) {
|
|
|
|
zfs_dirent_unlock(sdl);
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(szp));
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (sdzp == tdzp)
|
|
|
|
rw_exit(&sdzp->z_name_lock);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (strcmp(tnm, "..") == 0)
|
|
|
|
terr = EINVAL;
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (terr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must have write access at the source to remove the old entry
|
|
|
|
* and write access at the target to create the new entry.
|
|
|
|
* Note that if target and source are the same, this can be
|
|
|
|
* done in a single check.
|
|
|
|
*/
|
|
|
|
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_zaccess_rename(sdzp, szp, tdzp, tzp, cr)))
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (S_ISDIR(ZTOI(szp)->i_mode)) {
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Check to make sure rename is valid.
|
|
|
|
* Can't do a move like this: /usr/a/b to /usr/a/b/c/d
|
|
|
|
*/
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_rename_lock(szp, tdzp, sdzp, &zl)))
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Does target exist?
|
|
|
|
*/
|
|
|
|
if (tzp) {
|
|
|
|
/*
|
|
|
|
* Source and target must be the same type.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (S_ISDIR(ZTOI(szp)->i_mode)) {
|
|
|
|
if (!S_ISDIR(ZTOI(tzp)->i_mode)) {
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(ENOTDIR);
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
2011-02-08 19:16:06 +00:00
|
|
|
if (S_ISDIR(ZTOI(tzp)->i_mode)) {
|
2013-03-08 18:41:28 +00:00
|
|
|
error = SET_ERROR(EISDIR);
|
2008-11-20 20:01:55 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* POSIX dictates that when the source and target
|
|
|
|
* entries refer to the same file object, rename
|
|
|
|
* must do nothing and exit without error.
|
|
|
|
*/
|
|
|
|
if (szp->z_id == tzp->z_id) {
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
tx = dmu_tx_create(zsb->z_os);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, szp->z_sa_hdl, B_FALSE);
|
|
|
|
dmu_tx_hold_sa(tx, sdzp->z_sa_hdl, B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_hold_zap(tx, sdzp->z_id, FALSE, snm);
|
|
|
|
dmu_tx_hold_zap(tx, tdzp->z_id, TRUE, tnm);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (sdzp != tdzp) {
|
|
|
|
dmu_tx_hold_sa(tx, tdzp->z_sa_hdl, B_FALSE);
|
|
|
|
zfs_sa_upgrade_txholds(tx, tdzp);
|
|
|
|
}
|
|
|
|
if (tzp) {
|
|
|
|
dmu_tx_hold_sa(tx, tzp->z_sa_hdl, B_FALSE);
|
|
|
|
zfs_sa_upgrade_txholds(tx, tzp);
|
|
|
|
}
|
|
|
|
|
|
|
|
zfs_sa_upgrade_txholds(tx, szp);
|
2011-02-08 19:16:06 +00:00
|
|
|
dmu_tx_hold_zap(tx, zsb->z_unlinkedobj, FALSE, NULL);
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
error = dmu_tx_assign(tx, waited ? TXG_WAITED : TXG_NOWAIT);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error) {
|
|
|
|
if (zl != NULL)
|
|
|
|
zfs_rename_unlock(&zl);
|
|
|
|
zfs_dirent_unlock(sdl);
|
|
|
|
zfs_dirent_unlock(tdl);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (sdzp == tdzp)
|
|
|
|
rw_exit(&sdzp->z_name_lock);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(szp));
|
2008-11-20 20:01:55 +00:00
|
|
|
if (tzp)
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(tzp));
|
2009-01-15 21:59:39 +00:00
|
|
|
if (error == ERESTART) {
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
waited = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_wait(tx);
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
goto top;
|
|
|
|
}
|
|
|
|
dmu_tx_abort(tx);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tzp) /* Attempt to remove the existing target */
|
|
|
|
error = zfs_link_destroy(tdl, tzp, tx, zflg, NULL);
|
|
|
|
|
|
|
|
if (error == 0) {
|
|
|
|
error = zfs_link_create(tdl, szp, tx, ZRENAMING);
|
|
|
|
if (error == 0) {
|
2010-05-28 20:45:14 +00:00
|
|
|
szp->z_pflags |= ZFS_AV_MODIFIED;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
error = sa_update(szp->z_sa_hdl, SA_ZPL_FLAGS(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
(void *)&szp->z_pflags, sizeof (uint64_t), tx);
|
2013-05-10 21:17:03 +00:00
|
|
|
ASSERT0(error);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
error = zfs_link_destroy(sdl, szp, tx, ZRENAMING, NULL);
|
|
|
|
if (error == 0) {
|
|
|
|
zfs_log_rename(zilog, tx, TX_RENAME |
|
2010-08-26 21:24:34 +00:00
|
|
|
(flags & FIGNORECASE ? TX_CI : 0), sdzp,
|
|
|
|
sdl->dl_name, tdzp, tdl->dl_name, szp);
|
2010-05-28 20:45:14 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* At this point, we have successfully created
|
|
|
|
* the target name, but have failed to remove
|
|
|
|
* the source name. Since the create was done
|
|
|
|
* with the ZRENAMING flag, there are
|
|
|
|
* complications; for one, the link count is
|
|
|
|
* wrong. The easiest way to deal with this
|
|
|
|
* is to remove the newly created target, and
|
|
|
|
* return the original error. This must
|
|
|
|
* succeed; fortunately, it is very unlikely to
|
|
|
|
* fail, since we just created it.
|
|
|
|
*/
|
|
|
|
VERIFY3U(zfs_link_destroy(tdl, szp, tx,
|
|
|
|
ZRENAMING, NULL), ==, 0);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dmu_tx_commit(tx);
|
|
|
|
out:
|
|
|
|
if (zl != NULL)
|
|
|
|
zfs_rename_unlock(&zl);
|
|
|
|
|
|
|
|
zfs_dirent_unlock(sdl);
|
|
|
|
zfs_dirent_unlock(tdl);
|
|
|
|
|
2011-01-05 22:27:30 +00:00
|
|
|
zfs_inode_update(sdzp);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (sdzp == tdzp)
|
|
|
|
rw_exit(&sdzp->z_name_lock);
|
|
|
|
|
2011-01-05 22:27:30 +00:00
|
|
|
if (sdzp != tdzp)
|
|
|
|
zfs_inode_update(tdzp);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-01-05 22:27:30 +00:00
|
|
|
zfs_inode_update(szp);
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(szp));
|
2011-01-05 22:27:30 +00:00
|
|
|
if (tzp) {
|
|
|
|
zfs_inode_update(tzp);
|
2011-02-08 19:16:06 +00:00
|
|
|
iput(ZTOI(tzp));
|
2011-01-05 22:27:30 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
|
2010-08-26 21:24:34 +00:00
|
|
|
zil_commit(zilog, 0);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_rename);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert the indicated symbolic reference entry into the directory.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: dip - Directory to contain new symbolic link.
|
2008-11-20 20:01:55 +00:00
|
|
|
* link - Name for new symlink entry.
|
|
|
|
* vap - Attributes of new entry.
|
|
|
|
* target - Target path of new symlink.
|
2011-02-08 19:16:06 +00:00
|
|
|
*
|
2008-11-20 20:01:55 +00:00
|
|
|
* cr - credentials of caller.
|
|
|
|
* flags - case flags
|
|
|
|
*
|
2013-06-11 17:12:34 +00:00
|
|
|
* RETURN: 0 on success, error code on failure.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* dip - ctime|mtime updated
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_symlink(struct inode *dip, char *name, vattr_t *vap, char *link,
|
|
|
|
struct inode **ipp, cred_t *cr, int flags)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp, *dzp = ITOZ(dip);
|
2008-11-20 20:01:55 +00:00
|
|
|
zfs_dirlock_t *dl;
|
|
|
|
dmu_tx_t *tx;
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_sb_t *zsb = ITOZSB(dip);
|
2008-11-20 20:01:55 +00:00
|
|
|
zilog_t *zilog;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t len = strlen(link);
|
2008-11-20 20:01:55 +00:00
|
|
|
int error;
|
|
|
|
int zflg = ZNEW;
|
2009-07-02 22:44:48 +00:00
|
|
|
zfs_acl_ids_t acl_ids;
|
|
|
|
boolean_t fuid_dirtied;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t txtype = TX_SYMLINK;
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
boolean_t waited = B_FALSE;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ASSERT(S_ISLNK(vap->va_mode));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(dzp);
|
2011-02-08 19:16:06 +00:00
|
|
|
zilog = zsb->z_log;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_utf8 && u8_validate(name, strlen(name),
|
2008-11-20 20:01:55 +00:00
|
|
|
NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EILSEQ));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
if (flags & FIGNORECASE)
|
|
|
|
zflg |= ZCILOOK;
|
|
|
|
|
|
|
|
if (len > MAXPATHLEN) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(ENAMETOOLONG));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((error = zfs_acl_ids_create(dzp, 0,
|
|
|
|
vap, cr, NULL, &acl_ids)) != 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2010-05-28 20:45:14 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
top:
|
2011-02-08 19:16:06 +00:00
|
|
|
*ipp = NULL;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Attempt to lock directory; fail if entry already exists.
|
|
|
|
*/
|
|
|
|
error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg, NULL, NULL);
|
|
|
|
if (error) {
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2010-05-28 20:45:14 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr))) {
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
|
|
|
zfs_dirent_unlock(dl);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zfs_acl_ids_overquota(zsb, &acl_ids)) {
|
2009-07-02 22:44:48 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
|
|
|
zfs_dirent_unlock(dl);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EDQUOT));
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
tx = dmu_tx_create(zsb->z_os);
|
|
|
|
fuid_dirtied = zsb->z_fuid_dirty;
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, MAX(1, len));
|
|
|
|
dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
|
|
|
|
ZFS_SA_BASE_ATTR_SIZE + len);
|
|
|
|
dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
|
2011-02-08 19:16:06 +00:00
|
|
|
if (!zsb->z_use_sa && acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
|
|
|
|
acl_ids.z_aclp->z_acl_bytes);
|
|
|
|
}
|
2009-07-02 22:44:48 +00:00
|
|
|
if (fuid_dirtied)
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fuid_txhold(zsb, tx);
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
error = dmu_tx_assign(tx, waited ? TXG_WAITED : TXG_NOWAIT);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error) {
|
|
|
|
zfs_dirent_unlock(dl);
|
2009-01-15 21:59:39 +00:00
|
|
|
if (error == ERESTART) {
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
waited = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_wait(tx);
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
goto top;
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_abort(tx);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new object for the symlink.
|
2010-05-28 20:45:14 +00:00
|
|
|
* for version 4 ZPL datsets the symlink will be an SA attribute
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (fuid_dirtied)
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fuid_sync(zsb, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_enter(&zp->z_lock);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (zp->z_is_sa)
|
2011-02-08 19:16:06 +00:00
|
|
|
error = sa_update(zp->z_sa_hdl, SA_ZPL_SYMLINK(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
link, len, tx);
|
|
|
|
else
|
|
|
|
zfs_sa_symlink(zp, link, len, tx);
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_exit(&zp->z_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
zp->z_size = len;
|
2011-02-08 19:16:06 +00:00
|
|
|
(void) sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
&zp->z_size, sizeof (zp->z_size), tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Insert the new object into the directory.
|
|
|
|
*/
|
|
|
|
(void) zfs_link_create(dl, zp, tx, ZNEW);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (flags & FIGNORECASE)
|
|
|
|
txtype |= TX_CI;
|
|
|
|
zfs_log_symlink(zilog, tx, txtype, dzp, zp, name, link);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2011-01-05 22:27:30 +00:00
|
|
|
zfs_inode_update(dzp);
|
|
|
|
zfs_inode_update(zp);
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
zfs_acl_ids_free(&acl_ids);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
dmu_tx_commit(tx);
|
|
|
|
|
|
|
|
zfs_dirent_unlock(dl);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
*ipp = ZTOI(zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
|
2010-08-26 21:24:34 +00:00
|
|
|
zil_commit(zilog, 0);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_symlink);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return, in the buffer contained in the provided uio structure,
|
2011-02-08 19:16:06 +00:00
|
|
|
* the symbolic path referred to by ip.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2011-02-16 23:54:55 +00:00
|
|
|
* IN: ip - inode of symbolic link
|
|
|
|
* uio - structure to contain the link path.
|
|
|
|
* cr - credentials of caller.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* RETURN: 0 if success
|
|
|
|
* error code if failure
|
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* ip - atime updated
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-16 23:54:55 +00:00
|
|
|
zfs_readlink(struct inode *ip, uio_t *uio, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
int error;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_enter(&zp->z_lock);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (zp->z_is_sa)
|
2011-02-16 23:54:55 +00:00
|
|
|
error = sa_lookup_uio(zp->z_sa_hdl,
|
|
|
|
SA_ZPL_SYMLINK(zsb), uio);
|
2010-05-28 20:45:14 +00:00
|
|
|
else
|
2011-02-16 23:54:55 +00:00
|
|
|
error = zfs_sa_readlink(zp, uio);
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_exit(&zp->z_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ACCESSTIME_STAMP(zsb, zp);
|
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2011-02-16 23:54:55 +00:00
|
|
|
EXPORT_SYMBOL(zfs_readlink);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
2011-02-08 19:16:06 +00:00
|
|
|
* Insert a new entry into directory tdip referencing sip.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: tdip - Directory to contain new entry.
|
|
|
|
* sip - inode of new entry.
|
2008-11-20 20:01:55 +00:00
|
|
|
* name - name of new entry.
|
|
|
|
* cr - credentials of caller.
|
|
|
|
*
|
|
|
|
* RETURN: 0 if success
|
|
|
|
* error code if failure
|
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* tdip - ctime|mtime updated
|
|
|
|
* sip - ctime updated
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_link(struct inode *tdip, struct inode *sip, char *name, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *dzp = ITOZ(tdip);
|
2008-11-20 20:01:55 +00:00
|
|
|
znode_t *tzp, *szp;
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_sb_t *zsb = ITOZSB(tdip);
|
2008-11-20 20:01:55 +00:00
|
|
|
zilog_t *zilog;
|
|
|
|
zfs_dirlock_t *dl;
|
|
|
|
dmu_tx_t *tx;
|
|
|
|
int error;
|
|
|
|
int zf = ZNEW;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t parent;
|
2010-08-26 21:24:34 +00:00
|
|
|
uid_t owner;
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
boolean_t waited = B_FALSE;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ASSERT(S_ISDIR(tdip->i_mode));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(dzp);
|
2011-02-08 19:16:06 +00:00
|
|
|
zilog = zsb->z_log;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* POSIX dictates that we return EPERM here.
|
|
|
|
* Better choices include ENOTSUP or EISDIR.
|
|
|
|
*/
|
2011-02-08 19:16:06 +00:00
|
|
|
if (S_ISDIR(sip->i_mode)) {
|
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EPERM));
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
2010-04-06 01:59:44 +00:00
|
|
|
if (sip->i_sb != tdip->i_sb || zfsctl_is_node(sip)) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EXDEV));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
szp = ITOZ(sip);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(szp);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/* Prevent links to .zfs/shares files */
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((error = sa_lookup(szp->z_sa_hdl, SA_ZPL_PARENT(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
&parent, sizeof (uint64_t))) != 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2010-05-28 20:45:14 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
if (parent == zsb->z_shares_dir) {
|
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EPERM));
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_utf8 && u8_validate(name,
|
2008-11-20 20:01:55 +00:00
|
|
|
strlen(name), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EILSEQ));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_PN_UTILS
|
2008-11-20 20:01:55 +00:00
|
|
|
if (flags & FIGNORECASE)
|
|
|
|
zf |= ZCILOOK;
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_PN_UTILS */
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We do not support links between attributes and non-attributes
|
|
|
|
* because of the potential security risk of creating links
|
|
|
|
* into "normal" file space in order to circumvent restrictions
|
|
|
|
* imposed in attribute space.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((szp->z_pflags & ZFS_XATTR) != (dzp->z_pflags & ZFS_XATTR)) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
owner = zfs_fuid_map_id(zsb, szp->z_uid, cr, ZFS_OWNER);
|
2010-08-26 21:24:34 +00:00
|
|
|
if (owner != crgetuid(cr) && secpolicy_basic_link(cr) != 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EPERM));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-12-16 22:05:42 +00:00
|
|
|
if ((error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr))) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
top:
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Attempt to lock directory; fail if entry already exists.
|
|
|
|
*/
|
|
|
|
error = zfs_dirent_lock(&dl, dzp, name, &tzp, zf, NULL, NULL);
|
|
|
|
if (error) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
tx = dmu_tx_create(zsb->z_os);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, szp->z_sa_hdl, B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
|
2010-05-28 20:45:14 +00:00
|
|
|
zfs_sa_upgrade_txholds(tx, szp);
|
|
|
|
zfs_sa_upgrade_txholds(tx, dzp);
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
error = dmu_tx_assign(tx, waited ? TXG_WAITED : TXG_NOWAIT);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (error) {
|
|
|
|
zfs_dirent_unlock(dl);
|
2009-01-15 21:59:39 +00:00
|
|
|
if (error == ERESTART) {
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 03:01:20 +00:00
|
|
|
waited = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_wait(tx);
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
goto top;
|
|
|
|
}
|
|
|
|
dmu_tx_abort(tx);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = zfs_link_create(dl, szp, tx, 0);
|
|
|
|
|
|
|
|
if (error == 0) {
|
|
|
|
uint64_t txtype = TX_LINK;
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_PN_UTILS
|
2008-11-20 20:01:55 +00:00
|
|
|
if (flags & FIGNORECASE)
|
|
|
|
txtype |= TX_CI;
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_PN_UTILS */
|
2008-11-20 20:01:55 +00:00
|
|
|
zfs_log_link(zilog, tx, txtype, dzp, szp, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
dmu_tx_commit(tx);
|
|
|
|
|
|
|
|
zfs_dirent_unlock(dl);
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
|
2010-08-26 21:24:34 +00:00
|
|
|
zil_commit(zilog, 0);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-01-05 22:27:30 +00:00
|
|
|
zfs_inode_update(dzp);
|
|
|
|
zfs_inode_update(szp);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_link);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-08-02 04:28:51 +00:00
|
|
|
static void
|
Only commit the ZIL once in zpl_writepages() (msync() case).
Currently, using msync() results in the following code path:
sys_msync -> zpl_fsync -> filemap_write_and_wait_range -> zpl_writepages -> write_cache_pages -> zpl_putpage
In such a code path, zil_commit() is called as part of zpl_putpage().
This means that for each page, the write is handed to the DMU, the ZIL
is committed, and only then do we move on to the next page. As one might
imagine, this results in atrocious performance where there is a large
number of pages to write: instead of committing a batch of N writes,
we do N commits containing one page each. In some extreme cases this
can result in msync() being ~700 times slower than it should be, as well
as very inefficient use of ZIL resources.
This patch fixes this issue by making sure that the requested writes
are batched and then committed only once. Unfortunately, the
implementation is somewhat non-trivial because there is no way to run
write_cache_pages in SYNC mode (so that we get all pages) without
making it wait on the writeback tag for each page.
The solution implemented here is composed of two parts:
- I added a new callback system to the ZIL, which allows the caller to
be notified when its ITX gets written to stable storage. One nice
thing is that the callback is called not only in zil_commit() but
in zil_sync() as well, which means that the caller doesn't have to
care whether the write ended up in the ZIL or the DMU: it will get
notified as soon as it's safe, period. This is an improvement over
dmu_tx_callback_register() that was used previously, which only
supports DMU writes. The rationale for this change is to allow
zpl_putpage() to be notified when a ZIL commit is completed without
having to block on zil_commit() itself.
- zpl_writepages() now calls write_cache_pages in non-SYNC mode, which
will prevent (1) write_cache_pages from blocking, and (2) zpl_putpage
from issuing ZIL commits. zpl_writepages() will issue the commit
itself instead of relying on zpl_putpage() to do it, thus nicely
batching the writes. Note, however, that we still have to call
write_cache_pages() again in SYNC mode because there is an edge case
documented in the implementation of write_cache_pages() whereas it
will not give us all dirty pages when running in non-SYNC mode. Thus
we need to run it at least once in SYNC mode to make sure we honor
persistency guarantees. This only happens when the pages are
modified at the same time msync() is running, which should be rare.
In most cases there won't be any additional pages and this second
call will do nothing.
Note that this change also fixes a bug related to #907 whereas calling
msync() on pages that were already handed over to the DMU in a previous
writepages() call would make msync() block until the next TXG sync
instead of returning as soon as the ZIL commit is complete. The new
callback system fixes that problem.
Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1849
Closes #907
2013-11-10 15:00:11 +00:00
|
|
|
zfs_putpage_commit_cb(void *arg)
|
2011-08-02 04:28:51 +00:00
|
|
|
{
|
|
|
|
struct page *pp = arg;
|
|
|
|
|
Only commit the ZIL once in zpl_writepages() (msync() case).
Currently, using msync() results in the following code path:
sys_msync -> zpl_fsync -> filemap_write_and_wait_range -> zpl_writepages -> write_cache_pages -> zpl_putpage
In such a code path, zil_commit() is called as part of zpl_putpage().
This means that for each page, the write is handed to the DMU, the ZIL
is committed, and only then do we move on to the next page. As one might
imagine, this results in atrocious performance where there is a large
number of pages to write: instead of committing a batch of N writes,
we do N commits containing one page each. In some extreme cases this
can result in msync() being ~700 times slower than it should be, as well
as very inefficient use of ZIL resources.
This patch fixes this issue by making sure that the requested writes
are batched and then committed only once. Unfortunately, the
implementation is somewhat non-trivial because there is no way to run
write_cache_pages in SYNC mode (so that we get all pages) without
making it wait on the writeback tag for each page.
The solution implemented here is composed of two parts:
- I added a new callback system to the ZIL, which allows the caller to
be notified when its ITX gets written to stable storage. One nice
thing is that the callback is called not only in zil_commit() but
in zil_sync() as well, which means that the caller doesn't have to
care whether the write ended up in the ZIL or the DMU: it will get
notified as soon as it's safe, period. This is an improvement over
dmu_tx_callback_register() that was used previously, which only
supports DMU writes. The rationale for this change is to allow
zpl_putpage() to be notified when a ZIL commit is completed without
having to block on zil_commit() itself.
- zpl_writepages() now calls write_cache_pages in non-SYNC mode, which
will prevent (1) write_cache_pages from blocking, and (2) zpl_putpage
from issuing ZIL commits. zpl_writepages() will issue the commit
itself instead of relying on zpl_putpage() to do it, thus nicely
batching the writes. Note, however, that we still have to call
write_cache_pages() again in SYNC mode because there is an edge case
documented in the implementation of write_cache_pages() whereas it
will not give us all dirty pages when running in non-SYNC mode. Thus
we need to run it at least once in SYNC mode to make sure we honor
persistency guarantees. This only happens when the pages are
modified at the same time msync() is running, which should be rare.
In most cases there won't be any additional pages and this second
call will do nothing.
Note that this change also fixes a bug related to #907 whereas calling
msync() on pages that were already handed over to the DMU in a previous
writepages() call would make msync() block until the next TXG sync
instead of returning as soon as the ZIL commit is complete. The new
callback system fixes that problem.
Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1849
Closes #907
2013-11-10 15:00:11 +00:00
|
|
|
ClearPageError(pp);
|
2011-08-02 04:28:51 +00:00
|
|
|
end_page_writeback(pp);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
2011-08-02 04:28:51 +00:00
|
|
|
* Push a page out to disk, once the page is on stable storage the
|
|
|
|
* registered commit callback will be run as notification of completion.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2011-08-02 04:28:51 +00:00
|
|
|
* IN: ip - page mapped for inode.
|
|
|
|
* pp - page to push (page is locked)
|
|
|
|
* wbc - writeback control data
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* RETURN: 0 if success
|
|
|
|
* error code if failure
|
|
|
|
*
|
2011-08-02 04:28:51 +00:00
|
|
|
* Timestamps:
|
|
|
|
* ip - ctime|mtime updated
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2011-08-02 04:28:51 +00:00
|
|
|
int
|
|
|
|
zfs_putpage(struct inode *ip, struct page *pp, struct writeback_control *wbc)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-08-02 04:28:51 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
|
|
|
loff_t offset;
|
|
|
|
loff_t pgoff;
|
2012-10-31 17:06:34 +00:00
|
|
|
unsigned int pglen;
|
|
|
|
rl_t *rl;
|
2011-08-02 04:28:51 +00:00
|
|
|
dmu_tx_t *tx;
|
|
|
|
caddr_t va;
|
|
|
|
int err = 0;
|
|
|
|
uint64_t mtime[2], ctime[2];
|
|
|
|
sa_bulk_attr_t bulk[3];
|
|
|
|
int cnt = 0;
|
|
|
|
|
2012-10-31 17:06:34 +00:00
|
|
|
ZFS_ENTER(zsb);
|
|
|
|
ZFS_VERIFY_ZP(zp);
|
2009-02-18 20:51:31 +00:00
|
|
|
|
2011-08-02 04:28:51 +00:00
|
|
|
ASSERT(PageLocked(pp));
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
pgoff = page_offset(pp); /* Page byte-offset in file */
|
|
|
|
offset = i_size_read(ip); /* File length in bytes */
|
|
|
|
pglen = MIN(PAGE_CACHE_SIZE, /* Page length in bytes */
|
2011-08-02 04:28:51 +00:00
|
|
|
P2ROUNDUP(offset, PAGE_CACHE_SIZE)-pgoff);
|
|
|
|
|
|
|
|
/* Page is beyond end of file */
|
|
|
|
if (pgoff >= offset) {
|
|
|
|
unlock_page(pp);
|
2012-10-31 17:06:34 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2011-08-02 04:28:51 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Truncate page length to end of file */
|
|
|
|
if (pgoff + pglen > offset)
|
|
|
|
pglen = offset - pgoff;
|
|
|
|
|
|
|
|
#if 0
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
2011-08-02 04:28:51 +00:00
|
|
|
* FIXME: Allow mmap writes past its quota. The correct fix
|
|
|
|
* is to register a page_mkwrite() handler to count the page
|
|
|
|
* against its quota when it is about to be dirtied.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2011-05-28 01:53:07 +00:00
|
|
|
if (zfs_owner_overquota(zsb, zp, B_FALSE) ||
|
|
|
|
zfs_owner_overquota(zsb, zp, B_TRUE)) {
|
2009-07-02 22:44:48 +00:00
|
|
|
err = EDQUOT;
|
|
|
|
}
|
2011-08-02 04:28:51 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-07 00:54:57 +00:00
|
|
|
/*
|
|
|
|
* The ordering here is critical and must adhere to the following
|
|
|
|
* rules in order to avoid deadlocking in either zfs_read() or
|
|
|
|
* zfs_free_range() due to a lock inversion.
|
|
|
|
*
|
|
|
|
* 1) The page must be unlocked prior to acquiring the range lock.
|
|
|
|
* This is critical because zfs_read() calls find_lock_page()
|
|
|
|
* which may block on the page lock while holding the range lock.
|
|
|
|
*
|
|
|
|
* 2) Before setting or clearing write back on a page the range lock
|
|
|
|
* must be held in order to prevent a lock inversion with the
|
|
|
|
* zfs_free_range() function.
|
|
|
|
*/
|
|
|
|
unlock_page(pp);
|
2014-12-19 20:57:54 +00:00
|
|
|
rl = zfs_range_lock(zp, pgoff, pglen, RL_WRITER);
|
2011-08-02 04:28:51 +00:00
|
|
|
set_page_writeback(pp);
|
|
|
|
|
2011-05-28 01:53:07 +00:00
|
|
|
tx = dmu_tx_create(zsb->z_os);
|
2011-08-02 04:28:51 +00:00
|
|
|
dmu_tx_hold_write(tx, zp->z_id, pgoff, pglen);
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
|
|
|
|
zfs_sa_upgrade_txholds(tx, zp);
|
2015-01-07 00:54:57 +00:00
|
|
|
|
2009-01-15 21:59:39 +00:00
|
|
|
err = dmu_tx_assign(tx, TXG_NOWAIT);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err != 0) {
|
2011-08-02 04:28:51 +00:00
|
|
|
if (err == ERESTART)
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_wait(tx);
|
2011-08-02 04:28:51 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_tx_abort(tx);
|
Only commit the ZIL once in zpl_writepages() (msync() case).
Currently, using msync() results in the following code path:
sys_msync -> zpl_fsync -> filemap_write_and_wait_range -> zpl_writepages -> write_cache_pages -> zpl_putpage
In such a code path, zil_commit() is called as part of zpl_putpage().
This means that for each page, the write is handed to the DMU, the ZIL
is committed, and only then do we move on to the next page. As one might
imagine, this results in atrocious performance where there is a large
number of pages to write: instead of committing a batch of N writes,
we do N commits containing one page each. In some extreme cases this
can result in msync() being ~700 times slower than it should be, as well
as very inefficient use of ZIL resources.
This patch fixes this issue by making sure that the requested writes
are batched and then committed only once. Unfortunately, the
implementation is somewhat non-trivial because there is no way to run
write_cache_pages in SYNC mode (so that we get all pages) without
making it wait on the writeback tag for each page.
The solution implemented here is composed of two parts:
- I added a new callback system to the ZIL, which allows the caller to
be notified when its ITX gets written to stable storage. One nice
thing is that the callback is called not only in zil_commit() but
in zil_sync() as well, which means that the caller doesn't have to
care whether the write ended up in the ZIL or the DMU: it will get
notified as soon as it's safe, period. This is an improvement over
dmu_tx_callback_register() that was used previously, which only
supports DMU writes. The rationale for this change is to allow
zpl_putpage() to be notified when a ZIL commit is completed without
having to block on zil_commit() itself.
- zpl_writepages() now calls write_cache_pages in non-SYNC mode, which
will prevent (1) write_cache_pages from blocking, and (2) zpl_putpage
from issuing ZIL commits. zpl_writepages() will issue the commit
itself instead of relying on zpl_putpage() to do it, thus nicely
batching the writes. Note, however, that we still have to call
write_cache_pages() again in SYNC mode because there is an edge case
documented in the implementation of write_cache_pages() whereas it
will not give us all dirty pages when running in non-SYNC mode. Thus
we need to run it at least once in SYNC mode to make sure we honor
persistency guarantees. This only happens when the pages are
modified at the same time msync() is running, which should be rare.
In most cases there won't be any additional pages and this second
call will do nothing.
Note that this change also fixes a bug related to #907 whereas calling
msync() on pages that were already handed over to the DMU in a previous
writepages() call would make msync() block until the next TXG sync
instead of returning as soon as the ZIL commit is complete. The new
callback system fixes that problem.
Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1849
Closes #907
2013-11-10 15:00:11 +00:00
|
|
|
__set_page_dirty_nobuffers(pp);
|
|
|
|
ClearPageError(pp);
|
|
|
|
end_page_writeback(pp);
|
2012-10-31 17:06:34 +00:00
|
|
|
zfs_range_unlock(rl);
|
|
|
|
ZFS_EXIT(zsb);
|
2011-08-02 04:28:51 +00:00
|
|
|
return (err);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-05-28 01:53:07 +00:00
|
|
|
va = kmap(pp);
|
2011-08-02 04:28:51 +00:00
|
|
|
ASSERT3U(pglen, <=, PAGE_CACHE_SIZE);
|
|
|
|
dmu_write(zsb->z_os, zp->z_id, pgoff, pglen, va, tx);
|
2011-05-28 01:53:07 +00:00
|
|
|
kunmap(pp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-08-02 04:28:51 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(zsb), NULL, &mtime, 16);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(zsb), NULL, &ctime, 16);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(zsb), NULL, &zp->z_pflags, 8);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2012-12-04 20:11:02 +00:00
|
|
|
/* Preserve the mtime and ctime provided by the inode */
|
|
|
|
ZFS_TIME_ENCODE(&ip->i_mtime, mtime);
|
|
|
|
ZFS_TIME_ENCODE(&ip->i_ctime, ctime);
|
|
|
|
zp->z_atime_dirty = 0;
|
|
|
|
zp->z_seq++;
|
|
|
|
|
|
|
|
err = sa_bulk_update(zp->z_sa_hdl, bulk, cnt, tx);
|
|
|
|
|
Only commit the ZIL once in zpl_writepages() (msync() case).
Currently, using msync() results in the following code path:
sys_msync -> zpl_fsync -> filemap_write_and_wait_range -> zpl_writepages -> write_cache_pages -> zpl_putpage
In such a code path, zil_commit() is called as part of zpl_putpage().
This means that for each page, the write is handed to the DMU, the ZIL
is committed, and only then do we move on to the next page. As one might
imagine, this results in atrocious performance where there is a large
number of pages to write: instead of committing a batch of N writes,
we do N commits containing one page each. In some extreme cases this
can result in msync() being ~700 times slower than it should be, as well
as very inefficient use of ZIL resources.
This patch fixes this issue by making sure that the requested writes
are batched and then committed only once. Unfortunately, the
implementation is somewhat non-trivial because there is no way to run
write_cache_pages in SYNC mode (so that we get all pages) without
making it wait on the writeback tag for each page.
The solution implemented here is composed of two parts:
- I added a new callback system to the ZIL, which allows the caller to
be notified when its ITX gets written to stable storage. One nice
thing is that the callback is called not only in zil_commit() but
in zil_sync() as well, which means that the caller doesn't have to
care whether the write ended up in the ZIL or the DMU: it will get
notified as soon as it's safe, period. This is an improvement over
dmu_tx_callback_register() that was used previously, which only
supports DMU writes. The rationale for this change is to allow
zpl_putpage() to be notified when a ZIL commit is completed without
having to block on zil_commit() itself.
- zpl_writepages() now calls write_cache_pages in non-SYNC mode, which
will prevent (1) write_cache_pages from blocking, and (2) zpl_putpage
from issuing ZIL commits. zpl_writepages() will issue the commit
itself instead of relying on zpl_putpage() to do it, thus nicely
batching the writes. Note, however, that we still have to call
write_cache_pages() again in SYNC mode because there is an edge case
documented in the implementation of write_cache_pages() whereas it
will not give us all dirty pages when running in non-SYNC mode. Thus
we need to run it at least once in SYNC mode to make sure we honor
persistency guarantees. This only happens when the pages are
modified at the same time msync() is running, which should be rare.
In most cases there won't be any additional pages and this second
call will do nothing.
Note that this change also fixes a bug related to #907 whereas calling
msync() on pages that were already handed over to the DMU in a previous
writepages() call would make msync() block until the next TXG sync
instead of returning as soon as the ZIL commit is complete. The new
callback system fixes that problem.
Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1849
Closes #907
2013-11-10 15:00:11 +00:00
|
|
|
zfs_log_write(zsb->z_log, tx, TX_WRITE, zp, pgoff, pglen, 0,
|
|
|
|
zfs_putpage_commit_cb, pp);
|
2009-08-18 18:43:27 +00:00
|
|
|
dmu_tx_commit(tx);
|
2012-12-04 20:11:02 +00:00
|
|
|
|
2012-10-31 17:06:34 +00:00
|
|
|
zfs_range_unlock(rl);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
Only commit the ZIL once in zpl_writepages() (msync() case).
Currently, using msync() results in the following code path:
sys_msync -> zpl_fsync -> filemap_write_and_wait_range -> zpl_writepages -> write_cache_pages -> zpl_putpage
In such a code path, zil_commit() is called as part of zpl_putpage().
This means that for each page, the write is handed to the DMU, the ZIL
is committed, and only then do we move on to the next page. As one might
imagine, this results in atrocious performance where there is a large
number of pages to write: instead of committing a batch of N writes,
we do N commits containing one page each. In some extreme cases this
can result in msync() being ~700 times slower than it should be, as well
as very inefficient use of ZIL resources.
This patch fixes this issue by making sure that the requested writes
are batched and then committed only once. Unfortunately, the
implementation is somewhat non-trivial because there is no way to run
write_cache_pages in SYNC mode (so that we get all pages) without
making it wait on the writeback tag for each page.
The solution implemented here is composed of two parts:
- I added a new callback system to the ZIL, which allows the caller to
be notified when its ITX gets written to stable storage. One nice
thing is that the callback is called not only in zil_commit() but
in zil_sync() as well, which means that the caller doesn't have to
care whether the write ended up in the ZIL or the DMU: it will get
notified as soon as it's safe, period. This is an improvement over
dmu_tx_callback_register() that was used previously, which only
supports DMU writes. The rationale for this change is to allow
zpl_putpage() to be notified when a ZIL commit is completed without
having to block on zil_commit() itself.
- zpl_writepages() now calls write_cache_pages in non-SYNC mode, which
will prevent (1) write_cache_pages from blocking, and (2) zpl_putpage
from issuing ZIL commits. zpl_writepages() will issue the commit
itself instead of relying on zpl_putpage() to do it, thus nicely
batching the writes. Note, however, that we still have to call
write_cache_pages() again in SYNC mode because there is an edge case
documented in the implementation of write_cache_pages() whereas it
will not give us all dirty pages when running in non-SYNC mode. Thus
we need to run it at least once in SYNC mode to make sure we honor
persistency guarantees. This only happens when the pages are
modified at the same time msync() is running, which should be rare.
In most cases there won't be any additional pages and this second
call will do nothing.
Note that this change also fixes a bug related to #907 whereas calling
msync() on pages that were already handed over to the DMU in a previous
writepages() call would make msync() block until the next TXG sync
instead of returning as soon as the ZIL commit is complete. The new
callback system fixes that problem.
Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1849
Closes #907
2013-11-10 15:00:11 +00:00
|
|
|
if (wbc->sync_mode != WB_SYNC_NONE) {
|
|
|
|
/*
|
|
|
|
* Note that this is rarely called under writepages(), because
|
|
|
|
* writepages() normally handles the entire commit for
|
|
|
|
* performance reasons.
|
|
|
|
*/
|
2014-07-15 20:29:57 +00:00
|
|
|
if (zsb->z_log != NULL)
|
|
|
|
zil_commit(zsb->z_log, zp->z_id);
|
2012-08-29 18:52:47 +00:00
|
|
|
}
|
2011-08-02 04:28:51 +00:00
|
|
|
|
2012-10-31 17:06:34 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2011-08-02 04:28:51 +00:00
|
|
|
return (err);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2012-12-12 00:58:44 +00:00
|
|
|
/*
|
|
|
|
* Update the system attributes when the inode has been dirtied. For the
|
2013-10-28 16:22:15 +00:00
|
|
|
* moment we only update the mode, atime, mtime, and ctime.
|
2012-12-12 00:58:44 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_dirty_inode(struct inode *ip, int flags)
|
|
|
|
{
|
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
|
|
|
dmu_tx_t *tx;
|
2013-10-28 16:22:15 +00:00
|
|
|
uint64_t mode, atime[2], mtime[2], ctime[2];
|
|
|
|
sa_bulk_attr_t bulk[4];
|
2012-12-12 00:58:44 +00:00
|
|
|
int error;
|
|
|
|
int cnt = 0;
|
|
|
|
|
2014-10-20 21:37:47 +00:00
|
|
|
if (zfs_is_readonly(zsb) || dmu_objset_is_snapshot(zsb->z_os))
|
|
|
|
return (0);
|
|
|
|
|
2012-12-12 00:58:44 +00:00
|
|
|
ZFS_ENTER(zsb);
|
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
|
|
|
tx = dmu_tx_create(zsb->z_os);
|
|
|
|
|
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
|
|
|
|
zfs_sa_upgrade_txholds(tx, zp);
|
|
|
|
|
|
|
|
error = dmu_tx_assign(tx, TXG_WAIT);
|
|
|
|
if (error) {
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_enter(&zp->z_lock);
|
2013-10-28 16:22:15 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MODE(zsb), NULL, &mode, 8);
|
2012-12-12 00:58:44 +00:00
|
|
|
SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(zsb), NULL, &atime, 16);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(zsb), NULL, &mtime, 16);
|
|
|
|
SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(zsb), NULL, &ctime, 16);
|
|
|
|
|
2013-10-28 16:22:15 +00:00
|
|
|
/* Preserve the mode, mtime and ctime provided by the inode */
|
2012-12-12 00:58:44 +00:00
|
|
|
ZFS_TIME_ENCODE(&ip->i_atime, atime);
|
|
|
|
ZFS_TIME_ENCODE(&ip->i_mtime, mtime);
|
|
|
|
ZFS_TIME_ENCODE(&ip->i_ctime, ctime);
|
2013-10-28 16:22:15 +00:00
|
|
|
mode = ip->i_mode;
|
|
|
|
|
|
|
|
zp->z_mode = mode;
|
2012-12-12 00:58:44 +00:00
|
|
|
zp->z_atime_dirty = 0;
|
|
|
|
|
|
|
|
error = sa_bulk_update(zp->z_sa_hdl, bulk, cnt, tx);
|
|
|
|
mutex_exit(&zp->z_lock);
|
|
|
|
|
|
|
|
dmu_tx_commit(tx);
|
|
|
|
out:
|
|
|
|
ZFS_EXIT(zsb);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(zfs_dirty_inode);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2011-02-03 18:34:05 +00:00
|
|
|
zfs_inactive(struct inode *ip)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-03 18:34:05 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
int error;
|
|
|
|
|
2011-11-11 07:15:53 +00:00
|
|
|
if (zfsctl_is_node(ip)) {
|
|
|
|
zfsctl_inode_inactive(ip);
|
|
|
|
return;
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-03 18:34:05 +00:00
|
|
|
rw_enter(&zsb->z_teardown_inactive_lock, RW_READER);
|
|
|
|
if (zp->z_sa_hdl == NULL) {
|
|
|
|
rw_exit(&zsb->z_teardown_inactive_lock);
|
|
|
|
return;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (zp->z_atime_dirty && zp->z_unlinked == 0) {
|
2011-02-03 18:34:05 +00:00
|
|
|
dmu_tx_t *tx = dmu_tx_create(zsb->z_os);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
|
|
|
|
zfs_sa_upgrade_txholds(tx, zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
error = dmu_tx_assign(tx, TXG_WAIT);
|
|
|
|
if (error) {
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
} else {
|
|
|
|
mutex_enter(&zp->z_lock);
|
2011-02-08 19:16:06 +00:00
|
|
|
(void) sa_update(zp->z_sa_hdl, SA_ZPL_ATIME(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
(void *)&zp->z_atime, sizeof (zp->z_atime), tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
zp->z_atime_dirty = 0;
|
|
|
|
mutex_exit(&zp->z_lock);
|
|
|
|
dmu_tx_commit(tx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
zfs_zinactive(zp);
|
2011-02-08 19:16:06 +00:00
|
|
|
rw_exit(&zsb->z_teardown_inactive_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_inactive);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bounds-check the seek operation.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: ip - inode seeking within
|
2008-11-20 20:01:55 +00:00
|
|
|
* ooff - old file offset
|
|
|
|
* noffp - pointer to new file offset
|
|
|
|
* ct - caller context
|
|
|
|
*
|
|
|
|
* RETURN: 0 if success
|
|
|
|
* EINVAL if new offset invalid
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2011-02-08 19:16:06 +00:00
|
|
|
int
|
2011-03-02 00:24:21 +00:00
|
|
|
zfs_seek(struct inode *ip, offset_t ooff, offset_t *noffp)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
if (S_ISDIR(ip->i_mode))
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
EXPORT_SYMBOL(zfs_seek);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
2011-05-28 01:53:07 +00:00
|
|
|
* Fill pages with data from the disk.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
static int
|
2011-05-28 01:53:07 +00:00
|
|
|
zfs_fillpage(struct inode *ip, struct page *pl[], int nr_pages)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2013-11-01 19:26:11 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
|
|
|
objset_t *os;
|
2011-05-28 01:53:07 +00:00
|
|
|
struct page *cur_pp;
|
2013-11-01 19:26:11 +00:00
|
|
|
u_offset_t io_off, total;
|
|
|
|
size_t io_len;
|
|
|
|
loff_t i_size;
|
|
|
|
unsigned page_idx;
|
|
|
|
int err;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
os = zsb->z_os;
|
2011-05-28 01:53:07 +00:00
|
|
|
io_len = nr_pages << PAGE_CACHE_SHIFT;
|
|
|
|
i_size = i_size_read(ip);
|
|
|
|
io_off = page_offset(pl[0]);
|
|
|
|
|
|
|
|
if (io_off + io_len > i_size)
|
|
|
|
io_len = i_size - io_off;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
2011-05-28 01:53:07 +00:00
|
|
|
* Iterate over list of pages and read each page individually.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2011-05-28 01:53:07 +00:00
|
|
|
page_idx = 0;
|
|
|
|
cur_pp = pl[0];
|
2008-11-20 20:01:55 +00:00
|
|
|
for (total = io_off + io_len; io_off < total; io_off += PAGESIZE) {
|
2009-02-18 20:51:31 +00:00
|
|
|
caddr_t va;
|
|
|
|
|
2011-05-28 01:53:07 +00:00
|
|
|
va = kmap(cur_pp);
|
2009-07-02 22:44:48 +00:00
|
|
|
err = dmu_read(os, zp->z_id, io_off, PAGESIZE, va,
|
|
|
|
DMU_READ_PREFETCH);
|
2011-05-28 01:53:07 +00:00
|
|
|
kunmap(cur_pp);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err) {
|
2008-12-03 20:09:06 +00:00
|
|
|
/* convert checksum errors into IO errors */
|
|
|
|
if (err == ECKSUM)
|
2013-03-08 18:41:28 +00:00
|
|
|
err = SET_ERROR(EIO);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
}
|
2011-05-28 01:53:07 +00:00
|
|
|
cur_pp = pl[++page_idx];
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2009-02-18 20:51:31 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-05-28 01:53:07 +00:00
|
|
|
* Uses zfs_fillpage to read data from the file and fill the pages.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2011-05-28 01:53:07 +00:00
|
|
|
* IN: ip - inode of file to get data from.
|
|
|
|
* pl - list of pages to read
|
|
|
|
* nr_pages - number of pages to read
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2013-06-11 17:12:34 +00:00
|
|
|
* RETURN: 0 on success, error code on failure.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Timestamps:
|
|
|
|
* vp - atime updated
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2011-05-28 01:53:07 +00:00
|
|
|
int
|
|
|
|
zfs_getpage(struct inode *ip, struct page *pl[], int nr_pages)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-05-28 01:53:07 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
|
|
|
int err;
|
2009-02-18 20:51:31 +00:00
|
|
|
|
|
|
|
if (pl == NULL)
|
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-05-28 01:53:07 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
2011-05-28 01:53:07 +00:00
|
|
|
err = zfs_fillpage(ip, pl, nr_pages);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-05-28 01:53:07 +00:00
|
|
|
if (!err)
|
|
|
|
ZFS_ACCESSTIME_STAMP(zsb, zp);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-05-28 01:53:07 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
}
|
2011-05-28 01:53:07 +00:00
|
|
|
EXPORT_SYMBOL(zfs_getpage);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
2011-07-01 18:25:07 +00:00
|
|
|
* Check ZFS specific permissions to memory map a section of a file.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2011-07-01 18:25:07 +00:00
|
|
|
* IN: ip - inode of the file to mmap
|
|
|
|
* off - file offset
|
|
|
|
* addrp - start address in memory region
|
|
|
|
* len - length of memory region
|
|
|
|
* vm_flags- address flags
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2011-07-01 18:25:07 +00:00
|
|
|
* RETURN: 0 if success
|
|
|
|
* error code if failure
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
2011-07-01 18:25:07 +00:00
|
|
|
int
|
|
|
|
zfs_map(struct inode *ip, offset_t off, caddr_t *addrp, size_t len,
|
|
|
|
unsigned long vm_flags)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-07-01 18:25:07 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-07-01 18:25:07 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
2011-07-01 18:25:07 +00:00
|
|
|
if ((vm_flags & VM_WRITE) && (zp->z_pflags &
|
2010-05-28 20:45:14 +00:00
|
|
|
(ZFS_IMMUTABLE | ZFS_READONLY | ZFS_APPENDONLY))) {
|
2011-07-01 18:25:07 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EPERM));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-07-01 18:25:07 +00:00
|
|
|
if ((vm_flags & (VM_READ | VM_EXEC)) &&
|
2010-05-28 20:45:14 +00:00
|
|
|
(zp->z_pflags & ZFS_AV_QUARANTINED)) {
|
2011-07-01 18:25:07 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EACCES));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (off < 0 || len > MAXOFFSET_T - off) {
|
2011-07-01 18:25:07 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(ENXIO));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-07-01 18:25:07 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2011-07-01 18:25:07 +00:00
|
|
|
EXPORT_SYMBOL(zfs_map);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
/*
|
|
|
|
* convoff - converts the given data (start, whence) to the
|
|
|
|
* given whence.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
convoff(struct inode *ip, flock64_t *lckdat, int whence, offset_t offset)
|
|
|
|
{
|
2011-03-01 20:24:09 +00:00
|
|
|
vattr_t vap;
|
2011-02-08 19:16:06 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
if ((lckdat->l_whence == 2) || (whence == 2)) {
|
2011-03-01 20:24:09 +00:00
|
|
|
if ((error = zfs_getattr(ip, &vap, 0, CRED()) != 0))
|
2011-02-08 19:16:06 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (lckdat->l_whence) {
|
|
|
|
case 1:
|
|
|
|
lckdat->l_start += offset;
|
|
|
|
break;
|
|
|
|
case 2:
|
2011-03-01 20:24:09 +00:00
|
|
|
lckdat->l_start += vap.va_size;
|
2011-02-08 19:16:06 +00:00
|
|
|
/* FALLTHRU */
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2011-02-08 19:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lckdat->l_start < 0)
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2011-02-08 19:16:06 +00:00
|
|
|
|
|
|
|
switch (whence) {
|
|
|
|
case 1:
|
|
|
|
lckdat->l_start -= offset;
|
|
|
|
break;
|
|
|
|
case 2:
|
2011-03-01 20:24:09 +00:00
|
|
|
lckdat->l_start -= vap.va_size;
|
2011-02-08 19:16:06 +00:00
|
|
|
/* FALLTHRU */
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2011-02-08 19:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lckdat->l_whence = (short)whence;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Free or allocate space in a file. Currently, this function only
|
|
|
|
* supports the `F_FREESP' command. However, this command is somewhat
|
|
|
|
* misnamed, as its functionality includes the ability to allocate as
|
|
|
|
* well as free space.
|
|
|
|
*
|
2011-02-08 19:16:06 +00:00
|
|
|
* IN: ip - inode of file to free data in.
|
2008-11-20 20:01:55 +00:00
|
|
|
* cmd - action to take (only F_FREESP supported).
|
|
|
|
* bfp - section of file to free/alloc.
|
|
|
|
* flag - current file open mode flags.
|
|
|
|
* offset - current file offset.
|
|
|
|
* cr - credentials of caller [UNUSED].
|
|
|
|
*
|
2013-06-11 17:12:34 +00:00
|
|
|
* RETURN: 0 on success, error code on failure.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Timestamps:
|
2011-02-08 19:16:06 +00:00
|
|
|
* ip - ctime|mtime updated
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_space(struct inode *ip, int cmd, flock64_t *bfp, int flag,
|
|
|
|
offset_t offset, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
uint64_t off, len;
|
|
|
|
int error;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
|
|
|
|
if (cmd != F_FREESP) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((error = convoff(ip, bfp, 0, offset))) {
|
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bfp->l_len < 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-02 07:37:53 +00:00
|
|
|
/*
|
|
|
|
* Permissions aren't checked on Solaris because on this OS
|
|
|
|
* zfs_space() can only be called with an opened file handle.
|
|
|
|
* On Linux we can get here through truncate_range() which
|
|
|
|
* operates directly on inodes, so we need to check access rights.
|
|
|
|
*/
|
|
|
|
if ((error = zfs_zaccess(zp, ACE_WRITE_DATA, 0, B_FALSE, cr))) {
|
|
|
|
ZFS_EXIT(zsb);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
off = bfp->l_start;
|
|
|
|
len = bfp->l_len; /* 0 means from off to end of file */
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
error = zfs_freesp(zp, off, len, flag, TRUE);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_space);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*ARGSUSED*/
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_fid(struct inode *ip, fid_t *fidp)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
uint32_t gen;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t gen64;
|
2008-11-20 20:01:55 +00:00
|
|
|
uint64_t object = zp->z_id;
|
|
|
|
zfid_short_t *zfid;
|
2010-05-28 20:45:14 +00:00
|
|
|
int size, i, error;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zsb),
|
2010-05-28 20:45:14 +00:00
|
|
|
&gen64, sizeof (uint64_t))) != 0) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2010-05-28 20:45:14 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
gen = (uint32_t)gen64;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
size = (zsb->z_parent != zsb) ? LONG_FID_LEN : SHORT_FID_LEN;
|
2008-11-20 20:01:55 +00:00
|
|
|
if (fidp->fid_len < size) {
|
|
|
|
fidp->fid_len = size;
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(ENOSPC));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zfid = (zfid_short_t *)fidp;
|
|
|
|
|
|
|
|
zfid->zf_len = size;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof (zfid->zf_object); i++)
|
|
|
|
zfid->zf_object[i] = (uint8_t)(object >> (8 * i));
|
|
|
|
|
|
|
|
/* Must have a non-zero generation number to distinguish from .zfs */
|
|
|
|
if (gen == 0)
|
|
|
|
gen = 1;
|
|
|
|
for (i = 0; i < sizeof (zfid->zf_gen); i++)
|
|
|
|
zfid->zf_gen[i] = (uint8_t)(gen >> (8 * i));
|
|
|
|
|
|
|
|
if (size == LONG_FID_LEN) {
|
2011-02-08 19:16:06 +00:00
|
|
|
uint64_t objsetid = dmu_objset_id(zsb->z_os);
|
2008-11-20 20:01:55 +00:00
|
|
|
zfid_long_t *zlfid;
|
|
|
|
|
|
|
|
zlfid = (zfid_long_t *)fidp;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof (zlfid->zf_setid); i++)
|
|
|
|
zlfid->zf_setid[i] = (uint8_t)(objsetid >> (8 * i));
|
|
|
|
|
|
|
|
/* XXX - this should be the generation number for the objset */
|
|
|
|
for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
|
|
|
|
zlfid->zf_setgen[i] = 0;
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_fid);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*ARGSUSED*/
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_getsecattr(struct inode *ip, vsecattr_t *vsecp, int flag, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
int error;
|
|
|
|
boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
error = zfs_getacl(zp, vsecp, skipaclchk, cr);
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_getsecattr);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*ARGSUSED*/
|
2010-12-17 19:18:08 +00:00
|
|
|
int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_setsecattr(struct inode *ip, vsecattr_t *vsecp, int flag, cred_t *cr)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
2008-11-20 20:01:55 +00:00
|
|
|
int error;
|
|
|
|
boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
|
2011-02-08 19:16:06 +00:00
|
|
|
zilog_t *zilog = zsb->z_log;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
error = zfs_setacl(zp, vsecp, skipaclchk, cr);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
|
2010-08-26 21:24:34 +00:00
|
|
|
zil_commit(zilog, 0);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2010-12-17 19:18:08 +00:00
|
|
|
EXPORT_SYMBOL(zfs_setsecattr);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
#ifdef HAVE_UIO_ZEROCOPY
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* Tunable, both must be a power of 2.
|
|
|
|
*
|
|
|
|
* zcr_blksz_min: the smallest read we may consider to loan out an arcbuf
|
|
|
|
* zcr_blksz_max: if set to less than the file block size, allow loaning out of
|
2011-02-08 19:16:06 +00:00
|
|
|
* an arcbuf for a partial block read
|
2010-05-28 20:45:14 +00:00
|
|
|
*/
|
|
|
|
int zcr_blksz_min = (1 << 10); /* 1K */
|
|
|
|
int zcr_blksz_max = (1 << 17); /* 128K */
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_reqzcbuf(struct inode *ip, enum uio_rw ioflag, xuio_t *xuio, cred_t *cr)
|
2010-05-28 20:45:14 +00:00
|
|
|
{
|
2011-02-08 19:16:06 +00:00
|
|
|
znode_t *zp = ITOZ(ip);
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
|
|
|
int max_blksz = zsb->z_max_blksz;
|
2010-05-28 20:45:14 +00:00
|
|
|
uio_t *uio = &xuio->xu_uio;
|
|
|
|
ssize_t size = uio->uio_resid;
|
|
|
|
offset_t offset = uio->uio_loffset;
|
|
|
|
int blksz;
|
|
|
|
int fullblk, i;
|
|
|
|
arc_buf_t *abuf;
|
|
|
|
ssize_t maxsize;
|
|
|
|
int preamble, postamble;
|
|
|
|
|
|
|
|
if (xuio->xu_type != UIOTYPE_ZEROCOPY)
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_ENTER(zsb);
|
2010-05-28 20:45:14 +00:00
|
|
|
ZFS_VERIFY_ZP(zp);
|
|
|
|
switch (ioflag) {
|
|
|
|
case UIO_WRITE:
|
|
|
|
/*
|
|
|
|
* Loan out an arc_buf for write if write size is bigger than
|
|
|
|
* max_blksz, and the file's block size is also max_blksz.
|
|
|
|
*/
|
|
|
|
blksz = max_blksz;
|
|
|
|
if (size < blksz || zp->z_blksz != blksz) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Caller requests buffers for write before knowing where the
|
|
|
|
* write offset might be (e.g. NFS TCP write).
|
|
|
|
*/
|
|
|
|
if (offset == -1) {
|
|
|
|
preamble = 0;
|
|
|
|
} else {
|
|
|
|
preamble = P2PHASE(offset, blksz);
|
|
|
|
if (preamble) {
|
|
|
|
preamble = blksz - preamble;
|
|
|
|
size -= preamble;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
postamble = P2PHASE(size, blksz);
|
|
|
|
size -= postamble;
|
|
|
|
|
|
|
|
fullblk = size / blksz;
|
|
|
|
(void) dmu_xuio_init(xuio,
|
|
|
|
(preamble != 0) + fullblk + (postamble != 0));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Have to fix iov base/len for partial buffers. They
|
|
|
|
* currently represent full arc_buf's.
|
|
|
|
*/
|
|
|
|
if (preamble) {
|
|
|
|
/* data begins in the middle of the arc_buf */
|
|
|
|
abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
|
|
|
|
blksz);
|
|
|
|
ASSERT(abuf);
|
|
|
|
(void) dmu_xuio_add(xuio, abuf,
|
|
|
|
blksz - preamble, preamble);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < fullblk; i++) {
|
|
|
|
abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
|
|
|
|
blksz);
|
|
|
|
ASSERT(abuf);
|
|
|
|
(void) dmu_xuio_add(xuio, abuf, 0, blksz);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (postamble) {
|
|
|
|
/* data ends in the middle of the arc_buf */
|
|
|
|
abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
|
|
|
|
blksz);
|
|
|
|
ASSERT(abuf);
|
|
|
|
(void) dmu_xuio_add(xuio, abuf, 0, postamble);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UIO_READ:
|
|
|
|
/*
|
|
|
|
* Loan out an arc_buf for read if the read size is larger than
|
|
|
|
* the current file block size. Block alignment is not
|
|
|
|
* considered. Partial arc_buf will be loaned out for read.
|
|
|
|
*/
|
|
|
|
blksz = zp->z_blksz;
|
|
|
|
if (blksz < zcr_blksz_min)
|
|
|
|
blksz = zcr_blksz_min;
|
|
|
|
if (blksz > zcr_blksz_max)
|
|
|
|
blksz = zcr_blksz_max;
|
|
|
|
/* avoid potential complexity of dealing with it */
|
|
|
|
if (blksz > max_blksz) {
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
maxsize = zp->z_size - uio->uio_loffset;
|
|
|
|
if (size > maxsize)
|
|
|
|
size = maxsize;
|
|
|
|
|
2011-02-08 19:16:06 +00:00
|
|
|
if (size < blksz) {
|
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2013-03-08 18:41:28 +00:00
|
|
|
return (SET_ERROR(EINVAL));
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uio->uio_extflg = UIO_XUIO;
|
|
|
|
XUIO_XUZC_RW(xuio) = ioflag;
|
2011-02-08 19:16:06 +00:00
|
|
|
ZFS_EXIT(zsb);
|
2010-05-28 20:45:14 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static int
|
2011-02-08 19:16:06 +00:00
|
|
|
zfs_retzcbuf(struct inode *ip, xuio_t *xuio, cred_t *cr)
|
2010-05-28 20:45:14 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
arc_buf_t *abuf;
|
|
|
|
int ioflag = XUIO_XUZC_RW(xuio);
|
|
|
|
|
|
|
|
ASSERT(xuio->xu_type == UIOTYPE_ZEROCOPY);
|
|
|
|
|
|
|
|
i = dmu_xuio_cnt(xuio);
|
|
|
|
while (i-- > 0) {
|
|
|
|
abuf = dmu_xuio_arcbuf(xuio, i);
|
|
|
|
/*
|
|
|
|
* if abuf == NULL, it must be a write buffer
|
|
|
|
* that has been returned in zfs_write().
|
|
|
|
*/
|
|
|
|
if (abuf)
|
|
|
|
dmu_return_arcbuf(abuf);
|
|
|
|
ASSERT(abuf || ioflag == UIO_WRITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
dmu_xuio_fini(xuio);
|
|
|
|
return (0);
|
|
|
|
}
|
2011-02-08 19:16:06 +00:00
|
|
|
#endif /* HAVE_UIO_ZEROCOPY */
|
2011-05-03 22:09:28 +00:00
|
|
|
|
|
|
|
#if defined(_KERNEL) && defined(HAVE_SPL)
|
|
|
|
module_param(zfs_read_chunk_size, long, 0644);
|
|
|
|
MODULE_PARM_DESC(zfs_read_chunk_size, "Bytes to read per chunk");
|
|
|
|
#endif
|