1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

o removed old files

This commit is contained in:
Joe Thornber 2001-10-23 14:17:07 +00:00
parent 9d3bf3e2c1
commit 68c14b47aa
2 changed files with 0 additions and 706 deletions

View File

@ -1,501 +0,0 @@
/*
* Copyright (C) 2001 Sistina Software
*
* This LVM library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This LVM library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this LVM library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include "dbg_malloc.h"
#include "dev-manager.h"
#include "log.h"
#include "metadata.h"
/*
* FIXME: these should not allocate memory
*/
pv_t *pv_copy_from_disk(pv_disk_t * pv_disk)
{
pv_t *pv;
if (!pv_disk || !(pv = (pv_t *) dbg_malloc(sizeof (*pv))))
return 0;
#define xx16(v) pv->v = LVM_TO_CORE16(pv_disk->v)
#define xx32(v) pv->v = LVM_TO_CORE32(pv_disk->v)
memset(pv, 0, sizeof (*pv));
strncpy(pv->id, pv_disk->id, sizeof (pv->id));
xx16(version);
xx32(pv_on_disk.base);
xx32(pv_on_disk.size);
xx32(vg_on_disk.base);
xx32(vg_on_disk.size);
xx32(pv_uuidlist_on_disk.base);
xx32(pv_uuidlist_on_disk.size);
xx32(lv_on_disk.base);
xx32(lv_on_disk.size);
xx32(pe_on_disk.base);
xx32(pe_on_disk.size);
memset(pv->pv_name, 0, sizeof (pv->pv_name));
memset(pv->pv_uuid, 0, sizeof (pv->pv_uuid));
memcpy(pv->pv_uuid, pv_disk->pv_uuid, UUID_LEN);
strncpy(pv->vg_name, pv_disk->vg_name, sizeof (pv->vg_name));
strncpy(pv->system_id, pv_disk->system_id, sizeof (pv->system_id));
pv->pv_dev = LVM_TO_CORE32(pv_disk->pv_major);
xx32(pv_number);
xx32(pv_status);
xx32(pv_allocatable);
xx32(pv_size);
xx32(lv_cur);
xx32(pe_size);
xx32(pe_total);
xx32(pe_allocated);
pv->pe_stale = 0;
xx32(pe_start);
#undef xx16
#undef xx32
return pv;
}
pv_disk_t *pv_copy_to_disk(pv_t * pv_core)
{
pv_disk_t *pv;
if (!pv_core || !(pv = dbg_malloc(sizeof (*pv))))
return 0;
#define xx16(v) pv->v = LVM_TO_DISK16(pv_core->v)
#define xx32(v) pv->v = LVM_TO_DISK32(pv_core->v)
memset(pv, 0, sizeof (*pv));
strncpy(pv->id, pv_core->id, sizeof (pv->id));
xx16(version);
xx32(pv_on_disk.base);
xx32(pv_on_disk.size);
xx32(vg_on_disk.base);
xx32(vg_on_disk.size);
xx32(pv_uuidlist_on_disk.base);
xx32(pv_uuidlist_on_disk.size);
xx32(lv_on_disk.base);
xx32(lv_on_disk.size);
xx32(pe_on_disk.base);
xx32(pe_on_disk.size);
memcpy(pv->pv_uuid, pv_core->pv_uuid, UUID_LEN);
strncpy(pv->vg_name, pv_core->vg_name, sizeof (pv->vg_name));
strncpy(pv->system_id, pv_core->system_id, sizeof (pv->system_id));
/* core type is kdev_t; but no matter what it is,
only store major for check in pv_read() */
pv->pv_major = LVM_TO_DISK32(MAJOR(pv_core->pv_dev));
xx32(pv_number);
xx32(pv_status);
xx32(pv_allocatable);
xx32(pv_size);
xx32(lv_cur);
xx32(pe_size);
xx32(pe_total);
xx32(pe_allocated);
xx32(pe_start);
#undef xx16
#undef xx32
return pv;
}
lv_t *lv_copy_from_disk(lv_disk_t * lv_disk)
{
lv_t *lv;
if (!lv_disk || !(lv = dbg_malloc(sizeof (*lv))))
return 0;
memset(lv, 0, sizeof (*lv));
#define xx16(v) lv->v = LVM_TO_CORE16(lv_disk->v)
#define xx32(v) lv->v = LVM_TO_CORE32(lv_disk->v)
strncpy(lv->lv_name, lv_disk->lv_name, sizeof (lv->lv_name));
strncpy(lv->vg_name, lv_disk->vg_name, sizeof (lv->vg_name));
xx32(lv_access);
xx32(lv_status);
lv->lv_open = 0;
xx32(lv_dev);
xx32(lv_number);
xx32(lv_mirror_copies);
xx32(lv_recovery);
xx32(lv_schedule);
xx32(lv_size);
lv->lv_current_pe = NULL;
xx32(lv_allocated_le);
lv->lv_current_le = lv->lv_allocated_le;
xx32(lv_stripes);
xx32(lv_stripesize);
xx32(lv_badblock);
xx32(lv_allocation);
xx32(lv_io_timeout);
xx32(lv_read_ahead);
lv->lv_snapshot_org = NULL;
lv->lv_snapshot_prev = NULL;
lv->lv_snapshot_next = NULL;
lv->lv_block_exception = NULL;
lv->lv_remap_ptr = 0;
lv->lv_remap_end = 0;
xx32(lv_snapshot_minor);
xx16(lv_chunk_size);
#undef xx32
#undef xx16
return lv;
}
lv_disk_t *lv_copy_to_disk(lv_t * lv_core)
{
lv_disk_t *lv;
if (!lv_core || !(lv = dbg_malloc(sizeof (*lv))))
return 0;
memset(lv, 0, sizeof (*lv));
#define xx16(v) lv->v = LVM_TO_DISK16(lv_core->v)
#define xx32(v) lv->v = LVM_TO_DISK32(lv_core->v)
strncpy(lv->lv_name, lv_core->lv_name, sizeof (lv->lv_name));
strncpy(lv->vg_name, lv_core->vg_name, sizeof (lv->vg_name));
xx32(lv_access);
xx32(lv_status);
lv->lv_open = 0;
xx32(lv_dev);
xx32(lv_number);
xx32(lv_mirror_copies);
xx32(lv_recovery);
xx32(lv_schedule);
xx32(lv_size);
xx32(lv_snapshot_minor);
xx16(lv_chunk_size);
lv->dummy = 0;
xx32(lv_allocated_le);
xx32(lv_stripes);
xx32(lv_stripesize);
xx32(lv_badblock);
xx32(lv_allocation);
xx32(lv_io_timeout);
xx32(lv_read_ahead);
#undef xx32
#undef xx16
return lv;
}
vg_t *vg_copy_from_disk(vg_disk_t * vg_disk)
{
vg_t *vg;
if (!vg_disk || !(vg = dbg_malloc(sizeof (*vg))))
return 0;
#define xx32(v) vg->v = LVM_TO_CORE32(vg_disk->v)
memset(vg, 0, sizeof (vg_t));
xx32(vg_number);
xx32(vg_access);
xx32(vg_status);
xx32(lv_max);
xx32(lv_cur);
vg->lv_open = 0;
xx32(pv_max);
xx32(pv_cur);
xx32(pv_act);
vg->dummy = 0;
xx32(vgda);
xx32(pe_size);
xx32(pe_total);
xx32(pe_allocated);
xx32(pvg_total);
#undef xx32
memset(&vg->pv, 0, sizeof (vg->pv));
memset(&vg->lv, 0, sizeof (vg->lv));
memset(vg->vg_uuid, 0, sizeof (vg->vg_uuid));
memcpy(vg->vg_uuid, vg_disk->vg_uuid, UUID_LEN);
return vg;
}
vg_disk_t *vg_copy_to_disk(vg_t * vg_core)
{
vg_disk_t *vg;
if (!vg_core ||
/* FIXME: vg_check_consistency(vg_core) || */
!(vg = dbg_malloc(sizeof (*vg))))
return 0;
memset(vg, 0, sizeof (*vg));
#define xx32(v) vg->v = LVM_TO_DISK32(vg_core->v)
xx32(vg_number);
xx32(vg_access);
xx32(vg_status);
xx32(lv_max);
xx32(lv_cur);
vg->lv_open = 0;
xx32(pv_max);
xx32(pv_cur);
xx32(pv_act);
vg->dummy = 0;
xx32(vgda);
xx32(pe_size);
xx32(pe_total);
xx32(pe_allocated);
xx32(pvg_total);
#undef xx32
memcpy(vg->vg_uuid, vg_core->vg_uuid, UUID_LEN);
return vg;
}
pe_disk_t *pe_copy_from_disk(pe_disk_t * pe_file, int count)
{
int i;
pe_disk_t *pe;
size_t s = sizeof (*pe) * count;
if (!pe_file || count <= 0 || !(pe = dbg_malloc(s)))
return 0;
memset(pe, 0, s);
for (i = 0; i < count; i++) {
pe[i].lv_num = LVM_TO_CORE16(pe_file[i].lv_num);
pe[i].le_num = LVM_TO_CORE16(pe_file[i].le_num);
}
return pe;
}
pe_disk_t *pe_copy_to_disk(pe_disk_t * pe_core, int count)
{
int i;
pe_disk_t *pe;
size_t s = sizeof (*pe) * count;
if (!pe_core || count <= 0 || !(pe = dbg_malloc(s)))
return 0;
memset(pe, 0, s);
for (i = 0; i < count; i++) {
pe[i].lv_num = LVM_TO_DISK16(pe_core[i].lv_num);
pe[i].le_num = LVM_TO_DISK16(pe_core[i].le_num);
}
return pe;
}
pv_t *pv_read_lvm_v1(struct dev_mgr * dm, const char *pv_name)
{
int pv_handle = -1;
ssize_t read_ret;
ssize_t bytes_read = 0;
static pv_disk_t pv_this;
struct stat stat_b;
pv_t *pv = NULL;
struct device *pv_dev;
if ((pv_handle = open(pv_name, O_RDONLY)) == -1) {
log_error("%s: open failed: %s", pv_name, strerror(errno));
return NULL;
}
if ((fstat(pv_handle, &stat_b))) {
log_error("%s: fstat failed: %s", pv_name, strerror(errno));
goto pv_read_lvm_v1_out;
}
while ((bytes_read < sizeof (pv_this) &&
(read_ret = read(pv_handle, &pv_this + bytes_read,
sizeof (pv_this) - bytes_read)) != -1))
bytes_read += read_ret;
if (read_ret == -1) {
log_error("%s: read failed: %s", pv_name, strerror(errno));
goto pv_read_lvm_v1_out;
}
pv = pv_copy_from_disk(&pv_this);
/* correct for imported/moved volumes */
if (!(pv_dev = dev_by_dev(dm, stat_b.st_rdev))) {
log_error("Device missing from cache");
goto pv_read_lvm_v1_out;
}
memset(pv->pv_name, 0, sizeof (pv->pv_name));
strncpy(pv->pv_name, pv_dev->name, sizeof (pv->pv_name) - 1);
/* FIXME: Deleted version / consistency / export checks! */
pv->pv_dev = stat_b.st_rdev;
pv_read_lvm_v1_out:
if (pv_handle != -1)
close(pv_handle);
return pv;
}
pe_disk_t *pv_read_pe_lvm_v1(const char *pv_name, const pv_t * pv)
{
int pv_handle = -1;
uint size = 0;
ssize_t read_ret;
ssize_t bytes_read = 0;
pe_disk_t *pe = NULL;
pe_disk_t *pe_this;
size = pv->pe_total * sizeof (pe_disk_t);
if (size > pv->pe_on_disk.size) {
log_error("PEs extend beyond end of volume group!");
return pe; /*NULL*/
}
if ((pv_handle = open(pv_name, O_RDONLY)) == -1) {
log_error("%s: open failed: %s", pv_name, strerror(errno));
goto pv_read_pe_out;
}
if (lseek(pv_handle, pv->pe_on_disk.base, SEEK_SET) !=
pv->pe_on_disk.base) {
log_error("%s: lseek to PE failed: %s", pv_name, strerror(errno));
goto pv_read_pe_out;
}
if (!(pe_this = dbg_malloc(size))) {
log_error("PE malloc failed");
goto pv_read_pe_out;
}
while ((bytes_read < size &&
(read_ret = read(pv_handle, (void *)pe_this + bytes_read,
size - bytes_read)) != -1))
bytes_read += read_ret;
if (read_ret == -1) {
log_error("%s: read failed: %s", pv_name, strerror(errno));
goto pv_read_pe_out;
}
pe = pe_copy_from_disk(pe_this, pv->pe_total);
pv_read_pe_out:
if (pv_handle != -1)
close(pv_handle);
dbg_free(pe_this);
return pe;
}
lv_disk_t *pv_read_lvs_lvm_v1(const pv_t *pv)
{
int pv_handle = -1;
uint size = 0;
ssize_t read_ret;
ssize_t bytes_read = 0;
lv_disk_t *lvs;
/* FIXME: replace lv_cur? */
size = pv->lv_cur * sizeof (lv_disk_t);
if ((pv_handle = open(pv->pv_name, O_RDONLY)) == -1) {
log_error("%s: open failed: %s", pv->pv_name, strerror(errno));
goto pv_read_lvs_out;
}
if (lseek(pv_handle, pv->lv_on_disk.base, SEEK_SET) !=
pv->lv_on_disk.base) {
log_error("%s: lseek to LV failed: %s", pv->pv_name, strerror(errno));
goto pv_read_lvs_out;
}
if (!(lvs = dbg_malloc(size))) {
log_error("PE malloc failed");
goto pv_read_lvs_out;
}
while ((bytes_read < size &&
(read_ret = read(pv_handle, (void *) lvs + bytes_read,
size - bytes_read)) != -1))
bytes_read += read_ret;
if (read_ret == -1) {
log_error("%s: read failed: %s", pv->pv_name, strerror(errno));
goto pv_read_lvs_out;
}
pv_read_lvs_out:
if (pv_handle != -1)
close(pv_handle);
/* Caller frees */
return lvs;
}

View File

@ -1,205 +0,0 @@
/*
* Copyright (C) 2001 Sistina Software
*
* lvm is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* lvm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU CC; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifndef _LVM_V1_H_INCLUDE
#define _LVM_V1_H_INCLUDE
#ifdef __KERNEL__
#include <linux/kdev_t.h>
#include <linux/list.h>
#else
#define __KERNEL__
#include <linux/kdev_t.h>
#include <linux/list.h>
#undef __KERNEL__
#endif /* #ifndef __KERNEL__ */
#include <linux/major.h>
#include <linux/spinlock.h>
#include <sys/types.h>
#include <linux/version.h>
typedef unsigned long blkoff_t;
#ifndef uint8_t
# define uint8_t unsigned char
#endif
#ifndef uint16_t
# define uint16_t unsigned short int
#endif
#ifndef uint32_t
# define uint32_t unsigned int
#endif
#ifndef uint64_t
# define uint64_t unsigned long long int
#endif
/*
* This is basically the on disk metadata layout version.
*/
#define LVM_STRUCT_VERSION 2
/*
* Limits for VGs, PVs per VG and LVs per VG. The ABS_* limit's are
* used in defining the data structures, MAX_* are the real limits
* used.
*/
#define MAX_VG 99
#define MAX_PV 256
#define MAX_LV 256 /* caused by 8 bit minor */
#define NAME_LEN 128 /* the maximum length of various names */
#define UUID_LEN 32 /* some components have unique identifiers */
/*
* A little struct to hold a sector range on a block device. Used to
* hold the location of on disk metadata
*/
typedef struct {
uint32_t base;
uint32_t size;
} lvm_disk_data_t;
/***********************************************************
* On disk representation:
*
* The beginning of each PV contains metadata, known int the Volume
* Group Data Area (VGDA). This metadata has the following structure:
*
* offset description size
* --------------- ---------------------------------- ------------
* 0 physical volume structure ~500 byte
* 1K volume group structure ~200 byte
* 6K namelist of physical volumes 128 byte each
* + n * ~300byte n logical volume structures ~300 byte each
* + m * 4byte m physical extent alloc. structs 4 byte each
* + ~ 1 PE size physical extents total * size
*
* Spaces are left between the structures for later extensions.
***********************************************************/
/*
* physical volume - disk
*/
typedef struct {
uint8_t id[2]; /* identifier */
uint16_t version; /* lvm struct version */
/* these define the locations of various bits of on disk metadata */
lvm_disk_data_t pv_on_disk; /* pv_disk_t location */
lvm_disk_data_t vg_on_disk; /* vg_disk_t location */
lvm_disk_data_t pv_uuidlist_on_disk; /* uuid list location */
lvm_disk_data_t lv_on_disk; /* lv_disk_t locations */
lvm_disk_data_t pe_on_disk; /* pe mapping table location */
uint8_t pv_uuid[NAME_LEN]; /* uuid for this PV */
uint8_t vg_name[NAME_LEN]; /* which vg it belongs to */
uint8_t system_id[NAME_LEN]; /* for vgexport/vgimport */
uint32_t pv_major;
uint32_t pv_number;
uint32_t pv_status;
uint32_t pv_allocatable;
uint32_t pv_size;
uint32_t lv_cur;
uint32_t pe_size;
uint32_t pe_total;
uint32_t pe_allocated;
/* data_location.base holds the start of the pe's in sectors */
uint32_t pe_start;
} pv_disk_t;
/*
* logical volume - disk
*/
typedef struct {
uint8_t lv_name[NAME_LEN];
uint8_t vg_name[NAME_LEN];
uint32_t lv_access;
uint32_t lv_status;
uint32_t lv_open;
uint32_t lv_dev;
uint32_t lv_number;
uint32_t lv_mirror_copies; /* for future use */
uint32_t lv_recovery; /* " */
uint32_t lv_schedule; /* " */
uint32_t lv_size;
uint32_t lv_snapshot_minor; /* minor number of origin */
uint16_t lv_chunk_size; /* chunk size of snapshot */
uint16_t dummy;
uint32_t lv_allocated_le;
uint32_t lv_stripes;
uint32_t lv_stripesize;
uint32_t lv_badblock; /* for future use */
uint32_t lv_allocation;
uint32_t lv_io_timeout; /* for future use */
uint32_t lv_read_ahead;
} lv_disk_t;
/*
* volume group - disk
*/
typedef struct {
uint8_t vg_uuid[UUID_LEN]; /* volume group UUID */
/* rest of v1 VG name */
uint8_t vg_name_dummy[NAME_LEN-UUID_LEN];
uint32_t vg_number; /* volume group number */
uint32_t vg_access; /* read/write */
uint32_t vg_status; /* active or not */
uint32_t lv_max; /* maximum logical volumes */
uint32_t lv_cur; /* current logical volumes */
uint32_t lv_open; /* open logical volumes */
uint32_t pv_max; /* maximum physical volumes */
uint32_t pv_cur; /* current physical volumes FU */
uint32_t pv_act; /* active physical volumes */
uint32_t dummy;
uint32_t vgda; /* volume group descriptor arrays FU */
uint32_t pe_size; /* physical extent size in sectors */
uint32_t pe_total; /* total of physical extents */
uint32_t pe_allocated; /* allocated physical extents */
uint32_t pvg_total; /* physical volume groups FU */
} vg_disk_t;
/*
* pe mapping - disk
*/
typedef struct {
uint16_t lv_num;
uint16_t le_num;
} pe_disk_t;
/*
* copy on write tables - disk
*/
typedef struct lv_COW_table_disk_v1 {
uint64_t pv_org_number;
uint64_t pv_org_rsector;
uint64_t pv_snap_number;
uint64_t pv_snap_rsector;
} lv_COW_table_disk_t;
#endif