Commit fc71d833 authored by Alex Elder's avatar Alex Elder Committed by Sage Weil

rbd: fix up some sysfs stuff

This just tweaks a few things in the routines that implement
rbd sysfs files.

All of the entries for an rbd device in /sys/bus/rbd/devices/<id>/
will represent information whose valid values are known by the time
they are accessible.

Right now we get the size of the mapped image by a call to
get_capacity().  There's no need to do this, because that will
return what we last set the capacity to, which is just the size
recorded for the mapping.  So just show that value instead.

We also get this under protection of the header semaphore, in order
to provide a precisely correct value.  This isn't really necessary;
these files are really informational only and it's not necessary to
be so careful.

Finally, print a special value in case the major device number is
not recorded.  Right now that won't matter much but soon the parent
images won't have devices associated with them.
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent e28626a0
...@@ -3170,13 +3170,9 @@ static ssize_t rbd_size_show(struct device *dev, ...@@ -3170,13 +3170,9 @@ static ssize_t rbd_size_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_device *rbd_dev = dev_to_rbd_dev(dev);
sector_t size;
down_read(&rbd_dev->header_rwsem); return sprintf(buf, "%llu\n",
size = get_capacity(rbd_dev->disk); (unsigned long long)rbd_dev->mapping.size);
up_read(&rbd_dev->header_rwsem);
return sprintf(buf, "%llu\n", (unsigned long long) size * SECTOR_SIZE);
} }
/* /*
...@@ -3189,7 +3185,7 @@ static ssize_t rbd_features_show(struct device *dev, ...@@ -3189,7 +3185,7 @@ static ssize_t rbd_features_show(struct device *dev,
struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
return sprintf(buf, "0x%016llx\n", return sprintf(buf, "0x%016llx\n",
(unsigned long long) rbd_dev->mapping.features); (unsigned long long)rbd_dev->mapping.features);
} }
static ssize_t rbd_major_show(struct device *dev, static ssize_t rbd_major_show(struct device *dev,
...@@ -3197,7 +3193,11 @@ static ssize_t rbd_major_show(struct device *dev, ...@@ -3197,7 +3193,11 @@ static ssize_t rbd_major_show(struct device *dev,
{ {
struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
return sprintf(buf, "%d\n", rbd_dev->major); if (rbd_dev->major)
return sprintf(buf, "%d\n", rbd_dev->major);
return sprintf(buf, "(none)\n");
} }
static ssize_t rbd_client_id_show(struct device *dev, static ssize_t rbd_client_id_show(struct device *dev,
...@@ -3223,7 +3223,7 @@ static ssize_t rbd_pool_id_show(struct device *dev, ...@@ -3223,7 +3223,7 @@ static ssize_t rbd_pool_id_show(struct device *dev,
struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
return sprintf(buf, "%llu\n", return sprintf(buf, "%llu\n",
(unsigned long long) rbd_dev->spec->pool_id); (unsigned long long) rbd_dev->spec->pool_id);
} }
static ssize_t rbd_name_show(struct device *dev, static ssize_t rbd_name_show(struct device *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment