License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 21:07:57 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* linux/fs/ufs/balloc.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998
|
|
|
|
* Daniel Pirkl <daniel.pirkl@email.cz>
|
|
|
|
* Charles University, Faculty of Mathematics and Physics
|
2007-02-12 15:54:32 +07:00
|
|
|
*
|
|
|
|
* UFS2 write support Evgeniy Dushistov <dushistov@mail.ru>, 2007
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/buffer_head.h>
|
2006-01-12 03:17:46 +07:00
|
|
|
#include <linux/capability.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/bitops.h>
|
2016-11-01 20:40:13 +07:00
|
|
|
#include <linux/bio.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/byteorder.h>
|
|
|
|
|
2008-02-08 19:21:31 +07:00
|
|
|
#include "ufs_fs.h"
|
2007-10-17 13:26:51 +07:00
|
|
|
#include "ufs.h"
|
2005-04-17 05:20:36 +07:00
|
|
|
#include "swab.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
#define INVBLOCK ((u64)-1L)
|
|
|
|
|
2014-06-07 04:36:33 +07:00
|
|
|
static u64 ufs_add_fragments(struct inode *, u64, unsigned, unsigned);
|
2007-02-12 15:54:32 +07:00
|
|
|
static u64 ufs_alloc_fragments(struct inode *, unsigned, u64, unsigned, int *);
|
|
|
|
static u64 ufs_alloccg_block(struct inode *, struct ufs_cg_private_info *, u64, int *);
|
|
|
|
static u64 ufs_bitmap_search (struct super_block *, struct ufs_cg_private_info *, u64, unsigned);
|
2005-04-17 05:20:36 +07:00
|
|
|
static unsigned char ufs_fragtable_8fpb[], ufs_fragtable_other[];
|
|
|
|
static void ufs_clusteracct(struct super_block *, struct ufs_cg_private_info *, unsigned, int);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free 'count' fragments from fragment number 'fragment'
|
|
|
|
*/
|
2007-02-12 15:54:32 +07:00
|
|
|
void ufs_free_fragments(struct inode *inode, u64 fragment, unsigned count)
|
2006-06-25 19:47:20 +07:00
|
|
|
{
|
2005-04-17 05:20:36 +07:00
|
|
|
struct super_block * sb;
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_cg_private_info * ucpi;
|
|
|
|
struct ufs_cylinder_group * ucg;
|
2007-02-12 15:54:32 +07:00
|
|
|
unsigned cgno, bit, end_bit, bbase, blkmap, i;
|
|
|
|
u64 blkno;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
sb = inode->i_sb;
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("ENTER, fragment %llu, count %u\n",
|
|
|
|
(unsigned long long)fragment, count);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (ufs_fragnum(fragment) + count > uspi->s_fpg)
|
|
|
|
ufs_error (sb, "ufs_free_fragments", "internal error");
|
2015-06-10 07:09:32 +07:00
|
|
|
|
|
|
|
mutex_lock(&UFS_SB(sb)->s_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
cgno = ufs_dtog(uspi, fragment);
|
|
|
|
bit = ufs_dtogd(uspi, fragment);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (cgno >= uspi->s_ncg) {
|
|
|
|
ufs_panic (sb, "ufs_free_fragments", "freeing blocks are outside device");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
ucpi = ufs_load_cylinder (sb, cgno);
|
|
|
|
if (!ucpi)
|
|
|
|
goto failed;
|
2006-06-25 19:47:22 +07:00
|
|
|
ucg = ubh_get_ucg (UCPI_UBH(ucpi));
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!ufs_cg_chkmagic(sb, ucg)) {
|
|
|
|
ufs_panic (sb, "ufs_free_fragments", "internal error, bad magic number on cg %u", cgno);
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
end_bit = bit + count;
|
|
|
|
bbase = ufs_blknum (bit);
|
2006-06-25 19:47:22 +07:00
|
|
|
blkmap = ubh_blkmap (UCPI_UBH(ucpi), ucpi->c_freeoff, bbase);
|
2005-04-17 05:20:36 +07:00
|
|
|
ufs_fragacct (sb, blkmap, ucg->cg_frsum, -1);
|
|
|
|
for (i = bit; i < end_bit; i++) {
|
2006-06-25 19:47:22 +07:00
|
|
|
if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_freeoff, i))
|
|
|
|
ubh_setbit (UCPI_UBH(ucpi), ucpi->c_freeoff, i);
|
2006-01-14 15:42:06 +07:00
|
|
|
else
|
|
|
|
ufs_error (sb, "ufs_free_fragments",
|
|
|
|
"bit already cleared for fragment %u", i);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2017-06-09 08:15:03 +07:00
|
|
|
|
|
|
|
inode_sub_bytes(inode, count << uspi->s_fshift);
|
2005-04-17 05:20:36 +07:00
|
|
|
fs32_add(sb, &ucg->cg_cs.cs_nffree, count);
|
2006-06-25 19:47:30 +07:00
|
|
|
uspi->cs_total.cs_nffree += count;
|
2005-04-17 05:20:36 +07:00
|
|
|
fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, count);
|
2006-06-25 19:47:22 +07:00
|
|
|
blkmap = ubh_blkmap (UCPI_UBH(ucpi), ucpi->c_freeoff, bbase);
|
2005-04-17 05:20:36 +07:00
|
|
|
ufs_fragacct(sb, blkmap, ucg->cg_frsum, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trying to reassemble free fragments into block
|
|
|
|
*/
|
|
|
|
blkno = ufs_fragstoblks (bbase);
|
2006-06-25 19:47:22 +07:00
|
|
|
if (ubh_isblockset(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno)) {
|
2005-04-17 05:20:36 +07:00
|
|
|
fs32_sub(sb, &ucg->cg_cs.cs_nffree, uspi->s_fpb);
|
2006-06-25 19:47:30 +07:00
|
|
|
uspi->cs_total.cs_nffree -= uspi->s_fpb;
|
2005-04-17 05:20:36 +07:00
|
|
|
fs32_sub(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, uspi->s_fpb);
|
|
|
|
if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
|
|
|
|
ufs_clusteracct (sb, ucpi, blkno, 1);
|
|
|
|
fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1);
|
2006-06-25 19:47:30 +07:00
|
|
|
uspi->cs_total.cs_nbfree++;
|
2005-04-17 05:20:36 +07:00
|
|
|
fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nbfree, 1);
|
2007-02-12 15:54:32 +07:00
|
|
|
if (uspi->fs_magic != UFS2_MAGIC) {
|
|
|
|
unsigned cylno = ufs_cbtocylno (bbase);
|
|
|
|
|
|
|
|
fs16_add(sb, &ubh_cg_blks(ucpi, cylno,
|
|
|
|
ufs_cbtorpos(bbase)), 1);
|
|
|
|
fs32_add(sb, &ubh_cg_blktot(ucpi, cylno), 1);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2006-06-25 19:47:22 +07:00
|
|
|
ubh_mark_buffer_dirty (USPI_UBH(uspi));
|
|
|
|
ubh_mark_buffer_dirty (UCPI_UBH(ucpi));
|
2017-11-28 04:05:09 +07:00
|
|
|
if (sb->s_flags & SB_SYNCHRONOUS)
|
2010-08-11 22:06:24 +07:00
|
|
|
ubh_sync_block(UCPI_UBH(ucpi));
|
2012-07-12 20:28:08 +07:00
|
|
|
ufs_mark_sb_dirty(sb);
|
2015-06-10 07:09:32 +07:00
|
|
|
|
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2006-06-25 19:47:24 +07:00
|
|
|
UFSD("EXIT\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
failed:
|
2015-06-10 07:09:32 +07:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2006-06-25 19:47:24 +07:00
|
|
|
UFSD("EXIT (FAILED)\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free 'count' fragments from fragment number 'fragment' (free whole blocks)
|
|
|
|
*/
|
2007-02-12 15:54:32 +07:00
|
|
|
void ufs_free_blocks(struct inode *inode, u64 fragment, unsigned count)
|
2006-06-25 19:47:20 +07:00
|
|
|
{
|
2005-04-17 05:20:36 +07:00
|
|
|
struct super_block * sb;
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_cg_private_info * ucpi;
|
|
|
|
struct ufs_cylinder_group * ucg;
|
2007-02-12 15:54:32 +07:00
|
|
|
unsigned overflow, cgno, bit, end_bit, i;
|
|
|
|
u64 blkno;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
sb = inode->i_sb;
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("ENTER, fragment %llu, count %u\n",
|
|
|
|
(unsigned long long)fragment, count);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if ((fragment & uspi->s_fpbmask) || (count & uspi->s_fpbmask)) {
|
|
|
|
ufs_error (sb, "ufs_free_blocks", "internal error, "
|
2007-02-12 15:54:32 +07:00
|
|
|
"fragment %llu, count %u\n",
|
|
|
|
(unsigned long long)fragment, count);
|
2005-04-17 05:20:36 +07:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2015-06-10 07:09:32 +07:00
|
|
|
mutex_lock(&UFS_SB(sb)->s_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
do_more:
|
|
|
|
overflow = 0;
|
2007-02-12 15:54:32 +07:00
|
|
|
cgno = ufs_dtog(uspi, fragment);
|
|
|
|
bit = ufs_dtogd(uspi, fragment);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (cgno >= uspi->s_ncg) {
|
|
|
|
ufs_panic (sb, "ufs_free_blocks", "freeing blocks are outside device");
|
2006-06-25 19:47:26 +07:00
|
|
|
goto failed_unlock;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
end_bit = bit + count;
|
|
|
|
if (end_bit > uspi->s_fpg) {
|
|
|
|
overflow = bit + count - uspi->s_fpg;
|
|
|
|
count -= overflow;
|
|
|
|
end_bit -= overflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
ucpi = ufs_load_cylinder (sb, cgno);
|
|
|
|
if (!ucpi)
|
2006-06-25 19:47:26 +07:00
|
|
|
goto failed_unlock;
|
2006-06-25 19:47:22 +07:00
|
|
|
ucg = ubh_get_ucg (UCPI_UBH(ucpi));
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!ufs_cg_chkmagic(sb, ucg)) {
|
|
|
|
ufs_panic (sb, "ufs_free_blocks", "internal error, bad magic number on cg %u", cgno);
|
2006-06-25 19:47:26 +07:00
|
|
|
goto failed_unlock;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = bit; i < end_bit; i += uspi->s_fpb) {
|
|
|
|
blkno = ufs_fragstoblks(i);
|
2006-06-25 19:47:22 +07:00
|
|
|
if (ubh_isblockset(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno)) {
|
2005-04-17 05:20:36 +07:00
|
|
|
ufs_error(sb, "ufs_free_blocks", "freeing free fragment");
|
|
|
|
}
|
2006-06-25 19:47:22 +07:00
|
|
|
ubh_setblock(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno);
|
2017-06-09 08:15:03 +07:00
|
|
|
inode_sub_bytes(inode, uspi->s_fpb << uspi->s_fshift);
|
2005-04-17 05:20:36 +07:00
|
|
|
if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
|
|
|
|
ufs_clusteracct (sb, ucpi, blkno, 1);
|
|
|
|
|
|
|
|
fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1);
|
2006-06-25 19:47:30 +07:00
|
|
|
uspi->cs_total.cs_nbfree++;
|
2005-04-17 05:20:36 +07:00
|
|
|
fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nbfree, 1);
|
2007-02-12 15:54:32 +07:00
|
|
|
|
|
|
|
if (uspi->fs_magic != UFS2_MAGIC) {
|
|
|
|
unsigned cylno = ufs_cbtocylno(i);
|
|
|
|
|
|
|
|
fs16_add(sb, &ubh_cg_blks(ucpi, cylno,
|
|
|
|
ufs_cbtorpos(i)), 1);
|
|
|
|
fs32_add(sb, &ubh_cg_blktot(ucpi, cylno), 1);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2006-06-25 19:47:22 +07:00
|
|
|
ubh_mark_buffer_dirty (USPI_UBH(uspi));
|
|
|
|
ubh_mark_buffer_dirty (UCPI_UBH(ucpi));
|
2017-11-28 04:05:09 +07:00
|
|
|
if (sb->s_flags & SB_SYNCHRONOUS)
|
2010-08-11 22:06:24 +07:00
|
|
|
ubh_sync_block(UCPI_UBH(ucpi));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (overflow) {
|
|
|
|
fragment += count;
|
|
|
|
count = overflow;
|
|
|
|
goto do_more;
|
|
|
|
}
|
|
|
|
|
2012-07-12 20:28:08 +07:00
|
|
|
ufs_mark_sb_dirty(sb);
|
2015-06-10 07:09:32 +07:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2006-06-25 19:47:24 +07:00
|
|
|
UFSD("EXIT\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
|
2006-06-25 19:47:26 +07:00
|
|
|
failed_unlock:
|
2015-06-10 07:09:32 +07:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2006-06-25 19:47:26 +07:00
|
|
|
failed:
|
2006-06-25 19:47:24 +07:00
|
|
|
UFSD("EXIT (FAILED)\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-06-25 19:47:20 +07:00
|
|
|
/*
|
|
|
|
* Modify inode page cache in such way:
|
|
|
|
* have - blocks with b_blocknr equal to oldb...oldb+count-1
|
|
|
|
* get - blocks with b_blocknr equal to newb...newb+count-1
|
|
|
|
* also we suppose that oldb...oldb+count-1 blocks
|
|
|
|
* situated at the end of file.
|
|
|
|
*
|
|
|
|
* We can come here from ufs_writepage or ufs_prepare_write,
|
|
|
|
* locked_page is argument of these functions, so we already lock it.
|
|
|
|
*/
|
2007-03-17 04:38:08 +07:00
|
|
|
static void ufs_change_blocknr(struct inode *inode, sector_t beg,
|
|
|
|
unsigned int count, sector_t oldb,
|
|
|
|
sector_t newb, struct page *locked_page)
|
2006-06-25 19:47:20 +07:00
|
|
|
{
|
2007-03-17 04:38:08 +07:00
|
|
|
const unsigned blks_per_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 19:29:47 +07:00
|
|
|
1 << (PAGE_SHIFT - inode->i_blkbits);
|
2007-03-17 04:38:08 +07:00
|
|
|
const unsigned mask = blks_per_page - 1;
|
2007-01-30 04:19:56 +07:00
|
|
|
struct address_space * const mapping = inode->i_mapping;
|
2007-03-17 04:38:08 +07:00
|
|
|
pgoff_t index, cur_index, last_index;
|
|
|
|
unsigned pos, j, lblock;
|
|
|
|
sector_t end, i;
|
2006-06-25 19:47:20 +07:00
|
|
|
struct page *page;
|
|
|
|
struct buffer_head *head, *bh;
|
|
|
|
|
2007-03-17 04:38:08 +07:00
|
|
|
UFSD("ENTER, ino %lu, count %u, oldb %llu, newb %llu\n",
|
|
|
|
inode->i_ino, count,
|
|
|
|
(unsigned long long)oldb, (unsigned long long)newb);
|
2006-06-25 19:47:20 +07:00
|
|
|
|
2007-01-30 04:19:54 +07:00
|
|
|
BUG_ON(!locked_page);
|
2006-06-25 19:47:20 +07:00
|
|
|
BUG_ON(!PageLocked(locked_page));
|
|
|
|
|
2007-01-30 04:19:54 +07:00
|
|
|
cur_index = locked_page->index;
|
2007-03-17 04:38:08 +07:00
|
|
|
end = count + beg;
|
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 19:29:47 +07:00
|
|
|
last_index = end >> (PAGE_SHIFT - inode->i_blkbits);
|
2007-03-17 04:38:08 +07:00
|
|
|
for (i = beg; i < end; i = (i | mask) + 1) {
|
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 19:29:47 +07:00
|
|
|
index = i >> (PAGE_SHIFT - inode->i_blkbits);
|
2006-06-25 19:47:20 +07:00
|
|
|
|
|
|
|
if (likely(cur_index != index)) {
|
|
|
|
page = ufs_get_locked_page(mapping, index);
|
2007-03-17 04:38:08 +07:00
|
|
|
if (!page)/* it was truncated */
|
|
|
|
continue;
|
|
|
|
if (IS_ERR(page)) {/* or EIO */
|
2008-04-28 16:16:17 +07:00
|
|
|
ufs_error(inode->i_sb, __func__,
|
2007-03-17 04:38:08 +07:00
|
|
|
"read of page %llu failed\n",
|
|
|
|
(unsigned long long)index);
|
2006-06-25 19:47:20 +07:00
|
|
|
continue;
|
2007-03-17 04:38:08 +07:00
|
|
|
}
|
2006-06-25 19:47:20 +07:00
|
|
|
} else
|
|
|
|
page = locked_page;
|
|
|
|
|
|
|
|
head = page_buffers(page);
|
|
|
|
bh = head;
|
2007-03-17 04:38:08 +07:00
|
|
|
pos = i & mask;
|
2007-01-30 04:19:56 +07:00
|
|
|
for (j = 0; j < pos; ++j)
|
|
|
|
bh = bh->b_this_page;
|
2007-03-17 04:38:08 +07:00
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(index == last_index))
|
|
|
|
lblock = end & mask;
|
|
|
|
else
|
|
|
|
lblock = blks_per_page;
|
|
|
|
|
2006-06-25 19:47:20 +07:00
|
|
|
do {
|
2007-03-17 04:38:08 +07:00
|
|
|
if (j >= lblock)
|
|
|
|
break;
|
|
|
|
pos = (i - beg) + j;
|
|
|
|
|
|
|
|
if (!buffer_mapped(bh))
|
|
|
|
map_bh(bh, inode->i_sb, oldb + pos);
|
|
|
|
if (!buffer_uptodate(bh)) {
|
2016-06-06 02:31:44 +07:00
|
|
|
ll_rw_block(REQ_OP_READ, 0, 1, &bh);
|
2007-03-17 04:38:08 +07:00
|
|
|
wait_on_buffer(bh);
|
|
|
|
if (!buffer_uptodate(bh)) {
|
2008-04-28 16:16:17 +07:00
|
|
|
ufs_error(inode->i_sb, __func__,
|
2007-03-17 04:38:08 +07:00
|
|
|
"read of block failed\n");
|
|
|
|
break;
|
2007-01-30 04:19:56 +07:00
|
|
|
}
|
2006-06-25 19:47:20 +07:00
|
|
|
}
|
|
|
|
|
2007-03-17 04:38:08 +07:00
|
|
|
UFSD(" change from %llu to %llu, pos %u\n",
|
2008-03-20 07:01:05 +07:00
|
|
|
(unsigned long long)(pos + oldb),
|
|
|
|
(unsigned long long)(pos + newb), pos);
|
2007-03-17 04:38:08 +07:00
|
|
|
|
|
|
|
bh->b_blocknr = newb + pos;
|
2016-11-05 00:08:15 +07:00
|
|
|
clean_bdev_bh_alias(bh);
|
2007-03-17 04:38:08 +07:00
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
++j;
|
2006-06-25 19:47:20 +07:00
|
|
|
bh = bh->b_this_page;
|
|
|
|
} while (bh != head);
|
|
|
|
|
2006-07-01 18:36:24 +07:00
|
|
|
if (likely(cur_index != index))
|
|
|
|
ufs_put_locked_page(page);
|
2006-06-25 19:47:20 +07:00
|
|
|
}
|
2006-06-25 19:47:24 +07:00
|
|
|
UFSD("EXIT\n");
|
2006-06-25 19:47:20 +07:00
|
|
|
}
|
|
|
|
|
[PATCH] fix garbage instead of zeroes in UFS
Looks like this is the problem, which point Al Viro some time ago:
ufs's get_block callback allocates 16k of disk at a time, and links that
entire 16k into the file's metadata. But because get_block is called for only
a single buffer_head (a 2k buffer_head in this case?) we are only able to tell
the VFS that this 2k is buffer_new().
So when ufs_getfrag_block() is later called to map some more data in the file,
and when that data resides within the remaining 14k of this fragment,
ufs_getfrag_block() will incorrectly return a !buffer_new() buffer_head.
I don't see _right_ way to do nullification of whole block, if use inode
page cache, some pages may be outside of inode limits (inode size), and
will be lost; if use blockdev page cache it is possible to zero real data,
if later inode page cache will be used.
The simpliest way, as can I see usage of block device page cache, but not only
mark dirty, but also sync it during "nullification". I use my simple tests
collection, which I used for check that create,open,write,read,close works on
ufs, and I see that this patch makes ufs code 18% slower then before.
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2007-01-06 07:37:04 +07:00
|
|
|
static void ufs_clear_frags(struct inode *inode, sector_t beg, unsigned int n,
|
|
|
|
int sync)
|
|
|
|
{
|
|
|
|
struct buffer_head *bh;
|
|
|
|
sector_t end = beg + n;
|
|
|
|
|
|
|
|
for (; beg < end; ++beg) {
|
|
|
|
bh = sb_getblk(inode->i_sb, beg);
|
|
|
|
lock_buffer(bh);
|
|
|
|
memset(bh->b_data, 0, inode->i_sb->s_blocksize);
|
|
|
|
set_buffer_uptodate(bh);
|
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
unlock_buffer(bh);
|
|
|
|
if (IS_SYNC(inode) || sync)
|
|
|
|
sync_dirty_buffer(bh);
|
|
|
|
brelse(bh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
u64 ufs_new_fragments(struct inode *inode, void *p, u64 fragment,
|
|
|
|
u64 goal, unsigned count, int *err,
|
|
|
|
struct page *locked_page)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct super_block * sb;
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_super_block_first * usb1;
|
2007-02-12 15:54:32 +07:00
|
|
|
unsigned cgno, oldcount, newcount;
|
|
|
|
u64 tmp, request, result;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("ENTER, ino %lu, fragment %llu, goal %llu, count %u\n",
|
|
|
|
inode->i_ino, (unsigned long long)fragment,
|
|
|
|
(unsigned long long)goal, count);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
sb = inode->i_sb;
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
2006-01-14 15:42:06 +07:00
|
|
|
usb1 = ubh_get_usb_first(uspi);
|
2005-04-17 05:20:36 +07:00
|
|
|
*err = -ENOSPC;
|
|
|
|
|
2015-06-10 07:09:32 +07:00
|
|
|
mutex_lock(&UFS_SB(sb)->s_lock);
|
2007-02-12 15:54:32 +07:00
|
|
|
tmp = ufs_data_ptr_to_cpu(sb, p);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (count + ufs_fragnum(fragment) > uspi->s_fpb) {
|
2007-02-12 15:54:32 +07:00
|
|
|
ufs_warning(sb, "ufs_new_fragments", "internal warning"
|
|
|
|
" fragment %llu, count %u",
|
|
|
|
(unsigned long long)fragment, count);
|
2005-04-17 05:20:36 +07:00
|
|
|
count = uspi->s_fpb - ufs_fragnum(fragment);
|
|
|
|
}
|
|
|
|
oldcount = ufs_fragnum (fragment);
|
|
|
|
newcount = oldcount + count;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Somebody else has just allocated our fragments
|
|
|
|
*/
|
|
|
|
if (oldcount) {
|
|
|
|
if (!tmp) {
|
2007-02-12 15:54:32 +07:00
|
|
|
ufs_error(sb, "ufs_new_fragments", "internal error, "
|
|
|
|
"fragment %llu, tmp %llu\n",
|
|
|
|
(unsigned long long)fragment,
|
|
|
|
(unsigned long long)tmp);
|
2015-06-10 07:09:32 +07:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2007-02-12 15:54:32 +07:00
|
|
|
return INVBLOCK;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
if (fragment < UFS_I(inode)->i_lastfrag) {
|
2006-06-25 19:47:24 +07:00
|
|
|
UFSD("EXIT (ALREADY ALLOCATED)\n");
|
2015-06-10 07:09:32 +07:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (tmp) {
|
2006-06-25 19:47:24 +07:00
|
|
|
UFSD("EXIT (ALREADY ALLOCATED)\n");
|
2015-06-10 07:09:32 +07:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There is not enough space for user on the device
|
|
|
|
*/
|
2017-06-15 03:36:29 +07:00
|
|
|
if (unlikely(ufs_freefrags(uspi) <= uspi->s_root_blocks)) {
|
2017-06-15 02:41:17 +07:00
|
|
|
if (!capable(CAP_SYS_RESOURCE)) {
|
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
|
|
|
UFSD("EXIT (FAILED)\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (goal >= uspi->s_size)
|
|
|
|
goal = 0;
|
|
|
|
if (goal == 0)
|
|
|
|
cgno = ufs_inotocg (inode->i_ino);
|
|
|
|
else
|
2007-02-12 15:54:32 +07:00
|
|
|
cgno = ufs_dtog(uspi, goal);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* allocate new fragment
|
|
|
|
*/
|
|
|
|
if (oldcount == 0) {
|
|
|
|
result = ufs_alloc_fragments (inode, cgno, goal, count, err);
|
|
|
|
if (result) {
|
2015-09-09 16:16:39 +07:00
|
|
|
ufs_clear_frags(inode, result + oldcount,
|
|
|
|
newcount - oldcount, locked_page != NULL);
|
2017-06-15 11:17:30 +07:00
|
|
|
*err = 0;
|
2015-06-17 23:02:56 +07:00
|
|
|
write_seqlock(&UFS_I(inode)->meta_lock);
|
2007-02-12 15:54:32 +07:00
|
|
|
ufs_cpu_to_data_ptr(sb, p, result);
|
|
|
|
UFS_I(inode)->i_lastfrag =
|
2011-05-27 06:25:12 +07:00
|
|
|
max(UFS_I(inode)->i_lastfrag, fragment + count);
|
2017-06-15 11:17:30 +07:00
|
|
|
write_sequnlock(&UFS_I(inode)->meta_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2015-06-10 07:09:32 +07:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("EXIT, result %llu\n", (unsigned long long)result);
|
2005-04-17 05:20:36 +07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* resize block
|
|
|
|
*/
|
2014-06-07 04:36:33 +07:00
|
|
|
result = ufs_add_fragments(inode, tmp, oldcount, newcount);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (result) {
|
|
|
|
*err = 0;
|
2017-06-15 11:17:30 +07:00
|
|
|
read_seqlock_excl(&UFS_I(inode)->meta_lock);
|
2011-05-27 06:25:12 +07:00
|
|
|
UFS_I(inode)->i_lastfrag = max(UFS_I(inode)->i_lastfrag,
|
|
|
|
fragment + count);
|
2017-06-15 11:17:30 +07:00
|
|
|
read_sequnlock_excl(&UFS_I(inode)->meta_lock);
|
[PATCH] fix garbage instead of zeroes in UFS
Looks like this is the problem, which point Al Viro some time ago:
ufs's get_block callback allocates 16k of disk at a time, and links that
entire 16k into the file's metadata. But because get_block is called for only
a single buffer_head (a 2k buffer_head in this case?) we are only able to tell
the VFS that this 2k is buffer_new().
So when ufs_getfrag_block() is later called to map some more data in the file,
and when that data resides within the remaining 14k of this fragment,
ufs_getfrag_block() will incorrectly return a !buffer_new() buffer_head.
I don't see _right_ way to do nullification of whole block, if use inode
page cache, some pages may be outside of inode limits (inode size), and
will be lost; if use blockdev page cache it is possible to zero real data,
if later inode page cache will be used.
The simpliest way, as can I see usage of block device page cache, but not only
mark dirty, but also sync it during "nullification". I use my simple tests
collection, which I used for check that create,open,write,read,close works on
ufs, and I see that this patch makes ufs code 18% slower then before.
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2007-01-06 07:37:04 +07:00
|
|
|
ufs_clear_frags(inode, result + oldcount, newcount - oldcount,
|
|
|
|
locked_page != NULL);
|
2015-06-10 07:09:32 +07:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("EXIT, result %llu\n", (unsigned long long)result);
|
2005-04-17 05:20:36 +07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* allocate new block and move data
|
|
|
|
*/
|
2017-06-18 02:44:06 +07:00
|
|
|
if (fs32_to_cpu(sb, usb1->fs_optim) == UFS_OPTSPACE) {
|
2005-04-17 05:20:36 +07:00
|
|
|
request = newcount;
|
2017-06-18 02:44:06 +07:00
|
|
|
if (uspi->cs_total.cs_nffree < uspi->s_space_to_time)
|
|
|
|
usb1->fs_optim = cpu_to_fs32(sb, UFS_OPTTIME);
|
|
|
|
} else {
|
2005-04-17 05:20:36 +07:00
|
|
|
request = uspi->s_fpb;
|
2017-06-18 02:44:06 +07:00
|
|
|
if (uspi->cs_total.cs_nffree > uspi->s_time_to_space)
|
|
|
|
usb1->fs_optim = cpu_to_fs32(sb, UFS_OPTSPACE);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
result = ufs_alloc_fragments (inode, cgno, goal, request, err);
|
|
|
|
if (result) {
|
2007-01-30 04:19:56 +07:00
|
|
|
ufs_clear_frags(inode, result + oldcount, newcount - oldcount,
|
|
|
|
locked_page != NULL);
|
2017-06-15 11:42:56 +07:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
[PATCH] ufs: zeroize the rest of block in truncate
This patch fix behaviour in such test scenario:
lseek(fd, BIG_OFFSET)
write(fd, buf, sizeof(buf))
truncate(BIG_OFFSET)
truncate(BIG_OFFSET + sizeof(buf))
read(fd, buf...)
Because of if file big enough(BIG_OFFSET) we start allocate space by block,
ordinary block size > page size, so we should zeroize the rest of block in
truncate(except last framgnet, about which VFS should care), to not get
garbage, when we extend file.
Also patch corrects conversion from pointer to block to physical block number,
this helps in case of not common used UFS types.
And add to debug output inode number.
Signed-off-by: Evgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-03-17 04:38:09 +07:00
|
|
|
ufs_change_blocknr(inode, fragment - oldcount, oldcount,
|
|
|
|
uspi->s_sbbase + tmp,
|
|
|
|
uspi->s_sbbase + result, locked_page);
|
2017-06-15 11:17:30 +07:00
|
|
|
*err = 0;
|
2015-06-17 23:02:56 +07:00
|
|
|
write_seqlock(&UFS_I(inode)->meta_lock);
|
2007-02-12 15:54:32 +07:00
|
|
|
ufs_cpu_to_data_ptr(sb, p, result);
|
2011-05-27 06:25:12 +07:00
|
|
|
UFS_I(inode)->i_lastfrag = max(UFS_I(inode)->i_lastfrag,
|
|
|
|
fragment + count);
|
2017-06-15 11:17:30 +07:00
|
|
|
write_sequnlock(&UFS_I(inode)->meta_lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (newcount < request)
|
|
|
|
ufs_free_fragments (inode, result + newcount, request - newcount);
|
|
|
|
ufs_free_fragments (inode, tmp, oldcount);
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("EXIT, result %llu\n", (unsigned long long)result);
|
2005-04-17 05:20:36 +07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-06-10 07:09:32 +07:00
|
|
|
mutex_unlock(&UFS_SB(sb)->s_lock);
|
2006-06-25 19:47:24 +07:00
|
|
|
UFSD("EXIT (FAILED)\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-09 08:15:03 +07:00
|
|
|
static bool try_add_frags(struct inode *inode, unsigned frags)
|
|
|
|
{
|
|
|
|
unsigned size = frags * i_blocksize(inode);
|
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
__inode_add_bytes(inode, size);
|
|
|
|
if (unlikely((u32)inode->i_blocks != inode->i_blocks)) {
|
|
|
|
__inode_sub_bytes(inode, size);
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
static u64 ufs_add_fragments(struct inode *inode, u64 fragment,
|
2014-06-07 04:36:33 +07:00
|
|
|
unsigned oldcount, unsigned newcount)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct super_block * sb;
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_cg_private_info * ucpi;
|
|
|
|
struct ufs_cylinder_group * ucg;
|
|
|
|
unsigned cgno, fragno, fragoff, count, fragsize, i;
|
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("ENTER, fragment %llu, oldcount %u, newcount %u\n",
|
|
|
|
(unsigned long long)fragment, oldcount, newcount);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
sb = inode->i_sb;
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
count = newcount - oldcount;
|
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
cgno = ufs_dtog(uspi, fragment);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (fs32_to_cpu(sb, UFS_SB(sb)->fs_cs(cgno).cs_nffree) < count)
|
|
|
|
return 0;
|
|
|
|
if ((ufs_fragnum (fragment) + newcount) > uspi->s_fpb)
|
|
|
|
return 0;
|
|
|
|
ucpi = ufs_load_cylinder (sb, cgno);
|
|
|
|
if (!ucpi)
|
|
|
|
return 0;
|
2006-06-25 19:47:22 +07:00
|
|
|
ucg = ubh_get_ucg (UCPI_UBH(ucpi));
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!ufs_cg_chkmagic(sb, ucg)) {
|
|
|
|
ufs_panic (sb, "ufs_add_fragments",
|
|
|
|
"internal error, bad magic number on cg %u", cgno);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
fragno = ufs_dtogd(uspi, fragment);
|
2005-04-17 05:20:36 +07:00
|
|
|
fragoff = ufs_fragnum (fragno);
|
|
|
|
for (i = oldcount; i < newcount; i++)
|
2006-06-25 19:47:22 +07:00
|
|
|
if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i))
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
2017-06-09 08:15:03 +07:00
|
|
|
|
|
|
|
if (!try_add_frags(inode, count))
|
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Block can be extended
|
|
|
|
*/
|
|
|
|
ucg->cg_time = cpu_to_fs32(sb, get_seconds());
|
|
|
|
for (i = newcount; i < (uspi->s_fpb - fragoff); i++)
|
2006-06-25 19:47:22 +07:00
|
|
|
if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
fragsize = i - oldcount;
|
|
|
|
if (!fs32_to_cpu(sb, ucg->cg_frsum[fragsize]))
|
|
|
|
ufs_panic (sb, "ufs_add_fragments",
|
|
|
|
"internal error or corrupted bitmap on cg %u", cgno);
|
|
|
|
fs32_sub(sb, &ucg->cg_frsum[fragsize], 1);
|
|
|
|
if (fragsize != count)
|
|
|
|
fs32_add(sb, &ucg->cg_frsum[fragsize - count], 1);
|
|
|
|
for (i = oldcount; i < newcount; i++)
|
2006-06-25 19:47:22 +07:00
|
|
|
ubh_clrbit (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
fs32_sub(sb, &ucg->cg_cs.cs_nffree, count);
|
|
|
|
fs32_sub(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, count);
|
2006-06-25 19:47:30 +07:00
|
|
|
uspi->cs_total.cs_nffree -= count;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-06-25 19:47:22 +07:00
|
|
|
ubh_mark_buffer_dirty (USPI_UBH(uspi));
|
|
|
|
ubh_mark_buffer_dirty (UCPI_UBH(ucpi));
|
2017-11-28 04:05:09 +07:00
|
|
|
if (sb->s_flags & SB_SYNCHRONOUS)
|
2010-08-11 22:06:24 +07:00
|
|
|
ubh_sync_block(UCPI_UBH(ucpi));
|
2012-07-12 20:28:08 +07:00
|
|
|
ufs_mark_sb_dirty(sb);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("EXIT, fragment %llu\n", (unsigned long long)fragment);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define UFS_TEST_FREE_SPACE_CG \
|
|
|
|
ucg = (struct ufs_cylinder_group *) UFS_SB(sb)->s_ucg[cgno]->b_data; \
|
|
|
|
if (fs32_to_cpu(sb, ucg->cg_cs.cs_nbfree)) \
|
|
|
|
goto cg_found; \
|
|
|
|
for (k = count; k < uspi->s_fpb; k++) \
|
|
|
|
if (fs32_to_cpu(sb, ucg->cg_frsum[k])) \
|
|
|
|
goto cg_found;
|
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
static u64 ufs_alloc_fragments(struct inode *inode, unsigned cgno,
|
|
|
|
u64 goal, unsigned count, int *err)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct super_block * sb;
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_cg_private_info * ucpi;
|
|
|
|
struct ufs_cylinder_group * ucg;
|
2007-02-12 15:54:32 +07:00
|
|
|
unsigned oldcg, i, j, k, allocsize;
|
|
|
|
u64 result;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("ENTER, ino %lu, cgno %u, goal %llu, count %u\n",
|
|
|
|
inode->i_ino, cgno, (unsigned long long)goal, count);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
sb = inode->i_sb;
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
oldcg = cgno;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1. searching on preferred cylinder group
|
|
|
|
*/
|
|
|
|
UFS_TEST_FREE_SPACE_CG
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 2. quadratic rehash
|
|
|
|
*/
|
|
|
|
for (j = 1; j < uspi->s_ncg; j *= 2) {
|
|
|
|
cgno += j;
|
|
|
|
if (cgno >= uspi->s_ncg)
|
|
|
|
cgno -= uspi->s_ncg;
|
|
|
|
UFS_TEST_FREE_SPACE_CG
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 3. brute force search
|
|
|
|
* We start at i = 2 ( 0 is checked at 1.step, 1 at 2.step )
|
|
|
|
*/
|
|
|
|
cgno = (oldcg + 1) % uspi->s_ncg;
|
|
|
|
for (j = 2; j < uspi->s_ncg; j++) {
|
|
|
|
cgno++;
|
|
|
|
if (cgno >= uspi->s_ncg)
|
|
|
|
cgno = 0;
|
|
|
|
UFS_TEST_FREE_SPACE_CG
|
|
|
|
}
|
|
|
|
|
2006-06-25 19:47:24 +07:00
|
|
|
UFSD("EXIT (FAILED)\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
cg_found:
|
|
|
|
ucpi = ufs_load_cylinder (sb, cgno);
|
|
|
|
if (!ucpi)
|
|
|
|
return 0;
|
2006-06-25 19:47:22 +07:00
|
|
|
ucg = ubh_get_ucg (UCPI_UBH(ucpi));
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!ufs_cg_chkmagic(sb, ucg))
|
|
|
|
ufs_panic (sb, "ufs_alloc_fragments",
|
|
|
|
"internal error, bad magic number on cg %u", cgno);
|
|
|
|
ucg->cg_time = cpu_to_fs32(sb, get_seconds());
|
|
|
|
|
|
|
|
if (count == uspi->s_fpb) {
|
|
|
|
result = ufs_alloccg_block (inode, ucpi, goal, err);
|
2007-02-12 15:54:32 +07:00
|
|
|
if (result == INVBLOCK)
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
goto succed;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (allocsize = count; allocsize < uspi->s_fpb; allocsize++)
|
|
|
|
if (fs32_to_cpu(sb, ucg->cg_frsum[allocsize]) != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (allocsize == uspi->s_fpb) {
|
|
|
|
result = ufs_alloccg_block (inode, ucpi, goal, err);
|
2007-02-12 15:54:32 +07:00
|
|
|
if (result == INVBLOCK)
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
2007-02-12 15:54:32 +07:00
|
|
|
goal = ufs_dtogd(uspi, result);
|
2005-04-17 05:20:36 +07:00
|
|
|
for (i = count; i < uspi->s_fpb; i++)
|
2006-06-25 19:47:22 +07:00
|
|
|
ubh_setbit (UCPI_UBH(ucpi), ucpi->c_freeoff, goal + i);
|
2005-04-17 05:20:36 +07:00
|
|
|
i = uspi->s_fpb - count;
|
|
|
|
|
2017-06-09 08:15:03 +07:00
|
|
|
inode_sub_bytes(inode, i << uspi->s_fshift);
|
2005-04-17 05:20:36 +07:00
|
|
|
fs32_add(sb, &ucg->cg_cs.cs_nffree, i);
|
2006-06-25 19:47:30 +07:00
|
|
|
uspi->cs_total.cs_nffree += i;
|
2005-04-17 05:20:36 +07:00
|
|
|
fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, i);
|
|
|
|
fs32_add(sb, &ucg->cg_frsum[i], 1);
|
|
|
|
goto succed;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = ufs_bitmap_search (sb, ucpi, goal, allocsize);
|
2007-02-12 15:54:32 +07:00
|
|
|
if (result == INVBLOCK)
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
2017-06-09 08:15:03 +07:00
|
|
|
if (!try_add_frags(inode, count))
|
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
for (i = 0; i < count; i++)
|
2006-06-25 19:47:22 +07:00
|
|
|
ubh_clrbit (UCPI_UBH(ucpi), ucpi->c_freeoff, result + i);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
fs32_sub(sb, &ucg->cg_cs.cs_nffree, count);
|
2006-06-25 19:47:30 +07:00
|
|
|
uspi->cs_total.cs_nffree -= count;
|
2005-04-17 05:20:36 +07:00
|
|
|
fs32_sub(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, count);
|
|
|
|
fs32_sub(sb, &ucg->cg_frsum[allocsize], 1);
|
|
|
|
|
|
|
|
if (count != allocsize)
|
|
|
|
fs32_add(sb, &ucg->cg_frsum[allocsize - count], 1);
|
|
|
|
|
|
|
|
succed:
|
2006-06-25 19:47:22 +07:00
|
|
|
ubh_mark_buffer_dirty (USPI_UBH(uspi));
|
|
|
|
ubh_mark_buffer_dirty (UCPI_UBH(ucpi));
|
2017-11-28 04:05:09 +07:00
|
|
|
if (sb->s_flags & SB_SYNCHRONOUS)
|
2010-08-11 22:06:24 +07:00
|
|
|
ubh_sync_block(UCPI_UBH(ucpi));
|
2012-07-12 20:28:08 +07:00
|
|
|
ufs_mark_sb_dirty(sb);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
result += cgno * uspi->s_fpg;
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("EXIT3, result %llu\n", (unsigned long long)result);
|
2005-04-17 05:20:36 +07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
static u64 ufs_alloccg_block(struct inode *inode,
|
|
|
|
struct ufs_cg_private_info *ucpi,
|
|
|
|
u64 goal, int *err)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct super_block * sb;
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
struct ufs_cylinder_group * ucg;
|
2007-02-12 15:54:32 +07:00
|
|
|
u64 result, blkno;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("ENTER, goal %llu\n", (unsigned long long)goal);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
sb = inode->i_sb;
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
2006-06-25 19:47:22 +07:00
|
|
|
ucg = ubh_get_ucg(UCPI_UBH(ucpi));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (goal == 0) {
|
|
|
|
goal = ucpi->c_rotor;
|
|
|
|
goto norot;
|
|
|
|
}
|
|
|
|
goal = ufs_blknum (goal);
|
2007-02-12 15:54:32 +07:00
|
|
|
goal = ufs_dtogd(uspi, goal);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the requested block is available, use it.
|
|
|
|
*/
|
2006-06-25 19:47:22 +07:00
|
|
|
if (ubh_isblockset(UCPI_UBH(ucpi), ucpi->c_freeoff, ufs_fragstoblks(goal))) {
|
2005-04-17 05:20:36 +07:00
|
|
|
result = goal;
|
|
|
|
goto gotit;
|
|
|
|
}
|
|
|
|
|
|
|
|
norot:
|
|
|
|
result = ufs_bitmap_search (sb, ucpi, goal, uspi->s_fpb);
|
2007-02-12 15:54:32 +07:00
|
|
|
if (result == INVBLOCK)
|
|
|
|
return INVBLOCK;
|
2005-04-17 05:20:36 +07:00
|
|
|
ucpi->c_rotor = result;
|
|
|
|
gotit:
|
2017-06-09 08:15:03 +07:00
|
|
|
if (!try_add_frags(inode, uspi->s_fpb))
|
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
blkno = ufs_fragstoblks(result);
|
2006-06-25 19:47:22 +07:00
|
|
|
ubh_clrblock (UCPI_UBH(ucpi), ucpi->c_freeoff, blkno);
|
2005-04-17 05:20:36 +07:00
|
|
|
if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
|
|
|
|
ufs_clusteracct (sb, ucpi, blkno, -1);
|
|
|
|
|
|
|
|
fs32_sub(sb, &ucg->cg_cs.cs_nbfree, 1);
|
2006-06-25 19:47:30 +07:00
|
|
|
uspi->cs_total.cs_nbfree--;
|
2005-04-17 05:20:36 +07:00
|
|
|
fs32_sub(sb, &UFS_SB(sb)->fs_cs(ucpi->c_cgx).cs_nbfree, 1);
|
2007-02-12 15:54:32 +07:00
|
|
|
|
|
|
|
if (uspi->fs_magic != UFS2_MAGIC) {
|
|
|
|
unsigned cylno = ufs_cbtocylno((unsigned)result);
|
|
|
|
|
|
|
|
fs16_sub(sb, &ubh_cg_blks(ucpi, cylno,
|
|
|
|
ufs_cbtorpos((unsigned)result)), 1);
|
|
|
|
fs32_sub(sb, &ubh_cg_blktot(ucpi, cylno), 1);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("EXIT, result %llu\n", (unsigned long long)result);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-06-25 19:47:23 +07:00
|
|
|
static unsigned ubh_scanc(struct ufs_sb_private_info *uspi,
|
|
|
|
struct ufs_buffer_head *ubh,
|
|
|
|
unsigned begin, unsigned size,
|
|
|
|
unsigned char *table, unsigned char mask)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2006-06-25 19:47:23 +07:00
|
|
|
unsigned rest, offset;
|
|
|
|
unsigned char *cp;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
|
2006-06-25 19:47:23 +07:00
|
|
|
offset = begin & ~uspi->s_fmask;
|
|
|
|
begin >>= uspi->s_fshift;
|
|
|
|
for (;;) {
|
|
|
|
if ((offset + size) < uspi->s_fsize)
|
|
|
|
rest = size;
|
|
|
|
else
|
|
|
|
rest = uspi->s_fsize - offset;
|
|
|
|
size -= rest;
|
|
|
|
cp = ubh->bh[begin]->b_data + offset;
|
|
|
|
while ((table[*cp++] & mask) == 0 && --rest)
|
|
|
|
;
|
|
|
|
if (rest || !size)
|
|
|
|
break;
|
|
|
|
begin++;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
return (size + rest);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a block of the specified size in the specified cylinder group.
|
|
|
|
* @sp: pointer to super block
|
|
|
|
* @ucpi: pointer to cylinder group info
|
|
|
|
* @goal: near which block we want find new one
|
|
|
|
* @count: specified size
|
|
|
|
*/
|
2007-02-12 15:54:32 +07:00
|
|
|
static u64 ufs_bitmap_search(struct super_block *sb,
|
|
|
|
struct ufs_cg_private_info *ucpi,
|
|
|
|
u64 goal, unsigned count)
|
2006-06-25 19:47:23 +07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Bit patterns for identifying fragments in the block map
|
|
|
|
* used as ((map & mask_arr) == want_arr)
|
|
|
|
*/
|
|
|
|
static const int mask_arr[9] = {
|
|
|
|
0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff, 0x1ff, 0x3ff
|
|
|
|
};
|
|
|
|
static const int want_arr[9] = {
|
|
|
|
0x0, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe
|
|
|
|
};
|
|
|
|
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
|
2007-02-12 15:54:32 +07:00
|
|
|
unsigned start, length, loc;
|
2006-06-25 19:47:23 +07:00
|
|
|
unsigned pos, want, blockmap, mask, end;
|
2007-02-12 15:54:32 +07:00
|
|
|
u64 result;
|
2006-06-25 19:47:23 +07:00
|
|
|
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("ENTER, cg %u, goal %llu, count %u\n", ucpi->c_cgx,
|
|
|
|
(unsigned long long)goal, count);
|
2006-06-25 19:47:23 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (goal)
|
2007-02-12 15:54:32 +07:00
|
|
|
start = ufs_dtogd(uspi, goal) >> 3;
|
2005-04-17 05:20:36 +07:00
|
|
|
else
|
|
|
|
start = ucpi->c_frotor >> 3;
|
|
|
|
|
|
|
|
length = ((uspi->s_fpg + 7) >> 3) - start;
|
2006-06-25 19:47:23 +07:00
|
|
|
loc = ubh_scanc(uspi, UCPI_UBH(ucpi), ucpi->c_freeoff + start, length,
|
2005-04-17 05:20:36 +07:00
|
|
|
(uspi->s_fpb == 8) ? ufs_fragtable_8fpb : ufs_fragtable_other,
|
|
|
|
1 << (count - 1 + (uspi->s_fpb & 7)));
|
2006-06-25 19:47:23 +07:00
|
|
|
if (loc == 0) {
|
2005-04-17 05:20:36 +07:00
|
|
|
length = start + 1;
|
2006-06-25 19:47:23 +07:00
|
|
|
loc = ubh_scanc(uspi, UCPI_UBH(ucpi), ucpi->c_freeoff, length,
|
|
|
|
(uspi->s_fpb == 8) ? ufs_fragtable_8fpb :
|
|
|
|
ufs_fragtable_other,
|
|
|
|
1 << (count - 1 + (uspi->s_fpb & 7)));
|
|
|
|
if (loc == 0) {
|
|
|
|
ufs_error(sb, "ufs_bitmap_search",
|
|
|
|
"bitmap corrupted on cg %u, start %u,"
|
|
|
|
" length %u, count %u, freeoff %u\n",
|
|
|
|
ucpi->c_cgx, start, length, count,
|
|
|
|
ucpi->c_freeoff);
|
2007-02-12 15:54:32 +07:00
|
|
|
return INVBLOCK;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
start = 0;
|
|
|
|
}
|
2006-06-25 19:47:23 +07:00
|
|
|
result = (start + length - loc) << 3;
|
2005-04-17 05:20:36 +07:00
|
|
|
ucpi->c_frotor = result;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* found the byte in the map
|
|
|
|
*/
|
2006-06-25 19:47:23 +07:00
|
|
|
|
|
|
|
for (end = result + 8; result < end; result += uspi->s_fpb) {
|
|
|
|
blockmap = ubh_blkmap(UCPI_UBH(ucpi), ucpi->c_freeoff, result);
|
|
|
|
blockmap <<= 1;
|
|
|
|
mask = mask_arr[count];
|
|
|
|
want = want_arr[count];
|
|
|
|
for (pos = 0; pos <= uspi->s_fpb - count; pos++) {
|
|
|
|
if ((blockmap & mask) == want) {
|
2007-02-12 15:54:32 +07:00
|
|
|
UFSD("EXIT, result %llu\n",
|
|
|
|
(unsigned long long)result);
|
2006-06-25 19:47:23 +07:00
|
|
|
return result + pos;
|
|
|
|
}
|
|
|
|
mask <<= 1;
|
|
|
|
want <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ufs_error(sb, "ufs_bitmap_search", "block not in map on cg %u\n",
|
|
|
|
ucpi->c_cgx);
|
2006-06-25 19:47:24 +07:00
|
|
|
UFSD("EXIT (FAILED)\n");
|
2007-02-12 15:54:32 +07:00
|
|
|
return INVBLOCK;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ufs_clusteracct(struct super_block * sb,
|
|
|
|
struct ufs_cg_private_info * ucpi, unsigned blkno, int cnt)
|
|
|
|
{
|
|
|
|
struct ufs_sb_private_info * uspi;
|
|
|
|
int i, start, end, forw, back;
|
|
|
|
|
|
|
|
uspi = UFS_SB(sb)->s_uspi;
|
|
|
|
if (uspi->s_contigsumsize <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cnt > 0)
|
2006-06-25 19:47:22 +07:00
|
|
|
ubh_setbit(UCPI_UBH(ucpi), ucpi->c_clusteroff, blkno);
|
2005-04-17 05:20:36 +07:00
|
|
|
else
|
2006-06-25 19:47:22 +07:00
|
|
|
ubh_clrbit(UCPI_UBH(ucpi), ucpi->c_clusteroff, blkno);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the size of the cluster going forward.
|
|
|
|
*/
|
|
|
|
start = blkno + 1;
|
|
|
|
end = start + uspi->s_contigsumsize;
|
|
|
|
if ( end >= ucpi->c_nclusterblks)
|
|
|
|
end = ucpi->c_nclusterblks;
|
2006-06-25 19:47:22 +07:00
|
|
|
i = ubh_find_next_zero_bit (UCPI_UBH(ucpi), ucpi->c_clusteroff, end, start);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (i > end)
|
|
|
|
i = end;
|
|
|
|
forw = i - start;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the size of the cluster going backward.
|
|
|
|
*/
|
|
|
|
start = blkno - 1;
|
|
|
|
end = start - uspi->s_contigsumsize;
|
|
|
|
if (end < 0 )
|
|
|
|
end = -1;
|
2006-06-25 19:47:22 +07:00
|
|
|
i = ubh_find_last_zero_bit (UCPI_UBH(ucpi), ucpi->c_clusteroff, start, end);
|
2005-04-17 05:20:36 +07:00
|
|
|
if ( i < end)
|
|
|
|
i = end;
|
|
|
|
back = start - i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Account for old cluster and the possibly new forward and
|
|
|
|
* back clusters.
|
|
|
|
*/
|
|
|
|
i = back + forw + 1;
|
|
|
|
if (i > uspi->s_contigsumsize)
|
|
|
|
i = uspi->s_contigsumsize;
|
2006-06-25 19:47:22 +07:00
|
|
|
fs32_add(sb, (__fs32*)ubh_get_addr(UCPI_UBH(ucpi), ucpi->c_clustersumoff + (i << 2)), cnt);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (back > 0)
|
2006-06-25 19:47:22 +07:00
|
|
|
fs32_sub(sb, (__fs32*)ubh_get_addr(UCPI_UBH(ucpi), ucpi->c_clustersumoff + (back << 2)), cnt);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (forw > 0)
|
2006-06-25 19:47:22 +07:00
|
|
|
fs32_sub(sb, (__fs32*)ubh_get_addr(UCPI_UBH(ucpi), ucpi->c_clustersumoff + (forw << 2)), cnt);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned char ufs_fragtable_8fpb[] = {
|
|
|
|
0x00, 0x01, 0x01, 0x02, 0x01, 0x01, 0x02, 0x04, 0x01, 0x01, 0x01, 0x03, 0x02, 0x03, 0x04, 0x08,
|
|
|
|
0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 0x02, 0x03, 0x03, 0x02, 0x04, 0x05, 0x08, 0x10,
|
|
|
|
0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
|
|
|
|
0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06, 0x04, 0x05, 0x05, 0x06, 0x08, 0x09, 0x10, 0x20,
|
|
|
|
0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
|
|
|
|
0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11,
|
|
|
|
0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06, 0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0A,
|
|
|
|
0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04, 0x08, 0x09, 0x09, 0x0A, 0x10, 0x11, 0x20, 0x40,
|
|
|
|
0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
|
|
|
|
0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11,
|
|
|
|
0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
|
|
|
|
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07, 0x05, 0x05, 0x05, 0x07, 0x09, 0x09, 0x11, 0x21,
|
|
|
|
0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06, 0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0A,
|
|
|
|
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07, 0x02, 0x03, 0x03, 0x02, 0x06, 0x07, 0x0A, 0x12,
|
|
|
|
0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04, 0x05, 0x05, 0x05, 0x07, 0x06, 0x07, 0x04, 0x0C,
|
|
|
|
0x08, 0x09, 0x09, 0x0A, 0x09, 0x09, 0x0A, 0x0C, 0x10, 0x11, 0x11, 0x12, 0x20, 0x21, 0x40, 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned char ufs_fragtable_other[] = {
|
|
|
|
0x00, 0x16, 0x16, 0x2A, 0x16, 0x16, 0x26, 0x4E, 0x16, 0x16, 0x16, 0x3E, 0x2A, 0x3E, 0x4E, 0x8A,
|
|
|
|
0x16, 0x16, 0x16, 0x3E, 0x16, 0x16, 0x36, 0x5E, 0x16, 0x16, 0x16, 0x3E, 0x3E, 0x3E, 0x5E, 0x9E,
|
|
|
|
0x16, 0x16, 0x16, 0x3E, 0x16, 0x16, 0x36, 0x5E, 0x16, 0x16, 0x16, 0x3E, 0x3E, 0x3E, 0x5E, 0x9E,
|
|
|
|
0x2A, 0x3E, 0x3E, 0x2A, 0x3E, 0x3E, 0x2E, 0x6E, 0x3E, 0x3E, 0x3E, 0x3E, 0x2A, 0x3E, 0x6E, 0xAA,
|
|
|
|
0x16, 0x16, 0x16, 0x3E, 0x16, 0x16, 0x36, 0x5E, 0x16, 0x16, 0x16, 0x3E, 0x3E, 0x3E, 0x5E, 0x9E,
|
|
|
|
0x16, 0x16, 0x16, 0x3E, 0x16, 0x16, 0x36, 0x5E, 0x16, 0x16, 0x16, 0x3E, 0x3E, 0x3E, 0x5E, 0x9E,
|
|
|
|
0x26, 0x36, 0x36, 0x2E, 0x36, 0x36, 0x26, 0x6E, 0x36, 0x36, 0x36, 0x3E, 0x2E, 0x3E, 0x6E, 0xAE,
|
|
|
|
0x4E, 0x5E, 0x5E, 0x6E, 0x5E, 0x5E, 0x6E, 0x4E, 0x5E, 0x5E, 0x5E, 0x7E, 0x6E, 0x7E, 0x4E, 0xCE,
|
|
|
|
0x16, 0x16, 0x16, 0x3E, 0x16, 0x16, 0x36, 0x5E, 0x16, 0x16, 0x16, 0x3E, 0x3E, 0x3E, 0x5E, 0x9E,
|
|
|
|
0x16, 0x16, 0x16, 0x3E, 0x16, 0x16, 0x36, 0x5E, 0x16, 0x16, 0x16, 0x3E, 0x3E, 0x3E, 0x5E, 0x9E,
|
|
|
|
0x16, 0x16, 0x16, 0x3E, 0x16, 0x16, 0x36, 0x5E, 0x16, 0x16, 0x16, 0x3E, 0x3E, 0x3E, 0x5E, 0x9E,
|
|
|
|
0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x7E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x7E, 0xBE,
|
|
|
|
0x2A, 0x3E, 0x3E, 0x2A, 0x3E, 0x3E, 0x2E, 0x6E, 0x3E, 0x3E, 0x3E, 0x3E, 0x2A, 0x3E, 0x6E, 0xAA,
|
|
|
|
0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x7E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x7E, 0xBE,
|
|
|
|
0x4E, 0x5E, 0x5E, 0x6E, 0x5E, 0x5E, 0x6E, 0x4E, 0x5E, 0x5E, 0x5E, 0x7E, 0x6E, 0x7E, 0x4E, 0xCE,
|
|
|
|
0x8A, 0x9E, 0x9E, 0xAA, 0x9E, 0x9E, 0xAE, 0xCE, 0x9E, 0x9E, 0x9E, 0xBE, 0xAA, 0xBE, 0xCE, 0x8A,
|
|
|
|
};
|