From patchwork Tue Nov 13 11:59:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 997042 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="bH0e100s"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="TS8GDaMR"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42vR5l5rWHz9s9G for ; Tue, 13 Nov 2018 23:00:27 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1NOtnOQrunRY3nvpFs052oM/EE2GFI4u+3YWT0/i9Gc=; b=bH0e100sswclxLUqYy080t8dEZ /KjHEPO6TbMuTaxuHxaKo9DtDAvjg9me83ZkNPlz+nRCtjLybnPajwe7EroxANYsWa0+lRXYTznAE eQnFpE0Q68p4/yO5zd3XFlETURxkmK+UeqbUc51OMiKiOtkbLvX8vSk4AfU/nDN0pp33Q487jn1LW r2P2F1naltVhBMpl5/5EOjeqk2NSkhPYimbNCytXWUX8LC4xPOVIjPkvY9VKbkffpH7wJSgsTd/24 hNidNSpDSyTKjW4QvhUrDmuoAlSkkldoHrLnl7rG2ThhV3VzdskHM85Wt5azSrj8pqNapw/ApXVHb zzIhzlzg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMXMh-0005Mi-Mh; Tue, 13 Nov 2018 12:00:19 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMXMg-0005MN-9E for linux-um@bombadil.infradead.org; Tue, 13 Nov 2018 12:00:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=1LGYKOsCBvCkHuhrwjktA3KwVcxo8AY116sD1Z+imPM=; b=TS8GDaMRVatDCe+zUf1d7qFFz KWz8l8CzoeduTZvUN4SmmP5LTYwX4ZyF0upeYoHk+7Rhv2K88T9BQMjFReS0pQQfQkDuwgKrqIwV5 nFw8JBOoUzXPiAV4/YrQMcLkAamFuMUUehk+/Bf636YVXaUrMgfkcU9mWm0QJe/1DPsOUX6RpMebF yuJR4IQVZKJWEH+p52VUCkjrjPAojvwohsHDw/8shzNI0TZnZ4ADe8f6HPCW61C3TXxjtzOdyhGFY Xzf357mEwvVF5nC4tV+9soSMkPxIGjI3lm334RPWmZ0q4kuKrVDnLn6esYWS3nrHm4ybT6QnPBOEu D+wLK3OUA==; Received: from ivanoab6.miniserver.com ([5.153.251.140] helo=www.kot-begemot.co.uk) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMXMY-0004A1-DX for linux-um@lists.infradead.org; Tue, 13 Nov 2018 12:00:16 +0000 Received: from [192.168.17.6] (helo=smaug.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gMXML-0000OJ-HS; Tue, 13 Nov 2018 11:59:57 +0000 Received: from amistad.kot-begemot.co.uk ([192.168.3.89]) by smaug.kot-begemot.co.uk with esmtp (Exim 4.89) (envelope-from ) id 1gMXME-0004KO-PC; Tue, 13 Nov 2018 11:59:52 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH 1/4] um: Switch to block-mq constants in the UML UBD driver Date: Tue, 13 Nov 2018 11:59:44 +0000 Message-Id: <20181113115947.19290-2-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181113115947.19290-1-anton.ivanov@cambridgegreys.com> References: <20181113115947.19290-1-anton.ivanov@cambridgegreys.com> X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181113_070010_602164_6CE29D1D X-CRM114-Status: GOOD ( 16.68 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: axboe@kernel.dk, richard@nod.at, hch@lst.de, Anton Ivanov MIME-Version: 1.0 Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Anton Ivanov Switch to block mq-constants for both commands and error codes. Signed-off-by: Anton Ivanov --- arch/um/drivers/ubd_kern.c | 51 ++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 28c40624bcb6..331837f1f632 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -43,11 +43,12 @@ #include #include "cow.h" -enum ubd_req { UBD_READ, UBD_WRITE, UBD_FLUSH }; +#define UBD_SECTOR_SIZE (1 << 9) +/* Max request size is determined by sector mask - 32K */ +#define UBD_MAX_REQUEST (8 * sizeof(long)) struct io_thread_req { struct request *req; - enum ubd_req op; int fds[2]; unsigned long offsets[2]; unsigned long long offset; @@ -511,15 +512,13 @@ static void ubd_handler(void) } for (count = 0; count < n/sizeof(struct io_thread_req *); count++) { struct io_thread_req *io_req = (*irq_req_buffer)[count]; - int err = io_req->error ? BLK_STS_IOERR : BLK_STS_OK; - if (!blk_update_request(io_req->req, err, io_req->length)) - __blk_mq_end_request(io_req->req, err); + if (!blk_update_request(io_req->req, io_req->error, io_req->length)) + __blk_mq_end_request(io_req->req, io_req->error); kfree(io_req); } } - reactivate_fd(thread_fd, UBD_IRQ); } @@ -830,6 +829,7 @@ static int ubd_open_dev(struct ubd *ubd_dev) if(err < 0) goto error; ubd_dev->cow.fd = err; } + blk_queue_flag_set(QUEUE_FLAG_NONROT, ubd_dev->queue); return 0; error: os_close_file(ubd_dev->fd); @@ -882,7 +882,7 @@ static int ubd_disk_register(int major, u64 size, int unit, return 0; } -#define ROUND_BLOCK(n) ((n + ((1 << 9) - 1)) & (-1 << 9)) +#define ROUND_BLOCK(n) ((n + (UBD_SECTOR_SIZE - 1)) & (-UBD_SECTOR_SIZE)) static const struct blk_mq_ops ubd_mq_ops = { .queue_rq = ubd_queue_rq, @@ -1277,7 +1277,7 @@ static void cowify_req(struct io_thread_req *req, unsigned long *bitmap, if(req->length > (sizeof(req->sector_mask) * 8) << 9) panic("Operation too long"); - if(req->op == UBD_READ) { + if (req_op(req->req) == REQ_OP_READ) { for(i = 0; i < req->length >> 9; i++){ if(ubd_test_bit(sector + i, (unsigned char *) bitmap)) ubd_set_bit(i, (unsigned char *) @@ -1307,15 +1307,12 @@ static int ubd_queue_one_vec(struct blk_mq_hw_ctx *hctx, struct request *req, io_req->fds[0] = dev->fd; io_req->error = 0; - if (req_op(req) == REQ_OP_FLUSH) { - io_req->op = UBD_FLUSH; - } else { + if (req_op(req) != REQ_OP_FLUSH) { io_req->fds[1] = dev->fd; io_req->cow_offset = -1; io_req->offset = off; io_req->length = bvec->bv_len; io_req->sector_mask = 0; - io_req->op = rq_data_dir(req) == READ ? UBD_READ : UBD_WRITE; io_req->offsets[0] = 0; io_req->offsets[1] = dev->cow.data_offset; io_req->buffer = page_address(bvec->bv_page) + bvec->bv_offset; @@ -1413,22 +1410,36 @@ static int ubd_ioctl(struct block_device *bdev, fmode_t mode, return -EINVAL; } +static int map_error(int error_code) +{ + switch (error_code) { + case 0: + return BLK_STS_OK; + case ENOSYS: + case EOPNOTSUPP: + return BLK_STS_NOTSUPP; + case ENOSPC: + return BLK_STS_NOSPC; + } + return BLK_STS_IOERR; +} + static int update_bitmap(struct io_thread_req *req) { int n; if(req->cow_offset == -1) - return 0; + return map_error(0); n = os_pwrite_file(req->fds[1], &req->bitmap_words, sizeof(req->bitmap_words), req->cow_offset); if(n != sizeof(req->bitmap_words)){ printk("do_io - bitmap update failed, err = %d fd = %d\n", -n, req->fds[1]); - return 1; + return map_error(-n); } - return 0; + return map_error(0); } static void do_io(struct io_thread_req *req) @@ -1438,13 +1449,13 @@ static void do_io(struct io_thread_req *req) int n, nsectors, start, end, bit; __u64 off; - if (req->op == UBD_FLUSH) { + if (req_op(req->req) == REQ_OP_FLUSH) { /* fds[0] is always either the rw image or our cow file */ n = os_sync_file(req->fds[0]); if (n != 0) { printk("do_io - sync failed err = %d " "fd = %d\n", -n, req->fds[0]); - req->error = 1; + req->error = map_error(-n); } return; } @@ -1464,7 +1475,7 @@ static void do_io(struct io_thread_req *req) len = (end - start) * req->sectorsize; buf = &req->buffer[start * req->sectorsize]; - if(req->op == UBD_READ){ + if (req_op(req->req) == REQ_OP_READ) { n = 0; do { buf = &buf[n]; @@ -1473,7 +1484,7 @@ static void do_io(struct io_thread_req *req) if (n < 0) { printk("do_io - read failed, err = %d " "fd = %d\n", -n, req->fds[bit]); - req->error = 1; + req->error = map_error(-n); return; } } while((n < len) && (n != 0)); @@ -1483,7 +1494,7 @@ static void do_io(struct io_thread_req *req) if(n != len){ printk("do_io - write failed err = %d " "fd = %d\n", -n, req->fds[bit]); - req->error = 1; + req->error = map_error(-n); return; } }