Btrfs-progs: add dedup subcommand

This adds deduplication subcommands, 'btrfs dedup command <path>',
including enable/disable/on/off.

- btrfs dedup enable
Create the dedup tree, and it's the very first step when you're going to use
the dedup feature.

- btrfs dedup disable
Delete the dedup tree, after this we're not able to use dedup any more unless
you enable it again.

- btrfs dedup on [-b]
Switch on the dedup feature temporarily, and it's the second step of applying
dedup with writes.  Option '-b' is used to set dedup blocksize.
The default blocksize is 8192(no special reason, you may argue), and the current
limit is [4096, 128 * 1024], because 4K is the generic page size and 128K is the
upper limit of btrfs's compression.

- btrfs dedup off
Switch off the dedup feature temporarily, but the dedup tree remains.

---------------------------------------------------------
Usage:
Step 1: btrfs dedup enable /btrfs
Step 2: btrfs dedup on /btrfs or btrfs dedup on -b 4K /btrfs
Step 3: now we have dedup, run your test.
Step 4: btrfs dedup off /btrfs
Step 5: btrfs dedup disable /btrfs
---------------------------------------------------------

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Btrfs-progs: introduce btrfs property subgroup

"btrfs filesystem property" is a generic interface to set/get
properties on filesystem objects (inodes/subvolumes/filesystems
/devs).

This patch adds the generic framework for properties and also
implements two properties. The first is the read-only property
for subvolumes and the second is the label property for devices.

Signed-off-by: Alexander Block <ablock84@googlemail.com>
Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Btrfs-progs: fix detection of root objects in cmds-property.c

Several fixes:

1) The function check_is_root() returns 0 if the object is root;

2) Don't treat any error from get fsid ioctl as meaning the target
   is root. Only -ENOTTY means it's a root (parent directory is
   not a btrfs fs) and a -ENOTDIR means our target object is not a
   directory, therefore it can be the root;

3) Fix the comparison of the target and target's parent fs ids. If
   they are different, it means the target is a mount point in a
   btrfs fs, therefore it's a root, otherwise it isn't.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Btrfs-progs: add type root to label property

So that we can get the label of a mounted filesystem.

Before this change:

        $ btrfs prop get /mnt/btrfs label
        ERROR: object is not compatible with property

        $ btrfs prop get /dev/sdb3 label
        ERROR: dev /dev/sdb3 is mounted, use mount point
        ERROR: failed to set/get property for object.

After this change:

        $ btrfs prop get /mnt/btrfs label
        label=foobar

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Btrfs-progs: add support for the compression property

With this property, one can enable compression for individual files
without the need to mount the filesystem with the compress or
compress-force options, and specify the compression algorithm.

When applied against a directory, files created under that directory
will inherit the compression property.

This requires the corresponding kernel patch, which adds the support
for setting and getting properties and implements the compression
property.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: mechanism to fetch fsinfo from btrfs-control

need fsinfo from btrfs-control that is when mount path is
not known.
current method of going through each mount points isn't
efficient, and multiple subvol of a fsid could be mounted
means extra logic to handle that. Further this will help
to revamp check_mounted() (planned)

check_mounted is heavily used in the btrfs-progs, it
does full scan of all the disks in the system to confirm
if a multi-disk btrfs is mounted it doesn't scalable well
with few hundreds luns, check_mounted for sure needs a
revamp. using this it can be done easily. which is planned.

This patch depends on the btrfs kernel patch
btrfs: add framework to read fs info from btrfs-control

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: fs show should handle if subvol(s) mounted

as of now with out this patch user would see
fsinfo per btrfs mount path but which mean multiple
entry if more than one subvol is mounted of the same
fsid. so this patch will handle that nicely.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: lblkid wouldn't find non mapper path input

A new test case when disk is unmounted and if the non mapper
disk path is given as the argument to the btrfs filesystem show <arg>
we still need this to work but lblkid will pull only mapper disks,
it won't match. So this will normalize the input to find btrfs
by fsid and pass it to the search.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: return non zero when label is not found

btrfs filesystem show <not-found-label> should return non zero

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfs-progs: mid flight return leaks memory during filesystem show mnt

since now handle_print()->print_one_fs() calls add_seen_fsid()
the thread has to go through free_seen_fsid()

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Merge branch 'integration-next' into integration