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

Add lvm_errno and lvm_errmsg to liblvm to obtain failure information.

Change create_toolcontext to still return an object if it fails part-way.
Add EUNCLASSIFIED (-1) as the default LVM errno code.
This commit is contained in:
Alasdair Kergon 2009-07-16 00:36:59 +00:00
parent d614646157
commit d917192f00
7 changed files with 53 additions and 34 deletions

View File

@ -1,5 +1,8 @@
Version 2.02.50 -
================================
Add lvm_errno and lvm_errmsg to liblvm to obtain failure information.
Change create_toolcontext to still return an object if it fails part-way.
Add EUNCLASSIFIED (-1) as the default LVM errno code.
Store any errno and error messages issued while processing each command.
Use log_error macro consistently throughout in place of log_err.

View File

@ -792,6 +792,11 @@ int init_lvm(int using_gulm)
return 0;
}
if (stored_errno()) {
destroy_toolcontext(cmd);
return 0;
}
/* Use LOG_DAEMON for syslog messages instead of LOG_USER */
init_syslog(LOG_DAEMON);
openlog("clvmd", LOG_PID, LOG_DAEMON);

View File

@ -1083,6 +1083,9 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
dm_list_init(&cmd->tags);
dm_list_init(&cmd->config_files);
/* FIXME Make this configurable? */
reset_lvm_errno(1);
/*
* Environment variable LVM_SYSTEM_DIR overrides this below.
*/
@ -1092,7 +1095,7 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
strcpy(cmd->system_dir, DEFAULT_SYS_DIR);
if (!_get_env_vars(cmd))
goto error;
goto_out;
/* Create system directory if it doesn't already exist */
if (*cmd->system_dir && !dm_create_dir(cmd->system_dir)) {
@ -1100,58 +1103,58 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
"files and internal cache.");
log_error("Set environment variable LVM_SYSTEM_DIR to alternative location "
"or empty string.");
goto error;
goto out;
}
if (!(cmd->libmem = dm_pool_create("library", 4 * 1024))) {
log_error("Library memory pool creation failed");
goto error;
goto out;
}
if (!_init_lvm_conf(cmd))
goto error;
goto_out;
_init_logging(cmd);
if (!_init_hostname(cmd))
goto error;
goto_out;
if (!_init_tags(cmd, cmd->cft))
goto error;
goto_out;
if (!_init_tag_configs(cmd))
goto error;
goto_out;
if (!_merge_config_files(cmd))
goto error;
goto_out;
if (!_process_config(cmd))
goto error;
goto_out;
if (!_init_dev_cache(cmd))
goto error;
goto_out;
if (!_init_filters(cmd, 1))
goto error;
goto_out;
if (!(cmd->mem = dm_pool_create("command", 4 * 1024))) {
log_error("Command memory pool creation failed");
goto error;
goto out;
}
memlock_init(cmd);
if (!_init_formats(cmd))
goto error;
goto_out;
if (!init_lvmcache_orphans(cmd))
goto error;
goto_out;
if (!_init_segtypes(cmd))
goto error;
goto_out;
if (!_init_backup(cmd))
goto error;
goto_out;
_init_rand(cmd);
@ -1161,20 +1164,8 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
cmd->current_settings = cmd->default_settings;
cmd->config_valid = 1;
reset_lvm_errno(1); /* FIXME Move to top when cmd returned on error */
out:
return cmd;
error:
_destroy_tag_configs(cmd);
dev_cache_exit();
if (cmd->filter)
cmd->filter->destroy(cmd->filter);
if (cmd->mem)
dm_pool_destroy(cmd->mem);
if (cmd->libmem)
dm_pool_destroy(cmd->libmem);
dm_free(cmd);
return NULL;
}
static void _destroy_formats(struct dm_list *formats)

View File

@ -152,12 +152,12 @@ void reset_lvm_errno(int store_errmsg)
_store_errmsg = store_errmsg;
}
int lvm_errno(void)
int stored_errno(void)
{
return _lvm_errno;
}
const char *lvm_errmsg(void)
const char *stored_errmsg(void)
{
return _lvm_errmsg ? : "";
}

View File

@ -20,7 +20,8 @@ void print_log(int level, const char *file, int line, int dm_errno,
const char *format, ...)
__attribute__ ((format(printf, 5, 6)));
#define LOG_LINE(l, x...) print_log(l, __FILE__, __LINE__ , 0, ## x)
#define EUNCLASSIFIED -1 /* Generic error code */
#define LOG_LINE(l, x...) print_log(l, __FILE__, __LINE__ , EUNCLASSIFIED, ## x)
#include "log.h"
@ -44,8 +45,8 @@ void fin_syslog(void);
int error_message_produced(void);
void reset_lvm_errno(int store_errmsg);
int lvm_errno(void);
const char *lvm_errmsg(void);
int stored_errno(void);
const char *stored_errmsg(void);
/* Suppress messages to stdout/stderr (1) or everywhere (2) */
/* Returns previous setting */

View File

@ -29,6 +29,10 @@ lvm_t lvm_create(const char *system_dir)
cmd = create_toolcontext(1, system_dir);
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).
@ -66,3 +70,13 @@ int lvm_reload_config(lvm_t libh)
/* FIXME: re-init locking needed here? */
return refresh_toolcontext((struct cmd_context *)libh);
}
int lvm_errno(lvm_t libh)
{
return stored_errno();
}
const char *lvm_errmsg(lvm_t libh)
{
return stored_errmsg();
}

View File

@ -1181,6 +1181,11 @@ struct cmd_context *init_lvm(void)
if (!(cmd = create_toolcontext(0, NULL)))
return_NULL;
if (stored_errno()) {
destroy_toolcontext(cmd);
return_NULL;
}
return cmd;
}