2009-11-20 12:13:39 -07:00
|
|
|
/*
|
|
|
|
* fs/logfs/dev_bdev.c - Device access methods for block devices
|
|
|
|
*
|
|
|
|
* As should be obvious for Linux kernel code, license is GPLv2
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005-2008 Joern Engel <joern@logfs.org>
|
|
|
|
*/
|
|
|
|
#include "logfs.h"
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/buffer_head.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/gfp.h>
|
2011-05-20 13:50:29 -06:00
|
|
|
#include <linux/prefetch.h>
|
2009-11-20 12:13:39 -07:00
|
|
|
|
|
|
|
#define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1))
|
|
|
|
|
|
|
|
static int sync_request(struct page *page, struct block_device *bdev, int rw)
|
|
|
|
{
|
|
|
|
struct bio bio;
|
|
|
|
struct bio_vec bio_vec;
|
|
|
|
|
|
|
|
bio_init(&bio);
|
2012-04-01 21:53:04 -06:00
|
|
|
bio.bi_max_vecs = 1;
|
2009-11-20 12:13:39 -07:00
|
|
|
bio.bi_io_vec = &bio_vec;
|
|
|
|
bio_vec.bv_page = page;
|
|
|
|
bio_vec.bv_len = PAGE_SIZE;
|
|
|
|
bio_vec.bv_offset = 0;
|
|
|
|
bio.bi_vcnt = 1;
|
|
|
|
bio.bi_bdev = bdev;
|
2013-10-11 16:44:27 -06:00
|
|
|
bio.bi_iter.bi_sector = page->index * (PAGE_SIZE >> 9);
|
|
|
|
bio.bi_iter.bi_size = PAGE_SIZE;
|
2009-11-20 12:13:39 -07:00
|
|
|
|
2013-11-23 23:33:32 -07:00
|
|
|
return submit_bio_wait(rw, &bio);
|
2009-11-20 12:13:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int bdev_readpage(void *_sb, struct page *page)
|
|
|
|
{
|
|
|
|
struct super_block *sb = _sb;
|
|
|
|
struct block_device *bdev = logfs_super(sb)->s_bdev;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = sync_request(page, bdev, READ);
|
|
|
|
if (err) {
|
|
|
|
ClearPageUptodate(page);
|
|
|
|
SetPageError(page);
|
|
|
|
} else {
|
|
|
|
SetPageUptodate(page);
|
|
|
|
ClearPageError(page);
|
|
|
|
}
|
|
|
|
unlock_page(page);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(wq);
|
|
|
|
|
2015-07-20 07:29:37 -06:00
|
|
|
static void writeseg_end_io(struct bio *bio)
|
2009-11-20 12:13:39 -07:00
|
|
|
{
|
2013-11-07 13:20:26 -07:00
|
|
|
struct bio_vec *bvec;
|
|
|
|
int i;
|
2009-11-20 12:13:39 -07:00
|
|
|
struct super_block *sb = bio->bi_private;
|
|
|
|
struct logfs_super *super = logfs_super(sb);
|
|
|
|
|
2015-07-20 07:29:37 -06:00
|
|
|
BUG_ON(bio->bi_error); /* FIXME: Retry io or write elsewhere */
|
2009-11-20 12:13:39 -07:00
|
|
|
|
2013-11-07 13:20:26 -07:00
|
|
|
bio_for_each_segment_all(bvec, bio, i) {
|
|
|
|
end_page_writeback(bvec->bv_page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 06:29:47 -06:00
|
|
|
put_page(bvec->bv_page);
|
2013-11-07 13:20:26 -07:00
|
|
|
}
|
2009-11-20 12:13:39 -07:00
|
|
|
bio_put(bio);
|
|
|
|
if (atomic_dec_and_test(&super->s_pending_writes))
|
|
|
|
wake_up(&wq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __bdev_writeseg(struct super_block *sb, u64 ofs, pgoff_t index,
|
|
|
|
size_t nr_pages)
|
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(sb);
|
|
|
|
struct address_space *mapping = super->s_mapping_inode->i_mapping;
|
|
|
|
struct bio *bio;
|
|
|
|
struct page *page;
|
2012-07-22 23:02:11 -06:00
|
|
|
unsigned int max_pages;
|
2009-11-20 12:13:39 -07:00
|
|
|
int i;
|
|
|
|
|
2015-11-05 19:43:49 -07:00
|
|
|
max_pages = min_t(size_t, nr_pages, BIO_MAX_PAGES);
|
2012-07-22 23:02:11 -06:00
|
|
|
|
2009-11-20 12:13:39 -07:00
|
|
|
bio = bio_alloc(GFP_NOFS, max_pages);
|
2010-03-17 06:47:45 -06:00
|
|
|
BUG_ON(!bio);
|
2009-11-20 12:13:39 -07:00
|
|
|
|
|
|
|
for (i = 0; i < nr_pages; i++) {
|
|
|
|
if (i >= max_pages) {
|
|
|
|
/* Block layer cannot split bios :( */
|
|
|
|
bio->bi_vcnt = i;
|
2013-10-11 16:44:27 -06:00
|
|
|
bio->bi_iter.bi_size = i * PAGE_SIZE;
|
2009-11-20 12:13:39 -07:00
|
|
|
bio->bi_bdev = super->s_bdev;
|
2013-10-11 16:44:27 -06:00
|
|
|
bio->bi_iter.bi_sector = ofs >> 9;
|
2009-11-20 12:13:39 -07:00
|
|
|
bio->bi_private = sb;
|
|
|
|
bio->bi_end_io = writeseg_end_io;
|
|
|
|
atomic_inc(&super->s_pending_writes);
|
|
|
|
submit_bio(WRITE, bio);
|
|
|
|
|
|
|
|
ofs += i * PAGE_SIZE;
|
|
|
|
index += i;
|
|
|
|
nr_pages -= i;
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
bio = bio_alloc(GFP_NOFS, max_pages);
|
|
|
|
BUG_ON(!bio);
|
|
|
|
}
|
|
|
|
page = find_lock_page(mapping, index + i);
|
|
|
|
BUG_ON(!page);
|
|
|
|
bio->bi_io_vec[i].bv_page = page;
|
|
|
|
bio->bi_io_vec[i].bv_len = PAGE_SIZE;
|
|
|
|
bio->bi_io_vec[i].bv_offset = 0;
|
|
|
|
|
|
|
|
BUG_ON(PageWriteback(page));
|
|
|
|
set_page_writeback(page);
|
|
|
|
unlock_page(page);
|
|
|
|
}
|
|
|
|
bio->bi_vcnt = nr_pages;
|
2013-10-11 16:44:27 -06:00
|
|
|
bio->bi_iter.bi_size = nr_pages * PAGE_SIZE;
|
2009-11-20 12:13:39 -07:00
|
|
|
bio->bi_bdev = super->s_bdev;
|
2013-10-11 16:44:27 -06:00
|
|
|
bio->bi_iter.bi_sector = ofs >> 9;
|
2009-11-20 12:13:39 -07:00
|
|
|
bio->bi_private = sb;
|
|
|
|
bio->bi_end_io = writeseg_end_io;
|
|
|
|
atomic_inc(&super->s_pending_writes);
|
|
|
|
submit_bio(WRITE, bio);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bdev_writeseg(struct super_block *sb, u64 ofs, size_t len)
|
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(sb);
|
|
|
|
int head;
|
|
|
|
|
|
|
|
BUG_ON(super->s_flags & LOGFS_SB_FLAG_RO);
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
/* This can happen when the object fit perfectly into a
|
|
|
|
* segment, the segment gets written per sync and subsequently
|
|
|
|
* closed.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
head = ofs & (PAGE_SIZE - 1);
|
|
|
|
if (head) {
|
|
|
|
ofs -= head;
|
|
|
|
len += head;
|
|
|
|
}
|
|
|
|
len = PAGE_ALIGN(len);
|
|
|
|
__bdev_writeseg(sb, ofs, ofs >> PAGE_SHIFT, len >> PAGE_SHIFT);
|
|
|
|
}
|
|
|
|
|
2010-03-04 13:30:58 -07:00
|
|
|
|
2015-07-20 07:29:37 -06:00
|
|
|
static void erase_end_io(struct bio *bio)
|
2010-03-04 13:30:58 -07:00
|
|
|
{
|
|
|
|
struct super_block *sb = bio->bi_private;
|
|
|
|
struct logfs_super *super = logfs_super(sb);
|
|
|
|
|
2015-07-20 07:29:37 -06:00
|
|
|
BUG_ON(bio->bi_error); /* FIXME: Retry io or write elsewhere */
|
2010-03-04 13:30:58 -07:00
|
|
|
BUG_ON(bio->bi_vcnt == 0);
|
|
|
|
bio_put(bio);
|
|
|
|
if (atomic_dec_and_test(&super->s_pending_writes))
|
|
|
|
wake_up(&wq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_erase(struct super_block *sb, u64 ofs, pgoff_t index,
|
|
|
|
size_t nr_pages)
|
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(sb);
|
|
|
|
struct bio *bio;
|
2012-07-22 23:02:11 -06:00
|
|
|
unsigned int max_pages;
|
2010-03-04 13:30:58 -07:00
|
|
|
int i;
|
|
|
|
|
2015-11-05 19:43:49 -07:00
|
|
|
max_pages = min_t(size_t, nr_pages, BIO_MAX_PAGES);
|
2012-07-22 23:02:11 -06:00
|
|
|
|
2010-03-04 13:30:58 -07:00
|
|
|
bio = bio_alloc(GFP_NOFS, max_pages);
|
2010-03-17 06:47:45 -06:00
|
|
|
BUG_ON(!bio);
|
2010-03-04 13:30:58 -07:00
|
|
|
|
|
|
|
for (i = 0; i < nr_pages; i++) {
|
|
|
|
if (i >= max_pages) {
|
|
|
|
/* Block layer cannot split bios :( */
|
|
|
|
bio->bi_vcnt = i;
|
2013-10-11 16:44:27 -06:00
|
|
|
bio->bi_iter.bi_size = i * PAGE_SIZE;
|
2010-03-04 13:30:58 -07:00
|
|
|
bio->bi_bdev = super->s_bdev;
|
2013-10-11 16:44:27 -06:00
|
|
|
bio->bi_iter.bi_sector = ofs >> 9;
|
2010-03-04 13:30:58 -07:00
|
|
|
bio->bi_private = sb;
|
|
|
|
bio->bi_end_io = erase_end_io;
|
|
|
|
atomic_inc(&super->s_pending_writes);
|
|
|
|
submit_bio(WRITE, bio);
|
|
|
|
|
|
|
|
ofs += i * PAGE_SIZE;
|
|
|
|
index += i;
|
|
|
|
nr_pages -= i;
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
bio = bio_alloc(GFP_NOFS, max_pages);
|
|
|
|
BUG_ON(!bio);
|
|
|
|
}
|
|
|
|
bio->bi_io_vec[i].bv_page = super->s_erase_page;
|
|
|
|
bio->bi_io_vec[i].bv_len = PAGE_SIZE;
|
|
|
|
bio->bi_io_vec[i].bv_offset = 0;
|
|
|
|
}
|
|
|
|
bio->bi_vcnt = nr_pages;
|
2013-10-11 16:44:27 -06:00
|
|
|
bio->bi_iter.bi_size = nr_pages * PAGE_SIZE;
|
2010-03-04 13:30:58 -07:00
|
|
|
bio->bi_bdev = super->s_bdev;
|
2013-10-11 16:44:27 -06:00
|
|
|
bio->bi_iter.bi_sector = ofs >> 9;
|
2010-03-04 13:30:58 -07:00
|
|
|
bio->bi_private = sb;
|
|
|
|
bio->bi_end_io = erase_end_io;
|
|
|
|
atomic_inc(&super->s_pending_writes);
|
|
|
|
submit_bio(WRITE, bio);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bdev_erase(struct super_block *sb, loff_t to, size_t len,
|
|
|
|
int ensure_write)
|
2009-11-20 12:13:39 -07:00
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(sb);
|
|
|
|
|
|
|
|
BUG_ON(to & (PAGE_SIZE - 1));
|
|
|
|
BUG_ON(len & (PAGE_SIZE - 1));
|
|
|
|
|
2010-03-04 13:30:58 -07:00
|
|
|
if (super->s_flags & LOGFS_SB_FLAG_RO)
|
2009-11-20 12:13:39 -07:00
|
|
|
return -EROFS;
|
|
|
|
|
2010-03-04 13:30:58 -07:00
|
|
|
if (ensure_write) {
|
|
|
|
/*
|
|
|
|
* Object store doesn't care whether erases happen or not.
|
|
|
|
* But for the journal they are required. Otherwise a scan
|
|
|
|
* can find an old commit entry and assume it is the current
|
|
|
|
* one, travelling back in time.
|
|
|
|
*/
|
|
|
|
do_erase(sb, to, to >> PAGE_SHIFT, len >> PAGE_SHIFT);
|
2009-11-20 12:13:39 -07:00
|
|
|
}
|
2010-03-04 13:30:58 -07:00
|
|
|
|
2009-11-20 12:13:39 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bdev_sync(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(sb);
|
|
|
|
|
|
|
|
wait_event(wq, atomic_read(&super->s_pending_writes) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct page *bdev_find_first_sb(struct super_block *sb, u64 *ofs)
|
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(sb);
|
|
|
|
struct address_space *mapping = super->s_mapping_inode->i_mapping;
|
|
|
|
filler_t *filler = bdev_readpage;
|
|
|
|
|
|
|
|
*ofs = 0;
|
|
|
|
return read_cache_page(mapping, 0, filler, sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct page *bdev_find_last_sb(struct super_block *sb, u64 *ofs)
|
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(sb);
|
|
|
|
struct address_space *mapping = super->s_mapping_inode->i_mapping;
|
|
|
|
filler_t *filler = bdev_readpage;
|
|
|
|
u64 pos = (super->s_bdev->bd_inode->i_size & ~0xfffULL) - 0x1000;
|
|
|
|
pgoff_t index = pos >> PAGE_SHIFT;
|
|
|
|
|
|
|
|
*ofs = pos;
|
|
|
|
return read_cache_page(mapping, index, filler, sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bdev_write_sb(struct super_block *sb, struct page *page)
|
|
|
|
{
|
|
|
|
struct block_device *bdev = logfs_super(sb)->s_bdev;
|
|
|
|
|
|
|
|
/* Nothing special to do for block devices. */
|
|
|
|
return sync_request(page, bdev, WRITE);
|
|
|
|
}
|
|
|
|
|
2010-07-26 02:06:00 -06:00
|
|
|
static void bdev_put_device(struct logfs_super *s)
|
2009-11-20 12:13:39 -07:00
|
|
|
{
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 03:55:17 -07:00
|
|
|
blkdev_put(s->s_bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
|
2009-11-20 12:13:39 -07:00
|
|
|
}
|
|
|
|
|
2010-05-07 11:38:40 -06:00
|
|
|
static int bdev_can_write_buf(struct super_block *sb, u64 ofs)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-20 12:13:39 -07:00
|
|
|
static const struct logfs_device_ops bd_devops = {
|
|
|
|
.find_first_sb = bdev_find_first_sb,
|
|
|
|
.find_last_sb = bdev_find_last_sb,
|
|
|
|
.write_sb = bdev_write_sb,
|
|
|
|
.readpage = bdev_readpage,
|
|
|
|
.writeseg = bdev_writeseg,
|
|
|
|
.erase = bdev_erase,
|
2010-05-07 11:38:40 -06:00
|
|
|
.can_write_buf = bdev_can_write_buf,
|
2009-11-20 12:13:39 -07:00
|
|
|
.sync = bdev_sync,
|
|
|
|
.put_device = bdev_put_device,
|
|
|
|
};
|
|
|
|
|
2010-07-26 01:53:30 -06:00
|
|
|
int logfs_get_sb_bdev(struct logfs_super *p, struct file_system_type *type,
|
|
|
|
const char *devname)
|
2009-11-20 12:13:39 -07:00
|
|
|
{
|
|
|
|
struct block_device *bdev;
|
|
|
|
|
2010-11-13 03:55:18 -07:00
|
|
|
bdev = blkdev_get_by_path(devname, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
|
|
|
|
type);
|
2010-07-26 01:53:30 -06:00
|
|
|
if (IS_ERR(bdev))
|
2009-11-20 12:13:39 -07:00
|
|
|
return PTR_ERR(bdev);
|
|
|
|
|
|
|
|
if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {
|
|
|
|
int mtdnr = MINOR(bdev->bd_dev);
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 03:55:17 -07:00
|
|
|
blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
|
2010-07-26 01:53:30 -06:00
|
|
|
return logfs_get_sb_mtd(p, mtdnr);
|
2009-11-20 12:13:39 -07:00
|
|
|
}
|
|
|
|
|
2010-07-26 01:33:39 -06:00
|
|
|
p->s_bdev = bdev;
|
|
|
|
p->s_mtd = NULL;
|
|
|
|
p->s_devops = &bd_devops;
|
2010-07-26 01:53:30 -06:00
|
|
|
return 0;
|
2009-11-20 12:13:39 -07:00
|
|
|
}
|