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; } } From patchwork Tue Nov 13 11:59:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 997041 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="dX6yjupd"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="VgtjoxYj"; 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 42vR5k2gmqz9s5c for ; Tue, 13 Nov 2018 23:00:26 +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=F4zV0rdtxf2eO1pdYpdBh+zlp2HP5oV+i2nfOJ7eX/I=; b=dX6yjupdAe9Y/Y7DeFzSVYvZlw I5fWNvX4lMY53Ni962CI0Hf+4sPBXfxYnmdlCskJaUnsbrje12uxDNZU5AKGWGQSoko9Ac/wfyqUV 2jErmx3LM3R7X/sQpYDVVuE38eBRWFZmnjhQESi9sjPhCMCj+v0dQ1PpEq7FhR1p/vu9vgSy85Wwt 1pKd3l68bwI3NPsFO+vndPRWPkdFToP1iSU3DErAtQMpOlsux5IndtViwHghYmH1/hrl/S+6HQiyv 4Kj2L2yHPkFlwCRuEYFZhNlYd/IQ4T0kvTvJrnJJhlCTA5f/uqMpWu2joIZHblbhG4TbjolLxtd5d NL9JU+/g==; 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 1gMXMc-0005Lj-Im; Tue, 13 Nov 2018 12:00:14 +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 1gMXMb-0005Ky-F2 for linux-um@bombadil.infradead.org; Tue, 13 Nov 2018 12:00:13 +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=o+1abrHASjN4icLARufft2JoprufluiEhVeFN214iiY=; b=VgtjoxYj6NtbnGsp5iRBXtGtf xjHT2xPUY+eX5erEq3+GweOnVNJ0cfEjRPz49SceMPgZ9Z8ZEkgynKRNOFbc1Z84Tvdf5IlldFKnU ZILQxeyFJaEEUG2TUHhad4zFxiAdHMujXLzkvUXtPy0ef4fXfppKlNaMrfDTtQv3KuFn2FCAwFb+m POKlxFLSIk0L5CDA3Ep33LsCHi7ecNP00CJUb1+3JQOjye8WuLLa79R83jtouvgnbWUOARrw4dP5K KgWM20jqUDMf8FkQOLeKvWCzBZ7dcpXTK+xBuMhrRBJ80Jly0Z16PDMvhXK1wOJMBHXxGqUgypOLU JPnrva3Cw==; 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-0004A2-DZ for linux-um@lists.infradead.org; Tue, 13 Nov 2018 12:00:11 +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 1gMXMP-0000OS-95; Tue, 13 Nov 2018 12:00:01 +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 1gMXMG-0004KO-Mt; Tue, 13 Nov 2018 11:59:54 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH 2/4] um: Clean-up command processing in UML UBD driver Date: Tue, 13 Nov 2018 11:59:45 +0000 Message-Id: <20181113115947.19290-3-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_598878_D062A13C X-CRM114-Status: GOOD ( 13.03 ) 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 Clean-up command processing and return BLK_STS_NOTSUP for uknown commands. Signed-off-by: Anton Ivanov --- arch/um/drivers/ubd_kern.c | 64 ++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 331837f1f632..0f02373ef632 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -1307,21 +1307,25 @@ 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->fds[1] = dev->fd; - io_req->cow_offset = -1; - io_req->offset = off; + if (bvec != NULL) { io_req->length = bvec->bv_len; - io_req->sector_mask = 0; - io_req->offsets[0] = 0; - io_req->offsets[1] = dev->cow.data_offset; io_req->buffer = page_address(bvec->bv_page) + bvec->bv_offset; - io_req->sectorsize = 1 << 9; + } else { + io_req->buffer = NULL; + io_req->length = blk_rq_bytes(req); + } - if (dev->cow.file) { - cowify_req(io_req, dev->cow.bitmap, - dev->cow.bitmap_offset, dev->cow.bitmap_len); - } + io_req->sectorsize = UBD_SECTOR_SIZE; + io_req->fds[1] = dev->fd; + io_req->cow_offset = -1; + io_req->offset = off; + io_req->sector_mask = 0; + io_req->offsets[0] = 0; + io_req->offsets[1] = dev->cow.data_offset; + + if (dev->cow.file) { + cowify_req(io_req, dev->cow.bitmap, + dev->cow.bitmap_offset, dev->cow.bitmap_len); } ret = os_write_file(thread_fd, &io_req, sizeof(io_req)); @@ -1330,7 +1334,6 @@ static int ubd_queue_one_vec(struct blk_mq_hw_ctx *hctx, struct request *req, pr_err("write to io thread failed: %d\n", -ret); kfree(io_req); } - return ret; } @@ -1344,20 +1347,31 @@ static blk_status_t ubd_queue_rq(struct blk_mq_hw_ctx *hctx, blk_mq_start_request(req); spin_lock_irq(&ubd_dev->lock); - - if (req_op(req) == REQ_OP_FLUSH) { + switch (req_op(req)) { + /* operations with no lentgth/offset arguments */ + case REQ_OP_FLUSH: ret = ubd_queue_one_vec(hctx, req, 0, NULL); - } else { - struct req_iterator iter; - struct bio_vec bvec; - u64 off = (u64)blk_rq_pos(req) << 9; - - rq_for_each_segment(bvec, req, iter) { - ret = ubd_queue_one_vec(hctx, req, off, &bvec); - if (ret < 0) - goto out; - off += bvec.bv_len; + break; + /* operations with bio_vec arguments */ + case REQ_OP_READ: + case REQ_OP_WRITE: + { + struct req_iterator iter; + struct bio_vec bvec; + u64 off = (u64)blk_rq_pos(req) << 9; + + rq_for_each_segment(bvec, req, iter) { + ret = ubd_queue_one_vec(hctx, req, off, &bvec); + if (ret < 0) + goto out; + off += bvec.bv_len; + } } + break; + default: + WARN_ON_ONCE(1); + spin_unlock_irq(&ubd_dev->lock); + return BLK_STS_NOTSUPP; } out: spin_unlock_irq(&ubd_dev->lock); From patchwork Tue Nov 13 11:59:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 997040 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="sm6js1Ev"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="B9DuRASG"; 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 42vR5Y4Q0jz9s5c for ; Tue, 13 Nov 2018 23:00:17 +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=UtjxXwK7cMKAfFip8zlmvBDn75F3+owisgoTHu7CGfg=; b=sm6js1EvwdTawd5b5aU25vdyyC BcIVcLN506boZDMxBBkcDMJ95o5ONESlMWkQkx4sg4tYLYvXcHdQycGhn4i/Va2J60ZjKBG5wsdEt gZCC5/f6ubhmeiNsqgLYjMoEbH6wS4kuLc289k+JOhxPbDOP+yi2sxJKiGSC9sGMVP1NosaUh/Lsm v3FRP5JfdS7ABgoOyTtorzWO/utj5MmL/yF5wxvVupUFu99xFV3un54nBZPO3Sw4iOsubaP0s4qML jkzrBwa+1wI1QfGaWRwbjVvIUB2fYLb+f3qEdgHjMZrED7qi8Zd18+w/3ex37EtEsD/Yi6CWxOikx mTrdXRNA==; 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 1gMXMV-0004m4-8h; Tue, 13 Nov 2018 12:00:07 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMXMU-0004Nh-Qv for linux-um@bombadil.infradead.org; Tue, 13 Nov 2018 12:00:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=EmBbcCE9A2XhUPGs5M7RsKV/qvBafuBkPFaSIcDBV2g=; b=B9DuRASG0xfWhiuY56Sn3XM6e 7jbfv5d9BdaqnFLNuC7S5FahuQVz+MJ00jEgGYdkFmvvZdZtA7V0og0BvYLLkEQLE7HMMyVZUkZXj niPZIyC9tvB4iTGbNmINATDCccdimXvG78bZ4vPVU+hlzB6Yq+3b2g6qnQpB/hy5+pE0l/VDCzg52 cjpWxiA5v27+fkns2wRU67PhjFDvbm/WtB3OTCHtaOiD3xtnZmXDLp9+J5wbgF071C17cUS04QkDp Gi83B2UwGzSLJlR3SWQ2KYJacSqM1tSRbrkOGtcx7sV6gHmu9QBKUoxNqAFfcJ3vf4VNmpVj+udXK gUftcqPJw==; Received: from ivanoab6.miniserver.com ([5.153.251.140] helo=www.kot-begemot.co.uk) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMXMQ-0001oY-R5 for linux-um@lists.infradead.org; Tue, 13 Nov 2018 12:00:04 +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 1gMXMQ-0000OY-3X; Tue, 13 Nov 2018 12:00:02 +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 1gMXMI-0004KO-KY; Tue, 13 Nov 2018 11:59:56 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH 3/4] um: Remove unsafe printks from the io thread Date: Tue, 13 Nov 2018 11:59:46 +0000 Message-Id: <20181113115947.19290-4-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_120002_942857_2270A8EE X-CRM114-Status: GOOD ( 11.00 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (0.0 points, 5.0 required) 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 Printk out of the io thread has been proven to be unsafe. It is safer to pass the error to the block IO layer nad let it print it if need be. Signed-off-by: Anton Ivanov --- arch/um/drivers/ubd_kern.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 0f02373ef632..e78f27f5ce88 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -1447,11 +1447,8 @@ static int update_bitmap(struct io_thread_req *req) 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]); + if(n != sizeof(req->bitmap_words)) return map_error(-n); - } return map_error(0); } @@ -1465,12 +1462,7 @@ static void do_io(struct io_thread_req *req) 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 = map_error(-n); - } + req->error = map_error(-os_sync_file(req->fds[0])); return; } @@ -1495,9 +1487,7 @@ static void do_io(struct io_thread_req *req) buf = &buf[n]; len -= n; n = os_pread_file(req->fds[bit], buf, len, off); - if (n < 0) { - printk("do_io - read failed, err = %d " - "fd = %d\n", -n, req->fds[bit]); + if(n < 0){ req->error = map_error(-n); return; } @@ -1506,8 +1496,6 @@ static void do_io(struct io_thread_req *req) } else { n = os_pwrite_file(req->fds[bit], buf, len, off); if(n != len){ - printk("do_io - write failed err = %d " - "fd = %d\n", -n, req->fds[bit]); req->error = map_error(-n); return; } @@ -1545,11 +1533,6 @@ int io_thread(void *arg) if (n == -EAGAIN) { ubd_read_poll(-1); continue; - } else { - printk("io_thread - read failed, fd = %d, " - "err = %d," - "reminder = %d\n", - kernel_fd, -n, io_remainder_size); } } @@ -1564,11 +1547,6 @@ int io_thread(void *arg) res = os_write_file(kernel_fd, ((char *) io_req_buffer) + written, n); if (res >= 0) { written += res; - } else { - if (res != -EAGAIN) { - printk("io_thread - write failed, fd = %d, " - "err = %d\n", kernel_fd, -n); - } } if (written < n) { ubd_write_poll(-1); From patchwork Tue Nov 13 11:59:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 997043 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="LsdIkY3W"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="tXsu1XaW"; 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 42vR5t4dp6z9s5c for ; Tue, 13 Nov 2018 23:00:34 +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=8t+1KQsng3UWwxqxyPwNsDnPZJnhqPLEw0oe5De5C48=; b=LsdIkY3WUX//zTYugzOhNDXR57 lcbNSFtqR/6NikvRyFS3pSWxvtnQO68fCBuHWt6XuyNSGkZ0kBQzfYo0VYuEfuOK/WHrpwnhI8eQ4 G0oFA3uYPAQ/xq54aPoVKQD3PAckEBsTZRjJvJENnNoMqcVJc3Z700tLzbRwomhikKYfQq5dvp6rT y6a7TGrychOmE5EQXHhDsDJJr6xfO2qXETuv53FcT99xc5Tdc4ylZXKPatK7fbTlSx4JVsShW6JXf oPT/Pl0yuFIdk47saxQvpA5xI+lJRqBmIyMHEu5K+1sMIFcwmeeZPeIIQC1An7Ohzh5FXqyO6tioe KRetnH9Q==; 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 1gMXMk-0005NH-Qs; Tue, 13 Nov 2018 12:00:22 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMXMj-0005N4-HE for linux-um@bombadil.infradead.org; Tue, 13 Nov 2018 12:00:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=Zj8H5zVOMdHs029AHm5NcJELGOXdwZUrJk+uh/Sexuc=; b=tXsu1XaW3eGCdS2ai4pTd2xyc eI6K/zqgLF4CzW3+bKMZilVg4SfJL3HTwUqA0447vCQdEndtx2ZZ1A3VJhYqrPzOi+TMHlzQQnnjp Bj5VygF72UqeSIFLscaczl2+0fRcE9m8sIxayDn8epAuwaYdX/I9gEGEH2faezYF3197LzE0Lr4bD JVXqoekbd8p9OL77Ah+0Ri4JyVWfEWV38jhTn3GTFEcoZfrQi68WUh98bXt/2wxaaRkHnkAQDMYqt sw7SnIBX3EQ5XJvphv+rlnFiZWMM0LvzCMaVhD6thD+uFJzWoYj1T+ttqjsBY5QZhi97aP41Wk5uL lrWIK+CnA==; Received: from ivanoab6.miniserver.com ([5.153.251.140] helo=www.kot-begemot.co.uk) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMXMb-0001p1-R2 for linux-um@lists.infradead.org; Tue, 13 Nov 2018 12:00:20 +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 1gMXMR-0000Og-EM; Tue, 13 Nov 2018 12:00:03 +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 1gMXMK-0004KO-Ge; Tue, 13 Nov 2018 11:59:58 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH 4/4] um: Add support for DISCARD in the UBD Driver Date: Tue, 13 Nov 2018 11:59:47 +0000 Message-Id: <20181113115947.19290-5-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_120013_885415_9F9AE5F1 X-CRM114-Status: GOOD ( 17.82 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (0.0 points, 5.0 required) 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 Support for DISCARD and WRITE_ZEROES in the ubd driver using fallocate. DISCARD capable devices are autodetected at open time. Signed-off-by: Anton Ivanov --- arch/um/drivers/Kconfig | 21 +++++++++++++++ arch/um/drivers/ubd_kern.c | 66 ++++++++++++++++++++++++++++++++++++++------- arch/um/include/shared/os.h | 1 + arch/um/os-Linux/file.c | 10 +++++++ 4 files changed, 89 insertions(+), 9 deletions(-) diff --git a/arch/um/drivers/Kconfig b/arch/um/drivers/Kconfig index 2b1aaf7755aa..e817fd4a4c30 100644 --- a/arch/um/drivers/Kconfig +++ b/arch/um/drivers/Kconfig @@ -1,4 +1,25 @@ # SPDX-License-Identifier: GPL-2.0 +menu "UML Block Devices" + +config BLK_DEV_UBD + bool "UBD Block Device" + default y + help + User Mode Linux virtual block device driver + +config BLK_DEV_UBD_SYNC + bool "Use Synchronous mode for UBD" + default n + help + Perform all disk operations synchronously (extremely slow). + +config BLK_DEV_UBD_DISCARD + bool "Enable DISCARD/TRIM support in UBD" + default y + help + Enable discard/trim support. Requires host kernel 3.x or above and + may not be supported on all host filesystems. +endmenu menu "UML Character Devices" diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index e78f27f5ce88..4fd4cb68f033 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -513,9 +513,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]; - if (!blk_update_request(io_req->req, io_req->error, io_req->length)) - __blk_mq_end_request(io_req->req, io_req->error); - + if ((io_req->error) || (io_req->buffer == NULL)) { + blk_mq_end_request(io_req->req, io_req->error); + } else { + 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); } } @@ -775,6 +779,7 @@ static int ubd_open_dev(struct ubd *ubd_dev) char **back_ptr; int err, create_cow, *create_ptr; int fd; + int data; ubd_dev->openflags = ubd_dev->boot_openflags; create_cow = 0; @@ -829,6 +834,23 @@ static int ubd_open_dev(struct ubd *ubd_dev) if(err < 0) goto error; ubd_dev->cow.fd = err; } +#ifdef CONFIG_BLK_DEV_UBD_DISCARD + if (ubd_dev->cow.file != NULL) + fd = ubd_dev->cow.fd; + else + fd = ubd_dev->fd; + err = os_pread_file(fd, &data, sizeof(int), 0); + if (err == sizeof(int)) { + err = os_falloc_punch(fd, 0, sizeof(int)); + if (err == 0) { + ubd_dev->queue->limits.discard_granularity = UBD_SECTOR_SIZE; + ubd_dev->queue->limits.discard_alignment = UBD_SECTOR_SIZE; + blk_queue_max_discard_sectors(ubd_dev->queue, UBD_MAX_REQUEST); + blk_queue_flag_set(QUEUE_FLAG_DISCARD, ubd_dev->queue); + os_pwrite_file(fd, &data, sizeof(int), 0); + } + } +#endif blk_queue_flag_set(QUEUE_FLAG_NONROT, ubd_dev->queue); return 0; error: @@ -1368,6 +1390,12 @@ static blk_status_t ubd_queue_rq(struct blk_mq_hw_ctx *hctx, } } break; +#ifdef CONFIG_BLK_DEV_UBD_DISCARD + case REQ_OP_DISCARD: + case REQ_OP_WRITE_ZEROES: + ret = ubd_queue_one_vec(hctx, req, (u64)blk_rq_pos(req) << 9, NULL); + break; +#endif default: WARN_ON_ONCE(1); spin_unlock_irq(&ubd_dev->lock); @@ -1447,7 +1475,7 @@ static int update_bitmap(struct io_thread_req *req) n = os_pwrite_file(req->fds[1], &req->bitmap_words, sizeof(req->bitmap_words), req->cow_offset); - if(n != sizeof(req->bitmap_words)) + if (n != sizeof(req->bitmap_words)) return map_error(-n); return map_error(0); @@ -1455,11 +1483,13 @@ static int update_bitmap(struct io_thread_req *req) static void do_io(struct io_thread_req *req) { - char *buf; + char *buf = NULL; unsigned long len; int n, nsectors, start, end, bit; __u64 off; + /* FLUSH is really a special case, we cannot "case" it with others */ + if (req_op(req->req) == REQ_OP_FLUSH) { /* fds[0] is always either the rw image or our cow file */ req->error = map_error(-os_sync_file(req->fds[0])); @@ -1479,26 +1509,44 @@ static void do_io(struct io_thread_req *req) off = req->offset + req->offsets[bit] + start * req->sectorsize; len = (end - start) * req->sectorsize; - buf = &req->buffer[start * req->sectorsize]; + if (req->buffer != NULL) + buf = &req->buffer[start * req->sectorsize]; - if (req_op(req->req) == REQ_OP_READ) { + switch (req_op(req->req)) { + case REQ_OP_READ: n = 0; do { buf = &buf[n]; len -= n; n = os_pread_file(req->fds[bit], buf, len, off); - if(n < 0){ + if (n < 0) { req->error = map_error(-n); return; } } while((n < len) && (n != 0)); if (n < len) memset(&buf[n], 0, len - n); - } else { + break; + case REQ_OP_WRITE: n = os_pwrite_file(req->fds[bit], buf, len, off); if(n != len){ req->error = map_error(-n); return; } + break; +#ifdef CONFIG_BLK_DEV_UBD_DISCARD + case REQ_OP_DISCARD: + case REQ_OP_WRITE_ZEROES: + n = os_falloc_punch(req->fds[bit], off, len); + if (n) { + req->error = map_error(-n); + return; + } + break; +#endif + default: + WARN_ON_ONCE(1); + req->error = BLK_STS_NOTSUPP; + return; } start = end; diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index 048ae37eb5aa..ebf23012a59b 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -175,6 +175,7 @@ extern int os_fchange_dir(int fd); extern unsigned os_major(unsigned long long dev); extern unsigned os_minor(unsigned long long dev); extern unsigned long long os_makedev(unsigned major, unsigned minor); +extern int os_falloc_punch(int fd, unsigned long long offset, int count); /* start_up.c */ extern void os_early_checks(void); diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c index c0197097c86e..f25b110d4e70 100644 --- a/arch/um/os-Linux/file.c +++ b/arch/um/os-Linux/file.c @@ -610,3 +610,13 @@ unsigned long long os_makedev(unsigned major, unsigned minor) { return makedev(major, minor); } + +int os_falloc_punch(int fd, unsigned long long offset, int len) +{ + int n = fallocate(fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE, offset, len); + + if (n < 0) + return -errno; + return n; +} +