]> sourceware.org Git - lvm2.git/blob - liblvm/lvm_base.c
man: document allocation process in lvm.8
[lvm2.git] / liblvm / lvm_base.c
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"
16 #include "toolcontext.h"
17 #include "locking.h"
18 #include "lvm-version.h"
19 #include "metadata-exported.h"
20 #include "lvm2app.h"
21
22 const char *lvm_library_get_version(void)
23 {
24 return LVM_VERSION;
25 }
26
27 lvm_t lvm_init(const char *system_dir)
28 {
29 struct cmd_context *cmd;
30
31 /* FIXME: logging bound to handle
32 */
33
34 if (!udev_init_library_context())
35 stack;
36
37 /* create context */
38 /* FIXME: split create_toolcontext */
39 /* FIXME: make all globals configurable */
40 cmd = create_toolcontext(0, system_dir, 1, 0);
41 if (!cmd)
42 return NULL;
43
44 if (stored_errno())
45 return (lvm_t) cmd;
46
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 */
57 if (!init_locking(-1, cmd, 0)) {
58 /* FIXME: use EAGAIN as error code here */
59 lvm_quit((lvm_t) cmd);
60 return NULL;
61 }
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 */
67 cmd->cmd_line = "liblvm";
68
69 return (lvm_t) cmd;
70 }
71
72 void lvm_quit(lvm_t libh)
73 {
74 destroy_toolcontext((struct cmd_context *)libh);
75 udev_fin_library_context();
76 }
77
78 int lvm_config_reload(lvm_t libh)
79 {
80 /* FIXME: re-init locking needed here? */
81 if (!refresh_toolcontext((struct cmd_context *)libh))
82 return -1;
83 return 0;
84 }
85
86 /*
87 * FIXME: submit a patch to document the --config option
88 */
89 int 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
97 int 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
102 int lvm_errno(lvm_t libh)
103 {
104 return stored_errno();
105 }
106
107 const char *lvm_errmsg(lvm_t libh)
108 {
109 return stored_errmsg();
110 }
111
112 const char *lvm_vgname_from_pvid(lvm_t libh, const char *pvid)
113 {
114 struct cmd_context *cmd = (struct cmd_context *)libh;
115 struct id id;
116
117 if (!id_read_format(&id, pvid)) {
118 log_error(INTERNAL_ERROR "Unable to convert uuid");
119 return NULL;
120 }
121 return find_vgname_from_pvid(cmd, (char *)id.uuid);
122 }
123
124 const 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.040093 seconds and 5 git commands to generate.