Skip to contentSkip to conversation

lvm2app: Add thin and thin pool lv creation V2

PATCH New Tony Asleson 3 participants 6 messages May 3, 2013 – May 6, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lvm2app: Add thin and thin pool lv creation V2

From: "M. Mohan Kumar" <[email protected]>

Add thin and thin pool lv creation support to lvm library

This is Mohan's patch, re-worked to include suggestions from Zdenek.

V2: Remove const lvm_lv_params_create_thin
Add const lvm_lv_params_skip_zero_get

---
 liblvm/lvm2app.h | 116 +++++++++++++++++++++++++++++++
 liblvm/lvm_lv.c  | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 321 insertions(+)
liblvm/lvm2app.h +116 -0
index 93a78c3..0a00425 100644
@@ -97,6 +97,7 @@ struct volume_group;
 struct logical_volume;
 struct lv_segment;
 struct pv_segment;
+struct lvm_lv_create_params;
 
 /**
  * \class lvm_t
@@ -153,6 +154,14 @@ typedef struct lv_segment *lvseg_t;
 typedef struct pv_segment *pvseg_t;
 
 /**
+ * \class lv_create_params
+ *
+ * This lv_create_params represents the plethora of available options when
+ * creating a logical volume
+ */
+typedef struct lvm_lv_create_params *lv_create_params_t;
+
+/**
  * Logical Volume object list.
  *
  * Lists of these structures are returned by lvm_vg_list_lvs().
@@ -1400,6 +1409,113 @@ int lvm_lv_resize(const lv_t lv, uint64_t new_size);
  */
 lv_t lvm_lv_snapshot(const lv_t lv, const char *snap_name, uint64_t max_snap_size);
 
+/**
+ * Thin provisioning discard policies
+ */
+typedef enum {
+	LVM_THIN_DISCARDS_IGNORE,
+	LVM_THIN_DISCARDS_NO_PASSDOWN,
+	LVM_THIN_DISCARDS_PASSDOWN,
+} lvm_thin_discards_t;
+
+/**
+ * Create a thinpool parameter passing object for the specified VG
+ *
+ * \param   vg
+ * Volume Group handle.
+ *
+ * \param   pool_name
+ * Name of the pool.
+ *
+ * \param   size
+ * size of the pool
+ *
+ * \param   chunk_size
+ * data block size of the pool
+ * Default value is DEFAULT_THIN_POOL_CHUNK_SIZE * 2 when 0 passed as chunk_size
+ * DM_THIN_MIN_DATA_BLOCK_SIZE < chunk_size < DM_THIN_MAX_DATA_BLOCK_SIZE
+ *
+ * \param meta_size
+ * Size of thin pool's metadata logical volume. Allowed range is 2MB-16GB.
+ * Default value (ie if 0) pool size / pool chunk size * 64
+ *
+ * \param discard
+ * Thin discard policy
+ * Note: THIN_DISCARDS_PASSDOWN is the default.
+ *
+ * \return
+ * Valid lv_create_params pointer on success, else NULL on error.
+ * Note: Memory is associated with the vg, it will get reclaimed when vg is
+ * closed.
+ *
+ */
+lv_create_params_t lvm_lv_params_create_thin_pool(vg_t vg,
+		const char *pool_name, uint64_t size, uint32_t chunk_size,
+		uint64_t meta_size, lvm_thin_discards_t discard);
+
+#define lvm_lv_params_create_thin_pool_default(vg, pool_name, size) \
+			lvm_lv_params_create_thin_pool((vg), (pool_name), (size), 0, 0, \
+			LVM_THIN_DISCARDS_PASSDOWN)
+
+
+/**
+ * Set the value of zero skip for the lv_create_params
+ *
+ * \param params
+ * lv_create_prams to change
+ *
+ * \param skip
+ * Value of skip zero to be set (0 == zero, 1 == skip zero)
+ *
+ * \return
+ * 0 on success, else -1
+ */
+int lvm_lv_params_skip_zero_set(lv_create_params_t params, int skip);
+
+/**
+ * Get the value of zero skip for the lv_create_params
+ *
+ * \param params
+ * lv_create_prams to query
+ *
+ * \return
+ * -1 on error, else 0 == zero, 1 == skip zero
+ */
+int lvm_lv_params_skip_zero_get(const lv_create_params_t params);
+
+/**
+ * Create a thin LV creation parameters in a given VG & thin pool
+ *
+ * \param   vg
+ * Volume Group handle.
+ *
+ * \param   pool_name
+ * Name of the pool.
+ *
+ * \param lvname
+ * Name of the LV to create
+ *
+ * \param   size
+ * Size of logical volume
+ *
+ * \return
+ * Valid lv_create_params pointer on success, else NULL on error.
+ * Note: Memory is associated with the vg, it will get reclaimed when vg is
+ * closed.
+ *
+ */
+lv_create_params_t lvm_lv_params_create_thin(const vg_t vg, const char *pool_name,
+									const char *lvname, uint64_t size);
+/**
+ * Create the actual logical volume.
+ *
+ * \param	params		The parameters object for lv creation
+ *
+ * \return
+ * Valid lv pointer on success, else NULL on error.
+ */
+lv_t lvm_lv_create(lv_create_params_t params);
+
 /************************** physical volume handling ************************/
 
 /**
liblvm/lvm_lv.c +205 -0

214 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 1/1 lvm2app: Add thin and thin pool lv creation V2

Quoted 14 lines · Tony Asleson

+ *
+ */

liblvm/lvm2app.h +12 -0
+lv_create_params_t lvm_lv_params_create_thin_pool(vg_t vg,
+		const char *pool_name, uint64_t size, uint32_t chunk_size,
+		uint64_t meta_size, lvm_thin_discards_t discard);
+
+#define lvm_lv_params_create_thin_pool_default(vg, pool_name, size) \
+			lvm_lv_params_create_thin_pool((vg), (pool_name), (size), 0, 0, \
+			LVM_THIN_DISCARDS_PASSDOWN)
+
+
+/**
+ * Set the value of zero skip for the lv_create_params
+ *

liblvm/lvm2app.h int lvm_lv_resize(const lv_t lv, uint64_t new_size); · line 1473

Quoted 10 lines
liblvm/lvm2app.h +10 -0
+ * \param params
+ * lv_create_prams to change
+ *
+ * \param skip
+ * Value of skip zero to be set (0 == zero, 1 == skip zero)
+ *
+ * \return
+ * 0 on success, else -1
+ */
+int lvm_lv_params_skip_zero_set(lv_create_params_t params, int skip);

Are we going to provide as many helper functions to get/set parameters in lv_create_params structure? For example if an user does wants a new LV to be created in deactivation state, should we provide a helper something like this?

int lvm_lv_params_activation_set(lv_create_params_t params, int activate);

In this case lvm-api wont be flooded with lots of helper functions? Instead of individual helper function how about a common helper function to take care of this?

int lvm_lv_params_set(lv_create_params_t params, enum lv_create_param_type,

                      type, void *data);

lvm_lv_params_set function will validate 'data' based on the lv_create_param_type and will return error if 'data' does not match given enum (resource)?

enum lv_create_param_type {
     LV_CR_INVALID,
     LV_CR_ZERO,
     LV_CR_ACTIVATION,

     LV_CR_MAX_PARAM,
};

In above zero case, this function will be invoked like this:

lvm_lv_params_set(params, LV_CR_ZERO, &zero);

lvm_lv_params_set will do:

                  switch (type) {
                  case LV_CR_ZERO:
                     memcpy (&zero_skip, data, sizeof(int));
                     break;
                  case LV_CR_ACTIVATION:
                       memcpy (&activation, data, sizeof(int));
                       if (activation < CHANGE_AY && activation >
                          CHANGE_AAY) {
                          log_error();
                          return -1;
                       }
                  }
#2 lore raw

PATCH 1/1 lvm2app: Add thin and thin pool lv creation V2

Quoted 59 lines · M. Mohan Kumar
Quoted 14 lines · Tony Asleson

+ *
+ */

liblvm/lvm2app.h +12 -0
+lv_create_params_t lvm_lv_params_create_thin_pool(vg_t vg,
+		const char *pool_name, uint64_t size, uint32_t chunk_size,
+		uint64_t meta_size, lvm_thin_discards_t discard);
+
+#define lvm_lv_params_create_thin_pool_default(vg, pool_name, size) \
+			lvm_lv_params_create_thin_pool((vg), (pool_name), (size), 0, 0, \
+			LVM_THIN_DISCARDS_PASSDOWN)
+
+
+/**
+ * Set the value of zero skip for the lv_create_params
+ *

liblvm/lvm2app.h int lvm_lv_resize(const lv_t lv, uint64_t new_size); · line 1473

Quoted 10 lines
liblvm/lvm2app.h +10 -0
+ * \param params
+ * lv_create_prams to change
+ *
+ * \param skip
+ * Value of skip zero to be set (0 == zero, 1 == skip zero)
+ *
+ * \return
+ * 0 on success, else -1
+ */
+int lvm_lv_params_skip_zero_set(lv_create_params_t params, int skip);

