提交 ff96128f 编写于 作者: I Ilya Dryomov

rbd: show the entire chain of parent images

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.
Signed-off-by: NIlya Dryomov <ilya.dryomov@inktank.com>
Reviewed-by: NAlex Elder <elder@linaro.org>
上级 08a0f24e
...@@ -94,5 +94,5 @@ current_snap ...@@ -94,5 +94,5 @@ current_snap
parent parent
Information identifying the pool, image, and snapshot id for Information identifying the chain of parent images in a layered rbd
the parent image in a layered rbd image (format 2 only). image. Entries are separated by empty lines.
...@@ -3685,46 +3685,36 @@ static ssize_t rbd_snap_show(struct device *dev, ...@@ -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 a v2 image, shows the chain of parent images, separated by empty
* for the parent image. If there is no parent, simply shows * lines. For v1 images or if there is no parent, shows "(no parent
* "(no parent image)". * image)".
*/ */
static ssize_t rbd_parent_show(struct device *dev, static ssize_t rbd_parent_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
struct rbd_spec *spec = rbd_dev->parent_spec; ssize_t count = 0;
int count;
char *bufp = buf;
if (!spec) if (!rbd_dev->parent)
return sprintf(buf, "(no parent image)\n"); return sprintf(buf, "(no parent image)\n");
count = sprintf(bufp, "pool_id %llu\npool_name %s\n", for ( ; rbd_dev->parent; rbd_dev = rbd_dev->parent) {
(unsigned long long) spec->pool_id, spec->pool_name); struct rbd_spec *spec = rbd_dev->parent_spec;
if (count < 0)
return count; count += sprintf(&buf[count], "%s"
bufp += count; "pool_id %llu\npool_name %s\n"
"image_id %s\nimage_name %s\n"
count = sprintf(bufp, "image_id %s\nimage_name %s\n", spec->image_id, "snap_id %llu\nsnap_name %s\n"
spec->image_name ? spec->image_name : "(unknown)"); "overlap %llu\n",
if (count < 0) !count ? "" : "\n", /* first? */
return count; spec->pool_id, spec->pool_name,
bufp += count; spec->image_id, spec->image_name ?: "(unknown)",
spec->snap_id, spec->snap_name,
count = sprintf(bufp, "snap_id %llu\nsnap_name %s\n", rbd_dev->parent_overlap);
(unsigned long long) spec->snap_id, spec->snap_name); }
if (count < 0)
return count; 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);
} }
static ssize_t rbd_image_refresh(struct device *dev, static ssize_t rbd_image_refresh(struct device *dev,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册