linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: James Simmons <jsimmons@infradead.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org,
	Andreas Dilger <andreas.dilger@intel.com>,
	Oleg Drokin <oleg.drokin@intel.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Lustre Development List <lustre-devel@lists.lustre.org>,
	Mikhail Pershin <mike.pershin@intel.com>,
	James Simmons <jsimmons@infradead.org>
Subject: [PATCH 05/35] staging: lustre: llog: fix wrong offset in llog_process_thread()
Date: Thu, 10 Nov 2016 12:30:35 -0500	[thread overview]
Message-ID: <1478799065-24841-6-git-send-email-jsimmons@infradead.org> (raw)
In-Reply-To: <1478799065-24841-1-git-send-email-jsimmons@infradead.org>

From: Mikhail Pershin <mike.pershin@intel.com>

- llh_cat_idx may become bigger than llog bitmap size in
  llog_cat_set_first_idx() function
- it is wrong to use previous cur_offset as new buffer offset,
  new offset should be calculated from value returned by
  llog_next_block().
- optimize llog_skip_over() to find llog entry offset by index
  for llog with fixed-size records.

Signed-off-by: Mikhail Pershin <mike.pershin@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6714
Reviewed-on: http://review.whamcloud.com/15316
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 drivers/staging/lustre/lustre/obdclass/llog.c |   81 +++++++++++++++++-------
 1 files changed, 57 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/llog.c b/drivers/staging/lustre/lustre/obdclass/llog.c
index 3bc1789..f69fa32 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog.c
@@ -218,8 +218,7 @@ static int llog_process_thread(void *arg)
 	struct llog_process_cat_data	*cd  = lpi->lpi_catdata;
 	char				*buf;
 	__u64				 cur_offset;
-	__u64				 last_offset;
-	int chunk_size;
+	size_t chunk_size;
 	int				 rc = 0, index = 1, last_index;
 	int				 saved_index = 0;
 	int				 last_called_index = 0;
@@ -229,6 +228,8 @@ static int llog_process_thread(void *arg)
 
 	cur_offset = llh->llh_hdr.lrh_len;
 	chunk_size = llh->llh_hdr.lrh_len;
