mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-10 16:58:47 +03:00
o Oops, I thought this was checked in ages ago.
This commit is contained in:
parent
7c77eca4f7
commit
0d3593f5c1
@ -17,43 +17,6 @@
|
|||||||
|
|
||||||
#include <devmapper/libdevmapper.h>
|
#include <devmapper/libdevmapper.h>
|
||||||
|
|
||||||
/*
|
|
||||||
* FIXME: copied straight from LVM1.
|
|
||||||
*
|
|
||||||
* This should run through /proc/mounts once only,
|
|
||||||
* storing devfs mount points in a hash table.
|
|
||||||
*/
|
|
||||||
static int _check_devfs(const char *dev_dir)
|
|
||||||
{
|
|
||||||
int r = 0, len;
|
|
||||||
char dir[PATH_MAX], line[512];
|
|
||||||
char type[32];
|
|
||||||
FILE *mounts = NULL;
|
|
||||||
|
|
||||||
if (!(mounts = fopen("/proc/mounts", "r")))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
/* trim the trailing slash off dev_dir, yuck */
|
|
||||||
len = strlen(dev_dir) - 1;
|
|
||||||
while(len && dev_dir[len] == '/')
|
|
||||||
len--;
|
|
||||||
|
|
||||||
while (!feof(mounts)) {
|
|
||||||
fgets(line, sizeof(line) - 1, mounts);
|
|
||||||
if (sscanf(line, "%*s %s %s %*s", dir, type) != 2)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!strcmp(type, "devfs") && !strncmp(dir, dev_dir, len)) {
|
|
||||||
r = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(mounts);
|
|
||||||
|
|
||||||
out:
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _build_lv_path(char *buffer, size_t len, struct logical_volume *lv)
|
void _build_lv_path(char *buffer, size_t len, struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
snprintf(buffer, len, "%s%s/%s_%s",
|
snprintf(buffer, len, "%s%s/%s_%s",
|
||||||
@ -71,72 +34,25 @@ void _build_link_path(char *buffer, size_t len, struct logical_volume *lv)
|
|||||||
lv->vg->name, lv->name);
|
lv->vg->name, lv->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _mk_node(struct logical_volume *lv)
|
|
||||||
{
|
|
||||||
char lv_path[PATH_MAX];
|
|
||||||
char dm_path[PATH_MAX];
|
|
||||||
dev_t dev;
|
|
||||||
const char *dev_dir = lv->vg->cmd->dev_dir;
|
|
||||||
|
|
||||||
if (_check_devfs(dev_dir))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
snprintf(dm_path, PATH_MAX, "%s%s", dev_dir, dm_dir());
|
|
||||||
if (mkdir(dm_path, 0555) && errno != EEXIST) {
|
|
||||||
log_sys_error("mkdir", dm_path);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
_build_lv_path(lv_path, sizeof(lv_path), lv);
|
|
||||||
|
|
||||||
// FIXME: dev never get's initialised !
|
|
||||||
if (mknod(lv_path, S_IFBLK | S_IRUSR | S_IWUSR | S_IRGRP, dev) < 0) {
|
|
||||||
log_sys_error("mknod", lv_path);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _rm_node(struct logical_volume *lv)
|
|
||||||
{
|
|
||||||
char lv_path[PATH_MAX];
|
|
||||||
const char *dev_dir = lv->vg->cmd->dev_dir;
|
|
||||||
|
|
||||||
if (_check_devfs(dev_dir))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
_build_lv_path(lv_path, sizeof(lv_path), lv);
|
|
||||||
|
|
||||||
if (unlink(lv_path) < 0) {
|
|
||||||
log_sys_error("unlink", lv_path);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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 int _mk_dir(struct volume_group *vg)
|
static void _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);
|
_build_vg_path(vg_path, sizeof(vg_path), vg);
|
||||||
mkdir(vg_path, 0555);
|
mkdir(vg_path, 0555);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _rm_dir(struct volume_group *vg)
|
static void _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);
|
_build_vg_path(vg_path, sizeof(vg_path), vg);
|
||||||
rmdir(vg_path);
|
rmdir(vg_path);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _mk_link(struct logical_volume *lv)
|
static int _mk_link(struct logical_volume *lv)
|
||||||
@ -170,15 +86,7 @@ static int _rm_link(struct logical_volume *lv)
|
|||||||
|
|
||||||
int fs_add_lv(struct logical_volume *lv)
|
int fs_add_lv(struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
if (!_mk_node(lv)) {
|
_mk_dir(lv->vg);
|
||||||
stack;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_mk_dir(lv->vg)) {
|
|
||||||
stack;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_mk_link(lv)) {
|
if (!_mk_link(lv)) {
|
||||||
stack;
|
stack;
|
||||||
@ -195,15 +103,7 @@ int fs_del_lv(struct logical_volume *lv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_rm_dir(lv->vg)) {
|
_rm_dir(lv->vg);
|
||||||
stack;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_rm_node(lv)) {
|
|
||||||
stack;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
|
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These calls, private to the activate unit, set
|
||||||
|
* up the volume group directory in /dev and the
|
||||||
|
* symbolic links to the dm device.
|
||||||
|
*/
|
||||||
|
|
||||||
int fs_add_lv(struct logical_volume *lv);
|
int fs_add_lv(struct logical_volume *lv);
|
||||||
int fs_del_lv(struct logical_volume *lv);
|
int fs_del_lv(struct logical_volume *lv);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user