Are we going to provide as many helper functions to get/set parameters in lv_create_params structure? For example if an user does wants a new LV to be created in deactivation state, should we provide a helper something like this?

int lvm_lv_params_activation_set(lv_create_params_t params, int activate);

In this case lvm-api wont be flooded with lots of helper functions? Instead of individual helper function how about a common helper function to take care of this?

int lvm_lv_params_set(lv_create_params_t params, enum lv_create_param_type,

                      type, void *data);

lvm_lv_params_set function will validate 'data' based on the lv_create_param_type and will return error if 'data' does not match given enum (resource)?

enum lv_create_param_type {
     LV_CR_INVALID,
     LV_CR_ZERO,
     LV_CR_ACTIVATION,

     LV_CR_MAX_PARAM,
};

In above zero case, this function will be invoked like this:

lvm_lv_params_set(params, LV_CR_ZERO, &zero);

lvm_lv_params_set will do:

Quoted 14 lines
                  switch (type) {
                  case LV_CR_ZERO:
                     memcpy (&zero_skip, data, sizeof(int));
                     break;
                  case LV_CR_ACTIVATION:
                       memcpy (&activation, data, sizeof(int));
                       if (activation < CHANGE_AY && activation >
                          CHANGE_AAY) {
                          log_error();
                          return -1;
                       }
                  }

Yeah, this is probably a better approach to minimize API explosion. The only thing I would like to add is a size_t data_len field. This way we can accommodate variable size data for same operation.

Does that sound reasonable? I guess if we only support simple fixed type sizes it would be redundant.

Thanks,
Tony

#3 lore raw

PATCH 1/1 lvm2app: Add thin and thin pool lv creation V2

Dne 6.5.2013 17:37, Tony Asleson napsal(a):

Quoted 75 lines · M. Mohan Kumar
Quoted 59 lines
Quoted 14 lines · Tony Asleson

+ *
+ */

liblvm/lvm2app.h +12 -0
+lv_create_params_t lvm_lv_params_create_thin_pool(vg_t vg,
+		const char *pool_name, uint64_t size, uint32_t chunk_size,
+		uint64_t meta_size, lvm_thin_discards_t discard);
+
+#define lvm_lv_params_create_thin_pool_default(vg, pool_name, size) \
+			lvm_lv_params_create_thin_pool((vg), (pool_name), (size), 0, 0, \
+			LVM_THIN_DISCARDS_PASSDOWN)
+
+
+/**
+ * Set the value of zero skip for the lv_create_params
+ *

liblvm/lvm2app.h int lvm_lv_resize(const lv_t lv, uint64_t new_size); · line 1473

Quoted 10 lines
liblvm/lvm2app.h +10 -0
+ * \param params
+ * lv_create_prams to change
+ *
+ * \param skip
+ * Value of skip zero to be set (0 == zero, 1 == skip zero)
+ *
+ * \return
+ * 0 on success, else -1
+ */
+int lvm_lv_params_skip_zero_set(lv_create_params_t params, int skip);

Are we going to provide as many helper functions to get/set parameters in lv_create_params structure? For example if an user does wants a new LV to be created in deactivation state, should we provide a helper something like this?

int lvm_lv_params_activation_set(lv_create_params_t params, int activate);

In this case lvm-api wont be flooded with lots of helper functions? Instead of individual helper function how about a common helper function to take care of this?

int lvm_lv_params_set(lv_create_params_t params, enum lv_create_param_type,

                       type, void *data);

lvm_lv_params_set function will validate 'data' based on the lv_create_param_type and will return error if 'data' does not match given enum (resource)?

enum lv_create_param_type {
      LV_CR_INVALID,
      LV_CR_ZERO,
      LV_CR_ACTIVATION,

      LV_CR_MAX_PARAM,
};

In above zero case, this function will be invoked like this:

lvm_lv_params_set(params, LV_CR_ZERO, &zero);

lvm_lv_params_set will do:

Quoted 14 lines
                   switch (type) {
                   case LV_CR_ZERO:
                      memcpy (&zero_skip, data, sizeof(int));
                      break;
                   case LV_CR_ACTIVATION:
                        memcpy (&activation, data, sizeof(int));
                        if (activation < CHANGE_AY && activation >
                           CHANGE_AAY) {
                           log_error();
                           return -1;
                        }
                   }
Quoted 6 lines

Yeah, this is probably a better approach to minimize API explosion. The only thing I would like to add is a size_t data_len field. This way we can accommodate variable size data for same operation.

Does that sound reasonable? I guess if we only support simple fixed type sizes it would be redundant.

We already have the API 'explosion' for lvs/pvs/vgs properties. So I think it could probably share the same principal for lvcreate attrs.

I liked the 'X protocol' way of using string named fields - but then you lose compile time check whether you pass valid arguments...

Zdenek

#4 lore raw

PATCH 1/1 lvm2app: Add thin and thin pool lv creation V2

Quoted 2 lines · Zdenek Kabelac

We already have the API 'explosion' for lvs/pvs/vgs properties. So I think it could probably share the same principal for lvcreate attrs.

For API consistency we probably should use the same technique for get/set proprieties like we do in other parts of the API, for some reason when you mentioned more C++ like I went with a separate get/set functions. I've mentioned before that I don't like returning structures by value because there is a potential link issues if the library and client code compiled with different options:
-fpcc-struct-return/-freg-struct-return.

Quoted 2 lines

I liked the 'X protocol' way of using string named fields - but then you lose compile time check whether you pass valid arguments...

We are going to lose compile time enforcement regardless if we want generic get/set functionality.

Regards,
Tony

#5 lore raw

PATCH 1/1 lvm2app: Add thin and thin pool lv creation V2

In reply to Tony Asleson
Quoted 75 lines · Tony Asleson
Quoted 59 lines · M. Mohan Kumar
Quoted 14 lines · Tony Asleson

+ *
+ */

liblvm/lvm2app.h +12 -0
+lv_create_params_t lvm_lv_params_create_thin_pool(vg_t vg,
+		const char *pool_name, uint64_t size, uint32_t chunk_size,
+		uint64_t meta_size, lvm_thin_discards_t discard);
+
+#define lvm_lv_params_create_thin_pool_default(vg, pool_name, size) \
+			lvm_lv_params_create_thin_pool((vg), (pool_name), (size), 0, 0, \
+			LVM_THIN_DISCARDS_PASSDOWN)
+
+
+/**
+ * Set the value of zero skip for the lv_create_params
+ *

liblvm/lvm2app.h int lvm_lv_resize(const lv_t lv, uint64_t new_size); · line 1473

Quoted 10 lines
liblvm/lvm2app.h +10 -0
+ * \param params
+ * lv_create_prams to change
+ *
+ * \param skip
+ * Value of skip zero to be set (0 == zero, 1 == skip zero)
+ *
+ * \return
+ * 0 on success, else -1
+ */
+int lvm_lv_params_skip_zero_set(lv_create_params_t params, int skip);

Are we going to provide as many helper functions to get/set parameters in lv_create_params structure? For example if an user does wants a new LV to be created in deactivation state, should we provide a helper something like this?

int lvm_lv_params_activation_set(lv_create_params_t params, int activate);

In this case lvm-api wont be flooded with lots of helper functions? Instead of individual helper function how about a common helper function to take care of this?

int lvm_lv_params_set(lv_create_params_t params, enum lv_create_param_type,

                      type, void *data);

lvm_lv_params_set function will validate 'data' based on the lv_create_param_type and will return error if 'data' does not match given enum (resource)?

enum lv_create_param_type {
     LV_CR_INVALID,
     LV_CR_ZERO,
     LV_CR_ACTIVATION,

     LV_CR_MAX_PARAM,
};

In above zero case, this function will be invoked like this:

lvm_lv_params_set(params, LV_CR_ZERO, &zero);

lvm_lv_params_set will do:

Quoted 14 lines
                  switch (type) {
                  case LV_CR_ZERO:
                     memcpy (&zero_skip, data, sizeof(int));
                     break;
                  case LV_CR_ACTIVATION:
                       memcpy (&activation, data, sizeof(int));
                       if (activation < CHANGE_AY && activation >
                          CHANGE_AAY) {
                          log_error();
                          return -1;
                       }
                  }
Quoted 7 lines

Yeah, this is probably a better approach to minimize API explosion. The only thing I would like to add is a size_t data_len field. This way we can accommodate variable size data for same operation.

Does that sound reasonable? I guess if we only support simple fixed type sizes it would be redundant.

+1