All of lore.kernel.org
 help / color / mirror / Atom feed
From: Huang Jianan via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: linux-erofs@lists.ozlabs.org, hsiangkao@linux.alibaba.com
Cc: yh@oppo.com, guoweichao@oppo.com, zhangshiming@oppo.com,
	guanyuwei@oppo.com
Subject: [PATCH v2 1/2] erofs-utils: sort shared xattr
Date: Tue, 14 Dec 2021 17:52:01 +0800	[thread overview]
Message-ID: <20211214095202.11717-1-huangjianan@oppo.com> (raw)
In-Reply-To: <YXE30+2qU75+0szk@B-P7TQMD6M-0146.local>

Sort shared xattr before writing to disk to ensure the consistency
of reproducible builds.

Signed-off-by: Huang Jianan <huangjianan@oppo.com>
---
since v1:
- use strncmp instead of strcmp.

 lib/xattr.c | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/lib/xattr.c b/lib/xattr.c
index 196133a..fd998cd 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -562,13 +562,31 @@ static struct erofs_bhops erofs_write_shared_xattrs_bhops = {
 	.flush = erofs_bh_flush_write_shared_xattrs,
 };
 
+static int comp_xattr_item(const void *a, const void *b)
+{
+	const struct xattr_item *ia, *ib;
+	unsigned int la, lb;
+	int ret;
+
+	ia = (*((const struct inode_xattr_node **)a))->item;
+	ib = (*((const struct inode_xattr_node **)b))->item;
+	la = ia->len[0] + ia->len[1];
+	lb = ib->len[0] + ib->len[1];
+
+	ret = strncmp(ia->kvbuf, ib->kvbuf, min(la, lb));
+	if (ret != 0)
+		return ret;
+
+	return la > lb;
+}
+
 int erofs_build_shared_xattrs_from_path(const char *path)
 {
 	int ret;
 	struct erofs_buffer_head *bh;
-	struct inode_xattr_node *node, *n;
+	struct inode_xattr_node *node, *n, **sorted_n;
 	char *buf;
-	unsigned int p;
+	unsigned int p, i;
 	erofs_off_t off;
 
 	/* check if xattr or shared xattr is disabled */
@@ -606,6 +624,20 @@ int erofs_build_shared_xattrs_from_path(const char *path)
 	off %= EROFS_BLKSIZ;
 	p = 0;
 
+	sorted_n = malloc(shared_xattrs_count * sizeof(n));
+	if (!sorted_n)
+		return -ENOMEM;
+	i = 0;
+	list_for_each_entry_safe(node, n, &shared_xattrs_list, list) {
+		list_del(&node->list);
+		sorted_n[i++] = node;
+	}
+	DBG_BUGON(i != shared_xattrs_count);
+	qsort(sorted_n, shared_xattrs_count, sizeof(n), comp_xattr_item);
+	for (i = 0; i < shared_xattrs_count; i++)
+		list_add_tail(&sorted_n[i]->list, &shared_xattrs_list);
+	free(sorted_n);
+
 	list_for_each_entry_safe(node, n, &shared_xattrs_list, list) {
 		struct xattr_item *const item = node->item;
 		const struct erofs_xattr_entry entry = {
-- 
2.25.1


  reply	other threads:[~2021-12-14  9:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21  2:58 [PATCH] erofs-utils: add dump.erofs to .gitignore Huang Jianan via Linux-erofs
2021-10-21  2:58 ` [PATCH] erofs-utils: sort shared xattr Huang Jianan via Linux-erofs
2021-10-21  7:25   ` Gao Xiang
2021-10-21  9:28     ` Huang Jianan via Linux-erofs
2021-10-21  9:50       ` Gao Xiang
2021-12-14  9:52         ` Huang Jianan via Linux-erofs [this message]
2021-12-14  9:52           ` [PATCH 2/2] erofs-utils: tests: add test for xattr Huang Jianan via Linux-erofs
2021-12-14 15:31           ` [PATCH v2 1/2] erofs-utils: sort shared xattr Gao Xiang
2021-12-15  2:43             ` Huang Jianan via Linux-erofs
2021-12-15  3:22               ` Gao Xiang
2021-12-15  3:27                 ` Huang Jianan via Linux-erofs
2021-10-21  7:23 ` [PATCH] erofs-utils: add dump.erofs to .gitignore Gao Xiang
2021-10-21  8:30   ` Gao Xiang
2021-10-21  8:51     ` [PATCH v2] " Huang Jianan via Linux-erofs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211214095202.11717-1-huangjianan@oppo.com \
    --to=linux-erofs@lists.ozlabs.org \
    --cc=guanyuwei@oppo.com \
    --cc=guoweichao@oppo.com \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=huangjianan@oppo.com \
    --cc=yh@oppo.com \
    --cc=zhangshiming@oppo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.