]>
Commit | Line | Data |
---|---|---|
6711231a | 1 | /* |
67cdbd7e | 2 | * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. |
ec6a6fbe | 3 | * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved. |
6711231a AK |
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 | |
be684599 | 9 | * of the GNU Lesser General Public License v.2.1. |
6711231a | 10 | * |
be684599 | 11 | * You should have received a copy of the GNU Lesser General Public License |
6711231a | 12 | * along with this program; if not, write to the Free Software Foundation, |
fcbef05a | 13 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
6711231a AK |
14 | */ |
15 | ||
16 | #include "tools.h" | |
dfe3eb12 | 17 | |
6711231a | 18 | #include "lvm2cmdline.h" |
7f97c7ea JT |
19 | #include "lib/label/label.h" |
20 | #include "lib/mm/memlock.h" | |
6711231a | 21 | |
7f97c7ea | 22 | #include "tools/lvm2cmd.h" |
6711231a | 23 | |
6711231a AK |
24 | #include <sys/stat.h> |
25 | #include <time.h> | |
26 | #include <sys/resource.h> | |
27 | ||
bd272e3b | 28 | void *cmdlib_lvm2_init(unsigned static_compile, unsigned threaded) |
6711231a AK |
29 | { |
30 | struct cmd_context *cmd; | |
31 | ||
02961979 | 32 | init_is_static(static_compile); |
bd272e3b | 33 | if (!(cmd = init_lvm(1, 1, threaded))) |
6711231a AK |
34 | return NULL; |
35 | ||
b36ab8a0 WG |
36 | if (!lvm_register_commands(cmd, NULL)) { |
37 | free(cmd); | |
298b11ae | 38 | return NULL; |
b36ab8a0 | 39 | } |
1e2420bc | 40 | |
6711231a AK |
41 | return (void *) cmd; |
42 | } | |
43 | ||
44 | int lvm2_run(void *handle, const char *cmdline) | |
45 | { | |
46 | int argc, ret, oneoff = 0; | |
47 | char *args[MAX_ARGS], **argv, *cmdcopy = NULL; | |
48 | struct cmd_context *cmd; | |
49 | ||
50 | argv = args; | |
51 | ||
52 | if (!handle) { | |
53 | oneoff = 1; | |
54 | if (!(handle = lvm2_init())) { | |
55 | log_error("Handle initialisation failed."); | |
56 | return ECMD_FAILED; | |
57 | } | |
58 | } | |
59 | ||
60 | cmd = (struct cmd_context *) handle; | |
61 | ||
62 | cmd->argv = argv; | |
63 | ||
d5da55ed | 64 | if (!(cmdcopy = strdup(cmdline))) { |
6711231a AK |
65 | log_error("Cmdline copy failed."); |
66 | ret = ECMD_FAILED; | |
67 | goto out; | |
68 | } | |
69 | ||
70 | if (lvm_split(cmdcopy, &argc, argv, MAX_ARGS) == MAX_ARGS) { | |
71 | log_error("Too many arguments. Limit is %d.", MAX_ARGS); | |
72 | ret = EINVALID_CMD_LINE; | |
73 | goto out; | |
74 | } | |
75 | ||
76 | if (!argc) { | |
77 | log_error("No command supplied"); | |
78 | ret = EINVALID_CMD_LINE; | |
79 | goto out; | |
80 | } | |
81 | ||
6032a223 | 82 | /* FIXME Temporary - move to libdevmapper */ |
65b19284 | 83 | ret = ECMD_PROCESSED; |
d2c4ce25 | 84 | if (!strcmp(cmdline, "_memlock_inc")) { |
18b82048 | 85 | memlock_inc_daemon(cmd); |
d2c4ce25 | 86 | } else if (!strcmp(cmdline, "_memlock_dec")) |
18b82048 | 87 | memlock_dec_daemon(cmd); |
d80f9a10 ZK |
88 | else if (!strcmp(cmdline, "_dmeventd_thin_command")) { |
89 | if (setenv(cmdline, find_config_tree_str(cmd, dmeventd_thin_command_CFG, NULL), 1)) | |
90 | ret = ECMD_FAILED; | |
faa12688 ZK |
91 | } else if (!strcmp(cmdline, "_dmeventd_vdo_command")) { |
92 | if (setenv(cmdline, find_config_tree_str(cmd, dmeventd_vdo_command_CFG, NULL), 1)) | |
93 | ret = ECMD_FAILED; | |
d80f9a10 | 94 | } else |
6032a223 | 95 | ret = lvm_run_command(cmd, argc, argv); |
6711231a AK |
96 | |
97 | out: | |
d5da55ed | 98 | free(cmdcopy); |
6711231a AK |
99 | |
100 | if (oneoff) | |
101 | lvm2_exit(handle); | |
102 | ||
103 | return ret; | |
104 | } | |
105 | ||
4a7f2155 ZK |
106 | void lvm2_disable_dmeventd_monitoring(void *handle) |
107 | { | |
108 | init_run_by_dmeventd((struct cmd_context *) handle); | |
61cf772e PR |
109 | } |
110 | ||
6711231a AK |
111 | void lvm2_log_level(void *handle, int level) |
112 | { | |
113 | struct cmd_context *cmd = (struct cmd_context *) handle; | |
114 | ||
115 | cmd->default_settings.verbose = level - VERBOSE_BASE_LEVEL; | |
6711231a AK |
116 | } |
117 | ||
118 | void lvm2_log_fn(lvm2_log_fn_t log_fn) | |
119 | { | |
120 | init_log_fn(log_fn); | |
121 | } | |
122 | ||
123 | void lvm2_exit(void *handle) | |
124 | { | |
125 | struct cmd_context *cmd = (struct cmd_context *) handle; | |
126 | ||
127 | lvm_fin(cmd); | |
128 | } |