[PATCH] Btrfs-progs: btrfs subvolume delete could delete subvolumes

2012-09-21 Thread Anand jain
From: Anand Jain anand.j...@oracle.com

With this user will be able to provide more than one subvolume
to delete.
eg: btrfs subvolume delete subvol1 subvol2

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 cmds-subvolume.c |   36 
 man/btrfs.8.in   |4 ++--
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index f4aa80f..cfeaa8d 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -188,31 +188,34 @@ int test_issubvolume(char *path)
 }
 
 static const char * const cmd_subvol_delete_usage[] = {
-   btrfs subvolume delete name,
-   Delete a subvolume,
+   btrfs subvolume delete subvolume [subvolume...],
+   Delete subvolume(s),
NULL
 };
 
 static int cmd_subvol_delete(int argc, char **argv)
 {
-   int res, fd, len, e;
+   int res, fd, len, e, cnt = 1, ret = 0;
struct btrfs_ioctl_vol_args args;
char*dname, *vname, *cpath;
char*path;
 
-   if (check_argc_exact(argc, 2))
+   if (argc  2)
usage(cmd_subvol_delete_usage);
 
-   path = argv[1];
+again:
+   path = argv[cnt];
 
res = test_issubvolume(path);
if(res0){
fprintf(stderr, ERROR: error accessing '%s'\n, path);
-   return 12;
+   ret = 12;
+   goto out;
}
if(!res){
fprintf(stderr, ERROR: '%s' is not a subvolume\n, path);
-   return 13;
+   ret = 13;
+   goto out;
}
 
cpath = realpath(path, 0);
@@ -226,21 +229,24 @@ static int cmd_subvol_delete(int argc, char **argv)
 strchr(vname, '/') ){
fprintf(stderr, ERROR: incorrect subvolume name ('%s')\n,
vname);
-   return 14;
+   ret = 14;
+   goto out;
}
 
len = strlen(vname);
if (len == 0 || len = BTRFS_VOL_NAME_MAX) {
fprintf(stderr, ERROR: snapshot name too long ('%s)\n,
vname);
-   return 14;
+   ret = 14;
+   goto out;
}
 
fd = open_file_or_dir(dname);
if (fd  0) {
close(fd);
fprintf(stderr, ERROR: can't access to '%s'\n, dname);
-   return 12;
+   ret = 12;
+   goto out;
}
 
printf(Delete subvolume '%s/%s'\n, dname, vname);
@@ -254,10 +260,16 @@ static int cmd_subvol_delete(int argc, char **argv)
if(res  0 ){
fprintf( stderr, ERROR: cannot delete '%s/%s' - %s\n,
dname, vname, strerror(e));
-   return 11;
+   ret = 11;
+   goto out;
}
 
-   return 0;
+out:
+   cnt++;
+   if (cnt  argc)
+   goto again;
+
+   return ret;
 }
 
 static const char * const cmd_subvol_list_usage[] = {
diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 4b0a9f9..a1f172e 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -7,7 +7,7 @@ btrfs \- control a btrfs filesystem
 .SH SYNOPSIS
 \fBbtrfs\fP \fBsubvolume snapshot\fP\fI [-r] source [dest/]name\fP
 .PP
-\fBbtrfs\fP \fBsubvolume delete\fP\fI subvolume\fP
+\fBbtrfs\fP \fBsubvolume delete\fP\fI subvolume [subvolume...]\fP
 .PP
 \fBbtrfs\fP \fBsubvolume create\fP\fI [dest/]name\fP
 .PP
@@ -98,7 +98,7 @@ subvolume, \fBbtrfs\fR returns an error. If \fI-r\fR is 
given, the snapshot
 will be readonly.
 .TP
 
-\fBsubvolume delete\fR\fI subvolume\fR
+\fBsubvolume delete\fR\fI subvolume [subvolume...]\fR
 Delete the subvolume \fIsubvolume\fR. If \fIsubvolume\fR is not a
 subvolume, \fBbtrfs\fR returns an error.
 .TP
-- 
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 1/2] Btrfs-progs: fix the btrfs-debug-tree usage

2012-09-21 Thread Anand jain
From: Anand Jain anand.j...@oracle.com

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 debug-tree.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/debug-tree.c b/debug-tree.c
index 94ffd8e..0e391fc 100644
--- a/debug-tree.c
+++ b/debug-tree.c
@@ -30,7 +30,7 @@
 
 static int print_usage(void)
 {
-   fprintf(stderr, usage: debug-tree [ -e ] device\n);
+   fprintf(stderr, usage: debug-tree [-derR] [-b num] device\n);
fprintf(stderr, %s\n, BTRFS_BUILD_VERSION);
exit(1);
 }
@@ -51,6 +51,8 @@ static void print_extents(struct btrfs_root *root, struct 
extent_buffer *eb)
 btrfs_node_blockptr(eb, i),
 size,
 btrfs_node_ptr_generation(eb, i));
