diff options
| author | reinoud <reinoud@NetBSD.org> | 2023-06-27 09:58:50 +0000 |
|---|---|---|
| committer | reinoud <reinoud@NetBSD.org> | 2023-06-27 09:58:50 +0000 |
| commit | 87d35fd690e97d9ebeef0ba0c2cbd2e088676a50 (patch) | |
| tree | 85ceb64d8f9bb9fe1e164214fa3cc6b3e7108a58 /sys | |
| parent | 17bd8213d1480840b89b698241bf83af38084552 (diff) | |
Convert UDF file system code from the depricated tsleep(9)/wakeup(9) to the MP
friendly condvar(9). No functional change intended.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/fs/udf/udf.h | 6 | ||||
| -rw-r--r-- | sys/fs/udf/udf_strat_direct.c | 8 | ||||
| -rw-r--r-- | sys/fs/udf/udf_strat_rmw.c | 30 | ||||
| -rw-r--r-- | sys/fs/udf/udf_strat_sequential.c | 47 | ||||
| -rw-r--r-- | sys/fs/udf/udf_vnops.c | 8 |
5 files changed, 66 insertions, 33 deletions
diff --git a/sys/fs/udf/udf.h b/sys/fs/udf/udf.h index 5b9773dd9e1..29873fb2d78 100644 --- a/sys/fs/udf/udf.h +++ b/sys/fs/udf/udf.h @@ -1,4 +1,4 @@ -/* $NetBSD: udf.h,v 1.54 2022/08/07 11:06:19 andvar Exp $ */ +/* $NetBSD: udf.h,v 1.55 2023/06/27 09:58:50 reinoud Exp $ */ /* * Copyright (c) 2006, 2008 Reinoud Zandijk @@ -76,7 +76,9 @@ extern int udf_verbose; #define UDF_DEBUG_RESERVE 0x1000000 /* initial value of udf_verbose */ -#define UDF_DEBUGGING (0) +#define UDF_DEBUGGING (0x0000000) +//#define UDF_DEBUGGING (0x02fffff) + #ifdef UDF_DEBUG #define DPRINTF(name, arg) { \ diff --git a/sys/fs/udf/udf_strat_direct.c b/sys/fs/udf/udf_strat_direct.c index 891e141b31d..e01c5312e10 100644 --- a/sys/fs/udf/udf_strat_direct.c +++ b/sys/fs/udf/udf_strat_direct.c @@ -1,4 +1,4 @@ -/* $NetBSD: udf_strat_direct.c,v 1.15 2022/01/15 10:55:53 msaitoh Exp $ */ +/* $NetBSD: udf_strat_direct.c,v 1.16 2023/06/27 09:58:50 reinoud Exp $ */ /* * Copyright (c) 2006, 2008 Reinoud Zandijk @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #ifndef lint -__KERNEL_RCSID(0, "$NetBSD: udf_strat_direct.c,v 1.15 2022/01/15 10:55:53 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udf_strat_direct.c,v 1.16 2023/06/27 09:58:50 reinoud Exp $"); #endif /* not lint */ @@ -116,7 +116,7 @@ udf_wr_nodedscr_callback(struct buf *buf) if (udf_node->outstanding_nodedscr == 0) { /* unlock the node */ UDF_UNLOCK_NODE(udf_node, 0); - wakeup(&udf_node->outstanding_nodedscr); + cv_broadcast(&udf_node->node_lock); } putiobuf(buf); @@ -223,7 +223,7 @@ out: udf_node->outstanding_nodedscr--; if (udf_node->outstanding_nodedscr == 0) { UDF_UNLOCK_NODE(udf_node, 0); - wakeup(&udf_node->outstanding_nodedscr); + cv_broadcast(&udf_node->node_lock); } return error; diff --git a/sys/fs/udf/udf_strat_rmw.c b/sys/fs/udf/udf_strat_rmw.c index 37c43972466..d6c0c699068 100644 --- a/sys/fs/udf/udf_strat_rmw.c +++ b/sys/fs/udf/udf_strat_rmw.c @@ -1,4 +1,4 @@ -/* $NetBSD: udf_strat_rmw.c,v 1.30 2022/01/15 10:55:53 msaitoh Exp $ */ +/* $NetBSD: udf_strat_rmw.c,v 1.31 2023/06/27 09:58:50 reinoud Exp $ */ /* * Copyright (c) 2006, 2008 Reinoud Zandijk @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #ifndef lint -__KERNEL_RCSID(0, "$NetBSD: udf_strat_rmw.c,v 1.30 2022/01/15 10:55:53 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udf_strat_rmw.c,v 1.31 2023/06/27 09:58:50 reinoud Exp $"); #endif /* not lint */ @@ -756,7 +756,7 @@ udf_write_nodedscr_rmw(struct udf_strat_args *args) if (udf_node->outstanding_nodedscr == 0) { /* XXX still using wakeup! */ UDF_UNLOCK_NODE(udf_node, 0); - wakeup(&udf_node->outstanding_nodedscr); + cv_broadcast(&udf_node->node_lock); } udf_puteccline(eccline); @@ -1205,6 +1205,8 @@ udf_discstrat_thread(void *arg) work = 1; priv->thread_running = 1; + cv_broadcast(&priv->discstrat_cv); + mutex_enter(&priv->discstrat_mutex); priv->num_floating = 0; while (priv->run_thread || work || priv->num_floating) { @@ -1356,7 +1358,8 @@ udf_discstrat_thread(void *arg) priv->thread_running = 0; priv->thread_finished = 1; - wakeup(&priv->run_thread); + cv_broadcast(&priv->discstrat_cv); + kthread_exit(0); /* not reached */ } @@ -1459,9 +1462,11 @@ udf_discstrat_init_rmw(struct udf_strat_args *args) } /* wait for thread to spin up */ + mutex_enter(&priv->discstrat_mutex); while (!priv->thread_running) { - tsleep(&priv->thread_running, PRIBIO+1, "udfshedstart", hz); + cv_timedwait(&priv->discstrat_cv, &priv->discstrat_mutex, hz); } + mutex_exit(&priv->discstrat_mutex); } @@ -1477,20 +1482,23 @@ udf_discstrat_finish_rmw(struct udf_strat_args *args) /* stop our sheduling thread */ KASSERT(priv->run_thread == 1); priv->run_thread = 0; - wakeup(priv->queue_lwp); + + mutex_enter(&priv->discstrat_mutex); while (!priv->thread_finished) { - tsleep(&priv->run_thread, PRIBIO + 1, "udfshedfin", hz); + cv_broadcast(&priv->discstrat_cv); + cv_timedwait(&priv->discstrat_cv, &priv->discstrat_mutex, hz); } + mutex_exit(&priv->discstrat_mutex); + /* kthread should be finished now */ + cv_destroy(&priv->discstrat_cv); + mutex_destroy(&priv->discstrat_mutex); + mutex_destroy(&priv->seqwrite_mutex); /* cleanup our pools */ pool_destroy(&priv->eccline_pool); pool_destroy(&priv->ecclineblob_pool); - cv_destroy(&priv->discstrat_cv); - mutex_destroy(&priv->discstrat_mutex); - mutex_destroy(&priv->seqwrite_mutex); - /* free our private space */ free(ump->strategy_private, M_UDFTEMP); ump->strategy_private = NULL; diff --git a/sys/fs/udf/udf_strat_sequential.c b/sys/fs/udf/udf_strat_sequential.c index 2886ac70639..c55b0fdfbab 100644 --- a/sys/fs/udf/udf_strat_sequential.c +++ b/sys/fs/udf/udf_strat_sequential.c @@ -1,4 +1,4 @@ -/* $NetBSD: udf_strat_sequential.c,v 1.19 2022/08/27 05:32:41 skrll Exp $ */ +/* $NetBSD: udf_strat_sequential.c,v 1.20 2023/06/27 09:58:50 reinoud Exp $ */ /* * Copyright (c) 2006, 2008 Reinoud Zandijk @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #ifndef lint -__KERNEL_RCSID(0, "$NetBSD: udf_strat_sequential.c,v 1.19 2022/08/27 05:32:41 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udf_strat_sequential.c,v 1.20 2023/06/27 09:58:50 reinoud Exp $"); #endif /* not lint */ @@ -85,7 +85,10 @@ struct strat_private { kcondvar_t discstrat_cv; /* to wait on */ kmutex_t discstrat_mutex; /* disc strategy */ + int thread_running; /* thread control */ int run_thread; /* thread control */ + int thread_finished; /* thread control */ + int sync_req; /* thread control */ int cur_queue; @@ -127,7 +130,7 @@ udf_wr_nodedscr_callback(struct buf *buf) if (udf_node->outstanding_nodedscr == 0) { /* first unlock the node */ UDF_UNLOCK_NODE(udf_node, 0); - wakeup(&udf_node->outstanding_nodedscr); + cv_broadcast(&udf_node->node_lock); } putiobuf(buf); @@ -234,7 +237,7 @@ out: udf_node->outstanding_nodedscr--; if (udf_node->outstanding_nodedscr == 0) { UDF_UNLOCK_NODE(udf_node, 0); - wakeup(&udf_node->outstanding_nodedscr); + cv_broadcast(&udf_node->node_lock); } return error; @@ -565,6 +568,10 @@ udf_discstrat_thread(void *arg) int empty; empty = 1; + + priv->thread_running = 1; + cv_broadcast(&priv->discstrat_cv); + mutex_enter(&priv->discstrat_mutex); while (priv->run_thread || !empty || priv->sync_req) { /* process the current selected queue */ @@ -587,7 +594,10 @@ udf_discstrat_thread(void *arg) } mutex_exit(&priv->discstrat_mutex); - wakeup(&priv->run_thread); + priv->thread_running = 0; + priv->thread_finished = 1; + cv_broadcast(&priv->discstrat_cv); + kthread_exit(0); /* not reached */ } @@ -654,13 +664,22 @@ udf_discstrat_init_seq(struct udf_strat_args *args) vfs_timestamp(&priv->last_queued[UDF_SHED_SEQWRITING]); /* create our disk strategy thread */ - priv->run_thread = 1; - priv->sync_req = 0; + priv->thread_finished = 0; + priv->thread_running = 0; + priv->run_thread = 1; + priv->sync_req = 0; if (kthread_create(PRI_NONE, 0 /* KTHREAD_MPSAFE*/, NULL /* cpu_info*/, udf_discstrat_thread, ump, &priv->queue_lwp, "%s", "udf_rw")) { panic("fork udf_rw"); } + + /* wait for thread to spin up */ + mutex_enter(&priv->discstrat_mutex); + while (!priv->thread_running) { + cv_timedwait(&priv->discstrat_cv, &priv->discstrat_mutex, hz); + } + mutex_exit(&priv->discstrat_mutex); } @@ -669,7 +688,6 @@ udf_discstrat_finish_seq(struct udf_strat_args *args) { struct udf_mount *ump = args->ump; struct strat_private *priv = PRIV(ump); - int error; if (ump == NULL) return; @@ -677,11 +695,14 @@ udf_discstrat_finish_seq(struct udf_strat_args *args) /* stop our scheduling thread */ KASSERT(priv->run_thread == 1); priv->run_thread = 0; - wakeup(priv->queue_lwp); - do { - error = tsleep(&priv->run_thread, PRIBIO+1, - "udfshedfin", hz); - } while (error); + + mutex_enter(&priv->discstrat_mutex); + while (!priv->thread_finished) { + cv_broadcast(&priv->discstrat_cv); + cv_timedwait(&priv->discstrat_cv, &priv->discstrat_mutex, hz); + } + mutex_exit(&priv->discstrat_mutex); + /* kthread should be finished now */ /* set back old device strategy method */ diff --git a/sys/fs/udf/udf_vnops.c b/sys/fs/udf/udf_vnops.c index caa0c7b60e9..9904f929df5 100644 --- a/sys/fs/udf/udf_vnops.c +++ b/sys/fs/udf/udf_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: udf_vnops.c,v 1.126 2022/05/28 21:14:57 andvar Exp $ */ +/* $NetBSD: udf_vnops.c,v 1.127 2023/06/27 09:58:50 reinoud Exp $ */ /* * Copyright (c) 2006, 2008 Reinoud Zandijk @@ -32,7 +32,7 @@ #include <sys/cdefs.h> #ifndef lint -__KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.126 2022/05/28 21:14:57 andvar Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.127 2023/06/27 09:58:50 reinoud Exp $"); #endif /* not lint */ @@ -163,10 +163,12 @@ udf_reclaim(void *v) udf_update(vp, NULL, NULL, NULL, UPDATE_CLOSE); /* async check to see if all node descriptors are written out */ + mutex_enter(&udf_node->node_mutex); while ((volatile int) udf_node->outstanding_nodedscr > 0) { vprint("udf_reclaim(): waiting for writeout\n", vp); - tsleep(&udf_node->outstanding_nodedscr, PRIBIO, "recl wait", hz/8); + cv_timedwait(&udf_node->node_lock, &udf_node->node_mutex, hz/8); } + mutex_exit(&udf_node->node_mutex); /* dispose all node knowledge */ udf_dispose_node(udf_node); |
