[Sheepdog] [PATCH v2] sheep: fix get_nr_copies()
Liu Yuan
namei.unix at gmail.com
Mon Apr 30 18:45:43 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
We should never return anything greater than sys->nr_copies.
- use min() to get the better readability
- change this function into 'static inline'
- change sys->nr_copies as 'int' to stay in line with nr_zones
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
V2:
- use min() as Christoph suggests
- make it inline
sheep/group.c | 19 -------------------
sheep/sheep_priv.h | 19 ++++++++++++++++---
2 files changed, 16 insertions(+), 22 deletions(-)
diff --git a/sheep/group.c b/sheep/group.c
index ea02602..24e6b15 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -32,13 +32,6 @@ struct node {
struct list_head list;
};
-struct vnode_info {
- struct sd_vnode entries[SD_MAX_VNODES];
- int nr_vnodes;
- int nr_zones;
- int refcnt;
-};
-
struct join_message {
uint8_t proto_ver;
uint8_t nr_copies;
@@ -197,18 +190,6 @@ static int update_vnode_info(void)
return 0;
}
-/*
- * If we have less zones available than the desired redundancy we have to do
- * with nr_zones copies, sorry.
- */
-int get_nr_copies(struct vnode_info *vnode_info)
-{
- int nr_copies = vnode_info->nr_zones;
- if (nr_copies < sys->nr_copies)
- nr_copies = sys->nr_copies;
- return nr_copies;
-}
-
static void do_cluster_op(void *arg)
{
struct vdi_op_message *msg = arg;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index afd5c1b..bdaed8d 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -63,7 +63,12 @@ struct client_info {
};
struct request;
-struct vnode_info;
+struct vnode_info {
+ struct sd_vnode entries[SD_MAX_VNODES];
+ int nr_vnodes;
+ int nr_zones;
+ int refcnt;
+};
typedef void (*req_end_t) (struct request *);
@@ -136,7 +141,7 @@ struct cluster_info {
struct list_head consistent_obj_list;
struct list_head blocking_conn_list;
- uint32_t nr_copies;
+ int nr_copies;
struct list_head request_queue;
struct list_head event_queue;
@@ -212,6 +217,15 @@ extern char *obj_path;
extern mode_t def_fmode;
extern mode_t def_dmode;
+/*
+ * If we have less zones available than the desired redundancy we have to do
+ * with nr_zones copies, sorry.
+ */
+static inline int get_nr_copies(struct vnode_info *vnode_info)
+{
+ return min(vnode_info->nr_zones, sys->nr_copies);
+}
+
int create_listen_port(int port, void *data);
int init_store(const char *dir);
@@ -239,7 +253,6 @@ void put_vnode_info(struct vnode_info *vnodes);
struct sd_vnode *oid_to_vnode(struct vnode_info *vnode_info, uint64_t oid,
int copy_idx);
-int get_nr_copies(struct vnode_info *vnode_info);
int is_access_to_busy_objects(uint64_t oid);
--
1.7.8.2
More information about the sheepdog
mailing list