From patchwork Tue Jul 21 08:37:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Dongsheng X-Patchwork-Id: 6833371 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 D864FC05AC for ; Tue, 21 Jul 2015 08:44:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 07F3320690 for ; Tue, 21 Jul 2015 08:44:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 20DAD20678 for ; Tue, 21 Jul 2015 08:44:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754182AbbGUIoM (ORCPT ); Tue, 21 Jul 2015 04:44:12 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:7296 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754171AbbGUInx (ORCPT ); Tue, 21 Jul 2015 04:43:53 -0400 X-IronPort-AV: E=Sophos;i="5.13,665,1427731200"; d="scan'208";a="98671225" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Jul 2015 16:47:30 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t6L8fxcW005059; Tue, 21 Jul 2015 16:41:59 +0800 Received: from yds-PC.g08.fujitsu.local (10.167.226.66) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 21 Jul 2015 16:43:47 +0800 From: Dongsheng Yang To: , , CC: , , Dongsheng Yang Subject: [PATCH 20/25] ubifs: alloc quota space in ubifs_write_begin Date: Tue, 21 Jul 2015 16:37:51 +0800 Message-ID: <1437467876-22106-21-git-send-email-yangds.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1437467876-22106-1-git-send-email-yangds.fnst@cn.fujitsu.com> References: <1437467876-22106-1-git-send-email-yangds.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.66] 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.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 Besides inode, quota also limit the space. When use want to write something, we have to tell quota subsystem there is something is going to be written into ubifs, please check the quota limit. If it exceed the limit, return EQUOT. Else, record it and go on. Signed-off-by: Dongsheng Yang --- fs/ubifs/file.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 113c3a6..0c03a88 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c @@ -53,6 +53,7 @@ #include #include #include +#include int read_block(struct inode *inode, void *addr, unsigned int block, struct ubifs_data_node *dn) @@ -434,8 +435,10 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, struct ubifs_inode *ui = ubifs_inode(inode); pgoff_t index = pos >> PAGE_CACHE_SHIFT; int uninitialized_var(err), appending = !!(pos + len > inode->i_size); + int quota_size = 0; int skipped_read = 0; struct page *page; + int ret = 0; ubifs_assert(ubifs_inode(inode)->ui_size == inode->i_size); ubifs_assert(!c->ro_media && !c->ro_mount); @@ -443,10 +446,19 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, if (unlikely(c->ro_error)) return -EROFS; + quota_size = ((pos + len) - inode->i_size); + if (quota_size < 0) + quota_size = 0; + ret = dquot_alloc_space_nodirty(inode, quota_size); + if (unlikely(ret)) + goto err; + /* Try out the fast-path part first */ page = grab_cache_page_write_begin(mapping, index, flags); - if (unlikely(!page)) - return -ENOMEM; + if (unlikely(!page)) { + ret = -ENOMEM; + goto free_quot; + } if (!PageUptodate(page)) { /* The page is not loaded from the flash */ @@ -500,7 +512,9 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, unlock_page(page); page_cache_release(page); - return write_begin_slow(mapping, pos, len, pagep, flags); + ret = write_begin_slow(mapping, pos, len, pagep, flags); + if (unlikely(ret)) + goto free_quot; } /* @@ -510,7 +524,12 @@ static int ubifs_write_begin(struct file *file, struct address_space *mapping, * otherwise. This is an optimization (slightly hacky though). */ *pagep = page; - return 0; + + return ret; +free_quot: + dquot_free_space_nodirty(inode, quota_size); +err: + return ret; }