1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-25 01:34:38 +03:00
lvm2/lib/activate/fs.c

116 lines
2.1 KiB
C
Raw Normal View History

2001-11-09 11:48:22 +03:00
/*
* Copyright (C) 2001 Sistina Software (UK) Limited.
*
* This file is released under the LGPL.
*/
2001-11-12 14:48:31 +03:00
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
2001-11-09 11:48:22 +03:00
#include <unistd.h>
2001-11-12 14:48:31 +03:00
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "fs.h"
#include "log.h"
2001-11-09 11:48:22 +03:00
#include <libdevmapper.h>
2001-11-12 14:42:29 +03:00
void _build_lv_path(char *buffer, size_t len, struct logical_volume *lv)
2001-11-09 11:48:22 +03:00
{
snprintf(buffer, len, "%s/%s_%s", dm_dir(), lv->vg->name, lv->name);
2001-11-12 14:42:29 +03:00
}
2001-11-09 11:48:22 +03:00
2001-11-12 14:42:29 +03:00
void _build_vg_path(char *buffer, size_t len, struct volume_group *vg)
{
snprintf(buffer, len, "%s/%s", vg->cmd->dev_dir, vg->name);
}
2001-11-09 11:48:22 +03:00
2001-11-12 14:42:29 +03:00
void _build_link_path(char *buffer, size_t len, struct logical_volume *lv)
{
2001-11-12 14:48:31 +03:00
snprintf(buffer, len, "%s/%s/%s", lv->vg->cmd->dev_dir,
lv->vg->name, lv->name);
2001-11-09 11:48:22 +03:00
}
/*
* Lazy programmer: I'm just going to always try
* and create/remove the vg directory, and not say
* anything if it fails.
*/
static void _mk_dir(struct volume_group *vg)
2001-11-09 11:48:22 +03:00
{
char vg_path[PATH_MAX];
2001-11-12 14:42:29 +03:00
_build_vg_path(vg_path, sizeof(vg_path), vg);
2001-12-05 02:20:27 +03:00
log_very_verbose("Creating directory %s", vg_path);
2001-11-09 11:48:22 +03:00
mkdir(vg_path, 0555);
}
static void _rm_dir(struct volume_group *vg)
2001-11-09 11:48:22 +03:00
{
char vg_path[PATH_MAX];
2001-11-12 14:42:29 +03:00
_build_vg_path(vg_path, sizeof(vg_path), vg);
2001-12-05 02:20:27 +03:00
log_very_verbose("Removing directory %s", vg_path);
2001-11-09 11:48:22 +03:00
rmdir(vg_path);
}
2001-11-12 14:42:29 +03:00
static int _mk_link(struct logical_volume *lv)
2001-11-09 11:48:22 +03:00
{
char lv_path[PATH_MAX], link_path[PATH_MAX];
2001-11-12 14:42:29 +03:00
_build_lv_path(lv_path, sizeof(lv_path), lv);
_build_link_path(link_path, sizeof(link_path), lv);
2001-12-05 02:20:27 +03:00
log_very_verbose("Linking %s to %s", link_path, lv_path);
2001-11-12 14:42:29 +03:00
if (symlink(lv_path, link_path) < 0) {
log_sys_error("symlink", link_path);
2001-11-12 14:42:29 +03:00
return 0;
}
return 1;
}
static int _rm_link(struct logical_volume *lv)
{
char link_path[PATH_MAX];
_build_link_path(link_path, sizeof(link_path), lv);
2001-12-05 02:20:27 +03:00
log_very_verbose("Removing link %s", link_path);
2001-11-12 14:42:29 +03:00
if (unlink(link_path) < 0) {
log_sys_error("unlink", link_path);
2001-11-12 14:42:29 +03:00
return 0;
}
return 1;
2001-11-09 11:48:22 +03:00
}
2001-11-12 14:42:29 +03:00
int fs_add_lv(struct logical_volume *lv)
2001-11-09 11:48:22 +03:00
{
_mk_dir(lv->vg);
2001-11-09 11:48:22 +03:00
2001-11-12 14:42:29 +03:00
if (!_mk_link(lv)) {
2001-11-09 11:48:22 +03:00
stack;
return 0;
}
return 1;
}
int fs_del_lv(struct logical_volume *lv)
{
2001-11-12 14:42:29 +03:00
if (!_rm_link(lv)) {
2001-11-09 11:48:22 +03:00
stack;
return 0;
}
_rm_dir(lv->vg);
2001-11-09 11:48:22 +03:00
return 1;
}