From patchwork Mon Sep 5 07:30:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jeff.liu" X-Patchwork-Id: 1124642 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p857UuEs022531 for ; Mon, 5 Sep 2011 07:30:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751257Ab1IEHaf (ORCPT ); Mon, 5 Sep 2011 03:30:35 -0400 Received: from rcsinet15.oracle.com ([148.87.113.117]:51098 "EHLO rcsinet15.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751237Ab1IEHae (ORCPT ); Mon, 5 Sep 2011 03:30:34 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p857UFVQ023300 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 5 Sep 2011 07:30:17 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p857UERC022742 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 5 Sep 2011 07:30:15 GMT Received: from abhmt113.oracle.com (abhmt113.oracle.com [141.146.116.65]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p857U9iG021787; Mon, 5 Sep 2011 02:30:09 -0500 Received: from [192.168.1.103] (/221.223.119.224) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 05 Sep 2011 00:30:08 -0700 Message-ID: <4E647A7B.7000009@oracle.com> Date: Mon, 05 Sep 2011 15:30:03 +0800 From: Jeff Liu Reply-To: jeff.liu@oracle.com Organization: Oracle User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 To: linux-btrfs@vger.kernel.org, lizf@cn.fujitsu.com CC: Hugo Mills , dsterba@suse.cz, Chris Mason Subject: [PATCH] Btrfs: added new ioctl to set fs label V3 References: <4E5F47C7.3030803@oracle.com> <4E5F7216.7040909@oracle.com> <20110902125208.GF11678@ds.suse.cz> <4E60D67E.2070903@oracle.com> <20110902154810.GH11678@ds.suse.cz> <46CBCF59-89E1-4A80-B85D-17C65F695247@oracle.com> <20110904170301.GE9907@carfax.org.uk> In-Reply-To: <20110904170301.GE9907@carfax.org.uk> X-Source-IP: acsinet22.oracle.com [141.146.126.238] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090202.4E647A8A.0019:SCFMA922111, ss=1, re=-4.000, fgs=0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 05 Sep 2011 07:31:02 +0000 (UTC) Hello, According to Hugo and David's advise, the ioctl number of BTRFS_IOC_FS_SETLABEL ioctl was changed to 50 now. Signed-off-by: Jie Liu --- fs/btrfs/ctree.h | 4 ++++ fs/btrfs/ioctl.c | 36 ++++++++++++++++++++++++++++++++++++ fs/btrfs/ioctl.h | 2 ++ 3 files changed, 42 insertions(+), 0 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 03912c5..a4669f0 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1259,6 +1259,10 @@ struct btrfs_ioctl_defrag_range_args { }; +struct btrfs_ioctl_fs_label_args { + char label[BTRFS_LABEL_SIZE]; +}; + /* * inode items have the data typically returned from stat and store other * info about object characteristics. There is one for every file and dir in diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 970977a..c872e88 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -268,6 +268,40 @@ static int btrfs_ioctl_getversion(struct file *file, int __user *arg) return put_user(inode->i_generation, arg); } +static int btrfs_ioctl_fs_setlabel(struct btrfs_root *root, void __user *arg) +{ + struct btrfs_super_block *super_block = &(root->fs_info->super_copy); + struct btrfs_ioctl_fs_label_args *label_args; + struct btrfs_trans_handle *trans; + int ret; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (btrfs_root_readonly(root)) + return -EROFS; + + label_args = memdup_user(arg, sizeof(*label_args)); + if (IS_ERR(label_args)) + return PTR_ERR(label_args); + + label_args->label[BTRFS_LABEL_SIZE - 1] = '\0'; + + mutex_lock(&root->fs_info->volume_mutex); + trans = btrfs_start_transaction(root, 0); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + goto out_unlock; + } + strcpy(super_block->label, label_args->label); + btrfs_end_transaction(trans, root); + +out_unlock: + mutex_unlock(&root->fs_info->volume_mutex); + kfree(label_args); + return 0; +} + static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg) { struct btrfs_root *root = fdentry(file)->d_sb->s_fs_info; @@ -2876,6 +2910,8 @@ long btrfs_ioctl(struct file *file, unsigned int return btrfs_ioctl_fs_info(root, argp); case BTRFS_IOC_DEV_INFO: return btrfs_ioctl_dev_info(root, argp); + case BTRFS_IOC_FS_SETLABEL: + return btrfs_ioctl_fs_setlabel(root, argp); case BTRFS_IOC_BALANCE: return btrfs_balance(root->fs_info->dev_root); case BTRFS_IOC_CLONE: diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index ad1ea78..1117fe8 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -248,4 +248,6 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_dev_info_args) #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \ struct btrfs_ioctl_fs_info_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \ + struct btrfs_ioctl_fs_label_args) #endif