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: 619606 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3r2JHB66yvz9t0r for ; Sun, 8 May 2016 05:14:30 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=l8JSKByW; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750920AbcEGTOZ (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-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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; }