Re: [PATCH] Btrfs: do not add replace target to the alloc_list

2013-09-04 Thread Stefan Behrens
On Sun,  1 Sep 2013 18:56:44 +0300, Ilya Dryomov wrote:
 If replace was suspended by the umount, replace target device is added
 to the fs_devices-alloc_list during a later mount.  This is obviously
 wrong.  -is_tgtdev_for_dev_replace is supposed to guard against that,
 but -is_tgtdev_for_dev_replace is (and can only ever be) initialized
 *after* everything is opened and fs_devices lists are populated.  Fix
 this by checking the devid instead: for replace targets it's always
 equal to BTRFS_DEV_REPLACE_DEVID.
 
 Cc: Stefan Behrens sbehr...@giantdisaster.de
 Signed-off-by: Ilya Dryomov idryo...@gmail.com
 ---
 At first I thought this was caused by my btrfs_device rollback patch,
 but no, it just made it easier to spot -- previously one had to reboot
 or rmmod/insmod before mounting a suspended replace.
 
  fs/btrfs/volumes.c |3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
 
 diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
 index c9a0977..5b99f19 100644
 --- a/fs/btrfs/volumes.c
 +++ b/fs/btrfs/volumes.c
 @@ -793,7 +793,8 @@ static int __btrfs_open_devices(struct btrfs_fs_devices 
 *fs_devices,
   fs_devices-rotating = 1;
  
   fs_devices-open_devices++;
 - if (device-writeable  !device-is_tgtdev_for_dev_replace) {
 + if (device-writeable 
 + device-devid != BTRFS_DEV_REPLACE_DEVID) {
   fs_devices-rw_devices++;
   list_add(device-dev_alloc_list,
fs_devices-alloc_list);
 

Reviewed-by: Stefan Behrens sbehr...@giantdisaster.de

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


[PATCH] Btrfs-progs: fix compile warning in is_ssd()

2013-09-04 Thread Wang Shilong
mkfs.c: In function ‘is_ssd’:
mkfs.c:1168:26: warning: ignoring return value of ‘blkid_devno_to_wholedisk’,
declared with attribute warn_unused_result [-Wunused-result]
  blkid_devno_to_wholedisk(devno, wholedisk, sizeof(wholedisk), NULL);

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 mkfs.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mkfs.c b/mkfs.c
index 6d340cb..bcaca43 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1209,6 +1209,7 @@ static int is_ssd(const char *file)
dev_t devno;
int fd;
char rotational;
+   int ret;
 
probe = blkid_new_probe_from_filename(file);
if (!probe)
@@ -1220,7 +1221,12 @@ static int is_ssd(const char *file)
return 0;
 
/* Get whole disk name (not full path) for this devno */
-   blkid_devno_to_wholedisk(devno, wholedisk, sizeof(wholedisk), NULL);
+   ret = blkid_devno_to_wholedisk(devno,
+   wholedisk, sizeof(wholedisk), NULL);
+   if (ret) {
+   blkid_free_probe(probe);
+   return 0;
+   }
 
snprintf(sysfs_path, PATH_MAX, /sys/block/%s/queue/rotational,
 wholedisk);
-- 
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] rwsem: add rwsem_is_contended

2013-09-04 Thread Peter Hurley

On 09/03/2013 09:18 AM, Josef Bacik wrote:

On Mon, Sep 02, 2013 at 01:18:08PM -0400, Peter Hurley wrote:

On 09/01/2013 04:32 AM, Michel Lespinasse wrote:

Hi Josef,

On Fri, Aug 30, 2013 at 7:14 AM, Josef Bacik jba...@fusionio.com wrote:

Btrfs uses an rwsem to control access to its extent tree.  Threads will hold a
read lock on this rwsem while they scan the extent tree, and if need_resched()
they will drop the lock and schedule.  The transaction commit needs to take a
write lock for this rwsem for a very short period to switch out the commit
roots.  If there are a lot of threads doing this caching operation we can starve
out the committers which slows everybody out.  To address this we want to add
this functionality to see if our rwsem has anybody waiting to take a write lock
so we can drop it and schedule for a bit to allow the commit to continue.
Thanks,

Signed-off-by: Josef Bacik jba...@fusionio.com


FYI, I once tried to introduce something like this before, but my use
case was pretty weak so it was not accepted at the time. I don't think
there were any objections to the API itself though, and I think it's
potentially a good idea if you use case justifies it.


Exactly, I'm concerned about the use case: readers can't starve writers.
Of course, lots of existing readers can temporarily prevent a writer from
acquiring, but those readers would already have the lock. Any new readers
wouldn't be able to prevent a waiting writer from obtaining the lock.

Josef,
Could you be more explicit, maybe with some detailed numbers about the
condition you report?



Sure, this came from a community member

http://article.gmane.org/gmane.comp.file-systems.btrfs/28081

With the old approach we could block between 1-2 seconds waiting for this rwsem,
and with the new approach where we allow many more of these caching threads we
were staving out the writer for 80 seconds.

So what happens is these threads will scan our extent tree to put together the
free space cache, and they'll hold this lock while they are doing the scanning.
The only way they will drop this lock is if we hit need_resched(), but because
these threads are going to do quite a bit of IO I imagine we're not ever being
flagged with need_resched() because we schedule while waiting for IO.  So these
threads will hold onto this lock for bloody ever without giving it up so the
committer can take the write lock.  His patch to fix the problem was to have
an atomic that let us know somebody was waiting for a write lock and then we'd
drop the reader lock and schedule.


Thanks for the additional clarification.


So really we're just using a rwsem in a really mean way for writers.  I'm open
to other suggestions but I think this probably the cleanest way.


Is there substantial saved state at the point where the caching thread is
checking need_resched() that precludes dropping and reacquiring the
extent_commit_sem (or before find_next_key())?  Not that it's a cleaner
solution; just want to understand better the situation.

Regards,
Peter Hurley
--
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


Btrfs prog

2013-09-04 Thread Giuseppe Fierro
I'm using btrfs on ubuntu 13.04 with btrfs prog v0.20-rc1
This is my configuration using 2 disks in raid1 mode:

 gspe@jura:/mnt$ sudo btrfs f show
 Label: 'UbuntuDSK'  uuid: f4a3c832-f6ab-4b1d-9eb7-f9ba7d1cba01
 Total devices 2 FS bytes used 205.41GB
 devid1 size 2.70TB used 214.03GB path /dev/sdb2
 devid2 size 2.70TB used 214.01GB path /dev/sda2
 Btrfs v0.20-rc1


Some btrfs command behave strange:
If i want to check free space using df, i get:

 gspe@jura:/mnt$ sudo btrfs filesystem df /
 Data, RAID1: total=212.00GB, used=204.42GB
 Data: total=8.00MB, used=0.00
 System, RAID1: total=8.00MB, used=36.00KB
 System: total=4.00MB, used=0.00
 Metadata, RAID1: total=2.00GB, used=1010.04MB
 Metadata: total=8.00MB, used=0.00


If I would like to show the subvolume, i get

 gspe@jura:/mnt$ sudo btrfs subvolume list /
 gspe@jura:/mnt$


nothing is shown!!!

So what's happen to the btrfs prog?

Thanks
Giuseppe Fierro
--
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] rwsem: add rwsem_is_contended

2013-09-04 Thread Josef Bacik
On Wed, Sep 04, 2013 at 07:46:56AM -0400, Peter Hurley wrote:
 On 09/03/2013 09:18 AM, Josef Bacik wrote:
 On Mon, Sep 02, 2013 at 01:18:08PM -0400, Peter Hurley wrote:
 On 09/01/2013 04:32 AM, Michel Lespinasse wrote:
 Hi Josef,
 
 On Fri, Aug 30, 2013 at 7:14 AM, Josef Bacik jba...@fusionio.com wrote:
 Btrfs uses an rwsem to control access to its extent tree.  Threads will 
 hold a
 read lock on this rwsem while they scan the extent tree, and if 
 need_resched()
 they will drop the lock and schedule.  The transaction commit needs to 
 take a
 write lock for this rwsem for a very short period to switch out the commit
 roots.  If there are a lot of threads doing this caching operation we can 
 starve
 out the committers which slows everybody out.  To address this we want to 
 add
 this functionality to see if our rwsem has anybody waiting to take a 
 write lock
 so we can drop it and schedule for a bit to allow the commit to continue.
 Thanks,
 
 Signed-off-by: Josef Bacik jba...@fusionio.com
 
 FYI, I once tried to introduce something like this before, but my use
 case was pretty weak so it was not accepted at the time. I don't think
 there were any objections to the API itself though, and I think it's
 potentially a good idea if you use case justifies it.
 
 Exactly, I'm concerned about the use case: readers can't starve writers.
 Of course, lots of existing readers can temporarily prevent a writer from
 acquiring, but those readers would already have the lock. Any new readers
 wouldn't be able to prevent a waiting writer from obtaining the lock.
 
 Josef,
 Could you be more explicit, maybe with some detailed numbers about the
 condition you report?
 
 
 Sure, this came from a community member
 
 http://article.gmane.org/gmane.comp.file-systems.btrfs/28081
 
 With the old approach we could block between 1-2 seconds waiting for this 
 rwsem,
 and with the new approach where we allow many more of these caching threads 
 we
 were staving out the writer for 80 seconds.
 
 So what happens is these threads will scan our extent tree to put together 
 the
 free space cache, and they'll hold this lock while they are doing the 
 scanning.
 The only way they will drop this lock is if we hit need_resched(), but 
 because
 these threads are going to do quite a bit of IO I imagine we're not ever 
 being
 flagged with need_resched() because we schedule while waiting for IO.  So 
 these
 threads will hold onto this lock for bloody ever without giving it up so the
 committer can take the write lock.  His patch to fix the problem was to 
 have
 an atomic that let us know somebody was waiting for a write lock and then 
 we'd
 drop the reader lock and schedule.
 
 Thanks for the additional clarification.
 
 So really we're just using a rwsem in a really mean way for writers.  I'm 
 open
 to other suggestions but I think this probably the cleanest way.
 
 Is there substantial saved state at the point where the caching thread is
 checking need_resched() that precludes dropping and reacquiring the
 extent_commit_sem (or before find_next_key())?  Not that it's a cleaner
 solution; just want to understand better the situation.


Yes I had thought of just dropping our locks everytime we had to do
find_next_key() but that isn't going to work.  We do have to save state but
that's not the hard part, it's the fact that we could race with the committing
transaction and lose space.  So what would happen is something like this

caching_thread:
save last cached offset
drop locks
find_next_key
get a ref on the current commit root
search down to the next leaf
re-take locks
process leaf

transaction committer:
acquire locks
swap commit root
write transaction
unpin all extents up to the last saved cached offset

So if the caching thread grabs a ref on the commit root before the transaction
committer swaps out the commit root we are dealing with too old of a tree.  So
say the leaf we're going to process next has data that was free'ed (and
therefore would have been unpinned) during that transaction, because it is after
our last cached offset we don't unpin it because we know that the caching thread
is going to find the leaf where that extent is not there and add free space for
that extent.  However we got the leaf from two transactions ago which will still
show that extent in use, so we won't add free space for it, which will cause us
to leak the extent.  We need to make sure we are always consistently on the
previous extent root which is why we hold this lock.

I hope that makes sense.  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] rwsem: add rwsem_is_contended

