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 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-08-26 01:56:50 +08:00
|
|
|
/*
|
|
|
|
* Implementation of operations over local quota file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2008-08-26 01:56:50 +08:00
|
|
|
#include <linux/quota.h>
|
|
|
|
#include <linux/quotaops.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include <cluster/masklog.h>
|
|
|
|
|
|
|
|
#include "ocfs2_fs.h"
|
|
|
|
#include "ocfs2.h"
|
|
|
|
#include "inode.h"
|
|
|
|
#include "alloc.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "buffer_head_io.h"
|
|
|
|
#include "journal.h"
|
|
|
|
#include "sysfile.h"
|
|
|
|
#include "dlmglue.h"
|
|
|
|
#include "quota.h"
|
2009-07-22 19:17:16 +08:00
|
|
|
#include "uptodate.h"
|
2010-03-31 22:25:37 +08:00
|
|
|
#include "super.h"
|
2011-02-23 22:12:48 +08:00
|
|
|
#include "ocfs2_trace.h"
|
2008-08-26 01:56:50 +08:00
|
|
|
|
|
|
|
/* Number of local quota structures per block */
|
|
|
|
static inline unsigned int ol_quota_entries_per_block(struct super_block *sb)
|
|
|
|
{
|
|
|
|
return ((sb->s_blocksize - OCFS2_QBLK_RESERVED_SPACE) /
|
|
|
|
sizeof(struct ocfs2_local_disk_dqblk));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Number of blocks with entries in one chunk */
|
|
|
|
static inline unsigned int ol_chunk_blocks(struct super_block *sb)
|
|
|
|
{
|
|
|
|
return ((sb->s_blocksize - sizeof(struct ocfs2_local_disk_chunk) -
|
|
|
|
OCFS2_QBLK_RESERVED_SPACE) << 3) /
|
|
|
|
ol_quota_entries_per_block(sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Number of entries in a chunk bitmap */
|
|
|
|
static unsigned int ol_chunk_entries(struct super_block *sb)
|
|
|
|
{
|
|
|
|
return ol_chunk_blocks(sb) * ol_quota_entries_per_block(sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Offset of the chunk in quota file */
|
|
|
|
static unsigned int ol_quota_chunk_block(struct super_block *sb, int c)
|
|
|
|
{
|
|
|
|
/* 1 block for local quota file info, 1 block per chunk for chunk info */
|
|
|
|
return 1 + (ol_chunk_blocks(sb) + 1) * c;
|
|
|
|
}
|
|
|
|
|
2008-10-21 05:50:38 +08:00
|
|
|
static unsigned int ol_dqblk_block(struct super_block *sb, int c, int off)
|
|
|
|
{
|
|
|
|
int epb = ol_quota_entries_per_block(sb);
|
|
|
|
|
|
|
|
return ol_quota_chunk_block(sb, c) + 1 + off / epb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int ol_dqblk_block_off(struct super_block *sb, int c, int off)
|
2008-08-26 01:56:50 +08:00
|
|
|
{
|
|
|
|
int epb = ol_quota_entries_per_block(sb);
|
|
|
|
|
2008-10-21 05:50:38 +08:00
|
|
|
return (off % epb) * sizeof(struct ocfs2_local_disk_dqblk);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Offset of the dquot structure in the quota file */
|
|
|
|
static loff_t ol_dqblk_off(struct super_block *sb, int c, int off)
|
|
|
|
{
|
|
|
|
return (ol_dqblk_block(sb, c, off) << sb->s_blocksize_bits) +
|
|
|
|
ol_dqblk_block_off(sb, c, off);
|
2008-08-26 01:56:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int ol_dqblk_block_offset(struct super_block *sb, loff_t off)
|
|
|
|
{
|
|
|
|
return off & ((1 << sb->s_blocksize_bits) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute offset in the chunk of a structure with the given offset */
|
|
|
|
static int ol_dqblk_chunk_off(struct super_block *sb, int c, loff_t off)
|
|
|
|
{
|
|
|
|
int epb = ol_quota_entries_per_block(sb);
|
|
|
|
|
|
|
|
return ((off >> sb->s_blocksize_bits) -
|
|
|
|
ol_quota_chunk_block(sb, c) - 1) * epb
|
|
|
|
+ ((unsigned int)(off & ((1 << sb->s_blocksize_bits) - 1))) /
|
|
|
|
sizeof(struct ocfs2_local_disk_dqblk);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write bufferhead into the fs */
|
|
|
|
static int ocfs2_modify_bh(struct inode *inode, struct buffer_head *bh,
|
|
|
|
void (*modify)(struct buffer_head *, void *), void *private)
|
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
handle_t *handle;
|
|
|
|
int status;
|
|
|
|
|
2009-07-22 19:17:21 +08:00
|
|
|
handle = ocfs2_start_trans(OCFS2_SB(sb),
|
|
|
|
OCFS2_QUOTA_BLOCK_UPDATE_CREDITS);
|
2008-08-26 01:56:50 +08:00
|
|
|
if (IS_ERR(handle)) {
|
|
|
|
status = PTR_ERR(handle);
|
|
|
|
mlog_errno(status);
|
|
|
|
return status;
|
|
|
|
}
|
2009-02-13 08:41:25 +08:00
|
|
|
status = ocfs2_journal_access_dq(handle, INODE_CACHE(inode), bh,
|
2008-10-18 10:25:01 +08:00
|
|
|
OCFS2_JOURNAL_ACCESS_WRITE);
|
2008-08-26 01:56:50 +08:00
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
ocfs2_commit_trans(OCFS2_SB(sb), handle);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
lock_buffer(bh);
|
|
|
|
modify(bh, private);
|
|
|
|
unlock_buffer(bh);
|
2010-03-20 05:13:52 +08:00
|
|
|
ocfs2_journal_dirty(handle, bh);
|
|
|
|
|
2008-08-26 01:56:50 +08:00
|
|
|
status = ocfs2_commit_trans(OCFS2_SB(sb), handle);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-31 22:25:37 +08:00
|
|
|
/*
|
|
|
|
* Read quota block from a given logical offset.
|
|
|
|
*
|
|
|
|
* This function acquires ip_alloc_sem and thus it must not be called with a
|
|
|
|
* transaction started.
|
|
|
|
*/
|
|
|
|
static int ocfs2_read_quota_block(struct inode *inode, u64 v_block,
|
|
|
|
struct buffer_head **bh)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
struct buffer_head *tmp = *bh;
|
|
|
|
|
2018-08-18 06:44:24 +08:00
|
|
|
if (i_size_read(inode) >> inode->i_sb->s_blocksize_bits <= v_block)
|
|
|
|
return ocfs2_error(inode->i_sb,
|
|
|
|
"Quota file %llu is probably corrupted! Requested to read block %Lu but file has size only %Lu\n",
|
|
|
|
(unsigned long long)OCFS2_I(inode)->ip_blkno,
|
|
|
|
(unsigned long long)v_block,
|
|
|
|
(unsigned long long)i_size_read(inode));
|
|
|
|
|
2010-03-31 22:25:37 +08:00
|
|
|
rc = ocfs2_read_virt_blocks(inode, v_block, 1, &tmp, 0,
|
|
|
|
ocfs2_validate_quota_block);
|
|
|
|
if (rc)
|
|
|
|
mlog_errno(rc);
|
|
|
|
|
|
|
|
/* If ocfs2_read_virt_blocks() got us a new bh, pass it up. */
|
|
|
|
if (!rc && !*bh)
|
|
|
|
*bh = tmp;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-08-26 01:56:50 +08:00
|
|
|
/* Check whether we understand format of quota files */
|
|
|
|
static int ocfs2_local_check_quota_file(struct super_block *sb, int type)
|
|
|
|
{
|
2014-09-11 03:06:39 +08:00
|
|
|
unsigned int lmagics[OCFS2_MAXQUOTAS] = OCFS2_LOCAL_QMAGICS;
|
|
|
|
unsigned int lversions[OCFS2_MAXQUOTAS] = OCFS2_LOCAL_QVERSIONS;
|
|
|
|
unsigned int gmagics[OCFS2_MAXQUOTAS] = OCFS2_GLOBAL_QMAGICS;
|
|
|
|
unsigned int gversions[OCFS2_MAXQUOTAS] = OCFS2_GLOBAL_QVERSIONS;
|
|
|
|
unsigned int ino[OCFS2_MAXQUOTAS] = { USER_QUOTA_SYSTEM_INODE,
|
|
|
|
GROUP_QUOTA_SYSTEM_INODE };
|
2008-11-25 22:31:27 +08:00
|
|
|
struct buffer_head *bh = NULL;
|
2008-08-26 01:56:50 +08:00
|
|
|
struct inode *linode = sb_dqopt(sb)->files[type];
|
|
|
|
struct inode *ginode = NULL;
|
|
|
|
struct ocfs2_disk_dqheader *dqhead;
|
|
|
|
int status, ret = 0;
|
|
|
|
|
|
|
|
/* First check whether we understand local quota file */
|
2008-11-25 22:31:27 +08:00
|
|
|
status = ocfs2_read_quota_block(linode, 0, &bh);
|
|
|
|
if (status) {
|
2008-08-26 01:56:50 +08:00
|
|
|
mlog_errno(status);
|
|
|
|
mlog(ML_ERROR, "failed to read quota file header (type=%d)\n",
|
|
|
|
type);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
dqhead = (struct ocfs2_disk_dqheader *)(bh->b_data);
|
|
|
|
if (le32_to_cpu(dqhead->dqh_magic) != lmagics[type]) {
|
|
|
|
mlog(ML_ERROR, "quota file magic does not match (%u != %u),"
|
|
|
|
" type=%d\n", le32_to_cpu(dqhead->dqh_magic),
|
|
|
|
lmagics[type], type);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
if (le32_to_cpu(dqhead->dqh_version) != lversions[type]) {
|
|
|
|
mlog(ML_ERROR, "quota file version does not match (%u != %u),"
|
|
|
|
" type=%d\n", le32_to_cpu(dqhead->dqh_version),
|
|
|
|
lversions[type], type);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
brelse(bh);
|
|
|
|
bh = NULL;
|
|
|
|
|
|
|
|
/* Next check whether we understand global quota file */
|
|
|
|
ginode = ocfs2_get_system_file_inode(OCFS2_SB(sb), ino[type],
|
|
|
|
OCFS2_INVALID_SLOT);
|
|
|
|
if (!ginode) {
|
|
|
|
mlog(ML_ERROR, "cannot get global quota file inode "
|
|
|
|
"(type=%d)\n", type);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
/* Since the header is read only, we don't care about locking */
|
2008-11-25 22:31:27 +08:00
|
|
|
status = ocfs2_read_quota_block(ginode, 0, &bh);
|
|
|
|
if (status) {
|
2008-08-26 01:56:50 +08:00
|
|
|
mlog_errno(status);
|
|
|
|
mlog(ML_ERROR, "failed to read global quota file header "
|
|
|
|
"(type=%d)\n", type);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
dqhead = (struct ocfs2_disk_dqheader *)(bh->b_data);
|
|
|
|
if (le32_to_cpu(dqhead->dqh_magic) != gmagics[type]) {
|
|
|
|
mlog(ML_ERROR, "global quota file magic does not match "
|
|
|
|
"(%u != %u), type=%d\n",
|
|
|
|
le32_to_cpu(dqhead->dqh_magic), gmagics[type], type);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
if (le32_to_cpu(dqhead->dqh_version) != gversions[type]) {
|
|
|
|
mlog(ML_ERROR, "global quota file version does not match "
|
|
|
|
"(%u != %u), type=%d\n",
|
|
|
|
le32_to_cpu(dqhead->dqh_version), gversions[type],
|
|
|
|
type);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
out_err:
|
|
|
|
brelse(bh);
|
|
|
|
iput(ginode);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release given list of quota file chunks */
|
|
|
|
static void ocfs2_release_local_quota_bitmaps(struct list_head *head)
|
|
|
|
{
|
|
|
|
struct ocfs2_quota_chunk *pos, *next;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(pos, next, head, qc_chunk) {
|
|
|
|
list_del(&pos->qc_chunk);
|
|
|
|
brelse(pos->qc_headerbh);
|
|
|
|
kmem_cache_free(ocfs2_qf_chunk_cachep, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load quota bitmaps into memory */
|
|
|
|
static int ocfs2_load_local_quota_bitmaps(struct inode *inode,
|
|
|
|
struct ocfs2_local_disk_dqinfo *ldinfo,
|
|
|
|
struct list_head *head)
|
|
|
|
{
|
|
|
|
struct ocfs2_quota_chunk *newchunk;
|
|
|
|
int i, status;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(head);
|
|
|
|
for (i = 0; i < le32_to_cpu(ldinfo->dqi_chunks); i++) {
|
|
|
|
newchunk = kmem_cache_alloc(ocfs2_qf_chunk_cachep, GFP_NOFS);
|
|
|
|
if (!newchunk) {
|
|
|
|
ocfs2_release_local_quota_bitmaps(head);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
newchunk->qc_num = i;
|
2008-11-25 22:31:27 +08:00
|
|
|
newchunk->qc_headerbh = NULL;
|
|
|
|
status = ocfs2_read_quota_block(inode,
|
2008-08-26 01:56:50 +08:00
|
|
|
ol_quota_chunk_block(inode->i_sb, i),
|
2008-11-25 22:31:27 +08:00
|
|
|
&newchunk->qc_headerbh);
|
|
|
|
if (status) {
|
2008-08-26 01:56:50 +08:00
|
|
|
mlog_errno(status);
|
|
|
|
kmem_cache_free(ocfs2_qf_chunk_cachep, newchunk);
|
|
|
|
ocfs2_release_local_quota_bitmaps(head);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
list_add_tail(&newchunk->qc_chunk, head);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void olq_update_info(struct buffer_head *bh, void *private)
|
|
|
|
{
|
|
|
|
struct mem_dqinfo *info = private;
|
|
|
|
struct ocfs2_mem_dqinfo *oinfo = info->dqi_priv;
|
|
|
|
struct ocfs2_local_disk_dqinfo *ldinfo;
|
|
|
|
|
|
|
|
ldinfo = (struct ocfs2_local_disk_dqinfo *)(bh->b_data +
|
|
|
|
OCFS2_LOCAL_INFO_OFF);
|
|
|
|
spin_lock(&dq_data_lock);
|
2014-11-19 17:41:41 +08:00
|
|
|
ldinfo->dqi_flags = cpu_to_le32(oinfo->dqi_flags);
|
2008-08-26 01:56:50 +08:00
|
|
|
ldinfo->dqi_chunks = cpu_to_le32(oinfo->dqi_chunks);
|
|
|
|
ldinfo->dqi_blocks = cpu_to_le32(oinfo->dqi_blocks);
|
|
|
|
spin_unlock(&dq_data_lock);
|
|
|
|
}
|
|
|
|
|
2008-10-21 05:50:38 +08:00
|
|
|
static int ocfs2_add_recovery_chunk(struct super_block *sb,
|
|
|
|
struct ocfs2_local_disk_chunk *dchunk,
|
|
|
|
int chunk,
|
|
|
|
struct list_head *head)
|
|
|
|
{
|
|
|
|
struct ocfs2_recovery_chunk *rc;
|
|
|
|
|
|
|
|
rc = kmalloc(sizeof(struct ocfs2_recovery_chunk), GFP_NOFS);
|
|
|
|
if (!rc)
|
|
|
|
return -ENOMEM;
|
|
|
|
rc->rc_chunk = chunk;
|
|
|
|
rc->rc_bitmap = kmalloc(sb->s_blocksize, GFP_NOFS);
|
|
|
|
if (!rc->rc_bitmap) {
|
|
|
|
kfree(rc);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
memcpy(rc->rc_bitmap, dchunk->dqc_bitmap,
|
|
|
|
(ol_chunk_entries(sb) + 7) >> 3);
|
|
|
|
list_add_tail(&rc->rc_list, head);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_recovery_list(struct list_head *head)
|
|
|
|
{
|
|
|
|
struct ocfs2_recovery_chunk *next;
|
|
|
|
struct ocfs2_recovery_chunk *rchunk;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(rchunk, next, head, rc_list) {
|
|
|
|
list_del(&rchunk->rc_list);
|
|
|
|
kfree(rchunk->rc_bitmap);
|
|
|
|
kfree(rchunk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ocfs2_free_quota_recovery(struct ocfs2_quota_recovery *rec)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
|
2014-09-11 03:06:39 +08:00
|
|
|
for (type = 0; type < OCFS2_MAXQUOTAS; type++)
|
2008-10-21 05:50:38 +08:00
|
|
|
free_recovery_list(&(rec->r_list[type]));
|
|
|
|
kfree(rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load entries in our quota file we have to recover*/
|
|
|
|
static int ocfs2_recovery_load_quota(struct inode *lqinode,
|
|
|
|
struct ocfs2_local_disk_dqinfo *ldinfo,
|
|
|
|
int type,
|
|
|
|
struct list_head *head)
|
|
|
|
{
|
|
|
|
struct super_block *sb = lqinode->i_sb;
|
|
|
|
struct buffer_head *hbh;
|
|
|
|
struct ocfs2_local_disk_chunk *dchunk;
|
|
|
|
int i, chunks = le32_to_cpu(ldinfo->dqi_chunks);
|
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < chunks; i++) {
|
2008-11-25 22:31:27 +08:00
|
|
|
hbh = NULL;
|
|
|
|
status = ocfs2_read_quota_block(lqinode,
|
|
|
|
ol_quota_chunk_block(sb, i),
|
|
|
|
&hbh);
|
|
|
|
if (status) {
|
2008-10-21 05:50:38 +08:00
|
|
|
mlog_errno(status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dchunk = (struct ocfs2_local_disk_chunk *)hbh->b_data;
|
|
|
|
if (le32_to_cpu(dchunk->dqc_free) < ol_chunk_entries(sb))
|
|
|
|
status = ocfs2_add_recovery_chunk(sb, dchunk, i, head);
|
|
|
|
brelse(hbh);
|
|
|
|
if (status < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (status < 0)
|
|
|
|
free_recovery_list(head);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ocfs2_quota_recovery *ocfs2_alloc_quota_recovery(void)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
struct ocfs2_quota_recovery *rec;
|
|
|
|
|
|
|
|
rec = kmalloc(sizeof(struct ocfs2_quota_recovery), GFP_NOFS);
|
|
|
|
if (!rec)
|
|
|
|
return NULL;
|
2014-09-11 03:06:39 +08:00
|
|
|
for (type = 0; type < OCFS2_MAXQUOTAS; type++)
|
2008-10-21 05:50:38 +08:00
|
|
|
INIT_LIST_HEAD(&(rec->r_list[type]));
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load information we need for quota recovery into memory */
|
|
|
|
struct ocfs2_quota_recovery *ocfs2_begin_quota_recovery(
|
|
|
|
struct ocfs2_super *osb,
|
|
|
|
int slot_num)
|
|
|
|
{
|
2014-09-11 03:06:39 +08:00
|
|
|
unsigned int feature[OCFS2_MAXQUOTAS] = {
|
|
|
|
OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
|
|
|
|
OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
|
|
|
|
unsigned int ino[OCFS2_MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
|
|
|
|
LOCAL_GROUP_QUOTA_SYSTEM_INODE };
|
2008-10-21 05:50:38 +08:00
|
|
|
struct super_block *sb = osb->sb;
|
|
|
|
struct ocfs2_local_disk_dqinfo *ldinfo;
|
|
|
|
struct inode *lqinode;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
int type;
|
|
|
|
int status = 0;
|
|
|
|
struct ocfs2_quota_recovery *rec;
|
|
|
|
|
2011-07-25 01:34:54 +08:00
|
|
|
printk(KERN_NOTICE "ocfs2: Beginning quota recovery on device (%s) for "
|
|
|
|
"slot %u\n", osb->dev_str, slot_num);
|
|
|
|
|
2008-10-21 05:50:38 +08:00
|
|
|
rec = ocfs2_alloc_quota_recovery();
|
|
|
|
if (!rec)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
/* First init... */
|
|
|
|
|
2014-09-11 03:06:39 +08:00
|
|
|
for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
|
2008-10-21 05:50:38 +08:00
|
|
|
if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
|
|
|
|
continue;
|
|
|
|
/* At this point, journal of the slot is already replayed so
|
|
|
|
* we can trust metadata and data of the quota file */
|
|
|
|
lqinode = ocfs2_get_system_file_inode(osb, ino[type], slot_num);
|
|
|
|
if (!lqinode) {
|
|
|
|
status = -ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
status = ocfs2_inode_lock_full(lqinode, NULL, 1,
|
|
|
|
OCFS2_META_LOCK_RECOVERY);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_put;
|
|
|
|
}
|
|
|
|
/* Now read local header */
|
2008-11-25 22:31:27 +08:00
|
|
|
bh = NULL;
|
|
|
|
status = ocfs2_read_quota_block(lqinode, 0, &bh);
|
|
|
|
if (status) {
|
2008-10-21 05:50:38 +08:00
|
|
|
mlog_errno(status);
|
|
|
|
mlog(ML_ERROR, "failed to read quota file info header "
|
|
|
|
"(slot=%d type=%d)\n", slot_num, type);
|
|
|
|
goto out_lock;
|
|
|
|
}
|
|
|
|
ldinfo = (struct ocfs2_local_disk_dqinfo *)(bh->b_data +
|
|
|
|
OCFS2_LOCAL_INFO_OFF);
|
|
|
|
status = ocfs2_recovery_load_quota(lqinode, ldinfo, type,
|
|
|
|
&rec->r_list[type]);
|
|
|
|
brelse(bh);
|
|
|
|
out_lock:
|
|
|
|
ocfs2_inode_unlock(lqinode, 1);
|
|
|
|
out_put:
|
|
|
|
iput(lqinode);
|
|
|
|
if (status < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (status < 0) {
|
|
|
|
ocfs2_free_quota_recovery(rec);
|
|
|
|
rec = ERR_PTR(status);
|
|
|
|
}
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sync changes in local quota file into global quota file and
|
|
|
|
* reinitialize local quota file.
|
|
|
|
* The function expects local quota file to be already locked and
|
2016-11-23 21:35:26 +08:00
|
|
|
* s_umount locked in shared mode. */
|
2008-10-21 05:50:38 +08:00
|
|
|
static int ocfs2_recover_local_quota_file(struct inode *lqinode,
|
|
|
|
int type,
|
|
|
|
struct ocfs2_quota_recovery *rec)
|
|
|
|
{
|
|
|
|
struct super_block *sb = lqinode->i_sb;
|
|
|
|
struct ocfs2_mem_dqinfo *oinfo = sb_dqinfo(sb, type)->dqi_priv;
|
|
|
|
struct ocfs2_local_disk_chunk *dchunk;
|
|
|
|
struct ocfs2_local_disk_dqblk *dqblk;
|
|
|
|
struct dquot *dquot;
|
|
|
|
handle_t *handle;
|
|
|
|
struct buffer_head *hbh = NULL, *qbh = NULL;
|
|
|
|
int status = 0;
|
|
|
|
int bit, chunk;
|
|
|
|
struct ocfs2_recovery_chunk *rchunk, *next;
|
|
|
|
qsize_t spacechange, inodechange;
|
|
|
|
|
2011-02-23 22:12:48 +08:00
|
|
|
trace_ocfs2_recover_local_quota_file((unsigned long)lqinode->i_ino, type);
|
2008-10-21 05:50:38 +08:00
|
|
|
|
|
|
|
list_for_each_entry_safe(rchunk, next, &(rec->r_list[type]), rc_list) {
|
|
|
|
chunk = rchunk->rc_chunk;
|
2008-11-25 22:31:27 +08:00
|
|
|
hbh = NULL;
|
|
|
|
status = ocfs2_read_quota_block(lqinode,
|
|
|
|
ol_quota_chunk_block(sb, chunk),
|
|
|
|
&hbh);
|
|
|
|
if (status) {
|
2008-10-21 05:50:38 +08:00
|
|
|
mlog_errno(status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dchunk = (struct ocfs2_local_disk_chunk *)hbh->b_data;
|
2010-03-06 05:41:37 +08:00
|
|
|
for_each_set_bit(bit, rchunk->rc_bitmap, ol_chunk_entries(sb)) {
|
2008-11-25 22:31:27 +08:00
|
|
|
qbh = NULL;
|
|
|
|
status = ocfs2_read_quota_block(lqinode,
|
2008-10-21 05:50:38 +08:00
|
|
|
ol_dqblk_block(sb, chunk, bit),
|
2008-11-25 22:31:27 +08:00
|
|
|
&qbh);
|
|
|
|
if (status) {
|
2008-10-21 05:50:38 +08:00
|
|
|
mlog_errno(status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dqblk = (struct ocfs2_local_disk_dqblk *)(qbh->b_data +
|
|
|
|
ol_dqblk_block_off(sb, chunk, bit));
|
2012-09-16 18:11:50 +08:00
|
|
|
dquot = dqget(sb,
|
|
|
|
make_kqid(&init_user_ns, type,
|
|
|
|
le64_to_cpu(dqblk->dqb_id)));
|
2015-06-25 00:07:02 +08:00
|
|
|
if (IS_ERR(dquot)) {
|
|
|
|
status = PTR_ERR(dquot);
|
2008-10-21 05:50:38 +08:00
|
|
|
mlog(ML_ERROR, "Failed to get quota structure "
|
|
|
|
"for id %u, type %d. Cannot finish quota "
|
|
|
|
"file recovery.\n",
|
|
|
|
(unsigned)le64_to_cpu(dqblk->dqb_id),
|
|
|
|
type);
|
|
|
|
goto out_put_bh;
|
|
|
|
}
|
2009-06-02 20:24:02 +08:00
|
|
|
status = ocfs2_lock_global_qf(oinfo, 1);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_put_dquot;
|
|
|
|
}
|
|
|
|
|
2008-10-21 05:50:38 +08:00
|
|
|
handle = ocfs2_start_trans(OCFS2_SB(sb),
|
|
|
|
OCFS2_QSYNC_CREDITS);
|
|
|
|
if (IS_ERR(handle)) {
|
|
|
|
status = PTR_ERR(handle);
|
|
|
|
mlog_errno(status);
|
2009-06-02 20:24:02 +08:00
|
|
|
goto out_drop_lock;
|
2008-10-21 05:50:38 +08:00
|
|
|
}
|
2017-06-08 20:39:48 +08:00
|
|
|
down_write(&sb_dqopt(sb)->dqio_sem);
|
2017-08-07 19:19:50 +08:00
|
|
|
spin_lock(&dquot->dq_dqb_lock);
|
2008-10-21 05:50:38 +08:00
|
|
|
/* Add usage from quota entry into quota changes
|
|
|
|
* of our node. Auxiliary variables are important
|
|
|
|
* due to signedness */
|
|
|
|
spacechange = le64_to_cpu(dqblk->dqb_spacemod);
|
|
|
|
inodechange = le64_to_cpu(dqblk->dqb_inodemod);
|
|
|
|
dquot->dq_dqb.dqb_curspace += spacechange;
|
|
|
|
dquot->dq_dqb.dqb_curinodes += inodechange;
|
2017-08-07 19:19:50 +08:00
|
|
|
spin_unlock(&dquot->dq_dqb_lock);
|
2008-10-21 05:50:38 +08:00
|
|
|
/* We want to drop reference held by the crashed
|
|
|
|
* node. Since we have our own reference we know
|
|
|
|
* global structure actually won't be freed. */
|
|
|
|
status = ocfs2_global_release_dquot(dquot);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_commit;
|
|
|
|
}
|
|
|
|
/* Release local quota file entry */
|
2009-02-13 08:41:25 +08:00
|
|
|
status = ocfs2_journal_access_dq(handle,
|
|
|
|
INODE_CACHE(lqinode),
|
2008-10-21 05:50:38 +08:00
|
|
|
qbh, OCFS2_JOURNAL_ACCESS_WRITE);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_commit;
|
|
|
|
}
|
|
|
|
lock_buffer(qbh);
|
2011-11-16 06:56:34 +08:00
|
|
|
WARN_ON(!ocfs2_test_bit_unaligned(bit, dchunk->dqc_bitmap));
|
|
|
|
ocfs2_clear_bit_unaligned(bit, dchunk->dqc_bitmap);
|
2008-10-21 05:50:38 +08:00
|
|
|
le32_add_cpu(&dchunk->dqc_free, 1);
|
|
|
|
unlock_buffer(qbh);
|
2010-03-20 05:13:52 +08:00
|
|
|
ocfs2_journal_dirty(handle, qbh);
|
2008-10-21 05:50:38 +08:00
|
|
|
out_commit:
|
2017-06-08 20:39:48 +08:00
|
|
|
up_write(&sb_dqopt(sb)->dqio_sem);
|
2008-10-21 05:50:38 +08:00
|
|
|
ocfs2_commit_trans(OCFS2_SB(sb), handle);
|
2009-06-02 20:24:02 +08:00
|
|
|
out_drop_lock:
|
|
|
|
ocfs2_unlock_global_qf(oinfo, 1);
|
2008-10-21 05:50:38 +08:00
|
|
|
out_put_dquot:
|
|
|
|
dqput(dquot);
|
|
|
|
out_put_bh:
|
|
|
|
brelse(qbh);
|
|
|
|
if (status < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
brelse(hbh);
|
|
|
|
list_del(&rchunk->rc_list);
|
|
|
|
kfree(rchunk->rc_bitmap);
|
|
|
|
kfree(rchunk);
|
|
|
|
if (status < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (status < 0)
|
|
|
|
free_recovery_list(&(rec->r_list[type]));
|
2011-03-07 16:43:21 +08:00
|
|
|
if (status)
|
|
|
|
mlog_errno(status);
|
2008-10-21 05:50:38 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recover local quota files for given node different from us */
|
|
|
|
int ocfs2_finish_quota_recovery(struct ocfs2_super *osb,
|
|
|
|
struct ocfs2_quota_recovery *rec,
|
|
|
|
int slot_num)
|
|
|
|
{
|
2014-09-11 03:06:39 +08:00
|
|
|
unsigned int ino[OCFS2_MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
|
|
|
|
LOCAL_GROUP_QUOTA_SYSTEM_INODE };
|
2008-10-21 05:50:38 +08:00
|
|
|
struct super_block *sb = osb->sb;
|
|
|
|
struct ocfs2_local_disk_dqinfo *ldinfo;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
handle_t *handle;
|
|
|
|
int type;
|
|
|
|
int status = 0;
|
|
|
|
struct inode *lqinode;
|
|
|
|
unsigned int flags;
|
|
|
|
|
2011-07-25 01:34:54 +08:00
|
|
|
printk(KERN_NOTICE "ocfs2: Finishing quota recovery on device (%s) for "
|
|
|
|
"slot %u\n", osb->dev_str, slot_num);
|
|
|
|
|
2016-11-23 21:35:26 +08:00
|
|
|
down_read(&sb->s_umount);
|
2014-09-11 03:06:39 +08:00
|
|
|
for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
|
2008-10-21 05:50:38 +08:00
|
|
|
if (list_empty(&(rec->r_list[type])))
|
|
|
|
continue;
|
2011-02-23 22:12:48 +08:00
|
|
|
trace_ocfs2_finish_quota_recovery(slot_num);
|
2008-10-21 05:50:38 +08:00
|
|
|
lqinode = ocfs2_get_system_file_inode(osb, ino[type], slot_num);
|
|
|
|
if (!lqinode) {
|
|
|
|
status = -ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
status = ocfs2_inode_lock_full(lqinode, NULL, 1,
|
|
|
|
OCFS2_META_LOCK_NOQUEUE);
|
|
|
|
/* Someone else is holding the lock? Then he must be
|
|
|
|
* doing the recovery. Just skip the file... */
|
|
|
|
if (status == -EAGAIN) {
|
2011-07-25 01:34:54 +08:00
|
|
|
printk(KERN_NOTICE "ocfs2: Skipping quota recovery on "
|
|
|
|
"device (%s) for slot %d because quota file is "
|
|
|
|
"locked.\n", osb->dev_str, slot_num);
|
2008-10-21 05:50:38 +08:00
|
|
|
status = 0;
|
|
|
|
goto out_put;
|
|
|
|
} else if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_put;
|
|
|
|
}
|
|
|
|
/* Now read local header */
|
2008-11-25 22:31:27 +08:00
|
|
|
bh = NULL;
|
|
|
|
status = ocfs2_read_quota_block(lqinode, 0, &bh);
|
|
|
|
if (status) {
|
2008-10-21 05:50:38 +08:00
|
|
|
mlog_errno(status);
|
|
|
|
mlog(ML_ERROR, "failed to read quota file info header "
|
|
|
|
"(slot=%d type=%d)\n", slot_num, type);
|
|
|
|
goto out_lock;
|
|
|
|
}
|
|
|
|
ldinfo = (struct ocfs2_local_disk_dqinfo *)(bh->b_data +
|
|
|
|
OCFS2_LOCAL_INFO_OFF);
|
|
|
|
/* Is recovery still needed? */
|
|
|
|
flags = le32_to_cpu(ldinfo->dqi_flags);
|
|
|
|
if (!(flags & OLQF_CLEAN))
|
|
|
|
status = ocfs2_recover_local_quota_file(lqinode,
|
|
|
|
type,
|
|
|
|
rec);
|
|
|
|
/* We don't want to mark file as clean when it is actually
|
|
|
|
* active */
|
|
|
|
if (slot_num == osb->slot_num)
|
|
|
|
goto out_bh;
|
|
|
|
/* Mark quota file as clean if we are recovering quota file of
|
|
|
|
* some other node. */
|
2009-07-22 19:17:21 +08:00
|
|
|
handle = ocfs2_start_trans(osb,
|
|
|
|
OCFS2_LOCAL_QINFO_WRITE_CREDITS);
|
2008-10-21 05:50:38 +08:00
|
|
|
if (IS_ERR(handle)) {
|
|
|
|
status = PTR_ERR(handle);
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_bh;
|
|
|
|
}
|
2009-02-13 08:41:25 +08:00
|
|
|
status = ocfs2_journal_access_dq(handle, INODE_CACHE(lqinode),
|
|
|
|
bh,
|
2008-10-18 10:25:01 +08:00
|
|
|
OCFS2_JOURNAL_ACCESS_WRITE);
|
2008-10-21 05:50:38 +08:00
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_trans;
|
|
|
|
}
|
|
|
|
lock_buffer(bh);
|
|
|
|
ldinfo->dqi_flags = cpu_to_le32(flags | OLQF_CLEAN);
|
|
|
|
unlock_buffer(bh);
|
2010-03-20 05:13:52 +08:00
|
|
|
ocfs2_journal_dirty(handle, bh);
|
2008-10-21 05:50:38 +08:00
|
|
|
out_trans:
|
|
|
|
ocfs2_commit_trans(osb, handle);
|
|
|
|
out_bh:
|
|
|
|
brelse(bh);
|
|
|
|
out_lock:
|
|
|
|
ocfs2_inode_unlock(lqinode, 1);
|
|
|
|
out_put:
|
|
|
|
iput(lqinode);
|
|
|
|
if (status < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
2016-11-23 21:35:26 +08:00
|
|
|
up_read(&sb->s_umount);
|
2008-10-21 05:50:38 +08:00
|
|
|
kfree(rec);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-08-26 01:56:50 +08:00
|
|
|
/* Read information header from quota file */
|
|
|
|
static int ocfs2_local_read_info(struct super_block *sb, int type)
|
|
|
|
{
|
|
|
|
struct ocfs2_local_disk_dqinfo *ldinfo;
|
|
|
|
struct mem_dqinfo *info = sb_dqinfo(sb, type);
|
|
|
|
struct ocfs2_mem_dqinfo *oinfo;
|
|
|
|
struct inode *lqinode = sb_dqopt(sb)->files[type];
|
|
|
|
int status;
|
|
|
|
struct buffer_head *bh = NULL;
|
2008-10-21 05:50:38 +08:00
|
|
|
struct ocfs2_quota_recovery *rec;
|
2008-08-26 01:56:50 +08:00
|
|
|
int locked = 0;
|
|
|
|
|
2014-10-09 22:54:13 +08:00
|
|
|
info->dqi_max_spc_limit = 0x7fffffffffffffffLL;
|
|
|
|
info->dqi_max_ino_limit = 0x7fffffffffffffffLL;
|
2008-08-26 01:56:50 +08:00
|
|
|
oinfo = kmalloc(sizeof(struct ocfs2_mem_dqinfo), GFP_NOFS);
|
|
|
|
if (!oinfo) {
|
|
|
|
mlog(ML_ERROR, "failed to allocate memory for ocfs2 quota"
|
|
|
|
" info.");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
info->dqi_priv = oinfo;
|
|
|
|
oinfo->dqi_type = type;
|
|
|
|
INIT_LIST_HEAD(&oinfo->dqi_chunk);
|
2008-10-21 05:50:38 +08:00
|
|
|
oinfo->dqi_rec = NULL;
|
2008-08-26 01:56:50 +08:00
|
|
|
oinfo->dqi_lqi_bh = NULL;
|
2010-04-29 01:04:29 +08:00
|
|
|
oinfo->dqi_libh = NULL;
|
2008-08-26 01:56:50 +08:00
|
|
|
|
|
|
|
status = ocfs2_global_read_info(sb, type);
|
|
|
|
if (status < 0)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
status = ocfs2_inode_lock(lqinode, &oinfo->dqi_lqi_bh, 1);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
locked = 1;
|
|
|
|
|
|
|
|
/* Now read local header */
|
2008-11-25 22:31:27 +08:00
|
|
|
status = ocfs2_read_quota_block(lqinode, 0, &bh);
|
|
|
|
if (status) {
|
2008-08-26 01:56:50 +08:00
|
|
|
mlog_errno(status);
|
|
|
|
mlog(ML_ERROR, "failed to read quota file info header "
|
|
|
|
"(type=%d)\n", type);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
ldinfo = (struct ocfs2_local_disk_dqinfo *)(bh->b_data +
|
|
|
|
OCFS2_LOCAL_INFO_OFF);
|
2014-11-19 17:41:41 +08:00
|
|
|
oinfo->dqi_flags = le32_to_cpu(ldinfo->dqi_flags);
|
2008-08-26 01:56:50 +08:00
|
|
|
oinfo->dqi_chunks = le32_to_cpu(ldinfo->dqi_chunks);
|
|
|
|
oinfo->dqi_blocks = le32_to_cpu(ldinfo->dqi_blocks);
|
2010-04-29 01:04:29 +08:00
|
|
|
oinfo->dqi_libh = bh;
|
2008-08-26 01:56:50 +08:00
|
|
|
|
|
|
|
/* We crashed when using local quota file? */
|
2014-11-19 17:41:41 +08:00
|
|
|
if (!(oinfo->dqi_flags & OLQF_CLEAN)) {
|
2008-10-21 05:50:38 +08:00
|
|
|
rec = OCFS2_SB(sb)->quota_rec;
|
|
|
|
if (!rec) {
|
|
|
|
rec = ocfs2_alloc_quota_recovery();
|
|
|
|
if (!rec) {
|
|
|
|
status = -ENOMEM;
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
OCFS2_SB(sb)->quota_rec = rec;
|
|
|
|
}
|
2008-08-26 01:56:50 +08:00
|
|
|
|
2008-10-21 05:50:38 +08:00
|
|
|
status = ocfs2_recovery_load_quota(lqinode, ldinfo, type,
|
|
|
|
&rec->r_list[type]);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status = ocfs2_load_local_quota_bitmaps(lqinode,
|
2008-08-26 01:56:50 +08:00
|
|
|
ldinfo,
|
|
|
|
&oinfo->dqi_chunk);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now mark quota file as used */
|
2014-11-19 17:41:41 +08:00
|
|
|
oinfo->dqi_flags &= ~OLQF_CLEAN;
|
2008-08-26 01:56:50 +08:00
|
|
|
status = ocfs2_modify_bh(lqinode, bh, olq_update_info, info);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out_err:
|
|
|
|
if (oinfo) {
|
|
|
|
iput(oinfo->dqi_gqinode);
|
|
|
|
ocfs2_simple_drop_lockres(OCFS2_SB(sb), &oinfo->dqi_gqlock);
|
|
|
|
ocfs2_lock_res_free(&oinfo->dqi_gqlock);
|
|
|
|
brelse(oinfo->dqi_lqi_bh);
|
|
|
|
if (locked)
|
|
|
|
ocfs2_inode_unlock(lqinode, 1);
|
|
|
|
ocfs2_release_local_quota_bitmaps(&oinfo->dqi_chunk);
|
|
|
|
kfree(oinfo);
|
|
|
|
}
|
|
|
|
brelse(bh);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write local info to quota file */
|
|
|
|
static int ocfs2_local_write_info(struct super_block *sb, int type)
|
|
|
|
{
|
|
|
|
struct mem_dqinfo *info = sb_dqinfo(sb, type);
|
|
|
|
struct buffer_head *bh = ((struct ocfs2_mem_dqinfo *)info->dqi_priv)
|
2010-04-29 01:04:29 +08:00
|
|
|
->dqi_libh;
|
2008-08-26 01:56:50 +08:00
|
|
|
int status;
|
|
|
|
|
|
|
|
status = ocfs2_modify_bh(sb_dqopt(sb)->files[type], bh, olq_update_info,
|
|
|
|
info);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release info from memory */
|
|
|
|
static int ocfs2_local_free_info(struct super_block *sb, int type)
|
|
|
|
{
|
|
|
|
struct mem_dqinfo *info = sb_dqinfo(sb, type);
|
|
|
|
struct ocfs2_mem_dqinfo *oinfo = info->dqi_priv;
|
|
|
|
struct ocfs2_quota_chunk *chunk;
|
|
|
|
struct ocfs2_local_disk_chunk *dchunk;
|
|
|
|
int mark_clean = 1, len;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
iput(oinfo->dqi_gqinode);
|
|
|
|
ocfs2_simple_drop_lockres(OCFS2_SB(sb), &oinfo->dqi_gqlock);
|
|
|
|
ocfs2_lock_res_free(&oinfo->dqi_gqlock);
|
|
|
|
list_for_each_entry(chunk, &oinfo->dqi_chunk, qc_chunk) {
|
|
|
|
dchunk = (struct ocfs2_local_disk_chunk *)
|
|
|
|
(chunk->qc_headerbh->b_data);
|
|
|
|
if (chunk->qc_num < oinfo->dqi_chunks - 1) {
|
|
|
|
len = ol_chunk_entries(sb);
|
|
|
|
} else {
|
|
|
|
len = (oinfo->dqi_blocks -
|
|
|
|
ol_quota_chunk_block(sb, chunk->qc_num) - 1)
|
|
|
|
* ol_quota_entries_per_block(sb);
|
|
|
|
}
|
|
|
|
/* Not all entries free? Bug! */
|
|
|
|
if (le32_to_cpu(dchunk->dqc_free) != len) {
|
|
|
|
mlog(ML_ERROR, "releasing quota file with used "
|
|
|
|
"entries (type=%d)\n", type);
|
|
|
|
mark_clean = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ocfs2_release_local_quota_bitmaps(&oinfo->dqi_chunk);
|
|
|
|
|
2016-11-23 21:35:26 +08:00
|
|
|
/*
|
|
|
|
* s_umount held in exclusive mode protects us against racing with
|
|
|
|
* recovery thread...
|
|
|
|
*/
|
2008-10-21 05:50:38 +08:00
|
|
|
if (oinfo->dqi_rec) {
|
|
|
|
ocfs2_free_quota_recovery(oinfo->dqi_rec);
|
|
|
|
mark_clean = 0;
|
|
|
|
}
|
|
|
|
|
2008-08-26 01:56:50 +08:00
|
|
|
if (!mark_clean)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Mark local file as clean */
|
2014-11-19 17:41:41 +08:00
|
|
|
oinfo->dqi_flags |= OLQF_CLEAN;
|
2008-08-26 01:56:50 +08:00
|
|
|
status = ocfs2_modify_bh(sb_dqopt(sb)->files[type],
|
2010-04-29 01:04:29 +08:00
|
|
|
oinfo->dqi_libh,
|
2008-08-26 01:56:50 +08:00
|
|
|
olq_update_info,
|
|
|
|
info);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
ocfs2_inode_unlock(sb_dqopt(sb)->files[type], 1);
|
2010-04-29 01:04:29 +08:00
|
|
|
brelse(oinfo->dqi_libh);
|
2008-08-26 01:56:50 +08:00
|
|
|
brelse(oinfo->dqi_lqi_bh);
|
|
|
|
kfree(oinfo);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void olq_set_dquot(struct buffer_head *bh, void *private)
|
|
|
|
{
|
|
|
|
struct ocfs2_dquot *od = private;
|
|
|
|
struct ocfs2_local_disk_dqblk *dqblk;
|
|
|
|
struct super_block *sb = od->dq_dquot.dq_sb;
|
|
|
|
|
|
|
|
dqblk = (struct ocfs2_local_disk_dqblk *)(bh->b_data
|
|
|
|
+ ol_dqblk_block_offset(sb, od->dq_local_off));
|
|
|
|
|
2012-09-16 18:56:19 +08:00
|
|
|
dqblk->dqb_id = cpu_to_le64(from_kqid(&init_user_ns,
|
|
|
|
od->dq_dquot.dq_id));
|
2017-08-07 19:19:50 +08:00
|
|
|
spin_lock(&od->dq_dquot.dq_dqb_lock);
|
2008-08-26 01:56:50 +08:00
|
|
|
dqblk->dqb_spacemod = cpu_to_le64(od->dq_dquot.dq_dqb.dqb_curspace -
|
|
|
|
od->dq_origspace);
|
|
|
|
dqblk->dqb_inodemod = cpu_to_le64(od->dq_dquot.dq_dqb.dqb_curinodes -
|
|
|
|
od->dq_originodes);
|
2017-08-07 19:19:50 +08:00
|
|
|
spin_unlock(&od->dq_dquot.dq_dqb_lock);
|
2011-02-23 22:12:48 +08:00
|
|
|
trace_olq_set_dquot(
|
|
|
|
(unsigned long long)le64_to_cpu(dqblk->dqb_spacemod),
|
|
|
|
(unsigned long long)le64_to_cpu(dqblk->dqb_inodemod),
|
2012-09-16 18:56:19 +08:00
|
|
|
from_kqid(&init_user_ns, od->dq_dquot.dq_id));
|
2008-08-26 01:56:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write dquot to local quota file */
|
2010-05-14 00:05:15 +08:00
|
|
|
int ocfs2_local_write_dquot(struct dquot *dquot)
|
2008-08-26 01:56:50 +08:00
|
|
|
{
|
|
|
|
struct super_block *sb = dquot->dq_sb;
|
|
|
|
struct ocfs2_dquot *od = OCFS2_DQUOT(dquot);
|
2010-04-28 06:22:30 +08:00
|
|
|
struct buffer_head *bh;
|
2012-09-16 18:56:19 +08:00
|
|
|
struct inode *lqinode = sb_dqopt(sb)->files[dquot->dq_id.type];
|
2008-08-26 01:56:50 +08:00
|
|
|
int status;
|
|
|
|
|
2010-04-28 06:22:30 +08:00
|
|
|
status = ocfs2_read_quota_phys_block(lqinode, od->dq_local_phys_blk,
|
|
|
|
&bh);
|
2008-11-25 22:31:27 +08:00
|
|
|
if (status) {
|
2008-08-26 01:56:50 +08:00
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
2010-04-28 06:22:30 +08:00
|
|
|
status = ocfs2_modify_bh(lqinode, bh, olq_set_dquot, od);
|
2008-08-26 01:56:50 +08:00
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
brelse(bh);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find free entry in local quota file */
|
|
|
|
static struct ocfs2_quota_chunk *ocfs2_find_free_entry(struct super_block *sb,
|
|
|
|
int type,
|
|
|
|
int *offset)
|
|
|
|
{
|
|
|
|
struct mem_dqinfo *info = sb_dqinfo(sb, type);
|
|
|
|
struct ocfs2_mem_dqinfo *oinfo = info->dqi_priv;
|
2022-04-30 05:37:57 +08:00
|
|
|
struct ocfs2_quota_chunk *chunk = NULL, *iter;
|
2008-08-26 01:56:50 +08:00
|
|
|
struct ocfs2_local_disk_chunk *dchunk;
|
|
|
|
int found = 0, len;
|
|
|
|
|
2022-04-30 05:37:57 +08:00
|
|
|
list_for_each_entry(iter, &oinfo->dqi_chunk, qc_chunk) {
|
2008-08-26 01:56:50 +08:00
|
|
|
dchunk = (struct ocfs2_local_disk_chunk *)
|
2022-04-30 05:37:57 +08:00
|
|
|
iter->qc_headerbh->b_data;
|
2008-08-26 01:56:50 +08:00
|
|
|
if (le32_to_cpu(dchunk->dqc_free) > 0) {
|
2022-04-30 05:37:57 +08:00
|
|
|
chunk = iter;
|
2008-08-26 01:56:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-04-30 05:37:57 +08:00
|
|
|
if (!chunk)
|
2008-08-26 01:56:50 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (chunk->qc_num < oinfo->dqi_chunks - 1) {
|
|
|
|
len = ol_chunk_entries(sb);
|
|
|
|
} else {
|
|
|
|
len = (oinfo->dqi_blocks -
|
|
|
|
ol_quota_chunk_block(sb, chunk->qc_num) - 1)
|
|
|
|
* ol_quota_entries_per_block(sb);
|
|
|
|
}
|
|
|
|
|
2011-11-16 06:56:34 +08:00
|
|
|
found = ocfs2_find_next_zero_bit_unaligned(dchunk->dqc_bitmap, len, 0);
|
2008-08-26 01:56:50 +08:00
|
|
|
/* We failed? */
|
|
|
|
if (found == len) {
|
|
|
|
mlog(ML_ERROR, "Did not find empty entry in chunk %d with %u"
|
|
|
|
" entries free (type=%d)\n", chunk->qc_num,
|
|
|
|
le32_to_cpu(dchunk->dqc_free), type);
|
|
|
|
return ERR_PTR(-EIO);
|
|
|
|
}
|
|
|
|
*offset = found;
|
|
|
|
return chunk;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add new chunk to the local quota file */
|
|
|
|
static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk(
|
|
|
|
struct super_block *sb,
|
|
|
|
int type,
|
|
|
|
int *offset)
|
|
|
|
{
|
|
|
|
struct mem_dqinfo *info = sb_dqinfo(sb, type);
|
|
|
|
struct ocfs2_mem_dqinfo *oinfo = info->dqi_priv;
|
|
|
|
struct inode *lqinode = sb_dqopt(sb)->files[type];
|
|
|
|
struct ocfs2_quota_chunk *chunk = NULL;
|
|
|
|
struct ocfs2_local_disk_chunk *dchunk;
|
|
|
|
int status;
|
|
|
|
handle_t *handle;
|
2009-07-22 19:17:17 +08:00
|
|
|
struct buffer_head *bh = NULL, *dbh = NULL;
|
2008-08-26 01:56:50 +08:00
|
|
|
u64 p_blkno;
|
|
|
|
|
|
|
|
/* We are protected by dqio_sem so no locking needed */
|
2010-07-02 06:13:31 +08:00
|
|
|
status = ocfs2_extend_no_holes(lqinode, NULL,
|
2013-09-12 05:19:45 +08:00
|
|
|
i_size_read(lqinode) + 2 * sb->s_blocksize,
|
|
|
|
i_size_read(lqinode));
|
2008-08-26 01:56:50 +08:00
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
status = ocfs2_simple_size_update(lqinode, oinfo->dqi_lqi_bh,
|
2013-09-12 05:19:45 +08:00
|
|
|
i_size_read(lqinode) + 2 * sb->s_blocksize);
|
2008-08-26 01:56:50 +08:00
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
chunk = kmem_cache_alloc(ocfs2_qf_chunk_cachep, GFP_NOFS);
|
|
|
|
if (!chunk) {
|
|
|
|
status = -ENOMEM;
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-07-22 19:17:21 +08:00
|
|
|
/* Local quota info and two new blocks we initialize */
|
|
|
|
handle = ocfs2_start_trans(OCFS2_SB(sb),
|
|
|
|
OCFS2_LOCAL_QINFO_WRITE_CREDITS +
|
|
|
|
2 * OCFS2_QUOTA_BLOCK_UPDATE_CREDITS);
|
2009-07-22 19:17:17 +08:00
|
|
|
if (IS_ERR(handle)) {
|
|
|
|
status = PTR_ERR(handle);
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
2008-08-26 01:56:50 +08:00
|
|
|
|
2009-07-22 19:17:17 +08:00
|
|
|
/* Initialize chunk header */
|
2008-08-26 01:56:50 +08:00
|
|
|
status = ocfs2_extent_map_get_blocks(lqinode, oinfo->dqi_blocks,
|
|
|
|
&p_blkno, NULL, NULL);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
2009-07-22 19:17:17 +08:00
|
|
|
goto out_trans;
|
2008-08-26 01:56:50 +08:00
|
|
|
}
|
|
|
|
bh = sb_getblk(sb, p_blkno);
|
|
|
|
if (!bh) {
|
|
|
|
status = -ENOMEM;
|
|
|
|
mlog_errno(status);
|
2009-07-22 19:17:17 +08:00
|
|
|
goto out_trans;
|
2008-08-26 01:56:50 +08:00
|
|
|
}
|
|
|
|
dchunk = (struct ocfs2_local_disk_chunk *)bh->b_data;
|
2009-02-11 12:00:41 +08:00
|
|
|
ocfs2_set_new_buffer_uptodate(INODE_CACHE(lqinode), bh);
|
2009-02-13 08:41:25 +08:00
|
|
|
status = ocfs2_journal_access_dq(handle, INODE_CACHE(lqinode), bh,
|
2009-07-22 19:17:17 +08:00
|
|
|
OCFS2_JOURNAL_ACCESS_CREATE);
|
2008-08-26 01:56:50 +08:00
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_trans;
|
|
|
|
}
|
|
|
|
lock_buffer(bh);
|
2008-11-25 07:21:36 +08:00
|
|
|
dchunk->dqc_free = cpu_to_le32(ol_quota_entries_per_block(sb));
|
2008-08-26 01:56:50 +08:00
|
|
|
memset(dchunk->dqc_bitmap, 0,
|
|
|
|
sb->s_blocksize - sizeof(struct ocfs2_local_disk_chunk) -
|
|
|
|
OCFS2_QBLK_RESERVED_SPACE);
|
|
|
|
unlock_buffer(bh);
|
2010-03-20 05:13:52 +08:00
|
|
|
ocfs2_journal_dirty(handle, bh);
|
2008-08-26 01:56:50 +08:00
|
|
|
|
2009-07-22 19:17:17 +08:00
|
|
|
/* Initialize new block with structures */
|
|
|
|
status = ocfs2_extent_map_get_blocks(lqinode, oinfo->dqi_blocks + 1,
|
|
|
|
&p_blkno, NULL, NULL);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_trans;
|
|
|
|
}
|
|
|
|
dbh = sb_getblk(sb, p_blkno);
|
|
|
|
if (!dbh) {
|
|
|
|
status = -ENOMEM;
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_trans;
|
|
|
|
}
|
2009-02-11 12:00:41 +08:00
|
|
|
ocfs2_set_new_buffer_uptodate(INODE_CACHE(lqinode), dbh);
|
2009-02-13 08:41:25 +08:00
|
|
|
status = ocfs2_journal_access_dq(handle, INODE_CACHE(lqinode), dbh,
|
2009-07-22 19:17:17 +08:00
|
|
|
OCFS2_JOURNAL_ACCESS_CREATE);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_trans;
|
|
|
|
}
|
|
|
|
lock_buffer(dbh);
|
|
|
|
memset(dbh->b_data, 0, sb->s_blocksize - OCFS2_QBLK_RESERVED_SPACE);
|
|
|
|
unlock_buffer(dbh);
|
2010-03-20 05:13:52 +08:00
|
|
|
ocfs2_journal_dirty(handle, dbh);
|
2009-07-22 19:17:17 +08:00
|
|
|
|
|
|
|
/* Update local quotafile info */
|
2008-08-26 01:56:50 +08:00
|
|
|
oinfo->dqi_blocks += 2;
|
|
|
|
oinfo->dqi_chunks++;
|
|
|
|
status = ocfs2_local_write_info(sb, type);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_trans;
|
|
|
|
}
|
|
|
|
status = ocfs2_commit_trans(OCFS2_SB(sb), handle);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&chunk->qc_chunk, &oinfo->dqi_chunk);
|
|
|
|
chunk->qc_num = list_entry(chunk->qc_chunk.prev,
|
|
|
|
struct ocfs2_quota_chunk,
|
|
|
|
qc_chunk)->qc_num + 1;
|
|
|
|
chunk->qc_headerbh = bh;
|
|
|
|
*offset = 0;
|
|
|
|
return chunk;
|
|
|
|
out_trans:
|
|
|
|
ocfs2_commit_trans(OCFS2_SB(sb), handle);
|
|
|
|
out:
|
|
|
|
brelse(bh);
|
2009-07-22 19:17:17 +08:00
|
|
|
brelse(dbh);
|
2008-08-26 01:56:50 +08:00
|
|
|
kmem_cache_free(ocfs2_qf_chunk_cachep, chunk);
|
|
|
|
return ERR_PTR(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find free entry in local quota file */
|
|
|
|
static struct ocfs2_quota_chunk *ocfs2_extend_local_quota_file(
|
|
|
|
struct super_block *sb,
|
|
|
|
int type,
|
|
|
|
int *offset)
|
|
|
|
{
|
|
|
|
struct mem_dqinfo *info = sb_dqinfo(sb, type);
|
|
|
|
struct ocfs2_mem_dqinfo *oinfo = info->dqi_priv;
|
|
|
|
struct ocfs2_quota_chunk *chunk;
|
|
|
|
struct inode *lqinode = sb_dqopt(sb)->files[type];
|
|
|
|
struct ocfs2_local_disk_chunk *dchunk;
|
|
|
|
int epb = ol_quota_entries_per_block(sb);
|
|
|
|
unsigned int chunk_blocks;
|
2009-07-22 19:17:17 +08:00
|
|
|
struct buffer_head *bh;
|
|
|
|
u64 p_blkno;
|
2008-08-26 01:56:50 +08:00
|
|
|
int status;
|
|
|
|
handle_t *handle;
|
|
|
|
|
|
|
|
if (list_empty(&oinfo->dqi_chunk))
|
|
|
|
return ocfs2_local_quota_add_chunk(sb, type, offset);
|
|
|
|
/* Is the last chunk full? */
|
|
|
|
chunk = list_entry(oinfo->dqi_chunk.prev,
|
|
|
|
struct ocfs2_quota_chunk, qc_chunk);
|
|
|
|
chunk_blocks = oinfo->dqi_blocks -
|
|
|
|
ol_quota_chunk_block(sb, chunk->qc_num) - 1;
|
|
|
|
if (ol_chunk_blocks(sb) == chunk_blocks)
|
|
|
|
return ocfs2_local_quota_add_chunk(sb, type, offset);
|
|
|
|
|
|
|
|
/* We are protected by dqio_sem so no locking needed */
|
2010-07-02 06:13:31 +08:00
|
|
|
status = ocfs2_extend_no_holes(lqinode, NULL,
|
2013-09-12 05:19:45 +08:00
|
|
|
i_size_read(lqinode) + sb->s_blocksize,
|
|
|
|
i_size_read(lqinode));
|
2008-08-26 01:56:50 +08:00
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
status = ocfs2_simple_size_update(lqinode, oinfo->dqi_lqi_bh,
|
2013-09-12 05:19:45 +08:00
|
|
|
i_size_read(lqinode) + sb->s_blocksize);
|
2008-08-26 01:56:50 +08:00
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-07-22 19:17:17 +08:00
|
|
|
|
|
|
|
/* Get buffer from the just added block */
|
|
|
|
status = ocfs2_extent_map_get_blocks(lqinode, oinfo->dqi_blocks,
|
|
|
|
&p_blkno, NULL, NULL);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
bh = sb_getblk(sb, p_blkno);
|
|
|
|
if (!bh) {
|
|
|
|
status = -ENOMEM;
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-02-11 12:00:41 +08:00
|
|
|
ocfs2_set_new_buffer_uptodate(INODE_CACHE(lqinode), bh);
|
2009-07-22 19:17:17 +08:00
|
|
|
|
2009-07-22 19:17:21 +08:00
|
|
|
/* Local quota info, chunk header and the new block we initialize */
|
|
|
|
handle = ocfs2_start_trans(OCFS2_SB(sb),
|
|
|
|
OCFS2_LOCAL_QINFO_WRITE_CREDITS +
|
|
|
|
2 * OCFS2_QUOTA_BLOCK_UPDATE_CREDITS);
|
2008-08-26 01:56:50 +08:00
|
|
|
if (IS_ERR(handle)) {
|
|
|
|
status = PTR_ERR(handle);
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-07-22 19:17:17 +08:00
|
|
|
/* Zero created block */
|
2009-02-13 08:41:25 +08:00
|
|
|
status = ocfs2_journal_access_dq(handle, INODE_CACHE(lqinode), bh,
|
2009-07-22 19:17:17 +08:00
|
|
|
OCFS2_JOURNAL_ACCESS_CREATE);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_trans;
|
|
|
|
}
|
|
|
|
lock_buffer(bh);
|
|
|
|
memset(bh->b_data, 0, sb->s_blocksize);
|
|
|
|
unlock_buffer(bh);
|
2010-03-20 05:13:52 +08:00
|
|
|
ocfs2_journal_dirty(handle, bh);
|
|
|
|
|
2009-07-22 19:17:17 +08:00
|
|
|
/* Update chunk header */
|
2009-02-13 08:41:25 +08:00
|
|
|
status = ocfs2_journal_access_dq(handle, INODE_CACHE(lqinode),
|
|
|
|
chunk->qc_headerbh,
|
2008-08-26 01:56:50 +08:00
|
|
|
OCFS2_JOURNAL_ACCESS_WRITE);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_trans;
|
|
|
|
}
|
|
|
|
|
|
|
|
dchunk = (struct ocfs2_local_disk_chunk *)chunk->qc_headerbh->b_data;
|
|
|
|
lock_buffer(chunk->qc_headerbh);
|
|
|
|
le32_add_cpu(&dchunk->dqc_free, ol_quota_entries_per_block(sb));
|
|
|
|
unlock_buffer(chunk->qc_headerbh);
|
2010-03-20 05:13:52 +08:00
|
|
|
ocfs2_journal_dirty(handle, chunk->qc_headerbh);
|
|
|
|
|
2009-07-22 19:17:17 +08:00
|
|
|
/* Update file header */
|
2008-08-26 01:56:50 +08:00
|
|
|
oinfo->dqi_blocks++;
|
|
|
|
status = ocfs2_local_write_info(sb, type);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out_trans;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = ocfs2_commit_trans(OCFS2_SB(sb), handle);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
*offset = chunk_blocks * epb;
|
|
|
|
return chunk;
|
|
|
|
out_trans:
|
|
|
|
ocfs2_commit_trans(OCFS2_SB(sb), handle);
|
|
|
|
out:
|
|
|
|
return ERR_PTR(status);
|
|
|
|
}
|
|
|
|
|
2008-11-25 07:21:36 +08:00
|
|
|
static void olq_alloc_dquot(struct buffer_head *bh, void *private)
|
2008-08-26 01:56:50 +08:00
|
|
|
{
|
|
|
|
int *offset = private;
|
|
|
|
struct ocfs2_local_disk_chunk *dchunk;
|
|
|
|
|
|
|
|
dchunk = (struct ocfs2_local_disk_chunk *)bh->b_data;
|
2011-11-16 06:56:34 +08:00
|
|
|
ocfs2_set_bit_unaligned(*offset, dchunk->dqc_bitmap);
|
2008-08-26 01:56:50 +08:00
|
|
|
le32_add_cpu(&dchunk->dqc_free, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create dquot in the local file for given id */
|
2010-03-31 22:25:37 +08:00
|
|
|
int ocfs2_create_local_dquot(struct dquot *dquot)
|
2008-08-26 01:56:50 +08:00
|
|
|
{
|
|
|
|
struct super_block *sb = dquot->dq_sb;
|
2012-09-16 18:56:19 +08:00
|
|
|
int type = dquot->dq_id.type;
|
2008-08-26 01:56:50 +08:00
|
|
|
struct inode *lqinode = sb_dqopt(sb)->files[type];
|
|
|
|
struct ocfs2_quota_chunk *chunk;
|
|
|
|
struct ocfs2_dquot *od = OCFS2_DQUOT(dquot);
|
|
|
|
int offset;
|
|
|
|
int status;
|
2010-04-28 06:22:30 +08:00
|
|
|
u64 pcount;
|
2008-08-26 01:56:50 +08:00
|
|
|
|
2010-04-28 06:22:30 +08:00
|
|
|
down_write(&OCFS2_I(lqinode)->ip_alloc_sem);
|
2008-08-26 01:56:50 +08:00
|
|
|
chunk = ocfs2_find_free_entry(sb, type, &offset);
|
|
|
|
if (!chunk) {
|
|
|
|
chunk = ocfs2_extend_local_quota_file(sb, type, &offset);
|
2010-04-28 06:22:30 +08:00
|
|
|
if (IS_ERR(chunk)) {
|
|
|
|
status = PTR_ERR(chunk);
|
|
|
|
goto out;
|
|
|
|
}
|
2008-08-26 01:56:50 +08:00
|
|
|
} else if (IS_ERR(chunk)) {
|
2010-04-28 06:22:30 +08:00
|
|
|
status = PTR_ERR(chunk);
|
|
|
|
goto out;
|
2008-08-26 01:56:50 +08:00
|
|
|
}
|
|
|
|
od->dq_local_off = ol_dqblk_off(sb, chunk->qc_num, offset);
|
|
|
|
od->dq_chunk = chunk;
|
2010-04-28 06:22:30 +08:00
|
|
|
status = ocfs2_extent_map_get_blocks(lqinode,
|
|
|
|
ol_dqblk_block(sb, chunk->qc_num, offset),
|
|
|
|
&od->dq_local_phys_blk,
|
|
|
|
&pcount,
|
|
|
|
NULL);
|
2008-08-26 01:56:50 +08:00
|
|
|
|
|
|
|
/* Initialize dquot structure on disk */
|
|
|
|
status = ocfs2_local_write_dquot(dquot);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark structure as allocated */
|
|
|
|
status = ocfs2_modify_bh(lqinode, chunk->qc_headerbh, olq_alloc_dquot,
|
|
|
|
&offset);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
out:
|
2010-04-28 06:22:30 +08:00
|
|
|
up_write(&OCFS2_I(lqinode)->ip_alloc_sem);
|
2008-08-26 01:56:50 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2010-03-31 22:25:37 +08:00
|
|
|
/*
|
|
|
|
* Release dquot structure from local quota file. ocfs2_release_dquot() has
|
|
|
|
* already started a transaction and written all changes to global quota file
|
|
|
|
*/
|
|
|
|
int ocfs2_local_release_dquot(handle_t *handle, struct dquot *dquot)
|
2008-08-26 01:56:50 +08:00
|
|
|
{
|
|
|
|
int status;
|
2012-09-16 18:56:19 +08:00
|
|
|
int type = dquot->dq_id.type;
|
2008-08-26 01:56:50 +08:00
|
|
|
struct ocfs2_dquot *od = OCFS2_DQUOT(dquot);
|
|
|
|
struct super_block *sb = dquot->dq_sb;
|
|
|
|
struct ocfs2_local_disk_chunk *dchunk;
|
|
|
|
int offset;
|
|
|
|
|
2009-02-13 08:41:25 +08:00
|
|
|
status = ocfs2_journal_access_dq(handle,
|
|
|
|
INODE_CACHE(sb_dqopt(sb)->files[type]),
|
2008-08-26 01:56:50 +08:00
|
|
|
od->dq_chunk->qc_headerbh, OCFS2_JOURNAL_ACCESS_WRITE);
|
|
|
|
if (status < 0) {
|
|
|
|
mlog_errno(status);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
offset = ol_dqblk_chunk_off(sb, od->dq_chunk->qc_num,
|
|
|
|
od->dq_local_off);
|
|
|
|
dchunk = (struct ocfs2_local_disk_chunk *)
|
|
|
|
(od->dq_chunk->qc_headerbh->b_data);
|
|
|
|
/* Mark structure as freed */
|
|
|
|
lock_buffer(od->dq_chunk->qc_headerbh);
|
2011-11-16 06:56:34 +08:00
|
|
|
ocfs2_clear_bit_unaligned(offset, dchunk->dqc_bitmap);
|
2008-08-26 01:56:50 +08:00
|
|
|
le32_add_cpu(&dchunk->dqc_free, 1);
|
|
|
|
unlock_buffer(od->dq_chunk->qc_headerbh);
|
2010-03-20 05:13:52 +08:00
|
|
|
ocfs2_journal_dirty(handle, od->dq_chunk->qc_headerbh);
|
|
|
|
|
2008-08-26 01:56:50 +08:00
|
|
|
out:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-10-16 19:26:03 +08:00
|
|
|
static const struct quota_format_ops ocfs2_format_ops = {
|
2008-08-26 01:56:50 +08:00
|
|
|
.check_quota_file = ocfs2_local_check_quota_file,
|
|
|
|
.read_file_info = ocfs2_local_read_info,
|
|
|
|
.write_file_info = ocfs2_global_write_info,
|
|
|
|
.free_file_info = ocfs2_local_free_info,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct quota_format_type ocfs2_quota_format = {
|
|
|
|
.qf_fmt_id = QFMT_OCFS2,
|
|
|
|
.qf_ops = &ocfs2_format_ops,
|
|
|
|
.qf_owner = THIS_MODULE
|
|
|
|
};
|