diff mbox

Btrfs: Add get/set label ioctl

Message ID 1346229961-635-1-git-send-email-Anand.Jain@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Anand Jain Aug. 29, 2012, 8:46 a.m. UTC
From: Anand Jain <anand.jain@oracle.com>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/ctree.h |   10 ++++++++++
 fs/btrfs/ioctl.c |   30 ++++++++++++++++++++++++++++++
 fs/btrfs/ioctl.h |    2 ++
 3 files changed, 42 insertions(+), 0 deletions(-)

Comments

jeff.liu Aug. 29, 2012, 9 a.m. UTC | #1
Hi Anand,

I have posted a patch for set label back to last year, which can be
found at:
https://patchwork.kernel.org/patch/1124642/

Besides that,  we have discussed to use 50 as the ioctl(2) number at
that time.

task assignment in our wiki page:
https://btrfs.wiki.kernel.org/index.php/Project_ideas#Set.2Fchange_file_system_label

Thanks,
-Jeff

On 08/29/12 16:46, Anand jain wrote:
> From: Anand Jain <anand.jain@oracle.com>
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  fs/btrfs/ctree.h |   10 ++++++++++
>  fs/btrfs/ioctl.c |   30 ++++++++++++++++++++++++++++++
>  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 4bab807..eff506f 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -2583,6 +2583,16 @@ BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
>  BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
>  			 cache_generation, 64);
>  
> +static inline char * btrfs_super_label(struct btrfs_super_block *s)
> +{
> +	return s->label;
> +}
> +static inline void btrfs_set_super_label(struct btrfs_super_block *s,
> +	char *val)
> +{
> +	memcpy(s->label,val,BTRFS_LABEL_SIZE);
> +}
> +
>  static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
>  {
>  	int t = btrfs_super_csum_type(s);
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 7bb7556..b472942 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -3687,6 +3687,32 @@ out:
>  	return ret;
>  }
>  
> +static int btrfs_ioctl_get_label(struct btrfs_root *root, void __user *arg)
> +{
> +	char *label;
> +	label = btrfs_super_label(root->fs_info->super_copy);
> +	if (copy_to_user(arg, label, BTRFS_LABEL_SIZE))
> +		return -EFAULT;
> +	return 0;
> +}
> +
> +static int btrfs_ioctl_set_label(struct btrfs_root *root, void __user *arg)
> +{
> +	struct btrfs_trans_handle *trans;
> +	char label[BTRFS_LABEL_SIZE+1];
> +
> +	if (!capable(CAP_SYS_ADMIN))
> +		return -EPERM;
> +	if (copy_from_user(label, arg, BTRFS_LABEL_SIZE))
> +		return -EFAULT;
> +	label[BTRFS_LABEL_SIZE] = '\0';
> +	trans = btrfs_start_transaction(root, 1);
> +	btrfs_set_super_label(root->fs_info->super_copy, label);
> +	btrfs_commit_transaction(trans, root);
> +
> +	return 0;
> +}
> +
>  long btrfs_ioctl(struct file *file, unsigned int
>  		cmd, unsigned long arg)
>  {
> @@ -3785,6 +3811,10 @@ long btrfs_ioctl(struct file *file, unsigned int
>  		return btrfs_ioctl_qgroup_create(root, argp);
>  	case BTRFS_IOC_QGROUP_LIMIT:
>  		return btrfs_ioctl_qgroup_limit(root, argp);
> +	case BTRFS_IOC_GET_LABEL:
> +		return btrfs_ioctl_get_label(root, argp);
> +	case BTRFS_IOC_SET_LABEL:
> +		return btrfs_ioctl_set_label(root, argp);
>  	}
>  
>  	return -ENOTTY;
> diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
> index 731e287..0c60fcb 100644
> --- a/fs/btrfs/ioctl.h
> +++ b/fs/btrfs/ioctl.h
> @@ -453,4 +453,6 @@ struct btrfs_ioctl_send_args {
>  			       struct btrfs_ioctl_qgroup_limit_args)
>  #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
>  				      struct btrfs_ioctl_get_dev_stats)
> +#define BTRFS_IOC_GET_LABEL _IOR(BTRFS_IOCTL_MAGIC, 53, __u64)
> +#define BTRFS_IOC_SET_LABEL _IOW(BTRFS_IOCTL_MAGIC, 54, __u64)
>  #endif


