mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o move the path building functions to lib/activate/names.c
o Update activate.c and fs.c to use them o device names are now of the form <vg>:<lv>
This commit is contained in:
parent
682c0fef74
commit
12137231d3
@ -11,6 +11,7 @@ VPATH = @srcdir@
|
|||||||
SOURCES=\
|
SOURCES=\
|
||||||
activate/activate.c \
|
activate/activate.c \
|
||||||
activate/fs.c \
|
activate/fs.c \
|
||||||
|
activate/names.c \
|
||||||
config/config.c \
|
config/config.c \
|
||||||
datastruct/bitset.c \
|
datastruct/bitset.c \
|
||||||
datastruct/btree.c \
|
datastruct/btree.c \
|
||||||
|
@ -10,6 +10,10 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "lvm-string.h"
|
#include "lvm-string.h"
|
||||||
|
#include "names.h"
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
|
||||||
int library_version(char *version, size_t size)
|
int library_version(char *version, size_t size)
|
||||||
{
|
{
|
||||||
@ -18,14 +22,9 @@ int library_version(char *version, size_t size)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _build_lv_name(char *buffer, size_t s, const char *vg_name,
|
|
||||||
const char *lv_name)
|
|
||||||
{
|
|
||||||
snprintf(buffer, s, "%s_%s", vg_name, lv_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct dm_task *_setup_task_with_name(struct logical_volume *lv,
|
static struct dm_task *_setup_task_with_name(struct logical_volume *lv,
|
||||||
const char *lv_name, int task)
|
const char *lv_name,
|
||||||
|
int task)
|
||||||
{
|
{
|
||||||
char name[128];
|
char name[128];
|
||||||
struct dm_task *dmt;
|
struct dm_task *dmt;
|
||||||
@ -35,7 +34,11 @@ static struct dm_task *_setup_task_with_name(struct logical_volume *lv,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_build_lv_name(name, sizeof(name), lv->vg->name, lv_name);
|
if (!build_dm_name(name, sizeof(name), lv->vg->name, lv_name)) {
|
||||||
|
stack;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
dm_task_set_name(dmt, name);
|
dm_task_set_name(dmt, name);
|
||||||
|
|
||||||
return dmt;
|
return dmt;
|
||||||
@ -101,7 +104,7 @@ int lv_info(struct logical_volume *lv, struct dm_info *info)
|
|||||||
int lv_rename(const char *old_name, struct logical_volume *lv)
|
int lv_rename(const char *old_name, struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
int r = 0;
|
int r = 0;
|
||||||
char new_name[128];
|
char new_name[PATH_MAX];
|
||||||
struct dm_task *dmt;
|
struct dm_task *dmt;
|
||||||
|
|
||||||
if (test_mode())
|
if (test_mode())
|
||||||
@ -112,7 +115,11 @@ int lv_rename(const char *old_name, struct logical_volume *lv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_build_lv_name(new_name, sizeof(new_name), lv->vg->name, lv->name);
|
if (!build_dm_name(new_name, sizeof(new_name),
|
||||||
|
lv->vg->name, lv->name)) {
|
||||||
|
stack;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!dm_task_set_newname(dmt, new_name)) {
|
if (!dm_task_set_newname(dmt, new_name)) {
|
||||||
stack;
|
stack;
|
||||||
|
@ -14,59 +14,65 @@
|
|||||||
|
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "names.h"
|
||||||
|
|
||||||
#include <libdevmapper.h>
|
#include <libdevmapper.h>
|
||||||
|
|
||||||
|
|
||||||
void _build_lv_path(char *buffer, size_t len, struct logical_volume *lv,
|
|
||||||
const char *lv_name)
|
|
||||||
{
|
|
||||||
snprintf(buffer, len, "%s/%s_%s", dm_dir(), lv->vg->name, lv_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _build_vg_path(char *buffer, size_t len, struct volume_group *vg)
|
|
||||||
{
|
|
||||||
snprintf(buffer, len, "%s%s", vg->cmd->dev_dir, vg->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _build_link_path(char *buffer, size_t len, struct logical_volume *lv,
|
|
||||||
const char *lv_name)
|
|
||||||
{
|
|
||||||
snprintf(buffer, len, "%s%s/%s", lv->vg->cmd->dev_dir,
|
|
||||||
lv->vg->name, lv_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lazy programmer: I'm just going to always try
|
* Lazy programmer: I'm just going to always try
|
||||||
* and create/remove the vg directory, and not say
|
* and create/remove the vg directory, and not say
|
||||||
* anything if it fails.
|
* anything if it fails.
|
||||||
*/
|
*/
|
||||||
static void _mk_dir(struct volume_group *vg)
|
static int _mk_dir(struct volume_group *vg)
|
||||||
{
|
{
|
||||||
char vg_path[PATH_MAX];
|
char vg_path[PATH_MAX];
|
||||||
|
|
||||||
_build_vg_path(vg_path, sizeof(vg_path), vg);
|
if (!build_vg_path(vg_path, sizeof(vg_path),
|
||||||
|
vg->cmd->dev_dir, vg->name)) {
|
||||||
|
log_err("Couldn't create volume group directory.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
log_very_verbose("Creating directory %s", vg_path);
|
log_very_verbose("Creating directory %s", vg_path);
|
||||||
mkdir(vg_path, 0555);
|
mkdir(vg_path, 0555);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _rm_dir(struct volume_group *vg)
|
static int _rm_dir(struct volume_group *vg)
|
||||||
{
|
{
|
||||||
char vg_path[PATH_MAX];
|
char vg_path[PATH_MAX];
|
||||||
|
|
||||||
_build_vg_path(vg_path, sizeof(vg_path), vg);
|
if (!build_vg_path(vg_path, sizeof(vg_path),
|
||||||
|
vg->cmd->dev_dir, vg->name)) {
|
||||||
|
log_err("Couldn't remove volume group directory.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
log_very_verbose("Removing directory %s", vg_path);
|
log_very_verbose("Removing directory %s", vg_path);
|
||||||
rmdir(vg_path);
|
rmdir(vg_path);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _mk_link(struct logical_volume *lv)
|
static int _mk_link(struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
char lv_path[PATH_MAX], link_path[PATH_MAX];
|
char lv_path[PATH_MAX], link_path[PATH_MAX];
|
||||||
|
|
||||||
_build_lv_path(lv_path, sizeof(lv_path), lv, lv->name);
|
if (!build_dm_path(lv_path, sizeof(lv_path), lv->vg->name, lv->name)) {
|
||||||
_build_link_path(link_path, sizeof(link_path), lv, lv->name);
|
log_err("Couldn't create destination path for "
|
||||||
|
"logical volume link.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!build_lv_link_path(link_path, sizeof(link_path),
|
||||||
|
lv->vg->cmd->dev_dir,
|
||||||
|
lv->vg->name, lv->name)) {
|
||||||
|
log_err("Couldn't create source path for "
|
||||||
|
"logical volume link.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
log_very_verbose("Linking %s to %s", link_path, lv_path);
|
log_very_verbose("Linking %s to %s", link_path, lv_path);
|
||||||
if (symlink(lv_path, link_path) < 0) {
|
if (symlink(lv_path, link_path) < 0) {
|
||||||
@ -84,7 +90,12 @@ static int _rm_link(struct logical_volume *lv, const char *lv_name)
|
|||||||
if (!lv_name)
|
if (!lv_name)
|
||||||
lv_name = lv->name;
|
lv_name = lv->name;
|
||||||
|
|
||||||
_build_link_path(link_path, sizeof(link_path), lv, lv_name);
|
if (!build_lv_link_path(link_path, sizeof(link_path),
|
||||||
|
lv->vg->cmd->dev_dir,
|
||||||
|
lv->vg->name, lv->name)) {
|
||||||
|
log_err("Couldn't create link path (in order to remove it.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
log_very_verbose("Removing link %s", link_path);
|
log_very_verbose("Removing link %s", link_path);
|
||||||
if (unlink(link_path) < 0) {
|
if (unlink(link_path) < 0) {
|
||||||
@ -97,9 +108,8 @@ static int _rm_link(struct logical_volume *lv, const char *lv_name)
|
|||||||
|
|
||||||
int fs_add_lv(struct logical_volume *lv)
|
int fs_add_lv(struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
_mk_dir(lv->vg);
|
if (!_mk_dir(lv->vg) ||
|
||||||
|
!_mk_link(lv)) {
|
||||||
if (!_mk_link(lv)) {
|
|
||||||
stack;
|
stack;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -109,13 +119,12 @@ int fs_add_lv(struct logical_volume *lv)
|
|||||||
|
|
||||||
int fs_del_lv(struct logical_volume *lv)
|
int fs_del_lv(struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
if (!_rm_link(lv, NULL)) {
|
if (!_rm_link(lv, NULL) ||
|
||||||
|
!_rm_dir(lv->vg)) {
|
||||||
stack;
|
stack;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_rm_dir(lv->vg);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#ifndef _LVM_STRING_H
|
#ifndef _LVM_STRING_H
|
||||||
#define _LVM_STRING_H
|
#define _LVM_STRING_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user