Skip to contentSkip to conversation

lvm2app: Add function to retrieve the origin.

PATCH New Tony Asleson 2 participants 5 messages Apr 11, 2013 – Apr 12, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lvm2app: Add function to retrieve the origin.

---
 liblvm/lvm2app.h | 16 ++++++++++++++++
 liblvm/lvm_lv.c  |  5 +++++
 2 files changed, 21 insertions(+)
liblvm/lvm2app.h +16 -0
index 15827ac..369c300 100644
@@ -1223,6 +1223,22 @@ const char *lvm_lv_get_name(const lv_t lv);
 const char *lvm_lv_get_attr(const lv_t lv);
 
 /**
+ * Get the origin of a snapshot.
+ *
+ * \memberof lv_t
+ *
+ * The memory allocated for the name is tied to the vg_t handle and will be
+ * released when lvm_vg_close() is called.
+ *
+ * \param   lv
+ * Logical volume handle.
+ *
+ * \return
+ * Null if the logical volume is not a snapshot, else origin name.
+ */
+const char *lvm_lv_get_origin(const lv_t lv);
+
+/**
  * Get the current size in bytes of a logical volume.
  *
  * \memberof lv_t
liblvm/lvm_lv.c +5 -0
index 9d3ae79..f244a60 100644
@@ -53,6 +53,11 @@ const char *lvm_lv_get_attr(const lv_t lv)
 	return lv_attr_dup(lv->vg->vgmem, lv);
 }
 
+const char *lvm_lv_get_origin(const lv_t lv)
+{
+	return lv_origin_dup(lv->vg->vgmem, lv);
+}
+
 struct lvm_property_value lvm_lv_get_property(const lv_t lv, const char *name)
 {
 	return get_property(NULL, NULL, lv, NULL, NULL, name);
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 2/2 python-lvm: Added lv method getOrigin

---
 python/liblvm.c | 9 +++++++++
 1 file changed, 9 insertions(+)
python/liblvm.c +9 -0
index 96e94d4..09892ca 100644
@@ -1202,6 +1202,14 @@ liblvm_lvm_lv_get_attr(lvobject *self)
 }
 
 static PyObject *
+liblvm_lvm_lv_get_origin(lvobject *self)
+{
+	LV_VALID(self);
+
+	return Py_BuildValue("s", lvm_lv_get_origin(self->lv));
+}
+
+static PyObject *
 liblvm_lvm_lv_get_name(lvobject *self)
 {
 	LV_VALID(self);
@@ -1758,6 +1766,7 @@ static PyMethodDef liblvm_lv_methods[] = {
 	/* lv methods */
 	{ "getAttr",		(PyCFunction)liblvm_lvm_lv_get_attr, METH_NOARGS },
 	{ "getName",		(PyCFunction)liblvm_lvm_lv_get_name, METH_NOARGS },
+	{ "getOrigin",		(PyCFunction)liblvm_lvm_lv_get_origin, METH_NOARGS },
 	{ "getUuid",		(PyCFunction)liblvm_lvm_lv_get_uuid, METH_NOARGS },
 	{ "activate",		(PyCFunction)liblvm_lvm_lv_activate, METH_NOARGS },
 	{ "deactivate",		(PyCFunction)liblvm_lvm_lv_deactivate, METH_NOARGS },
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 1/2 lvm2app: Add function to retrieve the origin.

In reply to Tony Asleson

Dne 11.4.2013 22:58, Tony Asleson napsal(a):

Quoted 38 lines
---
  liblvm/lvm2app.h | 16 ++++++++++++++++
  liblvm/lvm_lv.c  |  5 +++++
  2 files changed, 21 insertions(+)
liblvm/lvm2app.h +16 -0
index 15827ac..369c300 100644
@@ -1223,6 +1223,22 @@ const char *lvm_lv_get_name(const lv_t lv);
  const char *lvm_lv_get_attr(const lv_t lv);
 
  /**
+ * Get the origin of a snapshot.
+ *
+ * \memberof lv_t
+ *
+ * The memory allocated for the name is tied to the vg_t handle and will be
+ * released when lvm_vg_close() is called.
+ *
+ * \param   lv
+ * Logical volume handle.
+ *
+ * \return
+ * Null if the logical volume is not a snapshot, else origin name.
+ */
+const char *lvm_lv_get_origin(const lv_t lv);
+
+/**
   * Get the current size in bytes of a logical volume.
   *
   * \memberof lv_t
liblvm/lvm_lv.c +0 -0
index 9d3ae79..f244a60 100644

liblvm/lvm_lv.c const char *lvm_lv_get_attr(const lv_t lv) · line 60

Quoted 8 lines
liblvm/lvm_lv.c +5 -0
@@ -53,6 +53,11 @@ const char *lvm_lv_get_attr(const lv_t lv)
  	return lv_attr_dup(lv->vg->vgmem, lv);
  }
 
+const char *lvm_lv_get_origin(const lv_t lv)
+{
+	return lv_origin_dup(lv->vg->vgmem, lv);
+}
+

If you need just 'const' pointer - it would be probably better, to directly return the name - instead of duplication.

i.e. lv_origin_dup() -> rewrite to 'const char *lv_get_origin(.)' -> and use it for lv_name_dup() in lv_origin_dup() which returns char *. as well as for lvm_lv_get_origin().

liblvm/lvm_lv.c const char *lvm_lv_get_attr(const lv_t lv) · line 63

Quoted 4 lines
liblvm/lvm_lv.c +0 -0
  struct lvm_property_value lvm_lv_get_property(const lv_t lv, const char *name)
  {
  	return get_property(NULL, NULL, lv, NULL, NULL, name);

Zdenek

#3 lore raw

PATCH 1/2 lvm2app: Add function to retrieve the origin.

Quoted 2 lines · Zdenek Kabelac

If you need just 'const' pointer - it would be probably better, to directly return the name - instead of duplication.

Agreed.

Quoted 3 lines

i.e. lv_origin_dup() -> rewrite to 'const char *lv_get_origin(.)' -> and use it for lv_name_dup() in lv_origin_dup() which returns char *. as well as for lvm_lv_get_origin().

I ran into at least 2 different implementations of *get_origin. There is lv_origin_dup() and _origin_disp. Both utilize the same logic with slightly different output. I haven't looked around it see if there are others.

To clean this up correctly I would want to write what you are suggesting and then use it in all the different places.

There is quite a bit of code that could certainly benefit from decoupling the generation/manipulation of the data from the presentation of it.

I've added this to a todo list.

Regards,
Tony

#4 lore raw

PATCH 1/2 lvm2app: Add function to retrieve the origin.

Dne 12.4.2013 17:44, Tony Asleson napsal(a):

Quoted 10 lines · Zdenek Kabelac
Quoted 2 lines

If you need just 'const' pointer - it would be probably better, to directly return the name - instead of duplication.

Agreed.

Quoted 3 lines

i.e. lv_origin_dup() -> rewrite to 'const char *lv_get_origin(.)' -> and use it for lv_name_dup() in lv_origin_dup() which returns char *. as well as for lvm_lv_get_origin().

Quoted 8 lines

I ran into at least 2 different implementations of *get_origin. There is lv_origin_dup() and _origin_disp. Both utilize the same logic with slightly different output. I haven't looked around it see if there are others.

To clean this up correctly I would want to write what you are suggesting and then use it in all the different places.

Yep, that would be very useful - since we already do a tons of useless string duplication - we should try to avoid a new set of those ;)

There are many more places, where we could be happy with just const reference, since the lifetime of object is clearly defined and parent object cannot be removed/changed, so there is no benefit of using duplicate copies.

Regards

Zdenek