1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00
lvm2/tools/lvactivate.c

99 lines
2.2 KiB
C
Raw Normal View History

2001-09-25 16:49:28 +04:00
/*
* 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 LVM; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "tools.h"
int lvactivate(int argc, char **argv)
{
int p;
struct io_space *ios;
2001-09-25 16:49:28 +04:00
struct device *pv_dev;
char *lv_name;
2001-09-25 16:49:28 +04:00
char *pv_name;
struct physical_volume *pv = NULL;
struct logical_volume *lv = NULL;
2001-09-25 16:49:28 +04:00
if (argc < 2) {
log_error("please enter logical volume & physical volume(s)");
return LVM_EINVALID_CMD_LINE;
}
lv_name = argv[0];
2001-09-25 16:49:28 +04:00
argc--;
argv++;
ios = active_ios();
2001-09-25 16:49:28 +04:00
while (argc--) {
pv_name = argv[argc];
if (!(pv_dev = dev_cache_get(pv_name))) {
2001-09-25 16:49:28 +04:00
log_error("device \"%s\" not found", pv_name);
return -1;
}
if (!(pv = pv_read(ios, pv_dev))) {
2001-09-25 16:49:28 +04:00
return -1;
}
if (pv->status & STATUS_ALLOCATED) {
2001-09-25 16:49:28 +04:00
if (!(pv->pe = pv_read_pe(pv_name, pv)))
goto pvdisplay_device_out;
if (!(lvs = pv_read_lvs(pv))) {
log_error("Failed to read LVs on %s",
pv->pv_name);
goto pvdisplay_device_out;
}
} else
log_print("no logical volume on physical volume %s",
pv_name);
for (p = 0; p < pv->pe_total; p++) {
int l = pv->pe[p].lv_num;
int le = pv->pe[p].le_num;
2001-10-02 21:09:05 +04:00
long pe_size_guess = lvs[l - 1].lv_size /
lvs[l - 1].lv_allocated_le;
2001-09-25 16:49:28 +04:00
if (l && !strcmp(lv, lvs[l - 1].lv_name))
2001-10-02 21:09:05 +04:00
printf("%012ld %ld linear %s %012ld\n",
pe_size_guess * le,
pe_size_guess,
pv_name, get_pe_offset(p, pv));
2001-09-25 16:49:28 +04:00
}
2001-09-25 20:26:38 +04:00
if (pv)
dbg_free(pv->pe);
2001-09-25 16:49:28 +04:00
dbg_free(pv);
dbg_free(lvs);
}
return 0;
pvdisplay_device_out:
2001-09-25 20:26:38 +04:00
if (pv)
dbg_free(pv->pe);
2001-09-25 16:49:28 +04:00
dbg_free(pv);
dbg_free(lvs);
return -1;
}