From patchwork Fri Oct 25 12:22:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 13850616 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 106191E8845 for ; Fri, 25 Oct 2024 12:23:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858991; cv=none; b=mhrxwtNJNBdrQZl/tu3O7PXkemVzrFNzRKSx7zOtayRdyzG+pQfvV3+1/3nlNxtpFgylcrj3fehy7dDPWpu3iHaxR3a5gKUvQ8Ako168XrQFqsqYhL0mkz9sFXuY0vaa14RL9txTIq1DOy+u9O022bbhiY9Ek3mIDtFdv7GvH2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858991; c=relaxed/simple; bh=LZ/n3hEnsp/MJH05VXcNhuGICUOKdYLSrROs6pR+ILw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BJAQ4QsKRX3YGifdYkRFG4UXQqIn+SD2y7axayowTufYQ7mU27x4Fa3o9jwtM9tWAHProfIzFW8x/6O98sll5BErL+d29VOzCm+h9Jg260xOSjc6b27q1EO2Ql6wFLLc3pJgUuRucIfHBHt793Of/RQcXX3pMGD803ChGHhUg/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FLbS4pQn; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FLbS4pQn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729858987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tEHSsCvK6YvCrDa7THoJ0nmcyDA/rlY7BBNXgdGj4+0=; b=FLbS4pQncoh5v4CLhtjKTcy8rQ7iEZ1nk34OTp9mdsteSdrLY2qVHSSNeLjNsB0vva2kQ/ 08rdgYhQKGZWFAQ+r1cVL4LesE4dpGxTa+lbXyzIDYKS+wUyIDDChL2JZFwAOBKdfsa9u+ pTImkVjqdGqj0RBhdMQ3ZUreLfYXoN8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-301-pVdE9p3IMWO5txCh7DM0vg-1; Fri, 25 Oct 2024 08:23:06 -0400 X-MC-Unique: pVdE9p3IMWO5txCh7DM0vg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D29FE195609E; Fri, 25 Oct 2024 12:23:04 +0000 (UTC) Received: from localhost (unknown [10.72.116.106]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9DEEE196BB7D; Fri, 25 Oct 2024 12:23:03 +0000 (UTC) From: Ming Lei To: Jens Axboe , io-uring@vger.kernel.org, Pavel Begunkov Cc: linux-block@vger.kernel.org, Uday Shankar , Akilesh Kailash , Ming Lei Subject: [PATCH V8 1/7] io_uring: add io_link_req() helper Date: Fri, 25 Oct 2024 20:22:38 +0800 Message-ID: <20241025122247.3709133-2-ming.lei@redhat.com> In-Reply-To: <20241025122247.3709133-1-ming.lei@redhat.com> References: <20241025122247.3709133-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Add io_link_req() helper, so that io_submit_sqe() can become more readable. Signed-off-by: Ming Lei --- io_uring/io_uring.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 58b401900b41..02f7dd58d44d 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2155,19 +2155,11 @@ static __cold int io_submit_fail_init(const struct io_uring_sqe *sqe, return 0; } -static inline int io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req, - const struct io_uring_sqe *sqe) - __must_hold(&ctx->uring_lock) +/* + * Return NULL if nothing to be queued, otherwise return request for queueing */ +static struct io_kiocb *io_link_sqe(struct io_submit_link *link, + struct io_kiocb *req) { - struct io_submit_link *link = &ctx->submit_state.link; - int ret; - - ret = io_init_req(ctx, req, sqe); - if (unlikely(ret)) - return io_submit_fail_init(sqe, req, ret); - - trace_io_uring_submit_req(req); - /* * If we already have a head request, queue this one for async * submittal once the head completes. If we don't have a head but @@ -2181,7 +2173,7 @@ static inline int io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req, link->last = req; if (req->flags & IO_REQ_LINK_FLAGS) - return 0; + return NULL; /* last request of the link, flush it */ req = link->head; link->head = NULL; @@ -2197,9 +2189,30 @@ static inline int io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req, fallback: io_queue_sqe_fallback(req); } - return 0; + return NULL; } + return req; +} + +static inline int io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req, + const struct io_uring_sqe *sqe) + __must_hold(&ctx->uring_lock) +{ + struct io_submit_link *link = &ctx->submit_state.link; + int ret; + ret = io_init_req(ctx, req, sqe); + if (unlikely(ret)) + return io_submit_fail_init(sqe, req, ret); + + trace_io_uring_submit_req(req); + + if (unlikely(link->head || (req->flags & (IO_REQ_LINK_FLAGS | + REQ_F_FORCE_ASYNC | REQ_F_FAIL)))) { + req = io_link_sqe(link, req); + if (!req) + return 0; + } io_queue_sqe(req); return 0; }