From patchwork Fri Oct 27 03:08:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10029041 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B30B96022E for ; Fri, 27 Oct 2017 03:08:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A949F28D73 for ; Fri, 27 Oct 2017 03:08:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E18528EF0; Fri, 27 Oct 2017 03:08:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F4D828D73 for ; Fri, 27 Oct 2017 03:08:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751856AbdJ0DIp (ORCPT ); Thu, 26 Oct 2017 23:08:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43392 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751719AbdJ0DIo (ORCPT ); Thu, 26 Oct 2017 23:08:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BFD757E42F; Fri, 27 Oct 2017 03:08:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BFD757E42F Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ming.lei@redhat.com Received: from localhost (ovpn-12-19.pek2.redhat.com [10.72.12.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id E020A5CC12; Fri, 27 Oct 2017 03:08:34 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org, Christoph Hellwig Cc: Omar Sandoval , Ming Lei , David Jeffery Subject: [PATCH] block: avoid to fail elevator switch Date: Fri, 27 Oct 2017 11:08:30 +0800 Message-Id: <20171027030830.25822-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 27 Oct 2017 03:08:44 +0000 (UTC) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP elevator switch can be done just between register_disk() and blk_register_queue(), then we can't change elevator during this period because FLAG_REGISTERED isn't set at that time. One typical use case is that elevator is changed via udev by the following rule, and the KOBJ_ADD uevent is just emited at the end of register_disk() and before running blk_register_queue(). ACTION=="add|change", SUBSYSTEM=="block" , KERNEL=="sda", RUN+="/bin/sh -c 'echo none > /sys/block/sda/queue/scheduler'" This patch fixes the elevator switch failure issue. Fixes: e9a823fb34a8b0(block: fix warning when I/O elevator is changed as request_queue is being removed) Cc: David Jeffery Signed-off-by: Ming Lei --- block/blk-sysfs.c | 7 ++++++- block/elevator.c | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index b8362c0df51d..480959c5b036 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -927,12 +927,17 @@ int blk_register_queue(struct gendisk *disk) void blk_unregister_queue(struct gendisk *disk) { struct request_queue *q = disk->queue; + bool elv_registered; if (WARN_ON(!q)) return; mutex_lock(&q->sysfs_lock); queue_flag_clear_unlocked(QUEUE_FLAG_REGISTERED, q); + if (q->request_fn || (q->mq_ops && q->elevator)) + elv_registered = q->elevator->registered; + else + elv_registered = false; mutex_unlock(&q->sysfs_lock); wbt_exit(q); @@ -941,7 +946,7 @@ void blk_unregister_queue(struct gendisk *disk) if (q->mq_ops) blk_mq_unregister_dev(disk_to_dev(disk), q); - if (q->request_fn || (q->mq_ops && q->elevator)) + if (elv_registered) elv_unregister_queue(q); kobject_uevent(&q->kobj, KOBJ_REMOVE); diff --git a/block/elevator.c b/block/elevator.c index 7ae50eb2732b..0e2a5140111f 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -852,6 +852,15 @@ int elv_register_queue(struct request_queue *q) struct elevator_queue *e = q->elevator; int error; + /* + * When queue isn't registerd to gendisk, the elevator queue + * will be added after it is registered to gendisk; When queue + * is being unregistered, not necessary to add elevator queue + * any more. + */ + if (!test_bit(QUEUE_FLAG_REGISTERED, &q->queue_flags)) + return 0; + error = kobject_add(&e->kobj, &q->kobj, "%s", "iosched"); if (!error) { struct elv_fs_entry *attr = e->type->elevator_attrs; @@ -1055,10 +1064,6 @@ static int __elevator_change(struct request_queue *q, const char *name) char elevator_name[ELV_NAME_MAX]; struct elevator_type *e; - /* Make sure queue is not in the middle of being removed */ - if (!test_bit(QUEUE_FLAG_REGISTERED, &q->queue_flags)) - return -ENOENT; - /* * Special case for mq, turn off scheduling */