1.1.8
by Bastian Blank
Import upstream version 2.02.62 |
1 |
/*
|
1.1.16
by Bastian Blank
Import upstream version 2.02.104 |
2 |
* Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
|
1.1.8
by Bastian Blank
Import upstream version 2.02.62 |
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 |
||
1.1.11
by Bastian Blank
Import upstream version 2.02.84 |
15 |
#include "lib.h" |
16 |
#include "properties.h" |
|
1.1.8
by Bastian Blank
Import upstream version 2.02.62 |
17 |
#include "lvm_misc.h" |
1.1.11
by Bastian Blank
Import upstream version 2.02.84 |
18 |
#include "lvm2app.h" |
1.1.16
by Bastian Blank
Import upstream version 2.02.104 |
19 |
#include "lvm_prop.h" |
1.1.8
by Bastian Blank
Import upstream version 2.02.62 |
20 |
|
21 |
struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list) |
|
22 |
{
|
|
23 |
struct dm_list *list; |
|
24 |
lvm_str_list_t *lsl; |
|
1.1.18
by Bastian Blank
Import upstream version 2.02.109 |
25 |
struct dm_str_list *sl; |
1.1.8
by Bastian Blank
Import upstream version 2.02.62 |
26 |
|
27 |
if (!(list = dm_pool_zalloc(p, sizeof(*list)))) { |
|
28 |
log_errno(ENOMEM, "Memory allocation fail for dm_list."); |
|
29 |
return NULL; |
|
30 |
}
|
|
31 |
dm_list_init(list); |
|
32 |
||
33 |
dm_list_iterate_items(sl, tag_list) { |
|
34 |
if (!(lsl = dm_pool_zalloc(p, sizeof(*lsl)))) { |
|
35 |
log_errno(ENOMEM, |
|
36 |
"Memory allocation fail for lvm_lv_list."); |
|
37 |
return NULL; |
|
38 |
}
|
|
39 |
if (!(lsl->str = dm_pool_strdup(p, sl->str))) { |
|
40 |
log_errno(ENOMEM, |
|
41 |
"Memory allocation fail for lvm_lv_list->str."); |
|
42 |
return NULL; |
|
43 |
}
|
|
44 |
dm_list_add(list, &lsl->list); |
|
45 |
}
|
|
46 |
return list; |
|
47 |
}
|
|
1.1.11
by Bastian Blank
Import upstream version 2.02.84 |
48 |
|
49 |
struct lvm_property_value get_property(const pv_t pv, const vg_t vg, |
|
1.1.16
by Bastian Blank
Import upstream version 2.02.104 |
50 |
const lv_t lv, |
51 |
const lvseg_t lvseg, |
|
52 |
const pvseg_t pvseg, |
|
53 |
const struct lvcreate_params *lvcp, |
|
1.1.17
by Bastian Blank
Import upstream version 2.02.106 |
54 |
const struct pvcreate_params *pvcp, |
1.1.16
by Bastian Blank
Import upstream version 2.02.104 |
55 |
const char *name) |
1.1.11
by Bastian Blank
Import upstream version 2.02.84 |
56 |
{
|
57 |
struct lvm_property_type prop; |
|
1.1.15
by Bastian Blank
Import upstream version 2.02.98 |
58 |
struct lvm_property_value v = { 0 }; |
1.1.11
by Bastian Blank
Import upstream version 2.02.84 |
59 |
|
60 |
prop.id = name; |
|
61 |
||
62 |
if (pv) { |
|
63 |
if (!pv_get_property(pv, &prop)) |
|
64 |
return v; |
|
65 |
} else if (vg) { |
|
66 |
if (!vg_get_property(vg, &prop)) |
|
67 |
return v; |
|
68 |
} else if (lv) { |
|
69 |
if (!lv_get_property(lv, &prop)) |
|
70 |
return v; |
|
71 |
} else if (lvseg) { |
|
72 |
if (!lvseg_get_property(lvseg, &prop)) |
|
73 |
return v; |
|
74 |
} else if (pvseg) { |
|
75 |
if (!pvseg_get_property(pvseg, &prop)) |
|
76 |
return v; |
|
1.1.16
by Bastian Blank
Import upstream version 2.02.104 |
77 |
} else if (lvcp) { |
78 |
if (!lv_create_param_get_property(lvcp, &prop)) |
|
79 |
return v; |
|
1.1.17
by Bastian Blank
Import upstream version 2.02.106 |
80 |
} else if (pvcp) { |
81 |
if (!pv_create_param_get_property(pvcp, &prop)) |
|
82 |
return v; |
|
1.1.11
by Bastian Blank
Import upstream version 2.02.84 |
83 |
} else { |
84 |
log_errno(EINVAL, "Invalid NULL handle passed to library function."); |
|
85 |
return v; |
|
86 |
}
|
|
87 |
||
88 |
v.is_settable = prop.is_settable; |
|
89 |
v.is_string = prop.is_string; |
|
90 |
v.is_integer = prop.is_integer; |
|
91 |
if (v.is_string) |
|
92 |
v.value.string = prop.value.string; |
|
93 |
if (v.is_integer) |
|
94 |
v.value.integer = prop.value.integer; |
|
95 |
v.is_valid = 1; |
|
96 |
return v; |
|
97 |
}
|
|
98 |
||
99 |
||
100 |
int set_property(const pv_t pv, const vg_t vg, const lv_t lv, |
|
1.1.16
by Bastian Blank
Import upstream version 2.02.104 |
101 |
struct lvcreate_params *lvcp, |
1.1.17
by Bastian Blank
Import upstream version 2.02.106 |
102 |
struct pvcreate_params *pvcp, |
1.1.16
by Bastian Blank
Import upstream version 2.02.104 |
103 |
const char *name, |
104 |
struct lvm_property_value *v) |
|
1.1.11
by Bastian Blank
Import upstream version 2.02.84 |
105 |
{
|
106 |
struct lvm_property_type prop; |
|
107 |
||
108 |
prop.id = name; |
|
109 |
if (v->is_string) |
|
110 |
prop.value.string = v->value.string; |
|
111 |
else
|
|
112 |
prop.value.integer = v->value.integer; |
|
113 |
if (pv) { |
|
114 |
if (!pv_set_property(pv, &prop)) { |
|
115 |
v->is_valid = 0; |
|
116 |
return -1; |
|
117 |
}
|
|
118 |
} else if (vg) { |
|
119 |
if (!vg_set_property(vg, &prop)) { |
|
120 |
v->is_valid = 0; |
|
121 |
return -1; |
|
122 |
}
|
|
123 |
} else if (lv) { |
|
124 |
if (!lv_set_property(lv, &prop)) { |
|
125 |
v->is_valid = 0; |
|
126 |
return -1; |
|
127 |
}
|
|
1.1.16
by Bastian Blank
Import upstream version 2.02.104 |
128 |
} else if (lvcp) { |
129 |
if (!lv_create_param_set_property(lvcp, &prop)) { |
|
130 |
v->is_valid = 0; |
|
131 |
return -1; |
|
132 |
}
|
|
1.1.17
by Bastian Blank
Import upstream version 2.02.106 |
133 |
} else if (pvcp) { |
134 |
if (!pv_create_param_set_property(pvcp, &prop)) { |
|
135 |
v->is_valid = 0; |
|
136 |
return -1; |
|
137 |
}
|
|
1.1.16
by Bastian Blank
Import upstream version 2.02.104 |
138 |
} else { |
139 |
return -1; |
|
1.1.11
by Bastian Blank
Import upstream version 2.02.84 |
140 |
}
|
141 |
return 0; |
|
142 |
}
|
|
1.1.17
by Bastian Blank
Import upstream version 2.02.106 |
143 |
|
144 |
/*
|
|
145 |
* Store anything that may need to be restored back to the user on library
|
|
146 |
* call exit. Currently the only thing we are preserving is the users umask.
|
|
147 |
*/
|
|
148 |
struct saved_env store_user_env(struct cmd_context *cmd) |
|
149 |
{
|
|
150 |
struct saved_env env = {0}; |
|
151 |
||
152 |
if (cmd) { |
|
153 |
env.user_umask = umask(cmd->default_settings.umask); |
|
154 |
} else { |
|
155 |
env.user_umask = umask(0); |
|
156 |
umask(env.user_umask); |
|
157 |
}
|
|
158 |
||
159 |
return env; |
|
160 |
}
|
|
161 |
||
162 |
void restore_user_env(const struct saved_env *env) |
|
163 |
{
|
|
164 |
if (env) { |
|
165 |
umask(env->user_umask); |
|
166 |
}
|
|
167 |
}
|