Commit afe7e3a9 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] (1/6) blksize_size[] removal

 - preliminary cleanups: make sure that swapoff restores original block
   size, kill set_blocksize() (and use of __bread()) in multipath.c,
   reorder opening device and finding its block size in mtdblock.c.
parent afae6f7c
...@@ -738,43 +738,56 @@ static int __check_consistency (mddev_t *mddev, int row) ...@@ -738,43 +738,56 @@ static int __check_consistency (mddev_t *mddev, int row)
{ {
multipath_conf_t *conf = mddev_to_conf(mddev); multipath_conf_t *conf = mddev_to_conf(mddev);
int disks = MD_SB_DISKS; int disks = MD_SB_DISKS;
kdev_t dev;
struct block_device *bdev; struct block_device *bdev;
struct buffer_head *bh = NULL;
int i, rc = 0; int i, rc = 0;
char *buffer = NULL; char *buffer;
struct page *page = NULL;
int first = 1;
int order = PAGE_CACHE_SHIFT-PAGE_SHIFT;
buffer = (char *) __get_free_pages(GFP_KERNEL, order);
if (!buffer)
return rc;
for (i = 0; i < disks; i++) { for (i = 0; i < disks; i++) {
struct address_space *mapping;
char *p;
if (!conf->multipaths[i].operational) if (!conf->multipaths[i].operational)
continue; continue;
printk("(checking disk %d)\n",i); printk("(checking disk %d)\n",i);
dev = conf->multipaths[i].dev;
bdev = conf->multipaths[i].bdev; bdev = conf->multipaths[i].bdev;
set_blocksize(dev, 4096); mapping = bdev->bd_inode->i_mapping;
if ((bh = __bread(bdev, row / 4, 4096)) == NULL) page = read_cache_page(mapping, row/(PAGE_CACHE_SIZE/1024),
(filler_t *)mapping->a_ops->readpage, NULL);
if (IS_ERR(page)) {
page = NULL;
break; break;
if (!buffer) { }
buffer = (char *) __get_free_page(GFP_KERNEL); wait_on_page_locked(page);
if (!buffer) if (!PageUptodate(page))
break; break;
memcpy(buffer, bh->b_data, 4096); if (PageError(page))
} else if (memcmp(buffer, bh->b_data, 4096)) { break;
p = page_address(page);
if (first) {
memcpy(buffer, p, PAGE_CACHE_SIZE);
first = 0;
} else if (memcmp(buffer, p, PAGE_CACHE_SIZE)) {
rc = 1; rc = 1;
break; break;
} }
bforget(bh); page_cache_release(page);
fsync_bdev(bdev); fsync_bdev(bdev);
invalidate_bdev(bdev, 0); invalidate_bdev(bdev, 0);
bh = NULL; page = NULL;
} }
if (buffer) if (page) {
free_page((unsigned long) buffer); bdev = page->mapping->host->i_bdev;
if (bh) { page_cache_release(page);
bdev = bh->b_bdev;
bforget(bh);
fsync_bdev(bdev); fsync_bdev(bdev);
invalidate_bdev(bdev, 0); invalidate_bdev(bdev, 0);
} }
free_pages((unsigned long) buffer, order);
return rc; return rc;
} }
......
...@@ -1062,6 +1062,7 @@ static int __init init_blkmtd(void) ...@@ -1062,6 +1062,7 @@ static int __init init_blkmtd(void)
int readonly = 0; int readonly = 0;
int erase_size = CONFIG_MTD_BLKDEV_ERASESIZE; int erase_size = CONFIG_MTD_BLKDEV_ERASESIZE;
kdev_t rdev; kdev_t rdev;
struct block_device *bdev;
int err; int err;
int mode; int mode;
int regions; int regions;
...@@ -1127,8 +1128,13 @@ static int __init init_blkmtd(void) ...@@ -1127,8 +1128,13 @@ static int __init init_blkmtd(void)
printk("blkmtd: attempting to use an MTD device as a block device\n"); printk("blkmtd: attempting to use an MTD device as a block device\n");
return 1; return 1;
} }
/* get the block device */
bdev = bdget(kdev_t_to_nr(mk_kdev(maj, min)));
err = blkdev_get(bdev, mode, 0, BDEV_RAW);
if (err)
return 1;
DEBUG(1, "blkmtd: devname = %s\n", __bdevname(rdev)); DEBUG(1, "blkmtd: devname = %s\n", bdevname(bdev));
blocksize = BLOCK_SIZE; blocksize = BLOCK_SIZE;
blocksize = bs ? bs : block_size(rdev); blocksize = bs ? bs : block_size(rdev);
...@@ -1139,27 +1145,24 @@ static int __init init_blkmtd(void) ...@@ -1139,27 +1145,24 @@ static int __init init_blkmtd(void)
i >>= 1; i >>= 1;
} }
size = (count ? count*blocksize : blkdev_size_in_bytes(rdev)); size = count ? count*blocksize : bdev->bd_inode->i_size;
DEBUG(1, "blkmtd: size = %ld\n", (long int)size); DEBUG(1, "blkmtd: size = %ld\n", (long int)size);
if(size == 0) { if(size == 0) {
printk("blkmtd: cant determine size\n"); printk("blkmtd: cant determine size\n");
blkdev_put(bdev, BDEV_RAW);
return 1; return 1;
} }
mtd_rawdevice = (mtd_raw_dev_data_t *)kmalloc(sizeof(mtd_raw_dev_data_t), GFP_KERNEL); mtd_rawdevice = (mtd_raw_dev_data_t *)kmalloc(sizeof(mtd_raw_dev_data_t), GFP_KERNEL);
if(mtd_rawdevice == NULL) { if(mtd_rawdevice == NULL) {
blkdev_put(bdev, BDEV_RAW);
err = -ENOMEM; err = -ENOMEM;
goto init_err; goto init_err;
} }
memset(mtd_rawdevice, 0, sizeof(mtd_raw_dev_data_t)); memset(mtd_rawdevice, 0, sizeof(mtd_raw_dev_data_t));
/* get the block device */ mtd_rawdevice->binding = bdev;
mtd_rawdevice->binding = bdget(kdev_t_to_nr(mk_kdev(maj, min)));
err = blkdev_get(mtd_rawdevice->binding, mode, 0, BDEV_RAW);
if (err) {
goto init_err;
}
mtd_rawdevice->totalsize = size; mtd_rawdevice->totalsize = size;
mtd_rawdevice->sector_size = blocksize; mtd_rawdevice->sector_size = blocksize;
mtd_rawdevice->sector_bits = blocksize_bits; mtd_rawdevice->sector_bits = blocksize_bits;
......
...@@ -79,6 +79,7 @@ struct swap_info_struct { ...@@ -79,6 +79,7 @@ struct swap_info_struct {
unsigned int flags; unsigned int flags;
spinlock_t sdev_lock; spinlock_t sdev_lock;
struct file *swap_file; struct file *swap_file;
unsigned old_block_size;
unsigned short * swap_map; unsigned short * swap_map;
unsigned int lowest_bit; unsigned int lowest_bit;
unsigned int highest_bit; unsigned int highest_bit;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/shm.h> #include <linux/shm.h>
#include <linux/blkdev.h>
#include <linux/compiler.h> #include <linux/compiler.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
...@@ -787,8 +788,12 @@ asmlinkage long sys_swapoff(const char * specialfile) ...@@ -787,8 +788,12 @@ asmlinkage long sys_swapoff(const char * specialfile)
swap_device_unlock(p); swap_device_unlock(p);
swap_list_unlock(); swap_list_unlock();
vfree(swap_map); vfree(swap_map);
if (S_ISBLK(swap_file->f_dentry->d_inode->i_mode)) if (S_ISBLK(swap_file->f_dentry->d_inode->i_mode)) {
bd_release(swap_file->f_dentry->d_inode->i_bdev); struct block_device *bdev;
bdev = swap_file->f_dentry->d_inode->i_bdev;
set_blocksize(to_kdev_t(bdev->bd_dev), p->old_block_size);
bd_release(bdev);
}
filp_close(swap_file, NULL); filp_close(swap_file, NULL);
err = 0; err = 0;
...@@ -879,6 +884,7 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags) ...@@ -879,6 +884,7 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
nr_swapfiles = type+1; nr_swapfiles = type+1;
p->flags = SWP_USED; p->flags = SWP_USED;
p->swap_file = NULL; p->swap_file = NULL;
p->old_block_size = 0;
p->swap_map = NULL; p->swap_map = NULL;
p->lowest_bit = 0; p->lowest_bit = 0;
p->highest_bit = 0; p->highest_bit = 0;
...@@ -914,6 +920,7 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags) ...@@ -914,6 +920,7 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
bdev = NULL; bdev = NULL;
goto bad_swap; goto bad_swap;
} }
p->old_block_size = block_size(to_kdev_t(bdev->bd_dev));
error = set_blocksize(swap_file->f_dentry->d_inode->i_rdev, error = set_blocksize(swap_file->f_dentry->d_inode->i_rdev,
PAGE_SIZE); PAGE_SIZE);
if (error < 0) if (error < 0)
...@@ -1066,8 +1073,10 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags) ...@@ -1066,8 +1073,10 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
error = 0; error = 0;
goto out; goto out;
bad_swap: bad_swap:
if (bdev) if (bdev) {
set_blocksize(to_kdev_t(bdev->bd_dev), p->old_block_size);
bd_release(bdev); bd_release(bdev);
}
bad_swap_2: bad_swap_2:
swap_list_lock(); swap_list_lock();
swap_map = p->swap_map; swap_map = p->swap_map;
......
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