* [PATCH v3 1/3] bcache: bch_sectors_dirty_init() check each thread result and return error
@ 2022-09-20 11:28 mingzhe.zou
2022-09-20 11:28 ` [PATCH v3 2/3] bcache: check bch_sectors_dirty_init() return value mingzhe.zou
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: mingzhe.zou @ 2022-09-20 11:28 UTC (permalink / raw)
To: colyli, linux-bcache; +Cc: zoumingzhe
From: ZouMingzhe <mingzhe.zou@easystack.cn>
1. bch_dirty_init_thread() dont check bch_root_node_dirty_init() error
and return it, add result in struct dirty_init_thrd_info.
2. bch_sectors_dirty_init() dont check each thread result and return void,
we should check each thread and return error.
3. bch_btree_check() and bch_sectors_dirty_init() must wait all threads stop,
cannot return error immediately.
Signed-off-by: mingzhe <mingzhe.zou@easystack.cn>
---
drivers/md/bcache/btree.c | 6 +++++-
drivers/md/bcache/writeback.c | 26 ++++++++++++++++++++++----
drivers/md/bcache/writeback.h | 3 ++-
3 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 147c493a989a..a76a77764b2c 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -2051,7 +2051,7 @@ int bch_btree_check(struct cache_set *c)
for (--i; i >= 0; i--)
kthread_stop(check_state.infos[i].thread);
ret = -ENOMEM;
- goto out;
+ goto out_wait;
}
atomic_inc(&check_state.started);
}
@@ -2059,8 +2059,12 @@ int bch_btree_check(struct cache_set *c)
/*
* Must wait for all threads to stop.
*/
+out_wait:
wait_event(check_state.wait, atomic_read(&check_state.started) == 0);
+ if (ret)
+ goto out;
+
for (i = 0; i < check_state.total_threads; i++) {
if (check_state.infos[i].result) {
ret = check_state.infos[i].result;
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
index 3f0ff3aab6f2..77db056cd97a 100644
--- a/drivers/md/bcache/writeback.c
+++ b/drivers/md/bcache/writeback.c
@@ -865,6 +865,7 @@ static int bch_root_node_dirty_init(struct cache_set *c,
static int bch_dirty_init_thread(void *arg)
{
+ int ret = 0;
struct dirty_init_thrd_info *info = arg;
struct bch_dirty_init_state *state = info->state;
struct cache_set *c = state->c;
@@ -905,7 +906,8 @@ static int bch_dirty_init_thread(void *arg)
}
if (p) {
- if (bch_root_node_dirty_init(c, state->d, p) < 0)
+ ret = bch_root_node_dirty_init(c, state->d, p);
+ if (ret < 0)
goto out;
}
@@ -914,6 +916,7 @@ static int bch_dirty_init_thread(void *arg)
}
out:
+ info->result = ret;
/* In order to wake up state->wait in time */
smp_mb__before_atomic();
if (atomic_dec_and_test(&state->started))
@@ -937,6 +940,7 @@ static int bch_btre_dirty_init_thread_nr(void)
void bch_sectors_dirty_init(struct bcache_device *d)
{
int i;
+ int ret = 0;
struct bkey *k = NULL;
struct btree_iter iter;
struct sectors_dirty_init op;
@@ -955,7 +959,7 @@ void bch_sectors_dirty_init(struct bcache_device *d)
sectors_dirty_init_fn(&op.op, c->root, k);
rw_unlock(0, c->root);
- return;
+ return 0;
}
memset(&state, 0, sizeof(struct bch_dirty_init_state));
@@ -982,15 +986,29 @@ void bch_sectors_dirty_init(struct bcache_device *d)
pr_err("fails to run thread bch_dirty_init[%d]\n", i);
for (--i; i >= 0; i--)
kthread_stop(state.infos[i].thread);
- goto out;
+ ret = -ENOMEM;
+ goto out_wait;
}
atomic_inc(&state.started);
}
-out:
+out_wait:
/* Must wait for all threads to stop. */
wait_event(state.wait, atomic_read(&state.started) == 0);
+
+ if (ret)
+ goto out;
+
+ for (i = 0; i < state.total_threads; i++) {
+ if (state.infos[i].result) {
+ ret = state.infos[i].result;
+ goto out;
+ }
+ }
+
+out:
rw_unlock(0, c->root);
+ return ret;
}
void bch_cached_dev_writeback_init(struct cached_dev *dc)
diff --git a/drivers/md/bcache/writeback.h b/drivers/md/bcache/writeback.h
index 31df716951f6..bb5372a14adc 100644
--- a/drivers/md/bcache/writeback.h
+++ b/drivers/md/bcache/writeback.h
@@ -32,6 +32,7 @@ struct bch_dirty_init_state;
struct dirty_init_thrd_info {
struct bch_dirty_init_state *state;
struct task_struct *thread;
+ int result;
};
struct bch_dirty_init_state {
@@ -148,7 +149,7 @@ static inline void bch_writeback_add(struct cached_dev *dc)
void bcache_dev_sectors_dirty_add(struct cache_set *c, unsigned int inode,
uint64_t offset, int nr_sectors);
-void bch_sectors_dirty_init(struct bcache_device *d);
+int bch_sectors_dirty_init(struct bcache_device *d);
void bch_cached_dev_writeback_init(struct cached_dev *dc);
int bch_cached_dev_writeback_start(struct cached_dev *dc);
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3 2/3] bcache: check bch_sectors_dirty_init() return value
2022-09-20 11:28 [PATCH v3 1/3] bcache: bch_sectors_dirty_init() check each thread result and return error mingzhe.zou
@ 2022-09-20 11:28 ` mingzhe.zou
2022-09-20 11:28 ` [PATCH v3 3/3] bcache: check bch_cached_dev_attach() " mingzhe.zou
2022-09-20 21:20 ` [PATCH v3 1/3] bcache: bch_sectors_dirty_init() check each thread result and return error kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: mingzhe.zou @ 2022-09-20 11:28 UTC (permalink / raw)
To: colyli, linux-bcache; +Cc: zoumingzhe
From: ZouMingzhe <mingzhe.zou@easystack.cn>
handle error when call bch_sectors_dirty_init() function
Signed-off-by: mingzhe <mingzhe.zou@easystack.cn>
---
drivers/md/bcache/super.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index ba3909bb6bea..9dcffeb4c182 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1298,21 +1298,17 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,
bch_writeback_queue(dc);
}
- bch_sectors_dirty_init(&dc->disk);
+ ret = bch_sectors_dirty_init(&dc->disk);
+ if (ret) {
+ pr_err("Fails in sectors dirty init for %s\n",
+ dc->disk.disk->disk_name);
+ goto err;
+ }
ret = bch_cached_dev_run(dc);
if (ret && (ret != -EBUSY)) {
- up_write(&dc->writeback_lock);
- /*
- * bch_register_lock is held, bcache_device_stop() is not
- * able to be directly called. The kthread and kworker
- * created previously in bch_cached_dev_writeback_start()
- * have to be stopped manually here.
- */
- kthread_stop(dc->writeback_thread);
- cancel_writeback_rate_update_dwork(dc);
pr_err("Couldn't run cached device %pg\n", dc->bdev);
- return ret;
+ goto err;
}
bcache_device_link(&dc->disk, c, "bdev");
@@ -1332,6 +1328,18 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,
dc->disk.disk->disk_name,
dc->disk.c->set_uuid);
return 0;
+
+err:
+ up_write(&dc->writeback_lock);
+ /*
+ * bch_register_lock is held, bcache_device_stop() is not
+ * able to be directly called. The kthread and kworker
+ * created previously in bch_cached_dev_writeback_start()
+ * have to be stopped manually here.
+ */
+ kthread_stop(dc->writeback_thread);
+ cancel_writeback_rate_update_dwork(dc);
+ return ret;
}
/* when dc->disk.kobj released */
@@ -1540,7 +1548,9 @@ static int flash_dev_run(struct cache_set *c, struct uuid_entry *u)
goto err;
bcache_device_attach(d, c, u - c->uuids);
- bch_sectors_dirty_init(d);
+ err = bch_sectors_dirty_init(d);
+ if (err)
+ goto err;
bch_flash_dev_request_init(d);
err = add_disk(d->disk);
if (err)
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3 3/3] bcache: check bch_cached_dev_attach() return value
2022-09-20 11:28 [PATCH v3 1/3] bcache: bch_sectors_dirty_init() check each thread result and return error mingzhe.zou
2022-09-20 11:28 ` [PATCH v3 2/3] bcache: check bch_sectors_dirty_init() return value mingzhe.zou
@ 2022-09-20 11:28 ` mingzhe.zou
2022-09-20 21:20 ` [PATCH v3 1/3] bcache: bch_sectors_dirty_init() check each thread result and return error kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: mingzhe.zou @ 2022-09-20 11:28 UTC (permalink / raw)
To: colyli, linux-bcache; +Cc: zoumingzhe
From: ZouMingzhe <mingzhe.zou@easystack.cn>
handle error when call bch_cached_dev_attach() function
Signed-off-by: mingzhe <mingzhe.zou@easystack.cn>
---
drivers/md/bcache/super.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 9dcffeb4c182..14cd5e5dc65b 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1458,7 +1458,7 @@ static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
{
const char *err = "cannot allocate memory";
struct cache_set *c;
- int ret = -ENOMEM;
+ int ret = -ENOMEM, ret_tmp;
memcpy(&dc->sb, sb, sizeof(struct cache_sb));
dc->bdev = bdev;
@@ -1478,8 +1478,14 @@ static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
list_add(&dc->list, &uncached_devices);
/* attach to a matched cache set if it exists */
- list_for_each_entry(c, &bch_cache_sets, list)
- bch_cached_dev_attach(dc, c, NULL);
+ err = "failed to attach cached device";
+ list_for_each_entry(c, &bch_cache_sets, list) {
+ ret_tmp = bch_cached_dev_attach(dc, c, NULL);
+ if (ret_tmp)
+ ret = ret_tmp;
+ }
+ if (ret)
+ goto err;
if (BDEV_STATE(&dc->sb) == BDEV_STATE_NONE ||
BDEV_STATE(&dc->sb) == BDEV_STATE_STALE) {
@@ -1979,6 +1985,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
static int run_cache_set(struct cache_set *c)
{
+ int ret = -EIO, ret_tmp;
const char *err = "cannot allocate memory";
struct cached_dev *dc, *t;
struct cache *ca = c->cache;
@@ -2131,8 +2138,14 @@ static int run_cache_set(struct cache_set *c)
if (bch_has_feature_obso_large_bucket(&c->cache->sb))
pr_err("Detect obsoleted large bucket layout, all attached bcache device will be read-only\n");
- list_for_each_entry_safe(dc, t, &uncached_devices, list)
- bch_cached_dev_attach(dc, c, NULL);
+ err = "failed to attach cached device";
+ list_for_each_entry_safe(dc, t, &uncached_devices, list) {
+ ret_tmp = bch_cached_dev_attach(dc, c, NULL);
+ if (ret_tmp)
+ ret = ret_tmp;
+ }
+ if (ret)
+ goto err;
flash_devs_run(c);
@@ -2150,7 +2163,7 @@ static int run_cache_set(struct cache_set *c)
bch_cache_set_error(c, "%s", err);
- return -EIO;
+ return ret;
}
static const char *register_cache_set(struct cache *ca)
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/3] bcache: bch_sectors_dirty_init() check each thread result and return error
2022-09-20 11:28 [PATCH v3 1/3] bcache: bch_sectors_dirty_init() check each thread result and return error mingzhe.zou
2022-09-20 11:28 ` [PATCH v3 2/3] bcache: check bch_sectors_dirty_init() return value mingzhe.zou
2022-09-20 11:28 ` [PATCH v3 3/3] bcache: check bch_cached_dev_attach() " mingzhe.zou
@ 2022-09-20 21:20 ` kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2022-09-20 21:20 UTC (permalink / raw)
To: mingzhe.zou, colyli, linux-bcache; +Cc: llvm, kbuild-all, zoumingzhe
Hi,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.0-rc6 next-20220920]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/mingzhe-zou-easystack-cn/bcache-bch_sectors_dirty_init-check-each-thread-result-and-return-error/20220920-193043
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 521a547ced6477c54b4b0cc206000406c221b4d6
config: hexagon-randconfig-r041-20220921 (https://download.01.org/0day-ci/archive/20220921/202209210545.PcfwfXrP-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/1e312ee12bfc74c18aa6bc0c1519b36f22d8db13
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review mingzhe-zou-easystack-cn/bcache-bch_sectors_dirty_init-check-each-thread-result-and-return-error/20220920-193043
git checkout 1e312ee12bfc74c18aa6bc0c1519b36f22d8db13
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/md/bcache/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
>> drivers/md/bcache/writeback.c:940:6: error: conflicting types for 'bch_sectors_dirty_init'
void bch_sectors_dirty_init(struct bcache_device *d)
^
drivers/md/bcache/writeback.h:152:5: note: previous declaration is here
int bch_sectors_dirty_init(struct bcache_device *d);
^
>> drivers/md/bcache/writeback.c:962:3: error: void function 'bch_sectors_dirty_init' should not return a value [-Wreturn-type]
return 0;
^ ~
drivers/md/bcache/writeback.c:1011:2: error: void function 'bch_sectors_dirty_init' should not return a value [-Wreturn-type]
return ret;
^ ~~~
3 errors generated.
vim +/bch_sectors_dirty_init +940 drivers/md/bcache/writeback.c
b144e45fc57649 Coly Li 2020-03-22 939
b144e45fc57649 Coly Li 2020-03-22 @940 void bch_sectors_dirty_init(struct bcache_device *d)
b144e45fc57649 Coly Li 2020-03-22 941 {
b144e45fc57649 Coly Li 2020-03-22 942 int i;
1e312ee12bfc74 ZouMingzhe 2022-09-20 943 int ret = 0;
b144e45fc57649 Coly Li 2020-03-22 944 struct bkey *k = NULL;
b144e45fc57649 Coly Li 2020-03-22 945 struct btree_iter iter;
b144e45fc57649 Coly Li 2020-03-22 946 struct sectors_dirty_init op;
b144e45fc57649 Coly Li 2020-03-22 947 struct cache_set *c = d->c;
4dc34ae1b45fe2 Coly Li 2022-05-24 948 struct bch_dirty_init_state state;
b144e45fc57649 Coly Li 2020-03-22 949
b144e45fc57649 Coly Li 2020-03-22 950 /* Just count root keys if no leaf node */
4dc34ae1b45fe2 Coly Li 2022-05-24 951 rw_lock(0, c->root, c->root->level);
b144e45fc57649 Coly Li 2020-03-22 952 if (c->root->level == 0) {
b144e45fc57649 Coly Li 2020-03-22 953 bch_btree_op_init(&op.op, -1);
b144e45fc57649 Coly Li 2020-03-22 954 op.inode = d->id;
b144e45fc57649 Coly Li 2020-03-22 955 op.count = 0;
b144e45fc57649 Coly Li 2020-03-22 956
b144e45fc57649 Coly Li 2020-03-22 957 for_each_key_filter(&c->root->keys,
b144e45fc57649 Coly Li 2020-03-22 958 k, &iter, bch_ptr_invalid)
b144e45fc57649 Coly Li 2020-03-22 959 sectors_dirty_init_fn(&op.op, c->root, k);
80db4e4707e78c Coly Li 2022-05-24 960
4dc34ae1b45fe2 Coly Li 2022-05-24 961 rw_unlock(0, c->root);
1e312ee12bfc74 ZouMingzhe 2022-09-20 @962 return 0;
b144e45fc57649 Coly Li 2020-03-22 963 }
b144e45fc57649 Coly Li 2020-03-22 964
7d6b902ea0e02b Coly Li 2022-05-27 965 memset(&state, 0, sizeof(struct bch_dirty_init_state));
4dc34ae1b45fe2 Coly Li 2022-05-24 966 state.c = c;
4dc34ae1b45fe2 Coly Li 2022-05-24 967 state.d = d;
4dc34ae1b45fe2 Coly Li 2022-05-24 968 state.total_threads = bch_btre_dirty_init_thread_nr();
4dc34ae1b45fe2 Coly Li 2022-05-24 969 state.key_idx = 0;
4dc34ae1b45fe2 Coly Li 2022-05-24 970 spin_lock_init(&state.idx_lock);
4dc34ae1b45fe2 Coly Li 2022-05-24 971 atomic_set(&state.started, 0);
4dc34ae1b45fe2 Coly Li 2022-05-24 972 atomic_set(&state.enough, 0);
4dc34ae1b45fe2 Coly Li 2022-05-24 973 init_waitqueue_head(&state.wait);
b144e45fc57649 Coly Li 2020-03-22 974
4dc34ae1b45fe2 Coly Li 2022-05-24 975 for (i = 0; i < state.total_threads; i++) {
4dc34ae1b45fe2 Coly Li 2022-05-24 976 /* Fetch latest state.enough earlier */
eb9b6666d6ca6f Coly Li 2020-03-22 977 smp_mb__before_atomic();
4dc34ae1b45fe2 Coly Li 2022-05-24 978 if (atomic_read(&state.enough))
b144e45fc57649 Coly Li 2020-03-22 979 break;
b144e45fc57649 Coly Li 2020-03-22 980
4dc34ae1b45fe2 Coly Li 2022-05-24 981 state.infos[i].state = &state;
4dc34ae1b45fe2 Coly Li 2022-05-24 982 state.infos[i].thread =
4dc34ae1b45fe2 Coly Li 2022-05-24 983 kthread_run(bch_dirty_init_thread, &state.infos[i],
4dc34ae1b45fe2 Coly Li 2022-05-24 984 "bch_dirtcnt[%d]", i);
4dc34ae1b45fe2 Coly Li 2022-05-24 985 if (IS_ERR(state.infos[i].thread)) {
46f5aa8806e34f Joe Perches 2020-05-27 986 pr_err("fails to run thread bch_dirty_init[%d]\n", i);
b144e45fc57649 Coly Li 2020-03-22 987 for (--i; i >= 0; i--)
4dc34ae1b45fe2 Coly Li 2022-05-24 988 kthread_stop(state.infos[i].thread);
1e312ee12bfc74 ZouMingzhe 2022-09-20 989 ret = -ENOMEM;
1e312ee12bfc74 ZouMingzhe 2022-09-20 990 goto out_wait;
b144e45fc57649 Coly Li 2020-03-22 991 }
4dc34ae1b45fe2 Coly Li 2022-05-24 992 atomic_inc(&state.started);
b144e45fc57649 Coly Li 2020-03-22 993 }
b144e45fc57649 Coly Li 2020-03-22 994
1e312ee12bfc74 ZouMingzhe 2022-09-20 995 out_wait:
4dc34ae1b45fe2 Coly Li 2022-05-24 996 /* Must wait for all threads to stop. */
4dc34ae1b45fe2 Coly Li 2022-05-24 997 wait_event(state.wait, atomic_read(&state.started) == 0);
1e312ee12bfc74 ZouMingzhe 2022-09-20 998
1e312ee12bfc74 ZouMingzhe 2022-09-20 999 if (ret)
1e312ee12bfc74 ZouMingzhe 2022-09-20 1000 goto out;
1e312ee12bfc74 ZouMingzhe 2022-09-20 1001
1e312ee12bfc74 ZouMingzhe 2022-09-20 1002 for (i = 0; i < state.total_threads; i++) {
1e312ee12bfc74 ZouMingzhe 2022-09-20 1003 if (state.infos[i].result) {
1e312ee12bfc74 ZouMingzhe 2022-09-20 1004 ret = state.infos[i].result;
1e312ee12bfc74 ZouMingzhe 2022-09-20 1005 goto out;
1e312ee12bfc74 ZouMingzhe 2022-09-20 1006 }
1e312ee12bfc74 ZouMingzhe 2022-09-20 1007 }
1e312ee12bfc74 ZouMingzhe 2022-09-20 1008
1e312ee12bfc74 ZouMingzhe 2022-09-20 1009 out:
4dc34ae1b45fe2 Coly Li 2022-05-24 1010 rw_unlock(0, c->root);
1e312ee12bfc74 ZouMingzhe 2022-09-20 1011 return ret;
444fc0b6b167ed Kent Overstreet 2013-05-11 1012 }
444fc0b6b167ed Kent Overstreet 2013-05-11 1013
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-20 21:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20 11:28 [PATCH v3 1/3] bcache: bch_sectors_dirty_init() check each thread result and return error mingzhe.zou
2022-09-20 11:28 ` [PATCH v3 2/3] bcache: check bch_sectors_dirty_init() return value mingzhe.zou
2022-09-20 11:28 ` [PATCH v3 3/3] bcache: check bch_cached_dev_attach() " mingzhe.zou
2022-09-20 21:20 ` [PATCH v3 1/3] bcache: bch_sectors_dirty_init() check each thread result and return error kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).