[sheepdog] [PATCH v3 2/9] sheep: introduce ledger objects

Hitoshi Mitake mitake.hitoshi at gmail.com
Thu Feb 27 13:21:06 CET 2014


At Thu, 27 Feb 2014 17:53:11 +0800,
Liu Yuan wrote:
> 
> On Sun, Feb 23, 2014 at 02:28:21PM +0900, Hitoshi Mitake wrote:
> > This introduces ledger objects, which keeps track of the number of
> > outstanding references of each generation.  Sheep decrements a
> > generational reference count with a gateway request SD_OP_DECREF_OBJ,
> > and reclaims objects when there is no generational reference.
> > 
> > Cc: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
> > Cc: Valerio Pachera <sirio81 at gmail.com>
> > Cc: Alessandro Bolgia <alessandro at extensys.it>
> > Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
> > ---
> >  include/internal_proto.h |  2 ++
> >  include/sheepdog_proto.h | 28 ++++++++++++++-
> >  sheep/gateway.c          |  5 +++
> >  sheep/ops.c              | 90 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  sheep/sheep_priv.h       |  5 +++
> >  sheep/store.c            | 25 ++++++++++++++
> >  6 files changed, 154 insertions(+), 1 deletion(-)
> > 
> > diff --git a/include/internal_proto.h b/include/internal_proto.h
> > index 460264c..8582817 100644
> > --- a/include/internal_proto.h
> > +++ b/include/internal_proto.h
> > @@ -99,6 +99,8 @@
> >  #define SD_OP_SET_LOGLEVEL	0xBA
> >  #define SD_OP_NFS_CREATE	0xBB
> >  #define SD_OP_NFS_DELETE	0xBC
> > +#define SD_OP_DECREF_OBJ     0xBD
> > +#define SD_OP_DECREF_PEER    0xBE
> >  
> >  /* internal flags for hdr.flags, must be above 0x80 */
> >  #define SD_FLAG_CMD_RECOVERY 0x0080
> > diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
> > index 39d57aa..a1db359 100644
> > --- a/include/sheepdog_proto.h
> > +++ b/include/sheepdog_proto.h
> > @@ -92,6 +92,7 @@
> >  #define VMSTATE_BIT (UINT64_C(1) << 62)
> >  #define VDI_ATTR_BIT (UINT64_C(1) << 61)
> >  #define VDI_BTREE_BIT (UINT64_C(1) << 60)
> > +#define LEDGER_BIT (UINT64_C(1) << 59)
> >  #define OLD_MAX_DATA_OBJS (1ULL << 20)
> >  #define MAX_DATA_OBJS (1ULL << 32)
> >  #define MAX_CHILDREN 1024U
> > @@ -111,6 +112,7 @@
> >  #define SD_INODE_DATA_INDEX_SIZE (sizeof(uint32_t) * SD_INODE_DATA_INDEX)
> >  #define SD_INODE_HEADER_SIZE offsetof(struct sd_inode, data_vdi_id)
> >  #define SD_ATTR_OBJ_SIZE (sizeof(struct sheepdog_vdi_attr))
> > +#define SD_LEDGER_OBJ_SIZE (UINT64_C(1) << 22)
> >  #define CURRENT_VDI_ID 0
> >  
> >  #define STORE_LEN 16
> > @@ -164,6 +166,11 @@ struct sd_req {
> >  						    /* others mean true */
> >  			uint8_t		copy_policy;
> >  		} vdi_state;
> > +		struct {
> > +			uint64_t	oid;
> > +			uint32_t	generation;
> > +			uint32_t	count;
> > +		} ref;
> >  
> >  		uint32_t		__pad[8];
> >  	};
> > @@ -401,10 +408,16 @@ static inline bool is_vdi_btree_obj(uint64_t oid)
> >  	return !!(oid & VDI_BTREE_BIT);
> >  }
> >  
> > +static inline bool is_ledger_object(uint64_t oid)
> > +{
> > +	return !!(oid & LEDGER_BIT);
> > +}
> > +
> >  static inline bool is_data_obj(uint64_t oid)
> >  {
> >  	return !is_vdi_obj(oid) && !is_vmstate_obj(oid) &&
> > -		!is_vdi_attr_obj(oid) && !is_vdi_btree_obj(oid);
> > +		!is_vdi_attr_obj(oid) && !is_vdi_btree_obj(oid) &&
> > +		!is_ledger_object(oid);
> >  }
> >  
> >  static inline size_t count_data_objs(const struct sd_inode *inode)
> > @@ -423,6 +436,9 @@ static inline size_t get_objsize(uint64_t oid)
> >  	if (is_vdi_btree_obj(oid))
> >  		return SD_INODE_DATA_INDEX_SIZE;
> >  
> > +	if (is_ledger_object(oid))
> > +		return SD_LEDGER_OBJ_SIZE;
> > +
> >  	return SD_DATA_OBJ_SIZE;
> >  }
> >  
> > @@ -473,4 +489,14 @@ static inline __attribute__((used)) void __sd_proto_build_bug_ons(void)
> >  	BUILD_BUG_ON(sizeof(struct sd_rsp) != SD_RSP_SIZE);
> >  }
> >  
> > +static inline uint64_t ledger_oid_to_data_oid(uint64_t oid)
> > +{
> > +	return ~LEDGER_BIT & oid;
> > +}
> > +
> > +static inline uint64_t data_oid_to_ledger_oid(uint64_t oid)
> > +{
> > +	return LEDGER_BIT | oid;
> > +}
> > +
> >  #endif
> > diff --git a/sheep/gateway.c b/sheep/gateway.c
> > index f0f716a..bfd3912 100644
> > --- a/sheep/gateway.c
> > +++ b/sheep/gateway.c
> > @@ -648,3 +648,8 @@ int gateway_remove_obj(struct request *req)
> >  {
> >  	return gateway_forward_request(req);
> >  }
> > +
> > +int gateway_decref_object(struct request *req)
> > +{
> > +	return gateway_forward_request(req);
> > +}
> > diff --git a/sheep/ops.c b/sheep/ops.c
> > index cc70c8c..660c021 100644
> > --- a/sheep/ops.c
> > +++ b/sheep/ops.c
> > @@ -1037,6 +1037,83 @@ static inline int local_nfs_delete(struct request *req)
> >  
> >  #endif
> >  
> > +int peer_decref_object(struct request *req)
> > +{
> > +	struct sd_req *hdr = &req->rq;
> > +	int ret;
> > +	uint32_t epoch = hdr->epoch;
> > +	uint64_t ledger_oid = hdr->ref.oid;
> > +	uint64_t data_oid = ledger_oid_to_data_oid(ledger_oid);
> > +	uint32_t generation = hdr->ref.generation;
> > +	uint32_t count = hdr->ref.count;
> > +	uint32_t *ledger = NULL, *zero = xzalloc(SD_LEDGER_OBJ_SIZE);
> > +	bool exist = false, locked = false;
> > +	static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
> 
> use sd_mutex please

Thanks for your pointing, I'll fix it in v5.

Thanks,
Hitoshi



More information about the sheepdog mailing list