All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Wysochanski <dwysocha@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH 02/14] Refactor and add code for (lv) 'lv_path' get function.
Date: Tue, 12 Oct 2010 10:29:59 -0400	[thread overview]
Message-ID: <1286893799.15299.13.camel@f12-work> (raw)
In-Reply-To: <87tyks38l1.fsf@twilight.int.mornfall.net.>

On Mon, 2010-10-11 at 20:09 +0200, Petr Rockai wrote:
> Dave Wysochanski <dwysocha@redhat.com> writes:
> 
> > Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
> Reviewed-By: Petr Rockai <prockai@redhat.com>
> 
> (But! See inline comments below. It would make sense to have another go
> at this one.)
> 

Ok.


> > +
> > +char *lv_path_dup(struct dm_pool *mem, const struct logical_volume *lv)
> > +{
> > +	char *repstr;
> > +	size_t len;
> > +
> > +	len = strlen(lv->vg->cmd->dev_dir);
> > +	len += strlen(lv->vg->name) + strlen(lv->name) + 2;
> Can you just make that a single size_t len = foo + bar + ...; line? That
> would make it clear there are no side effects involved...
> 

done.


> > +	if (!(repstr = dm_pool_zalloc(mem, len))) {
> > +		log_error("dm_pool_alloc failed");
> > +		return 0;
> > +	}
> > +
> > +	if (dm_snprintf(repstr, len, "%s%s/%s",
> > +			lv->vg->cmd->dev_dir, lv->vg->name, lv->name) < 0) {
> > +		log_error("lvpath snprintf failed");
> > +		return 0;
> > +	}
> ^^ Should the above dm_pool_zalloc/dm_snprintf go into some
> dm_pool_asprintf, in fact? That would also remove that "len" computation
> and make this function completely trivial. We already have dm_asprintf
> (which uses dm_malloc). You could probably parametrise dm_asprintf with
> the strdup function into dm_generic_asprintf and have both dm_asprintf
> and dm_pool_asprintf implemented in terms of that.
> 
> > +	return repstr;
> > +}
> 
> Also, the log_error bits aren't that spectacular... Could you make them
> a bit clearer, or even omit them? The caller has to check the result and
> error out anyway...
> 

If it's ok with you, I may defer these to a couple cleanup patches.
They are good suggestions but I'm mostly focused on straight moving and
refactoring for this patch set.

There's probably other places in the code that could benefit from such a
dm_pool_asprintf.  So when that is proposed as a patch, all code should
get cleaned up.

The error paths in the attribute and lvm2app code need a cleanup pass -
for example some places I'm using log_errno(ENOMEM, ....), others it
seems we're just doing return_NULL, and still others is this method.

I've placed these two items into the bz for now:
https://bugzilla.redhat.com/show_bug.cgi?id=614049





  reply	other threads:[~2010-10-12 14:29 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-11 15:14 [PATCH 00/14] Add lvm lv properties and lvm2app interfaces for pv/vg/lv Dave Wysochanski
2010-10-11 15:14 ` [PATCH 01/14] Add some lv 'get' functions that require no refactoring Dave Wysochanski
2010-10-11 18:00   ` Petr Rockai
2010-10-11 15:14 ` [PATCH 02/14] Refactor and add code for (lv) 'lv_path' get function Dave Wysochanski
2010-10-11 18:09   ` Petr Rockai
2010-10-12 14:29     ` Dave Wysochanski [this message]
2010-10-12 15:52       ` Petr Rockai
2010-10-11 15:14 ` [PATCH 03/14] Refactor and add code for (lv) 'origin_size' " Dave Wysochanski
2010-10-11 18:13   ` Petr Rockai
2010-10-12 14:22     ` Dave Wysochanski
2010-10-11 15:14 ` [PATCH 04/14] Refactor and add code for (lv) 'move_pv' " Dave Wysochanski
2010-10-11 18:21   ` Petr Rockai
2010-10-12 14:52     ` Dave Wysochanski
2010-10-11 15:14 ` [PATCH 05/14] Refactor and add code for (lv) 'convert_lv' " Dave Wysochanski
2010-10-11 18:25   ` Petr Rockai
2010-10-12 15:14     ` Dave Wysochanski
2010-10-12 15:55       ` Petr Rockai
2010-10-12 16:09         ` Dave Wysochanski
2010-10-11 15:14 ` [PATCH 06/14] Refactor and add code for (lv) 'lv_kernel_{major|minor}' get functions Dave Wysochanski
2010-10-11 18:27   ` Petr Rockai
2010-10-11 15:14 ` [PATCH 07/14] Refactor and add code for (lv) 'mirror_log' get function Dave Wysochanski
2010-10-11 18:29   ` Petr Rockai
2010-10-12 15:28     ` Dave Wysochanski
2010-10-11 15:14 ` [PATCH 08/14] Refactor and add code for (lv) 'modules' " Dave Wysochanski
2010-10-11 15:14 ` [PATCH 09/14] Refactor and add code for (lv) 'lv_name' " Dave Wysochanski
2010-10-11 18:36   ` Petr Rockai
2010-10-12 15:43     ` Dave Wysochanski
2010-10-11 15:14 ` [PATCH 10/14] Refactor and add code for (lv) 'lv_origin' " Dave Wysochanski
2010-10-11 15:14 ` [PATCH 11/14] Add lvm_vg_get_property() generic vg property function Dave Wysochanski
2010-10-12  8:40   ` Zdenek Kabelac
2010-10-12 10:51     ` Petr Rockai
2010-10-12 11:05     ` Petr Rockai
2010-10-15 14:18       ` Dave Wysochanski
2010-10-12 11:04   ` Petr Rockai
2010-10-11 15:14 ` [PATCH 12/14] Add lvm_pv_get_property() generic function to obtain value of any pv property Dave Wysochanski
2010-10-11 15:14 ` [PATCH 13/14] Add lvm_lv_get_property() generic function to obtain value of any lv property Dave Wysochanski
2010-10-11 15:14 ` [PATCH 14/14] Add interactive tests for lvm_{pv|vg|lv}_get_property() Dave Wysochanski

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=1286893799.15299.13.camel@f12-work \
    --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.