FreeBSD ZFS
The Zettabyte File System
Data Structures | Defines | Typedefs | Functions | Variables

zvol.c File Reference

ZFS volume emulation driver. More...

#include <sys/types.h>
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/errno.h>
#include <sys/uio.h>
#include <sys/bio.h>
#include <sys/buf.h>
#include <sys/kmem.h>
#include <sys/conf.h>
#include <sys/cmn_err.h>
#include <sys/stat.h>
#include <sys/zap.h>
#include <sys/spa.h>
#include <sys/zio.h>
#include <sys/dmu_traverse.h>
#include <sys/dnode.h>
#include <sys/dsl_dataset.h>
#include <sys/dsl_prop.h>
#include <sys/dkio.h>
#include <sys/byteorder.h>
#include <sys/sunddi.h>
#include <sys/dirent.h>
#include <sys/policy.h>
#include <sys/fs/zfs.h>
#include <sys/zfs_ioctl.h>
#include <sys/zil.h>
#include <sys/refcount.h>
#include <sys/zfs_znode.h>
#include <sys/zfs_rlock.h>
#include <sys/vdev_impl.h>
#include <sys/zvol.h>
#include <sys/zil_impl.h>
#include <geom/geom.h>
#include "zfs_namecheck.h"
Include dependency graph for zvol.c:

Go to the source code of this file.

Data Structures

struct  zvol_extent
struct  zvol_state
 The in-core state of each volume. More...
struct  maparg
 extent mapping arg More...

Defines

#define ZVOL_DUMPSIZE   "dumpsize"
#define ZVOL_RDONLY   0x1
#define ZVOL_DUMPIFIED   0x2
#define ZVOL_EXCL   0x4
#define ZVOL_WCE   0x8

Typedefs

typedef struct zvol_extent zvol_extent_t
typedef struct zvol_state zvol_state_t
 The in-core state of each volume.

Functions

 DECLARE_GEOM_CLASS (zfs_zvol_class, zfs_zvol)
int zfs_set_prop_nvlist (const char *, zprop_source_t, nvlist_t *, nvlist_t **)
 This function is best effort.
static int zvol_remove_zv (zvol_state_t *zv)
 Remove minor node for the specified volume.
static int zvol_get_data (void *arg, lr_write_t *lr, char *buf, zio_t *zio)
 Get data to generate a TX_WRITE intent log record.
