[PATCH 0/2] btrfs-progs: Introduce devel namespace

2013-08-06 Thread David Sterba
Add namespace for features under development and the first user.

David Sterba (2):
  btrfs-progs: introduce command namespace for development features
  btrfs-progs: move chunk-recover command to devel namespace

 btrfs.c | 26 +-
 1 file changed, 25 insertions(+), 1 deletion(-)

-- 
1.8.3.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: introduce command namespace for development features

2013-08-06 Thread David Sterba
We'd like to make it easier to preview a new feature and remove the
burden to invent sane user interface (command name, placement,
arguments, man) from the beginning. For this purpose the developer are
free to use the 1st level namespace called '_'. It will be hidden from
regular btrfs help output and the only way to get the commands is

  btrfs _ --help

The commands appear as if they are in the 1st level, but have to be used
from inside _, eg.

  btrfs _ newcommand

Once the interface is stable, the command will be moved to the right
place.

Signed-off-by: David Sterba dste...@suse.cz
---
 btrfs.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/btrfs.c b/btrfs.c
index 4e93e13..dff0d70 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -239,6 +239,28 @@ static int handle_options(int *argc, char ***argv)
return (*argv) - orig_argv;
 }
 
+static const char * const devel_features_cmd_usage[] = {
+   btrfs _ command [args],
+   NULL
+};
+
+const struct cmd_group devel_features_cmd_group = {
+   devel_features_cmd_usage,
+   WARNING: this is a namespace for commands that are in development\n
+   and anything is subject to change. Once the user interface gets\n
+   stabilized, it'll be moved to the appropriate place.\n
+   NOTE: you have to call the commands as eg.\n
+   \tbtrfs _ newcommand --args\n,
+   {
+   { 0, 0, 0, 0, 0 }
+   }
+};
+
+int cmd_devel_features(int argc, char **argv)
+{
+   return handle_command_group(devel_features_cmd_group, argc, argv);
+}
+
 const struct cmd_group btrfs_cmd_group = {
btrfs_cmd_group_usage, btrfs_cmd_group_info, {
{ subvolume, cmd_subvolume, NULL, subvolume_cmd_group, 0 },
@@ -255,6 +277,8 @@ const struct cmd_group btrfs_cmd_group = {
{ quota, cmd_quota, NULL, quota_cmd_group, 0 },
{ qgroup, cmd_qgroup, NULL, qgroup_cmd_group, 0 },
{ replace, cmd_replace, NULL, replace_cmd_group, 0 },
+   { _, cmd_devel_features, devel_features_cmd_usage,
+   devel_features_cmd_group, 1 },
{ help, cmd_help, cmd_help_usage, NULL, 0 },
{ version, cmd_version, cmd_version_usage, NULL, 0 },
{ 0, 0, 0, 0, 0 }
-- 
1.8.3.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/2] btrfs-progs: move chunk-recover command to devel namespace

2013-08-06 Thread David Sterba
Signed-off-by: David Sterba dste...@suse.cz
---
 btrfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/btrfs.c b/btrfs.c
index dff0d70..4bbce48 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -252,6 +252,7 @@ const struct cmd_group devel_features_cmd_group = {
NOTE: you have to call the commands as eg.\n
\tbtrfs _ newcommand --args\n,
{
+   { chunk-recover, cmd_chunk_recover, cmd_chunk_recover_usage, 
NULL, 0},
{ 0, 0, 0, 0, 0 }
}
 };
@@ -269,7 +270,6 @@ const struct cmd_group btrfs_cmd_group = {
{ device, cmd_device, NULL, device_cmd_group, 0 },
{ scrub, cmd_scrub, NULL, scrub_cmd_group, 0 },
{ check, cmd_check, cmd_check_usage, NULL, 0 },
-   { chunk-recover, cmd_chunk_recover, cmd_chunk_recover_usage, 
NULL, 0},
{ restore, cmd_restore, cmd_restore_usage, NULL, 0 },
{ inspect-internal, cmd_inspect, NULL, inspect_cmd_group, 0 
},
{ send, cmd_send, cmd_send_usage, NULL, 0 },
-- 
1.8.3.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 09/10] btrfs-progs: Fix the return value of btrfs-map-logical

2013-08-06 Thread David Sterba
On Thu, Aug 01, 2013 at 01:35:33PM +0800, Wang Shilong wrote:
 From: Qu Wenruo quwen...@cn.fujitsu.com
 
 The ret variant in the main function is not changed so even problems
 happen, return value is still 0.
 The patch fixs the minor bug and return 1 if any problems happen.

Please don't mix code fixes into documentation updates next time (unless
you're testing my attention).

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 09/10] btrfs-progs: Fix the return value of btrfs-map-logical

2013-08-06 Thread Wang Shilong
 On Thu, Aug 01, 2013 at 01:35:33PM +0800, Wang Shilong wrote:
 From: Qu Wenruo quwen...@cn.fujitsu.com
 
 The ret variant in the main function is not changed so even problems
 happen, return value is still 0.
 The patch fixs the minor bug and return 1 if any problems happen.
 
 Please don't mix code fixes into documentation updates next time (unless
 you're testing my attention).
 

I am sorry , we will take care of that.

Thanks,
Wang
 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

--
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 00/11 v2 (resend)] btrfs-progs: coalesce of patches

2013-08-06 Thread anand jain


On 06/08/2013 01:36, David Sterba wrote:

On Mon, Jul 15, 2013 at 01:30:46PM +0800, Anand Jain wrote:

Anand Jain (11):
   btrfs-progs: btrfs_scan_for_fsid doesn't need all the arguments
   btrfs-progs: label option in btrfs filesystem show is not coded
   btrfs-progs: update device scan usage
   btrfs-progs: congregate dev scan
   btrfs-progs: btrfs_scan_one_dir not to skip links when /dev/mapper is
 provided
   btrfs-progs: scan /dev/mapper in filesystem show and device scan
   btrfs-progs: device delete to get errors from the kernel
   btrfs-progs: get_label_mounted to return label instead of print
   btrfs-progs: move out print in cmd_df to another function
   btrfs-progs: get string for the group profile and type
   btrfs-progs: introduce btrfs filesystem show --kernel


patches 1-4,7,8 added to integration, skipped 5,6 as they enhance dev
scan that'll need a rewrite anyway.

9-11 are sort of independent of the previous changes so I'd like to look
at them in context of all the other df/show patches.


 makes sense. I am looking at them.

Thanks,  Anand
--
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 01/10] Btrfs-progs: add missing man page information for btrfsck

2013-08-06 Thread David Sterba
On Thu, Aug 01, 2013 at 01:35:25PM +0800, Wang Shilong wrote:
 +.SH COPYRIGHT
 +Copyright \(co 2013 Fujitsu, Inc.
 +License GPLv3: GNU GPL version 3 http://gnu.org/licenses/gpl.html.
 +.br
 +This is free software: you are free  to  change  and  redistribute  it. 
 There is NO WARRANTY, to the extent permitted by law.

Are you sure you want both a copyright statement and GPL wording here?

Another quiestion is about the GPL version itself, you're releasing it
under v3 but the rest of the code is under v2 and there are issues when
these licenses are mixed.

I'd like to avoid any flames about v2 vs v3, so for ease of maintenance
please either drop the section or change it to gplv2. You're free to
insist on v3, then I'm not going to merge the patches.

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


Re: [PROGS PATCH] Import btrfs-extent-same

2013-08-06 Thread David Sterba
On Thu, Jun 27, 2013 at 12:38:19AM +0200, Gabriel de Perthuis wrote:
 Originally from
 https://github.com/markfasheh/duperemove/blob/master/btrfs-extent-same.c

Can you (or Mark) please turn it into a subcommand of dedup? The idea is
to merge both in-bound and out-bound dedup into one command, eg.

 btrfs dedup files dir/*

Liu Bo's dedup patch is in today's integration snapshot
http://repo.or.cz/w/btrfs-progs-unstable/devel.git/shortlog/refs/heads/integration-20130806-2

you can use it as a base.

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


Re: Heavy memory leak when using quota groups

2013-08-06 Thread Tomasz Chmielewski
On Tue, 06 Aug 2013 07:24:26 +0200
Arne Jansen sensi...@gmx.net wrote:

 On 05.08.2013 18:35, Tomasz Chmielewski wrote:
  I am trying to use qgroups
  functionality  with a basic random-write workload, it constantly
  keeps leaking memory  within few minutes of IO, there is either
  out-of-memory killer trying to kill some tasks or there are
  page-allocation failures that btrfs or other kernel module
  experiences.
  
  FYI, I just saw something similar with 3.10 on a server with 32 GB
  RAM:
  
  The result was a frozen server and a need to hard reset.
  
 
 What do I have to do to reproduce it here? How do you generate the
 load? What is the disk setup, what the qgroups setup?

Unfortunately I don't have a way to reproduce, as the issue
happened to me only once.

Server uptime was about 2 weeks, and there were millions of files with
multiple hardlinks on disk (backuppc archive copied from ext4 to
btrfs). Then, rm command was running for many days, about 5 times in
parallel, and many other rsync commands, with snapshots being added and
removed.

When I saw the issue I looked up in btrfs list archives that there was
a similar report in the past - but I doubt I will be able to find a
reliable way to reproduce this.

-- 
Tomasz Chmielewski
http://wpkg.org
--
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: introduce command namespace for development features

2013-08-06 Thread Zach Brown
On Tue, Aug 06, 2013 at 02:25:20PM +0200, David Sterba wrote:
 We'd like to make it easier to preview a new feature and remove the
 burden to invent sane user interface (command name, placement,
 arguments, man) from the beginning.

My biggest worry about this is that it complicates the coordination of
automated testing, which is already in a terrible state for btrfs-progs.
It can't possibly motivate people to write tests if we make the process
more cumbersome than it already is.

So we develop tests for a command (maybe in xfstests,  maybe in
btrfs-progs) that use this magical _ namespace.  Then the command is
merged.  When are the tests updated?  Do they fallback to both so that
the tests can work across the merge?   Do we add some complexity to try
and magically match _ commands that aren't found with matching commands
somewhere else in the heirarchy?  Ugh, all 'round.

I'm not sure I understand what problem this is really solving.  People
shouldn't be expecting to find incomplete features in the master branch,
right?  If people are looking to test incomplete work they can get your
integration branch and, well, we don't care if it changes later?

- z
--
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 RFC] Btrfs-progs: allow btrfstune to set persistent mount options

2013-08-06 Thread Filipe David Borba Manana
This is the complement to the corresponding kernel patch that
adds support for permanent options.

NOTE: Like the corresponding kernel patch, this is a WIP with the
goal o gathering feedback.

Signed-off-by: Filipe David Borba Manana fdman...@gmail.com
---
 btrfstune.c  |  105 --
 ctree.h  |8 +
 print-tree.c |9 +
 3 files changed, 120 insertions(+), 2 deletions(-)

diff --git a/btrfstune.c b/btrfstune.c
index 4db1767..b3d3e57 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -97,12 +97,100 @@ int enable_skinny_metadata(struct btrfs_root *root)
return 0;
 }
 
+static int set_persistent_mount_options(struct btrfs_root *root,
+   const char *options)
+{
+   int ret;
+   struct btrfs_trans_handle *trans = NULL;
+   struct btrfs_path *path;
+   struct btrfs_key key, location;
+   struct extent_buffer *leaf;
+   struct btrfs_dir_item *dir_item;
+   struct btrfs_disk_key disk_key;
+   struct btrfs_root *tree_root = root-fs_info-tree_root;
+   unsigned long data_ptr;
+   u32 data_size, data_len;
+
+   path = btrfs_alloc_path();
+   if (!path)
+   return -ENOMEM;
+
+   trans = btrfs_start_transaction(root, 1);
+   if (!trans) {
+   ret = -ENOMEM;
+   goto out;
+   }
+
+   key.objectid = BTRFS_PERSISTENT_OPTIONS_OBJECTID;
+   key.type = 0;
+   key.offset = 0;
+
+   ret = btrfs_search_slot(trans, tree_root, key, path, -1, 1);
+   if (ret  0)
+   goto out;
+   if (!ret) {
+   char *buf;
+
+   leaf = path-nodes[0];
+   dir_item = btrfs_item_ptr(leaf, path-slots[0],
+ struct btrfs_dir_item);
+   buf = (char *) malloc(btrfs_dir_data_len(leaf, dir_item));
+   if (!buf) {
+   ret = -ENOMEM;
+   goto out;
+   }
+   read_extent_buffer(leaf, buf,
+  (unsigned long)((char *)(dir_item + 1)),
+  btrfs_dir_data_len(leaf, dir_item));
+   printf(Current persistent options:  %.*s\n,
+  btrfs_dir_data_len(leaf, dir_item), buf);
+   free(buf);
+   ret = btrfs_del_item(trans, tree_root, path);
+   if (ret)
+   goto out;
+   }
+
+   btrfs_release_path(root, path);
+
+   data_len = strlen(options);
+   data_size = sizeof(*dir_item) + data_len;
+   ret = btrfs_insert_empty_item(trans, tree_root, path, key, data_size);
+   if (ret)
+   goto out;
+
+   leaf = path-nodes[0];
+   dir_item = btrfs_item_ptr(leaf, path-slots[0], struct btrfs_dir_item);
+
+   memset(location, 0, sizeof(location));
+   btrfs_cpu_key_to_disk(disk_key, location);
+   btrfs_set_dir_item_key(leaf, dir_item, disk_key);
+   btrfs_set_dir_type(leaf, dir_item, BTRFS_FT_UNKNOWN);
+   btrfs_set_dir_name_len(leaf, dir_item, 0);
+   btrfs_set_dir_data_len(leaf, dir_item, data_len);
+   data_ptr = (unsigned long)((char *)(dir_item + 1));
+
+   write_extent_buffer(leaf, options, data_ptr, data_len);
+   btrfs_mark_buffer_dirty(leaf);
+
+out:
+   if (!ret  trans)
+   ret = btrfs_commit_transaction(trans, root);
+   else if (trans)
+   btrfs_free_transaction(root, trans);
+   btrfs_free_path(path);
+   if (!ret)
+   printf(New persistent options:  %s\n, options);
+
+   return ret;
+}
+
 static void print_usage(void)
 {
fprintf(stderr, usage: btrfstune [options] device\n);
fprintf(stderr, \t-S value\tenable/disable seeding\n);
fprintf(stderr, \t-r \t\tenable extended inode refs\n);
-   fprintf(stderr, \t-x enable skinny metadata extent refs\n);
+   fprintf(stderr, \t-x \t\tenable skinny metadata extent refs\n);
+   fprintf(stderr, \t-o options\tset persistent mount options\n);
 }
 
 int main(int argc, char *argv[])
@@ -114,9 +202,10 @@ int main(int argc, char *argv[])
int seeding_value = 0;
int skinny_flag = 0;
int ret;
+   char *options = NULL;
 
while(1) {
-   int c = getopt(argc, argv, S:rx);
+   int c = getopt(argc, argv, S:rxo:);
if (c  0)
break;
switch(c) {
@@ -130,6 +219,9 @@ int main(int argc, char *argv[])
case 'x':
skinny_flag = 1;
break;
+   case 'o':
+   options = optarg;
+   break;
default:
print_usage();
return 1;
@@ -171,6 +263,15 @@ int main(int argc, char *argv[])
success++;
}
 
+   if (options) {
+   ret = 

[PATCH 2/4] btrfs_ioctl_clone: Move clone code into it's own function

2013-08-06 Thread Mark Fasheh
There's some 250+ lines here that are easily encapsulated into their own
function. I don't change how anything works here, just create and document
the new btrfs_clone() function from btrfs_ioctl_clone() code.

Signed-off-by: Mark Fasheh mfas...@suse.de
---
 fs/btrfs/ioctl.c | 232 ++-
 1 file changed, 128 insertions(+), 104 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index ef53952..e90c519 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2476,125 +2476,43 @@ static inline void lock_extent_range(struct inode 
*inode, u64 off, u64 len)
}
 }
 
-static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
-  u64 off, u64 olen, u64 destoff)
+/**
+ * btrfs_clone() - clone a range from inode file to another
+ *
+ * @src: Inode to clone from
+ * @inode: Inode to clone to
+ * @off: Offset within source to start clone from
+ * @olen: Original length, passed by user, of range to clone
+ * @olen_aligned: Block-aligned value of olen, extent_same uses
+ *   identical values here
+ * @destoff: Offset within @inode to start clone
+ */
+static int btrfs_clone(struct inode *src, struct inode *inode,
+  u64 off, u64 olen, u64 olen_aligned, u64 destoff)
 {
-   struct inode *inode = file_inode(file);
struct btrfs_root *root = BTRFS_I(inode)-root;
-   struct fd src_file;
-   struct inode *src;
-   struct btrfs_trans_handle *trans;
-   struct btrfs_path *path;
+   struct btrfs_path *path = NULL;
struct extent_buffer *leaf;
-   char *buf;
+   struct btrfs_trans_handle *trans;
+   char *buf = NULL;
struct btrfs_key key;
u32 nritems;
int slot;
int ret;
-   u64 len = olen;
-   u64 bs = root-fs_info-sb-s_blocksize;
-
-   /*
-* TODO:
-* - split compressed inline extents.  annoying: we need to
-*   decompress into destination's address_space (the file offset
-*   may change, so source mapping won't do), then recompress (or
-*   otherwise reinsert) a subrange.
-* - allow ranges within the same file to be cloned (provided
-*   they don't overlap)?
-*/
-
-   /* the destination must be opened for writing */
-   if (!(file-f_mode  FMODE_WRITE) || (file-f_flags  O_APPEND))
-   return -EINVAL;
-
-   if (btrfs_root_readonly(root))
-   return -EROFS;
-
-   ret = mnt_want_write_file(file);
-   if (ret)
-   return ret;
-
-   src_file = fdget(srcfd);
-   if (!src_file.file) {
-   ret = -EBADF;
-   goto out_drop_write;
-   }
-
-   ret = -EXDEV;
-   if (src_file.file-f_path.mnt != file-f_path.mnt)
-   goto out_fput;
-
-   src = file_inode(src_file.file);
-
-   ret = -EINVAL;
-   if (src == inode)
-   goto out_fput;
-
-   /* the src must be open for reading */
-   if (!(src_file.file-f_mode  FMODE_READ))
-   goto out_fput;
-
-   /* don't make the dst file partly checksummed */
-   if ((BTRFS_I(src)-flags  BTRFS_INODE_NODATASUM) !=
-   (BTRFS_I(inode)-flags  BTRFS_INODE_NODATASUM))
-   goto out_fput;
-
-   ret = -EISDIR;
-   if (S_ISDIR(src-i_mode) || S_ISDIR(inode-i_mode))
-   goto out_fput;
-
-   ret = -EXDEV;
-   if (src-i_sb != inode-i_sb)
-   goto out_fput;
+   u64 len = olen_aligned;
 
ret = -ENOMEM;
buf = vmalloc(btrfs_level_size(root, 0));
if (!buf)
-   goto out_fput;
+   return ret;
 
path = btrfs_alloc_path();
if (!path) {
vfree(buf);
-   goto out_fput;
-   }
-   path-reada = 2;
-
-   if (inode  src) {
-   mutex_lock_nested(inode-i_mutex, I_MUTEX_PARENT);
-   mutex_lock_nested(src-i_mutex, I_MUTEX_CHILD);
-   } else {
-   mutex_lock_nested(src-i_mutex, I_MUTEX_PARENT);
-   mutex_lock_nested(inode-i_mutex, I_MUTEX_CHILD);
-   }
-
-   /* determine range to clone */
-   ret = -EINVAL;
-   if (off + len  src-i_size || off + len  off)
-   goto out_unlock;
-   if (len == 0)
-   olen = len = src-i_size - off;
-   /* if we extend to eof, continue to block boundary */
-   if (off + len == src-i_size)
-   len = ALIGN(src-i_size, bs) - off;
-
-   /* verify the end result is block aligned */
-   if (!IS_ALIGNED(off, bs) || !IS_ALIGNED(off + len, bs) ||
-   !IS_ALIGNED(destoff, bs))
-   goto out_unlock;
-
-   if (destoff  inode-i_size) {
-   ret = btrfs_cont_expand(inode, inode-i_size, destoff);
-   if (ret)
-   goto out_unlock;
+   return ret;
}
 
-   /* truncate page cache pages from 

[PATCH 0/4] btrfs: out-of-band (aka offline) dedupe v4

2013-08-06 Thread Mark Fasheh
Hi,

The following series of patches implements in btrfs an ioctl to do
out-of-band deduplication of file extents.

To be clear, this means that the file system is mounted and running, but the
dedupe is not done during file writes, but after the fact when some
userspace software initiates a dedupe.

The primary patch is loosely based off of one sent by Josef Bacik back
in January, 2011.

http://permalink.gmane.org/gmane.comp.file-systems.btrfs/8508

I've made significant updates and changes from the original. In
particular the structure passed is more fleshed out, this series has a
high degree of code sharing between itself and the clone code, and the
locking has been updated.


The ioctl accepts a struct:

struct btrfs_ioctl_same_args {
__u64 logical_offset;   /* in - start of extent in source */
__u64 length;   /* in - length of extent */
__u16 dest_count;   /* in - total elements in info array */
__u16 reserved1;
__u32 reserved2;
struct btrfs_ioctl_same_extent_info info[0];
};

Userspace puts each duplicate extent (other than the source) in an
item in the info array. As there can be multiple dedupes in one
operation, each info item has it's own status and 'bytes_deduped'
member. This provides a number of benefits:

- We don't have to fail the entire ioctl because one of the dedupes failed.

- Userspace will always know how much progress was made on a file as we always
  return the number of bytes deduped.


#define BTRFS_SAME_DATA_DIFFERS 1
/* For extent-same ioctl */
struct btrfs_ioctl_same_extent_info {
__s64 fd;   /* in - destination file */
__u64 logical_offset;   /* in - start of extent in destination */
__u64 bytes_deduped;/* out - total # of bytes we were able
 * to dedupe from this file */
/* status of this dedupe operation:
 * 0 if dedup succeeds
 *  0 for error
 * == BTRFS_SAME_DATA_DIFFERS if data differs
 */
__s32 status;   /* out - see above description */
__u32 reserved;
};


The kernel patches are based off Linux v3.9. At this point I've tested the
ioctl against a decent variety of files and conditions.

A git tree for the kernel changes can be found at:

https://github.com/markfasheh/btrfs-extent-same


I have a userspace project, duperemove available at:

https://github.com/markfasheh/duperemove

Hopefully this can serve as an example of one possible usage of the ioctl.

duperemove takes a list of files as argument and will search them for
duplicated extents. If given the '-D' switch, duperemove will send dedupe
requests for same extents and display the results.

Within the duperemove repo is a file, btrfs-extent-same.c that acts as
a test wrapper around the ioctl. It can be compiled completely
seperately from the rest of the project via make
btrfs-extent-same. This makes direct testing of the ioctl more
convenient.


Gabriel de Perthuis also has a bedup branch which works against this ioctl.
The branch can be found at:

https://github.com/g2p/bedup/tree/wip/dedup-syscall


Limitations

We can't yet dedupe within the same file (that is, source and destination
are the same inode). This is due to a limitation in btrfs_clone().
 

Code review is very much appreciated. Thanks,
 --Mark


ChangeLog

All of this rounds fixes are thanks to review from Zach Brown z...@redhat.com

- test for errors from extent_read_full_page_nolock()

- use kmap_atomic() instead of kmap()

- WARN_ON and return an error if blocksize  pagesize

- describe the use and reasoning of BTRFS_MAX_DEDUPE_LEN in comments

- explicitely check !S_ISREG on input files now

- copy arguments into/out of userspace on demand

- do i_size and data checksumming checks under lock

Changes from v2 to v3:

- allow root to always dedupe

- call flush_dcach_page() before we memcmp user data (thanks to Zach Brown
  z...@redhat.com for review)

- make sure we can't get a symlink passed in as one of our arguments (thanks
  to Zach Brown z...@redhat.com for review)

- we don't read into buffers any more and compare page by page (thanks to
  Zach Brown z...@redhat.com for review)

- rework btrfs_double_lock() a bit to use swap() (thanks to Zach Brown
  z...@redhat.com for review)

Changes from v1 to v2

- check that we have appropriate access to each file before deduping. For
  the source, we only check that it is opened for read. Target files have to
  be open for write.

- don't dedupe on readonly submounts (this is to maintain 

- check that we don't dedupe files with different checksumming states
 (compare BTRFS_INODE_NODATASUM flags)

- get and maintain write access to the mount during the extent same
  operation (mount_want_write())

- allocate our read buffers up front in btrfs_ioctl_file_extent_same() and
  pass them through for re-use on every call to btrfs_extent_same(). (thanks
  to David Sterba dste...@suse.cz for reporting this

- 

[PATCH 1/4] btrfs: abtract out range locking in clone ioctl()

2013-08-06 Thread Mark Fasheh
The range locking in btrfs_ioctl_clone is trivially broken out into it's own
function. This reduces the complexity of btrfs_ioctl_clone() by a small bit
and makes that locking code available to future functions in
fs/btrfs/ioctl.c

Signed-off-by: Mark Fasheh mfas...@suse.de
---
 fs/btrfs/ioctl.c | 36 +---
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 2c02310..ef53952 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2456,6 +2456,26 @@ out:
return ret;
 }
 
+static inline void lock_extent_range(struct inode *inode, u64 off, u64 len)
+{
+   /* do any pending delalloc/csum calc on src, one way or
+  another, and lock file content */
+   while (1) {
+   struct btrfs_ordered_extent *ordered;
+   lock_extent(BTRFS_I(inode)-io_tree, off, off + len - 1);
+   ordered = btrfs_lookup_first_ordered_extent(inode,
+   off + len - 1);
+   if (!ordered 
+   !test_range_bit(BTRFS_I(inode)-io_tree, off,
+   off + len - 1, EXTENT_DELALLOC, 0, NULL))
+   break;
+   unlock_extent(BTRFS_I(inode)-io_tree, off, off + len - 1);
+   if (ordered)
+   btrfs_put_ordered_extent(ordered);
+   btrfs_wait_ordered_range(inode, off, len);
+   }
+}
+
 static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
   u64 off, u64 olen, u64 destoff)
 {
@@ -2573,21 +2593,7 @@ static noinline long btrfs_ioctl_clone(struct file 
*file, unsigned long srcfd,
truncate_inode_pages_range(inode-i_data, destoff,
   PAGE_CACHE_ALIGN(destoff + len) - 1);
 
-   /* do any pending delalloc/csum calc on src, one way or
-  another, and lock file content */
-   while (1) {
-   struct btrfs_ordered_extent *ordered;
-   lock_extent(BTRFS_I(src)-io_tree, off, off + len - 1);
-   ordered = btrfs_lookup_first_ordered_extent(src, off + len - 1);
-   if (!ordered 
-   !test_range_bit(BTRFS_I(src)-io_tree, off, off + len - 1,
-   EXTENT_DELALLOC, 0, NULL))
-   break;
-   unlock_extent(BTRFS_I(src)-io_tree, off, off + len - 1);
-   if (ordered)
-   btrfs_put_ordered_extent(ordered);
-   btrfs_wait_ordered_range(src, off, len);
-   }
+   lock_extent_range(src, off, len);
 
/* clone data */
key.objectid = btrfs_ino(src);
-- 
1.8.1.4

--
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 3/4] btrfs: Introduce extent_read_full_page_nolock()

2013-08-06 Thread Mark Fasheh
We want this for btrfs_extent_same. Basically readpage and friends do their
own extent locking but for the purposes of dedupe, we want to have both
files locked down across a set of readpage operations (so that we can
compare data). Introduce this variant and a flag which can be set for
extent_read_full_page() to indicate that we are already locked.

Partial credit for this patch goes to Gabriel de Perthuis g2p.c...@gmail.com
as I have included a fix from him to the original patch which avoids a
deadlock on compressed extents.

Signed-off-by: Mark Fasheh mfas...@suse.de
---
 fs/btrfs/compression.c |  6 +-
 fs/btrfs/extent_io.c   | 41 +++--
 fs/btrfs/extent_io.h   |  3 +++
 3 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 15b9408..05819c3 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -636,7 +636,11 @@ int btrfs_submit_compressed_read(struct inode *inode, 
struct bio *bio,
faili = nr_pages - 1;
cb-nr_pages = nr_pages;
 
-   add_ra_bio_pages(inode, em_start + em_len, cb);
+   /* In the parent-locked case, we only locked the range we are
+* interested in.  In all other cases, we can opportunistically
+* cache decompressed data that goes beyond the requested range. */
+   if (!(bio_flags  EXTENT_BIO_PARENT_LOCKED))
+   add_ra_bio_pages(inode, em_start + em_len, cb);
 
/* include any pages we added in add_ra-bio_pages */
uncompressed_len = bio-bi_vcnt * PAGE_CACHE_SIZE;
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index cdee391..80ce106 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2643,11 +2643,12 @@ static int __extent_read_full_page(struct 
extent_io_tree *tree,
struct btrfs_ordered_extent *ordered;
int ret;
int nr = 0;
+   int parent_locked = *bio_flags  EXTENT_BIO_PARENT_LOCKED;
size_t pg_offset = 0;
size_t iosize;
size_t disk_io_size;
size_t blocksize = inode-i_sb-s_blocksize;
-   unsigned long this_bio_flag = 0;
+   unsigned long this_bio_flag = *bio_flags  EXTENT_BIO_PARENT_LOCKED;
 
set_page_extent_mapped(page);
 
@@ -2659,7 +2660,7 @@ static int __extent_read_full_page(struct extent_io_tree 
*tree,
}
 
end = page_end;
-   while (1) {
+   while (!parent_locked) {
lock_extent(tree, start, end);
ordered = btrfs_lookup_ordered_extent(inode, start);
if (!ordered)
@@ -2695,15 +2696,18 @@ static int __extent_read_full_page(struct 
extent_io_tree *tree,
kunmap_atomic(userpage);
set_extent_uptodate(tree, cur, cur + iosize - 1,
cached, GFP_NOFS);
-   unlock_extent_cached(tree, cur, cur + iosize - 1,
-cached, GFP_NOFS);
+   if (!parent_locked)
+   unlock_extent_cached(tree, cur,
+cur + iosize - 1,
+cached, GFP_NOFS);
break;
}
em = get_extent(inode, page, pg_offset, cur,
end - cur + 1, 0);
if (IS_ERR_OR_NULL(em)) {
SetPageError(page);
-   unlock_extent(tree, cur, end);
+   if (!parent_locked)
+   unlock_extent(tree, cur, end);
break;
}
extent_offset = cur - em-start;
@@ -2711,7 +2715,7 @@ static int __extent_read_full_page(struct extent_io_tree 
*tree,
BUG_ON(end  cur);
 
if (test_bit(EXTENT_FLAG_COMPRESSED, em-flags)) {
-   this_bio_flag = EXTENT_BIO_COMPRESSED;
+   this_bio_flag |= EXTENT_BIO_COMPRESSED;
extent_set_compress_type(this_bio_flag,
 em-compress_type);
}
@@ -2755,7 +2759,8 @@ static int __extent_read_full_page(struct extent_io_tree 
*tree,
if (test_range_bit(tree, cur, cur_end,
   EXTENT_UPTODATE, 1, NULL)) {
check_page_uptodate(tree, page);
-   unlock_extent(tree, cur, cur + iosize - 1);
+   if (!parent_locked)
+   unlock_extent(tree, cur, cur + iosize - 1);
cur = cur + iosize;
pg_offset += iosize;
continue;
@@ -2765,7 +2770,8 @@ static int __extent_read_full_page(struct extent_io_tree 
*tree,
 */
if (block_start == EXTENT_MAP_INLINE) {

[PATCH 4/4] btrfs: offline dedupe

2013-08-06 Thread Mark Fasheh
This patch adds an ioctl, BTRFS_IOC_FILE_EXTENT_SAME which will try to
de-duplicate a list of extents across a range of files.

Internally, the ioctl re-uses code from the clone ioctl. This avoids
rewriting a large chunk of extent handling code.

Userspace passes in an array of file, offset pairs along with a length
argument. The ioctl will then (for each dedupe) do a byte-by-byte comparison
of the user data before deduping the extent. Status and number of bytes
deduped are returned for each operation.

Signed-off-by: Mark Fasheh mfas...@suse.de
---
 fs/btrfs/ioctl.c   | 278 +
 include/uapi/linux/btrfs.h |  27 +
 2 files changed, 305 insertions(+)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index e90c519..7db2ee6 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -57,6 +57,9 @@
 #include send.h
 #include dev-replace.h
 
+static int btrfs_clone(struct inode *src, struct inode *inode,
+  u64 off, u64 olen, u64 olen_aligned, u64 destoff);
+
 /* Mask out flags that are inappropriate for the given type of inode. */
 static inline __u32 btrfs_mask_flags(umode_t mode, __u32 flags)
 {
@@ -2456,6 +2459,34 @@ out:
return ret;
 }
 
+static struct page *extent_same_get_page(struct inode *inode, u64 off)
+{
+   struct page *page;
+   pgoff_t index;
+   struct extent_io_tree *tree = BTRFS_I(inode)-io_tree;
+
+   index = off  PAGE_CACHE_SHIFT;
+
+   page = grab_cache_page(inode-i_mapping, index);
+   if (!page)
+   return NULL;
+
+   if (!PageUptodate(page)) {
+   if (extent_read_full_page_nolock(tree, page, btrfs_get_extent,
+0))
+   return NULL;
+   lock_page(page);
+   if (!PageUptodate(page)) {
+   unlock_page(page);
+   page_cache_release(page);
+   return NULL;
+   }
+   }
+   unlock_page(page);
+
+   return page;
+}
+
 static inline void lock_extent_range(struct inode *inode, u64 off, u64 len)
 {
/* do any pending delalloc/csum calc on src, one way or
@@ -2476,6 +2507,251 @@ static inline void lock_extent_range(struct inode 
*inode, u64 off, u64 len)
}
 }
 
+static void btrfs_double_unlock(struct inode *inode1, u64 loff1,
+   struct inode *inode2, u64 loff2, u64 len)
+{
+   unlock_extent(BTRFS_I(inode1)-io_tree, loff1, loff1 + len - 1);
+   unlock_extent(BTRFS_I(inode2)-io_tree, loff2, loff2 + len - 1);
+
+   mutex_unlock(inode1-i_mutex);
+   mutex_unlock(inode2-i_mutex);
+}
+
+static void btrfs_double_lock(struct inode *inode1, u64 loff1,
+ struct inode *inode2, u64 loff2, u64 len)
+{
+   if (inode1  inode2) {
+   swap(inode1, inode2);
+   swap(loff1, loff2);
+   }
+
+   mutex_lock_nested(inode1-i_mutex, I_MUTEX_PARENT);
+   lock_extent_range(inode1, loff1, len);
+   if (inode1 != inode2) {
+   mutex_lock_nested(inode2-i_mutex, I_MUTEX_CHILD);
+   lock_extent_range(inode2, loff2, len);
+   }
+}
+
+static int btrfs_cmp_data(struct inode *src, u64 loff, struct inode *dst,
+ u64 dst_loff, u64 len)
+{
+   int ret = 0;
+   struct page *src_page, *dst_page;
+   unsigned int cmp_len = PAGE_CACHE_SIZE;
+   void *addr, *dst_addr;
+
+   while (len) {
+   if (len  PAGE_CACHE_SIZE)
+   cmp_len = len;
+
+   src_page = extent_same_get_page(src, loff);
+   if (!src_page)
+   return -EINVAL;
+   dst_page = extent_same_get_page(dst, dst_loff);
+   if (!dst_page) {
+   page_cache_release(src_page);
+   return -EINVAL;
+   }
+   addr = kmap_atomic(src_page);
+   dst_addr = kmap_atomic(dst_page);
+
+   flush_dcache_page(src_page);
+   flush_dcache_page(dst_page);
+
+   if (memcmp(addr, dst_addr, cmp_len))
+   ret = BTRFS_SAME_DATA_DIFFERS;
+
+   kunmap_atomic(addr);
+   kunmap_atomic(dst_addr);
+   page_cache_release(src_page);
+   page_cache_release(dst_page);
+
+   if (ret)
+   break;
+
+   loff += cmp_len;
+   dst_loff += cmp_len;
+   len -= cmp_len;
+   }
+
+   return ret;
+}
+
+static int extent_same_check_offsets(struct inode *inode, u64 off, u64 len)
+{
+   u64 bs = BTRFS_I(inode)-root-fs_info-sb-s_blocksize;
+
+   if (off + len  inode-i_size || off + len  off)
+   return -EINVAL;
+   /* Check that we are block aligned - btrfs_clone() requires this */
+   if (!IS_ALIGNED(off, bs) || !IS_ALIGNED(off + len, bs))
+   

Re: [PATCH] btrfs-progs: don't overrun answer array in cmds-chunk.c

2013-08-06 Thread Zach Brown
  If you're in here, want to reimplement this thing in a few lines of
  scanf(%s) and strcasecmp()?  I can give it a go if you don't want to.
 
 I think it is better that moving it to utils.c because the other commands
 may use it in the future.

I disagree.  Let's stick to only writing the code that we need.
Implementing and testing code that meets future needs that we make up
isn't a good use of our time.  If someone has to tweak this in the
future, so be it.  They'll actually be in a position to implement and
test their needs.

Anyway, here's how I'd do a trivial y/n prompt.

- z

From 2c46c2b81061f1c55de07a80d9d177a7df7b33cb Mon Sep 17 00:00:00 2001
From: Zach Brown z...@redhat.com
Date: Tue, 6 Aug 2013 11:30:21 -0700
Subject: [PATCH] btrfs-progs: simplify ask_user()

Eric noticed the trivial stack overflow bug in ask_user().  I went to
see the context for that fix and found that ask_user() was a bit much.

This fixes the overflow bug that Eric found, endless spinning on scanf()
errors, removes dead code, and leaves us with a trivial helper.

Signed-off-by: Zach Brown z...@redhat.com
---
 cmds-chunk.c | 65 +---
 1 file changed, 14 insertions(+), 51 deletions(-)

diff --git a/cmds-chunk.c b/cmds-chunk.c
index 03314de..35a5c69 100644
--- a/cmds-chunk.c
+++ b/cmds-chunk.c
@@ -1307,58 +1307,22 @@ fail_close_fd:
return ret;
 }
 
-static int ask_user(char *question, int defval)
+/*
+ * This reads a line from the stdin and only returns non-zero if the
+ * first whitespace delimited token is a case insensitive match with yes
+ * or y.
+ */
+static int ask_user(char *question)
 {
-   char answer[5];
-   char *defstr;
-   int i;
-
-   if (defval == 1)
-   defstr = [Y/n];
-   else if (defval == 0)
-   defstr = [y/N];
-   else if (defval == -1)
-   defstr = [y/n];
-   else
-   BUG_ON(1);
-again:
-   printf(%s%s? , question, defstr);
-
-   i = 0;
-   while (i  4  scanf(%c, answer[i])) {
-   if (answer[i] == '\n') {
-   answer[i] = '\0';
-   break;
-   } else if (answer[i] == ' '){
-   answer[i] = '\0';
-   if (i == 0)
-   continue;
-   else
-   break;
-   } else if (answer[i] = 'A'  answer[i] = 'Z') {
-   answer[i] += 'a' - 'A';
-   }
-   i++;
-   }
-   answer[5] = '\0';
-   __fpurge(stdin);
-
-   if (strlen(answer) == 0) {
-   if (defval != -1)
-   return defval;
-   else
-   goto again;
-   }
+   char buf[30] = {0,};
+   char *saveptr = NULL;
+   char *answer;
 
-   if (!strcmp(answer, yes) ||
-   !strcmp(answer, y))
-   return 1;
-
-   if (!strcmp(answer, no) ||
-   !strcmp(answer, n))
-   return 0;
+   printf(%s [y/N]: , question);
 
-   goto again;
+   return fgets(buf, sizeof(buf) - 1, stdin) 
+  (answer = strtok_r(buf,  \t\n\r, saveptr)) 
+  (!strcasecmp(answer, yes) || !strcasecmp(answer, y));
 }
 
 static int btrfs_get_device_extents(u64 chunk_object,
@@ -1752,8 +1716,7 @@ static int btrfs_recover_chunk_tree(char *path, int 
verbose, int yes)
}
 
if (!rc.yes) {
-   ret = ask_user(We are going to rebuild the chunk tree on disk, 
it might destroy the old metadata on the disk, Are you sure,
-  0);
+   ret = ask_user(We are going to rebuild the chunk tree on disk, 
it might destroy the old metadata on the disk, Are you sure?);
if (!ret) {
ret = BTRFS_CHUNK_TREE_REBUILD_ABORTED;
goto fail_close_ctree;
-- 
1.7.11.7

--
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 4/4] btrfs: offline dedupe

2013-08-06 Thread Zach Brown
On Tue, Aug 06, 2013 at 11:42:51AM -0700, Mark Fasheh wrote:
 This patch adds an ioctl, BTRFS_IOC_FILE_EXTENT_SAME which will try to
 de-duplicate a list of extents across a range of files.

This addresses all my previous issues (save the interface that we've
aggreed to disagree on).  Thanks for taking the time to fix it up.

Reviewed-by: Zach Brown z...@redhat.com

- z
--
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 RFC] Btrfs: add support for persistent mount options

2013-08-06 Thread Eric Sandeen
On 8/6/13 1:27 PM, Filipe David Borba Manana wrote:
 This change allows for most mount options to be persisted in
 the filesystem, and be applied when the filesystem is mounted.
 If the same options are specified at mount time, the persisted
 values for those options are ignored.
 
 The only options not supported are: subvol, subvolid, subvolrootid,
 device and thread_pool. This limitation is due to how this feature
 is implemented: basically there's an optional value (of type
 struct btrfs_dir_item) in the tree of tree roots used to store the
 list of options in the same format as they are passed to btrfs_mount().
 This means any mount option that takes effect before the tree of tree
 roots is setup is not supported.
 
 To set these options, the user space tool btrfstune was modified
 to persist the list of options into an unmounted filesystem's
 tree of tree roots.

So, it does this thing, ok - but why?
What is seen as the administrative advantage of this new mechanism?

Just to play devil's advocate, and to add a bit of history:

On any production system, the filesystems will be mounted via fstab,
which has the advantages of being widely known, well understood, and
100% expected - as well as being transparent, unsurprising, and seamless.

For history: ext4 did this too.  And now it's in a situation where it's
got mount options coming at it from both the superblock and from
the commandline (or fstab), and sometimes they conflict; it also tries
to report mount options in /proc/mounts, but has grown hairy code
to decide which ones to print and which ones to not print (if it's
a default option, don't print it in /proc/mounts, but what's default,
code-default or fs-default?)  And it's really kind of an ugly mess.

Further, mounting 2 filesystems w/ no options in fstab or on the
commandline, and getting different behavior due to hidden (sorry,
persistent) options in the fs itself is surprising, and surprise
is rarely good.

So this patch adds 100+ lines of new code, to implement this idea, but:
what is the advantage?  Unless there is a compelling administrative
use case, I'd vote against it.  Lines of code that don't exist don't
have bugs.  ;)

-Eric

 NOTE: Like the corresponding btrfs-progs patch, this is a WIP with
 the goal o gathering feedback.
 
 Signed-off-by: Filipe David Borba Manana fdman...@gmail.com
 ---
  fs/btrfs/ctree.h   |   11 +++-
  fs/btrfs/disk-io.c |   72 
 +++-
  fs/btrfs/super.c   |   46 +++--
  3 files changed, 125 insertions(+), 4 deletions(-)
 
 diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
 index cbb1263..24363df 100644
 --- a/fs/btrfs/ctree.h
 +++ b/fs/btrfs/ctree.h
 @@ -121,6 +121,14 @@ struct btrfs_ordered_sum;
   */
  #define BTRFS_FREE_INO_OBJECTID -12ULL
  
 +/*
 + * Item that stores permanent mount options. These options
 + * have effect if they are not specified as well at mount
 + * time (that is, if a permanent option is also specified at
 + * mount time, the later wins).
 + */
 +#define BTRFS_PERSISTENT_OPTIONS_OBJECTID -13ULL
 +
  /* dummy objectid represents multiple objectids */
  #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
  
 @@ -3739,7 +3747,8 @@ void btrfs_exit_sysfs(void);
  ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
  
  /* super.c */
 -int btrfs_parse_options(struct btrfs_root *root, char *options);
 +int btrfs_parse_options(struct btrfs_root *root, char *options,
 + int parsing_persistent, int **options_parsed);
  int btrfs_sync_fs(struct super_block *sb, int wait);
  
  #ifdef CONFIG_PRINTK
 diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
 index 254cdc8..eeabdd4 100644
 --- a/fs/btrfs/disk-io.c
 +++ b/fs/btrfs/disk-io.c
 @@ -2077,6 +2077,53 @@ static void del_fs_roots(struct btrfs_fs_info *fs_info)
   }
  }
  
 +static char *get_persistent_options(struct btrfs_root *tree_root)
 +{
 + int ret;
 + struct btrfs_key key;
 + struct btrfs_path *path;
 + struct extent_buffer *leaf;
 + struct btrfs_dir_item *di;
 + u32 name_len, data_len;
 + char *options = NULL;
 +
 + path = btrfs_alloc_path();
 + if (!path)
 + return ERR_PTR(-ENOMEM);
 +
 + key.objectid = BTRFS_PERSISTENT_OPTIONS_OBJECTID;
 + key.type = 0;
 + key.offset = 0;
 +
 + ret = btrfs_search_slot(NULL, tree_root, key, path, 0, 0);
 + if (ret  0)
 + goto out;
 + if (ret  0) {
 + ret = 0;
 + goto out;
 + }
 +
 + leaf = path-nodes[0];
 + di = btrfs_item_ptr(leaf, path-slots[0], struct btrfs_dir_item);
 + name_len = btrfs_dir_name_len(leaf, di);
 + data_len = btrfs_dir_data_len(leaf, di);
 + options = kmalloc(data_len + 1, GFP_NOFS);
 + if (!options) {
 + ret = -ENOMEM;
 + goto out;
 + }
 + read_extent_buffer(leaf, options,
 +(unsigned long)((char *)(di + 1) + name_len),
 +

Re: [PATCH v2 1/2] xfstests: add fssum tool

2013-08-06 Thread Josef Bacik
On Wed, Jul 24, 2013 at 05:07:28PM +0200, Jan Schmidt wrote:
 fssum is a tool to build a recursive checksum for a file system. The home
 repository of fssum is
 
 git://git.kernel.org/pub/scm/linux/kernel/git/arne/far-progs.git
 
 It is added as an optional target, because it depends on glibc = 2.15 for
 SEEK_HOLE / SEEK_DATA. The test to be added using fssum will just be skipped
 if fssum wasn't built.
 
 Signed-off-by: Jan Schmidt list@jan-o-sch.net
 ---
  .gitignore|1 +
  common/config |2 +
  src/Makefile  |   11 +-
  src/fssum.c   |  819 
 +
  4 files changed, 832 insertions(+), 1 deletions(-)
  create mode 100644 src/fssum.c
 
 diff --git a/.gitignore b/.gitignore
 index 11594aa..c2fc6e3 100644
 --- a/.gitignore
 +++ b/.gitignore
 @@ -45,6 +45,7 @@
  /src/fill
  /src/fill2
  /src/fs_perms
 +/src/fssum
  /src/fstest
  /src/fsync-tester
  /src/ftrunc
 diff --git a/common/config b/common/config
 index 67c1498..c8bee29 100644
 --- a/common/config
 +++ b/common/config
 @@ -146,6 +146,8 @@ export SED_PROG=`set_prog_path sed`
  export BC_PROG=`set_prog_path bc`
  [ $BC_PROG =  ]  _fatal bc not found
  
 +export FSSUM_PROG=`set_prog_path fssum $here/src/fssum`
 +
  export PS_ALL_FLAGS=-ef
  
  export DF_PROG=`set_prog_path df`
 diff --git a/src/Makefile b/src/Makefile
 index cc679e8..a840669 100644
 --- a/src/Makefile
 +++ b/src/Makefile
 @@ -20,10 +20,14 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize 
 preallo_rw_pattern_reader \
   stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
   seek_copy_test t_readdir_1 t_readdir_2 fsync-tester
  
 +OPT_TARGETS = fssum
 +
  SUBDIRS =
  
  LLDLIBS = $(LIBATTR) $(LIBHANDLE) $(LIBACL)
  
 +OPT_LDLIBS = -lssl
 +

I had to add -lcrypto here for this to build, and I checked my copy of far-progs
and it looks like I'm not just crazy that you guys actually do -lcrypto in
far-progs as well, so looks like you missed it.  Thanks,

Josef
--
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 2/2] xfstests btrfs/316: test send / receive

2013-08-06 Thread Josef Bacik
On Wed, Jul 24, 2013 at 05:07:29PM +0200, Jan Schmidt wrote:
 Basic send / receive functionality test for btrfs. Requires current
 version of fsstress built (-x support). Relies on fssum tool but can
 skip the test if it failed to build.
 
 Signed-off-by: Jan Schmidt list@jan-o-sch.net
 ---
  README  |3 +
  tests/btrfs/316 |  113 
 +++
  tests/btrfs/316.out |4 ++
  tests/btrfs/group   |1 +
  4 files changed, 121 insertions(+), 0 deletions(-)
  create mode 100755 tests/btrfs/316
  create mode 100644 tests/btrfs/316.out
 
 diff --git a/README b/README
 index a49ca7c..d287f63 100644
 --- a/README
 +++ b/README
 @@ -26,6 +26,9 @@ Preparing system for tests (IRIX and Linux):
http://www.extra.research.philips.com/udf/, then copy the udf_test 
binary to xfstests/src/. If you wish to disable UDF verification test
set the environment variable DISABLE_UDF_TEST to 1.
 +- If you wish to run the btrfs send / receive components of the suite
 +  install fssum from
 +git://git.kernel.org/pub/scm/linux/kernel/git/arne/far-progs.git
   
  
  - create one or two partitions to use for testing
 diff --git a/tests/btrfs/316 b/tests/btrfs/316
 new file mode 100755
 index 000..2e86428
 --- /dev/null
 +++ b/tests/btrfs/316
 @@ -0,0 +1,113 @@
 +#! /bin/bash
 +# FSQA Test No. 314
 +#
 +# Run fsstress to create a reasonably strange file system, make a
 +# snapshot (base) and run more fsstress. Then take another snapshot
 +# (incr) and send both snapshots to a temp file. Remake the file
 +# system and receive from the files. Check both states with fssum.
 +#
 +#---
 +# Copyright (C) 2013 STRATO.  All rights reserved.
 +#
 +# This program is free software; you can redistribute it and/or
 +# modify it under the terms of the GNU General Public License as
 +# published by the Free Software Foundation.
 +#
 +# This program is distributed in the hope that it would be useful,
 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +# GNU General Public License for more details.
 +#
 +# You should have received a copy of the GNU General Public License
 +# along with this program; if not, write the Free Software Foundation,
 +# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 +#
 +#---
 +#
 +# creator
 +owner=list.bt...@jan-o-sch.net
 +
 +seq=`basename $0`
 +seqres=$RESULT_DIR/$seq
 +echo QA output created by $seq
 +
 +here=`pwd`
 +tmp=`mktemp -d`
 +status=1
 +
 +_cleanup()
 +{
 + echo *** unmount
 + umount $SCRATCH_MNT 2/dev/null
 + rm -f $tmp.*
 +}
 +trap _cleanup; exit \$status 0 1 2 3 15
 +
 +# get standard environment, filters and checks
 +. ./common/rc
 +. ./common/filter
 +
 +# real QA test starts here
 +_need_to_be_root
 +_supported_fs btrfs
 +_supported_os Linux
 +_require_scratch
 +_require_command $FSSUM_PROG fssum
 +
 +rm -f $seqres.full
 +
 +workout()
 +{
 + fsz=$1
 + ops=$2
 +
 + umount $SCRATCH_DEV /dev/null 21
 + echo *** mkfs -dsize=$fsz$seqres.full
 + echo  $seqres.full
 + _scratch_mkfs_sized $fsz $seqres.full 21 \
 + || _fail size=$fsz mkfs failed
 + run_check _scratch_mount -o noatime
 +
 + run_check $FSSTRESS_PROG -d $SCRATCH_MNT -n $ops $FSSTRESS_AVOID -x \
 + $BTRFS_UTIL_PROG subvol snap -r $SCRATCH_MNT $SCRATCH_MNT/base
 +
 + run_check $BTRFS_UTIL_PROG subvol snap -r $SCRATCH_MNT $SCRATCH_MNT/incr
 +
 + echo # $BTRFS_UTIL_PROG send $SCRATCH_MNT/base  $tmp/base.snap \
 +  $seqres.full
 + $BTRFS_UTIL_PROG send $SCRATCH_MNT/base  $tmp/base.snap 2 
 $seqres.full \
 + || _fail failed: '$@'
 + echo # $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base\
 + $SCRATCH_MNT/incr  $tmp/incr.snap  $seqres.full
 + $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base \
 + $SCRATCH_MNT/incr  $tmp/incr.snap 2 $seqres.full \
 + || _fail failed: '$@'
 +
 + run_check $FSSUM_PROG -A -f -w $tmp/base.fssum $SCRATCH_MNT/base
 + run_check $FSSUM_PROG -A -f -w $tmp/incr.fssum -x 
 $SCRATCH_MNT/incr/base \
 + $SCRATCH_MNT/incr
 +
 + umount $SCRATCH_DEV /dev/null 21
 + echo *** mkfs -dsize=$fsz$seqres.full
 + echo  $seqres.full
 + _scratch_mkfs_sized $fsz $seqres.full 21 \
 + || _fail size=$fsz mkfs failed
 + run_check _scratch_mount -o noatime
 +
 + run_check $BTRFS_UTIL_PROG receive $SCRATCH_MNT  $tmp/base.snap
 + run_check $FSSUM_PROG -r $tmp/base.fssum $SCRATCH_MNT/base
 +
 + run_check $BTRFS_UTIL_PROG receive $SCRATCH_MNT  $tmp/incr.snap
 + run_check $FSSUM_PROG -r $tmp/incr.fssum $SCRATCH_MNT/incr
 +}
 +
 +echo 

Re: [PATCH RFC] Btrfs: add support for persistent mount options

2013-08-06 Thread Filipe David Manana
On Tue, Aug 6, 2013 at 9:37 PM, Eric Sandeen sand...@redhat.com wrote:
 On 8/6/13 1:27 PM, Filipe David Borba Manana wrote:
 This change allows for most mount options to be persisted in
 the filesystem, and be applied when the filesystem is mounted.
 If the same options are specified at mount time, the persisted
 values for those options are ignored.

 The only options not supported are: subvol, subvolid, subvolrootid,
 device and thread_pool. This limitation is due to how this feature
 is implemented: basically there's an optional value (of type
 struct btrfs_dir_item) in the tree of tree roots used to store the
 list of options in the same format as they are passed to btrfs_mount().
 This means any mount option that takes effect before the tree of tree
 roots is setup is not supported.

 To set these options, the user space tool btrfstune was modified
 to persist the list of options into an unmounted filesystem's
 tree of tree roots.

 So, it does this thing, ok - but why?
 What is seen as the administrative advantage of this new mechanism?

 Just to play devil's advocate, and to add a bit of history:

 On any production system, the filesystems will be mounted via fstab,
 which has the advantages of being widely known, well understood, and
 100% expected - as well as being transparent, unsurprising, and seamless.

 For history: ext4 did this too.  And now it's in a situation where it's
 got mount options coming at it from both the superblock and from
 the commandline (or fstab), and sometimes they conflict; it also tries
 to report mount options in /proc/mounts, but has grown hairy code
 to decide which ones to print and which ones to not print (if it's
 a default option, don't print it in /proc/mounts, but what's default,
 code-default or fs-default?)  And it's really kind of an ugly mess.

 Further, mounting 2 filesystems w/ no options in fstab or on the
 commandline, and getting different behavior due to hidden (sorry,
 persistent) options in the fs itself is surprising, and surprise
 is rarely good.

 So this patch adds 100+ lines of new code, to implement this idea, but:
 what is the advantage?  Unless there is a compelling administrative
 use case, I'd vote against it.  Lines of code that don't exist don't
 have bugs.  ;)

There was a recent good example (imho at least) mentioned by Xavier
Gnata some time ago:

http://comments.gmane.org/gmane.comp.file-systems.btrfs/26011

cheers



 -Eric

 NOTE: Like the corresponding btrfs-progs patch, this is a WIP with
 the goal o gathering feedback.

 Signed-off-by: Filipe David Borba Manana fdman...@gmail.com
 ---
  fs/btrfs/ctree.h   |   11 +++-
  fs/btrfs/disk-io.c |   72 
 +++-
  fs/btrfs/super.c   |   46 +++--
  3 files changed, 125 insertions(+), 4 deletions(-)

 diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
 index cbb1263..24363df 100644
 --- a/fs/btrfs/ctree.h
 +++ b/fs/btrfs/ctree.h
 @@ -121,6 +121,14 @@ struct btrfs_ordered_sum;
   */
  #define BTRFS_FREE_INO_OBJECTID -12ULL

 +/*
 + * Item that stores permanent mount options. These options
 + * have effect if they are not specified as well at mount
 + * time (that is, if a permanent option is also specified at
 + * mount time, the later wins).
 + */
 +#define BTRFS_PERSISTENT_OPTIONS_OBJECTID -13ULL
 +
  /* dummy objectid represents multiple objectids */
  #define BTRFS_MULTIPLE_OBJECTIDS -255ULL

 @@ -3739,7 +3747,8 @@ void btrfs_exit_sysfs(void);
  ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);

  /* super.c */
 -int btrfs_parse_options(struct btrfs_root *root, char *options);
 +int btrfs_parse_options(struct btrfs_root *root, char *options,
 + int parsing_persistent, int **options_parsed);
  int btrfs_sync_fs(struct super_block *sb, int wait);

  #ifdef CONFIG_PRINTK
 diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
 index 254cdc8..eeabdd4 100644
 --- a/fs/btrfs/disk-io.c
 +++ b/fs/btrfs/disk-io.c
 @@ -2077,6 +2077,53 @@ static void del_fs_roots(struct btrfs_fs_info 
 *fs_info)
   }
  }

 +static char *get_persistent_options(struct btrfs_root *tree_root)
 +{
 + int ret;
 + struct btrfs_key key;
 + struct btrfs_path *path;
 + struct extent_buffer *leaf;
 + struct btrfs_dir_item *di;
 + u32 name_len, data_len;
 + char *options = NULL;
 +
 + path = btrfs_alloc_path();
 + if (!path)
 + return ERR_PTR(-ENOMEM);
 +
 + key.objectid = BTRFS_PERSISTENT_OPTIONS_OBJECTID;
 + key.type = 0;
 + key.offset = 0;
 +
 + ret = btrfs_search_slot(NULL, tree_root, key, path, 0, 0);
 + if (ret  0)
 + goto out;
 + if (ret  0) {
 + ret = 0;
 + goto out;
 + }
 +
 + leaf = path-nodes[0];
 + di = btrfs_item_ptr(leaf, path-slots[0], struct btrfs_dir_item);
 + name_len = btrfs_dir_name_len(leaf, di);
 + data_len = btrfs_dir_data_len(leaf, di);
 + options = 

[PATCH] Btrfs: check our parent dir when doing a compare send

2013-08-06 Thread Josef Bacik
When doing a send with a parent subvol we will check to see if the file we are
acting on is being overwritten and move it if we think it may be needed further
down the line during the send.  We check this by checking its directory and
making sure it existed in the parent and making sure the file existed in the
parent.  The problem with this check is that if we create a directory and a file
in that directory, and then snapshot, and then remove and re-create that same
directory and file with different inode numbers and then try to snapshot and
send with the original parent we will try and save the original file inside of
that directory.  This is a problem because during the receive we move the
directory out of the way because it is a completely new inode, which makes us
unable to find the old file inside of the directory when we try to move that out
of the way for the overwrite.  We fix this by checking the parent directory of
the inode we think we are overwriting.  If the parent directory generation in
the send root != the parent directory generation in the parent root then we know
it is a completely new directory and we need not bother with moving the file out
of the way because it would have been completely destroyed.  This fixes bz
60673.  Thanks,

Signed-off-by: Josef Bacik jba...@fusionio.com
---
 fs/btrfs/send.c |   28 ++--
 1 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index d3f3b43..ab82473 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -34,9 +34,9 @@
 #include btrfs_inode.h
 #include transaction.h
 
-static int g_verbose = 0;
+static int g_verbose = 1;
 
-#define verbose_printk(...) if (g_verbose) printk(__VA_ARGS__)
+#define verbose_printk(...) if (g_verbose) trace_printk(__VA_ARGS__)
 
 /*
  * A fs_path is a helper to dynamically build path names with unknown size.
@@ -608,8 +608,13 @@ static int send_rename(struct send_ctx *sctx,
 struct fs_path *from, struct fs_path *to)
 {
int ret;
+   int len = strlen(from-start);
+   char blah[] = nixpkgs/pkgs/development/libraries/liblqr-1/default.nix;
+
 
 verbose_printk(btrfs: send_rename %s - %s\n, from-start, to-start);
+   if (len == strlen(blah)  !memcmp(blah, from-start, len ))
+   dump_stack();
 
ret = begin_cmd(sctx, BTRFS_SEND_C_RENAME);
if (ret  0)
@@ -1668,6 +1673,7 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 
dir, u64 dir_gen,
  u64 *who_ino, u64 *who_gen)
 {
int ret = 0;
+   u64 gen;
u64 other_inode = 0;
u8 other_type = 0;
 
@@ -1678,6 +1684,24 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 
dir, u64 dir_gen,
if (ret = 0)
goto out;
 
+   /*
+* If we have a parent root we need to verify that the parent dir was
+* not delted and then re-created, if it was then we have no overwrite
+* and we can just unlink this entry.
+*/
+   if (sctx-parent_root) {
+   ret = get_inode_info(sctx-parent_root, dir, NULL, gen, NULL,
+NULL, NULL, NULL);
+   if (ret  0  ret != -ENOENT)
+   goto out;
+   if (ret) {
+   ret = 0;
+   goto out;
+   }
+   if (gen != dir_gen)
+   goto out;
+   }
+
ret = lookup_dir_item_inode(sctx-parent_root, dir, name, name_len,
other_inode, other_type);
if (ret  0  ret != -ENOENT)
-- 
1.7.7.6

--
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 RFC] Btrfs: add support for persistent mount options

2013-08-06 Thread Eric Sandeen
On 8/6/13 3:45 PM, Filipe David Manana wrote:
 On Tue, Aug 6, 2013 at 9:37 PM, Eric Sandeen sand...@redhat.com wrote:
 On 8/6/13 1:27 PM, Filipe David Borba Manana wrote:
 This change allows for most mount options to be persisted in
 the filesystem, and be applied when the filesystem is mounted.
 If the same options are specified at mount time, the persisted
 values for those options are ignored.

 The only options not supported are: subvol, subvolid, subvolrootid,
 device and thread_pool. This limitation is due to how this feature
 is implemented: basically there's an optional value (of type
 struct btrfs_dir_item) in the tree of tree roots used to store the
 list of options in the same format as they are passed to btrfs_mount().
 This means any mount option that takes effect before the tree of tree
 roots is setup is not supported.

 To set these options, the user space tool btrfstune was modified
 to persist the list of options into an unmounted filesystem's
 tree of tree roots.

 So, it does this thing, ok - but why?
 What is seen as the administrative advantage of this new mechanism?

 Just to play devil's advocate, and to add a bit of history:

 On any production system, the filesystems will be mounted via fstab,
 which has the advantages of being widely known, well understood, and
 100% expected - as well as being transparent, unsurprising, and seamless.

 For history: ext4 did this too.  And now it's in a situation where it's
 got mount options coming at it from both the superblock and from
 the commandline (or fstab), and sometimes they conflict; it also tries
 to report mount options in /proc/mounts, but has grown hairy code
 to decide which ones to print and which ones to not print (if it's
 a default option, don't print it in /proc/mounts, but what's default,
 code-default or fs-default?)  And it's really kind of an ugly mess.

 Further, mounting 2 filesystems w/ no options in fstab or on the
 commandline, and getting different behavior due to hidden (sorry,
 persistent) options in the fs itself is surprising, and surprise
 is rarely good.

 So this patch adds 100+ lines of new code, to implement this idea, but:
 what is the advantage?  Unless there is a compelling administrative
 use case, I'd vote against it.  Lines of code that don't exist don't
 have bugs.  ;)
 
 There was a recent good example (imho at least) mentioned by Xavier
 Gnata some time ago:
 
 http://comments.gmane.org/gmane.comp.file-systems.btrfs/26011
 
 cheers

Hm, I see.  I forgot about hotplugging in my most systems mount
via fstab assertion.  :)

I was thinking (and Josef just suggested too) that making a
dir flag, saying everything under this dir gets compressed might make
more sense for that scenario than adding a whole slew of
on-disk-persistent-mount-option code.

Because really, the motivation sounds like it's primarily for significant
on-disk format changes controlled by mount options.  I understand that
motivation more than being able to persist something like noatime.

-Eric

--
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: check our parent dir when doing a compare send V2

2013-08-06 Thread Josef Bacik
When doing a send with a parent subvol we will check to see if the file we are
acting on is being overwritten and move it if we think it may be needed further
down the line during the send.  We check this by checking its directory and
making sure it existed in the parent and making sure the file existed in the
parent.  The problem with this check is that if we create a directory and a file
in that directory, and then snapshot, and then remove and re-create that same
directory and file with different inode numbers and then try to snapshot and
send with the original parent we will try and save the original file inside of
that directory.  This is a problem because during the receive we move the
directory out of the way because it is a completely new inode, which makes us
unable to find the old file inside of the directory when we try to move that out
of the way for the overwrite.  We fix this by checking the parent directory of
the inode we think we are overwriting.  If the parent directory generation in
the send root != the parent directory generation in the parent root then we know
it is a completely new directory and we need not bother with moving the file out
of the way because it would have been completely destroyed.  This fixes bz
60673.  Thanks,

Signed-off-by: Josef Bacik jba...@fusionio.com
---
V1-V2: remove the debugging stuff

 fs/btrfs/send.c |   19 +++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index d3f3b43..0efc2e2 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -1668,6 +1668,7 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 
dir, u64 dir_gen,
  u64 *who_ino, u64 *who_gen)
 {
int ret = 0;
+   u64 gen;
u64 other_inode = 0;
u8 other_type = 0;
 
@@ -1678,6 +1679,24 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 
dir, u64 dir_gen,
if (ret = 0)
goto out;
 
+   /*
+* If we have a parent root we need to verify that the parent dir was
+* not delted and then re-created, if it was then we have no overwrite
+* and we can just unlink this entry.
+*/
+   if (sctx-parent_root) {
+   ret = get_inode_info(sctx-parent_root, dir, NULL, gen, NULL,
+NULL, NULL, NULL);
+   if (ret  0  ret != -ENOENT)
+   goto out;
+   if (ret) {
+   ret = 0;
+   goto out;
+   }
+   if (gen != dir_gen)
+   goto out;
+   }
+
ret = lookup_dir_item_inode(sctx-parent_root, dir, name, name_len,
other_inode, other_type);
if (ret  0  ret != -ENOENT)
-- 
1.7.7.6

--
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 0/2] btrfs-progs: more statics removals

2013-08-06 Thread Eric Sandeen
2 patches, one for shared kernel files, one for pure userspace.

In kernelspace, lots of unused functions purged.  Some functions
which could be static are left alone if they aren't marked static
in kernelspace.

userspace only has a couple removals, mostly just marking static
 removing prototypes in headers as appropriate.

Thanks,
-Eric
--
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: mark static remove unused from shared kernel code

2013-08-06 Thread Eric Sandeen
In files copied from the kernel, mark many functions as static,
and remove any resulting dead code.

Some functions are left unmarked if they aren't static in the
kernel tree.

Signed-off-by: Eric Sandeen sand...@redhat.com
---

 ctree.c|2 
 ctree.h|   43 ---
 dir-item.c |   97 ++--
 disk-io.c  |   14 +++---
 disk-io.h  |4 -
 extent-tree.c  |  115 +++--
 extent_io.c|   10 
 extent_io.h|2 
 file-item.c|   32 ++
 free-space-cache.c |2 
 inode-item.c   |   73 -
 inode-map.c|   32 --
 qgroup.c   |4 -
 qgroup.h   |2 
 root-tree.c|   27 
 volumes.c  |   69 ++-
 volumes.h  |7 ---
 17 files changed, 38 insertions(+), 497 deletions(-)

diff --git a/ctree.c b/ctree.c
index 66b146b..a79ed13 100644
--- a/ctree.c
+++ b/ctree.c
@@ -371,7 +371,7 @@ int btrfs_cow_block(struct btrfs_trans_handle *trans,
 /*
  * compare two keys in a memcmp fashion
  */
-int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2)
+static int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2)
 {
struct btrfs_key k1;
 
diff --git a/ctree.h b/ctree.h
index 257396d..16914a4 100644
--- a/ctree.h
+++ b/ctree.h
@@ -2097,23 +2097,17 @@ static inline int btrfs_fs_incompat(struct 
btrfs_fs_info *fs_info, u64 flag)
 /* extent-tree.c */
 int btrfs_fix_block_accounting(struct btrfs_trans_handle *trans,
 struct btrfs_root *root);
-int btrfs_check_block_accounting(struct btrfs_root *root);
 void btrfs_pin_extent(struct btrfs_fs_info *fs_info, u64 bytenr, u64 
num_bytes);
 void btrfs_unpin_extent(struct btrfs_fs_info *fs_info,
u64 bytenr, u64 num_bytes);
 int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
 struct btrfs_root *root);
-int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
 struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
 btrfs_fs_info *info,
 u64 bytenr);
 struct btrfs_block_group_cache *btrfs_lookup_first_block_group(struct
   btrfs_fs_info *info,
   u64 bytenr);
-struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
-struct btrfs_block_group_cache
-*hint, u64 search_start,
-int data, int owner);
 struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u32 blocksize, u64 root_objectid,
@@ -2184,7 +2178,6 @@ struct extent_buffer *read_node_slot(struct btrfs_root 
*root,
 int btrfs_previous_item(struct btrfs_root *root,
struct btrfs_path *path, u64 min_objectid,
int type);
-int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
 int btrfs_cow_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct extent_buffer *buf,
struct extent_buffer *parent, int parent_slot,
@@ -2257,8 +2250,6 @@ int btrfs_add_root_ref(struct btrfs_trans_handle *trans,
   u64 root_id, u8 type, u64 ref_id,
   u64 dirid, u64 sequence,
   const char *name, int name_len);
-int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
-  struct btrfs_key *key);
 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
  *root, struct btrfs_key *key, struct btrfs_root_item
  *item);
@@ -2276,46 +2267,20 @@ struct btrfs_dir_item *btrfs_lookup_dir_item(struct 
btrfs_trans_handle *trans,
 struct btrfs_path *path, u64 dir,
 const char *name, int name_len,
 int mod);
-struct btrfs_dir_item *
-btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
-   struct btrfs_root *root,
-   struct btrfs_path *path, u64 dir,
-   u64 objectid, const char *name, int name_len,
-   int mod);
-struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
- struct btrfs_path *path,
- const char *name, int name_len);
-int 

[PATCH 2/2] btrfs-progs: mark static remove unused from non-kernel code

2013-08-06 Thread Eric Sandeen
Mark many functions as static, and remove any resulting dead code.

Signed-off-by: Eric Sandeen sand...@redhat.com
---

 btrfs-convert.c |8 
 btrfs-find-root.c   |2 +-
 btrfs-list.c|   10 +-
 btrfs-list.h|3 ---
 btrfs-map-logical.c |4 ++--
 btrfs.c |5 +++--
 btrfstune.c |6 +++---
 cmds-chunk.c|5 +++--
 cmds-qgroup.c   |4 ++--
 cmds-quota.c|2 +-
 cmds-receive.c  |4 ++--
 cmds-restore.c  |2 +-
 cmds-scrub.c|2 +-
 ioctl-test.c|2 +-
 quick-test.c|2 +-
 send-test.c |2 +-
 send-utils.c|9 -
 send-utils.h|2 --
 utils.c |   18 ++
 utils.h |3 ---
 20 files changed, 41 insertions(+), 54 deletions(-)

diff --git a/btrfs-convert.c b/btrfs-convert.c
index a9ac9a5..7eaa478 100644
--- a/btrfs-convert.c
+++ b/btrfs-convert.c
@@ -1418,8 +1418,8 @@ fail:
return ret;
 }
 
-struct btrfs_root *link_subvol(struct btrfs_root *root, const char *base,
-  u64 root_objectid)
+static struct btrfs_root *
+link_subvol(struct btrfs_root *root, const char *base, u64 root_objectid)
 {
struct btrfs_trans_handle *trans;
struct btrfs_fs_info *fs_info = root-fs_info;
@@ -2277,7 +2277,7 @@ err:
return ret;
 }
 
-int do_convert(const char *devname, int datacsum, int packing, int noxattr)
+static int do_convert(const char *devname, int datacsum, int packing, int 
noxattr)
 {
int i, ret;
int fd = -1;
@@ -2456,7 +2456,7 @@ fail:
return -1;
 }
 
-int do_rollback(const char *devname, int force)
+static int do_rollback(const char *devname, int force)
 {
int fd = -1;
int ret;
diff --git a/btrfs-find-root.c b/btrfs-find-root.c
index 989535f..1912f9d 100644
--- a/btrfs-find-root.c
+++ b/btrfs-find-root.c
@@ -46,7 +46,7 @@ static void usage()
[ -g search_generation ] [ -l search_level ] device\n);
 }
 
-int csum_block(void *buf, u32 len)
+static int csum_block(void *buf, u32 len)
 {
char *result;
u32 crc = ~(u32)0;
diff --git a/btrfs-list.c b/btrfs-list.c
index a6902c3..0a9c52c 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -46,7 +46,7 @@ struct root_lookup {
struct rb_root root;
 };
 
-struct {
+static struct {
char*name;
char*column_name;
int need_print;
@@ -240,7 +240,7 @@ void btrfs_list_free_comparer_set(struct 
btrfs_list_comparer_set *comp_set)
free(comp_set);
 }
 
-int btrfs_list_setup_comparer(struct btrfs_list_comparer_set  **comp_set,
+static int btrfs_list_setup_comparer(struct btrfs_list_comparer_set  
**comp_set,
  enum btrfs_list_comp_enum comparer,
  int is_descending)
 {
@@ -820,7 +820,7 @@ static char *__ino_resolve(int fd, u64 dirid)
  * simple string builder, returning a new string with both
  * dirid and name
  */
-char *build_name(char *dirid, char *name)
+static char *build_name(char *dirid, char *name)
 {
char *full;
if (!dirid)
@@ -1477,7 +1477,7 @@ static void print_all_volume_info(struct root_lookup 
*sorted_tree,
}
 }
 
-int btrfs_list_subvols(int fd, struct root_lookup *root_lookup)
+static int btrfs_list_subvols(int fd, struct root_lookup *root_lookup)
 {
int ret;
 
@@ -1522,7 +1522,7 @@ int btrfs_list_subvols_print(int fd, struct 
btrfs_list_filter_set *filter_set,
return 0;
 }
 
-char *strdup_or_null(const char *s)
+static char *strdup_or_null(const char *s)
 {
if (!s)
return NULL;
diff --git a/btrfs-list.h b/btrfs-list.h
index d3fd9e2..5164467 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -150,9 +150,6 @@ int btrfs_list_setup_filter(struct btrfs_list_filter_set 
**filter_set,
enum btrfs_list_filter_enum filter, u64 data);
 struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void);
 void btrfs_list_free_comparer_set(struct btrfs_list_comparer_set *comp_set);
-int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
- enum btrfs_list_comp_enum comparer,
- int is_descending);
 
 int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
   struct btrfs_list_comparer_set *comp_set,
diff --git a/btrfs-map-logical.c b/btrfs-map-logical.c
index b9635f7..f17d2a0 100644
--- a/btrfs-map-logical.c
+++ b/btrfs-map-logical.c
@@ -37,8 +37,8 @@
  * */
 static FILE *info_file;
 
-struct extent_buffer *debug_read_block(struct btrfs_root *root, u64 bytenr,
-u32 blocksize, int copy)
+static struct extent_buffer *
+debug_read_block(struct btrfs_root *root, u64 bytenr, u32 blocksize, int copy)
 {
int ret;
struct extent_buffer *eb;
diff --git a/btrfs.c b/btrfs.c
index 4e93e13..9e212ce 100644
--- 

Re: [PATCH RFC] Btrfs: add support for persistent mount options

2013-08-06 Thread Duncan
Eric Sandeen posted on Tue, 06 Aug 2013 15:37:30 -0500 as excerpted:

 On 8/6/13 1:27 PM, Filipe David Borba Manana wrote:
 This change allows for most mount options to be persisted in the
 filesystem, and be applied when the filesystem is mounted.
 If the same options are specified at mount time, the persisted values
 for those options are ignored.
 
 The only options not supported are: subvol, subvolid, subvolrootid,
 device and thread_pool. This limitation is due to how this feature is
 implemented: basically there's an optional value (of type struct
 btrfs_dir_item) in the tree of tree roots used to store the list of
 options in the same format as they are passed to btrfs_mount().
 This means any mount option that takes effect before the tree of tree
 roots is setup is not supported.
 
 To set these options, the user space tool btrfstune was modified to
 persist the list of options into an unmounted filesystem's tree of tree
 roots.
 
 So, it does this thing, ok - but why?
 What is seen as the administrative advantage of this new mechanism?
 
 Just to play devil's advocate, and to add a bit of history:
 
 On any production system, the filesystems will be mounted via fstab,
 which has the advantages of being widely known, well understood, and
 100% expected - as well as being transparent, unsurprising, and
 seamless.
 
 For history: ext4 did this too.  And now it's in a situation where it's
 got mount options coming at it from both the superblock and from the
 commandline (or fstab), and sometimes they conflict; it also tries to
 report mount options in /proc/mounts, but has grown hairy code to decide
 which ones to print and which ones to not print (if it's a default
 option, don't print it in /proc/mounts, but what's default, code-default
 or fs-default?)  And it's really kind of an ugly mess.
 
 Further, mounting 2 filesystems w/ no options in fstab or on the
 commandline, and getting different behavior due to hidden (sorry,
 persistent) options in the fs itself is surprising, and surprise is
 rarely good.
 
 So this patch adds 100+ lines of new code, to implement this idea, but:
 what is the advantage?  Unless there is a compelling administrative use
 case, I'd vote against it.  Lines of code that don't exist don't have
 bugs.  ;)

As an admin, there's some options I want always applied as site policy.  
Here, that includes compress=lzo, autodefrag and noatime.  And with all 
the capacities btrfs has what with raid and the like, particularly if 
someone's needing to use device= (which won't go in the persistent 
options for what should be pretty obvious reasons) a bunch of times, that 
fstab line can get quite long indeed![1]

Just like the kernel has a config option for a built-in commandline that 
takes some of the pressure off the actually passed commandline for 
options that are pretty much always going to be used so it's easier to 
administer because only the possibly dynamic options or those going 
against the builtin commandline defaults need passed, a filesystem as 
complex and multi-optioned as btrfs is, really NEEDS some way to persist 
the options that are effectively site policy default, so the admin 
doesn't have to worry about them any longer.

FWIW, I had assumed persistent mount options were planned as a given and 
simply hadn't been implemented yet.  Because to me it's a no-brainer.  
After all, people don't have to use the feature if they don't like it.  
And it sure saves a headache when what might otherwise be a dozen 
parameters passed in can be cut in half or better, leaving only the ones 
that are going to differ depending on circumstances to worry about.  I 
know that from experience with the kernel builtin commandline option!

---
[1] I ran initr*less root-on-md-raid for many years.  That involved 
passing a complicated set of md1=/dev/sda3,/dev/sdb3,/dev/sdc3,/dev/sdd3 
type options to the kernel, along with more usual options I was passing, 
and I was SO happy when the kernel got that built-in-commandline option 
and I could put the default set in there, such that I only had to worry 
about passing that parameter for the backup boot option, thus along with 
several other passed options I was able to put in the builtin, shrinking 
the actual passed kernel commandline dramatically, so only the stuff that 
wasn't the default needed passed for a particular boot option.  It would 
sure be nice to be able to do the same thing, but at the filesystem 
level, here!

-- 
Duncan - List replies preferred.   No HTML msgs.
Every nonfree program has a lord, a master --
and if you use the program, he is your master.  Richard Stallman

--
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 RFC] Btrfs: add support for persistent mount options

2013-08-06 Thread Eric Sandeen
On 8/6/13 8:20 PM, Duncan wrote:
 Eric Sandeen posted on Tue, 06 Aug 2013 15:37:30 -0500 as excerpted:
 
 On 8/6/13 1:27 PM, Filipe David Borba Manana wrote:
 This change allows for most mount options to be persisted in the
 filesystem, and be applied when the filesystem is mounted.
 If the same options are specified at mount time, the persisted values
 for those options are ignored.

 The only options not supported are: subvol, subvolid, subvolrootid,
 device and thread_pool. This limitation is due to how this feature is
 implemented: basically there's an optional value (of type struct
 btrfs_dir_item) in the tree of tree roots used to store the list of
 options in the same format as they are passed to btrfs_mount().
 This means any mount option that takes effect before the tree of tree
 roots is setup is not supported.

 To set these options, the user space tool btrfstune was modified to
 persist the list of options into an unmounted filesystem's tree of tree
 roots.

 So, it does this thing, ok - but why?
 What is seen as the administrative advantage of this new mechanism?

 Just to play devil's advocate, and to add a bit of history:

 On any production system, the filesystems will be mounted via fstab,
 which has the advantages of being widely known, well understood, and
 100% expected - as well as being transparent, unsurprising, and
 seamless.

 For history: ext4 did this too.  And now it's in a situation where it's
 got mount options coming at it from both the superblock and from the
 commandline (or fstab), and sometimes they conflict; it also tries to
 report mount options in /proc/mounts, but has grown hairy code to decide
 which ones to print and which ones to not print (if it's a default
 option, don't print it in /proc/mounts, but what's default, code-default
 or fs-default?)  And it's really kind of an ugly mess.

 Further, mounting 2 filesystems w/ no options in fstab or on the
 commandline, and getting different behavior due to hidden (sorry,
 persistent) options in the fs itself is surprising, and surprise is
 rarely good.

 So this patch adds 100+ lines of new code, to implement this idea, but:
 what is the advantage?  Unless there is a compelling administrative use
 case, I'd vote against it.  Lines of code that don't exist don't have
 bugs.  ;)
 
 As an admin, there's some options I want always applied as site policy.  
 Here, that includes compress=lzo, autodefrag and noatime.  And with all 

