btrfs suddenly lost all om my huge free space

2012-10-13 Thread Tommy Pettersson
Hi,

(I'm not subscribed to the list, so please CC me.)

I have a btrfs with raid1 on two identical unpartitioned disks.
Today I noticed that df (normal df) said I am 77 % full. This
was a chock, because since forever it has been around 12 %.


# btrfs fi show
Label: 'green'  uuid: dd83031c-2447-4736-a8f6-9bd9cdeea879
Total devices 2 FS bytes used 212.88GB
devid2 size 1.82TB used 356.04GB path /dev/sdb
devid1 size 1.82TB used 356.06GB path /dev/sda

# btrfs fi df /
Data, RAID1: total=276.00GB, used=209.02GB
Data: total=8.00M, used=0.00
System, RAID1: total=40.00MB, used=64.00KB
System: total=4.00MB, used=0.00
Metadata, RAID1: total=80.00GB, used=3.88GB
Metadata: total=8.00MB, used=0.00

# df -h
Filesystem  Size  Used Avail Use% Mounted on
rootfs  3.7T  426G   134G  77% /


The thing that has drastically changed is Avail in the output
from df.

I tried a btrfs balance, which self-aborted after some hours
with No space left on device. I deleted two snapshots, so I got
some free space and could use the system again.

The balance, although it didn't finish, seems to have reduced
the used space, but it also reduced the "available" space:


# btrfs fi show
Label: 'green'  uuid: dd83031c-2447-4736-a8f6-9bd9cdeea879
Total devices 2 FS bytes used 212.88GB
devid2 size 1.82TB used 356.04GB path /dev/sdb
devid1 size 1.82TB used 215.01GB path /dev/sda

# btrfs fi df /
Data, RAID1: total=210.00GB, used=197.97GB
System, RAID1: total=8.00MB, used=44.00KB
System: total=4.00MB, used=0.00
Metadata, RAID1: total=5.00GB, used=3.41GB

# df -h
Filesystem  Size  Used Avail Use% Mounted on
rootfs  3.7T  403G   25G  95% /


I made an unqualified guess that the space cache was corrupted,
and tried to mount with option clear_cache and nospace_cache.
Both of them caused btrfs to scan my disks for a couple of
minutes at boot, but the amount of available space did not
improve.

What can I do to help locate the cause of this problem?


Regards,
Tommy
--
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: BTRFS filesystem is not mountable after crash

2012-10-13 Thread cwillu
On Sat, Oct 13, 2012 at 11:51 AM, Alfred Zastrow  wrote:
> Am 26.08.2012 08:17, schrieb Liu Bo:
>
>> On 08/26/2012 01:27 PM, Alfred Zastrow wrote:
>>
>>
>> Hello,
>>
>> has realy nobody a hint for me?
>>
>> Is compiling chris's latest for-linus helpful?
>>
>> git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git
>>
>> thanks,
>> liubo
>
>
> Hi dev's
>
> I was not able to install chris's latest for-linus under F17, but I tried
> with the latest 3.6.1-Kernel with was recently released.
> Same shit..  :-(

Chris's for-linus is currently all the btrfs changes that will be
going into 3.7.  3.6.1 won't likely have any of them.
--
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-progs: add btrfs subvol show cli

2012-10-13 Thread Goffredo Baroncelli

On 2012-10-12 07:20, Anand jain wrote:

From: Anand Jain

This will add a sub command to show information about a subvol.
eg:
btrfs su show /btrfs/sssv3
/btrfs/sssv3
uuid:   c5d646b5-a749-c646-b082-6d9a3ca870be
Parent uuid:34bc8edd-113f-5141-a814-f6dfae069b01
Creation time:  2012-10-12 11:37:00




+
+/* if in case we decide to have more available data
+   to be shown we can use it as below.
+
+   printf("Object ID: %llu", get_ri.root_id);
+   printf("\n");
+   printf("Generation: %llu", get_ri.gen);
+   printf("\n");
+   printf("OGeneration: %llu", get_ri.ogen);
+   printf("\n");
+   printf("Parent: %llu", get_ri.ref_tree);
+   printf("\n");
+   printf("Top Level: %llu", get_ri.top_id);
+   printf("\n");
+*/


Please, add a switch to show this further data. Does the flags contains 
sensible data ?



+
+   /* clean up */
+   if (get_ri.path)
+   free(get_ri.path);
+   if (get_ri.name)
+   free(get_ri.name);
+   if (get_ri.full_path)
+   free(get_ri.full_path);
+
+   close(fd);
+   free(mnt);
+   return 0;
+}
+
  const struct cmd_group subvolume_cmd_group = {
subvolume_cmd_group_usage, NULL, {
{ "create", cmd_subvol_create, cmd_subvol_create_usage, NULL, 0 
},
@@ -714,6 +826,7 @@ const struct cmd_group subvolume_cmd_group = {
{ "set-default", cmd_subvol_set_default,
cmd_subvol_set_default_usage, NULL, 0 },
{ "find-new", cmd_find_new, cmd_find_new_usage, NULL, 0 },
+   { "show", cmd_subvol_show, cmd_subvol_show_usage, NULL, 0 },
{ 0, 0, 0, 0, 0 }
}
  };
diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 9222580..57c25b0 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -17,6 +17,8 @@ btrfs \- control a btrfs filesystem
  .PP
  \fBbtrfs\fP \fBsubvolume get-default\fP\fI\fP
  .PP
+\fBbtrfs\fP \fBsubvolume show\fP\fI\fP
+.PP
  \fBbtrfs\fP \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] \
  [-s \fIstart\fR] [-t \fIsize\fR] -[vf]<\fIfile\fR>|<\fIdir\fR>  \
  [<\fIfile\fR>|<\fIdir\fR>...]
@@ -160,6 +162,10 @@ Get the default subvolume of the filesystem \fI\fR. 
The output format
  is similar to \fBsubvolume list\fR command.
  .TP

+\fBsubvolume show\fR\fI\fR
+Show information of a given subvolume in the \fI\fR.
+.TP


It is possible to allow "btrfs subvolume show" to process multiple paths ?

btrfs sub show  [ ... ]


+
  \fBfilesystem defragment\fP -c[zlib|lzo] [-l \fIlen\fR] [-s \fIstart\fR] \
  [-t \fIsize\fR] -[vf]<\fIfile\fR>|<\fIdir\fR>  [<\fIfile\fR>|<\fIdir\fR>...]



--
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 0/4] Add show sub command to btrfs subvolume

2012-10-13 Thread Goffredo Baroncelli

Hi Anad,

On 2012-10-12 07:20, Anand jain wrote:

From: Anand Jain

This set of patch will add show sub-command to
btrfs subvolume, which is to show more information
about a given subvol or snapshot. At present it shows
3 info, I hope this will be further useful if enhanced
as needed.


Thanks for working on that; do you think that is it feasible to merge 
the works on "btrfs sub list" and "btrfs sub show" ?
To date the output of "btrfs sub list" is quite cryptic: a lot of 
information on only on row, which is difficult to read. However it has 
the capability to traverse the filesystem to list the subvolumes, to 
sort the output, to filter it...
Instead your work has not the capability to traverse/filter/sort but has 
a very nice output.


The ideal is to extend the actual command (btrfs sub list) to have your 
output (as default) and the current one (as option) when used in script...


BR
G.Baroncelli




eg:
# btrfs su show /btrfs/sssv3
/btrfs/sssv3
uuid:   c5d646b5-a749-c646-b082-6d9a3ca870be
Parent uuid:34bc8edd-113f-5141-a814-f6dfae069b01
Creation time:  2012-10-12 11:37:00


