1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

Another step towards consistency & compilation.

This commit is contained in:
Alasdair Kergon 2001-10-01 22:12:10 +00:00
parent 28f5d16b4f
commit 1f6db21f32
10 changed files with 131 additions and 108 deletions

View File

@ -22,7 +22,8 @@ VPATH = @srcdir@
SOURCES=\ SOURCES=\
config/config.c \ config/config.c \
dev-mgr/dev-manager.c \ datastruct/hash.c \
dev-mgr/dev-cache.c \
device/device.c \ device/device.c \
display/display.c \ display/display.c \
display/metadata.c \ display/metadata.c \

View File

@ -5,8 +5,8 @@
*/ */
#include "hash.h"
#include "dbg_malloc.h" #include "dbg_malloc.h"
#include "hash.h"
#include "log.h" #include "log.h"
struct hash_node { struct hash_node {
@ -68,7 +68,7 @@ static unsigned _hash(const char *str)
return h; return h;
} }
hash_table_t create_hash_table(unsigned size_hint) struct hash_table *create_hash_table(unsigned size_hint)
{ {
size_t len; size_t len;
unsigned new_size = 16u; unsigned new_size = 16u;
@ -92,7 +92,7 @@ hash_table_t create_hash_table(unsigned size_hint)
goto bad; goto bad;
} }
memset(hc->slots, 0, len); memset(hc->slots, 0, len);
return (hash_table_t) hc; return (struct hash_table) hc;
bad: bad:
dbg_free(hc->slots); dbg_free(hc->slots);

View File

@ -7,6 +7,8 @@
#ifndef _LVM_DEV_CACHE_H #ifndef _LVM_DEV_CACHE_H
#define _LVM_DEV_CACHE_H #define _LVM_DEV_CACHE_H
#include <sys/types.h>
/* /*
* All devices in LVM will be represented by one of these. * All devices in LVM will be represented by one of these.
* pointer comparisons are valid. * pointer comparisons are valid.
@ -17,7 +19,7 @@ struct device {
}; };
struct dev_filter { struct dev_filter {
int (*passes_filter)(struct dev_cache_filter *f, struct device *dev); int (*passes_filter)(struct dev_filter *f, struct device *dev);
void *private; void *private;
}; };
@ -45,7 +47,7 @@ struct device *dev_iter_get(struct dev_iter *iter);
* All io should use these routines, rather than opening the devices * All io should use these routines, rather than opening the devices
* by hand. You do not have to call an open routine. * by hand. You do not have to call an open routine.
*/ */
uint64_t dev_get_size(struct device *dev); /* in 512 byte sectors */ __uint64_t dev_get_size(struct device *dev); /* in 512 byte sectors */
ssize_t dev_read(struct device *dev, size_t offset, size_t len, void *buffer); ssize_t dev_read(struct device *dev, size_t offset, size_t len, void *buffer);
ssize_t dev_write(struct device *dev, size_t offset, size_t len, void *buffer); ssize_t dev_write(struct device *dev, size_t offset, size_t len, void *buffer);

View File

@ -30,7 +30,7 @@
#include "dbg_malloc.h" #include "dbg_malloc.h"
#include "log.h" #include "log.h"
#include "dev-manager.h" #include "dev-cache.h"
#include "metadata.h" #include "metadata.h"
#include "device.h" #include "device.h"

View File

