]> sourceware.org Git - lvm2.git/blame - liblvm/lvm_misc.c
Always include debug mesg when cling to allocated is set.
[lvm2.git] / liblvm / lvm_misc.c
CommitLineData
322633e1
DW
1/*
2 * Copyright (C) 2008,2010 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
d01a6a2c 15#include "lib.h"
3c1febe0 16#include "properties.h"
8961b1d5
PR
17#include "lvm_misc.h"
18#include "lvm2app.h"
322633e1
DW
19
20struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list)
21{
22 struct dm_list *list;
23 lvm_str_list_t *lsl;
24 struct str_list *sl;
25
26 if (!(list = dm_pool_zalloc(p, sizeof(*list)))) {
27 log_errno(ENOMEM, "Memory allocation fail for dm_list.");
28 return NULL;
29 }
30 dm_list_init(list);
31
32 dm_list_iterate_items(sl, tag_list) {
33 if (!(lsl = dm_pool_zalloc(p, sizeof(*lsl)))) {
34 log_errno(ENOMEM,
35 "Memory allocation fail for lvm_lv_list.");
36 return NULL;
37 }
38 if (!(lsl->str = dm_pool_strdup(p, sl->str))) {
39 log_errno(ENOMEM,
40 "Memory allocation fail for lvm_lv_list->str.");
41 return NULL;
42 }
43 dm_list_add(list, &lsl->list);
44 }
45 return list;
46}
3c1febe0
DW
47
48struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
5de70620 49 const lv_t lv, const lvseg_t lvseg,
55429cde 50 const pvseg_t pvseg, const char *name)
3c1febe0
DW
51{
52 struct lvm_property_type prop;
53 struct lvm_property_value v;
54
12fbaae0 55 memset(&v, 0, sizeof(v));
3c1febe0 56 prop.id = name;
12fbaae0 57
3c1febe0 58 if (pv) {
12fbaae0 59 if (!pv_get_property(pv, &prop))
3c1febe0 60 return v;
3c1febe0 61 } else if (vg) {
12fbaae0 62 if (!vg_get_property(vg, &prop))
3c1febe0 63 return v;
3c1febe0 64 } else if (lv) {
12fbaae0 65 if (!lv_get_property(lv, &prop))
3c1febe0 66 return v;
5de70620 67 } else if (lvseg) {
12fbaae0 68 if (!lvseg_get_property(lvseg, &prop))
5de70620 69 return v;
55429cde 70 } else if (pvseg) {
12fbaae0 71 if (!pvseg_get_property(pvseg, &prop))
55429cde 72 return v;
12fbaae0
ZK
73 } else {
74 log_errno(EINVAL, "Invalid NULL handle passed to library function.");
75 return v;
3c1febe0 76 }
12fbaae0 77
3c1febe0
DW
78 v.is_settable = prop.is_settable;
79 v.is_string = prop.is_string;
80 v.is_integer = prop.is_integer;
81 if (v.is_string)
82 v.value.string = prop.value.string;
83 if (v.is_integer)
84 v.value.integer = prop.value.integer;
85 v.is_valid = 1;
86 return v;
87}
eeaf3ba7
PR
88
89
90int set_property(const pv_t pv, const vg_t vg, const lv_t lv,
91 const char *name, struct lvm_property_value *v)
92{
93 struct lvm_property_type prop;
94
95 prop.id = name;
96 if (v->is_string)
97 prop.value.string = v->value.string;
98 else
99 prop.value.integer = v->value.integer;
100 if (pv) {
101 if (!pv_set_property(pv, &prop)) {
102 v->is_valid = 0;
103 return -1;
104 }
105 } else if (vg) {
106 if (!vg_set_property(vg, &prop)) {
107 v->is_valid = 0;
108 return -1;
109 }
110 } else if (lv) {
111 if (!lv_set_property(lv, &prop)) {
112 v->is_valid = 0;
113 return -1;
114 }
115 }
116 return 0;
117}
This page took 0.057304 seconds and 5 git commands to generate.