Skip to contentSkip to conversation

ocfs2: code cleanup for .36

PATCH Superseded Tao Ma 3 participants 11 messages Aug 2, 2010 – Aug 14, 2010 OCFS2

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tao Ma

author
#0 lore raw

cover ocfs2: code cleanup for .36

Hi Joel,
These patches are generated when I read the codes. All are trivial
cleanups. So I guess you can pull it easily, but I'd like to send them to the list first.

You can pull from
git://oss.oracle.com/git/tma/linux-2.6.git trivial

Regards,
Tao

author
#1 lore raw

PATCH 1/4 ocfs2/trivial: Move 'wanted' into parens of ocfs2_resmap_resv_bits.

The first time I read the function ocfs2_resmap_resv_bits, I consider about what 'wanted' will be used and consider about the comments. Then I find it is only used if the reservation is empty. ;)

So we'd better move it to the parens so that it make the code more readable, what's more, ocfs2_resmap_resv_bits is used so frequently and we should save some cpus. The corresponding BUG_ON is also moved into parens since it is only meaningful after we reinit the resv.

Cc Mark Fasheh <[email protected]>
---
 fs/ocfs2/reservations.c |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)
fs/ocfs2/reservations.c +12 -14
index d8b6e42..567c1a0 100644
@@ -732,25 +732,23 @@ int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap,
 			   struct ocfs2_alloc_reservation *resv,
 			   int *cstart, int *clen)
 {
-	unsigned int wanted = *clen;
-
 	if (resv == NULL || ocfs2_resmap_disabled(resmap))
 		return -ENOSPC;
 
 	spin_lock(&resv_lock);
 
-	/*
-	 * We don't want to over-allocate for temporary
-	 * windows. Otherwise, we run the risk of fragmenting the
-	 * allocation space.
-	 */
-	wanted = ocfs2_resv_window_bits(resmap, resv);
-	if ((resv->r_flags & OCFS2_RESV_FLAG_TMP) || wanted < *clen)
-		wanted = *clen;
-
 	if (ocfs2_resv_empty(resv)) {
-		mlog(0, "empty reservation, find new window\n");
+		/*
+		 * We don't want to over-allocate for temporary
+		 * windows. Otherwise, we run the risk of fragmenting the
+		 * allocation space.
+		 */
+		unsigned int wanted = ocfs2_resv_window_bits(resmap, resv);
+
+		if ((resv->r_flags & OCFS2_RESV_FLAG_TMP) || wanted < *clen)
+			wanted = *clen;
 
+		mlog(0, "empty reservation, find new window\n");
 		/*
 		 * Try to get a window here. If it works, we must fall
 		 * through and test the bitmap . This avoids some
@@ -759,9 +757,9 @@ int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap,
 		 * that inode.
 		 */
 		ocfs2_resv_find_window(resmap, resv, wanted);
-	}
 
-	BUG_ON(ocfs2_resv_empty(resv));
+		BUG_ON(ocfs2_resv_empty(resv));
+	}
 
 	*cstart = resv->r_start;
 	*clen = resv->r_len;
Signature · 1 line
1.7.1.571.gba4d01
author
#4 lore raw

PATCH 2/4 ocfs2: Remove unused old_id in ocfs2_commit_cache.

In reply to Tao Ma
---
 fs/ocfs2/journal.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/ocfs2/journal.c +1 -2
index 47878cf..2a9eac8 100644
@@ -301,7 +301,6 @@ static int ocfs2_commit_cache(struct ocfs2_super *osb)
 {
 	int status = 0;
 	unsigned int flushed;
-	unsigned long old_id;
 	struct ocfs2_journal *journal = NULL;
 
 	mlog_entry_void();
@@ -326,7 +325,7 @@ static int ocfs2_commit_cache(struct ocfs2_super *osb)
 		goto finally;
 	}
 
-	old_id = ocfs2_inc_trans_id(journal);
+	ocfs2_inc_trans_id(journal);
 
 	flushed = atomic_read(&journal->j_num_trans);
 	atomic_set(&journal->j_num_trans, 0);
Signature · 1 line
1.7.1.571.gba4d01
author
#7 lore raw

PATCH 3/4 ocfs2: Remove obsolete comments before ocfs2_start_trans.

In reply to Tao Ma
---
 fs/ocfs2/journal.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
fs/ocfs2/journal.c +0 -3
index 2a9eac8..ac2ea71 100644
@@ -341,9 +341,6 @@ finally:
 	return status;
 }
 
