]> sourceware.org Git - lvm2.git/blob - liblvm/lvm_pv.c
pre-release
[lvm2.git] / liblvm / lvm_pv.c
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"
16 #include "metadata.h"
17 #include "lvm-string.h"
18 #include "lvm_misc.h"
19 #include "lvm2app.h"
20
21 const char *lvm_pv_get_uuid(const pv_t pv)
22 {
23 return pv_uuid_dup(pv);
24 }
25
26 const char *lvm_pv_get_name(const pv_t pv)
27 {
28 return dm_pool_strndup(pv->vg->vgmem,
29 (const char *)pv_dev_name(pv), NAME_LEN + 1);
30 }
31
32 uint64_t lvm_pv_get_mda_count(const pv_t pv)
33 {
34 return (uint64_t) pv_mda_count(pv);
35 }
36
37 uint64_t lvm_pv_get_dev_size(const pv_t pv)
38 {
39 return (uint64_t) SECTOR_SIZE * pv_dev_size(pv);
40 }
41
42 uint64_t lvm_pv_get_size(const pv_t pv)
43 {
44 return (uint64_t) SECTOR_SIZE * pv_size_field(pv);
45 }
46
47 uint64_t lvm_pv_get_free(const pv_t pv)
48 {
49 return (uint64_t) SECTOR_SIZE * pv_free(pv);
50 }
51
52 struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name)
53 {
54 return get_property(pv, NULL, NULL, NULL, NULL, name);
55 }
56
57 struct 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);
61 }
62
63 struct 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
90 pv_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
101 pv_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 }
110
111 if (!id_read_format(&id, uuid)) {
112 log_errno(EINVAL, "Invalid UUID format.");
113 return NULL;
114 }
115
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
123
124 int lvm_pv_resize(const pv_t pv, uint64_t new_size)
125 {
126 /* FIXME: add pv resize code here */
127 log_error("NOT IMPLEMENTED YET");
128 return -1;
129 }
This page took 0.042838 seconds and 5 git commands to generate.