From patchwork Mon Nov 2 14:20:11 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zdenek Kabelac X-Patchwork-Id: 57025 Received: from hormel.redhat.com (hormel1.redhat.com [209.132.177.33]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nA2EKlOf029902 for ; Mon, 2 Nov 2009 14:20:49 GMT Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com [10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 7FDA1619D88; Mon, 2 Nov 2009 09:20:40 -0500 (EST) Received: from int-mx04.intmail.prod.int.phx2.redhat.com (nat-pool.util.phx.redhat.com [10.8.5.200]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP id nA2EKaRe012327 for ; Mon, 2 Nov 2009 09:20:36 -0500 Received: from dhcp-0-185.brq.redhat.com (dhcp-0-185.brq.redhat.com [10.34.0.185]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nA2EKYBi028669 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 2 Nov 2009 09:20:35 -0500 Received: from dhcp-0-185.brq.redhat.com (dhcp-0-185.brq.redhat.com [127.0.0.1]) by dhcp-0-185.brq.redhat.com (8.14.3/8.14.3) with ESMTP id nA2EKXHo008469; Mon, 2 Nov 2009 15:20:33 +0100 Received: (from kabi@localhost) by dhcp-0-185.brq.redhat.com (8.14.3/8.14.3/Submit) id nA2EKXkk008468; Mon, 2 Nov 2009 15:20:33 +0100 From: Zdenek Kabelac To: dm-devel@redhat.com Date: Mon, 2 Nov 2009 15:20:11 +0100 Message-Id: <1257171622-8380-8-git-send-email-zkabelac@redhat.com> In-Reply-To: <1257171622-8380-7-git-send-email-zkabelac@redhat.com> References: <1257171622-8380-1-git-send-email-zkabelac@redhat.com> <1257171622-8380-2-git-send-email-zkabelac@redhat.com> <1257171622-8380-3-git-send-email-zkabelac@redhat.com> <1257171622-8380-4-git-send-email-zkabelac@redhat.com> <1257171622-8380-5-git-send-email-zkabelac@redhat.com> <1257171622-8380-6-git-send-email-zkabelac@redhat.com> <1257171622-8380-7-git-send-email-zkabelac@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-loop: dm-devel@redhat.com Cc: Zdenek Kabelac Subject: [dm-devel] [PATCH 07/18] Replicator: suspend/deactivate replicator X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.5 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com diff --git a/libdm/.exported_symbols b/libdm/.exported_symbols index 7b5e3f0..3217e03 100644 --- a/libdm/.exported_symbols +++ b/libdm/.exported_symbols @@ -79,6 +79,7 @@ dm_tree_node_add_mirror_target_log dm_tree_node_add_target_area dm_tree_node_add_replicator_target dm_tree_node_add_replicator_dev_target +dm_tree_set_replicator_suspend dm_tree_node_set_read_ahead dm_tree_skip_lockfs dm_tree_use_no_flush_suspend diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index f96aed3..66ce055 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -457,6 +457,8 @@ int dm_tree_node_add_replicator_dev_target(struct dm_tree_node *node, uint32_t slog_flags, /* Mirror log flags */ uint32_t slog_size); +int dm_tree_set_replicator_suspend(struct dm_tree *dtree, const char *uuid); + int dm_tree_node_add_target_area(struct dm_tree_node *node, const char *dev_name, const char *dlid, diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c index 0ba4e7e..652b9e8 100644 --- a/libdm/libdm-deptree.c +++ b/libdm/libdm-deptree.c @@ -157,6 +157,7 @@ struct dm_tree_node { struct dm_list used_by; /* Nodes that use this node */ int activation_priority; /* 0 gets activated first */ + int replicator_suspend; /* 1 gets suspend first */ uint16_t udev_flags; /* Udev control flags */ @@ -678,6 +679,18 @@ void dm_tree_node_set_read_ahead(struct dm_tree_node *dnode, dnode->props.read_ahead_flags = read_ahead_flags; } +int dm_tree_set_replicator_suspend(struct dm_tree *dtree, const char *uuid) +{ + struct dm_tree_node *dnode; + + if ((dnode = dm_tree_find_node_by_uuid(dtree, uuid))) { + log_verbose("Setting replicator suspend for %s", dnode->name); + dnode->replicator_suspend = 1; + } + + return 1; +} + int dm_tree_add_dev(struct dm_tree *dtree, uint32_t major, uint32_t minor) { return _add_dev(dtree, &dtree->root, major, minor) ? 1 : 0; @@ -1030,6 +1043,53 @@ static int _suspend_node(const char *name, uint32_t major, uint32_t minor, return r; } +static int _suspend_replicator_parent(struct dm_tree_node *dnode, + const char *uuid_prefix, + size_t uuid_prefix_len) +{ + struct dm_info info; + const struct dm_info *dinfo; + const char *name; + const char *uuid; + struct dm_tree_link *dlink; + + dm_list_iterate_items(dlink, &dnode->uses) { + if (!dlink->node->replicator_suspend) + continue; + + if (!(uuid = dm_tree_node_get_uuid(dlink->node))) { + stack; + continue; + } + /* Ignore if it doesn't belong to this VG */ + if (!_uuid_prefix_matches(uuid, uuid_prefix, uuid_prefix_len)) + continue; + + if (!(dinfo = dm_tree_node_get_info(dlink->node))) { + stack; + continue; + } + + if (dinfo->suspended) + continue; + + if (!(name = dm_tree_node_get_name(dlink->node))) { + stack; + continue; + } + + if (!_suspend_node(name, dinfo->major, dinfo->minor, + 1, 1, &info)) { + log_error("Unable to suspend %s (%" PRIu32 + ":%" PRIu32 ")", name, dinfo->major, + dinfo->minor); + return 0; + } + } + + return 1; +} + int dm_tree_deactivate_children(struct dm_tree_node *dnode, const char *uuid_prefix, size_t uuid_prefix_len) @@ -1066,6 +1126,9 @@ int dm_tree_deactivate_children(struct dm_tree_node *dnode, !info.exists || info.open_count) continue; + if (!_suspend_replicator_parent(child, uuid_prefix, uuid_prefix_len)) + continue; + if (!_deactivate_node(name, info.major, info.minor, &dnode->dtree->cookie, dnode->udev_flags)) { log_error("Unable to deactivate %s (%" PRIu32