From: Jan Kara <jack@suse.cz>
To: linux-fsdevel@vger.kernel.org
Cc: Christoph Hellwig <hch@infradead.org>,
Al Viro <viro@ZenIV.linux.org.uk>, Jan Kara <jack@suse.cz>
Subject: [PATCH 5/8] vfs: Create function for iterating over block devices
Date: Wed, 9 Nov 2011 18:45:04 +0100 [thread overview]
Message-ID: <1320860707-18559-6-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1320860707-18559-1-git-send-email-jack@suse.cz>
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/block_dev.c | 36 ++++++++++++++++++++++++++++++++++++
include/linux/fs.h | 1 +
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/fs/block_dev.c b/fs/block_dev.c
index b07f1da..4d6631e 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -196,6 +196,42 @@ blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
nr_segs, blkdev_get_blocks, NULL, NULL, 0);
}
+void iterate_bdevs(void (*func)(struct block_device *, void *), void *arg)
+{
+ struct inode *inode, *old_inode = NULL;
+
+ spin_lock(&inode_sb_list_lock);
+ list_for_each_entry(inode, &blockdev_superblock->s_inodes, i_sb_list) {
+ struct address_space *mapping = inode->i_mapping;
+
+ spin_lock(&inode->i_lock);
+ if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW) ||
+ mapping->nrpages == 0) {
+ spin_unlock(&inode->i_lock);
+ continue;
+ }
+ __iget(inode);
+ spin_unlock(&inode->i_lock);
+ spin_unlock(&inode_sb_list_lock);
+ /*
+ * We hold a reference to 'inode' so it couldn't have been
+ * removed from s_inodes list while we dropped the
+ * inode_sb_list_lock. We cannot iput the inode now as we can
+ * be holding the last reference and we cannot iput it under
+ * inode_sb_list_lock. So we keep the reference and iput it
+ * later.
+ */
+ iput(old_inode);
+ old_inode = inode;
+
+ func(I_BDEV(inode), arg);
+
+ spin_lock(&inode_sb_list_lock);
+ }
+ spin_unlock(&inode_sb_list_lock);
+ iput(old_inode);
+}
+
int __sync_blockdev(struct block_device *bdev, int wait)
{
if (!bdev)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 0c4df26..0404e7c 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2089,6 +2089,7 @@ extern void bd_set_size(struct block_device *, loff_t size);
extern void bd_forget(struct inode *inode);
extern void bdput(struct block_device *);
extern void invalidate_bdev(struct block_device *);
+extern void iterate_bdevs(void (*)(struct block_device *, void *), void *);
extern int sync_blockdev(struct block_device *bdev);
extern struct super_block *freeze_bdev(struct block_device *);
extern void emergency_thaw_all(void);
--
1.7.1
next prev parent reply other threads:[~2011-11-09 17:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-09 17:44 [PATCH 0/8] Cleanup and improve sync (v4) Jan Kara
2011-11-09 17:45 ` [PATCH 1/8] vfs: Move noop_backing_dev_info check from sync into writeback Jan Kara
2011-11-09 17:45 ` [PATCH 2/8] quota: Split dquot_quota_sync() to writeback and cache flushing part Jan Kara
2011-11-09 17:45 ` [PATCH 3/8] quota: Move quota syncing to ->sync_fs method Jan Kara
2011-11-09 17:45 ` [PATCH 4/8] vfs: Reorder operations during sys_sync Jan Kara
2011-11-09 17:45 ` Jan Kara [this message]
2011-11-09 17:45 ` [PATCH 6/8] vfs: Make sys_sync writeout also block device inodes Jan Kara
2011-11-09 17:45 ` [PATCH 7/8] vfs: Remove unnecessary flushing of block devices Jan Kara
2011-11-09 17:45 ` [PATCH 8/8] vfs: Avoid unnecessary WB_SYNC_NONE writeback during sys_sync and reorder sync passes Jan Kara
2011-11-24 22:42 ` [PATCH 0/8] Cleanup and improve sync (v4) Jan Kara
2011-12-13 16:44 ` Jan Kara
-- strict thread matches above, loose matches on Subject: below --
2012-01-05 23:46 [PATCH 0/8 RESEND] " Jan Kara
2012-01-05 23:46 ` [PATCH 5/8] vfs: Create function for iterating over block devices Jan Kara
2012-07-03 14:45 [PATCH 0/8 v4] Flush all block devices on sync(2) and cleanup the code Jan Kara
2012-07-03 14:45 ` [PATCH 5/8] vfs: Create function for iterating over block devices Jan Kara
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=1320860707-18559-6-git-send-email-jack@suse.cz \
--to=jack@suse.cz \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).