* [PATCH] additional bio list helpers
@ 2007-02-06 11:00 Bryn M. Reeves
2007-02-06 21:05 ` Kiyoshi Ueda
0 siblings, 1 reply; 3+ messages in thread
From: Bryn M. Reeves @ 2007-02-06 11:00 UTC (permalink / raw)
To: device-mapper development; +Cc: Heinz Mauelshagen
[-- Attachment #1: Type: text/plain, Size: 441 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Add a couple of extra helper routines to drivers/md/dm-bio-list.h. This
patch is required for the current dm-loop patch.
Kind regards,
Bryn.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFFyF+/6YSQoMYUY94RAnB0AJ9CUAbLJhy9sGeAkQuKvjfPOcXFhgCfXqXT
td9QjIOQK+ECBVf3H0Wl83g=
=NX1z
-----END PGP SIGNATURE-----
[-- Attachment #2: dm-bio-list-helpers.patch --]
[-- Type: text/x-patch, Size: 2395 bytes --]
Add additional bio list helpers to dm-bio-list.h:
bio_list_empty
bio_list_nr
bio_list_join
bio_list_join_init
bio_list_merge_init
bio_list_push
These are used by dm-loop for manipulating lists of bios to be
resubmitted by the fs I/O code.
Signed-off-by: Heinz Mauelshagen <hjm@redhat.com>
Signed-off-by: Bryn Reeves <breeves@redhat.com>
===================================================================
diff --git a/drivers/md/dm-bio-list.h b/drivers/md/dm-bio-list.h
index da43496..301efae 100644
--- a/drivers/md/dm-bio-list.h
+++ b/drivers/md/dm-bio-list.h
@@ -14,11 +14,33 @@ struct bio_list {
struct bio *tail;
};
+static inline int bio_list_empty(struct bio_list *bl)
+{
+ return bl->head == NULL && bl->tail == NULL;
+}
+
+#define BIO_LIST_HEAD(bl) struct bio_list bl = { NULL, NULL }
+
static inline void bio_list_init(struct bio_list *bl)
{
bl->head = bl->tail = NULL;
}
+#define bio_for_each(bio, bl) \
+ for (bio = (bl)->head; bio; bio = bio->bi_next)
+
+static inline int bio_list_nr(struct bio_list *bl)
+{
+ int i=0;
+ struct bio *bio;
+
+ if(bio_list_empty(bl))
+ return i;
+ bio_for_each(bio, bl)
+ i++;
+ return i;
+}
+
static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
{
bio->bi_next = NULL;
@@ -33,9 +55,6 @@ static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
{
- if (!bl2->head)
- return;
-
if (bl->tail)
bl->tail->bi_next = bl2->head;
else
@@ -58,6 +77,40 @@ static inline void bio_list_merge_head(struct bio_list *bl,
bl->head = bl2->head;
}
+static inline void bio_list_join(struct bio_list *bl, struct bio_list *bl2)
+{
+ if (bio_list_empty(bl2))
+ return;
+
+ bl2->tail->bi_next = bl->head;
+ bl->head = bl2->head;
+
+ if (!bl->tail)
+ bl->tail = bl2->tail;
+}
+
+static inline void bio_list_join_init(struct bio_list *bl, struct bio_list *bl2)
+{
+ bio_list_join(bl, bl2);
+ bio_list_init(bl2);
+}
+
+static inline void bio_list_merge_init(struct bio_list *bl,
+ struct bio_list *bl2)
+{
+ bio_list_merge(bl, bl2);
+ bio_list_init(bl2);
+}
+
+static inline void bio_list_push(struct bio_list *bl, struct bio *bio)
+{
+ bio->bi_next = bl->head;
+ bl->head = bio;
+
+ if (!bl->tail)
+ bl->tail = bio;
+}
+
static inline struct bio *bio_list_pop(struct bio_list *bl)
{
struct bio *bio = bl->head;
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] additional bio list helpers
2007-02-06 11:00 [PATCH] additional bio list helpers Bryn M. Reeves
@ 2007-02-06 21:05 ` Kiyoshi Ueda
2007-02-07 11:26 ` Bryn M. Reeves
0 siblings, 1 reply; 3+ messages in thread
From: Kiyoshi Ueda @ 2007-02-06 21:05 UTC (permalink / raw)
To: dm-devel, breeves; +Cc: mauelshagen
Hi Bryn,
On Tue, 06 Feb 2007 11:00:15 +0000, "Bryn M. Reeves" <breeves@redhat.com> wrote:
> @@ -33,9 +55,6 @@ static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
>
> static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
> {
> - if (!bl2->head)
> - return;
> -
> if (bl->tail)
> bl->tail->bi_next = bl2->head;
> else
This one breaks the bio_list if bl2 is a empty list.
Probably missed to add like below?
-----------------------------------
+ if (bio_list_empty(bl2))
+ return;
-----------------------------------
Other small comments are below:
> @@ -14,11 +14,33 @@ struct bio_list {
> struct bio *tail;
> };
>
> +static inline int bio_list_empty(struct bio_list *bl)
> +{
> + return bl->head == NULL && bl->tail == NULL;
> +}
I think that bl->tail is always NULL when bl->head is NULL,
unless the bio_list is corrupted. So no need to check bl->tail.
> +#define bio_for_each(bio, bl) \
> + for (bio = (bl)->head; bio; bio = bio->bi_next)
> +
> +static inline int bio_list_nr(struct bio_list *bl)
> +{
> + int i=0;
> + struct bio *bio;
> +
> + if(bio_list_empty(bl))
> + return i;
I think that this check in not needed because it is covered
by bio_for_each() below.
> + bio_for_each(bio, bl)
> + i++;
> + return i;
> +}
> @@ -58,6 +77,40 @@ static inline void bio_list_merge_head(struct bio_list *bl,
> bl->head = bl2->head;
> }
>
> +static inline void bio_list_join(struct bio_list *bl, struct bio_list *bl2)
> +{
> + if (bio_list_empty(bl2))
> + return;
> +
> + bl2->tail->bi_next = bl->head;
> + bl->head = bl2->head;
> +
> + if (!bl->tail)
> + bl->tail = bl2->tail;
> +}
> +
> +static inline void bio_list_join_init(struct bio_list *bl, struct bio_list *bl2)
> +{
> + bio_list_join(bl, bl2);
> + bio_list_init(bl2);
> +}
I think that bio_list_join() is same as existing bio_list_merge_head().
Regards,
Kiyoshi Ueda
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] additional bio list helpers
2007-02-06 21:05 ` Kiyoshi Ueda
@ 2007-02-07 11:26 ` Bryn M. Reeves
0 siblings, 0 replies; 3+ messages in thread
From: Bryn M. Reeves @ 2007-02-07 11:26 UTC (permalink / raw)
To: Kiyoshi Ueda; +Cc: dm-devel, mauelshagen
[-- Attachment #1: Type: text/plain, Size: 1263 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Kiyoshi,
Kiyoshi Ueda wrote:
> This one breaks the bio_list if bl2 is a empty list.
> Probably missed to add like below?
> -----------------------------------
> + if (bio_list_empty(bl2))
> + return;
> -----------------------------------
Quite right - fixed, thanks!
> I think that bl->tail is always NULL when bl->head is NULL,
> unless the bio_list is corrupted. So no need to check bl->tail.
This was actually already changed in my git copy, but I forgot to
re-generate the patch before posting - apologies!
> I think that this check in not needed because it is covered
> by bio_for_each() below.
Agreed!
> I think that bio_list_join() is same as existing bio_list_merge_head().
Also agreed - thanks for catching these. This one also isn't used by
dm-loop anyway.
Revised patch attached - this time just including the changes actually
needed by the dm-loop patch:
bio_list_empty
bio_for_each
bio_list_nr
bio_list_merge_init
Kind regards,
Bryn.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFFybdW6YSQoMYUY94RAgZxAKChuSEQAP0zs+f9/yzjCf92beTkJQCdEQBq
oxBR+Xsj1V6Fj4r9ec3sPZ0=
=nIAj
-----END PGP SIGNATURE-----
[-- Attachment #2: dm-bio-list-helpers.patch --]
[-- Type: text/x-patch, Size: 1467 bytes --]
Add additional bio list helpers to dm-bio-list.h:
bio_list_empty
bio_for_each
bio_list_nr
bio_list_merge_init
These are used by dm-loop for manipulating lists of bios to be
resubmitted by the fs I/O code.
Signed-off-by: Bryn Reeves <breeves@redhat.com>
===================================================================
diff --git a/drivers/md/dm-bio-list.h b/drivers/md/dm-bio-list.h
index da43496..6db7644 100644
--- a/drivers/md/dm-bio-list.h
+++ b/drivers/md/dm-bio-list.h
@@ -14,11 +14,31 @@ struct bio_list {
struct bio *tail;
};
+static inline int bio_list_empty(struct bio_list *bl)
+{
+ return bl->head == NULL;
+}
+
+#define BIO_LIST_HEAD(bl) struct bio_list bl = { NULL, NULL }
+
static inline void bio_list_init(struct bio_list *bl)
{
bl->head = bl->tail = NULL;
}
+#define bio_for_each(bio, bl) \
+ for (bio = (bl)->head; bio; bio = bio->bi_next)
+
+static inline int bio_list_nr(struct bio_list *bl)
+{
+ int i=0;
+ struct bio *bio;
+
+ bio_for_each(bio, bl)
+ i++;
+ return i;
+}
+
static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
{
bio->bi_next = NULL;
@@ -58,6 +78,13 @@ static inline void bio_list_merge_head(struct bio_list *bl,
bl->head = bl2->head;
}
+static inline void bio_list_merge_init(struct bio_list *bl,
+ struct bio_list *bl2)
+{
+ bio_list_merge(bl, bl2);
+ bio_list_init(bl2);
+}
+
static inline struct bio *bio_list_pop(struct bio_list *bl)
{
struct bio *bio = bl->head;
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-02-07 11:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-06 11:00 [PATCH] additional bio list helpers Bryn M. Reeves
2007-02-06 21:05 ` Kiyoshi Ueda
2007-02-07 11:26 ` Bryn M. Reeves
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.