2009-02-24 16:03:45 +03:00
/*
* Copyright ( C ) 2008 , 2009 Red Hat , Inc . All rights reserved .
*
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v .2 .1 .
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
# include "lib.h"
# include "toolcontext.h"
# include "locking.h"
2009-07-29 22:38:27 +04:00
# include "lvm-version.h"
2010-05-19 15:53:12 +04:00
# include "metadata-exported.h"
2010-12-15 02:20:58 +03:00
# include "lvm2app.h"
2009-02-24 16:03:45 +03:00
2009-07-28 15:03:28 +04:00
const char * lvm_library_get_version ( void )
{
return LVM_VERSION ;
}
2009-07-28 13:16:18 +04:00
lvm_t lvm_init ( const char * system_dir )
2009-02-24 16:03:45 +03:00
{
struct cmd_context * cmd ;
/* FIXME: logging bound to handle
*/
2011-06-15 17:29:48 +04:00
if ( ! udev_init_library_context ( ) )
stack ;
2009-02-24 16:03:45 +03:00
/* create context */
/* FIXME: split create_toolcontext */
2010-03-17 17:45:28 +03:00
/* FIXME: make all globals configurable */
2012-08-26 03:15:45 +04:00
cmd = create_toolcontext ( 0 , system_dir , 0 , 0 ) ;
2009-02-24 16:03:45 +03:00
if ( ! cmd )
return NULL ;
2009-07-16 04:36:59 +04:00
if ( stored_errno ( ) )
return ( lvm_t ) cmd ;
2009-02-24 16:03:45 +03:00
/*
* FIXME : if an non memory error occured , return the cmd ( maybe some
* cleanup needed ) .
*/
/* initialization from lvm_run_command */
init_error_message_produced ( 0 ) ;
/* FIXME: locking_type config option needed? */
/* initialize locking */
2010-05-06 15:15:55 +04:00
if ( ! init_locking ( - 1 , cmd , 0 ) ) {
2009-02-24 16:03:45 +03:00
/* FIXME: use EAGAIN as error code here */
2009-07-28 13:16:18 +04:00
lvm_quit ( ( lvm_t ) cmd ) ;
2009-02-24 16:03:45 +03:00
return NULL ;
}
2009-07-14 07:01:18 +04:00
/*
* FIXME : Use cmd - > cmd_line as audit trail for liblvm calls . Used in
* archive ( ) call . Possible example :
* cmd_line = " lvm_vg_create: vg1 \n lvm_vg_extend vg1 /dev/sda1 \n "
*/
2010-12-20 16:28:04 +03:00
cmd - > cmd_line = " liblvm " ;
2009-02-24 16:03:45 +03:00
return ( lvm_t ) cmd ;
}
2009-07-28 13:16:18 +04:00
void lvm_quit ( lvm_t libh )
2009-02-24 16:03:45 +03:00
{
destroy_toolcontext ( ( struct cmd_context * ) libh ) ;
2011-06-15 17:29:48 +04:00
udev_fin_library_context ( ) ;
2009-02-24 16:03:45 +03:00
}
2009-07-27 14:18:51 +04:00
int lvm_config_reload ( lvm_t libh )
2009-02-24 16:03:45 +03:00
{
/* FIXME: re-init locking needed here? */
2009-07-28 01:02:35 +04:00
if ( ! refresh_toolcontext ( ( struct cmd_context * ) libh ) )
2009-07-27 00:28:59 +04:00
return - 1 ;
return 0 ;
2009-02-24 16:03:45 +03:00
}
2009-07-16 04:36:59 +04:00
2009-07-28 17:16:40 +04:00
/*
* FIXME : submit a patch to document the - - config option
*/
2009-07-28 01:02:17 +04:00
int lvm_config_override ( lvm_t libh , const char * config_settings )
{
struct cmd_context * cmd = ( struct cmd_context * ) libh ;
2012-10-16 12:07:27 +04:00
if ( ! override_config_tree_from_string ( cmd , config_settings ) )
2009-07-28 01:02:17 +04:00
return - 1 ;
return 0 ;
}
2012-07-31 18:18:01 +04:00
int lvm_config_find_bool ( lvm_t libh , const char * config_path , int fail )
{
2013-03-05 20:00:43 +04:00
struct cmd_context * cmd = ( struct cmd_context * ) libh ;
return dm_config_tree_find_bool ( cmd - > cft , config_path , fail ) ;
2012-07-31 18:18:01 +04:00
}
2009-07-16 04:36:59 +04:00
int lvm_errno ( lvm_t libh )
{
return stored_errno ( ) ;
}
const char * lvm_errmsg ( lvm_t libh )
{
return stored_errmsg ( ) ;
}
2010-05-19 15:53:12 +04:00
const char * lvm_vgname_from_pvid ( lvm_t libh , const char * pvid )
{
struct cmd_context * cmd = ( struct cmd_context * ) libh ;
2010-05-19 16:12:47 +04:00
struct id id ;
2010-05-19 15:53:12 +04:00
2010-05-19 16:12:47 +04:00
if ( ! id_read_format ( & id , pvid ) ) {
2010-05-19 15:53:12 +04:00
log_error ( INTERNAL_ERROR " Unable to convert uuid " ) ;
return NULL ;
}
2010-05-19 16:12:47 +04:00
return find_vgname_from_pvid ( cmd , ( char * ) id . uuid ) ;
2010-05-19 15:53:12 +04:00
}
const char * lvm_vgname_from_device ( lvm_t libh , const char * device )
{
struct cmd_context * cmd = ( struct cmd_context * ) libh ;
return find_vgname_from_pvname ( cmd , device ) ;
}
2012-10-11 19:25:14 +04:00
float lvm_percent_to_float ( percent_t v )
{
return percent_to_float ( v ) ;
}