+	/* expect chunk_size to be power of two */
+	LASSERT(is_power_of_2(chunk_size));
 
 	buf = libcfs_kvzalloc(chunk_size, GFP_NOFS);
 	if (!buf) {
@@ -245,38 +246,49 @@ static int llog_process_thread(void *arg)
 	else
 		last_index = LLOG_HDR_BITMAP_SIZE(llh) - 1;
 
-	/* Record is not in this buffer. */
-	if (index > last_index)
-		goto out;
-
 	while (rc == 0) {
+		unsigned int buf_offset = 0;
 		struct llog_rec_hdr *rec;
+		bool partial_chunk;
+		off_t chunk_offset;
 
 		/* skip records not set in bitmap */
 		while (index <= last_index &&
 		       !ext2_test_bit(index, LLOG_HDR_BITMAP(llh)))
 			++index;
 
-		LASSERT(index <= last_index + 1);
-		if (index == last_index + 1)
+		if (index > last_index)
 			break;
-repeat:
+
 		CDEBUG(D_OTHER, "index: %d last_index %d\n",
 		       index, last_index);
-
+repeat:
 		/* get the buf with our target record; avoid old garbage */
 		memset(buf, 0, chunk_size);
-		last_offset = cur_offset;
 		rc = llog_next_block(lpi->lpi_env, loghandle, &saved_index,
 				     index, &cur_offset, buf, chunk_size);
 		if (rc)
 			goto out;
 
+		/*
+		 * NB: after llog_next_block() call the cur_offset is the
+		 * offset of the next block after read one.
+		 * The absolute offset of the current chunk is calculated
+		 * from cur_offset value and stored in chunk_offset variable.
+		 */
+		if (cur_offset % chunk_size) {
+			partial_chunk = true;
+			chunk_offset = cur_offset & ~(chunk_size - 1);
+		} else {
+			partial_chunk = false;
+			chunk_offset = cur_offset - chunk_size;
+		}
+
 		/* NB: when rec->lrh_len is accessed it is already swabbed
 		 * since it is used at the "end" of the loop and the rec
 		 * swabbing is done at the beginning of the loop.
 		 */
-		for (rec = (struct llog_rec_hdr *)buf;
+		for (rec = (struct llog_rec_hdr *)(buf + buf_offset);
 		     (char *)rec < buf + chunk_size;
 		     rec = llog_rec_hdr_next(rec)) {
 			CDEBUG(D_OTHER, "processing rec 0x%p type %#x\n",
@@ -288,13 +300,28 @@ static int llog_process_thread(void *arg)
 			CDEBUG(D_OTHER, "after swabbing, type=%#x idx=%d\n",
 			       rec->lrh_type, rec->lrh_index);
 
-			if (rec->lrh_index == 0) {
-				/* probably another rec just got added? */
-				rc = 0;
-				if (index <= loghandle->lgh_last_idx)
-					goto repeat;
-				goto out; /* no more records */
+			/*
+			 * for partial chunk the end of it is zeroed, check
+			 * for index 0 to distinguish it.
+			 */
+			if (partial_chunk && !rec->lrh_index) {
+				/* concurrent llog_add() might add new records
+				 * while llog_processing, check this is not
+				 * the case and re-read the current chunk
+				 * otherwise.
+				 */
+				if (index > loghandle->lgh_last_idx) {
+					rc = 0;
+					goto out;
+				}
+				CDEBUG(D_OTHER, "Re-read last llog buffer for new records, index %u, last %u\n",
+				       index, loghandle->lgh_last_idx);
+				/* save offset inside buffer for the re-read */
+				buf_offset = (char *)rec - (char *)buf;
+				cur_offset = chunk_offset;
+				goto repeat;
 			}
+
 			if (!rec->lrh_len || rec->lrh_len > chunk_size) {
 				CWARN("invalid length %d in llog record for index %d/%d\n",
 				      rec->lrh_len,
@@ -309,6 +336,14 @@ static int llog_process_thread(void *arg)
 				continue;
 			}
 
+			if (rec->lrh_index != index) {
+				CERROR("%s: Invalid record: index %u but expected %u\n",
+				       loghandle->lgh_ctxt->loc_obd->obd_name,
+				       rec->lrh_index, index);
+				rc = -ERANGE;
+				goto out;
+			}
+
 			CDEBUG(D_OTHER,
 			       "lrh_index: %d lrh_len: %d (%d remains)\n",
 			       rec->lrh_index, rec->lrh_len,
@@ -316,7 +351,7 @@ static int llog_process_thread(void *arg)
 
 			loghandle->lgh_cur_idx = rec->lrh_index;
 			loghandle->lgh_cur_offset = (char *)rec - (char *)buf +
-						    last_offset;
+						    chunk_offset;
 
 			/* if set, process the callback on this record */
 			if (ext2_test_bit(index, LLOG_HDR_BITMAP(llh))) {
@@ -325,16 +360,14 @@ static int llog_process_thread(void *arg)
 				last_called_index = index;
 				if (rc)
 					goto out;
-			} else {
-				CDEBUG(D_OTHER, "Skipped index %d\n", index);
 			}
 
-			/* next record, still in buffer? */
-			++index;
-			if (index > last_index) {
+			/* exit if the last index is reached */
+			if (index >= last_index) {
 				rc = 0;
 				goto out;
 			}
+			index++;
 		}
 	}
 
-- 
1.7.1

  parent reply	other threads:[~2016-11-10 17:46 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-10 17:30 [PATCH 00/35] second batch of missing lustre 2.8 patches James Simmons
2016-11-10 17:30 ` [PATCH 01/35] staging: lustre: hsm: Use file lease to implement migration James Simmons
2016-11-10 17:30 ` [PATCH 02/35] staging: lustre: obd: rename obd_unpackmd() to md_unpackmd() James Simmons
2016-11-10 17:30 ` [PATCH 03/35] staging: lustre: ptlrpc: mbits is sent within ptlrpc_body James Simmons
2016-11-10 17:30 ` [PATCH 04/35] staging: lustre: lov: init LOV stripe type beforehand James Simmons
2016-11-10 17:30 ` James Simmons [this message]
2016-11-11  4:35   ` [PATCH 05/35] staging: lustre: llog: fix wrong offset in llog_process_thread() kbuild test robot
2016-11-10 17:30 ` [PATCH 06/35] staging: lustre: osc: Performance tune for LRU James Simmons
2016-11-11  5:16   ` kbuild test robot
2016-11-10 17:30 ` [PATCH 07/35] staging: lustre: lov: avoid infinite loop in lsm_alloc_plain() James Simmons
2016-11-10 17:30 ` [PATCH 08/35] staging: lustre: lmv: lock necessary part of lmv_add_target James Simmons
2016-11-10 17:30 ` [PATCH 09/35] staging: lustre: mgc: IR log failure should not stop mount James Simmons
2016-11-10 17:30 ` [PATCH 10/35] staging: lustre: lmv: revalidate the dentry for striped dir James Simmons
2016-11-10 17:30 ` [PATCH 11/35] staging: lustre: ptlrpc: race at req processing James Simmons
2016-11-10 17:30 ` [PATCH 12/35] staging: lustre: clio: get rid of cl_req James Simmons
2016-11-10 17:30 ` [PATCH 13/35] staging: lustre: llite: lookup master inode by ilookup5_nowait James Simmons
2016-11-10 17:30 ` [PATCH 14/35] staging: lustre: nrs: serialize executions of nrs_policy_stop James Simmons
2016-11-10 17:30 ` [PATCH 15/35] staging: lustre: llite: tar restore fails for HSM released files James Simmons
2016-11-10 17:30 ` [PATCH 16/35] staging: lustre: llite: support SELinux context labelling James Simmons
2016-11-10 17:30 ` [PATCH 17/35] staging: lustre: obd: Remove dead code in precleanup James Simmons
2016-11-10 17:30 ` [PATCH 18/35] staging: lustre: osc: fix max_dirty_mb tunable setting limit James Simmons
2016-11-10 17:30 ` [PATCH 19/35] staging: lustre: obdclass: remove structure holes to reduce memory James Simmons
2016-11-10 17:30 ` [PATCH 20/35] staging: lustre: ptlrpc: Move IT_* definitions to lustre_idl.h James Simmons
2016-11-10 17:30 ` [PATCH 21/35] staging: lustre: statahead: lock leaks if statahead file recreated James Simmons
2016-11-10 17:30 ` [PATCH 22/35] staging: lustre: llite: clear dir stripe md in ll_iget James Simmons
2016-11-10 17:30 ` [PATCH 23/35] staging: lustre: ldlm: improve lock timeout messages James Simmons
2016-11-10 17:30 ` [PATCH 24/35] staging: lustre: osc: osc_extent should hold refcount to osc_object James Simmons
2016-11-10 17:30 ` [PATCH 25/35] staging: lustre: osc: Do not merge extents with partial pages James Simmons
2016-11-10 17:30 ` [PATCH 26/35] staging: lustre: mdc: remove console spew from mdc_ioc_fid2path James Simmons
2016-11-10 17:30 ` [PATCH 27/35] staging: lustre: ptlrpc: reset imp_replay_cursor James Simmons
2016-11-10 17:30 ` [PATCH 28/35] staging: lustre: osc: Remove remains of osc_ast_guard James Simmons
2016-11-10 17:30 ` [PATCH 29/35] staging: lustre: misc: clean up DFID related error messages James Simmons
2016-11-10 17:31 ` [PATCH 30/35] staging: lustre: llite: ll_write_begin/end not passing on errors James Simmons
2016-11-10 17:31 ` [PATCH 31/35] staging: lustre: obdclass: add export for lprocfs_stats_alloc_one() James Simmons
2016-11-14 14:59   ` Greg Kroah-Hartman
2016-11-10 17:31 ` [PATCH 32/35] staging: lustre: mount: fix lmd_parse() to handle commas in expr_list James Simmons
2016-11-14 15:12   ` Greg Kroah-Hartman
2016-11-18 16:54     ` James Simmons
2016-11-18 17:14       ` Greg Kroah-Hartman
2016-11-10 17:31 ` [PATCH 33/35] staging: lustre: hsm: prevent migration of HSM archived files James Simmons
2016-11-10 17:31 ` [PATCH 34/35] staging: lustre: lnet: add offset for selftest brw James Simmons
2016-11-10 17:31 ` [PATCH 35/35] staging: lustre: idl: clean up file attribute flags James Simmons
2016-11-14 15:16 ` [PATCH 00/35] second batch of missing lustre 2.8 patches Greg Kroah-Hartman
2016-11-14 18:27   ` James Simmons
2016-11-15 10:00     ` Greg Kroah-Hartman

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=1478799065-24841-6-git-send-email-jsimmons@infradead.org \
    --to=jsimmons@infradead.org \
    --cc=andreas.dilger@intel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lustre-devel@lists.lustre.org \
    --cc=mike.pershin@intel.com \
    --cc=oleg.drokin@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).