2013-09-04 Thread Peter Hurley

On 09/03/2013 11:47 AM, Josef Bacik wrote:

On Sun, Sep 01, 2013 at 01:32:36AM -0700, Michel Lespinasse wrote:

Hi Josef,

On Fri, Aug 30, 2013 at 7:14 AM, Josef Bacik jba...@fusionio.com wrote:

Btrfs uses an rwsem to control access to its extent tree.  Threads will hold a
read lock on this rwsem while they scan the extent tree, and if need_resched()
they will drop the lock and schedule.  The transaction commit needs to take a
write lock for this rwsem for a very short period to switch out the commit
roots.  If there are a lot of threads doing this caching operation we can starve
out the committers which slows everybody out.  To address this we want to add
this functionality to see if our rwsem has anybody waiting to take a write lock
so we can drop it and schedule for a bit to allow the commit to continue.
Thanks,

Signed-off-by: Josef Bacik jba...@fusionio.com


FYI, I once tried to introduce something like this before, but my use
case was pretty weak so it was not accepted at the time. I don't think
there were any objections to the API itself though, and I think it's
potentially a good idea if you use case justifies it.

Two comments:

- Note that there are two rwsem implementations - if you are going to
add functionality to rwsem.h you want to add the same functionality in
rwsem-spinlock.h as well.



Sure thing.


- I would prefer if you could avoid taking the wait_lock in your
rwsem.h implementation. In your use case (read lock is known to be
held), checking for sem-count  0 would be sufficient to indicate a
writer is queued (or getting onto the queue). In the general case,
some architectures have the various values set up so that
RWSEM_WAITING_BIAS != RWSEM_ACTIVE_WRITE_BIAS - for these
architectures at least, you can check for waiters by looking if the
lowest bit of RWSEM_WAITING_BIAS is set in sem-count.


Question about this one, I can't just do

if (sem-count  0)

since each arch has their own atomic way of looking at count, so I'd have to add
something to do just a normal read of count for each arch and call that wouldn't
I?


Reading sem-count is atomic.

For that matter, in your particular use case (which is more heuristic), you
could perform the list_empty() check without acquiring the wait_lock.

Regards,
Peter Hurley



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

2013-09-04 Thread Hugo Mills
On Wed, Sep 04, 2013 at 01:57:42PM +0200, Giuseppe Fierro wrote:
 I'm using btrfs on ubuntu 13.04 with btrfs prog v0.20-rc1
 This is my configuration using 2 disks in raid1 mode:
 
  gspe@jura:/mnt$ sudo btrfs f show
  Label: 'UbuntuDSK'  uuid: f4a3c832-f6ab-4b1d-9eb7-f9ba7d1cba01
  Total devices 2 FS bytes used 205.41GB
  devid1 size 2.70TB used 214.03GB path /dev/sdb2
  devid2 size 2.70TB used 214.01GB path /dev/sda2
  Btrfs v0.20-rc1
 
 
 Some btrfs command behave strange:
 If i want to check free space using df, i get:
 
  gspe@jura:/mnt$ sudo btrfs filesystem df /
  Data, RAID1: total=212.00GB, used=204.42GB
  Data: total=8.00MB, used=0.00
  System, RAID1: total=8.00MB, used=36.00KB
  System: total=4.00MB, used=0.00
  Metadata, RAID1: total=2.00GB, used=1010.04MB
  Metadata: total=8.00MB, used=0.00

   What do you think is wrong with this output? It looks OK to me:

   From the btrfs fi show at the top, you have 214 GB allocated on
