Skip to content

Commit c4c9fd5

Browse files
Tang Junhuigregkh
authored andcommitted
bcache: return attach error when no cache set exist
[ Upstream commit 7f4fc93 ] 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: Tang Junhui <[email protected]> Reviewed-by: Michael Lyle <[email protected]> Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4c8e027 commit c4c9fd5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/md/bcache/sysfs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ STORE(__cached_dev)
193193
{
194194
struct cached_dev *dc = container_of(kobj, struct cached_dev,
195195
disk.kobj);
196-
ssize_t v = size;
196+
ssize_t v;
197197
struct cache_set *c;
198198
struct kobj_uevent_env *env;
199199

@@ -270,14 +270,15 @@ STORE(__cached_dev)
270270
if (bch_parse_uuid(buf, set_uuid) < 16)
271271
return -EINVAL;
272272

273+
v = -ENOENT;
273274
list_for_each_entry(c, &bch_cache_sets, list) {
274275
v = bch_cached_dev_attach(dc, c, set_uuid);
275276
if (!v)
276277
return size;
277278
}
278279

279280
pr_err("Can't attach %s: cache set not found", buf);
280-
size = v;
281+
return v;
281282
}
282283

283284
if (attr == &sysfs_detach && dc->disk.c)

0 commit comments

Comments
 (0)