2 * Copyright (C) 2008,2009 Red Hat, Inc. All rights reserved.
4 * This file is part of LVM2.
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU Lesser General Public License v.2.1.
10 * You should have received a copy of the GNU Lesser General Public License
11 * along with this program; if not, write to the Free Software Foundation,
12 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #include "toolcontext.h"
18 #include "lvm-version.h"
19 #include "metadata-exported.h"
22 const char *lvm_library_get_version(void)
27 lvm_t lvm_init(const char *system_dir)
29 struct cmd_context *cmd;
31 /* FIXME: logging bound to handle
35 /* FIXME: split create_toolcontext */
36 /* FIXME: make all globals configurable */
37 cmd = create_toolcontext(0, system_dir);
45 * FIXME: if an non memory error occured, return the cmd (maybe some
49 /* initialization from lvm_run_command */
50 init_error_message_produced(0);
52 /* FIXME: locking_type config option needed? */
53 /* initialize locking */
54 if (!init_locking(-1, cmd, 0)) {
55 /* FIXME: use EAGAIN as error code here */
56 lvm_quit((lvm_t) cmd);
60 * FIXME: Use cmd->cmd_line as audit trail for liblvm calls. Used in
61 * archive() call. Possible example:
62 * cmd_line = "lvm_vg_create: vg1\nlvm_vg_extend vg1 /dev/sda1\n"
64 cmd->cmd_line = "liblvm";
69 void lvm_quit(lvm_t libh)
71 destroy_toolcontext((struct cmd_context *)libh);
74 int lvm_config_reload(lvm_t libh)
76 /* FIXME: re-init locking needed here? */
77 if (!refresh_toolcontext((struct cmd_context *)libh))
83 * FIXME: submit a patch to document the --config option
85 int lvm_config_override(lvm_t libh, const char *config_settings)
87 struct cmd_context *cmd = (struct cmd_context *)libh;
88 if (override_config_tree_from_string(cmd, config_settings))
93 int lvm_errno(lvm_t libh)
95 return stored_errno();
98 const char *lvm_errmsg(lvm_t libh)
100 return stored_errmsg();
103 const char *lvm_vgname_from_pvid(lvm_t libh, const char *pvid)
105 struct cmd_context *cmd = (struct cmd_context *)libh;
108 if (!id_read_format(&id, pvid)) {
109 log_error(INTERNAL_ERROR "Unable to convert uuid");
112 return find_vgname_from_pvid(cmd, (char *)id.uuid);
115 const char *lvm_vgname_from_device(lvm_t libh, const char *device)
117 struct cmd_context *cmd = (struct cmd_context *)libh;
118 return find_vgname_from_pvname(cmd, device);