Files
mirror_zfs/include/sys/zvol_impl.h
T

144 lines
4.9 KiB
C
Raw Normal View History

2025-01-04 11:04:27 +11:00
// SPDX-License-Identifier: CDDL-1.0
2019-09-25 09:20:30 -07:00
/*
* 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
2022-07-11 23:16:13 +02:00
* or https://opensource.org/licenses/CDDL-1.0.
2019-09-25 09:20:30 -07:00
* 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
*/
/*
* Copyright (c) 2024, 2025, Klara, Inc.
*/
2019-09-25 09:20:30 -07:00
#ifndef _SYS_ZVOL_IMPL_H
#define _SYS_ZVOL_IMPL_H
#include <sys/zfs_context.h>
2024-07-18 12:37:43 +10:00
#define ZVOL_RDONLY (1<<0) /* zvol is readonly (writes rejected) */
#define ZVOL_WRITTEN_TO (1<<1) /* zvol has been written to (needs flush) */
#define ZVOL_EXCL (1<<2) /* zvol has O_EXCL client right now */
#define ZVOL_REMOVING (1<<3) /* zvol waiting to remove minor */
2019-09-25 09:20:30 -07:00
/*
* 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 */
2020-11-17 09:50:52 -08:00
uint32_t zv_volmode; /* volmode */
2019-09-25 09:20:30 -07:00
zilog_t *zv_zilog; /* ZIL handle */
2019-11-01 10:37:33 -07:00
zfs_rangelock_t zv_rangelock; /* for range locking */
2019-09-25 09:20:30 -07:00
dnode_t *zv_dn; /* dnode hold */
2020-06-05 20:17:02 -04:00
dataset_kstats_t zv_kstat; /* zvol kstats */
2019-09-25 09:20:30 -07:00
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 */
kcondvar_t zv_removing_cv; /* ready to remove minor */
list_node_t zv_remove_node; /* node on removal list */
2019-09-25 09:20:30 -07:00
struct zvol_state_os *zv_zso; /* private platform state */
boolean_t zv_threading; /* volthreading property */
2019-09-25 09:20:30 -07:00
} zvol_state_t;
/*
* zvol taskqs
*/
typedef struct zv_taskq {
uint_t tqs_cnt;
taskq_t **tqs_taskq;
} zv_taskq_t;
typedef struct zv_request_stack {
zvol_state_t *zv;
struct bio *bio;
#ifdef __linux__
struct request *rq;
#endif
} zv_request_t;
typedef struct zv_request_task {
zv_request_t zvr;
taskq_ent_t ent;
} zv_request_task_t;
/*
* Switch taskq at multiple of 512 MB offset. This can be set to a lower value
* to utilize more threads for small files but may affect prefetch hits.
*/
#define ZVOL_TASKQ_OFFSET_SHIFT 29
2019-09-25 09:20:30 -07:00
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)])
2022-01-15 00:37:55 +01:00
extern zil_replay_func_t *const zvol_replay_vector[TX_MAX_TYPE];
2019-09-25 09:20:30 -07:00
extern unsigned int zvol_inhibit_dev;
extern unsigned int zvol_prefetch_bytes;
extern unsigned int zvol_volmode;
extern unsigned int zvol_threads;
extern unsigned int zvol_num_taskqs;
extern unsigned int zvol_request_sync;
extern zv_taskq_t zvol_taskqs;
2019-09-25 09:20:30 -07:00
/*
* 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_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,
2023-10-30 17:51:56 -04:00
uint64_t len);
2019-09-25 09:20:30 -07:00
void zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, uint64_t offset,
2023-10-30 17:51:56 -04:00
uint64_t size, boolean_t commit);
int zvol_get_data(void *arg, uint64_t arg2, lr_write_t *lr, char *buf,
struct lwb *lwb, zio_t *zio);
2019-09-25 09:20:30 -07:00
int zvol_init_impl(void);
void zvol_fini_impl(void);
2020-11-17 09:50:52 -08:00
void zvol_wait_close(zvol_state_t *zv);
int zvol_clone_range(zvol_state_handle_t *, uint64_t,
zvol_state_handle_t *, uint64_t, uint64_t);
void zvol_log_clone_range(zilog_t *zilog, dmu_tx_t *tx, int txtype,
uint64_t off, uint64_t len, uint64_t blksz, const blkptr_t *bps,
size_t nbps);
zv_request_task_t *zv_request_task_create(zv_request_t zvr);
void zv_request_task_free(zv_request_task_t *task);
2019-09-25 09:20:30 -07:00
/*
* platform dependent functions exported to platform independent code
*/
2022-02-07 19:24:38 +01:00
void zvol_os_free(zvol_state_t *zv);
int zvol_os_rename_minor(zvol_state_t *zv, const char *newname);
2022-02-07 19:24:38 +01:00
int zvol_os_create_minor(const char *name);
int zvol_os_update_volsize(zvol_state_t *zv, uint64_t volsize);
boolean_t zvol_os_is_zvol(const char *path);
void zvol_os_remove_minor(zvol_state_t *zv);
2022-02-07 19:24:38 +01:00
void zvol_os_set_disk_ro(zvol_state_t *zv, int flags);
void zvol_os_set_capacity(zvol_state_t *zv, uint64_t capacity);
2019-09-25 09:20:30 -07:00
#endif