But as an admin, you can add that to fstab, right?

 the capacities btrfs has what with raid and the like, particularly if 
 someone's needing to use device= (which won't go in the persistent 
 options for what should be pretty obvious reasons) a bunch of times, that 
 fstab line can get quite long indeed![1]
 
 Just like the kernel has a config option for a built-in commandline that 
 takes some of the pressure off the actually passed commandline for 
 options that are pretty much always going to be used so it's easier to 
 administer because only the possibly dynamic options or those going 
 against the builtin commandline defaults need passed, a filesystem as 
 complex and multi-optioned as btrfs is, really NEEDS some way to persist 
 the options that are effectively site policy default, so the admin 
 doesn't have to worry about them any longer.

Again, fstab is perfectly sufficient, simply for site policy.

It seems that your main argument here (no pun intended) is that the sheer
length of the options string becomes unwieldy.  i.e. it's too long
for fstab, so it must be moved into the filesystem.

too long is a bit subjective, unless util-linux
has an actual string limit.  If not, I guess it's mostly aesthetics.

 FWIW, I had assumed persistent mount options were planned as a given and 
 simply hadn't been implemented yet.  Because to me it's a no-brainer.  
 After all, people don't have to use the feature if they don't like it.  

no, but we still have to maintain it ;)

So just speaking for myself, 100+ new lines of code forever after, vs.
I find my fstab to be unattractive is an obvious choice.

 And it sure saves a headache when what might otherwise be a dozen 
 parameters passed in can be cut in half or better, leaving only the ones 
 that are going to differ depending on circumstances to worry about.  I 
 know that from experience with the kernel builtin commandline option!

But you still have to set them all.  Is it less headache to use btrfstune
vs edit fstab?  I'm not really convinced.

I guess the argument that it's easier to notice specific differences against
a site-wide (hidden) set of options, vs. a bunch of long option strings
resonates somewhat.

*shrug* well, I did my ghost-of-christmas-future bit; it's just my $0.02.

Thanks,
-Eric

 ---
 [1] I ran initr*less root-on-md-raid for many years.

isn't that kind of doing it wrong, though?  init*fs solves the problem
you complain about.  (There's probably a reason for it that I'm unaware
of, though.)

  That involved 
 passing a 

Re: [PATCH RFC] Btrfs: add support for persistent mount options

2013-08-06 Thread Eric Sandeen
On 8/6/13 1:27 PM, Filipe David Borba Manana wrote:
 This change allows for most mount options to be persisted in
 the filesystem, and be applied when the filesystem is mounted.
 If the same options are specified at mount time, the persisted
 values for those options are ignored.

I thought the plan was to make commandline mount options
override persistent ones, but that doesn't seem to be the case,
at least in this example:

# ./btrfstune -o compress,discard,ssd /dev/sdb1
New persistent options:  compress,discard,ssd
# mount -o nossd /dev/sdb1 /mnt/test
# dmesg | tail
[  995.657233] btrfs: use ssd allocation scheme
[  995.661501] btrfs: disk space caching is enabled

and /proc/mounts is similarly confused, showing both options:

# grep sdb1 /proc/mounts
/dev/sdb1 /mnt/test btrfs 
rw,seclabel,relatime,compress=zlib,nossd,ssd,discard,space_cache 0 0

(This is the trail of woe I was talking about from ext4-land) ;)

 The only options not supported are: subvol, subvolid, subvolrootid,
 device and thread_pool. This limitation is due to how this feature
 is implemented: basically there's an optional value (of type
 struct btrfs_dir_item) in the tree of tree roots used to store the
 list of options in the same format as they are passed to btrfs_mount().
 This means any mount option that takes effect before the tree of tree
 roots is setup is not supported.

Just FWIW, vfs-level mount options are also not supported; i.e. noatime
or ro won't work either, because the code is already past the VFS
option parsing:

# ./btrfstune -o compress,discard,ro /dev/sdb1
Current persistent options:  compress,discard
New persistent options:  compress,discard,ro
# mount /dev/sdb1 /mnt/test
mount: wrong fs type, bad option, bad superblock on /dev/sdb1, ...
# dmesg | tail
[  817.681417] btrfs: unrecognized mount option 'ro'
[  817.694689] btrfs: open_ctree failed

 To set these options, the user space tool btrfstune was modified
 to persist the list of options into an unmounted filesystem's
 tree of tree roots.

If this goes forward, you'd want an easy way to display
them, not just set them, I suppose.

Thanks,
-Eric
 
 NOTE: Like the corresponding btrfs-progs patch, this is a WIP with
 the goal o gathering feedback.
 
 Signed-off-by: Filipe David Borba Manana fdman...@gmail.com


--
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: introduce command namespace for development features

2013-08-06 Thread Anand Jain



 Further there is benefit of having newer subcommands
 in the master branch - it gets visibility.

 However if we are trying to solve the problem of it
 not being end user ready then there can be a warning
 message about it when the user uses it or sees it.

 I see some of online shops tagging new problem with
 bright red New on the product image. Could we have
 some warning shown against these new subcommands ?

 just my 1c.

Anand


On 08/07/2013 02:01 AM, Zach Brown wrote:

On Tue, Aug 06, 2013 at 02:25:20PM +0200, David Sterba wrote:

We'd like to make it easier to preview a new feature and remove the
burden to invent sane user interface (command name, placement,
arguments, man) from the beginning.


My biggest worry about this is that it complicates the coordination of
automated testing, which is already in a terrible state for btrfs-progs.
It can't possibly motivate people to write tests if we make the process
more cumbersome than it already is.

So we develop tests for a command (maybe in xfstests,  maybe in
btrfs-progs) that use this magical _ namespace.  Then the command is
merged.  When are the tests updated?  Do they fallback to both so that
the tests can work across the merge?   Do we add some complexity to try
and magically match _ commands that aren't found with matching commands
somewhere else in the heirarchy?  Ugh, all 'round.

I'm not sure I understand what problem this is really solving.  People
shouldn't be expecting to find incomplete features in the master branch,
right?  If people are looking to test incomplete work they can get your
integration branch and, well, we don't care if it changes later?

- z
--
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: [PATCH RFC] Btrfs: add support for persistent mount options

2013-08-06 Thread Filipe David Manana
On Tue, Aug 6, 2013 at 10:05 PM, Eric Sandeen sand...@redhat.com wrote:
 On 8/6/13 3:45 PM, Filipe David Manana wrote:
 On Tue, Aug 6, 2013 at 9:37 PM, Eric Sandeen sand...@redhat.com wrote:
 On 8/6/13 1:27 PM, Filipe David Borba Manana wrote:
 This change allows for most mount options to be persisted in
 the filesystem, and be applied when the filesystem is mounted.
 If the same options are specified at mount time, the persisted
 values for those options are ignored.

 The only options not supported are: subvol, subvolid, subvolrootid,
 device and thread_pool. This limitation is due to how this feature
 is implemented: basically there's an optional value (of type
 struct btrfs_dir_item) in the tree of tree roots used to store the
 list of options in the same format as they are passed to btrfs_mount().
 This means any mount option that takes effect before the tree of tree
 roots is setup is not supported.

 To set these options, the user space tool btrfstune was modified
 to persist the list of options into an unmounted filesystem's
 tree of tree roots.

 So, it does this thing, ok - but why?
 What is seen as the administrative advantage of this new mechanism?

 Just to play devil's advocate, and to add a bit of history:

 On any production system, the filesystems will be mounted via fstab,
 which has the advantages of being widely known, well understood, and
 100% expected - as well as being transparent, unsurprising, and seamless.

 For history: ext4 did this too.  And now it's in a situation where it's
 got mount options coming at it from both the superblock and from
 the commandline (or fstab), and sometimes they conflict; it also tries
 to report mount options in /proc/mounts, but has grown hairy code
 to decide which ones to print and which ones to not print (if it's
 a default option, don't print it in /proc/mounts, but what's default,
 code-default or fs-default?)  And it's really kind of an ugly mess.

 Further, mounting 2 filesystems w/ no options in fstab or on the
 commandline, and getting different behavior due to hidden (sorry,
 persistent) options in the fs itself is surprising, and surprise
 is rarely good.

 So this patch adds 100+ lines of new code, to implement this idea, but:
 what is the advantage?  Unless there is a compelling administrative
 use case, I'd vote against it.  Lines of code that don't exist don't
 have bugs.  ;)

 There was a recent good example (imho at least) mentioned by Xavier
 Gnata some time ago:

 http://comments.gmane.org/gmane.comp.file-systems.btrfs/26011

 cheers

 Hm, I see.  I forgot about hotplugging in my most systems mount
 via fstab assertion.  :)

 I was thinking (and Josef just suggested too) that making a
 dir flag, saying everything under this dir gets compressed might make
 more sense for that scenario than adding a whole slew of
 on-disk-persistent-mount-option code.

I like that idea too. Thanks for the suggestion. A quick experiment
allowed for that approach in under 20 lines, will test it a bit more.


 Because really, the motivation sounds like it's primarily for significant
 on-disk format changes controlled by mount options.  I understand that
 motivation more than being able to persist something like noatime.

 -Eric




-- 
Filipe David Manana,

Reasonable men adapt themselves to the world.
 Unreasonable men adapt the world to themselves.
 That's why all progress depends on unreasonable men.
--
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 RFC] Btrfs: add support for persistent mount options

2013-08-06 Thread Filipe David Manana
On Wed, Aug 7, 2013 at 4:04 AM, Eric Sandeen sand...@redhat.com wrote:
 On 8/6/13 1:27 PM, Filipe David Borba Manana wrote:
 This change allows for most mount options to be persisted in
 the filesystem, and be applied when the filesystem is mounted.
 If the same options are specified at mount time, the persisted
 values for those options are ignored.

 I thought the plan was to make commandline mount options
 override persistent ones, but that doesn't seem to be the case,
 at least in this example:

Yes, that was the idea. However I didn't try all possible combinations
of mount and persistent parameters.


 # ./btrfstune -o compress,discard,ssd /dev/sdb1
 New persistent options:  compress,discard,ssd
 # mount -o nossd /dev/sdb1 /mnt/test
 # dmesg | tail
 [  995.657233] btrfs: use ssd allocation scheme
 [  995.661501] btrfs: disk space caching is enabled

Yes. Misses some checks like the ones I added for the space_cache /
no_space_cache combinations:

+ if (token == Opt_no_space_cache 
+parsed[Opt_space_cache])
+ continue;
+ if (token == Opt_space_cache 
+parsed[Opt_no_space_cache])
+ continue;


 and /proc/mounts is similarly confused, showing both options:

 # grep sdb1 /proc/mounts
 /dev/sdb1 /mnt/test btrfs 
 rw,seclabel,relatime,compress=zlib,nossd,ssd,discard,space_cache 0 0

 (This is the trail of woe I was talking about from ext4-land) ;)

 The only options not supported are: subvol, subvolid, subvolrootid,
 device and thread_pool. This limitation is due to how this feature
 is implemented: basically there's an optional value (of type
 struct btrfs_dir_item) in the tree of tree roots used to store the
 list of options in the same format as they are passed to btrfs_mount().
 This means any mount option that takes effect before the tree of tree
 roots is setup is not supported.

 Just FWIW, vfs-level mount options are also not supported; i.e. noatime
 or ro won't work either, because the code is already past the VFS
 option parsing:

 # ./btrfstune -o compress,discard,ro /dev/sdb1
 Current persistent options:  compress,discard
 New persistent options:  compress,discard,ro
 # mount /dev/sdb1 /mnt/test
 mount: wrong fs type, bad option, bad superblock on /dev/sdb1, ...
 # dmesg | tail
 [  817.681417] btrfs: unrecognized mount option 'ro'
 [  817.694689] btrfs: open_ctree failed

Yes, that would be a next step to work on after getting community
feedback about the approach (from a user point of view and the
technical details / implementation).

Thanks for trying it and for your feedback Eric.


 To set these options, the user space tool btrfstune was modified
 to persist the list of options into an unmounted filesystem's
 tree of tree roots.

 If this goes forward, you'd want an easy way to display
 them, not just set them, I suppose.

 Thanks,
 -Eric

 NOTE: Like the corresponding btrfs-progs patch, this is a WIP with
 the goal o gathering feedback.

 Signed-off-by: Filipe David Borba Manana fdman...@gmail.com





-- 
Filipe David Manana,

Reasonable men adapt themselves to the world.
 Unreasonable men adapt the world to themselves.
 That's why all progress depends on unreasonable men.
--
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 2/2] btrfs-progs: mark static remove unused from non-kernel code

2013-08-06 Thread Eric Sandeen
On 8/6/13 8:05 PM, Eric Sandeen wrote:
 Mark many functions as static, and remove any resulting dead code.
 
 Signed-off-by: Eric Sandeen sand...@redhat.com
 ---
...

Actually, what the heck was this (note, this patch was against kdave's 
integration tree):

 diff --git a/send-utils.c b/send-utils.c
 index 874f8a5..3d562a4 100644
 --- a/send-utils.c
 +++ b/send-utils.c
 @@ -255,15 +255,6 @@ static int btrfs_subvolid_resolve_sub(int fd, char 
 *path, size_t *path_len,
   return 0;
  }
  
 -void subvol_uuid_search_add(struct subvol_uuid_search *s,
 - struct subvol_info *si)
 -{
 - if (si) {
 - free(si-path);
 - free(si);
 - }
 -}
 -

That code above came into being with [PATCH v4 3/5] Btrfs-progs: use UUID tree 
for send/receive -

 void subvol_uuid_search_add(struct subvol_uuid_search *s,
struct subvol_info *si)
 {
-   int cnt;
-
-   tree_insert(s-root_id_subvols, si, subvol_search_by_root_id);
-   tree_insert(s-path_subvols, si, subvol_search_by_path);
-
-   cnt = count_bytes(si-uuid, BTRFS_UUID_SIZE, 0);
-   if (cnt != BTRFS_UUID_SIZE)
-   tree_insert(s-local_subvols, si, subvol_search_by_uuid);
-   cnt = count_bytes(si-received_uuid, BTRFS_UUID_SIZE, 0);
-   if (cnt != BTRFS_UUID_SIZE)
-   tree_insert(s-received_subvols, si,
-   subvol_search_by_received_uuid);
+   if (si) {
+   free(si-path);
+   free(si);
+   }
 }

is that, um, really as intended, or did something get misapplied somewhere?

-Eric
--
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 3/3] Btrfs: remove reduplicate check when disabling quota

2013-08-06 Thread Wang Shilong
We have checked 'quota_root' with qgroup_ioctl_lock held before,So
here the check is reduplicate, remove it.

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
Reviewed-by: Miao Xie mi...@cn.fujitsu.com
---
 fs/btrfs/qgroup.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index b809616..df2841d 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -943,11 +943,6 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,
 
btrfs_free_qgroup_config(fs_info);
 
