From patchwork Tue Mar 19 10:57:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 2300181 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 2DFE9DFB79 for ; Tue, 19 Mar 2013 10:57:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750897Ab3CSK5V (ORCPT ); Tue, 19 Mar 2013 06:57:21 -0400 Received: from mail-pb0-f42.google.com ([209.85.160.42]:55153 "EHLO mail-pb0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750773Ab3CSK5T (ORCPT ); Tue, 19 Mar 2013 06:57:19 -0400 Received: by mail-pb0-f42.google.com with SMTP id xb4so333092pbc.29 for ; Tue, 19 Mar 2013 03:57:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=tvHhaEOe3Ko+gaedjd/ItvswnKFugd3zot7vQLiRnao=; b=bUAiTyTckGGFS1OjNep80Fw1rkQyGJY8zzf2EW58Yeym+IUmTchGBpqXHC5G/AekPp ynVTB3PkEBPn0IxPONC8RlvsTu47Hhqnm2dBtt2vnu/1JsXeFk2IdABWgxq0yAHp+Nw+ lLvWGuUcc4mLnBEN87iyozDCtd8jeWYtRau2WhQr1qnwaU8DqgHPlPoomqLspRIGU1n+ X8HD+/c9z64evizYC3s5RUzU54Okd9JE3uUhmEnwOJCqotQ6GxGcgqaOBldXDijxB+ou zcXjqvYWu5/uzCzE++Mkq/hrrbD8/IsEAKWjmmHJI3IEZAnLoqQja0XRJQwA4tvsQR2O /l6Q== X-Received: by 10.68.196.225 with SMTP id ip1mr2361840pbc.72.1363690639489; Tue, 19 Mar 2013 03:57:19 -0700 (PDT) Received: from localhost.localdomain ([183.213.84.36]) by mx.google.com with ESMTPS id qd8sm23855209pbc.29.2013.03.19.03.57.17 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 19 Mar 2013 03:57:18 -0700 (PDT) From: Wang Shilong To: linux-btrfs@vger.kernel.org Cc: wangshilong1991@gmail.com, sensille@gmx.net Subject: [PATCH] Btrfs: fix missing qgroup reservation before fallocating Date: Tue, 19 Mar 2013 18:57:14 +0800 Message-Id: <1363690634-1622-1-git-send-email-wangshilong1991@gmail.com> X-Mailer: git-send-email 1.7.11.7 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Wang Shilong Steps to reproduce: mkfs.btrfs mount btrfs quota enable btrfs sub create /subv btrfs qgroup limit 10M /subv fallocate --length 20M /subv/data For the above example, fallocating will return successfully which is not expected, we try to fix it by doing qgroup reservation before fallocating. Signed-off-by: Wang Shilong Reviewed-by: Miao Xie --- fs/btrfs/file.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index af1d060..bdf5cd7 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2141,6 +2141,7 @@ static long btrfs_fallocate(struct file *file, int mode, { struct inode *inode = file_inode(file); struct extent_state *cached_state = NULL; + struct btrfs_root *root = BTRFS_I(inode)->root; u64 cur_offset; u64 last_byte; u64 alloc_start; @@ -2168,6 +2169,11 @@ static long btrfs_fallocate(struct file *file, int mode, ret = btrfs_check_data_free_space(inode, alloc_end - alloc_start); if (ret) return ret; + if (root->fs_info->quota_enabled) { + ret = btrfs_qgroup_reserve(root, alloc_end - alloc_start); + if (ret) + goto out_reserve_fail; + } /* * wait for ordered IO before we have any locks. We'll loop again @@ -2271,6 +2277,9 @@ static long btrfs_fallocate(struct file *file, int mode, &cached_state, GFP_NOFS); out: mutex_unlock(&inode->i_mutex); + if (root->fs_info->quota_enabled) + btrfs_qgroup_free(root, alloc_end - alloc_start); +out_reserve_fail: /* Let go of our reservation. */ btrfs_free_reserved_data_space(inode, alloc_end - alloc_start); return ret;