xref: /netbsd-src/external/gpl2/lvm2/dist/liblvm/lvm_base.c (revision 7c604eea85b4f330dc75ffe65e947f4d73758aa0)
1*7c604eeaShaad /*	$NetBSD: lvm_base.c,v 1.1.1.1 2009/12/02 00:26:15 haad Exp $	*/
2*7c604eeaShaad 
3*7c604eeaShaad /*
4*7c604eeaShaad  * Copyright (C) 2008,2009 Red Hat, Inc. All rights reserved.
5*7c604eeaShaad  *
6*7c604eeaShaad  * This file is part of LVM2.
7*7c604eeaShaad  *
8*7c604eeaShaad  * This copyrighted material is made available to anyone wishing to use,
9*7c604eeaShaad  * modify, copy, or redistribute it subject to the terms and conditions
10*7c604eeaShaad  * of the GNU Lesser General Public License v.2.1.
11*7c604eeaShaad  *
12*7c604eeaShaad  * You should have received a copy of the GNU Lesser General Public License
13*7c604eeaShaad  * along with this program; if not, write to the Free Software Foundation,
14*7c604eeaShaad  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15*7c604eeaShaad  */
16*7c604eeaShaad 
17*7c604eeaShaad #include "lib.h"
18*7c604eeaShaad #include "lvm2app.h"
19*7c604eeaShaad #include "toolcontext.h"
20*7c604eeaShaad #include "locking.h"
21*7c604eeaShaad #include "lvm-version.h"
22*7c604eeaShaad 
lvm_library_get_version(void)23*7c604eeaShaad const char *lvm_library_get_version(void)
24*7c604eeaShaad {
25*7c604eeaShaad 	return LVM_VERSION;
26*7c604eeaShaad }
27*7c604eeaShaad 
lvm_init(const char * system_dir)28*7c604eeaShaad lvm_t lvm_init(const char *system_dir)
29*7c604eeaShaad {
30*7c604eeaShaad 	struct cmd_context *cmd;
31*7c604eeaShaad 
32*7c604eeaShaad 	/* FIXME: logging bound to handle
33*7c604eeaShaad 	 */
34*7c604eeaShaad 
35*7c604eeaShaad 	/* create context */
36*7c604eeaShaad 	/* FIXME: split create_toolcontext */
37*7c604eeaShaad 	cmd = create_toolcontext(1, system_dir);
38*7c604eeaShaad 	if (!cmd)
39*7c604eeaShaad 		return NULL;
40*7c604eeaShaad 
41*7c604eeaShaad 	if (stored_errno())
42*7c604eeaShaad 		return (lvm_t) cmd;
43*7c604eeaShaad 
44*7c604eeaShaad 	/*
45*7c604eeaShaad 	 * FIXME: if an non memory error occured, return the cmd (maybe some
46*7c604eeaShaad 	 * cleanup needed).
47*7c604eeaShaad 	 */
48*7c604eeaShaad 
49*7c604eeaShaad 	/* initialization from lvm_run_command */
50*7c604eeaShaad 	init_error_message_produced(0);
51*7c604eeaShaad 
52*7c604eeaShaad 	/* FIXME: locking_type config option needed? */
53*7c604eeaShaad 	/* initialize locking */
54*7c604eeaShaad 	if (!init_locking(-1, cmd)) {
55*7c604eeaShaad 		/* FIXME: use EAGAIN as error code here */
56*7c604eeaShaad 		log_error("Locking initialisation failed.");
57*7c604eeaShaad 		lvm_quit((lvm_t) cmd);
58*7c604eeaShaad 		return NULL;
59*7c604eeaShaad 	}
60*7c604eeaShaad 	/*
61*7c604eeaShaad 	 * FIXME: Use cmd->cmd_line as audit trail for liblvm calls.  Used in
62*7c604eeaShaad 	 * archive() call.  Possible example:
63*7c604eeaShaad 	 * cmd_line = "lvm_vg_create: vg1\nlvm_vg_extend vg1 /dev/sda1\n"
64*7c604eeaShaad 	 */
65*7c604eeaShaad 	cmd->cmd_line = (char *)"liblvm";
66*7c604eeaShaad 
67*7c604eeaShaad 	return (lvm_t) cmd;
68*7c604eeaShaad }
69*7c604eeaShaad 
lvm_quit(lvm_t libh)70*7c604eeaShaad void lvm_quit(lvm_t libh)
71*7c604eeaShaad {
72*7c604eeaShaad 	destroy_toolcontext((struct cmd_context *)libh);
73*7c604eeaShaad }
74*7c604eeaShaad 
lvm_config_reload(lvm_t libh)75*7c604eeaShaad int lvm_config_reload(lvm_t libh)
76*7c604eeaShaad {
77*7c604eeaShaad 	/* FIXME: re-init locking needed here? */
78*7c604eeaShaad 	if (!refresh_toolcontext((struct cmd_context *)libh))
79*7c604eeaShaad 		return -1;
80*7c604eeaShaad 	return 0;
81*7c604eeaShaad }
82*7c604eeaShaad 
83*7c604eeaShaad /*
84*7c604eeaShaad  * FIXME: submit a patch to document the --config option
85*7c604eeaShaad  */
lvm_config_override(lvm_t libh,const char * config_settings)86*7c604eeaShaad int lvm_config_override(lvm_t libh, const char *config_settings)
87*7c604eeaShaad {
88*7c604eeaShaad 	struct cmd_context *cmd = (struct cmd_context *)libh;
89*7c604eeaShaad 	if (override_config_tree_from_string(cmd, config_settings))
90*7c604eeaShaad 		return -1;
91*7c604eeaShaad 	return 0;
92*7c604eeaShaad }
93*7c604eeaShaad 
lvm_errno(lvm_t libh)94*7c604eeaShaad int lvm_errno(lvm_t libh)
95*7c604eeaShaad {
96*7c604eeaShaad 	return stored_errno();
97*7c604eeaShaad }
98*7c604eeaShaad 
lvm_errmsg(lvm_t libh)99*7c604eeaShaad const char *lvm_errmsg(lvm_t libh)
100*7c604eeaShaad {
101*7c604eeaShaad 	return stored_errmsg();
102*7c604eeaShaad }
103