+   if(!next)
+   BUG();
if (btrfs_is_leaf(next) 
btrfs_header_level(eb) != 1)
BUG();
-- 
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] Btrfs-progs: correct the mkfs.btrfs man page

2012-09-21 Thread Anand jain
From: Anand Jain anand.j...@oracle.com

Signed-off-by: Anand Jain anand.j...@oracle.com
---
 man/mkfs.btrfs.8.in |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/man/mkfs.btrfs.8.in b/man/mkfs.btrfs.8.in
index fc2e1d2..d425c33 100644
--- a/man/mkfs.btrfs.8.in
+++ b/man/mkfs.btrfs.8.in
@@ -1,6 +1,6 @@
 .TH MKFS.BTRFS 8
 .SH NAME
-mkfs.btrfs \- create an btrfs filesystem
+mkfs.btrfs \- create a btrfs filesystem
 .SH SYNOPSIS
 .B mkfs.btrfs
 [ \fB\-A\fP\fI alloc-start\fP ]
@@ -18,7 +18,7 @@ mkfs.btrfs \- create an btrfs filesystem
 \fI device\fP [ \fIdevice ...\fP ]
 .SH DESCRIPTION
 .B mkfs.btrfs
-is used to create an btrfs filesystem (usually in a disk partition, or an array
+is used to create a btrfs filesystem (usually in a disk partition, or an array
 of disk partitions).
 .I device
 is the special file corresponding to the device (e.g \fI/dev/sdXX\fP ).
-- 
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] Btrfs-progs: btrfs subvolume delete could delete subvolumes

2012-09-21 Thread Ilya Dryomov
On Fri, Sep 21, 2012 at 02:54:08PM +0800, Anand jain wrote:
 From: Anand Jain anand.j...@oracle.com
 
 With this user will be able to provide more than one subvolume
 to delete.
 eg: btrfs subvolume delete subvol1 subvol2
 
 Signed-off-by: Anand Jain anand.j...@oracle.com
 ---
  cmds-subvolume.c |   36 
  man/btrfs.8.in   |4 ++--
  2 files changed, 26 insertions(+), 14 deletions(-)
 
 diff --git a/cmds-subvolume.c b/cmds-subvolume.c
 index f4aa80f..cfeaa8d 100644
 --- a/cmds-subvolume.c
 +++ b/cmds-subvolume.c
 @@ -188,31 +188,34 @@ int test_issubvolume(char *path)
  }
  
  static const char * const cmd_subvol_delete_usage[] = {
 - btrfs subvolume delete name,
 - Delete a subvolume,
 + btrfs subvolume delete subvolume [subvolume...],
 + Delete subvolume(s),
   NULL
  };
  
  static int cmd_subvol_delete(int argc, char **argv)
  {
 - int res, fd, len, e;
 + int res, fd, len, e, cnt = 1, ret = 0;
   struct btrfs_ioctl_vol_args args;
   char*dname, *vname, *cpath;
   char*path;
  
 - if (check_argc_exact(argc, 2))
 + if (argc  2)
   usage(cmd_subvol_delete_usage);

check_argc_min(argc, 2)

Haven't looked at the rest.

Thanks,

Ilya
--
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 1/2] Btrfs: cleanup duplicated division functions

2012-09-21 Thread Miao Xie
On Thu, 20 Sep 2012 15:28:03 +0200, David Sterba wrote:
 On Thu, Sep 20, 2012 at 10:57:54AM +0800, Miao Xie wrote:
 Because those functions are mostly used on the hot path, and we are sure
 the parameters are right in the most cases, we don't add complex checks
 for the parameters. But in the other place, we must check and make sure
 the parameters are right. So besides the code cleanup, this patch also
 add a check for the usage of the space balance, it is the only place that
 we need add check to make sure the parameters of div_factor{_fine} are
 right till now.
 
 I've reviewed the hotpaths, makes sense to optimize for speed. Adding
 the boundary checks to balance ioctl is ok.
 
 A few suggestions:
 
 * drop the version that does the /10 version and keep only /100 (naming
   it div_factor)
 * drop the
 
 + if (factor == 10)
 + return num;
 
 check, there's only one instance where we pass the maximum value (and
 it's not a frequent case), so there's the if() penalty, makes the
 function smaller and even more suitable for inlining.

