[Devel] [RFC 06/54] aio: fix CONFIG_VE=n build

Eva Kurchatova eva.kurchatova at virtuozzo.com
Wed Apr 29 22:58:06 MSK 2026


Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
---
 fs/aio.c | 42 +++++++++++++++++++++++++++++-------------
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index c6c3e5808ceb..5dc853b6d965 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -221,18 +221,33 @@ struct aio_kiocb {
 	struct eventfd_ctx	*ki_eventfd;
 };
 
+#ifdef CONFIG_VE
+#define aio_nr_lock_ve(ve) (ve)->aio_nr_lock
+#define aio_nr_ve(ve)      (ve)->aio_nr
+#define aio_max_nr_ve(ve)  (ve)->aio_max_nr
+#else
+/*------ sysctl variables----*/
+static DEFINE_SPINLOCK(aio_nr_lock);
+static unsigned long aio_nr;		/* current system wide number of aio requests */
+static unsigned long aio_max_nr = 0x10000; /* system wide maximum number of aio requests */
+/*----end sysctl variables---*/
+#define aio_nr_lock_ve(ve) aio_nr_lock
+#define aio_nr_ve(ve)      aio_nr
+#define aio_max_nr_ve(ve)  aio_max_nr
+#endif
+
 #ifdef CONFIG_SYSCTL
 static struct ctl_table aio_sysctls[] = {
 	{
 		.procname	= "aio-nr",
-		.data		= &ve0.aio_nr,
+		.data		= &aio_nr_ve(&ve0),
 		.maxlen		= sizeof(unsigned long),
 		.mode		= 0444 | S_ISVTX,
 		.proc_handler	= proc_doulongvec_minmax_virtual,
 	},
 	{
 		.procname	= "aio-max-nr",
-		.data		= &ve0.aio_max_nr,
+		.data		= &aio_max_nr_ve(&ve0),
 		.maxlen		= sizeof(unsigned long),
 		.mode		= 0644 | S_ISVTX,
 		.proc_handler	= proc_doulongvec_minmax_virtual,
@@ -719,14 +734,15 @@ static int ioctx_add_table(struct kioctx *ctx, struct mm_struct *mm)
 
 static void aio_nr_sub(struct kioctx *ctx, unsigned nr)
 {
+#ifdef CONFIG_VE
 	struct ve_struct *ve = ctx->ve;
-
-	spin_lock(&ve->aio_nr_lock);
-	if (WARN_ON(ve->aio_nr - nr > ve->aio_nr))
-		ve->aio_nr = 0;
+#endif
+	spin_lock(&aio_nr_lock_ve(ve));
+	if (WARN_ON(aio_nr_ve(ve) - nr > aio_nr_ve(ve)))
+		aio_nr_ve(ve) = 0;
 	else
-		ve->aio_nr -= nr;
-	spin_unlock(&ve->aio_nr_lock);
+		aio_nr_ve(ve) -= nr;
+	spin_unlock(&aio_nr_lock_ve(ve));
 }
 
 /* ioctx_alloc
@@ -803,15 +819,15 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
 		ctx->req_batch = 1;
 
 	/* limit the number of system wide aios */
-	spin_lock(&ve->aio_nr_lock);
-	if (ve->aio_nr + ctx->max_reqs > ve->aio_max_nr ||
-	    ve->aio_nr + ctx->max_reqs < ve->aio_nr) {
+	spin_lock(&aio_nr_lock_ve(ve));
+	if (aio_nr_ve(ve) + ctx->max_reqs > ve->aio_max_nr ||
+	    aio_nr_ve(ve) + ctx->max_reqs < aio_nr_ve(ve)) {
 		spin_unlock(&ve->aio_nr_lock);
 		err = -EAGAIN;
 		goto err_ctx;
 	}
-	ve->aio_nr += ctx->max_reqs;
-	spin_unlock(&ve->aio_nr_lock);
+	aio_nr_ve(ve) += ctx->max_reqs;
+	spin_unlock(&aio_nr_lock_ve(ve));
 
 	percpu_ref_get(&ctx->users);	/* io_setup() will drop this ref */
 	percpu_ref_get(&ctx->reqs);	/* free_ioctx_users() will drop this */
-- 
2.54.0



More information about the Devel mailing list