[PATCH] Btrfs: fix race in check-integrity caused by usage of bitfield

2012-11-27 Thread Stefan Behrens
The structure member mirror_num is modified concurrently to the
structure member is_iodone. This doesn't require any locking by
design, unless everything is stored in the same 32 bits of a
bit field. This was the case and xfstest 284 was able to
trigger false warnings from the checker code. This patch
seperates the bits and fixes the race.

Signed-off-by: Stefan Behrens sbehr...@giantdisaster.de
---
 fs/btrfs/check-integrity.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 5a3e45d..a6baa8e 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -137,7 +137,7 @@ struct btrfsic_block {
unsigned int never_written:1;   /* block was added because it was
 * referenced, not because it was
 * written */
-   unsigned int mirror_num:2;  /* large enough to hold
+   unsigned int mirror_num;/* large enough to hold
 * BTRFS_SUPER_MIRROR_MAX */
struct btrfsic_dev_state *dev_state;
u64 dev_bytenr; /* key, physical byte num on disk */
-- 
1.8.0.1

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: extended attributes wiredness

2012-11-27 Thread David Arendt
Hi,

I tried to create an ext4 filesystem on a loop device and do a cp -a of
/var/lib/nfs/sm to the ext4 filesystem. Here the problem does not exist.
Perhaps ext4 has another behaviour in the sense that it doesn't store
empty attributes or doesn't return empty attributes.

I am using Gentoo and will try to do a new install on a loop device to
figure out which userspace program creates files this way.

Thanks in advance,
David Arendt

On 11/27/12 08:46, Liu Bo wrote:
 Hi,  
  
 (cc btrfs Mailing list to notify others.)

 Thanks for the helpful test.img.

 Well...after deeper debug, I'm sure that it's not a btrfs bug,
 at least not a btrfs acl/xattr bug. 
  
 The debug tree shows 
  
 item 10 key (257 INODE_ITEM 0) itemoff 3387 itemsize 160 
 inode generation 6 transid 6 size 102 block group 0 mode 40755 links 
 1 
 item 11 key (257 INODE_REF 256) itemoff 3372 itemsize 15 
 inode ref index 2 namelen 5 name: test1 
 item 12 key (257 XATTR_ITEM 367492571) itemoff 3318 itemsize 54 
 location key (0 UNKNOWN.0 0) type 8 
 namelen 24 datalen 0 name: system.posix_acl_default 
   ^^^ 
 item 13 key (257 XATTR_ITEM 2038346239) itemoff 3237 itemsize 81 
 location key (0 UNKNOWN.0 0) type 8 
 namelen 23 datalen 28 name: system.posix_acl_access 
 data ^B 
  
 == 

 so extended attribute system.posix_acl_default here has not data, which'll
 make filesystems(not just btrfs) return -ENODATA. 
  
 I guess some userspace applications may make it like that. 
  
 thanks, 
 liubo

 On Mon, Nov 26, 2012 at 06:38:06AM +0100, David Arendt wrote:
 Hi,

 I don't know if your xattr patch was meant to fix this issue, but I have
 just tested kernel 3.7-rc7 with your patch applied on another directory
 having the problem and I still have the weird behaviour.

 Thanks in advance,
 David Arendt

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Btrfs: fix a scrub regression in case of write errors

2012-11-27 Thread Stefan Behrens
This regression was introduced by the device-replace patches.
Scrub immediately stops checking those disks that have write errors.
This is nothing that happens in the real world, but it is wrong
since scrub is the tool to detect and repair defects. Fix it.

Signed-off-by: Stefan Behrens sbehr...@giantdisaster.de
---
This patch is only for btrfs-next.

 fs/btrfs/scrub.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 30ba997..8db6a64 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -2657,7 +2657,8 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
btrfs_put_block_group(cache);
if (ret)
break;
-   if (atomic64_read(dev_replace-num_write_errors)  0) {
+   if (is_dev_replace 
+   atomic64_read(dev_replace-num_write_errors)  0) {
ret = -EIO;
break;
}
-- 
1.8.0.1

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Btrfs: fix a build warning for an unused label

2012-11-27 Thread Stefan Behrens
This issue was detected by the 0-DAY kernel build testing.

fs/btrfs/volumes.c: In function 'btrfs_rm_device':
fs/btrfs/volumes.c:1505:1: warning: label 'error_close' defined but not used 
[-Wunused-label]

Signed-off-by: Stefan Behrens sbehr...@giantdisaster.de
---
This patch is only for btrfs-next.

 fs/btrfs/volumes.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 012eb7a..69d1388 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1541,7 +1541,6 @@ int btrfs_rm_device(struct btrfs_root *root, char 
*device_path)
 
 error_brelse:
brelse(bh);
-error_close:
if (bdev)
blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
 out:
-- 
1.8.0.1

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Request for review v3] [RFC] Add label support for snapshots and subvols

2012-11-27 Thread Anand jain
From: Anand Jain anand.j...@oracle.com

v2-v3:
Changes are in the btrfs kernel patch only, which accepts
review comments by Miao.
v1-v2:
This v2 patch accepts the review comments on the btrfs
kernel changes by Jan. and
Moved the get and set subvol label to under subvol sub-cmd
eg:
btrfs subvolume label /btrfs/ss5
btrfs su la /btrfs/ss5 ss5-label
btrfs su la /btrfs/ss5
ss5-label

v1:
 (This patch is for the review/test not yet for the integration).

 Here is an implementation of the feature to add label to the
 subvolume and snapshots. Which would help sysadmin to better manager
 the subvol and snapshots.

 This can be done in two ways, one - using attr which is user land
 only changes but drawback is able to change the label using the
 non btrfs cli. And the other way is to add a member to
 btrfs_root_item in the btrfs kernel to hold the label info for
 each snapshot and subvol. The drawback here is having to introduce
 V3 version of this structure. If there is any better way pls do share.
 The patch code is for the review.

Any comments/suggestion welcome.

Below is a demo of this new feature.

 btrfs fi label -t /btrfs/sv1 Prod-DB

 btrfs fi label -t /btrfs/sv1
Prod-DB

 btrfs su snap /btrfs/sv1 /btrfs/snap1-sv1
Create a snapshot of '/btrfs/sv1' in '/btrfs/snap1-sv1'
 btrfs fi label -t /btrfs/snap1-sv1

 btrfs fi label -t /btrfs/snap1-sv1 Prod-DB-sand-box-testing
 
 btrfs fi label -t /btrfs/snap1-sv1
Prod-DB-sand-box-testing


Anand Jain (3):
  Btrfs-progs: move open_file_or_dir() to utils.c
  Btrfs-progs: add feature to label subvol and snapshot
  Btrfs-progs: cmd option to show or set the subvol label

 Makefile |4 ++--
 btrfsctl.c   |7 ---
 btrfslabel.c |   45 +
 btrfslabel.h |4 +++-
 cmds-balance.c   |1 +
 cmds-inspect.c   |1 +
 cmds-qgroup.c|1 +
 cmds-quota.c |1 +
 cmds-subvolume.c |   38 ++
 commands.h   |3 ---
 common.c |   46 --
 ctree.h  |4 +++-
 ioctl.h  |2 ++
 man/btrfs.8.in   |6 ++
 print-tree.c |2 ++
 utils.c  |   30 --
 utils.h  |3 +++
 17 files changed, 140 insertions(+), 58 deletions(-)
 delete mode 100644 common.c

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] Btrfs: add label to snapshot and subvol