static int zvol_dumpify (zvol_state_t *zv)
static int zvol_dump_fini (zvol_state_t *zv)
static int zvol_dump_init (zvol_state_t *zv, boolean_t resize)
static zvol_state_tzvol_geom_create (const char *name)
static void zvol_geom_run (zvol_state_t *zv)
static void zvol_geom_destroy (zvol_state_t *zv)
static int zvol_geom_access (struct g_provider *pp, int acr, int acw, int ace)
static void zvol_geom_start (struct bio *bp)
static void zvol_geom_worker (void *arg)
static void zvol_size_changed (zvol_state_t *zv)
int zvol_check_volsize (uint64_t volsize, uint64_t blocksize)
int zvol_check_volblocksize (uint64_t volblocksize)
int zvol_get_stats (objset_t *os, nvlist_t *nv)
static zvol_state_tzvol_minor_lookup (const char *name)
static int zvol_map_block (spa_t *spa, zilog_t *zilog, const blkptr_t *bp, arc_buf_t *pbuf, const zbookmark_t *zb, const dnode_phys_t *dnp, void *arg)
static void zvol_free_extents (zvol_state_t *zv)
static int zvol_get_lbas (zvol_state_t *zv)
void zvol_create_cb (objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
static int zvol_replay_write (zvol_state_t *zv, lr_write_t *lr, boolean_t byteswap)
 Replay a TX_WRITE ZIL transaction that didn't get committed after a system failure.
static int zvol_replay_err (zvol_state_t *zv, lr_t *lr, boolean_t byteswap)
int zvol_create_minor (const char *name)
 Create a minor node (plus a whole lot more) for the specified volume.
int zvol_remove_minor (const char *name)
int zvol_first_open (zvol_state_t *zv)
void zvol_last_close (zvol_state_t *zv)
int zvol_update_volsize (objset_t *os, uint64_t volsize)
void zvol_remove_minors (const char *name)
int zvol_set_volsize (const char *name, major_t maj, uint64_t volsize)
static int zvol_open (struct g_provider *pp, int flag, int count)
static int zvol_close (struct g_provider *pp, int flag, int count)
static void zvol_get_done (zgd_t *zgd, int error)
static void zvol_log_write (zvol_state_t *zv, dmu_tx_t *tx, offset_t off, ssize_t resid, boolean_t sync)
 handles synchronous writes using TX_WRITE ZIL transactions.
int zvol_strategy (struct bio *bp)
int zvol_busy (void)
void zvol_init (void)
void zvol_fini (void)
boolean_t dataset_name_hidden (const char *name)
static int zvol_create_snapshots (objset_t *os, const char *name)
int zvol_create_minors (const char *name)
static void zvol_rename_minor (struct g_geom *gp, const char *newname)
void zvol_rename_minors (const char *oldname, const char *newname)

Variables

struct g_class zfs_zvol_class
void * zfsdev_state
 The zfsdev_state structure is protected by spa_namespace_lock from being modified while it's being used, e.g.
static char * zvol_tag = "zvol_tag"
static uint32_t zvol_minors
int zvol_maxphys = DMU_MAX_ACCESS/2
 zvol maximum transfer size in one DMU tx.
zil_replay_func_tzvol_replay_vector [TX_MAX_TYPE]
 Callback vectors for replaying records.
ssize_t zvol_immediate_write_sz = 32768

Detailed Description

ZFS volume emulation driver.

Makes a DMU object look like a volume of arbitrary size, up to 2^64 bytes. Volumes are accessed through the symbolic links named:

/dev/zvol/dsk/<pool_name>/<dataset_name> /dev/zvol/rdsk/<pool_name>/<dataset_name>

These links are created by the /dev filesystem (sdev_zvolops.c). Volumes are persistent through reboot. No user command needs to be run before opening and using a device.

FreeBSD notes. On FreeBSD ZVOLs are simply GEOM providers like any other storage device in the system.

Definition in file zvol.c.


Define Documentation

#define ZVOL_DUMPIFIED   0x2

Definition at line 137 of file zvol.c.

#define ZVOL_DUMPSIZE   "dumpsize"

Definition at line 102 of file zvol.c.

#define ZVOL_EXCL   0x4

Definition at line 138 of file zvol.c.

#define ZVOL_RDONLY   0x1

Definition at line 136 of file zvol.c.

#define ZVOL_WCE   0x8

Definition at line 139 of file zvol.c.


Typedef Documentation

typedef struct zvol_extent zvol_extent_t
typedef struct zvol_state zvol_state_t

The in-core state of each volume.


Function Documentation

boolean_t dataset_name_hidden ( const char *  name)

Definition at line 1975 of file zfs_ioctl.c.

DECLARE_GEOM_CLASS ( zfs_zvol_class  ,
zfs_zvol   
)
int zfs_set_prop_nvlist ( const char *  dsname,
zprop_source_t  source,
nvlist_t *  nvl,
nvlist_t **  errlist 
)

This function is best effort.

If it fails to set any of the given properties, it continues to set as many as it can and returns the first error encountered. If the caller provides a non-NULL errlist, it also gives the complete list of names of all the properties it failed to set along with the corresponding error numbers. The caller is responsible for freeing the returned errlist.

If every property is set successfully, zero is returned and the list pointed at by errlist is NULL.

Definition at line 2281 of file zfs_ioctl.c.

int zvol_busy ( void  )

Definition at line 1737 of file zvol.c.

int zvol_check_volblocksize ( uint64_t  volblocksize)

Definition at line 204 of file zvol.c.

int zvol_check_volsize ( uint64_t  volsize,
uint64_t  blocksize 
)

Definition at line 188 of file zvol.c.

static int zvol_close ( struct g_provider *  pp,
int  flag,
int  count 
) [static]

Definition at line 959 of file zvol.c.

void zvol_create_cb ( objset_t os,
void *  arg,
cred_t *  cr,
dmu_tx_t tx 
)

Definition at line 345 of file zvol.c.

int zvol_create_minor ( const char *  name)

Create a minor node (plus a whole lot more) for the specified volume.

Definition at line 473 of file zvol.c.

int zvol_create_minors ( const char *  name)

Definition at line 2208 of file zvol.c.

static int zvol_create_snapshots ( objset_t os,
const char *  name 
) [static]

Definition at line 2168 of file zvol.c.

static int zvol_dump_fini ( zvol_state_t zv) [static]
static int zvol_dump_init ( zvol_state_t zv,
boolean_t  resize 
) [static]
static int zvol_dumpify ( zvol_state_t zv) [static]
void zvol_fini ( void  )

Definition at line 1751 of file zvol.c.

int zvol_first_open ( zvol_state_t zv)

Definition at line 643 of file zvol.c.

static void zvol_free_extents ( zvol_state_t zv) [static]

Definition at line 310 of file zvol.c.

static int zvol_geom_access ( struct g_provider *  pp,
int  acr,
int  acw,
int  ace 
) [static]

Definition at line 2050 of file zvol.c.

static zvol_state_t * zvol_geom_create ( const char *  name) [static]

Definition at line 1992 of file zvol.c.

static void zvol_geom_destroy ( zvol_state_t zv) [static]

Definition at line 2028 of file zvol.c.

static void zvol_geom_run ( zvol_state_t zv) [static]

Definition at line 2016 of file zvol.c.

static void zvol_geom_start ( struct bio *  bp) [static]

Definition at line 2100 of file zvol.c.

static void zvol_geom_worker ( void *  arg) [static]

Definition at line 2127 of file zvol.c.

static int zvol_get_data ( void *  arg,
lr_write_t lr,
char *  buf,
zio_t zio 
) [static]

Get data to generate a TX_WRITE intent log record.

Definition at line 1020 of file zvol.c.

static void zvol_get_done ( zgd_t zgd,
int  error 
) [static]

Definition at line 1003 of file zvol.c.

static int zvol_get_lbas ( zvol_state_t zv) [static]

Definition at line 321 of file zvol.c.

int zvol_get_stats ( objset_t os,
nvlist_t *  nv 
)

Definition at line 215 of file zvol.c.

void zvol_init ( void  )

Definition at line 1743 of file zvol.c.

void zvol_last_close ( zvol_state_t zv)

Definition at line 683 of file zvol.c.

static void zvol_log_write ( zvol_state_t zv,
dmu_tx_t tx,
offset_t  off,
ssize_t  resid,
boolean_t  sync 
) [static]

handles synchronous writes using TX_WRITE ZIL transactions.

We store data in the log buffers if it's small enough. Otherwise we will later flush the data out via dmu_sync().

Definition at line 1082 of file zvol.c.

static int zvol_map_block ( spa_t spa,
zilog_t zilog,
const blkptr_t bp,
arc_buf_t pbuf,
const zbookmark_t zb,
const dnode_phys_t dnp,
void *  arg 
) [static]

Definition at line 270 of file zvol.c.

static zvol_state_t* zvol_minor_lookup ( const char *  name) [static]

Definition at line 238 of file zvol.c.

static int zvol_open ( struct g_provider *  pp,
int  flag,
int  count 
) [static]

Definition at line 890 of file zvol.c.

int zvol_remove_minor ( const char *  name)

Definition at line 625 of file zvol.c.

void zvol_remove_minors ( const char *  name)

Definition at line 771 of file zvol.c.

static int zvol_remove_zv ( zvol_state_t zv) [static]

Remove minor node for the specified volume.

Definition at line 598 of file zvol.c.

static void zvol_rename_minor ( struct g_geom *  gp,
const char *  newname 
) [static]

Definition at line 2272 of file zvol.c.

void zvol_rename_minors ( const char *  oldname,
const char *  newname 
)

Definition at line 2298 of file zvol.c.

static int zvol_replay_err ( zvol_state_t zv,
lr_t lr,
boolean_t  byteswap 
) [static]

Definition at line 422 of file zvol.c.

static int zvol_replay_write ( zvol_state_t zv,
lr_write_t lr,
boolean_t  byteswap 
) [static]

Replay a TX_WRITE ZIL transaction that didn't get committed after a system failure.

Definition at line 384 of file zvol.c.

int zvol_set_volsize ( const char *  name,
major_t  maj,
uint64_t  volsize 
)

Definition at line 804 of file zvol.c.

static void zvol_size_changed ( zvol_state_t zv) [static]

Definition at line 162 of file zvol.c.

int zvol_strategy ( struct bio *  bp)

Definition at line 1235 of file zvol.c.

int zvol_update_volsize ( objset_t os,
uint64_t  volsize 
)

Definition at line 745 of file zvol.c.


Variable Documentation

struct g_class zfs_zvol_class
Initial value:
 {
        .name = "ZFS::ZVOL",
        .version = G_VERSION,
}

Definition at line 86 of file zvol.c.

void* zfsdev_state

The zfsdev_state structure is protected by spa_namespace_lock from being modified while it's being used, e.g.

an open that comes in before a create finishes. It's also protected from temporary opens of the dataset so that, e.g., an open doesn't get a spurious EBUSY.

Definition at line 99 of file zvol.c.

ssize_t zvol_immediate_write_sz = 32768

Definition at line 1074 of file zvol.c.

int zvol_maxphys = DMU_MAX_ACCESS/2

zvol maximum transfer size in one DMU tx.

Definition at line 144 of file zvol.c.

uint32_t zvol_minors [static]

Definition at line 104 of file zvol.c.

char* zvol_tag = "zvol_tag" [static]

Definition at line 100 of file zvol.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines