From: Dave Wysochanski <dwysocha@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH 5/8] Add lvm_vg_get_property() generic vg property function.
Date: Thu, 21 Oct 2010 14:39:37 -0400 [thread overview]
Message-ID: <1287686377.5097.63.camel@f12-work> (raw)
In-Reply-To: <87sk008rcz.fsf@twilight.int.mornfall.net.>
On Wed, 2010-10-20 at 23:51 +0200, Petr Rockai wrote:
> Dave Wysochanski <dwysocha@redhat.com> writes:
>
> > + * This structure defines a single LVM property value for an LVM object.
> > + * The structures are returned by functions such as
> > + * lvm_vg_get_property() and lvm_vg_set_property().
> > + *
> > + * is_settable: indicates whether a 'set' function exists for this property
> > + * is_string: indicates whether this property is a string (1) or integer (0)
> > + * is_valid: indicates whether 'value' is valid (1) or not (0)
> > + */
> > +typedef struct lvm_property_value {
> > + unsigned is_settable:1;
> > + unsigned is_string:1;
> > + unsigned is_valid:1;
> > + union {
> > + const char *string;
> > + uint64_t integer;
> > + } value;
> > +} lvm_property_value_t;
>
> A is_integer might be useful here, for symmetry. In the client code, it
> might not be obvious that !p.is_string means that it is an integer. It
> would also improve API extensibility for the future, may we ever run
> into a property that's neither string nor integer (although it won't
> help with ABI).
>
Ok, I've implemented this - easy. But...
Now that I think about it, rather than a bitfield and 'is_string' and
'is_integer", should we have a 'type' field and leave this an unsigned
(for example, #define LVM_PROPERTY_TYPE_NUM 1 and #define
LVM_PROPERTY_TYPE STR 2) or at least should we add padding to this
struct? The struct might warrant a bit more thought, given how much
we've changed it recently, and given the ABI implications.
> > + }
> > + } else if (lv) {
> > + if (!lv_get_property(lv, &prop)) {
> > + v.is_valid = 0;
> > + return v;
> > + }
> > + }
> > + v.is_settable = prop.is_settable;
> > + v.is_string = prop.is_string;
> > + if (v.is_string)
> > + v.value.string = prop.value.string;
> > + else
> > + v.value.integer = prop.value.integer;
> > + v.is_valid = 1;
>
> Would it be more convenient to say v.is_valid = !lvm_errno(...) here?
> That way, the client code would not need to check lvm_errno unless it
> cared what went wrong. (The documentation above would need to be
> updated, too.)
>
As the code is, the client does not need to check lvm_errno() unless it
cares what went wrong. In essence, v.is_valid "should =" !lvm_errno()
today, though there's no explicit assignment. However, if we explicitly
assign v.is_valid = !lvm_errno(), then this assumes all error paths will
properly set lvm_errno(). Otherwise, we may end up telling the user the
value is valid when it may not be. Now this case is clearly a bug but
keeping them separate avoids the potential bug. It's fairly clear right
now that all error paths do properly set lvm_errno(), so this assignment
would be safe today.
I think I'm going to leave this one as is, though perhaps clarify the
comments. One of the near-term TODOs for lvm2app should probably be
take a look a the error paths anyway, and make any adjustments and/or
cleanups. Maybe you can tackle this specific item on that TODO, and
once further testing is in place.
next prev parent reply other threads:[~2010-10-21 18:39 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-19 11:32 [PATCH 00/08] Add lvm lv properties for lvm2app, return struct Dave Wysochanski
2010-10-19 11:32 ` [PATCH 1/8] Refactor and add code for (lv) 'lv_name' get function Dave Wysochanski
2010-10-20 21:31 ` Petr Rockai
2010-10-19 11:32 ` [PATCH 2/8] Refactor and add code for (lv) 'lv_origin' " Dave Wysochanski
2010-10-20 21:41 ` Petr Rockai
2010-10-21 14:38 ` Dave Wysochanski
2010-10-19 11:32 ` [PATCH 3/8] Add lv_read_ahead and lv_kernel_read_ahead 'get' functions Dave Wysochanski
2010-10-20 21:43 ` Petr Rockai
2010-10-19 11:32 ` [PATCH 4/8] Rename fields in lvm_property_type Dave Wysochanski
2010-10-20 21:45 ` Petr Rockai
2010-10-19 11:32 ` [PATCH 5/8] Add lvm_vg_get_property() generic vg property function Dave Wysochanski
2010-10-20 21:51 ` Petr Rockai
2010-10-21 18:39 ` Dave Wysochanski [this message]
2010-10-24 12:04 ` Petr Rockai
2010-10-25 13:55 ` Dave Wysochanski
2010-10-19 11:32 ` [PATCH 6/8] Add lvm_pv_get_property() generic function to obtain value of any pv property Dave Wysochanski
2010-10-20 21:54 ` Petr Rockai
2010-10-19 11:32 ` [PATCH 7/8] Add lvm_lv_get_property() generic function to obtain value of any lv property Dave Wysochanski
2010-10-20 21:55 ` Petr Rockai
2010-10-19 11:32 ` [PATCH 8/8] Add interactive tests for lvm_{pv|vg|lv}_get_property() Dave Wysochanski
2010-10-20 21:57 ` Petr Rockai
-- strict thread matches above, loose matches on Subject: below --
2010-10-19 4:02 [PATCH 00/08] Add lvm lv properties for lvm2app Dave Wysochanski
2010-10-19 4:02 ` [PATCH 5/8] Add lvm_vg_get_property() generic vg property function 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=1287686377.5097.63.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.