2001-09-25 16:49:28 +04:00
/*
2004-03-30 23:35:44 +04:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2007-08-21 00:55:30 +04:00
* Copyright ( C ) 2004 - 2007 Red Hat , Inc . All rights reserved .
2001-09-25 16:49:28 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
2007-08-21 00:55:30 +04:00
* of the GNU Lesser General Public License v .2 .1 .
2004-03-30 23:35:44 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 23:35:44 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2001-09-25 16:49:28 +04:00
*/
# ifndef _LVM_DEVICE_H
# define _LVM_DEVICE_H
2002-11-18 17:01:16 +03:00
# include "uuid.h"
2005-10-17 03:03:59 +04:00
2003-07-05 02:34:56 +04:00
# include <fcntl.h>
2001-10-03 16:41:29 +04:00
2002-04-24 22:20:51 +04:00
# define DEV_ACCESSED_W 0x00000001 /* Device written to? */
2003-07-05 02:34:56 +04:00
# define DEV_REGULAR 0x00000002 /* Regular file? */
2005-10-17 03:03:59 +04:00
# define DEV_ALLOCED 0x00000004 /* dm_malloc used */
2004-12-10 19:01:35 +03:00
# define DEV_OPENED_RW 0x00000008 /* Opened RW */
2005-10-04 01:10:41 +04:00
# define DEV_OPENED_EXCL 0x00000010 /* Opened EXCL */
# define DEV_O_DIRECT 0x00000020 /* Use O_DIRECT */
# define DEV_O_DIRECT_TESTED 0x00000040 /* DEV_O_DIRECT is reliable */
2016-03-17 15:45:14 +03:00
# define DEV_OPEN_FAILURE 0x00000080 /* Has last open failed? */
2016-03-16 16:01:26 +03:00
# define DEV_USED_FOR_LV 0x00000100 /* Is device used for an LV */
# define DEV_ASSUMED_FOR_LV 0x00000200 /* Is device assumed for an LV */
2016-05-12 03:05:52 +03:00
# define DEV_NOT_O_NOATIME 0x00000400 /* Don't use O_NOATIME */
2002-04-24 22:20:51 +04:00
2018-01-05 17:24:10 +03:00
/*
2018-01-06 03:33:09 +03:00
* Standard format for callback functions .
* When provided , callback functions are called exactly once .
* If failed is set , data cannot be accessed .
2018-01-05 17:24:10 +03:00
*/
2018-01-21 18:41:49 +03:00
typedef void ( * lvm_callback_fn_t ) ( int failed , unsigned ioflags , void * context , const void * data ) ;
2018-01-05 17:24:10 +03:00
2014-12-12 14:55:41 +03:00
/*
* Support for external device info .
* Any new external device info source needs to be
* registered using EXT_REGISTER macro in dev - ext . c .
*/
2015-11-07 19:17:37 +03:00
typedef enum dev_ext_e {
2014-12-12 14:55:41 +03:00
DEV_EXT_NONE ,
DEV_EXT_UDEV ,
DEV_EXT_NUM
} dev_ext_t ;
struct dev_ext {
int enabled ;
dev_ext_t src ;
void * handle ;
} ;
2018-01-15 22:24:01 +03:00
/*
* All I / O is annotated with the reason it is performed .
*/
typedef enum dev_io_reason {
DEV_IO_SIGNATURES = 0 , /* Scanning device signatures */
DEV_IO_LABEL , /* LVM PV disk label */
DEV_IO_MDA_HEADER , /* Text format metadata area header */
DEV_IO_MDA_CONTENT , /* Text format metadata area content */
DEV_IO_MDA_EXTRA_HEADER , /* Header of any extra metadata areas on device */
DEV_IO_MDA_EXTRA_CONTENT , /* Content of any extra metadata areas on device */
DEV_IO_FMT1 , /* Original LVM1 metadata format */
DEV_IO_POOL , /* Pool metadata format */
DEV_IO_LV , /* Content written to an LV */
DEV_IO_LOG /* Logging messages */
} dev_io_reason_t ;
/*
* Is this I / O for a device ' s extra metadata area ?
*/
# define EXTRA_IO(reason) ((reason) == DEV_IO_MDA_EXTRA_HEADER || (reason) == DEV_IO_MDA_EXTRA_CONTENT)
# define DEV_DEVBUF(dev, reason) (EXTRA_IO((reason)) ? &(dev)->last_extra_devbuf : &(dev)->last_devbuf)
2018-01-15 22:32:59 +03:00
# define DEV_DEVBUF_DATA(dev, reason) ((char *) DEV_DEVBUF((dev), (reason))->buf + DEV_DEVBUF((dev), (reason))->data_offset)
2018-01-15 22:24:01 +03:00
2018-01-10 05:09:06 +03:00
struct device_area {
struct device * dev ;
uint64_t start ; /* Bytes */
uint64_t size ; /* Bytes */
} ;
struct device_buffer {
2018-01-15 22:32:59 +03:00
uint64_t data_offset ; /* Offset to start of requested data within buf */
2018-01-15 22:24:01 +03:00
void * malloc_address ; /* Start of allocated memory */
void * buf ; /* Aligned buffer that contains data within it */
struct device_area where ; /* Location of buf */
2018-01-15 22:38:18 +03:00
dev_io_reason_t reason ;
2018-01-15 22:24:01 +03:00
unsigned write : 1 ; /* 1 if write; 0 if read */
2018-01-10 05:09:06 +03:00
} ;
2001-10-03 16:41:29 +04:00
/*
* All devices in LVM will be represented by one of these .
* pointer comparisons are valid .
*/
struct device {
2014-05-29 11:41:03 +04:00
struct dm_list aliases ; /* struct dm_str_list */
2001-10-03 16:41:29 +04:00
dev_t dev ;
2001-11-14 13:01:52 +03:00
/* private */
int fd ;
2003-07-05 02:34:56 +04:00
int open_count ;
2010-10-13 19:40:38 +04:00
int error_count ;
int max_error_count ;
2013-12-12 14:26:35 +04:00
int phys_block_size ;
2004-12-10 19:01:35 +03:00
int block_size ;
2009-05-20 15:09:49 +04:00
int read_ahead ;
2002-04-24 22:20:51 +04:00
uint32_t flags ;
2016-01-15 18:41:27 +03:00
unsigned size_seqno ;
uint64_t size ;
2003-07-05 02:34:56 +04:00
uint64_t end ;
2008-11-04 01:14:30 +03:00
struct dm_list open_list ;
2014-12-12 14:55:41 +03:00
struct dev_ext ext ;
2018-01-10 05:09:06 +03:00
struct device_buffer last_devbuf ; /* Last data buffer read from the device */
struct device_buffer last_extra_devbuf ; /* Last data buffer read from the device for extra metadata area */
2002-11-18 17:01:16 +03:00
2016-03-16 16:01:26 +03:00
const char * vgid ; /* if device is an LV */
const char * lvid ; /* if device is an LV */
char pvid [ ID_LEN + 1 ] ; /* if device is a PV */
2005-04-06 17:47:41 +04:00
char _padding [ 7 ] ;
2001-10-03 16:41:29 +04:00
} ;
2002-01-15 13:24:48 +03:00
struct device_list {
2008-11-04 01:14:30 +03:00
struct dm_list list ;
2002-01-15 13:24:48 +03:00
struct device * dev ;
} ;
2014-12-12 14:55:41 +03:00
/*
* Support for external device info .
*/
const char * dev_ext_name ( struct device * dev ) ;
int dev_ext_enable ( struct device * dev , dev_ext_t src ) ;
int dev_ext_disable ( struct device * dev ) ;
struct dev_ext * dev_ext_get ( struct device * dev ) ;
int dev_ext_release ( struct device * dev ) ;
2016-01-15 18:41:27 +03:00
/*
* Increment current dev_size_seqno .
* This is used to control lifetime
* of cached device size .
*/
void dev_size_seqno_inc ( void ) ;
2001-10-03 16:41:29 +04:00
/*
2001-11-14 13:01:52 +03:00
* All io should use these routines .
2001-10-03 16:41:29 +04:00
*/
2013-12-12 14:26:35 +04:00
int dev_get_block_size ( struct device * dev , unsigned int * phys_block_size , unsigned int * block_size ) ;
2015-03-03 17:37:17 +03:00
int dev_get_size ( struct device * dev , uint64_t * size ) ;
2009-05-20 15:09:49 +04:00
int dev_get_read_ahead ( struct device * dev , uint32_t * read_ahead ) ;
2011-04-13 01:59:01 +04:00
int dev_discard_blocks ( struct device * dev , uint64_t offset_bytes , uint64_t size_bytes ) ;
2001-11-14 13:01:52 +03:00
2003-07-05 02:34:56 +04:00
/* Use quiet version if device number could change e.g. when opening LV */
int dev_open ( struct device * dev ) ;
int dev_open_quiet ( struct device * dev ) ;
2005-04-07 16:17:46 +04:00
int dev_open_flags ( struct device * dev , int flags , int direct , int quiet ) ;
2011-05-24 17:36:57 +04:00
int dev_open_readonly ( struct device * dev ) ;
int dev_open_readonly_buffered ( struct device * dev ) ;
int dev_open_readonly_quiet ( struct device * dev ) ;
2001-11-14 13:01:52 +03:00
int dev_close ( struct device * dev ) ;
2003-11-14 20:55:39 +03:00
int dev_close_immediate ( struct device * dev ) ;
2003-07-05 02:34:56 +04:00
void dev_close_all ( void ) ;
2005-10-04 01:10:41 +04:00
int dev_test_excl ( struct device * dev ) ;
2001-11-14 13:01:52 +03:00
2006-04-19 19:33:07 +04:00
int dev_fd ( struct device * dev ) ;
const char * dev_name ( const struct device * dev ) ;
2002-11-18 17:01:16 +03:00
2017-12-19 04:12:18 +03:00
/* Returns a read-only buffer */
2018-01-10 22:50:53 +03:00
const char * dev_read ( struct device * dev , uint64_t offset , size_t len , dev_io_reason_t reason ) ;
const char * dev_read_circular ( struct device * dev , uint64_t offset , size_t len ,
uint64_t offset2 , size_t len2 , dev_io_reason_t reason ) ;
2017-12-19 04:12:18 +03:00
2018-01-06 03:33:09 +03:00
/* Passes the data to dev_read_callback_fn */
int dev_read_callback ( struct device * dev , uint64_t offset , size_t len , dev_io_reason_t reason ,
2018-01-21 18:41:49 +03:00
unsigned ioflags , lvm_callback_fn_t dev_read_callback_fn , void * callback_context ) ;
2018-01-06 03:33:09 +03:00
2017-12-19 04:12:18 +03:00
/* Read data and copy it into a supplied private buffer. */
/* Only use for tiny reads or on unimportant code paths. */
int dev_read_buf ( struct device * dev , uint64_t offset , size_t len , dev_io_reason_t reason , void * retbuf ) ;
2017-12-05 02:18:56 +03:00
int dev_write ( struct device * dev , uint64_t offset , size_t len , dev_io_reason_t reason , void * buffer ) ;
int dev_append ( struct device * dev , size_t len , dev_io_reason_t reason , char * buffer ) ;
int dev_set ( struct device * dev , uint64_t offset , size_t len , dev_io_reason_t reason , int value ) ;
2003-07-05 02:34:56 +04:00
void dev_flush ( struct device * dev ) ;
struct device * dev_create_file ( const char * filename , struct device * dev ,
2014-05-29 11:41:03 +04:00
struct dm_str_list * alias , int use_malloc ) ;
2015-08-17 14:57:01 +03:00
void dev_destroy_file ( struct device * dev ) ;
2001-10-03 16:41:29 +04:00
2018-01-10 05:09:06 +03:00
void devbufs_release ( struct device * dev ) ;
2002-01-25 02:16:19 +03:00
/* Return a valid device name from the alias list; NULL otherwise */
2003-07-05 02:34:56 +04:00
const char * dev_name_confirmed ( struct device * dev , int quiet ) ;
2001-09-25 16:49:28 +04:00
2002-11-18 17:01:16 +03:00
# endif