]> sourceware.org Git - lvm2.git/blame - liblvm/lvm_pv.c
Fix error message when pvmove LV activation fails with name already in use.
[lvm2.git] / liblvm / lvm_pv.c
CommitLineData
f032ed74
DW
1/*
2 * Copyright (C) 2008,2009 Red Hat, Inc. All rights reserved.
3 *
4 * This file is part of LVM2.
5 *
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU Lesser General Public License v.2.1.
9 *
10 * You should have received a copy of the GNU Lesser General Public License
11 * along with this program; if not, write to the Free Software Foundation,
12 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13 */
14
15#include "lib.h"
254d672d 16#include "metadata.h"
f032ed74 17#include "lvm-string.h"
4e92d7c9 18#include "lvm_misc.h"
8961b1d5 19#include "lvm2app.h"
f032ed74 20
298ec21e 21const char *lvm_pv_get_uuid(const pv_t pv)
f032ed74 22{
254d672d 23 return pv_uuid_dup(pv);
f032ed74
DW
24}
25
298ec21e 26const char *lvm_pv_get_name(const pv_t pv)
f032ed74 27{
298ec21e
DW
28 return dm_pool_strndup(pv->vg->vgmem,
29 (const char *)pv_dev_name(pv), NAME_LEN + 1);
f032ed74
DW
30}
31
e0e7fb84 32uint64_t lvm_pv_get_mda_count(const pv_t pv)
83f25cd1
DW
33{
34 return (uint64_t) pv_mda_count(pv);
35}
ee7e183f 36
629efc6a
DW
37uint64_t lvm_pv_get_dev_size(const pv_t pv)
38{
9e7b0091 39 return (uint64_t) SECTOR_SIZE * pv_dev_size(pv);
629efc6a
DW
40}
41
42uint64_t lvm_pv_get_size(const pv_t pv)
43{
9e7b0091 44 return (uint64_t) SECTOR_SIZE * pv_size_field(pv);
629efc6a
DW
45}
46
47uint64_t lvm_pv_get_free(const pv_t pv)
48{
9e7b0091 49 return (uint64_t) SECTOR_SIZE * pv_free(pv);
629efc6a
DW
50}
51
4e92d7c9
DW
52struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name)
53{
55429cde
PR
54 return get_property(pv, NULL, NULL, NULL, NULL, name);
55}
56
57struct lvm_property_value lvm_pvseg_get_property(const pvseg_t pvseg,
58 const char *name)
59{
60 return get_property(NULL, NULL, NULL, NULL, pvseg, name);
4e92d7c9
DW
61}
62
b2b27cd7
PR
63struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
64{
65 struct dm_list *list;
66 pvseg_list_t *pvseg;
67 struct pv_segment *pvl;
68
69 if (dm_list_empty(&pv->segments))
70 return NULL;
71
72 if (!(list = dm_pool_zalloc(pv->vg->vgmem, sizeof(*list)))) {
73 log_errno(ENOMEM, "Memory allocation fail for dm_list.");
74 return NULL;
75 }
76 dm_list_init(list);
77
78 dm_list_iterate_items(pvl, &pv->segments) {
79 if (!(pvseg = dm_pool_zalloc(pv->vg->vgmem, sizeof(*pvseg)))) {
80 log_errno(ENOMEM,
81 "Memory allocation fail for lvm_pvseg_list.");
82 return NULL;
83 }
84 pvseg->pvseg = pvl;
85 dm_list_add(list, &pvseg->list);
86 }
87 return list;
88}
89
14b0c96b
PR
90pv_t lvm_pv_from_name(vg_t vg, const char *name)
91{
92 struct pv_list *pvl;
93
94 dm_list_iterate_items(pvl, &vg->pvs) {
95 if (!strcmp(name, pv_dev_name(pvl->pv)))
96 return pvl->pv;
97 }
98 return NULL;
99}
100
5219fe3c
PR
101pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid)
102{
103 struct pv_list *pvl;
104 struct id id;
105
106 if (strlen(uuid) < ID_LEN) {
107 log_errno (EINVAL, "Invalid UUID string length");
108 return NULL;
109 }
eae8784a
ZK
110
111 if (!id_read_format(&id, uuid)) {
112 log_errno(EINVAL, "Invalid UUID format.");
113 return NULL;
5219fe3c 114 }
eae8784a 115
5219fe3c
PR
116 dm_list_iterate_items(pvl, &vg->pvs) {
117 if (id_equal(&id, &pvl->pv->id))
118 return pvl->pv;
119 }
120 return NULL;
121}
122
14b0c96b 123
e0e7fb84 124int lvm_pv_resize(const pv_t pv, uint64_t new_size)
ee7e183f
DW
125{
126 /* FIXME: add pv resize code here */
df621aa3 127 log_error("NOT IMPLEMENTED YET");
ee7e183f
DW
128 return -1;
129}
This page took 0.060898 seconds and 5 git commands to generate.