2009-02-24 13:03:45 +00: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 18:38:27 +00:00
# include "lvm-version.h"
2010-05-19 11:53:12 +00:00
# include "metadata-exported.h"
2010-12-14 23:20:58 +00:00
# include "lvm2app.h"
2009-02-24 13:03:45 +00:00
2009-07-28 11:03:28 +00:00
const char * lvm_library_get_version ( void )
{
return LVM_VERSION ;
}
2009-07-28 09:16:18 +00:00
lvm_t lvm_init ( const char * system_dir )
2009-02-24 13:03:45 +00:00
{
struct cmd_context * cmd ;
/* FIXME: logging bound to handle
*/
2011-06-15 13:29:48 +00:00
if ( ! udev_init_library_context ( ) )
stack ;
2009-02-24 13:03:45 +00:00
/* create context */
/* FIXME: split create_toolcontext */
2010-03-17 14:45:28 +00:00
/* FIXME: make all globals configurable */
2012-08-26 00:15:45 +01:00
cmd = create_toolcontext ( 0 , system_dir , 0 , 0 ) ;
2009-02-24 13:03:45 +00:00
if ( ! cmd )
return NULL ;
2009-07-16 00:36:59 +00:00
if ( stored_errno ( ) )
return ( lvm_t ) cmd ;
2009-02-24 13:03:45 +00: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 11:15:55 +00:00
if ( ! init_locking ( - 1 , cmd , 0 ) ) {
2009-02-24 13:03:45 +00:00
/* FIXME: use EAGAIN as error code here */
2009-07-28 09:16:18 +00:00
lvm_quit ( ( lvm_t ) cmd ) ;
2009-02-24 13:03:45 +00:00
return NULL ;
}
2009-07-14 03:01:18 +00: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 13:28:04 +00:00
cmd - > cmd_line = " liblvm " ;
2009-02-24 13:03:45 +00:00
return ( lvm_t ) cmd ;
}
2009-07-28 09:16:18 +00:00
void lvm_quit ( lvm_t libh )
2009-02-24 13:03:45 +00:00
{
destroy_toolcontext ( ( struct cmd_context * ) libh ) ;
2011-06-15 13:29:48 +00:00
udev_fin_library_context ( ) ;
2009-02-24 13:03:45 +00:00
}
2009-07-27 10:18:51 +00:00
int lvm_config_reload ( lvm_t libh )
2009-02-24 13:03:45 +00:00
{
/* FIXME: re-init locking needed here? */
2009-07-27 21:02:35 +00:00
if ( ! refresh_toolcontext ( ( struct cmd_context * ) libh ) )
2009-07-26 20:28:59 +00:00
return - 1 ;
return 0 ;
2009-02-24 13:03:45 +00:00
}
2009-07-16 00:36:59 +00:00
2009-07-28 13:16:40 +00:00
/*
* FIXME : submit a patch to document the - - config option
*/
2009-07-27 21:02:17 +00:00
int lvm_config_override ( lvm_t libh , const char * config_settings )
{
struct cmd_context * cmd = ( struct cmd_context * ) libh ;
2012-10-16 10:07:27 +02:00
if ( ! override_config_tree_from_string ( cmd , config_settings ) )
2009-07-27 21:02:17 +00:00
return - 1 ;
return 0 ;
}
2012-07-31 16:18:01 +02:00
int lvm_config_find_bool ( lvm_t libh , const char * config_path , int fail )
{
return find_config_tree_bool ( ( struct cmd_context * ) libh , config_path , fail ) ;
}
2009-07-16 00:36:59 +00:00
int lvm_errno ( lvm_t libh )
{
return stored_errno ( ) ;
}
const char * lvm_errmsg ( lvm_t libh )
{
return stored_errmsg ( ) ;
}
2010-05-19 11:53:12 +00:00
const char * lvm_vgname_from_pvid ( lvm_t libh , const char * pvid )
{
struct cmd_context * cmd = ( struct cmd_context * ) libh ;
2010-05-19 12:12:47 +00:00
struct id id ;
2010-05-19 11:53:12 +00:00
2010-05-19 12:12:47 +00:00
if ( ! id_read_format ( & id , pvid ) ) {
2010-05-19 11:53:12 +00:00
log_error ( INTERNAL_ERROR " Unable to convert uuid " ) ;
return NULL ;
}
2010-05-19 12:12:47 +00:00
return find_vgname_from_pvid ( cmd , ( char * ) id . uuid ) ;
2010-05-19 11:53:12 +00: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 17:25:14 +02:00
float lvm_percent_to_float ( percent_t v )
{
return percent_to_float ( v ) ;
}