--
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
Anand Jain Aug. 30, 2012, 1:54 a.m. UTC | #2
Ah. I missed that. Thanks.
  So should use your original patch.

-Anand

On 29/08/12 17:00, Jie Liu wrote:
> Hi Anand,
>
> I have posted a patch for set label back to last year, which can be
> found at:
> https://patchwork.kernel.org/patch/1124642/
>
> Besides that,  we have discussed to use 50 as the ioctl(2) number at
> that time.
>
> task assignment in our wiki page:
> https://btrfs.wiki.kernel.org/index.php/Project_ideas#Set.2Fchange_file_system_label
>
> Thanks,
> -Jeff
>
> On 08/29/12 16:46, Anand jain wrote:
>> From: Anand Jain<anand.jain@oracle.com>
>>
>> Signed-off-by: Anand Jain<anand.jain@oracle.com>
>> ---
>>   fs/btrfs/ctree.h |   10 ++++++++++
>>   fs/btrfs/ioctl.c |   30 ++++++++++++++++++++++++++++++
>>   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 4bab807..eff506f 100644
>> --- a/fs/btrfs/ctree.h
>> +++ b/fs/btrfs/ctree.h
>> @@ -2583,6 +2583,16 @@ BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
>>   BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
>>   			 cache_generation, 64);
>>
>> +static inline char * btrfs_super_label(struct btrfs_super_block *s)
>> +{
>> +	return s->label;
>> +}
>> +static inline void btrfs_set_super_label(struct btrfs_super_block *s,
>> +	char *val)
>> +{
>> +	memcpy(s->label,val,BTRFS_LABEL_SIZE);
>> +}
>> +
>>   static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
>>   {
>>   	int t = btrfs_super_csum_type(s);
>> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
>> index 7bb7556..b472942 100644
>> --- a/fs/btrfs/ioctl.c
>> +++ b/fs/btrfs/ioctl.c
>> @@ -3687,6 +3687,32 @@ out:
>>   	return ret;
>>   }
>>
>> +static int btrfs_ioctl_get_label(struct btrfs_root *root, void __user *arg)
>> +{
>> +	char *label;
>> +	label = btrfs_super_label(root->fs_info->super_copy);
>> +	if (copy_to_user(arg, label, BTRFS_LABEL_SIZE))
>> +		return -EFAULT;
>> +	return 0;
>> +}
>> +
>> +static int btrfs_ioctl_set_label(struct btrfs_root *root, void __user *arg)
>> +{
>> +	struct btrfs_trans_handle *trans;
>> +	char label[BTRFS_LABEL_SIZE+1];
>> +
>> +	if (!capable(CAP_SYS_ADMIN))
>> +		return -EPERM;
>> +	if (copy_from_user(label, arg, BTRFS_LABEL_SIZE))
>> +		return -EFAULT;
>> +	label[BTRFS_LABEL_SIZE] = '\0';
>> +	trans = btrfs_start_transaction(root, 1);
>> +	btrfs_set_super_label(root->fs_info->super_copy, label);
>> +	btrfs_commit_transaction(trans, root);
>> +
>> +	return 0;
>> +}
>> +
>>   long btrfs_ioctl(struct file *file, unsigned int
>>   		cmd, unsigned long arg)
>>   {
>> @@ -3785,6 +3811,10 @@ long btrfs_ioctl(struct file *file, unsigned int
>>   		return btrfs_ioctl_qgroup_create(root, argp);
>>   	case BTRFS_IOC_QGROUP_LIMIT:
>>   		return btrfs_ioctl_qgroup_limit(root, argp);
>> +	case BTRFS_IOC_GET_LABEL:
>> +		return btrfs_ioctl_get_label(root, argp);
>> +	case BTRFS_IOC_SET_LABEL:
>> +		return btrfs_ioctl_set_label(root, argp);
>>   	}
>>
>>   	return -ENOTTY;
>> diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
>> index 731e287..0c60fcb 100644
>> --- a/fs/btrfs/ioctl.h
>> +++ b/fs/btrfs/ioctl.h
>> @@ -453,4 +453,6 @@ struct btrfs_ioctl_send_args {
>>   			       struct btrfs_ioctl_qgroup_limit_args)
>>   #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
>>   				      struct btrfs_ioctl_get_dev_stats)
>> +#define BTRFS_IOC_GET_LABEL _IOR(BTRFS_IOCTL_MAGIC, 53, __u64)
>> +#define BTRFS_IOC_SET_LABEL _IOW(BTRFS_IOCTL_MAGIC, 54, __u64)
>>   #endif
>
>
> --
> 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
--
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
Anand Jain Aug. 30, 2012, 5:44 a.m. UTC | #3
Jeff,

  I don't find the get label ioctl part unless I am missing something.
  Any idea?

