]>
sourceware.org Git - lvm2.git/blob - liblvm/lvm_lv.c
2 * Copyright (C) 2008,2009 Red Hat, Inc. All rights reserved.
4 * This file is part of LVM2.
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.
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
17 #include "lvm-string.h"
25 static int _lv_check_handle(const lv_t lv
, const int vg_writeable
)
27 if (!lv
|| !lv
->vg
|| vg_read_error(lv
->vg
))
29 if (vg_writeable
&& !vg_check_write_mode(lv
->vg
))
34 /* FIXME: have lib/report/report.c _disp function call lv_size()? */
35 uint64_t lvm_lv_get_size(const lv_t lv
)
37 return SECTOR_SIZE
* lv_size(lv
);
40 const char *lvm_lv_get_uuid(const lv_t lv
)
42 return lv_uuid_dup(lv
);
45 const char *lvm_lv_get_name(const lv_t lv
)
47 return dm_pool_strndup(lv
->vg
->vgmem
, (const char *)lv
->name
,
51 struct lvm_property_value
lvm_lv_get_property(const lv_t lv
, const char *name
)
53 return get_property(NULL
, NULL
, lv
, NULL
, NULL
, name
);
56 struct lvm_property_value
lvm_lvseg_get_property(const lvseg_t lvseg
,
59 return get_property(NULL
, NULL
, NULL
, lvseg
, NULL
, name
);
62 uint64_t lvm_lv_is_active(const lv_t lv
)
65 if (lv_info(lv
->vg
->cmd
, lv
, 0, &info
, 0, 0) &&
66 info
.exists
&& info
.live_table
)
71 uint64_t lvm_lv_is_suspended(const lv_t lv
)
74 if (lv_info(lv
->vg
->cmd
, lv
, 0, &info
, 0, 0) &&
75 info
.exists
&& info
.suspended
)
80 int lvm_lv_add_tag(lv_t lv
, const char *tag
)
82 if (_lv_check_handle(lv
, 1))
84 if (!lv_change_tag(lv
, tag
, 1))
90 int lvm_lv_remove_tag(lv_t lv
, const char *tag
)
92 if (_lv_check_handle(lv
, 1))
94 if (!lv_change_tag(lv
, tag
, 0))
100 struct dm_list
*lvm_lv_get_tags(const lv_t lv
)
102 return tag_list_copy(lv
->vg
->vgmem
, &lv
->tags
);
105 /* Set defaults for non-segment specific LV parameters */
106 static void _lv_set_default_params(struct lvcreate_params
*lp
,
107 vg_t vg
, const char *lvname
,
113 lp
->activate
= CHANGE_AY
;
114 lp
->vg_name
= vg
->name
;
115 lp
->lv_name
= lvname
; /* FIXME: check this for safety */
118 lp
->extents
= extents
;
119 lp
->permission
= LVM_READ
| LVM_WRITE
;
120 lp
->read_ahead
= DM_READ_AHEAD_NONE
;
121 lp
->alloc
= ALLOC_INHERIT
;
122 dm_list_init(&lp
->tags
);
125 /* Set default for linear segment specific LV parameters */
126 static int _lv_set_default_linear_params(struct cmd_context
*cmd
,
127 struct lvcreate_params
*lp
)
129 if (!(lp
->segtype
= get_segtype_from_string(cmd
, "striped"))) {
130 log_error(INTERNAL_ERROR
"Segtype striped not found.");
135 lp
->stripe_size
= DEFAULT_STRIPESIZE
* 2;
141 * FIXME: This function should probably not commit to disk but require calling
142 * lvm_vg_write. However, this appears to be non-trivial change until
143 * lv_create_single is refactored by segtype.
145 lv_t
lvm_vg_create_lv_linear(vg_t vg
, const char *name
, uint64_t size
)
147 struct lvcreate_params lp
;
151 if (vg_read_error(vg
))
153 if (!vg_check_write_mode(vg
))
155 memset(&lp
, 0, sizeof(lp
));
156 extents
= extents_from_size(vg
->cmd
, size
/ SECTOR_SIZE
,
158 _lv_set_default_params(&lp
, vg
, name
, extents
);
159 if (!_lv_set_default_linear_params(vg
->cmd
, &lp
))
161 if (!lv_create_single(vg
, &lp
))
163 lvl
= find_lv_in_vg(vg
, name
);
166 return (lv_t
) lvl
->lv
;
170 * FIXME: This function should probably not commit to disk but require calling
173 int lvm_vg_remove_lv(lv_t lv
)
175 if (!lv
|| !lv
->vg
|| vg_read_error(lv
->vg
))
177 if (!vg_check_write_mode(lv
->vg
))
179 if (!lv_remove_single(lv
->vg
->cmd
, lv
, DONT_PROMPT
))
184 int lvm_lv_activate(lv_t lv
)
186 if (!lv
|| !lv
->vg
|| vg_read_error(lv
->vg
) || !lv
->vg
->cmd
)
189 /* FIXME: handle pvmove stuff later */
190 if (lv
->status
& LOCKED
) {
191 log_error("Unable to activate locked LV");
195 /* FIXME: handle lvconvert stuff later */
196 if (lv
->status
& CONVERTING
) {
197 log_error("Unable to activate LV with in-progress lvconvert");
201 if (lv_is_origin(lv
)) {
202 log_verbose("Activating logical volume \"%s\" "
203 "exclusively", lv
->name
);
204 if (!activate_lv_excl(lv
->vg
->cmd
, lv
)) {
205 log_error("Activate exclusive failed.");
209 log_verbose("Activating logical volume \"%s\"",
211 if (!activate_lv(lv
->vg
->cmd
, lv
)) {
212 log_error("Activate failed.");
219 int lvm_lv_deactivate(lv_t lv
)
221 if (!lv
|| !lv
->vg
|| vg_read_error(lv
->vg
) || !lv
->vg
->cmd
)
224 log_verbose("Deactivating logical volume \"%s\"", lv
->name
);
225 if (!deactivate_lv(lv
->vg
->cmd
, lv
)) {
226 log_error("Deactivate failed.");
232 struct dm_list
*lvm_lv_list_lvsegs(lv_t lv
)
234 struct dm_list
*list
;
236 struct lv_segment
*lvl
;
238 if (dm_list_empty(&lv
->segments
))
241 if (!(list
= dm_pool_zalloc(lv
->vg
->vgmem
, sizeof(*list
)))) {
242 log_errno(ENOMEM
, "Memory allocation fail for dm_list.");
247 dm_list_iterate_items(lvl
, &lv
->segments
) {
248 if (!(lvseg
= dm_pool_zalloc(lv
->vg
->vgmem
, sizeof(*lvseg
)))) {
250 "Memory allocation fail for lvm_lvseg_list.");
254 dm_list_add(list
, &lvseg
->list
);
259 lv_t
lvm_lv_from_name(vg_t vg
, const char *name
)
263 dm_list_iterate_items(lvl
, &vg
->lvs
) {
264 if (!strcmp(name
, lvl
->lv
->name
))
270 lv_t
lvm_lv_from_uuid(vg_t vg
, const char *uuid
)
275 if (strlen(uuid
) < ID_LEN
) {
276 log_errno (EINVAL
, "Invalid UUID string length");
280 if (!id_read_format(&id
, uuid
)) {
281 log_errno(EINVAL
, "Invalid UUID format.");
285 dm_list_iterate_items(lvl
, &vg
->lvs
) {
286 if (id_equal(&vg
->id
, &lvl
->lv
->lvid
.id
[0]) &&
287 id_equal(&id
, &lvl
->lv
->lvid
.id
[1]))
292 int lvm_lv_resize(const lv_t lv
, uint64_t new_size
)
294 /* FIXME: add lv resize code here */
295 log_error("NOT IMPLEMENTED YET");
This page took 0.056522 seconds and 5 git commands to generate.