All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Wysochanski <dwysocha@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH 4/8] Add dm_pool_strdup to allocate memory and copy a tag in {lv|vg}_change_tag()
Date: Thu, 18 Feb 2010 07:17:31 -0500	[thread overview]
Message-ID: <1266495451.2497.8.camel@f10-node1> (raw)
In-Reply-To: <4B7D006A.9040109@redhat.com>

On Thu, 2010-02-18 at 09:55 +0100, Zdenek Kabelac wrote:
> On 17.2.2010 18:29, Dave Wysochanski wrote:
> > We need to allocate memory for the tag and copy the tag value before we
> > add it to the list of tags.  We could put this inside lvm2app since the
> > tools keep their memory around until vg_write/vg_commit is called, but
> > we put it inside the internal library to minimize code in lvm2app.
> > We need to copy the tag passed in by the caller to ensure the lifetime of
> > the memory until the {vg|lv} handle is released.
> > 
> > Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
> > ---
> >  lib/metadata/metadata.c |   14 ++++++++++++--
> >  1 files changed, 12 insertions(+), 2 deletions(-)
> > 
> > diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
> > index 2b8a1be..2667e90 100644
> > --- a/lib/metadata/metadata.c
> > +++ b/lib/metadata/metadata.c
> > @@ -667,6 +667,8 @@ int vg_reduce(struct volume_group *vg, char *pv_name)
> >  
> >  int lv_change_tag(struct logical_volume *lv, const char *tag, int add_tag)
> >  {
> > +	char *tag_new;
> > +
> >  	if (!(lv->vg->fid->fmt->features & FMT_TAGS)) {
> >  		log_error("Logical volume %s/%s does not support tags",
> >  			  lv->vg->name, lv->name);
> > @@ -674,7 +676,10 @@ int lv_change_tag(struct logical_volume *lv, const char *tag, int add_tag)
> >  	}
> >  
> >  	if (add_tag) {
> > -		if (!str_list_add(lv->vg->vgmem, &lv->tags, tag)) {
> > +		if (!(tag_new = dm_pool_strdup(lv->vg->vgmem, tag))) {
> > +			return_0;
> > +		}
> 
> just a tiny change here:
> 
> return_0;
> prints just backtrace - however dm_pool_strdup() doesn't report allocation
> failure message so a better way would be:
> 
> +log_error("tag duplication failed")
> +return 0;
> 
Ok.  Changed to:

-               if (!str_list_add(lv->vg->vgmem, &lv->tags, tag)) {
+               if (!(tag_new = dm_pool_strdup(lv->vg->vgmem, tag))) {
+                       log_error("Failed to duplicate tag %s from %s/%s",
+                                 tag, lv->vg->name, lv->name);
+                       return 0;
+               }


> To remain consistent with the rest of lvm code.
> 
> 
> Zdenek
> 
> --
> lvm-devel mailing list
> lvm-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/lvm-devel




      reply	other threads:[~2010-02-18 12:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-17 17:28 [PATCH 0/8] Add vg/lv tag addition/deletion to lvm2app, v2 Dave Wysochanski
2010-02-17 17:28 ` [PATCH 1/8] Refactor _vgchange_tag() to vg_change_tag() library function Dave Wysochanski
2010-02-17 17:28   ` [PATCH 2/8] Refactor vgcreate to call new vg_change_tag() function Dave Wysochanski
2010-02-17 17:28     ` [PATCH 3/8] Refactor lvchange_tag() to call lv_change_tag() library function Dave Wysochanski
2010-02-17 17:29       ` [PATCH 4/8] Add dm_pool_strdup to allocate memory and copy a tag in {lv|vg}_change_tag() Dave Wysochanski
2010-02-17 17:29         ` [PATCH 5/8] Add tag_list_copy() supporting function inside lvm2app Dave Wysochanski
2010-02-17 17:29           ` [PATCH 6/8] Add lvm_vg_get_tags(), lvm_vg_add_tag(), and lvm_vg_remove_tag() Dave Wysochanski
2010-02-17 17:29             ` [PATCH 7/8] Add lvm_lv_get_tags(), lvm_lv_add_tag(), and lvm_lv_remove_tag() Dave Wysochanski
2010-02-17 17:29               ` [PATCH 8/8] Update lvm2app interactive unit test for vg/lv tags Dave Wysochanski
2010-02-23 19:30                 ` [PATCH 0/4] Cleanup lvm2app.h doxygen documentation and add example Dave Wysochanski
2010-02-23 19:30                   ` [PATCH 1/4] Update doxygen comments for lvm2app.h Dave Wysochanski
2010-02-23 19:30                     ` [PATCH 2/4] Add Doxygen file for lvm2app to generate documentation from lvm2app.h Dave Wysochanski
2010-02-23 19:30                       ` [PATCH 3/4] Add an example to the lvm2app.h code, which is also part of the unit testing Dave Wysochanski
2010-02-23 19:30                         ` [PATCH 4/4] Add lvm_list_all.c to lvm2app nightly tests Dave Wysochanski
2010-02-18  9:05             ` [PATCH 6/8] Add lvm_vg_get_tags(), lvm_vg_add_tag(), and lvm_vg_remove_tag() Zdenek Kabelac
2010-02-23 15:07               ` [PATCH] RFC: move str_list inside lvm2app.h, include lvm2app.h inside lvm-types.h Dave Wysochanski
2010-02-23 18:21               ` [PATCH 6/8] Add lvm_vg_get_tags(), lvm_vg_add_tag(), and lvm_vg_remove_tag() Dave Wysochanski
2010-02-18  8:55         ` [PATCH 4/8] Add dm_pool_strdup to allocate memory and copy a tag in {lv|vg}_change_tag() Zdenek Kabelac
2010-02-18 12:17           ` Dave Wysochanski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1266495451.2497.8.camel@f10-node1 \
    --to=dwysocha@redhat.com \
    --cc=lvm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.