All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Jeff Layton <jeff.layton@primarydata.com>
Cc: linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"Kirill A. Shutemov" <kirill@shutemov.name>,
	"J. Bruce Fields" <bfields@fieldses.org>,
	Christoph Hellwig <hch@lst.de>,
	Dave Chinner <david@fromorbit.com>,
	Sasha Levin <sasha.levin@oracle.com>
Subject: Re: [PATCH 0/4] locks: flock and lease related bugfixes, and remove i_flctx counters
Date: Tue, 17 Feb 2015 12:20:20 -0800	[thread overview]
Message-ID: <CA+55aFw2tODqepCea+wWatE+sVeRcsn6cfSzUqSBOhKau2ZB5w@mail.gmail.com> (raw)
In-Reply-To: <CA+55aFwdAg_St3_qJPSHfityE7772taoPKwSg1M3B0WiBWnCsA@mail.gmail.com>

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

On Tue, Feb 17, 2015 at 11:55 AM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> I do believe that we should add a "list_count()" function, so that we could write
>
>    *flock_count = list_count(&ctx->flc_flock);
>
> instead of that horribly ugly
>
>     list_for_each_entry(lock, &ctx->flc_flock, fl_list)
>          ++(*flock_count);
>
> thing. But that's a separate cleanup.

The helper function would possibly be something like this.

Untested. It may mix-count, or it might do unspeakable acts on your
pets. No guarantees.

                        Linus

[-- Attachment #2: patch.diff --]
[-- Type: text/plain, Size: 1178 bytes --]

 include/linux/list.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/include/linux/list.h b/include/linux/list.h
index feb773c76ee0..495566be02e1 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -190,6 +190,20 @@ static inline int list_empty(const struct list_head *head)
 }
 
 /**
+ * list_count - count number of entries on list
+ * @head: the list to count.
+ */
+static inline int list_count(const struct list_head *head)
+{
+	int len = 0;
+	const struct list_head *p = head;
+
+	while ((p = p->next) != head)
+		len++;
+	return len;
+}
+
+/**
  * list_empty_careful - tests whether a list is empty and not being modified
  * @head: the list to test
  *
@@ -611,6 +625,20 @@ static inline int hlist_empty(const struct hlist_head *h)
 	return !h->first;
 }
 
+/**
+ * hlist_count - count number of entries on hlist
+ * @head: the list to count.
+ */
+static inline int hlist_count(const struct hlist_head *head)
+{
+	int len = 0;
+	const struct hlist_node *p;
+
+	for (p = head->first; p; p = p->next)
+		len++;
+	return len;
+}
+
 static inline void __hlist_del(struct hlist_node *n)
 {
 	struct hlist_node *next = n->next;

  reply	other threads:[~2015-02-17 20:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-17 12:46 [PATCH 0/4] locks: flock and lease related bugfixes, and remove i_flctx counters Jeff Layton
2015-02-17 12:46 ` [PATCH 1/4] Revert "locks: keep a count of locks on the flctx lists" Jeff Layton
2015-02-17 12:46 ` [PATCH 2/4] locks: remove conditional lock release in middle of flock_lock_file Jeff Layton
2015-02-17 17:10   ` J. Bruce Fields
2015-02-17 17:56     ` Jeff Layton
2015-02-17 19:11       ` J. Bruce Fields
2015-02-17 22:21         ` J. Bruce Fields
2015-02-17 22:29           ` Jeff Layton
2015-02-17 12:46 ` [PATCH 3/4] locks: when upgrading, don't remove old flock lock until replacing with new one Jeff Layton
2015-02-17 12:46 ` [PATCH 4/4] locks: only remove leases associated with the file being closed Jeff Layton
2015-02-17 19:55 ` [PATCH 0/4] locks: flock and lease related bugfixes, and remove i_flctx counters Linus Torvalds
2015-02-17 20:20   ` Linus Torvalds [this message]
2015-02-17 20:20   ` Al Viro
2015-02-17 21:10     ` Jeff Layton

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=CA+55aFw2tODqepCea+wWatE+sVeRcsn6cfSzUqSBOhKau2ZB5w@mail.gmail.com \
    --to=torvalds@linux-foundation.org \
    --cc=bfields@fieldses.org \
    --cc=david@fromorbit.com \
    --cc=hch@lst.de \
    --cc=jeff.layton@primarydata.com \
    --cc=kirill@shutemov.name \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sasha.levin@oracle.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.