each device. The btrfs fi df shows you how that allocation is used:
212 GB (*2, because it's RAID-1) is allocated to data, with 204 GB
holding useful data. The remaining 2 GB (*2) is allocated to metadata,
and 1 GB of that is actually used.

 If I would like to show the subvolume, i get
 
  gspe@jura:/mnt$ sudo btrfs subvolume list /
  gspe@jura:/mnt$

 nothing is shown!!!

   Try using the -a option. It got added a while ago, and has been a
complete pain in the neck ever since...

   Hugo.

-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 65E74AC0 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- The English language has the mot juste for every occasion. ---


signature.asc
Description: Digital signature


Re: Btrfs prog

2013-09-04 Thread Giuseppe Fierro
Thanks,
as I can see I misunderstood the meaning of btrfs filesystem df I
was expecting that the 'df' has been to display free space remaining.

The -a option works

Giuseppe Fierro

On 4 September 2013 15:32, Hugo Mills h...@carfax.org.uk wrote:
 On Wed, Sep 04, 2013 at 01:57:42PM +0200, Giuseppe Fierro wrote:
 I'm using btrfs on ubuntu 13.04 with btrfs prog v0.20-rc1
 This is my configuration using 2 disks in raid1 mode:

  gspe@jura:/mnt$ sudo btrfs f show
  Label: 'UbuntuDSK'  uuid: f4a3c832-f6ab-4b1d-9eb7-f9ba7d1cba01
  Total devices 2 FS bytes used 205.41GB
  devid1 size 2.70TB used 214.03GB path /dev/sdb2
  devid2 size 2.70TB used 214.01GB path /dev/sda2
  Btrfs v0.20-rc1


 Some btrfs command behave strange:
 If i want to check free space using df, i get:

  gspe@jura:/mnt$ sudo btrfs filesystem df /
  Data, RAID1: total=212.00GB, used=204.42GB
  Data: total=8.00MB, used=0.00
  System, RAID1: total=8.00MB, used=36.00KB
  System: total=4.00MB, used=0.00
  Metadata, RAID1: total=2.00GB, used=1010.04MB
  Metadata: total=8.00MB, used=0.00

What do you think is wrong with this output? It looks OK to me:

From the btrfs fi show at the top, you have 214 GB allocated on
 each device. The btrfs fi df shows you how that allocation is used:
 212 GB (*2, because it's RAID-1) is allocated to data, with 204 GB
 holding useful data. The remaining 2 GB (*2) is allocated to metadata,
 and 1 GB of that is actually used.

 If I would like to show the subvolume, i get

  gspe@jura:/mnt$ sudo btrfs subvolume list /
  gspe@jura:/mnt$

 nothing is shown!!!

Try using the -a option. It got added a while ago, and has been a
 complete pain in the neck ever since...

Hugo.

 --
 === Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
   PGP key: 65E74AC0 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
--- The English language has the mot juste for every occasion. ---



-- 
This email and any attachments to it may be confidential and are
intended solely for the use of the individual to whom it is addressed.
Any views or opinions expressed are solely those of the author and do
not necessarily represent those of fierro.org.

If you are not the intended recipient of this email, you must neither
take any action based upon its contents, nor copy or show it to
anyone.

Please contact the sender if you believe you have received this email in error.
--
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 prog

2013-09-04 Thread Chris Murphy

On Sep 4, 2013, at 3:32 PM, Hugo Mills h...@carfax.org.uk wrote:

 If I would like to show the subvolume, i get
 
 gspe@jura:/mnt$ sudo btrfs subvolume list /
 gspe@jura:/mnt$
 
 nothing is shown!!!
 
   Try using the -a option. It got added a while ago, and has been a
 complete pain in the neck ever since…

What does -a do?

I recall with older versions of btrfs-progs that if a subvolume was mounted, 
btrfs subvol list would only list subvolumes under the one that was mounted, 
not all subvolumes on the volume. I just tried this with 
btrfs-progs-0.20.rc1.20130501git7854c8b-4.fc20.x86_64 without -a option, but 
with a subvolume mounted and the command lists all subvolumes.

OK now I'm seeing the behavior is sometimes wrong.

[root@f19v ~]# btrfs subvolume create /mnt/cookies
Create subvolume '/mnt/cookies'
[root@f19v ~]# btrfs subvolume create /mnt/chips
Create subvolume '/mnt/chips'
[root@f19v ~]# btrfs subvolume create /mnt/nuts
Create subvolume '/mnt/nuts'
[root@f19v ~]# btrfs subvolume create /mnt/nuts/cashew
Create subvolume '/mnt/nuts/cashew'
[root@f19v ~]# btrfs subvolume create /mnt/nuts/cashew
ERROR: '/mnt/nuts/cashew' exists
[root@f19v ~]# btrfs subvolume create /mnt/nuts/cashew/small
Create subvolume '/mnt/nuts/cashew/small'
[root@f19v ~]# umount /mnt
[root@f19v ~]# mount -o subvol=nuts/cashew /dev/sdb /mnt
[root@f19v ~]# btrfs subvolume list /mnt
ID 256 gen 5 top level 5 path cookies
ID 258 gen 10 top level 5 path chips
ID 259 gen 12 top level 5 path nuts
ID 260 gen 13 top level 5 path nuts/cashew
ID 261 gen 13 top level 260 path small


The last one should be /nuts/cashew/small. Or the one before it should be 
cashew instead of nuts/cashew.


Chris Murphy


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

2013-09-04 Thread Wang Shilong
Hello Chris,
 
 On Sep 4, 2013, at 3:32 PM, Hugo Mills h...@carfax.org.uk wrote:
 
 If I would like to show the subvolume, i get
 
 gspe@jura:/mnt$ sudo btrfs subvolume list /
 gspe@jura:/mnt$
 
 nothing is shown!!!
 
  Try using the -a option. It got added a while ago, and has been a
 complete pain in the neck ever since…
 
 What does -a do?
 
 I recall with older versions of btrfs-progs that if a subvolume was mounted, 
 btrfs subvol list would only list subvolumes under the one that was mounted, 
 not all subvolumes on the volume. I just tried this with 
 btrfs-progs-0.20.rc1.20130501git7854c8b-4.fc20.x86_64 without -a option, but 
 with a subvolume mounted and the command lists all subvolumes.
 
 OK now I'm seeing the behavior is sometimes wrong.
 
 [root@f19v ~]# btrfs subvolume create /mnt/cookies
 Create subvolume '/mnt/cookies'
 [root@f19v ~]# btrfs subvolume create /mnt/chips
 Create subvolume '/mnt/chips'
 [root@f19v ~]# btrfs subvolume create /mnt/nuts
 Create subvolume '/mnt/nuts'
 [root@f19v ~]# btrfs subvolume create /mnt/nuts/cashew
 Create subvolume '/mnt/nuts/cashew'
 [root@f19v ~]# btrfs subvolume create /mnt/nuts/cashew
 ERROR: '/mnt/nuts/cashew' exists
 [root@f19v ~]# btrfs subvolume create /mnt/nuts/cashew/small
 Create subvolume '/mnt/nuts/cashew/small'
 [root@f19v ~]# umount /mnt
 [root@f19v ~]# mount -o subvol=nuts/cashew /dev/sdb /mnt
 [root@f19v ~]# btrfs subvolume list /mnt
 ID 256 gen 5 top level 5 path cookies
 ID 258 gen 10 top level 5 path chips
 ID 259 gen 12 top level 5 path nuts
 ID 260 gen 13 top level 5 path nuts/cashew
 ID 261 gen 13 top level 260 path small

I get the following output:
cookies
chips
nuts
nuts/cashew
nuts/cashew/small

Why small occurs in your test box?

Thanks,
wang

 
 
 The last one should be /nuts/cashew/small. Or the one before it should be 
 cashew instead of nuts/cashew.
 
 
 Chris Murphy
 
 
 --
 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: Btrfs prog

2013-09-04 Thread Chris Murphy

On Sep 4, 2013, at 3:51 PM, Giuseppe Fierro giuse...@fierro.org wrote:

 Thanks,
 as I can see I misunderstood the meaning of btrfs filesystem df I
 was expecting that the 'df' has been to display free space remaining.

Check the archives, this is a long running issue that no one has particularly 
great answers for because what free space remains depends on future (unknown) 
usage of the file system. But I still think it's a worse problem to not report 
anything at all in btrfs fi df, considering the historical point of df is to 
show space available. And it's also not good that the regular df shows e.g. for 
raid1, twice the free space as the amount of data that can be saved to the 
volume.

Chris Murphy--
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 04/20] Btrfs-progs: fix magic return value in cmds-dedup.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-dedup.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/cmds-dedup.c b/cmds-dedup.c
index eb43414..674952a 100644
--- a/cmds-dedup.c
+++ b/cmds-dedup.c
@@ -39,7 +39,7 @@ int dedup_ctl(int cmd, int argc, char **argv)
DIR *dirstream;
 
if (check_argc_exact(argc, 2))
-   return -1;
+   return -EINVAL;
 
fd = open_file_or_dir(path, dirstream);
if (fd  0) {
@@ -71,7 +71,7 @@ static int cmd_dedup_enable(int argc, char **argv)
int ret = dedup_ctl(BTRFS_DEDUP_CTL_REG, argc, argv);
if (ret  0)
usage(cmd_dedup_enable_usage);
-   return ret;
+   return !!ret;
 }
 
 static const char * const cmd_dedup_disable_usage[] = {
@@ -85,7 +85,7 @@ static int cmd_dedup_disable(int argc, char **argv)
int ret = dedup_ctl(BTRFS_DEDUP_CTL_UNREG, argc, argv);
if (ret  0)
usage(cmd_dedup_disable_usage);
-   return ret;
+   return !!ret;
 }
 
 const struct cmd_group dedup_cmd_group = {
-- 
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


[PATCH 00/20] fix magic return value in btrfs-progs

2013-09-04 Thread Wang Shilong
This patchset tries to fix all the magic return value in btrfs-progs.
Most commands will have three kinds of return value:

0 success
1 usage of syntax errors

Exceptions come from balance/scrub/replace. For example, replace cancel
will return 2 if there is no operations in progress.

Some tools including(btrfsck,chunk-recover) since they are still under
development. Also we should update man page if these magic return values
have been corrected.

Any comments are welcome.

Notice: this patchset is based on David integration-20130902

Wang Shilong (20):
  Btrfs-progs: return 1 rather than 129 in usage()
  Btrfs-progs: fix magic return value in cmds-subvolume.c
  Btrfs-progs: fix magic return value in cmds-chunk.c
  Btrfs-progs: fix magic return value in cmds-dedup.c
  Btrfs-progs: fix magic return value in cmds-device.c
  Btrfs-progs: fix magic return value in cmds-filesystem.c
  Btrfs-progs: fix magic return value in cmds-inspect.c
  Btrfs-progs: fix magic return value in cmds-qgroup.c
  Btrfs-progs: fix magic return value in cmds-quota.c
  Btrfs-progs: fix magic return value in cmds-receive.c
  Btrfs-progs: fix magic return value in cmds-restore.c
  Btrfs-progs: fix magic return value in cmds-send.c
  Btrfs-progs: fix magic return value in btrfs-imgae.c
  Btrfs-progs: fix magic return value in btrfs-zero-log.c
  Btrfs-progs: fix magic return value in send-test.c
  Btrfs-progs: fix magic return value in dir-test.c
  Btrfs-progs: fix magic return value in random-test.c
  Btrfs-progs: fix magic return value in cmds-balance.c
  Btrfs-progs: fix magic return value in cmds-replace.c
  Btrfs-progs: fix magic return value in cmds-scrub.c

 btrfs-image.c |  2 +-
 btrfs-zero-log.c  |  8 +++--
 cmds-balance.c| 93 ++-
 cmds-chunk.c  |  9 --
 cmds-dedup.c  |  6 ++--
 cmds-device.c | 24 ++
 cmds-filesystem.c | 28 -
 cmds-inspect.c| 10 +++---
 cmds-qgroup.c | 26 +++-
 cmds-quota.c  | 10 +++---
 cmds-receive.c|  4 +--
 cmds-replace.c| 16 ++
 cmds-restore.c| 18 +--
 cmds-scrub.c  | 20 ++--
 cmds-send.c   |  2 +-
 cmds-subvolume.c  | 45 ---
 dir-test.c| 16 +-
 help.c|  2 +-
 random-test.c | 18 +--
 send-test.c   |  2 +-
 20 files changed, 189 insertions(+), 170 deletions(-)

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


[PATCH 06/20] Btrfs-progs: fix magic return value in cmds-filesystem.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-filesystem.c | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index ca0855b..815d59a 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -62,12 +62,14 @@ static int cmd_df(int argc, char **argv)
fd = open_file_or_dir(path, dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access to '%s'\n, path);
-   return 12;
+   return 1;
}
 
sargs_orig = sargs = malloc(sizeof(struct btrfs_ioctl_space_args));
-   if (!sargs)
-   return -ENOMEM;
+   if (!sargs) {
+   ret = -ENOMEM;
+   goto out;
+   }
 
sargs-space_slots = 0;
sargs-total_spaces = 0;
@@ -157,7 +159,7 @@ out:
close_file_or_dir(fd, dirstream);
free(sargs);
 
-   return 0;
+   return !!ret;
 }
 
 static int uuid_search(struct btrfs_fs_devices *fs_devices, char *search)
@@ -248,7 +250,7 @@ static int cmd_show(int argc, char **argv)
 
if (ret){
fprintf(stderr, ERROR: error %d while scanning\n, ret);
-   return 18;
+   return 1;
}

if(searchstart  argc)
@@ -286,7 +288,7 @@ static int cmd_sync(int argc, char **argv)
fd = open_file_or_dir(path, dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access to '%s'\n, path);
-   return 12;
+   return 1;
}
 
printf(FSSync '%s'\n, path);
@@ -296,7 +298,7 @@ static int cmd_sync(int argc, char **argv)
if( res  0 ){
fprintf(stderr, ERROR: unable to fs-syncing '%s' - %s\n, 
path, strerror(e));
-   return 16;
+   return 1;
}
 
return 0;
@@ -429,12 +431,10 @@ static int cmd_defrag(int argc, char **argv)
}
if (verbose)
printf(%s\n, BTRFS_BUILD_VERSION);
-   if (errors) {
+   if (errors)
fprintf(stderr, total %d failures\n, errors);
-   exit(1);
-   }
 
-   return errors;
+   return !!errors;
 }
 
 static const char * const cmd_resize_usage[] = {
@@ -462,13 +462,13 @@ static int cmd_resize(int argc, char **argv)
if (len == 0 || len = BTRFS_VOL_NAME_MAX) {
fprintf(stderr, ERROR: size value too long ('%s)\n,
amount);
-   return 14;
+   return 1;
}
 
fd = open_file_or_dir(path, dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access to '%s'\n, path);
-   return 12;
+   return 1;
}
 
printf(Resize '%s' of '%s'\n, path, amount);
@@ -479,7 +479,7 @@ static int cmd_resize(int argc, char **argv)
if( res  0 ){
fprintf(stderr, ERROR: unable to resize '%s' - %s\n, 
path, strerror(e));
-   return 30;
+   return 1;
}
return 0;
 }
-- 
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


[PATCH 09/20] Btrfs-progs: fix magic return value in cmds-quota.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-quota.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/cmds-quota.c b/cmds-quota.c
index 94e3a5c..89cc89c 100644
--- a/cmds-quota.c
+++ b/cmds-quota.c
@@ -48,7 +48,7 @@ static int quota_ctl(int cmd, int argc, char **argv)
fd = open_file_or_dir(path, dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access '%s'\n, path);
-   return 12;
+   return 1;
}
 
ret = ioctl(fd, BTRFS_IOC_QUOTA_CTL, args);
@@ -57,7 +57,7 @@ static int quota_ctl(int cmd, int argc, char **argv)
if (ret  0) {
fprintf(stderr, ERROR: quota command failed: %s\n,
strerror(e));
-   return 30;
+   return 1;
}
return 0;
 }
@@ -132,7 +132,7 @@ static int cmd_quota_rescan(int argc, char **argv)
 
if (ioctlnum != BTRFS_IOC_QUOTA_RESCAN  wait_for_completion) {
fprintf(stderr, ERROR: -w cannot be used with -s\n);
-   return 12;
+   return 1;
}
 
if (check_argc_exact(argc - optind, 1))
@@ -144,7 +144,7 @@ static int cmd_quota_rescan(int argc, char **argv)
fd = open_file_or_dir(path, dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access '%s'\n, path);
-   return 12;
+   return 1;
}
 
ret = ioctl(fd, ioctlnum, args);
@@ -160,7 +160,7 @@ static int cmd_quota_rescan(int argc, char **argv)
if (ret  0) {
fprintf(stderr, ERROR: quota rescan failed: 
%s\n, strerror(e));
-   return 30;
+   return 1;
}  else {
printf(quota rescan started\n);
}
-- 
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


[PATCH 01/20] Btrfs-progs: return 1 rather than 129 in usage()

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

