All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jun'ichi Nomura" <j-nomura@ce.jp.nec.com>
To: linux-lvm@redhat.com, Alasdair Kergon <agk@redhat.com>
Subject: [linux-lvm] [PATCH LVM2] (2/3) use _for_each_pv() from _check_contiguous()
Date: Fri, 06 Oct 2006 17:56:06 -0400	[thread overview]
Message-ID: <4526D0F6.7090406@ce.jp.nec.com> (raw)
In-Reply-To: <4526D08C.8010303@ce.jp.nec.com>

[-- Attachment #1: Type: text/plain, Size: 810 bytes --]

This patch rewrites _check_contiguous() to use _for_each_pv().

_for_each_pv() is a generic iterator function to execute given
function on each PV constituting the specified range of LV.
Since _check_contiguous() tries to find contiguous PV segment from
the end of the existing LV segment, I gave the last one LE as
a iteration range of _for_each_pv().

To pass necessary parameters to _for_each_pv callback (_match_pv()),
this patch adds new struct pv_match_handle.

The patch doesn't fix any bug but is a preparation for later patch.
Also, the use like this is what _for_each_pv() is intended for, I think.

diffstat:
 lv_manip.c |   89 +++++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 66 insertions(+), 23 deletions(-)

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America


[-- Attachment #2: 05-use-for_each_pv-from-check_contiguous.patch --]
[-- Type: text/x-patch, Size: 3632 bytes --]

diff -X ../dontdiff -urp LVM2.04-shrink-checkcontig-arg/lib/metadata/lv_manip.c LVM2.05.use_for_each_pv/lib/metadata/lv_manip.c
--- LVM2.04-shrink-checkcontig-arg/lib/metadata/lv_manip.c	2006-10-07 02:46:21.000000000 -0400
+++ LVM2.05.use_for_each_pv/lib/metadata/lv_manip.c	2006-10-07 02:49:12.000000000 -0400
@@ -24,6 +24,11 @@
 #include "display.h"
 #include "segtype.h"
 
+static int _for_each_pv(struct cmd_context *cmd, struct logical_volume *lv,
+			uint32_t le, uint32_t len, uint32_t *max_seg_len,
+			int (*fn)(struct cmd_context *cmd, struct pv_segment *peg, void *data),
+			void *data);
+
 /*
  * PVs used by a segment of an LV
  */
@@ -680,42 +685,80 @@ static int _comp_area(const void *l, con
 	return 0;
 }
 
+struct pv_match_handle {
+	/* function to check if pv_segment fits for the pv_area */
+	int (*cond)(struct pv_segment *, struct pv_area *);
+
+	struct pv_area *pva; /* pv_area to match */
+	int index; /* index of pv in flattened lv segment */
+	int matched; /* 1 if matching pv_segment is found */
+};
+
 /*
- * Is pva contiguous to any existing areas or on the same PV?
+ * (_for_each_pv callback)
+ * Check if the pv_segment fits for the pv_match_handle
  */
-static int _check_contiguous(struct lv_segment *prev_lvseg, struct pv_area *pva,
-			     struct pv_area **areas, uint32_t areas_size)
+static int _match_pv(struct cmd_context *cmd, struct pv_segment *peg,
+		     void *data)
 {
-	struct pv_segment *prev_pvseg;
-	struct lv_segment *lastseg;
-	uint32_t s;
+	struct pv_match_handle *h = (struct pv_match_handle *)data;
 
-	for (s = 0; s < prev_lvseg->area_count && s < areas_size; s++) {
-		if (seg_type(prev_lvseg, s) == AREA_LV) {
-			lastseg = list_item(list_last(&seg_lv(prev_lvseg, s)->segments), struct lv_segment);
-			/* FIXME For more areas supply flattened prev_lvseg to ensure consistency */
-			if (lastseg->area_count == 1 &&
-			    _check_contiguous(lastseg, pva, &areas[s], 1))
-				return 1;
-			continue;
-		}
+	h->index++;
+	if (h->cond && h->cond(peg, h->pva)) {
+		h->matched = 1;
+		return 0; /* to exit from for_each_pv loop */
+	}
 
-		if (!(prev_pvseg = seg_pvseg(prev_lvseg, s)))
-			continue; /* FIXME Broken */
+	return 1;
+}
 
-		if ((prev_pvseg->pv != pva->map->pv))
-			continue;
+static int _find_and_set_pv_area(struct lv_segment *prev_lvseg,
+				 struct pv_area *pva,
+				 struct pv_area **areas, uint32_t areas_size,
+				 int (*cond)(struct pv_segment *,
+					     struct pv_area *))
+{
+	struct pv_match_handle pmh;
+
+	pmh.cond = cond;
+	pmh.pva = pva;
+	pmh.index = -1;
+	pmh.matched = 0;
+
+	/* search through all PVs in the last extent of the LV */
+	_for_each_pv(NULL, prev_lvseg->lv,
+		     prev_lvseg->le + prev_lvseg->len - 1, 1,
+		     NULL, _match_pv, &pmh);
 
-		if (prev_pvseg->pe + prev_pvseg->len == pva->start) {
-			areas[s] = pva;
-			return 1;
-		}
+	if (pmh.matched && pmh.index >= 0 && pmh.index < areas_size) {
+		areas[pmh.index] = pva;
+		return 1;
 	}
 
 	return 0;
 }
 
 /*
+ * Is pva contiguous to any existing areas or on the same PV?
+ */
+static int is_contiguous(struct pv_segment *prev, struct pv_area *pva)
+{
+	if ((prev->pv == pva->map->pv) &&
+	    (prev->pe + prev->len == pva->start))
+		return 1;
+
+	return 0;
+}
+
+static int _check_contiguous(struct lv_segment *prev_lvseg, struct pv_area *pva,
+			     struct pv_area **areas, uint32_t areas_size)
+{
+	return _find_and_set_pv_area(prev_lvseg, pva, areas, areas_size,
+				     is_contiguous);
+}
+
+
+/*
  * Choose sets of parallel areas to use, respecting any constraints.
  */
 static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc,

  parent reply	other threads:[~2006-10-06 21:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-06 21:54 [linux-lvm] [PATCH LVM2] (0/3) 'cling' allocation policy Jun'ichi Nomura
2006-10-06 21:55 ` [linux-lvm] [PATCH LVM2] (1/3) remove unnecessary parameter from _check_contiguous Jun'ichi Nomura
2006-10-06 21:56 ` Jun'ichi Nomura [this message]
2006-10-07 23:38   ` [linux-lvm] Re: [PATCH LVM2] (2/3) use _for_each_pv() from _check_contiguous() Alasdair G Kergon
2006-10-09 16:27     ` Jun'ichi Nomura
2006-10-06 21:56 ` [linux-lvm] [PATCH LVM2] (3/3) add 'cling' allocation policy Jun'ichi Nomura
2006-10-08 12:06   ` [linux-lvm] " Alasdair G Kergon
2006-10-07 10:51 ` [linux-lvm] Re: [PATCH LVM2] (0/3) " Alasdair G Kergon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4526D0F6.7090406@ce.jp.nec.com \
    --to=j-nomura@ce.jp.nec.com \
    --cc=agk@redhat.com \
    --cc=linux-lvm@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.