hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/ubifs/log.c
....@@ -1,20 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * This file is part of UBIFS.
34 *
45 * Copyright (C) 2006-2008 Nokia Corporation.
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms of the GNU General Public License version 2 as published by
8
- * the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful, but WITHOUT
11
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
- * more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * this program; if not, write to the Free Software Foundation, Inc., 51
17
- * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
186 *
197 * Authors: Artem Bityutskiy (Битюцкий Артём)
208 * Adrian Hunter
....@@ -236,6 +224,7 @@
236224 bud->lnum = lnum;
237225 bud->start = offs;
238226 bud->jhead = jhead;
227
+ bud->log_hash = NULL;
239228
240229 ref->ch.node_type = UBIFS_REF_NODE;
241230 ref->lnum = cpu_to_le32(bud->lnum);
....@@ -272,6 +261,14 @@
272261 c->lhead_lnum, c->lhead_offs);
273262 err = ubifs_write_node(c, ref, UBIFS_REF_NODE_SZ, c->lhead_lnum,
274263 c->lhead_offs);
264
+ if (err)
265
+ goto out_unlock;
266
+
267
+ err = ubifs_shash_update(c, c->log_hash, ref, UBIFS_REF_NODE_SZ);
268
+ if (err)
269
+ goto out_unlock;
270
+
271
+ err = ubifs_shash_copy_state(c, c->log_hash, c->jheads[jhead].log_hash);
275272 if (err)
276273 goto out_unlock;
277274
....@@ -377,6 +374,14 @@
377374 cs->cmt_no = cpu_to_le64(c->cmt_no);
378375 ubifs_prepare_node(c, cs, UBIFS_CS_NODE_SZ, 0);
379376
377
+ err = ubifs_shash_init(c, c->log_hash);
378
+ if (err)
379
+ goto out;
380
+
381
+ err = ubifs_shash_update(c, c->log_hash, cs, UBIFS_CS_NODE_SZ);
382
+ if (err < 0)
383
+ goto out;
384
+
380385 /*
381386 * Note, we do not lock 'c->log_mutex' because this is the commit start
382387 * phase and we are exclusively using the log. And we do not lock
....@@ -402,6 +407,12 @@
402407
403408 ubifs_prepare_node(c, ref, UBIFS_REF_NODE_SZ, 0);
404409 len += UBIFS_REF_NODE_SZ;
410
+
411
+ err = ubifs_shash_update(c, c->log_hash, ref,
412
+ UBIFS_REF_NODE_SZ);
413
+ if (err)
414
+ goto out;
415
+ ubifs_shash_copy_state(c, c->log_hash, c->jheads[i].log_hash);
405416 }
406417
407418 ubifs_pad(c, buf + len, ALIGN(len, c->min_io_size) - len);
....@@ -427,10 +438,7 @@
427438 *ltail_lnum = c->lhead_lnum;
428439
429440 c->lhead_offs += len;
430
- if (c->lhead_offs == c->leb_size) {
431
- c->lhead_lnum = ubifs_next_log_lnum(c, c->lhead_lnum);
432
- c->lhead_offs = 0;
433
- }
441
+ ubifs_assert(c, c->lhead_offs < c->leb_size);
434442
435443 remove_buds(c);
436444
....@@ -516,6 +524,7 @@
516524 if (err)
517525 return err;
518526 list_del(&bud->list);
527
+ kfree(bud->log_hash);
519528 kfree(bud);
520529 }
521530 mutex_lock(&c->log_mutex);