mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-25 18:59:33 +03:00
OpenZFS restructuring - zvol
Refactor the zvol in to platform dependent and independent bits. Reviewed-by: Allan Jude <allanjude@freebsd.org> Reviewed-by: Jorgen Lundman <lundman@lundman.net> Reviewed-by: Igor Kozhukhov <igor@dilos.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Matt Macy <mmacy@FreeBSD.org> Closes #9295
This commit is contained in:
parent
d359e99c38
commit
5df7e9d85c
@ -125,7 +125,8 @@ COMMON_H = \
|
||||
KERNEL_H = \
|
||||
$(top_srcdir)/include/sys/zfs_ioctl.h \
|
||||
$(top_srcdir)/include/sys/zfs_onexit.h \
|
||||
$(top_srcdir)/include/sys/zvol.h
|
||||
$(top_srcdir)/include/sys/zvol.h \
|
||||
$(top_srcdir)/include/sys/zvol_impl.h
|
||||
|
||||
USER_H =
|
||||
|
||||
|
@ -337,7 +337,7 @@ int dsl_destroy_snapshots_nvl(struct nvlist *snaps, boolean_t defer,
|
||||
struct nvlist *errlist);
|
||||
int dmu_objset_snapshot_one(const char *fsname, const char *snapname);
|
||||
int dmu_objset_snapshot_tmp(const char *, const char *, int);
|
||||
int dmu_objset_find(char *name, int func(const char *, void *), void *arg,
|
||||
int dmu_objset_find(const char *name, int func(const char *, void *), void *arg,
|
||||
int flags);
|
||||
void dmu_objset_byteswap(void *buf, size_t size);
|
||||
int dsl_dataset_rename_snapshot(const char *fsname,
|
||||
|
@ -41,7 +41,8 @@ extern void zvol_rename_minors(spa_t *spa, const char *oldname,
|
||||
const char *newname, boolean_t async);
|
||||
|
||||
#ifdef _KERNEL
|
||||
typedef struct zvol_state zvol_state_t;
|
||||
struct zvol_state;
|
||||
typedef struct zvol_state zvol_state_handle_t;
|
||||
|
||||
extern int zvol_check_volsize(uint64_t volsize, uint64_t blocksize);
|
||||
extern int zvol_check_volblocksize(const char *name, uint64_t volblocksize);
|
||||
@ -52,11 +53,13 @@ extern int zvol_set_volsize(const char *, uint64_t);
|
||||
extern int zvol_set_volblocksize(const char *, uint64_t);
|
||||
extern int zvol_set_snapdev(const char *, zprop_source_t, uint64_t);
|
||||
extern int zvol_set_volmode(const char *, zprop_source_t, uint64_t);
|
||||
extern zvol_state_t *zvol_suspend(const char *);
|
||||
extern int zvol_resume(zvol_state_t *);
|
||||
extern void *zvol_tag(zvol_state_t *);
|
||||
extern zvol_state_handle_t *zvol_suspend(const char *);
|
||||
extern int zvol_resume(zvol_state_handle_t *);
|
||||
extern void *zvol_tag(zvol_state_handle_t *);
|
||||
|
||||
extern int zvol_init(void);
|
||||
extern void zvol_fini(void);
|
||||
extern int zvol_busy(void);
|
||||
|
||||
#endif /* _KERNEL */
|
||||
#endif /* _SYS_ZVOL_H */
|
||||
|
107
include/sys/zvol_impl.h
Normal file
107
include/sys/zvol_impl.h
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef _SYS_ZVOL_IMPL_H
|
||||
#define _SYS_ZVOL_IMPL_H
|
||||
|
||||
#include <sys/zfs_context.h>
|
||||
|
||||
#define ZVOL_RDONLY 0x1
|
||||
/*
|
||||
* Whether the zvol has been written to (as opposed to ZVOL_RDONLY, which
|
||||
* specifies whether or not the zvol _can_ be written to)
|
||||
*/
|
||||
#define ZVOL_WRITTEN_TO 0x2
|
||||
|
||||
#define ZVOL_DUMPIFIED 0x4
|
||||
|
||||
#define ZVOL_EXCL 0x8
|
||||
|
||||
/*
|
||||
* The in-core state of each volume.
|
||||
*/
|
||||
typedef struct zvol_state {
|
||||
char zv_name[MAXNAMELEN]; /* name */
|
||||
uint64_t zv_volsize; /* advertised space */
|
||||
uint64_t zv_volblocksize; /* volume block size */
|
||||
objset_t *zv_objset; /* objset handle */
|
||||
uint32_t zv_flags; /* ZVOL_* flags */
|
||||
uint32_t zv_open_count; /* open counts */
|
||||
uint32_t zv_changed; /* disk changed */
|
||||
zilog_t *zv_zilog; /* ZIL handle */
|
||||
rangelock_t zv_rangelock; /* for range locking */
|
||||
dnode_t *zv_dn; /* dnode hold */
|
||||
list_node_t zv_next; /* next zvol_state_t linkage */
|
||||
uint64_t zv_hash; /* name hash */
|
||||
struct hlist_node zv_hlink; /* hash link */
|
||||
kmutex_t zv_state_lock; /* protects zvol_state_t */
|
||||
atomic_t zv_suspend_ref; /* refcount for suspend */
|
||||
krwlock_t zv_suspend_lock; /* suspend lock */
|
||||
struct zvol_state_os *zv_zso; /* private platform state */
|
||||
} zvol_state_t;
|
||||
|
||||
|
||||
extern list_t zvol_state_list;
|
||||
extern krwlock_t zvol_state_lock;
|
||||
#define ZVOL_HT_SIZE 1024
|
||||
extern struct hlist_head *zvol_htable;
|
||||
#define ZVOL_HT_HEAD(hash) (&zvol_htable[(hash) & (ZVOL_HT_SIZE-1)])
|
||||
extern zil_replay_func_t *zvol_replay_vector[TX_MAX_TYPE];
|
||||
|
||||
extern unsigned int zvol_volmode;
|
||||
extern unsigned int zvol_inhibit_dev;
|
||||
|
||||
/*
|
||||
* platform independent functions exported to platform code
|
||||
*/
|
||||
zvol_state_t *zvol_find_by_name_hash(const char *name,
|
||||
uint64_t hash, int mode);
|
||||
int zvol_first_open(zvol_state_t *zv, boolean_t readonly);
|
||||
uint64_t zvol_name_hash(const char *name);
|
||||
void zvol_remove_minors_impl(const char *name);
|
||||
void zvol_last_close(zvol_state_t *zv);
|
||||
void zvol_insert(zvol_state_t *zv);
|
||||
void zvol_log_truncate(zvol_state_t *zv, dmu_tx_t *tx, uint64_t off,
|
||||
uint64_t len, boolean_t sync);
|
||||
void zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, uint64_t offset,
|
||||
uint64_t size, int sync);
|
||||
int zvol_get_data(void *arg, lr_write_t *lr, char *buf, struct lwb *lwb,
|
||||
zio_t *zio);
|
||||
int zvol_init_impl(void);
|
||||
void zvol_fini_impl(void);
|
||||
|
||||
/*
|
||||
* platform dependent functions exported to platform independent code
|
||||
*/
|
||||
typedef struct zvol_platform_ops {
|
||||
void (*zv_free)(zvol_state_t *);
|
||||
void (*zv_rename_minor)(zvol_state_t *, const char *);
|
||||
int (*zv_create_minor)(const char *);
|
||||
int (*zv_update_volsize)(zvol_state_t *, uint64_t);
|
||||
boolean_t (*zv_is_zvol)(const char *);
|
||||
void (*zv_clear_private)(zvol_state_t *);
|
||||
void (*zv_set_disk_ro)(zvol_state_t *, int flags);
|
||||
void (*zv_set_capacity)(zvol_state_t *, uint64_t capacity);
|
||||
} zvol_platform_ops_t;
|
||||
|
||||
void zvol_register_ops(const zvol_platform_ops_t *ops);
|
||||
|
||||
#endif
|
@ -33,3 +33,4 @@ $(MODULE)-objs += ../os/linux/zfs/zpl_file.o
|
||||
$(MODULE)-objs += ../os/linux/zfs/zpl_inode.o
|
||||
$(MODULE)-objs += ../os/linux/zfs/zpl_super.o
|
||||
$(MODULE)-objs += ../os/linux/zfs/zpl_xattr.o
|
||||
$(MODULE)-objs += ../os/linux/zfs/zvol_os.o
|
||||
|
1120
module/os/linux/zfs/zvol_os.c
Normal file
1120
module/os/linux/zfs/zvol_os.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -2856,7 +2856,7 @@ dmu_objset_find_impl(spa_t *spa, const char *name,
|
||||
* See comment above dmu_objset_find_impl().
|
||||
*/
|
||||
int
|
||||
dmu_objset_find(char *name, int func(const char *, void *), void *arg,
|
||||
dmu_objset_find(const char *name, int func(const char *, void *), void *arg,
|
||||
int flags)
|
||||
{
|
||||
spa_t *spa;
|
||||
|
@ -4136,7 +4136,7 @@ static int
|
||||
zfs_ioc_rollback(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
|
||||
{
|
||||
zfsvfs_t *zfsvfs;
|
||||
zvol_state_t *zv;
|
||||
zvol_state_handle_t *zv;
|
||||
char *target = NULL;
|
||||
int error;
|
||||
|
||||
@ -4861,7 +4861,7 @@ zfs_ioc_recv_impl(char *tofs, char *tosnap, char *origin, nvlist_t *recvprops,
|
||||
|
||||
if (error == 0) {
|
||||
zfsvfs_t *zfsvfs = NULL;
|
||||
zvol_state_t *zv = NULL;
|
||||
zvol_state_handle_t *zv = NULL;
|
||||
|
||||
if (getzfsvfs(tofs, &zfsvfs) == 0) {
|
||||
/* online recv */
|
||||
@ -7671,7 +7671,7 @@ _init(void)
|
||||
{
|
||||
int error;
|
||||
|
||||
if ((error = -zvol_init()) != 0)
|
||||
if ((error = zvol_init()) != 0)
|
||||
return (error);
|
||||
|
||||
spa_init(FREAD | FWRITE);
|
||||
|
1159
module/zfs/zvol.c
1159
module/zfs/zvol.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user