Thxs, -Anand


On 30/08/12 09:54, Anand Jain wrote:
>
> Ah. I missed that. Thanks.
> So should use your original patch.
>
> -Anand
>
> On 29/08/12 17:00, Jie Liu wrote:
>> Hi Anand,
>>
>> I have posted a patch for set label back to last year, which can be
>> found at:
>> https://patchwork.kernel.org/patch/1124642/
>>
>> Besides that, we have discussed to use 50 as the ioctl(2) number at
>> that time.
>>
>> task assignment in our wiki page:
>> https://btrfs.wiki.kernel.org/index.php/Project_ideas#Set.2Fchange_file_system_label
>>
>> Thanks,
>> -Jeff
>>
>> On 08/29/12 16:46, Anand jain wrote:
>>> From: Anand Jain<anand.jain@oracle.com>
>>>
>>> Signed-off-by: Anand Jain<anand.jain@oracle.com>
>>> ---
>>> fs/btrfs/ctree.h | 10 ++++++++++
>>> fs/btrfs/ioctl.c | 30 ++++++++++++++++++++++++++++++
>>> 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 4bab807..eff506f 100644
>>> --- a/fs/btrfs/ctree.h
>>> +++ b/fs/btrfs/ctree.h
>>> @@ -2583,6 +2583,16 @@ BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
>>> BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
>>> cache_generation, 64);
>>>
>>> +static inline char * btrfs_super_label(struct btrfs_super_block *s)
>>> +{
>>> + return s->label;
>>> +}
>>> +static inline void btrfs_set_super_label(struct btrfs_super_block *s,
>>> + char *val)
>>> +{
>>> + memcpy(s->label,val,BTRFS_LABEL_SIZE);
>>> +}
>>> +
>>> static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
>>> {
>>> int t = btrfs_super_csum_type(s);
>>> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
>>> index 7bb7556..b472942 100644
>>> --- a/fs/btrfs/ioctl.c
>>> +++ b/fs/btrfs/ioctl.c
>>> @@ -3687,6 +3687,32 @@ out:
>>> return ret;
>>> }
>>>
>>> +static int btrfs_ioctl_get_label(struct btrfs_root *root, void __user *arg)
>>> +{
>>> + char *label;
>>> + label = btrfs_super_label(root->fs_info->super_copy);
>>> + if (copy_to_user(arg, label, BTRFS_LABEL_SIZE))
>>> + return -EFAULT;
>>> + return 0;
>>> +}
>>> +
>>> +static int btrfs_ioctl_set_label(struct btrfs_root *root, void __user *arg)
>>> +{
>>> + struct btrfs_trans_handle *trans;
>>> + char label[BTRFS_LABEL_SIZE+1];
>>> +
>>> + if (!capable(CAP_SYS_ADMIN))
>>> + return -EPERM;
>>> + if (copy_from_user(label, arg, BTRFS_LABEL_SIZE))
>>> + return -EFAULT;
>>> + label[BTRFS_LABEL_SIZE] = '\0';
>>> + trans = btrfs_start_transaction(root, 1);
>>> + btrfs_set_super_label(root->fs_info->super_copy, label);
>>> + btrfs_commit_transaction(trans, root);
>>> +
>>> + return 0;
>>> +}
>>> +
>>> long btrfs_ioctl(struct file *file, unsigned int
>>> cmd, unsigned long arg)
>>> {
>>> @@ -3785,6 +3811,10 @@ long btrfs_ioctl(struct file *file, unsigned int
>>> return btrfs_ioctl_qgroup_create(root, argp);
>>> case BTRFS_IOC_QGROUP_LIMIT:
>>> return btrfs_ioctl_qgroup_limit(root, argp);
>>> + case BTRFS_IOC_GET_LABEL:
>>> + return btrfs_ioctl_get_label(root, argp);
>>> + case BTRFS_IOC_SET_LABEL:
>>> + return btrfs_ioctl_set_label(root, argp);
>>> }
>>>
>>> return -ENOTTY;
>>> diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
>>> index 731e287..0c60fcb 100644
>>> --- a/fs/btrfs/ioctl.h
>>> +++ b/fs/btrfs/ioctl.h
>>> @@ -453,4 +453,6 @@ struct btrfs_ioctl_send_args {
>>> struct btrfs_ioctl_qgroup_limit_args)
>>> #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
>>> struct btrfs_ioctl_get_dev_stats)
>>> +#define BTRFS_IOC_GET_LABEL _IOR(BTRFS_IOCTL_MAGIC, 53, __u64)
>>> +#define BTRFS_IOC_SET_LABEL _IOW(BTRFS_IOCTL_MAGIC, 54, __u64)
>>> #endif
>>
>>
>> --
>> 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
> --
> 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
--
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
jeff.liu Aug. 30, 2012, 5:55 a.m. UTC | #4
On 08/30/12 13:44, Anand Jain wrote:
>
> Jeff,
>
>  I don't find the get label ioctl part unless I am missing something.
>  Any idea?
Yes, you're right, I have not post the get label at that time.