if usage or syntax error happens, we return 1.

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 help.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/help.c b/help.c
index d429a6b..09dc706 100644
--- a/help.c
+++ b/help.c
@@ -121,7 +121,7 @@ void usage_command(const struct cmd_struct *cmd, int full, 
int err)
 void usage(const char * const *usagestr)
 {
usage_command_usagestr(usagestr, NULL, 1, 1);
-   exit(129);
+   exit(1);
 }
 
 static void usage_command_group_internal(const struct cmd_group *grp, int full,
-- 
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


[PATCH 03/20] Btrfs-progs: fix magic return value in cmds-chunk.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-chunk.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/cmds-chunk.c b/cmds-chunk.c
index 54f0573..115db61 100644
--- a/cmds-chunk.c
+++ b/cmds-chunk.c
@@ -794,13 +794,15 @@ static int scan_devices(struct recover_control *rc)
int ret = 0;
int fd;
struct btrfs_device *dev;
+   int e;
 
list_for_each_entry(dev, rc-fs_devices-devices, dev_list) {
fd = open(dev-name, O_RDONLY);
if (fd  0) {
+   e = errno;
fprintf(stderr, Failed to open device %s\n,
dev-name);
-   return -1;
+   return -e;
}
ret = scan_one_device(rc, fd, dev);
close(fd);
@@ -1785,7 +1787,7 @@ int cmd_chunk_recover(int argc, char *argv[])
ret = check_mounted(file);
if (ret) {
fprintf(stderr, the device is busy\n);
-   return ret;
+   goto out;
}
 
ret = btrfs_recover_chunk_tree(file, verbose, yes);
@@ -1797,5 +1799,6 @@ int cmd_chunk_recover(int argc, char *argv[])
} else {
fprintf(stdout, Fail to recover the chunk tree.\n);
}
-   return ret;
+out:
+   return !!ret;
 }
-- 
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


[PATCH 10/20] Btrfs-progs: fix magic return value in cmds-receive.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-receive.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmds-receive.c b/cmds-receive.c
index 1630f64..2b880c0 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -951,13 +951,13 @@ int cmd_receive(int argc, char **argv)
receive_fd = open(fromfile, O_RDONLY | O_NOATIME);
if (receive_fd  0) {
fprintf(stderr, ERROR: failed to open %s\n, fromfile);
-   return -errno;
+   return 1;
}
}
 
ret = do_receive(r, tomnt, receive_fd);
 
-   return ret;
+   return !!ret;
 }
 
 const char * const cmd_receive_usage[] = {
-- 
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


[PATCH 08/20] Btrfs-progs: fix magic return value in cmds-qgroup.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-qgroup.c | 26 --
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 6fa4c17..ff2a1fa 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -54,12 +54,12 @@ static int qgroup_assign(int assign, int argc, char **argv)
 */
if ((args.src  48) = (args.dst  48)) {
fprintf(stderr, ERROR: bad relation requested '%s'\n, path);
-   return 12;
+   return 1;
}
fd = open_file_or_dir(path, dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access '%s'\n, path);
-   return 12;
+   return 1;
}
 
ret = ioctl(fd, BTRFS_IOC_QGROUP_ASSIGN, args);
@@ -68,7 +68,7 @@ static int qgroup_assign(int assign, int argc, char **argv)
if (ret  0) {
fprintf(stderr, ERROR: unable to assign quota group: %s\n,
strerror(e));
-   return 30;
+   return 1;
}
return 0;
 }
@@ -92,7 +92,7 @@ static int qgroup_create(int create, int argc, char **argv)
fd = open_file_or_dir(path, dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access '%s'\n, path);
-   return 12;
+   return 1;
}
 
ret = ioctl(fd, BTRFS_IOC_QGROUP_CREATE, args);
@@ -101,7 +101,7 @@ static int qgroup_create(int create, int argc, char **argv)
if (ret  0) {
fprintf(stderr, ERROR: unable to create quota group: %s\n,
strerror(e));
-   return 30;
+   return 1;
}
return 0;
 }
@@ -310,19 +310,17 @@ static int cmd_qgroup_show(int argc, char **argv)
fd = open_file_or_dir(path, dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access '%s'\n, path);
-   return 12;
+   return 1;
}
 
ret = list_qgroups(fd);
e = errno;
close_file_or_dir(fd, dirstream);
-   if (ret  0) {
+   if (ret  0)
fprintf(stderr, ERROR: can't list qgroups: %s\n,
strerror(e));
-   return 30;
-   }
 
