Skip to content

Commit e53d678

Browse files
authored
Share zfs_fsync, zfs_read, zfs_write, et al between Linux and FreeBSD
The zfs_fsync, zfs_read, and zfs_write function are almost identical between Linux and FreeBSD. With a little refactoring they can be moved to the common code which is what is done by this commit. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Signed-off-by: Matt Macy <[email protected]> Closes #11078
1 parent 666aa69 commit e53d678

File tree

29 files changed

+768
-1268
lines changed

29 files changed

+768
-1268
lines changed

include/os/freebsd/spl/sys/misc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,7 @@ struct opensolaris_utsname {
5353

5454
extern char hw_serial[11];
5555

56+
#define task_io_account_read(n)
57+
#define task_io_account_write(n)
58+
5659
#endif /* _OPENSOLARIS_SYS_MISC_H_ */

include/os/freebsd/spl/sys/policy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <sys/vnode.h>
3535
struct mount;
3636
struct vattr;
37+
struct znode;
3738

3839
int secpolicy_nfs(cred_t *cr);
3940
int secpolicy_zfs(cred_t *crd);
@@ -57,7 +58,7 @@ int secpolicy_vnode_setattr(cred_t *cr, vnode_t *vp, struct vattr *vap,
5758
int unlocked_access(void *, int, cred_t *), void *node);
5859
int secpolicy_vnode_create_gid(cred_t *cr);
5960
int secpolicy_vnode_setids_setgids(vnode_t *vp, cred_t *cr, gid_t gid);
60-
int secpolicy_vnode_setid_retain(vnode_t *vp, cred_t *cr,
61+
int secpolicy_vnode_setid_retain(struct znode *zp, cred_t *cr,
6162
boolean_t issuidroot);
6263
void secpolicy_setid_clear(struct vattr *vap, vnode_t *vp, cred_t *cr);
6364
int secpolicy_setid_setsticky_clear(vnode_t *vp, struct vattr *vap,

include/os/freebsd/spl/sys/uio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void uioskip(uio_t *uiop, size_t n);
8282
#define uio_iovcnt(uio) (uio)->uio_iovcnt
8383
#define uio_iovlen(uio, idx) (uio)->uio_iov[(idx)].iov_len
8484
#define uio_iovbase(uio, idx) (uio)->uio_iov[(idx)].iov_base
85+
#define uio_fault_disable(uio, set)
8586

8687
static inline void
8788
uio_iov_at_index(uio_t *uio, uint_t idx, void **base, uint64_t *len)

include/os/freebsd/zfs/sys/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ KERNEL_H = \
88
zfs_dir.h \
99
zfs_ioctl_compat.h \
1010
zfs_vfsops_os.h \
11-
zfs_vnops.h \
11+
zfs_vnops_os.h \
1212
zfs_znode_impl.h \
1313
zpl.h
1414

include/os/freebsd/zfs/sys/zfs_context_os.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <linux/types.h>
4343

4444
#define cond_resched() kern_yield(PRI_USER)
45+
#define uio_prefaultpages(size, uio) (0)
4546

4647
#define taskq_create_sysdc(a, b, d, e, p, dc, f) \
4748
(taskq_create(a, b, maxclsyspri, d, e, f))

include/os/freebsd/zfs/sys/zfs_vnops.h renamed to include/os/freebsd/zfs/sys/zfs_vnops_os.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
* $FreeBSD$
2727
*/
2828

29-
#ifndef _SYS_ZFS_VNOPS_H_
30-
#define _SYS_ZFS_VNOPS_H_
29+
#ifndef _SYS_FS_ZFS_VNOPS_OS_H
30+
#define _SYS_FS_ZFS_VNOPS_OS_H
31+
3132
int dmu_write_pages(objset_t *os, uint64_t object, uint64_t offset,
3233
uint64_t size, struct vm_page **ppa, dmu_tx_t *tx);
3334
int dmu_read_pages(objset_t *os, uint64_t object, vm_page_t *ma, int count,

include/os/freebsd/zfs/sys/zfs_znode_impl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <sys/zfs_acl.h>
4040
#include <sys/zil.h>
4141
#include <sys/zfs_project.h>
42+
#include <vm/vm_object.h>
4243

4344
#ifdef __cplusplus
4445
extern "C" {
@@ -113,7 +114,10 @@ extern minor_t zfsdev_minor_alloc(void);
113114
#define Z_ISBLK(type) ((type) == VBLK)
114115
#define Z_ISCHR(type) ((type) == VCHR)
115116
#define Z_ISLNK(type) ((type) == VLNK)
117+
#define Z_ISDIR(type) ((type) == VDIR)
116118

119+
#define zn_has_cached_data(zp) vn_has_cached_data(ZTOV(zp))
120+
#define zn_rlimit_fsize(zp, uio, td) vn_rlimit_fsize(ZTOV(zp), (uio), (td))
117121

118122
/* Called on entry to each ZFS vnode and vfs operation */
119123
#define ZFS_ENTER(zfsvfs) \
@@ -175,7 +179,7 @@ extern int zfsfstype;
175179

176180
extern int zfs_znode_parent_and_name(struct znode *zp, struct znode **dzpp,
177181
char *buf);
178-
182+
extern void zfs_inode_update(struct znode *);
179183
#ifdef __cplusplus
180184
}
181185
#endif

include/os/linux/kernel/linux/mod_compat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ enum scope_prefix_types {
7474
zfs_vdev_cache,
7575
zfs_vdev_file,
7676
zfs_vdev_mirror,
77+
zfs_vnops,
7778
zfs_zevent,
7879
zfs_zio,
7980
zfs_zil

include/os/linux/spl/sys/uio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ typedef struct uio {
5959
boolean_t uio_fault_disable;
6060
uint16_t uio_fmode;
6161
uint16_t uio_extflg;
62-
offset_t uio_limit;
6362
ssize_t uio_resid;
6463
size_t uio_skip;
6564
} uio_t;
@@ -113,6 +112,7 @@ typedef struct xuio {
113112
#define uio_iovcnt(uio) (uio)->uio_iovcnt
114113
#define uio_iovlen(uio, idx) (uio)->uio_iov[(idx)].iov_len
115114
#define uio_iovbase(uio, idx) (uio)->uio_iov[(idx)].iov_base
115+
#define uio_fault_disable(uio, set) (uio)->uio_fault_disable = set
116116

117117
static inline void
118118
uio_iov_at_index(uio_t *uio, uint_t idx, void **base, uint64_t *len)

include/os/linux/zfs/sys/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ KERNEL_H = \
2121
zfs_ctldir.h \
2222
zfs_dir.h \
2323
zfs_vfsops_os.h \
24-
zfs_vnops.h \
24+
zfs_vnops_os.h \
2525
zfs_znode_impl.h \
2626
zpl.h
2727

include/os/linux/zfs/sys/policy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include <sys/xvattr.h>
3636
#include <sys/zpl.h>
3737

38+
struct znode;
39+
3840
int secpolicy_nfs(const cred_t *);
3941
int secpolicy_sys_config(const cred_t *, boolean_t);
4042
int secpolicy_vnode_access2(const cred_t *, struct inode *,
@@ -44,7 +46,7 @@ int secpolicy_vnode_chown(const cred_t *, uid_t);
4446
int secpolicy_vnode_create_gid(const cred_t *);
4547
int secpolicy_vnode_remove(const cred_t *);
4648
int secpolicy_vnode_setdac(const cred_t *, uid_t);
47-
int secpolicy_vnode_setid_retain(const cred_t *, boolean_t);
49+
int secpolicy_vnode_setid_retain(struct znode *, const cred_t *, boolean_t);
4850
int secpolicy_vnode_setids_setgids(const cred_t *, gid_t);
4951
int secpolicy_zinject(const cred_t *);
5052
int secpolicy_zfs(const cred_t *);

include/os/linux/zfs/sys/zfs_vnops.h renamed to include/os/linux/zfs/sys/zfs_vnops_os.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2323
*/
2424

25-
#ifndef _SYS_FS_ZFS_VNOPS_H
26-
#define _SYS_FS_ZFS_VNOPS_H
25+
#ifndef _SYS_FS_ZFS_VNOPS_OS_H
26+
#define _SYS_FS_ZFS_VNOPS_OS_H
2727

2828
#include <sys/vnode.h>
2929
#include <sys/xvattr.h>
@@ -41,8 +41,6 @@ extern "C" {
4141
extern int zfs_open(struct inode *ip, int mode, int flag, cred_t *cr);
4242
extern int zfs_close(struct inode *ip, int flag, cred_t *cr);
4343
extern int zfs_holey(struct inode *ip, int cmd, loff_t *off);
44-
extern int zfs_read(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr);
45-
extern int zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr);
4644
extern int zfs_write_simple(znode_t *zp, const void *data, size_t len,
4745
loff_t pos, size_t *resid);
4846
extern int zfs_access(struct inode *ip, int mode, int flag, cred_t *cr);
@@ -58,7 +56,6 @@ extern int zfs_mkdir(znode_t *dzp, char *dirname, vattr_t *vap,
5856
extern int zfs_rmdir(znode_t *dzp, char *name, znode_t *cwd,
5957
cred_t *cr, int flags);
6058
extern int zfs_readdir(struct inode *ip, zpl_dir_context_t *ctx, cred_t *cr);
61-
extern int zfs_fsync(znode_t *zp, int syncflag, cred_t *cr);
6259
extern int zfs_getattr_fast(struct inode *ip, struct kstat *sp);
6360
extern int zfs_setattr(znode_t *zp, vattr_t *vap, int flag, cred_t *cr);
6461
extern int zfs_rename(znode_t *sdzp, char *snm, znode_t *tdzp,
@@ -72,10 +69,6 @@ extern void zfs_inactive(struct inode *ip);
7269
extern int zfs_space(znode_t *zp, int cmd, flock64_t *bfp, int flag,
7370
offset_t offset, cred_t *cr);
7471
extern int zfs_fid(struct inode *ip, fid_t *fidp);
75-
extern int zfs_getsecattr(struct inode *ip, vsecattr_t *vsecp, int flag,
76-
cred_t *cr);
77-
extern int zfs_setsecattr(znode_t *zp, vsecattr_t *vsecp, int flag,
78-
cred_t *cr);
7972
extern int zfs_getpage(struct inode *ip, struct page *pl[], int nr_pages);
8073
extern int zfs_putpage(struct inode *ip, struct page *pp,
8174
struct writeback_control *wbc);

include/os/linux/zfs/sys/zfs_znode_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ extern "C" {
6868
#define Z_ISCHR(type) S_ISCHR(type)
6969
#define Z_ISLNK(type) S_ISLNK(type)
7070
#define Z_ISDEV(type) (S_ISCHR(type) || S_ISBLK(type) || S_ISFIFO(type))
71+
#define Z_ISDIR(type) S_ISDIR(type)
72+
73+
#define zn_has_cached_data(zp) ((zp)->z_is_mapped)
74+
#define zn_rlimit_fsize(zp, uio, td) (0)
7175

7276
#define zhold(zp) igrab(ZTOI((zp)))
7377
#define zrele(zp) iput(ZTOI((zp)))
@@ -143,6 +147,8 @@ do { \
143147
} while (0)
144148
#endif /* HAVE_INODE_TIMESPEC64_TIMES */
145149

150+
#define ZFS_ACCESSTIME_STAMP(zfsvfs, zp)
151+
146152
struct znode;
147153

148154
extern int zfs_sync(struct super_block *, int, cred_t *);

include/sys/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ COMMON_H = \
117117
zfs_stat.h \
118118
zfs_sysfs.h \
119119
zfs_vfsops.h \
120+
zfs_vnops.h \
120121
zfs_znode.h \
121122
zil.h \
122123
zil_impl.h \

include/sys/zfs_vnops.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9+
* or http://www.opensolaris.org/os/licensing.
10+
* See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*
13+
* When distributing Covered Code, include this CDDL HEADER in each
14+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15+
* If applicable, add the following below this CDDL HEADER, with the
16+
* fields enclosed by brackets "[]" replaced with your own identifying
17+
* information: Portions Copyright [yyyy] [name of copyright owner]
18+
*
19+
* CDDL HEADER END
20+
*/
21+
/*
22+
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23+
*/
24+
25+
#ifndef _SYS_FS_ZFS_VNOPS_H
26+
#define _SYS_FS_ZFS_VNOPS_H
27+
#include <sys/zfs_vnops_os.h>
28+
29+
extern int zfs_fsync(znode_t *, int, cred_t *);
30+
extern int zfs_read(znode_t *, uio_t *, int, cred_t *);
31+
extern int zfs_write(znode_t *, uio_t *, int, cred_t *);
32+
extern int zfs_getsecattr(znode_t *zp, vsecattr_t *vsecp, int flag, cred_t *cr);
33+
extern int zfs_setsecattr(znode_t *zp, vsecattr_t *vsecp, int flag, cred_t *cr);
34+
35+
extern int mappedread(znode_t *, int, uio_t *);
36+
extern int mappedread_sf(znode_t *, int, uio_t *);
37+
extern void update_pages(znode_t *, int64_t, int, objset_t *, uint64_t);
38+
39+
#endif

lib/libspl/include/sys/uio.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ typedef struct uio {
7373
uio_seg_t uio_segflg; /* address space (kernel or user) */
7474
uint16_t uio_fmode; /* file mode flags */
7575
uint16_t uio_extflg; /* extended flags */
76-
offset_t uio_limit; /* u-limit (maximum byte offset) */
7776
ssize_t uio_resid; /* residual count */
7877
} uio_t;
7978

module/Makefile.bsd

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,28 +101,27 @@ SRCS+= nvpair.c \
101101

102102
#os/freebsd/spl
103103
SRCS+= acl_common.c \
104-
btree.c \
105104
callb.c \
106105
list.c \
106+
sha256c.c \
107+
sha512c.c \
107108
spl_acl.c \
108109
spl_cmn_err.c \
109110
spl_dtrace.c \
110111
spl_kmem.c \
111112
spl_kstat.c \
112113
spl_misc.c \
113114
spl_policy.c \
115+
spl_procfs_list.c \
114116
spl_string.c \
115117
spl_sunddi.c \
116118
spl_sysevent.c \
117119
spl_taskq.c \
118120
spl_uio.c \
119121
spl_vfs.c \
120122
spl_vm.c \
121-
spl_zone.c \
122-
sha256c.c \
123-
sha512c.c \
124-
spl_procfs_list.c \
125-
spl_zlib.c
123+
spl_zlib.c \
124+
spl_zone.c
126125

127126

128127
.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "powerpc" || \
@@ -132,24 +131,24 @@ SRCS+= spl_atomic.c
132131

133132
#os/freebsd/zfs
134133
SRCS+= abd_os.c \
134+
arc_os.c \
135135
crypto_os.c \
136136
dmu_os.c \
137137
hkdf.c \
138138
kmod_core.c \
139139
spa_os.c \
140140
sysctl_os.c \
141141
vdev_file.c \
142-
vdev_label_os.c \
143142
vdev_geom.c \
143+
vdev_label_os.c \
144144
zfs_acl.c \
145145
zfs_ctldir.c \
146+
zfs_debug.c \
146147
zfs_dir.c \
147148
zfs_ioctl_compat.c \
148149
zfs_ioctl_os.c \
149-
zfs_log.c \
150-
zfs_replay.c \
151150
zfs_vfsops.c \
152-
zfs_vnops.c \
151+
zfs_vnops_os.c \
153152
zfs_znode.c \
154153
zio_crypt.c \
155154
zvol_os.c
@@ -177,10 +176,10 @@ SRCS+= zfeature_common.c \
177176
SRCS+= abd.c \
178177
aggsum.c \
179178
arc.c \
180-
arc_os.c \
181179
blkptr.c \
182180
bplist.c \
183181
bpobj.c \
182+
btree.c \
184183
cityhash.c \
185184
dbuf.c \
186185
dbuf_stats.c \
@@ -275,16 +274,18 @@ SRCS+= abd.c \
275274
zcp_synctask.c \
276275
zfeature.c \
277276
zfs_byteswap.c \
278-
zfs_debug.c \
279277
zfs_file_os.c \
280278
zfs_fm.c \
281279
zfs_fuid.c \
282280
zfs_ioctl.c \
281+
zfs_log.c \
283282
zfs_onexit.c \
284283
zfs_quota.c \
285284
zfs_ratelimit.c \
285+
zfs_replay.c \
286286
zfs_rlock.c \
287287
zfs_sa.c \
288+
zfs_vnops.c \
288289
zil.c \
289290
zio.c \
290291
zio_checksum.c \
@@ -322,7 +323,7 @@ CFLAGS.spl_vm.c= -Wno-cast-qual
322323
CFLAGS.spl_zlib.c= -Wno-cast-qual
323324
CFLAGS.abd.c= -Wno-cast-qual
324325
CFLAGS.zfs_log.c= -Wno-cast-qual
325-
CFLAGS.zfs_vnops.c= -Wno-pointer-arith
326+
CFLAGS.zfs_vnops_os.c= -Wno-pointer-arith
326327
CFLAGS.u8_textprep.c= -Wno-cast-qual
327328
CFLAGS.zfs_fletcher.c= -Wno-cast-qual -Wno-pointer-arith
328329
CFLAGS.zfs_fletcher_intel.c= -Wno-cast-qual -Wno-pointer-arith

module/os/freebsd/spl/spl_policy.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
3737
#include <sys/jail.h>
3838
#include <sys/policy.h>
3939
#include <sys/zfs_vfsops.h>
40+
#include <sys/zfs_znode.h>
4041

4142

4243
int
@@ -312,11 +313,11 @@ secpolicy_vnode_setids_setgids(vnode_t *vp, cred_t *cr, gid_t gid)
312313
}
313314

314315
int
315-
secpolicy_vnode_setid_retain(vnode_t *vp, cred_t *cr,
316+
secpolicy_vnode_setid_retain(znode_t *zp, cred_t *cr,
316317
boolean_t issuidroot __unused)
317318
{
318319

319-
if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
320+
if (secpolicy_fs_owner(ZTOV(zp)->v_mount, cr) == 0)
320321
return (0);
321322
return (spl_priv_check_cred(cr, PRIV_VFS_RETAINSUGID));
322323
}

module/os/freebsd/zfs/sysctl_os.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ SYSCTL_NODE(_vfs_zfs, OID_AUTO, spa, CTLFLAG_RW, 0, "ZFS space allocation");
114114
SYSCTL_NODE(_vfs_zfs, OID_AUTO, trim, CTLFLAG_RW, 0, "ZFS TRIM");
115115
SYSCTL_NODE(_vfs_zfs, OID_AUTO, txg, CTLFLAG_RW, 0, "ZFS transaction group");
116116
SYSCTL_NODE(_vfs_zfs, OID_AUTO, vdev, CTLFLAG_RW, 0, "ZFS VDEV");
117+
SYSCTL_NODE(_vfs_zfs, OID_AUTO, vnops, CTLFLAG_RW, 0, "ZFS VNOPS");
117118
SYSCTL_NODE(_vfs_zfs, OID_AUTO, zevent, CTLFLAG_RW, 0, "ZFS event");
118119
SYSCTL_NODE(_vfs_zfs, OID_AUTO, zil, CTLFLAG_RW, 0, "ZFS ZIL");
119120
SYSCTL_NODE(_vfs_zfs, OID_AUTO, zio, CTLFLAG_RW, 0, "ZFS ZIO");

0 commit comments

Comments
 (0)