Skip to contentSkip to conversation

Replicator: export out_ function for modules

PATCH New Zdenek Kabelac 3 participants 23 messages Oct 5, 2009 – Oct 9, 2009 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/13 Replicator: export out_ function for modules

Exporting functions out_inc_indent(), out_dec_indent(), out_newline() for creating indented metadata lines.

---
 lib/format_text/export.c      |   19 +++++++++++++++++++
 lib/format_text/text_export.h |    4 ++++
 2 files changed, 23 insertions(+), 0 deletions(-)
lib/format_text/export.c +19 -0
index 482eea9..49cf785 100644
@@ -235,6 +235,25 @@ static int _sectors_to_units(uint64_t sectors, char *buffer, size_t s)
 	return dm_snprintf(buffer, s, "# %g %s", d, _units[i]) > 0;
 }
 
+/* increment indention level */
+void out_inc_indent(struct formatter *f)
+{
+	_inc_indent(f);
+}
+
+/* decrement indention level */
+void out_dec_indent(struct formatter *f)
+{
+	_dec_indent(f);
+}
+
+/* insert new line */
+int out_newline(struct formatter *f)
+{
+	outnl(f);
+	return 0;
+}
+
 /*
  * Appends a comment giving a size in more easily
  * readable form (eg, 4M instead of 8096).
lib/format_text/text_export.h +4 -0
index 2f2b531..12a8691 100644
@@ -34,4 +34,8 @@ int out_text(struct formatter *f, const char *fmt, ...)
 int out_areas(struct formatter *f, const struct lv_segment *seg,
 	      const char *type);
 
+void out_inc_indent(struct formatter *f);
+void out_dec_indent(struct formatter *f);
+int out_newline(struct formatter *f);
+
 #endif
Signature · 1 line
1.6.5.rc2
#1 lore raw

PATCH 2/13 Replicator: add libdm support

Introducing dm_tree_node_add_replicator_target() and dm_tree_node_add_replicator_dev_target()

Modifing API dm_tree_suspend_children() to support prioritized suspend and update lvm activation.

Avoid preloading childrens with nonzero activation priority

---
 lib/activate/dev_manager.c |    2 +-
 libdm/.exported_symbols    |    3 +
 libdm/libdevmapper.h       |   34 +++++-
 libdm/libdm-deptree.c      |  296 ++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 323 insertions(+), 12 deletions(-)
lib/activate/dev_manager.c +1 -1
index 13cec36..19deab8 100644
@@ -1221,7 +1221,7 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv, actio
 		if (!dm->flush_required && (lv->status & MIRRORED) && !(lv->status & PVMOVE))
 			dm_tree_use_no_flush_suspend(root);
 	case SUSPEND_WITH_LOCKFS:
-		if (!dm_tree_suspend_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1))
+		if (!dm_tree_suspend_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1, 0))
 			goto_out;
 		break;
 	case PRELOAD:
libdm/.exported_symbols +3 -0
index c357131..5fd81ec 100644
@@ -64,6 +64,7 @@ dm_tree_next_parent
 dm_tree_deactivate_children
 dm_tree_activate_children
 dm_tree_preload_children
+dm_tree_set_priority
 dm_tree_suspend_children
 dm_tree_children_use_uuid
 dm_tree_node_add_snapshot_origin_target
@@ -76,6 +77,8 @@ dm_tree_node_add_crypt_target
 dm_tree_node_add_mirror_target
 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_node_set_read_ahead
 dm_tree_skip_lockfs
 dm_tree_use_no_flush_suspend
libdm/libdevmapper.h +32 -2
index 204372a..4e0103a 100644
@@ -341,8 +341,9 @@ int dm_tree_activate_children(struct dm_tree_node *dnode,
  * Ignores devices that don't have a uuid starting with uuid_prefix.
  */
 int dm_tree_suspend_children(struct dm_tree_node *dnode,
-				   const char *uuid_prefix,
-				   size_t uuid_prefix_len);
+			     const char *uuid_prefix,
+			     size_t uuid_prefix_len,
+			     int priority);
 
 /*
  * Skip the filesystem sync when suspending.
@@ -421,11 +422,40 @@ int dm_tree_node_add_mirror_target_log(struct dm_tree_node *node,
 					  const char *log_uuid,
 					  unsigned area_count,
 					  uint32_t flags);
+
+int dm_tree_node_add_replicator_target(struct dm_tree_node *node,
+				       uint64_t size,
+				       const char *rlog_uuid,
+				       const char *rlog_type,
+				       unsigned site_index,
+				       int async_action,
+/* Replicator async action flags */
+#define DM_REPLICATOR_SYNC	0		/* use synchronous replication */
+#define DM_REPLICATOR_WARN	1		/* warn if replicator is slow */
+#define DM_REPLICATOR_STALL	2		/* stall replicator if not fast enough */
+#define DM_REPLICATOR_DROP	3		/* drop legs */
+#define DM_REPLICATOR_FAIL	4		/* fail replicator if slow */
+				       uint32_t async_timeout,
+				       uint64_t fall_behind_data,
+				       uint32_t fall_behind_ios);
+
+int dm_tree_node_add_replicator_dev_target(struct dm_tree_node *node,
+					   uint64_t size,
+					   const char *replog_uuid,	/* replicator-log device */
+					   uint64_t rdevice_index,
+					   const char *rdev_uuid,	/* remove/rimage device name/uuid */
+					   unsigned rsite_index,
+					   const char *llog_uuid,
+					   uint32_t llog_flags,		/* Mirror log flags */
+					   uint32_t llog_size);
+
 int dm_tree_node_add_target_area(struct dm_tree_node *node,
 				    const char *dev_name,
 				    const char *dlid,
 				    uint64_t offset);
 
+int dm_tree_set_priority(struct dm_tree *dtree, const char *uuid, int priority);
+
 /*
  * Set readahead (in sectors) after loading the node.
  */
libdm/libdm-deptree.c +287 -9

409 lines not on this page · raw message

Signature · 1 line
1.6.5.rc2
#2 lore raw

PATCH 3/13 Replicator: add lvm support