The original patch could be revised with this support easily.
How about using one structure and one ioctl number for both of them? i.e,

#define BTRFS_IOC_FSLABEL_CTL    _IOW(BTRFS_IOCTL_MAGIC, 50, struct
btrfs_ioctl_fslabel_ctl_args)

#define BTRFS_FSLABEL_CTL_GET    0
#define BTRFS_FSLABEL_CTL_SET    1

struct btrfs_ioctl_fslabel_ctl_args {
        char label[BTRFS_LABEL_SIZE];
        u32  flags;
};

so that get/set label from user tools would looks like,

struct btrfs_ioctl_fslabel_ctl_args arg;
arg.flags = BTRFS_FSLABEL_CTL_GET;  /* get label */
or
arg.flags = BTRFS_FSLABEL_CTL_SET; /* set label */
....

ioctl(fd, BTRFS_FSLABEL_CTL, &arg);


Thanks,
-Jeff
>
> Thxs, -Anand
>
>
> On 30/08/12 09:54, Anand Jain wrote:
>>
>> Ah. I missed that. Thanks.
>> So should use your original patch.
>>
>> -Anand
>>
>> On 29/08/12 17:00, Jie Liu wrote:
>>> Hi Anand,
>>>
>>> I have posted a patch for set label back to last year, which can be
>>> found at:
>>> https://patchwork.kernel.org/patch/1124642/
>>>
>>> Besides that, we have discussed to use 50 as the ioctl(2) number at
>>> that time.
>>>
>>> task assignment in our wiki page:
>>> https://btrfs.wiki.kernel.org/index.php/Project_ideas#Set.2Fchange_file_system_label
>>>
>>>
>>> Thanks,
>>> -Jeff
>>>
>>> On 08/29/12 16:46, Anand jain wrote:
>>>> From: Anand Jain<anand.jain@oracle.com>
>>>>
>>>> Signed-off-by: Anand Jain<anand.jain@oracle.com>
>>>> ---
>>>> fs/btrfs/ctree.h | 10 ++++++++++
>>>> fs/btrfs/ioctl.c | 30 ++++++++++++++++++++++++++++++
>>>> 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 4bab807..eff506f 100644
>>>> --- a/fs/btrfs/ctree.h
>>>> +++ b/fs/btrfs/ctree.h
>>>> @@ -2583,6 +2583,16 @@ BTRFS_SETGET_STACK_FUNCS(super_csum_type,
>>>> struct btrfs_super_block,
>>>> BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct
>>>> btrfs_super_block,
>>>> cache_generation, 64);
>>>>
>>>> +static inline char * btrfs_super_label(struct btrfs_super_block *s)
>>>> +{
>>>> + return s->label;
>>>> +}
>>>> +static inline void btrfs_set_super_label(struct btrfs_super_block *s,
>>>> + char *val)
>>>> +{
>>>> + memcpy(s->label,val,BTRFS_LABEL_SIZE);
>>>> +}
>>>> +
>>>> static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
>>>> {
>>>> int t = btrfs_super_csum_type(s);
>>>> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
>>>> index 7bb7556..b472942 100644
>>>> --- a/fs/btrfs/ioctl.c
>>>> +++ b/fs/btrfs/ioctl.c
>>>> @@ -3687,6 +3687,32 @@ out:
>>>> return ret;
>>>> }
>>>>
>>>> +static int btrfs_ioctl_get_label(struct btrfs_root *root, void
>>>> __user *arg)
>>>> +{
>>>> + char *label;
>>>> + label = btrfs_super_label(root->fs_info->super_copy);
>>>> + if (copy_to_user(arg, label, BTRFS_LABEL_SIZE))
>>>> + return -EFAULT;
>>>> + return 0;
>>>> +}
>>>> +
>>>> +static int btrfs_ioctl_set_label(struct btrfs_root *root, void
>>>> __user *arg)
>>>> +{
>>>> + struct btrfs_trans_handle *trans;
>>>> + char label[BTRFS_LABEL_SIZE+1];
>>>> +
>>>> + if (!capable(CAP_SYS_ADMIN))
>>>> + return -EPERM;
>>>> + if (copy_from_user(label, arg, BTRFS_LABEL_SIZE))
>>>> + return -EFAULT;
>>>> + label[BTRFS_LABEL_SIZE] = '\0';
>>>> + trans = btrfs_start_transaction(root, 1);
>>>> + btrfs_set_super_label(root->fs_info->super_copy, label);
>>>> + btrfs_commit_transaction(trans, root);
>>>> +
>>>> + return 0;
>>>> +}
>>>> +
>>>> long btrfs_ioctl(struct file *file, unsigned int
>>>> cmd, unsigned long arg)
>>>> {
>>>> @@ -3785,6 +3811,10 @@ long btrfs_ioctl(struct file *file, unsigned
>>>> int
>>>> return btrfs_ioctl_qgroup_create(root, argp);
>>>> case BTRFS_IOC_QGROUP_LIMIT:
>>>> return btrfs_ioctl_qgroup_limit(root, argp);
>>>> + case BTRFS_IOC_GET_LABEL:
>>>> + return btrfs_ioctl_get_label(root, argp);
>>>> + case BTRFS_IOC_SET_LABEL:
>>>> + return btrfs_ioctl_set_label(root, argp);
>>>> }
>>>>
>>>> return -ENOTTY;
>>>> diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
>>>> index 731e287..0c60fcb 100644
>>>> --- a/fs/btrfs/ioctl.h
>>>> +++ b/fs/btrfs/ioctl.h
>>>> @@ -453,4 +453,6 @@ struct btrfs_ioctl_send_args {
>>>> struct btrfs_ioctl_qgroup_limit_args)
>>>> #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
>>>> struct btrfs_ioctl_get_dev_stats)
>>>> +#define BTRFS_IOC_GET_LABEL _IOR(BTRFS_IOCTL_MAGIC, 53, __u64)
>>>> +#define BTRFS_IOC_SET_LABEL _IOW(BTRFS_IOCTL_MAGIC, 54, __u64)
>>>> #endif
>>>
>>>
>>> -- 
>>> 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
>> -- 
>> 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

