All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: linux-mtd@lists.infradead.org
Cc: david@sigma-star.at, tytso@mit.edu, dedekind1@gmail.com,
	ebiggers@google.com, mhalcrow@google.com,
	adrian.hunter@intel.com, linux-kernel@vger.kernel.org,
	hch@infradead.org, linux-fsdevel@vger.kernel.org,
	jaegeuk@kernel.org, dengler@linutronix.de, sbabic@denx.de,
	wd@denx.de, Richard Weinberger <richard@nod.at>
Subject: [PATCH 22/24] ubifs: Implement UBIFS_FLG_DOUBLE_HASH
Date: Thu,  1 Dec 2016 22:21:09 +0100	[thread overview]
Message-ID: <1480627271-10441-23-git-send-email-richard@nod.at> (raw)
In-Reply-To: <1480627271-10441-1-git-send-email-richard@nod.at>

This feature flag indicates that all directory entry nodes have a 32bit
cookie set and therefore UBIFS is allowed to perform lookups by hash.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 fs/ubifs/journal.c     | 14 +++++++++++---
 fs/ubifs/sb.c          |  2 ++
 fs/ubifs/tnc.c         |  3 +++
 fs/ubifs/ubifs-media.h |  3 +++
 fs/ubifs/ubifs.h       |  2 ++
 5 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
index 88d33775f18b..a459211a1c21 100644
--- a/fs/ubifs/journal.c
+++ b/fs/ubifs/journal.c
@@ -501,6 +501,14 @@ static void mark_inode_clean(struct ubifs_info *c, struct ubifs_inode *ui)
 	ui->dirty = 0;
 }
 
+static void set_dent_cookie(struct ubifs_info *c, struct ubifs_dent_node *dent)
+{
+	if (c->double_hash)
+		dent->cookie = prandom_u32();
+	else
+		dent->cookie = 0;
+}
+
 /**
  * ubifs_jnl_update - update inode.
  * @c: UBIFS file-system description object
@@ -589,7 +597,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
 	dent->nlen = cpu_to_le16(fname_len(nm));
 	memcpy(dent->name, fname_name(nm), fname_len(nm));
 	dent->name[fname_len(nm)] = '\0';
-	dent->cookie = prandom_u32();
+	set_dent_cookie(c, dent);
 
 	zero_dent_node_unused(dent);
 	ubifs_prep_grp_node(c, dent, dlen, 0);
@@ -1125,7 +1133,7 @@ int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
 	dent->nlen = cpu_to_le16(fname_len(new_nm));
 	memcpy(dent->name, fname_name(new_nm), fname_len(new_nm));
 	dent->name[fname_len(new_nm)] = '\0';
-	dent->cookie = prandom_u32();
+	set_dent_cookie(c, dent);
 	zero_dent_node_unused(dent);
 	ubifs_prep_grp_node(c, dent, dlen1, 0);
 
@@ -1144,7 +1152,7 @@ int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
 	dent2->nlen = cpu_to_le16(fname_len(old_nm));
 	memcpy(dent2->name, fname_name(old_nm), fname_len(old_nm));
 	dent2->name[fname_len(old_nm)] = '\0';
-	dent2->cookie = prandom_u32();
+	set_dent_cookie(c, dent2);
 	zero_dent_node_unused(dent2);
 	ubifs_prep_grp_node(c, dent2, dlen2, 0);
 
diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c
index 3cbb904a6d7d..4a2b4c361587 100644
--- a/fs/ubifs/sb.c
+++ b/fs/ubifs/sb.c
@@ -163,6 +163,7 @@ static int create_default_filesystem(struct ubifs_info *c)
 	tmp64 = (long long)max_buds * c->leb_size;
 	if (big_lpt)
 		sup_flags |= UBIFS_FLG_BIGLPT;
+	sup_flags |= UBIFS_FLG_DOUBLE_HASH;
 
 	sup->ch.node_type  = UBIFS_SB_NODE;
 	sup->key_hash      = UBIFS_KEY_HASH_R5;
@@ -620,6 +621,7 @@ int ubifs_read_superblock(struct ubifs_info *c)
 	memcpy(&c->uuid, &sup->uuid, 16);
 	c->big_lpt = !!(sup_flags & UBIFS_FLG_BIGLPT);
 	c->space_fixup = !!(sup_flags & UBIFS_FLG_SPACE_FIXUP);
+	c->double_hash = !!(sup_flags & UBIFS_FLG_DOUBLE_HASH);
 
 	/* Automatically increase file system size to the maximum size */
 	c->old_leb_cnt = c->leb_cnt;
diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c
index 1bba4c8b5d3d..74ae2de949df 100644
--- a/fs/ubifs/tnc.c
+++ b/fs/ubifs/tnc.c
@@ -1930,6 +1930,9 @@ int ubifs_tnc_lookup_dh(struct ubifs_info *c, const union ubifs_key *key,
 	int err;
 	const struct ubifs_dent_node *dent = node;
 
+	if (!c->double_hash)
+		return -EOPNOTSUPP;
+
 	/*
 	 * We assume that in most of the cases there are no name collisions and
 	 * 'ubifs_tnc_lookup()' returns us the right direntry.
diff --git a/fs/ubifs/ubifs-media.h b/fs/ubifs/ubifs-media.h
index 249124d9a801..0cbdc6b70a00 100644
--- a/fs/ubifs/ubifs-media.h
+++ b/fs/ubifs/ubifs-media.h
@@ -418,10 +418,13 @@ enum {
  *
  * UBIFS_FLG_BIGLPT: if "big" LPT model is used if set
  * UBIFS_FLG_SPACE_FIXUP: first-mount "fixup" of free space within LEBs needed
+ * UBIFS_FLG_DOUBLE_HASH: store a 32bit cookie in directory entry nodes to
+ *			  support 64bit cookies for lookups by hash
  */
 enum {
 	UBIFS_FLG_BIGLPT = 0x02,
 	UBIFS_FLG_SPACE_FIXUP = 0x04,
+	UBIFS_FLG_DOUBLE_HASH = 0x08,
 };
 
 /**
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 85c74ad98898..1b4c86ddd9e2 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -1015,6 +1015,7 @@ struct ubifs_debug_info;
  *
  * @big_lpt: flag that LPT is too big to write whole during commit
  * @space_fixup: flag indicating that free space in LEBs needs to be cleaned up
+ * @double_hash: flag indicating that we can do lookups by hash
  * @no_chk_data_crc: do not check CRCs when reading data nodes (except during
  *                   recovery)
  * @bulk_read: enable bulk-reads
@@ -1257,6 +1258,7 @@ struct ubifs_info {
 
 	unsigned int big_lpt:1;
 	unsigned int space_fixup:1;
+	unsigned int double_hash:1;
 	unsigned int no_chk_data_crc:1;
 	unsigned int bulk_read:1;
 	unsigned int default_compr:2;
-- 
2.7.3

  parent reply	other threads:[~2016-12-01 21:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-01 21:20 [PATCH 00/24] UBIFS File Encryption v2 Richard Weinberger
2016-12-01 21:20 ` [PATCH 01/24] ubifs: Export ubifs_check_dir_empty() Richard Weinberger
2016-12-01 21:20 ` [PATCH 02/24] ubifs: Export xattr get and set functions Richard Weinberger
2016-12-01 21:20 ` [PATCH 03/24] ubifs: Define UBIFS crypto context xattr Richard Weinberger
2016-12-01 21:20 ` [PATCH 04/24] ubifs: Add skeleton for fscrypto Richard Weinberger
2016-12-01 21:20 ` [PATCH 05/24] ubifs: Massage ubifs_listxattr() for encryption context Richard Weinberger
2016-12-01 21:20 ` [PATCH 06/24] ubifs: Implement directory open operation Richard Weinberger
2016-12-01 21:20 ` [PATCH 07/24] ubifs: Implement file " Richard Weinberger
2016-12-01 21:20 ` [PATCH 08/24] ubifs: Enforce crypto policy in ->link and ->rename Richard Weinberger
2016-12-01 21:20 ` [PATCH 09/24] ubifs: Preload crypto context in ->lookup() Richard Weinberger
2016-12-01 21:20 ` [PATCH 10/24] ubifs: Massage assert in ubifs_xattr_set() wrt. fscrypto Richard Weinberger
2016-12-01 21:20 ` [PATCH 11/24] ubifs: Enforce crypto policy in mmap Richard Weinberger
2016-12-01 21:20 ` [PATCH 12/24] ubifs: Introduce new data node field, compr_size Richard Weinberger
2016-12-01 21:21 ` [PATCH 13/24] ubifs: Constify struct inode pointer in ubifs_crypt_is_encrypted() Richard Weinberger
2016-12-01 21:21 ` [PATCH 14/24] ubifs: Implement encrypt/decrypt for all IO Richard Weinberger
2016-12-01 21:21 ` [PATCH 15/24] ubifs: Relax checks in ubifs_validate_entry() Richard Weinberger
2016-12-01 21:21 ` [PATCH 16/24] ubifs: Make r5 hash binary string aware Richard Weinberger
2016-12-01 21:21 ` [PATCH 17/24] ubifs: Implement encrypted filenames Richard Weinberger
2016-12-01 21:21 ` [PATCH 18/24] ubifs: Add support for encrypted symlinks Richard Weinberger
2016-12-01 21:21 ` [PATCH 19/24] ubifs: Rename tnc_read_node_nm Richard Weinberger
2016-12-01 21:21 ` [PATCH 20/24] ubifs: Add full hash lookup support Richard Weinberger
2016-12-01 21:21 ` [PATCH 21/24] ubifs: Use a random number for cookies Richard Weinberger
2016-12-01 21:21 ` Richard Weinberger [this message]
2016-12-01 21:21 ` [PATCH 23/24] ubifs: Implement UBIFS_FLG_ENCRYPTION Richard Weinberger
2016-12-01 21:21 ` [PATCH 24/24] ubifs: Raise write version to 5 Richard Weinberger

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=1480627271-10441-23-git-send-email-richard@nod.at \
    --to=richard@nod.at \
    --cc=adrian.hunter@intel.com \
    --cc=david@sigma-star.at \
    --cc=dedekind1@gmail.com \
    --cc=dengler@linutronix.de \
    --cc=ebiggers@google.com \
    --cc=hch@infradead.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=mhalcrow@google.com \
    --cc=sbabic@denx.de \
    --cc=tytso@mit.edu \
    --cc=wd@denx.de \
    /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.