mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Support device queries by uuid as well as by name. (Used by lvrename.)
This commit is contained in:
parent
2ed2a72439
commit
902098d615
@ -30,31 +30,30 @@ static char _dm_dir[PATH_MAX] = DEV_DIR DM_DIR;
|
||||
* Library users can provide their own logging
|
||||
* function.
|
||||
*/
|
||||
void _default_log(int level, const char *file, int line,
|
||||
const char *f, ...)
|
||||
void _default_log(int level, const char *file, int line, const char *f, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
|
||||
if (level > _LOG_WARN)
|
||||
return;
|
||||
|
||||
va_start(ap, f);
|
||||
va_start(ap, f);
|
||||
|
||||
if (level == _LOG_WARN)
|
||||
vprintf(f, ap);
|
||||
vprintf(f, ap);
|
||||
else
|
||||
vfprintf(stderr, f, ap);
|
||||
vfprintf(stderr, f, ap);
|
||||
|
||||
va_end(ap);
|
||||
va_end(ap);
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
dm_log_fn _log = _default_log;
|
||||
|
||||
void dm_log_init(dm_log_fn fn)
|
||||
{
|
||||
_log = fn;
|
||||
_log = fn;
|
||||
}
|
||||
|
||||
void _build_dev_path(char *buffer, size_t len, const char *dev_name)
|
||||
@ -63,7 +62,7 @@ void _build_dev_path(char *buffer, size_t len, const char *dev_name)
|
||||
if (strchr(dev_name, '/'))
|
||||
snprintf(buffer, len, "%s", dev_name);
|
||||
else
|
||||
snprintf(buffer, len, "%s/%s", _dm_dir, dev_name);
|
||||
snprintf(buffer, len, "%s/%s", _dm_dir, dev_name);
|
||||
}
|
||||
|
||||
int dm_get_library_version(char *version, size_t size)
|
||||
@ -74,18 +73,18 @@ int dm_get_library_version(char *version, size_t size)
|
||||
|
||||
struct dm_task *dm_task_create(int type)
|
||||
{
|
||||
struct dm_task *dmt = malloc(sizeof(*dmt));
|
||||
struct dm_task *dmt = malloc(sizeof(*dmt));
|
||||
|
||||
if (!dmt) {
|
||||
log_error("dm_task_create: malloc(%d) failed", sizeof(*dmt));
|
||||
return NULL;
|
||||
}
|
||||
if (!dmt) {
|
||||
log_error("dm_task_create: malloc(%d) failed", sizeof(*dmt));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(dmt, 0, sizeof(*dmt));
|
||||
memset(dmt, 0, sizeof(*dmt));
|
||||
|
||||
dmt->type = type;
|
||||
dmt->type = type;
|
||||
dmt->minor = -1;
|
||||
return dmt;
|
||||
return dmt;
|
||||
}
|
||||
|
||||
int dm_task_set_name(struct dm_task *dmt, const char *name)
|
||||
@ -94,8 +93,8 @@ int dm_task_set_name(struct dm_task *dmt, const char *name)
|
||||
char path[PATH_MAX];
|
||||
struct stat st1, st2;
|
||||
|
||||
if (dmt->dev_name) {
|
||||
free(dmt->dev_name);
|
||||
if (dmt->dev_name) {
|
||||
free(dmt->dev_name);
|
||||
dmt->dev_name = NULL;
|
||||
}
|
||||
|
||||
@ -107,21 +106,22 @@ int dm_task_set_name(struct dm_task *dmt, const char *name)
|
||||
|
||||
if (stat(name, &st1) || stat(path, &st2) ||
|
||||
!(st1.st_dev == st2.st_dev)) {
|
||||
log_error("dm_task_set_name: Device %s not found", name);
|
||||
log_error("dm_task_set_name: Device %s not found",
|
||||
name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
name = pos + 1;
|
||||
}
|
||||
|
||||
if (!(dmt->dev_name = strdup(name))) {
|
||||
if (!(dmt->dev_name = strdup(name))) {
|
||||
log_error("dm_task_set_name: strdup(%s) failed", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_very_verbose("Setting name: %s", dmt->dev_name);
|
||||
log_debug("Setting name: %s", dmt->dev_name);
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dm_task_set_uuid(struct dm_task *dmt, const char *uuid)
|
||||
@ -136,96 +136,94 @@ int dm_task_set_uuid(struct dm_task *dmt, const char *uuid)
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_very_verbose("Setting uuid: %s", dmt->uuid);
|
||||
log_debug("Setting uuid: %s", dmt->uuid);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dm_task_set_minor(struct dm_task *dmt, int minor)
|
||||
{
|
||||
dmt->minor = minor;
|
||||
return 1;
|
||||
dmt->minor = minor;
|
||||
log_debug("Setting minor: %d", dmt->minor);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int dm_task_add_target(struct dm_task *dmt,
|
||||
uint64_t start,
|
||||
uint64_t size,
|
||||
const char *ttype,
|
||||
const char *params)
|
||||
int dm_task_add_target(struct dm_task *dmt, uint64_t start, uint64_t size,
|
||||
const char *ttype, const char *params)
|
||||
{
|
||||
struct target *t = create_target(start, size, ttype, params);
|
||||
struct target *t = create_target(start, size, ttype, params);
|
||||
|
||||
if (!t)
|
||||
return 0;
|
||||
if (!t)
|
||||
return 0;
|
||||
|
||||
if (!dmt->head)
|
||||
dmt->head = dmt->tail = t;
|
||||
else {
|
||||
dmt->tail->next = t;
|
||||
dmt->tail = t;
|
||||
}
|
||||
if (!dmt->head)
|
||||
dmt->head = dmt->tail = t;
|
||||
else {
|
||||
dmt->tail->next = t;
|
||||
dmt->tail = t;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int add_dev_node(const char *dev_name, dev_t dev)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
struct stat info;
|
||||
char path[PATH_MAX];
|
||||
struct stat info;
|
||||
|
||||
_build_dev_path(path, sizeof(path), dev_name);
|
||||
_build_dev_path(path, sizeof(path), dev_name);
|
||||
|
||||
if (stat(path, &info) >= 0) {
|
||||
if (!S_ISBLK(info.st_mode)) {
|
||||
log_error("A non-block device file at '%s' "
|
||||
"is already present", path);
|
||||
return 0;
|
||||
}
|
||||
if (stat(path, &info) >= 0) {
|
||||
if (!S_ISBLK(info.st_mode)) {
|
||||
log_error("A non-block device file at '%s' "
|
||||
"is already present", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (info.st_rdev == dev)
|
||||
return 1;
|
||||
if (info.st_rdev == dev)
|
||||
return 1;
|
||||
|
||||
if (unlink(path) < 0) {
|
||||
log_error("Unable to unlink device node for '%s'", dev_name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (unlink(path) < 0) {
|
||||
log_error("Unable to unlink device node for '%s'",
|
||||
dev_name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (mknod(path, S_IFBLK | S_IRUSR | S_IWUSR | S_IRGRP, dev) < 0) {
|
||||
log_error("Unable to make device node for '%s'", dev_name);
|
||||
return 0;
|
||||
}
|
||||
if (mknod(path, S_IFBLK | S_IRUSR | S_IWUSR | S_IRGRP, dev) < 0) {
|
||||
log_error("Unable to make device node for '%s'", dev_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int rm_dev_node(const char *dev_name)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
struct stat info;
|
||||
char path[PATH_MAX];
|
||||
struct stat info;
|
||||
|
||||
_build_dev_path(path, sizeof(path), dev_name);
|
||||
_build_dev_path(path, sizeof(path), dev_name);
|
||||
|
||||
if (stat(path, &info) < 0)
|
||||
return 1;
|
||||
if (stat(path, &info) < 0)
|
||||
return 1;
|
||||
|
||||
if (unlink(path) < 0) {
|
||||
log_error("Unable to unlink device node for '%s'", dev_name);
|
||||
return 0;
|
||||
}
|
||||
if (unlink(path) < 0) {
|
||||
log_error("Unable to unlink device node for '%s'", dev_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dm_set_dev_dir(const char *dir)
|
||||
{
|
||||
snprintf(_dm_dir, sizeof(_dm_dir), "%s%s", dir, DM_DIR);
|
||||
return 1;
|
||||
snprintf(_dm_dir, sizeof(_dm_dir), "%s%s", dir, DM_DIR);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *dm_dir(void)
|
||||
{
|
||||
return _dm_dir;
|
||||
return _dm_dir;
|
||||
}
|
||||
|
||||
|
@ -230,7 +230,7 @@ static int _resume(int argc, char **argv)
|
||||
static int _info(int argc, char **argv)
|
||||
{
|
||||
int r = 0;
|
||||
char *uuid;
|
||||
const char *uuid;
|
||||
|
||||
/* remove <dev_name> */
|
||||
struct dm_task *dmt;
|
||||
|
Loading…
Reference in New Issue
Block a user