Skip to content

Commit

Permalink
Factor out non-portable vnode_t usage
Browse files Browse the repository at this point in the history
On FreeBSD file offset state is maintained in struct file. A given
vnode can be referenced from many different struct file *. As a
consequence, FreeBSD's SPL doesn't support vn_rdwr with the FAPPEND
flag.

This change replaces the non-portable vnode_t with the portable
file_t in the common code.

Signed-off-by: Matt Macy <[email protected]>
  • Loading branch information
mattmacy committed Nov 19, 2019
1 parent 8221bcf commit b4edfe5
Show file tree
Hide file tree
Showing 53 changed files with 1,175 additions and 1,556 deletions.
2 changes: 1 addition & 1 deletion cmd/raidz_test/raidz_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ main(int argc, char **argv)

process_options(argc, argv);

kernel_init(FREAD);
kernel_init(SPA_MODE_READ);

/* setup random data because rand() is not reentrant */
rand_data = (int *)umem_alloc(SPA_MAXBLOCKSIZE, UMEM_NOFAIL);
Expand Down
2 changes: 1 addition & 1 deletion cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6781,7 +6781,7 @@ main(int argc, char **argv)
*/
spa_load_verify_dryrun = B_TRUE;

kernel_init(FREAD);
kernel_init(SPA_MODE_READ);

if (dump_all)
verbose = MAX(verbose, 1);
Expand Down
3 changes: 2 additions & 1 deletion cmd/zhack/zhack.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ zhack_import(char *target, boolean_t readonly)
nvlist_t *props;
int error;

kernel_init(readonly ? FREAD : (FREAD | FWRITE));
kernel_init(readonly ? SPA_MODE_READ :
(SPA_MODE_READ | SPA_MODE_WRITE));

dmu_objset_register_type(DMU_OST_ZFS, space_delta_cb);

Expand Down
14 changes: 7 additions & 7 deletions cmd/ztest/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -5826,8 +5826,8 @@ ztest_fault_inject(ztest_ds_t *zd, uint64_t id)
(long long)vd0->vdev_id, (int)maxfaults);

