mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
dumpconfig to dump active configuration
This commit is contained in:
parent
c7ee8edc33
commit
dcc31da516
@ -385,17 +385,25 @@ static int _write_config(struct config_node *n, FILE *fp, int level)
|
|||||||
int write_config_file(struct config_tree *cf, const char *file)
|
int write_config_file(struct config_tree *cf, const char *file)
|
||||||
{
|
{
|
||||||
int r = 1;
|
int r = 1;
|
||||||
FILE *fp = fopen(file, "w");
|
FILE *fp;
|
||||||
if (!fp) {
|
|
||||||
|
if (!file) {
|
||||||
|
fp = stdout;
|
||||||
|
file = "stdout";
|
||||||
|
} else if (!(fp = fopen(file, "w"))) {
|
||||||
log_sys_error("open", file);
|
log_sys_error("open", file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_verbose("Dumping configuration to %s", file);
|
||||||
if (!_write_config(cf->root, fp, 0)) {
|
if (!_write_config(cf->root, fp, 0)) {
|
||||||
stack;
|
log_error("Failure while writing configuration");
|
||||||
r = 0;
|
r = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fp != stdout)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ VPATH = @srcdir@
|
|||||||
|
|
||||||
SOURCES=\
|
SOURCES=\
|
||||||
archive.c \
|
archive.c \
|
||||||
|
dumpconfig.c \
|
||||||
lvchange.c \
|
lvchange.c \
|
||||||
lvcreate.c \
|
lvcreate.c \
|
||||||
lvdisplay.c \
|
lvdisplay.c \
|
||||||
@ -81,7 +82,7 @@ lvm: $(OBJECTS) $(top_srcdir)/lib/liblvm.a
|
|||||||
|
|
||||||
.commands: commands.h cmdnames.h Makefile
|
.commands: commands.h cmdnames.h Makefile
|
||||||
$(CC) -E -P cmdnames.h 2> /dev/null | \
|
$(CC) -E -P cmdnames.h 2> /dev/null | \
|
||||||
egrep -v '^ *(|#.*|help|pvdata|version) *$$' > .commands
|
egrep -v '^ *(|#.*|dumpconfig|help|pvdata|version) *$$' > .commands
|
||||||
|
|
||||||
install: $(TARGETS)
|
install: $(TARGETS)
|
||||||
$(INSTALL) -D -o $(OWNER) -g $(GROUP) -m 555 $(STRIP) lvm \
|
$(INSTALL) -D -o $(OWNER) -g $(GROUP) -m 555 $(STRIP) lvm \
|
||||||
|
@ -33,6 +33,10 @@ xx(e2fsadm,
|
|||||||
extents_ARG, size_ARG, nofsck_ARG, test_ARG)
|
extents_ARG, size_ARG, nofsck_ARG, test_ARG)
|
||||||
*********/
|
*********/
|
||||||
|
|
||||||
|
xx(dumpconfig,
|
||||||
|
"Dump active configuration",
|
||||||
|
"dumpconfig <filename>\n")
|
||||||
|
|
||||||
xx(help,
|
xx(help,
|
||||||
"Display help for commands",
|
"Display help for commands",
|
||||||
"help <command>" "\n")
|
"help <command>" "\n")
|
||||||
|
39
tools/dumpconfig.c
Normal file
39
tools/dumpconfig.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2003 Sistina Software
|
||||||
|
*
|
||||||
|
* LVM is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* LVM is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with LVM; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tools.h"
|
||||||
|
|
||||||
|
int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
|
||||||
|
{
|
||||||
|
const char *file = NULL;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
file = argv[0];
|
||||||
|
|
||||||
|
if (argc > 1) {
|
||||||
|
log_error("Please specify one file for output");
|
||||||
|
return EINVALID_CMD_LINE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!write_config_file(cmd->cft, file))
|
||||||
|
return ECMD_FAILED;
|
||||||
|
|
||||||
|
return ECMD_PROCESSED;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user