-   if (!quota_root) {
-   ret = -EINVAL;
-   goto out;
-   }
-
ret = btrfs_clean_quota_tree(trans, quota_root);
if (ret)
goto 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


[PATCH 2/3] Btrfs: move btrfs_free_qgroup_config() out of spin_lock and fix comments

2013-08-06 Thread Wang Shilong
btrfs_free_qgroup_config() is not only called by open/close_ctree(),but
also btrfs_disable_quota().And for btrfs_disable_quota(),we have set
'quota_root' to be null before calling btrfs_free_qgroup_config(),so it
is safe to cleanup in-memory structures without lock held.

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
Reviewed-by: Miao Xie mi...@cn.fujitsu.com
---
 fs/btrfs/qgroup.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 3b103e2..b809616 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -432,8 +432,10 @@ out:
 }
 
 /*
- * This is only called from close_ctree() or open_ctree(), both in single-
- * treaded paths. Clean up the in-memory structures. No locking needed.
+ * This is called from close_ctree() or open_ctree() or btrfs_quota_disable(),
+ * first two are in single-treaded paths.And for the third one, we have set
+ * quota_root to be null with qgroup_lock held before, so it is safe to clean
+ * up the in-memory structures without qgroup_lock held.
  */
 void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info)
 {
@@ -937,9 +939,10 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans,
fs_info-pending_quota_state = 0;
quota_root = fs_info-quota_root;
fs_info-quota_root = NULL;
-   btrfs_free_qgroup_config(fs_info);
spin_unlock(fs_info-qgroup_lock);
 
+   btrfs_free_qgroup_config(fs_info);
+
if (!quota_root) {
ret = -EINVAL;
goto 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


[PATCH 1/3] Btrfs: fix oops when writing dirty qgroups to disk

2013-08-06 Thread Wang Shilong
When disabling quota, we should clear out list 'dirty_qgroups',otherwise,
we will get oops if enabling quota again. Fix this by abstracting similar
code from del_qgroup_rb().

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
Reviewed-by: Miao Xie mi...@cn.fujitsu.com
---
 fs/btrfs/qgroup.c | 43 ++-
 1 file changed, 14 insertions(+), 29 deletions(-)

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 64a9e3c..3b103e2 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -157,18 +157,11 @@ static struct btrfs_qgroup *add_qgroup_rb(struct 
btrfs_fs_info *fs_info,
return qgroup;
 }
 
-/* must be called with qgroup_lock held */
-static int del_qgroup_rb(struct btrfs_fs_info *fs_info, u64 qgroupid)
+static void __del_qgroup_rb(struct btrfs_qgroup *qgroup)
 {
-   struct btrfs_qgroup *qgroup = find_qgroup_rb(fs_info, qgroupid);
-   struct btrfs_qgroup_list *list;
+   struct btrfs_qgroup_list *list = NULL;
 
-   if (!qgroup)
-   return -ENOENT;
-
-   rb_erase(qgroup-node, fs_info-qgroup_tree);
list_del(qgroup-dirty);
-
while (!list_empty(qgroup-groups)) {
list = list_first_entry(qgroup-groups,
struct btrfs_qgroup_list, next_group);
@@ -185,7 +178,18 @@ static int del_qgroup_rb(struct btrfs_fs_info *fs_info, 
u64 qgroupid)
kfree(list);
}
kfree(qgroup);
+}
+
+/* must be called with qgroup_lock held */
+static int del_qgroup_rb(struct btrfs_fs_info *fs_info, u64 qgroupid)
+{
+   struct btrfs_qgroup *qgroup = find_qgroup_rb(fs_info, qgroupid);
 
+   if (!qgroup)
+   return -ENOENT;
+
+   rb_erase(qgroup-node, fs_info-qgroup_tree);
+   __del_qgroup_rb(qgroup);
return 0;
 }
 
@@ -435,30 +439,11 @@ void btrfs_free_qgroup_config(struct btrfs_fs_info 
*fs_info)
 {
struct rb_node *n;
struct btrfs_qgroup *qgroup;
-   struct btrfs_qgroup_list *list;
 
while ((n = rb_first(fs_info-qgroup_tree))) {
qgroup = rb_entry(n, struct btrfs_qgroup, node);
rb_erase(n, fs_info-qgroup_tree);
-
-   while (!list_empty(qgroup-groups)) {
-   list = list_first_entry(qgroup-groups,
-   struct btrfs_qgroup_list,
-   next_group);
-   list_del(list-next_group);
-   list_del(list-next_member);
-   kfree(list);
-   }
-
-   while (!list_empty(qgroup-members)) {
-   list = list_first_entry(qgroup-members,
-   struct btrfs_qgroup_list,
-   next_member);
-   list_del(list-next_group);
-   list_del(list-next_member);
-   kfree(list);
-   }
-   kfree(qgroup);
+   __del_qgroup_rb(qgroup);
}
/*
 * we call btrfs_free_qgroup_config() when umounting
-- 
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: [PATCH 1/3] Btrfs: fix oops when writing dirty qgroups to disk

2013-08-06 Thread Wang Shilong
On 08/07/2013 01:12 PM, Wang Shilong wrote:
 When disabling quota, we should clear out list 'dirty_qgroups',otherwise,
 we will get oops if enabling quota again. Fix this by abstracting similar
 code from del_qgroup_rb().

Hello Arne,

Would you pleae review this patch and other cleanup patches,
i just hit this oops when i want to reproduce memory leak of qgroups.


Thanks,
Wang
 
 Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
 Reviewed-by: Miao Xie mi...@cn.fujitsu.com
 ---
  fs/btrfs/qgroup.c | 43 ++-
  1 file changed, 14 insertions(+), 29 deletions(-)
 
 diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
 index 64a9e3c..3b103e2 100644
 --- a/fs/btrfs/qgroup.c
 +++ b/fs/btrfs/qgroup.c
 @@ -157,18 +157,11 @@ static struct btrfs_qgroup *add_qgroup_rb(struct 
 btrfs_fs_info *fs_info,
   return qgroup;
  }
  
 -/* must be called with qgroup_lock held */
 -static int del_qgroup_rb(struct btrfs_fs_info *fs_info, u64 qgroupid)
 +static void __del_qgroup_rb(struct btrfs_qgroup *qgroup)
  {
 - struct btrfs_qgroup *qgroup = find_qgroup_rb(fs_info, qgroupid);
 - struct btrfs_qgroup_list *list;
 + struct btrfs_qgroup_list *list = NULL;
  
 - if (!qgroup)
 - return -ENOENT;
 -
 - rb_erase(qgroup-node, fs_info-qgroup_tree);
   list_del(qgroup-dirty);
 -
   while (!list_empty(qgroup-groups)) {
   list = list_first_entry(qgroup-groups,
   struct btrfs_qgroup_list, next_group);
 @@ -185,7 +178,18 @@ static int del_qgroup_rb(struct btrfs_fs_info *fs_info, 
 u64 qgroupid)
   kfree(list);
   }
   kfree(qgroup);
 +}
 +
 +/* must be called with qgroup_lock held */
 +static int del_qgroup_rb(struct btrfs_fs_info *fs_info, u64 qgroupid)
 +{
 + struct btrfs_qgroup *qgroup = find_qgroup_rb(fs_info, qgroupid);
  
 + if (!qgroup)
 + return -ENOENT;
 +
 + rb_erase(qgroup-node, fs_info-qgroup_tree);
 + __del_qgroup_rb(qgroup);
   return 0;
  }
  
 @@ -435,30 +439,11 @@ void btrfs_free_qgroup_config(struct btrfs_fs_info 
 *fs_info)
  {
   struct rb_node *n;
   struct btrfs_qgroup *qgroup;
 - struct btrfs_qgroup_list *list;
  
   while ((n = rb_first(fs_info-qgroup_tree))) {
   qgroup = rb_entry(n, struct btrfs_qgroup, node);
   rb_erase(n, fs_info-qgroup_tree);
 -
 - while (!list_empty(qgroup-groups)) {
 - list = list_first_entry(qgroup-groups,
 - struct btrfs_qgroup_list,
 - next_group);
 - list_del(list-next_group);
 - list_del(list-next_member);
 - kfree(list);
 - }
 -
 - while (!list_empty(qgroup-members)) {
 - list = list_first_entry(qgroup-members,
 - struct btrfs_qgroup_list,
 - next_member);
 - list_del(list-next_group);
 - list_del(list-next_member);
 - kfree(list);
 - }
 - kfree(qgroup);
 + __del_qgroup_rb(qgroup);
   }
   /*
* we call btrfs_free_qgroup_config() when umounting
 

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


[v2 1/8] Btrfs-progs: add missing man page information for btrfsck

2013-08-06 Thread Wang Shilong
Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
Signed-off-by: Qu Wenruo quwen...@cn.fujitsu.com
---
V1-V2: remove wrong copyright information
---
 man/btrfsck.8.in | 29 -
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/man/btrfsck.8.in b/man/btrfsck.8.in
index 5004ba0..37b9cf6 100644
--- a/man/btrfsck.8.in
+++ b/man/btrfsck.8.in
@@ -1,11 +1,29 @@
 .TH BTRFSCK 8
 .SH NAME
-btrfsck \- check a btrfs filesystem
+btrfsck \- check and repair of a Btrfs filesystem
 .SH SYNOPSIS
-.B btrfsck \fI device\fP
+.B btrfsck [\fIoptions\fP] \fIdevice\fP
 .SH DESCRIPTION
-\fBbtrfsck\fP is used to check a btrfs filesystem.
-\fIdevice\fP is the device file where the filesystem is stored.
+\fBbtrfsck\fP is used to check and optionally repair of a Btrfs filesystem. 
Now, it can only be run on an unmounted FS. Considering it is not well-tested
+in real-life situations yet. if you have a broken Btrfs filesystem, btrfsck 
may not repair but cause aditional damages. \fIdevice\fP is the device file
+where the filesystem is stored.
+
+\fIOptions\fP
+.IP \fB-s,--super \fIsuperblock\fP 5
+specify which superblock copy that you want to use.
+.IP \fB--repair\fP 5
+try to repair the filesystem.
+.IP \fB--init-csum-tree\fP 5
+create a new CRC tree.
+.IP \fB--init-extent-tree\fP 5
+create a new extent tree.
+
+.SH EXIT CODE
+\fBbtrfsck\fR will return 0 exit code if no error happened.
+Other exit code means some problems happened.
+
+.br
+This is free software: you are free  to  change  and  redistribute  it. There 
is NO WARRANTY, to the extent permitted by law.
 .SH AVAILABILITY
 .B btrfsck
 is part of btrfs-progs. Btrfs is currently under heavy development,
@@ -13,4 +31,5 @@ and not suitable for any uses other than benchmarking and 
review.
 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
 further details.
 .SH SEE ALSO
-.BR mkfs.btrfs (8)
+.BR mkfs.btrfs (8),
+.BR btrfs (8)
-- 
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


[v2 5/8] Btrfs-progs: add man page information for btrfs-convert

2013-08-06 Thread Wang Shilong
Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
Signed-off-by: Qu Wenruo quwen...@cn.fujitsu.com
---
V1-V2: GPLv3-GPLv2
---
 man/Makefile   |  3 ++-
 man/btrfs-convert.8.in | 39 +++
 2 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 man/btrfs-convert.8.in

diff --git a/man/Makefile b/man/Makefile
index 3d2e3ba..a2201e8 100644
--- a/man/Makefile
+++ b/man/Makefile
@@ -12,7 +12,8 @@ man8dir = $(mandir)/man8
 .SUFFIXES: .in .gz
 
 MANPAGES = mkfs.btrfs.8.gz btrfsck.8.gz btrfs-image.8.gz btrfs.8.gz \
-  btrfs-debug-tree.8.gz btrfs-show-super.8.gz btrfs-find-root.8.gz
+  btrfs-debug-tree.8.gz btrfs-show-super.8.gz btrfs-find-root.8.gz \
+  btrfs-convert.8.gz
 INFILES = ${MANPAGES:.in=.gz}
 
 all: $(MANPAGES)
diff --git a/man/btrfs-convert.8.in b/man/btrfs-convert.8.in
new file mode 100644
index 000..e394df2
--- /dev/null
+++ b/man/btrfs-convert.8.in
@@ -0,0 +1,39 @@
+.TH BTRFS-CONVERT 8
+.SH NAME
+btrfs-convert \- convert ext2/3/4 to btrfs.
+.SH SYNOPSIS
+.B btrfs-convert [\fIoptions\fP] \fIdev\fP
+.SH DESCRIPTION
+\fBbtrfs-convert\fP is used to convert existed ext2/3/4 to btrfs filesystem, 
and the original filesystem image is accessible as from separate subvolume 
named ext2_subvol as file image.
+
+\fIOptions\fP
+.IP \fB-d\fP 5
+disable data checksum.
+.IP \fB-i\fP 5
+ignore xattrs and ACLs.
+.IP \fB-n\fP 5
+disable packing of small files.
+.IP \fB-r\fP 5
+roll back to ext2fs.
+
+.SH EXIT CODE
+\fBbtrfs-convert\fP will return 0 if no error happened.
+If any problems happened, 1 will be returned.
+
+.SH AUTHOR
+Written by Shilong Wang and Wenruo Qu.
+
+.SH COPYRIGHT
+Copyright \(co 2013 Fujitsu, Inc.
+License GPLv2: GNU GPL version 2 http://gnu.org/licenses/gpl.html.
+.br
+This is free software: you are free  to  change  and  redistribute  it. There 
is NO WARRANTY, to the extent permitted by law.
+
+.SH AVAILABILITY
+.B btrfs-convert
+is part of btrfs-progs. Btrfs is currently under heavy development,
+and not suitable for any uses other than benchmarking and review.
+Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
+further details.
+.SH SEE ALSO
+.BR mkfs.btrfs (8)
-- 
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


[v2 6/8] Btrfs-progs: add missing man page for btrfstune

2013-08-06 Thread Wang Shilong
Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
Signed-off-by: Qu Wenruo quwen...@cn.fujitsu.com
---
V1-V2: GPLv3-GPLv2
---
 man/Makefile   |  2 +-
 man/btrfstune.8.in | 37 +
 2 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 man/btrfstune.8.in

diff --git a/man/Makefile b/man/Makefile
index a2201e8..e1246db 100644
--- a/man/Makefile
+++ b/man/Makefile
@@ -13,7 +13,7 @@ man8dir = $(mandir)/man8
 
 MANPAGES = mkfs.btrfs.8.gz btrfsck.8.gz btrfs-image.8.gz btrfs.8.gz \
   btrfs-debug-tree.8.gz btrfs-show-super.8.gz btrfs-find-root.8.gz \
-  btrfs-convert.8.gz
+  btrfs-convert.8.gz btrfstune.8.gz
 INFILES = ${MANPAGES:.in=.gz}
 
 all: $(MANPAGES)
diff --git a/man/btrfstune.8.in b/man/btrfstune.8.in
new file mode 100644
index 000..315b2fa
--- /dev/null
+++ b/man/btrfstune.8.in
@@ -0,0 +1,37 @@
+.TH BTRFSTUNE 8
+.SH NAME
+btrfstune \- tune various filesystem parameters.
+.SH SYNOPSIS
+.B btrfstune [\fIoptions\fP] \fImnt\fP
+.SH DESCRIPTION
+\fBbtrfstune\fP is used to tune various filesystem parameters,you can
+enable/disable some extended features for btrfs.
+
+\fIOptions\fP
+.IP \fB-S \fIvalue\fP 5
+updates the seeding value, it forces a fs readonly so that you can use it to 
build other filesystems.
+.IP \fB-r\fP 5
+enable extended inode refs.
+.IP \fB-x\fP 5
+enable skinny metadata extent refs.
+
+.SH EXIT CODE
+\fBbtrfstune\fP will return 0 if no error happened.
+If any problems happened, 1 will be returned.
+
+.SH AUTHOR
+Written by Shilong Wang and Wenruo Qu.
+
+.SH COPYRIGHT
+Copyright \(co 2013 Fujitsu, Inc.
+License GPLv2: GNU GPL version 2 http://gnu.org/licenses/gpl.html.
+.br
+This is free software: you are free  to  change  and  redistribute  it. There 
is NO WARRANTY, to the extent permitted by law.
+.SH AVAILABILITY
+.B btrfstune
+is part of btrfs-progs. Btrfs is currently under heavy development,
+and not suitable for any uses other than benchmarking and review.
+Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
+further details.
+.SH SEE ALSO
+.BR mkfs.btrfs (8)
-- 
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


[v2 4/8] Btrfs-progs: add man page information for btrfs-find-root

2013-08-06 Thread Wang Shilong
Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
Signed-off-by: Qu Wenruo quwen...@cn.fujitsu.com
---
V1-V2: GPLv3-GPLv2
---
 man/Makefile  |  2 +-
 man/btrfs-find-root.8.in  | 36 
 man/btrfs-show-super.8.in |  4 ++--
 3 files changed, 39 insertions(+), 3 deletions(-)
 create mode 100644 man/btrfs-find-root.8.in

diff --git a/man/Makefile b/man/Makefile
index b1d3645..3d2e3ba 100644
--- a/man/Makefile
+++ b/man/Makefile
@@ -12,7 +12,7 @@ man8dir = $(mandir)/man8
 .SUFFIXES: .in .gz
 
 MANPAGES = mkfs.btrfs.8.gz btrfsck.8.gz btrfs-image.8.gz btrfs.8.gz \
-  btrfs-debug-tree.8.gz btrfs-show-super.8.gz
+  btrfs-debug-tree.8.gz btrfs-show-super.8.gz btrfs-find-root.8.gz
 INFILES = ${MANPAGES:.in=.gz}
 
 all: $(MANPAGES)
diff --git a/man/btrfs-find-root.8.in b/man/btrfs-find-root.8.in
new file mode 100644
index 000..966bd33
--- /dev/null
+++ b/man/btrfs-find-root.8.in
@@ -0,0 +1,36 @@
+.TH BTRFS-FIND-ROOT 8
+.SH NAME
+btrfs-find-root \- filter to find btrfs root.
+.SH SYNOPSIS
+.B btrfs-find-root [\fIoptions\fP] \fIdev\fP
+.SH DESCRIPTION
+\fBbtrfs-find-root\fP is used to find the satisfied root, you can filter by 
root tree's objectid, generation, level.
+
+\fIOptions\fP
+.IP \fB-g \fIgeneration\fP 5
+filter root tree by it's original transaction id, tree root's generation in 
default.
+.IP \fB-o \fIobjectid\fP 5
+filter root tree by it's objectid,tree root's objectid in default.
+.IP \fB-l \fIlevel\fP 5
+filter root tree by B-+ tree's level, level 0 in default.
+
+.SH EXIT CODE
+\fBbtrfs-find-root\fP will return 0 if no error happened.
+If any problems happened, 1 will be returned.
+
+.SH AUTHOR
+Written by Shilong Wang and Wenruo Qu.
+
+.SH COPYRIGHT
+Copyright \(co 2013 Fujitsu, Inc.
+License GPLv2: GNU GPL version 2 http://gnu.org/licenses/gpl.html.
+.br
+This is free software: you are free  to  change  and  redistribute  it. There 
is NO WARRANTY, to the extent permitted by law.
+.SH AVAILABILITY
+.B btrfs-find-root
+is part of btrfs-progs. Btrfs is currently under heavy development,
+and not suitable for any uses other than benchmarking and review.
+Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
+further details.
+.SH SEE ALSO
+.BR mkfs.btrfs (8)
diff --git a/man/btrfs-show-super.8.in b/man/btrfs-show-super.8.in
index 6588d46..f7af33c 100644
--- a/man/btrfs-show-super.8.in
+++ b/man/btrfs-show-super.8.in
@@ -1,6 +1,6 @@
 .TH BTRFS-SHOW-SUPER 8
 .SH NAME
-btrfs-show-super \- show btrfs superblock information stored in devices
+btrfs-show-super \- show Btrfs superblock information stored in devices
 .SH SYNOPSIS
 .B btrfs-show-super [\fIoptions\fP] \fIdev\fP [\fIdev...\fP]
 .SH DESCRIPTION
@@ -23,7 +23,7 @@ Written by Shilong Wang and Wenruo Qu.
 
 .SH COPYRIGHT
 Copyright \(co 2013 Fujitsu, Inc.
-License GPLv2: GNU GPL version 2 http://gnu.org/licenses/gpl.html.
+License GPLv3: GNU GPL version 3 http://gnu.org/licenses/gpl.html.
 .br
 This is free software: you are free  to  change  and  redistribute  it. There 
is NO WARRANTY, to the extent permitted by law.
 .SH AVAILABILITY
-- 
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


[v2 8/8] Btrfs-progs: add missing man page for btrfs-map-logical

2013-08-06 Thread Wang Shilong
Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
Signed-off-by: Qu Wenruo quwen...@cn.fujitsu.com
---
V1-V2: GPLv3-GPLv2
---
 man/Makefile   |  2 +-
 man/btrfs-map-logical.8.in | 39 +++
 2 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 man/btrfs-map-logical.8.in

diff --git a/man/Makefile b/man/Makefile
index 5ccb60a..690fa65 100644
--- a/man/Makefile
+++ b/man/Makefile
@@ -13,7 +13,7 @@ man8dir = $(mandir)/man8
 
 MANPAGES = mkfs.btrfs.8.gz btrfsck.8.gz btrfs-image.8.gz btrfs.8.gz \
   btrfs-debug-tree.8.gz btrfs-show-super.8.gz btrfs-find-root.8.gz \
-  btrfs-convert.8.gz btrfstune.8.gz btrfs-zero-log.8.gz
+  btrfs-convert.8.gz btrfstune.8.gz btrfs-zero-log.8.gz 
btrfs-map-logical.8.gz
 INFILES = ${MANPAGES:.in=.gz}
 
 all: $(MANPAGES)
diff --git a/man/btrfs-map-logical.8.in b/man/btrfs-map-logical.8.in
new file mode 100644
index 000..a18cca4
--- /dev/null
+++ b/man/btrfs-map-logical.8.in
@@ -0,0 +1,39 @@
+.TH BTRFS-MAP-LOGICAL 8
+.SH NAME
+btrfs-map-logical \- map btrfs logical extent to physical extent
+.SH SYNOPSIS
+.B btrfs-map-logical [\fIoptions\fP] \fIdevice\fP
+.SH DESCRIPTION
+\fBbtrfs-map-logical\fP can be used to find out what the physical offsets are
+on the mirrors, the result is dumped into stdout in default.
+
+\fIOptions\fP
+.IP \fB-l|--logical \fIlogical_num\fP 5
+Logical extent to map.
+.IP \fB-c|--copy \fIcopy\fP 5
+Copy of the extent to read(usually 1 or 2).
+.IP \fB-o|--output \fIfilename\fP 5
+Output file to hold the extent.
+.IP \fB-b|--bytes \fIbytes\fP 5
+Number of bytes to read.
+
+.SH EXIT CODE
+\fBbtrfs-map-logical\fP will return 0 if no error happened.
+If any problems happened, 1 will be returned.
+
+.SH AUTHOR
+Written by Shilong Wang and Wenruo Qu.
+
+.SH COPYRIGHT
+Copyright \(co 2013 Fujitsu, Inc.
+License GPLv2: GNU GPL version 2 http://gnu.org/licenses/gpl.html.
+.br
+This is free software: you are free  to  change  and  redistribute  it. There 
is NO WARRANTY, to the extent permitted by law.
+.SH AVAILABILITY
+.B btrfs-map-logical
+is part of btrfs-progs. Btrfs is currently under heavy development,
+and not suitable for any uses other than benchmarking and review.
+Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
+further details.
+.SH SEE ALSO
+.BR mkfs.btrfs (8)
-- 
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


[v2 3/8] Btrfs-progs: add missing man page for btrfs-show-super

2013-08-06 Thread Wang Shilong
Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
Signed-off-by: Qu Wenruo quwen...@cn.fujitsu.com
---
V1-V2: GPLv3-GPLv2
---
 man/Makefile  |  2 +-
 man/btrfs-show-super.8.in | 36 
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 man/btrfs-show-super.8.in

diff --git a/man/Makefile b/man/Makefile
index e5c1f7c..b1d3645 100644
--- a/man/Makefile
+++ b/man/Makefile
@@ -12,7 +12,7 @@ man8dir = $(mandir)/man8
 .SUFFIXES: .in .gz
 
 MANPAGES = mkfs.btrfs.8.gz btrfsck.8.gz btrfs-image.8.gz btrfs.8.gz \
-  btrfs-debug-tree.8.gz
+  btrfs-debug-tree.8.gz btrfs-show-super.8.gz
 INFILES = ${MANPAGES:.in=.gz}
 
 all: $(MANPAGES)
diff --git a/man/btrfs-show-super.8.in b/man/btrfs-show-super.8.in
new file mode 100644
index 000..6588d46
--- /dev/null
+++ b/man/btrfs-show-super.8.in
@@ -0,0 +1,36 @@
+.TH BTRFS-SHOW-SUPER 8
+.SH NAME
+btrfs-show-super \- show btrfs superblock information stored in devices
+.SH SYNOPSIS
+.B btrfs-show-super [\fIoptions\fP] \fIdev\fP [\fIdev...\fP]
+.SH DESCRIPTION
+\fBbtrfs-show-super\fP is used to print the information of superblock,
+you can specify which mirror to print out. In default, every device's
+first superblock will be printed out.
+
+\fIOptions\fP
+.IP \fB-a\fP 5
+print all the superblock information, if this option is given, '\fB-i\fP' 
option will be ignored.
+.IP \fB-i \fIsuper_mirror\fP 5
+specify which mirror to print out. \fIsuper_mirror\fP is between 0 and 2. if 
several '\fB-i \fIsuper_mirror\fP'\fR are given, only the last one is valid.
+
+.SH EXIT CODE
+\fBbtrfs-show-super\fR will return 0 exit code if no error happened.
+If any problems happened, 1 will be returned.
+
+.SH AUTHOR
+Written by Shilong Wang and Wenruo Qu.
+
+.SH COPYRIGHT
+Copyright \(co 2013 Fujitsu, Inc.
+License GPLv2: GNU GPL version 2 http://gnu.org/licenses/gpl.html.
+.br
+This is free software: you are free  to  change  and  redistribute  it. There 
is NO WARRANTY, to the extent permitted by law.
+.SH AVAILABILITY
+.B btrfs-show-super
+is part of btrfs-progs. Btrfs is currently under heavy development,
+and not suitable for any uses other than benchmarking and review.
+Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
+further details.
+.SH SEE ALSO
+.BR mkfs.btrfs (8)
-- 
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


[v2 7/8] Btrfs-progs: add missing man page information for btrfs-zero-log

2013-08-06 Thread Wang Shilong
Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
Signed-off-by: Qu Wenruo quwen...@cn.fujitsu.com
---
V1-V2: GPLv3-GPLv2
---
 man/Makefile|  2 +-
 man/btrfs-zero-log.8.in | 29 +
 2 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 man/btrfs-zero-log.8.in

diff --git a/man/Makefile b/man/Makefile
index e1246db..5ccb60a 100644
--- a/man/Makefile
+++ b/man/Makefile
@@ -13,7 +13,7 @@ man8dir = $(mandir)/man8
 
 MANPAGES = mkfs.btrfs.8.gz btrfsck.8.gz btrfs-image.8.gz btrfs.8.gz \
   btrfs-debug-tree.8.gz btrfs-show-super.8.gz btrfs-find-root.8.gz \
-  btrfs-convert.8.gz btrfstune.8.gz
+  btrfs-convert.8.gz btrfstune.8.gz btrfs-zero-log.8.gz
 INFILES = ${MANPAGES:.in=.gz}
 
 all: $(MANPAGES)
diff --git a/man/btrfs-zero-log.8.in b/man/btrfs-zero-log.8.in
new file mode 100644
index 000..9bdf34b
--- /dev/null
+++ b/man/btrfs-zero-log.8.in
@@ -0,0 +1,29 @@
+.TH BTRFS-ZERO-LOG 8
+.SH NAME
+btrfs-zero-log \- clear out log tree.
+.SH SYNOPSIS
+.B btrfs-zero-log \fI dev\fP
+.SH DESCRIPTION
+\fBbtrfs-zero-log\fP will remove the log tree if log tree is corrupt, which 
will allow you to mount the filesystem again. The common case where this
+happens has been fixed a long time ago, so it is unlikely that you will see 
this particular problem.
+
+.SH EXIT CODE
+\fBbtrfs-zero-log\fR will return 0 exit code if no error happened.
+Other exit code means some problems happened.
+
+.SH AUTHOR
+Written by Shilong Wang and Wenruo Qu.
+
+.SH COPYRIGHT
+Copyright \(co 2013 Fujitsu, Inc.
+License GPLv2: GNU GPL version 2 http://gnu.org/licenses/gpl.html.
+.br
+This is free software: you are free  to  change  and  redistribute  it. There 
is NO WARRANTY, to the extent permitted by law.
+.SH AVAILABILITY
+.B btrfs-zero-log
+is part of btrfs-progs. Btrfs is currently under heavy development,
+and not suitable for any uses other than benchmarking and review.
+Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
+further details.
+.SH SEE ALSO
+.BR mkfs.btrfs (8)
-- 
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


[v2 2/8] Btrfs-progs: add missing man information for btrfs-debug-tree

2013-08-06 Thread Wang Shilong
Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
Signed-off-by: Qu Wenruo quwen...@cn.fujitsu.com
---
V1-V2: GPLv3-GPLv2
---
 btrfs-debug-tree.c|  2 +-
 man/Makefile  |  3 ++-
 man/btrfs-debug-tree.8.in | 41 +
 3 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 man/btrfs-debug-tree.8.in

diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c
index bae7f94..dc912f1 100644
--- a/btrfs-debug-tree.c
+++ b/btrfs-debug-tree.c
@@ -195,7 +195,7 @@ int main(int ac, char **av)
if (!leaf) {
fprintf(stderr, failed to read %llu\n,
(unsigned long long)block_only);
-   return 0;
+   exit(1);
}
btrfs_print_tree(root, leaf, 0);
return 0;
diff --git a/man/Makefile b/man/Makefile
index 1ba23b5..e5c1f7c 100644
--- a/man/Makefile
+++ b/man/Makefile
@@ -11,7 +11,8 @@ man8dir = $(mandir)/man8
 # list only those we use
 .SUFFIXES: .in .gz
 
-MANPAGES = mkfs.btrfs.8.gz btrfsck.8.gz btrfs-image.8.gz btrfs.8.gz
+MANPAGES = mkfs.btrfs.8.gz btrfsck.8.gz btrfs-image.8.gz btrfs.8.gz \
+  btrfs-debug-tree.8.gz
 INFILES = ${MANPAGES:.in=.gz}
 
 all: $(MANPAGES)
diff --git a/man/btrfs-debug-tree.8.in b/man/btrfs-debug-tree.8.in
new file mode 100644
index 000..281fe98
--- /dev/null
+++ b/man/btrfs-debug-tree.8.in
@@ -0,0 +1,41 @@
+.TH BTRFS-DEBUG-TREE 8
+.SH NAME
+btrfs-debug-tree \- dump Btrfs filesystem metadata into stdout.
+.SH SYNOPSIS
+.B btrfs-debug-tree [\fIoptions\fP] \fIdevice\fP
+.SH DESCRIPTION
+\fBbtrfs-debug-tree\fP is used to dump the whole tree of the given device.
+This is maybe useful for analyzing filesystem state or inconsistence and has
+a positive educational effect on understanding the internal structure.
+\fIdevice\fP is the device file where the filesystem is stored.
+
+\fIOptions\fP
+.IP \fB-e\fP 5
+print detailed extents info.
+.IP \fB-d\fP 5
+print info of btrfs device and root tree dirs only.
+.IP \fB-r\fP 5
+print info of roots only.
+.IP \fB-b \fIblock_num\fP 5
+print info of the specified block only.
+
+.SH EXIT CODE
+\fBbtrfs-debug-tree\fP will return 0 if no error happened.
+If any problems happened, 1 will be returned.
+
+.SH AUTHOR
+Written by Shilong Wang and Wenruo Qu.
+
+.SH COPYRIGHT
+Copyright \(co 2013 Fujitsu, Inc.
+License GPLv2: GNU GPL version 2 http://gnu.org/licenses/gpl.html.
+.br
+This is free software: you are free  to  change  and  redistribute  it. There 
is NO WARRANTY, to the extent permitted by law.
+.SH AVAILABILITY
+.B btrfs-debug-tree
+is part of btrfs-progs. Btrfs is currently under heavy development,
+and not suitable for any uses other than benchmarking and review.
+Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
+further details.
+.SH SEE ALSO
+.BR mkfs.btrfs (8)
-- 
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