[Cluster-devel] GFS2: Use rbm for gfs2_setbit()

2012-08-13 Thread Steven Whitehouse
From 257cd649be9710e12f9e3c7b3384c8b07802a6a0 Mon Sep 17 00:00:00 2001
From: Steven Whitehouse swhit...@redhat.com
Date: Mon, 13 Aug 2012 11:37:51 +0100
Subject: [PATCH 2/2] GFS2: Use rbm for gfs2_setbit()

Use the rbm structure for gfs2_setbit() in order to simplify the
arguments to the function. We have to add a bool to control whether
the clone bitmap should be updated (if it exists) but otherwise it
is a more or less direct substitution.

Signed-off-by: Steven Whitehouse swhit...@redhat.com

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 3a288ce..55a2651 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -69,47 +69,42 @@ static const char valid_change[16] = {
 
 /**
  * gfs2_setbit - Set a bit in the bitmaps
- * @rgd: the resource group descriptor
- * @buf2: the clone buffer that holds the bitmaps
- * @bi: the bitmap structure
- * @block: the block to set
+ * @rbm: The position of the bit to set
+ * @do_clone: Also set the clone bitmap, if it exists
  * @new_state: the new state of the block
  *
  */
 
-static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buf2,
-  struct gfs2_bitmap *bi, u32 block,
+static inline void gfs2_setbit(const struct gfs2_rbm *rbm, bool do_clone,
   unsigned char new_state)
 {
unsigned char *byte1, *byte2, *end, cur_state;
-   unsigned int buflen = bi-bi_len;
-   const unsigned int bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE;
+   unsigned int buflen = rbm-bi-bi_len;
+   const unsigned int bit = (rbm-offset % GFS2_NBBY) * GFS2_BIT_SIZE;
 
-   byte1 = bi-bi_bh-b_data + bi-bi_offset + (block / GFS2_NBBY);
-   end = bi-bi_bh-b_data + bi-bi_offset + buflen;
+   byte1 = rbm-bi-bi_bh-b_data + rbm-bi-bi_offset + (rbm-offset / 
GFS2_NBBY);
+   end = rbm-bi-bi_bh-b_data + rbm-bi-bi_offset + buflen;
 
BUG_ON(byte1 = end);
 
cur_state = (*byte1  bit)  GFS2_BIT_MASK;
 
if (unlikely(!valid_change[new_state * 4 + cur_state])) {
-   printk(KERN_WARNING GFS2: buf_blk = 0x%llx old_state=%d, 
-  new_state=%d\n,
-  (unsigned long long)block, cur_state, new_state);
-   printk(KERN_WARNING GFS2: rgrp=0x%llx bi_start=0x%lx\n,
-  (unsigned long long)rgd-rd_addr,
-  (unsigned long)bi-bi_start);
-   printk(KERN_WARNING GFS2: bi_offset=0x%lx bi_len=0x%lx\n,
-  (unsigned long)bi-bi_offset,
-  (unsigned long)bi-bi_len);
+   printk(KERN_WARNING GFS2: buf_blk = 0x%x old_state=%d, 
+  new_state=%d\n, rbm-offset, cur_state, new_state);
+   printk(KERN_WARNING GFS2: rgrp=0x%llx bi_start=0x%x\n,
+  (unsigned long long)rbm-rgd-rd_addr,
+  rbm-bi-bi_start);
+   printk(KERN_WARNING GFS2: bi_offset=0x%x bi_len=0x%x\n,
+  rbm-bi-bi_offset, rbm-bi-bi_len);
dump_stack();
-   gfs2_consist_rgrpd(rgd);
+   gfs2_consist_rgrpd(rbm-rgd);
return;
}
*byte1 ^= (cur_state ^ new_state)  bit;
 
-   if (buf2) {
-   byte2 = buf2 + bi-bi_offset + (block / GFS2_NBBY);
+   if (do_clone  rbm-bi-bi_clone) {
+   byte2 = rbm-bi-bi_clone + rbm-bi-bi_offset + (rbm-offset / 
GFS2_NBBY);
cur_state = (*byte2  bit)  GFS2_BIT_MASK;
*byte2 ^= (cur_state ^ new_state)  bit;
}
@@ -1852,8 +1847,7 @@ static void gfs2_alloc_extent(const struct gfs2_rbm *rbm, 
bool dinode,
*n = 1;
block = gfs2_rbm_to_block(rbm);
gfs2_trans_add_bh(rbm-rgd-rd_gl, rbm-bi-bi_bh, 1);
-   gfs2_setbit(rbm-rgd, rbm-bi-bi_clone, rbm-bi, rbm-offset,
-   dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
+   gfs2_setbit(rbm, true, dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
block++;
while (*n  elen) {
ret = gfs2_rbm_from_block(pos, block);
@@ -1861,7 +1855,7 @@ static void gfs2_alloc_extent(const struct gfs2_rbm *rbm, 
bool dinode,
if (gfs2_testbit(pos) != GFS2_BLKST_FREE)
break;
gfs2_trans_add_bh(pos.rgd-rd_gl, pos.bi-bi_bh, 1);
-   gfs2_setbit(pos.rgd, pos.bi-bi_clone, pos.bi, pos.offset, 
GFS2_BLKST_USED);
+   gfs2_setbit(pos, true, GFS2_BLKST_USED);
(*n)++;
block++;
}
@@ -1900,7 +1894,7 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd 
*sdp, u64 bstart,
   rbm.bi-bi_len);
}
gfs2_trans_add_bh(rbm.rgd-rd_gl, rbm.bi-bi_bh, 1);
-   gfs2_setbit(rbm.rgd, NULL, rbm.bi, rbm.offset, new_state);
+   gfs2_setbit(rbm, false, new_state);
}
 
return rbm.rgd;
-- 
1.7.4





[Cluster-devel] GFS2: Use rbm for gfs2_testbit()

2012-08-13 Thread Steven Whitehouse
From 29b2a71fe1db0b4dae5855acd58b2cb79555b2ea Mon Sep 17 00:00:00 2001
From: Steven Whitehouse swhit...@redhat.com
Date: Mon, 13 Aug 2012 11:14:57 +0100
Subject: [PATCH 1/2] GFS2: Use rbm for gfs2_testbit()

Change the arguments to gfs2_testbit() so that it now just takes an
rbm specifying the position of the two bit entry to return.

Signed-off-by: Steven Whitehouse swhit...@redhat.com

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 47d2346..3a288ce 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -117,30 +117,21 @@ static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, 
unsigned char *buf2,
 
 /**
  * gfs2_testbit - test a bit in the bitmaps
- * @rgd: the resource group descriptor
- * @buffer: the buffer that holds the bitmaps
- * @buflen: the length (in bytes) of the buffer
- * @block: the block to read
+ * @rbm: The bit to test
  *
+ * Returns: The two bit block state of the requested bit
  */
 
-static inline unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd,
-const unsigned char *buffer,
-unsigned int buflen, u32 block)
+static inline u8 gfs2_testbit(const struct gfs2_rbm *rbm)
 {
-   const unsigned char *byte, *end;
-   unsigned char cur_state;
+   const u8 *buffer = rbm-bi-bi_bh-b_data + rbm-bi-bi_offset;
+   const u8 *byte;
unsigned int bit;
 
-   byte = buffer + (block / GFS2_NBBY);
-   bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE;
-   end = buffer + buflen;
-
-   gfs2_assert(rgd-rd_sbd, byte  end);
-
-   cur_state = (*byte  bit)  GFS2_BIT_MASK;
+   byte = buffer + (rbm-offset / GFS2_NBBY);
+   bit = (rbm-offset % GFS2_NBBY) * GFS2_BIT_SIZE;
 
-   return cur_state;
+   return (*byte  bit)  GFS2_BIT_MASK;
 }
 
 /**
@@ -1837,8 +1828,7 @@ static unsigned char gfs2_get_block_type(struct 
gfs2_rgrpd *rgd, u64 block)
ret = gfs2_rbm_from_block(rbm, block);
WARN_ON_ONCE(ret != 0);
 
-   return gfs2_testbit(rgd, rbm.bi-bi_bh-b_data + rbm.bi-bi_offset,
-   rbm.bi-bi_len, rbm.offset);
+   return gfs2_testbit(rbm);
 }
 
 
@@ -1846,42 +1836,35 @@ static unsigned char gfs2_get_block_type(struct 
gfs2_rgrpd *rgd, u64 block)
  * gfs2_alloc_extent - allocate an extent from a given bitmap
  * @rbm: the resource group information
  * @dinode: TRUE if the first block we allocate is for a dinode
- * @n: The extent length
+ * @n: The extent length (value/result)
  *
- * Add the found bitmap buffer to the transaction.
+ * Add the bitmap buffer to the transaction.
  * Set the found bits to @new_state to change block's allocation state.
- * Returns: starting block number of the extent (fs scope)
  */
-static u64 gfs2_alloc_extent(const struct gfs2_rbm *rbm, bool dinode,
+static void gfs2_alloc_extent(const struct gfs2_rbm *rbm, bool dinode,
 unsigned int *n)
 {
-   struct gfs2_rgrpd *rgd = rbm-rgd;
-   struct gfs2_bitmap *bi = rbm-bi;
-   u32 blk = rbm-offset;
+   struct gfs2_rbm pos = { .rgd = rbm-rgd, };
const unsigned int elen = *n;
-   u32 goal;
-   const u8 *buffer = NULL;
+   u64 block;
+   int ret;
 
-   *n = 0;
-   buffer = bi-bi_bh-b_data + bi-bi_offset;
-   gfs2_trans_add_bh(rgd-rd_gl, bi-bi_bh, 1);
-   gfs2_setbit(rgd, bi-bi_clone, bi, blk,
+   *n = 1;
+   block = gfs2_rbm_to_block(rbm);
+   gfs2_trans_add_bh(rbm-rgd-rd_gl, rbm-bi-bi_bh, 1);
+   gfs2_setbit(rbm-rgd, rbm-bi-bi_clone, rbm-bi, rbm-offset,
dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
-   (*n)++;
-   goal = blk;
+   block++;
while (*n  elen) {
-   goal++;
-   if (goal = (bi-bi_len * GFS2_NBBY))
-   break;
-   if (gfs2_testbit(rgd, buffer, bi-bi_len, goal) !=
-   GFS2_BLKST_FREE)
+   ret = gfs2_rbm_from_block(pos, block);
+   WARN_ON(ret);
+   if (gfs2_testbit(pos) != GFS2_BLKST_FREE)
break;
-   gfs2_setbit(rgd, bi-bi_clone, bi, goal, GFS2_BLKST_USED);
+   gfs2_trans_add_bh(pos.rgd-rd_gl, pos.bi-bi_bh, 1);
+   gfs2_setbit(pos.rgd, pos.bi-bi_clone, pos.bi, pos.offset, 
GFS2_BLKST_USED);
(*n)++;
+   block++;
}
-   blk = gfs2_bi2rgd_blk(bi, blk);
-   rgd-rd_last_alloc = blk + *n - 1;
-   return rgd-rd_data0 + blk;
 }
 
 /**
@@ -2042,7 +2025,8 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, 
unsigned int *nblocks,
goto rgrp_error;
}
 
-   block = gfs2_alloc_extent(rbm, dinode, nblocks);
+   gfs2_alloc_extent(rbm, dinode, nblocks);
+   block = gfs2_rbm_to_block(rbm);
if (gfs2_rs_active(ip-i_res))
gfs2_adjust_reservation(ip, rbm, *nblocks);
ndata = *nblocks;
-- 
1.7.4





[Cluster-devel] [PATCH] qdiskd: backport dual socket connection to cman

2012-08-13 Thread Fabio M. Di Nitto
From: Fabio M. Di Nitto fdini...@redhat.com

Patch 76741bb2a94ae94e493c609d50f570d02e2f3029 had a not so obvious
dependency on 08ae3ce147b2771c5ee6e1d364a5e48c88384427.

Backport portion of 08ae3ce147b2771c5ee6e1d364a5e48c88384427 to handle
dual cman socket (admin and user) and use the correct socket (user)
for send/receive data.

Move cman_alive check and heartbeat (for dispatch) to ch_user.

Resolves: rhbz#782900

Signed-off-by: Fabio M. Di Nitto fdini...@redhat.com
---
 cman/qdisk/disk.h  |5 ++-
 cman/qdisk/disk_util.c |7 +++--
 cman/qdisk/iostate.c   |8 +++---
 cman/qdisk/main.c  |   69 ++-
 4 files changed, 43 insertions(+), 46 deletions(-)

diff --git a/cman/qdisk/disk.h b/cman/qdisk/disk.h
index d491de1..83167ea 100644
--- a/cman/qdisk/disk.h
+++ b/cman/qdisk/disk.h
@@ -270,7 +270,8 @@ typedef struct {
int qc_master;  /* Master?! */
int qc_status_sock;
run_flag_t qc_flags;
-   cman_handle_t qc_ch;
+   cman_handle_t qc_ch_admin;
+   cman_handle_t qc_ch_user;
char *qc_device;
char *qc_label;
char *qc_status_file;
@@ -299,7 +300,7 @@ typedef struct {
 int qd_write_status(qd_ctx *ctx, int nid, disk_node_state_t state,
disk_msg_t *msg, memb_mask_t mask, memb_mask_t master);
 int qd_read_print_status(target_info_t *disk, int nid);
-int qd_init(qd_ctx *ctx, cman_handle_t ch, int me);
+int qd_init(qd_ctx *ctx, cman_handle_t ch_admin, cman_handle_t ch_user, int 
me);
 void qd_destroy(qd_ctx *ctx);
 
 /* proc.c */
diff --git a/cman/qdisk/disk_util.c b/cman/qdisk/disk_util.c
index f5539c0..25f4013 100644
--- a/cman/qdisk/disk_util.c
+++ b/cman/qdisk/disk_util.c
@@ -312,16 +312,17 @@ generate_token(void)
   Initialize a quorum disk context, given a CMAN handle and a nodeid.
  */
 int
-qd_init(qd_ctx *ctx, cman_handle_t ch, int me)
+qd_init(qd_ctx *ctx, cman_handle_t ch_admin, cman_handle_t ch_user, int me)
 {
-   if (!ctx || !ch || !me) {
+   if (!ctx || !ch_admin || !ch_user || !me) {
errno = EINVAL;
return -1;
}   
 
memset(ctx, 0, sizeof(*ctx));
ctx-qc_incarnation = generate_token();
-   ctx-qc_ch = ch;
+   ctx-qc_ch_admin = ch_admin;
+   ctx-qc_ch_user = ch_user;
ctx-qc_my_id = me;
ctx-qc_status_sock = -1;
 
diff --git a/cman/qdisk/iostate.c b/cman/qdisk/iostate.c
index eb74ad2..ba7ad12 100644
--- a/cman/qdisk/iostate.c
+++ b/cman/qdisk/iostate.c
@@ -69,7 +69,7 @@ io_nanny_thread(void *arg)
iostate_t last_main_state = 0, current_main_state = 0;
int last_main_incarnation = 0, current_main_incarnation = 0;
int logged_incarnation = 0;
-   cman_handle_t ch = (cman_handle_t)arg;
+   cman_handle_t ch_user = (cman_handle_t)arg;
int32_t whine_state;
 
/* Start with wherever we're at now */
@@ -105,7 +105,7 @@ io_nanny_thread(void *arg)
/* Whine on CMAN api */
whine_state = (int32_t)current_main_state;
swab32(whine_state);
-   cman_send_data(ch, whine_state, sizeof(int32_t), 0, 
CLUSTER_PORT_QDISKD, 0);
+   cman_send_data(ch_user, whine_state, sizeof(int32_t), 0, 
CLUSTER_PORT_QDISKD, 0);
 
/* Don't log things twice */
if (logged_incarnation == current_main_incarnation)
@@ -125,7 +125,7 @@ io_nanny_thread(void *arg)
 
 
 int
-io_nanny_start(cman_handle_t ch, int timeout)
+io_nanny_start(cman_handle_t ch_user, int timeout)
 {
int ret;
 
@@ -135,7 +135,7 @@ io_nanny_start(cman_handle_t ch, int timeout)
qdisk_timeout = timeout;
thread_active = 1;
 
-   ret = pthread_create(io_nanny_tid, NULL, io_nanny_thread, ch);
+   ret = pthread_create(io_nanny_tid, NULL, io_nanny_thread, ch_user);
pthread_mutex_unlock(state_mutex);
 
return ret;
diff --git a/cman/qdisk/main.c b/cman/qdisk/main.c
index 90d00ab..72a3c07 100644
--- a/cman/qdisk/main.c
+++ b/cman/qdisk/main.c
@@ -287,7 +287,7 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, 
memb_mask_t mask)
if (ctx-qc_flags  RF_ALLOW_KILL) {
clulog(LOG_DEBUG, Telling CMAN to 
kill the node\n);
-   cman_kill_node(ctx-qc_ch,
+   cman_kill_node(ctx-qc_ch_admin,
ni[x].ni_status.ps_nodeid);
}
}
@@ -325,7 +325,7 @@ check_transitions(qd_ctx *ctx, node_info_t *ni, int max, 
memb_mask_t mask)
if (ctx-qc_flags  RF_ALLOW_KILL) {
clulog(LOG_DEBUG, Telling CMAN to 
kill the node\n);
-   cman_kill_node(ctx-qc_ch,
+ 

Re: [Cluster-devel] [PATCH] qdiskd: backport dual socket connection to cman

2012-08-13 Thread Lon Hohberger
On 08/13/2012 08:39 AM, Fabio M. Di Nitto wrote:
 From: Fabio M. Di Nitto fdini...@redhat.com
 
 Patch 76741bb2a94ae94e493c609d50f570d02e2f3029 had a not so obvious
 dependency on 08ae3ce147b2771c5ee6e1d364a5e48c88384427.
 
 Backport portion of 08ae3ce147b2771c5ee6e1d364a5e48c88384427 to handle
 dual cman socket (admin and user) and use the correct socket (user)
 for send/receive data.
 

That looks right.  The cman admin socket can't be used for
sending/receiving data, so the previous patch wouldn't work without it.

-- Lon