[sheepdog] [PATCH 1/2] sheep : add new strage type "tree"

Saeki Masaki saeki.masaki at po.ntts.co.jp
Mon Mar 16 07:54:30 CET 2015


On 2015/03/16 11:06, Liu Yuan wrote:
> On Thu, Mar 12, 2015 at 01:50:26PM +0900, Saeki Masaki wrote:
>> Current sheepdog stores whole objects in single directory like "/var/lib/sheepdog/obj"
>> This mechanism is difficult to handle massive files when increasing cluster volume.
>>
>> In particular, inode object having special informations about VDI,
>> so it is preferable to divide.
>>
>> new storage type named "tree"
>> It separates the inode object and data object.
>>
>> How to use ,
>> specify the --store option at the time format
>>
>> dog cluster format --store tree
>>
>> Signed-off-by: Masaki Saeki <saeki.masaki at po.ntts.co.jp>
>> ---
>>   sheep/Makefile.am  |    2 +-
>>   sheep/md.c         |   14 +
>>   sheep/sheep_priv.h |   13 +
>>   sheep/tree_store.c |  844 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>   4 files changed, 872 insertions(+), 1 deletions(-)
>>   create mode 100644 sheep/tree_store.c
>>
>> diff --git a/sheep/Makefile.am b/sheep/Makefile.am
>> index 7a08838..c6b7441 100644
>> --- a/sheep/Makefile.am
>> +++ b/sheep/Makefile.am
>> @@ -27,7 +27,7 @@ sbin_PROGRAMS		= sheep
>>   sheep_SOURCES		= sheep.c group.c request.c gateway.c store.c vdi.c \
>>   			  journal.c ops.c recovery.c cluster/local.c \
>>   			  object_cache.c object_list_cache.c \
>> -			  plain_store.c config.c migrate.c md.c
>> +			  plain_store.c tree_store.c config.c migrate.c md.c
>>
>>   if BUILD_HTTP
>>   sheep_SOURCES		+= http/http.c http/kv.c http/s3.c http/swift.c \
>> diff --git a/sheep/md.c b/sheep/md.c
>> index c00d7a5..7aca7c0 100644
>> --- a/sheep/md.c
>> +++ b/sheep/md.c
>> @@ -212,6 +212,20 @@ static int for_each_object_in_path(const char *path,
>>   		if (unlikely(!strncmp(d->d_name, ".", 1)))
>>   			continue;
>>
>> +		/* recursive call for tree store driver sub directories*/
>> +		if (check_store_name("tree")) {
>> +			struct stat s;
>> +
>> +			snprintf(file_name, sizeof(file_name),
>> +				 "%s/%s", path, d->d_name);
>> +			stat(file_name, &s);
>> +			if (S_ISDIR(s.st_mode)) {
>> +				ret = for_each_object_in_path(file_name,
>> +						func, cleanup, vinfo, arg);
>> +				continue;
>> +			}
>> +		}
>> +
>>   		sd_debug("%s, %s", path, d->d_name);
>>   		oid = strtoull(d->d_name, NULL, 16);
>>   		if (oid == 0 || oid == ULLONG_MAX)
>> diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
>> index 26afa89..3c3154d 100644
>> --- a/sheep/sheep_priv.h
>> +++ b/sheep/sheep_priv.h
>> @@ -269,6 +269,18 @@ int default_format(void);
>>   int default_remove_object(uint64_t oid, uint8_t ec_index);
>>   int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1);
>>   int default_purge_obj(void);
>> +int tree_init(void);
>> +bool tree_exist(uint64_t oid, uint8_t ec_index);
>> +int tree_create_and_write(uint64_t oid, const struct siocb *iocb);
>> +int tree_write(uint64_t oid, const struct siocb *iocb);
>> +int tree_read(uint64_t oid, const struct siocb *iocb);
>> +int tree_link(uint64_t oid, uint32_t tgt_epoch);
>> +int tree_update_epoch(uint32_t epoch);
>> +int tree_cleanup(void);
>> +int tree_format(void);
>> +int tree_remove_object(uint64_t oid, uint8_t ec_index);
>> +int tree_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1);
>> +int tree_purge_obj(void);
>>   int for_each_object_in_wd(int (*func)(uint64_t, const char *, uint32_t,
>>   				      uint8_t, struct vnode_info *, void *),
>>   			  bool, void *);
>> @@ -278,6 +290,7 @@ int for_each_object_in_stale(int (*func)(uint64_t oid, const char *path,
>>   			     void *arg);
>>   int for_each_obj_path(int (*func)(const char *path));
>>   size_t get_store_objsize(uint64_t oid);
>> +bool check_store_name(const char *name);
>>
>>   extern struct list_head store_drivers;
>>   #define add_store_driver(driver)				\
>> diff --git a/sheep/tree_store.c b/sheep/tree_store.c
>> new file mode 100644
>> index 0000000..7402f42
>> --- /dev/null
>> +++ b/sheep/tree_store.c
>> @@ -0,0 +1,844 @@
>> +/*
>> + * Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
>> + *
>> + * This program is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU General Public License version
>> + * 2 as published by the Free Software Foundation.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
>> + */
>> +
>> +#include <libgen.h>
>> +#include <linux/falloc.h>
>> +
>> +#include "sheep_priv.h"
>> +
>> +#ifndef FALLOC_FL_PUNCH_HOLE
>> +#define FALLOC_FL_PUNCH_HOLE 0x02
>> +#endif
>> +
>> +#define sector_algined(x) ({ ((x) & (SECTOR_SIZE - 1)) == 0; })
>> +
>> +static inline bool iocb_is_aligned(const struct siocb *iocb)
>> +{
>> +	return  sector_algined(iocb->offset) && sector_algined(iocb->length);
>> +}
>> +
>> +static int prepare_iocb(uint64_t oid, const struct siocb *iocb, bool create)
>> +{
>> +	int syncflag = create ? O_SYNC : O_DSYNC;
>> +	int flags = syncflag | O_RDWR;
>> +
>> +	if (uatomic_is_true(&sys->use_journal) || sys->nosync == true)
>> +		flags &= ~syncflag;
>> +
>> +	if (sys->backend_dio && iocb_is_aligned(iocb)) {
>> +		if (!is_aligned_to_pagesize(iocb->buf))
>> +			panic("Memory isn't aligned to pagesize %p", iocb->buf);
>> +		flags |= O_DIRECT;
>> +	}
>> +
>> +	if (create)
>> +		flags |= O_CREAT | O_EXCL;
>> +
>> +	return flags;
>> +}
>
> I think you need preparation patch to share these duplicated lines.

Thanks for your advice.
your pointed out may be iocb_is_aligned() and prepare_iocb() ?

Which is more preferable for preparation patch?
Create a new file or transfer the definition to an existing file "store.c"

In addition, I would like to make a new folder for store drivers.
ex.) "store/"

Regards, Saeki.
>
> Thanks,
> Yuan
>






More information about the sheepdog mailing list