aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/sysfs.c')
-rw-r--r--fs/btrfs/sysfs.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index ec6315391111..669fdf777b6c 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -355,6 +355,49 @@ static const struct attribute *allocation_attrs[] = {
355 NULL, 355 NULL,
356}; 356};
357 357
358static ssize_t btrfs_label_show(struct kobject *kobj,
359 struct kobj_attribute *a, char *buf)
360{
361 struct btrfs_fs_info *fs_info = to_fs_info(kobj);
362 return snprintf(buf, PAGE_SIZE, "%s\n", fs_info->super_copy->label);
363}
364
365static ssize_t btrfs_label_store(struct kobject *kobj,
366 struct kobj_attribute *a,
367 const char *buf, size_t len)
368{
369 struct btrfs_fs_info *fs_info = to_fs_info(kobj);
370 struct btrfs_trans_handle *trans;
371 struct btrfs_root *root = fs_info->fs_root;
372 int ret;
373
374 if (len >= BTRFS_LABEL_SIZE) {
375 pr_err("btrfs: unable to set label with more than %d bytes\n",
376 BTRFS_LABEL_SIZE - 1);
377 return -EINVAL;
378 }
379
380 trans = btrfs_start_transaction(root, 0);
381 if (IS_ERR(trans))
382 return PTR_ERR(trans);
383
384 spin_lock(&root->fs_info->super_lock);
385 strcpy(fs_info->super_copy->label, buf);
386 spin_unlock(&root->fs_info->super_lock);
387 ret = btrfs_commit_transaction(trans, root);
388
389 if (!ret)
390 return len;
391
392 return ret;
393}
394BTRFS_ATTR_RW(label, 0644, btrfs_label_show, btrfs_label_store);
395
396static struct attribute *btrfs_attrs[] = {
397 BTRFS_ATTR_PTR(label),
398 NULL,
399};
400
358static void btrfs_release_super_kobj(struct kobject *kobj) 401static void btrfs_release_super_kobj(struct kobject *kobj)
359{ 402{
360 struct btrfs_fs_info *fs_info = to_fs_info(kobj); 403 struct btrfs_fs_info *fs_info = to_fs_info(kobj);
@@ -364,6 +407,7 @@ static void btrfs_release_super_kobj(struct kobject *kobj)
364static struct kobj_type btrfs_ktype = { 407static struct kobj_type btrfs_ktype = {
365 .sysfs_ops = &kobj_sysfs_ops, 408 .sysfs_ops = &kobj_sysfs_ops,
366 .release = btrfs_release_super_kobj, 409 .release = btrfs_release_super_kobj,
410 .default_attrs = btrfs_attrs,
367}; 411};
368 412
369static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj) 413static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj)