Commit 16c44cae authored by Tang Junhui's avatar Tang Junhui Committed by Khalid Elmously

bcache: return attach error when no cache set exist

BugLink: https://bugs.launchpad.net/bugs/1775771

[ Upstream commit 7f4fc93d ]

I attach a back-end device to a cache set, and the cache set is not
registered yet, this back-end device did not attach successfully, and no
error returned:
[root]# echo 87859280-fec6-4bcc-20df7ca8f86b > /sys/block/sde/bcache/attach
[root]#

In sysfs_attach(), the return value "v" is initialized to "size" in
the beginning, and if no cache set exist in bch_cache_sets, the "v" value
would not change any more, and return to sysfs, sysfs regard it as success
since the "size" is a positive number.

This patch fixes this issue by assigning "v" with "-ENOENT" in the
initialization.
Signed-off-by: default avatarTang Junhui <tang.junhui@zte.com.cn>
Reviewed-by: default avatarMichael Lyle <mlyle@lyle.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 868d34e6
...@@ -191,7 +191,7 @@ STORE(__cached_dev) ...@@ -191,7 +191,7 @@ STORE(__cached_dev)
{ {
struct cached_dev *dc = container_of(kobj, struct cached_dev, struct cached_dev *dc = container_of(kobj, struct cached_dev,
disk.kobj); disk.kobj);
ssize_t v = size; ssize_t v;
struct cache_set *c; struct cache_set *c;
struct kobj_uevent_env *env; struct kobj_uevent_env *env;
...@@ -268,6 +268,7 @@ STORE(__cached_dev) ...@@ -268,6 +268,7 @@ STORE(__cached_dev)
if (bch_parse_uuid(buf, set_uuid) < 16) if (bch_parse_uuid(buf, set_uuid) < 16)
return -EINVAL; return -EINVAL;
v = -ENOENT;
list_for_each_entry(c, &bch_cache_sets, list) { list_for_each_entry(c, &bch_cache_sets, list) {
v = bch_cached_dev_attach(dc, c, set_uuid); v = bch_cached_dev_attach(dc, c, set_uuid);
if (!v) if (!v)
...@@ -275,7 +276,7 @@ STORE(__cached_dev) ...@@ -275,7 +276,7 @@ STORE(__cached_dev)
} }
pr_err("Can't attach %s: cache set not found", buf); pr_err("Can't attach %s: cache set not found", buf);
size = v; return v;
} }
if (attr == &sysfs_detach && dc->disk.c) if (attr == &sysfs_detach && dc->disk.c)
......
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