From patchwork Sat May 20 08:39:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 9738533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 55B286034C for ; Sat, 20 May 2017 08:40:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 488C4285C8 for ; Sat, 20 May 2017 08:40:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A665285D4; Sat, 20 May 2017 08:40:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE95D285C8 for ; Sat, 20 May 2017 08:40:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755751AbdETIkD (ORCPT ); Sat, 20 May 2017 04:40:03 -0400 Received: from mail-it0-f43.google.com ([209.85.214.43]:37560 "EHLO mail-it0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755708AbdETIj6 (ORCPT ); Sat, 20 May 2017 04:39:58 -0400 Received: by mail-it0-f43.google.com with SMTP id g126so58110050ith.0 for ; Sat, 20 May 2017 01:39:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=bYibWi62/GBuIPnkDPQN45FBxxXNYk0ZOMg0WHU1IBs=; b=jtrKMTPJ2Z5Z24YBdIJYkKOSqo8S/aglJW0hy2ev8+UptkUjknLmN0tL6XAIbrfrmK uvl+2Ow7d6LSZovdtQJC1GLnPlWI3eKq6FMKW9q7exleUaJVrLnGesZbmZ41P7km6n65 /K0xbD1VM6sBUXtafHLluYAH1CWn4HGR+ORPs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=bYibWi62/GBuIPnkDPQN45FBxxXNYk0ZOMg0WHU1IBs=; b=aGZyt3w2dH86WVV30uKW8ClDBPw8mtPUf2GI8r2qGJd51jedPRPnKOobF0PNbjWV8m PPiNVTrJyHZECG5muw/6hrzgBuS1oSL39y3ff9719qm4fMmH5/j6yNbRvsblSoG0+csz FoGgKpfz+SviUQeV8jKqmZKtTWWOolqEwBgp0jIB0kwGdqoFdPZV+sWZIixOemMDZWNv w7FkxvnaQZKwmWznjDXuwZVZDWr4YRRfPSLBKS+3cj0MHqu0KohXOd96FoyFcOWS3x27 n1BeJ+hJ/kINu+okjOM6py9bpzG0GfQYEjte60cLRowmKZY0gMIvyhxDKog/fv8j1Ldn 7SKw== X-Gm-Message-State: AODbwcCSuoDDyZQdgF3kb//9F3uxNZmL4SVM3vD4LQRwQBqEZNrBmrTi 8HFsNp+7rIt71PHyN9GWqA== X-Received: by 10.36.79.6 with SMTP id c6mr1374236itb.95.1495269597039; Sat, 20 May 2017 01:39:57 -0700 (PDT) Received: from ircssh-2.c.rugged-nimbus-611.internal (80.60.198.104.bc.googleusercontent.com. [104.198.60.80]) by smtp.gmail.com with ESMTPSA id a137sm4874001ioe.41.2017.05.20.01.39.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 May 2017 01:39:56 -0700 (PDT) Date: Sat, 20 May 2017 08:39:55 +0000 From: Sargun Dhillon To: linux-btrfs@vger.kernel.org Subject: [PATCH 7/8] btrfs: Add code to prevent qgroup creation for a non-existent subvol Message-ID: <20170520083954.GA4253@ircssh-2.c.rugged-nimbus-611.internal> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch is to prepare for following patches in this patchset. The code allows you to check if a subvol exists, and to only allow the creation of qgroups on subvols that already exist. It doesn't make sense to allow the creation of level 0 qgroups otherwise. The behaviour is to inherit (create) a qgroup when you create a new subvol with quota on. If there is an existing qgroup with this same ID, it will be reset. Signed-off-by: Sargun Dhillon --- fs/btrfs/ioctl.c | 2 +- fs/btrfs/qgroup.c | 11 ++++++++++- fs/btrfs/qgroup.h | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 2b1a8c1..5e20643 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4972,7 +4972,7 @@ static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg) /* FIXME: check if the IDs really exist */ if (sa->create) { - ret = btrfs_create_qgroup(trans, fs_info, sa->qgroupid); + ret = btrfs_create_qgroup(trans, fs_info, sa->qgroupid, 0); } else { ret = btrfs_remove_qgroup(trans, fs_info, sa->qgroupid, 0); } diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index a0699fd..28e2c7f 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1317,10 +1317,19 @@ static int __btrfs_create_qgroup(struct btrfs_trans_handle *trans, } int btrfs_create_qgroup(struct btrfs_trans_handle *trans, - struct btrfs_fs_info *fs_info, u64 qgroupid) + struct btrfs_fs_info *fs_info, u64 qgroupid, + int check_subvol_exists) { int ret; + if (check_subvol_exists && btrfs_qgroup_level(qgroupid) == 0) { + ret = btrfs_subvolume_exists(fs_info, qgroupid); + if (ret < 0) + return ret; + if (!ret) + return -ENOENT; + } + mutex_lock(&fs_info->qgroup_ioctl_lock); ret = __btrfs_create_qgroup(trans, fs_info, qgroupid); mutex_unlock(&fs_info->qgroup_ioctl_lock); diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h index fc08bdb..1afbe40 100644 --- a/fs/btrfs/qgroup.h +++ b/fs/btrfs/qgroup.h @@ -125,7 +125,8 @@ int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans, int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info, u64 src, u64 dst); int btrfs_create_qgroup(struct btrfs_trans_handle *trans, - struct btrfs_fs_info *fs_info, u64 qgroupid); + struct btrfs_fs_info *fs_info, u64 qgroupid, + int check_subvol_exists); int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info, u64 qgroupid, int check_in_use);