summaryrefslogtreecommitdiffstats
path: root/module/zfs
diff options
context:
space:
mode:
authorMatthew Macy <[email protected]>2019-11-21 09:32:57 -0800
committerBrian Behlendorf <[email protected]>2019-11-21 09:32:57 -0800
commitda92d5cbb38cea3a860b8a6bb8ee21f9129e7d7c (patch)
treecc2d84b481a30b43d4097603e79a55a1975b0b64 /module/zfs
parent67a6c3bc9ff401fa04bc41354c5172b51aaed1c9 (diff)
Add zfs_file_* interface, remove vnodes
Provide a common zfs_file_* interface which can be implemented on all platforms to perform normal file access from either the kernel module or the libzpool library. This allows all non-portable vnode_t usage in the common code to be replaced by the new portable zfs_file_t. The associated vnode and kobj compatibility functions, types, and macros have been removed from the SPL. Moving forward, vnodes should only be used in platform specific code when provided by the native operating system. Reviewed-by: Sean Eric Fagan <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Igor Kozhukhov <[email protected]> Reviewed-by: Jorgen Lundman <[email protected]> Signed-off-by: Matt Macy <[email protected]> Closes #9556
Diffstat (limited to 'module/zfs')
-rw-r--r--module/zfs/arc.c4
-rw-r--r--module/zfs/dmu_diff.c33
-rw-r--r--module/zfs/dmu_recv.c16
-rw-r--r--module/zfs/dsl_crypt.c2
-rw-r--r--module/zfs/fm.c3
-rw-r--r--module/zfs/spa.c21
-rw-r--r--module/zfs/spa_config.c84
-rw-r--r--module/zfs/spa_misc.c14
-rw-r--r--module/zfs/vdev_label.c2
-rw-r--r--module/zfs/zfs_ioctl.c89
-rw-r--r--module/zfs/zfs_log.c5
-rw-r--r--module/zfs/zfs_replay.c4
12 files changed, 126 insertions, 151 deletions
diff --git a/module/zfs/arc.c b/module/zfs/arc.c
index 6ed2a220d..87df07cc0 100644
--- a/module/zfs/arc.c
+++ b/module/zfs/arc.c
@@ -8666,7 +8666,7 @@ l2arc_fini(void)
void
l2arc_start(void)
{
- if (!(spa_mode_global & FWRITE))
+ if (!(spa_mode_global & SPA_MODE_WRITE))
return;
(void) thread_create(NULL, 0, l2arc_feed_thread, NULL, 0, &p0,
@@ -8676,7 +8676,7 @@ l2arc_start(void)
void
l2arc_stop(void)
{
- if (!(spa_mode_global & FWRITE))
+ if (!(spa_mode_global & SPA_MODE_WRITE))
return;
mutex_enter(&l2arc_feed_thr_lock);
diff --git a/module/zfs/dmu_diff.c b/module/zfs/dmu_diff.c
index c40ed57f2..e08cf21ab 100644
--- a/module/zfs/dmu_diff.c
+++ b/module/zfs/dmu_diff.c
@@ -40,33 +40,36 @@
#include <sys/zap.h>
#include <sys/zio_checksum.h>
#include <sys/zfs_znode.h>
+#include <sys/zfs_file.h>
-struct diffarg {
- struct vnode *da_vp; /* file to which we are reporting */
+
+typedef struct dmu_diffarg {
+ zfs_file_t *da_fp; /* file to which we are reporting */
offset_t *da_offp;
int da_err; /* error that stopped diff search */
dmu_diff_record_t da_ddr;
-};
+} dmu_diffarg_t;
-static int
-write_record(struct diffarg *da)
+int
+write_record(dmu_diffarg_t *da)
{
- ssize_t resid; /* have to get resid to get detailed errno */
+ zfs_file_t *fp;
+ ssize_t resid;
if (da->da_ddr.ddr_type == DDR_NONE) {
da->da_err = 0;
return (0);
}
- da->da_err = vn_rdwr(UIO_WRITE, da->da_vp, (caddr_t)&da->da_ddr,
- sizeof (da->da_ddr), 0, UIO_SYSSPACE, FAPPEND,
- RLIM64_INFINITY, CRED(), &resid);
+ fp = da->da_fp;
+ da->da_err = zfs_file_write(fp, (caddr_t)&da->da_ddr,
+ sizeof (da->da_ddr), &resid);
*da->da_offp += sizeof (da->da_ddr);
return (da->da_err);
}
static int
-report_free_dnode_range(struct diffarg *da, uint64_t first, uint64_t last)
+report_free_dnode_range(dmu_diffarg_t *da, uint64_t first, uint64_t last)
{
ASSERT(first <= last);
if (da->da_ddr.ddr_type != DDR_FREE ||
@@ -83,7 +86,7 @@ report_free_dnode_range(struct diffarg *da, uint64_t first, uint64_t last)
}
static int
-report_dnode(struct diffarg *da, uint64_t object, dnode_phys_t *dnp)
+report_dnode(dmu_diffarg_t *da, uint64_t object, dnode_phys_t *dnp)
{
ASSERT(dnp != NULL);
if (dnp->dn_type == DMU_OT_NONE)
@@ -110,7 +113,7 @@ static int
diff_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
const zbookmark_phys_t *zb, const dnode_phys_t *dnp, void *arg)
{
- struct diffarg *da = arg;
+ dmu_diffarg_t *da = arg;
int err = 0;
if (issig(JUSTLOOKING) && issig(FORREAL))
@@ -162,9 +165,9 @@ diff_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
int
dmu_diff(const char *tosnap_name, const char *fromsnap_name,
- struct vnode *vp, offset_t *offp)
+ zfs_file_t *fp, offset_t *offp)
{
- struct diffarg da;
+ dmu_diffarg_t da;
dsl_dataset_t *fromsnap;
dsl_dataset_t *tosnap;
dsl_pool_t *dp;
@@ -205,7 +208,7 @@ dmu_diff(const char *tosnap_name, const char *fromsnap_name,
dsl_dataset_long_hold(tosnap, FTAG);
dsl_pool_rele(dp, FTAG);
- da.da_vp = vp;
+ da.da_fp = fp;
da.da_offp = offp;
da.da_ddr.ddr_type = DDR_NONE;
da.da_ddr.ddr_first = da.da_ddr.ddr_last = 0;
diff --git a/module/zfs/dmu_recv.c b/module/zfs/dmu_recv.c
index 48c3705c6..f68419bfa 100644
--- a/module/zfs/dmu_recv.c
+++ b/module/zfs/dmu_recv.c
@@ -61,6 +61,7 @@
#ifdef _KERNEL
#include <sys/zfs_vfsops.h>
#endif
+#include <sys/zfs_file.h>
int zfs_recv_queue_length = SPA_MAXBLOCKSIZE;
int zfs_recv_queue_ff = 20;
@@ -1103,8 +1104,8 @@ dmu_recv_resume_begin_sync(void *arg, dmu_tx_t *tx)
int
dmu_recv_begin(char *tofs, char *tosnap, dmu_replay_record_t *drr_begin,
boolean_t force, boolean_t resumable, nvlist_t *localprops,
- nvlist_t *hidden_args, char *origin, dmu_recv_cookie_t *drc, vnode_t *vp,
- offset_t *voffp)
+ nvlist_t *hidden_args, char *origin, dmu_recv_cookie_t *drc,
+ zfs_file_t *fp, offset_t *voffp)
{
dmu_recv_begin_arg_t drba = { 0 };
int err;
@@ -1131,7 +1132,7 @@ dmu_recv_begin(char *tofs, char *tosnap, dmu_replay_record_t *drr_begin,
return (SET_ERROR(EINVAL));
}
- drc->drc_vp = vp;
+ drc->drc_fp = fp;
drc->drc_voff = *voffp;
drc->drc_featureflags =
DMU_GET_FEATUREFLAGS(drc->drc_drrb->drr_versioninfo);
@@ -1248,12 +1249,11 @@ receive_read(dmu_recv_cookie_t *drc, int len, void *buf)
while (done < len) {
ssize_t resid;
+ zfs_file_t *fp;
- drc->drc_err = vn_rdwr(UIO_READ, drc->drc_vp,
- (char *)buf + done, len - done,
- drc->drc_voff, UIO_SYSSPACE, FAPPEND,
- RLIM64_INFINITY, CRED(), &resid);
-
+ fp = drc->drc_fp;
+ drc->drc_err = zfs_file_read(fp, (char *)buf + done,
+ len - done, &resid);
if (resid == len - done) {
/*
* Note: ECKSUM indicates that the receive
diff --git a/module/zfs/dsl_crypt.c b/module/zfs/dsl_crypt.c
index 162a3613c..96a402ffa 100644
--- a/module/zfs/dsl_crypt.c
+++ b/module/zfs/dsl_crypt.c
@@ -921,7 +921,7 @@ spa_keystore_unload_wkey(const char *dsname)
* Wait for any outstanding txg IO to complete, releasing any
* remaining references on the wkey.
*/
- if (spa_mode(spa) != FREAD)
+ if (spa_mode(spa) != SPA_MODE_READ)
txg_wait_synced(spa->spa_dsl_pool, 0);
spa_close(spa, FTAG);
diff --git a/module/zfs/fm.c b/module/zfs/fm.c
index 722855492..e3c3a1700 100644
--- a/module/zfs/fm.c
+++ b/module/zfs/fm.c
@@ -67,7 +67,6 @@
#include <sys/atomic.h>
#include <sys/condvar.h>
#include <sys/console.h>
-#include <sys/kobj.h>
#include <sys/time.h>
#include <sys/zfs_ioctl.h>
@@ -597,7 +596,7 @@ zfs_zevent_fd_hold(int fd, minor_t *minorp, zfs_zevent_t **ze)
void
zfs_zevent_fd_rele(int fd)
{
- releasef(fd);
+ zfs_file_put(fd);
}
/*
diff --git a/module/zfs/spa.c b/module/zfs/spa.c
index 9bfd24d98..0eb4910af 100644
--- a/module/zfs/spa.c
+++ b/module/zfs/spa.c
@@ -319,7 +319,7 @@ spa_prop_get_config(spa_t *spa, nvlist_t **nvp)
spa_prop_add_list(*nvp, ZPOOL_PROP_EXPANDSZ, NULL,
metaslab_class_expandable_space(mc), src);
spa_prop_add_list(*nvp, ZPOOL_PROP_READONLY, NULL,
- (spa_mode(spa) == FREAD), src);
+ (spa_mode(spa) == SPA_MODE_READ), src);
cap = (size == 0) ? 0 : (alloc * 100 / size);
spa_prop_add_list(*nvp, ZPOOL_PROP_CAPACITY, NULL, cap, src);
@@ -1196,7 +1196,7 @@ spa_thread(void *arg)
* Activate an uninitialized pool.
*/
static void
-spa_activate(spa_t *spa, int mode)
+spa_activate(spa_t *spa, spa_mode_t mode)
{
ASSERT(spa->spa_state == POOL_STATE_UNINITIALIZED);
@@ -3362,7 +3362,7 @@ spa_ld_open_vdevs(spa_t *spa)
if (spa->spa_missing_tvds != 0) {
spa_load_note(spa, "vdev tree has %lld missing top-level "
"vdevs.", (u_longlong_t)spa->spa_missing_tvds);
- if (spa->spa_trust_config && (spa->spa_mode & FWRITE)) {
+ if (spa->spa_trust_config && (spa->spa_mode & SPA_MODE_WRITE)) {
/*
* Although theoretically we could allow users to open
* incomplete pools in RW mode, we'd need to add a lot
@@ -4358,7 +4358,7 @@ spa_ld_check_for_config_update(spa_t *spa, uint64_t config_cache_txg,
static void
spa_ld_prepare_for_reload(spa_t *spa)
{
- int mode = spa->spa_mode;
+ spa_mode_t mode = spa->spa_mode;
int async_suspended = spa->spa_async_suspended;
spa_unload(spa);
@@ -4868,7 +4868,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, char **ereport)
static int
spa_load_retry(spa_t *spa, spa_load_state_t state)
{
- int mode = spa->spa_mode;
+ spa_mode_t mode = spa->spa_mode;
spa_unload(spa);
spa_deactivate(spa);
@@ -5915,7 +5915,7 @@ spa_import(char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags)
char *altroot = NULL;
spa_load_state_t state = SPA_LOAD_IMPORT;
zpool_load_policy_t policy;
- uint64_t mode = spa_mode_global;
+ spa_mode_t mode = spa_mode_global;
uint64_t readonly = B_FALSE;
int error;
nvlist_t *nvroot;
@@ -5939,7 +5939,7 @@ spa_import(char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags)
(void) nvlist_lookup_uint64(props,
zpool_prop_to_name(ZPOOL_PROP_READONLY), &readonly);
if (readonly)
- mode = FREAD;
+ mode = SPA_MODE_READ;
spa = spa_add(pool, config, altroot);
spa->spa_import_flags = flags;
@@ -6109,7 +6109,7 @@ spa_tryimport(nvlist_t *tryconfig)
*/
mutex_enter(&spa_namespace_lock);
spa = spa_add(TRYIMPORT_NAME, tryconfig, NULL);
- spa_activate(spa, FREAD);
+ spa_activate(spa, SPA_MODE_READ);
/*
* Rewind pool if a max txg was provided.
@@ -6219,7 +6219,7 @@ spa_export_common(char *pool, int new_state, nvlist_t **oldconfig,
if (oldconfig)
*oldconfig = NULL;
- if (!(spa_mode_global & FWRITE))
+ if (!(spa_mode_global & SPA_MODE_WRITE))
return (SET_ERROR(EROFS));
mutex_enter(&spa_namespace_lock);
@@ -8073,8 +8073,7 @@ spa_async_dispatch(spa_t *spa)
mutex_enter(&spa->spa_async_lock);
if (spa_async_tasks_pending(spa) &&
!spa->spa_async_suspended &&
- spa->spa_async_thread == NULL &&
- rootdir != NULL)
+ spa->spa_async_thread == NULL)
spa->spa_async_thread = thread_create(NULL, 0,
spa_async_thread, spa, 0, &p0, TS_RUN, maxclsyspri);
mutex_exit(&spa->spa_async_lock);
diff --git a/module/zfs/spa_config.c b/module/zfs/spa_config.c
index de1ad21da..3a65b0bb4 100644
--- a/module/zfs/spa_config.c
+++ b/module/zfs/spa_config.c
@@ -37,8 +37,8 @@
#include <sys/systeminfo.h>
#include <sys/sunddi.h>
#include <sys/zfeature.h>
+#include <sys/zfs_file.h>
#ifdef _KERNEL
-#include <sys/kobj.h>
#include <sys/zone.h>
#endif
@@ -80,8 +80,10 @@ spa_config_load(void)
nvlist_t *nvlist, *child;
nvpair_t *nvpair;
char *pathname;
- struct _buf *file;
+ zfs_file_t *fp;
+ zfs_file_attr_t zfa;
uint64_t fsize;
+ int err;
#ifdef _KERNEL
if (zfs_autoimport_disable)
@@ -95,22 +97,23 @@ spa_config_load(void)
(void) snprintf(pathname, MAXPATHLEN, "%s", spa_config_path);
- file = kobj_open_file(pathname);
+ err = zfs_file_open(pathname, O_RDONLY, 0, &fp);
kmem_free(pathname, MAXPATHLEN);
- if (file == (struct _buf *)-1)
+ if (err)
return;
- if (kobj_get_filesize(file, &fsize) != 0)
+ if (zfs_file_getattr(fp, &zfa))
goto out;
+ fsize = zfa.zfa_size;
buf = kmem_alloc(fsize, KM_SLEEP);
/*
* Read the nvlist from the file.
*/
- if (kobj_read_file(file, buf, fsize, 0) < 0)
+ if (zfs_file_read(fp, buf, fsize, NULL) < 0)
goto out;
/*
@@ -143,27 +146,32 @@ out:
if (buf != NULL)
kmem_free(buf, fsize);
- kobj_close_file(file);
+ zfs_file_close(fp);
}
static int
spa_config_remove(spa_config_dirent_t *dp)
{
-#if defined(__linux__) && defined(_KERNEL)
- int error, flags = FWRITE | FTRUNC;
- uio_seg_t seg = UIO_SYSSPACE;
- vnode_t *vp;
-
- error = vn_open(dp->scd_path, seg, flags, 0644, &vp, 0, 0);
- if (error == 0) {
- (void) VOP_FSYNC(vp, FSYNC, kcred, NULL);
- (void) VOP_CLOSE(vp, 0, 1, 0, kcred, NULL);
+ int error = 0;
+
+ /*
+ * Remove the cache file. If zfs_file_unlink() in not supported by the
+ * platform fallback to truncating the file which is functionally
+ * equivalent.
+ */
+ error = zfs_file_unlink(dp->scd_path);
+ if (error == EOPNOTSUPP) {
+ int flags = O_RDWR | O_TRUNC;
+ zfs_file_t *fp;
+
+ error = zfs_file_open(dp->scd_path, flags, 0644, &fp);
+ if (error == 0) {
+ (void) zfs_file_fsync(fp, O_SYNC);
+ (void) zfs_file_close(fp);
+ }
}
return (error);
-#else
- return (vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE));
-#endif
}
static int
@@ -171,10 +179,10 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
{
size_t buflen;
char *buf;
- vnode_t *vp;
- int oflags = FWRITE | FTRUNC | FCREAT | FOFFMAX;
+ int oflags = O_RDWR | O_TRUNC | O_CREAT | O_LARGEFILE;
char *temp;
int err;
+ zfs_file_t *fp;
/*
* If the nvlist is empty (NULL), then remove the old cachefile.
@@ -193,46 +201,22 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
buf = fnvlist_pack(nvl, &buflen);
temp = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
-#if defined(__linux__) && defined(_KERNEL)
/*
* Write the configuration to disk. Due to the complexity involved
* in performing a rename and remove from within the kernel the file
* is instead truncated and overwritten in place. This way we always
* have a consistent view of the data or a zero length file.
*/
- err = vn_open(dp->scd_path, UIO_SYSSPACE, oflags, 0644, &vp, 0, 0);
+ err = zfs_file_open(dp->scd_path, oflags, 0644, &fp);
if (err == 0) {
- err = vn_rdwr(UIO_WRITE, vp, buf, buflen, 0,
- UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, NULL);
+ err = zfs_file_write(fp, buf, buflen, NULL);
if (err == 0)
- err = VOP_FSYNC(vp, FSYNC, kcred, NULL);
+ err = zfs_file_fsync(fp, O_SYNC);
- (void) VOP_CLOSE(vp, oflags, 1, 0, kcred, NULL);
+ zfs_file_close(fp);
if (err)
(void) spa_config_remove(dp);
}
-#else
- /*
- * Write the configuration to disk. We need to do the traditional
- * 'write to temporary file, sync, move over original' to make sure we
- * always have a consistent view of the data.
- */
- (void) snprintf(temp, MAXPATHLEN, "%s.tmp", dp->scd_path);
-
- err = vn_open(temp, UIO_SYSSPACE, oflags, 0644, &vp, CRCREAT, 0);
- if (err == 0) {
- err = vn_rdwr(UIO_WRITE, vp, buf, buflen, 0, UIO_SYSSPACE,
- 0, RLIM64_INFINITY, kcred, NULL);
- if (err == 0)
- err = VOP_FSYNC(vp, FSYNC, kcred, NULL);
- if (err == 0)
- err = vn_rename(temp, dp->scd_path, UIO_SYSSPACE);
- (void) VOP_CLOSE(vp, oflags, 1, 0, kcred, NULL);
- }
-
- (void) vn_remove(temp, UIO_SYSSPACE, RMFILE);
-#endif
-
fnvlist_pack_free(buf, buflen);
kmem_free(temp, MAXPATHLEN);
return (err);
@@ -258,7 +242,7 @@ spa_write_cachefile(spa_t *target, boolean_t removing, boolean_t postsysevent)
ASSERT(MUTEX_HELD(&spa_namespace_lock));
- if (rootdir == NULL || !(spa_mode_global & FWRITE))
+ if (!(spa_mode_global & SPA_MODE_WRITE))
return;
/*
diff --git a/module/zfs/spa_misc.c b/module/zfs/spa_misc.c
index 5dd11f6a3..d49c92e20 100644
--- a/module/zfs/spa_misc.c
+++ b/module/zfs/spa_misc.c
@@ -242,7 +242,7 @@ static kmutex_t spa_l2cache_lock;
static avl_tree_t spa_l2cache_avl;
kmem_cache_t *spa_buffer_pool;
-int spa_mode_global;
+spa_mode_t spa_mode_global = SPA_MODE_UNINIT;
#ifdef ZFS_DEBUG
/*
@@ -2282,7 +2282,7 @@ spa_boot_init(void)
}
void
-spa_init(int mode)
+spa_init(spa_mode_t mode)
{
mutex_init(&spa_namespace_lock, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&spa_spare_lock, NULL, MUTEX_DEFAULT, NULL);
@@ -2301,7 +2301,7 @@ spa_init(int mode)
spa_mode_global = mode;
#ifndef _KERNEL
- if (spa_mode_global != FREAD && dprintf_find_string("watch")) {
+ if (spa_mode_global != SPA_MODE_READ && dprintf_find_string("watch")) {
struct sigaction sa;
sa.sa_flags = SA_SIGINFO;
@@ -2406,7 +2406,7 @@ spa_is_root(spa_t *spa)
boolean_t
spa_writeable(spa_t *spa)
{
- return (!!(spa->spa_mode & FWRITE) && spa->spa_trust_config);
+ return (!!(spa->spa_mode & SPA_MODE_WRITE) && spa->spa_trust_config);
}
/*
@@ -2420,7 +2420,7 @@ spa_has_pending_synctask(spa_t *spa)
!txg_all_lists_empty(&spa->spa_dsl_pool->dp_early_sync_tasks));
}
-int
+spa_mode_t
spa_mode(spa_t *spa)
{
return (spa->spa_mode);
@@ -2670,7 +2670,7 @@ boolean_t
spa_importing_readonly_checkpoint(spa_t *spa)
{
return ((spa->spa_import_flags & ZFS_IMPORT_CHECKPOINT) &&
- spa->spa_mode == FREAD);
+ spa->spa_mode == SPA_MODE_READ);
}
uint64_t
@@ -2724,7 +2724,7 @@ param_set_deadman_failmode(const char *val, zfs_kernel_param_t *kp)
strcmp(val, "panic"))
return (SET_ERROR(-EINVAL));
- if (spa_mode_global != 0) {
+ if (spa_mode_global != SPA_MODE_UNINIT) {
mutex_enter(&spa_namespace_lock);
while ((spa = spa_next(spa)) != NULL)
spa_set_deadman_failmode(spa, val);
diff --git a/module/zfs/vdev_label.c b/module/zfs/vdev_label.c
index 6bb3c3c68..aeee6499b 100644
--- a/module/zfs/vdev_label.c
+++ b/module/zfs/vdev_label.c
@@ -932,7 +932,7 @@ vdev_inuse(vdev_t *vd, uint64_t crtxg, vdev_labeltype_t reason,
*/
if (state != POOL_STATE_SPARE && state != POOL_STATE_L2CACHE &&
(spa = spa_by_guid(pool_guid, device_guid)) != NULL &&
- spa_mode(spa) == FREAD)
+ spa_mode(spa) == SPA_MODE_READ)
state = POOL_STATE_ACTIVE;
/*
diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c
index 25863c8e4..902c0b2b2 100644
--- a/module/zfs/zfs_ioctl.c
+++ b/module/zfs/zfs_ioctl.c
@@ -192,6 +192,7 @@
#include <sys/fm/util.h>
#include <sys/dsl_crypt.h>
#include <sys/rrwlock.h>
+#include <sys/zfs_file.h>
#include <sys/dmu_recv.h>
#include <sys/dmu_send.h>
@@ -4708,26 +4709,26 @@ zfs_ioc_recv_impl(char *tofs, char *tosnap, char *origin, nvlist_t *recvprops,
dmu_recv_cookie_t drc;
int error = 0;
int props_error = 0;
- offset_t off;
+ offset_t off, noff;
nvlist_t *local_delayprops = NULL;
nvlist_t *recv_delayprops = NULL;
nvlist_t *origprops = NULL; /* existing properties */
nvlist_t *origrecvd = NULL; /* existing received properties */
boolean_t first_recvd_props = B_FALSE;
boolean_t tofs_was_redacted;
- file_t *input_fp;
+ zfs_file_t *input_fp;
*read_bytes = 0;
*errflags = 0;
*errors = fnvlist_alloc();
+ off = 0;
- input_fp = getf(input_fd);
- if (input_fp == NULL)
- return (SET_ERROR(EBADF));
+ if ((error = zfs_file_get(input_fd, &input_fp)))
+ return (error);
- off = input_fp->f_offset;
+ noff = off = zfs_file_off(input_fp);
error = dmu_recv_begin(tofs, tosnap, begin_record, force,
- resumable, localprops, hidden_args, origin, &drc, input_fp->f_vnode,
+ resumable, localprops, hidden_args, origin, &drc, input_fp,
&off);
if (error != 0)
goto out;
@@ -4901,10 +4902,7 @@ zfs_ioc_recv_impl(char *tofs, char *tosnap, char *origin, nvlist_t *recvprops,
ASSERT(nvlist_merge(localprops, local_delayprops, 0) == 0);
nvlist_free(local_delayprops);
}
-
- *read_bytes = off - input_fp->f_offset;
- if (VOP_SEEK(input_fp->f_vnode, input_fp->f_offset, &off, NULL) == 0)
- input_fp->f_offset = off;
+ *read_bytes = off - noff;
#ifdef DEBUG
if (zfs_ioc_recv_inject_err) {
@@ -5006,7 +5004,7 @@ zfs_ioc_recv_impl(char *tofs, char *tosnap, char *origin, nvlist_t *recvprops,
nvlist_free(inheritprops);
}
out:
- releasef(input_fd);
+ zfs_file_put(input_fd);
nvlist_free(origrecvd);
nvlist_free(origprops);
@@ -5221,8 +5219,8 @@ zfs_ioc_recv_new(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
}
typedef struct dump_bytes_io {
- vnode_t *dbi_vp;
- void *dbi_buf;
+ zfs_file_t *dbi_fp;
+ caddr_t dbi_buf;
int dbi_len;
int dbi_err;
} dump_bytes_io_t;
@@ -5231,11 +5229,13 @@ static void
dump_bytes_cb(void *arg)
{
dump_bytes_io_t *dbi = (dump_bytes_io_t *)arg;
- ssize_t resid; /* have to get resid to get detailed errno */
+ zfs_file_t *fp;
+ caddr_t buf;
+
+ fp = dbi->dbi_fp;
+ buf = dbi->dbi_buf;
- dbi->dbi_err = vn_rdwr(UIO_WRITE, dbi->dbi_vp,
- (caddr_t)dbi->dbi_buf, dbi->dbi_len,
- 0, UIO_SYSSPACE, FAPPEND, RLIM64_INFINITY, CRED(), &resid);
+ dbi->dbi_err = zfs_file_write(fp, buf, dbi->dbi_len, NULL);
}
static int
@@ -5243,7 +5243,7 @@ dump_bytes(objset_t *os, void *buf, int len, void *arg)
{
dump_bytes_io_t dbi;
- dbi.dbi_vp = arg;
+ dbi.dbi_fp = arg;
dbi.dbi_buf = buf;
dbi.dbi_len = len;
@@ -5346,22 +5346,21 @@ zfs_ioc_send(zfs_cmd_t *zc)
dsl_dataset_rele(tosnap, FTAG);
dsl_pool_rele(dp, FTAG);
} else {
- file_t *fp = getf(zc->zc_cookie);
- if (fp == NULL)
- return (SET_ERROR(EBADF));
-
- off = fp->f_offset;
+ zfs_file_t *fp;
dmu_send_outparams_t out = {0};
+
+ if ((error = zfs_file_get(zc->zc_cookie, &fp)))
+ return (error);
+
+ off = zfs_file_off(fp);
out.dso_outfunc = dump_bytes;
- out.dso_arg = fp->f_vnode;
+ out.dso_arg = fp;
out.dso_dryrun = B_FALSE;
error = dmu_send_obj(zc->zc_name, zc->zc_sendobj,
zc->zc_fromobj, embedok, large_block_ok, compressok, rawok,
zc->zc_cookie, &off, &out);
- if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
- fp->f_offset = off;
- releasef(zc->zc_cookie);
+ zfs_file_put(zc->zc_cookie);
}
return (error);
}
@@ -5924,21 +5923,17 @@ zfs_ioc_tmp_snapshot(zfs_cmd_t *zc)
static int
zfs_ioc_diff(zfs_cmd_t *zc)
{
- file_t *fp;
+ zfs_file_t *fp;
offset_t off;
int error;
- fp = getf(zc->zc_cookie);
- if (fp == NULL)
- return (SET_ERROR(EBADF));
-
- off = fp->f_offset;
+ if ((error = zfs_file_get(zc->zc_cookie, &fp)))
+ return (error);
- error = dmu_diff(zc->zc_name, zc->zc_value, fp->f_vnode, &off);
+ off = zfs_file_off(fp);
+ error = dmu_diff(zc->zc_name, zc->zc_value, fp, &off);
- if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
- fp->f_offset = off;
- releasef(zc->zc_cookie);
+ zfs_file_put(zc->zc_cookie);
return (error);
}
@@ -6278,7 +6273,7 @@ zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
offset_t off;
char *fromname = NULL;
int fd;
- file_t *fp;
+ zfs_file_t *fp;
boolean_t largeblockok;
boolean_t embedok;
boolean_t compressok;
@@ -6301,21 +6296,19 @@ zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
(void) nvlist_lookup_string(innvl, "redactbook", &redactbook);
- if ((fp = getf(fd)) == NULL)
- return (SET_ERROR(EBADF));
+ if ((error = zfs_file_get(fd, &fp)))
+ return (error);
+
+ off = zfs_file_off(fp);
- off = fp->f_offset;
dmu_send_outparams_t out = {0};
out.dso_outfunc = dump_bytes;
- out.dso_arg = fp->f_vnode;
+ out.dso_arg = fp;
out.dso_dryrun = B_FALSE;
error = dmu_send(snapname, fromname, embedok, largeblockok, compressok,
rawok, resumeobj, resumeoff, redactbook, fd, &off, &out);
- if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
- fp->f_offset = off;
-
- releasef(fd);
+ zfs_file_put(fd);
return (error);
}
@@ -7438,7 +7431,7 @@ zfs_kmod_init(void)
if ((error = zvol_init()) != 0)
return (error);
- spa_init(FREAD | FWRITE);
+ spa_init(SPA_MODE_READ | SPA_MODE_WRITE);
zfs_init();
zfs_ioctl_init();
diff --git a/module/zfs/zfs_log.c b/module/zfs/zfs_log.c
index 8b7c594f8..9cf55c29b 100644
--- a/module/zfs/zfs_log.c
+++ b/module/zfs/zfs_log.c
@@ -39,7 +39,6 @@
#include <sys/byteorder.h>
#include <sys/policy.h>
#include <sys/stat.h>
-#include <sys/mode.h>
#include <sys/acl.h>
#include <sys/dmu.h>
#include <sys/dbuf.h>
@@ -528,7 +527,7 @@ zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
else if (!spa_has_slogs(zilog->zl_spa) &&
resid >= zfs_immediate_write_sz)
write_state = WR_INDIRECT;
- else if (ioflag & (FSYNC | FDSYNC))
+ else if (ioflag & (O_SYNC | O_DSYNC))
write_state = WR_COPIED;
else
write_state = WR_NEED_COPY;
@@ -578,7 +577,7 @@ zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype,
itx->itx_private = ZTOZSB(zp);
- if (!(ioflag & (FSYNC | FDSYNC)) && (zp->z_sync_cnt == 0) &&
+ if (!(ioflag & (O_SYNC | O_DSYNC)) && (zp->z_sync_cnt == 0) &&
(fsync_cnt == 0))
itx->itx_sync = B_FALSE;
diff --git a/module/zfs/zfs_replay.c b/module/zfs/zfs_replay.c
index 7dea85bb6..59b3f3af1 100644
--- a/module/zfs/zfs_replay.c
+++ b/module/zfs/zfs_replay.c
@@ -43,7 +43,6 @@
#include <sys/zil.h>
#include <sys/byteorder.h>
#include <sys/stat.h>
-#include <sys/mode.h>
#include <sys/acl.h>
#include <sys/atomic.h>
#include <sys/cred.h>
@@ -61,7 +60,6 @@ zfs_init_vattr(vattr_t *vap, uint64_t mask, uint64_t mode,
{
bzero(vap, sizeof (*vap));
vap->va_mask = (uint_t)mask;
- vap->va_type = IFTOVT(mode);
vap->va_mode = mode;
vap->va_uid = (uid_t)(IS_EPHEMERAL(uid)) ? -1 : uid;
vap->va_gid = (gid_t)(IS_EPHEMERAL(gid)) ? -1 : gid;
@@ -796,7 +794,7 @@ zfs_replay_truncate(void *arg1, void *arg2, boolean_t byteswap)
fl.l_start = lr->lr_offset;
fl.l_len = lr->lr_length;
- error = zfs_space(ZTOI(zp), F_FREESP, &fl, FWRITE | FOFFMAX,
+ error = zfs_space(ZTOI(zp), F_FREESP, &fl, O_RDWR | O_LARGEFILE,
lr->lr_offset, kcred);
iput(ZTOI(zp));