]>
Commit | Line | Data |
---|---|---|
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 |
22 | const char *lvm_library_get_version(void) |
23 | { | |
24 | return LVM_VERSION; | |
25 | } | |
26 | ||
9c2e73fd | 27 | lvm_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 | 72 | void 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 | 78 | int 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 |
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 | ||
d917192f AK |
97 | int lvm_errno(lvm_t libh) |
98 | { | |
99 | return stored_errno(); | |
100 | } | |
101 | ||
102 | const char *lvm_errmsg(lvm_t libh) | |
103 | { | |
104 | return stored_errmsg(); | |
105 | } | |
0d23926e DW |
106 | |
107 | const char *lvm_vgname_from_pvid(lvm_t libh, const char *pvid) | |
108 | { | |
109 | struct cmd_context *cmd = (struct cmd_context *)libh; | |
8f4a9e6a | 110 | struct id id; |
0d23926e | 111 | |
8f4a9e6a | 112 | if (!id_read_format(&id, pvid)) { |
0d23926e DW |
113 | log_error(INTERNAL_ERROR "Unable to convert uuid"); |
114 | return NULL; | |
115 | } | |
8f4a9e6a | 116 | return find_vgname_from_pvid(cmd, (char *)id.uuid); |
0d23926e DW |
117 | } |
118 | ||
119 | const char *lvm_vgname_from_device(lvm_t libh, const char *device) | |
120 | { | |
121 | struct cmd_context *cmd = (struct cmd_context *)libh; | |
122 | return find_vgname_from_pvname(cmd, device); | |
123 | } |