@ -3,19 +3,47 @@
* *
* This file is released under the GPL. * This file is released under the GPL.
* *
* This is the in core representation of a volume group and it's * This is the in core representation of a volume group and its
* associated physical and logical volumes. * associated physical and logical volumes.
*/ */
#ifndef _LVM_METADATA_H #ifndef _LVM_METADATA_H
#define _LVM_METADATA_H #define _LVM_METADATA_H
#include <sys/types.h>
#include "dev-cache.h" #include "dev-cache.h"
#define ID_LEN 32 #define ID_LEN 32
/* Various flags */
/* Note that the bits no longer necessarily correspond to LVM1 disk format */
#define STATUS_ACTIVE 0x01 /* PV VG LV */
#define STATUS_EXPORTED 0x02 /* VG */
#define STATUS_EXTENDABLE 0x04 /* VG */
#define STATUS_ALLOCATED 0x02 /* PV */
#define STATUS_SPINDOWN 0x02 /* LV */
#define STATUS_BADBLOCK_ON 0x04 /* LV */
#define STATUS_ALLOC_STRICT 0x08 /* LV */
#define STATUS_ALLOC_CONTIGUOUS 0x10 /* LV */
#define ACCESS_READ 0x01 /* LV VG */
#define ACCESS_WRITE 0x02 /* LV VG */
#define ACCESS_SNAPSHOT 0x04 /* LV */
#define ACCESS_SNAPSHOT_ORG 0x08 /* LV */
#define ACCESS_CLUSTERED 0x04 /* VG */
#define ACCESS_SHARED 0x08 /* VG */
struct id { struct id {
uint8_t chars[ID_LEN]; __uint8_t chars[ID_LEN];
}; };
struct logical_volume; struct logical_volume;
@ -25,19 +53,19 @@ struct physical_volume {
struct device *dev; struct device *dev;
char *vg_name; char *vg_name;
uint32_t status; __uint32_t status;
uint64_t size; __uint64_t size;
/* physical extents */ /* physical extents */
uint64_t pe_size; __uint64_t pe_size;
uint64_t pe_start; __uint64_t pe_start;
uint32_t pe_count; __uint32_t pe_count;
uint32_t pe_allocated; __uint32_t pe_allocated;
}; };
struct pe_specifier { struct pe_specifier {
struct physical_volume *pv; struct physical_volume *pv;
uint32_t pe; __uint32_t pe;
}; };
struct logical_volume { struct logical_volume {
@ -45,12 +73,12 @@ struct logical_volume {
struct id *id; struct id *id;
char *name; char *name;
uint32_t access; __uint32_t access;
uint32_t status; __uint32_t status;
uint32_t open; __uint32_t open;
uint64_t size; __uint64_t size;
uint32_t le_count; __uint32_t le_count;
/* le -> pe mapping array */ /* le -> pe mapping array */
struct pe_specifier *map; struct pe_specifier *map;
@ -60,76 +88,62 @@ struct volume_group {
struct id *id; struct id *id;
char *name; char *name;
uint64_t extent_size; __uint64_t extent_size;
uint32_t extent_count; __uint32_t extent_count;
uint32_t free_count; __uint32_t free_count;
/* physical volumes */ /* physical volumes */
uint32_t pv_count; __uint32_t pv_count;
struct physical_volume **pv; struct physical_volume **pv;
/* logical volumes */ /* logical volumes */
uint32_t lv_count; __uint32_t lv_count;
struct logical_volume **lv; struct logical_volume **lv;
}; };
/* ownership of returned objects passes */ /* ownership of returned objects passes */
struct io_space { struct io_space {
struct str_list *(*get_vgs)(struct io_space *is); struct str_list *(*get_vgs)(struct io_space *is);
struct dev_list *(*get_pvs)(struct io_space *is); struct dev_list *(*get_pvs)(struct io_space *is);
struct physical_volume *pv_read(struct io_space *is, struct physical_volume *(*pv_read)(struct io_space *is,
struct device *dev); struct device *dev);
int pv_write(struct io_space *is, struct physical_volume *pv); int (*pv_write)(struct io_space *is, struct physical_volume *pv);
struct volume_group *(*vg_read)(struct io_space *is, struct volume_group *(*vg_read)(struct io_space *is,
const char *vg_name); const char *vg_name);
int (*vg_write)(struct io_space *is, struct volume_group *vg); int (*vg_write)(struct io_space *is, struct volume_group *vg);
void (*destructor)(struct io_space *is); void (*destroy)(struct io_space *is);
struct dev_filter *filter; struct dev_filter *filter;
void *private; void *private;
}; };
struct io_space *create_text_format(struct device_manager *mgr, /* FIXME: Move to other files */
struct io_space *create_text_format(struct dev_filter *filter,
const char *text_file); const char *text_file);
struct io_space *create_lvm_v1_format(struct dev_filter *filter);
inline struct volume_group *read_vg(struct io_space *f) inline int write_backup(struct io_space *orig, struct io_space *text)
{
struct dev_list *pvs = f->get_pvs();
return f->read_vg(pvs);
}
inline int write_vg(struct io_object *f, struct volume_group *vg)
{
return f->write_vg(vg);
}
inline int write_backup(struct io_format *orig, struct io_format *text)
{ {
} }
int id_eq(struct id *op1, struct id *op2); int id_eq(struct id *op1, struct id *op2);
struct volume_group *create_vg(); struct volume_group *vg_create();
int destroy_vg(struct volume_group *vg); struct physical_volume *pv_create();
int add_pv(struct volume_group *vg, struct physical_volume *pv); int vg_destroy(struct volume_group *vg);
struct physical_volume *find_pv(struct volume_group *vg,
int pv_add(struct volume_group *vg, struct physical_volume *pv);
struct physical_volume *pv_find(struct volume_group *vg,
struct physical_volume *pv); struct physical_volume *pv);
int add_lv(struct volume_group *vg, struct logical_volume *lv); int lv_add(struct volume_group *vg, struct logical_volume *lv);
struct logical_volume *find_lv(struct volume_group *vg, struct logical_volume *lv_find(struct volume_group *vg,
struct logical_volume *lv); struct logical_volume *lv);
struct io_handler {
struct volume_group *read_vg();
int write_vg(struct volume_group *vg);
};
#endif #endif

View File

@ -21,6 +21,8 @@
#ifndef _LVM_DBG_MALLOC_H #ifndef _LVM_DBG_MALLOC_H
#define _LVM_DBG_MALLOC_H #define _LVM_DBG_MALLOC_H
#include <sys/types.h>
#ifdef DEBUG_MEM #ifdef DEBUG_MEM
void *malloc_aux(size_t s, const char *file, int line); void *malloc_aux(size_t s, const char *file, int line);
void free_aux(void *p); void free_aux(void *p);

View File

@ -22,8 +22,9 @@ VPATH = @srcdir@
SOURCES=\ SOURCES=\
lvm.c\ lvm.c\
lvactivate.c\ pvcreate.c\
pvdisplay.c pvdisplay.c\
lvactivate.c
TARGETS=\ TARGETS=\
lvm lvm

View File

@ -24,38 +24,38 @@ int lvactivate(int argc, char **argv)
{ {
int p; int p;
struct dev_mgr *dm; struct io_space *ios;
struct device *pv_dev; struct device *pv_dev;
char *lv; char *lv_name;
char *pv_name; char *pv_name;
pv_t *pv = NULL; struct physical_volume *pv = NULL;
lv_disk_t *lvs = NULL; struct logical_volume *lv = NULL;
if (argc < 2) { if (argc < 2) {
log_error("please enter logical volume & physical volume(s)"); log_error("please enter logical volume & physical volume(s)");
return LVM_EINVALID_CMD_LINE; return LVM_EINVALID_CMD_LINE;
} }
lv = argv[0]; lv_name = argv[0];
argc--; argc--;
argv++; argv++;
dm = active_dev_mgr(); ios = active_ios();
while (argc--) { while (argc--) {
pv_name = argv[argc]; pv_name = argv[argc];
if (!(pv_dev = dev_by_name(dm, pv_name))) { if (!(pv_dev = dev_cache_get(pv_name))) {
log_error("device \"%s\" not found", pv_name); log_error("device \"%s\" not found", pv_name);
return -1; return -1;
} }
if (!(pv = pv_read(dm, pv_name))) { if (!(pv = pv_read(ios, pv_dev))) {
return -1; return -1;
} }
if (pv->pe_allocated) { if (pv->status & STATUS_ALLOCATED) {
if (!(pv->pe = pv_read_pe(pv_name, pv))) if (!(pv->pe = pv_read_pe(pv_name, pv)))
goto pvdisplay_device_out; goto pvdisplay_device_out;
if (!(lvs = pv_read_lvs(pv))) { if (!(lvs = pv_read_lvs(pv))) {

View File

@ -59,6 +59,7 @@ static int _num_commands;
static struct command *_commands; static struct command *_commands;
static struct dev_filter *_filter; static struct dev_filter *_filter;
static struct io_space *_ios;
static struct config_file *_cf; static struct config_file *_cf;
static int _interactive; static int _interactive;
@ -211,10 +212,10 @@ int string_arg(struct arg *a)
int permission_arg(struct arg *a) int permission_arg(struct arg *a)
{ {
if ((!strcmp(a->value, "rw")) || (!strcmp(a->value, "wr"))) if ((!strcmp(a->value, "rw")) || (!strcmp(a->value, "wr")))
a->i_value = LV_READ | LV_WRITE; a->i_value = ACCESS_READ | ACCESS_WRITE;
else if (!strcmp(a->value, "r")) else if (!strcmp(a->value, "r"))
a->i_value = LV_READ; a->i_value = ACCESS_READ;
else else
return 0; return 0;
@ -447,8 +448,8 @@ static int process_common_commands(struct command *com)
} }
if (arg_count(version_ARG)) { if (arg_count(version_ARG)) {
/* FIXME: Add driver version */ /* FIXME: Add driver and software version */
log_error("%s: %s", com->name, lvm_version); log_error("%s: ", com->name);
return LVM_ECMD_PROCESSED; return LVM_ECMD_PROCESSED;
} }
@ -548,6 +549,14 @@ struct config_file *active_config_file(void) {
return _cf; return _cf;
} }
struct dev_filter *active_filter(void) {
return _filter;
}
struct io_space *active_ios(void) {
return _ios;
}
static void __init_log(struct config_file *cf) static void __init_log(struct config_file *cf)
{ {
const char *log_file = find_config_str(cf->root, "log/file", '/', 0); const char *log_file = find_config_str(cf->root, "log/file", '/', 0);
@ -601,6 +610,10 @@ static int init(void)
goto out; goto out;
} }
if (!(_ios = create_lvm_v1_format(_filter))) {
goto out;
}
ret = 1; ret = 1;
out: out:
@ -619,6 +632,7 @@ static void __fin_commands(void)
static void fin(void) static void fin(void)
{ {
_ios->destroy(_ios);
config_filter_destroy(_filter); config_filter_destroy(_filter);
dev_cache_exit(); dev_cache_exit();
destroy_config_file(_cf); destroy_config_file(_cf);

View File

@ -45,42 +45,36 @@ int pvcreate(int argc, char **argv)
void pvcreate_single(const char *pv_name) void pvcreate_single(const char *pv_name)
{ {
int size; int size;
pv_t *pv = NULL; struct physical_volume *pv = NULL;
pv_t *pv_new;
struct dev_mgr *dm; struct io_space *ios;
struct device *pv_dev; struct device *pv_dev;
dm = active_dev_mgr(); ios = active_ios();
if (!(pv_dev = dev_by_name(dm, pv_name))) { if (!(pv_dev = dev_cache_get(pv_name))) {
log_error("Device %s not found", pv_name); log_error("Device %s not found", pv_name);
return; return;
} }
if ((size = device_get_size(pv_name)) < 0) { if ((size = dev_get_size(pv_dev)) < 0) {
log_error("Unable to get size of %s", pv_name); log_error("Unable to get size of %s", pv_name);
return; return;
} }
if (arg_count(force_ARG) < 1 && !partition_type_is_lvm(dm, pv_dev)) { if (arg_count(force_ARG) < 1 && !partition_type_is_lvm(ios, pv_dev)) {
return; return;
} }
if (!(pv = pv_read(dm, pv_name))) { pv = ios->pv_read(ios, pv_dev);
if (pv && (pv->status & STATUS_EXPORTED)) {
log_error ("Physical volume %s belongs to exported volume"
" group %s", pv_name, pv->vg_name);
return; return;
} }
/**** if (pv && pv->vg_name[0]) {
FIXME: Check attributes
EXPORTED
pv->vg_name[strlen(pv->vg_name) - strlen(EXPORTED)] = 0;
log_error ("physical volume \"%s\" belongs to exported volume group \"%s\"",
pv_name, pv->vg_name);
*****/
if (pv->vg_name[0]) {
if (arg_count(force_ARG) < 2) { if (arg_count(force_ARG) < 2) {
log_error("Can't initialize physical volume %s of " log_error("Can't initialize physical volume %s of "
"volume group %s without -ff", pv_name, "volume group %s without -ff", pv_name,
@ -99,18 +93,20 @@ void pvcreate_single(const char *pv_name)
} }
} }
/***
if (pv) { if (pv && (pv->status & STATUS_ACTIVE)) {
if (pv_check_active((char *) pv->vg_name, (char *) pv_name) == log_error("Can't create on active physical volume %s",
TRUE) {
log_error
("can't force create on active physical volume \"%s\"",
pv_name); pv_name);
return; return;
} }
***/
if (!pv) {
if (!(pv = pv_create()))
return;
/* FIXME: Set up initial size & PEs here */
}
if (arg_count(force_ARG)) { if (arg_count(force_ARG)) {
/* FIXME: Change to log_print */ /* FIXME: Change to log_print */
@ -127,20 +123,13 @@ void pvcreate_single(const char *pv_name)
log_verbose("setting up physical volume for %s with %u sectors", log_verbose("setting up physical volume for %s with %u sectors",
pv_name, size); pv_name, size);
/*** FIXME: New metadata creation fn reqd
if (!(pv_new = pv_setup_for_create(pv_name, size)) < 0) {
log_error("Failed to set up physical volume %s", pv_name);
return;
}
***/
log_verbose("writing physical volume data to disk %s", pv_name); log_verbose("writing physical volume data to disk %s", pv_name);
/*** FIXME: New metadata write fn reqd if (!(pv_write(ios, pv))) {
if (!(pv_write(pv_name, pv_new)) == 0) {
log_error("Failed to create physical volume %s", pv_name); log_error("Failed to create physical volume %s", pv_name);
return;
} }
***/
printf("physical volume %s successfully created\n", pv_name); printf("physical volume %s successfully created\n", pv_name);