-/* pass it NULL and it will allocate a new handle object for you.  If
- * you pass it a handle however, it may still return error, in which
- * case it has free'd the passed handle for you. */
 handle_t *ocfs2_start_trans(struct ocfs2_super *osb, int max_buffs)
 {
 	journal_t *journal = osb->journal->j_journal;
Signature · 1 line
1.7.1.571.gba4d01
author
#10 lore raw

PATCH 4/4 ocfs2: Add some trace log for orphan scan.

In reply to Tao Ma

Now orphan scan worker has no trace log, so it is very hard to tell whether it is finished or blocked. So add 2 mlog trace log so that we can tell whether the current orphan scan worker is blocked or not. It does help when I analyzed an orphan scan bug.

---
 fs/ocfs2/journal.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
fs/ocfs2/journal.c +3 -0
index ac2ea71..9209f19 100644
@@ -1887,6 +1887,8 @@ void ocfs2_queue_orphan_scan(struct ocfs2_super *osb)
 	if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
 		goto out;
 
+	mlog(0, "Begin orphan scan\n");
+
 	status = ocfs2_orphan_scan_lock(osb, &seqno);
 	if (status < 0) {
 		if (status != -EAGAIN)
@@ -1915,6 +1917,7 @@ void ocfs2_queue_orphan_scan(struct ocfs2_super *osb)
 	os->os_scantime = CURRENT_TIME;
 unlock:
 	ocfs2_orphan_scan_unlock(osb, seqno);
+	mlog(0, "Orphan scan completed\n");
 out:
 	return;
 }
Signature · 1 line
1.7.1.571.gba4d01
#6 lore raw

PATCH 2/4 ocfs2: Remove unused old_id in ocfs2_commit_cache.

In reply to Tao Ma
Quoted 1 line · Tao Ma

This patch is now in the merge-window branch of ocfs2.git.

Joel

Signature · 9 lines
"If you are ever in doubt as to whether or not to kiss a pretty girl, 
 give her the benefit of the doubt"
                                        -Thomas Carlyle

Joel Becker
Consulting Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
#9 lore raw

PATCH 3/4 ocfs2: Remove obsolete comments before ocfs2_start_trans.

In reply to Tao Ma
Quoted 1 line · Tao Ma

This patch is now in the merge-window branch of ocfs2.git.

Joel

Signature · 9 lines
Life's Little Instruction Book #237

	"Seek out the good in people."

Joel Becker
Consulting Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
#2 lore raw

PATCH 1/4 ocfs2/trivial: Move 'wanted' into parens of ocfs2_resmap_resv_bits.

In reply to Tao Ma

Hi Tao,

Quoted 56 lines · Tao Ma

The first time I read the function ocfs2_resmap_resv_bits, I consider about what 'wanted' will be used and consider about the comments. Then I find it is only used if the reservation is empty. ;)

So we'd better move it to the parens so that it make the code more readable, what's more, ocfs2_resmap_resv_bits is used so frequently and we should save some cpus. The corresponding BUG_ON is also moved into parens since it is only meaningful after we reinit the resv.

Cc Mark Fasheh <[email protected]>
---
 fs/ocfs2/reservations.c |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)
fs/ocfs2/reservations.c +10 -12
index d8b6e42..567c1a0 100644
@@ -732,25 +732,23 @@ int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap,
 			   struct ocfs2_alloc_reservation *resv,
 			   int *cstart, int *clen)
 {
-	unsigned int wanted = *clen;
-
 	if (resv == NULL || ocfs2_resmap_disabled(resmap))
 		return -ENOSPC;
 
 	spin_lock(&resv_lock);
 
-	/*
-	 * We don't want to over-allocate for temporary
-	 * windows. Otherwise, we run the risk of fragmenting the
-	 * allocation space.
-	 */
-	wanted = ocfs2_resv_window_bits(resmap, resv);
-	if ((resv->r_flags & OCFS2_RESV_FLAG_TMP) || wanted < *clen)
-		wanted = *clen;
-
 	if (ocfs2_resv_empty(resv)) {
-		mlog(0, "empty reservation, find new window\n");
+		/*
+		 * We don't want to over-allocate for temporary
+		 * windows. Otherwise, we run the risk of fragmenting the
+		 * allocation space.
+		 */
+		unsigned int wanted = ocfs2_resv_window_bits(resmap, resv);
+
+		if ((resv->r_flags & OCFS2_RESV_FLAG_TMP) || wanted < *clen)
+			wanted = *clen;
 
+		mlog(0, "empty reservation, find new window\n");
 		/*
 		 * Try to get a window here. If it works, we must fall
 		 * through and test the bitmap . This avoids some

fs/ocfs2/reservations.c int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap, · line 762

Quoted 8 lines
fs/ocfs2/reservations.c +2 -2
@@ -759,9 +757,9 @@ int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap,
 		 * that inode.
 		 */
 		ocfs2_resv_find_window(resmap, resv, wanted);
-	}
 
-	BUG_ON(ocfs2_resv_empty(resv));
+		BUG_ON(ocfs2_resv_empty(resv));
+	}

