Tizen 2.1 base
[external/device-mapper.git] / lib / commands / toolcontext.h
1 /*
2  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.  
3  * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
4  *
5  * This file is part of LVM2.
6  *
7  * This copyrighted material is made available to anyone wishing to use,
8  * modify, copy, or redistribute it subject to the terms and conditions
9  * of the GNU Lesser General Public License v.2.1.
10  *
11  * You should have received a copy of the GNU Lesser General Public License
12  * along with this program; if not, write to the Free Software Foundation,
13  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14  */
15
16 #ifndef _LVM_TOOLCONTEXT_H
17 #define _LVM_TOOLCONTEXT_H
18
19 #include "dev-cache.h"
20
21 #include <stdio.h>
22 #include <limits.h>
23
24 /*
25  * Config options that can be changed while commands are processed
26  */
27 struct config_info {
28         int debug;
29         int verbose;
30         int test;
31         int syslog;
32         int activation;
33         int suffix;
34         int archive;            /* should we archive ? */
35         int backup;             /* should we backup ? */
36         int read_ahead;         /* DM_READ_AHEAD_NONE or _AUTO */
37         int udev_rules;
38         int udev_sync;
39         int cache_vgmetadata;
40         const char *msg_prefix;
41         const char *fmt_name;
42         uint64_t unit_factor;
43         int cmd_name;           /* Show command name? */
44         mode_t umask;
45         char unit_type;
46         char _padding[1];
47 };
48
49 struct config_tree;
50 struct archive_params;
51 struct backup_params;
52 struct arg_values;
53
54 /* FIXME Split into tool & library contexts */
55 /* command-instance-related variables needed by library */
56 struct cmd_context {
57         struct dm_pool *libmem; /* For permanent config data */
58         struct dm_pool *mem;    /* Transient: Cleared between each command */
59
60         const struct format_type *fmt;  /* Current format to use by default */
61         struct format_type *fmt_backup; /* Format to use for backups */
62
63         struct dm_list formats; /* Available formats */
64         struct dm_list segtypes;        /* Available segment types */
65         const char *hostname;
66         const char *kernel_vsn;
67
68         unsigned rand_seed;
69         const char *cmd_line;
70         struct command *command;
71         char **argv;
72         struct arg_values *arg_values;
73         struct dm_list arg_value_groups;
74         unsigned is_long_lived:1;       /* Optimises persistent_filter handling */
75         unsigned handles_missing_pvs:1;
76         unsigned handles_unknown_segments:1;
77         unsigned partial_activation:1;
78         unsigned si_unit_consistency:1;
79         unsigned metadata_read_only:1;
80
81         unsigned independent_metadata_areas:1;  /* Active formats have MDAs outside PVs */
82
83         struct dev_filter *filter;
84         int dump_filter;        /* Dump filter when exiting? */
85
86         struct dm_list config_files;
87         int config_valid;
88         struct config_tree *cft;
89         struct config_tree *cft_override;
90         struct config_info default_settings;
91         struct config_info current_settings;
92
93         struct archive_params *archive_params;
94         struct backup_params *backup_params;
95         const char *stripe_filler;
96
97         /* List of defined tags */
98         struct dm_list tags;
99         int hosttags;
100
101         char system_dir[PATH_MAX];
102         char dev_dir[PATH_MAX];
103         char proc_dir[PATH_MAX];
104         char sysfs_dir[PATH_MAX]; /* FIXME Use global value instead. */
105 };
106
107 /*
108  * system_dir may be NULL to use the default value.
109  * The environment variable LVM_SYSTEM_DIR always takes precedence.
110  */
111 struct cmd_context *create_toolcontext(unsigned is_long_lived,
112                                        const char *system_dir);
113 void destroy_toolcontext(struct cmd_context *cmd);
114 int refresh_toolcontext(struct cmd_context *cmd);
115 int refresh_filters(struct cmd_context *cmd);
116 int config_files_changed(struct cmd_context *cmd);
117 int init_lvmcache_orphans(struct cmd_context *cmd);
118
119 struct format_type *get_format_by_name(struct cmd_context *cmd, const char *format);
120
121 #endif