--
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
jeff.liu Aug. 30, 2012, 6:04 a.m. UTC | #5
On 08/30/12 13:55, Jie Liu wrote:
> On 08/30/12 13:44, Anand Jain wrote:
>> Jeff,
>>
>>  I don't find the get label ioctl part unless I am missing something.
>>  Any idea?
Sorry, I took for granted that this patch has already been merged last
year. :(

To honor your efforts, I'd like to re-send a revised version with set
label only, if other folks like it, you can proceed to
add the get label routine based on it.

Are you happy? :)

Thanks,
-Jeff
> Yes, you're right, I have not post the get label at that time.
>
> The original patch could be revised with this support easily.
> How about using one structure and one ioctl number for both of them? i.e,
>
> #define BTRFS_IOC_FSLABEL_CTL    _IOW(BTRFS_IOCTL_MAGIC, 50, struct
> btrfs_ioctl_fslabel_ctl_args)
>
> #define BTRFS_FSLABEL_CTL_GET    0
> #define BTRFS_FSLABEL_CTL_SET    1
>
> struct btrfs_ioctl_fslabel_ctl_args {
>         char label[BTRFS_LABEL_SIZE];
>         u32  flags;
> };
>
> so that get/set label from user tools would looks like,
>
> struct btrfs_ioctl_fslabel_ctl_args arg;
> arg.flags = BTRFS_FSLABEL_CTL_GET;  /* get label */
> or
> arg.flags = BTRFS_FSLABEL_CTL_SET; /* set label */
> ....
>
> ioctl(fd, BTRFS_FSLABEL_CTL, &arg);
>
>
> Thanks,
> -Jeff
>> Thxs, -Anand
>>
>>
>> On 30/08/12 09:54, Anand Jain wrote:
>>> Ah. I missed that. Thanks.
>>> So should use your original patch.
>>>
>>> -Anand
>>>
>>> On 29/08/12 17:00, Jie Liu wrote:
>>>> Hi Anand,
>>>>
>>>> I have posted a patch for set label back to last year, which can be
>>>> found at:
>>>> https://patchwork.kernel.org/patch/1124642/
>>>>
>>>> Besides that, we have discussed to use 50 as the ioctl(2) number at
>>>> that time.
>>>>
>>>> task assignment in our wiki page:
>>>> https://btrfs.wiki.kernel.org/index.php/Project_ideas#Set.2Fchange_file_system_label
>>>>
>>>>
>>>> Thanks,
>>>> -Jeff
>>>>
>>>> On 08/29/12 16:46, Anand jain wrote:
>>>>> From: Anand Jain<anand.jain@oracle.com>
>>>>>
>>>>> Signed-off-by: Anand Jain<anand.jain@oracle.com>
>>>>> ---
>>>>> fs/btrfs/ctree.h | 10 ++++++++++
>>>>> fs/btrfs/ioctl.c | 30 ++++++++++++++++++++++++++++++
>>>>> 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 4bab807..eff506f 100644
>>>>> --- a/fs/btrfs/ctree.h
>>>>> +++ b/fs/btrfs/ctree.h
>>>>> @@ -2583,6 +2583,16 @@ BTRFS_SETGET_STACK_FUNCS(super_csum_type,
>>>>> struct btrfs_super_block,
>>>>> BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct
>>>>> btrfs_super_block,
>>>>> cache_generation, 64);
>>>>>
>>>>> +static inline char * btrfs_super_label(struct btrfs_super_block *s)
>>>>> +{
>>>>> + return s->label;
>>>>> +}
>>>>> +static inline void btrfs_set_super_label(struct btrfs_super_block *s,
>>>>> + char *val)
>>>>> +{
>>>>> + memcpy(s->label,val,BTRFS_LABEL_SIZE);
>>>>> +}
>>>>> +
>>>>> static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
>>>>> {
>>>>> int t = btrfs_super_csum_type(s);
>>>>> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
>>>>> index 7bb7556..b472942 100644
>>>>> --- a/fs/btrfs/ioctl.c
>>>>> +++ b/fs/btrfs/ioctl.c
>>>>> @@ -3687,6 +3687,32 @@ out:
>>>>> return ret;
>>>>> }
>>>>>
>>>>> +static int btrfs_ioctl_get_label(struct btrfs_root *root, void
>>>>> __user *arg)
>>>>> +{
>>>>> + char *label;
>>>>> + label = btrfs_super_label(root->fs_info->super_copy);
>>>>> + if (copy_to_user(arg, label, BTRFS_LABEL_SIZE))
>>>>> + return -EFAULT;
>>>>> + return 0;
>>>>> +}
>>>>> +
>>>>> +static int btrfs_ioctl_set_label(struct btrfs_root *root, void
>>>>> __user *arg)
>>>>> +{
>>>>> + struct btrfs_trans_handle *trans;
>>>>> + char label[BTRFS_LABEL_SIZE+1];
>>>>> +
>>>>> + if (!capable(CAP_SYS_ADMIN))
>>>>> + return -EPERM;
>>>>> + if (copy_from_user(label, arg, BTRFS_LABEL_SIZE))
>>>>> + return -EFAULT;
>>>>> + label[BTRFS_LABEL_SIZE] = '\0';
>>>>> + trans = btrfs_start_transaction(root, 1);
>>>>> + btrfs_set_super_label(root->fs_info->super_copy, label);
>>>>> + btrfs_commit_transaction(trans, root);
>>>>> +
>>>>> + return 0;
>>>>> +}
>>>>> +
>>>>> long btrfs_ioctl(struct file *file, unsigned int
>>>>> cmd, unsigned long arg)
>>>>> {
>>>>> @@ -3785,6 +3811,10 @@ long btrfs_ioctl(struct file *file, unsigned
>>>>> int
>>>>> return btrfs_ioctl_qgroup_create(root, argp);
>>>>> case BTRFS_IOC_QGROUP_LIMIT:
>>>>> return btrfs_ioctl_qgroup_limit(root, argp);
>>>>> + case BTRFS_IOC_GET_LABEL:
>>>>> + return btrfs_ioctl_get_label(root, argp);
>>>>> + case BTRFS_IOC_SET_LABEL:
>>>>> + return btrfs_ioctl_set_label(root, argp);
>>>>> }
>>>>>
>>>>> return -ENOTTY;
>>>>> diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
>>>>> index 731e287..0c60fcb 100644
>>>>> --- a/fs/btrfs/ioctl.h
>>>>> +++ b/fs/btrfs/ioctl.h
>>>>> @@ -453,4 +453,6 @@ struct btrfs_ioctl_send_args {
>>>>> struct btrfs_ioctl_qgroup_limit_args)
>>>>> #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
>>>>> struct btrfs_ioctl_get_dev_stats)
>>>>> +#define BTRFS_IOC_GET_LABEL _IOR(BTRFS_IOCTL_MAGIC, 53, __u64)
>>>>> +#define BTRFS_IOC_SET_LABEL _IOW(BTRFS_IOCTL_MAGIC, 54, __u64)
>>>>> #endif
>>>>
>>>> -- 
>>>> 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
>>> -- 
>>> 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
> --
> 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

