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 07:07:57 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-05-24 15:31:25 -07:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/random.h>
|
|
|
|
#include <linux/buffer_head.h>
|
|
|
|
#include <linux/utsname.h>
|
|
|
|
#include <linux/kthread.h>
|
|
|
|
|
|
|
|
#include "ext4.h"
|
|
|
|
|
2012-04-29 15:47:10 -07:00
|
|
|
/* Checksumming functions */
|
2013-04-09 20:56:48 -07:00
|
|
|
static __le32 ext4_mmp_csum(struct super_block *sb, struct mmp_struct *mmp)
|
2012-04-29 15:47:10 -07:00
|
|
|
{
|
|
|
|
struct ext4_sb_info *sbi = EXT4_SB(sb);
|
|
|
|
int offset = offsetof(struct mmp_struct, mmp_checksum);
|
|
|
|
__u32 csum;
|
|
|
|
|
|
|
|
csum = ext4_chksum(sbi, sbi->s_csum_seed, (char *)mmp, offset);
|
|
|
|
|
|
|
|
return cpu_to_le32(csum);
|
|
|
|
}
|
|
|
|
|
2014-05-12 07:50:23 -07:00
|
|
|
static int ext4_mmp_csum_verify(struct super_block *sb, struct mmp_struct *mmp)
|
2012-04-29 15:47:10 -07:00
|
|
|
{
|
2014-10-13 00:36:16 -07:00
|
|
|
if (!ext4_has_metadata_csum(sb))
|
2012-04-29 15:47:10 -07:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return mmp->mmp_checksum == ext4_mmp_csum(sb, mmp);
|
|
|
|
}
|
|
|
|
|
2014-05-12 07:50:23 -07:00
|
|
|
static void ext4_mmp_csum_set(struct super_block *sb, struct mmp_struct *mmp)
|
2012-04-29 15:47:10 -07:00
|
|
|
{
|
2014-10-13 00:36:16 -07:00
|
|
|
if (!ext4_has_metadata_csum(sb))
|
2012-04-29 15:47:10 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
mmp->mmp_checksum = ext4_mmp_csum(sb, mmp);
|
|
|
|
}
|
|
|
|
|
2011-05-24 15:31:25 -07:00
|
|
|
/*
|
2016-11-01 06:40:10 -07:00
|
|
|
* Write the MMP block using REQ_SYNC to try to get the block on-disk
|
2011-05-24 15:31:25 -07:00
|
|
|
* faster.
|
|
|
|
*/
|
2023-04-11 05:10:19 -07:00
|
|
|
static int write_mmp_block_thawed(struct super_block *sb,
|
|
|
|
struct buffer_head *bh)
|
2011-05-24 15:31:25 -07:00
|
|
|
{
|
2012-04-29 15:47:10 -07:00
|
|
|
struct mmp_struct *mmp = (struct mmp_struct *)(bh->b_data);
|
|
|
|
|
|
|
|
ext4_mmp_csum_set(sb, mmp);
|
2011-05-24 15:31:25 -07:00
|
|
|
lock_buffer(bh);
|
|
|
|
bh->b_end_io = end_buffer_write_sync;
|
|
|
|
get_bh(bh);
|
2022-07-14 11:07:13 -07:00
|
|
|
submit_bh(REQ_OP_WRITE | REQ_SYNC | REQ_META | REQ_PRIO, bh);
|
2011-05-24 15:31:25 -07:00
|
|
|
wait_on_buffer(bh);
|
|
|
|
if (unlikely(!buffer_uptodate(bh)))
|
2021-04-05 19:53:31 -07:00
|
|
|
return -EIO;
|
2011-05-24 15:31:25 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-04-11 05:10:19 -07:00
|
|
|
static int write_mmp_block(struct super_block *sb, struct buffer_head *bh)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We protect against freezing so that we don't create dirty buffers
|
|
|
|
* on frozen filesystem.
|
|
|
|
*/
|
|
|
|
sb_start_write(sb);
|
|
|
|
err = write_mmp_block_thawed(sb, bh);
|
|
|
|
sb_end_write(sb);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-05-24 15:31:25 -07:00
|
|
|
/*
|
|
|
|
* Read the MMP block. It _must_ be read from disk and hence we clear the
|
|
|
|
* uptodate flag on the buffer.
|
|
|
|
*/
|
|
|
|
static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
|
|
|
|
ext4_fsblk_t mmp_block)
|
|
|
|
{
|
|
|
|
struct mmp_struct *mmp;
|
2015-08-15 08:30:31 -07:00
|
|
|
int ret;
|
2011-05-24 15:31:25 -07:00
|
|
|
|
|
|
|
if (*bh)
|
|
|
|
clear_buffer_uptodate(*bh);
|
|
|
|
|
|
|
|
/* This would be sb_bread(sb, mmp_block), except we need to be sure
|
|
|
|
* that the MD RAID device cache has been bypassed, and that the read
|
|
|
|
* is not blocked in the elevator. */
|
2015-08-15 08:30:31 -07:00
|
|
|
if (!*bh) {
|
2011-05-24 15:31:25 -07:00
|
|
|
*bh = sb_getblk(sb, mmp_block);
|
2015-08-15 08:30:31 -07:00
|
|
|
if (!*bh) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto warn_exit;
|
2011-05-24 15:31:25 -07:00
|
|
|
}
|
|
|
|
}
|
2015-08-15 08:30:31 -07:00
|
|
|
|
|
|
|
lock_buffer(*bh);
|
2020-09-24 00:33:33 -07:00
|
|
|
ret = ext4_read_bh(*bh, REQ_META | REQ_PRIO, NULL);
|
|
|
|
if (ret)
|
2015-08-15 08:30:31 -07:00
|
|
|
goto warn_exit;
|
2020-09-24 00:33:33 -07:00
|
|
|
|
2011-05-24 15:31:25 -07:00
|
|
|
mmp = (struct mmp_struct *)((*bh)->b_data);
|
2016-03-13 14:56:52 -07:00
|
|
|
if (le32_to_cpu(mmp->mmp_magic) != EXT4_MMP_MAGIC) {
|
2015-10-17 13:16:04 -07:00
|
|
|
ret = -EFSCORRUPTED;
|
2016-03-13 14:56:52 -07:00
|
|
|
goto warn_exit;
|
|
|
|
}
|
|
|
|
if (!ext4_mmp_csum_verify(sb, mmp)) {
|
2015-10-17 13:16:04 -07:00
|
|
|
ret = -EFSBADCRC;
|
2016-03-13 14:56:52 -07:00
|
|
|
goto warn_exit;
|
|
|
|
}
|
|
|
|
return 0;
|
2015-08-15 08:30:31 -07:00
|
|
|
warn_exit:
|
2016-03-13 14:56:52 -07:00
|
|
|
brelse(*bh);
|
|
|
|
*bh = NULL;
|
2015-08-15 08:30:31 -07:00
|
|
|
ext4_warning(sb, "Error %d while reading MMP block %llu",
|
|
|
|
ret, mmp_block);
|
|
|
|
return ret;
|
2011-05-24 15:31:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump as much information as possible to help the admin.
|
|
|
|
*/
|
|
|
|
void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
|
|
|
|
const char *function, unsigned int line, const char *msg)
|
|
|
|
{
|
2015-08-15 08:38:13 -07:00
|
|
|
__ext4_warning(sb, function, line, "%s", msg);
|
2011-05-24 15:31:25 -07:00
|
|
|
__ext4_warning(sb, function, line,
|
2020-01-26 15:03:34 -07:00
|
|
|
"MMP failure info: last update time: %llu, last update node: %.*s, last update device: %.*s",
|
|
|
|
(unsigned long long)le64_to_cpu(mmp->mmp_time),
|
|
|
|
(int)sizeof(mmp->mmp_nodename), mmp->mmp_nodename,
|
|
|
|
(int)sizeof(mmp->mmp_bdevname), mmp->mmp_bdevname);
|
2011-05-24 15:31:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kmmpd will update the MMP sequence every s_mmp_update_interval seconds
|
|
|
|
*/
|
|
|
|
static int kmmpd(void *data)
|
|
|
|
{
|
2022-04-01 01:13:21 -07:00
|
|
|
struct super_block *sb = data;
|
2011-05-24 15:31:25 -07:00
|
|
|
struct ext4_super_block *es = EXT4_SB(sb)->s_es;
|
2021-04-30 11:50:46 -07:00
|
|
|
struct buffer_head *bh = EXT4_SB(sb)->s_mmp_bh;
|
2011-05-24 15:31:25 -07:00
|
|
|
struct mmp_struct *mmp;
|
|
|
|
ext4_fsblk_t mmp_block;
|
|
|
|
u32 seq = 0;
|
|
|
|
unsigned long failed_writes = 0;
|
|
|
|
int mmp_update_interval = le16_to_cpu(es->s_mmp_update_interval);
|
|
|
|
unsigned mmp_check_interval;
|
|
|
|
unsigned long last_update_time;
|
|
|
|
unsigned long diff;
|
2021-07-12 19:27:28 -07:00
|
|
|
int retval = 0;
|
2011-05-24 15:31:25 -07:00
|
|
|
|
|
|
|
mmp_block = le64_to_cpu(es->s_mmp_block);
|
|
|
|
mmp = (struct mmp_struct *)(bh->b_data);
|
2018-07-29 12:49:00 -07:00
|
|
|
mmp->mmp_time = cpu_to_le64(ktime_get_real_seconds());
|
2011-05-24 15:31:25 -07:00
|
|
|
/*
|
|
|
|
* Start with the higher mmp_check_interval and reduce it if
|
|
|
|
* the MMP block is being updated on time.
|
|
|
|
*/
|
|
|
|
mmp_check_interval = max(EXT4_MMP_CHECK_MULT * mmp_update_interval,
|
|
|
|
EXT4_MMP_MIN_CHECK_INTERVAL);
|
|
|
|
mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
|
|
|
|
|
2011-10-18 07:49:51 -07:00
|
|
|
memcpy(mmp->mmp_nodename, init_utsname()->nodename,
|
2011-05-24 15:31:25 -07:00
|
|
|
sizeof(mmp->mmp_nodename));
|
|
|
|
|
2023-06-16 09:50:57 -07:00
|
|
|
while (!kthread_should_stop() && !ext4_forced_shutdown(sb)) {
|
2021-07-02 09:45:02 -07:00
|
|
|
if (!ext4_has_feature_mmp(sb)) {
|
|
|
|
ext4_warning(sb, "kmmpd being stopped since MMP feature"
|
|
|
|
" has been disabled.");
|
|
|
|
goto wait_to_exit;
|
|
|
|
}
|
2011-05-24 15:31:25 -07:00
|
|
|
if (++seq > EXT4_MMP_SEQ_MAX)
|
|
|
|
seq = 1;
|
|
|
|
|
|
|
|
mmp->mmp_seq = cpu_to_le32(seq);
|
2018-07-29 12:49:00 -07:00
|
|
|
mmp->mmp_time = cpu_to_le64(ktime_get_real_seconds());
|
2011-05-24 15:31:25 -07:00
|
|
|
last_update_time = jiffies;
|
|
|
|
|
2012-04-29 15:47:10 -07:00
|
|
|
retval = write_mmp_block(sb, bh);
|
2011-05-24 15:31:25 -07:00
|
|
|
/*
|
|
|
|
* Don't spew too many error messages. Print one every
|
|
|
|
* (s_mmp_update_interval * 60) seconds.
|
|
|
|
*/
|
2011-10-18 07:51:51 -07:00
|
|
|
if (retval) {
|
2019-11-19 19:54:15 -07:00
|
|
|
if ((failed_writes % 60) == 0) {
|
2020-03-28 16:33:43 -07:00
|
|
|
ext4_error_err(sb, -retval,
|
|
|
|
"Error writing to MMP block");
|
2019-11-19 19:54:15 -07:00
|
|
|
}
|
2011-05-24 15:31:25 -07:00
|
|
|
failed_writes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff = jiffies - last_update_time;
|
|
|
|
if (diff < mmp_update_interval * HZ)
|
|
|
|
schedule_timeout_interruptible(mmp_update_interval *
|
|
|
|
HZ - diff);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to make sure that more than mmp_check_interval
|
|
|
|
* seconds have not passed since writing. If that has happened
|
|
|
|
* we need to check if the MMP block is as we left it.
|
|
|
|
*/
|
|
|
|
diff = jiffies - last_update_time;
|
|
|
|
if (diff > mmp_check_interval * HZ) {
|
|
|
|
struct buffer_head *bh_check = NULL;
|
|
|
|
struct mmp_struct *mmp_check;
|
|
|
|
|
|
|
|
retval = read_mmp_block(sb, &bh_check, mmp_block);
|
|
|
|
if (retval) {
|
2020-03-28 16:33:43 -07:00
|
|
|
ext4_error_err(sb, -retval,
|
|
|
|
"error reading MMP data: %d",
|
|
|
|
retval);
|
2021-07-02 09:45:02 -07:00
|
|
|
goto wait_to_exit;
|
2011-05-24 15:31:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mmp_check = (struct mmp_struct *)(bh_check->b_data);
|
|
|
|
if (mmp->mmp_seq != mmp_check->mmp_seq ||
|
|
|
|
memcmp(mmp->mmp_nodename, mmp_check->mmp_nodename,
|
|
|
|
sizeof(mmp->mmp_nodename))) {
|
|
|
|
dump_mmp_msg(sb, mmp_check,
|
|
|
|
"Error while updating MMP info. "
|
|
|
|
"The filesystem seems to have been"
|
|
|
|
" multiply mounted.");
|
2020-03-28 16:33:43 -07:00
|
|
|
ext4_error_err(sb, EBUSY, "abort");
|
2016-03-13 14:56:52 -07:00
|
|
|
put_bh(bh_check);
|
|
|
|
retval = -EBUSY;
|
2021-07-02 09:45:02 -07:00
|
|
|
goto wait_to_exit;
|
2011-05-24 15:31:25 -07:00
|
|
|
}
|
|
|
|
put_bh(bh_check);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust the mmp_check_interval depending on how much time
|
|
|
|
* it took for the MMP block to be written.
|
|
|
|
*/
|
|
|
|
mmp_check_interval = max(min(EXT4_MMP_CHECK_MULT * diff / HZ,
|
|
|
|
EXT4_MMP_MAX_CHECK_INTERVAL),
|
|
|
|
EXT4_MMP_MIN_CHECK_INTERVAL);
|
|
|
|
mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unmount seems to be clean.
|
|
|
|
*/
|
|
|
|
mmp->mmp_seq = cpu_to_le32(EXT4_MMP_SEQ_CLEAN);
|
2018-07-29 12:49:00 -07:00
|
|
|
mmp->mmp_time = cpu_to_le64(ktime_get_real_seconds());
|
2011-05-24 15:31:25 -07:00
|
|
|
|
2012-04-29 15:47:10 -07:00
|
|
|
retval = write_mmp_block(sb, bh);
|
2011-05-24 15:31:25 -07:00
|
|
|
|
2021-07-02 09:45:02 -07:00
|
|
|
wait_to_exit:
|
|
|
|
while (!kthread_should_stop()) {
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
if (!kthread_should_stop())
|
|
|
|
schedule();
|
|
|
|
}
|
|
|
|
set_current_state(TASK_RUNNING);
|
2011-05-24 15:31:25 -07:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2021-04-30 11:50:46 -07:00
|
|
|
void ext4_stop_mmpd(struct ext4_sb_info *sbi)
|
|
|
|
{
|
|
|
|
if (sbi->s_mmp_tsk) {
|
|
|
|
kthread_stop(sbi->s_mmp_tsk);
|
|
|
|
brelse(sbi->s_mmp_bh);
|
|
|
|
sbi->s_mmp_tsk = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-24 15:31:25 -07:00
|
|
|
/*
|
|
|
|
* Get a random new sequence number but make sure it is not greater than
|
|
|
|
* EXT4_MMP_SEQ_MAX.
|
|
|
|
*/
|
|
|
|
static unsigned int mmp_new_seq(void)
|
|
|
|
{
|
2022-10-09 19:44:02 -07:00
|
|
|
return get_random_u32_below(EXT4_MMP_SEQ_MAX + 1);
|
2011-05-24 15:31:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Protect the filesystem from being mounted more than once.
|
|
|
|
*/
|
|
|
|
int ext4_multi_mount_protect(struct super_block *sb,
|
|
|
|
ext4_fsblk_t mmp_block)
|
|
|
|
{
|
|
|
|
struct ext4_super_block *es = EXT4_SB(sb)->s_es;
|
|
|
|
struct buffer_head *bh = NULL;
|
|
|
|
struct mmp_struct *mmp = NULL;
|
|
|
|
u32 seq;
|
|
|
|
unsigned int mmp_check_interval = le16_to_cpu(es->s_mmp_update_interval);
|
|
|
|
unsigned int wait_time = 0;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (mmp_block < le32_to_cpu(es->s_first_data_block) ||
|
|
|
|
mmp_block >= ext4_blocks_count(es)) {
|
|
|
|
ext4_warning(sb, "Invalid MMP block in superblock");
|
2023-04-27 19:49:34 -07:00
|
|
|
retval = -EINVAL;
|
2011-05-24 15:31:25 -07:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = read_mmp_block(sb, &bh, mmp_block);
|
|
|
|
if (retval)
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
mmp = (struct mmp_struct *)(bh->b_data);
|
|
|
|
|
|
|
|
if (mmp_check_interval < EXT4_MMP_MIN_CHECK_INTERVAL)
|
|
|
|
mmp_check_interval = EXT4_MMP_MIN_CHECK_INTERVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If check_interval in MMP block is larger, use that instead of
|
|
|
|
* update_interval from the superblock.
|
|
|
|
*/
|
2012-02-26 23:09:03 -07:00
|
|
|
if (le16_to_cpu(mmp->mmp_check_interval) > mmp_check_interval)
|
|
|
|
mmp_check_interval = le16_to_cpu(mmp->mmp_check_interval);
|
2011-05-24 15:31:25 -07:00
|
|
|
|
|
|
|
seq = le32_to_cpu(mmp->mmp_seq);
|
|
|
|
if (seq == EXT4_MMP_SEQ_CLEAN)
|
|
|
|
goto skip;
|
|
|
|
|
|
|
|
if (seq == EXT4_MMP_SEQ_FSCK) {
|
|
|
|
dump_mmp_msg(sb, mmp, "fsck is running on the filesystem");
|
2023-04-27 19:49:34 -07:00
|
|
|
retval = -EBUSY;
|
2011-05-24 15:31:25 -07:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
wait_time = min(mmp_check_interval * 2 + 1,
|
|
|
|
mmp_check_interval + 60);
|
|
|
|
|
|
|
|
/* Print MMP interval if more than 20 secs. */
|
|
|
|
if (wait_time > EXT4_MMP_MIN_CHECK_INTERVAL * 4)
|
|
|
|
ext4_warning(sb, "MMP interval %u higher than expected, please"
|
|
|
|
" wait.\n", wait_time * 2);
|
|
|
|
|
|
|
|
if (schedule_timeout_interruptible(HZ * wait_time) != 0) {
|
|
|
|
ext4_warning(sb, "MMP startup interrupted, failing mount\n");
|
2023-04-27 19:49:34 -07:00
|
|
|
retval = -ETIMEDOUT;
|
2011-05-24 15:31:25 -07:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = read_mmp_block(sb, &bh, mmp_block);
|
|
|
|
if (retval)
|
|
|
|
goto failed;
|
|
|
|
mmp = (struct mmp_struct *)(bh->b_data);
|
|
|
|
if (seq != le32_to_cpu(mmp->mmp_seq)) {
|
|
|
|
dump_mmp_msg(sb, mmp,
|
|
|
|
"Device is already active on another node.");
|
2023-04-27 19:49:34 -07:00
|
|
|
retval = -EBUSY;
|
2011-05-24 15:31:25 -07:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
skip:
|
|
|
|
/*
|
|
|
|
* write a new random sequence number.
|
|
|
|
*/
|
2011-10-18 07:53:51 -07:00
|
|
|
seq = mmp_new_seq();
|
|
|
|
mmp->mmp_seq = cpu_to_le32(seq);
|
2011-05-24 15:31:25 -07:00
|
|
|
|
2023-04-11 05:10:19 -07:00
|
|
|
/*
|
|
|
|
* On mount / remount we are protected against fs freezing (by s_umount
|
|
|
|
* semaphore) and grabbing freeze protection upsets lockdep
|
|
|
|
*/
|
|
|
|
retval = write_mmp_block_thawed(sb, bh);
|
2011-05-24 15:31:25 -07:00
|
|
|
if (retval)
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* wait for MMP interval and check mmp_seq.
|
|
|
|
*/
|
|
|
|
if (schedule_timeout_interruptible(HZ * wait_time) != 0) {
|
2016-04-26 22:11:21 -07:00
|
|
|
ext4_warning(sb, "MMP startup interrupted, failing mount");
|
2023-04-27 19:49:34 -07:00
|
|
|
retval = -ETIMEDOUT;
|
2011-05-24 15:31:25 -07:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = read_mmp_block(sb, &bh, mmp_block);
|
|
|
|
if (retval)
|
|
|
|
goto failed;
|
|
|
|
mmp = (struct mmp_struct *)(bh->b_data);
|
|
|
|
if (seq != le32_to_cpu(mmp->mmp_seq)) {
|
|
|
|
dump_mmp_msg(sb, mmp,
|
|
|
|
"Device is already active on another node.");
|
2023-04-27 19:49:34 -07:00
|
|
|
retval = -EBUSY;
|
2011-05-24 15:31:25 -07:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2021-04-30 11:50:46 -07:00
|
|
|
EXT4_SB(sb)->s_mmp_bh = bh;
|
2011-05-24 15:31:25 -07:00
|
|
|
|
2022-07-12 22:53:16 -07:00
|
|
|
BUILD_BUG_ON(sizeof(mmp->mmp_bdevname) < BDEVNAME_SIZE);
|
2022-07-12 22:53:17 -07:00
|
|
|
snprintf(mmp->mmp_bdevname, sizeof(mmp->mmp_bdevname),
|
|
|
|
"%pg", bh->b_bdev);
|
2022-07-12 22:53:16 -07:00
|
|
|
|
2011-05-24 15:31:25 -07:00
|
|
|
/*
|
|
|
|
* Start a kernel thread to update the MMP block periodically.
|
|
|
|
*/
|
2021-04-30 11:50:46 -07:00
|
|
|
EXT4_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, sb, "kmmpd-%.*s",
|
2020-01-26 15:03:34 -07:00
|
|
|
(int)sizeof(mmp->mmp_bdevname),
|
2022-07-12 22:53:16 -07:00
|
|
|
mmp->mmp_bdevname);
|
2011-05-24 15:31:25 -07:00
|
|
|
if (IS_ERR(EXT4_SB(sb)->s_mmp_tsk)) {
|
|
|
|
EXT4_SB(sb)->s_mmp_tsk = NULL;
|
|
|
|
ext4_warning(sb, "Unable to create kmmpd thread for %s.",
|
|
|
|
sb->s_id);
|
2023-04-27 19:49:34 -07:00
|
|
|
retval = -ENOMEM;
|
2011-05-24 15:31:25 -07:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
brelse(bh);
|
2023-04-27 19:49:34 -07:00
|
|
|
return retval;
|
2011-05-24 15:31:25 -07:00
|
|
|
}
|