[PATCH RFCv2 8/8] rcu: Rewrite and rename list_splice_init_rcu()

From: Jan H. SchÃnherr
Date: Wed Jul 27 2011 - 15:13:10 EST


From: Jan H. SchÃnherr <schnhrr@xxxxxxxxxxxxxxx>

Rewrite list_splice_init_rcu() to make use of the newly introduced
__list_splice_rcu(). Also, add "_sync" to the name, so that we can
differentiate whether the list to be spliced is allowed to have its own
concurrent readers: with "_sync", readers not belonging to the
destination list are allowed and the function will block; without
"_sync", readers not belonging to the destination list are forbidden and
the function will not block.

Signed-off-by: Jan H. SchÃnherr <schnhrr@xxxxxxxxxxxxxxx>
---
drivers/char/ipmi/ipmi_msghandler.c | 2 +-
fs/btrfs/volumes.c | 2 +-
include/linux/rculist.h | 19 +++++++++----------
3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 58c0e63..62b48e8 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -502,7 +502,7 @@ static void clean_up_interface_data(ipmi_smi_t intf)
*/
mutex_lock(&intf->cmd_rcvrs_mutex);
INIT_LIST_HEAD(&list);
- list_splice_init_rcu(&intf->cmd_rcvrs, &list, synchronize_rcu);
+ list_splice_init_rcu_sync(&intf->cmd_rcvrs, &list, synchronize_rcu);
mutex_unlock(&intf->cmd_rcvrs_mutex);

list_for_each_entry_safe(rcvr, rcvr2, &list, link)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 19450bc..e1d5149 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1440,7 +1440,7 @@ static int btrfs_prepare_sprout(struct btrfs_trans_handle *trans,
mutex_init(&seed_devices->device_list_mutex);

mutex_lock(&root->fs_info->fs_devices->device_list_mutex);
- list_splice_init_rcu(&fs_devices->devices, &seed_devices->devices,
+ list_splice_init_rcu_sync(&fs_devices->devices, &seed_devices->devices,
synchronize_rcu);
mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);

diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index c5db505..b695e88 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -277,7 +277,8 @@ static inline void list_splice_tail_init_rcu(struct list_head *list,
}

/**
- * list_splice_init_rcu - splice an RCU-protected list into an existing list.
+ * list_splice_init_rcu_sync - splice an RCU-protected list into an existing
+ * RCU-protected list.
* @list: the RCU-protected list to splice
* @head: the place in the list to splice the first list into
* @sync: function to sync: synchronize_rcu(), synchronize_sched(), ...
@@ -293,18 +294,19 @@ static inline void list_splice_tail_init_rcu(struct list_head *list,
* based on call_rcu() could be created. But only if -really-
* needed -- there is no shortage of RCU API members.
*/
-static inline void list_splice_init_rcu(struct list_head *list,
+static inline void list_splice_init_rcu_sync(struct list_head *list,
struct list_head *head,
void (*sync)(void))
{
- struct list_head *first = list->next;
- struct list_head *last = list->prev;
- struct list_head *at = head->next;
+ struct list_head tmp;

if (list_empty(head))
return;

- /* "first" and "last" tracking list, so initialize it. */
+ tmp.next = list->next;
+ tmp.prev = list->prev;
+
+ /* "tmp" is tracking "list", so we can safely initialize "list". */

INIT_LIST_HEAD(list);

@@ -325,10 +327,7 @@ static inline void list_splice_init_rcu(struct list_head *list,
* this function.
*/

- last->next = at;
- rcu_assign_pointer(list_next_rcu(head), first);
- first->prev = head;
- at->prev = last;
+ __list_splice_rcu(&tmp, head, head->next);
}

/**
--
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/