1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-26 03:22:12 +03:00

rename deptree

This commit is contained in:
Alasdair Kergon 2005-11-09 14:10:50 +00:00
parent ad6b0ebb73
commit b4f1578fc2
5 changed files with 364 additions and 398 deletions

View File

@ -1,5 +1,7 @@
Version 1.02.00 - Version 1.02.00 -
============================= =============================
Added activation functions to library.
Added return macros.
Also suppress error if device doesn't exist with DM_DEVICE_STATUS. Also suppress error if device doesn't exist with DM_DEVICE_STATUS.
Export dm_set_selinux_context(). Export dm_set_selinux_context().
Add dm_driver_version(). Add dm_driver_version().

View File

@ -30,34 +30,34 @@ dm_get_next_target
dm_set_dev_dir dm_set_dev_dir
dm_dir dm_dir
dm_format_dev dm_format_dev
dm_deptree_create dm_tree_create
dm_deptree_free dm_tree_free
dm_deptree_add_dev dm_tree_add_dev
dm_deptree_add_new_dev dm_tree_add_new_dev
dm_deptree_node_get_name dm_tree_node_get_name
dm_deptree_node_get_uuid dm_tree_node_get_uuid
dm_deptree_node_get_info dm_tree_node_get_info
dm_deptree_node_get_context dm_tree_node_get_context
dm_deptree_node_num_children dm_tree_node_num_children
dm_deptree_node_num_parents dm_tree_node_num_parents
dm_deptree_find_node dm_tree_find_node
dm_deptree_find_node_by_uuid dm_tree_find_node_by_uuid
dm_deptree_next_child dm_tree_next_child
dm_deptree_next_parent dm_tree_next_parent
dm_deptree_deactivate_children dm_tree_deactivate_children
dm_deptree_activate_children dm_tree_activate_children
dm_deptree_preload_children dm_tree_preload_children
dm_deptree_suspend_children dm_tree_suspend_children
dm_deptree_children_use_uuid dm_tree_children_use_uuid
dm_deptree_node_add_snapshot_origin_target dm_tree_node_add_snapshot_origin_target
dm_deptree_node_add_snapshot_target dm_tree_node_add_snapshot_target
dm_deptree_node_add_error_target dm_tree_node_add_error_target
dm_deptree_node_add_zero_target dm_tree_node_add_zero_target
dm_deptree_node_add_linear_target dm_tree_node_add_linear_target
dm_deptree_node_add_striped_target dm_tree_node_add_striped_target
dm_deptree_node_add_mirror_target dm_tree_node_add_mirror_target
dm_deptree_node_add_mirror_target_log dm_tree_node_add_mirror_target_log
dm_deptree_node_add_target_area dm_tree_node_add_target_area
dm_is_dm_major dm_is_dm_major
dm_mknodes dm_mknodes
dm_malloc_aux dm_malloc_aux

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved. * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
* *
* This file is part of the device-mapper userspace tools. * This file is part of the device-mapper userspace tools.
* *
@ -27,6 +27,11 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
/*****************************************************************
* The first section of this file provides direct access to the
* individual device-mapper ioctls.
****************************************************************/
/* /*
* Since it is quite laborious to build the ioctl * Since it is quite laborious to build the ioctl
* arguments for the device-mapper people are * arguments for the device-mapper people are
@ -180,21 +185,17 @@ int dm_is_dm_major(uint32_t major);
void dm_lib_release(void); void dm_lib_release(void);
void dm_lib_exit(void) __attribute((destructor)); void dm_lib_exit(void) __attribute((destructor));
/***********************************************************************
* Wrappers
***********************************************************************/
/* /*
* Use NULL for all devices. * Use NULL for all devices.
*/ */
int dm_mknodes(const char *name); int dm_mknodes(const char *name);
int dm_driver_version(char *version, size_t size); int dm_driver_version(char *version, size_t size);
/***************************** /******************************************************
* Dependency tree functions * * Functions to build and manipulate trees of devices *
*****************************/ ******************************************************/
struct deptree; struct dm_tree;
struct deptree_node; struct dm_tree_node;
/* /*
* Initialise an empty dependency tree. * Initialise an empty dependency tree.
@ -207,18 +208,18 @@ struct deptree_node;
* The root node is the parent/child of every node that doesn't have other * The root node is the parent/child of every node that doesn't have other
* parents/children. * parents/children.
*/ */
struct deptree *dm_deptree_create(void); struct dm_tree *dm_tree_create(void);
void dm_deptree_free(struct deptree *deptree); void dm_tree_free(struct dm_tree *tree);
/* /*
* Add nodes to the tree for a given device and all the devices it uses. * Add nodes to the tree for a given device and all the devices it uses.
*/ */
int dm_deptree_add_dev(struct deptree *deptree, uint32_t major, uint32_t minor); int dm_tree_add_dev(struct dm_tree *tree, uint32_t major, uint32_t minor);
/* /*
* Add a new node to the tree if it doesn't already exist. * Add a new node to the tree if it doesn't already exist.
*/ */
struct deptree_node *dm_deptree_add_new_dev(struct deptree *deptree, struct dm_tree_node *dm_tree_add_new_dev(struct dm_tree *tree,
const char *name, const char *name,
const char *uuid, const char *uuid,
uint32_t major, uint32_t minor, uint32_t major, uint32_t minor,
@ -230,10 +231,10 @@ struct deptree_node *dm_deptree_add_new_dev(struct deptree *deptree,
* Search for a node in the tree. * Search for a node in the tree.
* Set major and minor to 0 or uuid to NULL to get the root node. * Set major and minor to 0 or uuid to NULL to get the root node.
*/ */
struct deptree_node *dm_deptree_find_node(struct deptree *deptree, struct dm_tree_node *dm_tree_find_node(struct dm_tree *tree,
uint32_t major, uint32_t major,
uint32_t minor); uint32_t minor);
struct deptree_node *dm_deptree_find_node_by_uuid(struct deptree *deptree, struct dm_tree_node *dm_tree_find_node_by_uuid(struct dm_tree *tree,
const char *uuid); const char *uuid);
/* /*
@ -242,36 +243,36 @@ struct deptree_node *dm_deptree_find_node_by_uuid(struct deptree *deptree,
* Returns NULL after the last child. * Returns NULL after the last child.
* Set inverted to use inverted tree. * Set inverted to use inverted tree.
*/ */
struct deptree_node *dm_deptree_next_child(void **handle, struct dm_tree_node *dm_tree_next_child(void **handle,
struct deptree_node *parent, struct dm_tree_node *parent,
uint32_t inverted); uint32_t inverted);
/* /*
* Get properties of a node. * Get properties of a node.
*/ */
const char *dm_deptree_node_get_name(struct deptree_node *node); const char *dm_tree_node_get_name(struct dm_tree_node *node);
const char *dm_deptree_node_get_uuid(struct deptree_node *node); const char *dm_tree_node_get_uuid(struct dm_tree_node *node);
const struct dm_info *dm_deptree_node_get_info(struct deptree_node *node); const struct dm_info *dm_tree_node_get_info(struct dm_tree_node *node);
void *dm_deptree_node_get_context(struct deptree_node *node); void *dm_tree_node_get_context(struct dm_tree_node *node);
/* /*
* Returns the number of children of the given node (excluding the root node). * Returns the number of children of the given node (excluding the root node).
* Set inverted for the number of parents. * Set inverted for the number of parents.
*/ */
int dm_deptree_node_num_children(struct deptree_node *node, uint32_t inverted); int dm_tree_node_num_children(struct dm_tree_node *node, uint32_t inverted);
/* /*
* Deactivate a device plus all dependencies. * Deactivate a device plus all dependencies.
* Ignores devices that don't have a uuid starting with uuid_prefix. * Ignores devices that don't have a uuid starting with uuid_prefix.
*/ */
int dm_deptree_deactivate_children(struct deptree_node *dnode, int dm_tree_deactivate_children(struct dm_tree_node *dnode,
const char *uuid_prefix, const char *uuid_prefix,
size_t uuid_prefix_len); size_t uuid_prefix_len);
/* /*
* Preload/create a device plus all dependencies. * Preload/create a device plus all dependencies.
* Ignores devices that don't have a uuid starting with uuid_prefix. * Ignores devices that don't have a uuid starting with uuid_prefix.
*/ */
int dm_deptree_preload_children(struct deptree_node *dnode, int dm_tree_preload_children(struct dm_tree_node *dnode,
const char *uuid_prefix, const char *uuid_prefix,
size_t uuid_prefix_len); size_t uuid_prefix_len);
@ -279,7 +280,7 @@ int dm_deptree_preload_children(struct deptree_node *dnode,
* Resume a device plus all dependencies. * Resume a device plus all dependencies.
* Ignores devices that don't have a uuid starting with uuid_prefix. * Ignores devices that don't have a uuid starting with uuid_prefix.
*/ */
int dm_deptree_activate_children(struct deptree_node *dnode, int dm_tree_activate_children(struct dm_tree_node *dnode,
const char *uuid_prefix, const char *uuid_prefix,
size_t uuid_prefix_len); size_t uuid_prefix_len);
@ -287,7 +288,7 @@ int dm_deptree_activate_children(struct deptree_node *dnode,
* Suspend a device plus all dependencies. * Suspend a device plus all dependencies.
* Ignores devices that don't have a uuid starting with uuid_prefix. * Ignores devices that don't have a uuid starting with uuid_prefix.
*/ */
int dm_deptree_suspend_children(struct deptree_node *dnode, int dm_tree_suspend_children(struct dm_tree_node *dnode,
const char *uuid_prefix, const char *uuid_prefix,
size_t uuid_prefix_len); size_t uuid_prefix_len);
@ -296,39 +297,39 @@ int dm_deptree_suspend_children(struct deptree_node *dnode,
* Only returns 0 if every node was checked successfully. * Only returns 0 if every node was checked successfully.
* Returns 1 if the tree walk has to be aborted. * Returns 1 if the tree walk has to be aborted.
*/ */
int dm_deptree_children_use_uuid(struct deptree_node *dnode, int dm_tree_children_use_uuid(struct dm_tree_node *dnode,
const char *uuid_prefix, const char *uuid_prefix,
size_t uuid_prefix_len); size_t uuid_prefix_len);
/* /*
* Construct tables for new nodes. * Construct tables for new nodes before activating them.
*/ */
int dm_deptree_node_add_snapshot_origin_target(struct deptree_node *dnode, int dm_tree_node_add_snapshot_origin_target(struct dm_tree_node *dnode,
uint64_t size, uint64_t size,
const char *origin_uuid); const char *origin_uuid);
int dm_deptree_node_add_snapshot_target(struct deptree_node *node, int dm_tree_node_add_snapshot_target(struct dm_tree_node *node,
uint64_t size, uint64_t size,
const char *origin_uuid, const char *origin_uuid,
const char *cow_uuid, const char *cow_uuid,
int persistent, int persistent,
uint32_t chunk_size); uint32_t chunk_size);
int dm_deptree_node_add_error_target(struct deptree_node *node, int dm_tree_node_add_error_target(struct dm_tree_node *node,
uint64_t size); uint64_t size);
int dm_deptree_node_add_zero_target(struct deptree_node *node, int dm_tree_node_add_zero_target(struct dm_tree_node *node,
uint64_t size); uint64_t size);
int dm_deptree_node_add_linear_target(struct deptree_node *node, int dm_tree_node_add_linear_target(struct dm_tree_node *node,
uint64_t size); uint64_t size);
int dm_deptree_node_add_striped_target(struct deptree_node *node, int dm_tree_node_add_striped_target(struct dm_tree_node *node,
uint64_t size, uint64_t size,
uint32_t stripe_size); uint32_t stripe_size);
int dm_deptree_node_add_mirror_target(struct deptree_node *node, int dm_tree_node_add_mirror_target(struct dm_tree_node *node,
uint64_t size); uint64_t size);
int dm_deptree_node_add_mirror_target_log(struct deptree_node *node, int dm_tree_node_add_mirror_target_log(struct dm_tree_node *node,
uint32_t region_size, uint32_t region_size,
unsigned clustered, unsigned clustered,
const char *log_uuid, const char *log_uuid,
unsigned area_count); unsigned area_count);
int dm_deptree_node_add_target_area(struct deptree_node *node, int dm_tree_node_add_target_area(struct dm_tree_node *node,
const char *dev_name, const char *dev_name,
const char *dlid, const char *dlid,
uint64_t offset); uint64_t offset);
@ -337,6 +338,10 @@ int dm_deptree_node_add_target_area(struct deptree_node *node,
* Library functions * Library functions
*****************************************************************************/ *****************************************************************************/
/*******************
* Memory management
*******************/
void *dm_malloc_aux(size_t s, const char *file, int line); void *dm_malloc_aux(size_t s, const char *file, int line);
#define dm_malloc(s) dm_malloc_aux((s), __FILE__, __LINE__) #define dm_malloc(s) dm_malloc_aux((s), __FILE__, __LINE__)
@ -361,10 +366,6 @@ void dm_bounds_check(void);
#endif #endif
/******************
* pool functions
******************/
/* /*
* The pool allocator is useful when you are going to allocate * The pool allocator is useful when you are going to allocate
* lots of memory, use the memory for a bit, and then free the * lots of memory, use the memory for a bit, and then free the
@ -533,7 +534,7 @@ struct dm_hash_node *dm_hash_get_next(struct dm_hash_table *t, struct dm_hash_no
#endif /* LIB_DEVICE_MAPPER_H */ #endif /* LIB_DEVICE_MAPPER_H */
/* /*********
* selinux * selinux
*/ *********/
int dm_set_selinux_context(const char *path, mode_t mode); int dm_set_selinux_context(const char *path, mode_t mode);

File diff suppressed because it is too large Load Diff

View File

@ -107,7 +107,7 @@ static char *_uuid;
static char *_fields; static char *_fields;
static char *_target; static char *_target;
static char *_command; static char *_command;
static struct deptree *_dtree; static struct dm_tree *_dtree;
/* /*
* Commands * Commands
@ -1107,14 +1107,14 @@ static void _out_prefix(int depth)
/* /*
* Display tree * Display tree
*/ */
static void _display_tree_attributes(struct deptree_node *node) static void _display_tree_attributes(struct dm_tree_node *node)
{ {
int attr = 0; int attr = 0;
const char *uuid; const char *uuid;
const struct dm_info *info; const struct dm_info *info;
uuid = dm_deptree_node_get_uuid(node); uuid = dm_tree_node_get_uuid(node);
info = dm_deptree_node_get_info(node); info = dm_tree_node_get_info(node);
if (!info->exists) if (!info->exists)
return; return;
@ -1143,7 +1143,7 @@ static void _display_tree_attributes(struct deptree_node *node)
_out_char(']'); _out_char(']');
} }
static void _display_tree_node(struct deptree_node *node, unsigned depth, static void _display_tree_node(struct dm_tree_node *node, unsigned depth,
unsigned first_child, unsigned last_child, unsigned first_child, unsigned last_child,
unsigned has_children) unsigned has_children)
{ {
@ -1156,7 +1156,7 @@ static void _display_tree_node(struct deptree_node *node, unsigned depth,
if (depth + 2 > MAX_DEPTH) if (depth + 2 > MAX_DEPTH)
return; return;
name = dm_deptree_node_get_name(node); name = dm_tree_node_get_name(node);
if ((!name || !*name) && !_tree_switches[TR_DEVICE]) if ((!name || !*name) && !_tree_switches[TR_DEVICE])
return; return;
@ -1181,7 +1181,7 @@ static void _display_tree_node(struct deptree_node *node, unsigned depth,
if (name) if (name)
_out_string(name); _out_string(name);
info = dm_deptree_node_get_info(node); info = dm_tree_node_get_info(node);
if (_tree_switches[TR_DEVICE]) { if (_tree_switches[TR_DEVICE]) {
_out_string(name ? " (" : "("); _out_string(name ? " (" : "(");
@ -1210,20 +1210,20 @@ static void _display_tree_node(struct deptree_node *node, unsigned depth,
/* /*
* Walk the dependency tree * Walk the dependency tree
*/ */
static void _tree_walk_children(struct deptree_node *node, unsigned depth) static void _tree_walk_children(struct dm_tree_node *node, unsigned depth)
{ {
struct deptree_node *child, *next_child; struct dm_tree_node *child, *next_child;
void *handle = NULL; void *handle = NULL;
uint32_t inverted = _tree_switches[TR_BOTTOMUP]; uint32_t inverted = _tree_switches[TR_BOTTOMUP];
unsigned first_child = 1; unsigned first_child = 1;
unsigned has_children; unsigned has_children;
next_child = dm_deptree_next_child(&handle, node, inverted); next_child = dm_tree_next_child(&handle, node, inverted);
while ((child = next_child)) { while ((child = next_child)) {
next_child = dm_deptree_next_child(&handle, node, inverted); next_child = dm_tree_next_child(&handle, node, inverted);
has_children = has_children =
dm_deptree_node_num_children(child, inverted) ? 1 : 0; dm_tree_node_num_children(child, inverted) ? 1 : 0;
_display_tree_node(child, depth, first_child, _display_tree_node(child, depth, first_child,
next_child ? 0 : 1, has_children); next_child ? 0 : 1, has_children);
@ -1239,7 +1239,7 @@ static int _add_dep(int argc, char **argv, void *data)
{ {
struct dm_names *names = (struct dm_names *) data; struct dm_names *names = (struct dm_names *) data;
if (!dm_deptree_add_dev(_dtree, MAJOR(names->dev), MINOR(names->dev))) if (!dm_tree_add_dev(_dtree, MAJOR(names->dev), MINOR(names->dev)))
return 0; return 0;
return 1; return 1;
@ -1250,15 +1250,15 @@ static int _add_dep(int argc, char **argv, void *data)
*/ */
static int _tree(int argc, char **argv, void *data) static int _tree(int argc, char **argv, void *data)
{ {
if (!(_dtree = dm_deptree_create())) if (!(_dtree = dm_tree_create()))
return 0; return 0;
if (!_process_all(argc, argv, _add_dep)) if (!_process_all(argc, argv, _add_dep))
return 0; return 0;
_tree_walk_children(dm_deptree_find_node(_dtree, 0, 0), 0); _tree_walk_children(dm_tree_find_node(_dtree, 0, 0), 0);
dm_deptree_free(_dtree); dm_tree_free(_dtree);
return 1; return 1;
} }