aboutsummaryrefslogtreecommitdiffstats
path: root/package/utils/f2fs-tools/patches/100-f2fs-WARNING-at-fs-f2fs-segment.c-718-update_sit_ent.patch
blob: d4e25397a30ead24f7e69b6ad2af435efd7b3388 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From 31873d5cdf8a97d5f7921451c54f6d293293c6cc Mon Sep 17 00:00:00 2001
From: Jaegeuk Kim <jaegeuk@kernel.org>
Date: Wed, 23 Aug 2017 13:33:00 -0700
Subject: [PATCH] mkfs.f2fs: fix missing cpu_to_le64 for checkpoint version

The error on mips was reported by Stijn as follow.

Commit 8399a29df92d6867d226df362edbf2e0efa527c1 in f2fs-tools
("mkfs.f2fs: give random checkpoint version") causes a bug when mounting
a filesystem created with it on a MIPS64 device running a 4.4(.83)
kernel. The following kernel warning appears several times per second,
for 30 seconds:

[   23.837262] ------------[ cut here ]------------
[   23.842039] WARNING: CPU: 0 PID: 935 at fs/f2fs/segment.c:718
update_sit_entry+0x1c0/0x2b0()
[   23.850507] Modules linked in: pppoe ppp_async l2tp_ppp iptable_nat
[   24.174064] Call Trace:
[   24.176527] [<ffffffff81126e14>] show_stack+0x68/0xb4
[   24.181595] [<ffffffff81321fc4>] dump_stack+0x8c/0xc4
[   24.186660] [<ffffffff8113d004>] warn_slowpath_common+0xa0/0xd0
[   24.192597] [<ffffffff812e0148>] update_sit_entry+0x1c0/0x2b0
[   24.198353] [<ffffffff812e0a70>] refresh_sit_entry+0x70/0xf8
[   24.204022] [<ffffffff812e251c>] allocate_data_block+0x1f0/0x310
[   24.210038] [<ffffffff812e28d8>] do_write_page+0x29c/0x2bc
[   24.215532] [<ffffffff812e2a88>] write_data_page+0xa0/0xd8
[   24.221028] [<ffffffff812d844c>] do_write_data_page+0xe4/0x384
[   24.226870] [<ffffffff812d88f4>] f2fs_write_data_page+0x208/0x464
[   24.232972] [<ffffffff812d5184>] __f2fs_writepage+0x1c/0x74
[   24.238553] [<ffffffff812d54dc>]
f2fs_write_cache_pages.constprop.7+0x250/0x394
[   24.245869] [<ffffffff812d57f4>] f2fs_write_data_pages+0x130/0x1b0
[   24.252066] [<ffffffff811a9f80>] __filemap_fdatawrite_range+0xa0/0xd4
[   24.258515] [<ffffffff812d2338>] sync_dirty_dir_inodes+0x94/0xd8
[   24.264530] [<ffffffff812d2484>] write_checkpoint+0x108/0xb9c
[   24.270283] [<ffffffff812cc398>] f2fs_sync_fs+0x68/0xb0
[   24.275526] [<ffffffff812c641c>] f2fs_sync_file+0x2e8/0x518
[   24.281107] [<ffffffff81213ff4>] do_fsync+0x38/0x70
[   24.285992] [<ffffffff812142e8>] SyS_fsync+0x14/0x20
[   24.290972] [<ffffffff81103950>] syscall_common+0x34/0x58
[   24.296372]
[   24.298096] ---[ end trace fd3ac44449b218ab ]---

Fix: 8399a29df92d68 ("mkfs.f2fs: give random checkpoint version")
Reported-And-Tested-by: Stijn Tintel <stijn@linux-ipv6.be>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 mkfs/f2fs_format.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 92876b8..b379e80 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -546,7 +546,7 @@ static int f2fs_write_check_point_pack(void)
 	}
 
 	/* 1. cp page 1 of checkpoint pack 1 */
