sys_swapon: separate parsing of bad blocks and extents
Move the code which parses the bad block list and the extents to a separate function. Only code movement, no functional changes. This change uses the fact that, after the success path, nr_good_pages == p->pages. Signed-off-by: Cesar Eduardo Barros <cesarb@cesarb.net> Tested-by: Eric B Munson <emunson@mgebm.net> Acked-by: Eric B Munson <emunson@mgebm.net> Reviewed-by: Pekka Enberg <penberg@kernel.org> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Родитель
1421ef3cd1
Коммит
915d4d7bc0
|
@ -1991,6 +1991,54 @@ static unsigned long read_swap_header(struct swap_info_struct *p,
|
||||||
return maxpages;
|
return maxpages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int setup_swap_map_and_extents(struct swap_info_struct *p,
|
||||||
|
union swap_header *swap_header,
|
||||||
|
unsigned char *swap_map,
|
||||||
|
unsigned long maxpages,
|
||||||
|
sector_t *span)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int error;
|
||||||
|
unsigned int nr_good_pages;
|
||||||
|
int nr_extents;
|
||||||
|
|
||||||
|
nr_good_pages = maxpages - 1; /* omit header page */
|
||||||
|
|
||||||
|
for (i = 0; i < swap_header->info.nr_badpages; i++) {
|
||||||
|
unsigned int page_nr = swap_header->info.badpages[i];
|
||||||
|
if (page_nr == 0 || page_nr > swap_header->info.last_page) {
|
||||||
|
error = -EINVAL;
|
||||||
|
goto bad_swap;
|
||||||
|
}
|
||||||
|
if (page_nr < maxpages) {
|
||||||
|
swap_map[page_nr] = SWAP_MAP_BAD;
|
||||||
|
nr_good_pages--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nr_good_pages) {
|
||||||
|
swap_map[0] = SWAP_MAP_BAD;
|
||||||
|
p->max = maxpages;
|
||||||
|
p->pages = nr_good_pages;
|
||||||
|
nr_extents = setup_swap_extents(p, span);
|
||||||
|
if (nr_extents < 0) {
|
||||||
|
error = nr_extents;
|
||||||
|
goto bad_swap;
|
||||||
|
}
|
||||||
|
nr_good_pages = p->pages;
|
||||||
|
}
|
||||||
|
if (!nr_good_pages) {
|
||||||
|
printk(KERN_WARNING "Empty swap-file\n");
|
||||||
|
error = -EINVAL;
|
||||||
|
goto bad_swap;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nr_extents;
|
||||||
|
|
||||||
|
bad_swap:
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
|
SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
|
||||||
{
|
{
|
||||||
struct swap_info_struct *p;
|
struct swap_info_struct *p;
|
||||||
|
@ -2001,7 +2049,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
|
||||||
int error;
|
int error;
|
||||||
union swap_header *swap_header;
|
union swap_header *swap_header;
|
||||||
unsigned int nr_good_pages;
|
unsigned int nr_good_pages;
|
||||||
int nr_extents = 0;
|
int nr_extents;
|
||||||
sector_t span;
|
sector_t span;
|
||||||
unsigned long maxpages;
|
unsigned long maxpages;
|
||||||
unsigned char *swap_map = NULL;
|
unsigned char *swap_map = NULL;
|
||||||
|
@ -2078,36 +2126,13 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
|
||||||
if (error)
|
if (error)
|
||||||
goto bad_swap;
|
goto bad_swap;
|
||||||
|
|
||||||
nr_good_pages = maxpages - 1; /* omit header page */
|
nr_extents = setup_swap_map_and_extents(p, swap_header, swap_map,
|
||||||
|
maxpages, &span);
|
||||||
for (i = 0; i < swap_header->info.nr_badpages; i++) {
|
if (unlikely(nr_extents < 0)) {
|
||||||
unsigned int page_nr = swap_header->info.badpages[i];
|
|
||||||
if (page_nr == 0 || page_nr > swap_header->info.last_page) {
|
|
||||||
error = -EINVAL;
|
|
||||||
goto bad_swap;
|
|
||||||
}
|
|
||||||
if (page_nr < maxpages) {
|
|
||||||
swap_map[page_nr] = SWAP_MAP_BAD;
|
|
||||||
nr_good_pages--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nr_good_pages) {
|
|
||||||
swap_map[0] = SWAP_MAP_BAD;
|
|
||||||
p->max = maxpages;
|
|
||||||
p->pages = nr_good_pages;
|
|
||||||
nr_extents = setup_swap_extents(p, &span);
|
|
||||||
if (nr_extents < 0) {
|
|
||||||
error = nr_extents;
|
error = nr_extents;
|
||||||
goto bad_swap;
|
goto bad_swap;
|
||||||
}
|
}
|
||||||
nr_good_pages = p->pages;
|
nr_good_pages = p->pages;
|
||||||
}
|
|
||||||
if (!nr_good_pages) {
|
|
||||||
printk(KERN_WARNING "Empty swap-file\n");
|
|
||||||
error = -EINVAL;
|
|
||||||
goto bad_swap;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p->bdev) {
|
if (p->bdev) {
|
||||||
if (blk_queue_nonrot(bdev_get_queue(p->bdev))) {
|
if (blk_queue_nonrot(bdev_get_queue(p->bdev))) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче