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