-	cp->checkpoint_ver = rand() | 0x1;
+	cp->checkpoint_ver = cpu_to_le64(rand() | 0x1);
 	set_cp(cur_node_segno[0], c.cur_seg[CURSEG_HOT_NODE]);
 	set_cp(cur_node_segno[1], c.cur_seg[CURSEG_WARM_NODE]);
 	set_cp(cur_node_segno[2], c.cur_seg[CURSEG_COLD_NODE]);
-- 
2.13.5
>353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
/*
 * lib/genl/ctrl.c		Generic Netlink Controller
 *
 *	This library is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation version 2.1
 *	of the License.
 *
 * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
 */

/**
 * @ingroup genl_mngt
 * @defgroup ctrl Controller
 * @brief
 *
 * @{
 */

#include <netlink-generic.h>
#include <netlink/netlink.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/mngt.h>
#include <netlink/genl/ctrl.h>
#include <netlink/utils.h>

/** @cond SKIP */
#define CTRL_VERSION		0x0001

static struct nl_cache_ops genl_ctrl_ops;
/** @endcond */

static int ctrl_request_update(struct nl_cache *c, struct nl_sock *h)
{
	return genl_send_simple(h, GENL_ID_CTRL, CTRL_CMD_GETFAMILY,
				CTRL_VERSION, NLM_F_DUMP);
}

static struct nla_policy ctrl_policy[CTRL_ATTR_MAX+1] = {
	[CTRL_ATTR_FAMILY_ID]	= { .type = NLA_U16 },
	[CTRL_ATTR_FAMILY_NAME]	= { .type = NLA_STRING,
				    .maxlen = GENL_NAMSIZ },
	[CTRL_ATTR_VERSION]	= { .type = NLA_U32 },
	[CTRL_ATTR_HDRSIZE]	= { .type = NLA_U32 },
	[CTRL_ATTR_MAXATTR]	= { .type = NLA_U32 },
	[CTRL_ATTR_OPS]		= { .type = NLA_NESTED },
	[CTRL_ATTR_MCAST_GROUPS] = { .type = NLA_NESTED },
};

static struct nla_policy family_op_policy[CTRL_ATTR_OP_MAX+1] = {
	[CTRL_ATTR_OP_ID]	= { .type = NLA_U32 },
	[CTRL_ATTR_OP_FLAGS]	= { .type = NLA_U32 },
};

static struct nla_policy family_grp_policy[CTRL_ATTR_MCAST_GRP_MAX+1] = {
	[CTRL_ATTR_MCAST_GRP_NAME] = { .type = NLA_STRING },
	[CTRL_ATTR_MCAST_GRP_ID]   = { .type = NLA_U32 },
};

static int ctrl_msg_parser(struct nl_cache_ops *ops, struct genl_cmd *cmd,
			   struct genl_info *info, void *arg)
{
	struct genl_family *family;
	struct nl_parser_param *pp = arg;
	int err;

	family = genl_family_alloc();
	if (family == NULL) {
		err = -NLE_NOMEM;
		goto errout;
	}

	if (info->attrs[CTRL_ATTR_FAMILY_NAME] == NULL) {
		err = -NLE_MISSING_ATTR;
		goto errout;
	}

	if (info->attrs[CTRL_ATTR_FAMILY_ID] == NULL) {
		err = -NLE_MISSING_ATTR;
		goto errout;
	}

	family->ce_msgtype = info->nlh->nlmsg_type;
	genl_family_set_id(family,
			   nla_get_u16(info->attrs[CTRL_ATTR_FAMILY_ID]));
	genl_family_set_name(family,
		     nla_get_string(info->attrs[CTRL_ATTR_FAMILY_NAME]));

	if (info->attrs[CTRL_ATTR_VERSION]) {
		uint32_t version = nla_get_u32(info->attrs[CTRL_ATTR_VERSION]);
		genl_family_set_version(family, version);
	}

	if (info->attrs[CTRL_ATTR_HDRSIZE]) {
		uint32_t hdrsize = nla_get_u32(info->attrs[CTRL_ATTR_HDRSIZE]);
		genl_family_set_hdrsize(family, hdrsize);
	}