Can we leave the BUG_ON() outside the if (ocfs2_resv_empty(...)) { } block? You're technically correct in that the only possibility right now is if there's a bug in ocfs2_resv_find_window(). However, I think it still belongs outside the block because we're returning an allocation at that point. The code is self documenting then - "don't let it get here unless resv->r_start and resv->r_len mean something". That way any future changes to the function will be forced to take this BUG_ON() into consideration, and we are then less likely to accidentally corrupt data.

Otherwise the patch looks great to me. Thanks for the cleanup in the first hunk!

	--Mark

--
Mark Fasheh

author
#3 lore raw

PATCH 1/4 ocfs2/trivial: Move 'wanted' into parens of ocfs2_resmap_resv_bits.

Hi Mark,

Quoted 64 lines · Mark Fasheh

Hi Tao,

Quoted 61 lines · Tao Ma

The first time I read the function ocfs2_resmap_resv_bits, I consider about what 'wanted' will be used and consider about the comments. Then I find it is only used if the reservation is empty. ;)

So we'd better move it to the parens so that it make the code more readable, what's more, ocfs2_resmap_resv_bits is used so frequently and we should save some cpus. The corresponding BUG_ON is also moved into parens since it is only meaningful after we reinit the resv.

Cc Mark Fasheh<[email protected]>
---
  fs/ocfs2/reservations.c |   26 ++++++++++++--------------
  1 files changed, 12 insertions(+), 14 deletions(-)
fs/ocfs2/reservations.c +10 -13
index d8b6e42..567c1a0 100644
@@ -732,25 +732,23 @@ int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap,
  			   struct ocfs2_alloc_reservation *resv,
  			   int *cstart, int *clen)
  {
-	unsigned int wanted = *clen;
-
  	if (resv == NULL || ocfs2_resmap_disabled(resmap))
  		return -ENOSPC;
 
  	spin_lock(&resv_lock);
 
-	/*
-	 * We don't want to over-allocate for temporary
-	 * windows. Otherwise, we run the risk of fragmenting the
-	 * allocation space.
-	 */
-	wanted = ocfs2_resv_window_bits(resmap, resv);
-	if ((resv->r_flags&  OCFS2_RESV_FLAG_TMP) || wanted<  *clen)
-		wanted = *clen;
-
  	if (ocfs2_resv_empty(resv)) {
-		mlog(0, "empty reservation, find new window\n");
+		/*
+		 * We don't want to over-allocate for temporary
+		 * windows. Otherwise, we run the risk of fragmenting the
+		 * allocation space.
+		 */
+		unsigned int wanted = ocfs2_resv_window_bits(resmap, resv);
+
+		if ((resv->r_flags&  OCFS2_RESV_FLAG_TMP) || wanted<  *clen)
+			wanted = *clen;
 
+		mlog(0, "empty reservation, find new window\n");
  		/*
  		 * Try to get a window here. If it works, we must fall
  		 * through and test the bitmap . This avoids some
@@ -759,9 +757,9 @@ int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap,
  		 * that inode.
  		 */
  		ocfs2_resv_find_window(resmap, resv, wanted);
-	}
 
Quoted 12 lines

fs/ocfs2/reservations.c int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap, · line 762

Quoted 3 lines
fs/ocfs2/reservations.c +2 -1
-	BUG_ON(ocfs2_resv_empty(resv));
+		BUG_ON(ocfs2_resv_empty(resv));
+	}

Can we leave the BUG_ON() outside the if (ocfs2_resv_empty(...)) { } block? You're technically correct in that the only possibility right now is if there's a bug in ocfs2_resv_find_window(). However, I think it still belongs outside the block because we're returning an allocation at that point. The code is self documenting then - "don't let it get here unless resv->r_start and resv->r_len mean something". That way any future changes to the function will be forced to take this BUG_ON() into consideration, and we are then less likely to accidentally corrupt data.

Actually I have thought of it. But please note that the if check is ocfs2_resv_empty. So does it look a little bit strange that:
if (ocfs2_resv_empty()) {
}

BUG_ON(ocfs2_resv_empty());

We have just checked ocfs2_resv_empty and now we BUG_ON it again?

Regards,
Tao