From patchwork Sat May 7 18:31:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eryu Guan X-Patchwork-Id: 9038391 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 694E5BF29F for ; Sat, 7 May 2016 19:14:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6428720149 for ; Sat, 7 May 2016 19:14:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 672EF20148 for ; Sat, 7 May 2016 19:14:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750927AbcEGTOZ (ORCPT ); Sat, 7 May 2016 15:14:25 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:36612 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750857AbcEGTOY (ORCPT ); Sat, 7 May 2016 15:14:24 -0400 Received: by mail-pa0-f66.google.com with SMTP id i5so12734132pag.3; Sat, 07 May 2016 12:14:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=ueGMulmBqAaZp8YNm9RY6OVXpr4KmhXOZaOapQ8RlHk=; b=l8JSKByWsQhOyxotYoHM23sCjentQpsQ+T4PXiTHqwbxMFm0uQdsJVq20JMOYIZZjo SaRzcH+iqUI6LJOAQso+h1Hiwk3kOK88XWlcgVW8CGbbUtnTzJ0c8A6X4igMG5Zq0NWC 7EjJF5oFZmHgjLq8q7g+Xka7RYuGOdHUmAwQR/AjUD1jJQ5cz306xxW/fAsQP9wxIlNF n6jym6oZcakFDYxPipgoChAABvPkmqp9VC30T0ve0sN3XJA9bCNTCSJeQjvAMr+6jBzQ kt8oczPAr5w55fBhWYb9uwOBlKylQi0BoBkwuQvligbHWEtV03HfVfhm3L82Jhm5mGOv yaZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ueGMulmBqAaZp8YNm9RY6OVXpr4KmhXOZaOapQ8RlHk=; b=NDZpLxPTe2VKBOE59FME73zQGSyjQQv0lw1N4Yo3vrdQARxOLYb6s6Jf7IyBOYiR8P yjYMN8r+IcxWnZ5rBsxgG1dQGjZTYQyVrhByXqZoUL4VLz5A3UneLEg39+8mWuZt4UI5 JIZ0Al7MsETq3L9RcQ8AjZs7yYQNAg9l6BJSGVsX76s2Al6Py/soqdJmnihjwCUJUdoe R0o0XNQl31aV1ra15An74120pbwVRZeEqZxVe0O2q2PI0jlSPpBIew70LLQT9uK1rEog fEEOCtFU3XFMJNFY52zMdBz68Uj3ff9yo+4CJKrFqvUq2lZZSOqaHLs+UZcFvMqiOv4p 4POw== X-Gm-Message-State: AOPr4FUJmKSQKabMz9GrG9nW3VFWHhXQT0xMVEouIFQRU3jvHbGJjHAGTWEvIV8Q6V48Yw== X-Received: by 10.66.81.136 with SMTP id a8mr38171598pay.113.1462648463434; Sat, 07 May 2016 12:14:23 -0700 (PDT) Received: from localhost ([128.199.137.77]) by smtp.gmail.com with ESMTPSA id ym8sm29860365pab.22.2016.05.07.12.14.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 May 2016 12:14:22 -0700 (PDT) From: Eryu Guan To: linux-fsdevel@vger.kernel.org Cc: linux-ext4@vger.kernel.org, jmoyer@redhat.com, Eryu Guan Subject: [PATCH v2 1/2] direct-io: cleanup get_more_blocks() Date: Sun, 8 May 2016 02:31:49 +0800 Message-Id: <1462645910-23290-1-git-send-email-guaneryu@gmail.com> X-Mailer: git-send-email 2.5.5 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Save one level of indention by returning error early. Introduce some local variables to make the code easier to read a bit, and do preparation for next patch. Signed-off-by: Eryu Guan --- v2: split the cleanup code into a seperate patch to make the review easier fs/direct-io.c | 69 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index 4720377..9d5aff9 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -607,52 +607,55 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio, int ret; sector_t fs_startblk; /* Into file, in filesystem-sized blocks */ sector_t fs_endblk; /* Into file, in filesystem-sized blocks */ + sector_t block_in_file = sdio->block_in_file; unsigned long fs_count; /* Number of filesystem-sized blocks */ int create; - unsigned int i_blkbits = sdio->blkbits + sdio->blkfactor; + unsigned int blkbits = sdio->blkbits; + unsigned int blkfactor = sdio->blkfactor; + unsigned int i_blkbits = blkbits + blkfactor; + struct inode *inode = dio->inode; /* * If there was a memory error and we've overwritten all the * mapped blocks then we can now return that memory error */ ret = dio->page_errors; - if (ret == 0) { - BUG_ON(sdio->block_in_file >= sdio->final_block_in_request); - fs_startblk = sdio->block_in_file >> sdio->blkfactor; - fs_endblk = (sdio->final_block_in_request - 1) >> - sdio->blkfactor; - fs_count = fs_endblk - fs_startblk + 1; + if (ret) + return ret; - map_bh->b_state = 0; - map_bh->b_size = fs_count << i_blkbits; + BUG_ON(block_in_file >= sdio->final_block_in_request); + fs_startblk = block_in_file >> blkfactor; + fs_endblk = (sdio->final_block_in_request - 1) >> blkfactor; + fs_count = fs_endblk - fs_startblk + 1; - /* - * For writes inside i_size on a DIO_SKIP_HOLES filesystem we - * forbid block creations: only overwrites are permitted. - * We will return early to the caller once we see an - * unmapped buffer head returned, and the caller will fall - * back to buffered I/O. - * - * Otherwise the decision is left to the get_blocks method, - * which may decide to handle it or also return an unmapped - * buffer head. - */ - create = dio->rw & WRITE; - if (dio->flags & DIO_SKIP_HOLES) { - if (sdio->block_in_file < (i_size_read(dio->inode) >> - sdio->blkbits)) - create = 0; - } + map_bh->b_state = 0; + map_bh->b_size = fs_count << i_blkbits; + + /* + * For writes inside i_size on a DIO_SKIP_HOLES filesystem we + * forbid block creations: only overwrites are permitted. + * We will return early to the caller once we see an + * unmapped buffer head returned, and the caller will fall + * back to buffered I/O. + * + * Otherwise the decision is left to the get_blocks method, + * which may decide to handle it or also return an unmapped + * buffer head. + */ + create = dio->rw & WRITE; + if (dio->flags & DIO_SKIP_HOLES) { + if (block_in_file < (i_size_read(inode) >> blkbits)) + create = 0; + } - ret = (*sdio->get_block)(dio->inode, fs_startblk, - map_bh, create); + ret = (*sdio->get_block)(inode, fs_startblk, map_bh, create); - /* Store for completion */ - dio->private = map_bh->b_private; + /* Store for completion */ + dio->private = map_bh->b_private; + + if (ret == 0 && buffer_defer_completion(map_bh)) + ret = dio_set_defer_completion(dio); - if (ret == 0 && buffer_defer_completion(map_bh)) - ret = dio_set_defer_completion(dio); - } return ret; }