OK.

 
 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
 index 9384a2a..d8d53f7 100644
 --- a/fs/btrfs/ioctl.c
 +++ b/fs/btrfs/ioctl.c
 @@ -3335,6 +3335,24 @@ static long btrfs_ioctl_balance(struct file *file, 
 void __user *arg)
  
  goto do_balance;
  }
 +
 +if ((bargs-data.flags  BTRFS_BALANCE_ARGS_USAGE) 
 +(bargs-data.usage  0 || bargs-data.usage  100)) {
 
 data.usage = 0
 
 otherwise you'd divide by 0 in chunk_usage_filter()

The divisor always is 100 or 10, so...

 diff --git a/fs/btrfs/math.h b/fs/btrfs/math.h
 new file mode 100644
 index 000..b7816ce
 --- /dev/null
 +++ b/fs/btrfs/math.h
 
 I think we don't need single file to hold one trivial function then :)
 
 @@ -0,0 +1,44 @@
 +#include asm/div64.h
 +
 +static inline u64 div_factor(u64 num, int factor)
 +{
 +num *= factor;
 +do_div(num, 100);
 +return num;
 +}

I don't find a suitable file to put it down. Maybe we can stuff it
into ctree.h, but I prefer a single file to a unrelated file.

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


Re: [PATCH 1/2] Btrfs-progs: fix the btrfs-debug-tree usage

2012-09-21 Thread David Sterba
On Fri, Sep 21, 2012 at 02:59:44PM +0800, Anand jain wrote:
 @@ -51,6 +51,8 @@ static void print_extents(struct btrfs_root *root, struct 
 extent_buffer *eb)
btrfs_node_blockptr(eb, i),
size,
btrfs_node_ptr_generation(eb, i));
 + if(!next)
 + BUG();

Is there a better way how to get out of this? btrfs-debug-tree is aimed
to help debugging, I don't want to see it crashed if there's some
inconsistency found, rather report it, that's a valuable information.

david
--
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] Btrfs-progs: btrfs subvolume delete could delete subvolumes

2012-09-21 Thread David Sterba
On Fri, Sep 21, 2012 at 02:54:08PM +0800, Anand jain wrote:
 From: Anand Jain anand.j...@oracle.com
 
 With this user will be able to provide more than one subvolume
 to delete.
 eg: btrfs subvolume delete subvol1 subvol2

Yes, this is useful, thanks. I'm thinking if it's ok to stop on
first error, ie. when the subvolume does not exist or is a directory.

david
--
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 1/2] Btrfs: cleanup duplicated division functions

2012-09-21 Thread David Sterba
On Fri, Sep 21, 2012 at 05:07:46PM +0800, Miao Xie wrote:
 --- a/fs/btrfs/ioctl.c
 +++ b/fs/btrfs/ioctl.c
 @@ -3335,6 +3335,24 @@ static long btrfs_ioctl_balance(struct file *file, 
 void __user *arg)
  
   goto do_balance;
   }
 +
 + if ((bargs-data.flags  BTRFS_BALANCE_ARGS_USAGE) 
 + (bargs-data.usage  0 || bargs-data.usage  100)) {

the 0 checks belong here

 + ret = -EINVAL;
 + goto out_bargs;
 + }
 +
 + if ((bargs-meta.flags  BTRFS_BALANCE_ARGS_USAGE) 
 + (bargs-meta.usage  0 || bargs-meta.usage  100)) {
 + ret = -EINVAL;
 + goto out_bargs;
 + }
 +
 + if ((bargs-sys.flags  BTRFS_BALANCE_ARGS_USAGE) 
 + (bargs-sys.usage  0 || bargs-sys.usage  100)) {
 + ret = -EINVAL;
 + goto out_bargs;
 + }
   } else {
   bargs = NULL;
   }
 @@ -2347,7 +2335,8 @@ static int chunk_usage_filter(struct btrfs_fs_info 
 *fs_info, u64 chunk_offset,
   cache = btrfs_lookup_block_group(fs_info, chunk_offset);
   chunk_used = btrfs_block_group_used(cache-item);
  
 - user_thresh = div_factor_fine(cache-key.offset, bargs-usage);
 + BUG_ON(bargs-usage  0 || bargs-usage  100);

otherwise it reliably crashes here

 + user_thresh = div_factor(cache-key.offset, bargs-usage);
   if (chunk_used  user_thresh)
   ret = 0;
  

other than that, patch looks good tome,

thanks,
david
--
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


Identifying reflink / CoW files

2012-09-21 Thread Jp Wise
Good morning, I'm working on an offline deduplication script intended to 
work around the copy-on-write functionality of BTRFS.


Simply put - is there any existing utility to compare two files (or 
dirs) and output if the files share the same physical extents / data 
blocks on disk?

- aka - they're CoW copies.

I'm not actively working with BTRFS yet, but for the project i'm working 
on it's looking to the be most suitable candidate, and the CoW 
functionality avoids issues with file changes that hardlinks would create.
From reading other posts, aware the information could be pulled out via 
btrfs-debug-tree, but it would then involve parsing the entire output to 
locate the required files inodes and their extents which seems like 
quite a roundabout way to retrieve the information.


Also my programming skills aren't  up to the task of trying to pull the 
tree data directly from the filesystem to do it, and I'd like to avoid 
doing byte-by-byte comparisons on all files as it's inefficient if the 
file can instead be identified as a CoW copy.


Open to suggestions of other tools that could be used to acheive the 
desired result.


Thanks.
Jp.
--
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