if (vf != NULL && ztest_random(3) == 0) {
(void) close(vf->vf_vnode->v_fd);
vf->vf_vnode->v_fd = -1;
(void) close(vf->vf_file->f_fd);
vf->vf_file->f_fd = -1;
} else if (ztest_random(2) == 0) {
vd0->vdev_cant_read = B_TRUE;
} else {
Expand Down Expand Up @@ -6933,7 +6933,7 @@ ztest_run(ztest_shared_t *zs)
/*
* Open our pool.
*/
kernel_init(FREAD | FWRITE);
kernel_init(SPA_MODE_READ | SPA_MODE_WRITE);
VERIFY0(spa_open(ztest_opts.zo_pool, &spa, FTAG));
metaslab_preload_limit = ztest_random(20) + 1;
ztest_spa = spa;
Expand Down Expand Up @@ -7122,7 +7122,7 @@ ztest_freeze(void)
if (ztest_opts.zo_verbose >= 3)
(void) printf("testing spa_freeze()...\n");

kernel_init(FREAD | FWRITE);
kernel_init(SPA_MODE_READ | SPA_MODE_WRITE);
VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
VERIFY3U(0, ==, ztest_dataset_open(0));
ztest_spa = spa;
Expand Down Expand Up @@ -7189,7 +7189,7 @@ ztest_freeze(void)
/*
* Open and close the pool and dataset to induce log replay.
*/
kernel_init(FREAD | FWRITE);
kernel_init(SPA_MODE_READ | SPA_MODE_WRITE);
VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
ASSERT(spa_freeze_txg(spa) == UINT64_MAX);
VERIFY3U(0, ==, ztest_dataset_open(0));
Expand Down Expand Up @@ -7262,7 +7262,7 @@ ztest_import(ztest_shared_t *zs)
mutex_init(&ztest_checkpoint_lock, NULL, MUTEX_DEFAULT, NULL);
VERIFY0(pthread_rwlock_init(&ztest_name_lock, NULL));

kernel_init(FREAD | FWRITE);
kernel_init(SPA_MODE_READ | SPA_MODE_WRITE);

searchdirs[0] = ztest_opts.zo_dir;
args.paths = nsearch;
Expand Down Expand Up @@ -7308,7 +7308,7 @@ ztest_init(ztest_shared_t *zs)
mutex_init(&ztest_checkpoint_lock, NULL, MUTEX_DEFAULT, NULL);
VERIFY0(pthread_rwlock_init(&ztest_name_lock, NULL));

kernel_init(FREAD | FWRITE);
kernel_init(SPA_MODE_READ | SPA_MODE_WRITE);

/*
* Create the storage pool.
Expand Down
2 changes: 0 additions & 2 deletions include/os/linux/spl/sys/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ KERNEL_H = \
$(top_srcdir)/include/os/linux/spl/sys/isa_defs.h \
$(top_srcdir)/include/os/linux/spl/sys/kmem_cache.h \
$(top_srcdir)/include/os/linux/spl/sys/kmem.h \
$(top_srcdir)/include/os/linux/spl/sys/kobj.h \
$(top_srcdir)/include/os/linux/spl/sys/kstat.h \
$(top_srcdir)/include/os/linux/spl/sys/list.h \
$(top_srcdir)/include/os/linux/spl/sys/mod_os.h \
$(top_srcdir)/include/os/linux/spl/sys/mode.h \
$(top_srcdir)/include/os/linux/spl/sys/mutex.h \
$(top_srcdir)/include/os/linux/spl/sys/param.h \
$(top_srcdir)/include/os/linux/spl/sys/processor.h \
Expand Down
42 changes: 0 additions & 42 deletions include/os/linux/spl/sys/kobj.h

This file was deleted.

32 changes: 0 additions & 32 deletions include/os/linux/spl/sys/mode.h

This file was deleted.

95 changes: 0 additions & 95 deletions include/os/linux/spl/sys/vnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,8 @@
#define O_DSYNC O_SYNC
#endif

#define FREAD 1
#define FWRITE 2
#define FCREAT O_CREAT
#define FTRUNC O_TRUNC
#define FOFFMAX O_LARGEFILE
#define FSYNC O_SYNC
#define FDSYNC O_DSYNC
#define FEXCL O_EXCL
#define FDIRECT O_DIRECT
#define FAPPEND O_APPEND

#define FNODSYNC 0x10000 /* fsync pseudo flag */
#define FNOFOLLOW 0x20000 /* don't follow symlinks */

#define F_FREESP 11 /* Free file space */


/*
* The vnode AT_ flags are mapped to the Linux ATTR_* flags.
* This allows them to be used safely with an iattr structure.
Expand Down Expand Up @@ -102,23 +87,7 @@
#define CREATE_XATTR_DIR 0x04
#define ATTR_NOACLCHECK 0x20

typedef enum vtype {
VNON = 0,
VREG = 1,
VDIR = 2,
VBLK = 3,
VCHR = 4,
VLNK = 5,
VFIFO = 6,
VDOOR = 7,
VPROC = 8,
VSOCK = 9,
VPORT = 10,
VBAD = 11
} vtype_t;

typedef struct vattr {
enum vtype va_type; /* vnode type */
uint32_t va_mask; /* attribute bit-mask */
ushort_t va_mode; /* acc mode */
uid_t va_uid; /* owner uid */
Expand All @@ -133,70 +102,6 @@ typedef struct vattr {
dev_t va_rdev; /* dev */
uint64_t va_nblocks; /* space used */
uint32_t va_blksize; /* block size */
uint32_t va_seq; /* sequence */
struct dentry *va_dentry; /* dentry to wire */
} vattr_t;

typedef struct vnode {
struct file *v_file;
kmutex_t v_lock; /* protects vnode fields */
uint_t v_flag; /* vnode flags (see below) */
uint_t v_count; /* reference count */
void *v_data; /* private data for fs */
struct vfs *v_vfsp; /* ptr to containing VFS */
struct stdata *v_stream; /* associated stream */
enum vtype v_type; /* vnode type */
dev_t v_rdev; /* device (VCHR, VBLK) */
gfp_t v_gfp_mask; /* original mapping gfp mask */
} vnode_t;

typedef struct vn_file {
int f_fd; /* linux fd for lookup */
struct task_struct *f_task; /* linux task this fd belongs to */
struct file *f_file; /* linux file struct */
atomic_t f_ref; /* ref count */
kmutex_t f_lock; /* struct lock */
loff_t f_offset; /* offset */
vnode_t *f_vnode; /* vnode */
struct list_head f_list; /* list referenced file_t's */
} file_t;

extern vnode_t *vn_alloc(int flag);
void vn_free(vnode_t *vp);
extern vtype_t vn_mode_to_vtype(mode_t);
extern mode_t vn_vtype_to_mode(vtype_t);
extern int vn_open(const char *path, uio_seg_t seg, int flags, int mode,
vnode_t **vpp, int x1, void *x2);
extern int vn_openat(const char *path, uio_seg_t seg, int flags, int mode,
vnode_t **vpp, int x1, void *x2, vnode_t *vp, int fd);
extern int vn_rdwr(uio_rw_t uio, vnode_t *vp, void *addr, ssize_t len,
offset_t off, uio_seg_t seg, int x1, rlim64_t x2,
void *x3, ssize_t *residp);
extern int vn_close(vnode_t *vp, int flags, int x1, int x2, void *x3, void *x4);
extern int vn_seek(vnode_t *vp, offset_t o, offset_t *op, void *ct);

extern int vn_getattr(vnode_t *vp, vattr_t *vap, int flags, void *x3, void *x4);
extern int vn_fsync(vnode_t *vp, int flags, void *x3, void *x4);
extern int vn_space(vnode_t *vp, int cmd, struct flock *bfp, int flag,
offset_t offset, void *x6, void *x7);
extern file_t *vn_getf(int fd);
extern void vn_releasef(int fd);
extern void vn_areleasef(int fd, uf_info_t *fip);

int spl_vn_init(void);
void spl_vn_fini(void);

#define VOP_CLOSE vn_close
#define VOP_SEEK vn_seek
#define VOP_GETATTR vn_getattr
#define VOP_FSYNC vn_fsync
#define VOP_SPACE vn_space
#define VOP_PUTPAGE(vp, o, s, f, x1, x2) ((void)0)
#define vn_is_readonly(vp) 0
#define getf vn_getf
#define releasef vn_releasef
#define areleasef vn_areleasef

extern vnode_t *rootdir;

#endif /* SPL_VNODE_H */
2 changes: 1 addition & 1 deletion include/os/linux/zfs/sys/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int secpolicy_zfs(const cred_t *);
void secpolicy_setid_clear(vattr_t *, cred_t *);
int secpolicy_setid_setsticky_clear(struct inode *, vattr_t *,
const vattr_t *, cred_t *);
int secpolicy_xvattr(xvattr_t *, uid_t, cred_t *, vtype_t);
int secpolicy_xvattr(xvattr_t *, uid_t, cred_t *, mode_t);
int secpolicy_vnode_setattr(cred_t *, struct inode *, struct vattr *,
const struct vattr *, int, int (void *, int, cred_t *), void *);
int secpolicy_basic_link(const cred_t *);
Expand Down
1 change: 1 addition & 0 deletions include/os/linux/zfs/sys/zfs_vnops.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <sys/fcntl.h>
#include <sys/pathname.h>
#include <sys/zpl.h>
#include <sys/zfs_file.h>

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions include/sys/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ COMMON_H = \
$(top_srcdir)/include/sys/zfs_context.h \
$(top_srcdir)/include/sys/zfs_debug.h \
$(top_srcdir)/include/sys/zfs_delay.h \
$(top_srcdir)/include/sys/zfs_file.h \
$(top_srcdir)/include/sys/zfs_fuid.h \
$(top_srcdir)/include/sys/zfs_project.h \
$(top_srcdir)/include/sys/zfs_ratelimit.h \
Expand Down
3 changes: 2 additions & 1 deletion include/sys/dmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <sys/zio_compress.h>
#include <sys/zio_priority.h>
#include <sys/uio.h>
#include <sys/zfs_file.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -1071,7 +1072,7 @@ void dmu_traverse_objset(objset_t *os, uint64_t txg_start,
dmu_traverse_cb_t cb, void *arg);