2012-11-27 Thread Anand jain
From: Anand Jain anand.j...@oracle.com

v3-v2:
accepts Miao' review comment.

Signed-off-by: Anand Jain anand.j...@oracle.com
Reviewed-by: Jan Schmidt list.bt...@jan-o-sch.net
Reviewed-by: Miao Xie mi...@cn.fujitsu.com
---
 fs/btrfs/ctree.h   |   12 +-
 fs/btrfs/ioctl.c   |   55 
 fs/btrfs/ioctl.h   |2 +
 fs/btrfs/transaction.c |1 +
 4 files changed, 69 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 994d255..039e11c 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -383,6 +383,7 @@ struct btrfs_header {
  */
 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
 #define BTRFS_LABEL_SIZE 256
+#define BTRFS_SUBVOL_LABEL_SIZE 32
 
 /*
  * just in case we somehow lose the roots and are not able to mount,
@@ -759,7 +760,8 @@ struct btrfs_root_item {
struct btrfs_timespec otime;
struct btrfs_timespec stime;
struct btrfs_timespec rtime;
-   __le64 reserved[8]; /* for future */
+   char label[BTRFS_SUBVOL_LABEL_SIZE];
+   __le64 reserved[4]; /* for future */
 } __attribute__ ((__packed__));
 
 /*
@@ -2441,6 +2443,14 @@ static inline bool btrfs_root_readonly(struct btrfs_root 
*root)
 {
return (root-root_item.flags  cpu_to_le64(BTRFS_ROOT_SUBVOL_RDONLY)) 
!= 0;
 }
+static inline char * btrfs_root_label(struct btrfs_root_item *root_item)
+{
+   return (root_item-label);
+}
+static inline void btrfs_root_set_label(struct btrfs_root_item *root_item, 
char *val)
+{
+   memcpy(root_item-label, val, BTRFS_SUBVOL_LABEL_SIZE);
+}
 
 /* struct btrfs_root_backup */
 BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup,
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index e58bd9d..f0b3d9d 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3725,6 +3725,57 @@ static int btrfs_ioctl_set_label(struct btrfs_root 
*root, void __user *arg)
return 0;
 }
 
+static int btrfs_ioctl_subvol_getlabel(struct btrfs_root *root,
+   void __user *arg)
+{
+   char *label;
+
+   label = btrfs_root_label(root-root_item);
+   if (copy_to_user(arg, label, BTRFS_SUBVOL_LABEL_SIZE))
+   return -EFAULT;
+   return 0;
+}
+
+static int btrfs_ioctl_subvol_setlabel(struct file *file,
+   void __user *arg)
+{
+   char label[BTRFS_SUBVOL_LABEL_SIZE+1];
+   struct btrfs_trans_handle *trans;
+   struct btrfs_root *root = BTRFS_I(fdentry(file)-d_inode)-root;
+   struct inode *inode = file-f_path.dentry-d_inode;
+   int ret;
+
+   if (btrfs_root_readonly(root))
+   return -EROFS;
+
+   if (!inode_owner_or_capable(inode))
+   return -EACCES;
+
+   ret = mnt_want_write_file(file);
+   if (ret)
+   return ret;
+
+   if (copy_from_user(label, arg, BTRFS_SUBVOL_LABEL_SIZE)) {
+   ret = -EFAULT;
+   goto out;
+   }
+
+   mutex_lock(inode-i_mutex);
+   trans = btrfs_join_transaction(root);
+   if (IS_ERR(trans)) {
+   ret = PTR_ERR(trans);
+   mutex_unlock(inode-i_mutex);
+   goto out;
+   }
+   btrfs_root_set_label(root-root_item, label);
+   btrfs_end_transaction(trans, root);
+   mutex_unlock(inode-i_mutex);
+
+out:
+   mnt_drop_write_file(file);
+   return ret;
+}
+
 long btrfs_ioctl(struct file *file, unsigned int
cmd, unsigned long arg)
 {
@@ -3827,6 +3878,10 @@ long btrfs_ioctl(struct file *file, unsigned int
return btrfs_ioctl_get_label(root, argp);
case BTRFS_IOC_SET_LABEL:
return btrfs_ioctl_set_label(root, argp);
+   case BTRFS_IOC_SUBVOL_GETLABEL:
+   return btrfs_ioctl_subvol_getlabel(root, argp);
+   case BTRFS_IOC_SUBVOL_SETLABEL:
+   return btrfs_ioctl_subvol_setlabel(file, argp);
}
 
return -ENOTTY;
diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
index 0c60fcb..1009a0c 100644
--- a/fs/btrfs/ioctl.h
+++ b/fs/btrfs/ioctl.h
@@ -455,4 +455,6 @@ struct btrfs_ioctl_send_args {
  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)
+#define BTRFS_IOC_SUBVOL_GETLABEL _IOWR(BTRFS_IOCTL_MAGIC, 55, __u64)
+#define BTRFS_IOC_SUBVOL_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 56, __u64)
 #endif
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 04bbfb1..0a3f8b3 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1118,6 +1118,7 @@ static noinline int create_pending_snapshot(struct 
btrfs_trans_handle *trans,
memset(new_root_item-rtime, 0, sizeof(new_root_item-rtime));
btrfs_set_root_stransid(new_root_item, 0);
btrfs_set_root_rtransid(new_root_item, 0);
+   memset(new_root_item-label, 0, 

[PATCH 1/3] Btrfs-progs: move open_file_or_dir() to utils.c

2012-11-27 Thread Anand jain
From: Anand Jain anand.j...@oracle.com

The definition of the function open_file_or_dir() is moved from common.c
to utils.c in order to be able to share some common code between scrub
and the device stats in the following step. That common code uses
open_file_or_dir(). Since open_file_or_dir() makes use of the function
dirfd(3), the required XOPEN version was raised from 6 to 7.

Signed-off-by: Anand Jain anand.j...@oracle.com
Original-Signed-off-by: Stefan Behrens sbehr...@giantdisaster.de
---
 Makefile |4 ++--
 btrfsctl.c   |7 ---
 cmds-balance.c   |1 +
 cmds-inspect.c   |1 +
 cmds-qgroup.c|1 +
 cmds-quota.c |1 +
 cmds-subvolume.c |1 +
 commands.h   |3 ---
 common.c |   46 --
 utils.c  |   30 --
 utils.h  |3 +++
 11 files changed, 42 insertions(+), 56 deletions(-)
 delete mode 100644 common.c

diff --git a/Makefile b/Makefile
index 4894903..8576d90 100644
--- a/Makefile
+++ b/Makefile
@@ -41,8 +41,8 @@ all: version $(progs) manpages
 version:
bash version.sh
 
-btrfs: $(objects) btrfs.o help.o common.o $(cmds_objects)
-   $(CC) $(CFLAGS) -o btrfs btrfs.o help.o common.o $(cmds_objects) \
+btrfs: $(objects) btrfs.o help.o $(cmds_objects)
+   $(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
$(objects) $(LDFLAGS) $(LIBS) -lpthread
 
 calc-size: $(objects) calc-size.o
diff --git a/btrfsctl.c b/btrfsctl.c
index 518684c..049a5f3 100644
--- a/btrfsctl.c
+++ b/btrfsctl.c
@@ -63,7 +63,7 @@ static void print_usage(void)
exit(1);
 }
 
-static int open_file_or_dir(const char *fname)
+static int btrfsctl_open_file_or_dir(const char *fname)
 {
int ret;
struct stat st;
@@ -91,6 +91,7 @@ static int open_file_or_dir(const char *fname)
}
return fd;
 }
+
 int main(int ac, char **av)
 {
char *fname = NULL;
@@ -128,7 +129,7 @@ int main(int ac, char **av)
snap_location = strdup(fullpath);
snap_location = dirname(snap_location);
 
-   snap_fd = open_file_or_dir(snap_location);
+   snap_fd = btrfsctl_open_file_or_dir(snap_location);
 
name = strdup(fullpath);
name = basename(name);
@@ -238,7 +239,7 @@ int main(int ac, char **av)
}
name = fname;
 } else {
-   fd = open_file_or_dir(fname);
+   fd = btrfsctl_open_file_or_dir(fname);
 }
 
if (name) {
diff --git a/cmds-balance.c b/cmds-balance.c
index 38a7426..6268b61 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -28,6 +28,7 @@
 #include volumes.h
 
 #include commands.h
+#include utils.h
 
 static const char * const balance_cmd_group_usage[] = {
btrfs [filesystem] balance command [options] path,
diff --git a/cmds-inspect.c b/cmds-inspect.c
index edabff5..79e069b 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -22,6 +22,7 @@
 
 #include kerncompat.h
 #include ioctl.h
+#include utils.h
 
 #include commands.h
 #include btrfs-list.h
diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 1525c11..cafc284 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -24,6 +24,7 @@
 #include ioctl.h
 
 #include commands.h
+#include utils.h
 
 static const char * const qgroup_cmd_group_usage[] = {
btrfs qgroup command [options] path,
diff --git a/cmds-quota.c b/cmds-quota.c
index cf9ad97..8481514 100644
--- a/cmds-quota.c
+++ b/cmds-quota.c
@@ -23,6 +23,7 @@
 #include ioctl.h
 
 #include commands.h
+#include utils.h
 
 static const char * const quota_cmd_group_usage[] = {
btrfs quota command [options] path,
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index ac39f7b..e3cdb1e 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -32,6 +32,7 @@
 #include ctree.h
 #include commands.h
 #include btrfs-list.h
+#include utils.h
 
 static const char * const subvolume_cmd_group_usage[] = {
btrfs subvolume command args,
diff --git a/commands.h b/commands.h
index bb6d2dd..8114a73 100644
--- a/commands.h
+++ b/commands.h
@@ -79,9 +79,6 @@ void help_ambiguous_token(const char *arg, const struct 
cmd_group *grp);
 
 void help_command_group(const struct cmd_group *grp, int argc, char **argv);
 
-/* common.c */
-int open_file_or_dir(const char *fname);
-
 extern const struct cmd_group subvolume_cmd_group;
 extern const struct cmd_group filesystem_cmd_group;
 extern const struct cmd_group balance_cmd_group;
diff --git a/common.c b/common.c
deleted file mode 100644
index 03f6570..000
--- a/common.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License v2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; 

[PATCH 3/3] Btrfs-progs: cmd option to show or set the subvol label

2012-11-27 Thread Anand jain
From: Anand Jain anand.j...@oracle.com

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 cmds-subvolume.c |   37 +
 man/btrfs.8.in   |6 ++
 2 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index e3cdb1e..759eade 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -33,6 +33,7 @@
 #include commands.h
 #include btrfs-list.h
 #include utils.h
+#include btrfslabel.h
 
 static const char * const subvolume_cmd_group_usage[] = {
btrfs subvolume command args,
@@ -700,6 +701,41 @@ static int cmd_find_new(int argc, char **argv)
return 0;
 }
 
+static const char * const cmd_subvol_label_usage[] = {
+   btrfs subvolume label path [label],
+   Show or set label for the subvol or snapshot,
+   NULL
+};
+
+static int cmd_subvol_label(int argc, char **argv)
+{
+   struct stat st;
+   char label[BTRFS_SUBVOL_LABEL_SIZE+1];
+   int ret;
+
+   if (check_argc_min(argc, 2) || check_argc_max(argc, 3))
+   usage(cmd_subvol_label_usage);
+
+   if (stat(argv[1], st)  0) {
+   fprintf(stderr, Error: %s\n,strerror(errno));
+   return -errno;
+   }
+   if (!S_ISDIR(st.st_mode)) {
+   fprintf(stderr, Error: Not a dir\n);
+   return -1;
+   }
+   if (argc  2)
+   return set_subvol_label(argv[1], argv[2]);
+   else {
+   ret = get_subvol_label(argv[1], label);
+   if (ret)
+   return ret;
+   label[BTRFS_SUBVOL_LABEL_SIZE]=0;
+   printf(%s\n,label);
+   }
+   return 0;
+}
+
 const struct cmd_group subvolume_cmd_group = {
subvolume_cmd_group_usage, NULL, {
{ create, cmd_subvol_create, cmd_subvol_create_usage, NULL, 0 
},
@@ -711,6 +747,7 @@ const struct cmd_group subvolume_cmd_group = {
{ set-default, cmd_subvol_set_default,
cmd_subvol_set_default_usage, NULL, 0 },
{ find-new, cmd_find_new, cmd_find_new_usage, NULL, 0 },
+   { label, cmd_subvol_label, cmd_subvol_label_usage, NULL, 0 },
{ 0, 0, 0, 0, 0 }
}
 };
diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 9222580..aa225d9 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -17,6 +17,8 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBsubvolume get-default\fP\fI path\fP
 .PP
+\fBbtrfs\fP \fBsubvolume label\fP\fI path [label]\fP
+.PP
 \fBbtrfs\fP \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] \
 [-s \fIstart\fR] [-t \fIsize\fR] -[vf] \fIfile\fR|\fIdir\fR \
 [\fIfile\fR|\fIdir\fR...]
@@ -160,6 +162,10 @@ Get the default subvolume of the filesystem \fIpath\fR. 
The output format
 is similar to \fBsubvolume list\fR command.
 .TP
 
+\fBsubvolume label\fR\fI path [label]\fR
+Show or set \fI[label]\fR for the subvolume or the snapshot \fIpath\fR.
+.TP
+
 \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] [-s \fIstart\fR] \
 [-t \fIsize\fR] -[vf] \fIfile\fR|\fIdir\fR [\fIfile\fR|\fIdir\fR...]
 
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] Btrfs-progs: add feature to label subvol and snapshot

2012-11-27 Thread Anand jain
From: Anand Jain anand.j...@oracle.com

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 btrfslabel.c |   45 +
 btrfslabel.h |4 +++-
 ctree.h  |4 +++-
 ioctl.h  |2 ++
 print-tree.c |2 ++
 5 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/btrfslabel.c b/btrfslabel.c
index cb142b0..e161af1 100644
--- a/btrfslabel.c
+++ b/btrfslabel.c
@@ -126,3 +126,48 @@ int set_label(char *btrfs_dev, char *nLabel)
change_label_unmounted(btrfs_dev, nLabel);
return 0;
 }
+
+int get_subvol_label(char *subvol, char *labelp)
+{
+   int fd, e=0;
+
+   fd = open_file_or_dir(subvol);
+
+   if(ioctl(fd, BTRFS_IOC_SUBVOL_GETLABEL, labelp)  0) {
+   e = errno;
+   fprintf(stderr, ERROR: get subvol label failed, %s\n,
+   strerror(e));
+   close(fd);
+   return -e;
+   }
+   labelp[BTRFS_LABEL_SIZE] = '\0';
+   if (!strlen(labelp))
+   return -1;
+   close(fd);
+   return 0;
+}
+
+int set_subvol_label(char *subvol, char *labelp)
+{
+   int fd, e=0;
+   char label[BTRFS_SUBVOL_LABEL_SIZE+1];
+
+   if (strlen(labelp)  BTRFS_SUBVOL_LABEL_SIZE) {
+   fprintf(stderr, ERROR: Subvol label is more than max length 
%d\n,
+   BTRFS_SUBVOL_LABEL_SIZE);
+   return -1;
+   }
+   memset(label, 0, BTRFS_SUBVOL_LABEL_SIZE+1);
+   strcpy(label, labelp);
+   fd = open_file_or_dir(subvol);
+
+   if(ioctl(fd, BTRFS_IOC_SUBVOL_SETLABEL, label)  0) {
+   e = errno;
+   fprintf(stderr, ERROR: set subvol label failed, %s\n,
+   strerror(e));
+   close(fd);
+   return -e;
+   }
+   close(fd);
+   return 0;
+}
diff --git a/btrfslabel.h b/btrfslabel.h
index abf43ad..1abc483 100644
--- a/btrfslabel.h
+++ b/btrfslabel.h
@@ -2,4 +2,6 @@
 
 
 int get_label(char *btrfs_dev);
-int set_label(char *btrfs_dev, char *nLabel);
\ No newline at end of file
+int set_label(char *btrfs_dev, char *nLabel);
+int get_subvol_label(char *subvol, char *labelp);
+int set_subvol_label(char *subvol, char *labelp);
diff --git a/ctree.h b/ctree.h
index 293b24f..68bae28 100644
--- a/ctree.h
+++ b/ctree.h
@@ -325,6 +325,7 @@ struct btrfs_header {
  */
 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
 #define BTRFS_LABEL_SIZE 256
+#define BTRFS_SUBVOL_LABEL_SIZE 32
 
 /*
  * just in case we somehow lose the roots and are not able to mount,
@@ -702,7 +703,8 @@ struct btrfs_root_item {
struct btrfs_timespec otime;
struct btrfs_timespec stime;
struct btrfs_timespec rtime;
-__le64 reserved[8]; /* for future */
+   char label[BTRFS_SUBVOL_LABEL_SIZE];
+   __le64 reserved[4]; /* for future */
 } __attribute__ ((__packed__));
 
 /*
diff --git a/ioctl.h b/ioctl.h
index 6fda3a1..009fa6e 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -432,4 +432,6 @@ struct btrfs_ioctl_clone_range_args {
struct btrfs_ioctl_qgroup_create_args)
 #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \
struct btrfs_ioctl_qgroup_limit_args)
+#define BTRFS_IOC_SUBVOL_GETLABEL _IOWR(BTRFS_IOCTL_MAGIC, 55, __u64)
+#define BTRFS_IOC_SUBVOL_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 56, __u64)
 #endif
diff --git a/print-tree.c b/print-tree.c
index 7c615dd..5979109 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -330,6 +330,8 @@ static void print_root(struct extent_buffer *leaf, int slot)
btrfs_root_stransid(root_item),
btrfs_root_rtransid(root_item));
}
+   if (strlen(root_item.label))
+   printf(\t\tlabel %s\n, root_item.label);
}
if (btrfs_root_refs(root_item) == 0) {
struct btrfs_key drop_key;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] Btrfs: add label to snapshot and subvol

2012-11-27 Thread Anand Jain


Hi Maio,

 Thanks for the review.
 Was away for sometime sorry for delay, have sent out the
 patch with review comments accepted.

-Anand

On 11/16/2012 02:33 PM, Miao Xie wrote:

Hi, Anand

On fri, 16 Nov 2012 12:52:25 +0800, Anand jain wrote:

+static int btrfs_ioctl_subvol_getlabel(struct btrfs_root *root,
+   void __user *arg)
+{
+   char *label;
+
+   label = btrfs_root_label(root-root_item);
+   if (copy_to_user(arg, label, BTRFS_SUBVOL_LABEL_SIZE))
+   return -EFAULT;
+   return 0;
+}
+
+static int btrfs_ioctl_subvol_setlabel(struct btrfs_root *root,
+   void __user *arg)
+{
+   char label[BTRFS_SUBVOL_LABEL_SIZE+1];
+   struct btrfs_trans_handle *trans;
+
+   if (copy_from_user(label, arg, BTRFS_SUBVOL_LABEL_SIZE))
+   return -EFAULT;
+   trans = btrfs_join_transaction(root);
+   if (IS_ERR(trans))
+   return PTR_ERR(trans);
+   btrfs_root_set_label(root-root_item, label);
+   btrfs_end_transaction(trans, root);


We need a lock to protect the label, and besides that, we need to get the write
access before we set the label for the subvolume.

Thanks
Miao

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: extended attributes wiredness

2012-11-27 Thread David Arendt
Hi,

I have now tested a gentoo reinstall with a recompile of nfs-utils. By
observing how the directory /var/lib/nfs is created, I found a rather
simple way to reproduce the problem:

dd if=/dev/zero of=test.img bs=8192 count=81920
81920+0 records in
81920+0 records out
671088640 bytes (671 MB) copied, 1.52943 s, 439 MB/s

losetup /dev/loop0 test.img

mkfs.btrfs /dev/loop0

WARNING! - Btrfs v0.20-rc1-37-g91d9eec IS EXPERIMENTAL
WARNING! - see http://btrfs.wiki.kernel.org before using

SMALL VOLUME: forcing mixed metadata/data groups
Created a data/metadata chunk of size 8388608
fs created label (null) on /dev/loop0
nodesize 4096 leafsize 4096 sectorsize 4096 size 640.00MB
Btrfs v0.20-rc1-37-g91d9eec

mount /dev/loop0 /mnt

btrfs subvolume create /mnt/test
Create subvolume '/mnt/test'

mkdir /mnt/test/test1

/root/x/testxattr /mnt/test/test1 
processing file /mnt/test/test1

cp -a /mnt/test/test1 /mnt/test/test2

/root/x/testxattr /mnt/test/test2
processing file /mnt/test/test2
processing attribute system.posix_acl_default
lgetxattr failed: No data available

Might it be a bug in coreutils ?

Thanks in advance,
David Arendt

On 11/27/12 08:46, Liu Bo wrote:
 Hi,  
  
 (cc btrfs Mailing list to notify others.)

 Thanks for the helpful test.img.

 Well...after deeper debug, I'm sure that it's not a btrfs bug,
 at least not a btrfs acl/xattr bug. 
  
 The debug tree shows 
  
 item 10 key (257 INODE_ITEM 0) itemoff 3387 itemsize 160 
 inode generation 6 transid 6 size 102 block group 0 mode 40755 links 
 1 
 item 11 key (257 INODE_REF 256) itemoff 3372 itemsize 15 
 inode ref index 2 namelen 5 name: test1 
 item 12 key (257 XATTR_ITEM 367492571) itemoff 3318 itemsize 54 
 location key (0 UNKNOWN.0 0) type 8 
 namelen 24 datalen 0 name: system.posix_acl_default 
   ^^^ 
 item 13 key (257 XATTR_ITEM 2038346239) itemoff 3237 itemsize 81 
 location key (0 UNKNOWN.0 0) type 8 
 namelen 23 datalen 28 name: system.posix_acl_access 
 data ^B 
  
 == 

 so extended attribute system.posix_acl_default here has not data, which'll
 make filesystems(not just btrfs) return -ENODATA. 
  
 I guess some userspace applications may make it like that. 
  
 thanks, 
 liubo

 On Mon, Nov 26, 2012 at 06:38:06AM +0100, David Arendt wrote:
 Hi,

 I don't know if your xattr patch was meant to fix this issue, but I have
 just tested kernel 3.7-rc7 with your patch applied on another directory
 having the problem and I still have the weird behaviour.

 Thanks in advance,
 David Arendt

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] Btrfs: add label to snapshot and subvol

2012-11-27 Thread Miao Xie
On wed, 28 Nov 2012 02:29:17 +0800, Anand jain wrote:
  /*
 @@ -2441,6 +2443,14 @@ static inline bool btrfs_root_readonly(struct 
 btrfs_root *root)
  {
   return (root-root_item.flags  cpu_to_le64(BTRFS_ROOT_SUBVOL_RDONLY)) 
 != 0;
  }
 +static inline char * btrfs_root_label(struct btrfs_root_item *root_item)
 +{
 + return (root_item-label);
 +}
 +static inline void btrfs_root_set_label(struct btrfs_root_item *root_item, 
 char *val)
 +{
 + memcpy(root_item-label, val, BTRFS_SUBVOL_LABEL_SIZE);
 +}
  
  /* struct btrfs_root_backup */
  BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup,
 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
 index e58bd9d..f0b3d9d 100644
 --- a/fs/btrfs/ioctl.c
 +++ b/fs/btrfs/ioctl.c
 @@ -3725,6 +3725,57 @@ static int btrfs_ioctl_set_label(struct btrfs_root 
 *root, void __user *arg)
   return 0;
  }
  
 +static int btrfs_ioctl_subvol_getlabel(struct btrfs_root *root,
 + void __user *arg)
 +{
 + char *label;
 +
 + label = btrfs_root_label(root-root_item);
 + if (copy_to_user(arg, label, BTRFS_SUBVOL_LABEL_SIZE))
 + return -EFAULT;

we also need lock here.

 + return 0;
 +}
 +
 +static int btrfs_ioctl_subvol_setlabel(struct file *file,
 + void __user *arg)
 +{
 + char label[BTRFS_SUBVOL_LABEL_SIZE+1];
 + struct btrfs_trans_handle *trans;
 + struct btrfs_root *root = BTRFS_I(fdentry(file)-d_inode)-root;
 + struct inode *inode = file-f_path.dentry-d_inode;
 + int ret;
 +
 + if (btrfs_root_readonly(root))
 + return -EROFS;
 +
 + if (!inode_owner_or_capable(inode))
 + return -EACCES;
 +
 + ret = mnt_want_write_file(file);
 + if (ret)
 + return ret;
 +
 + if (copy_from_user(label, arg, BTRFS_SUBVOL_LABEL_SIZE)) {
 + ret = -EFAULT;
 + goto out;
 + }
 +
 + mutex_lock(inode-i_mutex);

we should use a lock which belongs to the root not inode.

Thanks
Miao
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html