From patchwork Wed May 16 12:52:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Reardon X-Patchwork-Id: 159621 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2EE05B6FF2 for ; Wed, 16 May 2012 22:54:27 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SUdiW-0003eQ-Lc; Wed, 16 May 2012 12:52:36 +0000 Received: from [78.46.68.141] (helo=eristoteles.iwoars.net) by merlin.infradead.org with smtp (Exim 4.76 #1 (Red Hat Linux)) id 1SUdiT-0003dk-Sl for linux-mtd@lists.infradead.org; Wed, 16 May 2012 12:52:34 +0000 Received: (qmail 29511 invoked by uid 5144); 16 May 2012 14:52:32 +0200 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 16 May 2012 14:52:32 +0200 Date: Wed, 16 May 2012 14:52:32 +0200 (CEST) From: Joel Reardon X-X-Sender: joel@eristoteles.iwoars.net To: Artem Bityutskiy Subject: [PATCH v2] UBIFS: read crypto_lookup from datanodes to znodes In-Reply-To: <1337087022.2528.204.camel@sauron.fi.intel.com> Message-ID: References: <1337087022.2528.204.camel@sauron.fi.intel.com> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS 0.3 FROM_12LTRDOM From a 12-letter domain Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Crypto_lookup values are now read from the data node header whenever a data node is read from flash and cached in the TNC. The value will be zero until it is read from flash. (If it is needed before it happens to be loaded, i.e., to delete a node, then it will be forced read.) It was tested by setting cryptolookup values for new datanodes by their lnum and offset on flash. This was later asserted in the TNC that they were either zero, or always equal. On mounting, the TNC crypto lookup values were confirmed to be zero and later, after reading the corresponding files, confirmed they were loaded and corresponded to the location on flash. Signed-off-by: Joel Reardon --- fs/ubifs/gc.c | 7 ++++++- fs/ubifs/journal.c | 8 +++++--- fs/ubifs/tnc.c | 39 +++++++++++++++++++++++++++++++++++++++ fs/ubifs/ubifs-media.h | 3 ++- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c index f146447..98e6683 100644 --- a/fs/ubifs/gc.c +++ b/fs/ubifs/gc.c @@ -322,15 +322,20 @@ static int move_node(struct ubifs_info *c, struct ubifs_scan_leb *sleb, struct ubifs_scan_node *snod, struct ubifs_wbuf *wbuf) { int err, new_lnum = wbuf->lnum, new_offs = wbuf->offs + wbuf->used; + long long crypto_lookup = 0; cond_resched(); err = ubifs_wbuf_write_nolock(wbuf, snod->node, snod->len); if (err) return err; + if (key_type(c, &snod->key) == UBIFS_DATA_KEY) { + struct ubifs_data_node *dn = snod->node; + crypto_lookup = le64_to_cpu(dn->crypto_lookup); + } err = ubifs_tnc_replace(c, &snod->key, sleb->lnum, snod->offs, new_lnum, new_offs, - snod->len, 0); + snod->len, crypto_lookup); list_del(&snod->list); kfree(snod); return err; diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c index 2072b9a..5f39f75 100644 --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c @@ -89,7 +89,6 @@ static inline void zero_dent_node_unused(struct ubifs_dent_node *dent) */ static inline void zero_data_node_unused(struct ubifs_data_node *data) { - data->padding0 = 0; memset(data->padding1, 0, 2); } @@ -735,6 +734,7 @@ int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode, dlen = UBIFS_DATA_NODE_SZ + out_len; data->compr_type = cpu_to_le16(compr_type); + data->crypto_lookup = cpu_to_le64(0); /* Make reservation before allocating sequence numbers */ err = make_reservation(c, DATAHD, dlen); @@ -747,7 +747,8 @@ int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode, ubifs_wbuf_add_ino_nolock(&c->jheads[DATAHD].wbuf, key_inum(c, key)); release_head(c, DATAHD); - err = ubifs_tnc_add(c, key, lnum, offs, dlen, 0); + err = ubifs_tnc_add(c, key, lnum, offs, dlen, + le64_to_cpu(data->crypto_lookup)); if (err) goto out_ro; @@ -1226,7 +1227,8 @@ int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode, if (dlen) { sz = offs + UBIFS_INO_NODE_SZ + UBIFS_TRUN_NODE_SZ; - err = ubifs_tnc_add(c, &key, lnum, sz, dlen, 0); + err = ubifs_tnc_add(c, &key, lnum, sz, dlen, + le64_to_cpu(dn->crypto_lookup)); if (err) goto out_ro; } diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c index b222a72..006caa7 100644 --- a/fs/ubifs/tnc.c +++ b/fs/ubifs/tnc.c @@ -1431,6 +1431,34 @@ static int maybe_leb_gced(struct ubifs_info *c, int lnum, int gc_seq1) } /** + * tnc_set_crypto_lookup - set the crypto_lookup field in a zbranch. + * @c: UBIFS file-system description object + * @zbr: the crypto_lookup field is set in this zbranch + * @node: a pointer to a node containing the zbranch. + * + * Crypto_lookup values are stored on flash memory inside the data node. + * When the system is running, they are also stored in memory inside the + * zbranch to avoid requiring reading the old data node simply to retrieve the + * crypto_lookup when performing a truncation / overwrite / delete operation. + * This function is called whenever a node is read from flash memory. If @node + * is a data node (therefore containing a @crypto_lookup field), then: + * if @zbr has an unset @crypto_lookup, set it to the value from @node + * if @zbr has already a @crypto_lookup, assert they are the same. + */ +static void tnc_set_crypto_lookup(struct ubifs_info *c, + struct ubifs_zbranch *zbr, void *node) +{ + if (key_type(c, &(zbr->key)) == UBIFS_DATA_KEY) { + struct ubifs_data_node *dn = node; + long long crypto_lookup = le64_to_cpu(dn->crypto_lookup); + if (zbr->crypto_lookup != 0) + ubifs_assert(zbr->crypto_lookup == crypto_lookup); + else + zbr->crypto_lookup = crypto_lookup; + } +} + +/** * ubifs_tnc_locate - look up a file-system node and return it and its location. * @c: UBIFS file-system description object * @key: node key to lookup @@ -1485,6 +1513,11 @@ again: if (ubifs_get_wbuf(c, zbr.lnum)) { /* We do not GC journal heads */ err = ubifs_tnc_read_node(c, &zbr, node); + if (!err) { + mutex_lock(&c->tnc_mutex); + tnc_set_crypto_lookup(c, &(znode->zbranch[n]), node); + mutex_unlock(&c->tnc_mutex); + } return err; } @@ -1497,9 +1530,15 @@ again: safely = 1; goto again; } + + mutex_lock(&c->tnc_mutex); + tnc_set_crypto_lookup(c, &(znode->zbranch[n]), node); + mutex_unlock(&c->tnc_mutex); return 0; out: + if (!err) + tnc_set_crypto_lookup(c, zt, node); mutex_unlock(&c->tnc_mutex); return err; } diff --git a/fs/ubifs/ubifs-media.h b/fs/ubifs/ubifs-media.h index 9ecbd37..e03adcf 100644 --- a/fs/ubifs/ubifs-media.h +++ b/fs/ubifs/ubifs-media.h @@ -539,6 +539,7 @@ struct ubifs_dent_node { * struct ubifs_data_node - data node. * @ch: common header * @key: node key + * @crypto_lookup: the node's cryptographic key's position in the KSA * @size: uncompressed data size in bytes * @compr_type: compression type (%UBIFS_COMPR_NONE, %UBIFS_COMPR_LZO, etc) * @padding: reserved for future, zeroes @@ -550,7 +551,7 @@ struct ubifs_dent_node { struct ubifs_data_node { struct ubifs_ch ch; __u8 key[UBIFS_KEY_LEN]; - __le64 padding0; /* Watch 'zero_data_node_unused()' if changing! */ + __le64 crypto_lookup; __le32 size; __le16 compr_type; __u8 padding1[2]; /* Watch 'zero_data_node_unused()' if changing! */