1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-28 20:25:52 +03:00
lvm2/liblvm/lvm_base.c
Petr Rockai eee66d2a80 When glibc needs buffers for line buffering of input and output buffers, it
allocates these buffers in such way it adds memory page for each such buffer
and size of unlock memory check will mismatch by 1 or 2 pages.

This happens when we print or read lines without '\n' so these buffers are
used. To avoid this extra allocation, use setvbuf to set these bufffers ahead.

Signed-off-by: Zdenek Kabelac <zkabelac@redhat.com>
Reviewed-by: Milan Broz <mbroz@redhat.com>
Reviewed-by: Petr Rockai <prockai@redhat.com>
2011-05-07 13:50:11 +00:00

120 lines
2.7 KiB
C

/*
* 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"
#include "lvm-version.h"
#include "metadata-exported.h"
#include "lvm2app.h"
const char *lvm_library_get_version(void)
{
return LVM_VERSION;
}
lvm_t lvm_init(const char *system_dir)
{
struct cmd_context *cmd;
/* FIXME: logging bound to handle
*/
/* create context */
/* FIXME: split create_toolcontext */
/* FIXME: make all globals configurable */
cmd = create_toolcontext(0, system_dir, 1);
if (!cmd)
return NULL;
if (stored_errno())
return (lvm_t) cmd;
/*
* 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 */
if (!init_locking(-1, cmd, 0)) {
/* FIXME: use EAGAIN as error code here */
lvm_quit((lvm_t) cmd);
return NULL;
}
/*
* FIXME: Use cmd->cmd_line as audit trail for liblvm calls. Used in
* archive() call. Possible example:
* cmd_line = "lvm_vg_create: vg1\nlvm_vg_extend vg1 /dev/sda1\n"
*/
cmd->cmd_line = "liblvm";
return (lvm_t) cmd;
}
void lvm_quit(lvm_t libh)
{
destroy_toolcontext((struct cmd_context *)libh);
}
int lvm_config_reload(lvm_t libh)
{
/* FIXME: re-init locking needed here? */
if (!refresh_toolcontext((struct cmd_context *)libh))
return -1;
return 0;
}
/*
* FIXME: submit a patch to document the --config option
*/
int lvm_config_override(lvm_t libh, const char *config_settings)
{
struct cmd_context *cmd = (struct cmd_context *)libh;
if (override_config_tree_from_string(cmd, config_settings))
return -1;
return 0;
}
int lvm_errno(lvm_t libh)
{
return stored_errno();
}
const char *lvm_errmsg(lvm_t libh)
{
return stored_errmsg();
}
const char *lvm_vgname_from_pvid(lvm_t libh, const char *pvid)
{
struct cmd_context *cmd = (struct cmd_context *)libh;
struct id id;
if (!id_read_format(&id, pvid)) {
log_error(INTERNAL_ERROR "Unable to convert uuid");
return NULL;
}
return find_vgname_from_pvid(cmd, (char *)id.uuid);
}
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);
}