Thanks

Anand Jain (4):
   Btrfs-progs: introduce btrfs_get_subvols function
   Btrfs-progs: need struct root_info to be accesible
   Btrfs-progs: method to fetch root info for subvol
   Btrfs-progs: add btrfs subvol show cli

  btrfs-list.c |  119 ++---
  btrfs-list.h |   49 ++-
  cmds-subvolume.c |  113 +++
  man/btrfs.8.in   |6 +++
  4 files changed, 225 insertions(+), 62 deletions(-)

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


[PATCH 3/3] Document the use of BTRFS_UNIT in man page.

2012-10-13 Thread Goffredo Baroncelli
From: Goffredo Baroncelli 

---
 man/btrfs.8.in |   14 ++
 1 file changed, 14 insertions(+)

diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 9222580..fe7a5e3 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -355,6 +355,20 @@ not enough to read all the resolved results. The max value 
one can set is 64k.
 \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in
 case of failure.
 
+.SH ENVIRONMENTAL VARIABLES
+\fBBTRFS_UNIT\fR set the kind of suffix for the number output by \fBbtrfs\fR. 
+Possible values:
+.RS
+.IP BTRFS_UNIT=IEC
+The number have the IEC suffix: e.g. KiB = 1024 bytes, MiB = 1024 KiB...
+.IP BTRFS_UNIT=SI 
+The number have the SI suffix: e.g. KB = 1000 bytes, MB = 1000 KB...
+.IP BTRFS_UNIT=COMPACT
+For compatibility; the number have the SI suffix but the unit is multiply
+of power of two. E.g. KB = 1024 bytes, MB = 1024 KiB...
+There is no space between the number and the suffix.
+.RE
+
 .SH AVAILABILITY
 .B btrfs
 is part of btrfs-progs. Btrfs filesystem is currently under heavy development,
-- 
1.7.10.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 2/3] Deleted the byte prefix with pretty_sizes().

2012-10-13 Thread Goffredo Baroncelli
From: Goffredo Baroncelli 

When the function pretty_sizes() is used, the word "bytes" must
avoided.
---
 cmds-filesystem.c |2 +-
 cmds-scrub.c  |8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 9c43d35..21cdd7f 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -202,7 +202,7 @@ static void print_one_uuid(struct btrfs_fs_devices 
*fs_devices)
super_bytes_used = pretty_sizes(device->super_bytes_used);
 
total = device->total_devs;
-   printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n", uuidbuf,
+   printf(" uuid: %s\n\tTotal devices %llu FS space used %s\n", uuidbuf,
   (unsigned long long)total, super_bytes_used);
 
free(super_bytes_used);
diff --git a/cmds-scrub.c b/cmds-scrub.c
index 24be20f..69dfa7e 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -125,7 +125,7 @@ static void print_scrub_summary(struct btrfs_scrub_progress 
*p)
 {
u64 err_cnt;
u64 err_cnt2;
-   char *bytes;
+   char *total;
 
err_cnt = p->read_errors +
p->csum_errors +
@@ -137,10 +137,10 @@ static void print_scrub_summary(struct 
btrfs_scrub_progress *p)
if (p->malloc_errors)
printf("*** WARNING: memory allocation failed while scrubbing. "
   "results may be inaccurate\n");
-   bytes = pretty_sizes(p->data_bytes_scrubbed + p->tree_bytes_scrubbed);
-   printf("\ttotal bytes scrubbed: %s with %llu errors\n", bytes,
+   total = pretty_sizes(p->data_bytes_scrubbed + p->tree_bytes_scrubbed);
+   printf("\ttotal scrubbed: %s with %llu errors\n", total,
max(err_cnt, err_cnt2));
-   free(bytes);
+   free(total);
if (err_cnt || err_cnt2) {
printf("\terror details:");
PRINT_SCRUB_ERROR(p->read_errors, "read");
-- 
1.7.10.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 1/3] Add support for different unit.

2012-10-13 Thread Goffredo Baroncelli
From: Goffredo Baroncelli 

The function pretty_sizes() returns a string containing the passed
number. It add a suffix depending by the number: eg KiB, MiB.
This change replace the old SI suffix (KB, MB..) by the IEC
ones (KiB, MiB..). Moreover a space is added between the suffix
and the number.

Setting opprtunately the enviroment variable BTRFS_UNIT, it is
possible to:
BTRFS_UNIT=SI the suffix is KB for 1000bytes, MB for 10^6 bytes...
BTRFS_UNIT=IEC the suffix is KiB for 1024bytes, MiB for 1024 KiB ...
BTRFS_UNIT=COMPACT the suffix is KB for 1024 bytes, MB for 1024 KiB;
   no space between the number and the suffix.

See http://en.wikipedia.org/wiki/Byte for further information about
the different suffix.
---
 utils.c |   70 +++
 1 file changed, 61 insertions(+), 9 deletions(-)

diff --git a/utils.c b/utils.c
index 205e667..8528cc1 100644
--- a/utils.c
+++ b/utils.c
@@ -1085,33 +1085,85 @@ out:
return ret;
 }
 
-static char *size_strs[] = { "", "KB", "MB", "GB", "TB",
+static char *size_strs_inf[] = { "", "KiB", "MiB", "GiB", "TiB",
+   "PiB", "EiB", "ZiB", "YiB"};
+static char *size_strs_dec[] = { "", "KB", "MB", "GB", "TB",
"PB", "EB", "ZB", "YB"};
+
+static int which_unit( ){
+   static int unit=-1;
+   char*u;
+
+   if( unit != -1 )
+   return unit;
+
+   unit = 0;
+
+   u =getenv("BTRFS_UNIT");
+   if(!u) return 0;
+
+   if( !strcmp(u,"SI") )
+   unit = 1;
+   else if( !strcmp(u, "COMPACT") )
+   unit = 2;
+   else if( !strcmp(u, "IEC") )
+   unit = 0;
+   /* else
+   Shall we raise an error ? 
+   */
+   
+   return unit;
+
+}
+
+
 char *pretty_sizes(u64 size)
 {
int num_divs = 0;
-int pretty_len = 16;
+int pretty_len = 20;
float fraction;
-   char *pretty;
+   char *pretty, *space;
+   int  shift = 1024;
+   char **size_strs;
+
+   if( which_unit() == 1 ){/* SI */
+   shift = 1000;
+   size_strs = size_strs_dec;
+   space = " ";
+   } else if( which_unit() == 2 ){ /* Old method:
+  SI suffix, but 
+  multiply of 1024 */
+   shift = 1024;
+   size_strs = size_strs_dec;
+   space = "";
+   }else{
+   shift = 1024;   /* IEC */
+   size_strs = size_strs_inf;
+   space = " ";
+   }
 
-   if( size < 1024 ){
+   if( size < shift ){
fraction = size;
num_divs = 0;
} else {
u64 last_size = size;
num_divs = 0;
-   while(size >= 1024){
+   while(size >= shift){
last_size = size;
-   size /= 1024;
+   size /= shift;
num_divs ++;
}
 
-   if (num_divs > ARRAY_SIZE(size_strs))
+   if (num_divs > ARRAY_SIZE(size_strs_inf))
return NULL;
-   fraction = (float)last_size / 1024;
+   fraction = (float)last_size / shift;
}
pretty = malloc(pretty_len);
-   snprintf(pretty, pretty_len, "%.2f%s", fraction, size_strs[num_divs]);
+
+   snprintf(pretty, pretty_len, "%.2f%s%s", 
+   fraction, 
+   space,
+   size_strs[num_divs]);
return pretty;
 }
 
-- 
1.7.10.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][V1][BTRFS-PROGS] Replace the units from KB to KiB..

2012-10-13 Thread Goffredo Baroncelli
Hi All,

several people asked to update the units showed by the "btrfs" tool
form the SI ones (KB, MB, GB...) to the IEC ones (KiB, MiB...).

The aim of this patch is to allow the user to choice which units
are showed. Depending by the BTRFS_UNIT environmental variable,
the following units are showed:

BTRFS_UNIT=SI the suffix is KB for 1000bytes, MB for 10^6 bytes...
BTRFS_UNIT=IEC the suffix is KiB for 1024bytes, MiB for 1024 KiB ...
BTRFS_UNIT=COMPACT the suffix is KB for 1024 bytes, MB for 1024 KiB;
   no space between the number and the suffix.

BR
G.Baroncelli

Signed-off-by Goffredo Baroncelli 



--
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] Update help page

2012-10-13 Thread Goffredo Baroncelli
From: Goffredo Baroncelli 

---
 man/btrfs.8.in |  100 
 1 file changed, 100 insertions(+)

diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 9222580..7048273 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -27,6 +27,8 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBfilesystem label\fP\fI  [newlabel]\fP
 .PP
+\fBbtrfs\fP \fBfilesystem df\fP\fI [-k] \fIpath [path..]\fR\fP
+.PP
 \fBbtrfs\fP \fBsubvolume find-new\fP\fI  \fP
 .PP
 \fBbtrfs\fP \fBfilesystem balance\fP\fI  \fP
@@ -242,6 +244,104 @@ NOTE: Currently there are the following limitations:
 - the filesystem should not have more than one device.
 .TP
 
+\fBfilesystem df\fP [-k] \fIpath [path..]\fR
+
+Show space usage information for a mount point.
+
+\fIOptions\fP
+
+\fB-k\fP Set KB (1024 bytes) as unit
+
+\fIUsage information\fP
+
+.\"
+.\" this section is extract from 
+.\"http://en.wikipedia.org/wiki/Btrfs#Chunk_and_device_trees
+The disk(s) of a btrfs filesystem are divided into chunks of 256 MB or more. 
+Chunks may be mirrored or striped across multiple devices, depending by
+the allocation policy.
+The mirroring/striping arrangement is transparent to the rest of the 
+file system, which simply sees the single, logical address space that 
+chunks are mapped into.
+Chunks are allocated on demand. In the default allocation policy 
+the data chunks are not duplicated and the metadata chunks
+are duplicated. This default can be changed during the filesystem
+creation, and in general the chunks allocation policy may change
+during the filesystem life. 
+
+Depending by the allocation policy a chunk may require a space on
+the disk greater than the logical space that it provides. E.g.
+a chunk DUPlicated or with a RAID1/RAID10 level 
+requires a space on the disk 
+two times greater than the logical space provided. 
+Different RAID levels
+have a different ratio disk-usage / logical space offered.
+
+Normally the file contents are stored in the Data chunks; however
+small files (which fit into a btree leaf) are stored in the 
+metadata chunks. So the computation of the \fIfree space\fP 
+and \fIused space\fP
+is complex: depending by the file size different 
+allocation policies are used.
+
+The command \fBbtrfs filesystem df\fP is used to query the status
+of the chunks, how many space on the disk(s) are used by the chunks, 
+how many space are available in the chunks, and an estimation of the free
+space of the filesystem.
+The output of the command \fBbtrfs filesystem df\fP shows:
+
+.RS
+.IP \fBDisk\ size\fP
+the total size of the disks which compose the filesystem.
+
+.IP \fBDisk\ allocated\fP\ or\ \fBSize_(disk)\fP
+the size of the area of the disks used by the chunks.
+
+.IP \fBDisk\ unallocated\fP 
+the size of the area of the disks which is free (i.e.
+the differences of the values above).
+
+.IP \fBLogical\ size\fP\ or\ \fBSize_(logical)\fP
+the available logical space of chunk. 
+
+.IP \fBUsed\fP
+the portion of the logical space used by the file and metadata.
+
+.IP \fBFree\ (estimated)\fP
+the estimated free space available. The evaluation 
+cannot be rigorous because it depends by the allocation policy (DUP,Single,
+RAID1...) of the metadata and data chunks. If every chunks is stored as
+"Single" the sum of the \fBfree (estimated)\fP space and the \fBused\fP 
+space  is equal to the \fBdisk size\fP.
+Otherwise if all the chunk are mirrored (raid1 or raid10) or duplicated
+the sum of the \fBfree (estimated)\fP space and the \fBused\fP space is
+half of the \fBdisk size\fP. Normally the \fBfree (estimated)\fP is between
+these two limits.
+
+.IP \fBData\ to\ disk\ ratio\fP
+the ratio betwen the \fBlogical size\fP and the \fBdisk allocated\fP.
+
+.IP \fBMode\fP
+the kind of allocation policy used by the chunk (e.g. DUPlicated,
+RAID1, RAID10, Single)
+
+.IP \fBType\fP
+the kind of chunk (Data, Metdata, System...)
+
+.RE
+.RS
+\fINOTE\fP
+
+When a chunk is allocated, its disk-area is used and its allocation
+policy is fixed.
+A rebalance operation could rearrange the chunks, moving data in the chunks
+and resizing the allocated chunks. This causes the change of all the values 
+discussed above, with the exception of the \fBused\fP and 
+\fBdisk size\fP values.
+
+.RE
+.TP
+
 \fBfilesystem show\fR [--all-devices||]\fR
 Show the btrfs filesystem with some additional info. If no \fIUUID\fP or 
 \fIlabel\fP is passed, \fBbtrfs\fR show info of all the btrfs filesystem.
-- 
1.7.10.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 1/2] Update btrfs filesystem df command

2012-10-13 Thread Goffredo Baroncelli
From: Goffredo Baroncelli 

The  command  btrfs  filesystem  df is used to query the
status of the chunks, how many space on the disk(s) are used  by
the  chunks,  how many space are available in the chunks, and an
estimation of the free space of the filesystem.
---
 cmds-filesystem.c |  311 -
 1 file changed, 260 insertions(+), 51 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 9c43d35..fceba0e 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "kerncompat.h"
 #include "ctree.h"
@@ -39,25 +40,86 @@ static const char * const filesystem_cmd_group_usage[] = {
NULL
 };
 
-static const char * const cmd_df_usage[] = {
-   "btrfs filesystem df ",
-   "Show space usage information for a mount point",
-   NULL
-};
+static u64 disk_size( char *path){
+   struct statfs   sfs;
+
+   if( statfs(path, &sfs) < 0 )
+   return 0;
+   else
+   return sfs.f_bsize * sfs.f_blocks;
+
+}
+
+static void **strings_to_free=0;
+static int count_string_to_free=0;
+
+static void add_strings_to_free(char *s)
+{
+   int  size;
+
+   size = sizeof(void*) * ++count_string_to_free;
+   strings_to_free = realloc( strings_to_free, size);
+
+   /* if we don't have enough memory, we have more serius
+  problem than that a wrong handling of not enough memory */
+   if(!strings_to_free){
+   fprintf(stderr, "add_string_to_free(): Not enough memory\n");
+   strings_to_free=0;
+   count_string_to_free=0;
+   }
+
+   strings_to_free[count_string_to_free-1] = s;
+}
+
+static void free_strings_to_free( )
+{
+   int i;
+   for( i = 0 ; i < count_string_to_free ; i++ )
+   free(strings_to_free[i]);
+
+   free(strings_to_free);
+
+   strings_to_free=0;
+   count_string_to_free=0;
+}
+
+#define DF_SHOW_SUMMARY(1<<1)
+#define DF_SHOW_DETAIL (1<<2)
+#define DF_HUMAN_UNIT  (1<<3)
+
+static char *df_pretty_sizes(u64 size, int mode)
+{
+   char *s;
+
+   if( mode & DF_HUMAN_UNIT ){
+   s = pretty_sizes(size);
+   if(!s) return NULL;
+   } else {
+   s = malloc(20);
+   if(!s) return NULL;
+   sprintf(s, "%llu", size/1024);
+   }
+
+   add_strings_to_free(s);
+   return s;
+}
+
 
-static int cmd_df(int argc, char **argv)
+static int _cmd_disk_free(char *path, int mode)
 {
struct btrfs_ioctl_space_args *sargs, *sargs_orig;
u64 count = 0, i;
int ret;
int fd;
-   int e;
-   char *path;
-
-   if (check_argc_exact(argc, 2))
-   usage(cmd_df_usage);
-
-   path = argv[1];
+   int e, width, width_sl;
+   u64  total_disk;/* filesystem size == sum of
+  disks sizes */
+   u64  total_chunks;  /* sum of chunks sizes on disk(s) */
+   u64  total_used;/* logical space used */
+   u64  total_free;/* logical space un-used */
+   double K;
+   char*rpath;
+   
 
fd = open_file_or_dir(path);
if (fd < 0) {
@@ -102,65 +164,212 @@ static int cmd_df(int argc, char **argv)
 
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
e = errno;
+   close(fd);
+
if (ret) {
fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n",
path, strerror(e));
-   close(fd);
free(sargs);
return ret;
}
 
-   for (i = 0; i < sargs->total_spaces; i++) {
-   char description[80];
-   char *total_bytes;
-   char *used_bytes;
-   int written = 0;
-   u64 flags = sargs->spaces[i].flags;
+   total_disk = disk_size(path);
+   e = errno;
+   if( total_disk == 0 ){
+   fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n",
+   path, strerror(e));
+   free(sargs);
+   return 19;
+   }
+   
+   total_chunks = total_used = total_free = 0;
 
-   memset(description, 0, 80);
+   for (i = 0; i < sargs->total_spaces; i++) {
+   int  ratio=1;
+   u64  allocated;
 
-   if (flags & BTRFS_BLOCK_GROUP_DATA) {
-   if (flags & BTRFS_BLOCK_GROUP_METADATA) {
-   snprintf(description, 14, "%s",
-"Data+Metadata");
-   written += 13;
-   } else {
-   snprintf(description, 5, "%s", "Data");
-   written += 4;
-   }
-   } else if (flags & BTRFS_BLOCK_GROUP_SYSTE

[PATCH][BTRFS-PROGS][V6] btrfs filesystem df

2012-10-13 Thread Goffredo Baroncelli
Hi Chris,

this serie of patches updated the command "btrfs filesystem
df". I update this command because it is not so easy to get
the information about the disk usage from the command "fi df" and "fi show".
This patch was the result of some discussions on the btrfs 
mailing list. Many thanks to all the contributors.

from the man page (see 2nd patch):

[...]
The  command  btrfs  filesystem  df is used to query the
status of the chunks, how many space on the disk(s) are used  by
the  chunks,  how many space are available in the chunks, and an
estimation of the free space of the filesystem.
[...]

$ ./btrfs filesystem df --help
usage: btrfs filesystem disk-usage [-k]  [..]

Show space usage information for a mount point(s).

-k  Set KB (1024 bytes) as unit

$ ./btrfs filesystem df /
Path: /
Summary:
  Disk_size: 72.57GB
  Disk_allocated:25.10GB
  Disk_unallocated:  47.48GB
  Logical_size:  23.06GB
  Used:  11.01GB
  Free_(Estimated):  55.66GB(Max: 59.52GB, Min: 35.78GB)
  Data_to_disk_ratio:   92 %

Allocated_area:
  TypeMode   Size_(disk)Size_(logical)  Used
  DataSingle 21.01GB   21.01GB   12.77GB
  System  DUP80.00MB   40.00MB4.00KB
  System  Single  4.00MB4.00MB  0.00
  MetadataDUP 4.00GB2.00GB  709.63MB
  MetadataSingle  8.00MB8.00MB  0.00

Where:
Disk_size   -> sum of sizes of teh disks
Disk_allocated  -> sum of chunk sizes
Disk_unallocated-> Disk_size - Disk_allocated
Logical_size-> sum of logical area sizes
Used-> logical area used
Free_(Estimated)-> on the basis of allocated
   chunk, an estrapolation of
   the free space
Data_to_disk_ratio  -> ration between the space occuped
   by a chunk and the real space
   available ( due to duplication
   and/or RAID level)
Type-> kind of chunk
Mode-> allocation policy of a chunk
Size_(disk) -> area of disk(s) occuped by the
   chunk (see it as raw space used)
Size_(logical)  -> logical area size of the chunk
Used-> portion of the logical area
   used by the filesystem



You can pull this change from
   http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git
branch
   disk_free

Please pull.

Signed-off-by: Goffredo Baroncelli 

BR
Goffredo Baroncelli

Changelog:
V5->V6  Th V5 was a wrong patch, please discard it.
V4->V5  Add a close(fd) to avoid file descriptor leaking
V3->V4  Removed the switch -d -s from getopt(), aligned the
column Size_(logical), renamed the fields:
- Details -> Allocated_area
- Chunk_type -> Type
V2->V3  Removed the options '-s' and '-d'; replaced Chunk-size 
and Logical-size with Size_(disk) and Size_(logical).
Update the man page.
V1->V2  Uses getopt(); replace "-" with "_"; change the behaviour
of the switches '-s' and '-d'.
V0->V1  Change the name of command from disk-usage to df

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


Re: [PATCH][BTRFS-PROGS][V5] btrfs filesystem df

2012-10-13 Thread Goffredo Baroncelli

Please, discard this email...

On 2012-10-13 20:52, Goffredo Baroncelli wrote:

Hi Chris,

this serie of patches updated the command "btrfs filesystem
df". I update this command because it is not so easy to get
the information about the disk usage from the command "fi df" and "fi show".
This patch was the result of some discussions on the btrfs
mailing list. Many thanks to all the contributors.

from the man page (see 2nd patch):

[...]
The  command  btrfs  filesystem  df is used to query the
status of the chunks, how many space on the disk(s) are used  by
the  chunks,  how many space are available in the chunks, and an
estimation of the free space of the filesystem.
[...]

$ ./btrfs filesystem df --help
usage: btrfs filesystem disk-usage [-k]  [..]

 Show space usage information for a mount point(s).

 -k  Set KB (1024 bytes) as unit

$ ./btrfs filesystem df /
Path: /
Summary:
   Disk_size: 72.57GB
   Disk_allocated:25.10GB
   Disk_unallocated:  47.48GB
   Logical_size:  23.06GB
   Used:  11.01GB
   Free_(Estimated):  55.66GB(Max: 59.52GB, Min: 35.78GB)
   Data_to_disk_ratio:   92 %

Allocated_area:
   TypeMode   Size_(disk)Size_(logical)  Used
   DataSingle 21.01GB   21.01GB   12.77GB
   System  DUP80.00MB   40.00MB4.00KB
   System  Single  4.00MB4.00MB  0.00
   MetadataDUP 4.00GB2.00GB  709.63MB
   MetadataSingle  8.00MB8.00MB  0.00

Where:
 Disk_size   ->  sum of sizes of teh disks
 Disk_allocated  ->  sum of chunk sizes
 Disk_unallocated->  Disk_size - Disk_allocated
 Logical_size->  sum of logical area sizes
 Used->  logical area used
 Free_(Estimated)->  on the basis of allocated
chunk, an estrapolation of
the free space
 Data_to_disk_ratio  ->  ration between the space occuped
by a chunk and the real space
available ( due to duplication
and/or RAID level)
 Type   ->  kind of chunk
 Mode->  allocation policy of a chunk
 Size_(disk) ->  area of disk(s) occuped by the
chunk (see it as raw space used)
 Size_(logical)  ->  logical area size of the chunk
 Used->  portion of the logical area
used by the filesystem



You can pull this change from
http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git
branch
disk_free

Please pull.

Signed-off-by: Goffredo Baroncelli

BR
Goffredo Baroncelli

Changelog:
V4->V5   Add a close(fd) to avoid file descriptor leaking
V3->V4   Removed the switch -d -s from getopt(), aligned the
column Size_(logical), renamed the fields:
- Details ->  Allocated_area
- Chunk_type ->  Type
V2->V3  Removed the options '-s' and '-d'; replaced Chunk-size
 and Logical-size with Size_(disk) and Size_(logical).
 Update the man page.
V1->V2  Uses getopt(); replace "-" with "_"; change the behaviour
 of the switches '-s' and '-d'.
V0->V1  Change the name of command from disk-usage to df





--
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] Update btrfs filesystem df command

2012-10-13 Thread Goffredo Baroncelli
From: Goffredo Baroncelli 

The  command  btrfs  filesystem  df is used to query the
status of the chunks, how many space on the disk(s) are used  by
the  chunks,  how many space are available in the chunks, and an
estimation of the free space of the filesystem.
---
 cmds-filesystem.c |  310 -
 1 file changed, 260 insertions(+), 50 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index b1457de..77623f2 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "kerncompat.h"
 #include "ctree.h"
@@ -39,25 +40,86 @@ static const char * const filesystem_cmd_group_usage[] = {
NULL
 };
 
-static const char * const cmd_df_usage[] = {
-   "btrfs filesystem df ",
-   "Show space usage information for a mount point",
-   NULL
-};
+static u64 disk_size( char *path){
+   struct statfs   sfs;
+
+   if( statfs(path, &sfs) < 0 )
+   return 0;
+   else
+   return sfs.f_bsize * sfs.f_blocks;
+
+}
+
+static void **strings_to_free=0;
+static int count_string_to_free=0;
+
+static void add_strings_to_free(char *s)
+{
+   int  size;
+
+   size = sizeof(void*) * ++count_string_to_free;
+   strings_to_free = realloc( strings_to_free, size);
 
-static int cmd_df(int argc, char **argv)
+   /* if we don't have enough memory, we have more serius
+  problem than that a wrong handling of not enough memory */
+   if(!strings_to_free){
+   fprintf(stderr, "add_string_to_free(): Not enough memory\n");
+   strings_to_free=0;
+   count_string_to_free=0;
+   }
+
+   strings_to_free[count_string_to_free-1] = s;
+}
+
+static void free_strings_to_free( )
+{
+   int i;
+   for( i = 0 ; i < count_string_to_free ; i++ )
+   free(strings_to_free[i]);
+
+   free(strings_to_free);
+
+   strings_to_free=0;
+   count_string_to_free=0;
+}
+
+#define DF_SHOW_SUMMARY(1<<1)
+#define DF_SHOW_DETAIL (1<<2)
+#define DF_HUMAN_UNIT  (1<<3)
+
+static char *df_pretty_sizes(u64 size, int mode)
+{
+   char *s;
+
+   if( mode & DF_HUMAN_UNIT ){
+   s = pretty_sizes(size);
+   if(!s) return NULL;
+   } else {
+   s = malloc(20);
+   if(!s) return NULL;
+   sprintf(s, "%llu", size/1024);
+   }
+
+   add_strings_to_free(s);
+   return s;
+}
+
+
+static int _cmd_disk_free(char *path, int mode)
 {
struct btrfs_ioctl_space_args *sargs;
u64 count = 0, i;
int ret;
int fd;
-   int e;
-   char *path;
-
-   if (check_argc_exact(argc, 2))
-   usage(cmd_df_usage);
-
-   path = argv[1];
+   int e, width, width_sl;
+   u64  total_disk;/* filesystem size == sum of
+  disks sizes */
+   u64  total_chunks;  /* sum of chunks sizes on disk(s) */
+   u64  total_used;/* logical space used */
+   u64  total_free;/* logical space un-used */
+   double K;
+   char*rpath;
+   
 
fd = open_file_or_dir(path);
if (fd < 0) {
@@ -95,64 +157,212 @@ static int cmd_df(int argc, char **argv)
 
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
e = errno;
+   close(fd);
+
if (ret) {
fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n",
path, strerror(e));
-   close(fd);
free(sargs);
return ret;
}
 
-   for (i = 0; i < sargs->total_spaces; i++) {
-   char description[80];
-   char *total_bytes;
-   char *used_bytes;
-   int written = 0;
-   u64 flags = sargs->spaces[i].flags;
+   total_disk = disk_size(path);
+   e = errno;
+   if( total_disk == 0 ){
+   fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n",
+   path, strerror(e));
+   free(sargs);
+   return 19;
+   }
+   
+   total_chunks = total_used = total_free = 0;
 
-   memset(description, 0, 80);
+   for (i = 0; i < sargs->total_spaces; i++) {
+   int  ratio=1;
+   u64  allocated;
 
-   if (flags & BTRFS_BLOCK_GROUP_DATA) {
-   if (flags & BTRFS_BLOCK_GROUP_METADATA) {
-   snprintf(description, 14, "%s",
-"Data+Metadata");
-   written += 13;
-   } else {
-   snprintf(description, 5, "%s", "Data");
-   written += 4;
-   }
-   } else if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
-

[PATCH][BTRFS-PROGS][V5] btrfs filesystem df

2012-10-13 Thread Goffredo Baroncelli
Hi Chris,

this serie of patches updated the command "btrfs filesystem
df". I update this command because it is not so easy to get
the information about the disk usage from the command "fi df" and "fi show".
This patch was the result of some discussions on the btrfs 
mailing list. Many thanks to all the contributors.

from the man page (see 2nd patch):

[...]
The  command  btrfs  filesystem  df is used to query the
status of the chunks, how many space on the disk(s) are used  by
the  chunks,  how many space are available in the chunks, and an
estimation of the free space of the filesystem.
[...]

$ ./btrfs filesystem df --help
usage: btrfs filesystem disk-usage [-k]  [..]

Show space usage information for a mount point(s).

-k  Set KB (1024 bytes) as unit

$ ./btrfs filesystem df /
Path: /
Summary:
  Disk_size: 72.57GB
  Disk_allocated:25.10GB
  Disk_unallocated:  47.48GB
  Logical_size:  23.06GB
  Used:  11.01GB
  Free_(Estimated):  55.66GB(Max: 59.52GB, Min: 35.78GB)
  Data_to_disk_ratio:   92 %

Allocated_area:
  TypeMode   Size_(disk)Size_(logical)  Used
  DataSingle 21.01GB   21.01GB   12.77GB
  System  DUP80.00MB   40.00MB4.00KB
  System  Single  4.00MB4.00MB  0.00
  MetadataDUP 4.00GB2.00GB  709.63MB
  MetadataSingle  8.00MB8.00MB  0.00

Where:
Disk_size   -> sum of sizes of teh disks
Disk_allocated  -> sum of chunk sizes
Disk_unallocated-> Disk_size - Disk_allocated
Logical_size-> sum of logical area sizes
Used-> logical area used
Free_(Estimated)-> on the basis of allocated
   chunk, an estrapolation of
   the free space
Data_to_disk_ratio  -> ration between the space occuped
   by a chunk and the real space
   available ( due to duplication
   and/or RAID level)
Type-> kind of chunk
Mode-> allocation policy of a chunk
Size_(disk) -> area of disk(s) occuped by the
   chunk (see it as raw space used)
Size_(logical)  -> logical area size of the chunk
Used-> portion of the logical area
   used by the filesystem



You can pull this change from
   http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git
branch
   disk_free

Please pull.

Signed-off-by: Goffredo Baroncelli 

BR
Goffredo Baroncelli

Changelog:
V4->V5  Add a close(fd) to avoid file descriptor leaking
V3->V4  Removed the switch -d -s from getopt(), aligned the
column Size_(logical), renamed the fields:
- Details -> Allocated_area
- Chunk_type -> Type
V2->V3  Removed the options '-s' and '-d'; replaced Chunk-size 
and Logical-size with Size_(disk) and Size_(logical).
Update the man page.
V1->V2  Uses getopt(); replace "-" with "_"; change the behaviour
of the switches '-s' and '-d'.
V0->V1  Change the name of command from disk-usage to df


--
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: BTRFS filesystem is not mountable after crash

2012-10-13 Thread Alfred Zastrow

Am 26.08.2012 08:17, schrieb Liu Bo:

On 08/26/2012 01:27 PM, Alfred Zastrow wrote:


Hello,

has realy nobody a hint for me?

Is compiling chris's latest for-linus helpful?

git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git

thanks,
liubo


Hi dev's

I was not able to install chris's latest for-linus under F17, but I 
tried with the latest 3.6.1-Kernel with was recently released.

Same shit..  :-(


[root@z2 alfred]# mount /dev/sdb1 /mnt -o recovery,ro
mount: mount /dev/sdb1 on /mnt failed: Veraltete NFS-Dateizugriffsnummer

[root@z2 alfred]# dmesg

[...]

[41005.694357] device fsid 4d00f0e6-e9d7-42d9-8514-827d8f01f7d3 devid 1 
transid 192347 /dev/sdb1

[41005.696173] btrfs: enabling auto recovery
[41005.698539] btrfs: mismatching generation and generation_v2 found in 
root item. This root was probably mounted with an older kernel. 
Resetting all new fields.
[41005.698732] btrfs: mismatching generation and generation_v2 found in 
root item. This root was probably mounted with an older kernel. 
Resetting all new fields.
[41005.699307] btrfs: bdev /dev/sdb1 errs: wr 0, rd 0, flush 0, corrupt 
20, gen 0

[41005.741978] Btrfs detected SSD devices, enabling SSD mode
[41005.742459] btrfs bad tree block start 0 29450240
[41005.742514] btrfs bad tree block start 0 29450240

All the other tools (btrfs-restore, btrfsck, restore from Josef) gave me 
the same results as I  have written in my 1st mail.


Sadly I have realized, that some of my vacation pictures are still on 
the SSD - without backup...  :-(



Best regards
Alfred
--
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] Update help page

2012-10-13 Thread Goffredo Baroncelli
From: Goffredo Baroncelli 

---
 man/btrfs.8.in |  100 
 1 file changed, 100 insertions(+)

diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 4b0a9f9..ecd0916 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -27,6 +27,8 @@ btrfs \- control a btrfs filesystem
 .PP
 \fBbtrfs\fP \fBfilesystem label\fP\fI  [newlabel]\fP
 .PP
+\fBbtrfs\fP \fBfilesystem df\fP\fI [-k] \fIpath [path..]\fR\fP
+.PP
 \fBbtrfs\fP \fBsubvolume find-new\fP\fI  \fP
 .PP
 \fBbtrfs\fP \fBfilesystem balance\fP\fI  \fP
@@ -214,6 +216,104 @@ NOTE: Currently there are the following limitations:
 - the filesystem should not have more than one device.
 .TP
 
+\fBfilesystem df\fP [-k] \fIpath [path..]\fR
+
+Show space usage information for a mount point.
+
+\fIOptions\fP
+
+\fB-k\fP Set KB (1024 bytes) as unit
+
+\fIUsage information\fP
+
+.\"
+.\" this section is extract from 
+.\"http://en.wikipedia.org/wiki/Btrfs#Chunk_and_device_trees
+The disk(s) of a btrfs filesystem are divided into chunks of 256 MB or more. 
+Chunks may be mirrored or striped across multiple devices, depending by
+the allocation policy.
+The mirroring/striping arrangement is transparent to the rest of the 
+file system, which simply sees the single, logical address space that 
+chunks are mapped into.
+Chunks are allocated on demand. In the default allocation policy 
+the data chunks are not duplicated and the metadata chunks
+are duplicated. This default can be changed during the filesystem
+creation, and in general the chunks allocation policy may change
+during the filesystem life. 
+
+Depending by the allocation policy a chunk may require a space on
+the disk greater than the logical space that it provides. E.g.
+a chunk DUPlicated or with a RAID1/RAID10 level 
+requires a space on the disk 
+two times greater than the logical space provided. 
+Different RAID levels
+have a different ratio disk-usage / logical space offered.
+
+Normally the file contents are stored in the Data chunks; however
+small files (which fit into a btree leaf) are stored in the 
+metadata chunks. So the computation of the \fIfree space\fP 
+and \fIused space\fP
+is complex: depending by the file size different 
+allocation policies are used.
+
+The command \fBbtrfs filesystem df\fP is used to query the status
+of the chunks, how many space on the disk(s) are used by the chunks, 
+how many space are available in the chunks, and an estimation of the free
+space of the filesystem.
+The output of the command \fBbtrfs filesystem df\fP shows:
+
+.RS
+.IP \fBDisk\ size\fP
+the total size of the disks which compose the filesystem.
+
+.IP \fBDisk\ allocated\fP\ or\ \fBSize_(disk)\fP
+the size of the area of the disks used by the chunks.
+
+.IP \fBDisk\ unallocated\fP 
+the size of the area of the disks which is free (i.e.
+the differences of the values above).
+
+.IP \fBLogical\ size\fP\ or\ \fBSize_(logical)\fP
+the available logical space of chunk. 
+
+.IP \fBUsed\fP
+the portion of the logical space used by the file and metadata.
+
+.IP \fBFree\ (estimated)\fP
+the estimated free space available. The evaluation 
+cannot be rigorous because it depends by the allocation policy (DUP,Single,
+RAID1...) of the metadata and data chunks. If every chunks is stored as
+"Single" the sum of the \fBfree (estimated)\fP space and the \fBused\fP 
+space  is equal to the \fBdisk size\fP.
+Otherwise if all the chunk are mirrored (raid1 or raid10) or duplicated
+the sum of the \fBfree (estimated)\fP space and the \fBused\fP space is
+half of the \fBdisk size\fP. Normally the \fBfree (estimated)\fP is between
+these two limits.
+
+.IP \fBData\ to\ disk\ ratio\fP
+the ratio betwen the \fBlogical size\fP and the \fBdisk allocated\fP.
+
+.IP \fBMode\fP
+the kind of allocation policy used by the chunk (e.g. DUPlicated,
+RAID1, RAID10, Single)
+
+.IP \fBType\fP
+the kind of chunk (Data, Metdata, System...)
+
+.RE
+.RS
+\fINOTE\fP
+
+When a chunk is allocated, its disk-area is used and its allocation
+policy is fixed.
+A rebalance operation could rearrange the chunks, moving data in the chunks
+and resizing the allocated chunks. This causes the change of all the values 
+discussed above, with the exception of the \fBused\fP and 
+\fBdisk size\fP values.
+
+.RE
+.TP
+
 \fBfilesystem show\fR [--all-devices||]\fR
 Show the btrfs filesystem with some additional info. If no \fIUUID\fP or 
 \fIlabel\fP is passed, \fBbtrfs\fR show info of all the btrfs filesystem.
-- 
1.7.10.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 1/2] Update btrfs filesystem df command

2012-10-13 Thread Goffredo Baroncelli
From: Goffredo Baroncelli 

The  command  btrfs  filesystem  df is used to query the
status of the chunks, how many space on the disk(s) are used  by
the  chunks,  how many space are available in the chunks, and an
estimation of the free space of the filesystem.
---
 cmds-filesystem.c |  308 -
 1 file changed, 259 insertions(+), 49 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index b1457de..509e393 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "kerncompat.h"
 #include "ctree.h"
@@ -39,25 +40,86 @@ static const char * const filesystem_cmd_group_usage[] = {
NULL
 };
 
-static const char * const cmd_df_usage[] = {
-   "btrfs filesystem df ",
-   "Show space usage information for a mount point",
-   NULL
-};
+static u64 disk_size( char *path){
+   struct statfs   sfs;
+
+   if( statfs(path, &sfs) < 0 )
+   return 0;
+   else
+   return sfs.f_bsize * sfs.f_blocks;
+
+}
+
+static void **strings_to_free=0;
+static int count_string_to_free=0;
+
+static void add_strings_to_free(char *s)
+{
+   int  size;
+
+   size = sizeof(void*) * ++count_string_to_free;
+   strings_to_free = realloc( strings_to_free, size);
+
+   /* if we don't have enough memory, we have more serius
+  problem than that a wrong handling of not enough memory */
+   if(!strings_to_free){
+   fprintf(stderr, "add_string_to_free(): Not enough memory\n");
+   strings_to_free=0;
+   count_string_to_free=0;
+   }
+
+   strings_to_free[count_string_to_free-1] = s;
+}
+
+static void free_strings_to_free( )
+{
+   int i;
+   for( i = 0 ; i < count_string_to_free ; i++ )
+   free(strings_to_free[i]);
+
+   free(strings_to_free);
+
+   strings_to_free=0;
+   count_string_to_free=0;
+}
+
+#define DF_SHOW_SUMMARY(1<<1)
+#define DF_SHOW_DETAIL (1<<2)
+#define DF_HUMAN_UNIT  (1<<3)
 
-static int cmd_df(int argc, char **argv)
+static char *df_pretty_sizes(u64 size, int mode)
+{
+   char *s;
+
+   if( mode & DF_HUMAN_UNIT ){
+   s = pretty_sizes(size);
+   if(!s) return NULL;
+   } else {
+   s = malloc(20);
+   if(!s) return NULL;
+   sprintf(s, "%llu", size/1024);
+   }
+
+   add_strings_to_free(s);
+   return s;
+}
+
+
+static int _cmd_disk_free(char *path, int mode)
 {
struct btrfs_ioctl_space_args *sargs;
u64 count = 0, i;
int ret;
int fd;
-   int e;
-   char *path;
-
-   if (check_argc_exact(argc, 2))
-   usage(cmd_df_usage);
-
-   path = argv[1];
+   int e, width, width_sl;
+   u64  total_disk;/* filesystem size == sum of
+  disks sizes */
+   u64  total_chunks;  /* sum of chunks sizes on disk(s) */
+   u64  total_used;/* logical space used */
+   u64  total_free;/* logical space un-used */
+   double K;
+   char*rpath;
+   
 
fd = open_file_or_dir(path);
if (fd < 0) {
@@ -103,56 +165,204 @@ static int cmd_df(int argc, char **argv)
return ret;
}
 
-   for (i = 0; i < sargs->total_spaces; i++) {
-   char description[80];
-   char *total_bytes;
-   char *used_bytes;
-   int written = 0;
-   u64 flags = sargs->spaces[i].flags;
+   total_disk = disk_size(path);
+   e = errno;
+   if( total_disk == 0 ){
+   fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n",
+   path, strerror(e));
+   close(fd);
+   free(sargs);
+   return 19;
+   }
+   
+   total_chunks = total_used = total_free = 0;
 
-   memset(description, 0, 80);
+   for (i = 0; i < sargs->total_spaces; i++) {
+   int  ratio=1;
+   u64  allocated;
 
-   if (flags & BTRFS_BLOCK_GROUP_DATA) {
-   if (flags & BTRFS_BLOCK_GROUP_METADATA) {
-   snprintf(description, 14, "%s",
-"Data+Metadata");
-   written += 13;
-   } else {
-   snprintf(description, 5, "%s", "Data");
-   written += 4;
-   }
-   } else if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
-   snprintf(description, 7, "%s", "System");
-   written += 6;
-   } else if (flags & BTRFS_BLOCK_GROUP_METADATA) {
-   snprintf(description, 9, "%s", "Metadata");
-   written += 8;
- 

[PATCH][BTRFS-PROGS][V4] btrfs filesystem df

2012-10-13 Thread Goffredo Baroncelli
Hi Chris,

this serie of patches updated the command "btrfs filesystem
df". I update this command because it is not so easy to get
the information about the disk usage from the command "fi df" and "fi show".
This patch was the result of some discussions on the btrfs 
mailing list. Many thanks to all the contributors.

from the man page (see 2nd patch):

[...]
The  command  btrfs  filesystem  df is used to query the
status of the chunks, how many space on the disk(s) are used  by
the  chunks,  how many space are available in the chunks, and an
estimation of the free space of the filesystem.
[...]

$ ./btrfs filesystem df --help
usage: btrfs filesystem disk-usage [-k]  [..]

Show space usage information for a mount point(s).

-k  Set KB (1024 bytes) as unit

$ ./btrfs filesystem df /
Path: /
Summary:
  Disk_size: 72.57GB
  Disk_allocated:25.10GB
  Disk_unallocated:  47.48GB
  Logical_size:  23.06GB
  Used:  11.01GB
  Free_(Estimated):  55.66GB(Max: 59.52GB, Min: 35.78GB)
  Data_to_disk_ratio:   92 %

Allocated_area:
  TypeMode   Size_(disk)Size_(logical)  Used
  DataSingle 21.01GB   21.01GB   12.77GB
  System  DUP80.00MB   40.00MB4.00KB
  System  Single  4.00MB4.00MB  0.00
  MetadataDUP 4.00GB2.00GB  709.63MB
  MetadataSingle  8.00MB8.00MB  0.00

Where:
Disk_size   -> sum of sizes of teh disks
Disk_allocated  -> sum of chunk sizes
Disk_unallocated-> Disk_size - Disk_allocated
Logical_size-> sum of logical area sizes
Used-> logical area used
Free_(Estimated)-> on the basis of allocated
   chunk, an estrapolation of
   the free space
Data_to_disk_ratio  -> ration between the space occuped
   by a chunk and the real space
   available ( due to duplication
   and/or RAID level)
Type-> kind of chunk
Mode-> allocation policy of a chunk
Size_(disk) -> area of disk(s) occuped by the
   chunk (see it as raw space used)
Size_(logical)  -> logical area size of the chunk
Used-> portion of the logical area
   used by the filesystem



You can pull this change from
   http://cassiopea.homelinux.net/git/btrfs-progs-unstable.git
branch
   disk_free

Please pull.

BR
Goffredo Baroncelli

Changelog:
V3->V4  Removed the switch -d -s from getopt(), aligned the
column Size_(logical), renamed the fields:
- Details -> Allocated_area
- Chunk_type -> Type
V2->V3  Removed the options '-s' and '-d'; replaced Chunk-size 
and Logical-size with Size_(disk) and Size_(logical).
Update the man page.
V1->V2  Uses getopt(); replace "-" with "_"; change the behaviour
of the switches '-s' and '-d'.
V0->V1  Change the name of command from disk-usage to df

--
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: btrfs receive to subdirectory

2012-10-13 Thread Alex Lyakas
Rory,
thanks for confirming. I will put together a more formal patch to the list.

Thanks,
Alex.


On Fri, Oct 12, 2012 at 6:10 PM, Rory Campbell-Lange
 wrote:
> On 12/10/12, Alex Lyakas (alex.bt...@zadarastorage.com) wrote:
>> Hi Rory,
>> can you pls check if you have a file "/etc/mtab" on your machine? If
>> not or if it's empty or something like, then this probably explains
>> the issue. In this case, pls apply patch2 that is attached (instead of
>> previous patches). Otherwise, pls try with patch1 (instead of
>> previous) and then with patch2 (instead of any previous). Both will do
>> some amount of prints, pls post them. With both patches your tests
>> work fine for me.
>
> Hi Alex
>
> I reset everything and remade the btrfs partitions. I re-pulled
> git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git
> and applied your first patch.
>
>   (in /bkp)
>   mkdir snaps
>   btrfs snapshot -r mail snaps/snap1
>   btrfs subvolume snapshot -r mail snaps/snap1
>   mutt -f mail/INBOX/
>   btrfs subvolume snapshot -r mail snaps/snap2
>
>   # targets (dir, subvol with same name, subvol with different name)
>   mkdir /mnt/snaps
>   btrfs subvolume create /mnt/mail
>   btrfs subvolume create /mnt/snapmail
>   # base backup
>   btrfs send snaps/snap1 | btrfs receive /mnt/snaps
>   btrfs send snaps/snap1 | btrfs receive /mnt/mail
>   btrfs send snaps/snap1 | btrfs receive /mnt/snapmail
>   # update snapshots
>   btrfs send -p snaps/snap1 snaps/snap2 | btrfs receive /mnt/snaps
>   btrfs send -p snaps/snap1 snaps/snap2 | btrfs receive /mnt/mail
>   btrfs send -p snaps/snap1 snaps/snap2 | btrfs receive /mnt/snapmail
>
> All worked fine. Sorry for the previous errors, which look to be
> invalid.
>
> Cheers
> Rory
>
>
> /etc/mtab:
>
> rootfs / rootfs rw 0 0
> sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
> proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
> udev /dev devtmpfs rw,relatime,size=10240k,nr_inodes=749414,mode=755 0 0
> devpts /dev/pts devpts 
> rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
> tmpfs /run tmpfs rw,nosuid,noexec,relatime,size=600748k,mode=755 0 0
> /dev/disk/by-uuid/6e899e2d-c401-4a92-8adf-a097bcaf2148 / ext4 
> rw,relatime,errors=remount-ro,data=ordered 0 0
> tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
> tmpfs /run/shm tmpfs rw,nosuid,nodev,noexec,relatime,size=1396860k 0 0
> /dev/sda1 /boot ext4 rw,relatime,data=ordered 0 0
> rpc_pipefs /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0
> /dev/sdb1 /mnt btrfs rw,relatime,space_cache 0 0
> /dev/sda6 /bkp btrfs rw,relatime,space_cache 0 0
>
> --
> Rory Campbell-Lange
> r...@campbell-lange.net
--
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] Fits: tool to parse stream

2012-10-13 Thread David Sterba
On Sat, Oct 13, 2012 at 09:08:57AM +0100, Rory Campbell-Lange wrote:
> Perhaps "BTRFS Incremental Stream" or "Backup Incremental Stream" should
> be considered, with the file extension ".bis".

>From the brainstorming we had about the name, the intention behind the
stream is to be filesystem independent.

So this might be named FIS with .fis extension, that is not far from the
proposed name. However, this hasn't been approved by the Slang committee
yet :)

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] Fits: tool to parse stream

2012-10-13 Thread Rory Campbell-Lange
On 13/10/12, Arne Jansen (sensi...@gmx.net) wrote:
> On 10/12/12 15:32, Arne Jansen wrote:
> 
> > The idea of the btrfs send stream format was to generate it in a way that
> > it is easy to receive on different platforms. Thus the proposed name FITS, 
> > for
> > Filesystem Incremental Backup Stream. We should also build the tools to
> > receive the stream on different platforms.
> 
> I meant to write 'Filesystem Incremental Transport Stream', but, as
> Andrey Kuzmin pointed out, the name FITS is already taken. As the
> 'Backup' slipped in somehow, FIBS might be an alternative. Any
> thoughts?

Perhaps "BTRFS Incremental Stream" or "Backup Incremental Stream" should
be considered, with the file extension ".bis".

The word "bis" is also, according to Wikipedia, "...a prefix of suffix
designating the second instance of a thing...", which seems largely
appropriate.
http://en.m.wikipedia.org/wiki/BIS

Rory

-- 
Rory Campbell-Lange
r...@campbell-lange.net
--
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] Fits: tool to parse stream

2012-10-13 Thread Hugo Mills
On Sat, Oct 13, 2012 at 09:02:27AM +0200, Arne Jansen wrote:
> On 10/12/12 15:32, Arne Jansen wrote:
> 
> > The idea of the btrfs send stream format was to generate it in a way that
> > it is easy to receive on different platforms. Thus the proposed name FITS, 
> > for
> > Filesystem Incremental Backup Stream. We should also build the tools to
> > receive the stream on different platforms.
> 
> I meant to write 'Filesystem Incremental Transport Stream', but, as
> Andrey Kuzmin pointed out, the name FITS is already taken. As the
> 'Backup' slipped in somehow, FIBS might be an alternative. Any
> thoughts?

   Fibs is a slang term for lies. Probably not ideal.

   Hugo.

-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- Strive for apathy! ---


signature.asc
Description: Digital signature


Re: [PATCH] Fits: tool to parse stream

2012-10-13 Thread Arne Jansen
On 10/12/12 15:32, Arne Jansen wrote:

> The idea of the btrfs send stream format was to generate it in a way that
> it is easy to receive on different platforms. Thus the proposed name FITS, for
> Filesystem Incremental Backup Stream. We should also build the tools to
> receive the stream on different platforms.

I meant to write 'Filesystem Incremental Transport Stream', but, as
Andrey Kuzmin pointed out, the name FITS is already taken. As the
'Backup' slipped in somehow, FIBS might be an alternative. Any
thoughts?

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