[DLM] change lkid format [19/34]

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Steven Whitehouse
Date: Tuesday, May 1, 2007 - 3:13 am

>From ce03f12b37c0bd81ad707d3642241cc55c944711 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Mon, 2 Apr 2007 12:12:55 -0500
Subject: [PATCH] [DLM] change lkid format

A lock id is a uint32 and is used as an opaque reference to the lock.  For
userland apps, the lkid is passed up, through libdlm, as the return value
from a write() on the dlm device.  This created a problem when the high
bit was 1, making the lkid look like an error.  This is fixed by changing
how the lkid is composed.  The low 16 bits identified the hash bucket for
the lock and the high 16 bits were a per-bucket counter (which eventually
hit 0x8000 causing the problem).  These are simply swapped around; the
number of hash table buckets is far below 0x8000, making all lkid's
positive when viewed as signed.

Signed-off-by: David Teigland <teigland@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>

diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c
index 9d26b3a..eac54d2 100644
--- a/fs/dlm/lock.c
+++ b/fs/dlm/lock.c
@@ -580,7 +580,7 @@ static int create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret)
 	/* counter can roll over so we must verify lkid is not in use */
 
 	while (lkid == 0) {
-		lkid = bucket | (ls->ls_lkbtbl[bucket].counter++ << 16);
+		lkid = (bucket << 16) | ls->ls_lkbtbl[bucket].counter++;
 
 		list_for_each_entry(tmp, &ls->ls_lkbtbl[bucket].list,
 				    lkb_idtbl_list) {
@@ -601,8 +601,8 @@ static int create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret)
 
 static struct dlm_lkb *__find_lkb(struct dlm_ls *ls, uint32_t lkid)
 {
-	uint16_t bucket = lkid & 0xFFFF;
 	struct dlm_lkb *lkb;
+	uint16_t bucket = (lkid >> 16);
 
 	list_for_each_entry(lkb, &ls->ls_lkbtbl[bucket].list, lkb_idtbl_list) {
 		if (lkb->lkb_id == lkid)
@@ -614,7 +614,7 @@ static struct dlm_lkb *__find_lkb(struct dlm_ls *ls, uint32_t lkid)
 static int find_lkb(struct dlm_ls *ls, uint32_t lkid, struct dlm_lkb **lkb_ret)
 {
 	struct dlm_lkb *lkb;
-	uint16_t bucket = lkid & 0xFFFF;
+	uint16_t bucket = (lkid >> 16);
 
 	if (bucket >= ls->ls_lkbtbl_size)
 		return -EBADSLT;
@@ -644,7 +644,7 @@ static void kill_lkb(struct kref *kref)
 
 static int __put_lkb(struct dlm_ls *ls, struct dlm_lkb *lkb)
 {
-	uint16_t bucket = lkb->lkb_id & 0xFFFF;
+	uint16_t bucket = (lkb->lkb_id >> 16);
 
 	write_lock(&ls->ls_lkbtbl[bucket].lock);
 	if (kref_put(&lkb->lkb_ref, kill_lkb)) {
-- 
1.5.1.2



-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[GFS2] Patches for the current merge window [0/34], Steven Whitehouse, (Tue May 1, 2:56 am)
[DLM] Fix uninitialised variable in receiving [3/34], Steven Whitehouse, (Tue May 1, 2:59 am)
[GFS2] Fix bz 224480 and cleanup glock demotion code [5/34], Steven Whitehouse, (Tue May 1, 3:02 am)
[GFS2] Fix a bug on i386 due to evaluation order [6/34], Steven Whitehouse, (Tue May 1, 3:02 am)
[DLM] Don't delete misc device if lockspace removal fails ..., Steven Whitehouse, (Tue May 1, 3:03 am)
[GFS2] Speed up lock_dlm's locking (move sprintf) [8/34], Steven Whitehouse, (Tue May 1, 3:04 am)
[GFS2] Fix log entry list corruption [9/34], Steven Whitehouse, (Tue May 1, 3:05 am)
[GFS2] Red Hat bz 228540: owner references [11/34], Steven Whitehouse, (Tue May 1, 3:07 am)
[DLM] fix coverity-spotted stupidity [12/34], Steven Whitehouse, (Tue May 1, 3:07 am)
[DLM] overlapping cancel and unlock [13/34], Steven Whitehouse, (Tue May 1, 3:09 am)
[GFS2] use log_error before LM_OUT_ERROR [14/34], Steven Whitehouse, (Tue May 1, 3:09 am)
[GFS2] Set drop_count to 0 (off) by default [15/34], Steven Whitehouse, (Tue May 1, 3:10 am)
[DLM] split create_message function [16/34], Steven Whitehouse, (Tue May 1, 3:11 am)
[DLM] add orphan purging code (1/2) [17/34], Steven Whitehouse, (Tue May 1, 3:12 am)
[DLM] interface for purge (2/2) [18/34], Steven Whitehouse, (Tue May 1, 3:12 am)
[DLM] change lkid format [19/34], Steven Whitehouse, (Tue May 1, 3:13 am)
[DLM] change lkid format [19/34], Steven Whitehouse, (Tue May 1, 3:14 am)
GFS2] Fix bz 234168 (ignoring rgrp flags) [20/34], Steven Whitehouse, (Tue May 1, 3:14 am)
[DLM] Remove redundant assignment [21/34], Steven Whitehouse, (Tue May 1, 3:15 am)
[DLM] Consolidate transport protocols [21/34], Steven Whitehouse, (Tue May 1, 3:16 am)
DLM] fs/dlm/ast.c should #include &quot;ast.h&quot; [23/34], Steven Whitehouse, (Tue May 1, 3:17 am)
[GFS2] lockdump improvements [26/34], Steven Whitehouse, (Tue May 1, 3:20 am)
[DLM] fix mode munging [27/34], Steven Whitehouse, (Tue May 1, 3:20 am)
[DLM] Fix dlm_lowcoms_stop hang [28/34], Steven Whitehouse, (Tue May 1, 3:21 am)
[GFS2] use lib/parser for parsing mount options [30/34], Steven Whitehouse, (Tue May 1, 3:22 am)
[GFS2] Patch to fix mmap of stuffed files [31/34], Steven Whitehouse, (Tue May 1, 3:23 am)
[GFS2] printk warning fixes [32/34], Steven Whitehouse, (Tue May 1, 3:24 am)
[DLM] lowcomms style [33/34], Steven Whitehouse, (Tue May 1, 3:24 am)
[GFS2] Uncomment sprintf_symbol calling code [34/34], Steven Whitehouse, (Tue May 1, 3:25 am)
[GFS2/DLM] Pull request, Steven Whitehouse, (Tue May 1, 7:11 am)