-   return ret;
+   return !!ret;
 }
 
 static const char * const cmd_qgroup_limit_usage[] = {
@@ -392,12 +390,12 @@ static int cmd_qgroup_limit(int argc, char **argv)
ret = test_issubvolume(path);
if (ret  0) {
fprintf(stderr, ERROR: error accessing '%s'\n, path);
-   return 12;
+   return 1;
}
if (!ret) {
fprintf(stderr, ERROR: '%s' is not a subvolume\n,
path);
-   return 13;
+   return 1;
}
/*
 * keep qgroupid at 0, this indicates that the subvolume the
@@ -412,7 +410,7 @@ static int cmd_qgroup_limit(int argc, char **argv)
fd = open_file_or_dir(path, dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access '%s'\n, path);
-   return 12;
+   return 1;
}
 
ret = ioctl(fd, BTRFS_IOC_QGROUP_LIMIT, args);
@@ -421,7 +419,7 @@ static int cmd_qgroup_limit(int argc, char **argv)
if (ret  0) {
fprintf(stderr, ERROR: unable to limit requested quota group: 
%s\n, strerror(e));
-   return 30;
+   return 1;
}
return 0;
 }
-- 
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: Btrfs prog

2013-09-04 Thread Wang Shilong

在 2013-9-4,下午10:10,Chris Murphy li...@colorremedies.com 写道:

 
 On Sep 4, 2013, at 3:51 PM, Giuseppe Fierro giuse...@fierro.org wrote:
 
 Thanks,
 as I can see I misunderstood the meaning of btrfs filesystem df I
 was expecting that the 'df' has been to display free space remaining.
 
 Check the archives, this is a long running issue that no one has particularly 
 great answers for because what free space remains depends on future (unknown) 
 usage of the file system. But I still think it's a worse problem to not 
 report anything at all in btrfs fi df, considering the historical point of df 
 is to show space available. And it's also not good that the regular df shows 
 e.g. for raid1, twice the free space as the amount of data that can be saved 
 to the volume.
 
 Chris Murphy--
 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 12/20] Btrfs-progs: fix magic return value in cmds-send.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

If btrfs send return failure, we return 1,otherwise 0 will be returned.

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-send.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmds-send.c b/cmds-send.c
index f7f98bc..374d040 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -715,7 +715,7 @@ out:
close(send.mnt_fd);
free(send.root_path);
subvol_uuid_search_finit(send.sus);
-   return ret;
+   return !!ret;
 }
 
 const char * const cmd_send_usage[] = {
-- 
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


[PATCH 14/20] Btrfs-progs: fix magic return value in btrfs-zero-log.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 btrfs-zero-log.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/btrfs-zero-log.c b/btrfs-zero-log.c
index f249aec..31ec215 100644
--- a/btrfs-zero-log.c
+++ b/btrfs-zero-log.c
@@ -52,10 +52,11 @@ int main(int ac, char **av)
 
if((ret = check_mounted(av[1]))  0) {
fprintf(stderr, Could not check mount status: %s\n, 
strerror(-ret));
-   return ret;
+   goto out;
} else if(ret) {
fprintf(stderr, %s is currently mounted. Aborting.\n, av[1]);
-   return -EBUSY;
+   ret = -EBUSY;
+   goto out;
}
 
root = open_ctree(av[1], 0, 1);
@@ -68,5 +69,6 @@ int main(int ac, char **av)
btrfs_set_super_log_root_level(root-fs_info-super_copy, 0);
btrfs_commit_transaction(trans, root);
close_ctree(root);
-   return ret;
+out:
+   return !!ret;
 }
-- 
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


[PATCH 19/20] Btrfs-progs: fix magic return value in cmds-replace.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

There are 3 kinds of return values in replace cancel:

0: cancel successfully.
1: usage or syntal errors
2: cancel a not started or finished replacing operations.

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-replace.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/cmds-replace.c b/cmds-replace.c
index 1df719b..d9b0940 100644
--- a/cmds-replace.c
+++ b/cmds-replace.c
@@ -324,7 +324,7 @@ leave_with_error:
close(fdsrcdev);
if (fddstdev != -1)
close(fddstdev);
-   return -1;
+   return 1;
 }
 
 static const char *const cmd_status_replace_usage[] = {
@@ -367,12 +367,12 @@ static int cmd_status_replace(int argc, char **argv)
if (fd  0) {
fprintf(stderr, ERROR: can't access \%s\: %s\n,
path, strerror(e));
-   return -1;
+   return 1;
}
 
ret = print_replace_status(fd, path, once);
close_file_or_dir(fd, dirstream);
-   return ret;
+   return !!ret;
 }
 
 static int print_replace_status(int fd, const char *path, int once)
@@ -530,7 +530,7 @@ static int cmd_cancel_replace(int argc, char **argv)
if (fd  0) {
fprintf(stderr, ERROR: can't access \%s\: %s\n,
path, strerror(errno));
-   return -1;
+   return 1;
}
 
args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL;
@@ -541,9 +541,13 @@ static int cmd_cancel_replace(int argc, char **argv)
fprintf(stderr, ERROR: ioctl(DEV_REPLACE_CANCEL) failed on 
\%s\: %s, %s\n,
path, strerror(e),
replace_dev_result2string(args.result));
-   return ret;
+   return 1;
+   }
+   if (args.result == BTRFS_IOCTL_DEV_REPLACE_RESULT_NOT_STARTED) {
+   printf(INFO: ioctl(DEV_REPLACE_CANCEL)\%s\: %s\n,
+   path, replace_dev_result2string(args.result));
+   return 2;
}
-
return 0;
 }
 
-- 
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


[PATCH 13/20] Btrfs-progs: fix magic return value in btrfs-imgae.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 btrfs-image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/btrfs-image.c b/btrfs-image.c
index 3ea3730..ab229f3 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -2588,5 +2588,5 @@ out:
else
fclose(out);
 
-   return ret;
+   return !!ret;
 }
-- 
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


[PATCH 15/20] Btrfs-progs: fix magic return value in send-test.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 send-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/send-test.c b/send-test.c
index cb1f57d..3775f5f 100644
--- a/send-test.c
+++ b/send-test.c
@@ -454,5 +454,5 @@ int main(int argc, char **argv)
 
pthread_attr_destroy(t_attr);
 out:
-   return ret;
+   return !!ret;
 }
-- 
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


[PATCH 16/20] Btrfs-progs: fix magic return value in dir-test.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 dir-test.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/dir-test.c b/dir-test.c
index d95219a..a54b777 100644
--- a/dir-test.c
+++ b/dir-test.c
@@ -140,7 +140,7 @@ fatal_release:
btrfs_release_path(path);
 fatal:
printf(failed to insert %lu ret %d\n, oid, ret);
-   return -1;
+   return ret;
 }
 
 static int insert_dup(struct btrfs_trans_handle *trans, struct btrfs_root
@@ -213,7 +213,7 @@ out_release:
btrfs_release_path(path);
 out:
printf(failed to delete %lu %d\n, radix_index, ret);
-   return -1;
+   return ret;
 }
 
 static int del_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
@@ -241,7 +241,7 @@ static int del_one(struct btrfs_trans_handle *trans, struct 
btrfs_root *root,
 out_release:
btrfs_release_path(path);
printf(failed to delete %lu %d\n, oid, ret);
-   return -1;
+   return ret;
 }
 
 static int lookup_item(struct btrfs_trans_handle *trans, struct btrfs_root
@@ -269,7 +269,7 @@ static int lookup_item(struct btrfs_trans_handle *trans, 
struct btrfs_root
btrfs_release_path(path);
if (ret) {
printf(unable to find key %lu\n, oid);
-   return -1;
+   return ret;
}
return 0;
 }
@@ -292,7 +292,7 @@ static int lookup_enoent(struct btrfs_trans_handle *trans, 
struct btrfs_root
btrfs_release_path(path);
if (!ret) {
printf(able to find key that should not exist %lu\n, oid);
-   return -1;
+   return ret;
}
return 0;
 }
@@ -342,14 +342,14 @@ static int empty_tree(struct btrfs_trans_handle *trans, 
struct btrfs_root
fprintf(stderr,
failed to remove %lu from tree\n,
found);
-   return -1;
+   return ret;
}
if (!keep_running)
break;
}
return 0;
fprintf(stderr, failed to delete from the radix %lu\n, found);
-   return -1;
+   return ret;
 }
 
 static int fill_tree(struct btrfs_trans_handle *trans, struct btrfs_root *root,
@@ -512,6 +512,6 @@ int main(int ac, char **av)
}
 out:
close_ctree(root, super);
-   return err;
+   return !!err;
 }
 
-- 
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


[PATCH 17/20] Btrfs-progs: fix magic return value in random-test.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 random-test.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/random-test.c b/random-test.c
index 2f44593..b7c6cdb 100644
--- a/random-test.c
+++ b/random-test.c
@@ -43,7 +43,7 @@ again:
ret = radix_tree_gang_lookup(root, (void **)res, num, 2);
if (exists) {
if (ret == 0)
-   return -1;
+   return -EEXIST;
num = res[0];
} else if (ret != 0  num == res[0]) {
num++;
@@ -79,7 +79,7 @@ static int ins_one(struct btrfs_trans_handle *trans, struct 
btrfs_root *root,
return ret;
 error:
printf(failed to insert %llu\n, (unsigned long long)key.objectid);
-   return -1;
+   return ret;
 }
 
 static int insert_dup(struct btrfs_trans_handle *trans, struct btrfs_root
@@ -98,7 +98,7 @@ static int insert_dup(struct btrfs_trans_handle *trans, 
struct btrfs_root
if (ret != -EEXIST) {
printf(insert on %llu gave us %d\n,
   (unsigned long long)key.objectid, ret);
-   return 1;
+   return ret;
}
return 0;
 }
@@ -127,7 +127,7 @@ static int del_one(struct btrfs_trans_handle *trans, struct 
btrfs_root *root,
return 0;
 error:
printf(failed to delete %llu\n, (unsigned long long)key.objectid);
-   return -1;
+   return ret;
 }
 
 static int lookup_item(struct btrfs_trans_handle *trans, struct btrfs_root
@@ -147,7 +147,7 @@ static int lookup_item(struct btrfs_trans_handle *trans, 
struct btrfs_root
return 0;
 error:
printf(unable to find key %llu\n, (unsigned long long)key.objectid);
-   return -1;
+   return ret;
 }
 
 static int lookup_enoent(struct btrfs_trans_handle *trans, struct btrfs_root
@@ -168,7 +168,7 @@ static int lookup_enoent(struct btrfs_trans_handle *trans, 
struct btrfs_root
 error:
printf(able to find key that should not exist %llu\n,
   (unsigned long long)key.objectid);
-   return -1;
+   return -EEXIST;
 }
 
 static int empty_tree(struct btrfs_trans_handle *trans, struct btrfs_root
@@ -209,7 +209,7 @@ static int empty_tree(struct btrfs_trans_handle *trans, 
struct btrfs_root
fprintf(stderr,
failed to remove %lu from tree\n,
found);
-   return -1;
+   return ret;
}
btrfs_release_path(path);
ptr = radix_tree_delete(radix, found);
@@ -221,7 +221,7 @@ static int empty_tree(struct btrfs_trans_handle *trans, 
struct btrfs_root
return 0;
 error:
fprintf(stderr, failed to delete from the radix %lu\n, found);
-   return -1;
+   return -ENOENT;
 }
 
 static int fill_tree(struct btrfs_trans_handle *trans, struct btrfs_root *root,
@@ -428,6 +428,6 @@ int main(int ac, char **av)
}
 out:
close_ctree(root, super);
-   return err;
+   return !!err;
 }
 
-- 
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


[PATCH 18/20] Btrfs-progs: fix magic return value in cmds-balance.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

If there is no balance in progress.resume/pause/cancel will
return 2. For usage or syntal errors will return 1. 0 means
operations return successfully.

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-balance.c | 93 --
 1 file changed, 58 insertions(+), 35 deletions(-)

diff --git a/cmds-balance.c b/cmds-balance.c
index b7382ef..fd68051 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -58,7 +58,7 @@ static int parse_one_profile(const char *profile, u64 *flags)
*flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
} else {
fprintf(stderr, Unknown profile '%s'\n, profile);
-   return 1;
+   return -ENOENT;
}
 
return 0;
@@ -68,12 +68,14 @@ static int parse_profiles(char *profiles, u64 *flags)
 {
char *this_char;
char *save_ptr = NULL; /* Satisfy static checkers */
+   int ret;
 
for (this_char = strtok_r(profiles, |, save_ptr);
 this_char != NULL;
 this_char = strtok_r(NULL, |, save_ptr)) {
-   if (parse_one_profile(this_char, flags))
-   return 1;
+   ret = parse_one_profile(this_char, flags);
+   if (ret)
+   return ret;
}
 
return 0;
@@ -86,7 +88,7 @@ static int parse_u64(const char *str, u64 *result)
 
val = strtoull(str, endptr, 10);
if (*endptr)
-   return 1;
+   return -EINVAL;
 
*result = val;
return 0;
@@ -95,6 +97,7 @@ static int parse_u64(const char *str, u64 *result)
 static int parse_range(const char *range, u64 *start, u64 *end)
 {
char *dots;
+   int ret;
 
dots = strstr(range, ..);
if (dots) {
@@ -107,29 +110,31 @@ static int parse_range(const char *range, u64 *start, u64 
*end)
*end = (u64)-1;
skipped++;
} else {
-   if (parse_u64(rest, end))
-   return 1;
+   ret = parse_u64(rest, end);
+   if (ret)
+   return ret;
}
if (dots == range) {
*start = 0;
skipped++;
} else {
+   ret = parse_u64(rest, end);
if (parse_u64(range, start))
-   return 1;
+   return ret;
}
 
if (*start = *end) {
fprintf(stderr, Range %llu..%llu doesn't make 
sense\n, (unsigned long long)*start,
(unsigned long long)*end);
-   return 1;
+   return -EINVAL;
}
 
if (skipped = 1)
return 0;
}
 
-   return 1;
+   return -EINVAL;
 }
 
 static int parse_filters(char *filters, struct btrfs_balance_args *args)
@@ -137,6 +142,7 @@ static int parse_filters(char *filters, struct 
btrfs_balance_args *args)
char *this_char;
char *value;
char *save_ptr = NULL; /* Satisfy static checkers */
+   int ret = 0;
 
if (!filters)
return 0;
@@ -150,70 +156,72 @@ static int parse_filters(char *filters, struct 
btrfs_balance_args *args)
if (!value || !*value) {
fprintf(stderr, the profiles filter requires 
   an argument\n);
-   return 1;
+   return -EINVAL;
}
if (parse_profiles(value, args-profiles)) {
fprintf(stderr, Invalid profiles argument\n);
-   return 1;
+   return -EINVAL;
}
args-flags |= BTRFS_BALANCE_ARGS_PROFILES;
} else if (!strcmp(this_char, usage)) {
if (!value || !*value) {
fprintf(stderr, the usage filter requires 
   an argument\n);
-   return 1;
+   return -EINVAL;
}
if (parse_u64(value, args-usage) ||
args-usage  100) {
fprintf(stderr, Invalid usage argument: %s\n,
   value);
-   return 1;
+   return -EINVAL;
}
args-flags |= BTRFS_BALANCE_ARGS_USAGE;
} else if (!strcmp(this_char, devid)) {
if (!value 

[PATCH 20/20] Btrfs-progs: fix magic return value in cmds-scrub.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

There will be four kinds of return value for command scrub start:

0: scrub dosen't find errors and return success.
1: usage or syntax errors.
3: scrub finds errors and correct all of them.
4: scrub finds errors and some of them are not correctable.

Three kinds of return values for scrub cancel/resume:

0: cancel successfully.
1: usage or syntax errors.
2: cancel a not started or finished scrub.

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-scrub.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/cmds-scrub.c b/cmds-scrub.c
index 55da405..605af45 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -1018,7 +1018,7 @@ static int mkdir_p(char *path)
path[i] = '\0';
ret = mkdir(path, 0777);
if (ret  errno != EEXIST)
-   return 1;
+   return -errno;
path[i] = '/';
}
 
@@ -1155,7 +1155,7 @@ static int scrub_start(int argc, char **argv, int resume)
 
if (fdmnt  0) {
ERR(!do_quiet, ERROR: can't access '%s'\n, path);
-   return 12;
+   return 1;
}
 
ret = get_fs_info(path, fi_args, di_args);
@@ -1261,8 +1261,7 @@ static int scrub_start(int argc, char **argv, int resume)
if (!do_quiet)
printf(scrub: nothing to resume for %s, fsid %s\n,
   path, fsid);
-   err = 0;
-   goto out;
+   return 2;
}
 
ret = prg_fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -1501,9 +1500,9 @@ out:
if (err)
return 1;
if (e_correctable)
-   return 7;
+   return 3;
if (e_uncorrectable)
-   return 8;
+   return 4;
return 0;
 }
 
