]> sourceware.org Git - lvm2.git/blame - libdm/libdm-deptree.c
Fix 'pvs -o pv_all' to include label fields. (Also removed recursion.)
[lvm2.git] / libdm / libdm-deptree.c
CommitLineData
3d0480ed 1/*
4ef2bf27 2 * Copyright (C) 2005-2010 Red Hat, Inc. All rights reserved.
3d0480ed
AK
3 *
4 * This file is part of the device-mapper userspace tools.
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
3e5b6ed2 15#include "dmlib.h"
3d0480ed
AK
16#include "libdm-targets.h"
17#include "libdm-common.h"
3d0480ed 18#include "kdev_t.h"
0782ad50 19#include "dm-ioctl.h"
3d0480ed
AK
20
21#include <stdarg.h>
22#include <sys/param.h>
8f26e18c 23#include <sys/utsname.h>
3d0480ed 24
165e4a11
AK
25#define MAX_TARGET_PARAMSIZE 500000
26
87f98002
AK
27/* FIXME Fix interface so this is used only by LVM */
28#define UUID_PREFIX "LVM-"
29
b262f3e1
ZK
30#define REPLICATOR_LOCAL_SITE 0
31
165e4a11
AK
32/* Supported segment types */
33enum {
12ca060e
MB
34 SEG_CRYPT,
35 SEG_ERROR,
165e4a11
AK
36 SEG_LINEAR,
37 SEG_MIRRORED,
b262f3e1
ZK
38 SEG_REPLICATOR,
39 SEG_REPLICATOR_DEV,
165e4a11
AK
40 SEG_SNAPSHOT,
41 SEG_SNAPSHOT_ORIGIN,
aa6f4e51 42 SEG_SNAPSHOT_MERGE,
165e4a11
AK
43 SEG_STRIPED,
44 SEG_ZERO,
45};
b4f1578f 46
165e4a11
AK
47/* FIXME Add crypt and multipath support */
48
49struct {
50 unsigned type;
51 const char *target;
52} dm_segtypes[] = {
12ca060e 53 { SEG_CRYPT, "crypt" },
165e4a11
AK
54 { SEG_ERROR, "error" },
55 { SEG_LINEAR, "linear" },
56 { SEG_MIRRORED, "mirror" },
b262f3e1
ZK
57 { SEG_REPLICATOR, "replicator" },
58 { SEG_REPLICATOR_DEV, "replicator-dev" },
165e4a11
AK
59 { SEG_SNAPSHOT, "snapshot" },
60 { SEG_SNAPSHOT_ORIGIN, "snapshot-origin" },
aa6f4e51 61 { SEG_SNAPSHOT_MERGE, "snapshot-merge" },
165e4a11
AK
62 { SEG_STRIPED, "striped" },
63 { SEG_ZERO, "zero"},
64};
65
66/* Some segment types have a list of areas of other devices attached */
67struct seg_area {
2c44337b 68 struct dm_list list;
165e4a11 69
b4f1578f 70 struct dm_tree_node *dev_node;
165e4a11
AK
71
72 uint64_t offset;
b262f3e1
ZK
73
74 unsigned rsite_index; /* Replicator site index */
75 struct dm_tree_node *slog; /* Replicator sync log node */
76 uint64_t region_size; /* Replicator sync log size */
77 uint32_t flags; /* Replicator sync log flags */
78};
79
80/* Replicator-log has a list of sites */
81/* FIXME: maybe move to seg_area too? */
82struct replicator_site {
83 struct dm_list list;
84
85 unsigned rsite_index;
86 dm_replicator_mode_t mode;
87 uint32_t async_timeout;
88 uint32_t fall_behind_ios;
89 uint64_t fall_behind_data;
165e4a11
AK
90};
91
92/* Per-segment properties */
93struct load_segment {
2c44337b 94 struct dm_list list;
165e4a11
AK
95
96 unsigned type;
97
98 uint64_t size;
99
b262f3e1
ZK
100 unsigned area_count; /* Linear + Striped + Mirrored + Crypt + Replicator */
101 struct dm_list areas; /* Linear + Striped + Mirrored + Crypt + Replicator */
165e4a11
AK
102
103 uint32_t stripe_size; /* Striped */
104
105 int persistent; /* Snapshot */
106 uint32_t chunk_size; /* Snapshot */
b4f1578f
AK
107 struct dm_tree_node *cow; /* Snapshot */
108 struct dm_tree_node *origin; /* Snapshot + Snapshot origin */
aa6f4e51 109 struct dm_tree_node *merge; /* Snapshot */
165e4a11 110
b262f3e1 111 struct dm_tree_node *log; /* Mirror + Replicator */
165e4a11
AK
112 uint32_t region_size; /* Mirror */
113 unsigned clustered; /* Mirror */
114 unsigned mirror_area_count; /* Mirror */
dbcb64b8 115 uint32_t flags; /* Mirror log */
67b25ed4 116 char *uuid; /* Clustered mirror log */
12ca060e
MB
117
118 const char *cipher; /* Crypt */
119 const char *chainmode; /* Crypt */
120 const char *iv; /* Crypt */
121 uint64_t iv_offset; /* Crypt */
122 const char *key; /* Crypt */
b262f3e1
ZK
123
124 const char *rlog_type; /* Replicator */
125 struct dm_list rsites; /* Replicator */
126 unsigned rsite_count; /* Replicator */
127 unsigned rdevice_count; /* Replicator */
128 struct dm_tree_node *replicator;/* Replicator-dev */
129 uint64_t rdevice_index; /* Replicator-dev */
165e4a11
AK
130};
131
132/* Per-device properties */
133struct load_properties {
134 int read_only;
135 uint32_t major;
136 uint32_t minor;
137
52b84409
AK
138 uint32_t read_ahead;
139 uint32_t read_ahead_flags;
140
165e4a11 141 unsigned segment_count;
bb875bb9 142 unsigned size_changed;
2c44337b 143 struct dm_list segs;
165e4a11
AK
144
145 const char *new_name;
566515c0
PR
146
147 /* If immediate_dev_node is set to 1, try to create the dev node
148 * as soon as possible (e.g. in preload stage even during traversal
149 * and processing of dm tree). This will also flush all stacked dev
150 * node operations, synchronizing with udev.
151 */
df390f17
AK
152 unsigned immediate_dev_node;
153
154 /*
155 * If the device size changed from zero and this is set,
156 * don't resume the device immediately, even if the device
157 * has parents. This works provided the parents do not
158 * validate the device size and is required by pvmove to
159 * avoid starting the mirror resync operation too early.
160 */
161 unsigned delay_resume_if_new;
165e4a11
AK
162};
163
164/* Two of these used to join two nodes with uses and used_by. */
b4f1578f 165struct dm_tree_link {
2c44337b 166 struct dm_list list;
b4f1578f 167 struct dm_tree_node *node;
165e4a11
AK
168};
169
b4f1578f
AK
170struct dm_tree_node {
171 struct dm_tree *dtree;
3d0480ed
AK
172
173 const char *name;
174 const char *uuid;
175 struct dm_info info;
176
2c44337b
AK
177 struct dm_list uses; /* Nodes this node uses */
178 struct dm_list used_by; /* Nodes that use this node */
165e4a11 179
56c28292
AK
180 int activation_priority; /* 0 gets activated first */
181
f16aea9e
PR
182 uint16_t udev_flags; /* Udev control flags */
183
165e4a11
AK
184 void *context; /* External supplied context */
185
186 struct load_properties props; /* For creation/table (re)load */
76d1aec8
ZK
187
188 /*
189 * If presuspend of child node is needed
190 * Note: only direct child is allowed
191 */
192 struct dm_tree_node *presuspend_node;
3d0480ed
AK
193};
194
b4f1578f 195struct dm_tree {
a3f6b2ce
AK
196 struct dm_pool *mem;
197 struct dm_hash_table *devs;
165e4a11 198 struct dm_hash_table *uuids;
b4f1578f 199 struct dm_tree_node root;
c55b1410 200 int skip_lockfs; /* 1 skips lockfs (for non-snapshots) */
b9ffd32c 201 int no_flush; /* 1 sets noflush (mirrors/multipath) */
bd90c6b2 202 uint32_t cookie;
3d0480ed
AK
203};
204
b4f1578f 205struct dm_tree *dm_tree_create(void)
3d0480ed 206{
b4f1578f 207 struct dm_tree *dtree;
3d0480ed 208
ac0252ca 209 if (!(dtree = dm_zalloc(sizeof(*dtree)))) {
b4f1578f 210 log_error("dm_tree_create malloc failed");
3d0480ed
AK
211 return NULL;
212 }
213
b4f1578f 214 dtree->root.dtree = dtree;
2c44337b
AK
215 dm_list_init(&dtree->root.uses);
216 dm_list_init(&dtree->root.used_by);
c55b1410 217 dtree->skip_lockfs = 0;
b9ffd32c 218 dtree->no_flush = 0;
3d0480ed 219
b4f1578f
AK
220 if (!(dtree->mem = dm_pool_create("dtree", 1024))) {
221 log_error("dtree pool creation failed");
222 dm_free(dtree);
3d0480ed
AK
223 return NULL;
224 }
225
b4f1578f
AK
226 if (!(dtree->devs = dm_hash_create(8))) {
227 log_error("dtree hash creation failed");
228 dm_pool_destroy(dtree->mem);
229 dm_free(dtree);
3d0480ed
AK
230 return NULL;
231 }
232
b4f1578f
AK
233 if (!(dtree->uuids = dm_hash_create(32))) {
234 log_error("dtree uuid hash creation failed");
235 dm_hash_destroy(dtree->devs);
236 dm_pool_destroy(dtree->mem);
237 dm_free(dtree);
165e4a11
AK
238 return NULL;
239 }
240
b4f1578f 241 return dtree;
3d0480ed
AK
242}
243
b4f1578f 244void dm_tree_free(struct dm_tree *dtree)
3d0480ed 245{
b4f1578f 246 if (!dtree)
3d0480ed
AK
247 return;
248
b4f1578f
AK
249 dm_hash_destroy(dtree->uuids);
250 dm_hash_destroy(dtree->devs);
251 dm_pool_destroy(dtree->mem);
252 dm_free(dtree);
3d0480ed
AK
253}
254
04bde319
ZK
255static int _nodes_are_linked(const struct dm_tree_node *parent,
256 const struct dm_tree_node *child)
3d0480ed 257{
b4f1578f 258 struct dm_tree_link *dlink;
3d0480ed 259
2c44337b 260 dm_list_iterate_items(dlink, &parent->uses)
3d0480ed
AK
261 if (dlink->node == child)
262 return 1;
3d0480ed
AK
263
264 return 0;
265}
266
2c44337b 267static int _link(struct dm_list *list, struct dm_tree_node *node)
3d0480ed 268{
b4f1578f 269 struct dm_tree_link *dlink;
3d0480ed 270
b4f1578f
AK
271 if (!(dlink = dm_pool_alloc(node->dtree->mem, sizeof(*dlink)))) {
272 log_error("dtree link allocation failed");
3d0480ed
AK
273 return 0;
274 }
275
276 dlink->node = node;
2c44337b 277 dm_list_add(list, &dlink->list);
3d0480ed
AK
278
279 return 1;
280}
281
b4f1578f
AK
282static int _link_nodes(struct dm_tree_node *parent,
283 struct dm_tree_node *child)
3d0480ed
AK
284{
285 if (_nodes_are_linked(parent, child))
286 return 1;
287
288 if (!_link(&parent->uses, child))
289 return 0;
290
291 if (!_link(&child->used_by, parent))
292 return 0;
293
294 return 1;
295}
296
2c44337b 297static void _unlink(struct dm_list *list, struct dm_tree_node *node)
3d0480ed 298{
b4f1578f 299 struct dm_tree_link *dlink;
3d0480ed 300
2c44337b 301 dm_list_iterate_items(dlink, list)
3d0480ed 302 if (dlink->node == node) {
2c44337b 303 dm_list_del(&dlink->list);
3d0480ed
AK
304 break;
305 }
3d0480ed
AK
306}
307
b4f1578f
AK
308static void _unlink_nodes(struct dm_tree_node *parent,
309 struct dm_tree_node *child)
3d0480ed
AK
310{
311 if (!_nodes_are_linked(parent, child))
312 return;
313
314 _unlink(&parent->uses, child);
315 _unlink(&child->used_by, parent);
316}
317
b4f1578f 318static int _add_to_toplevel(struct dm_tree_node *node)
165e4a11 319{
b4f1578f 320 return _link_nodes(&node->dtree->root, node);
165e4a11
AK
321}
322
b4f1578f 323static void _remove_from_toplevel(struct dm_tree_node *node)
3d0480ed 324{
b1ebf028 325 _unlink_nodes(&node->dtree->root, node);
3d0480ed
AK
326}
327
b4f1578f 328static int _add_to_bottomlevel(struct dm_tree_node *node)
3d0480ed 329{
b4f1578f 330 return _link_nodes(node, &node->dtree->root);
3d0480ed
AK
331}
332
b4f1578f 333static void _remove_from_bottomlevel(struct dm_tree_node *node)
165e4a11 334{
b1ebf028 335 _unlink_nodes(node, &node->dtree->root);
165e4a11
AK
336}
337
b4f1578f 338static int _link_tree_nodes(struct dm_tree_node *parent, struct dm_tree_node *child)
165e4a11
AK
339{
340 /* Don't link to root node if child already has a parent */
f77736ca 341 if (parent == &parent->dtree->root) {
b4f1578f 342 if (dm_tree_node_num_children(child, 1))
165e4a11
AK
343 return 1;
344 } else
345 _remove_from_toplevel(child);
346
f77736ca 347 if (child == &child->dtree->root) {
b4f1578f 348 if (dm_tree_node_num_children(parent, 0))
165e4a11
AK
349 return 1;
350 } else
351 _remove_from_bottomlevel(parent);
352
353 return _link_nodes(parent, child);
354}
355
b4f1578f 356static struct dm_tree_node *_create_dm_tree_node(struct dm_tree *dtree,
3d0480ed
AK
357 const char *name,
358 const char *uuid,
165e4a11 359 struct dm_info *info,
f16aea9e
PR
360 void *context,
361 uint16_t udev_flags)
3d0480ed 362{
b4f1578f 363 struct dm_tree_node *node;
3d0480ed
AK
364 uint64_t dev;
365
b4f1578f
AK
366 if (!(node = dm_pool_zalloc(dtree->mem, sizeof(*node)))) {
367 log_error("_create_dm_tree_node alloc failed");
3d0480ed
AK
368 return NULL;
369 }
370
b4f1578f 371 node->dtree = dtree;
3d0480ed
AK
372
373 node->name = name;
374 node->uuid = uuid;
375 node->info = *info;
165e4a11 376 node->context = context;
f16aea9e 377 node->udev_flags = udev_flags;
56c28292 378 node->activation_priority = 0;
3d0480ed 379
2c44337b
AK
380 dm_list_init(&node->uses);
381 dm_list_init(&node->used_by);
382 dm_list_init(&node->props.segs);
3d0480ed
AK
383
384 dev = MKDEV(info->major, info->minor);
385
b4f1578f 386 if (!dm_hash_insert_binary(dtree->devs, (const char *) &dev,
3d0480ed 387 sizeof(dev), node)) {
b4f1578f
AK
388 log_error("dtree node hash insertion failed");
389 dm_pool_free(dtree->mem, node);
3d0480ed
AK
390 return NULL;
391 }
392
165e4a11 393 if (uuid && *uuid &&
b4f1578f
AK
394 !dm_hash_insert(dtree->uuids, uuid, node)) {
395 log_error("dtree uuid hash insertion failed");
396 dm_hash_remove_binary(dtree->devs, (const char *) &dev,
165e4a11 397 sizeof(dev));
b4f1578f 398 dm_pool_free(dtree->mem, node);
165e4a11
AK
399 return NULL;
400 }
401
3d0480ed
AK
402 return node;
403}
404
b4f1578f 405static struct dm_tree_node *_find_dm_tree_node(struct dm_tree *dtree,
3d0480ed
AK
406 uint32_t major, uint32_t minor)
407{
408 uint64_t dev = MKDEV(major, minor);
409
b4f1578f 410 return dm_hash_lookup_binary(dtree->devs, (const char *) &dev,
3d0480ed
AK
411 sizeof(dev));
412}
413
b4f1578f 414static struct dm_tree_node *_find_dm_tree_node_by_uuid(struct dm_tree *dtree,
165e4a11
AK
415 const char *uuid)
416{
87f98002
AK
417 struct dm_tree_node *node;
418
419 if ((node = dm_hash_lookup(dtree->uuids, uuid)))
420 return node;
421
422 if (strncmp(uuid, UUID_PREFIX, sizeof(UUID_PREFIX) - 1))
423 return NULL;
424
425 return dm_hash_lookup(dtree->uuids, uuid + sizeof(UUID_PREFIX) - 1);
165e4a11
AK
426}
427
a3f6b2ce 428static int _deps(struct dm_task **dmt, struct dm_pool *mem, uint32_t major, uint32_t minor,
3d0480ed
AK
429 const char **name, const char **uuid,
430 struct dm_info *info, struct dm_deps **deps)
431{
432 memset(info, 0, sizeof(*info));
433
434 if (!dm_is_dm_major(major)) {
435 *name = "";
436 *uuid = "";
437 *deps = NULL;
438 info->major = major;
439 info->minor = minor;
440 info->exists = 0;
165e4a11
AK
441 info->live_table = 0;
442 info->inactive_table = 0;
443 info->read_only = 0;
3d0480ed
AK
444 return 1;
445 }
446
447 if (!(*dmt = dm_task_create(DM_DEVICE_DEPS))) {
448 log_error("deps dm_task creation failed");
449 return 0;
450 }
451
b4f1578f
AK
452 if (!dm_task_set_major(*dmt, major)) {
453 log_error("_deps: failed to set major for (%" PRIu32 ":%" PRIu32 ")",
454 major, minor);
3d0480ed 455 goto failed;
b4f1578f 456 }
3d0480ed 457
b4f1578f
AK
458 if (!dm_task_set_minor(*dmt, minor)) {
459 log_error("_deps: failed to set minor for (%" PRIu32 ":%" PRIu32 ")",
460 major, minor);
3d0480ed 461 goto failed;
b4f1578f 462 }
3d0480ed 463
b4f1578f
AK
464 if (!dm_task_run(*dmt)) {
465 log_error("_deps: task run failed for (%" PRIu32 ":%" PRIu32 ")",
466 major, minor);
3d0480ed 467 goto failed;
b4f1578f 468 }
3d0480ed 469
b4f1578f
AK
470 if (!dm_task_get_info(*dmt, info)) {
471 log_error("_deps: failed to get info for (%" PRIu32 ":%" PRIu32 ")",
472 major, minor);
3d0480ed 473 goto failed;
b4f1578f 474 }
3d0480ed
AK
475
476 if (!info->exists) {
477 *name = "";
478 *uuid = "";
479 *deps = NULL;
480 } else {
481 if (info->major != major) {
b4f1578f 482 log_error("Inconsistent dtree major number: %u != %u",
3d0480ed
AK
483 major, info->major);
484 goto failed;
485 }
486 if (info->minor != minor) {
b4f1578f 487 log_error("Inconsistent dtree minor number: %u != %u",
3d0480ed
AK
488 minor, info->minor);
489 goto failed;
490 }
a3f6b2ce 491 if (!(*name = dm_pool_strdup(mem, dm_task_get_name(*dmt)))) {
3d0480ed
AK
492 log_error("name pool_strdup failed");
493 goto failed;
494 }
a3f6b2ce 495 if (!(*uuid = dm_pool_strdup(mem, dm_task_get_uuid(*dmt)))) {
3d0480ed
AK
496 log_error("uuid pool_strdup failed");
497 goto failed;
498 }
499 *deps = dm_task_get_deps(*dmt);
500 }
501
502 return 1;
503
504failed:
505 dm_task_destroy(*dmt);
506 return 0;
507}
508
b4f1578f
AK
509static struct dm_tree_node *_add_dev(struct dm_tree *dtree,
510 struct dm_tree_node *parent,
cda69e17
PR
511 uint32_t major, uint32_t minor,
512 uint16_t udev_flags)
3d0480ed
AK
513{
514 struct dm_task *dmt = NULL;
515 struct dm_info info;
516 struct dm_deps *deps = NULL;
517 const char *name = NULL;
518 const char *uuid = NULL;
b4f1578f 519 struct dm_tree_node *node = NULL;
3d0480ed 520 uint32_t i;
3d0480ed
AK
521 int new = 0;
522
523 /* Already in tree? */
b4f1578f
AK
524 if (!(node = _find_dm_tree_node(dtree, major, minor))) {
525 if (!_deps(&dmt, dtree->mem, major, minor, &name, &uuid, &info, &deps))
526 return_NULL;
3d0480ed 527
f16aea9e 528 if (!(node = _create_dm_tree_node(dtree, name, uuid, &info,
cda69e17 529 NULL, udev_flags)))
b4f1578f 530 goto_out;
3d0480ed
AK
531 new = 1;
532 }
533
165e4a11
AK
534 if (!_link_tree_nodes(parent, node)) {
535 node = NULL;
b4f1578f 536 goto_out;
165e4a11 537 }
3d0480ed
AK
538
539 /* If node was already in tree, no need to recurse. */
540 if (!new)
165e4a11 541 goto out;
3d0480ed
AK
542
543 /* Can't recurse if not a mapped device or there are no dependencies */
544 if (!node->info.exists || !deps->count) {
b4f1578f
AK
545 if (!_add_to_bottomlevel(node)) {
546 stack;
165e4a11 547 node = NULL;
b4f1578f 548 }
165e4a11 549 goto out;
3d0480ed
AK
550 }
551
552 /* Add dependencies to tree */
553 for (i = 0; i < deps->count; i++)
b4f1578f 554 if (!_add_dev(dtree, node, MAJOR(deps->device[i]),
cda69e17 555 MINOR(deps->device[i]), udev_flags)) {
165e4a11 556 node = NULL;
b4f1578f 557 goto_out;
165e4a11 558 }
3d0480ed 559
3d0480ed
AK
560out:
561 if (dmt)
562 dm_task_destroy(dmt);
563
165e4a11
AK
564 return node;
565}
566
b4f1578f 567static int _node_clear_table(struct dm_tree_node *dnode)
165e4a11
AK
568{
569 struct dm_task *dmt;
570 struct dm_info *info;
571 const char *name;
572 int r;
573
574 if (!(info = &dnode->info)) {
b4f1578f 575 log_error("_node_clear_table failed: missing info");
165e4a11
AK
576 return 0;
577 }
578
b4f1578f
AK
579 if (!(name = dm_tree_node_get_name(dnode))) {
580 log_error("_node_clear_table failed: missing name");
165e4a11
AK
581 return 0;
582 }
583
584 /* Is there a table? */
585 if (!info->exists || !info->inactive_table)
586 return 1;
587
588 log_verbose("Clearing inactive table %s (%" PRIu32 ":%" PRIu32 ")",
589 name, info->major, info->minor);
590
591 if (!(dmt = dm_task_create(DM_DEVICE_CLEAR))) {
165e4a11
AK
592 log_error("Table clear dm_task creation failed for %s", name);
593 return 0;
594 }
595
596 if (!dm_task_set_major(dmt, info->major) ||
597 !dm_task_set_minor(dmt, info->minor)) {
598 log_error("Failed to set device number for %s table clear", name);
599 dm_task_destroy(dmt);
600 return 0;
601 }
602
603 r = dm_task_run(dmt);
604
605 if (!dm_task_get_info(dmt, info)) {
b4f1578f 606 log_error("_node_clear_table failed: info missing after running task for %s", name);
165e4a11
AK
607 r = 0;
608 }
609
610 dm_task_destroy(dmt);
611
3d0480ed
AK
612 return r;
613}
614
b4f1578f 615struct dm_tree_node *dm_tree_add_new_dev(struct dm_tree *dtree,
165e4a11
AK
616 const char *name,
617 const char *uuid,
618 uint32_t major, uint32_t minor,
619 int read_only,
620 int clear_inactive,
621 void *context)
622{
b4f1578f 623 struct dm_tree_node *dnode;
165e4a11
AK
624 struct dm_info info;
625 const char *name2;
626 const char *uuid2;
627
628 /* Do we need to add node to tree? */
b4f1578f
AK
629 if (!(dnode = dm_tree_find_node_by_uuid(dtree, uuid))) {
630 if (!(name2 = dm_pool_strdup(dtree->mem, name))) {
165e4a11
AK
631 log_error("name pool_strdup failed");
632 return NULL;
633 }
b4f1578f 634 if (!(uuid2 = dm_pool_strdup(dtree->mem, uuid))) {
165e4a11
AK
635 log_error("uuid pool_strdup failed");
636 return NULL;
637 }
638
639 info.major = 0;
640 info.minor = 0;
641 info.exists = 0;
642 info.live_table = 0;
643 info.inactive_table = 0;
644 info.read_only = 0;
645
f16aea9e
PR
646 if (!(dnode = _create_dm_tree_node(dtree, name2, uuid2, &info,
647 context, 0)))
b4f1578f 648 return_NULL;
165e4a11
AK
649
650 /* Attach to root node until a table is supplied */
b4f1578f
AK
651 if (!_add_to_toplevel(dnode) || !_add_to_bottomlevel(dnode))
652 return_NULL;
165e4a11
AK
653
654 dnode->props.major = major;
655 dnode->props.minor = minor;
656 dnode->props.new_name = NULL;
bb875bb9 657 dnode->props.size_changed = 0;
165e4a11
AK
658 } else if (strcmp(name, dnode->name)) {
659 /* Do we need to rename node? */
b4f1578f 660 if (!(dnode->props.new_name = dm_pool_strdup(dtree->mem, name))) {
165e4a11
AK
661 log_error("name pool_strdup failed");
662 return 0;
663 }
664 }
665
666 dnode->props.read_only = read_only ? 1 : 0;
52b84409
AK
667 dnode->props.read_ahead = DM_READ_AHEAD_AUTO;
668 dnode->props.read_ahead_flags = 0;
165e4a11 669
b4f1578f
AK
670 if (clear_inactive && !_node_clear_table(dnode))
671 return_NULL;
165e4a11
AK
672
673 dnode->context = context;
f16aea9e 674 dnode->udev_flags = 0;
165e4a11
AK
675
676 return dnode;
677}
678
f16aea9e
PR
679struct dm_tree_node *dm_tree_add_new_dev_with_udev_flags(struct dm_tree *dtree,
680 const char *name,
681 const char *uuid,
682 uint32_t major,
683 uint32_t minor,
684 int read_only,
685 int clear_inactive,
686 void *context,
687 uint16_t udev_flags)
688{
689 struct dm_tree_node *node;
690
691 if ((node = dm_tree_add_new_dev(dtree, name, uuid, major, minor, read_only,
692 clear_inactive, context)))
693 node->udev_flags = udev_flags;
694
695 return node;
696}
697
698
52b84409
AK
699void dm_tree_node_set_read_ahead(struct dm_tree_node *dnode,
700 uint32_t read_ahead,
701 uint32_t read_ahead_flags)
08e64ce5 702{
52b84409
AK
703 dnode->props.read_ahead = read_ahead;
704 dnode->props.read_ahead_flags = read_ahead_flags;
705}
706
76d1aec8
ZK
707void dm_tree_node_set_presuspend_node(struct dm_tree_node *node,
708 struct dm_tree_node *presuspend_node)
709{
710 node->presuspend_node = presuspend_node;
711}
712
b4f1578f 713int dm_tree_add_dev(struct dm_tree *dtree, uint32_t major, uint32_t minor)
3d0480ed 714{
cda69e17
PR
715 return _add_dev(dtree, &dtree->root, major, minor, 0) ? 1 : 0;
716}
717
718int dm_tree_add_dev_with_udev_flags(struct dm_tree *dtree, uint32_t major,
719 uint32_t minor, uint16_t udev_flags)
720{
721 return _add_dev(dtree, &dtree->root, major, minor, udev_flags) ? 1 : 0;
3d0480ed
AK
722}
723
04bde319 724const char *dm_tree_node_get_name(const struct dm_tree_node *node)
3d0480ed
AK
725{
726 return node->info.exists ? node->name : "";
727}
728
04bde319 729const char *dm_tree_node_get_uuid(const struct dm_tree_node *node)
3d0480ed
AK
730{
731 return node->info.exists ? node->uuid : "";
732}
733
04bde319 734const struct dm_info *dm_tree_node_get_info(const struct dm_tree_node *node)
3d0480ed
AK
735{
736 return &node->info;
737}
738
04bde319 739void *dm_tree_node_get_context(const struct dm_tree_node *node)
165e4a11
AK
740{
741 return node->context;
742}
743
04bde319 744int dm_tree_node_size_changed(const struct dm_tree_node *dnode)
eb91c4ee
MB
745{
746 return dnode->props.size_changed;
747}
748
04bde319 749int dm_tree_node_num_children(const struct dm_tree_node *node, uint32_t inverted)
3d0480ed
AK
750{
751 if (inverted) {
b4f1578f 752 if (_nodes_are_linked(&node->dtree->root, node))
3d0480ed 753 return 0;
2c44337b 754 return dm_list_size(&node->used_by);
3d0480ed
AK
755 }
756
b4f1578f 757 if (_nodes_are_linked(node, &node->dtree->root))
3d0480ed
AK
758 return 0;
759
2c44337b 760 return dm_list_size(&node->uses);
3d0480ed
AK
761}
762
2b69db1f
AK
763/*
764 * Returns 1 if no prefix supplied
765 */
766static int _uuid_prefix_matches(const char *uuid, const char *uuid_prefix, size_t uuid_prefix_len)
767{
768 if (!uuid_prefix)
769 return 1;
770
771 if (!strncmp(uuid, uuid_prefix, uuid_prefix_len))
772 return 1;
773
774 /* Handle transition: active device uuids might be missing the prefix */
775 if (uuid_prefix_len <= 4)
776 return 0;
777
87f98002 778 if (!strncmp(uuid, UUID_PREFIX, sizeof(UUID_PREFIX) - 1))
872dea04
AK
779 return 0;
780
87f98002 781 if (strncmp(uuid_prefix, UUID_PREFIX, sizeof(UUID_PREFIX) - 1))
2b69db1f
AK
782 return 0;
783
87f98002 784 if (!strncmp(uuid, uuid_prefix + sizeof(UUID_PREFIX) - 1, uuid_prefix_len - (sizeof(UUID_PREFIX) - 1)))
2b69db1f
AK
785 return 1;
786
787 return 0;
788}
789
690a5da2
AK
790/*
791 * Returns 1 if no children.
792 */
b4f1578f 793static int _children_suspended(struct dm_tree_node *node,
690a5da2
AK
794 uint32_t inverted,
795 const char *uuid_prefix,
796 size_t uuid_prefix_len)
797{
2c44337b 798 struct dm_list *list;
b4f1578f 799 struct dm_tree_link *dlink;
690a5da2
AK
800 const struct dm_info *dinfo;
801 const char *uuid;
802
803 if (inverted) {
b4f1578f 804 if (_nodes_are_linked(&node->dtree->root, node))
690a5da2
AK
805 return 1;
806 list = &node->used_by;
807 } else {
b4f1578f 808 if (_nodes_are_linked(node, &node->dtree->root))
690a5da2
AK
809 return 1;
810 list = &node->uses;
811 }
812
2c44337b 813 dm_list_iterate_items(dlink, list) {
b4f1578f 814 if (!(uuid = dm_tree_node_get_uuid(dlink->node))) {
690a5da2
AK
815 stack;
816 continue;
817 }
818
819 /* Ignore if it doesn't belong to this VG */
2b69db1f 820 if (!_uuid_prefix_matches(uuid, uuid_prefix, uuid_prefix_len))
690a5da2
AK
821 continue;
822
76d1aec8
ZK
823 /* Ignore if parent node wants to presuspend this node */
824 if (dlink->node->presuspend_node == node)
825 continue;
826
b4f1578f
AK
827 if (!(dinfo = dm_tree_node_get_info(dlink->node))) {
828 stack; /* FIXME Is this normal? */
690a5da2
AK
829 return 0;
830 }
831
832 if (!dinfo->suspended)
833 return 0;
834 }
835
836 return 1;
837}
838
3d0480ed
AK
839/*
840 * Set major and minor to zero for root of tree.
841 */
b4f1578f 842struct dm_tree_node *dm_tree_find_node(struct dm_tree *dtree,
3d0480ed
AK
843 uint32_t major,
844 uint32_t minor)
845{
846 if (!major && !minor)
b4f1578f 847 return &dtree->root;
3d0480ed 848
b4f1578f 849 return _find_dm_tree_node(dtree, major, minor);
3d0480ed
AK
850}
851
165e4a11
AK
852/*
853 * Set uuid to NULL for root of tree.
854 */
b4f1578f 855struct dm_tree_node *dm_tree_find_node_by_uuid(struct dm_tree *dtree,
165e4a11
AK
856 const char *uuid)
857{
858 if (!uuid || !*uuid)
b4f1578f 859 return &dtree->root;
165e4a11 860
b4f1578f 861 return _find_dm_tree_node_by_uuid(dtree, uuid);
165e4a11
AK
862}
863
3d0480ed
AK
864/*
865 * First time set *handle to NULL.
866 * Set inverted to invert the tree.
867 */
b4f1578f 868struct dm_tree_node *dm_tree_next_child(void **handle,
04bde319
ZK
869 const struct dm_tree_node *parent,
870 uint32_t inverted)
3d0480ed 871{
2c44337b 872 struct dm_list **dlink = (struct dm_list **) handle;
04bde319 873 const struct dm_list *use_list;
3d0480ed
AK
874
875 if (inverted)
876 use_list = &parent->used_by;
877 else
878 use_list = &parent->uses;
879
880 if (!*dlink)
2c44337b 881 *dlink = dm_list_first(use_list);
3d0480ed 882 else
2c44337b 883 *dlink = dm_list_next(use_list, *dlink);
3d0480ed 884
2c44337b 885 return (*dlink) ? dm_list_item(*dlink, struct dm_tree_link)->node : NULL;
3d0480ed
AK
886}
887
3e8c6b73 888/*
a6d97ede 889 * Deactivate a device with its dependencies if the uuid prefix matches.
3e8c6b73 890 */
db208f51
AK
891static int _info_by_dev(uint32_t major, uint32_t minor, int with_open_count,
892 struct dm_info *info)
3e8c6b73
AK
893{
894 struct dm_task *dmt;
895 int r;
896
897 if (!(dmt = dm_task_create(DM_DEVICE_INFO))) {
898 log_error("_info_by_dev: dm_task creation failed");
899 return 0;
900 }
901
902 if (!dm_task_set_major(dmt, major) || !dm_task_set_minor(dmt, minor)) {
903 log_error("_info_by_dev: Failed to set device number");
904 dm_task_destroy(dmt);
905 return 0;
906 }
907
db208f51
AK
908 if (!with_open_count && !dm_task_no_open_count(dmt))
909 log_error("Failed to disable open_count");
910
3e8c6b73
AK
911 if ((r = dm_task_run(dmt)))
912 r = dm_task_get_info(dmt, info);
913
914 dm_task_destroy(dmt);
915
916 return r;
917}
918
f3ef15ef
ZK
919/* Check if all parent nodes of given node have open_count == 0 */
920static int _node_has_closed_parents(struct dm_tree_node *node,
921 const char *uuid_prefix,
922 size_t uuid_prefix_len)
923{
924 struct dm_tree_link *dlink;
925 const struct dm_info *dinfo;
926 struct dm_info info;
927 const char *uuid;
928
929 /* Iterate through parents of this node */
930 dm_list_iterate_items(dlink, &node->used_by) {
931 if (!(uuid = dm_tree_node_get_uuid(dlink->node))) {
932 stack;
933 continue;
934 }
935
936 /* Ignore if it doesn't belong to this VG */
937 if (!_uuid_prefix_matches(uuid, uuid_prefix, uuid_prefix_len))
938 continue;
939
940 if (!(dinfo = dm_tree_node_get_info(dlink->node))) {
941 stack; /* FIXME Is this normal? */
942 return 0;
943 }
944
945 /* Refresh open_count */
946 if (!_info_by_dev(dinfo->major, dinfo->minor, 1, &info) ||
947 !info.exists)
948 continue;
949
eb418883
ZK
950 if (info.open_count) {
951 log_debug("Node %s %d:%d has open_count %d", uuid_prefix,
952 dinfo->major, dinfo->minor, info.open_count);
f3ef15ef 953 return 0;
eb418883 954 }
f3ef15ef
ZK
955 }
956
957 return 1;
958}
959
f16aea9e
PR
960static int _deactivate_node(const char *name, uint32_t major, uint32_t minor,
961 uint32_t *cookie, uint16_t udev_flags)
3e8c6b73
AK
962{
963 struct dm_task *dmt;
bd90c6b2 964 int r = 0;
3e8c6b73
AK
965
966 log_verbose("Removing %s (%" PRIu32 ":%" PRIu32 ")", name, major, minor);
967
968 if (!(dmt = dm_task_create(DM_DEVICE_REMOVE))) {
969 log_error("Deactivation dm_task creation failed for %s", name);
970 return 0;
971 }
972
973 if (!dm_task_set_major(dmt, major) || !dm_task_set_minor(dmt, minor)) {
974 log_error("Failed to set device number for %s deactivation", name);
bd90c6b2 975 goto out;
3e8c6b73
AK
976 }
977
978 if (!dm_task_no_open_count(dmt))
979 log_error("Failed to disable open_count");
980
f16aea9e 981 if (!dm_task_set_cookie(dmt, cookie, udev_flags))
bd90c6b2
AK
982 goto out;
983
3e8c6b73
AK
984 r = dm_task_run(dmt);
985
165e4a11 986 /* FIXME Until kernel returns actual name so dm-ioctl.c can handle it */
cda69e17
PR
987 rm_dev_node(name, dmt->cookie_set &&
988 !(udev_flags & DM_UDEV_DISABLE_DM_RULES_FLAG));
165e4a11 989
db208f51
AK
990 /* FIXME Remove node from tree or mark invalid? */
991
bd90c6b2 992out:
db208f51
AK
993 dm_task_destroy(dmt);
994
995 return r;
996}
997
bd90c6b2 998static int _rename_node(const char *old_name, const char *new_name, uint32_t major,
f16aea9e 999 uint32_t minor, uint32_t *cookie, uint16_t udev_flags)
165e4a11
AK
1000{
1001 struct dm_task *dmt;
1002 int r = 0;
1003
1004 log_verbose("Renaming %s (%" PRIu32 ":%" PRIu32 ") to %s", old_name, major, minor, new_name);
1005
1006 if (!(dmt = dm_task_create(DM_DEVICE_RENAME))) {
1007 log_error("Rename dm_task creation failed for %s", old_name);
1008 return 0;
1009 }
1010
1011 if (!dm_task_set_name(dmt, old_name)) {
1012 log_error("Failed to set name for %s rename.", old_name);
1013 goto out;
1014 }
1015
b4f1578f
AK
1016 if (!dm_task_set_newname(dmt, new_name))
1017 goto_out;
165e4a11
AK
1018
1019 if (!dm_task_no_open_count(dmt))
1020 log_error("Failed to disable open_count");
1021
f16aea9e 1022 if (!dm_task_set_cookie(dmt, cookie, udev_flags))
bd90c6b2
AK
1023 goto out;
1024
165e4a11
AK
1025 r = dm_task_run(dmt);
1026
1027out:
1028 dm_task_destroy(dmt);
1029
1030 return r;
1031}
1032
165e4a11
AK
1033/* FIXME Merge with _suspend_node? */
1034static int _resume_node(const char *name, uint32_t major, uint32_t minor,
52b84409 1035 uint32_t read_ahead, uint32_t read_ahead_flags,
f16aea9e
PR
1036 struct dm_info *newinfo, uint32_t *cookie,
1037 uint16_t udev_flags)
165e4a11
AK
1038{
1039 struct dm_task *dmt;
bd90c6b2 1040 int r = 0;
165e4a11
AK
1041
1042 log_verbose("Resuming %s (%" PRIu32 ":%" PRIu32 ")", name, major, minor);
1043
1044 if (!(dmt = dm_task_create(DM_DEVICE_RESUME))) {
1045 log_error("Suspend dm_task creation failed for %s", name);
1046 return 0;
1047 }
1048
0b7d16bc
AK
1049 /* FIXME Kernel should fill in name on return instead */
1050 if (!dm_task_set_name(dmt, name)) {
1051 log_error("Failed to set readahead device name for %s", name);
bd90c6b2 1052 goto out;
0b7d16bc
AK
1053 }
1054
165e4a11
AK
1055 if (!dm_task_set_major(dmt, major) || !dm_task_set_minor(dmt, minor)) {
1056 log_error("Failed to set device number for %s resumption.", name);
bd90c6b2 1057 goto out;
165e4a11
AK
1058 }
1059
1060 if (!dm_task_no_open_count(dmt))
1061 log_error("Failed to disable open_count");
1062
52b84409
AK
1063 if (!dm_task_set_read_ahead(dmt, read_ahead, read_ahead_flags))
1064 log_error("Failed to set read ahead");
1065
f16aea9e 1066 if (!dm_task_set_cookie(dmt, cookie, udev_flags))
bd90c6b2
AK
1067 goto out;
1068
165e4a11
AK
1069 if ((r = dm_task_run(dmt)))
1070 r = dm_task_get_info(dmt, newinfo);
1071
bd90c6b2 1072out:
165e4a11
AK
1073 dm_task_destroy(dmt);
1074
1075 return r;
1076}
1077
db208f51 1078static int _suspend_node(const char *name, uint32_t major, uint32_t minor,
b9ffd32c 1079 int skip_lockfs, int no_flush, struct dm_info *newinfo)
db208f51
AK
1080{
1081 struct dm_task *dmt;
1082 int r;
1083
b9ffd32c
AK
1084 log_verbose("Suspending %s (%" PRIu32 ":%" PRIu32 ")%s%s",
1085 name, major, minor,
1086 skip_lockfs ? "" : " with filesystem sync",
6e1898a5 1087 no_flush ? "" : " with device flush");
db208f51
AK
1088
1089 if (!(dmt = dm_task_create(DM_DEVICE_SUSPEND))) {
1090 log_error("Suspend dm_task creation failed for %s", name);
1091 return 0;
1092 }
1093
1094 if (!dm_task_set_major(dmt, major) || !dm_task_set_minor(dmt, minor)) {
1095 log_error("Failed to set device number for %s suspension.", name);
1096 dm_task_destroy(dmt);
1097 return 0;
1098 }
1099
1100 if (!dm_task_no_open_count(dmt))
1101 log_error("Failed to disable open_count");
1102
c55b1410
AK
1103 if (skip_lockfs && !dm_task_skip_lockfs(dmt))
1104 log_error("Failed to set skip_lockfs flag.");
1105
b9ffd32c
AK
1106 if (no_flush && !dm_task_no_flush(dmt))
1107 log_error("Failed to set no_flush flag.");
1108
db208f51
AK
1109 if ((r = dm_task_run(dmt)))
1110 r = dm_task_get_info(dmt, newinfo);
1111
3e8c6b73
AK
1112 dm_task_destroy(dmt);
1113
1114 return r;
1115}
1116
18e0f934
AK
1117/*
1118 * FIXME Don't attempt to deactivate known internal dependencies.
1119 */
1120static int _dm_tree_deactivate_children(struct dm_tree_node *dnode,
1121 const char *uuid_prefix,
1122 size_t uuid_prefix_len,
1123 unsigned level)
3e8c6b73 1124{
b7eb2ad0 1125 int r = 1;
3e8c6b73 1126 void *handle = NULL;
b4f1578f 1127 struct dm_tree_node *child = dnode;
3e8c6b73
AK
1128 struct dm_info info;
1129 const struct dm_info *dinfo;
1130 const char *name;
1131 const char *uuid;
1132
b4f1578f
AK
1133 while ((child = dm_tree_next_child(&handle, dnode, 0))) {
1134 if (!(dinfo = dm_tree_node_get_info(child))) {
3e8c6b73
AK
1135 stack;
1136 continue;
1137 }
1138
b4f1578f 1139 if (!(name = dm_tree_node_get_name(child))) {
3e8c6b73
AK
1140 stack;
1141 continue;
1142 }
1143
b4f1578f 1144 if (!(uuid = dm_tree_node_get_uuid(child))) {
3e8c6b73
AK
1145 stack;
1146 continue;
1147 }
1148
1149 /* Ignore if it doesn't belong to this VG */
2b69db1f 1150 if (!_uuid_prefix_matches(uuid, uuid_prefix, uuid_prefix_len))
3e8c6b73 1151 continue;
3e8c6b73
AK
1152
1153 /* Refresh open_count */
db208f51 1154 if (!_info_by_dev(dinfo->major, dinfo->minor, 1, &info) ||
f55021f4 1155 !info.exists)
3e8c6b73
AK
1156 continue;
1157
f3ef15ef
ZK
1158 /* Also checking open_count in parent nodes of presuspend_node */
1159 if (info.open_count ||
1160 (child->presuspend_node &&
1161 !_node_has_closed_parents(child->presuspend_node,
1162 uuid_prefix, uuid_prefix_len))) {
18e0f934
AK
1163 /* Only report error from (likely non-internal) dependency at top level */
1164 if (!level) {
1165 log_error("Unable to deactivate open %s (%" PRIu32
1166 ":%" PRIu32 ")", name, info.major,
1167 info.minor);
1168 r = 0;
1169 }
f55021f4
AK
1170 continue;
1171 }
1172
76d1aec8
ZK
1173 /* Suspend child node first if requested */
1174 if (child->presuspend_node &&
1175 !dm_tree_suspend_children(child, uuid_prefix, uuid_prefix_len))
1176 continue;
1177
f16aea9e 1178 if (!_deactivate_node(name, info.major, info.minor,
584d1fb7 1179 &child->dtree->cookie, child->udev_flags)) {
3e8c6b73
AK
1180 log_error("Unable to deactivate %s (%" PRIu32
1181 ":%" PRIu32 ")", name, info.major,
1182 info.minor);
b7eb2ad0 1183 r = 0;
3e8c6b73
AK
1184 continue;
1185 }
1186
18e0f934
AK
1187 if (dm_tree_node_num_children(child, 0)) {
1188 if (!_dm_tree_deactivate_children(child, uuid_prefix, uuid_prefix_len, level + 1))
b7eb2ad0 1189 return_0;
18e0f934 1190 }
3e8c6b73
AK
1191 }
1192
b7eb2ad0 1193 return r;
3e8c6b73 1194}
db208f51 1195
18e0f934
AK
1196int dm_tree_deactivate_children(struct dm_tree_node *dnode,
1197 const char *uuid_prefix,
1198 size_t uuid_prefix_len)
1199{
1200 return _dm_tree_deactivate_children(dnode, uuid_prefix, uuid_prefix_len, 0);
1201}
1202
c55b1410
AK
1203void dm_tree_skip_lockfs(struct dm_tree_node *dnode)
1204{
1205 dnode->dtree->skip_lockfs = 1;
1206}
1207
b9ffd32c
AK
1208void dm_tree_use_no_flush_suspend(struct dm_tree_node *dnode)
1209{
1210 dnode->dtree->no_flush = 1;
1211}
1212
b4f1578f 1213int dm_tree_suspend_children(struct dm_tree_node *dnode,
08e64ce5
ZK
1214 const char *uuid_prefix,
1215 size_t uuid_prefix_len)
db208f51 1216{
68085c93 1217 int r = 1;
db208f51 1218 void *handle = NULL;
b4f1578f 1219 struct dm_tree_node *child = dnode;
db208f51
AK
1220 struct dm_info info, newinfo;
1221 const struct dm_info *dinfo;
1222 const char *name;
1223 const char *uuid;
1224
690a5da2 1225 /* Suspend nodes at this level of the tree */
b4f1578f
AK
1226 while ((child = dm_tree_next_child(&handle, dnode, 0))) {
1227 if (!(dinfo = dm_tree_node_get_info(child))) {
db208f51
AK
1228 stack;
1229 continue;
1230 }
1231
b4f1578f 1232 if (!(name = dm_tree_node_get_name(child))) {
db208f51
AK
1233 stack;
1234 continue;
1235 }
1236
b4f1578f 1237 if (!(uuid = dm_tree_node_get_uuid(child))) {
db208f51
AK
1238 stack;
1239 continue;
1240 }
1241
1242 /* Ignore if it doesn't belong to this VG */
2b69db1f 1243 if (!_uuid_prefix_matches(uuid, uuid_prefix, uuid_prefix_len))
db208f51
AK
1244 continue;
1245
690a5da2
AK
1246 /* Ensure immediate parents are already suspended */
1247 if (!_children_suspended(child, 1, uuid_prefix, uuid_prefix_len))
1248 continue;
1249
db208f51 1250 if (!_info_by_dev(dinfo->major, dinfo->minor, 0, &info) ||
b700541f 1251 !info.exists || info.suspended)
db208f51
AK
1252 continue;
1253
c55b1410 1254 if (!_suspend_node(name, info.major, info.minor,
b9ffd32c
AK
1255 child->dtree->skip_lockfs,
1256 child->dtree->no_flush, &newinfo)) {
db208f51
AK
1257 log_error("Unable to suspend %s (%" PRIu32
1258 ":%" PRIu32 ")", name, info.major,
1259 info.minor);
68085c93 1260 r = 0;
db208f51
AK
1261 continue;
1262 }
1263
1264 /* Update cached info */
1265 child->info = newinfo;
690a5da2
AK
1266 }
1267
1268 /* Then suspend any child nodes */
1269 handle = NULL;
1270
b4f1578f
AK
1271 while ((child = dm_tree_next_child(&handle, dnode, 0))) {
1272 if (!(uuid = dm_tree_node_get_uuid(child))) {
690a5da2
AK
1273 stack;
1274 continue;
1275 }
1276
1277 /* Ignore if it doesn't belong to this VG */
87f98002 1278 if (!_uuid_prefix_matches(uuid, uuid_prefix, uuid_prefix_len))
690a5da2 1279 continue;
db208f51 1280
b4f1578f 1281 if (dm_tree_node_num_children(child, 0))
68085c93
MS
1282 if (!dm_tree_suspend_children(child, uuid_prefix, uuid_prefix_len))
1283 return_0;
db208f51
AK
1284 }
1285
68085c93 1286 return r;
db208f51
AK
1287}
1288
b4f1578f 1289int dm_tree_activate_children(struct dm_tree_node *dnode,
db208f51
AK
1290 const char *uuid_prefix,
1291 size_t uuid_prefix_len)
1292{
2ca6b865 1293 int r = 1;
db208f51 1294 void *handle = NULL;
b4f1578f 1295 struct dm_tree_node *child = dnode;
165e4a11
AK
1296 struct dm_info newinfo;
1297 const char *name;
db208f51 1298 const char *uuid;
56c28292 1299 int priority;
db208f51 1300
165e4a11 1301 /* Activate children first */
b4f1578f
AK
1302 while ((child = dm_tree_next_child(&handle, dnode, 0))) {
1303 if (!(uuid = dm_tree_node_get_uuid(child))) {
165e4a11
AK
1304 stack;
1305 continue;
db208f51
AK
1306 }
1307
908db078
AK
1308 if (!_uuid_prefix_matches(uuid, uuid_prefix, uuid_prefix_len))
1309 continue;
db208f51 1310
b4f1578f 1311 if (dm_tree_node_num_children(child, 0))
2ca6b865
MS
1312 if (!dm_tree_activate_children(child, uuid_prefix, uuid_prefix_len))
1313 return_0;
56c28292 1314 }
165e4a11 1315
56c28292 1316 handle = NULL;
165e4a11 1317
aa6f4e51 1318 for (priority = 0; priority < 3; priority++) {
56c28292
AK
1319 while ((child = dm_tree_next_child(&handle, dnode, 0))) {
1320 if (!(uuid = dm_tree_node_get_uuid(child))) {
1321 stack;
1322 continue;
165e4a11 1323 }
165e4a11 1324
56c28292
AK
1325 if (!_uuid_prefix_matches(uuid, uuid_prefix, uuid_prefix_len))
1326 continue;
165e4a11 1327
56c28292
AK
1328 if (priority != child->activation_priority)
1329 continue;
165e4a11 1330
56c28292
AK
1331 if (!(name = dm_tree_node_get_name(child))) {
1332 stack;
1333 continue;
1334 }
1335
1336 /* Rename? */
1337 if (child->props.new_name) {
bd90c6b2 1338 if (!_rename_node(name, child->props.new_name, child->info.major,
f16aea9e
PR
1339 child->info.minor, &child->dtree->cookie,
1340 child->udev_flags)) {
56c28292
AK
1341 log_error("Failed to rename %s (%" PRIu32
1342 ":%" PRIu32 ") to %s", name, child->info.major,
1343 child->info.minor, child->props.new_name);
1344 return 0;
1345 }
1346 child->name = child->props.new_name;
1347 child->props.new_name = NULL;
1348 }
1349
1350 if (!child->info.inactive_table && !child->info.suspended)
1351 continue;
1352
bafa2f39 1353 if (!_resume_node(child->name, child->info.major, child->info.minor,
bd90c6b2 1354 child->props.read_ahead, child->props.read_ahead_flags,
f16aea9e 1355 &newinfo, &child->dtree->cookie, child->udev_flags)) {
56c28292 1356 log_error("Unable to resume %s (%" PRIu32
bafa2f39 1357 ":%" PRIu32 ")", child->name, child->info.major,
56c28292 1358 child->info.minor);
2ca6b865 1359 r = 0;
56c28292
AK
1360 continue;
1361 }
1362
1363 /* Update cached info */
1364 child->info = newinfo;
1365 }
db208f51
AK
1366 }
1367
165e4a11
AK
1368 handle = NULL;
1369
2ca6b865 1370 return r;
165e4a11
AK
1371}
1372
b4f1578f 1373static int _create_node(struct dm_tree_node *dnode)
165e4a11
AK
1374{
1375 int r = 0;
1376 struct dm_task *dmt;
1377
1378 log_verbose("Creating %s", dnode->name);
1379
1380 if (!(dmt = dm_task_create(DM_DEVICE_CREATE))) {
1381 log_error("Create dm_task creation failed for %s", dnode->name);
1382 return 0;
1383 }
1384
1385 if (!dm_task_set_name(dmt, dnode->name)) {
1386 log_error("Failed to set device name for %s", dnode->name);
1387 goto out;
1388 }
1389
1390 if (!dm_task_set_uuid(dmt, dnode->uuid)) {
1391 log_error("Failed to set uuid for %s", dnode->name);
1392 goto out;
1393 }
1394
1395 if (dnode->props.major &&
1396 (!dm_task_set_major(dmt, dnode->props.major) ||
1397 !dm_task_set_minor(dmt, dnode->props.minor))) {
1398 log_error("Failed to set device number for %s creation.", dnode->name);
1399 goto out;
1400 }
1401
1402 if (dnode->props.read_only && !dm_task_set_ro(dmt)) {
1403 log_error("Failed to set read only flag for %s", dnode->name);
1404 goto out;
1405 }
1406
1407 if (!dm_task_no_open_count(dmt))
1408 log_error("Failed to disable open_count");
1409
1410 if ((r = dm_task_run(dmt)))
1411 r = dm_task_get_info(dmt, &dnode->info);
1412
1413out:
1414 dm_task_destroy(dmt);
1415
1416 return r;
1417}
1418
1419
b4f1578f 1420static int _build_dev_string(char *devbuf, size_t bufsize, struct dm_tree_node *node)
165e4a11
AK
1421{
1422 if (!dm_format_dev(devbuf, bufsize, node->info.major, node->info.minor)) {
1423 log_error("Failed to format %s device number for %s as dm "
1424 "target (%u,%u)",
1425 node->name, node->uuid, node->info.major, node->info.minor);
1426 return 0;
1427 }
1428
1429 return 1;
1430}
1431
ffa9b6a5
ZK
1432/* simplify string emiting code */
1433#define EMIT_PARAMS(p, str...)\
7b6c011c
AK
1434do {\
1435 int w;\
1436 if ((w = dm_snprintf(params + p, paramsize - (size_t) p, str)) < 0) {\
1437 stack; /* Out of space */\
1438 return -1;\
1439 }\
1440 p += w;\
1441} while (0)
ffa9b6a5 1442
3c74075f
JEB
1443/*
1444 * _emit_areas_line
1445 *
1446 * Returns: 1 on success, 0 on failure
1447 */
08f1ddea 1448static int _emit_areas_line(struct dm_task *dmt __attribute__((unused)),
4dcaa230
AK
1449 struct load_segment *seg, char *params,
1450 size_t paramsize, int *pos)
165e4a11
AK
1451{
1452 struct seg_area *area;
7d7d93ac 1453 char devbuf[DM_FORMAT_DEV_BUFSIZE];
609faae9 1454 unsigned first_time = 1;
db3c1ac1 1455 const char *logtype, *synctype;
b262f3e1 1456 unsigned log_parm_count;
165e4a11 1457
2c44337b 1458 dm_list_iterate_items(area, &seg->areas) {
b4f1578f
AK
1459 if (!_build_dev_string(devbuf, sizeof(devbuf), area->dev_node))
1460 return_0;
165e4a11 1461
b262f3e1
ZK
1462 switch (seg->type) {
1463 case SEG_REPLICATOR_DEV:
1464 EMIT_PARAMS(*pos, " %d 1 %s", area->rsite_index, devbuf);
1465 if (first_time)
1466 EMIT_PARAMS(*pos, " nolog 0");
1467 else {
1468 /* Remote devices */
1469 log_parm_count = (area->flags &
1470 (DM_NOSYNC | DM_FORCESYNC)) ? 2 : 1;
1471
1472 if (!area->slog) {
1473 devbuf[0] = 0; /* Only core log parameters */
1474 logtype = "core";
1475 } else {
1476 devbuf[0] = ' '; /* Extra space before device name */
1477 if (!_build_dev_string(devbuf + 1,
1478 sizeof(devbuf) - 1,
1479 area->slog))
1480 return_0;
1481 logtype = "disk";
1482 log_parm_count++; /* Extra sync log device name parameter */
1483 }
1484
1485 EMIT_PARAMS(*pos, " %s %u%s %" PRIu64, logtype,
1486 log_parm_count, devbuf, area->region_size);
1487
db3c1ac1
AK
1488 synctype = (area->flags & DM_NOSYNC) ?
1489 " nosync" : (area->flags & DM_FORCESYNC) ?
1490 " sync" : NULL;
b262f3e1 1491
db3c1ac1
AK
1492 if (synctype)
1493 EMIT_PARAMS(*pos, "%s", synctype);
b262f3e1
ZK
1494 }
1495 break;
1496 default:
1497 EMIT_PARAMS(*pos, "%s%s %" PRIu64, first_time ? "" : " ",
1498 devbuf, area->offset);
1499 }
609faae9
AK
1500
1501 first_time = 0;
165e4a11
AK
1502 }
1503
1504 return 1;
1505}
1506
b262f3e1
ZK
1507static int _replicator_emit_segment_line(const struct load_segment *seg, char *params,
1508 size_t paramsize, int *pos)
1509{
1510 const struct load_segment *rlog_seg;
1511 struct replicator_site *rsite;
1512 char rlogbuf[DM_FORMAT_DEV_BUFSIZE];
1513 unsigned parm_count;
1514
1515 if (!seg->log || !_build_dev_string(rlogbuf, sizeof(rlogbuf), seg->log))
1516 return_0;
1517
1518 rlog_seg = dm_list_item(dm_list_last(&seg->log->props.segs),
1519 struct load_segment);
1520
1521 EMIT_PARAMS(*pos, "%s 4 %s 0 auto %" PRIu64,
1522 seg->rlog_type, rlogbuf, rlog_seg->size);
1523
1524 dm_list_iterate_items(rsite, &seg->rsites) {
1525 parm_count = (rsite->fall_behind_data
1526 || rsite->fall_behind_ios
1527 || rsite->async_timeout) ? 4 : 2;
1528
1529 EMIT_PARAMS(*pos, " blockdev %u %u %s", parm_count, rsite->rsite_index,
1530 (rsite->mode == DM_REPLICATOR_SYNC) ? "synchronous" : "asynchronous");
1531
1532 if (rsite->fall_behind_data)
1533 EMIT_PARAMS(*pos, " data %" PRIu64, rsite->fall_behind_data);
1534 else if (rsite->fall_behind_ios)
1535 EMIT_PARAMS(*pos, " ios %" PRIu32, rsite->fall_behind_ios);
1536 else if (rsite->async_timeout)
1537 EMIT_PARAMS(*pos, " timeout %" PRIu32, rsite->async_timeout);
1538 }
1539
1540 return 1;
1541}
1542
3c74075f 1543/*
3c74075f
JEB
1544 * Returns: 1 on success, 0 on failure
1545 */
536f0e08
AK
1546static int _mirror_emit_segment_line(struct dm_task *dmt, uint32_t major,
1547 uint32_t minor, struct load_segment *seg,
1548 uint64_t *seg_start, char *params,
1549 size_t paramsize)
165e4a11 1550{
8f26e18c
JEB
1551 int block_on_error = 0;
1552 int handle_errors = 0;
1553 int dm_log_userspace = 0;
1554 struct utsname uts;
dbcb64b8 1555 unsigned log_parm_count;
b39fdcf4 1556 int pos = 0, parts;
7d7d93ac 1557 char logbuf[DM_FORMAT_DEV_BUFSIZE];
dbcb64b8 1558 const char *logtype;
b39fdcf4 1559 unsigned kmaj = 0, kmin = 0, krel = 0;
165e4a11 1560
b39fdcf4
MB
1561 if (uname(&uts) == -1) {
1562 log_error("Cannot read kernel release version.");
1563 return 0;
1564 }
1565
1566 /* Kernels with a major number of 2 always had 3 parts. */
1567 parts = sscanf(uts.release, "%u.%u.%u", &kmaj, &kmin, &krel);
1568 if (parts < 1 || (kmaj < 3 && parts < 3)) {
1569 log_error("Wrong kernel release version %s.", uts.release);
30a65310
ZK
1570 return 0;
1571 }
67b25ed4 1572
8f26e18c
JEB
1573 if ((seg->flags & DM_BLOCK_ON_ERROR)) {
1574 /*
1575 * Originally, block_on_error was an argument to the log
1576 * portion of the mirror CTR table. It was renamed to
1577 * "handle_errors" and now resides in the 'features'
1578 * section of the mirror CTR table (i.e. at the end).
1579 *
1580 * We can identify whether to use "block_on_error" or
1581 * "handle_errors" by the dm-mirror module's version
1582 * number (>= 1.12) or by the kernel version (>= 2.6.22).
1583 */
ba61f848 1584 if (KERNEL_VERSION(kmaj, kmin, krel) >= KERNEL_VERSION(2, 6, 22))
8f26e18c
JEB
1585 handle_errors = 1;
1586 else
1587 block_on_error = 1;
1588 }
1589
1590 if (seg->clustered) {
1591 /* Cluster mirrors require a UUID */
1592 if (!seg->uuid)
1593 return_0;
1594
1595 /*
1596 * Cluster mirrors used to have their own log
1597 * types. Now they are accessed through the
1598 * userspace log type.
1599 *
1600 * The dm-log-userspace module was added to the
1601 * 2.6.31 kernel.
1602 */
ba61f848 1603 if (KERNEL_VERSION(kmaj, kmin, krel) >= KERNEL_VERSION(2, 6, 31))
8f26e18c
JEB
1604 dm_log_userspace = 1;
1605 }
1606
1607 /* Region size */
1608 log_parm_count = 1;
1609
1610 /* [no]sync, block_on_error etc. */
1611 log_parm_count += hweight32(seg->flags);
311d6d81 1612
8f26e18c
JEB
1613 /* "handle_errors" is a feature arg now */
1614 if (handle_errors)
1615 log_parm_count--;
1616
1617 /* DM_CORELOG does not count in the param list */
1618 if (seg->flags & DM_CORELOG)
1619 log_parm_count--;
1620
1621 if (seg->clustered) {
1622 log_parm_count++; /* For UUID */
1623
1624 if (!dm_log_userspace)
ffa9b6a5 1625 EMIT_PARAMS(pos, "clustered-");
49b95a5e
JEB
1626 else
1627 /* For clustered-* type field inserted later */
1628 log_parm_count++;
8f26e18c 1629 }
dbcb64b8 1630
8f26e18c
JEB
1631 if (!seg->log)
1632 logtype = "core";
1633 else {
1634 logtype = "disk";
1635 log_parm_count++;
1636 if (!_build_dev_string(logbuf, sizeof(logbuf), seg->log))
1637 return_0;
1638 }
dbcb64b8 1639
8f26e18c
JEB
1640 if (dm_log_userspace)
1641 EMIT_PARAMS(pos, "userspace %u %s clustered-%s",
1642 log_parm_count, seg->uuid, logtype);
1643 else
ffa9b6a5 1644 EMIT_PARAMS(pos, "%s %u", logtype, log_parm_count);
dbcb64b8 1645
8f26e18c
JEB
1646 if (seg->log)
1647 EMIT_PARAMS(pos, " %s", logbuf);
1648
1649 EMIT_PARAMS(pos, " %u", seg->region_size);
dbcb64b8 1650
8f26e18c
JEB
1651 if (seg->clustered && !dm_log_userspace)
1652 EMIT_PARAMS(pos, " %s", seg->uuid);
67b25ed4 1653
8f26e18c
JEB
1654 if ((seg->flags & DM_NOSYNC))
1655 EMIT_PARAMS(pos, " nosync");
1656 else if ((seg->flags & DM_FORCESYNC))
1657 EMIT_PARAMS(pos, " sync");
dbcb64b8 1658
8f26e18c
JEB
1659 if (block_on_error)
1660 EMIT_PARAMS(pos, " block_on_error");
1661
1662 EMIT_PARAMS(pos, " %u ", seg->mirror_area_count);
1663
5f3325fc 1664 if (_emit_areas_line(dmt, seg, params, paramsize, &pos) <= 0)
3c74075f 1665 return_0;
dbcb64b8 1666
8f26e18c
JEB
1667 if (handle_errors)
1668 EMIT_PARAMS(pos, " 1 handle_errors");
ffa9b6a5 1669
3c74075f 1670 return 1;
8f26e18c
JEB
1671}
1672
1673static int _emit_segment_line(struct dm_task *dmt, uint32_t major,
1674 uint32_t minor, struct load_segment *seg,
1675 uint64_t *seg_start, char *params,
1676 size_t paramsize)
1677{
1678 int pos = 0;
1679 int r;
1680 char originbuf[DM_FORMAT_DEV_BUFSIZE], cowbuf[DM_FORMAT_DEV_BUFSIZE];
dbcb64b8 1681
8f26e18c
JEB
1682 switch(seg->type) {
1683 case SEG_ERROR:
1684 case SEG_ZERO:
1685 case SEG_LINEAR:
1686 break;
1687 case SEG_MIRRORED:
1688 /* Mirrors are pretty complicated - now in separate function */
536f0e08
AK
1689 r = _mirror_emit_segment_line(dmt, major, minor, seg, seg_start,
1690 params, paramsize);
3c74075f
JEB
1691 if (!r)
1692 return_0;
165e4a11 1693 break;
b262f3e1
ZK
1694 case SEG_REPLICATOR:
1695 if ((r = _replicator_emit_segment_line(seg, params, paramsize,
1696 &pos)) <= 0) {
1697 stack;
1698 return r;
1699 }
1700 break;
1701 case SEG_REPLICATOR_DEV:
1702 if (!seg->replicator || !_build_dev_string(originbuf,
1703 sizeof(originbuf),
1704 seg->replicator))
1705 return_0;
1706
1707 EMIT_PARAMS(pos, "%s %" PRIu64, originbuf, seg->rdevice_index);
1708 break;
165e4a11 1709 case SEG_SNAPSHOT:
aa6f4e51 1710 case SEG_SNAPSHOT_MERGE:
b4f1578f
AK
1711 if (!_build_dev_string(originbuf, sizeof(originbuf), seg->origin))
1712 return_0;
1713 if (!_build_dev_string(cowbuf, sizeof(cowbuf), seg->cow))
1714 return_0;
ffa9b6a5
ZK
1715 EMIT_PARAMS(pos, "%s %s %c %d", originbuf, cowbuf,
1716 seg->persistent ? 'P' : 'N', seg->chunk_size);
165e4a11
AK
1717 break;
1718 case SEG_SNAPSHOT_ORIGIN:
b4f1578f
AK
1719 if (!_build_dev_string(originbuf, sizeof(originbuf), seg->origin))
1720 return_0;
ffa9b6a5 1721 EMIT_PARAMS(pos, "%s", originbuf);
165e4a11
AK
1722 break;
1723 case SEG_STRIPED:
609faae9 1724 EMIT_PARAMS(pos, "%u %u ", seg->area_count, seg->stripe_size);
165e4a11 1725 break;
12ca060e 1726 case SEG_CRYPT:
609faae9 1727 EMIT_PARAMS(pos, "%s%s%s%s%s %s %" PRIu64 " ", seg->cipher,
12ca060e
MB
1728 seg->chainmode ? "-" : "", seg->chainmode ?: "",
1729 seg->iv ? "-" : "", seg->iv ?: "", seg->key,
1730 seg->iv_offset != DM_CRYPT_IV_DEFAULT ?
1731 seg->iv_offset : *seg_start);
1732 break;
165e4a11
AK
1733 }
1734
1735 switch(seg->type) {
1736 case SEG_ERROR:
b262f3e1 1737 case SEG_REPLICATOR:
165e4a11
AK
1738 case SEG_SNAPSHOT:
1739 case SEG_SNAPSHOT_ORIGIN:
aa6f4e51 1740 case SEG_SNAPSHOT_MERGE:
165e4a11
AK
1741 case SEG_ZERO:
1742 break;
12ca060e 1743 case SEG_CRYPT:
165e4a11 1744 case SEG_LINEAR:
b262f3e1 1745 case SEG_REPLICATOR_DEV:
165e4a11
AK
1746 case SEG_STRIPED:
1747 if ((r = _emit_areas_line(dmt, seg, params, paramsize, &pos)) <= 0) {
1748 stack;
1749 return r;
1750 }
1751 break;
1752 }
1753
4b2cae46
AK
1754 log_debug("Adding target to (%" PRIu32 ":%" PRIu32 "): %" PRIu64
1755 " %" PRIu64 " %s %s", major, minor,
165e4a11
AK
1756 *seg_start, seg->size, dm_segtypes[seg->type].target, params);
1757
b4f1578f
AK
1758 if (!dm_task_add_target(dmt, *seg_start, seg->size, dm_segtypes[seg->type].target, params))
1759 return_0;
165e4a11
AK
1760
1761 *seg_start += seg->size;
1762
1763 return 1;
1764}
1765
ffa9b6a5
ZK
1766#undef EMIT_PARAMS
1767
4b2cae46
AK
1768static int _emit_segment(struct dm_task *dmt, uint32_t major, uint32_t minor,
1769 struct load_segment *seg, uint64_t *seg_start)
165e4a11
AK
1770{
1771 char *params;
1772 size_t paramsize = 4096;
1773 int ret;
1774
1775 do {
1776 if (!(params = dm_malloc(paramsize))) {
1777 log_error("Insufficient space for target parameters.");
1778 return 0;
1779 }
1780
12ea7cb1 1781 params[0] = '\0';
4b2cae46
AK
1782 ret = _emit_segment_line(dmt, major, minor, seg, seg_start,
1783 params, paramsize);
165e4a11
AK
1784 dm_free(params);
1785
1786 if (!ret)
1787 stack;
1788
1789 if (ret >= 0)
1790 return ret;
1791
1792 log_debug("Insufficient space in params[%" PRIsize_t
1793 "] for target parameters.", paramsize);
1794
1795 paramsize *= 2;
1796 } while (paramsize < MAX_TARGET_PARAMSIZE);
1797
1798 log_error("Target parameter size too big. Aborting.");
1799 return 0;
1800}
1801
b4f1578f 1802static int _load_node(struct dm_tree_node *dnode)
165e4a11
AK
1803{
1804 int r = 0;
1805 struct dm_task *dmt;
1806 struct load_segment *seg;
df390f17 1807 uint64_t seg_start = 0, existing_table_size;
165e4a11 1808
4b2cae46
AK
1809 log_verbose("Loading %s table (%" PRIu32 ":%" PRIu32 ")", dnode->name,
1810 dnode->info.major, dnode->info.minor);
165e4a11
AK
1811
1812 if (!(dmt = dm_task_create(DM_DEVICE_RELOAD))) {
1813 log_error("Reload dm_task creation failed for %s", dnode->name);
1814 return 0;
1815 }
1816
1817 if (!dm_task_set_major(dmt, dnode->info.major) ||
1818 !dm_task_set_minor(dmt, dnode->info.minor)) {
1819 log_error("Failed to set device number for %s reload.", dnode->name);
1820 goto out;
1821 }
1822
1823 if (dnode->props.read_only && !dm_task_set_ro(dmt)) {
1824 log_error("Failed to set read only flag for %s", dnode->name);
1825 goto out;
1826 }
1827
1828 if (!dm_task_no_open_count(dmt))
1829 log_error("Failed to disable open_count");
1830
2c44337b 1831 dm_list_iterate_items(seg, &dnode->props.segs)
4b2cae46
AK
1832 if (!_emit_segment(dmt, dnode->info.major, dnode->info.minor,
1833 seg, &seg_start))
b4f1578f 1834 goto_out;
165e4a11 1835
ec289b64
AK
1836 if (!dm_task_suppress_identical_reload(dmt))
1837 log_error("Failed to suppress reload of identical tables.");
1838
1839 if ((r = dm_task_run(dmt))) {
165e4a11 1840 r = dm_task_get_info(dmt, &dnode->info);
ec289b64
AK
1841 if (r && !dnode->info.inactive_table)
1842 log_verbose("Suppressed %s identical table reload.",
1843 dnode->name);
bb875bb9 1844
df390f17 1845 existing_table_size = dm_task_get_existing_table_size(dmt);
bb875bb9 1846 if ((dnode->props.size_changed =
df390f17 1847 (existing_table_size == seg_start) ? 0 : 1)) {
bb875bb9 1848 log_debug("Table size changed from %" PRIu64 " to %"
df390f17 1849 PRIu64 " for %s", existing_table_size,
bb875bb9 1850 seg_start, dnode->name);
df390f17
AK
1851 /*
1852 * Kernel usually skips size validation on zero-length devices
1853 * now so no need to preload them.
1854 */
1855 /* FIXME In which kernel version did this begin? */
1856 if (!existing_table_size && dnode->props.delay_resume_if_new)
1857 dnode->props.size_changed = 0;
1858 }
ec289b64 1859 }
165e4a11
AK
1860
1861 dnode->props.segment_count = 0;
1862
1863out:
1864 dm_task_destroy(dmt);
1865
1866 return r;
165e4a11
AK
1867}
1868
b4f1578f 1869int dm_tree_preload_children(struct dm_tree_node *dnode,
bb875bb9
AK
1870 const char *uuid_prefix,
1871 size_t uuid_prefix_len)
165e4a11 1872{
2ca6b865 1873 int r = 1;
165e4a11 1874 void *handle = NULL;
b4f1578f 1875 struct dm_tree_node *child;
165e4a11 1876 struct dm_info newinfo;
566515c0 1877 int update_devs_flag = 0;
165e4a11
AK
1878
1879 /* Preload children first */
b4f1578f 1880 while ((child = dm_tree_next_child(&handle, dnode, 0))) {
165e4a11
AK
1881 /* Skip existing non-device-mapper devices */
1882 if (!child->info.exists && child->info.major)
1883 continue;
1884
1885 /* Ignore if it doesn't belong to this VG */
87f98002
AK
1886 if (child->info.exists &&
1887 !_uuid_prefix_matches(child->uuid, uuid_prefix, uuid_prefix_len))
165e4a11
AK
1888 continue;
1889
b4f1578f 1890 if (dm_tree_node_num_children(child, 0))
2ca6b865
MS
1891 if (!dm_tree_preload_children(child, uuid_prefix, uuid_prefix_len))
1892 return_0;
165e4a11 1893
165e4a11
AK
1894 /* FIXME Cope if name exists with no uuid? */
1895 if (!child->info.exists) {
1896 if (!_create_node(child)) {
1897 stack;
1898 return 0;
1899 }
1900 }
1901
1902 if (!child->info.inactive_table && child->props.segment_count) {
1903 if (!_load_node(child)) {
1904 stack;
1905 return 0;
1906 }
1907 }
1908
eb91c4ee
MB
1909 /* Propagate device size change change */
1910 if (child->props.size_changed)
1911 dnode->props.size_changed = 1;
1912
bb875bb9 1913 /* Resume device immediately if it has parents and its size changed */
3776c494 1914 if (!dm_tree_node_num_children(child, 1) || !child->props.size_changed)
165e4a11
AK
1915 continue;
1916
7707ea90
AK
1917 if (!child->info.inactive_table && !child->info.suspended)
1918 continue;
1919
fc795d87 1920 if (!_resume_node(child->name, child->info.major, child->info.minor,
bd90c6b2 1921 child->props.read_ahead, child->props.read_ahead_flags,
f16aea9e 1922 &newinfo, &child->dtree->cookie, child->udev_flags)) {
165e4a11 1923 log_error("Unable to resume %s (%" PRIu32
fc795d87 1924 ":%" PRIu32 ")", child->name, child->info.major,
165e4a11 1925 child->info.minor);
2ca6b865 1926 r = 0;
165e4a11
AK
1927 continue;
1928 }
1929
1930 /* Update cached info */
1931 child->info = newinfo;
566515c0
PR
1932
1933 /*
1934 * Prepare for immediate synchronization with udev and flush all stacked
1935 * dev node operations if requested by immediate_dev_node property. But
1936 * finish processing current level in the tree first.
1937 */
1938 if (child->props.immediate_dev_node)
1939 update_devs_flag = 1;
1940
165e4a11
AK
1941 }
1942
1943 handle = NULL;
1944
566515c0
PR
1945 if (update_devs_flag) {
1946 if (!dm_udev_wait(dm_tree_get_cookie(dnode)))
1947 stack;
1948 dm_tree_set_cookie(dnode, 0);
566515c0
PR
1949 }
1950
2ca6b865 1951 return r;
165e4a11
AK
1952}
1953
165e4a11
AK
1954/*
1955 * Returns 1 if unsure.
1956 */
b4f1578f 1957int dm_tree_children_use_uuid(struct dm_tree_node *dnode,
165e4a11
AK
1958 const char *uuid_prefix,
1959 size_t uuid_prefix_len)
1960{
1961 void *handle = NULL;
b4f1578f 1962 struct dm_tree_node *child = dnode;
165e4a11
AK
1963 const char *uuid;
1964
b4f1578f
AK
1965 while ((child = dm_tree_next_child(&handle, dnode, 0))) {
1966 if (!(uuid = dm_tree_node_get_uuid(child))) {
1967 log_error("Failed to get uuid for dtree node.");
165e4a11
AK
1968 return 1;
1969 }
1970
87f98002 1971 if (_uuid_prefix_matches(uuid, uuid_prefix, uuid_prefix_len))
165e4a11
AK
1972 return 1;
1973
b4f1578f
AK
1974 if (dm_tree_node_num_children(child, 0))
1975 dm_tree_children_use_uuid(child, uuid_prefix, uuid_prefix_len);
165e4a11
AK
1976 }
1977
1978 return 0;
1979}
1980
1981/*
1982 * Target functions
1983 */
b4f1578f 1984static struct load_segment *_add_segment(struct dm_tree_node *dnode, unsigned type, uint64_t size)
165e4a11
AK
1985{
1986 struct load_segment *seg;
1987
b4f1578f
AK
1988 if (!(seg = dm_pool_zalloc(dnode->dtree->mem, sizeof(*seg)))) {
1989 log_error("dtree node segment allocation failed");
165e4a11
AK
1990 return NULL;
1991 }
1992
1993 seg->type = type;
1994 seg->size = size;
1995 seg->area_count = 0;
2c44337b 1996 dm_list_init(&seg->areas);
165e4a11
AK
1997 seg->stripe_size = 0;
1998 seg->persistent = 0;
1999 seg->chunk_size = 0;
2000 seg->cow = NULL;
2001 seg->origin = NULL;
aa6f4e51 2002 seg->merge = NULL;
165e4a11 2003
2c44337b 2004 dm_list_add(&dnode->props.segs, &seg->list);
165e4a11
AK
2005 dnode->props.segment_count++;
2006
2007 return seg;
2008}
2009
b4f1578f 2010int dm_tree_node_add_snapshot_origin_target(struct dm_tree_node *dnode,
165e4a11
AK
2011 uint64_t size,
2012 const char *origin_uuid)
2013{
2014 struct load_segment *seg;
b4f1578f 2015 struct dm_tree_node *origin_node;
165e4a11 2016
b4f1578f
AK
2017 if (!(seg = _add_segment(dnode, SEG_SNAPSHOT_ORIGIN, size)))
2018 return_0;
165e4a11 2019
b4f1578f 2020 if (!(origin_node = dm_tree_find_node_by_uuid(dnode->dtree, origin_uuid))) {
165e4a11
AK
2021 log_error("Couldn't find snapshot origin uuid %s.", origin_uuid);
2022 return 0;
2023 }
2024
2025 seg->origin = origin_node;
b4f1578f
AK
2026 if (!_link_tree_nodes(dnode, origin_node))
2027 return_0;
165e4a11 2028
56c28292
AK
2029 /* Resume snapshot origins after new snapshots */
2030 dnode->activation_priority = 1;
2031
165e4a11
AK
2032 return 1;
2033}
2034
aa6f4e51
MS
2035static int _add_snapshot_target(struct dm_tree_node *node,
2036 uint64_t size,
2037 const char *origin_uuid,
2038 const char *cow_uuid,
2039 const char *merge_uuid,
2040 int persistent,
2041 uint32_t chunk_size)
165e4a11
AK
2042{
2043 struct load_segment *seg;
aa6f4e51
MS
2044 struct dm_tree_node *origin_node, *cow_node, *merge_node;
2045 unsigned seg_type;
2046
2047 seg_type = !merge_uuid ? SEG_SNAPSHOT : SEG_SNAPSHOT_MERGE;
165e4a11 2048
aa6f4e51 2049 if (!(seg = _add_segment(node, seg_type, size)))
b4f1578f 2050 return_0;
165e4a11 2051
b4f1578f 2052 if (!(origin_node = dm_tree_find_node_by_uuid(node->dtree, origin_uuid))) {
165e4a11
AK
2053 log_error("Couldn't find snapshot origin uuid %s.", origin_uuid);
2054 return 0;
2055 }
2056
2057 seg->origin = origin_node;
b4f1578f
AK
2058 if (!_link_tree_nodes(node, origin_node))
2059 return_0;
165e4a11 2060
b4f1578f 2061 if (!(cow_node = dm_tree_find_node_by_uuid(node->dtree, cow_uuid))) {
aa6f4e51 2062 log_error("Couldn't find snapshot COW device uuid %s.", cow_uuid);
165e4a11
AK
2063 return 0;
2064 }
2065
2066 seg->cow = cow_node;
b4f1578f
AK
2067 if (!_link_tree_nodes(node, cow_node))
2068 return_0;
165e4a11
AK
2069
2070 seg->persistent = persistent ? 1 : 0;
2071 seg->chunk_size = chunk_size;
2072
aa6f4e51
MS
2073 if (merge_uuid) {
2074 if (!(merge_node = dm_tree_find_node_by_uuid(node->dtree, merge_uuid))) {
2075 /* not a pure error, merging snapshot may have been deactivated */
2076 log_verbose("Couldn't find merging snapshot uuid %s.", merge_uuid);
2077 } else {
2078 seg->merge = merge_node;
2079 /* must not link merging snapshot, would undermine activation_priority below */
2080 }
2081
2082 /* Resume snapshot-merge (acting origin) after other snapshots */
2083 node->activation_priority = 1;
2084 if (seg->merge) {
2085 /* Resume merging snapshot after snapshot-merge */
2086 seg->merge->activation_priority = 2;
2087 }
2088 }
2089
165e4a11
AK
2090 return 1;
2091}
2092
aa6f4e51
MS
2093
2094int dm_tree_node_add_snapshot_target(struct dm_tree_node *node,
2095 uint64_t size,
2096 const char *origin_uuid,
2097 const char *cow_uuid,
2098 int persistent,
2099 uint32_t chunk_size)
2100{
2101 return _add_snapshot_target(node, size, origin_uuid, cow_uuid,
2102 NULL, persistent, chunk_size);
2103}
2104
2105int dm_tree_node_add_snapshot_merge_target(struct dm_tree_node *node,
2106 uint64_t size,
2107 const char *origin_uuid,
2108 const char *cow_uuid,
2109 const char *merge_uuid,
2110 uint32_t chunk_size)
2111{
2112 return _add_snapshot_target(node, size, origin_uuid, cow_uuid,
2113 merge_uuid, 1, chunk_size);
2114}
2115
b4f1578f 2116int dm_tree_node_add_error_target(struct dm_tree_node *node,
165e4a11
AK
2117 uint64_t size)
2118{
b4f1578f
AK
2119 if (!_add_segment(node, SEG_ERROR, size))
2120 return_0;
165e4a11
AK
2121
2122 return 1;
2123}
2124
b4f1578f 2125int dm_tree_node_add_zero_target(struct dm_tree_node *node,
165e4a11
AK
2126 uint64_t size)
2127{
b4f1578f
AK
2128 if (!_add_segment(node, SEG_ZERO, size))
2129 return_0;
165e4a11
AK
2130
2131 return 1;
2132}
2133
b4f1578f 2134int dm_tree_node_add_linear_target(struct dm_tree_node *node,
165e4a11
AK
2135 uint64_t size)
2136{
b4f1578f
AK
2137 if (!_add_segment(node, SEG_LINEAR, size))
2138 return_0;
165e4a11
AK
2139
2140 return 1;
2141}
2142
b4f1578f 2143int dm_tree_node_add_striped_target(struct dm_tree_node *node,
165e4a11
AK
2144 uint64_t size,
2145 uint32_t stripe_size)
2146{
2147 struct load_segment *seg;
2148
b4f1578f
AK
2149 if (!(seg = _add_segment(node, SEG_STRIPED, size)))
2150 return_0;
165e4a11
AK
2151
2152 seg->stripe_size = stripe_size;
2153
2154 return 1;
2155}
2156
12ca060e
MB
2157int dm_tree_node_add_crypt_target(struct dm_tree_node *node,
2158 uint64_t size,
2159 const char *cipher,
2160 const char *chainmode,
2161 const char *iv,
2162 uint64_t iv_offset,
2163 const char *key)
2164{
2165 struct load_segment *seg;
2166
2167 if (!(seg = _add_segment(node, SEG_CRYPT, size)))
2168 return_0;
2169
2170 seg->cipher = cipher;
2171 seg->chainmode = chainmode;
2172 seg->iv = iv;
2173 seg->iv_offset = iv_offset;
2174 seg->key = key;
2175
2176 return 1;
2177}
2178
b4f1578f 2179int dm_tree_node_add_mirror_target_log(struct dm_tree_node *node,
165e4a11 2180 uint32_t region_size,
08e64ce5 2181 unsigned clustered,
165e4a11 2182 const char *log_uuid,
ce7ed2c0
AK
2183 unsigned area_count,
2184 uint32_t flags)
165e4a11 2185{
908db078 2186 struct dm_tree_node *log_node = NULL;
165e4a11
AK
2187 struct load_segment *seg;
2188
2189 if (!node->props.segment_count) {
b8175c33 2190 log_error(INTERNAL_ERROR "Attempt to add target area to missing segment.");
165e4a11
AK
2191 return 0;
2192 }
2193
2c44337b 2194 seg = dm_list_item(dm_list_last(&node->props.segs), struct load_segment);
165e4a11 2195
24b026e3 2196 if (log_uuid) {
67b25ed4
AK
2197 if (!(seg->uuid = dm_pool_strdup(node->dtree->mem, log_uuid))) {
2198 log_error("log uuid pool_strdup failed");
2199 return 0;
2200 }
df390f17
AK
2201 if ((flags & DM_CORELOG))
2202 /* For pvmove: immediate resume (for size validation) isn't needed. */
2203 node->props.delay_resume_if_new = 1;
2204 else {
9723090c
AK
2205 if (!(log_node = dm_tree_find_node_by_uuid(node->dtree, log_uuid))) {
2206 log_error("Couldn't find mirror log uuid %s.", log_uuid);
2207 return 0;
2208 }
2209
566515c0
PR
2210 if (clustered)
2211 log_node->props.immediate_dev_node = 1;
2212
0a99713e
AK
2213 /* The kernel validates the size of disk logs. */
2214 /* FIXME Propagate to any devices below */
2215 log_node->props.delay_resume_if_new = 0;
2216
9723090c
AK
2217 if (!_link_tree_nodes(node, log_node))
2218 return_0;
2219 }
165e4a11
AK
2220 }
2221
2222 seg->log = log_node;
165e4a11
AK
2223 seg->region_size = region_size;
2224 seg->clustered = clustered;
2225 seg->mirror_area_count = area_count;
dbcb64b8 2226 seg->flags = flags;
165e4a11
AK
2227
2228 return 1;
2229}
2230
b4f1578f 2231int dm_tree_node_add_mirror_target(struct dm_tree_node *node,
165e4a11
AK
2232 uint64_t size)
2233{
cbecd3cd 2234 if (!_add_segment(node, SEG_MIRRORED, size))
b4f1578f 2235 return_0;
165e4a11
AK
2236
2237 return 1;
2238}
2239
b262f3e1
ZK
2240int dm_tree_node_add_replicator_target(struct dm_tree_node *node,
2241 uint64_t size,
2242 const char *rlog_uuid,
2243 const char *rlog_type,
2244 unsigned rsite_index,
2245 dm_replicator_mode_t mode,
2246 uint32_t async_timeout,
2247 uint64_t fall_behind_data,
2248 uint32_t fall_behind_ios)
2249{
2250 struct load_segment *rseg;
2251 struct replicator_site *rsite;
2252
2253 /* Local site0 - adds replicator segment and links rlog device */
2254 if (rsite_index == REPLICATOR_LOCAL_SITE) {
2255 if (node->props.segment_count) {
2256 log_error(INTERNAL_ERROR "Attempt to add replicator segment to already used node.");
2257 return 0;
2258 }
2259
2260 if (!(rseg = _add_segment(node, SEG_REPLICATOR, size)))
2261 return_0;
2262
2263 if (!(rseg->log = dm_tree_find_node_by_uuid(node->dtree, rlog_uuid))) {
2264 log_error("Missing replicator log uuid %s.", rlog_uuid);
2265 return 0;
2266 }
2267
2268 if (!_link_tree_nodes(node, rseg->log))
2269 return_0;
2270
2271 if (strcmp(rlog_type, "ringbuffer") != 0) {
2272 log_error("Unsupported replicator log type %s.", rlog_type);
2273 return 0;
2274 }
2275
2276 if (!(rseg->rlog_type = dm_pool_strdup(node->dtree->mem, rlog_type)))
2277 return_0;
2278
2279 dm_list_init(&rseg->rsites);
2280 rseg->rdevice_count = 0;
2281 node->activation_priority = 1;
2282 }
2283
2284 /* Add site to segment */
2285 if (mode == DM_REPLICATOR_SYNC
2286 && (async_timeout || fall_behind_ios || fall_behind_data)) {
2287 log_error("Async parameters passed for synchronnous replicator.");
2288 return 0;
2289 }
2290
2291 if (node->props.segment_count != 1) {
2292 log_error(INTERNAL_ERROR "Attempt to add remote site area before setting replicator log.");
2293 return 0;
2294 }
2295
2296 rseg = dm_list_item(dm_list_last(&node->props.segs), struct load_segment);
2297 if (rseg->type != SEG_REPLICATOR) {
2298 log_error(INTERNAL_ERROR "Attempt to use non replicator segment %s.",
2299 dm_segtypes[rseg->type].target);
2300 return 0;
2301 }
2302
2303 if (!(rsite = dm_pool_zalloc(node->dtree->mem, sizeof(*rsite)))) {
2304 log_error("Failed to allocate remote site segment.");
2305 return 0;
2306 }
2307
2308 dm_list_add(&rseg->rsites, &rsite->list);
2309 rseg->rsite_count++;
2310
2311 rsite->mode = mode;
2312 rsite->async_timeout = async_timeout;
2313 rsite->fall_behind_data = fall_behind_data;
2314 rsite->fall_behind_ios = fall_behind_ios;
2315 rsite->rsite_index = rsite_index;
2316
2317 return 1;
2318}
2319
2320/* Appends device node to Replicator */
2321int dm_tree_node_add_replicator_dev_target(struct dm_tree_node *node,
2322 uint64_t size,
2323 const char *replicator_uuid,
2324 uint64_t rdevice_index,
2325 const char *rdev_uuid,
2326 unsigned rsite_index,
2327 const char *slog_uuid,
2328 uint32_t slog_flags,
2329 uint32_t slog_region_size)
2330{
2331 struct seg_area *area;
2332 struct load_segment *rseg;
2333 struct load_segment *rep_seg;
2334
2335 if (rsite_index == REPLICATOR_LOCAL_SITE) {
2336 /* Site index for local target */
2337 if (!(rseg = _add_segment(node, SEG_REPLICATOR_DEV, size)))
2338 return_0;
2339
2340 if (!(rseg->replicator = dm_tree_find_node_by_uuid(node->dtree, replicator_uuid))) {
2341 log_error("Missing replicator uuid %s.", replicator_uuid);
2342 return 0;
2343 }
2344
2345 /* Local slink0 for replicator must be always initialized first */
2346 if (rseg->replicator->props.segment_count != 1) {
2347 log_error(INTERNAL_ERROR "Attempt to use non replicator segment.");
2348 return 0;
2349 }
2350
2351 rep_seg = dm_list_item(dm_list_last(&rseg->replicator->props.segs), struct load_segment);
2352 if (rep_seg->type != SEG_REPLICATOR) {
2353 log_error(INTERNAL_ERROR "Attempt to use non replicator segment %s.",
2354 dm_segtypes[rep_seg->type].target);
2355 return 0;
2356 }
2357 rep_seg->rdevice_count++;
2358
2359 if (!_link_tree_nodes(node, rseg->replicator))
2360 return_0;
2361
2362 rseg->rdevice_index = rdevice_index;
2363 } else {
2364 /* Local slink0 for replicator must be always initialized first */
2365 if (node->props.segment_count != 1) {
2366 log_error(INTERNAL_ERROR "Attempt to use non replicator-dev segment.");
2367 return 0;
2368 }
2369
2370 rseg = dm_list_item(dm_list_last(&node->props.segs), struct load_segment);
2371 if (rseg->type != SEG_REPLICATOR_DEV) {
2372 log_error(INTERNAL_ERROR "Attempt to use non replicator-dev segment %s.",
2373 dm_segtypes[rseg->type].target);
2374 return 0;
2375 }
2376 }
2377
2378 if (!(slog_flags & DM_CORELOG) && !slog_uuid) {
2379 log_error("Unspecified sync log uuid.");
2380 return 0;
2381 }
2382
2383 if (!dm_tree_node_add_target_area(node, NULL, rdev_uuid, 0))
2384 return_0;
2385
2386 area = dm_list_item(dm_list_last(&rseg->areas), struct seg_area);
2387
2388 if (!(slog_flags & DM_CORELOG)) {
2389 if (!(area->slog = dm_tree_find_node_by_uuid(node->dtree, slog_uuid))) {
2390 log_error("Couldn't find sync log uuid %s.", slog_uuid);
2391 return 0;
2392 }
2393
2394 if (!_link_tree_nodes(node, area->slog))
2395 return_0;
2396 }
2397
2398 area->flags = slog_flags;
2399 area->region_size = slog_region_size;
2400 area->rsite_index = rsite_index;
2401
2402 return 1;
2403}
2404
b4f1578f 2405static int _add_area(struct dm_tree_node *node, struct load_segment *seg, struct dm_tree_node *dev_node, uint64_t offset)
165e4a11
AK
2406{
2407 struct seg_area *area;
2408
b4f1578f 2409 if (!(area = dm_pool_zalloc(node->dtree->mem, sizeof (*area)))) {
165e4a11
AK
2410 log_error("Failed to allocate target segment area.");
2411 return 0;
2412 }
2413
2414 area->dev_node = dev_node;
2415 area->offset = offset;
2416
2c44337b 2417 dm_list_add(&seg->areas, &area->list);
165e4a11
AK
2418 seg->area_count++;
2419
2420 return 1;
2421}
2422
b4f1578f 2423int dm_tree_node_add_target_area(struct dm_tree_node *node,
165e4a11
AK
2424 const char *dev_name,
2425 const char *uuid,
2426 uint64_t offset)
2427{
2428 struct load_segment *seg;
2429 struct stat info;
b4f1578f 2430 struct dm_tree_node *dev_node;
165e4a11
AK
2431
2432 if ((!dev_name || !*dev_name) && (!uuid || !*uuid)) {
b4f1578f 2433 log_error("dm_tree_node_add_target_area called without device");
165e4a11
AK
2434 return 0;
2435 }
2436
2437 if (uuid) {
b4f1578f 2438 if (!(dev_node = dm_tree_find_node_by_uuid(node->dtree, uuid))) {
165e4a11
AK
2439 log_error("Couldn't find area uuid %s.", uuid);
2440 return 0;
2441 }
b4f1578f
AK
2442 if (!_link_tree_nodes(node, dev_node))
2443 return_0;
165e4a11
AK
2444 } else {
2445 if (stat(dev_name, &info) < 0) {
2446 log_error("Device %s not found.", dev_name);
2447 return 0;
2448 }
2449
2450 if (!S_ISBLK(info.st_mode)) {
2451 log_error("Device %s is not a block device.", dev_name);
2452 return 0;
2453 }
2454
2455 /* FIXME Check correct macro use */
cda69e17
PR
2456 if (!(dev_node = _add_dev(node->dtree, node, MAJOR(info.st_rdev),
2457 MINOR(info.st_rdev), 0)))
b4f1578f 2458 return_0;
165e4a11
AK
2459 }
2460
2461 if (!node->props.segment_count) {
b8175c33 2462 log_error(INTERNAL_ERROR "Attempt to add target area to missing segment.");
165e4a11
AK
2463 return 0;
2464 }
2465
2c44337b 2466 seg = dm_list_item(dm_list_last(&node->props.segs), struct load_segment);
165e4a11 2467
b4f1578f
AK
2468 if (!_add_area(node, seg, dev_node, offset))
2469 return_0;
165e4a11
AK
2470
2471 return 1;
db208f51 2472}
bd90c6b2
AK
2473
2474void dm_tree_set_cookie(struct dm_tree_node *node, uint32_t cookie)
2475{
2476 node->dtree->cookie = cookie;
2477}
2478
2479uint32_t dm_tree_get_cookie(struct dm_tree_node *node)
2480{
2481 return node->dtree->cookie;
2482}
This page took 0.361907 seconds and 5 git commands to generate.