[sheepdog] [PATCH 3/3] dog: add a new option to specify the vid space

2015-02-01 Thread Takafumi Fujieda
This patch adds a new option -s bits to dog cluster format to
specify the VID space size.
dog cluster info -v shows the specified VID space size.

Signed-off-by: Takafumi Fujieda fujieda.takaf...@lab.ntt.co.jp
---
 dog/cluster.c |   28 +++-
 1 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/dog/cluster.c b/dog/cluster.c
index d4a45ec..97c5b3b 100644
--- a/dog/cluster.c
+++ b/dog/cluster.c
@@ -24,6 +24,7 @@ static struct sd_option cluster_options[] = {
{'f', force, false, do not prompt for confirmation},
{'m', multithread, false,
 use multi-thread for 'cluster snapshot save'},
+   {'s', vid_space, true, specify the VID space size},
{'t', strict, false,
 do not serve write request if number of nodes is not sufficient},
{'z', block_size_shift, true, specify the shift num of default
@@ -96,6 +97,10 @@ static int cluster_format(int argc, char **argv)
uint32_t old_nr_vdis;
unsigned long *vdi_inuse = NULL;
size_t bmp_size;
+   if (!cluster_cmd_data.vid_space)
+   new_space = SD_VID_SPACE;
+   else
+   new_space = (uint8_t)cluster_cmd_data.vid_space;
 
rb_for_each_entry(n, sd_nroot, rb) {
struct sd_req info_req;
@@ -177,6 +182,7 @@ static int cluster_format(int argc, char **argv)
hdr.cluster.copies = cluster_cmd_data.copies;
hdr.cluster.copy_policy = cluster_cmd_data.copy_policy;
hdr.cluster.block_size_shift = cluster_cmd_data.block_size_shift;
+   hdr.cluster.vid_space = new_space;
hdr.cluster.ctime = (uint64_t) tv.tv_sec  32 | tv.tv_usec * 1000;
 
if (strlen(cluster_cmd_data.name))
@@ -281,6 +287,12 @@ retry:
printf(%s\n, sd_strerror(rsp-result));
 
if (verbose) {
+   /* show cluster vid space size */
+   if (logs-vid_space) {
+   if (!raw_output)
+   printf(Cluster VID space size: );
+   printf(%d\n, logs-vid_space);
+   }
/* show cluster backend store */
if (!raw_output)
printf(Cluster store: );
@@ -841,7 +853,7 @@ failure:
 static struct subcommand cluster_cmd[] = {
{info, NULL, aprhvT, show cluster information,
 NULL, CMD_NEED_NODELIST, cluster_info, cluster_options},
-   {format, NULL, bctaphzTV, create a Sheepdog store,
+   {format, NULL, bctaphzsTV, create a Sheepdog store,
 NULL, CMD_NEED_NODELIST, cluster_format, cluster_options},
{shutdown, NULL, aphT, stop Sheepdog,
 NULL, 0, cluster_shutdown, cluster_options},
@@ -865,6 +877,7 @@ static struct subcommand cluster_cmd[] = {
 static int cluster_parser(int ch, const char *opt)
 {
uint32_t block_size_shift;
+   uint32_t vid_space;
switch (ch) {
case 'b':
pstrcpy(cluster_cmd_data.name, sizeof(cluster_cmd_data.name),
@@ -889,6 +902,19 @@ static int cluster_parser(int ch, const char *opt)
break;
case 'm':
cluster_cmd_data.multithread = true;
+   case 's':
+   vid_space = (uint32_t)atoi(opt);
+   if (vid_space  26) {
+   sd_err(VID space size is limited to 26 bits.
+Please set VID space size lower than 26);
+   exit(EXIT_FAILURE);
+   } else if (vid_space  24) {
+   sd_err(VID space size is larger than 24 bits.
+Please set VID space size larger than 24);
+   exit(EXIT_FAILURE);
+   }
+   cluster_cmd_data.vid_space = vid_space;
+   break;
case 't':
cluster_cmd_data.strict = true;
break;
-- 
1.7.1

-- 
sheepdog mailing list
sheepdog@lists.wpkg.org
https://lists.wpkg.org/mailman/listinfo/sheepdog


[sheepdog] [PATCH 1/3] sheep, dog: add vid space variables to the structs

2015-02-01 Thread Takafumi Fujieda
This patch adds new variables to some structs (cluster_info,
system_info, etc...) to store the vid space size.

Signed-off-by: Takafumi Fujieda fujieda.takaf...@lab.ntt.co.jp
---
 dog/cluster.c|1 +
 dog/farm/farm.h  |3 ++-
 include/internal_proto.h |6 --
 include/sheepdog_proto.h |   10 ++
 sheep/config.c   |4 +++-
 sheep/sheep_priv.h   |2 ++
 6 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/dog/cluster.c b/dog/cluster.c
index 6a2db6e..2b6864a 100644
--- a/dog/cluster.c
+++ b/dog/cluster.c
@@ -37,6 +37,7 @@ static struct cluster_cmd_data {
uint8_t copy_policy;
uint8_t multithread;
uint8_t block_size_shift;
+   uint8_t vid_space;
bool force;
bool strict;
char name[STORE_LEN];
diff --git a/dog/farm/farm.h b/dog/farm/farm.h
index 6b96c5e..ca25e6f 100644
--- a/dog/farm/farm.h
+++ b/dog/farm/farm.h
@@ -41,7 +41,8 @@ struct snap_log_hdr {
uint8_t copy_number;
uint8_t copy_policy;
uint8_t block_size_shift;
-   uint8_t reserved[21];
+   uint8_t vid_space;
+   uint8_t reserved[20];
 };
 
 struct snap_log {
diff --git a/include/internal_proto.h b/include/internal_proto.h
index 6b24b5c..6637568 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -219,7 +219,8 @@ struct cluster_info {
uint8_t copy_policy;
enum sd_status status : 8;
uint8_t block_size_shift;
-   uint8_t __pad[3];
+   uint8_t vid_space;
+   uint8_t __pad[2];
uint8_t store[STORE_LEN];
 
/* Node list at cluster_info-epoch */
@@ -234,7 +235,8 @@ struct epoch_log {
uint8_t  disable_recovery;
uint8_t  nr_copies;
uint8_t  copy_policy;
-   uint8_t  __pad[3];
+   uint8_t  vid_space;
+   uint8_t  __pad[2];
uint16_t flags;
char drv_name[STORE_LEN];
struct sd_node nodes[0];
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index bf3e9df..5db2394 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -101,6 +101,7 @@
  * 60 - 63 ( 4 bits): object type identifier space
  */
 
+#define SD_VID_SPACE 24
 #define VDI_SPACE_SHIFT   32
 #define SD_VDI_MASK 0x00FF
 #define VDI_BIT (UINT64_C(1)  63)
@@ -115,7 +116,7 @@
 #define SD_MAX_VDI_ATTR_KEY_LEN 256U
 #define SD_MAX_VDI_ATTR_VALUE_LEN 65536U
 #define SD_MAX_SNAPSHOT_TAG_LEN 256U
-#define SD_NR_VDIS   (1U  24)
+#define SD_NR_VDIS   (1U  SD_VID_SPACE)
 #define SD_DATA_OBJ_SIZE (UINT64_C(1)  22)
 #define SD_OLD_MAX_VDI_SIZE (SD_DATA_OBJ_SIZE * OLD_MAX_DATA_OBJS)
 #define SD_MAX_VDI_SIZE (SD_DATA_OBJ_SIZE * MAX_DATA_OBJS)
@@ -180,7 +181,8 @@ struct sd_req {
uint32_ttag;
uint32_tnodes_nr;
uint8_t block_size_shift;
-   uint8_t reserved[3];
+   uint8_t vid_space;
+   uint8_t reserved[2];
} cluster;
struct {
uint32_told_vid;
@@ -258,11 +260,11 @@ struct sd_rsp {
uint8_t digest[20];
} hash;
struct {
-   uint32_t__pad1;
+   uint32_t__pad;
uint8_t nr_copies;
uint8_t copy_policy;
uint8_t block_size_shift;
-   uint8_t __pad2;
+   uint8_t vid_space;
} cluster_default;
 
uint32_t__pad[8];
diff --git a/sheep/config.c b/sheep/config.c
index 9518109..548a1e8 100644
--- a/sheep/config.c
+++ b/sheep/config.c
@@ -12,7 +12,7 @@
 #include sheep_priv.h
 
 #define SD_FORMAT_VERSION 0x0006
-#define SD_CONFIG_SIZE 40
+#define SD_CONFIG_SIZE 48
 
 static struct sheepdog_config {
uint64_t ctime;
@@ -24,6 +24,8 @@ static struct sheepdog_config {
uint8_t block_size_shift;
uint16_t version;
uint64_t space;
+   uint8_t vid_space;
+   uint8_t _pad[7];
 } config;
 
 char *config_path;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 3399a36..5608cbc 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -130,6 +130,8 @@ struct system_info {
 
uint64_t disk_space;
 
+   uint32_t nr_vdis;
+   uint64_t vdi_mask;
DECLARE_BITMAP(vdi_inuse, SD_NR_VDIS);
DECLARE_BITMAP(vdi_deleted, SD_NR_VDIS);
 
-- 
1.7.1

-- 
sheepdog mailing list
sheepdog@lists.wpkg.org
https://lists.wpkg.org/mailman/listinfo/sheepdog


[sheepdog] [PATCH 2/3] sheep, dog: make vid space size variable

2015-02-01 Thread Takafumi Fujieda
This patch changes vid space size from constant to variable.
The vid space size value is assigned to the variables (member of
cluster_info and system_info) only at cluster_make_fs or reloading
config file.
Not the constants, but the variables are always refered.

Signed-off-by: Takafumi Fujieda fujieda.takaf...@lab.ntt.co.jp
---
 dog/cluster.c |   38 +++---
 dog/common.c  |   32 +---
 dog/dog.h |3 ++-
 dog/farm/farm.c   |   16 +++-
 dog/node.c|3 ++-
 dog/vdi.c |   22 +++---
 include/sheepdog_proto.h  |8 
 sheep/config.c|   16 +++-
 sheep/gateway.c   |   23 +--
 sheep/group.c |   10 --
 sheep/journal.c   |3 ++-
 sheep/nfs/fs.c|4 ++--
 sheep/nfs/nfs.c   |4 ++--
 sheep/object_cache.c  |   13 +++--
 sheep/object_list_cache.c |2 +-
 sheep/ops.c   |   35 ---
 sheep/plain_store.c   |   25 +++--
 sheep/recovery.c  |   10 ++
 sheep/request.c   |3 ++-
 sheep/sheep_priv.h|4 ++--
 sheep/vdi.c   |   43 ++-
 sheepfs/volume.c  |2 +-
 22 files changed, 224 insertions(+), 95 deletions(-)

diff --git a/dog/cluster.c b/dog/cluster.c
index 2b6864a..d4a45ec 100644
--- a/dog/cluster.c
+++ b/dog/cluster.c
@@ -71,9 +71,9 @@ static int list_store(void)
return EXIT_SYSFAIL;
 }
 
-static bool no_vdi(const unsigned long *vdis)
+static bool no_vdi(const unsigned long *vdis, uint32_t nr_vdis)
 {
-   return find_next_bit(vdis, SD_NR_VDIS, 0) == SD_NR_VDIS;
+   return find_next_bit(vdis, nr_vdis, 0) == nr_vdis;
 }
 
 #define FORMAT_PRINT   \
@@ -90,8 +90,12 @@ static int cluster_format(int argc, char **argv)
struct sd_rsp *rsp = (struct sd_rsp *)hdr;
struct timeval tv;
char store_name[STORE_LEN];
-   static DECLARE_BITMAP(vdi_inuse, SD_NR_VDIS);
struct sd_node *n;
+   uint8_t new_space = 0;
+   uint8_t old_space = 0;
+   uint32_t old_nr_vdis;
+   unsigned long *vdi_inuse = NULL;
+   size_t bmp_size;
 
rb_for_each_entry(n, sd_nroot, rb) {
struct sd_req info_req;
@@ -110,6 +114,17 @@ static int cluster_format(int argc, char **argv)
return EXIT_FAILURE;
}
 
+   if (!old_space)
+   if (!cinfo.vid_space)
+   old_space = SD_VID_SPACE;
+   else
+   old_space = cinfo.vid_space;
+   else
+   if (cinfo.vid_space  old_space != cinfo.vid_space) {
+   sd_err(there are nodes have different VID 
space);
+   return EXIT_FAILURE;
+   }
+
if (n-nr_vnodes != 0) {
if ((cinfo.flags  SD_CLUSTER_FLAG_AUTO_VNODES)
 cluster_cmd_data.fixed_vnodes) {
@@ -136,19 +151,25 @@ static int cluster_format(int argc, char **argv)
confirm(info);
}
 
+   old_nr_vdis = (1U  old_space);
+   bmp_size = sizeof(unsigned long) * BITS_TO_LONGS(old_nr_vdis);
+   vdi_inuse = (unsigned long *)malloc(bmp_size);
+
sd_init_req(hdr, SD_OP_READ_VDIS);
-   hdr.data_length = sizeof(vdi_inuse);
+   hdr.data_length = bmp_size;
 
ret = dog_exec_req(sd_nid, hdr, vdi_inuse);
if (ret  0)
return EXIT_SYSFAIL;
if (rsp-result != SD_RES_SUCCESS) {
sd_err(%s, sd_strerror(rsp-result));
+   free(vdi_inuse);
return EXIT_FAILURE;
}
 
-   if (!no_vdi(vdi_inuse))
+   if (!no_vdi(vdi_inuse, old_nr_vdis))
confirm(FORMAT_PRINT);
+   free(vdi_inuse);
 
gettimeofday(tv, NULL);
 
@@ -401,7 +422,8 @@ static void fill_cb(struct sd_index *idx, void *arg, int 
ignore)
 
 static void fill_object_tree(uint32_t vid, const char *name, const char *tag,
 uint32_t snapid, uint32_t flags,
-const struct sd_inode *i, void *data)
+const struct sd_inode *i, void *data,
+uint32_t nr_vdis)
 {
uint64_t vdi_oid = vid_to_vdi_oid(vid), vmstate_oid;
uint32_t vdi_id;
@@ -548,6 +570,7 @@ static int load_snapshot(int argc, char **argv)
cluster_cmd_data.copies = hdr.copy_number;
cluster_cmd_data.copy_policy = hdr.copy_policy;
cluster_cmd_data.block_size_shift = hdr.block_size_shift;
+   cluster_cmd_data.vid_space = hdr.vid_space;
if (cluster_format(0, NULL) != SD_RES_SUCCESS

[sheepdog] [PATCH 0/3] sheep, dog: configurable vid space

2015-02-01 Thread Takafumi Fujieda
Current, deleted vids are not reused, without cutting relations.
If snapshots of many online vdis in a cluster are created continuously,
the vid space will be exhausted.

These patches make vid space size configurable from 24 bits to 26 bits
by using the reserved bits in the oid.
A new option -s bits is added to dog cluster format for specify the vid 
space size.
(The default vid space size is 24 bits)

These patches don't care compatibility of object files and cluster snapshot data
created under different vid spaces.
If you want to change your cluster's vid space keeping existing vdis,
the cluster must be shutdowned and all vdis should be outputted
by using qemu-img and dog vdi backup.

Takafumi Fujieda (3):
  sheep, dog: add vid space variables to the structs
  sheep, dog: make vid space size variable
  dog: add a new option to specify the vid space

 dog/cluster.c |   67 +++-
 dog/common.c  |   32 +-
 dog/dog.h |3 +-
 dog/farm/farm.c   |   16 ++-
 dog/farm/farm.h   |3 +-
 dog/node.c|3 +-
 dog/vdi.c |   22 ++-
 include/internal_proto.h  |6 +++-
 include/sheepdog_proto.h  |   18 +++-
 sheep/config.c|   20 -
 sheep/gateway.c   |   23 +---
 sheep/group.c |   10 +-
 sheep/journal.c   |3 +-
 sheep/nfs/fs.c|4 +-
 sheep/nfs/nfs.c   |4 +-
 sheep/object_cache.c  |   13 +
 sheep/object_list_cache.c |2 +-
 sheep/ops.c   |   35 +++-
 sheep/plain_store.c   |   25 ++---
 sheep/recovery.c  |   10 ---
 sheep/request.c   |3 +-
 sheep/sheep_priv.h|6 +++-
 sheep/vdi.c   |   43 +---
 sheepfs/volume.c  |2 +-
 24 files changed, 269 insertions(+), 104 deletions(-)

-- 
sheepdog mailing list
sheepdog@lists.wpkg.org
https://lists.wpkg.org/mailman/listinfo/sheepdog