1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Move CMDLIB code into separate file and record whether static build.

This commit is contained in:
Alasdair Kergon 2006-08-18 21:17:18 +00:00
parent ade81b8aed
commit 6711231a13
11 changed files with 196 additions and 122 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.10 -
==================================
Move CMDLIB code into separate file and record whether static build.
Version 2.02.09 - 17th August 2006
==================================

8
configure vendored
View File

@ -7534,14 +7534,6 @@ fi;
echo "$as_me:$LINENO: result: $CMDLIB" >&5
echo "${ECHO_T}$CMDLIB" >&6
if test x$CMDLIB = xyes; then
cat >>confdefs.h <<\_ACEOF
#define CMDLIB 1
_ACEOF
fi
################################################################################
echo "$as_me:$LINENO: checking whether to build fsadm" >&5
echo $ECHO_N "checking whether to build fsadm... $ECHO_C" >&6

View File

@ -351,10 +351,6 @@ AC_ARG_ENABLE(cmdlib, [ --enable-cmdlib Build shared command library],
CMDLIB=$enableval, CMDLIB=no)
AC_MSG_RESULT($CMDLIB)
if test x$CMDLIB = xyes; then
AC_DEFINE([CMDLIB], 1, [Define to 1 to build the shared command library.])
fi
################################################################################
dnl -- Enable fsadm
AC_MSG_CHECKING(whether to build fsadm)

View File

@ -879,7 +879,7 @@ static int _init_backup(struct cmd_context *cmd)
}
/* Entry point */
struct cmd_context *create_toolcontext(struct arg *the_args)
struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static)
{
struct cmd_context *cmd;
@ -902,6 +902,7 @@ struct cmd_context *create_toolcontext(struct arg *the_args)
}
memset(cmd, 0, sizeof(*cmd));
cmd->args = the_args;
cmd->is_static = is_static;
cmd->hosttags = 0;
list_init(&cmd->formats);
list_init(&cmd->segtypes);

View File

@ -64,6 +64,7 @@ struct cmd_context {
struct command *command;
struct arg *args;
char **argv;
unsigned is_static; /* Static binary? */
struct dev_filter *filter;
int dump_filter; /* Dump filter when exiting? */
@ -87,7 +88,7 @@ struct cmd_context {
char proc_dir[PATH_MAX];
};
struct cmd_context *create_toolcontext(struct arg *the_args);
struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static);
void destroy_toolcontext(struct cmd_context *cmd);
int refresh_toolcontext(struct cmd_context *cmd);
int config_files_changed(struct cmd_context *cmd);

View File

@ -80,7 +80,9 @@ endif
LVMLIBS = -llvm
CLEAN_TARGETS = liblvm2cmd.so liblvm2cmd.a lvm lvm.o lvm.static lvm.cflow lvm.xref lvm.tree lvm.rxref lvm.rtree
CLEAN_TARGETS = liblvm2cmd.so liblvm2cmd.a liblvm2cmd-static.a lvm lvm.o \
lvm2cmd.o lvm2cmd-static.o lvm2cmdlib.o lvm.static \
lvm.cflow lvm.xref lvm.tree lvm.rxref lvm.rtree
ifeq ("@CMDLIB@", "yes")
TARGETS += liblvm2cmd.so
@ -104,9 +106,13 @@ lvm.static: $(OBJECTS) lvm-static.o $(top_srcdir)/lib/liblvm.a
$(CC) -o $@ $(OBJECTS) lvm-static.o -static $(LDFLAGS) $(LVMLIBS) \
$(LIBS) -rdynamic
liblvm2cmd.a: $(top_srcdir)/lib/liblvm.a $(OBJECTS)
liblvm2cmd.a: $(top_srcdir)/lib/liblvm.a $(OBJECTS) lvmcmdlib.o lvm2cmd.o
cat $(top_srcdir)/lib/liblvm.a > $@
$(AR) rs $@ $(OBJECTS)
$(AR) rs $@ $(OBJECTS) lvmcmdlib.o lvm2cmd.o
liblvm2cmd-static.a: $(top_srcdir)/lib/liblvm.a $(OBJECTS) lvmcmdlib.o lvm2cmd-static.o
cat $(top_srcdir)/lib/liblvm.a > $@
$(AR) rs $@ $(OBJECTS) lvmcmdlib.o lvm2cmd-static.o
liblvm2cmd.so: liblvm2cmd.a $(LDDEPS)
@ -141,8 +147,8 @@ install_cmdlib_dynamic: liblvm2cmd.so
$(INSTALL) -D $(OWNER) $(GROUP) -m 444 lvm2cmd.h \
$(includedir)/lvm2cmd.h
install_cmdlib_static: liblvm2cmd.a
$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) liblvm2cmd.a \
install_cmdlib_static: liblvm2cmd-static.a
$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) liblvm2cmd-static.a \
$(libdir)/liblvm2cmd.a.$(LIB_VERSION)
$(LN_S) -f liblvm2cmd.a.$(LIB_VERSION) $(libdir)/liblvm2cmd.a
$(INSTALL) -D $(OWNER) $(GROUP) -m 444 lvm2cmd.h \