Adding basic lib lvm elements for Replicator
Validation of Replicator segment

---
 configure.in                     |   17 +
 lib/Makefile.in                  |    9 +
 lib/commands/toolcontext.c       |    5 +
 lib/metadata/lv_manip.c          |    1 +
 lib/metadata/merge.c             |   14 +
 lib/metadata/metadata-exported.h |   94 ++++-
 lib/metadata/replicator.c        |  339 ++++++++++++++
 lib/metadata/segtype.h           |    8 +
 lib/replicator/.exported_symbols |    1 +
 lib/replicator/Makefile.in       |   28 ++
 lib/replicator/replicator.c      |  912 ++++++++++++++++++++++++++++++++++++++
 11 files changed, 1427 insertions(+), 1 deletions(-)
 create mode 100644 lib/metadata/replicator.c
 create mode 100644 lib/replicator/.exported_symbols
 create mode 100644 lib/replicator/Makefile.in
 create mode 100644 lib/replicator/replicator.c
configure.in +17 -0
index bf360ed..197e17a 100644
@@ -308,6 +308,21 @@ if test x$MIRRORS = xinternal; then
 fi
 
 ################################################################################
+dnl -- Asynchronous Volume Replicator inclusion type
+AC_MSG_CHECKING(whether to include replicator)
+AC_ARG_WITH(replicator, AC_HELP_STRING([--with-replicator=TYPE],
+        [Replicator support: internal/shared/none [[TYPE=none]]]),
+        [ REPLICATOR="$withval" ], [ REPLICATOR="none" ])
+AC_MSG_RESULT($REPLICATOR)
+
+case "$REPLICATOR" in
+ none|shared) ;;
+ internal) AC_DEFINE([REPLICATOR_INTERNAL], 1,
+                     [Define to 1 to include built-in support for replicator.]) ;;
+ *) AC_MSG_ERROR([--with-replicator parameter invalid ($REPLICATOR)]) ;;
+esac
+
+################################################################################
 dnl -- Disable readline
 AC_MSG_CHECKING(whether to enable readline)
 AC_ARG_ENABLE([readline],
@@ -1116,6 +1131,7 @@ AC_SUBST(LVM_PATCHLEVEL)
 AC_SUBST(LVM_RELEASE)
 AC_SUBST(LVM_RELEASE_DATE)
 AC_SUBST(MIRRORS)
+AC_SUBST(REPLICATOR)
 AC_SUBST(MSGFMT)
 AC_SUBST(OWNER)
 AC_SUBST(PKGCONFIG)
@@ -1163,6 +1179,7 @@ lib/format1/Makefile
 lib/format_pool/Makefile
 lib/locking/Makefile
 lib/mirror/Makefile
+lib/replicator/Makefile
 lib/misc/lvm-version.h
 lib/snapshot/Makefile
 libdm/Makefile
lib/Makefile.in +9 -0
index 9396fb2..38a3589 100644
@@ -33,6 +33,10 @@ ifeq ("@MIRRORS@", "shared")
   SUBDIRS += mirror
 endif
 
+ifeq ("@REPLICATOR@", "shared")
+  SUBDIRS += replicator
+endif
+
 SOURCES =\
 	activate/activate.c \
 	cache/lvmcache.c \
@@ -74,6 +78,7 @@ SOURCES =\
 	metadata/mirror.c \
 	metadata/pv_manip.c \
 	metadata/pv_map.c \
+	metadata/replicator.c \
 	metadata/segtype.c \
 	metadata/snapshot_manip.c \
 	misc/crc.c \
@@ -125,6 +130,10 @@ ifeq ("@MIRRORS@", "internal")
   SOURCES += mirror/mirrored.c
 endif
 
+ifeq ("@REPLICATOR@", "internal")
+  SOURCES += replicator/replicator.c
+endif
+
 ifeq ("@DEVMAPPER@", "yes")
   SOURCES +=\
 	activate/dev_manager.c \
lib/commands/toolcontext.c +5 -0
index 2a56100..d1f4724 100644
@@ -904,6 +904,11 @@ static int _init_segtypes(struct cmd_context *cmd)
 	dm_list_add(&cmd->segtypes, &segtype->list);
 #endif
 
+#ifdef REPLICATOR_INTERNAL
+	if (!init_replicator_segtype(&seglib))
+		return 0;
+#endif
+
 #ifdef HAVE_LIBDL
 	/* Load any formats in shared libs unless static */
 	if (!is_static() &&
lib/metadata/lv_manip.c +1 -0
index 7bcd64f..51e100e 100644
@@ -1876,6 +1876,7 @@ struct logical_volume *alloc_lv(struct dm_pool *mem)
 	dm_list_init(&lv->segments);
 	dm_list_init(&lv->tags);
 	dm_list_init(&lv->segs_using_this_lv);
+	dm_list_init(&lv->rsites);
 
 	return lv;
 }
lib/metadata/merge.c +14 -0
index 66e9ce0..3233d2b 100644
@@ -66,6 +66,8 @@ int check_lv_segments(struct logical_volume *lv, int complete_vg)
 	int r = 1;
 	uint32_t area_multiplier, s;
 	struct seg_list *sl;
+	struct replicator_site *rsite;
+	struct replicator_device *rdev;
 
 	dm_list_iterate_items(seg, &lv->segments) {
 		seg_count++;
@@ -207,6 +209,18 @@ int check_lv_segments(struct logical_volume *lv, int complete_vg)
 			if (lv == seg_lv(seg, s))
 				seg_found++;
 		}
+		if (seg_is_replicator_dev(seg)) {
+			dm_list_iterate_items(rsite, &seg->replicator->rsites) {
+				dm_list_iterate_items(rdev, &rsite->rdevices) {
+					if (lv == rdev->lv || lv == rdev->slog)
+						seg_found++;
+				}
+			}
+			if (lv == seg->replicator)
+				seg_found++;
+		}
+		if (seg_is_replicator(seg) && lv == seg->rlog_lv)
+				seg_found++;
 		if (seg->log_lv == lv)
 			seg_found++;
 		if (!seg_found) {
lib/metadata/metadata-exported.h +93 -1

136 lines not on this page · raw message

lib/metadata/replicator.c new file +339 -0

339 lines not on this page · raw message

lib/metadata/segtype.h +8 -0
index ff6fb08..4454cb2 100644
@@ -35,8 +35,12 @@ struct dev_manager;
 #define SEG_VIRTUAL		0x00000020U
 #define SEG_CANNOT_BE_ZEROED	0x00000040U
 #define SEG_MONITORED		0x00000080U
+#define SEG_REPLICATOR		0x00000100U
+#define SEG_REPLICATOR_DEV	0x00000200U
 
 #define seg_is_mirrored(seg)	((seg)->segtype->flags & SEG_AREAS_MIRRORED ? 1 : 0)
+#define seg_is_replicator(seg)	((seg)->segtype->flags & SEG_REPLICATOR ? 1 : 0)
+#define seg_is_replicator_dev(seg) ((seg)->segtype->flags & SEG_REPLICATOR_DEV ? 1 : 0)
 #define seg_is_striped(seg)	((seg)->segtype->flags & SEG_AREAS_STRIPED ? 1 : 0)
 #define seg_is_snapshot(seg)	((seg)->segtype->flags & SEG_SNAPSHOT ? 1 : 0)
 #define seg_is_virtual(seg)	((seg)->segtype->flags & SEG_VIRTUAL ? 1 : 0)
@@ -106,6 +110,10 @@ struct segment_type *init_zero_segtype(struct cmd_context *cmd);
 struct segment_type *init_error_segtype(struct cmd_context *cmd);
 struct segment_type *init_free_segtype(struct cmd_context *cmd);
 
+#ifdef REPLICATOR_INTERNAL
+int init_replicator_segtype(struct segtype_library *seglib);
+#endif
+
 #ifdef SNAPSHOT_INTERNAL
 struct segment_type *init_snapshot_segtype(struct cmd_context *cmd);
 #endif
lib/replicator/.exported_symbols new file +1 -0
new file mode 100644
index 0000000..1c92c6a
@@ -0,0 +1 @@
+init_segtype
lib/replicator/Makefile.in new file +28 -0
new file mode 100644
index 0000000..db1f9b7
@@ -0,0 +1,28 @@
+#
+# Copyright (C) 2009 Red Hat, Inc. All rights reserved.
+#
+# This file is part of LVM2.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+
+SOURCES = replicator.c
+
+LIB_SHARED = liblvm2replicator.so
+
+include $(top_srcdir)/make.tmpl
+
+install: $(LIB_SHARED)
+	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \
+		$(libdir)/$(LIB_SHARED).$(LIB_VERSION)
+	$(LN_S) -f $(LIB_SHARED).$(LIB_VERSION) \
+		$(libdir)/$(LIB_SHARED)
lib/replicator/replicator.c new file +912 -0

912 lines not on this page · raw message

Signature · 1 line
1.6.5.rc2
#3 lore raw

PATCH 4/13 Replicator: new variable in generated file

---
 lib/misc/configure.h.in |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
lib/misc/configure.h.in +3 -0
index 4273eeb..a49cd6e 100644
@@ -419,6 +419,9 @@
 /* Define to 1 to include the LVM readline shell. */
 #undef READLINE_SUPPORT
 
+/* Define to 1 to include built-in support for replicator. */
+#undef REPLICATOR_INTERNAL
+
 /* Define as the return type of signal handlers (`int' or `void'). */
 #undef RETSIGTYPE
 
Signature · 1 line
1.6.5.rc2
#4 lore raw

PATCH 5/13 Replicator: use dm_tree_suspend_children

Before of suspend/deactivation of replicator_dev node the suspend of replicator node is mandatory.

---
 lib/activate/dev_manager.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
lib/activate/dev_manager.c +2 -0
index 19deab8..55daf14 100644
@@ -1169,6 +1169,7 @@ static int _clean_tree(struct dev_manager *dm, struct dm_tree_node *root)
 			continue;
 
 		dm_tree_set_cookie(root, 0);
+		dm_tree_suspend_children(root, uuid, strlen(uuid), 1);
 		r = dm_tree_deactivate_children(root, uuid, strlen(uuid));
 		if (!dm_udev_wait(dm_tree_get_cookie(root)))
 			stack;
@@ -1208,6 +1209,7 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv, actio
 	case DEACTIVATE:
  		/* Deactivate LV and all devices it references that nothing else has open. */
 		dm_tree_set_cookie(root, 0);
+		dm_tree_suspend_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1, 1);
 		r = dm_tree_deactivate_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1);
 		if (!dm_udev_wait(dm_tree_get_cookie(root)))
 			stack;
