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 .
2015-04-10 15:08:19 +03:00
* Copyright ( C ) 2004 - 2015 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
*/
2002-04-24 22:20:51 +04:00
# ifndef _LVM_TOOLS_H
# define _LVM_TOOLS_H
2001-09-25 16:49:28 +04:00
2015-07-06 19:30:18 +03:00
# include "tool.h"
2002-12-20 02:25:55 +03:00
2008-10-30 20:27:28 +03:00
# include "lvm-logging.h"
2015-07-06 19:30:18 +03:00
2002-11-18 17:04:08 +03:00
# include "activate.h"
2004-03-26 15:25:15 +03:00
# include "archiver.h"
2003-07-05 02:34:56 +04:00
# include "lvmcache.h"
2012-02-23 17:11:07 +04:00
# include "lvmetad.h"
2015-03-05 23:00:44 +03:00
# include "lvmlockd.h"
2013-03-05 20:48:29 +04:00
# include "lvm-version.h"
2001-10-01 19:14:39 +04:00
# include "config.h"
2002-12-20 02:25:55 +03:00
# include "defaults.h"
2001-10-01 19:14:39 +04:00
# include "dev-cache.h"
# include "device.h"
# include "display.h"
2001-09-25 16:49:28 +04:00
# include "errors.h"
2007-07-18 19:38:58 +04:00
# include "metadata-exported.h"
2002-02-11 18:42:34 +03:00
# include "locking.h"
2005-10-17 21:56:27 +04:00
# include "lvm-exec.h"
2002-11-18 17:04:08 +03:00
# include "lvm-file.h"
2014-05-01 23:07:17 +04:00
# include "lvm-signal.h"
2002-11-18 17:04:08 +03:00
# include "lvm-string.h"
2004-09-16 22:40:56 +04:00
# include "segtype.h"
2004-03-08 20:19:15 +03:00
# include "str_list.h"
2002-02-11 23:50:53 +03:00
# include "toolcontext.h"
2002-11-18 17:04:08 +03:00
# include "toollib.h"
2016-02-22 18:42:03 +03:00
# include "lvmnotify.h"
2002-01-07 14:12:11 +03:00
2002-11-18 17:04:08 +03:00
# include <ctype.h>
2002-01-07 14:12:11 +03:00
# include <sys/types.h>
2001-09-25 16:49:28 +04:00
# define CMD_LEN 256
# define MAX_ARGS 64
/* command functions */
2002-02-12 00:00:35 +03:00
typedef int ( * command_fn ) ( struct cmd_context * cmd , int argc , char * * argv ) ;
2001-09-25 16:49:28 +04:00
2002-02-11 23:50:53 +03:00
# define xx(a, b...) int a(struct cmd_context *cmd, int argc, char **argv);
2001-09-25 16:49:28 +04:00
# include "commands.h"
# undef xx
/* define the enums for the command line switches */
enum {
2016-06-17 12:03:14 +03:00
# define arg(a, b, c, d, e, f) a ,
2001-09-25 16:49:28 +04:00
# include "args.h"
2001-12-17 19:58:17 +03:00
# undef arg
2001-09-25 16:49:28 +04:00
} ;
2010-11-11 20:29:05 +03:00
# define ARG_COUNTABLE 0x00000001 /* E.g. -vvvv */
# define ARG_GROUPABLE 0x00000002 /* E.g. --addtag */
2002-01-10 19:47:04 +03:00
2010-11-11 20:29:05 +03:00
struct arg_values {
2006-05-10 01:23:51 +04:00
unsigned count ;
2001-09-25 16:49:28 +04:00
char * value ;
2002-12-20 02:25:55 +03:00
int32_t i_value ;
uint32_t ui_value ;
2002-12-12 23:55:49 +03:00
int64_t i64_value ;
uint64_t ui64_value ;
2001-11-10 01:01:04 +03:00
sign_t sign ;
2010-11-30 14:53:31 +03:00
percent_type_t percent ;
2010-04-29 05:38:12 +04:00
/* void *ptr; // Currently not used. */
2001-09-25 16:49:28 +04:00
} ;
2010-11-11 20:29:05 +03:00
/* a global table of possible arguments */
struct arg_props {
const char short_arg ;
char _padding [ 7 ] ;
const char * long_arg ;
int ( * fn ) ( struct cmd_context * cmd , struct arg_values * av ) ;
uint32_t flags ;
2016-06-17 12:03:14 +03:00
uint32_t prio ;
2010-11-11 20:29:05 +03:00
} ;
struct arg_value_group_list {
struct dm_list list ;
struct arg_values arg_values [ 0 ] ;
2016-06-17 12:03:14 +03:00
uint32_t prio ;
2010-11-11 20:29:05 +03:00
} ;
2010-10-25 15:20:54 +04:00
# define CACHE_VGMETADATA 0x00000001
# define PERMITTED_READ_ONLY 0x00000002
2015-02-13 17:58:51 +03:00
/* Process all VGs if none specified on the command line. */
2014-10-02 01:58:00 +04:00
# define ALL_VGS_IS_DEFAULT 0x00000004
2014-10-02 01:58:23 +04:00
/* Process all devices with --all if none are specified on the command line. */
# define ENABLE_ALL_DEVS 0x00000008
2015-12-02 00:50:14 +03:00
/* Command may try to interpret a vgname arg as a uuid. */
# define ALLOW_UUID_AS_NAME 0x00000010
2015-03-05 23:00:44 +03:00
/* Command needs a shared lock on a VG; it only reads the VG. */
# define LOCKD_VG_SH 0x00000020
commands: add new NO_METADATA_PROCESSING flag to selected commands
When a command is flagged with NO_METADATA_PROCESSING flag, it means
such command does not process any metadata and hence it doens't require
lvmetad, lvmpolld and it can get away with no locking too. These are
mostly simple commands (like lvmconfig/dumpconfig, version, types,
segtypes and other builtin commands that do not process metadata
in any way).
At first, when lvm command is executed, create toolcontext without
initializing connections (lvmetad,lvmpolld) and without initializing
filters (which depend on connections init). Instead, delay this
initialization until we know we need this. That is, until the
lvm_run_command fn is called in which we know what the actual
command to run is and hence we can avoid any connection, filter
or locking initiliazation for commands that would not make use
of it anyway.
For all the other create_toolcontext calls, we keep the original
behaviour - the filters and connections are initialized together
with the toolcontext.
2015-07-30 11:48:28 +03:00
/* Command does not process any metadata. */
# define NO_METADATA_PROCESSING 0x00000040
2015-12-01 23:09:01 +03:00
/* Command wants to scan for new devices and force labels to be read from them all. */
# define REQUIRES_FULL_LABEL_SCAN 0x00000080
2016-02-16 23:15:24 +03:00
/* Command must use all specified arg names and fail if all cannot be used. */
# define MUST_USE_ALL_ARGS 0x00000100
2016-01-29 01:40:26 +03:00
/* Command wants to control the device scan for lvmetad itself. */
# define NO_LVMETAD_AUTOSCAN 0x00000200
lvmcache: process duplicate PVs directly
Previously, duplicate PVs were processed as a side effect
of processing the "chosen" PV in lvmcache. The duplicate
PV would be hacked into lvmcache temporarily in place of
the chosen PV.
In the old way, we had to always process the "chosen" PV
device, even if a duplicate of it was named on the command
line. This meant we were processing a different device than
was asked for. This could be worked around by naming
multiple duplicate devs on the command line in which case
they were swapped in and out of lvmcache for processing.
Now, the duplicate devs are processed directly in their
own processing loop. This means we can remove the old
hacks related to processing dups as a side effect of
processing the chosen device. We can now simply process
the device that was named on the command line.
When the same PVID exists on two or more devices, one device
is preferred and used in the VG, and the others are duplicates
and are not used in the VG. The preferred device exists in
lvmcache as usual. The duplicates exist in a specical list
of unused duplicate devices.
The duplicate devs have the "d" attribute and the "duplicate"
reporting field displays "duplicate" for them.
'pvs' warns about duplicates, but the formal output only
includes the single preferred PV.
'pvs -a' has the same warnings, and the duplicate devs are
included in the output.
'pvs <path>' has the same warnings, and displays the named
device, whether it is preferred or a duplicate.
2016-02-11 21:37:36 +03:00
/* Command should process unused duplicate devices. */
# define ENABLE_DUPLICATE_DEVS 0x00000400
2016-06-03 17:56:48 +03:00
/* Command does not accept tags as args. */
# define DISALLOW_TAG_ARGS 0x00000800
2014-10-02 01:58:23 +04:00
2001-11-13 17:17:50 +03:00
/* a register of the lvm commands */
struct command {
2002-02-12 00:00:35 +03:00
const char * name ;
const char * desc ;
const char * usage ;
command_fn fn ;
2001-11-13 17:17:50 +03:00
2008-04-03 01:23:39 +04:00
unsigned flags ;
2002-02-12 00:00:35 +03:00
int num_args ;
int * valid_args ;
2001-11-13 17:17:50 +03:00
} ;
2001-09-25 16:49:28 +04:00
void usage ( const char * name ) ;
/* the argument verify/normalise functions */
2010-11-11 20:29:05 +03:00
int yes_no_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
2012-06-27 15:48:31 +04:00
int activation_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
2016-04-25 14:39:30 +03:00
int cachemode_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
2012-08-08 00:24:41 +04:00
int discards_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
2014-10-22 23:02:29 +04:00
int mirrorlog_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
2010-11-11 20:29:05 +03:00
int size_kb_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
int size_mb_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
2014-10-30 16:52:37 +03:00
int size_mb_arg_with_percent ( struct cmd_context * cmd , struct arg_values * av ) ;
2010-11-11 20:29:05 +03:00
int int_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
int int_arg_with_sign ( struct cmd_context * cmd , struct arg_values * av ) ;
int int_arg_with_sign_and_percent ( struct cmd_context * cmd , struct arg_values * av ) ;
int major_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
int minor_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
int string_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
int tag_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
int permission_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
int metadatatype_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
int units_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
int segtype_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
int alloc_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
2015-03-05 23:00:44 +03:00
int locktype_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
2010-11-11 20:29:05 +03:00
int readahead_arg ( struct cmd_context * cmd , struct arg_values * av ) ;
int metadatacopies_arg ( struct cmd_context * cmd __attribute__ ( ( unused ) ) , struct arg_values * av ) ;
2001-09-25 16:49:28 +04:00
/* we use the enums to access the switches */
2009-11-03 18:50:42 +03:00
unsigned arg_count ( const struct cmd_context * cmd , int a ) ;
unsigned arg_is_set ( const struct cmd_context * cmd , int a ) ;
2014-07-18 23:56:37 +04:00
int arg_from_list_is_set ( const struct cmd_context * cmd , const char * err_found , . . . ) ;
int arg_outside_list_is_set ( const struct cmd_context * cmd , const char * err_found , . . . ) ;
2014-10-15 17:06:42 +04:00
int arg_from_list_is_negative ( const struct cmd_context * cmd , const char * err_found , . . . ) ;
int arg_from_list_is_zero ( const struct cmd_context * cmd , const char * err_found , . . . ) ;
2013-03-22 23:20:33 +04:00
const char * arg_long_option_name ( int a ) ;
2014-09-19 16:29:12 +04:00
const char * arg_value ( const struct cmd_context * cmd , int a ) ;
const char * arg_str_value ( const struct cmd_context * cmd , int a , const char * def ) ;
int32_t arg_int_value ( const struct cmd_context * cmd , int a , const int32_t def ) ;
int32_t first_grouped_arg_int_value ( const struct cmd_context * cmd , int a , const int32_t def ) ;
uint32_t arg_uint_value ( const struct cmd_context * cmd , int a , const uint32_t def ) ;
int64_t arg_int64_value ( const struct cmd_context * cmd , int a , const int64_t def ) ;
uint64_t arg_uint64_value ( const struct cmd_context * cmd , int a , const uint64_t def ) ;
const void * arg_ptr_value ( const struct cmd_context * cmd , int a , const void * def ) ;
sign_t arg_sign_value ( const struct cmd_context * cmd , int a , const sign_t def ) ;
percent_type_t arg_percent_value ( const struct cmd_context * cmd , int a , const percent_type_t def ) ;
2006-04-19 19:33:07 +04:00
int arg_count_increment ( struct cmd_context * cmd , int a ) ;
2010-11-11 20:29:05 +03:00
unsigned grouped_arg_count ( const struct arg_values * av , int a ) ;
unsigned grouped_arg_is_set ( const struct arg_values * av , int a ) ;
const char * grouped_arg_str_value ( const struct arg_values * av , int a , const char * def ) ;
2012-03-06 06:30:49 +04:00
int32_t grouped_arg_int_value ( const struct arg_values * av , int a , const int32_t def ) ;
2010-11-11 20:29:05 +03:00
2006-04-19 19:33:07 +04:00
const char * command_name ( struct cmd_context * cmd ) ;
2001-10-08 22:44:22 +04:00
2015-04-10 15:08:19 +03:00
int pvmove_poll ( struct cmd_context * cmd , const char * pv_name , const char * uuid ,
const char * vg_name , const char * lv_name , unsigned background ) ;
2009-06-01 18:43:27 +04:00
int lvconvert_poll ( struct cmd_context * cmd , struct logical_volume * lv , unsigned background ) ;
2003-05-06 16:20:11 +04:00
2011-07-08 23:42:11 +04:00
int mirror_remove_missing ( struct cmd_context * cmd ,
struct logical_volume * lv , int force ) ;
2012-06-27 16:59:34 +04:00
int vgchange_activate ( struct cmd_context * cmd , struct volume_group * vg ,
activation_change_t activate ) ;
2014-10-07 19:45:45 +04:00
2016-01-07 17:17:08 +03:00
int vgchange_background_polling ( struct cmd_context * cmd , struct volume_group * vg ) ;
2001-10-06 01:39:30 +04:00
# endif