	if (info->attrs[CTRL_ATTR_MAXATTR]) {
		uint32_t maxattr = nla_get_u32(info->attrs[CTRL_ATTR_MAXATTR]);
		genl_family_set_maxattr(family, maxattr);
	}

	if (info->attrs[CTRL_ATTR_OPS]) {
		struct nlattr *nla, *nla_ops;
		int remaining;

		nla_ops = info->attrs[CTRL_ATTR_OPS];
		nla_for_each_nested(nla, nla_ops, remaining) {
			struct nlattr *tb[CTRL_ATTR_OP_MAX+1];
			int flags = 0, id;

			err = nla_parse_nested(tb, CTRL_ATTR_OP_MAX, nla,
					       family_op_policy);
			if (err < 0)
				goto errout;

			if (tb[CTRL_ATTR_OP_ID] == NULL) {
				err = -NLE_MISSING_ATTR;
				goto errout;
			}
			
			id = nla_get_u32(tb[CTRL_ATTR_OP_ID]);

			if (tb[CTRL_ATTR_OP_FLAGS])
				flags = nla_get_u32(tb[CTRL_ATTR_OP_FLAGS]);

			err = genl_family_add_op(family, id, flags);
			if (err < 0)
				goto errout;

		}
	}

	if (info->attrs[CTRL_ATTR_MCAST_GROUPS]) {
		struct nlattr *nla, *nla_grps;
		int remaining;

		nla_grps = info->attrs[CTRL_ATTR_MCAST_GROUPS];
		nla_for_each_nested(nla, nla_grps, remaining) {
			struct nlattr *tb[CTRL_ATTR_MCAST_GRP_MAX+1];
			int id;
			const char * name;

			err = nla_parse_nested(tb, CTRL_ATTR_MCAST_GRP_MAX, nla,
					       family_grp_policy);
			if (err < 0)
				goto errout;

			if (tb[CTRL_ATTR_MCAST_GRP_ID] == NULL) {
				err = -NLE_MISSING_ATTR;
				goto errout;
			}
			id = nla_get_u32(tb[CTRL_ATTR_MCAST_GRP_ID]);

			if (tb[CTRL_ATTR_MCAST_GRP_NAME] == NULL) {
				err = -NLE_MISSING_ATTR;
				goto errout;
			}
			name = nla_get_string(tb[CTRL_ATTR_MCAST_GRP_NAME]);

			err = genl_family_add_grp(family, id, name);
			if (err < 0)
				goto errout;
		}

	}

	err = pp->pp_cb((struct nl_object *) family, pp);
errout:
	genl_family_put(family);
	return err;
}

/**
 * @name Cache Management
 * @{
 */

int genl_ctrl_alloc_cache(struct nl_sock *sock, struct nl_cache **result)
{
	return nl_cache_alloc_and_fill(&genl_ctrl_ops, sock, result);
}

/**
 * Look up generic netlink family by id in the provided cache.
 * @arg cache		Generic netlink family cache.
 * @arg id		Family identifier.
 *
 * Searches through the cache looking for a registered family
 * matching the specified identifier. The caller will own a
 * reference on the returned object which needs to be given
 * back after usage using genl_family_put().
 *
 * @return Generic netlink family object or NULL if no match was found.
 */
struct genl_family *genl_ctrl_search(struct nl_cache *cache, int id)
{
	struct genl_family *fam;

	if (cache->c_ops != &genl_ctrl_ops)
		BUG();

	nl_list_for_each_entry(fam, &cache->c_items, ce_list) {
		if (fam->gf_id == id) {
			nl_object_get((struct nl_object *) fam);
			return fam;
		}
	}

	return NULL;
}

/**
 * @name Resolver
 * @{
 */

/**
 * Look up generic netlink family by family name in the provided cache.
 * @arg cache		Generic netlink family cache.
 * @arg name		Family name.
 *
 * Searches through the cache looking for a registered family
 * matching the specified name. The caller will own a reference
 * on the returned object which needs to be given back after
 * usage using genl_family_put().
 *
 * @return Generic netlink family object or NULL if no match was found.
 */