@@ -1557,7 +1556,10 @@ static int cmd_scrub_cancel(int argc, char **argv)
if (ret  0) {
fprintf(stderr, ERROR: scrub cancel failed on %s: %s\n, path,
errno == ENOTCONN ? not running : strerror(errno));
-   ret = 1;
+   if (errno == ENOTCONN)
+   ret = 2;
+   else
+   ret = 1;
goto out;
}
 
@@ -1642,7 +1644,7 @@ static int cmd_scrub_status(int argc, char **argv)
 
if (fdmnt  0) {
fprintf(stderr, ERROR: can't access to '%s'\n, path);
-   return 12;
+   return 1;
}
 
ret = get_fs_info(path, fi_args, di_args);
@@ -1727,7 +1729,7 @@ out:
close(fdres);
close_file_or_dir(fdmnt, dirstream);
 
-   return err;
+   return !!err;
 }
 
 const struct cmd_group scrub_cmd_group = {
-- 
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


[PATCH 07/20] Btrfs-progs: fix magic return value in cmds-inspect.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-inspect.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/cmds-inspect.c b/cmds-inspect.c
index 9101470..bdebf7d 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -44,7 +44,7 @@ static int __ino_to_path_fd(u64 inum, int fd, int verbose, 
const char *prepend)
 
fspath = malloc(4096);
if (!fspath)
-   return 1;
+   return -ENOMEM;
 
memset(fspath, 0, sizeof(*fspath));
ipa.inum = inum;
@@ -78,7 +78,7 @@ static int __ino_to_path_fd(u64 inum, int fd, int verbose, 
const char *prepend)
 
 out:
free(fspath);
-   return ret;
+   return !!ret;
 }
 
 static const char * const cmd_inode_resolve_usage[] = {
@@ -117,13 +117,13 @@ static int cmd_inode_resolve(int argc, char **argv)
fd = open_file_or_dir(argv[optind+1], dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access '%s'\n, argv[optind+1]);
-   return 12;
+   return 1;
}
 
ret = __ino_to_path_fd(atoll(argv[optind]), fd, verbose,
   argv[optind+1]);
close_file_or_dir(fd, dirstream);
-   return ret;
+   return !!ret;
 
 }
 
@@ -256,7 +256,7 @@ static int cmd_logical_resolve(int argc, char **argv)
 out:
close_file_or_dir(fd, dirstream);
free(inodes);
-   return ret;
+   return !!ret;
 }
 
 static const char * const cmd_subvolid_resolve_usage[] = {
-- 
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


[PATCH 05/20] Btrfs-progs: fix magic return value in cmds-device.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-device.c | 24 +---
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/cmds-device.c b/cmds-device.c
index 7524d08..800a050 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -55,7 +55,7 @@ static int cmd_add_dev(int argc, char **argv)
fdmnt = open_file_or_dir(mntpnt, dirstream);
if (fdmnt  0) {
fprintf(stderr, ERROR: can't access to '%s'\n, mntpnt);
-   return 12;
+   return 1;
}
 
for (i = 1; i  argc - 1; i++ ){
@@ -120,10 +120,7 @@ static int cmd_add_dev(int argc, char **argv)
}
 
close_file_or_dir(fdmnt, dirstream);
-   if (ret)
-   return ret+20;
-   else
-   return 0;
+   return !!ret;
 }
 
 static const char * const cmd_rm_dev_usage[] = {
@@ -146,7 +143,7 @@ static int cmd_rm_dev(int argc, char **argv)
fdmnt = open_file_or_dir(mntpnt, dirstream);
if (fdmnt  0) {
fprintf(stderr, ERROR: can't access to '%s'\n, mntpnt);
-   return 12;
+   return 1;
}
 
for(i=1 ; i  argc - 1; i++ ){
@@ -170,10 +167,7 @@ static int cmd_rm_dev(int argc, char **argv)
}
 
close_file_or_dir(fdmnt, dirstream);
-   if( ret)
-   return ret+20;
-   else
-   return 0;
+   return !!ret;
 }
 
 static const char * const cmd_scan_dev_usage[] = {
@@ -202,7 +196,7 @@ static int cmd_scan_dev(int argc, char **argv)
ret = scan_for_btrfs(where, 1);
if (ret){
fprintf(stderr, ERROR: error %d while scanning\n, 
ret);
-   return 18;
+   return 1;
}
return 0;
}
@@ -210,7 +204,7 @@ static int cmd_scan_dev(int argc, char **argv)
fd = open(/dev/btrfs-control, O_RDWR);
if (fd  0) {
perror(failed to open /dev/btrfs-control);
-   return 10;
+   return 1;
}
 
for( i = devstart ; i  argc ; i++ ){
@@ -232,7 +226,7 @@ static int cmd_scan_dev(int argc, char **argv)
close(fd);
fprintf(stderr, ERROR: unable to scan the device '%s' 
- %s\n,
argv[i], strerror(e));
-   return 11;
+   return 1;
}
}
 
@@ -258,7 +252,7 @@ static int cmd_ready_dev(int argc, char **argv)
fd = open(/dev/btrfs-control, O_RDWR);
if (fd  0) {
perror(failed to open /dev/btrfs-control);
-   return 10;
+   return 1;
}
 
strncpy(args.name, argv[argc - 1], BTRFS_PATH_NAME_MAX);
@@ -320,7 +314,7 @@ static int cmd_dev_stats(int argc, char **argv)
 
if (fdmnt  0) {
fprintf(stderr, ERROR: can't access '%s'\n, dev_path);
-   return 12;
+   return 1;
}
 
ret = get_fs_info(dev_path, fi_args, di_args);
-- 
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


[PATCH 02/20] Btrfs-progs: fix magic return value in cmds-subvolume.c

2013-09-04 Thread Wang Shilong
From: Wang Shilong wangsl.f...@cn.fujitsu.com

The patch also fixes some coding styles problems.

Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
---
 cmds-subvolume.c | 45 +++--
 1 file changed, 19 insertions(+), 26 deletions(-)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index e1fa81a..2c62492 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -218,14 +218,14 @@ again:
path = argv[cnt];
 
res = test_issubvolume(path);
-   if(res0){
+   if (res  0) {
fprintf(stderr, ERROR: error accessing '%s'\n, path);
-   ret = 12;
+   ret = 1;
goto out;
}
-   if(!res){
+   if (!res) {
fprintf(stderr, ERROR: '%s' is not a subvolume\n, path);
-   ret = 13;
+   ret = 1;
goto out;
}
 
@@ -236,11 +236,11 @@ again:
vname = basename(vname);
free(cpath);
 
-   if( !strcmp(vname,.) || !strcmp(vname,..) ||
-strchr(vname, '/') ){
+   if (!strcmp(vname, .) || !strcmp(vname, ..) ||
+strchr(vname, '/')) {
fprintf(stderr, ERROR: incorrect subvolume name ('%s')\n,
vname);
-   ret = 14;
+   ret = 1;
goto out;
}
 
@@ -248,14 +248,14 @@ again:
if (len == 0 || len = BTRFS_VOL_NAME_MAX) {
fprintf(stderr, ERROR: snapshot name too long ('%s)\n,
vname);
-   ret = 14;
+   ret = 1;
goto out;
}
 
fd = open_file_or_dir(dname, dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access to '%s'\n, dname);
-   ret = 12;
+   ret = 1;
goto out;
}
 
@@ -269,7 +269,7 @@ again:
if(res  0 ){
fprintf( stderr, ERROR: cannot delete '%s/%s' - %s\n,
dname, vname, strerror(e));
-   ret = 11;
+   ret = 1;
goto out;
}
 
@@ -471,8 +471,7 @@ out:
btrfs_list_free_comparer_set(comparer_set);
if (uerr)
usage(cmd_subvol_list_usage);
-
-   return ret;
+   return !!ret;
 }
 
 static const char * const cmd_snapshot_usage[] = {
@@ -694,9 +693,7 @@ static int cmd_subvol_get_default(int argc, char **argv)
btrfs_list_free_filter_set(filter_set);
 out:
close_file_or_dir(fd, dirstream);
-   if (ret)
-   return 1;
-   return 0;
+   return !!ret;
 }
 
 static const char * const cmd_subvol_set_default_usage[] = {
@@ -765,23 +762,21 @@ static int cmd_find_new(int argc, char **argv)
ret = test_issubvolume(subvol);
if (ret  0) {
fprintf(stderr, ERROR: error accessing '%s'\n, subvol);
-   return 12;
+   return 1;
}
if (!ret) {
fprintf(stderr, ERROR: '%s' is not a subvolume\n, subvol);
-   return 13;
+   return 1;
}
 
fd = open_file_or_dir(subvol, dirstream);
if (fd  0) {
fprintf(stderr, ERROR: can't access '%s'\n, subvol);
-   return 12;
+   return 1;
}
ret = btrfs_list_find_updated_files(fd, 0, last_gen);
close_file_or_dir(fd, dirstream);
-   if (ret)
-   return 19;
-   return 0;
+   return !!ret;
 }
 
 static const char * const cmd_subvol_show_usage[] = {
@@ -800,7 +795,7 @@ static int cmd_subvol_show(int argc, char **argv)
char raw_prefix[] = \t\t\t\t;
u64 sv_id, mntid;
int fd = -1, mntfd = -1;
-   int ret = -1;
+   int ret = 1;
DIR *dirstream1 = NULL, *dirstream2 = NULL;
 
if (check_argc_exact(argc, 2))
@@ -820,7 +815,6 @@ static int cmd_subvol_show(int argc, char **argv)
}
if (!ret) {
fprintf(stderr, ERROR: '%s' is not a subvolume\n, fullpath);
-   ret = -1;
goto out;
}
 
@@ -830,7 +824,7 @@ static int cmd_subvol_show(int argc, char **argv)
%s\n, fullpath, strerror(-ret));
goto out;
}
-   ret = -1;
+   ret = 1;
svpath = get_subvol_name(mnt, fullpath);
 
fd = open_file_or_dir(fullpath, dirstream1);
@@ -935,8 +929,7 @@ out:
free(mnt);
if (fullpath)
free(fullpath);
-
-   return ret;
+   return !!ret;
 }
 
 const struct cmd_group subvolume_cmd_group = {
-- 
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 18/20] Btrfs-progs: fix magic return value in cmds-balance.c

2013-09-04 Thread Ilya Dryomov
Hi Wang,

Thank you for doing the grunt work, it's been a long standing todo.
See the comments below.

On Wed, Sep 4, 2013 at 6:22 PM, Wang Shilong wangshilong1...@gmail.com wrote:
 From: Wang Shilong wangsl.f...@cn.fujitsu.com

 If there is no balance in progress.resume/pause/cancel will
 return 2. For usage or syntal errors will return 1. 0 means
 operations return successfully.

This needs to be reworded (spelling, punctuation).


 Signed-off-by: Wang Shilong wangsl.f...@cn.fujitsu.com
 ---
  cmds-balance.c | 93 
 --
  1 file changed, 58 insertions(+), 35 deletions(-)

 diff --git a/cmds-balance.c b/cmds-balance.c
 index b7382ef..fd68051 100644
 --- a/cmds-balance.c
 +++ b/cmds-balance.c
 @@ -58,7 +58,7 @@ static int parse_one_profile(const char *profile, u64 
 *flags)
 *flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
 } else {
 fprintf(stderr, Unknown profile '%s'\n, profile);
 -   return 1;
 +   return -ENOENT;
 }

 return 0;
 @@ -68,12 +68,14 @@ static int parse_profiles(char *profiles, u64 *flags)
  {
 char *this_char;
 char *save_ptr = NULL; /* Satisfy static checkers */
 +   int ret;

 for (this_char = strtok_r(profiles, |, save_ptr);
  this_char != NULL;
  this_char = strtok_r(NULL, |, save_ptr)) {
 -   if (parse_one_profile(this_char, flags))
 -   return 1;
 +   ret = parse_one_profile(this_char, flags);
 +   if (ret)
 +   return ret;
 }

 return 0;
 @@ -86,7 +88,7 @@ static int parse_u64(const char *str, u64 *result)

 val = strtoull(str, endptr, 10);
 if (*endptr)
 -   return 1;
 +   return -EINVAL;

 *result = val;
 return 0;
 @@ -95,6 +97,7 @@ static int parse_u64(const char *str, u64 *result)
  static int parse_range(const char *range, u64 *start, u64 *end)
  {
 char *dots;
 +   int ret;

 dots = strstr(range, ..);
 if (dots) {
 @@ -107,29 +110,31 @@ static int parse_range(const char *range, u64 *start, 
 u64 *end)
 *end = (u64)-1;
 skipped++;
 } else {
 -   if (parse_u64(rest, end))
 -   return 1;
 +   ret = parse_u64(rest, end);
 +   if (ret)
 +   return ret;
 }
 if (dots == range) {
 *start = 0;
 skipped++;
 } else {
 +   ret = parse_u64(rest, end);
 if (parse_u64(range, start))
 -   return 1;
 +   return ret;
 }

 if (*start = *end) {
 fprintf(stderr, Range %llu..%llu doesn't make 
 sense\n, (unsigned long long)*start,
 (unsigned long long)*end);
 -   return 1;
 +   return -EINVAL;
 }

 if (skipped = 1)
 return 0;
 }

 -   return 1;
 +   return -EINVAL;
  }

  static int parse_filters(char *filters, struct btrfs_balance_args *args)
 @@ -137,6 +142,7 @@ static int parse_filters(char *filters, struct 
 btrfs_balance_args *args)
 char *this_char;
 char *value;
 char *save_ptr = NULL; /* Satisfy static checkers */
 +   int ret = 0;

 if (!filters)
 return 0;
 @@ -150,70 +156,72 @@ static int parse_filters(char *filters, struct 
 btrfs_balance_args *args)
 if (!value || !*value) {
 fprintf(stderr, the profiles filter requires 
 
an argument\n);
 -   return 1;
 +   return -EINVAL;
 }
 if (parse_profiles(value, args-profiles)) {
 fprintf(stderr, Invalid profiles 
 argument\n);
 -   return 1;
 +   return -EINVAL;
 }
 args-flags |= BTRFS_BALANCE_ARGS_PROFILES;
 } else if (!strcmp(this_char, usage)) {
 if (!value || !*value) {
 fprintf(stderr, the usage filter requires 
an argument\n);
 -   return 1;
 +   return -EINVAL;
 }
 if (parse_u64(value, args-usage) ||
 args-usage  100) {
 fprintf(stderr, 

Newer kernels do not oops if log cannot be re-read at mount

2013-09-04 Thread Marc MERLIN
I just wanted to confirm that the crash on unexpected log read during mount
is indeed fixed for me, I now just get a log read failed message.

I've filed a bug with debian to encourage them to add btrfs-zero-log as a
tool in the initrd so that one can have the choice of running this on a non
mounting root filesystem.

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=721857

Thanks for having fixed this.

In case someone is wondering why I'm still sticking with my SSD :) I'm holding
off just a bit longer for the next generation of SSDs coming out now so that
I can switch away from that questionable line of OCZ Vertex 4 (I tried 4,
they all have this problem of not writing everything correctly when they
hang, which fortunately is rarely).

Marc
-- 
A mouse is a device used to point at the xterm you want to type in - A.S.R.
Microsoft is to operating systems 
   what McDonalds is to gourmet cooking
Home page: http://marc.merlins.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] xfstests: fix device lookup in btrfs/003

2013-09-04 Thread Dave Chinner
Add x...@oss.sgi.com to the cc list.

On Tue, Sep 03, 2013 at 06:19:01PM -0400, Jeff Mahoney wrote:
 The DEVHTL lookup in btrfs/003 is broken. It can only handle full LUNs and
 not partitions on a disk.
 
 Rather than returning 2:0:0:0 for /dev/sdc7, it returns 'block' and we see:
 ./common/rc: line 2081: /sys/class/scsi_device/block/device/delete:
 No such file or directory
 
 If we look up the device by dev instead of by name, we can handle working
 with full disks and partitions more easily and get the ability to use
 any device name rather than just the ones that match sysfs.
 
 Signed-off-by: Jeff Mahoney je...@suse.com
 ---
  tests/btrfs/003 |   18 +++---
  1 file changed, 15 insertions(+), 3 deletions(-)
 
 --- a/tests/btrfs/003
 +++ b/tests/btrfs/003
 @@ -137,9 +137,21 @@ _test_replace()
   #pick the 2nd last disk 
   ds=${devs[@]:$(($n-1)):1}
  
 - # retrive the HTL for this scsi disk
 - d=`echo $ds|cut -d/ -f3`
 - DEVHTL=`ls -l /sys/class/block/${d} | rev | cut -d / -f 3 | rev`
 + HEXMAJOR=$(stat -c %t $ds)
 + HEXMINOR=$(stat -c %T $ds)
 + if [ -z $HEXMAJOR -o -z $HEXMINOR ]; then
 + _fail tr: HEXMAJOR and/or HEXMINOR is unset for $ds
 + fi
 +
 + DIR=/sys/dev/block/$(( 0x$HEXMAJOR )):$(( 0x$HEXMINOR ))
 +
 + if [ -L $DIR/device ]; then # whole disk
 + DEVHTL=$(basename $(readlink $DIR/device))
 + elif [ -L $DIR/../device ]; then # partition
 + DEVHTL=$(basename $(readlink $DIR/../device))
 + else
 + _fail tr: Can't locate device backing $ds
 + fi
  
   #fail disk
   _devmgt_remove ${DEVHTL}
 
 --
 Jeff Mahoney
 SUSE Labs
 --
 To unsubscribe from this list: send the line unsubscribe linux-fsdevel in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 

-- 
Dave Chinner
da...@fromorbit.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 00/20] fix magic return value in btrfs-progs

2013-09-04 Thread Anand Jain


On 09/04/2013 11:22 PM, Wang Shilong wrote:

This patchset tries to fix all the magic return value in btrfs-progs.
Most commands will have three kinds of return value:

0 success
1 usage of syntax errors

Exceptions come from balance/scrub/replace. For example, replace cancel
will return 2 if there is no operations in progress.


 Thanks for writing this much needed.
 Its better to have these return error codes defined
 in a header. So that it would guide the future developments.

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


[PATCH 5/5] btrfs-progs:free strdup()s that are not freed

2013-09-04 Thread Gui Hecheng
The strdup()s not freed are reported as memory leaks by valgrind.

Signed-off-by: Gui Hecheng guihc.f...@cn.fujitsu.com
---
 cmds-subvolume.c | 48 ++--
 1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index e1fa81a..51c529c 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -75,6 +75,8 @@ static int cmd_subvol_create(int argc, char **argv)
 {
int retval, res, len;
int fddst = -1;
+   char*dupname = NULL;
+   char*dupdir = NULL;
char*newname;
char*dstdir;
char*dst;
@@ -119,10 +121,10 @@ static int cmd_subvol_create(int argc, char **argv)
goto out;
}
 
-   newname = strdup(dst);
-   newname = basename(newname);
-   dstdir = strdup(dst);
-   dstdir = dirname(dstdir);
+   dupname = strdup(dst);
+   newname = basename(dupname);
+   dupdir = strdup(dst);
+   dstdir = dirname(dupdir);
 
if (!strcmp(newname, .) || !strcmp(newname, ..) ||
 strchr(newname, '/') ){
@@ -175,6 +177,11 @@ out:
close_file_or_dir(fddst, dirstream);
free(inherit);
 
+   if (dupname != NULL)
+   free(dupname);
+   if (dupdir != NULL)
+   free(dupdir);
+
return retval;
 }
 
@@ -208,6 +215,8 @@ static int cmd_subvol_delete(int argc, char **argv)
int res, fd, len, e, cnt = 1, ret = 0;
struct btrfs_ioctl_vol_args args;
char*dname, *vname, *cpath;
+   char*dupdname = NULL;
+   char*dupvname = NULL;
char*path;
DIR *dirstream = NULL;
 
@@ -230,10 +239,10 @@ again:
}
 
cpath = realpath(path, NULL);
-   dname = strdup(cpath);
-   dname = dirname(dname);
-   vname = strdup(cpath);
-   vname = basename(vname);
+   dupdname = strdup(cpath);
+   dname = dirname(dupdname);
+   dupvname = strdup(cpath);
+   vname = basename(dupvname);
free(cpath);
 
if( !strcmp(vname,.) || !strcmp(vname,..) ||
@@ -274,6 +283,10 @@ again:
}
 
 out:
+   if (dupdname != NULL)
+   free(dupdname);
+   if (dupvname != NULL)
+   free(dupvname);
cnt++;
if (cnt  argc)
goto again;
@@ -495,6 +508,8 @@ static int cmd_snapshot(int argc, char **argv)
int res, retval;
int fd = -1, fddst = -1;
int len, readonly = 0;
+   char*dupname = NULL;
+   char*dupdir = NULL;
char*newname;
char*dstdir;
struct btrfs_ioctl_vol_args_v2  args;
@@ -562,14 +577,14 @@ static int cmd_snapshot(int argc, char **argv)
}
 