int dmu_diff(const char *tosnap_name, const char *fromsnap_name,
struct vnode *vp, offset_t *offp);
zfs_file_t *fp, offset_t *offp);

/* CRC64 table */
#define ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */
Expand Down
4 changes: 2 additions & 2 deletions include/sys/dmu_recv.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typedef struct dmu_recv_cookie {
nvlist_t *drc_begin_nvl;

objset_t *drc_os;
vnode_t *drc_vp; /* The vnode to read the stream from */
zfs_file_t *drc_fp; /* The file to read the stream from */
uint64_t drc_voff; /* The current offset in the stream */
uint64_t drc_bytes_read;
/*
Expand All @@ -82,7 +82,7 @@ typedef struct dmu_recv_cookie {
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);
zfs_file_t *fp, offset_t *voffp);
int dmu_recv_stream(dmu_recv_cookie_t *drc, int cleanup_fd,
uint64_t *action_handlep, offset_t *voffp);
int dmu_recv_end(dmu_recv_cookie_t *drc, void *owner);
Expand Down
12 changes: 9 additions & 3 deletions include/sys/spa.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,12 @@ typedef enum spa_import_type {
SPA_IMPORT_ASSEMBLE
} spa_import_type_t;

typedef enum spa_mode {
SPA_MODE_UNINIT = 0,
SPA_MODE_READ = 1,
SPA_MODE_WRITE = 2,
} spa_mode_t;

/*
* Send TRIM commands in-line during normal pool operation while deleting.
* OFF: no
Expand Down Expand Up @@ -1099,7 +1105,7 @@ extern uint32_t spa_get_hostid(spa_t *spa);
extern void spa_activate_allocation_classes(spa_t *, dmu_tx_t *);
extern boolean_t spa_livelist_delete_check(spa_t *spa);

extern int spa_mode(spa_t *spa);
extern spa_mode_t spa_mode(spa_t *spa);
extern uint64_t zfs_strtonum(const char *str, char **nptr);

extern char *spa_his_ievent_table[];
Expand Down Expand Up @@ -1149,7 +1155,7 @@ extern void vdev_mirror_stat_init(void);
extern void vdev_mirror_stat_fini(void);

/* Initialization and termination */
extern void spa_init(int flags);
extern void spa_init(spa_mode_t mode);
extern void spa_fini(void);
extern void spa_boot_init(void);

Expand Down Expand Up @@ -1189,7 +1195,7 @@ _NOTE(CONSTCOND) } while (0)
#define dprintf_bp(bp, fmt, ...)
#endif

extern int spa_mode_global; /* mode, e.g. FREAD | FWRITE */
extern spa_mode_t spa_mode_global;
extern int zfs_deadman_enabled;
extern unsigned long zfs_deadman_synctime_ms;
extern unsigned long zfs_deadman_ziotime_ms;
Expand Down
2 changes: 1 addition & 1 deletion include/sys/spa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ struct spa {
uint8_t spa_claiming; /* pool is doing zil_claim() */
boolean_t spa_is_root; /* pool is root */
int spa_minref; /* num refs when first opened */
int spa_mode; /* FREAD | FWRITE */
spa_mode_t spa_mode; /* SPA_MODE_{READ|WRITE} */
spa_log_state_t spa_log_state; /* log state */
uint64_t spa_autoexpand; /* lun expansion on/off */
ddt_t *spa_ddt[ZIO_CHECKSUM_FUNCTIONS]; /* in-core DDTs */
Expand Down
Loading

0 comments on commit b4edfe5

Please sign in to comment.