From patchwork Wed Apr 23 13:28:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "J S, Ajesh" X-Patchwork-Id: 4041041 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B4814BFF02 for ; Wed, 23 Apr 2014 13:31:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C25C4201EC for ; Wed, 23 Apr 2014 13:31:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3F7720166 for ; Wed, 23 Apr 2014 13:31:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755608AbaDWNaV (ORCPT ); Wed, 23 Apr 2014 09:30:21 -0400 Received: from g9t1613g.houston.hp.com ([15.240.0.71]:58594 "EHLO g9t1613g.houston.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755077AbaDWNaQ convert rfc822-to-8bit (ORCPT ); Wed, 23 Apr 2014 09:30:16 -0400 Received: from g6t1525.atlanta.hp.com (g6t1525.atlanta.hp.com [15.193.200.68]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by g9t1613g.houston.hp.com (Postfix) with ESMTPS id A808562723; Wed, 23 Apr 2014 13:30:15 +0000 (UTC) Received: from G6W4001.americas.hpqcorp.net (g6w4001.atlanta.hp.com [16.205.80.210]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by g6t1525.atlanta.hp.com (Postfix) with ESMTPS id D3185132; Wed, 23 Apr 2014 13:29:27 +0000 (UTC) Received: from G5W5498.americas.hpqcorp.net (16.201.144.178) by G6W4001.americas.hpqcorp.net (16.205.80.210) with Microsoft SMTP Server (TLS) id 14.3.169.1; Wed, 23 Apr 2014 13:28:02 +0000 Received: from G5W2738.americas.hpqcorp.net ([169.254.9.100]) by G5W5498.americas.hpqcorp.net ([16.201.144.178]) with mapi id 14.03.0169.001; Wed, 23 Apr 2014 13:28:02 +0000 From: "J S, Ajesh" To: "clm@fb.com" , "jbacik@fb.com" CC: "linux-btrfs@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH 001/001] btrfs: Mechanism to modify the permission of a subvolume Thread-Topic: [PATCH 001/001] btrfs: Mechanism to modify the permission of a subvolume Thread-Index: Ac9e99iHjeArEQIQQNGoH9v0JpmHTg== Date: Wed, 23 Apr 2014 13:28:01 +0000 Message-ID: <1C24A869E87C7B45BE3E2BB439AB8F8C0D13DAE0@G5W2738.americas.hpqcorp.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [15.193.49.18] MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 From: Ajesh JS This patch provides a mechanism to modify the permission of a subvolume in a btrfs file system This helps to apply a policy of having read-write subvolume inside a read-only subvolume. One use case is to have the whole root file system as a read-only subvolume and have /etc as a read-write subvolume inside. Signed-off-by: Ajesh JS Reviewed-by: Liverance Fletcher ; Clemenceau, "-------------------------------------------------------------------------" --- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff -rup linux-3.13.6/fs/btrfs/ioctl.c linux-3.13.6_btrfs/fs/btrfs/ioctl.c --- linux-3.13.6/fs/btrfs/ioctl.c 2014-03-07 11:37:02.000000000 +0530 +++ linux-3.13.6_btrfs/fs/btrfs/ioctl.c 2014-03-19 14:25:28.375139699 +0530 @@ -1636,6 +1636,68 @@ out: return ret; } +static noinline int btrfs_ioctl_subvol_modify(struct file *file, + void __user *arg) +{ + struct btrfs_ioctl_vol_args_v2 *vol_args; + struct inode *inode = file_inode(file); + struct btrfs_root *root = BTRFS_I(inode)->root; + struct btrfs_trans_handle *trans; + u64 root_flags; + u64 flags; + int ret = 0; + + ret = mnt_want_write_file(file); + if (ret) + goto out; + + if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID) { + ret = -EINVAL; + goto out_drop_write; + } + vol_args = memdup_user(arg, sizeof(*vol_args)); + if (IS_ERR(vol_args)) + goto out_drop_write; + vol_args->name[BTRFS_SUBVOL_NAME_MAX] = '\0'; + flags = vol_args->flags; + if (!inode_owner_or_capable(inode)) { + ret = -EACCES; + goto out_drop_write; + } + + down_write(&root->fs_info->subvol_sem); + root_flags = btrfs_root_flags(&root->root_item); + + if (flags & BTRFS_SUBVOL_RDONLY) { + btrfs_set_root_flags(&root->root_item, + root_flags | BTRFS_ROOT_SUBVOL_RDONLY); + printk(KERN_INFO "Setting %s to ro\n", vol_args->name); + } else { + btrfs_set_root_flags(&root->root_item, + root_flags & ~BTRFS_ROOT_SUBVOL_RDONLY); + printk(KERN_INFO "Setting %s to rw\n", vol_args->name); + } + + trans = btrfs_start_transaction(root, 1); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + goto out_reset; + } + + ret = btrfs_update_root(trans, root->fs_info->tree_root, + &root->root_key, &root->root_item); + btrfs_commit_transaction(trans, root); + +out_reset: + if (ret) + btrfs_set_root_flags(&root->root_item, root_flags); + up_write(&root->fs_info->subvol_sem); +out_drop_write: + mnt_drop_write_file(file); +out: + return ret; +} + static noinline int btrfs_ioctl_subvol_getflags(struct file *file, void __user *arg) { @@ -4509,6 +4571,8 @@ long btrfs_ioctl(struct file *file, unsi return btrfs_ioctl_snap_create(file, argp, 1); case BTRFS_IOC_SUBVOL_CREATE_V2: return btrfs_ioctl_snap_create_v2(file, argp, 1); + case BTRFS_IOC_SUBVOL_MODIFY: + return btrfs_ioctl_subvol_modify(file, argp); case BTRFS_IOC_SNAP_DESTROY: return btrfs_ioctl_snap_destroy(file, argp); case BTRFS_IOC_SUBVOL_GETFLAGS: diff -rup linux-3.13.6/include/uapi/linux/btrfs.h linux-3.13.6_btrfs/include/uapi/linux/btrfs.h --- linux-3.13.6/include/uapi/linux/btrfs.h 2014-03-07 11:37:02.000000000 +0530 +++ linux-3.13.6_btrfs/include/uapi/linux/btrfs.h 2014-03-19 15:34:30.648255239 +0530 @@ -606,5 +606,7 @@ static inline char *btrfs_err_str(enum b struct btrfs_ioctl_dev_replace_args) #define BTRFS_IOC_FILE_EXTENT_SAME _IOWR(BTRFS_IOCTL_MAGIC, 54, \ struct btrfs_ioctl_same_args) +#define BTRFS_IOC_SUBVOL_MODIFY _IOW(BTRFS_IOCTL_MAGIC, 55, \ + struct btrfs_ioctl_vol_args_v2) #endif /* _UAPI_LINUX_BTRFS_H */