2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "lvm2cmdline.h"
19 #include "lib/label/label.h"
20 #include "lib/mm/memlock.h"
22 #include "tools/lvm2cmd.h"
26 #include <sys/resource.h>
28 void *cmdlib_lvm2_init(unsigned static_compile
, unsigned threaded
)
30 struct cmd_context
*cmd
;
32 init_is_static(static_compile
);
33 if (!(cmd
= init_lvm(1, 1, threaded
)))
36 if (!lvm_register_commands(cmd
, NULL
)) {
44 int lvm2_run(void *handle
, const char *cmdline
)
46 int argc
, ret
, oneoff
= 0;
47 char *args
[MAX_ARGS
], **argv
, *cmdcopy
= NULL
;
48 struct cmd_context
*cmd
;
54 if (!(handle
= lvm2_init())) {
55 log_error("Handle initialisation failed.");
60 cmd
= (struct cmd_context
*) handle
;
64 if (!(cmdcopy
= strdup(cmdline
))) {
65 log_error("Cmdline copy failed.");
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
;
77 log_error("No command supplied");
78 ret
= EINVALID_CMD_LINE
;
82 /* FIXME Temporary - move to libdevmapper */
84 if (!strcmp(cmdline
, "_memlock_inc")) {
85 memlock_inc_daemon(cmd
);
86 } else if (!strcmp(cmdline
, "_memlock_dec"))
87 memlock_dec_daemon(cmd
);
88 else if (!strcmp(cmdline
, "_dmeventd_thin_command")) {
89 if (setenv(cmdline
, find_config_tree_str(cmd
, dmeventd_thin_command_CFG
, NULL
), 1))
91 } else if (!strcmp(cmdline
, "_dmeventd_vdo_command")) {
92 if (setenv(cmdline
, find_config_tree_str(cmd
, dmeventd_vdo_command_CFG
, NULL
), 1))
95 ret
= lvm_run_command(cmd
, argc
, argv
);
106 void lvm2_disable_dmeventd_monitoring(void *handle
)
108 init_run_by_dmeventd((struct cmd_context
*) handle
);
111 void lvm2_log_level(void *handle
, int level
)
113 struct cmd_context
*cmd
= (struct cmd_context
*) handle
;
115 cmd
->default_settings
.verbose
= level
- VERBOSE_BASE_LEVEL
;
118 void lvm2_log_fn(lvm2_log_fn_t log_fn
)
123 void lvm2_exit(void *handle
)
125 struct cmd_context
*cmd
= (struct cmd_context
*) handle
;