From patchwork Thu Oct 11 18:30:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 21DCB17E3 for ; Thu, 11 Oct 2018 18:30:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C73B2BEF5 for ; Thu, 11 Oct 2018 18:30:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00D9B2BEDC; Thu, 11 Oct 2018 18:30:50 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,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 7D8F52BEEA for ; Thu, 11 Oct 2018 18:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729192AbeJLB7N (ORCPT ); Thu, 11 Oct 2018 21:59:13 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36324 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729175AbeJLB7N (ORCPT ); Thu, 11 Oct 2018 21:59:13 -0400 Received: by mail-pg1-f195.google.com with SMTP id f18-v6so4583586pgv.3 for ; Thu, 11 Oct 2018 11:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LHNgOBPRAw2HSrLay2mD8bP3FPFWkFAOZGj6ry1/IJ0=; b=kEbK9OnH4Hsz0ODaU+YagzTj/zQj1n2S77YUvcx8Y/VrkY8W7qI0dzXxOi3gLaffUb CWz4KNwP3X2vdYoXQvO1c/ClyLn6ergCv1mLCCI7CqHd4a8XP3/fLMKAFZZkOOCO/LL1 dNqxNNelGbU91Ul2FWFnunSSzmR6QhzYfBgoNJh9sA3bwcFwamw8urkjg1L5RV7MpHKB I1sOQGT7jryAHBgotnooG1foaj/2hu6FIbvmUuuiBY3UWPv0ryNrmSuOUssRVAhjAWxR g/09tHQQ935mO8H+dDdMcvCy+U5ABLqeCBZo9jRW1QSJxUjqdvU8wYM6aCJgusLyuIK2 uLBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LHNgOBPRAw2HSrLay2mD8bP3FPFWkFAOZGj6ry1/IJ0=; b=lxWIHs5nQlbXKSL/0IGV3fg8Wiag9phvtKVuFNaGHbx1EQCfYlmMpvTPOkQoB0RDVs cFYOBoG9y8lawt76o6KTmx3E35GRfVCar9OJA8Lwzn/3fxJZc93HfwrlfGWRdWlJ/UCp puz09HPkLEpFqyYyoHF2UQ3Z8I6P+jt7dCoZAFZlEtb2WN7hsLCp+XxdcYrJZm8Ptqwh 4eR6wI7wZ4fMtRKrDgq67ryF2HyQKCCGP4L6bIrC76JNBORdjZ6N7mZb0p/aOhbmRkD8 fkmyFFBfKVY2qrl2/fqJM+o1CXH8WP6ypaTY5OImM8CqCnzJKGKI9AXnS/g0pgmOFfrH 3aNA== X-Gm-Message-State: ABuFfoiz/WXsqjl/4MZ+WTKhbkdk/eeVkr+7MJO9QmhV3LvFk4rBWtDR XaktNr5APCBDdwuIrIGwnB3LHUwIGhE= X-Google-Smtp-Source: ACcGV60uq6Kng2z1Hn0DUUqpei8cash81kroJ/61S62Sy2Yb/8oU1QBlY+YOuw6n0s5hHeAIQUKOZg== X-Received: by 2002:a63:1148:: with SMTP id 8-v6mr2450585pgr.172.1539282648641; Thu, 11 Oct 2018 11:30:48 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:48 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH 13/13] floppy: convert to blk-mq Date: Thu, 11 Oct 2018 11:30:23 -0700 Message-Id: <5aa64bbc9651c69eb75cf8a6e4f9182f2e68ade3.1539282366.git.osandov@fb.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 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 From: Omar Sandoval This driver likes to fetch requests from all over the place, so make queue_rq put requests on a list so that the logic stays the same. Tested with QEMU. Signed-off-by: Omar Sandoval --- drivers/block/floppy.c | 74 +++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index acbafd831ea3..eb19125beb90 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -252,13 +252,13 @@ static int allowed_drive_mask = 0x33; static int irqdma_allocated; -#include +#include #include #include /* for the compatibility eject ioctl */ #include +static LIST_HEAD(floppy_reqs); static struct request *current_req; -static void do_fd_request(struct request_queue *q); static int set_next_request(void); #ifndef fd_get_dma_residue @@ -414,10 +414,10 @@ static struct floppy_drive_struct drive_state[N_DRIVE]; static struct floppy_write_errors write_errors[N_DRIVE]; static struct timer_list motor_off_timer[N_DRIVE]; static struct gendisk *disks[N_DRIVE]; +static struct blk_mq_tag_set tag_sets[N_DRIVE]; static struct block_device *opened_bdev[N_DRIVE]; static DEFINE_MUTEX(open_lock); static struct floppy_raw_cmd *raw_cmd, default_raw_cmd; -static int fdc_queue; /* * This struct defines the different floppy types. @@ -2218,8 +2218,9 @@ static void floppy_end_request(struct request *req, blk_status_t error) nr_bytes = blk_rq_bytes(req); else nr_bytes = current_count_sectors << 9; - if (__blk_end_request(req, error, nr_bytes)) + if (blk_update_request(req, error, nr_bytes)) return; + __blk_mq_end_request(req, error); /* We're done with the request */ floppy_off(drive); @@ -2799,27 +2800,14 @@ static int make_raw_rw_request(void) return 2; } -/* - * Round-robin between our available drives, doing one request from each - */ static int set_next_request(void) { - struct request_queue *q; - int old_pos = fdc_queue; - - do { - q = disks[fdc_queue]->queue; - if (++fdc_queue == N_DRIVE) - fdc_queue = 0; - if (q) { - current_req = blk_fetch_request(q); - if (current_req) { - current_req->error_count = 0; - break; - } - } - } while (fdc_queue != old_pos); - + current_req = list_first_entry_or_null(&floppy_reqs, struct request, + queuelist); + if (current_req) { + current_req->error_count = 0; + list_del_init(¤t_req->queuelist); + } return current_req != NULL; } @@ -2903,29 +2891,38 @@ static void process_fd_request(void) schedule_bh(redo_fd_request); } -static void do_fd_request(struct request_queue *q) +static blk_status_t floppy_queue_rq(struct blk_mq_hw_ctx *hctx, + const struct blk_mq_queue_data *bd) { + blk_mq_start_request(bd->rq); + if (WARN(max_buffer_sectors == 0, "VFS: %s called on non-open device\n", __func__)) - return; + return BLK_STS_IOERR; if (WARN(atomic_read(&usage_count) == 0, "warning: usage count=0, current_req=%p sect=%ld flags=%llx\n", current_req, (long)blk_rq_pos(current_req), (unsigned long long) current_req->cmd_flags)) - return; + return BLK_STS_IOERR; + + spin_lock_irq(&floppy_lock); + list_add_tail(&bd->rq->queuelist, &floppy_reqs); + spin_unlock_irq(&floppy_lock); if (test_and_set_bit(0, &fdc_busy)) { /* fdc busy, this new request will be treated when the current one is done */ is_alive(__func__, "old request running"); - return; + return BLK_STS_OK; } + command_status = FD_COMMAND_NONE; __reschedule_timeout(MAXTIMEOUT, "fd_request"); set_fdc(0); process_fd_request(); is_alive(__func__, ""); + return BLK_STS_OK; } static const struct cont_t poll_cont = { @@ -4488,6 +4485,10 @@ static struct platform_driver floppy_driver = { }, }; +static const struct blk_mq_ops floppy_mq_ops = { + .queue_rq = floppy_queue_rq, +}; + static struct platform_device floppy_device[N_DRIVE]; static bool floppy_available(int drive) @@ -4529,15 +4530,28 @@ static int __init do_floppy_init(void) return -ENOMEM; for (drive = 0; drive < N_DRIVE; drive++) { + struct blk_mq_tag_set *set; + disks[drive] = alloc_disk(1); if (!disks[drive]) { err = -ENOMEM; goto out_put_disk; } - disks[drive]->queue = blk_init_queue(do_fd_request, &floppy_lock); - if (!disks[drive]->queue) { - err = -ENOMEM; + set = &tag_sets[drive]; + set->ops = &floppy_mq_ops; + set->nr_hw_queues = 1; + set->queue_depth = 2; + set->numa_node = NUMA_NO_NODE; + set->flags = BLK_MQ_F_SHOULD_MERGE; + err = blk_mq_alloc_tag_set(set); + if (err) + goto out_put_disk; + + disks[drive]->queue = blk_mq_init_queue(set); + if (IS_ERR(disks[drive]->queue)) { + err = PTR_ERR(disks[drive]->queue); + disks[drive]->queue = NULL; goto out_put_disk; }