struct genl_family *genl_ctrl_search_by_name(struct nl_cache *cache,
					    const char *name)
{
	struct genl_family *fam;

	if (cache->c_ops != &genl_ctrl_ops)
		BUG();

	nl_list_for_each_entry(fam, &cache->c_items, ce_list) {
		if (!strcmp(name, fam->gf_name)) {
			nl_object_get((struct nl_object *) fam);
			return fam;
		}
	}

	return NULL;
}

/** @} */

/**
 * Resolve generic netlink family name to its identifier
 * @arg sk		Netlink socket.
 * @arg name		Name of generic netlink family
 *
 * Resolves the generic netlink family name to its identifer and returns
 * it.
 *
 * @return A positive identifier or a negative error code.
 */
int genl_ctrl_resolve(struct nl_sock *sk, const char *name)
{
	struct nl_cache *cache;
	struct genl_family *family;
	int err;

	if ((err = genl_ctrl_alloc_cache(sk, &cache)) < 0)
		return err;

	family = genl_ctrl_search_by_name(cache, name);
	if (family == NULL) {
		err = -NLE_OBJ_NOTFOUND;
		goto errout;
	}

	err = genl_family_get_id(family);
	genl_family_put(family);
errout:
	nl_cache_free(cache);

	return err;
}

static int genl_ctrl_grp_by_name(const struct genl_family *family,
				const char *grp_name)
{
	struct genl_family_grp *grp;

	nl_list_for_each_entry(grp, &family->gf_mc_grps, list) {
		if (!strcmp(grp->name, grp_name)) {
			return grp->id;
		}
	}

	return -NLE_OBJ_NOTFOUND;
}

int genl_ctrl_resolve_grp(struct nl_sock *sk, const char *family_name,
	const char *grp_name)
{
	struct nl_cache *cache;
	struct genl_family *family;
	int err;

	if ((err = genl_ctrl_alloc_cache(sk, &cache)) < 0)
		return err;

	family = genl_ctrl_search_by_name(cache, family_name);
	if (family == NULL) {
		err = -NLE_OBJ_NOTFOUND;
		goto errout;
	}

	err = genl_ctrl_grp_by_name(family, grp_name);
	genl_family_put(family);
errout:
	nl_cache_free(cache);

	return err;
}

/** @} */

static struct genl_cmd genl_cmds[] = {
	{
		.c_id		= CTRL_CMD_NEWFAMILY,
		.c_name		= "NEWFAMILY" ,
		.c_maxattr	= CTRL_ATTR_MAX,
		.c_attr_policy	= ctrl_policy,
		.c_msg_parser	= ctrl_msg_parser,
	},
	{
		.c_id		= CTRL_CMD_DELFAMILY,
		.c_name		= "DELFAMILY" ,
	},
	{
		.c_id		= CTRL_CMD_GETFAMILY,
		.c_name		= "GETFAMILY" ,
	},
	{
		.c_id		= CTRL_CMD_NEWOPS,
		.c_name		= "NEWOPS" ,
	},
	{
		.c_id		= CTRL_CMD_DELOPS,
		.c_name		= "DELOPS" ,
	},
};

static struct genl_ops genl_ops = {
	.o_cmds			= genl_cmds,
	.o_ncmds		= ARRAY_SIZE(genl_cmds),
};

/** @cond SKIP */
extern struct nl_object_ops genl_family_ops;
/** @endcond */

static struct nl_cache_ops genl_ctrl_ops = {
	.co_name		= "genl/family",
	.co_hdrsize		= GENL_HDRSIZE(0),
	.co_msgtypes		= GENL_FAMILY(GENL_ID_CTRL, "nlctrl"),
	.co_genl		= &genl_ops,
	.co_protocol		= NETLINK_GENERIC,
	.co_request_update      = ctrl_request_update,
	.co_obj_ops		= &genl_family_ops,
};

static void __init ctrl_init(void)
{
	genl_register(&genl_ctrl_ops);
}

static void __exit ctrl_exit(void)
{
	genl_unregister(&genl_ctrl_ops);
}

/** @} */