From patchwork Fri Nov 18 12:09:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinlong Chen X-Patchwork-Id: 22289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp158545wrr; Fri, 18 Nov 2022 04:13:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf7YX56fK93ui+CML+Yl5YR7SOHjuhH1c+iqeTRR+823hio+AOjVpDTwRnV1fJCw3CZQLngg X-Received: by 2002:a05:6a00:216e:b0:56e:7b62:bba with SMTP id r14-20020a056a00216e00b0056e7b620bbamr7533441pff.55.1668773625647; Fri, 18 Nov 2022 04:13:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668773625; cv=none; d=google.com; s=arc-20160816; b=GItzvk4L/BH6I5ZHg7Cf8/OnDt9TjQ5wO1HdMjKVyJBi08/j18OdQRnSlndmRtRa4X NerFgLYVeD+hDSQ0OVSgMiPkq5F89yTInB/cHVXmMaANN5hys2dSIgbgT2ORIMYruOP6 w5N3yecVxlWms67trWxA4MueWyeOIYVjD2KQVRsSaXbQJQgrkYvSe0fdTg0EJtzT3zHx W4LvMSQqqjCn6ik2sjAkHTbf8Q4KTjZhlHxHVEtYi7dE85kal6G/0YoO268wsAZDQp5i zpLg7zw1CMvZdly9LOqn0EWiLojQscbQihXMVnhB5iucOfVamj8dO5IB0ShHuMj02y9C 7E4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5ck1b6v2qcs3j/xUIVXz0quLdXwFCsdWY/CiTKEi7T0=; b=Gq8xzGYZONGrJ9av/LZu1utTPCvJI8HCC3xcnWi6/swFx811tc809n6ndbJE5UK4KA q3MOwRtZnpOZJnHJnpSauORhMVIE2TqRQJhXXQfJZQx+DM3/yJejAwff6QVBsOvgKKww 2HpaATunfbn3CuaQDoE/S15yyXCFC3JlZlmHsCgfhvapcMX6C7Qbn0B7DVOYLZKJ/kxB Q2LZkJefP6OJgUb0IeQAylRnrRHbnFiAY18CxlNJIcl4qCRLd2wewM5sw6sFRK+HaoJQ stsCx2hkmzJ/HUT0Fm9bKnfBHJ3SbS0Kwn0C9YNDCXlSAb5Is9z/hzgIqGf1xqv0o6hm 7O3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a170902c94600b00172f6726d91si3744743pla.565.2022.11.18.04.13.31; Fri, 18 Nov 2022 04:13:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241710AbiKRMK2 (ORCPT + 99 others); Fri, 18 Nov 2022 07:10:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241441AbiKRMKP (ORCPT ); Fri, 18 Nov 2022 07:10:15 -0500 Received: from zju.edu.cn (spam.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E6DE8FF8B; Fri, 18 Nov 2022 04:10:13 -0800 (PST) Received: from localhost.localdomain (unknown [10.14.30.251]) by mail-app4 (Coremail) with SMTP id cS_KCgDX2MwUdndjSIwaCA--.39489S4; Fri, 18 Nov 2022 20:10:11 +0800 (CST) From: Jinlong Chen To: axboe@kernel.dk Cc: hch@lst.de, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, nickyc975@zju.edu.cn Subject: [RFC PATCH 2/2] elevator: restore the old io scheduler if failed to switch to the new one Date: Fri, 18 Nov 2022 20:09:54 +0800 Message-Id: <29281ffcdd756bdbdfcee8769cd8b2eb867b74e2.1668772991.git.nickyc975@zju.edu.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: cS_KCgDX2MwUdndjSIwaCA--.39489S4 X-Coremail-Antispam: 1UD129KBjvJXoW7Kry7JFWDAryUGr45Zw4Dtwb_yoW8AF1xpF 4rGwsxKrsrJr47X3W3Cw17Z345tF9agrW3XrWxC34FkFn3tr47Ja1UGF1IvF4DJrW8JFsI vr48tFWDGa4UurJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvq1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2 z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vYz4IE04k24V AvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xf McIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7 v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxAIw28IcxkI 7VAKI48JMxAIw28IcVCjz48v1sIEY20_GFWkJr1UJwCFx2IqxVCFs4IE7xkEbVWUJVW8Jw C20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAF wI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjx v20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2 jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0x ZFpf9x0JUQZ23UUUUU= X-CM-SenderInfo: qssqjiaqqzq6lmxovvfxof0/1tbiAg0SB1ZdtcfEpQAAsC X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749835973283102423?= X-GMAIL-MSGID: =?utf-8?q?1749835973283102423?= If we failed to switch to the new io scheduler, we should try to restore the old one instead of just switching to none. This also makes elevator_switch match its document. Signed-off-by: Jinlong Chen --- block/elevator.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/block/elevator.c b/block/elevator.c index 517857a9a68f..b7bd0b8468bd 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -672,6 +672,7 @@ static int __elevator_apply(struct request_queue *q, struct elevator_type *e) */ int elevator_switch(struct request_queue *q, struct elevator_type *new_e) { + struct elevator_type *old_e = NULL; int ret; lockdep_assert_held(&q->sysfs_lock); @@ -680,17 +681,37 @@ int elevator_switch(struct request_queue *q, struct elevator_type *new_e) blk_mq_quiesce_queue(q); if (q->elevator) { + old_e = q->elevator->type; + /* + * Keep a reference so we can fallback on failure. + */ + __elevator_get(old_e); elv_unregister_queue(q); elevator_exit(q); } ret = __elevator_apply(q, new_e); - if (ret) - goto out_unfreeze; + if (likely(!ret)) { + blk_add_trace_msg(q, "elv switch: %s", new_e->elevator_name); + } else if (old_e) { + int err; + + err = __elevator_apply(q, old_e); + if (unlikely(err)) { + blk_add_trace_msg(q, + "elv switch failed: %s (%d), fallback failed: %s (%d)", + new_e->elevator_name, ret, old_e->elevator_name, err + ); + } + } - blk_add_trace_msg(q, "elv switch: %s", new_e->elevator_name); + if (old_e) { + /* + * Done, release the reference we kept. + */ + elevator_put(old_e); + } -out_unfreeze: blk_mq_unquiesce_queue(q); blk_mq_unfreeze_queue(q); return ret;