--
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
Anand Jain Aug. 30, 2012, 6:28 a.m. UTC | #6
> The original patch could be revised with this support easily.
> How about using one structure and one ioctl number for both of them? i.e,
>
> #define BTRFS_IOC_FSLABEL_CTL    _IOW(BTRFS_IOCTL_MAGIC, 50, struct
> btrfs_ioctl_fslabel_ctl_args)
>
> #define BTRFS_FSLABEL_CTL_GET    0
> #define BTRFS_FSLABEL_CTL_SET    1
>
> struct btrfs_ioctl_fslabel_ctl_args {
>          char label[BTRFS_LABEL_SIZE];
>          u32  flags;
> };
>
> so that get/set label from user tools would looks like,
>
> struct btrfs_ioctl_fslabel_ctl_args arg;
> arg.flags = BTRFS_FSLABEL_CTL_GET;  /* get label */
> or
> arg.flags = BTRFS_FSLABEL_CTL_SET; /* set label */
> ....
>
> ioctl(fd, BTRFS_FSLABEL_CTL,&arg);


  I would prefer separating GET and SET label ioctl,
  (to have one operation with an ioctl define) that
  will be similar to rest of the ioctl in btrfs.
  Further we don't need ioctl-arg-struct here, unless
  if you are keeping the flags.

  And in my understanding in kernel memcpy are better
  instead of strcpy.
  
  If you could add GET that will be nicer.

  I would need this for an experiment to add the label
  for the subvol/snapshots.

Thanks, Anand
--
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
jeff.liu Aug. 30, 2012, 7:22 a.m. UTC | #7
On 08/30/12 14:28, Anand Jain wrote:
>
>> The original patch could be revised with this support easily.
>> How about using one structure and one ioctl number for both of them?
>> i.e,
>>
>> #define BTRFS_IOC_FSLABEL_CTL    _IOW(BTRFS_IOCTL_MAGIC, 50, struct
>> btrfs_ioctl_fslabel_ctl_args)
>>
>> #define BTRFS_FSLABEL_CTL_GET    0
>> #define BTRFS_FSLABEL_CTL_SET    1
>>
>> struct btrfs_ioctl_fslabel_ctl_args {
>>          char label[BTRFS_LABEL_SIZE];
>>          u32  flags;
>> };
>>
>> so that get/set label from user tools would looks like,
>>
>> struct btrfs_ioctl_fslabel_ctl_args arg;
>> arg.flags = BTRFS_FSLABEL_CTL_GET;  /* get label */
>> or
>> arg.flags = BTRFS_FSLABEL_CTL_SET; /* set label */
>> ....
>>
>> ioctl(fd, BTRFS_FSLABEL_CTL,&arg);
>
>
>  I would prefer separating GET and SET label ioctl,
>  (to have one operation with an ioctl define) that
>  will be similar to rest of the ioctl in btrfs.
>  Further we don't need ioctl-arg-struct here, unless
>  if you are keeping the flags.
>
Thanks for the suggestions.

