Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2869986ybi; Thu, 18 Jul 2019 16:11:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqz56DCOXCwT1Z4raNHZjUSCFfBdxzxa54ZFjpVmzzKIRsVq/AELEYdG/fqRY81HfW2AKJ43 X-Received: by 2002:a63:484d:: with SMTP id x13mr50189525pgk.122.1563491512089; Thu, 18 Jul 2019 16:11:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563491512; cv=none; d=google.com; s=arc-20160816; b=ZHkZuiKrpYIZc/wPuKGoeYKeXo90ZaJe63c4l4wufpgk+T6rRjIEaR0AJ2NoLJGkNn qDZgdd2iH8iBm2TO9/L2Y+Z+DwACyYgvEH3AYU4uMJ2Yo00kCpe7Qmlz/FLY0Fgm9PSa HINZkezvxxV167u0lqHw5Gp1f6se0MGbS9Ygkr+nKZ7FAtdU7G9SCo9QY/ypX9ZZVN9f jeZO5StNn0N/aiBcdsVJlv9KvkDtaql9g9NpDlziHiyquN7orTG+V9iA/Ov0HXyTwKKi Xr+2xiGVrYO7U3OxeO61txhKepAKOAeUZL2ll8gdM0E+Ej1qYLtCQNtxVZ/jWDJ+cfhi Ssfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=4Bh3i6WETjmo2gyscMLqDfoKBlO0O1C7LBrFVC3WzwM=; b=m4bFo+Tgjr0Jip/kreIGDuVSVg3d2PWbIsm3cg2PYy1tzxOu1+KGbbTIBOv+OL0UDz daPOcxdXe97Z94KpNdJYUYbAoqAUSZouQaZ9jDK70rp6X5NW2270faTXMtHNu/fLlSxO LDkIpCS6huqPVFIAOObQmP0M7+nSUGqGeKQZMlK2SCqjBQv1Sh2QsqyhShctZtSxa8+X a3CrKT2vlLzMh5uU2PDxr9VDGHzbhMGIBgLq3fUmn8AWjXfCwk2BNoaSzPJpmQr4Lv+d DQ2Th1k7bwfIobA2rUYCvUoJcuyKu24hp/8+jZg/8+47vXdD1hagg1bd71x+r6UcgA65 gVcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A2OQZovN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si1010347plj.90.2019.07.18.16.11.35; Thu, 18 Jul 2019 16:11:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A2OQZovN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391428AbfGRXK7 (ORCPT + 99 others); Thu, 18 Jul 2019 19:10:59 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:36372 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727972AbfGRXK7 (ORCPT ); Thu, 18 Jul 2019 19:10:59 -0400 Received: by mail-pf1-f195.google.com with SMTP id r7so13291148pfl.3 for ; Thu, 18 Jul 2019 16:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=4Bh3i6WETjmo2gyscMLqDfoKBlO0O1C7LBrFVC3WzwM=; b=A2OQZovNRceZTr0qvqRWA+vvSU0W8aBl7wly3yLkbkIHZUeYJAtJQTzRAPjfB0QiP7 BLkaNNWPXS38CuOrGw7tP/rIX2i/CahcuukE3O/+iiFAUg+tNY431SacXuFB3Z0NqQxv Qt/x6dIoS+nu0xB2FIOh0Leo/ZlL3/JJTE1ff84W2a1l/BUsslte3rSOxOh6yy4fI52E fYbcMoaWmQayMWjLXTaR+OqTe/GUawChy0OTfdcdZ5dFGXkR8e7QocydqMkoK71VfJ73 u6of+gYDyfkxe60FwCZOoNQnHg907/TdQdliWws+9Pc28mWdRcIvQxPAYrwlQ7Lu/1uD oLAw== 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; bh=4Bh3i6WETjmo2gyscMLqDfoKBlO0O1C7LBrFVC3WzwM=; b=rBWHcC4NqPXoPFRnhxclan8B3BWTV+TnojDj/BgUPe2KvADE+jYhHpoxVGuvxP11A2 3utnmD/QhdRYHnm4lRu9GERTeCKPNt/4cJsZ8tKOG0MYOZB/uw9g5IdKn9Bm5JPQWgq3 aukVfdkQt/se3+FYHQEA5ltGMoM+19GuJiJNZinHBEwHJf+LntltJZgF4rK8adYpfUyP KRICdRzTzYv/xDyw6qZEvqB9AanOXFVpnJHIYuUqafOM4r3OntYsAL7KiBoNqk/rK9md mjakl4Libm0cxPXYJC7Wt7pyIeMOYlLYWkZvmVLuXN2wIUQsplr298jZlrhxzPgzY65c mPpg== X-Gm-Message-State: APjAAAUOXyg28BwRXv8S1gV3v+qHd1+wDMHTSJDZHplTr+ndln48M/T1 MJ9VXzMN6L3Dr4bPwHwBF1iAwA== X-Received: by 2002:a65:4844:: with SMTP id i4mr51178039pgs.113.1563491458290; Thu, 18 Jul 2019 16:10:58 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id w14sm32502763pfn.47.2019.07.18.16.10.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jul 2019 16:10:57 -0700 (PDT) From: Bjorn Andersson To: Alexander Viro , Benjamin LaHaise Cc: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] aio: Support read/write with non-iter file-ops Date: Thu, 18 Jul 2019 16:10:54 -0700 Message-Id: <20190718231054.8175-1-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.18.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement a wrapper for aio_read()/write() to allow async IO on files not implementing the iter version of read/write, such as sysfs. This mimics how readv/writev uses non-iter ops in do_loop_readv_writev(). Signed-off-by: Bjorn Andersson --- fs/aio.c | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index f9f441b59966..0137a1a9bef1 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1514,12 +1514,44 @@ static inline void aio_rw_done(struct kiocb *req, ssize_t ret) } } +static ssize_t aio_iter_readv_writev(struct file *file, struct kiocb *req, + struct iov_iter *iter, int type) +{ + ssize_t ret = 0; + ssize_t nr; + + while (iov_iter_count(iter)) { + struct iovec iovec = iov_iter_iovec(iter); + + if (type == READ) { + nr = file->f_op->read(file, iovec.iov_base, + iovec.iov_len, &req->ki_pos); + } else { + nr = file->f_op->write(file, iovec.iov_base, + iovec.iov_len, &req->ki_pos); + } + + if (nr < 0) { + ret = nr; + break; + } + + ret += nr; + if (nr != iovec.iov_len) + break; + iov_iter_advance(iter, nr); + } + + return ret; +} + static int aio_read(struct kiocb *req, const struct iocb *iocb, bool vectored, bool compat) { struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs; struct iov_iter iter; struct file *file; + ssize_t count; int ret; ret = aio_prep_rw(req, iocb); @@ -1529,15 +1561,18 @@ static int aio_read(struct kiocb *req, const struct iocb *iocb, if (unlikely(!(file->f_mode & FMODE_READ))) return -EBADF; ret = -EINVAL; - if (unlikely(!file->f_op->read_iter)) - return -EINVAL; ret = aio_setup_rw(READ, iocb, &iovec, vectored, compat, &iter); if (ret < 0) return ret; ret = rw_verify_area(READ, file, &req->ki_pos, iov_iter_count(&iter)); - if (!ret) - aio_rw_done(req, call_read_iter(file, req, &iter)); + if (!ret) { + if (likely(file->f_op->read_iter)) + count = call_read_iter(file, req, &iter); + else + count = aio_iter_readv_writev(file, req, &iter, READ); + aio_rw_done(req, count); + } kfree(iovec); return ret; } @@ -1548,6 +1583,7 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb, struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs; struct iov_iter iter; struct file *file; + ssize_t count; int ret; ret = aio_prep_rw(req, iocb); @@ -1557,8 +1593,6 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb, if (unlikely(!(file->f_mode & FMODE_WRITE))) return -EBADF; - if (unlikely(!file->f_op->write_iter)) - return -EINVAL; ret = aio_setup_rw(WRITE, iocb, &iovec, vectored, compat, &iter); if (ret < 0) @@ -1577,7 +1611,11 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb, __sb_writers_release(file_inode(file)->i_sb, SB_FREEZE_WRITE); } req->ki_flags |= IOCB_WRITE; - aio_rw_done(req, call_write_iter(file, req, &iter)); + if (likely(file->f_op->write_iter)) + count = call_write_iter(file, req, &iter); + else + count = aio_iter_readv_writev(file, req, &iter, WRITE); + aio_rw_done(req, count); } kfree(iovec); return ret; -- 2.18.0