if (res  0) {
-   newname = strdup(subvol);
-   newname = basename(newname);
+   dupname = strdup(subvol);
+   newname = basename(dupname);
dstdir = dst;
} else {
-   newname = strdup(dst);
-   newname = basename(newname);
-   dstdir = strdup(dst);
-   dstdir = dirname(dstdir);
+   dupname = strdup(dst);
+   newname = basename(dupname);
+   dupdir = strdup(dst);
+   dstdir = dirname(dupdir);
}
 
if (!strcmp(newname, .) || !strcmp(newname, ..) ||
@@ -630,6 +645,11 @@ out:
close_file_or_dir(fd, dirstream2);
free(inherit);
 
+   if (dupname != NULL)
+   free(dupname);
+   if (dupdir != NULL)
+   free(dupdir);
+
return retval;
 }
 
-- 
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 4/5] btrfs-progs:free the local list pending_list in btrfs_scan_one_dir

2013-09-04 Thread Gui Hecheng
Originally the local pending_list is not guaranteed to be freed upon fails, it 
should be emptyed and the elements should be freed.

Signed-off-by: Gui Hecheng guihc.f...@cn.fujitsu.com
---
 utils.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/utils.c b/utils.c
index d022d58..134bf80 100644
--- a/utils.c
+++ b/utils.c
@@ -1066,8 +1066,8 @@ again:
dirp = opendir(dirname);
if (!dirp) {
fprintf(stderr, Unable to open %s for scanning\n, dirname);
-   free(fullpath);
-   return -ENOENT;
+   ret = -ENOENT;
+   goto fail;
}
while(1) {
dirent = readdir(dirp);
@@ -1133,6 +1133,12 @@ again:
 fail:
free(pending);
free(fullpath);
+   while (!list_empty(pending_list)) {
+   pending = list_entry(pending_list.next, struct pending_dir,
+list);
+   list_del(pending-list);
+   free(pending);
+   }
if (dirp)
closedir(dirp);
return ret;
-- 
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/5] btrfs-progs:local variable memory freed

2013-09-04 Thread Gui Hecheng
The local probe variable in is_ssd() freed upon unsuccessful return;
The local dir_head list in make_image() freed upon unsuccessful return.

Signed-off-by: Gui Hecheng guihc.f...@cn.fujitsu.com
---
 mkfs.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/mkfs.c b/mkfs.c
index 1701783..415889e 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1024,6 +1024,8 @@ static int make_image(char *source_dir, struct btrfs_root 
*root, int out_fd)
 
struct directory_name_entry dir_head;
 
+   struct directory_name_entry *dir_entry = NULL;
+
ret = lstat(source_dir, root_st);
if (ret) {
fprintf(stderr, unable to lstat the %s\n, source_dir);
@@ -1043,6 +1045,12 @@ static int make_image(char *source_dir, struct 
btrfs_root *root, int out_fd)
printf(Making image is completed.\n);
return 0;
 fail:
+   while (!list_empty(dir_head.list)) {
+   dir_entry = list_entry(dir_head.list.next,
+  struct directory_name_entry, list);
+   list_del(dir_entry-list);
+   free(dir_entry);
+   }
fprintf(stderr, Making image is aborted.\n);
return -1;
 }
@@ -1161,8 +1169,10 @@ static int is_ssd(const char *file)
 
/* Device number of this disk (possibly a partition) */
devno = blkid_probe_get_devno(probe);
-   if (!devno)
+   if (!devno) {
+   blkid_free_probe(probe);
return 0;
+   }
 
/* Get whole disk name (not full path) for this devno */
blkid_devno_to_wholedisk(devno, wholedisk, sizeof(wholedisk), NULL);
-- 
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 3/5] btrfs-progs: missing tree-freeing statements added

2013-09-04 Thread Gui Hecheng
The seen cache_tree in run_next_block freed.
Originally, this missing causes memory leaks, reported by valgrind.

Signed-off-by: Gui Hecheng guihc.f...@cn.fujitsu.com
---
 cmds-check.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/cmds-check.c b/cmds-check.c
index 6cbd5a6..0cba4cc 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -3595,6 +3595,11 @@ static int run_next_block(struct btrfs_root *root,
remove_cache_extent(nodes, cache);
free(cache);
}
+   cache = lookup_cache_extent(seen, bytenr, size);
+   if (cache) {
+   remove_cache_extent(seen, cache);
+   free(cache);
+   }
 
/* fixme, get the real parent transid */
buf = read_tree_block(root, bytenr, size, 0);
-- 
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 0/5] Memory leaks amended

2013-09-04 Thread Gui Hecheng
Memory leaks found by the tool--valgrind along with static reviewing.

Based on Daivd's branch 'integration-20130903'.

Gui Hecheng (5):
  btrfs-progs:free local variable buf upon unsuccessful returns
  btrfs-progs:local variable memory freed
  btrfs-progs: missing tree-freeing statements added
  btrfs-progs:free the local list pending_list in btrfs_scan_one_dir
  btrfs-progs:free strdup()s that are not freed

 btrfs-image.c|  2 ++
 cmds-check.c |  5 +
 cmds-subvolume.c | 48 ++--
 mkfs.c   | 12 +++-
 utils.c  | 10 --
 5 files changed, 60 insertions(+), 17 deletions(-)

-- 
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/5] btrfs-progs:free local variable buf upon unsuccessful returns

2013-09-04 Thread Gui Hecheng
The variable buf passed into find_collision() as parameter name should be 
freed on unsuccessful returns.

Signed-off-by: Gui Hecheng guihc.f...@cn.fujitsu.com
---
 btrfs-image.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/btrfs-image.c b/btrfs-image.c
index 3ea3730..1a52aa6 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -284,6 +284,7 @@ static char *find_collision(struct metadump_struct *md, 
char *name,
val = malloc(sizeof(struct name));
if (!val) {
fprintf(stderr, Couldn't sanitize name, enomem\n);
+   free(name);
return NULL;
}
 
@@ -295,6 +296,7 @@ static char *find_collision(struct metadump_struct *md, 
char *name,
if (!val-sub) {
fprintf(stderr, Couldn't sanitize name, enomem\n);
free(val);
+   free(name);
return NULL;
}
 
-- 
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 V2 1/5] btrfs-progs:free strdup()s that are not freed

2013-09-04 Thread Gui Hecheng
The strdup()s not freed are reported as memory leaks by valgrind.

Signed-off-by: Gui Hecheng guihc.f...@cn.fujitsu.com
---
Changelog V1 - V2:
- None
---
 cmds-subvolume.c | 40 ++--
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index e1fa81a..f7a0c5f 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -75,6 +75,8 @@ static int cmd_subvol_create(int argc, char **argv)
 {
int retval, res, len;
int fddst = -1;
+   char*dupname = NULL;
+   char*dupdir = NULL;
char*newname;
char*dstdir;
char*dst;
@@ -119,10 +121,10 @@ static int cmd_subvol_create(int argc, char **argv)
goto out;
}
 
-   newname = strdup(dst);
-   newname = basename(newname);
-   dstdir = strdup(dst);
-   dstdir = dirname(dstdir);
+   dupname = strdup(dst);
+   newname = basename(dupname);
+   dupdir = strdup(dst);
+   dstdir = dirname(dupdir);
 
if (!strcmp(newname, .) || !strcmp(newname, ..) ||
 strchr(newname, '/') ){
@@ -174,6 +176,8 @@ static int cmd_subvol_create(int argc, char **argv)
 out:
close_file_or_dir(fddst, dirstream);
free(inherit);
+   free(dupname);
+   free(dupdir);
 
return retval;
 }
@@ -208,6 +212,8 @@ static int cmd_subvol_delete(int argc, char **argv)
int res, fd, len, e, cnt = 1, ret = 0;
struct btrfs_ioctl_vol_args args;
char*dname, *vname, *cpath;
+   char*dupdname = NULL;
+   char*dupvname = NULL;
char*path;
DIR *dirstream = NULL;
 
@@ -230,10 +236,10 @@ again:
}
 
cpath = realpath(path, NULL);
-   dname = strdup(cpath);
-   dname = dirname(dname);
-   vname = strdup(cpath);
-   vname = basename(vname);
+   dupdname = strdup(cpath);
+   dname = dirname(dupdname);
+   dupvname = strdup(cpath);
+   vname = basename(dupvname);
free(cpath);
 
if( !strcmp(vname,.) || !strcmp(vname,..) ||
@@ -274,6 +280,8 @@ again:
}
 
 out:
+   free(dupdname);
+   free(dupvname);
cnt++;
if (cnt  argc)
goto again;
@@ -495,6 +503,8 @@ static int cmd_snapshot(int argc, char **argv)
int res, retval;
int fd = -1, fddst = -1;
int len, readonly = 0;
+   char*dupname = NULL;
+   char*dupdir = NULL;
char*newname;
char*dstdir;
struct btrfs_ioctl_vol_args_v2  args;
@@ -562,14 +572,14 @@ static int cmd_snapshot(int argc, char **argv)
}
 
if (res  0) {
-   newname = strdup(subvol);
-   newname = basename(newname);
+   dupname = strdup(subvol);
+   newname = basename(dupname);
dstdir = dst;
} else {
-   newname = strdup(dst);
-   newname = basename(newname);
-   dstdir = strdup(dst);
-   dstdir = dirname(dstdir);
+   dupname = strdup(dst);
+   newname = basename(dupname);
+   dupdir = strdup(dst);
+   dstdir = dirname(dupdir);
}
 
if (!strcmp(newname, .) || !strcmp(newname, ..) ||
@@ -629,6 +639,8 @@ out:
close_file_or_dir(fddst, dirstream1);
close_file_or_dir(fd, dirstream2);
free(inherit);
+   free(dupname);
+   free(dupdir);
 
return retval;
 }
-- 
1.8.0.1

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


[PATCH] btrfs-progs: btrfs_setup_chunk_tree_and_device_map: Return -EIO on error.

2013-09-04 Thread chandan
As a result of a successful call to btrfs_read_sys_array(), the 'ret'
variable is already set to 0. Hence the function would return 0 even
if the call to read_tree_block() fails.

Signed-off-by: chandan chan...@linux.vnet.ibm.com
---
 disk-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/disk-io.c b/disk-io.c
index fec7700..0f69f0f 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -966,7 +966,7 @@ int btrfs_setup_chunk_tree_and_device_map(struct 
btrfs_fs_info *fs_info)
if (!fs_info-chunk_root-node ||
!extent_buffer_uptodate(fs_info-chunk_root-node)) {
fprintf(stderr, Couldn't read chunk root\n);
-   return ret;
+   return -EIO;
}
 
if (!(btrfs_super_flags(sb)  BTRFS_SUPER_FLAG_METADUMP)) {
-- 
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