Yes, I noticed Btrfs perform add/rm devices, as well as set/set flags,
etc... all with two separated ioctls,
It's better to make the code style in a manner consistent with them.

However, get/set label is assigned one number in previous, the next
number(51) has been assigned to David,
51 - compressed file size - David Sterba

To make the code style in a consistent manner,
We can re-assign those numbers if Chris and David would happy to hear that.

>  And in my understanding in kernel memcpy are better
>  instead of strcpy.
If we do copy binary structure/elements, memcpy is nice.
However, consider we're copying a label in string, I think the
difference between them in kernel is
same to the user lib, which means that the copy is stops or not when it
encounters a NUL.

By contrast , I think strcpy is better here, if the label is specified
with a NUL('\0', why do that?) in the middle of it,
and we do memcpy for it in kernel,  but, the user will get surprised
when he/she fetch the label and printf(3) it out.

Thanks,
-Jeff
>  
>  If you could add GET that will be nicer.
>
>  I would need this for an experiment to add the label
>  for the subvol/snapshots.
>
> Thanks, Anand

--
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 mbox

Patch

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 4bab807..eff506f 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2583,6 +2583,16 @@  BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
 BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
 			 cache_generation, 64);
 
+static inline char * btrfs_super_label(struct btrfs_super_block *s)
+{
+	return s->label;
+}
+static inline void btrfs_set_super_label(struct btrfs_super_block *s,
+	char *val)
+{
+	memcpy(s->label,val,BTRFS_LABEL_SIZE);
+}
+
 static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
 {
 	int t = btrfs_super_csum_type(s);
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 7bb7556..b472942 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3687,6 +3687,32 @@  out:
 	return ret;
 }
 
+static int btrfs_ioctl_get_label(struct btrfs_root *root, void __user *arg)
+{
+	char *label;
+	label = btrfs_super_label(root->fs_info->super_copy);
+	if (copy_to_user(arg, label, BTRFS_LABEL_SIZE))
+		return -EFAULT;
+	return 0;
+}
+
+static int btrfs_ioctl_set_label(struct btrfs_root *root, void __user *arg)
+{
+	struct btrfs_trans_handle *trans;
+	char label[BTRFS_LABEL_SIZE+1];
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+	if (copy_from_user(label, arg, BTRFS_LABEL_SIZE))
+		return -EFAULT;
+	label[BTRFS_LABEL_SIZE] = '\0';
+	trans = btrfs_start_transaction(root, 1);
+	btrfs_set_super_label(root->fs_info->super_copy, label);
+	btrfs_commit_transaction(trans, root);
+
+	return 0;
+}
+
 long btrfs_ioctl(struct file *file, unsigned int
 		cmd, unsigned long arg)
 {
@@ -3785,6 +3811,10 @@  long btrfs_ioctl(struct file *file, unsigned int
 		return btrfs_ioctl_qgroup_create(root, argp);
 	case BTRFS_IOC_QGROUP_LIMIT:
 		return btrfs_ioctl_qgroup_limit(root, argp);
+	case BTRFS_IOC_GET_LABEL:
+		return btrfs_ioctl_get_label(root, argp);
+	case BTRFS_IOC_SET_LABEL:
+		return btrfs_ioctl_set_label(root, argp);
 	}
 
 	return -ENOTTY;
diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
index 731e287..0c60fcb 100644
--- a/fs/btrfs/ioctl.h
+++ b/fs/btrfs/ioctl.h
@@ -453,4 +453,6 @@  struct btrfs_ioctl_send_args {
 			       struct btrfs_ioctl_qgroup_limit_args)
 #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
 				      struct btrfs_ioctl_get_dev_stats)
+#define BTRFS_IOC_GET_LABEL _IOR(BTRFS_IOCTL_MAGIC, 53, __u64)
+#define BTRFS_IOC_SET_LABEL _IOW(BTRFS_IOCTL_MAGIC, 54, __u64)
 #endif