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.
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.
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]
22 #ifndef _SYS_ZVOL_IMPL_H
23 #define _SYS_ZVOL_IMPL_H
25 #include <sys/zfs_context.h>
27 #define ZVOL_RDONLY 0x1
29 * Whether the zvol has been written to (as opposed to ZVOL_RDONLY, which
30 * specifies whether or not the zvol _can_ be written to)
32 #define ZVOL_WRITTEN_TO 0x2
34 #define ZVOL_DUMPIFIED 0x4
39 * The in-core state of each volume.
41 typedef struct zvol_state
{
42 char zv_name
[MAXNAMELEN
]; /* name */
43 uint64_t zv_volsize
; /* advertised space */
44 uint64_t zv_volblocksize
; /* volume block size */
45 objset_t
*zv_objset
; /* objset handle */
46 uint32_t zv_flags
; /* ZVOL_* flags */
47 uint32_t zv_open_count
; /* open counts */
48 uint32_t zv_changed
; /* disk changed */
49 zilog_t
*zv_zilog
; /* ZIL handle */
50 zfs_rangelock_t zv_rangelock
; /* for range locking */
51 dnode_t
*zv_dn
; /* dnode hold */
52 dataset_kstats_t zv_kstat
; /* zvol kstats */
53 list_node_t zv_next
; /* next zvol_state_t linkage */
54 uint64_t zv_hash
; /* name hash */
55 struct hlist_node zv_hlink
; /* hash link */
56 kmutex_t zv_state_lock
; /* protects zvol_state_t */
57 atomic_t zv_suspend_ref
; /* refcount for suspend */
58 krwlock_t zv_suspend_lock
; /* suspend lock */
59 struct zvol_state_os
*zv_zso
; /* private platform state */
63 extern list_t zvol_state_list
;
64 extern krwlock_t zvol_state_lock
;
65 #define ZVOL_HT_SIZE 1024
66 extern struct hlist_head
*zvol_htable
;
67 #define ZVOL_HT_HEAD(hash) (&zvol_htable[(hash) & (ZVOL_HT_SIZE-1)])
68 extern zil_replay_func_t
*zvol_replay_vector
[TX_MAX_TYPE
];
70 extern unsigned int zvol_volmode
;
71 extern unsigned int zvol_inhibit_dev
;
74 * platform independent functions exported to platform code
76 zvol_state_t
*zvol_find_by_name_hash(const char *name
,
77 uint64_t hash
, int mode
);
78 int zvol_first_open(zvol_state_t
*zv
, boolean_t readonly
);
79 uint64_t zvol_name_hash(const char *name
);
80 void zvol_remove_minors_impl(const char *name
);
81 void zvol_last_close(zvol_state_t
*zv
);
82 void zvol_insert(zvol_state_t
*zv
);
83 void zvol_log_truncate(zvol_state_t
*zv
, dmu_tx_t
*tx
, uint64_t off
,
84 uint64_t len
, boolean_t sync
);
85 void zvol_log_write(zvol_state_t
*zv
, dmu_tx_t
*tx
, uint64_t offset
,
86 uint64_t size
, int sync
);
87 int zvol_get_data(void *arg
, lr_write_t
*lr
, char *buf
, struct lwb
*lwb
,
89 int zvol_init_impl(void);
90 void zvol_fini_impl(void);
93 * platform dependent functions exported to platform independent code
95 typedef struct zvol_platform_ops
{
96 void (*zv_free
)(zvol_state_t
*);
97 void (*zv_rename_minor
)(zvol_state_t
*, const char *);
98 int (*zv_create_minor
)(const char *);
99 int (*zv_update_volsize
)(zvol_state_t
*, uint64_t);
100 boolean_t (*zv_is_zvol
)(const char *);
101 void (*zv_clear_private
)(zvol_state_t
*);
102 void (*zv_set_disk_ro
)(zvol_state_t
*, int flags
);
103 void (*zv_set_capacity
)(zvol_state_t
*, uint64_t capacity
);
104 } zvol_platform_ops_t
;
106 void zvol_register_ops(const zvol_platform_ops_t
*ops
);