Signature · 1 line
1.6.5.rc2
#5 lore raw

PATCH 6/13 Replicator: extend _lv_each_dependency() rep. deps

---
 lib/metadata/metadata.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
lib/metadata/metadata.c +4 -0
index 263c705..feb7cc1 100644
@@ -1850,6 +1850,8 @@ static int _lv_each_dependency(struct logical_volume *lv,
 	struct lv_segment *lvseg;
 
 	struct logical_volume *deps[] = {
+		(lv->rdevice && lv != lv->rdevice->lv) ? lv->rdevice->lv : 0,
+		(lv->rdevice && lv != lv->rdevice->slog) ? lv->rdevice->slog : 0,
 		lv->snapshot ? lv->snapshot->origin : 0,
 		lv->snapshot ? lv->snapshot->cow : 0 };
 	for (i = 0; i < sizeof(deps) / sizeof(*deps); ++i) {
@@ -1860,6 +1862,8 @@ static int _lv_each_dependency(struct logical_volume *lv,
 	dm_list_iterate_items(lvseg, &lv->segments) {
 		if (lvseg->log_lv && !fn(lvseg->log_lv, data))
 			return_0;
+		if (lvseg->rlog_lv && !fn(lvseg->rlog_lv, data))
+			return_0;
 		for (s = 0; s < lvseg->area_count; ++s) {
 			if (seg_type(lvseg, s) == AREA_LV && !fn(seg_lv(lvseg,s), data))
 				return_0;
Signature · 1 line
1.6.5.rc2
#6 lore raw

PATCH 7/13 Replicator: update _create_partial_dtree()

Creating partial tree for Replicator target.
Using dm_tree_set_priority() to set higher priority for Replicator.

---
 lib/activate/dev_manager.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)
lib/activate/dev_manager.c +26 -1
index 55daf14..8ad737b 100644
@@ -730,6 +730,9 @@ static struct dm_tree *_create_partial_dtree(struct dev_manager *dm, struct logi
 	struct dm_list *snh, *snht;
 	struct lv_segment *seg;
 	uint32_t s;
+	struct replicator_device *rdev;
+	struct replicator_site *rsite;
+	const char *replog_dlid;
 
 	if (!(dtree = dm_tree_create())) {
 		log_error("Partial dtree creation failed for %s.", lv->name);
@@ -745,12 +748,34 @@ static struct dm_tree *_create_partial_dtree(struct dev_manager *dm, struct logi
 			goto_bad;
 
 	/* Add any LVs used by segments in this LV */
-	dm_list_iterate_items(seg, &lv->segments)
+	dm_list_iterate_items(seg, &lv->segments) {
 		for (s = 0; s < seg->area_count; s++)
 			if (seg_type(seg, s) == AREA_LV && seg_lv(seg, s)) {
 				if (!_add_lv_to_dtree(dm, dtree, seg_lv(seg, s)))
 					goto_bad;
 			}
+		if (seg->replicator) {
+                        /* Add all replicator-dev from same replicator */
+			dm_list_iterate_items(rsite, &seg->replicator->rsites) {
+				dm_list_iterate_items(rdev, &rsite->rdevices) {
+					if (rsite->state == REPLICATOR_STATE_ACTIVE) {
+						if (!rdev->replicator_dev->lv)
+							goto_bad;
+						if (lv == rdev->replicator_dev->lv)
+                                                        continue;
+						/* Add replicator-dev LV */
+						if (!_add_lv_to_dtree(dm, dtree, rdev->replicator_dev->lv))
+							goto_bad;
+					}
+				}
+			}
+
+			if (!(replog_dlid = build_dlid(dm, seg->replicator->lvid.s, NULL)))
+				goto_bad;
+			if (!dm_tree_set_priority(dtree, replog_dlid, 1))
+				goto_bad;
+		}
+	}
 
 	return dtree;
 
Signature · 1 line
1.6.5.rc2
#7 lore raw

PATCH 8/13 Replicator: add replicator/_dev to dtree

Adding all replicator related LVs to dtree.
Start of one replicator_dev initiate start of all other related.

---
 lib/activate/dev_manager.c |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
lib/activate/dev_manager.c +39 -1
index 8ad737b..ce2d7bf 100644
@@ -950,6 +950,38 @@ static int _add_target_to_dtree(struct dev_manager *dm,
 static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
 				  struct logical_volume *lv, const char *layer);
 
+/* Add all replicators' LVs from active segment */
+static int _add_replicator_dev_target_to_dtree(struct dev_manager *dm,
+					       struct dm_tree *dtree,
+					       struct lv_segment *seg)
+{
+	struct replicator_device *rdev;
+	struct replicator_site *rsite;
+
+	if (lv_is_active_replicator_dev(seg->lv)) {
+		/* activation of one replicator node activate all other nodes */
+		if (!seg->replicator ||
+		    !_add_new_lv_to_dtree(dm, dtree, seg->replicator, NULL))
+			return_0;
+
+		dm_list_iterate_items(rsite, &seg->replicator->rsites) {
+			dm_list_iterate_items(rdev, &rsite->rdevices) {
+				if (rdev->slog && !_add_new_lv_to_dtree(dm, dtree, rdev->slog, NULL))
+					return_0;
+				if (rsite->state == REPLICATOR_STATE_ACTIVE &&
+				    (!rdev->lv ||
+				     !_add_new_lv_to_dtree(dm, dtree, rdev->lv, NULL) ||
+				     !rdev->replicator_dev->lv ||
+				     !_add_new_lv_to_dtree(dm, dtree, rdev->replicator_dev->lv, NULL)))
+					return_0;
+			}
+		}
+	} else if (!_add_new_lv_to_dtree(dm, dtree, seg->lv->rdevice->lv, NULL))
+		return_0;
+
+        return 1;
+}
+
 static int _add_segment_to_dtree(struct dev_manager *dm,
 				   struct dm_tree *dtree,
 				   struct dm_tree_node *dnode,
@@ -980,8 +1012,14 @@ static int _add_segment_to_dtree(struct dev_manager *dm,
 	    !_add_new_lv_to_dtree(dm, dtree, seg->log_lv, NULL))
 		return_0;
 
+	if (seg_is_replicator_dev(seg)) {
+		if (!_add_replicator_dev_target_to_dtree(dm, dtree, seg))
+			return_0;
+        } else if (seg_is_replicator(seg) && seg->rlog_lv) {
+		if (!_add_new_lv_to_dtree(dm, dtree, seg->rlog_lv, NULL))
+			return_0;
 	/* If this is a snapshot origin, add real LV */
-	if (lv_is_origin(seg->lv) && !layer) {
+	} else if (lv_is_origin(seg->lv) && !layer) {
 		if (vg_is_clustered(seg->lv->vg)) {
 			log_error("Clustered snapshots are not yet supported");
 			return 0;
Signature · 1 line
1.6.5.rc2
#8 lore raw

PATCH 9/13 Replicator: do not remove of replicators' LVs

---
 lib/metadata/lv_manip.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
lib/metadata/lv_manip.c +9 -0
index 51e100e..5e21fca 100644
@@ -2084,6 +2084,15 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
 		return 0;
 	}
 
+	if (lv_is_replicator_dev(lv) ||
+	    lv_is_rimage(lv) ||
+	    lv_is_rlog(lv) ||
+	    lv_is_slog(lv)) {
+		log_error("Can't remove logical volume %s used by a replicator",
+			  lv->name);
+		return 0;
+	}
+
 	if (lv->status & LOCKED) {
 		log_error("Can't remove locked LV %s", lv->name);
 		return 0;
Signature · 1 line
1.6.5.rc2
#9 lore raw

PATCH 10/13 Replicator: activate change for vgchange

Activate only replicator-dev segment. Activation of one segment will activivate also all other related heads.

---
 tools/vgchange.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
tools/vgchange.c +5 -0
index 07d5262..78660be 100644
@@ -69,6 +69,11 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd,
 		if ((lv->status & MIRROR_IMAGE) || (lv->status & MIRROR_LOG))
 			continue;
 
+		/* Only request activation of replicator device LV */
+		if (lv_is_rlog(lv) || lv_is_slog(lv) || lv_is_rimage(lv) ||
+		    lv_is_replicator(lv))
+			continue;
+
 		/* Can't deactivate a pvmove LV */
 		/* FIXME There needs to be a controlled way of doing this */
 		if (((activate == CHANGE_AN) || (activate == CHANGE_ALN)) &&
Signature · 1 line
1.6.5.rc2
#10 lore raw

PATCH 11/13 Replicator: add new options for replicator

New options: addsite, delsite, replicator,
replicatorlog, replicatorlogtype

---
 tools/args.h       |    5 +++++
 tools/commands.h   |   10 ++++++++--
 tools/lvcreate.c   |   17 +++++++++++++++++
 tools/lvmcmdline.c |   10 ++++++++++
 tools/tools.h      |    1 +
 5 files changed, 41 insertions(+), 2 deletions(-)
tools/args.h +5 -0
index 1204683..f3b61b7 100644
@@ -63,6 +63,11 @@ arg(dataalignmentoffset_ARG, '\0', "dataalignmentoffset", size_kb_arg, 0)
 arg(virtualoriginsize_ARG, '\0', "virtualoriginsize", size_mb_arg, 0)
 arg(virtualsize_ARG, '\0', "virtualsize", size_mb_arg, 0)
 arg(noudevsync_ARG, '\0', "noudevsync", NULL, 0)
+arg(replicator_ARG, '\0', "replicator", NULL, 0)
+arg(replicatorlog_ARG, '\0', "replicatorlog", NULL, 0)
+arg(replicatorlogtype_ARG, '\0', "replicatorlogtype", NULL, 0)
+arg(addsite_ARG, '\0', "addsite", site_arg, 0)
+arg(delsite_ARG, '\0', "delsite", site_arg, 0)
 
 /* Allow some variations */
 arg(resizable_ARG, '\0', "resizable", yes_no_arg, 0)
tools/commands.h +8 -2
index 73ebd0b..fbf59b2 100644
@@ -63,10 +63,12 @@ xx(lvchange,
    "\t[-A|--autobackup y|n]\n"
    "\t[-a|--available [e|l]y|n]\n"
    "\t[--addtag Tag]\n"
+   "\t[--addsite Site]\n"
    "\t[--alloc AllocationPolicy]\n"
    "\t[-C|--contiguous y|n]\n"
    "\t[-d|--debug]\n"
    "\t[--deltag Tag]\n"
+   "\t[--delsite Site]\n"
    "\t[-f|--force]\n"
    "\t[-h|--help]\n"
    "\t[--ignorelockingfailure]\n"
@@ -89,7 +91,7 @@ xx(lvchange,
    ignorelockingfailure_ARG, ignoremonitoring_ARG, major_ARG, minor_ARG,
    monitor_ARG, noudevsync_ARG, partial_ARG, permission_ARG, persistent_ARG,
    readahead_ARG, resync_ARG, refresh_ARG, addtag_ARG, deltag_ARG, test_ARG,
-   yes_ARG)
+   addsite_ARG, delsite_ARG, yes_ARG)
 
 xx(lvconvert,
    "Change logical volume layout",
@@ -145,6 +147,9 @@ xx(lvcreate,
    "\t[-p|--permission {r|rw}]\n"
    "\t[-r|--readahead ReadAheadSectors|auto|none]\n"
    "\t[-R|--regionsize MirrorLogRegionSize]\n"
+   "\t[--replicator]\n"
+   "\t[--replicatorlog LogicalVolumeName]\n"
+   "\t[--replicatorlogtype ringbuffer]\n"
    "\t[-t|--test]\n"
    "\t[--type VolumeType]\n"
    "\t[-v|--verbose]\n"
@@ -179,7 +184,8 @@ xx(lvcreate,
    addtag_ARG, alloc_ARG, autobackup_ARG, chunksize_ARG, contiguous_ARG,
    corelog_ARG, extents_ARG, major_ARG, minor_ARG, mirrorlog_ARG, mirrors_ARG,
    name_ARG, nosync_ARG, noudevsync_ARG, permission_ARG, persistent_ARG,
-   readahead_ARG, regionsize_ARG, size_ARG, snapshot_ARG, stripes_ARG,
+   readahead_ARG, regionsize_ARG, replicator_ARG, replicatorlog_ARG,
+   replicatorlogtype_ARG, size_ARG, snapshot_ARG, stripes_ARG,
    stripesize_ARG, test_ARG, type_ARG, virtualoriginsize_ARG, virtualsize_ARG,
    zero_ARG)
 
tools/lvcreate.c +17 -0
index be6b5cc..c655a2b 100644
@@ -405,6 +405,9 @@ static int _lvcreate_params(struct lvcreate_params *lp,
 	if (seg_is_mirrored(lp))
 		lp->mirrors = 2;
 
+	if (seg_is_replicator(lp) || arg_count(cmd, replicator_ARG))
+		lp->replicator = 1;
+
 	if (arg_count(cmd, mirrors_ARG)) {
 		lp->mirrors = arg_uint_value(cmd, mirrors_ARG, 0) + 1;
 		if (lp->mirrors == 1)
@@ -469,6 +472,20 @@ static int _lvcreate_params(struct lvcreate_params *lp,
 		}
 	}
 
+	if (lp->replicator) {
+		log_error("--replicator for replicators");
+
+	} else {
+		if (arg_count(cmd, replicatorlog_ARG)) {
+			log_error("--replicatorlog is only available with replicators");
+			return 0;
+		}
+		if (arg_count(cmd, replicatorlogtype_ARG)) {
+			log_error("--replicatorlogtype is only available with replicators");
+			return 0;
+		}
+	}
+
 	if (activation() && lp->segtype->ops->target_present &&
 	    !lp->segtype->ops->target_present(cmd, NULL, NULL)) {
 		log_error("%s: Required device-mapper target(s) not "
tools/lvmcmdline.c +10 -0
index 80c1a46..f3c0e21 100644
@@ -483,6 +483,16 @@ int readahead_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a)
 	return 1;
 }
 
+int site_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a)
+{
+	char *pos = a->value;
+	if (!validate_name(pos))
+		return 0;
+
+	return 1;
+}
+
+
 static void __alloc(int size)
 {
 	if (!(_cmdline.commands = dm_realloc(_cmdline.commands, sizeof(*_cmdline.commands) * size))) {
tools/tools.h +1 -0
index 3afa1a1..67b2178 100644
@@ -151,6 +151,7 @@ int units_arg(struct cmd_context *cmd, struct arg *a);
 int segtype_arg(struct cmd_context *cmd, struct arg *a);
 int alloc_arg(struct cmd_context *cmd, struct arg *a);
 int readahead_arg(struct cmd_context *cmd, struct arg *a);
+int site_arg(struct cmd_context *cmd, struct arg *a);
 
 /* we use the enums to access the switches */
 unsigned int arg_count(const struct cmd_context *cmd, int a);
Signature · 1 line
1.6.5.rc2
#11 lore raw

PATCH 12/13 Replicator: update copyright dates

---
 lib/activate/dev_manager.c |    2 +-
 lib/metadata/segtype.h     |    2 +-
 libdm/libdm-deptree.c      |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
lib/activate/dev_manager.c +1 -1
index ce2d7bf..0a3c30c 100644
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
  *
  * This file is part of LVM2.
  *
lib/metadata/segtype.h +1 -1
index 4454cb2..009a199 100644
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.  
- * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
  *
  * This file is part of LVM2.
  *
libdm/libdm-deptree.c +1 -1
index 4fc625f..d80b13b 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2005-2009 Red Hat, Inc. All rights reserved.
  *
  * This file is part of the device-mapper userspace tools.
  *
Signature · 1 line
1.6.5.rc2
#12 lore raw

PATCH 13/13 Replicator: update of generated configure file

---
 configure |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)
configure +33 -1
index ae42377..88ca84c 100755
@@ -654,6 +654,7 @@ SNAPSHOTS
 POOL
 PKGCONFIG
 OWNER
+REPLICATOR
 MIRRORS
 LVM_RELEASE_DATE
 LVM_RELEASE
@@ -813,6 +814,7 @@ with_pool
 with_cluster
 with_snapshots
 with_mirrors
+with_replicator
 enable_readline
 enable_realtime
 with_clvmd
@@ -1545,6 +1547,8 @@ Optional Packages:
                           TYPE=internal
   --with-mirrors=TYPE     Mirror support: internal/shared/none
                           TYPE=internal
+  --with-replicator=TYPE  Replicator support: internal/shared/none
+                          [TYPE=none]
   --with-clvmd=TYPE       Build cluster LVM Daemon.
                           The following cluster manager combinations are valid:
                            * cman,gulm             (RHEL4 or equivalent)
@@ -9326,6 +9330,32 @@ _ACEOF
 fi
 
 ################################################################################
+{ $as_echo "$as_me:$LINENO: checking whether to include replicator" >&5
+$as_echo_n "checking whether to include replicator... " >&6; }
+
+# Check whether --with-replicator was given.
+if test "${with_replicator+set}" = set; then
+  withval=$with_replicator;  REPLICATOR="$withval"
+else
+   REPLICATOR="none"
+fi
+
+{ $as_echo "$as_me:$LINENO: result: $REPLICATOR" >&5
+$as_echo "$REPLICATOR" >&6; }
+
+case "$REPLICATOR" in
+ none|shared) ;;
+ internal)
+cat >>confdefs.h <<\_ACEOF
+#define REPLICATOR_INTERNAL 1
+_ACEOF
+ ;;
+ *) { { $as_echo "$as_me:$LINENO: error: --with-replicator parameter invalid ($REPLICATOR)" >&5
+$as_echo "$as_me: error: --with-replicator parameter invalid ($REPLICATOR)" >&2;}
+   { (exit 1); exit 1; }; } ;;
+esac
+
+################################################################################
 { $as_echo "$as_me:$LINENO: checking whether to enable readline" >&5
 $as_echo_n "checking whether to enable readline... " >&6; }
 # Check whether --enable-readline was given.
@@ -15524,8 +15554,9 @@ LVM_LIBAPI=`echo "$VER" | $AWK -F '[()]' '{print $2}'`
 
 
 
+
 ################################################################################
-ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile daemons/cmirrord/Makefile daemons/dmeventd/Makefile daemons/dmeventd/libdevmapper-event.pc daemons/dmeventd/plugins/Makefile daemons/dmeventd/plugins/mirror/Makefile daemons/dmeventd/plugins/snapshot/Makefile doc/Makefile include/.symlinks include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/misc/lvm-version.h lib/snapshot/Makefile libdm/Makefile libdm/libdevmapper.pc liblvm/Makefile liblvm/liblvm2app.pc man/Makefile po/Makefile scripts/clvmd_init_red_hat scripts/lvm2_monitoring_init_red_hat scripts/Makefile test/Makefile test/api/Makefile tools/Makefile udev/Makefile"
+ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile daemons/cmirrord/Makefile daemons/dmeventd/Makefile daemons/dmeventd/libdevmapper-event.pc daemons/dmeventd/plugins/Makefile daemons/dmeventd/plugins/mirror/Makefile daemons/dmeventd/plugins/snapshot/Makefile doc/Makefile include/.symlinks include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/replicator/Makefile lib/misc/lvm-version.h lib/snapshot/Makefile libdm/Makefile libdm/libdevmapper.pc liblvm/Makefile liblvm/liblvm2app.pc man/Makefile po/Makefile scripts/clvmd_init_red_hat scripts/lvm2_monitoring_init_red_hat scripts/Makefile test/Makefile test/api/Makefile tools/Makefile udev/Makefile"
 
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
@@ -16142,6 +16173,7 @@ do
     "lib/format_pool/Makefile") CONFIG_FILES="$CONFIG_FILES lib/format_pool/Makefile" ;;
     "lib/locking/Makefile") CONFIG_FILES="$CONFIG_FILES lib/locking/Makefile" ;;
     "lib/mirror/Makefile") CONFIG_FILES="$CONFIG_FILES lib/mirror/Makefile" ;;
+    "lib/replicator/Makefile") CONFIG_FILES="$CONFIG_FILES lib/replicator/Makefile" ;;
     "lib/misc/lvm-version.h") CONFIG_FILES="$CONFIG_FILES lib/misc/lvm-version.h" ;;
     "lib/snapshot/Makefile") CONFIG_FILES="$CONFIG_FILES lib/snapshot/Makefile" ;;
     "libdm/Makefile") CONFIG_FILES="$CONFIG_FILES libdm/Makefile" ;;
Signature · 1 line
1.6.5.rc2
#13 lore raw

PATCH 3/13 Replicator: add lvm support

In reply to Zdenek Kabelac
Quoted 2 lines · Zdenek Kabelac
 lib/metadata/replicator.c        |  339 ++++++++++++++
 lib/replicator/replicator.c      |  912 ++++++++++++++++++++++++++++++++++++++

Filenames need to be globally unique in this tree: one of those needs renaming.

Alasdair

#14 lore raw

PATCH 3/13 Replicator: add lvm support

Dne 7.10.2009 17:07, Alasdair G Kergon napsal(a):

Quoted 9 lines · Zdenek Kabelac
Quoted 2 lines
 lib/metadata/replicator.c        |  339 ++++++++++++++
 lib/replicator/replicator.c      |  912 ++++++++++++++++++++++++++++++++++++++

Filenames need to be globally unique in this tree: one of those needs renaming.

Alasdair

lib/metadata/replicator.c -> lib/metadata/replicator_manip.c ?

Zdenek

#15 lore raw

PATCH 2/13 Replicator: add libdm support

In reply to Zdenek Kabelac

libdm/libdevmapper.h int dm_tree_activate_children(struct dm_tree_node *dnode, · line 346

Quoted 6 lines · Zdenek Kabelac

int dm_tree_suspend_children(struct dm_tree_node *dnode,

libdm/libdevmapper.h +3 -2
-				   const char *uuid_prefix,
-				   size_t uuid_prefix_len);
+			     const char *uuid_prefix,
+			     size_t uuid_prefix_len,
+			     int priority);

We can't change the published interface like that.

If there really is no alternative to this parameter then you need to introduce a new function instead.

Alasdair

#16 lore raw

PATCH 2/13 Replicator: add libdm support

Hi,

Quoted 10 lines · Alasdair G Kergon

libdm/libdevmapper.h int dm_tree_activate_children(struct dm_tree_node *dnode, · line 346

Quoted 6 lines · Zdenek Kabelac

int dm_tree_suspend_children(struct dm_tree_node *dnode,

libdm/libdevmapper.h +3 -2
-				   const char *uuid_prefix,
-				   size_t uuid_prefix_len);
+			     const char *uuid_prefix,
+			     size_t uuid_prefix_len,
+			     int priority);

We can't change the published interface like that.

Quoted 2 lines

If there really is no alternative to this parameter then you need to introduce a new function instead.

I have discussed this in person with Zden?k, and it seems that the main reason for this is to allow more atomic suspension of complete replicator.

The normal semantics of DM tree operations is that suspension of a node is done after all its children are suspended. For replicator, it would be beneficial to suspend the parent first (to stop the IO stream from the client side) and only afterwards start suspending the inferior nodes.

In practice, this constitutes only a very slight increase in risk of tripping a "synchronicity" threshold -- by the amount of data that arrives to the replicator head in the time frame between a leg is suspended and the replicator as a whole is suspended -- if this extra data exceeds the amount of free space in the replicator log, this could trip an extra resync that would be costly. But it should be stressed, that in these situations, this was already quite likely to happen, and the outlined problem only increases the chance of this happening by a small margin.

In other words, I think it is not worth worrying about just yet. At the point when a dmeventd-style leg dropping is implemented for replicator, this may become a more pressing problem, but I think the solution should be deferred until the work on that aspect has begun -- at that time, we ought to have a clearer picture of the problem area, so it may turn out that a better solution exists that would not require similar incompatible (and arguably risky) changes to the libdm core.

Yours,
Petr.

#17 lore raw

PATCH 2/13 Replicator: add libdm support

Dne 8.10.2009 11:42, Petr Rockai napsal(a):

Quoted 32 lines

Hi,

Quoted 10 lines · Alasdair G Kergon

libdm/libdevmapper.h int dm_tree_activate_children(struct dm_tree_node *dnode, · line 346

Quoted 6 lines · Zdenek Kabelac

int dm_tree_suspend_children(struct dm_tree_node *dnode,

libdm/libdevmapper.h +3 -2
-				   const char *uuid_prefix,
-				   size_t uuid_prefix_len);
+			     const char *uuid_prefix,
+			     size_t uuid_prefix_len,
+			     int priority);

We can't change the published interface like that.

Quoted 2 lines

If there really is no alternative to this parameter then you need to introduce a new function instead.

I have discussed this in person with Zden?k, and it seems that the main reason for this is to allow more atomic suspension of complete replicator.

The normal semantics of DM tree operations is that suspension of a node is done after all its children are suspended. For replicator, it would be beneficial to suspend the parent first (to stop the IO stream from the client side) and only afterwards start suspending the inferior nodes.

In practice, this constitutes only a very slight increase in risk of tripping a "synchronicity" threshold -- by the amount of data that arrives to the replicator head in the time frame between a leg is suspended and the replicator as a whole is suspended -- if this extra data exceeds the amount of free space in the replicator log, this could trip an extra resync that would be costly. But it should be stressed, that in these situations, this was already quite likely to happen, and the outlined problem only increases the chance of this happening by a small margin.

Quoted 7 lines

In other words, I think it is not worth worrying about just yet. At the point when a dmeventd-style leg dropping is implemented for replicator, this may become a more pressing problem, but I think the solution should be deferred until the work on that aspect has begun -- at that time, we ought to have a clearer picture of the problem area, so it may turn out that a better solution exists that would not require similar incompatible (and arguably risky) changes to the libdm core.

The orginal primary idea for my suspend_children patch was the intent to keep logic inverse to prioritized activation - so what is activated last gets suspended first - but it seems to be a problematic concept.

So this is my second attempt to suspend the replicator control node before deactivation of the replicator's head.

I think we need to be able to distinguish from the situation when we want to simply cut off one of replicator's head - and gracefully shutdown whole replicator.

So I've introduced new variable along the old activation_priority and I use it as a sign (similar to noflush,skipfs) and before deactivation of node I simply check whether that node is connected with flagged replicator control node. In that case the node is suspend in front of deactivation.

This patch should have no influence on other targets.

Zdenek

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0008-Replicator-solution-for-suspend-deactivate.patch
URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20091009/4a8de653/attachment.ksh>

#18 lore raw

PATCH 2/13 Replicator: add libdm support

In reply to Zdenek Kabelac

Hi,

lib/activate/dev_manager.c static int _tree_action(struct dev_manager *dm, struct logical_volume *lv, actio · line 1224

Quoted 3 lines · Zdenek Kabelac
lib/activate/dev_manager.c +1 -1
 	case SUSPEND_WITH_LOCKFS:
-		if (!dm_tree_suspend_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1))
+		if (!dm_tree_suspend_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1, 0))

other than the API change Alasdair pointed out, this bit here changes existing behaviour (although it may turn out to not affect anything, it would at least deserve a comment as to why only priority 0 targets should be suspended).

Please also note that just calling this twice, once for 0 and once for 1 does not correspond to pre-existing behaviour either (it constitutes an ordering change).

Yours,
Petr.

#19 lore raw

PATCH 1/13 Replicator: export out_ function for modules

In reply to Zdenek Kabelac

lib/format_text/export.c static int _sectors_to_units(uint64_t sectors, char *buffer, size_t s) · line 254

Quoted 5 lines · Zdenek Kabelac
lib/format_text/export.c +5 -0
+/* insert new line */
+int out_newline(struct formatter *f)
+{
+	outnl(f);
+	return 0;

Should return 1 here, and the caller has to check that.
Instead, I think the outnl macro should be changed to work like the outf one. (make the 'f->nl' part internal to an export.c function instead of the header file) The idea was that the callers would be using this so frequently, it was clearer just writing 'outf(...)' than 'if (!out_text(...)) return_0;' everywhere.

Alasdair

#20 lore raw

PATCH 1/13 Replicator: export out_ function for modules

Dne 7.10.2009 17:05, Alasdair G Kergon napsal(a):

Quoted 8 lines · Zdenek Kabelac

lib/format_text/export.c static int _sectors_to_units(uint64_t sectors, char *buffer, size_t s) · line 254

Quoted 5 lines
lib/format_text/export.c +5 -0
+/* insert new line */
+int out_newline(struct formatter *f)
+{
+	outnl(f);
+	return 0;

Should return 1 here, and the caller has to check that.

true

Quoted 7 lines

Instead, I think the outnl macro should be changed to work like the outf one. (make the 'f->nl' part internal to an export.c function instead of the header file) The idea was that the callers would be using this so frequently, it was clearer just writing 'outf(...)' than 'if (!out_text(...)) return_0;' everywhere.

Alasdair

So how about this:

+/* insert new line */
+int out_newline(struct formatter *f)
+{
+ return f->nl(f);
+}
+

I think this will be the easiest way - nl() is virtual function thus it can't be easily 'macro-ised'.

Zdenek

#21 lore raw

PATCH 1/13 Replicator: export out_ function for modules

Dne 8.10.2009 13:02, Zdenek Kabelac napsal(a):

Quoted 29 lines

Dne 7.10.2009 17:05, Alasdair G Kergon napsal(a):

Quoted 8 lines · Zdenek Kabelac

lib/format_text/export.c static int _sectors_to_units(uint64_t sectors, char *buffer, size_t s) · line 254

Quoted 5 lines
lib/format_text/export.c +5 -0
+/* insert new line */
+int out_newline(struct formatter *f)
+{
+	outnl(f);
+	return 0;

Should return 1 here, and the caller has to check that.

true

Quoted 7 lines

Instead, I think the outnl macro should be changed to work like the outf one. (make the 'f->nl' part internal to an export.c function instead of the header file) The idea was that the callers would be using this so frequently, it was clearer just writing 'outf(...)' than 'if (!out_text(...)) return_0;' everywhere.

Alasdair

So how about this:

lib/format_text/export.c +6 -0
+/* insert new line */
+int out_newline(struct formatter *f)
+{
+	return f->nl(f);
+}
+
Quoted 3 lines

I think this will be the easiest way - nl() is virtual function thus it can't be easily 'macro-ised'.

Hmm I've maybe slightly misunderstood your comment. So would you agree with following extension:

-#define outnl(f) do {if (!f->nl(f)) return_0;} while (0) +#define outnl(f) do {if (!out_newline(f)) return_0;} while (0)

Thus the internal code would be also using out_newline() just like outf() is using out_text()?

Eventually we may keep outnl() as is - and introduce outnewl for externs. +#define outnewl(f) do {if (!out_newline(f)) return_0;} while (0)

Zdenek

#22 lore raw

PATCH 1/13 Replicator: export out_ function for modules

Review

Quoted 2 lines · Zdenek Kabelac
(quoted diff) +1 -1
-#define outnl(f) do {if (!f->nl(f)) return_0;} while (0)
+#define outnl(f) do {if (!out_newline(f)) return_0;} while (0)

That was what I was thinking, yes.

Alasdair