4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
7 * This file is part of LVM2.
9 * This copyrighted material is made available to anyone wishing to use,
10 * modify, copy, or redistribute it subject to the terms and conditions
11 * of the GNU Lesser General Public License v.2.1.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "lvm2cmdline.h"
22 #include "lvm-version.h"
31 #include <sys/resource.h>
33 void *cmdlib_lvm2_init(unsigned static_compile
)
35 struct cmd_context
*cmd
;
37 lvm_register_commands();
39 init_is_static(static_compile
);
40 if (!(cmd
= init_lvm()))
46 int lvm2_run(void *handle
, const char *cmdline
)
48 int argc
, ret
, oneoff
= 0;
49 char *args
[MAX_ARGS
], **argv
, *cmdcopy
= NULL
;
50 struct cmd_context
*cmd
;
56 if (!(handle
= lvm2_init())) {
57 log_error("Handle initialisation failed.");
62 cmd
= (struct cmd_context
*) handle
;
66 if (!(cmdcopy
= dm_strdup(cmdline
))) {
67 log_error("Cmdline copy failed.");
72 if (lvm_split(cmdcopy
, &argc
, argv
, MAX_ARGS
) == MAX_ARGS
) {
73 log_error("Too many arguments. Limit is %d.", MAX_ARGS
);
74 ret
= EINVALID_CMD_LINE
;
79 log_error("No command supplied");
80 ret
= EINVALID_CMD_LINE
;
84 /* FIXME Temporary - move to libdevmapper */
86 if (!strcmp(cmdline
, "_memlock_inc"))
88 else if (!strcmp(cmdline
, "_memlock_dec"))
91 ret
= lvm_run_command(cmd
, argc
, argv
);
102 void lvm2_log_level(void *handle
, int level
)
104 struct cmd_context
*cmd
= (struct cmd_context
*) handle
;
106 cmd
->default_settings
.verbose
= level
- VERBOSE_BASE_LEVEL
;
111 void lvm2_log_fn(lvm2_log_fn_t log_fn
)
116 void lvm2_exit(void *handle
)
118 struct cmd_context
*cmd
= (struct cmd_context
*) handle
;