mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
o Remove LVM_CONFIG_FILE environment variable.
o Introduced the LVM_SYSTEM_DIR variable. This makes more sense because the persistent cache, and backup directories are config specific. eg, I use /etc/lvm for running my real LV's but I have another directory /dev/lvm_loops that contains a config that allows only loopback devices, I use this for testing.
This commit is contained in:
parent
3813dd120e
commit
27f6cd0a88
83
tools/lvm.c
83
tools/lvm.c
@ -27,6 +27,7 @@
|
|||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include "stub.h"
|
#include "stub.h"
|
||||||
#include "vgcache.h"
|
#include "vgcache.h"
|
||||||
@ -64,6 +65,16 @@ static int _interactive;
|
|||||||
static FILE *_log;
|
static FILE *_log;
|
||||||
static int _debug_level;
|
static int _debug_level;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The lvm_system_dir contains:
|
||||||
|
*
|
||||||
|
* o The lvm configuration (lvm.conf)
|
||||||
|
* o The persistent filter cache (.cache)
|
||||||
|
* o Volume group backups (backups)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static char _system_dir[PATH_MAX] = "/etc/lvm";
|
||||||
|
|
||||||
/* static functions */
|
/* static functions */
|
||||||
static void register_commands(void);
|
static void register_commands(void);
|
||||||
static struct command *find_command(const char *name);
|
static struct command *find_command(const char *name);
|
||||||
@ -536,7 +547,7 @@ int help(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_help()
|
static void display_help(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -702,14 +713,22 @@ static struct dev_filter *filter_setup(struct config_file *cf)
|
|||||||
const char *lvm_cache;
|
const char *lvm_cache;
|
||||||
struct dev_filter *f3, *f4;
|
struct dev_filter *f3, *f4;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
char cache_file[PATH_MAX];
|
||||||
|
|
||||||
_dump_filter = 0;
|
_dump_filter = 0;
|
||||||
|
|
||||||
if (!(f3 = filter_components_setup(cmd->cf)))
|
if (!(f3 = filter_components_setup(cmd->cf)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (snprintf(cache_file, sizeof(cache_file),
|
||||||
|
"%s/.cache", _system_dir) < 0) {
|
||||||
|
log_err("Persistent cache filename too long ('%s/.cache').",
|
||||||
|
_system_dir);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
lvm_cache = find_config_str(cf->root, "devices/cache", '/',
|
lvm_cache = find_config_str(cf->root, "devices/cache", '/',
|
||||||
"/etc/lvm/.cache");
|
cache_file);
|
||||||
|
|
||||||
if (!(f4 = persistent_filter_create(f3, lvm_cache))) {
|
if (!(f4 = persistent_filter_create(f3, lvm_cache))) {
|
||||||
log_error("Failed to create persistent device filter");
|
log_error("Failed to create persistent device filter");
|
||||||
@ -727,15 +746,32 @@ static struct dev_filter *filter_setup(struct config_file *cf)
|
|||||||
return f4;
|
return f4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _get_env_vars(void)
|
||||||
|
{
|
||||||
|
const char *e;
|
||||||
|
|
||||||
|
if ((e = getenv("LVM_SYSTEM_DIR"))) {
|
||||||
|
if (snprintf(_system_dir, sizeof(_system_dir), "%s", e) < 0) {
|
||||||
|
log_err("LVM_SYSTEM_DIR environment variable "
|
||||||
|
"is too long.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int init(void)
|
static int init(void)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
|
||||||
const char *e = getenv("LVM_CONFIG_FILE");
|
|
||||||
struct stat info;
|
struct stat info;
|
||||||
|
char config_file[PATH_MAX];
|
||||||
|
|
||||||
|
if (!_get_env_vars())
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (!(cmd = dbg_malloc(sizeof(*cmd)))) {
|
if (!(cmd = dbg_malloc(sizeof(*cmd)))) {
|
||||||
log_error("Failed to allocate command context");
|
log_error("Failed to allocate command context");
|
||||||
goto out;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: Override from config file. (Append trailing slash if reqd) */
|
/* FIXME: Override from config file. (Append trailing slash if reqd) */
|
||||||
@ -744,7 +780,7 @@ static int init(void)
|
|||||||
|
|
||||||
if (!(cmd->cf = create_config_file())) {
|
if (!(cmd->cf = create_config_file())) {
|
||||||
stack;
|
stack;
|
||||||
goto out;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use LOG_USER for syslog messages by default */
|
/* Use LOG_USER for syslog messages by default */
|
||||||
@ -753,12 +789,18 @@ static int init(void)
|
|||||||
/* send log messages to stderr for now */
|
/* send log messages to stderr for now */
|
||||||
init_log(stderr);
|
init_log(stderr);
|
||||||
|
|
||||||
e = e ? e : "/etc/lvm/lvm.conf";
|
if (snprintf(config_file, sizeof(config_file),
|
||||||
if (stat(e, &info) != -1) {
|
"%s/lvm.conf", _system_dir) < 0) {
|
||||||
|
log_err("lvm_system_dir was too long");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stat(config_file, &info) != -1) {
|
||||||
/* we've found a config file */
|
/* we've found a config file */
|
||||||
if (!read_config(cmd->cf, e)) {
|
if (!read_config(cmd->cf, config_file)) {
|
||||||
log_error("Failed to load config file %s", e);
|
log_error("Failed to load config file %s",
|
||||||
goto out;
|
config_file);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
__init_log(cmd->cf);
|
__init_log(cmd->cf);
|
||||||
@ -766,28 +808,23 @@ static int init(void)
|
|||||||
|
|
||||||
dm_log_init(print_log);
|
dm_log_init(print_log);
|
||||||
|
|
||||||
if (!dev_cache_setup(cmd->cf)) {
|
if (!dev_cache_setup(cmd->cf))
|
||||||
goto out;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(cmd->filter = filter_setup(cmd->cf))) {
|
if (!(cmd->filter = filter_setup(cmd->cf))) {
|
||||||
log_error("Failed to set up internal device filters");
|
log_error("Failed to set up internal device filters");
|
||||||
goto out;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(cmd->mem = pool_create(4 * 1024))) {
|
if (!(cmd->mem = pool_create(4 * 1024))) {
|
||||||
log_error("Command pool creation failed");
|
log_error("Command pool creation failed");
|
||||||
goto out;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(fid = create_lvm1_format(cmd))) {
|
if (!(fid = create_lvm1_format(cmd)))
|
||||||
goto out;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
ret = 1;
|
return 1;
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __fin_commands(void)
|
static void __fin_commands(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user