From: Alex Elder <elder@ieee.org>
To: Ilya Dryomov <ilya.dryomov@inktank.com>, ceph-devel@vger.kernel.org
Subject: Re: [PATCH 1/8] rbd: show the entire chain of parent images
Date: Thu, 24 Jul 2014 07:31:40 -0500 [thread overview]
Message-ID: <53D0FCAC.3030801@ieee.org> (raw)
In-Reply-To: <1406191369-6746-2-git-send-email-ilya.dryomov@inktank.com>
On 07/24/2014 03:42 AM, Ilya Dryomov wrote:
> Make /sys/bus/rbd/devices/<id>/parent show the entire chain of parent
> images. While at it, kernel sprintf() doesn't return negative values,
> casting to unsigned long long is no longer necessary and there is no
> good reason to split into multiple sprintf() calls.
I like the use of a single snprintf() call, it is much less
cumbersome.
The reason I always cast u64 values to (unsigned long long)
in printf() calls is because on some 64-bit architectures,
u64 is defined as simply (unsigned long), so without the
cast they spit out warnings. I hate this, but it is reality
(see include/asm-generic/{int-l64.h,int-ll64.h}). You can
alternatively use %PRIu64 rather than %llu in your format
strings, but I think I hate that more. Anyway, if you want
to avoid warnings on all architectures you should fix that.
As another aside, I've been too timid to use the ?: conditional
expression without its middle operand. I have no objection
to it at all, I like it. I bring it up because I recently
got burned for using a gcc feature that wasn't supported
on older compilers (unnamed struct/union fields)--specifically
a version newer than gcc 3.2, which is the minimum supported
version for the kernel (see Documentation/Changes).
But fear not! That extension is supported in gcc 3.2:
https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Conditionals.html#Conditionals
Just FYI...
Reviewed-by: Alex Elder <elder@linaro.org>
> Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
> ---
> Documentation/ABI/testing/sysfs-bus-rbd | 4 +--
> drivers/block/rbd.c | 56 +++++++++++++------------------
> 2 files changed, 25 insertions(+), 35 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-rbd b/Documentation/ABI/testing/sysfs-bus-rbd
> index 501adc2a9ec7..2ddd680929d8 100644
> --- a/Documentation/ABI/testing/sysfs-bus-rbd
> +++ b/Documentation/ABI/testing/sysfs-bus-rbd
> @@ -94,5 +94,5 @@ current_snap
>
> parent
>
> - Information identifying the pool, image, and snapshot id for
> - the parent image in a layered rbd image (format 2 only).
> + Information identifying the chain of parent images in a layered rbd
> + image. Entries are separated by empty lines.
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 703b728e05fa..7847fbb949ff 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -3685,46 +3685,36 @@ static ssize_t rbd_snap_show(struct device *dev,
> }
>
> /*
> - * For an rbd v2 image, shows the pool id, image id, and snapshot id
> - * for the parent image. If there is no parent, simply shows
> - * "(no parent image)".
> + * For a v2 image, shows the chain of parent images, separated by empty
> + * lines. For v1 images or if there is no parent, shows "(no parent
> + * image)".
> */
> static ssize_t rbd_parent_show(struct device *dev,
> - struct device_attribute *attr,
> - char *buf)
> + struct device_attribute *attr,
> + char *buf)
> {
> struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
> - struct rbd_spec *spec = rbd_dev->parent_spec;
> - int count;
> - char *bufp = buf;
> + ssize_t count = 0;
>
> - if (!spec)
> + if (!rbd_dev->parent)
> return sprintf(buf, "(no parent image)\n");
>
> - count = sprintf(bufp, "pool_id %llu\npool_name %s\n",
> - (unsigned long long) spec->pool_id, spec->pool_name);
> - if (count < 0)
> - return count;
> - bufp += count;
> -
> - count = sprintf(bufp, "image_id %s\nimage_name %s\n", spec->image_id,
> - spec->image_name ? spec->image_name : "(unknown)");
> - if (count < 0)
> - return count;
> - bufp += count;
> -
> - count = sprintf(bufp, "snap_id %llu\nsnap_name %s\n",
> - (unsigned long long) spec->snap_id, spec->snap_name);
> - if (count < 0)
> - return count;
> - bufp += count;
> -
> - count = sprintf(bufp, "overlap %llu\n", rbd_dev->parent_overlap);
> - if (count < 0)
> - return count;
> - bufp += count;
> -
> - return (ssize_t) (bufp - buf);
> + for ( ; rbd_dev->parent; rbd_dev = rbd_dev->parent) {
> + struct rbd_spec *spec = rbd_dev->parent_spec;
> +
> + count += sprintf(&buf[count], "%s"
> + "pool_id %llu\npool_name %s\n"
> + "image_id %s\nimage_name %s\n"
> + "snap_id %llu\nsnap_name %s\n"
> + "overlap %llu\n",
> + !count ? "" : "\n", /* first? */
> + spec->pool_id, spec->pool_name,
> + spec->image_id, spec->image_name ?: "(unknown)",
> + spec->snap_id, spec->snap_name,
> + rbd_dev->parent_overlap);
> + }
> +
> + return count;
> }
>
> static ssize_t rbd_image_refresh(struct device *dev,
>
next prev parent reply other threads:[~2014-07-24 12:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-24 8:42 [PATCH 0/8] wip-overlap Ilya Dryomov
2014-07-24 8:42 ` [PATCH 1/8] rbd: show the entire chain of parent images Ilya Dryomov
2014-07-24 12:31 ` Alex Elder [this message]
2014-07-24 12:45 ` Ilya Dryomov
2014-07-24 8:42 ` [PATCH 2/8] rbd: introduce rbd_dev_header_info() Ilya Dryomov
2014-07-24 12:34 ` Alex Elder
2014-07-24 8:42 ` [PATCH 3/8] rbd: remove unnecessary asserts in rbd_dev_image_probe() Ilya Dryomov
2014-07-24 12:40 ` Alex Elder
2014-07-24 8:42 ` [PATCH 4/8] rbd: split rbd_dev_spec_update() into two functions Ilya Dryomov
2014-07-24 12:55 ` Alex Elder
2014-07-24 8:42 ` [PATCH 5/8] rbd: harden rbd_dev_refresh() caller Ilya Dryomov
2014-07-24 13:09 ` Alex Elder
2014-07-24 8:42 ` [PATCH 6/8] rbd: update mapping size only on refresh Ilya Dryomov
2014-07-24 13:25 ` Alex Elder
2014-07-24 13:46 ` Ilya Dryomov
2014-07-24 15:10 ` Ilya Dryomov
2014-07-25 13:31 ` Alex Elder
2014-07-24 17:59 ` Alex Elder
2014-07-24 8:42 ` [PATCH 7/8] rbd: do not read in parent info before snap context Ilya Dryomov
2014-07-25 8:14 ` Alex Elder
2014-07-25 8:36 ` Ilya Dryomov
2014-07-25 12:46 ` Alex Elder
2014-07-24 8:42 ` [PATCH 8/8] rbd: take snap_id into account when reading in parent info Ilya Dryomov
2014-07-24 18:43 ` Alex Elder
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=53D0FCAC.3030801@ieee.org \
--to=elder@ieee.org \
--cc=ceph-devel@vger.kernel.org \
--cc=ilya.dryomov@inktank.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox