]> sourceware.org Git - lvm2.git/blame - liblvm/lvm_base.c
man: document allocation process in lvm.8
[lvm2.git] / liblvm / lvm_base.c
CommitLineData
5f4b7a26
TW
1/*
2 * Copyright (C) 2008,2009 Red Hat, Inc. All rights reserved.
3 *
4 * This file is part of LVM2.
5 *
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.
9 *
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
13 */
14
15#include "lib.h"
5f4b7a26
TW
16#include "toolcontext.h"
17#include "locking.h"
e3d384af 18#include "lvm-version.h"
0d23926e 19#include "metadata-exported.h"
8961b1d5 20#include "lvm2app.h"
5f4b7a26 21
f7bc94ac
DW
22const char *lvm_library_get_version(void)
23{
24 return LVM_VERSION;
25}
26
9c2e73fd 27lvm_t lvm_init(const char *system_dir)
5f4b7a26
TW
28{
29 struct cmd_context *cmd;
30
31 /* FIXME: logging bound to handle
32 */
33
53dd32f4
PR
34 if (!udev_init_library_context())
35 stack;
36
5f4b7a26
TW
37 /* create context */
38 /* FIXME: split create_toolcontext */
917c57e7 39 /* FIXME: make all globals configurable */
59475375 40 cmd = create_toolcontext(0, system_dir, 1, 0);
5f4b7a26
TW
41 if (!cmd)
42 return NULL;
d917192f
AK
43
44 if (stored_errno())
45 return (lvm_t) cmd;
46
5f4b7a26
TW
47 /*
48 * FIXME: if an non memory error occured, return the cmd (maybe some
49 * cleanup needed).
50 */
51
52 /* initialization from lvm_run_command */
53 init_error_message_produced(0);
54
55 /* FIXME: locking_type config option needed? */
56 /* initialize locking */
d50c6d4b 57 if (!init_locking(-1, cmd, 0)) {
5f4b7a26 58 /* FIXME: use EAGAIN as error code here */
9c2e73fd 59 lvm_quit((lvm_t) cmd);
5f4b7a26
TW
60 return NULL;
61 }
9c5a7b04
DW
62 /*
63 * FIXME: Use cmd->cmd_line as audit trail for liblvm calls. Used in
64 * archive() call. Possible example:
65 * cmd_line = "lvm_vg_create: vg1\nlvm_vg_extend vg1 /dev/sda1\n"
66 */
66781f5d 67 cmd->cmd_line = "liblvm";
5f4b7a26
TW
68
69 return (lvm_t) cmd;
70}
71
9c2e73fd 72void lvm_quit(lvm_t libh)
5f4b7a26 73{
5f4b7a26 74 destroy_toolcontext((struct cmd_context *)libh);
53dd32f4 75 udev_fin_library_context();
5f4b7a26
TW
76}
77
f6b1eaf7 78int lvm_config_reload(lvm_t libh)
5f4b7a26
TW
79{
80 /* FIXME: re-init locking needed here? */
b3417a32 81 if (!refresh_toolcontext((struct cmd_context *)libh))
f864285b
DW
82 return -1;
83 return 0;
5f4b7a26 84}
d917192f 85
88e3ced7
DW
86/*
87 * FIXME: submit a patch to document the --config option
88 */
dce56c97
DW
89int lvm_config_override(lvm_t libh, const char *config_settings)
90{
91 struct cmd_context *cmd = (struct cmd_context *)libh;
92 if (override_config_tree_from_string(cmd, config_settings))
93 return -1;
94 return 0;
95}
96
f64f22e2
PR
97int lvm_config_find_bool(lvm_t libh, const char *config_path, int fail)
98{
99 return find_config_tree_bool((struct cmd_context *)libh, config_path, fail);
100}
101
d917192f
AK
102int lvm_errno(lvm_t libh)
103{
104 return stored_errno();
105}
106
107const char *lvm_errmsg(lvm_t libh)
108{
109 return stored_errmsg();
110}
0d23926e
DW
111
112const char *lvm_vgname_from_pvid(lvm_t libh, const char *pvid)
113{
114 struct cmd_context *cmd = (struct cmd_context *)libh;
8f4a9e6a 115 struct id id;
0d23926e 116
8f4a9e6a 117 if (!id_read_format(&id, pvid)) {
0d23926e
DW
118 log_error(INTERNAL_ERROR "Unable to convert uuid");
119 return NULL;
120 }
8f4a9e6a 121 return find_vgname_from_pvid(cmd, (char *)id.uuid);
0d23926e
DW
122}
123
124const char *lvm_vgname_from_device(lvm_t libh, const char *device)
125{
126 struct cmd_context *cmd = (struct cmd_context *)libh;
127 return find_vgname_from_pvname(cmd, device);
128}
This page took 0.057407 seconds and 5 git commands to generate.