Commit f42e6ed8 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] add new list_splice_init()

A little cleanup: Most callers of list_splice() immediately
reinitialise the source list_head after calling list_splice().

So create a new list_splice_init() which does all that.
parent e7c89646
...@@ -964,8 +964,7 @@ void blk_run_queues(void) ...@@ -964,8 +964,7 @@ void blk_run_queues(void)
return; return;
} }
list_splice(&blk_plug_list, &local_plug_list); list_splice_init(&blk_plug_list, &local_plug_list);
INIT_LIST_HEAD(&blk_plug_list);
spin_unlock_irq(&blk_plug_lock); spin_unlock_irq(&blk_plug_lock);
while (!list_empty(&local_plug_list)) { while (!list_empty(&local_plug_list)) {
......
...@@ -740,8 +740,7 @@ void abort_requests(struct hpsb_host *host) ...@@ -740,8 +740,7 @@ void abort_requests(struct hpsb_host *host)
host->ops->devctl(host, CANCEL_REQUESTS, 0); host->ops->devctl(host, CANCEL_REQUESTS, 0);
spin_lock_irqsave(&host->pending_pkt_lock, flags); spin_lock_irqsave(&host->pending_pkt_lock, flags);
list_splice(&host->pending_packets, &llist); list_splice_init(&host->pending_packets, &llist);
INIT_LIST_HEAD(&host->pending_packets);
spin_unlock_irqrestore(&host->pending_pkt_lock, flags); spin_unlock_irqrestore(&host->pending_pkt_lock, flags);
list_for_each(lh, &llist) { list_for_each(lh, &llist) {
......
...@@ -220,8 +220,7 @@ static void sync_sb_inodes(struct super_block *sb, int sync_mode, ...@@ -220,8 +220,7 @@ static void sync_sb_inodes(struct super_block *sb, int sync_mode,
struct list_head *head; struct list_head *head;
const unsigned long start = jiffies; /* livelock avoidance */ const unsigned long start = jiffies; /* livelock avoidance */
list_splice(&sb->s_dirty, &sb->s_io); list_splice_init(&sb->s_dirty, &sb->s_io);
INIT_LIST_HEAD(&sb->s_dirty);
head = &sb->s_io; head = &sb->s_io;
while ((tmp = head->prev) != head) { while ((tmp = head->prev) != head) {
struct inode *inode = list_entry(tmp, struct inode, i_list); struct inode *inode = list_entry(tmp, struct inode, i_list);
...@@ -262,13 +261,10 @@ static void sync_sb_inodes(struct super_block *sb, int sync_mode, ...@@ -262,13 +261,10 @@ static void sync_sb_inodes(struct super_block *sb, int sync_mode,
break; break;
} }
out: out:
if (!list_empty(&sb->s_io)) { /*
/* * Put the rest back, in the correct order.
* Put the rest back, in the correct order. */
*/ list_splice_init(&sb->s_io, sb->s_dirty.prev);
list_splice(&sb->s_io, sb->s_dirty.prev);
INIT_LIST_HEAD(&sb->s_io);
}
return; return;
} }
......
...@@ -2975,10 +2975,7 @@ int jfs_sync(void) ...@@ -2975,10 +2975,7 @@ int jfs_sync(void)
} }
} }
/* Add anon_list2 back to anon_list */ /* Add anon_list2 back to anon_list */
if (!list_empty(&TxAnchor.anon_list2)) { list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list);
list_splice(&TxAnchor.anon_list2, &TxAnchor.anon_list);
INIT_LIST_HEAD(&TxAnchor.anon_list2);
}
add_wait_queue(&jfs_sync_thread_wait, &wq); add_wait_queue(&jfs_sync_thread_wait, &wq);
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
TXN_UNLOCK(); TXN_UNLOCK();
......
...@@ -490,8 +490,7 @@ mpage_writepages(struct address_space *mapping, ...@@ -490,8 +490,7 @@ mpage_writepages(struct address_space *mapping,
write_lock(&mapping->page_lock); write_lock(&mapping->page_lock);
list_splice(&mapping->dirty_pages, &mapping->io_pages); list_splice_init(&mapping->dirty_pages, &mapping->io_pages);
INIT_LIST_HEAD(&mapping->dirty_pages);
while (!list_empty(&mapping->io_pages) && !done) { while (!list_empty(&mapping->io_pages) && !done) {
struct page *page = list_entry(mapping->io_pages.prev, struct page *page = list_entry(mapping->io_pages.prev,
...@@ -538,13 +537,10 @@ mpage_writepages(struct address_space *mapping, ...@@ -538,13 +537,10 @@ mpage_writepages(struct address_space *mapping,
page_cache_release(page); page_cache_release(page);
write_lock(&mapping->page_lock); write_lock(&mapping->page_lock);
} }
if (!list_empty(&mapping->io_pages)) { /*
/* * Put the rest back, in the correct order.
* Put the rest back, in the correct order. */
*/ list_splice_init(&mapping->io_pages, mapping->dirty_pages.prev);
list_splice(&mapping->io_pages, mapping->dirty_pages.prev);
INIT_LIST_HEAD(&mapping->io_pages);
}
write_unlock(&mapping->page_lock); write_unlock(&mapping->page_lock);
if (bio) if (bio)
mpage_bio_submit(WRITE, bio); mpage_bio_submit(WRITE, bio);
......
...@@ -1110,8 +1110,7 @@ nfs_commit_rpcsetup(struct list_head *head, struct nfs_write_data *data) ...@@ -1110,8 +1110,7 @@ nfs_commit_rpcsetup(struct list_head *head, struct nfs_write_data *data)
/* Set up the RPC argument and reply structs /* Set up the RPC argument and reply structs
* NB: take care not to mess about with data->commit et al. */ * NB: take care not to mess about with data->commit et al. */
list_splice(head, &data->pages); list_splice_init(head, &data->pages);
INIT_LIST_HEAD(head);
first = nfs_list_entry(data->pages.next); first = nfs_list_entry(data->pages.next);
last = nfs_list_entry(data->pages.prev); last = nfs_list_entry(data->pages.prev);
inode = first->wb_inode; inode = first->wb_inode;
......
...@@ -136,6 +136,19 @@ static inline int list_empty(list_t *head) ...@@ -136,6 +136,19 @@ static inline int list_empty(list_t *head)
return head->next == head; return head->next == head;
} }
static inline void __list_splice(list_t *list, list_t *head)
{
list_t *first = list->next;
list_t *last = list->prev;
list_t *at = head->next;
first->prev = head;
head->next = first;
last->next = at;
at->prev = last;
}
/** /**
* list_splice - join two lists * list_splice - join two lists
* @list: the new list to add. * @list: the new list to add.
...@@ -145,15 +158,22 @@ static inline void list_splice(list_t *list, list_t *head) ...@@ -145,15 +158,22 @@ static inline void list_splice(list_t *list, list_t *head)
{ {
list_t *first = list->next; list_t *first = list->next;
if (first != list) { if (first != list)
list_t *last = list->prev; __list_splice(list, head);
list_t *at = head->next; }
first->prev = head;
head->next = first;
last->next = at; /**
at->prev = last; * list_splice_init - join two lists and reinitialise the emptied list.
* @list: the new list to add.
* @head: the place to add it in the first list.
*
* The list at @list is reinitialised
*/
static inline void list_splice_init(list_t *list, list_t *head)
{
if (!list_empty(list)) {
__list_splice(list, head);
INIT_LIST_HEAD(list);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment