Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2964316imm; Sun, 7 Oct 2018 16:29:20 -0700 (PDT) X-Google-Smtp-Source: ACcGV62YBgiioe/ozUTZdGldelQUIrY8fUittuS6YO3xPblICjOE/drzUCjRVFNP4ex0TNk+n/fs X-Received: by 2002:a62:d713:: with SMTP id b19-v6mr22587850pfh.238.1538954960364; Sun, 07 Oct 2018 16:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538954960; cv=none; d=google.com; s=arc-20160816; b=DNAyLGz473Ac09m0sClBGQI9XhUVouuROlNSbw4weDd8TtqDWtBojJPWrfeBadpARx QFn5IMSWjCjgy+L+5vtehAhBQ/eDwJmsLhiEK74wWaG490iAWM0Acz7pdlUQqxokhnil +pqfXQK34tTHupEgXnO1L2KRYAvVrmMULm3d64kgNqvYiNQpuFbA5FoOoyDKxU0W0gWt PockPTUwUSmJ0eCV6f3+hyOQB191+3H+rd569ubtcFSK3x4WIGfP6cuQj5GRVp4CaT5u 6GFOgcrGrtBq0pR2sk+iPXYiOX5vDah1XbI1HXlFRcX67g1VPfCRgFY9GXkq2RXgQ7VK scVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WyJDUInPj/ncKWy6ColCfgvGT7HOPVuvI6ekHZb86EA=; b=cIuEYAC6PsAsKUxNJCFR+6+59y0oaHNF+5zyg3wF4GXxOMLbnGLnCWX9xxNFYIMPcB 8p9GMH9FLLD1QMUeFTvlVXVjHTLk0wcmHLbO4d2oFIsfqsN4zxcVq32FNHGn6AriBFFv U2JRVdvZ5Lno8GeQRy1aby2sVi13uJBNfwmzDxoShHznDlWP0yr2urVgLLjIUn0yIxlx QvgaY435U0HvPoyD5rANgg1Z5DKcFlsxujrywL8KRKyTotkXNL71k9IjG/9xqRUIjHai qfFQBlyaJ7oDirTJ/m5/qpCroTsummjq1xdtai0M/QD7xgETsIRg/GcfOZHsDgPIVXLe iCRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@omnibond-com.20150623.gappssmtp.com header.s=20150623 header.b=Z5jT+vMc; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5-v6si15925315ple.392.2018.10.07.16.29.02; Sun, 07 Oct 2018 16:29:20 -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=@omnibond-com.20150623.gappssmtp.com header.s=20150623 header.b=Z5jT+vMc; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728495AbeJHGhM (ORCPT + 99 others); Mon, 8 Oct 2018 02:37:12 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:45609 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727761AbeJHGhL (ORCPT ); Mon, 8 Oct 2018 02:37:11 -0400 Received: by mail-qt1-f195.google.com with SMTP id e10-v6so8179201qtq.12 for ; Sun, 07 Oct 2018 16:28:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omnibond-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WyJDUInPj/ncKWy6ColCfgvGT7HOPVuvI6ekHZb86EA=; b=Z5jT+vMcRWJCj5GW1xs9JafGh/yQjOjVp3oCaYX2pbKPAQvcV0tddqf4kIl2VotjwI I4qDehDSbaUaoWs13ErFkIjO/vSCcb+EnEccmR66cYZNqkBP1kZQYMd568e2t12mrZFU XgKpKxxjrkY5A/TjqKVFOQVWEwFfBR5s8OPYhTQzCGx+VsCd5aBQIxcigJdfOFqNYt98 OPgZB6FztjMSxWVSVEen9fUNB4czRmkR+3LqWYcjhcc2ioaZ73pd3KkCShh4Fto3qw1Z Z3B1FTQXSHbSetKtNDBHRg8zZkUOmppiPS2PIATKZhjSt9SwuCLWciwZVuuw2FBaGaWK VWgg== 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=WyJDUInPj/ncKWy6ColCfgvGT7HOPVuvI6ekHZb86EA=; b=P1WsYMsbgDpA1A1PkZkSR/rAM5wYQEw/taK6lmysRfADn3CX096ULnlmjgrjwJeUkP r6sDTa1k9mnQyyiF9Pf2p5HFBKscw/l6xxhdTAsk0N4TQBSzY0A1lbdSLIxj5qZVt0Lk UvZfuPkaFo8A6QQYpKwymFURfys6ntohklvB9NAeJ/nKYzPEuTPS2WwaNbPGFGQXBQtf sdaEUEn7SeOF5DwtSIdEUqKMegpyal3UDo4ATrvCMXcXBD94MT6QU7YPYErGLIQ2kONa bLbI5XYvB990rYq8mkK4pHT0+v8CdQcoCtIPbQBhMC38ehpZ4ack187nVpTVzwx3NaPd orkA== X-Gm-Message-State: ABuFfoj6T/Sz8P+zXdNUkbdsARR+QRVYFevQOGyjJGSwMr9IOvzFrNaz ta74axZ1u54uSRd5FeSCmhduelF5PH01BA== X-Received: by 2002:ac8:5487:: with SMTP id h7-v6mr17576097qtq.150.1538954897673; Sun, 07 Oct 2018 16:28:17 -0700 (PDT) Received: from ip-172-31-22-34.ec2.internal (ec2-35-153-175-159.compute-1.amazonaws.com. [35.153.175.159]) by smtp.gmail.com with ESMTPSA id x38-v6sm6793915qtc.39.2018.10.07.16.28.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Oct 2018 16:28:16 -0700 (PDT) From: Martin Brandenburg To: devel@lists.orangefs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, hubcap@omnibond.com Cc: Martin Brandenburg Subject: [PATCH 17/19] orangefs: implement writepages Date: Sun, 7 Oct 2018 23:27:34 +0000 Message-Id: <20181007232736.3780-18-martin@omnibond.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181007232736.3780-1-martin@omnibond.com> References: <20181007232736.3780-1-martin@omnibond.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Go through pages and look for a consecutive writable region. After finding 128 consecutive writable pages or when finding a non-consecutive region, do the write. Signed-off-by: Martin Brandenburg --- fs/orangefs/file.c | 1 + fs/orangefs/inode.c | 144 +++++++++++++++++++++++++++++++++- fs/orangefs/orangefs-kernel.h | 1 + fs/orangefs/super.c | 1 + 4 files changed, 145 insertions(+), 2 deletions(-) diff --git a/fs/orangefs/file.c b/fs/orangefs/file.c index d5ecfea3288a..0d9cef37404f 100644 --- a/fs/orangefs/file.c +++ b/fs/orangefs/file.c @@ -491,6 +491,7 @@ static int orangefs_file_release(struct inode *inode, struct file *file) gossip_debug(GOSSIP_INODE_DEBUG, "flush_racache finished\n"); } + } return 0; } diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c index f53d768acdd9..9a41b7d2ce54 100644 --- a/fs/orangefs/inode.c +++ b/fs/orangefs/inode.c @@ -15,6 +15,8 @@ #include "orangefs-kernel.h" #include "orangefs-bufmap.h" +#define ORANGEFS_WRITEPAGES_COUNT 128 + static int orangefs_writepage_locked(struct page *page, struct writeback_control *wbc) { @@ -44,10 +46,10 @@ static int orangefs_writepage_locked(struct page *page, len = i_size_read(inode); } } else { -/* BUG();*/ + end_page_writeback(page); /* It's not private so there's nothing to write, right? */ printk("writepage not private!\n"); - end_page_writeback(page); + BUG(); return 0; } @@ -230,6 +232,143 @@ static int orangefs_readpage(struct file *file, struct page *page) return ret; } +struct orangefs_writepages { + loff_t off; + size_t len; + kuid_t uid; + kgid_t gid; + struct page *pages[ORANGEFS_WRITEPAGES_COUNT]; + int npages; + struct bio_vec bv[ORANGEFS_WRITEPAGES_COUNT]; +}; + +static int orangefs_writepages_work(struct orangefs_writepages *ow, + struct writeback_control *wbc) +{ + struct inode *inode = ow->pages[0]->mapping->host; + struct orangefs_write_request *wrp, wr; + struct iov_iter iter; + ssize_t ret; + loff_t off; + int i; + + for (i = 0; i < ow->npages; i++) { + set_page_writeback(ow->pages[i]); + ow->bv[i].bv_page = ow->pages[i]; + /* uh except the last one maybe... */ + if (i == ow->npages - 1 && ow->len % PAGE_SIZE) + ow->bv[i].bv_len = ow->len % PAGE_SIZE; + else + ow->bv[i].bv_len = PAGE_SIZE; + ow->bv[i].bv_offset = 0; + } + iov_iter_bvec(&iter, ITER_BVEC | WRITE, ow->bv, ow->npages, ow->len); + + off = ow->off; + wr.uid = ow->uid; + wr.gid = ow->gid; + ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, ow->len, + 0, &wr); + if (ret < 0) { + for (i = 0; i < ow->npages; i++) { + SetPageError(ow->pages[i]); + mapping_set_error(ow->pages[i]->mapping, ret); + end_page_writeback(ow->pages[i]); + unlock_page(ow->pages[i]); + } + } else { + for (i = 0; i < ow->npages; i++) { + if (PagePrivate(ow->pages[i])) { + wrp = (struct orangefs_write_request *) + page_private(ow->pages[i]); + ClearPagePrivate(ow->pages[i]); + wr_release(wrp); + } + end_page_writeback(ow->pages[i]); + unlock_page(ow->pages[i]); + } + } + return ret; +} + +static int orangefs_writepages_callback(struct page *page, + struct writeback_control *wbc, void *data) +{ + struct orangefs_writepages *ow = data; + struct orangefs_write_request *wr; + int ret; + + if (!PagePrivate(page)) { + unlock_page(page); + /* It's not private so there's nothing to write, right? */ + printk("writepages_callback not private!\n"); + BUG(); + return 0; + } + wr = (struct orangefs_write_request *)page_private(page); + + if (wr->len != PAGE_SIZE) { + ret = orangefs_writepage_locked(page, wbc); + mapping_set_error(page->mapping, ret); + unlock_page(page); + } else { + ret = -1; + if (ow->npages == 0) { + ow->off = wr->pos; + ow->len = wr->len; + ow->uid = wr->uid; + ow->gid = wr->gid; + ow->pages[ow->npages++] = page; + ret = 0; + goto done; + } + if (!uid_eq(ow->uid, wr->uid) || !gid_eq(ow->gid, wr->gid)) { + orangefs_writepages_work(ow, wbc); + memset(ow, 0, sizeof *ow); + ret = -1; + goto done; + } + if (ow->off + ow->len == wr->pos) { + ow->len += wr->len; + ow->pages[ow->npages++] = page; + ret = 0; + goto done; + } +done: + if (ret == -1) { + ret = orangefs_writepage_locked(page, wbc); + mapping_set_error(page->mapping, ret); + unlock_page(page); + } else { + if (ow->npages == ORANGEFS_WRITEPAGES_COUNT) { + orangefs_writepages_work(ow, wbc); + memset(ow, 0, sizeof *ow); + } + } + } + return ret; +} + +static int orangefs_writepages(struct address_space *mapping, + struct writeback_control *wbc) +{ + struct orangefs_writepages *ow; + struct blk_plug plug; + int ret; + ow = kzalloc(sizeof(struct orangefs_writepages), GFP_KERNEL); + if (!ow) + return -ENOMEM; + mutex_lock(&ORANGEFS_SB(mapping->host->i_sb)->writepages_mutex); + blk_start_plug(&plug); + ret = write_cache_pages(mapping, wbc, orangefs_writepages_callback, ow); + if (ow->npages) + ret = orangefs_writepages_work(ow, wbc); + blk_finish_plug(&plug); + mutex_unlock(&ORANGEFS_SB(mapping->host->i_sb)->writepages_mutex); + kfree(ow); + return ret; +} + static int orangefs_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned flags, struct page **pagep, void **fsdata) @@ -348,6 +487,7 @@ static int orangefs_launder_page(struct page *page) static const struct address_space_operations orangefs_address_operations = { .writepage = orangefs_writepage, .readpage = orangefs_readpage, + .writepages = orangefs_writepages, .set_page_dirty = __set_page_dirty_nobuffers, .write_begin = orangefs_write_begin, .write_end = orangefs_write_end, diff --git a/fs/orangefs/orangefs-kernel.h b/fs/orangefs/orangefs-kernel.h index 256851bab7a5..9e23f97fb5cc 100644 --- a/fs/orangefs/orangefs-kernel.h +++ b/fs/orangefs/orangefs-kernel.h @@ -220,6 +220,7 @@ struct orangefs_sb_info_s { int mount_pending; int no_list; struct list_head list; + struct mutex writepages_mutex; }; struct orangefs_stats { diff --git a/fs/orangefs/super.c b/fs/orangefs/super.c index 83abe5ec2d11..204e1ac7f228 100644 --- a/fs/orangefs/super.c +++ b/fs/orangefs/super.c @@ -467,6 +467,7 @@ static int orangefs_fill_sb(struct super_block *sb, sb->s_export_op = &orangefs_export_ops; sb->s_root = root_dentry; + mutex_init(&ORANGEFS_SB(sb)->writepages_mutex); return 0; } -- 2.19.0