Re: [PATCH 0/4] locks: flock and lease related bugfixes, and remove i_flctx counters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 17, 2015 at 11:55 AM, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> 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
 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;

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux