[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] [RFC LVM2] (3/6) Add _pv_allocate() (split from _pv_create)



In the patch "(6/6) Allow allocation from LV",
'struct physical_volume' will be allocated from function
other than _pv_create().

This patch splits the allocation/initialization part from
_pv_create().

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America
Move the PV allocation code in _pv_create() to a separate function

Index: LVM2.work/lib/metadata/metadata.c
===================================================================
--- LVM2.work.orig/lib/metadata/metadata.c
+++ LVM2.work/lib/metadata/metadata.c
@@ -708,6 +708,34 @@ pv_t *pv_create(const struct format_type
 			  pvmetadatasize, mdas);
 }
 
+static struct physical_volume *_pv_alloc(struct dm_pool *mem)
+{
+	struct physical_volume *pv = dm_pool_zalloc(mem, sizeof(*pv));
+
+	if (!pv) {
+		stack;
+		return NULL;
+	}
+
+	if (!(pv->vg_name = dm_pool_zalloc(mem, NAME_LEN))) {
+		dm_pool_free(mem, pv);
+		return NULL;
+	}
+
+	pv->pe_size = 0;
+	pv->pe_start = 0;
+	pv->pe_count = 0;
+	pv->pe_alloc_count = 0;
+	pv->fmt = NULL;
+
+	pv->status = ALLOCATABLE_PV;
+
+	list_init(&pv->tags);
+	list_init(&pv->segments);
+
+	return pv;
+}
+
 /* Sizes in sectors */
 static struct physical_volume *_pv_create(const struct format_type *fmt,
 				  struct device *dev,
@@ -719,7 +747,7 @@ static struct physical_volume *_pv_creat
 				  uint64_t pvmetadatasize, struct list *mdas)
 {
 	struct dm_pool *mem = fmt->cmd->mem;
-	struct physical_volume *pv = dm_pool_zalloc(mem, sizeof(*pv));
+	struct physical_volume *pv = _pv_alloc(mem);
 
 	if (!pv) {
 		stack;
@@ -731,16 +759,11 @@ static struct physical_volume *_pv_creat
 	else if (!id_create(&pv->id)) {
 		log_error("Failed to create random uuid for %s.",
 			  dev_name(dev));
-		return NULL;
+		goto bad;
 	}
 
 	pv->dev = dev;
 
-	if (!(pv->vg_name = dm_pool_zalloc(mem, NAME_LEN)))
-		goto_bad;
-
-	pv->status = ALLOCATABLE_PV;
-
 	if (!dev_get_size(pv->dev, &pv->size)) {
 		log_error("%s: Couldn't get size.", pv_dev_name(pv));
 		goto bad;
@@ -761,15 +784,8 @@ static struct physical_volume *_pv_creat
 		goto bad;
 	}
 
-	pv->pe_size = 0;
-	pv->pe_start = 0;
-	pv->pe_count = 0;
-	pv->pe_alloc_count = 0;
 	pv->fmt = fmt;
 
-	list_init(&pv->tags);
-	list_init(&pv->segments);
-
 	if (!fmt->ops->pv_setup(fmt, pe_start, existing_extent_count,
 				existing_extent_size,
 				pvmetadatacopies, pvmetadatasize, mdas,

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]