21
tools/lvm2cmd-static.c Normal file
View File

@ -0,0 +1,21 @@
/*
* Copyright (C) 2006 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 General Public License v.2.
*
* You should have received a copy of the GNU 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 "lvm2cmdline.h"
#include "lvm2cmd.h"
void *lvm2_init(void)
{
return cmdlib_lvm2_init(1);
}

21
tools/lvm2cmd.c Normal file
View File

@ -0,0 +1,21 @@
/*
* Copyright (C) 2006 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 General Public License v.2.
*
* You should have received a copy of the GNU 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 "lvm2cmdline.h"
#include "lvm2cmd.h"
void *lvm2_init(void)
{
return cmdlib_lvm2_init(0);
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2003-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@ -16,6 +16,16 @@
#ifndef _LVM_CMDLINE_H
#define _LVM_CMDLINE_H
int lvm2_main(int argc, char **argv, int is_static);
struct cmd_context;
int lvm2_main(int argc, char **argv, unsigned is_static);
void *cmdlib_lvm2_init(unsigned is_static);
void lvm_fin(struct cmd_context *cmd);
struct cmd_context *init_lvm(unsigned is_static);
void lvm_register_commands(void);
int lvm_split(char *str, int *argc, char **argv, int max);
int lvm_run_command(struct cmd_context *cmd, int argc, char **argv);
#endif

111
tools/lvmcmdlib.c Normal file
View File

@ -0,0 +1,111 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 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 General Public License v.2.
*
* You should have received a copy of the GNU 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 "tools.h"
#include "lvm2cmdline.h"
#include "label.h"
#include "version.h"
#include "stub.h"
#include "lvm2cmd.h"
#include <signal.h>
#include <syslog.h>
#include <libgen.h>
#include <sys/stat.h>
#include <time.h>
#include <sys/resource.h>
void *cmdlib_lvm2_init(unsigned is_static)
{
struct cmd_context *cmd;
lvm_register_commands();
if (!(cmd = init_lvm(is_static)))
return NULL;
return (void *) cmd;
}
int lvm2_run(void *handle, const char *cmdline)
{
int argc, ret, oneoff = 0;
char *args[MAX_ARGS], **argv, *cmdcopy = NULL;
struct cmd_context *cmd;
argv = args;
if (!handle) {
oneoff = 1;
if (!(handle = lvm2_init())) {
log_error("Handle initialisation failed.");
return ECMD_FAILED;
}
}
cmd = (struct cmd_context *) handle;
cmd->argv = argv;
if (!(cmdcopy = dm_strdup(cmdline))) {
log_error("Cmdline copy failed.");
ret = ECMD_FAILED;
goto out;
}
if (lvm_split(cmdcopy, &argc, argv, MAX_ARGS) == MAX_ARGS) {
log_error("Too many arguments. Limit is %d.", MAX_ARGS);
ret = EINVALID_CMD_LINE;
goto out;
}
if (!argc) {
log_error("No command supplied");
ret = EINVALID_CMD_LINE;
goto out;
}
ret = lvm_run_command(cmd, argc, argv);
out:
dm_free(cmdcopy);
if (oneoff)
lvm2_exit(handle);
return ret;
}
void lvm2_log_level(void *handle, int level)
{
struct cmd_context *cmd = (struct cmd_context *) handle;
cmd->default_settings.verbose = level - VERBOSE_BASE_LEVEL;
return;
}
void lvm2_log_fn(lvm2_log_fn_t log_fn)
{
init_log_fn(log_fn);
}
void lvm2_exit(void *handle)
{
struct cmd_context *cmd = (struct cmd_context *) handle;
lvm_fin(cmd);
}

View File

@ -443,7 +443,7 @@ static void _register_command(const char *name, command_fn fn,
_create_new_command(name, fn, desc, usagestr, nargs, args);
}
static void _register_commands()
void lvm_register_commands(void)
{
#define xx(a, b, c...) _register_command(# a, a, b, ## c, \
driverloaded_ARG, \
@ -843,7 +843,7 @@ static char *_copy_command_line(struct cmd_context *cmd, int argc, char **argv)
return NULL;
}
static int _run_command(struct cmd_context *cmd, int argc, char **argv)
int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
{
int ret = 0;
int locking_type;
@ -936,7 +936,7 @@ static int _run_command(struct cmd_context *cmd, int argc, char **argv)
return ret;
}
static int _split(char *str, int *argc, char **argv, int max)
int lvm_split(char *str, int *argc, char **argv, int max)
{
char *b = str, *e;
*argc = 0;
@ -995,11 +995,11 @@ static void _close_stray_fds(void)
}
}
static struct cmd_context *_init_lvm(void)
struct cmd_context *init_lvm(unsigned is_static)
{
struct cmd_context *cmd;
if (!(cmd = create_toolcontext(&the_args[0]))) {
if (!(cmd = create_toolcontext(&the_args[0], is_static))) {
stack;
return NULL;
}
@ -1021,7 +1021,7 @@ static void _fin_commands(void)
dm_free(_commands);
}
static void _fin(struct cmd_context *cmd)
void lvm_fin(struct cmd_context *cmd)
{
_fin_commands();
destroy_toolcontext(cmd);
@ -1055,7 +1055,7 @@ static int _run_script(struct cmd_context *cmd, int argc, char **argv)
ret = EINVALID_CMD_LINE;
break;
}
if (_split(buffer, &argc, argv, MAX_ARGS) == MAX_ARGS) {
if (lvm_split(buffer, &argc, argv, MAX_ARGS) == MAX_ARGS) {
buffer[50] = '\0';
log_error("Too many arguments: %s", buffer);
ret = EINVALID_CMD_LINE;
@ -1065,7 +1065,7 @@ static int _run_script(struct cmd_context *cmd, int argc, char **argv)
continue;
if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "exit"))
break;
_run_command(cmd, argc, argv);
lvm_run_command(cmd, argc, argv);
}
fclose(script);
@ -1251,7 +1251,7 @@ static int _shell(struct cmd_context *cmd)
argv = args;
if (_split(input, &argc, argv, MAX_ARGS) == MAX_ARGS) {
if (lvm_split(input, &argc, argv, MAX_ARGS) == MAX_ARGS) {
log_error("Too many arguments, sorry.");
continue;
}
@ -1270,7 +1270,7 @@ static int _shell(struct cmd_context *cmd)
break;
}
ret = _run_command(cmd, argc, argv);
ret = lvm_run_command(cmd, argc, argv);
if (ret == ENO_SUCH_CMD)
log_error("No such command '%s'. Try 'help'.",
argv[0]);
@ -1284,92 +1284,6 @@ static int _shell(struct cmd_context *cmd)
#endif
#ifdef CMDLIB
void *lvm2_init(void)
{
struct cmd_context *cmd;
_register_commands();
if (!(cmd = _init_lvm()))
return NULL;
return (void *) cmd;
}
int lvm2_run(void *handle, const char *cmdline)
{
int argc, ret, oneoff = 0;
char *args[MAX_ARGS], **argv, *cmdcopy = NULL;
struct cmd_context *cmd;
argv = args;
if (!handle) {
oneoff = 1;
if (!(handle = lvm2_init())) {
log_error("Handle initialisation failed.");
return ECMD_FAILED;
}
}
cmd = (struct cmd_context *) handle;
cmd->argv = argv;
if (!(cmdcopy = dm_strdup(cmdline))) {
log_error("Cmdline copy failed.");
ret = ECMD_FAILED;
goto out;
}
if (_split(cmdcopy, &argc, argv, MAX_ARGS) == MAX_ARGS) {
log_error("Too many arguments. Limit is %d.", MAX_ARGS);
ret = EINVALID_CMD_LINE;
goto out;
}
if (!argc) {
log_error("No command supplied");
ret = EINVALID_CMD_LINE;
goto out;
}
ret = _run_command(cmd, argc, argv);
out:
dm_free(cmdcopy);
if (oneoff)
lvm2_exit(handle);
return ret;
}
void lvm2_log_level(void *handle, int level)
{
struct cmd_context *cmd = (struct cmd_context *) handle;
cmd->default_settings.verbose = level - VERBOSE_BASE_LEVEL;
return;
}
void lvm2_log_fn(lvm2_log_fn_t log_fn)
{
init_log_fn(log_fn);
}
void lvm2_exit(void *handle)
{
struct cmd_context *cmd = (struct cmd_context *) handle;
_fin(cmd);
}
#endif
/*
* Determine whether we should fall back and exec the equivalent LVM1 tool
*/
@ -1406,7 +1320,7 @@ static void _exec_lvm1_command(char **argv)
log_sys_error("execvp", path);
}
int lvm2_main(int argc, char **argv, int is_static)
int lvm2_main(int argc, char **argv, unsigned is_static)
{
char *namebase, *base;
int ret, alias = 0;
@ -1432,11 +1346,11 @@ int lvm2_main(int argc, char **argv, int is_static)
free(namebase);
if (!(cmd = _init_lvm()))
if (!(cmd = init_lvm(is_static)))
return -1;
cmd->argv = argv;
_register_commands();
lvm_register_commands();
if (_lvm1_fallback(cmd)) {
/* Attempt to run equivalent LVM1 tool instead */
@ -1472,14 +1386,14 @@ int lvm2_main(int argc, char **argv, int is_static)
argv++;
}
ret = _run_command(cmd, argc, argv);
ret = lvm_run_command(cmd, argc, argv);
if ((ret == ENO_SUCH_CMD) && (!alias))
ret = _run_script(cmd, argc, argv);
if (ret == ENO_SUCH_CMD)
log_error("No such command. Try 'help'.");
out:
_fin(cmd);
lvm_fin(cmd);
if (ret == ECMD_PROCESSED)
ret = 0;
return ret;