]>
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 AK |
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 | #include "tools.h" | |
17 | #include "lvm2cmdline.h" | |
18 | #include "label.h" | |
d838a1e3 | 19 | #include "memlock.h" |
ec6a6fbe | 20 | #include "lvm-version.h" |
6711231a | 21 | |
6711231a AK |
22 | #include "lvm2cmd.h" |
23 | ||
24 | #include <signal.h> | |
25 | #include <syslog.h> | |
26 | #include <libgen.h> | |
27 | #include <sys/stat.h> | |
28 | #include <time.h> | |
29 | #include <sys/resource.h> | |
30 | ||
02961979 | 31 | void *cmdlib_lvm2_init(unsigned static_compile) |
6711231a AK |
32 | { |
33 | struct cmd_context *cmd; | |
34 | ||
35 | lvm_register_commands(); | |
36 | ||
02961979 DW |
37 | init_is_static(static_compile); |
38 | if (!(cmd = init_lvm())) | |
6711231a AK |
39 | return NULL; |
40 | ||
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 | ||
64 | if (!(cmdcopy = dm_strdup(cmdline))) { | |
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; |
6032a223 | 84 | if (!strcmp(cmdline, "_memlock_inc")) |
18b82048 | 85 | memlock_inc_daemon(cmd); |
65b19284 | 86 | else if (!strcmp(cmdline, "_memlock_dec")) |
18b82048 | 87 | memlock_dec_daemon(cmd); |
6032a223 AK |
88 | else |
89 | ret = lvm_run_command(cmd, argc, argv); | |
6711231a AK |
90 | |
91 | out: | |
92 | dm_free(cmdcopy); | |
93 | ||
94 | if (oneoff) | |
95 | lvm2_exit(handle); | |
96 | ||
97 | return ret; | |
98 | } | |
99 | ||
61cf772e PR |
100 | void lvm2_disable_dmeventd_monitoring(void *handle) { |
101 | init_dmeventd_monitor(DMEVENTD_MONITOR_IGNORE); | |
102 | } | |
103 | ||
6711231a AK |
104 | void lvm2_log_level(void *handle, int level) |
105 | { | |
106 | struct cmd_context *cmd = (struct cmd_context *) handle; | |
107 | ||
108 | cmd->default_settings.verbose = level - VERBOSE_BASE_LEVEL; | |
6711231a AK |
109 | } |
110 | ||
111 | void lvm2_log_fn(lvm2_log_fn_t log_fn) | |
112 | { | |
113 | init_log_fn(log_fn); | |
114 | } | |
115 | ||
116 | void lvm2_exit(void *handle) | |
117 | { | |
118 | struct cmd_context *cmd = (struct cmd_context *) handle; | |
119 | ||
120 | lvm_fin(cmd); | |
121 | } |