[sheepdog] [PATCH] dog/vdi: stop preallocation for no share option in vdi cloning

Ruoyu liangry at ucweb.com
Tue May 27 08:45:27 CEST 2014


Previous patch add a -n (--no-share) option in dog vdi clone.
Preallocation is also enabled by this option. However, it is
unnecessary to preallocate data object. In fact, we only need to
copy parent's data objects into its own.

This patch fix this problem to carry out thin-provision.

Signed-off-by: Ruoyu <liangry at ucweb.com>
---
 dog/vdi.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/dog/vdi.c b/dog/vdi.c
index a8491c3..3daec21 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -23,8 +23,7 @@
 
 static struct sd_option vdi_options[] = {
 	{'P', "prealloc", false, "preallocate all the data objects"},
-	{'n', "no-share", false, "share nothing with its parent, "
-				"prealloc also enabled"},
+	{'n', "no-share", false, "share nothing with its parent"},
 	{'i', "index", true, "specify the index of data objects"},
 	{'s', "snapshot", true, "specify a snapshot id or tag name"},
 	{'x', "exclusive", false, "write in an exclusive mode"},
@@ -575,7 +574,8 @@ static int vdi_clone(int argc, char **argv)
 	ret = do_vdi_create(dst_vdi, inode->vdi_size, base_vid, &new_vid, false,
 			    inode->nr_copies, inode->copy_policy,
 			    inode->store_policy);
-	if (ret != EXIT_SUCCESS || !vdi_cmd_data.prealloc)
+	if (ret != EXIT_SUCCESS ||
+			(!vdi_cmd_data.prealloc && !vdi_cmd_data.no_share))
 		goto out;
 
 	new_inode = xmalloc(sizeof(*inode));
@@ -601,8 +601,11 @@ static int vdi_clone(int argc, char **argv)
 				goto out;
 			}
 			size = SD_DATA_OBJ_SIZE;
-		} else
+		} else {
+			if (vdi_cmd_data.no_share)
+				continue;
 			size = 0;
+		}
 
 		oid = vid_to_data_oid(new_vid, idx);
 		ret = dog_write_object(oid, 0, buf, size, 0, 0,
@@ -2424,7 +2427,6 @@ static int vdi_parser(int ch, const char *opt)
 		break;
 	case 'n':
 		vdi_cmd_data.no_share = true;
-		vdi_cmd_data.prealloc = true;
 		break;
 	case 'i':
 		vdi_cmd_data.index = strtol(opt, &p, 10);
-- 
1.8.3.2





More information about the sheepdog mailing list